Mercurial > pidgin
annotate src/gtkimhtml.c @ 9696:a57fa78e5752
[gaim-migrate @ 10555]
gtk 2.0 fixes from nosnilmot
committer: Tailor Script <tailor@pidgin.im>
| author | Mark Doliner <mark@kingant.net> |
|---|---|
| date | Sat, 07 Aug 2004 03:22:47 +0000 |
| parents | 53e3c74b3628 |
| children | d6292978a704 |
| rev | line source |
|---|---|
| 1428 | 1 /* |
| 2 * GtkIMHtml | |
| 3 * | |
| 8046 | 4 * Gaim is the legal property of its developers, whose names are too numerous |
| 5 * to list here. Please refer to the COPYRIGHT file distributed with this | |
| 6 * source distribution. | |
| 1428 | 7 * |
| 8 * This program is free software; you can redistribute it and/or modify | |
| 9 * under the terms of the GNU General Public License as published by | |
| 10 * the Free Software Foundation; either version 2 of the License, or | |
| 11 * (at your option) any later version. | |
| 12 * | |
| 13 * This program is distributed in the hope that it will be useful, | |
| 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 16 * GNU General Public License for more details. | |
| 17 * | |
| 18 * You should have received a copy of the GNU General Public License | |
| 19 * along with this program; if not, write to the Free Software | |
| 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 21 * | |
| 22 */ | |
| 23 | |
|
2541
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
24 #ifdef HAVE_CONFIG_H |
|
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
25 #include <config.h> |
|
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
26 #endif |
| 8526 | 27 #include "debug.h" |
| 8091 | 28 #include "util.h" |
| 1428 | 29 #include "gtkimhtml.h" |
| 7358 | 30 #include "gtksourceiter.h" |
| 1428 | 31 #include <gtk/gtk.h> |
| 4895 | 32 #include <glib/gerror.h> |
| 4046 | 33 #include <gdk/gdkkeysyms.h> |
| 1428 | 34 #include <string.h> |
| 35 #include <ctype.h> | |
| 36 #include <stdio.h> | |
| 4629 | 37 #include <stdlib.h> |
| 1428 | 38 #include <math.h> |
|
2541
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
39 #ifdef HAVE_LANGINFO_CODESET |
|
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
40 #include <langinfo.h> |
|
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
41 #include <locale.h> |
|
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
42 #endif |
| 8692 | 43 #ifdef _WIN32 |
| 44 #include <windows.h> | |
| 45 #endif | |
| 1428 | 46 |
| 4417 | 47 #ifdef ENABLE_NLS |
| 48 # include <libintl.h> | |
| 49 # define _(x) gettext(x) | |
| 50 # ifdef gettext_noop | |
| 51 # define N_(String) gettext_noop (String) | |
| 52 # else | |
| 53 # define N_(String) (String) | |
| 54 # endif | |
| 55 #else | |
| 56 # define N_(String) (String) | |
| 57 # define _(x) (x) | |
| 58 #endif | |
| 59 | |
| 4735 | 60 #include <pango/pango-font.h> |
| 61 | |
| 5105 | 62 /* GTK+ < 2.2.2 hack, see ui.h for details. */ |
| 63 #ifndef GTK_WRAP_WORD_CHAR | |
| 64 #define GTK_WRAP_WORD_CHAR GTK_WRAP_WORD | |
| 65 #endif | |
| 66 | |
| 4735 | 67 #define TOOLTIP_TIMEOUT 500 |
| 68 | |
| 8786 | 69 /* GTK+ 2.0 hack */ |
| 70 #if (!GTK_CHECK_VERSION(2,2,0)) | |
| 71 #define gtk_widget_get_clipboard(x, y) gtk_clipboard_get(y) | |
| 72 #endif | |
| 73 | |
| 9300 | 74 static gboolean |
| 75 gtk_text_view_drag_motion (GtkWidget *widget, | |
| 76 GdkDragContext *context, | |
| 77 gint x, | |
| 78 gint y, | |
| 79 guint time); | |
| 80 | |
| 8677 | 81 static void preinsert_cb(GtkTextBuffer *buffer, GtkTextIter *iter, gchar *text, gint len, GtkIMHtml *imhtml); |
| 8061 | 82 static void insert_cb(GtkTextBuffer *buffer, GtkTextIter *iter, gchar *text, gint len, GtkIMHtml *imhtml); |
| 8505 | 83 static gboolean gtk_imhtml_is_amp_escape (const gchar *string, gchar **replace, gint *length); |
| 8698 | 84 void gtk_imhtml_close_tags(GtkIMHtml *imhtml, GtkTextIter *iter); |
| 9300 | 85 static void gtk_imhtml_link_drop_cb(GtkWidget *widget, GdkDragContext *context, gint x, gint y, guint time, gpointer user_data); |
| 8091 | 86 static void gtk_imhtml_link_drag_rcv_cb(GtkWidget *widget, GdkDragContext *dc, guint x, guint y, GtkSelectionData *sd, guint info, guint t, GtkIMHtml *imhtml); |
| 8677 | 87 static void mark_set_cb(GtkTextBuffer *buffer, GtkTextIter *arg1, GtkTextMark *mark, GtkIMHtml *imhtml); |
| 8931 | 88 static void hijack_menu_cb(GtkIMHtml *imhtml, GtkMenu *menu, gpointer data); |
| 89 static void paste_received_cb (GtkClipboard *clipboard, GtkSelectionData *selection_data, gpointer data); | |
| 90 static void paste_plaintext_received_cb (GtkClipboard *clipboard, const gchar *text, gpointer data); | |
| 8061 | 91 |
| 3922 | 92 /* POINT_SIZE converts from AIM font sizes to point sizes. It probably should be redone in such a |
| 93 * way that it base the sizes off the default font size rather than using arbitrary font sizes. */ | |
| 94 #define MAX_FONT_SIZE 7 | |
| 5367 | 95 #define POINT_SIZE(x) (options & GTK_IMHTML_USE_POINTSIZE ? x : _point_sizes [MIN ((x), MAX_FONT_SIZE) - 1]) |
| 8380 | 96 static gdouble _point_sizes [] = { .69444444, .8333333, 1, 1.2, 1.44, 1.728, 2.0736}; |
|
2349
60c716c32c40
[gaim-migrate @ 2362]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2348
diff
changeset
|
97 |
| 8498 | 98 enum { |
| 8677 | 99 TARGET_HTML, |
| 8061 | 100 TARGET_UTF8_STRING, |
| 101 TARGET_COMPOUND_TEXT, | |
| 102 TARGET_STRING, | |
| 103 TARGET_TEXT | |
| 104 }; | |
| 105 | |
| 8091 | 106 enum { |
| 9300 | 107 DRAG_URL, |
| 108 DRAG_HTML, | |
| 109 DRAG_UTF8_STRING, | |
| 110 DRAG_COMPOUND_TEXT, | |
| 111 DRAG_STRING, | |
| 112 DRAG_TEXT, | |
| 8091 | 113 }; |
| 114 | |
| 8420 | 115 enum { |
| 116 URL_CLICKED, | |
| 117 BUTTONS_UPDATE, | |
| 118 TOGGLE_FORMAT, | |
| 8427 | 119 CLEAR_FORMAT, |
| 8506 | 120 UPDATE_FORMAT, |
| 8420 | 121 LAST_SIGNAL |
| 122 }; | |
| 123 static guint signals [LAST_SIGNAL] = { 0 }; | |
| 124 | |
| 8061 | 125 GtkTargetEntry selection_targets[] = { |
| 8566 | 126 { "text/html", 0, TARGET_HTML }, |
| 8061 | 127 { "UTF8_STRING", 0, TARGET_UTF8_STRING }, |
| 128 { "COMPOUND_TEXT", 0, TARGET_COMPOUND_TEXT }, | |
| 129 { "STRING", 0, TARGET_STRING }, | |
| 130 { "TEXT", 0, TARGET_TEXT}}; | |
| 131 | |
| 8091 | 132 GtkTargetEntry link_drag_drop_targets[] = { |
| 9300 | 133 {"text/html", 0, DRAG_HTML }, |
| 8091 | 134 {"x-url/ftp", 0, DRAG_URL}, |
| 135 {"x-url/http", 0, DRAG_URL}, | |
| 136 {"text/uri-list", 0, DRAG_URL}, | |
| 9300 | 137 {"_NETSCAPE_URL", 0, DRAG_URL}, |
| 138 { "UTF8_STRING", 0, DRAG_UTF8_STRING }, | |
| 139 { "COMPOUND_TEXT", 0, DRAG_COMPOUND_TEXT }, | |
| 140 { "STRING", 0, DRAG_STRING }, | |
| 141 { "TEXT", 0, DRAG_TEXT}}; | |
| 142 | |
| 8091 | 143 |
| 8692 | 144 #ifdef _WIN32 |
| 145 /* Win32 clipboard format value, and functions to convert back and | |
| 146 * forth between HTML and the clipboard format. | |
| 147 */ | |
| 148 static UINT win_html_fmt; | |
| 149 | |
| 150 static gchar * | |
| 151 clipboard_win32_to_html(char *clipboard) { | |
| 9465 | 152 const char *header; |
| 8693 | 153 const char *begin, *end; |
| 9465 | 154 gint start=0; |
| 155 gint finish=0; | |
| 8692 | 156 gchar *html; |
| 9465 | 157 |
| 158 #if 0 /* Debugging for Windows clipboard */ | |
| 9467 | 159 FILE *fd; |
| 160 | |
| 9465 | 161 gaim_debug_info("imhtml clipboard", "from clipboard: %s\n", clipboard); |
| 162 | |
| 163 fd = fopen("e:\\gaimcb.txt", "wb"); | |
| 164 fprintf(fd, "%s", clipboard); | |
| 165 fclose(fd); | |
| 166 #endif | |
| 167 | |
| 168 if (!(header = strstr(clipboard, "StartFragment:"))) | |
| 169 return NULL; | |
| 170 | |
| 171 sscanf(header, "StartFragment:%d", &start); | |
| 172 | |
| 173 header = strstr(clipboard, "EndFragment:"); | |
| 174 sscanf(header, "EndFragment:%d", &finish); | |
| 175 | |
| 176 begin = clipboard + start; | |
| 177 | |
| 178 if (header == NULL) | |
| 179 end = clipboard + strlen(clipboard); | |
| 180 else | |
| 181 end = clipboard + finish; | |
| 182 | |
| 183 html = g_strstrip(g_strndup(begin, end-begin)); | |
| 184 | |
| 185 #if 0 /* Debugging for Windows clipboard */ | |
| 186 gaim_debug_info("imhtml clipboard", "HTML fragment: %s\n", html); | |
| 187 #endif | |
| 188 | |
| 8707 | 189 return html; |
| 8692 | 190 } |
| 191 | |
| 192 static gchar * | |
| 193 clipboard_html_to_win32(char *html) { | |
| 8693 | 194 int length; |
| 8692 | 195 gchar *ret; |
| 196 GString *clipboard; | |
| 197 | |
| 8693 | 198 if (html == NULL) |
| 199 return NULL; | |
| 8692 | 200 |
| 201 length = strlen(html); | |
| 9465 | 202 clipboard = g_string_new ("Version:1.0\r\n"); |
| 8692 | 203 g_string_append(clipboard, "StartHTML:0000000105\r\n"); |
| 9465 | 204 g_string_append(clipboard, g_strdup_printf("EndHTML:%010d\r\n", 147 + length)); |
| 205 g_string_append(clipboard, "StartFragment:0000000127\r\n"); | |
| 206 g_string_append(clipboard, g_strdup_printf("EndFragment:%010d\r\n", 127 + length)); | |
| 207 g_string_append(clipboard, "<!--StartFragment-->\r\n"); | |
| 8692 | 208 g_string_append(clipboard, html); |
| 9465 | 209 g_string_append(clipboard, "\r\n<!--EndFragment-->"); |
| 8692 | 210 ret = clipboard->str; |
| 211 g_string_free(clipboard, FALSE); | |
| 9465 | 212 |
| 213 #if 0 /* Debugging for Windows clipboard */ | |
| 214 gaim_debug_info("imhtml clipboard", "from gaim: %s\n", ret); | |
| 215 #endif | |
| 216 | |
| 8692 | 217 return ret; |
| 218 } | |
| 219 #endif | |
| 220 | |
| 4032 | 221 static GtkSmileyTree* |
| 222 gtk_smiley_tree_new () | |
| 223 { | |
| 224 return g_new0 (GtkSmileyTree, 1); | |
| 225 } | |
| 226 | |
| 227 static void | |
| 228 gtk_smiley_tree_insert (GtkSmileyTree *tree, | |
| 4263 | 229 GtkIMHtmlSmiley *smiley) |
| 4032 | 230 { |
| 231 GtkSmileyTree *t = tree; | |
| 4263 | 232 const gchar *x = smiley->smile; |
| 4032 | 233 |
| 234 if (!strlen (x)) | |
| 235 return; | |
| 236 | |
| 237 while (*x) { | |
| 238 gchar *pos; | |
| 239 gint index; | |
| 240 | |
| 241 if (!t->values) | |
| 242 t->values = g_string_new (""); | |
| 243 | |
| 244 pos = strchr (t->values->str, *x); | |
| 245 if (!pos) { | |
| 246 t->values = g_string_append_c (t->values, *x); | |
| 247 index = t->values->len - 1; | |
| 248 t->children = g_realloc (t->children, t->values->len * sizeof (GtkSmileyTree *)); | |
| 249 t->children [index] = g_new0 (GtkSmileyTree, 1); | |
| 250 } else | |
| 7386 | 251 index = GPOINTER_TO_INT(pos) - GPOINTER_TO_INT(t->values->str); |
| 8061 | 252 |
| 4032 | 253 t = t->children [index]; |
| 8061 | 254 |
| 4032 | 255 x++; |
| 256 } | |
| 8061 | 257 |
| 4263 | 258 t->image = smiley; |
| 4032 | 259 } |
| 4041 | 260 |
| 4263 | 261 |
| 4264 | 262 void gtk_smiley_tree_destroy (GtkSmileyTree *tree) |
| 4032 | 263 { |
| 264 GSList *list = g_slist_append (NULL, tree); | |
| 265 | |
| 266 while (list) { | |
| 267 GtkSmileyTree *t = list->data; | |
| 268 gint i; | |
| 269 list = g_slist_remove(list, t); | |
| 7384 | 270 if (t && t->values) { |
| 4032 | 271 for (i = 0; i < t->values->len; i++) |
| 272 list = g_slist_append (list, t->children [i]); | |
| 273 g_string_free (t->values, TRUE); | |
| 274 g_free (t->children); | |
| 275 } | |
| 276 g_free (t); | |
| 277 } | |
| 278 } | |
| 279 | |
| 5967 | 280 static gboolean gtk_size_allocate_cb(GtkIMHtml *widget, GtkAllocation *alloc, gpointer user_data) |
| 281 { | |
| 282 GdkRectangle rect; | |
| 8726 | 283 int xminus; |
| 5967 | 284 |
| 285 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(widget), &rect); | |
| 286 if(widget->old_rect.width != rect.width || widget->old_rect.height != rect.height){ | |
| 287 GList *iter = GTK_IMHTML(widget)->scalables; | |
| 288 | |
| 8726 | 289 xminus = gtk_text_view_get_left_margin(GTK_TEXT_VIEW(widget)) + |
| 290 gtk_text_view_get_right_margin(GTK_TEXT_VIEW(widget)); | |
| 291 | |
| 5967 | 292 while(iter){ |
| 293 GtkIMHtmlScalable *scale = GTK_IMHTML_SCALABLE(iter->data); | |
| 8726 | 294 scale->scale(scale, rect.width - xminus, rect.height); |
| 5967 | 295 |
| 296 iter = iter->next; | |
| 297 } | |
| 298 } | |
| 299 | |
| 300 widget->old_rect = rect; | |
| 301 return FALSE; | |
| 302 } | |
| 303 | |
| 304 static gint | |
| 305 gtk_imhtml_tip_paint (GtkIMHtml *imhtml) | |
| 306 { | |
| 307 PangoLayout *layout; | |
| 308 | |
| 309 g_return_val_if_fail(GTK_IS_IMHTML(imhtml), FALSE); | |
| 310 | |
| 311 layout = gtk_widget_create_pango_layout(imhtml->tip_window, imhtml->tip); | |
| 312 | |
| 8061 | 313 gtk_paint_flat_box (imhtml->tip_window->style, imhtml->tip_window->window, |
| 5967 | 314 GTK_STATE_NORMAL, GTK_SHADOW_OUT, NULL, imhtml->tip_window, |
| 315 "tooltip", 0, 0, -1, -1); | |
| 316 | |
| 317 gtk_paint_layout (imhtml->tip_window->style, imhtml->tip_window->window, GTK_STATE_NORMAL, | |
| 318 FALSE, NULL, imhtml->tip_window, NULL, 4, 4, layout); | |
| 319 | |
| 320 g_object_unref(layout); | |
| 321 return FALSE; | |
| 322 } | |
| 323 | |
| 324 static gint | |
| 325 gtk_imhtml_tip (gpointer data) | |
| 326 { | |
| 327 GtkIMHtml *imhtml = data; | |
| 8526 | 328 PangoFontMetrics *font_metrics; |
| 5967 | 329 PangoLayout *layout; |
| 8526 | 330 PangoFont *font; |
| 5967 | 331 |
| 332 gint gap, x, y, h, w, scr_w, baseline_skip; | |
| 333 | |
| 334 g_return_val_if_fail(GTK_IS_IMHTML(imhtml), FALSE); | |
| 335 | |
| 336 if (!imhtml->tip || !GTK_WIDGET_DRAWABLE (GTK_WIDGET(imhtml))) { | |
| 337 imhtml->tip_timer = 0; | |
| 338 return FALSE; | |
| 339 } | |
| 8061 | 340 |
| 5967 | 341 if (imhtml->tip_window){ |
| 342 gtk_widget_destroy (imhtml->tip_window); | |
| 343 imhtml->tip_window = NULL; | |
| 344 } | |
| 345 | |
| 346 imhtml->tip_timer = 0; | |
| 347 imhtml->tip_window = gtk_window_new (GTK_WINDOW_POPUP); | |
| 348 gtk_widget_set_app_paintable (imhtml->tip_window, TRUE); | |
| 349 gtk_window_set_resizable (GTK_WINDOW (imhtml->tip_window), FALSE); | |
| 350 gtk_widget_set_name (imhtml->tip_window, "gtk-tooltips"); | |
| 351 g_signal_connect_swapped (G_OBJECT (imhtml->tip_window), "expose_event", | |
| 352 G_CALLBACK (gtk_imhtml_tip_paint), imhtml); | |
| 353 | |
| 354 gtk_widget_ensure_style (imhtml->tip_window); | |
| 355 layout = gtk_widget_create_pango_layout(imhtml->tip_window, imhtml->tip); | |
| 8526 | 356 font = pango_context_load_font(pango_layout_get_context(layout), |
| 357 imhtml->tip_window->style->font_desc); | |
| 358 | |
| 359 if (font == NULL) { | |
| 360 char *tmp = pango_font_description_to_string( | |
| 361 imhtml->tip_window->style->font_desc); | |
| 362 | |
| 363 gaim_debug(GAIM_DEBUG_ERROR, "gtk_imhtml_tip", | |
| 364 "pango_context_load_font() couldn't load font: '%s'\n", | |
| 365 tmp); | |
| 366 g_free(tmp); | |
| 367 | |
| 368 return FALSE; | |
| 369 | |
| 370 } | |
| 371 | |
| 372 font_metrics = pango_font_get_metrics(font, NULL); | |
| 8309 | 373 |
| 5967 | 374 |
| 375 pango_layout_get_pixel_size(layout, &scr_w, NULL); | |
| 8526 | 376 gap = PANGO_PIXELS((pango_font_metrics_get_ascent(font_metrics) + |
| 377 pango_font_metrics_get_descent(font_metrics))/ 4); | |
| 5967 | 378 |
| 379 if (gap < 2) | |
| 380 gap = 2; | |
| 8526 | 381 baseline_skip = PANGO_PIXELS(pango_font_metrics_get_ascent(font_metrics) + |
| 382 pango_font_metrics_get_descent(font_metrics)); | |
| 5967 | 383 w = 8 + scr_w; |
| 384 h = 8 + baseline_skip; | |
| 385 | |
| 386 gdk_window_get_pointer (NULL, &x, &y, NULL); | |
| 387 if (GTK_WIDGET_NO_WINDOW (GTK_WIDGET(imhtml))) | |
| 388 y += GTK_WIDGET(imhtml)->allocation.y; | |
| 389 | |
| 390 scr_w = gdk_screen_width(); | |
| 391 | |
| 392 x -= ((w >> 1) + 4); | |
| 393 | |
| 394 if ((x + w) > scr_w) | |
| 395 x -= (x + w) - scr_w; | |
| 396 else if (x < 0) | |
| 397 x = 0; | |
| 398 | |
| 8526 | 399 y = y + PANGO_PIXELS(pango_font_metrics_get_ascent(font_metrics) + |
| 400 pango_font_metrics_get_descent(font_metrics)); | |
| 5967 | 401 |
| 402 gtk_widget_set_size_request (imhtml->tip_window, w, h); | |
| 403 gtk_widget_show (imhtml->tip_window); | |
| 404 gtk_window_move (GTK_WINDOW(imhtml->tip_window), x, y); | |
| 405 | |
| 8526 | 406 pango_font_metrics_unref(font_metrics); |
| 5967 | 407 g_object_unref(layout); |
| 408 | |
| 409 return FALSE; | |
| 410 } | |
| 411 | |
| 412 gboolean gtk_motion_event_notify(GtkWidget *imhtml, GdkEventMotion *event, gpointer data) | |
| 8061 | 413 { |
| 5967 | 414 GtkTextIter iter; |
| 415 GdkWindow *win = event->window; | |
| 416 int x, y; | |
| 417 char *tip = NULL; | |
| 418 GSList *tags = NULL, *templist = NULL; | |
| 419 gdk_window_get_pointer(GTK_WIDGET(imhtml)->window, NULL, NULL, NULL); | |
| 420 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(imhtml), GTK_TEXT_WINDOW_WIDGET, | |
| 421 event->x, event->y, &x, &y); | |
| 422 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(imhtml), &iter, x, y); | |
| 423 tags = gtk_text_iter_get_tags(&iter); | |
| 424 | |
| 425 templist = tags; | |
| 426 while (templist) { | |
| 427 GtkTextTag *tag = templist->data; | |
| 428 tip = g_object_get_data(G_OBJECT(tag), "link_url"); | |
| 429 if (tip) | |
| 430 break; | |
| 431 templist = templist->next; | |
| 432 } | |
| 8061 | 433 |
| 5967 | 434 if (GTK_IMHTML(imhtml)->tip) { |
| 435 if ((tip == GTK_IMHTML(imhtml)->tip)) { | |
| 436 return FALSE; | |
| 437 } | |
| 438 /* We've left the cell. Remove the timeout and create a new one below */ | |
| 439 if (GTK_IMHTML(imhtml)->tip_window) { | |
| 440 gtk_widget_destroy(GTK_IMHTML(imhtml)->tip_window); | |
| 441 GTK_IMHTML(imhtml)->tip_window = NULL; | |
| 442 } | |
| 8061 | 443 if (GTK_IMHTML(imhtml)->editable) |
| 444 gdk_window_set_cursor(win, GTK_IMHTML(imhtml)->text_cursor); | |
| 445 else | |
| 446 gdk_window_set_cursor(win, GTK_IMHTML(imhtml)->arrow_cursor); | |
| 5967 | 447 if (GTK_IMHTML(imhtml)->tip_timer) |
| 448 g_source_remove(GTK_IMHTML(imhtml)->tip_timer); | |
| 449 GTK_IMHTML(imhtml)->tip_timer = 0; | |
| 450 } | |
| 8061 | 451 |
| 5967 | 452 if(tip){ |
| 8061 | 453 if (!GTK_IMHTML(imhtml)->editable) |
| 454 gdk_window_set_cursor(win, GTK_IMHTML(imhtml)->hand_cursor); | |
| 455 GTK_IMHTML(imhtml)->tip_timer = g_timeout_add (TOOLTIP_TIMEOUT, | |
| 5967 | 456 gtk_imhtml_tip, imhtml); |
| 457 } | |
| 8061 | 458 |
| 5967 | 459 GTK_IMHTML(imhtml)->tip = tip; |
| 460 g_slist_free(tags); | |
| 461 return FALSE; | |
| 462 } | |
| 463 | |
| 464 gboolean gtk_leave_event_notify(GtkWidget *imhtml, GdkEventCrossing *event, gpointer data) | |
| 465 { | |
| 466 /* when leaving the widget, clear any current & pending tooltips and restore the cursor */ | |
| 467 if (GTK_IMHTML(imhtml)->tip_window) { | |
| 468 gtk_widget_destroy(GTK_IMHTML(imhtml)->tip_window); | |
| 469 GTK_IMHTML(imhtml)->tip_window = NULL; | |
| 470 } | |
| 471 if (GTK_IMHTML(imhtml)->tip_timer) { | |
| 472 g_source_remove(GTK_IMHTML(imhtml)->tip_timer); | |
| 473 GTK_IMHTML(imhtml)->tip_timer = 0; | |
| 474 } | |
| 8061 | 475 if (GTK_IMHTML(imhtml)->editable) |
| 476 gdk_window_set_cursor(event->window, GTK_IMHTML(imhtml)->text_cursor); | |
| 477 else | |
| 478 gdk_window_set_cursor(event->window, GTK_IMHTML(imhtml)->arrow_cursor); | |
| 5967 | 479 |
| 8568 | 480 /* propagate the event normally */ |
| 5967 | 481 return FALSE; |
| 482 } | |
| 483 | |
| 6066 | 484 /* |
| 485 * XXX - This should be removed eventually. | |
| 486 * | |
| 8061 | 487 * This function exists to work around a gross bug in GtkTextView. |
| 488 * Basically, we short circuit ctrl+a and ctrl+end because they make | |
| 6066 | 489 * el program go boom. |
| 490 * | |
| 8061 | 491 * It's supposed to be fixed in gtk2.2. You can view the bug report at |
| 6066 | 492 * http://bugzilla.gnome.org/show_bug.cgi?id=107939 |
| 493 */ | |
| 8317 | 494 |
| 495 /* | |
| 496 * I'm adding some keyboard shortcuts too. | |
| 497 */ | |
| 498 | |
| 499 gboolean gtk_key_pressed_cb(GtkIMHtml *imhtml, GdkEventKey *event, gpointer data) | |
| 8677 | 500 { |
| 8317 | 501 char buf[7]; |
| 502 buf[0] = '\0'; | |
| 503 | |
| 6066 | 504 if (event->state & GDK_CONTROL_MASK) |
| 505 switch (event->keyval) { | |
| 8539 | 506 #if (!GTK_CHECK_VERSION(2,2,0)) |
| 8317 | 507 case 'a': |
| 508 return TRUE; | |
| 509 break; | |
| 8677 | 510 |
| 8317 | 511 case GDK_Home: |
| 512 return TRUE; | |
| 513 break; | |
| 514 | |
| 515 case GDK_End: | |
| 516 return TRUE; | |
| 517 break; | |
| 8758 | 518 #endif /* !(Gtk+ >= 2.2.0) */ |
| 8317 | 519 |
| 520 case 'b': /* ctrl-b is GDK_Left, which moves backwards. */ | |
| 521 case 'B': | |
| 8420 | 522 if (imhtml->format_functions & GTK_IMHTML_BOLD) { |
| 8456 | 523 if(imhtml->html_shortcuts) { |
| 524 gtk_imhtml_toggle_bold(imhtml); | |
| 8466 | 525 return TRUE; |
| 8456 | 526 } |
| 8420 | 527 } |
| 8466 | 528 return FALSE; |
| 8317 | 529 break; |
| 8654 | 530 |
| 8317 | 531 case 'i': |
| 532 case 'I': | |
| 8481 | 533 if (imhtml->format_functions & GTK_IMHTML_ITALIC) { |
| 8466 | 534 if(imhtml->html_shortcuts) { |
| 8456 | 535 gtk_imhtml_toggle_italic(imhtml); |
| 8466 | 536 return TRUE; |
| 537 } | |
| 8481 | 538 } |
| 8466 | 539 return FALSE; |
| 8317 | 540 break; |
| 541 | |
| 542 case 'u': /* ctrl-u is GDK_Clear, which clears the line. */ | |
| 543 case 'U': | |
| 8481 | 544 if (imhtml->format_functions & GTK_IMHTML_UNDERLINE) { |
| 8466 | 545 if(imhtml->html_shortcuts) { |
| 8456 | 546 gtk_imhtml_toggle_underline(imhtml); |
| 8466 | 547 return TRUE; |
| 548 } | |
| 8481 | 549 } |
| 8466 | 550 return FALSE; |
| 8317 | 551 break; |
| 552 | |
| 553 case '-': | |
| 8420 | 554 if (imhtml->format_functions & GTK_IMHTML_SHRINK) |
| 555 gtk_imhtml_font_shrink(imhtml); | |
| 8317 | 556 return TRUE; |
| 557 break; | |
| 558 | |
| 559 case '=': | |
| 560 case '+': | |
| 8420 | 561 if (imhtml->format_functions & GTK_IMHTML_GROW) |
| 562 gtk_imhtml_font_grow(imhtml); | |
| 8317 | 563 return TRUE; |
| 564 break; | |
| 8677 | 565 |
| 8317 | 566 case '1': strcpy(buf, ":-)"); break; |
| 567 case '2': strcpy(buf, ":-("); break; | |
| 568 case '3': strcpy(buf, ";-)"); break; | |
| 569 case '4': strcpy(buf, ":-P"); break; | |
| 570 case '5': strcpy(buf, "=-O"); break; | |
| 571 case '6': strcpy(buf, ":-*"); break; | |
| 572 case '7': strcpy(buf, ">:o"); break; | |
| 573 case '8': strcpy(buf, "8-)"); break; | |
| 574 case '!': strcpy(buf, ":-$"); break; | |
| 575 case '@': strcpy(buf, ":-!"); break; | |
| 576 case '#': strcpy(buf, ":-["); break; | |
| 577 case '$': strcpy(buf, "O:-)"); break; | |
| 578 case '%': strcpy(buf, ":-/"); break; | |
| 579 case '^': strcpy(buf, ":'("); break; | |
| 580 case '&': strcpy(buf, ":-X"); break; | |
| 581 case '*': strcpy(buf, ":-D"); break; | |
| 6066 | 582 } |
| 8456 | 583 if (*buf && imhtml->smiley_shortcuts) { |
| 584 gtk_imhtml_insert_smiley(imhtml, imhtml->protocol_name, buf); | |
| 8317 | 585 return TRUE; |
| 8677 | 586 } |
| 6066 | 587 return FALSE; |
| 588 } | |
| 589 | |
| 8931 | 590 static void paste_unformatted_cb(GtkMenuItem *menu, GtkIMHtml *imhtml) |
| 591 { | |
| 592 GtkClipboard *clipboard = gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_CLIPBOARD); | |
| 593 | |
| 594 gtk_clipboard_request_text(clipboard, paste_plaintext_received_cb, imhtml); | |
| 595 | |
| 596 } | |
| 597 | |
| 598 static void hijack_menu_cb(GtkIMHtml *imhtml, GtkMenu *menu, gpointer data) | |
| 599 { | |
| 600 GtkWidget *menuitem; | |
| 601 | |
| 602 menuitem = gtk_menu_item_new_with_mnemonic(_("Pa_ste As Text")); | |
| 603 gtk_widget_show(menuitem); | |
| 604 gtk_widget_set_sensitive(menuitem, | |
| 605 (imhtml->editable && | |
| 606 gtk_clipboard_wait_is_text_available( | |
| 607 gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_CLIPBOARD)))); | |
| 608 /* put it after "Paste" */ | |
| 609 gtk_menu_shell_insert(GTK_MENU_SHELL(menu), menuitem, 3); | |
| 610 | |
| 611 g_signal_connect(G_OBJECT(menuitem), "activate", | |
| 612 G_CALLBACK(paste_unformatted_cb), imhtml); | |
| 613 } | |
| 614 | |
| 8061 | 615 static void gtk_imhtml_clipboard_get(GtkClipboard *clipboard, GtkSelectionData *selection_data, guint info, GtkIMHtml *imhtml) { |
| 8681 | 616 char *text; |
|
8782
5a2b5e4abf3a
[gaim-migrate @ 9544]
Christian Hammond <chipx86@chipx86.com>
parents:
8758
diff
changeset
|
617 gboolean primary; |
| 8061 | 618 GtkTextIter start, end; |
| 619 GtkTextMark *sel = gtk_text_buffer_get_selection_bound(imhtml->text_buffer); | |
| 620 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); | |
| 8681 | 621 |
| 8061 | 622 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &start, sel); |
| 623 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &end, ins); | |
|
8782
5a2b5e4abf3a
[gaim-migrate @ 9544]
Christian Hammond <chipx86@chipx86.com>
parents:
8758
diff
changeset
|
624 primary = gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_PRIMARY) == clipboard; |
| 8061 | 625 |
| 626 if (info == TARGET_HTML) { | |
| 8907 | 627 gsize len; |
| 8148 | 628 char *selection; |
| 8061 | 629 GString *str = g_string_new(NULL); |
| 8681 | 630 if (primary) { |
| 631 text = gtk_imhtml_get_markup_range(imhtml, &start, &end); | |
| 632 } else | |
| 633 text = imhtml->clipboard_html_string; | |
| 8061 | 634 |
| 635 /* Mozilla asks that we start our text/html with the Unicode byte order mark */ | |
| 636 str = g_string_append_unichar(str, 0xfeff); | |
| 637 str = g_string_append(str, text); | |
| 638 str = g_string_append_unichar(str, 0x0000); | |
| 8148 | 639 selection = g_convert(str->str, str->len, "UCS-2", "UTF-8", NULL, &len, NULL); |
| 8719 | 640 gtk_selection_data_set(selection_data, gdk_atom_intern("text/html", FALSE), 16, selection, len); |
| 8061 | 641 g_string_free(str, TRUE); |
| 642 g_free(selection); | |
| 643 } else { | |
| 8681 | 644 if (primary) { |
| 645 text = gtk_imhtml_get_text(imhtml, &start, &end); | |
| 646 } else | |
| 647 text = imhtml->clipboard_text_string; | |
| 8061 | 648 gtk_selection_data_set_text(selection_data, text, strlen(text)); |
| 649 } | |
| 8681 | 650 if (primary) /* This was allocated here */ |
| 651 g_free(text); | |
| 652 } | |
| 8061 | 653 |
| 654 static void gtk_imhtml_primary_clipboard_clear(GtkClipboard *clipboard, GtkIMHtml *imhtml) | |
| 7749 | 655 { |
| 8061 | 656 GtkTextIter insert; |
| 657 GtkTextIter selection_bound; | |
| 658 | |
| 659 gtk_text_buffer_get_iter_at_mark (imhtml->text_buffer, &insert, | |
| 660 gtk_text_buffer_get_mark (imhtml->text_buffer, "insert")); | |
| 661 gtk_text_buffer_get_iter_at_mark (imhtml->text_buffer, &selection_bound, | |
| 662 gtk_text_buffer_get_mark (imhtml->text_buffer, "selection_bound")); | |
| 663 | |
| 664 if (!gtk_text_iter_equal (&insert, &selection_bound)) | |
| 665 gtk_text_buffer_move_mark (imhtml->text_buffer, | |
| 666 gtk_text_buffer_get_mark (imhtml->text_buffer, "selection_bound"), | |
| 667 &insert); | |
| 7749 | 668 } |
| 7742 | 669 |
| 8677 | 670 static void copy_clipboard_cb(GtkIMHtml *imhtml, gpointer unused) |
| 7749 | 671 { |
| 8681 | 672 GtkTextIter start, end; |
| 673 GtkTextMark *sel = gtk_text_buffer_get_selection_bound(imhtml->text_buffer); | |
| 674 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); | |
| 675 | |
| 676 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &start, sel); | |
| 677 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &end, ins); | |
| 678 | |
| 8061 | 679 gtk_clipboard_set_with_owner(gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_CLIPBOARD), |
| 680 selection_targets, sizeof(selection_targets) / sizeof(GtkTargetEntry), | |
| 681 (GtkClipboardGetFunc)gtk_imhtml_clipboard_get, | |
| 682 (GtkClipboardClearFunc)NULL, G_OBJECT(imhtml)); | |
| 7346 | 683 |
| 8681 | 684 if (imhtml->clipboard_html_string) { |
| 685 g_free(imhtml->clipboard_html_string); | |
| 686 g_free(imhtml->clipboard_text_string); | |
| 687 } | |
| 688 | |
| 689 imhtml->clipboard_html_string = gtk_imhtml_get_markup_range(imhtml, &start, &end); | |
| 690 imhtml->clipboard_text_string = gtk_imhtml_get_text(imhtml, &start, &end); | |
| 691 | |
| 8692 | 692 #ifdef _WIN32 |
| 693 /* We're going to still copy plain text, but let's toss the "HTML Format" | |
| 694 we need into the windows clipboard now as well. */ | |
| 695 HGLOBAL hdata; | |
| 696 gchar *clipboard = clipboard_html_to_win32(imhtml->clipboard_html_string); | |
| 697 gchar *buffer; | |
| 698 gint length = strlen(clipboard); | |
| 699 if(clipboard != NULL) { | |
| 8693 | 700 OpenClipboard(NULL); |
| 8692 | 701 hdata = GlobalAlloc(GMEM_MOVEABLE, length); |
| 702 buffer = GlobalLock(hdata); | |
| 703 memcpy(buffer, clipboard, length); | |
| 704 GlobalUnlock(hdata); | |
| 705 SetClipboardData(win_html_fmt, hdata); | |
| 706 CloseClipboard(); | |
| 8693 | 707 g_free(clipboard); |
| 8692 | 708 } |
| 709 #endif | |
| 710 | |
| 8061 | 711 g_signal_stop_emission_by_name(imhtml, "copy-clipboard"); |
| 712 } | |
| 713 | |
| 8698 | 714 static void cut_clipboard_cb(GtkIMHtml *imhtml, gpointer unused) |
| 715 { | |
| 716 GtkTextIter start, end; | |
| 717 GtkTextMark *sel = gtk_text_buffer_get_selection_bound(imhtml->text_buffer); | |
| 718 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); | |
| 719 | |
| 720 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &start, sel); | |
| 721 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &end, ins); | |
| 722 | |
| 723 gtk_clipboard_set_with_owner(gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_CLIPBOARD), | |
| 724 selection_targets, sizeof(selection_targets) / sizeof(GtkTargetEntry), | |
| 725 (GtkClipboardGetFunc)gtk_imhtml_clipboard_get, | |
| 726 (GtkClipboardClearFunc)NULL, G_OBJECT(imhtml)); | |
| 727 | |
| 728 if (imhtml->clipboard_html_string) { | |
| 729 g_free(imhtml->clipboard_html_string); | |
| 730 g_free(imhtml->clipboard_text_string); | |
| 731 } | |
| 732 | |
| 733 imhtml->clipboard_html_string = gtk_imhtml_get_markup_range(imhtml, &start, &end); | |
| 734 imhtml->clipboard_text_string = gtk_imhtml_get_text(imhtml, &start, &end); | |
| 735 | |
| 736 #ifdef _WIN32 | |
| 737 /* We're going to still copy plain text, but let's toss the "HTML Format" | |
| 738 we need into the windows clipboard now as well. */ | |
| 739 HGLOBAL hdata; | |
| 740 gchar *clipboard = clipboard_html_to_win32(imhtml->clipboard_html_string); | |
| 741 gchar *buffer; | |
| 742 gint length = strlen(clipboard); | |
| 743 if(clipboard != NULL) { | |
| 744 OpenClipboard(NULL); | |
| 745 hdata = GlobalAlloc(GMEM_MOVEABLE, length); | |
| 746 buffer = GlobalLock(hdata); | |
| 747 memcpy(buffer, clipboard, length); | |
| 748 GlobalUnlock(hdata); | |
| 749 SetClipboardData(win_html_fmt, hdata); | |
| 750 CloseClipboard(); | |
| 751 g_free(clipboard); | |
| 752 } | |
| 753 #endif | |
| 754 | |
| 755 if (imhtml->editable) | |
| 756 gtk_text_buffer_delete_selection(imhtml->text_buffer, FALSE, FALSE); | |
| 757 g_signal_stop_emission_by_name(imhtml, "cut-clipboard"); | |
| 758 } | |
| 759 | |
| 8931 | 760 static void imhtml_paste_insert(GtkIMHtml *imhtml, const char *text, gboolean plaintext) |
| 761 { | |
| 762 GtkTextIter iter; | |
| 9465 | 763 GtkIMHtmlOptions flags = plaintext ? 0 : (GTK_IMHTML_NO_NEWLINE | GTK_IMHTML_NO_COMMENTS); |
| 8931 | 764 |
| 9028 | 765 if (gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, NULL, NULL)) |
| 766 gtk_text_buffer_delete_selection(imhtml->text_buffer, TRUE, TRUE); | |
| 767 | |
| 8931 | 768 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, gtk_text_buffer_get_insert(imhtml->text_buffer)); |
| 769 if (!imhtml->wbfo && !plaintext) | |
| 770 gtk_imhtml_close_tags(imhtml, &iter); | |
| 771 | |
| 772 gtk_imhtml_insert_html_at_iter(imhtml, text, flags, &iter); | |
| 773 gtk_text_buffer_move_mark_by_name(imhtml->text_buffer, "insert", &iter); | |
| 774 gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(imhtml), gtk_text_buffer_get_insert(imhtml->text_buffer), | |
| 775 0, FALSE, 0.0, 0.0); | |
| 776 } | |
| 777 | |
| 778 static void paste_plaintext_received_cb (GtkClipboard *clipboard, const gchar *text, gpointer data) | |
| 779 { | |
| 780 char *tmp; | |
| 781 | |
| 782 if (text == NULL) | |
| 783 return; | |
| 784 | |
| 785 tmp = gaim_escape_html(text); | |
| 786 imhtml_paste_insert(data, tmp, TRUE); | |
| 787 g_free(tmp); | |
| 788 } | |
| 789 | |
| 8061 | 790 static void paste_received_cb (GtkClipboard *clipboard, GtkSelectionData *selection_data, gpointer data) |
| 791 { | |
| 792 char *text; | |
| 793 GtkIMHtml *imhtml = data; | |
| 7809 | 794 |
| 8123 | 795 if (!gtk_text_view_get_editable(GTK_TEXT_VIEW(imhtml))) |
| 8105 | 796 return; |
| 797 | |
| 8061 | 798 if (selection_data->length < 0) { |
| 8931 | 799 gtk_clipboard_request_text(clipboard, paste_plaintext_received_cb, imhtml); |
| 800 return; | |
| 8061 | 801 } else { |
| 8719 | 802 #if 0 |
| 803 /* Here's some debug code, for figuring out what sent to us over the clipboard. */ | |
| 804 { | |
| 805 int i; | |
| 806 | |
| 807 gaim_debug_misc("gtkimhtml", "In paste_received_cb():\n\tformat = %d, length = %d\n\t", | |
| 808 selection_data->format, selection_data->length); | |
| 809 | |
| 810 for (i = 0; i < (/*(selection_data->format / 8) **/ selection_data->length); i++) { | |
| 811 if ((i % 70) == 0) | |
| 812 printf("\n\t"); | |
| 813 if (selection_data->data[i] == '\0') | |
| 814 printf("."); | |
| 815 else | |
| 816 printf("%c", selection_data->data[i]); | |
| 817 } | |
| 818 printf("\n"); | |
| 819 } | |
| 820 #endif | |
| 821 text = g_malloc(selection_data->length); | |
| 822 memcpy(text, selection_data->data, selection_data->length); | |
| 7766 | 823 } |
| 8061 | 824 |
| 8869 | 825 if (selection_data->length >= 2 && |
| 826 (*(guint16 *)text == 0xfeff || *(guint16 *)text == 0xfffe)) { | |
| 827 /* This is UCS-2 */ | |
| 8909 | 828 char *tmp; |
| 8869 | 829 char *utf8 = g_convert(text, selection_data->length, "UTF-8", "UCS-2", NULL, NULL, NULL); |
| 8061 | 830 g_free(text); |
| 831 text = utf8; | |
| 8698 | 832 if (!text) { |
| 8869 | 833 gaim_debug_warning("gtkimhtml", "g_convert from UCS-2 failed in paste_received_cb\n"); |
| 8698 | 834 return; |
| 835 } | |
| 8909 | 836 tmp = g_utf8_next_char(text); |
| 837 memmove(text, tmp, strlen(tmp) + 1); | |
| 8061 | 838 } |
| 9621 | 839 |
| 8698 | 840 if (!(*text) || !g_utf8_validate(text, -1, NULL)) { |
| 841 gaim_debug_warning("gtkimhtml", "empty string or invalid UTF-8 in paste_received_cb\n"); | |
| 842 g_free(text); | |
| 843 return; | |
| 844 } | |
| 845 | |
| 8931 | 846 imhtml_paste_insert(imhtml, text, FALSE); |
| 8681 | 847 g_free(text); |
| 8061 | 848 } |
| 849 | |
| 850 static void paste_clipboard_cb(GtkIMHtml *imhtml, gpointer blah) | |
| 851 { | |
| 8931 | 852 #ifdef _WIN32 |
| 853 /* If we're on windows, let's see if we can get data from the HTML Format | |
| 854 clipboard before we try to paste from the GTK buffer */ | |
| 855 HGLOBAL hdata; | |
| 856 DWORD err; | |
| 857 char *buffer; | |
| 858 char *text; | |
| 859 | |
| 860 if (!gtk_text_view_get_editable(GTK_TEXT_VIEW(imhtml))) | |
| 861 return; | |
| 862 | |
| 863 if (IsClipboardFormatAvailable(win_html_fmt)) { | |
| 864 OpenClipboard(NULL); | |
| 865 hdata = GetClipboardData(win_html_fmt); | |
| 866 if (hdata == NULL) { | |
| 867 err = GetLastError(); | |
| 868 gaim_debug_info("html clipboard", "error number %u! See http://msdn.microsoft.com/library/en-us/debug/base/system_error_codes.asp\n", err); | |
| 869 CloseClipboard(); | |
| 870 return; | |
| 871 } | |
| 872 buffer = GlobalLock(hdata); | |
| 873 if (buffer == NULL) { | |
| 874 err = GetLastError(); | |
| 875 gaim_debug_info("html clipboard", "error number %u! See http://msdn.microsoft.com/library/en-us/debug/base/system_error_codes.asp\n", err); | |
| 876 CloseClipboard(); | |
| 877 return; | |
| 878 } | |
| 879 text = clipboard_win32_to_html(buffer); | |
| 880 GlobalUnlock(hdata); | |
| 881 CloseClipboard(); | |
| 882 | |
| 883 imhtml_paste_insert(imhtml, text, FALSE); | |
| 884 g_free(text); | |
| 885 } else { | |
| 886 #endif | |
| 8061 | 887 GtkClipboard *clipboard = gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_CLIPBOARD); |
| 888 gtk_clipboard_request_contents(clipboard, gdk_atom_intern("text/html", FALSE), | |
| 889 paste_received_cb, imhtml); | |
| 8931 | 890 #ifdef _WIN32 |
| 891 } | |
| 892 #endif | |
| 8061 | 893 g_signal_stop_emission_by_name(imhtml, "paste-clipboard"); |
| 7766 | 894 } |
| 895 | |
| 8677 | 896 static void imhtml_realized_remove_primary(GtkIMHtml *imhtml, gpointer unused) |
| 897 { | |
| 898 gtk_text_buffer_remove_selection_clipboard(GTK_IMHTML(imhtml)->text_buffer, | |
| 899 gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_PRIMARY)); | |
| 900 | |
| 901 } | |
| 902 | |
|
8740
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
903 static void imhtml_destroy_add_primary(GtkIMHtml *imhtml, gpointer unused) |
|
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
904 { |
|
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
905 gtk_text_buffer_add_selection_clipboard(GTK_IMHTML(imhtml)->text_buffer, |
|
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
906 gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_PRIMARY)); |
|
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
907 } |
| 8677 | 908 |
| 909 static void mark_set_so_update_selection_cb(GtkTextBuffer *buffer, GtkTextIter *arg1, GtkTextMark *mark, GtkIMHtml *imhtml) | |
| 910 { | |
| 911 if (gtk_text_buffer_get_selection_bounds(buffer, NULL, NULL)) { | |
| 912 gtk_clipboard_set_with_owner(gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_PRIMARY), | |
| 913 selection_targets, sizeof(selection_targets) / sizeof(GtkTargetEntry), | |
| 914 (GtkClipboardGetFunc)gtk_imhtml_clipboard_get, | |
| 915 (GtkClipboardClearFunc)gtk_imhtml_primary_clipboard_clear, G_OBJECT(imhtml)); | |
| 916 } | |
| 917 } | |
| 918 | |
| 919 static gboolean gtk_imhtml_button_press_event(GtkIMHtml *imhtml, GdkEventButton *event, gpointer unused) | |
| 7346 | 920 { |
| 8677 | 921 if (event->button == 2) { |
| 922 int x, y; | |
| 923 GtkTextIter iter; | |
| 924 GtkClipboard *clipboard = gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_PRIMARY); | |
| 925 | |
| 926 if (!imhtml->editable) | |
| 927 return FALSE; | |
| 928 | |
| 929 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(imhtml), | |
| 930 GTK_TEXT_WINDOW_TEXT, | |
| 931 event->x, | |
| 932 event->y, | |
| 933 &x, | |
| 934 &y); | |
| 935 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(imhtml), &iter, x, y); | |
| 936 gtk_text_buffer_place_cursor(imhtml->text_buffer, &iter); | |
| 937 | |
| 938 gtk_clipboard_request_contents(clipboard, gdk_atom_intern("text/html", FALSE), | |
| 939 paste_received_cb, imhtml); | |
| 940 | |
| 941 return TRUE; | |
| 942 } | |
| 943 | |
| 7346 | 944 return FALSE; |
| 945 } | |
| 4263 | 946 |
| 4032 | 947 static GtkTextViewClass *parent_class = NULL; |
| 948 | |
| 949 static void | |
| 950 gtk_imhtml_finalize (GObject *object) | |
| 951 { | |
| 952 GtkIMHtml *imhtml = GTK_IMHTML(object); | |
| 4895 | 953 GList *scalables; |
| 8962 | 954 GSList *l; |
| 8061 | 955 |
| 4138 | 956 g_hash_table_destroy(imhtml->smiley_data); |
| 4032 | 957 gtk_smiley_tree_destroy(imhtml->default_smilies); |
| 4138 | 958 gdk_cursor_unref(imhtml->hand_cursor); |
| 959 gdk_cursor_unref(imhtml->arrow_cursor); | |
| 8061 | 960 gdk_cursor_unref(imhtml->text_cursor); |
| 8677 | 961 |
| 4735 | 962 if(imhtml->tip_window){ |
| 963 gtk_widget_destroy(imhtml->tip_window); | |
| 964 } | |
| 965 if(imhtml->tip_timer) | |
| 966 gtk_timeout_remove(imhtml->tip_timer); | |
| 967 | |
| 4895 | 968 for(scalables = imhtml->scalables; scalables; scalables = scalables->next) { |
| 969 GtkIMHtmlScalable *scale = GTK_IMHTML_SCALABLE(scalables->data); | |
| 970 scale->free(scale); | |
| 971 } | |
| 7991 | 972 |
| 8962 | 973 for (l = imhtml->im_images; l; l = l->next) { |
| 974 int id; | |
| 975 id = GPOINTER_TO_INT(l->data); | |
| 976 if (imhtml->funcs->image_unref) | |
| 977 imhtml->funcs->image_unref(id); | |
| 978 } | |
| 979 | |
| 8681 | 980 if (imhtml->clipboard_text_string) { |
| 981 g_free(imhtml->clipboard_text_string); | |
| 982 g_free(imhtml->clipboard_html_string); | |
| 983 } | |
| 984 | |
| 4895 | 985 g_list_free(imhtml->scalables); |
| 8962 | 986 g_slist_free(imhtml->im_images); |
| 9029 | 987 if (imhtml->protocol_name) |
| 988 g_free(imhtml->protocol_name); | |
| 4032 | 989 G_OBJECT_CLASS(parent_class)->finalize (object); |
| 990 } | |
| 1428 | 991 |
| 3922 | 992 /* Boring GTK stuff */ |
| 8519 | 993 static void gtk_imhtml_class_init (GtkIMHtmlClass *klass) |
| 1428 | 994 { |
| 9007 | 995 GtkWidgetClass *widget_class = (GtkWidgetClass *) klass; |
| 3922 | 996 GtkObjectClass *object_class; |
| 4032 | 997 GObjectClass *gobject_class; |
| 8519 | 998 object_class = (GtkObjectClass*) klass; |
| 999 gobject_class = (GObjectClass*) klass; | |
| 4032 | 1000 parent_class = gtk_type_class(GTK_TYPE_TEXT_VIEW); |
| 4417 | 1001 signals[URL_CLICKED] = g_signal_new("url_clicked", |
| 1002 G_TYPE_FROM_CLASS(gobject_class), | |
| 1003 G_SIGNAL_RUN_FIRST, | |
| 1004 G_STRUCT_OFFSET(GtkIMHtmlClass, url_clicked), | |
| 1005 NULL, | |
| 1006 0, | |
| 1007 g_cclosure_marshal_VOID__POINTER, | |
| 1008 G_TYPE_NONE, 1, | |
| 1009 G_TYPE_POINTER); | |
| 8506 | 1010 signals[BUTTONS_UPDATE] = g_signal_new("format_buttons_update", |
| 8420 | 1011 G_TYPE_FROM_CLASS(gobject_class), |
| 1012 G_SIGNAL_RUN_FIRST, | |
| 1013 G_STRUCT_OFFSET(GtkIMHtmlClass, buttons_update), | |
| 1014 NULL, | |
| 1015 0, | |
| 1016 g_cclosure_marshal_VOID__POINTER, | |
| 1017 G_TYPE_NONE, 1, | |
| 1018 G_TYPE_INT); | |
| 1019 signals[TOGGLE_FORMAT] = g_signal_new("format_function_toggle", | |
| 1020 G_TYPE_FROM_CLASS(gobject_class), | |
| 1021 G_SIGNAL_RUN_FIRST, | |
| 1022 G_STRUCT_OFFSET(GtkIMHtmlClass, toggle_format), | |
| 1023 NULL, | |
| 1024 0, | |
| 1025 g_cclosure_marshal_VOID__POINTER, | |
| 8427 | 1026 G_TYPE_NONE, 1, |
| 8420 | 1027 G_TYPE_INT); |
| 8427 | 1028 signals[CLEAR_FORMAT] = g_signal_new("format_function_clear", |
| 1029 G_TYPE_FROM_CLASS(gobject_class), | |
| 1030 G_SIGNAL_RUN_FIRST, | |
| 1031 G_STRUCT_OFFSET(GtkIMHtmlClass, clear_format), | |
| 1032 NULL, | |
| 1033 0, | |
| 8481 | 1034 g_cclosure_marshal_VOID__VOID, |
| 1035 G_TYPE_NONE, 0); | |
| 8506 | 1036 signals[UPDATE_FORMAT] = g_signal_new("format_function_update", |
| 1037 G_TYPE_FROM_CLASS(gobject_class), | |
| 1038 G_SIGNAL_RUN_FIRST, | |
| 1039 G_STRUCT_OFFSET(GtkIMHtmlClass, update_format), | |
| 1040 NULL, | |
| 1041 0, | |
| 1042 g_cclosure_marshal_VOID__VOID, | |
| 1043 G_TYPE_NONE, 0); | |
| 4032 | 1044 gobject_class->finalize = gtk_imhtml_finalize; |
| 9300 | 1045 widget_class->drag_motion = gtk_text_view_drag_motion; |
| 9007 | 1046 gtk_widget_class_install_style_property(widget_class, g_param_spec_boxed("hyperlink-color", |
| 1047 _("Hyperlink color"), | |
| 1048 _("Color to draw hyperlinks."), | |
| 1049 GDK_TYPE_COLOR, G_PARAM_READABLE)); | |
| 1428 | 1050 } |
| 1051 | |
| 3922 | 1052 static void gtk_imhtml_init (GtkIMHtml *imhtml) |
| 1428 | 1053 { |
| 3922 | 1054 GtkTextIter iter; |
| 1055 imhtml->text_buffer = gtk_text_buffer_new(NULL); | |
| 1056 gtk_text_buffer_get_end_iter (imhtml->text_buffer, &iter); | |
| 8677 | 1057 imhtml->scrollpoint = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, FALSE); |
| 3922 | 1058 gtk_text_view_set_buffer(GTK_TEXT_VIEW(imhtml), imhtml->text_buffer); |
| 5105 | 1059 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(imhtml), GTK_WRAP_WORD_CHAR); |
| 3922 | 1060 gtk_text_view_set_pixels_below_lines(GTK_TEXT_VIEW(imhtml), 5); |
| 8677 | 1061 gtk_text_view_set_left_margin(GTK_TEXT_VIEW(imhtml), 2); |
| 1062 gtk_text_view_set_right_margin(GTK_TEXT_VIEW(imhtml), 2); | |
| 8061 | 1063 /*gtk_text_view_set_indent(GTK_TEXT_VIEW(imhtml), -15);*/ |
| 3922 | 1064 /*gtk_text_view_set_justification(GTK_TEXT_VIEW(imhtml), GTK_JUSTIFY_FILL);*/ |
| 8061 | 1065 |
| 3922 | 1066 /* These tags will be used often and can be reused--we create them on init and then apply them by name |
| 8932 | 1067 * other tags (color, size, face, etc.) will have to be created and applied dynamically |
| 1068 * Note that even though we created STRIKE, SUB, SUP, and PRE tags here, we don't really | |
| 1069 * apply them anywhere yet. */ | |
| 3922 | 1070 gtk_text_buffer_create_tag(imhtml->text_buffer, "BOLD", "weight", PANGO_WEIGHT_BOLD, NULL); |
| 1071 gtk_text_buffer_create_tag(imhtml->text_buffer, "ITALICS", "style", PANGO_STYLE_ITALIC, NULL); | |
| 1072 gtk_text_buffer_create_tag(imhtml->text_buffer, "UNDERLINE", "underline", PANGO_UNDERLINE_SINGLE, NULL); | |
| 1073 gtk_text_buffer_create_tag(imhtml->text_buffer, "STRIKE", "strikethrough", TRUE, NULL); | |
| 1074 gtk_text_buffer_create_tag(imhtml->text_buffer, "SUB", "rise", -5000, NULL); | |
| 1075 gtk_text_buffer_create_tag(imhtml->text_buffer, "SUP", "rise", 5000, NULL); | |
| 1076 gtk_text_buffer_create_tag(imhtml->text_buffer, "PRE", "family", "Monospace", NULL); | |
| 7295 | 1077 gtk_text_buffer_create_tag(imhtml->text_buffer, "search", "background", "#22ff00", "weight", "bold", NULL); |
| 8677 | 1078 |
| 3922 | 1079 /* When hovering over a link, we show the hand cursor--elsewhere we show the plain ol' pointer cursor */ |
| 1080 imhtml->hand_cursor = gdk_cursor_new (GDK_HAND2); | |
| 1081 imhtml->arrow_cursor = gdk_cursor_new (GDK_LEFT_PTR); | |
| 8061 | 1082 imhtml->text_cursor = gdk_cursor_new (GDK_XTERM); |
| 2993 | 1083 |
| 6124 | 1084 imhtml->show_comments = TRUE; |
| 4253 | 1085 |
|
8740
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
1086 imhtml->zoom = 1.0; |
|
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
1087 imhtml->original_fsize = 0; |
|
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
1088 |
| 4892 | 1089 imhtml->smiley_data = g_hash_table_new_full(g_str_hash, g_str_equal, |
| 4902 | 1090 g_free, (GDestroyNotify)gtk_smiley_tree_destroy); |
| 4032 | 1091 imhtml->default_smilies = gtk_smiley_tree_new(); |
| 4735 | 1092 |
| 4944 | 1093 g_signal_connect(G_OBJECT(imhtml), "size-allocate", G_CALLBACK(gtk_size_allocate_cb), NULL); |
| 4735 | 1094 g_signal_connect(G_OBJECT(imhtml), "motion-notify-event", G_CALLBACK(gtk_motion_event_notify), NULL); |
| 4944 | 1095 g_signal_connect(G_OBJECT(imhtml), "leave-notify-event", G_CALLBACK(gtk_leave_event_notify), NULL); |
| 6066 | 1096 g_signal_connect(G_OBJECT(imhtml), "key_press_event", G_CALLBACK(gtk_key_pressed_cb), NULL); |
| 8677 | 1097 g_signal_connect(G_OBJECT(imhtml), "button_press_event", G_CALLBACK(gtk_imhtml_button_press_event), NULL); |
| 1098 g_signal_connect(G_OBJECT(imhtml->text_buffer), "insert-text", G_CALLBACK(preinsert_cb), imhtml); | |
| 8061 | 1099 g_signal_connect_after(G_OBJECT(imhtml->text_buffer), "insert-text", G_CALLBACK(insert_cb), imhtml); |
| 8091 | 1100 gtk_drag_dest_set(GTK_WIDGET(imhtml), 0, |
| 1101 link_drag_drop_targets, sizeof(link_drag_drop_targets) / sizeof(GtkTargetEntry), | |
| 1102 GDK_ACTION_COPY); | |
| 1103 g_signal_connect(G_OBJECT(imhtml), "drag_data_received", G_CALLBACK(gtk_imhtml_link_drag_rcv_cb), imhtml); | |
| 9300 | 1104 g_signal_connect(G_OBJECT(imhtml), "drag_drop", G_CALLBACK(gtk_imhtml_link_drop_cb), imhtml); |
| 8091 | 1105 |
| 7353 | 1106 g_signal_connect(G_OBJECT(imhtml), "copy-clipboard", G_CALLBACK(copy_clipboard_cb), NULL); |
| 8698 | 1107 g_signal_connect(G_OBJECT(imhtml), "cut-clipboard", G_CALLBACK(cut_clipboard_cb), NULL); |
| 8061 | 1108 g_signal_connect(G_OBJECT(imhtml), "paste-clipboard", G_CALLBACK(paste_clipboard_cb), NULL); |
| 8677 | 1109 g_signal_connect_after(G_OBJECT(imhtml), "realize", G_CALLBACK(imhtml_realized_remove_primary), NULL); |
|
8740
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
1110 g_signal_connect(G_OBJECT(imhtml), "unrealize", G_CALLBACK(imhtml_destroy_add_primary), NULL); |
| 8677 | 1111 |
| 1112 g_signal_connect_after(G_OBJECT(GTK_IMHTML(imhtml)->text_buffer), "mark-set", | |
| 1113 G_CALLBACK(mark_set_so_update_selection_cb), imhtml); | |
| 1114 | |
| 4944 | 1115 gtk_widget_add_events(GTK_WIDGET(imhtml), GDK_LEAVE_NOTIFY_MASK); |
| 4735 | 1116 |
| 8681 | 1117 imhtml->clipboard_text_string = NULL; |
| 1118 imhtml->clipboard_html_string = NULL; | |
| 1119 | |
| 4735 | 1120 imhtml->tip = NULL; |
| 1121 imhtml->tip_timer = 0; | |
| 1122 imhtml->tip_window = NULL; | |
| 4895 | 1123 |
| 8677 | 1124 imhtml->edit.bold = FALSE; |
| 1125 imhtml->edit.italic = FALSE; | |
| 1126 imhtml->edit.underline = FALSE; | |
| 8061 | 1127 imhtml->edit.forecolor = NULL; |
| 1128 imhtml->edit.backcolor = NULL; | |
| 1129 imhtml->edit.fontface = NULL; | |
| 8677 | 1130 imhtml->edit.fontsize = 0; |
| 1131 imhtml->edit.link = NULL; | |
| 1132 | |
| 9300 | 1133 |
| 4895 | 1134 imhtml->scalables = NULL; |
| 8061 | 1135 |
| 1136 gtk_imhtml_set_editable(imhtml, FALSE); | |
| 8931 | 1137 g_signal_connect(G_OBJECT(imhtml), "populate-popup", |
| 1138 G_CALLBACK(hijack_menu_cb), NULL); | |
| 1139 | |
| 8692 | 1140 #ifdef _WIN32 |
| 1141 /* Register HTML Format as desired clipboard format */ | |
| 1142 win_html_fmt = RegisterClipboardFormat("HTML Format"); | |
| 1143 #endif | |
| 2993 | 1144 } |
| 1145 | |
| 3922 | 1146 GtkWidget *gtk_imhtml_new(void *a, void *b) |
| 1428 | 1147 { |
| 4635 | 1148 return GTK_WIDGET(g_object_new(gtk_imhtml_get_type(), NULL)); |
| 1428 | 1149 } |
| 1150 | |
| 9037 | 1151 GType gtk_imhtml_get_type() |
| 1428 | 1152 { |
| 9037 | 1153 static GType imhtml_type = 0; |
| 1428 | 1154 |
| 1155 if (!imhtml_type) { | |
| 9037 | 1156 static const GTypeInfo imhtml_info = { |
| 4635 | 1157 sizeof(GtkIMHtmlClass), |
| 1158 NULL, | |
| 1159 NULL, | |
| 1160 (GClassInitFunc) gtk_imhtml_class_init, | |
| 1161 NULL, | |
| 1162 NULL, | |
| 1428 | 1163 sizeof (GtkIMHtml), |
| 4635 | 1164 0, |
| 1165 (GInstanceInitFunc) gtk_imhtml_init | |
| 1428 | 1166 }; |
| 4635 | 1167 |
| 1168 imhtml_type = g_type_register_static(gtk_text_view_get_type(), | |
| 1169 "GtkIMHtml", &imhtml_info, 0); | |
| 1428 | 1170 } |
| 1171 | |
| 1172 return imhtml_type; | |
| 1173 } | |
| 1174 | |
| 4417 | 1175 struct url_data { |
| 1176 GObject *object; | |
| 1177 gchar *url; | |
| 1178 }; | |
| 1179 | |
| 8677 | 1180 static void url_data_destroy(gpointer mydata) |
| 1181 { | |
| 1182 struct url_data *data = mydata; | |
| 1183 g_object_unref(data->object); | |
| 1184 g_free(data->url); | |
| 1185 g_free(data); | |
| 1186 } | |
| 1187 | |
| 4417 | 1188 static void url_open(GtkWidget *w, struct url_data *data) { |
| 1189 if(!data) return; | |
| 8061 | 1190 g_signal_emit(data->object, signals[URL_CLICKED], 0, data->url); |
| 7988 | 1191 |
| 4417 | 1192 } |
| 5582 | 1193 |
| 4417 | 1194 static void url_copy(GtkWidget *w, gchar *url) { |
| 1195 GtkClipboard *clipboard; | |
| 1196 | |
| 8931 | 1197 clipboard = gtk_widget_get_clipboard(w, GDK_SELECTION_PRIMARY); |
| 4417 | 1198 gtk_clipboard_set_text(clipboard, url, -1); |
| 5582 | 1199 |
| 8931 | 1200 clipboard = gtk_widget_get_clipboard(w, GDK_SELECTION_CLIPBOARD); |
| 5582 | 1201 gtk_clipboard_set_text(clipboard, url, -1); |
| 4417 | 1202 } |
| 1203 | |
| 1204 /* The callback for an event on a link tag. */ | |
| 8677 | 1205 gboolean tag_event(GtkTextTag *tag, GObject *imhtml, GdkEvent *event, GtkTextIter *arg2, gpointer unused) { |
| 4417 | 1206 GdkEventButton *event_button = (GdkEventButton *) event; |
| 8061 | 1207 if (GTK_IMHTML(imhtml)->editable) |
| 1208 return FALSE; | |
| 3922 | 1209 if (event->type == GDK_BUTTON_RELEASE) { |
| 8957 | 1210 if ((event_button->button == 1) || (event_button->button == 2)) { |
| 4417 | 1211 GtkTextIter start, end; |
| 1212 /* we shouldn't open a URL if the user has selected something: */ | |
| 8677 | 1213 if (gtk_text_buffer_get_selection_bounds( |
| 1214 gtk_text_iter_get_buffer(arg2), &start, &end)) | |
| 4417 | 1215 return FALSE; |
| 1216 | |
| 1217 /* A link was clicked--we emit the "url_clicked" signal | |
| 1218 * with the URL as the argument */ | |
| 8677 | 1219 g_object_ref(G_OBJECT(tag)); |
| 1220 g_signal_emit(imhtml, signals[URL_CLICKED], 0, g_object_get_data(G_OBJECT(tag), "link_url")); | |
| 1221 g_object_unref(G_OBJECT(tag)); | |
| 4417 | 1222 return FALSE; |
| 1223 } else if(event_button->button == 3) { | |
| 4745 | 1224 GtkWidget *img, *item, *menu; |
| 4417 | 1225 struct url_data *tempdata = g_new(struct url_data, 1); |
| 5091 | 1226 tempdata->object = g_object_ref(imhtml); |
| 8677 | 1227 tempdata->url = g_strdup(g_object_get_data(G_OBJECT(tag), "link_url")); |
| 4745 | 1228 |
| 5091 | 1229 /* Don't want the tooltip around if user right-clicked on link */ |
| 1230 if (GTK_IMHTML(imhtml)->tip_window) { | |
| 1231 gtk_widget_destroy(GTK_IMHTML(imhtml)->tip_window); | |
| 1232 GTK_IMHTML(imhtml)->tip_window = NULL; | |
| 1233 } | |
| 1234 if (GTK_IMHTML(imhtml)->tip_timer) { | |
| 1235 g_source_remove(GTK_IMHTML(imhtml)->tip_timer); | |
| 1236 GTK_IMHTML(imhtml)->tip_timer = 0; | |
| 1237 } | |
| 8061 | 1238 if (GTK_IMHTML(imhtml)->editable) |
| 1239 gdk_window_set_cursor(event_button->window, GTK_IMHTML(imhtml)->text_cursor); | |
| 1240 else | |
| 1241 gdk_window_set_cursor(event_button->window, GTK_IMHTML(imhtml)->arrow_cursor); | |
| 4417 | 1242 menu = gtk_menu_new(); |
| 8677 | 1243 g_object_set_data_full(G_OBJECT(menu), "x-imhtml-url-data", tempdata, url_data_destroy); |
| 4745 | 1244 |
| 4417 | 1245 /* buttons and such */ |
| 1246 | |
| 8677 | 1247 if (!strncmp(tempdata->url, "mailto:", 7)) |
|
7140
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1248 { |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1249 /* Copy E-Mail Address */ |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1250 img = gtk_image_new_from_stock(GTK_STOCK_COPY, |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1251 GTK_ICON_SIZE_MENU); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1252 item = gtk_image_menu_item_new_with_mnemonic( |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1253 _("_Copy E-Mail Address")); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1254 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), img); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1255 g_signal_connect(G_OBJECT(item), "activate", |
| 8677 | 1256 G_CALLBACK(url_copy), tempdata->url + 7); |
|
7140
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1257 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1258 } |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1259 else |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1260 { |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1261 /* Copy Link Location */ |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1262 img = gtk_image_new_from_stock(GTK_STOCK_COPY, |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1263 GTK_ICON_SIZE_MENU); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1264 item = gtk_image_menu_item_new_with_mnemonic( |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1265 _("_Copy Link Location")); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1266 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), img); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1267 g_signal_connect(G_OBJECT(item), "activate", |
| 8677 | 1268 G_CALLBACK(url_copy), tempdata->url); |
|
7140
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1269 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1270 |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1271 /* Open Link in Browser */ |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1272 img = gtk_image_new_from_stock(GTK_STOCK_JUMP_TO, |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1273 GTK_ICON_SIZE_MENU); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1274 item = gtk_image_menu_item_new_with_mnemonic( |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1275 _("_Open Link in Browser")); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1276 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), img); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1277 g_signal_connect(G_OBJECT(item), "activate", |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1278 G_CALLBACK(url_open), tempdata); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1279 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1280 } |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
1281 |
| 4756 | 1282 |
| 4417 | 1283 gtk_widget_show_all(menu); |
| 4756 | 1284 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, |
| 1285 event_button->button, event_button->time); | |
| 4745 | 1286 |
| 4417 | 1287 return TRUE; |
| 1288 } | |
| 1428 | 1289 } |
| 4417 | 1290 if(event->type == GDK_BUTTON_PRESS && event_button->button == 3) |
| 1291 return TRUE; /* Clicking the right mouse button on a link shouldn't | |
| 1292 be caught by the regular GtkTextView menu */ | |
| 1293 else | |
| 1294 return FALSE; /* Let clicks go through if we didn't catch anything */ | |
| 1428 | 1295 } |
| 1296 | |
| 9300 | 1297 static gboolean |
| 1298 gtk_text_view_drag_motion (GtkWidget *widget, | |
| 1299 GdkDragContext *context, | |
| 1300 gint x, | |
| 1301 gint y, | |
| 1302 guint time) | |
| 1303 { | |
| 1304 GdkDragAction suggested_action = 0; | |
| 1305 | |
| 1306 if (gtk_drag_dest_find_target (widget, context, | |
| 1307 gtk_drag_dest_get_target_list (widget)) == GDK_NONE) { | |
| 1308 /* can't accept any of the offered targets */ | |
| 1309 } else { | |
| 1310 GtkWidget *source_widget; | |
| 1311 suggested_action = context->suggested_action; | |
| 1312 source_widget = gtk_drag_get_source_widget (context); | |
| 1313 if (source_widget == widget) { | |
| 1314 /* Default to MOVE, unless the user has | |
| 1315 * pressed ctrl or alt to affect available actions | |
| 1316 */ | |
| 1317 if ((context->actions & GDK_ACTION_MOVE) != 0) | |
| 1318 suggested_action = GDK_ACTION_MOVE; | |
| 1319 } | |
| 1320 } | |
| 1321 | |
| 1322 if (suggested_action != 0) { | |
| 1323 gdk_drag_status (context, suggested_action, time); | |
| 1324 } else { | |
| 1325 gdk_drag_status (context, 0, time); | |
| 1326 } | |
| 1327 | |
| 1328 /* TRUE return means don't propagate the drag motion to parent | |
| 1329 * widgets that may also be drop sites. | |
| 1330 */ | |
| 1331 return TRUE; | |
| 1332 } | |
| 1333 | |
| 1334 static void | |
| 1335 gtk_imhtml_link_drop_cb(GtkWidget *widget, GdkDragContext *context, gint x, gint y, guint time, gpointer user_data) | |
| 1336 { | |
| 1337 GdkAtom target = gtk_drag_dest_find_target (widget, context, NULL); | |
| 1338 | |
| 1339 if (target != GDK_NONE) | |
| 1340 gtk_drag_get_data (widget, context, target, time); | |
| 1341 else | |
| 1342 gtk_drag_finish (context, FALSE, FALSE, time); | |
| 1343 | |
| 1344 return; | |
| 1345 } | |
| 1346 | |
| 8091 | 1347 static void |
| 1348 gtk_imhtml_link_drag_rcv_cb(GtkWidget *widget, GdkDragContext *dc, guint x, guint y, | |
| 1349 GtkSelectionData *sd, guint info, guint t, GtkIMHtml *imhtml) | |
| 1350 { | |
| 9300 | 1351 gchar **links; |
| 1352 gchar *link; | |
| 1353 char *text = sd->data; | |
| 1354 GtkTextMark *mark = gtk_text_buffer_get_insert(imhtml->text_buffer); | |
| 1355 GtkTextIter iter; | |
| 1356 | |
| 1357 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, mark); | |
| 1358 | |
| 1359 | |
| 8091 | 1360 if(gtk_imhtml_get_editable(imhtml) && sd->data){ |
| 9300 | 1361 switch (info) { |
| 1362 case DRAG_URL: | |
| 1363 gaim_str_strip_cr(sd->data); | |
| 1364 | |
| 1365 links = g_strsplit(sd->data, "\n", 0); | |
| 1366 while((link = *links++) != NULL){ | |
| 1367 if(gaim_str_has_prefix(link, "http://") || | |
| 1368 gaim_str_has_prefix(link, "https://") || | |
| 1369 gaim_str_has_prefix(link, "ftp://")){ | |
| 1370 gtk_imhtml_insert_link(imhtml, mark, link, link); | |
| 1371 } else if (link=='\0') { | |
| 1372 /* Ignore blank lines */ | |
| 1373 } else { | |
| 1374 /* Special reasons, aka images being put in via other tag, etc. */ | |
| 1375 } | |
| 8091 | 1376 } |
| 9300 | 1377 break; |
| 1378 case DRAG_HTML: | |
| 1379 if (sd->length >= 2 && | |
| 1380 (*(guint16 *)text == 0xfeff || *(guint16 *)text == 0xfffe)) { | |
| 1381 /* This is UCS-2 */ | |
| 1382 char *tmp; | |
| 1383 char *utf8 = g_convert(text, sd->length, "UTF-8", "UCS-2", NULL, NULL, NULL); | |
| 1384 g_free(text); | |
| 1385 text = utf8; | |
| 1386 if (!text) { | |
| 1387 gaim_debug_warning("gtkimhtml", "g_convert from UCS-2 failed in drag_rcv_cb\n"); | |
| 1388 return; | |
| 1389 } | |
| 1390 tmp = g_utf8_next_char(text); | |
| 1391 memmove(text, tmp, strlen(tmp) + 1); | |
| 1392 } | |
| 1393 | |
| 1394 if (!(*text) || !g_utf8_validate(text, -1, NULL)) { | |
| 1395 gaim_debug_warning("gtkimhtml", "empty string or invalid UTF-8 in drag_rcv_cb\n"); | |
| 1396 g_free(text); | |
| 1397 return; | |
| 1398 } | |
| 1399 gtk_imhtml_insert_html_at_iter(imhtml, text, 0, &iter); | |
| 1400 break; | |
| 1401 default: | |
| 1402 break; | |
| 8091 | 1403 } |
| 9300 | 1404 |
| 1405 | |
| 8091 | 1406 gtk_drag_finish(dc, TRUE, (dc->action == GDK_ACTION_MOVE), t); |
| 1407 } else { | |
| 1408 gtk_drag_finish(dc, FALSE, FALSE, t); | |
| 1409 } | |
| 1410 } | |
| 1411 | |
| 4298 | 1412 /* this isn't used yet |
| 9300 | 1413 static void gtk_smiley_tree_remove (GtkSmileyTree *tree, |
| 4263 | 1414 GtkIMHtmlSmiley *smiley) |
| 4032 | 1415 { |
| 1416 GtkSmileyTree *t = tree; | |
| 4263 | 1417 const gchar *x = smiley->smile; |
| 4032 | 1418 gint len = 0; |
| 1419 | |
| 1420 while (*x) { | |
| 1421 gchar *pos; | |
| 1422 | |
| 1423 if (!t->values) | |
| 1424 return; | |
| 1425 | |
| 1426 pos = strchr (t->values->str, *x); | |
| 1427 if (pos) | |
| 1428 t = t->children [(int) pos - (int) t->values->str]; | |
| 1429 else | |
| 1430 return; | |
| 1431 | |
| 1432 x++; len++; | |
| 1433 } | |
| 1434 | |
|
4141
ccec4fde84f4
[gaim-migrate @ 4359]
Christian Hammond <chipx86@chipx86.com>
parents:
4140
diff
changeset
|
1435 if (t->image) { |
| 4032 | 1436 t->image = NULL; |
|
4141
ccec4fde84f4
[gaim-migrate @ 4359]
Christian Hammond <chipx86@chipx86.com>
parents:
4140
diff
changeset
|
1437 } |
| 4032 | 1438 } |
| 4298 | 1439 */ |
| 1440 | |
| 4032 | 1441 |
| 1442 static gint | |
| 1443 gtk_smiley_tree_lookup (GtkSmileyTree *tree, | |
| 1444 const gchar *text) | |
| 1445 { | |
| 1446 GtkSmileyTree *t = tree; | |
| 1447 const gchar *x = text; | |
| 1448 gint len = 0; | |
| 8505 | 1449 gchar *amp; |
| 1450 gint alen; | |
| 4032 | 1451 |
| 1452 while (*x) { | |
| 1453 gchar *pos; | |
| 1454 | |
| 1455 if (!t->values) | |
| 1456 break; | |
| 1457 | |
| 8505 | 1458 if(*x == '&' && gtk_imhtml_is_amp_escape(x, &, &alen)) { |
| 1459 len += alen - strlen(amp); | |
| 1460 x += alen - strlen(amp); | |
| 1461 pos = strchr (t->values->str, *amp); | |
| 1462 } | |
| 9636 | 1463 else if (*x == '<') /* Because we're all WYSIWYG now, a '<' |
| 1464 * char should only appear as the start of a tag. Perhaps a safer (but costlier) | |
| 1465 * check would be to call gtk_imhtml_is_tag on it */ | |
| 1466 return 0; | |
| 8505 | 1467 else |
| 1468 pos = strchr (t->values->str, *x); | |
| 1469 | |
| 4032 | 1470 if (pos) |
| 7371 | 1471 t = t->children [GPOINTER_TO_INT(pos) - GPOINTER_TO_INT(t->values->str)]; |
| 4032 | 1472 else |
| 1473 break; | |
| 1474 | |
| 1475 x++; len++; | |
| 1476 } | |
| 1477 | |
| 1478 if (t->image) | |
| 1479 return len; | |
| 1480 | |
| 1481 return 0; | |
| 1482 } | |
| 1483 | |
| 1484 void | |
| 4263 | 1485 gtk_imhtml_associate_smiley (GtkIMHtml *imhtml, |
| 1486 gchar *sml, | |
| 1487 GtkIMHtmlSmiley *smiley) | |
| 4032 | 1488 { |
| 1489 GtkSmileyTree *tree; | |
| 1490 g_return_if_fail (imhtml != NULL); | |
| 1491 g_return_if_fail (GTK_IS_IMHTML (imhtml)); | |
| 7371 | 1492 |
| 4032 | 1493 if (sml == NULL) |
| 1494 tree = imhtml->default_smilies; | |
| 1495 else if ((tree = g_hash_table_lookup(imhtml->smiley_data, sml))) { | |
| 1496 } else { | |
| 1497 tree = gtk_smiley_tree_new(); | |
| 4892 | 1498 g_hash_table_insert(imhtml->smiley_data, g_strdup(sml), tree); |
| 4032 | 1499 } |
| 1500 | |
| 4263 | 1501 gtk_smiley_tree_insert (tree, smiley); |
| 4032 | 1502 } |
| 1503 | |
| 1504 static gboolean | |
| 1505 gtk_imhtml_is_smiley (GtkIMHtml *imhtml, | |
| 1506 GSList *fonts, | |
| 1507 const gchar *text, | |
| 1508 gint *len) | |
| 1509 { | |
| 1510 GtkSmileyTree *tree; | |
| 5967 | 1511 GtkIMHtmlFontDetail *font; |
| 4032 | 1512 char *sml = NULL; |
| 1513 | |
| 1514 if (fonts) { | |
| 1515 font = fonts->data; | |
| 1516 sml = font->sml; | |
| 1517 } | |
| 1518 | |
| 9029 | 1519 if (!sml) |
| 1520 sml = imhtml->protocol_name; | |
| 1521 | |
| 1522 if (!sml || !(tree = g_hash_table_lookup(imhtml->smiley_data, sml))) | |
| 4032 | 1523 tree = imhtml->default_smilies; |
| 9029 | 1524 |
| 4032 | 1525 if (tree == NULL) |
| 1526 return FALSE; | |
| 7371 | 1527 |
| 8505 | 1528 *len = gtk_smiley_tree_lookup (tree, text); |
| 4032 | 1529 return (*len > 0); |
| 1530 } | |
| 1531 | |
|
6814
782907a6ae65
[gaim-migrate @ 7354]
Christian Hammond <chipx86@chipx86.com>
parents:
6648
diff
changeset
|
1532 GdkPixbufAnimation * |
| 4032 | 1533 gtk_smiley_tree_image (GtkIMHtml *imhtml, |
| 1534 const gchar *sml, | |
| 1535 const gchar *text) | |
| 1536 { | |
| 1537 GtkSmileyTree *t; | |
| 1538 const gchar *x = text; | |
| 1539 if (sml == NULL) | |
| 1540 t = imhtml->default_smilies; | |
| 7371 | 1541 else |
| 4032 | 1542 t = g_hash_table_lookup(imhtml->smiley_data, sml); |
| 7371 | 1543 |
| 4032 | 1544 |
| 1545 if (t == NULL) | |
| 1546 return sml ? gtk_smiley_tree_image(imhtml, NULL, text) : NULL; | |
| 1547 | |
| 1548 while (*x) { | |
| 1549 gchar *pos; | |
| 1550 | |
| 1551 if (!t->values) { | |
| 1552 return sml ? gtk_smiley_tree_image(imhtml, NULL, text) : NULL; | |
| 1553 } | |
| 7371 | 1554 |
| 4032 | 1555 pos = strchr (t->values->str, *x); |
| 1556 if (pos) { | |
| 7371 | 1557 t = t->children [GPOINTER_TO_INT(pos) - GPOINTER_TO_INT(t->values->str)]; |
| 4032 | 1558 } else { |
| 1559 return sml ? gtk_smiley_tree_image(imhtml, NULL, text) : NULL; | |
| 1560 } | |
| 1561 x++; | |
| 1562 } | |
| 1563 | |
| 8890 | 1564 if (!t->image->file) |
| 1565 return NULL; | |
| 1566 | |
| 4263 | 1567 if (!t->image->icon) |
|
6814
782907a6ae65
[gaim-migrate @ 7354]
Christian Hammond <chipx86@chipx86.com>
parents:
6648
diff
changeset
|
1568 t->image->icon = gdk_pixbuf_animation_new_from_file(t->image->file, NULL); |
| 4263 | 1569 |
| 1570 return t->image->icon; | |
| 4032 | 1571 } |
| 8890 | 1572 |
| 4793 | 1573 #define VALID_TAG(x) if (!g_ascii_strncasecmp (string, x ">", strlen (x ">"))) { \ |
| 3922 | 1574 *tag = g_strndup (string, strlen (x)); \ |
| 1575 *len = strlen (x) + 1; \ | |
| 1576 return TRUE; \ | |
| 1577 } \ | |
| 1578 (*type)++ | |
| 1428 | 1579 |
| 4793 | 1580 #define VALID_OPT_TAG(x) if (!g_ascii_strncasecmp (string, x " ", strlen (x " "))) { \ |
| 3922 | 1581 const gchar *c = string + strlen (x " "); \ |
| 1582 gchar e = '"'; \ | |
| 1583 gboolean quote = FALSE; \ | |
| 1584 while (*c) { \ | |
| 1585 if (*c == '"' || *c == '\'') { \ | |
| 1586 if (quote && (*c == e)) \ | |
| 1587 quote = !quote; \ | |
| 1588 else if (!quote) { \ | |
| 1589 quote = !quote; \ | |
| 1590 e = *c; \ | |
| 1591 } \ | |
| 1592 } else if (!quote && (*c == '>')) \ | |
| 1593 break; \ | |
| 1594 c++; \ | |
| 1595 } \ | |
| 1596 if (*c) { \ | |
| 1597 *tag = g_strndup (string, c - string); \ | |
| 1598 *len = c - string + 1; \ | |
| 1599 return TRUE; \ | |
| 1600 } \ | |
| 1601 } \ | |
| 1602 (*type)++ | |
| 1428 | 1603 |
| 1604 | |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1605 static gboolean |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1606 gtk_imhtml_is_amp_escape (const gchar *string, |
| 7280 | 1607 gchar **replace, |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1608 gint *length) |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1609 { |
| 7287 | 1610 static char buf[7]; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1611 g_return_val_if_fail (string != NULL, FALSE); |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1612 g_return_val_if_fail (replace != NULL, FALSE); |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1613 g_return_val_if_fail (length != NULL, FALSE); |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1614 |
| 4793 | 1615 if (!g_ascii_strncasecmp (string, "&", 5)) { |
| 7280 | 1616 *replace = "&"; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1617 *length = 5; |
| 4793 | 1618 } else if (!g_ascii_strncasecmp (string, "<", 4)) { |
| 7280 | 1619 *replace = "<"; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1620 *length = 4; |
| 4793 | 1621 } else if (!g_ascii_strncasecmp (string, ">", 4)) { |
| 7280 | 1622 *replace = ">"; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1623 *length = 4; |
| 4793 | 1624 } else if (!g_ascii_strncasecmp (string, " ", 6)) { |
| 7280 | 1625 *replace = " "; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1626 *length = 6; |
| 4793 | 1627 } else if (!g_ascii_strncasecmp (string, "©", 6)) { |
| 7280 | 1628 *replace = "©"; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1629 *length = 6; |
| 4793 | 1630 } else if (!g_ascii_strncasecmp (string, """, 6)) { |
| 7280 | 1631 *replace = "\""; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1632 *length = 6; |
| 4793 | 1633 } else if (!g_ascii_strncasecmp (string, "®", 5)) { |
| 7280 | 1634 *replace = "®"; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1635 *length = 5; |
| 5093 | 1636 } else if (!g_ascii_strncasecmp (string, "'", 6)) { |
| 7280 | 1637 *replace = "\'"; |
| 5093 | 1638 *length = 6; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1639 } else if (*(string + 1) == '#') { |
|
2022
199ba82faacb
[gaim-migrate @ 2032]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2002
diff
changeset
|
1640 guint pound = 0; |
| 3004 | 1641 if ((sscanf (string, "&#%u;", £) == 1) && pound != 0) { |
| 7287 | 1642 int buflen; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1643 if (*(string + 3 + (gint)log10 (pound)) != ';') |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1644 return FALSE; |
| 7287 | 1645 buflen = g_unichar_to_utf8((gunichar)pound, buf); |
| 1646 buf[buflen] = '\0'; | |
| 7280 | 1647 *replace = buf; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1648 *length = 2; |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1649 while (isdigit ((gint) string [*length])) (*length)++; |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1650 if (string [*length] == ';') (*length)++; |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1651 } else { |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1652 return FALSE; |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1653 } |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1654 } else { |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1655 return FALSE; |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1656 } |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1657 |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1658 return TRUE; |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1659 } |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1660 |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1661 static gboolean |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1662 gtk_imhtml_is_tag (const gchar *string, |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1663 gchar **tag, |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1664 gint *len, |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1665 gint *type) |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1666 { |
| 8061 | 1667 char *close; |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1668 *type = 1; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1669 |
| 8118 | 1670 |
| 8061 | 1671 if (!(close = strchr (string, '>'))) |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1672 return FALSE; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1673 |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1674 VALID_TAG ("B"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1675 VALID_TAG ("BOLD"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1676 VALID_TAG ("/B"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1677 VALID_TAG ("/BOLD"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1678 VALID_TAG ("I"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1679 VALID_TAG ("ITALIC"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1680 VALID_TAG ("/I"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1681 VALID_TAG ("/ITALIC"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1682 VALID_TAG ("U"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1683 VALID_TAG ("UNDERLINE"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1684 VALID_TAG ("/U"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1685 VALID_TAG ("/UNDERLINE"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1686 VALID_TAG ("S"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1687 VALID_TAG ("STRIKE"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1688 VALID_TAG ("/S"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1689 VALID_TAG ("/STRIKE"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1690 VALID_TAG ("SUB"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1691 VALID_TAG ("/SUB"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1692 VALID_TAG ("SUP"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1693 VALID_TAG ("/SUP"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1694 VALID_TAG ("PRE"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1695 VALID_TAG ("/PRE"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1696 VALID_TAG ("TITLE"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1697 VALID_TAG ("/TITLE"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1698 VALID_TAG ("BR"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1699 VALID_TAG ("HR"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1700 VALID_TAG ("/FONT"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1701 VALID_TAG ("/A"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1702 VALID_TAG ("P"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1703 VALID_TAG ("/P"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1704 VALID_TAG ("H3"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1705 VALID_TAG ("/H3"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1706 VALID_TAG ("HTML"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1707 VALID_TAG ("/HTML"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1708 VALID_TAG ("BODY"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1709 VALID_TAG ("/BODY"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1710 VALID_TAG ("FONT"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1711 VALID_TAG ("HEAD"); |
| 2993 | 1712 VALID_TAG ("/HEAD"); |
| 1713 VALID_TAG ("BINARY"); | |
| 1714 VALID_TAG ("/BINARY"); | |
| 5093 | 1715 |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1716 VALID_OPT_TAG ("HR"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1717 VALID_OPT_TAG ("FONT"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1718 VALID_OPT_TAG ("BODY"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1719 VALID_OPT_TAG ("A"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1720 VALID_OPT_TAG ("IMG"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1721 VALID_OPT_TAG ("P"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1722 VALID_OPT_TAG ("H3"); |
| 5093 | 1723 VALID_OPT_TAG ("HTML"); |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1724 |
| 5101 | 1725 VALID_TAG ("CITE"); |
| 1726 VALID_TAG ("/CITE"); | |
| 1727 VALID_TAG ("EM"); | |
| 1728 VALID_TAG ("/EM"); | |
| 1729 VALID_TAG ("STRONG"); | |
| 1730 VALID_TAG ("/STRONG"); | |
| 1731 | |
| 5104 | 1732 VALID_OPT_TAG ("SPAN"); |
| 1733 VALID_TAG ("/SPAN"); | |
| 5174 | 1734 VALID_TAG ("BR/"); /* hack until gtkimhtml handles things better */ |
| 6982 | 1735 VALID_TAG ("IMG"); |
| 8026 | 1736 VALID_TAG("SPAN"); |
| 8061 | 1737 VALID_OPT_TAG("BR"); |
| 7988 | 1738 |
| 4793 | 1739 if (!g_ascii_strncasecmp(string, "!--", strlen ("!--"))) { |
|
2954
f6c4f2187c08
[gaim-migrate @ 2967]
Christian Hammond <chipx86@chipx86.com>
parents:
2898
diff
changeset
|
1740 gchar *e = strstr (string + strlen("!--"), "-->"); |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1741 if (e) { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1742 *len = e - string + strlen ("-->"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1743 *tag = g_strndup (string + strlen ("!--"), *len - strlen ("!---->")); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1744 return TRUE; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1745 } |
| 8118 | 1746 } |
| 1747 | |
| 8061 | 1748 *type = -1; |
| 1749 *len = close - string + 1; | |
| 1750 *tag = g_strndup(string, *len - 1); | |
| 1751 return TRUE; | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1752 } |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1753 |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1754 static gchar* |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1755 gtk_imhtml_get_html_opt (gchar *tag, |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1756 const gchar *opt) |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1757 { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1758 gchar *t = tag; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1759 gchar *e, *a; |
| 5177 | 1760 gchar *val; |
| 1761 gint len; | |
| 7280 | 1762 gchar *c; |
| 5177 | 1763 GString *ret; |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1764 |
| 4793 | 1765 while (g_ascii_strncasecmp (t, opt, strlen (opt))) { |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1766 gboolean quote = FALSE; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1767 if (*t == '\0') break; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1768 while (*t && !((*t == ' ') && !quote)) { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1769 if (*t == '\"') |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1770 quote = ! quote; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1771 t++; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1772 } |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1773 while (*t && (*t == ' ')) t++; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1774 } |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1775 |
| 4793 | 1776 if (!g_ascii_strncasecmp (t, opt, strlen (opt))) { |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1777 t += strlen (opt); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1778 } else { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1779 return NULL; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1780 } |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1781 |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1782 if ((*t == '\"') || (*t == '\'')) { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1783 e = a = ++t; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1784 while (*e && (*e != *(t - 1))) e++; |
| 2993 | 1785 if (*e == '\0') { |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1786 return NULL; |
| 5177 | 1787 } else |
| 1788 val = g_strndup(a, e - a); | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1789 } else { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1790 e = a = t; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1791 while (*e && !isspace ((gint) *e)) e++; |
| 5177 | 1792 val = g_strndup(a, e - a); |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1793 } |
| 5177 | 1794 |
| 1795 ret = g_string_new(""); | |
| 1796 e = val; | |
| 1797 while(*e) { | |
| 1798 if(gtk_imhtml_is_amp_escape(e, &c, &len)) { | |
| 7280 | 1799 ret = g_string_append(ret, c); |
| 5177 | 1800 e += len; |
| 1801 } else { | |
| 1802 ret = g_string_append_c(ret, *e); | |
| 1803 e++; | |
| 1804 } | |
| 1805 } | |
| 1806 | |
| 1807 g_free(val); | |
| 8568 | 1808 |
| 1809 return g_string_free(ret, FALSE); | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1810 } |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1811 |
| 8118 | 1812 /* Inline CSS Support - Douglas Thrift */ |
| 1813 static gchar* | |
| 1814 gtk_imhtml_get_css_opt (gchar *style, | |
| 1815 const gchar *opt) | |
| 1816 { | |
| 1817 gchar *t = style; | |
| 1818 gchar *e, *a; | |
| 1819 gchar *val; | |
| 1820 gint len; | |
| 1821 gchar *c; | |
| 1822 GString *ret; | |
| 1823 | |
| 1824 while (g_ascii_strncasecmp (t, opt, strlen (opt))) { | |
| 8177 | 1825 /* gboolean quote = FALSE; */ |
| 8118 | 1826 if (*t == '\0') break; |
| 1827 while (*t && !((*t == ' ') /*&& !quote*/)) { | |
| 1828 /* if (*t == '\"') | |
| 8177 | 1829 quote = ! quote; */ |
| 8118 | 1830 t++; |
| 1831 } | |
| 1832 while (*t && (*t == ' ')) t++; | |
| 1833 } | |
| 1834 | |
| 1835 if (!g_ascii_strncasecmp (t, opt, strlen (opt))) { | |
| 1836 t += strlen (opt); | |
| 1837 } else { | |
| 1838 return NULL; | |
| 1839 } | |
| 1840 | |
| 1841 /* if ((*t == '\"') || (*t == '\'')) { | |
| 1842 e = a = ++t; | |
| 1843 while (*e && (*e != *(t - 1))) e++; | |
| 1844 if (*e == '\0') { | |
| 1845 return NULL; | |
| 1846 } else | |
| 1847 val = g_strndup(a, e - a); | |
| 1848 } else { | |
| 1849 e = a = t; | |
| 1850 while (*e && !isspace ((gint) *e)) e++; | |
| 1851 val = g_strndup(a, e - a); | |
| 1852 }*/ | |
| 1853 | |
| 1854 e = a = t; | |
| 1855 while (*e && *e != ';') e++; | |
| 1856 val = g_strndup(a, e - a); | |
| 1857 | |
| 1858 ret = g_string_new(""); | |
| 1859 e = val; | |
| 1860 while(*e) { | |
| 1861 if(gtk_imhtml_is_amp_escape(e, &c, &len)) { | |
| 1862 ret = g_string_append(ret, c); | |
| 1863 e += len; | |
| 1864 } else { | |
| 1865 ret = g_string_append_c(ret, *e); | |
| 1866 e++; | |
| 1867 } | |
| 1868 } | |
| 1869 | |
| 1870 g_free(val); | |
| 1871 val = ret->str; | |
| 1872 g_string_free(ret, FALSE); | |
| 1873 return val; | |
| 1874 } | |
| 3922 | 1875 |
| 8334 | 1876 static const char *accepted_protocols[] = { |
| 1877 "http://", | |
| 1878 "https://", | |
| 1879 "ftp://" | |
| 1880 }; | |
| 1881 | |
| 1882 static const int accepted_protocols_size = 3; | |
| 1883 | |
| 1884 /* returns if the beginning of the text is a protocol. If it is the protocol, returns the length so | |
| 1885 the caller knows how long the protocol string is. */ | |
| 1886 int gtk_imhtml_is_protocol(const char *text) | |
| 1887 { | |
| 1888 gint i; | |
| 1889 | |
| 1890 for(i=0; i<accepted_protocols_size; i++){ | |
| 1891 if( strncasecmp(text, accepted_protocols[i], strlen(accepted_protocols[i])) == 0 ){ | |
| 1892 return strlen(accepted_protocols[i]); | |
| 1893 } | |
| 1894 } | |
| 1895 return 0; | |
| 1896 } | |
| 1897 | |
| 8677 | 1898 /* |
| 1899 <KingAnt> marv: The two IM image functions in oscar are gaim_odc_send_im and gaim_odc_incoming | |
| 1900 | |
| 1901 | |
| 1902 [19:58] <Robot101> marv: images go into the imgstore, a refcounted... well.. hash. :) | |
| 1903 [19:59] <KingAnt> marv: I think the image tag used by the core is something like <img id="#"/> | |
| 1904 [19:59] Ro0tSiEgE robert42 RobFlynn Robot101 ross22 roz | |
| 1905 [20:00] <KingAnt> marv: Where the ID is the what is returned when you add the image to the imgstore using gaim_imgstore_add | |
| 1906 [20:00] <marv> Robot101: so how does the image get passed to serv_got_im() and serv_send_im()? just as the <img id="#" and then the prpl looks it up from the store? | |
| 1907 [20:00] <KingAnt> marv: Right | |
| 1908 [20:00] <marv> alright | |
| 1909 | |
| 1910 Here's my plan with IMImages. make gtk_imhtml_[append|insert]_text_with_images instead just | |
| 1911 gtkimhtml_[append|insert]_text (hrm maybe it should be called html instead of text), add a | |
| 1912 function for gaim to register for look up images, i.e. gtk_imhtml_set_get_img_fnc, so that | |
| 1913 images can be looked up like that, instead of passing a GSList of them. | |
| 1914 */ | |
| 1915 | |
| 1916 void gtk_imhtml_append_text_with_images (GtkIMHtml *imhtml, | |
| 1917 const gchar *text, | |
| 1918 GtkIMHtmlOptions options, | |
| 1919 GSList *unused) | |
| 1428 | 1920 { |
| 8677 | 1921 GtkTextIter iter, ins, sel; |
| 1922 GdkRectangle rect; | |
| 1923 int y, height, ins_offset = 0, sel_offset = 0; | |
| 1924 gboolean fixins = FALSE, fixsel = FALSE; | |
| 1925 | |
| 1926 g_return_if_fail (imhtml != NULL); | |
| 1927 g_return_if_fail (GTK_IS_IMHTML (imhtml)); | |
| 1928 g_return_if_fail (text != NULL); | |
| 1929 | |
| 1930 | |
| 1931 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &iter); | |
| 1932 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &ins, gtk_text_buffer_get_insert(imhtml->text_buffer)); | |
| 1933 if (gtk_text_iter_equal(&iter, &ins) && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, NULL, NULL)) { | |
| 1934 fixins = TRUE; | |
| 1935 ins_offset = gtk_text_iter_get_offset(&ins); | |
| 1936 } | |
| 1937 | |
| 1938 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &sel, gtk_text_buffer_get_selection_bound(imhtml->text_buffer)); | |
| 1939 if (gtk_text_iter_equal(&iter, &sel) && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, NULL, NULL)) { | |
| 1940 fixsel = TRUE; | |
| 1941 sel_offset = gtk_text_iter_get_offset(&sel); | |
| 1942 } | |
| 1943 | |
| 1944 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); | |
| 1945 gtk_text_view_get_line_yrange(GTK_TEXT_VIEW(imhtml), &iter, &y, &height); | |
| 1946 | |
| 1947 | |
| 1948 if(((y + height) - (rect.y + rect.height)) > height | |
| 1949 && gtk_text_buffer_get_char_count(imhtml->text_buffer)){ | |
| 1950 options |= GTK_IMHTML_NO_SCROLL; | |
| 1951 } | |
| 1952 | |
| 1953 gtk_imhtml_insert_html_at_iter(imhtml, text, options, &iter); | |
| 1954 | |
| 1955 if (fixins) { | |
| 1956 gtk_text_buffer_get_iter_at_offset(imhtml->text_buffer, &ins, ins_offset); | |
| 1957 gtk_text_buffer_move_mark(imhtml->text_buffer, gtk_text_buffer_get_insert(imhtml->text_buffer), &ins); | |
| 1958 } | |
| 1959 | |
| 1960 if (fixsel) { | |
| 1961 gtk_text_buffer_get_iter_at_offset(imhtml->text_buffer, &sel, sel_offset); | |
| 1962 gtk_text_buffer_move_mark(imhtml->text_buffer, gtk_text_buffer_get_selection_bound(imhtml->text_buffer), &sel); | |
| 1963 } | |
| 1964 | |
| 1965 if (!(options & GTK_IMHTML_NO_SCROLL)) { | |
| 8729 | 1966 gtk_imhtml_scroll_to_end(imhtml); |
| 8677 | 1967 } |
| 1968 } | |
| 1969 | |
| 8729 | 1970 void gtk_imhtml_scroll_to_end(GtkIMHtml *imhtml) |
| 1971 { | |
| 1972 GtkTextIter iter; | |
| 1973 /* If this seems backwards at first glance, well it's not. | |
| 1974 * It means scroll such that the mark is closest to the top, | |
| 1975 * and closest to the right as possible. Remember kids, you have | |
| 1976 * to scroll left to move a given spot closest to the right, | |
| 1977 * and scroll down to move a spot closest to the top. | |
| 1978 */ | |
| 1979 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &iter); | |
| 1980 gtk_text_iter_set_line_offset(&iter, 0); | |
| 1981 gtk_text_buffer_move_mark(imhtml->text_buffer, imhtml->scrollpoint, &iter); | |
| 1982 gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(imhtml), imhtml->scrollpoint, | |
| 1983 0, TRUE, 1.0, 0.0); | |
| 1984 } | |
| 1985 | |
| 8677 | 1986 void gtk_imhtml_insert_html_at_iter(GtkIMHtml *imhtml, |
| 1987 const gchar *text, | |
| 1988 GtkIMHtmlOptions options, | |
| 1989 GtkTextIter *iter) | |
| 1990 { | |
| 8061 | 1991 GdkRectangle rect; |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1992 gint pos = 0; |
| 3922 | 1993 gchar *ws; |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1994 gchar *tag; |
| 3922 | 1995 gchar *bg = NULL; |
| 6982 | 1996 gint len; |
| 4032 | 1997 gint tlen, smilelen, wpos=0; |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1998 gint type; |
| 3922 | 1999 const gchar *c; |
| 7280 | 2000 gchar *amp; |
| 8334 | 2001 gint len_protocol; |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2002 |
| 1428 | 2003 guint bold = 0, |
| 2004 italics = 0, | |
| 2005 underline = 0, | |
| 2006 strike = 0, | |
| 2007 sub = 0, | |
| 2008 sup = 0, | |
|
1691
d802b115800f
[gaim-migrate @ 1701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1647
diff
changeset
|
2009 title = 0, |
| 8061 | 2010 pre = 0; |
| 1428 | 2011 |
| 3922 | 2012 GSList *fonts = NULL; |
| 8506 | 2013 GObject *object; |
| 8061 | 2014 GtkIMHtmlScalable *scalable = NULL; |
| 8677 | 2015 |
| 2016 g_return_if_fail (imhtml != NULL); | |
| 2017 g_return_if_fail (GTK_IS_IMHTML (imhtml)); | |
| 2018 g_return_if_fail (text != NULL); | |
| 3922 | 2019 c = text; |
| 6982 | 2020 len = strlen(text); |
| 3922 | 2021 ws = g_malloc(len + 1); |
| 2022 ws[0] = 0; | |
| 1428 | 2023 |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2024 while (pos < len) { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2025 if (*c == '<' && gtk_imhtml_is_tag (c + 1, &tag, &tlen, &type)) { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2026 c++; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2027 pos++; |
| 8061 | 2028 ws[wpos] = '\0'; |
| 2029 switch (type) | |
| 3922 | 2030 { |
| 2031 case 1: /* B */ | |
| 2032 case 2: /* BOLD */ | |
| 5101 | 2033 case 54: /* STRONG */ |
| 8677 | 2034 |
| 2035 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); | |
| 2036 | |
| 2037 if ((bold == 0) && (imhtml->format_functions & GTK_IMHTML_BOLD)) | |
| 8061 | 2038 gtk_imhtml_toggle_bold(imhtml); |
| 3922 | 2039 bold++; |
| 8061 | 2040 ws[0] = '\0'; wpos = 0; |
| 3922 | 2041 break; |
| 2042 case 3: /* /B */ | |
| 2043 case 4: /* /BOLD */ | |
| 5101 | 2044 case 55: /* /STRONG */ |
| 8677 | 2045 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
| 8061 | 2046 ws[0] = '\0'; wpos = 0; |
| 2047 | |
| 3922 | 2048 if (bold) |
| 2049 bold--; | |
| 8677 | 2050 if ((bold == 0) && (imhtml->format_functions & GTK_IMHTML_BOLD) && !imhtml->wbfo) |
| 8061 | 2051 gtk_imhtml_toggle_bold(imhtml); |
| 3922 | 2052 break; |
| 2053 case 5: /* I */ | |
| 2054 case 6: /* ITALIC */ | |
| 5101 | 2055 case 52: /* EM */ |
| 8677 | 2056 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
| 8061 | 2057 ws[0] = '\0'; wpos = 0; |
| 8677 | 2058 if ((italics == 0) && (imhtml->format_functions & GTK_IMHTML_ITALIC)) |
| 8061 | 2059 gtk_imhtml_toggle_italic(imhtml); |
| 3922 | 2060 italics++; |
| 2061 break; | |
| 2062 case 7: /* /I */ | |
| 2063 case 8: /* /ITALIC */ | |
| 5101 | 2064 case 53: /* /EM */ |
| 8677 | 2065 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
| 8061 | 2066 ws[0] = '\0'; wpos = 0; |
| 3922 | 2067 if (italics) |
| 2068 italics--; | |
| 8677 | 2069 if ((italics == 0) && (imhtml->format_functions & GTK_IMHTML_ITALIC) && !imhtml->wbfo) |
| 8061 | 2070 gtk_imhtml_toggle_italic(imhtml); |
| 3922 | 2071 break; |
| 2072 case 9: /* U */ | |
| 2073 case 10: /* UNDERLINE */ | |
| 8677 | 2074 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
| 8061 | 2075 ws[0] = '\0'; wpos = 0; |
| 8677 | 2076 if ((underline == 0) && (imhtml->format_functions & GTK_IMHTML_UNDERLINE)) |
| 8061 | 2077 gtk_imhtml_toggle_underline(imhtml); |
| 3922 | 2078 underline++; |
| 2079 break; | |
| 2080 case 11: /* /U */ | |
| 2081 case 12: /* /UNDERLINE */ | |
| 8677 | 2082 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
| 8061 | 2083 ws[0] = '\0'; wpos = 0; |
| 3922 | 2084 if (underline) |
| 2085 underline--; | |
| 8677 | 2086 if ((underline == 0) && (imhtml->format_functions & GTK_IMHTML_UNDERLINE) && !imhtml->wbfo) |
| 8061 | 2087 gtk_imhtml_toggle_underline(imhtml); |
| 3922 | 2088 break; |
| 2089 case 13: /* S */ | |
| 2090 case 14: /* STRIKE */ | |
| 8677 | 2091 /* FIXME: reimplement this */ |
| 3922 | 2092 strike++; |
| 2093 break; | |
| 2094 case 15: /* /S */ | |
| 2095 case 16: /* /STRIKE */ | |
| 8677 | 2096 /* FIXME: reimplement this */ |
| 3922 | 2097 if (strike) |
| 2098 strike--; | |
| 2099 break; | |
| 2100 case 17: /* SUB */ | |
| 8677 | 2101 /* FIXME: reimpliment this */ |
| 3922 | 2102 sub++; |
| 2103 break; | |
| 2104 case 18: /* /SUB */ | |
| 8677 | 2105 /* FIXME: reimpliment this */ |
| 3922 | 2106 if (sub) |
| 2107 sub--; | |
| 2108 break; | |
| 2109 case 19: /* SUP */ | |
| 8677 | 2110 /* FIXME: reimplement this */ |
| 3922 | 2111 sup++; |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2112 break; |
| 3922 | 2113 case 20: /* /SUP */ |
| 8677 | 2114 /* FIXME: reimplement this */ |
| 3922 | 2115 if (sup) |
| 2116 sup--; | |
| 2117 break; | |
| 2118 case 21: /* PRE */ | |
| 8677 | 2119 /* FIXME: reimplement this */ |
| 3922 | 2120 pre++; |
| 2121 break; | |
| 2122 case 22: /* /PRE */ | |
| 8677 | 2123 /* FIXME: reimplement this */ |
| 3922 | 2124 if (pre) |
| 2125 pre--; | |
| 2126 break; | |
| 2127 case 23: /* TITLE */ | |
| 8677 | 2128 /* FIXME: what was this supposed to do anyway? */ |
| 3922 | 2129 title++; |
| 2130 break; | |
| 2131 case 24: /* /TITLE */ | |
| 8677 | 2132 /* FIXME: make this undo whatever 23 was supposed to do */ |
| 3922 | 2133 if (title) { |
| 2134 if (options & GTK_IMHTML_NO_TITLE) { | |
| 2135 wpos = 0; | |
| 2136 ws [wpos] = '\0'; | |
| 2137 } | |
| 2138 title--; | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2139 } |
| 3922 | 2140 break; |
| 2141 case 25: /* BR */ | |
| 5174 | 2142 case 58: /* BR/ */ |
| 8061 | 2143 case 61: /* BR (opt) */ |
| 3922 | 2144 ws[wpos] = '\n'; |
| 2145 wpos++; | |
| 6982 | 2146 break; |
| 3922 | 2147 case 26: /* HR */ |
| 2148 case 42: /* HR (opt) */ | |
| 8726 | 2149 { |
| 2150 int minus; | |
| 2151 | |
| 3922 | 2152 ws[wpos++] = '\n'; |
| 8677 | 2153 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
| 2154 | |
| 5967 | 2155 scalable = gtk_imhtml_hr_new(); |
| 8061 | 2156 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); |
| 8677 | 2157 scalable->add_to(scalable, imhtml, iter); |
| 8726 | 2158 minus = gtk_text_view_get_left_margin(GTK_TEXT_VIEW(imhtml)) + |
| 2159 gtk_text_view_get_right_margin(GTK_TEXT_VIEW(imhtml)); | |
| 2160 scalable->scale(scalable, rect.width - minus, rect.height); | |
| 8061 | 2161 imhtml->scalables = g_list_append(imhtml->scalables, scalable); |
| 2162 ws[0] = '\0'; wpos = 0; | |
| 7942 | 2163 ws[wpos++] = '\n'; |
| 8061 | 2164 |
| 3922 | 2165 break; |
| 8726 | 2166 } |
| 3922 | 2167 case 27: /* /FONT */ |
| 8677 | 2168 if (fonts && !imhtml->wbfo) { |
| 5967 | 2169 GtkIMHtmlFontDetail *font = fonts->data; |
| 8677 | 2170 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
| 8061 | 2171 ws[0] = '\0'; wpos = 0; |
| 8177 | 2172 /* NEW_BIT (NEW_TEXT_BIT); */ |
| 8677 | 2173 |
| 8698 | 2174 if (font->face && (imhtml->format_functions & GTK_IMHTML_FACE)) { |
| 8061 | 2175 gtk_imhtml_toggle_fontface(imhtml, NULL); |
| 3922 | 2176 g_free (font->face); |
| 8061 | 2177 } |
| 8698 | 2178 if (font->fore && (imhtml->format_functions & GTK_IMHTML_FORECOLOR)) { |
| 8061 | 2179 gtk_imhtml_toggle_forecolor(imhtml, NULL); |
| 3922 | 2180 g_free (font->fore); |
| 8061 | 2181 } |
| 8698 | 2182 if (font->back && (imhtml->format_functions & GTK_IMHTML_BACKCOLOR)) { |
| 8061 | 2183 gtk_imhtml_toggle_backcolor(imhtml, NULL); |
| 3922 | 2184 g_free (font->back); |
| 8061 | 2185 } |
| 4032 | 2186 if (font->sml) |
| 2187 g_free (font->sml); | |
| 8309 | 2188 |
| 8698 | 2189 if ((font->size != 3) && (imhtml->format_functions & (GTK_IMHTML_GROW|GTK_IMHTML_SHRINK))) |
| 8309 | 2190 gtk_imhtml_font_set_size(imhtml, 3); |
| 2191 | |
| 9245 | 2192 g_free(font); |
| 2193 | |
| 8309 | 2194 fonts = fonts->next; |
| 2195 if (fonts) { | |
| 2196 GtkIMHtmlFontDetail *font = fonts->data; | |
| 8677 | 2197 |
| 8698 | 2198 if (font->face && (imhtml->format_functions & GTK_IMHTML_FACE)) |
| 8309 | 2199 gtk_imhtml_toggle_fontface(imhtml, font->face); |
| 8698 | 2200 if (font->fore && (imhtml->format_functions & GTK_IMHTML_FORECOLOR)) |
| 8309 | 2201 gtk_imhtml_toggle_forecolor(imhtml, font->fore); |
| 8698 | 2202 if (font->back && (imhtml->format_functions & GTK_IMHTML_BACKCOLOR)) |
| 8309 | 2203 gtk_imhtml_toggle_backcolor(imhtml, font->back); |
| 8698 | 2204 if ((font->size != 3) && (imhtml->format_functions & (GTK_IMHTML_GROW|GTK_IMHTML_SHRINK))) |
| 8309 | 2205 gtk_imhtml_font_set_size(imhtml, font->size); |
| 2206 } | |
| 3922 | 2207 } |
| 8309 | 2208 break; |
| 3922 | 2209 case 28: /* /A */ |
| 8677 | 2210 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
| 2211 gtk_imhtml_toggle_link(imhtml, NULL); | |
| 2212 ws[0] = '\0'; wpos = 0; | |
| 8061 | 2213 break; |
| 8118 | 2214 |
| 3922 | 2215 case 29: /* P */ |
| 2216 case 30: /* /P */ | |
| 2217 case 31: /* H3 */ | |
| 2218 case 32: /* /H3 */ | |
| 2219 case 33: /* HTML */ | |
| 2220 case 34: /* /HTML */ | |
| 2221 case 35: /* BODY */ | |
| 2222 case 36: /* /BODY */ | |
| 2223 case 37: /* FONT */ | |
| 2224 case 38: /* HEAD */ | |
| 2225 case 39: /* /HEAD */ | |
| 6982 | 2226 case 40: /* BINARY */ |
| 2227 case 41: /* /BINARY */ | |
| 3922 | 2228 break; |
| 2229 case 43: /* FONT (opt) */ | |
| 2230 { | |
| 4032 | 2231 gchar *color, *back, *face, *size, *sml; |
| 5967 | 2232 GtkIMHtmlFontDetail *font, *oldfont = NULL; |
| 3922 | 2233 color = gtk_imhtml_get_html_opt (tag, "COLOR="); |
| 2234 back = gtk_imhtml_get_html_opt (tag, "BACK="); | |
| 2235 face = gtk_imhtml_get_html_opt (tag, "FACE="); | |
| 2236 size = gtk_imhtml_get_html_opt (tag, "SIZE="); | |
| 4032 | 2237 sml = gtk_imhtml_get_html_opt (tag, "SML="); |
| 2238 if (!(color || back || face || size || sml)) | |
| 3922 | 2239 break; |
| 8061 | 2240 |
| 8677 | 2241 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
| 8061 | 2242 ws[0] = '\0'; wpos = 0; |
| 2243 | |
| 5967 | 2244 font = g_new0 (GtkIMHtmlFontDetail, 1); |
| 3922 | 2245 if (fonts) |
| 2246 oldfont = fonts->data; | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2247 |
| 8677 | 2248 if (color && !(options & GTK_IMHTML_NO_COLOURS) && (imhtml->format_functions & GTK_IMHTML_FORECOLOR)) { |
| 3922 | 2249 font->fore = color; |
| 8061 | 2250 gtk_imhtml_toggle_forecolor(imhtml, font->fore); |
| 8677 | 2251 } |
| 8309 | 2252 //else if (oldfont && oldfont->fore) |
| 2253 // font->fore = g_strdup(oldfont->fore); | |
| 8677 | 2254 |
| 2255 if (back && !(options & GTK_IMHTML_NO_COLOURS) && (imhtml->format_functions & GTK_IMHTML_BACKCOLOR)) { | |
| 3922 | 2256 font->back = back; |
| 8061 | 2257 gtk_imhtml_toggle_backcolor(imhtml, font->back); |
| 8309 | 2258 } |
| 2259 //else if (oldfont && oldfont->back) | |
| 2260 // font->back = g_strdup(oldfont->back); | |
| 8677 | 2261 |
| 2262 if (face && !(options & GTK_IMHTML_NO_FONTS) && (imhtml->format_functions & GTK_IMHTML_FACE)) { | |
| 3922 | 2263 font->face = face; |
| 8061 | 2264 gtk_imhtml_toggle_fontface(imhtml, font->face); |
| 8309 | 2265 } |
| 2266 //else if (oldfont && oldfont->face) | |
| 2267 // font->face = g_strdup(oldfont->face); | |
| 4032 | 2268 |
| 2269 if (sml) | |
| 2270 font->sml = sml; | |
| 2271 else if (oldfont && oldfont->sml) | |
| 2272 font->sml = g_strdup(oldfont->sml); | |
| 2273 | |
| 8677 | 2274 if (size && !(options & GTK_IMHTML_NO_SIZES) && (imhtml->format_functions & (GTK_IMHTML_GROW|GTK_IMHTML_SHRINK))) { |
| 3922 | 2275 if (*size == '+') { |
| 2276 sscanf (size + 1, "%hd", &font->size); | |
| 2277 font->size += 3; | |
| 2278 } else if (*size == '-') { | |
| 2279 sscanf (size + 1, "%hd", &font->size); | |
| 2280 font->size = MAX (0, 3 - font->size); | |
| 2281 } else if (isdigit (*size)) { | |
| 2282 sscanf (size, "%hd", &font->size); | |
| 8061 | 2283 } |
| 6042 | 2284 if (font->size > 100) |
| 2285 font->size = 100; | |
| 3922 | 2286 } else if (oldfont) |
| 2287 font->size = oldfont->size; | |
| 8309 | 2288 else |
| 2289 font->size = 3; | |
| 8698 | 2290 if ((imhtml->format_functions & (GTK_IMHTML_GROW|GTK_IMHTML_SHRINK))) |
| 2291 gtk_imhtml_font_set_size(imhtml, font->size); | |
| 3922 | 2292 g_free(size); |
| 2293 fonts = g_slist_prepend (fonts, font); | |
| 2294 } | |
| 2295 break; | |
| 2296 case 44: /* BODY (opt) */ | |
| 2297 if (!(options & GTK_IMHTML_NO_COLOURS)) { | |
| 2298 char *bgcolor = gtk_imhtml_get_html_opt (tag, "BGCOLOR="); | |
| 8677 | 2299 if (bgcolor && (imhtml->format_functions & GTK_IMHTML_BACKCOLOR)) { |
| 2300 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); | |
| 8061 | 2301 ws[0] = '\0'; wpos = 0; |
| 8177 | 2302 /* NEW_BIT(NEW_TEXT_BIT); */ |
| 3922 | 2303 if (bg) |
| 2304 g_free(bg); | |
| 2305 bg = bgcolor; | |
| 8061 | 2306 gtk_imhtml_toggle_backcolor(imhtml, bg); |
|
2885
f72efa29c109
[gaim-migrate @ 2898]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2871
diff
changeset
|
2307 } |
| 1428 | 2308 } |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2309 break; |
| 3922 | 2310 case 45: /* A (opt) */ |
| 2311 { | |
| 2312 gchar *href = gtk_imhtml_get_html_opt (tag, "HREF="); | |
| 8677 | 2313 if (href && (imhtml->format_functions & GTK_IMHTML_LINK)) { |
| 2314 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); | |
| 8061 | 2315 ws[0] = '\0'; wpos = 0; |
| 8677 | 2316 gtk_imhtml_toggle_link(imhtml, href); |
| 3922 | 2317 } |
| 2993 | 2318 } |
| 3922 | 2319 break; |
| 4895 | 2320 case 46: /* IMG (opt) */ |
| 6982 | 2321 case 59: /* IMG */ |
| 4895 | 2322 { |
| 8962 | 2323 const char *id; |
| 2324 | |
| 2325 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); | |
| 2326 ws[0] = '\0'; wpos = 0; | |
| 4895 | 2327 |
| 8677 | 2328 if (!(imhtml->format_functions & GTK_IMHTML_IMAGE)) |
| 2329 break; | |
| 2330 | |
| 8962 | 2331 id = gtk_imhtml_get_html_opt(tag, "ID="); |
| 9186 | 2332 if (!id) |
| 2333 break; | |
| 8962 | 2334 gtk_imhtml_insert_image_at_iter(imhtml, atoi(id), iter); |
| 2335 break; | |
| 4895 | 2336 } |
| 3922 | 2337 case 47: /* P (opt) */ |
| 2338 case 48: /* H3 (opt) */ | |
| 5093 | 2339 case 49: /* HTML (opt) */ |
| 5101 | 2340 case 50: /* CITE */ |
| 2341 case 51: /* /CITE */ | |
| 8026 | 2342 case 56: /* SPAN (opt) */ |
| 8118 | 2343 /* Inline CSS Support - Douglas Thrift |
| 2344 * | |
| 2345 * color | |
| 8686 | 2346 * background |
| 8118 | 2347 * font-family |
| 2348 * font-size | |
| 8686 | 2349 * text-decoration: underline |
| 8118 | 2350 */ |
| 2351 { | |
| 8686 | 2352 gchar *style, *color, *background, *family, *size; |
| 2353 gchar *textdec; | |
| 8118 | 2354 GtkIMHtmlFontDetail *font, *oldfont = NULL; |
| 2355 style = gtk_imhtml_get_html_opt (tag, "style="); | |
| 2356 | |
| 2357 if (!style) break; | |
| 2358 | |
| 2359 color = gtk_imhtml_get_css_opt (style, "color: "); | |
| 8686 | 2360 background = gtk_imhtml_get_css_opt (style, "background: "); |
| 8118 | 2361 family = gtk_imhtml_get_css_opt (style, |
| 2362 "font-family: "); | |
| 2363 size = gtk_imhtml_get_css_opt (style, "font-size: "); | |
| 8686 | 2364 textdec = gtk_imhtml_get_css_opt (style, "text-decoration: "); |
| 2365 | |
| 2366 if (!(color || family || size || background || textdec)) { | |
| 8120 | 2367 g_free(style); |
| 2368 break; | |
| 2369 } | |
| 8118 | 2370 |
| 8677 | 2371 |
| 2372 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); | |
| 8118 | 2373 ws[0] = '\0'; wpos = 0; |
| 8177 | 2374 /* NEW_BIT (NEW_TEXT_BIT); */ |
| 8118 | 2375 |
| 2376 font = g_new0 (GtkIMHtmlFontDetail, 1); | |
| 2377 if (fonts) | |
| 2378 oldfont = fonts->data; | |
| 2379 | |
| 8677 | 2380 if (color && !(options & GTK_IMHTML_NO_COLOURS) && (imhtml->format_functions & GTK_IMHTML_FORECOLOR)) |
| 8686 | 2381 { |
| 8118 | 2382 font->fore = color; |
| 8686 | 2383 gtk_imhtml_toggle_forecolor(imhtml, font->fore); |
| 2384 } | |
| 8118 | 2385 else if (oldfont && oldfont->fore) |
| 2386 font->fore = g_strdup(oldfont->fore); | |
| 2387 | |
| 8686 | 2388 if (background && !(options & GTK_IMHTML_NO_COLOURS) && (imhtml->format_functions & GTK_IMHTML_BACKCOLOR)) |
| 2389 { | |
| 2390 font->back = background; | |
| 2391 gtk_imhtml_toggle_backcolor(imhtml, font->back); | |
| 2392 } | |
| 2393 else if (oldfont && oldfont->back) | |
| 8118 | 2394 font->back = g_strdup(oldfont->back); |
| 2395 | |
| 8677 | 2396 if (family && !(options & GTK_IMHTML_NO_FONTS) && (imhtml->format_functions & GTK_IMHTML_FACE)) |
| 8686 | 2397 { |
| 8118 | 2398 font->face = family; |
| 8686 | 2399 gtk_imhtml_toggle_fontface(imhtml, font->face); |
| 2400 } | |
| 8118 | 2401 else if (oldfont && oldfont->face) |
| 2402 font->face = g_strdup(oldfont->face); | |
| 2403 if (font->face && (atoi(font->face) > 100)) { | |
| 8677 | 2404 /* WTF is this? */ |
| 9696 | 2405 /* Maybe it sets a max size on the font face? I seem to |
| 2406 * remember bad things happening if the font size was | |
| 2407 * 2 billion */ | |
| 8118 | 2408 g_free(font->face); |
| 2409 font->face = g_strdup("100"); | |
| 2410 } | |
| 2411 | |
| 2412 if (oldfont && oldfont->sml) | |
| 2413 font->sml = g_strdup(oldfont->sml); | |
| 2414 | |
| 8677 | 2415 if (size && !(options & GTK_IMHTML_NO_SIZES) && (imhtml->format_functions & (GTK_IMHTML_SHRINK|GTK_IMHTML_GROW))) { |
| 8686 | 2416 if (g_ascii_strcasecmp(size, "xx-small") == 0) |
| 2417 font->size = 1; | |
| 2418 else if (g_ascii_strcasecmp(size, "smaller") == 0 | |
| 2419 || g_ascii_strcasecmp(size, "x-small") == 0) | |
| 8118 | 2420 font->size = 2; |
| 8686 | 2421 else if (g_ascii_strcasecmp(size, "larger") == 0 |
| 2422 || g_ascii_strcasecmp(size, "medium") == 0) | |
| 8118 | 2423 font->size = 4; |
| 8686 | 2424 else if (g_ascii_strcasecmp(size, "large") == 0) |
| 2425 font->size = 5; | |
| 2426 else if (g_ascii_strcasecmp(size, "x-large") == 0) | |
| 2427 font->size = 6; | |
| 2428 else if (g_ascii_strcasecmp(size, "xx-large") == 0) | |
| 2429 font->size = 7; | |
| 8118 | 2430 else |
| 2431 font->size = 3; | |
| 8686 | 2432 gtk_imhtml_font_set_size(imhtml, font->size); |
| 2433 } | |
| 2434 else if (oldfont) | |
| 2435 { | |
| 2436 font->size = oldfont->size; | |
| 2437 } | |
| 2438 | |
| 2439 if (oldfont) | |
| 2440 { | |
| 2441 font->underline = oldfont->underline; | |
| 2442 } | |
| 2443 if (textdec && font->underline != 1 | |
| 9025 | 2444 && g_ascii_strcasecmp(textdec, "underline") == 0 |
| 8686 | 2445 && (imhtml->format_functions & GTK_IMHTML_UNDERLINE)) |
| 2446 { | |
| 2447 gtk_imhtml_toggle_underline(imhtml); | |
| 2448 font->underline = 1; | |
| 2449 } | |
| 8118 | 2450 |
| 2451 g_free(style); | |
| 2452 g_free(size); | |
| 2453 fonts = g_slist_prepend (fonts, font); | |
| 2454 } | |
| 2455 break; | |
| 5104 | 2456 case 57: /* /SPAN */ |
| 8118 | 2457 /* Inline CSS Support - Douglas Thrift */ |
| 8677 | 2458 if (fonts && !imhtml->wbfo) { |
| 8686 | 2459 GtkIMHtmlFontDetail *oldfont = NULL; |
| 8118 | 2460 GtkIMHtmlFontDetail *font = fonts->data; |
| 8677 | 2461 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
| 8118 | 2462 ws[0] = '\0'; wpos = 0; |
| 8177 | 2463 /* NEW_BIT (NEW_TEXT_BIT); */ |
| 8118 | 2464 fonts = g_slist_remove (fonts, font); |
| 8692 | 2465 if (fonts) |
| 2466 oldfont = fonts->data; | |
| 2467 | |
| 2468 if (!oldfont) { | |
| 2469 gtk_imhtml_font_set_size(imhtml, 3); | |
| 2470 if (font->underline) | |
| 2471 gtk_imhtml_toggle_underline(imhtml); | |
| 2472 gtk_imhtml_toggle_fontface(imhtml, NULL); | |
| 2473 gtk_imhtml_toggle_forecolor(imhtml, NULL); | |
| 2474 gtk_imhtml_toggle_backcolor(imhtml, NULL); | |
| 8686 | 2475 } |
| 8692 | 2476 else |
| 8686 | 2477 { |
| 8692 | 2478 |
| 2479 if (font->size != oldfont->size) | |
| 2480 gtk_imhtml_font_set_size(imhtml, oldfont->size); | |
| 2481 | |
| 2482 if (font->underline != oldfont->underline) | |
| 2483 gtk_imhtml_toggle_underline(imhtml); | |
| 2484 | |
| 9286 | 2485 if (font->face && (!oldfont->face || strcmp(font->face, oldfont->face) != 0)) |
| 8692 | 2486 gtk_imhtml_toggle_fontface(imhtml, oldfont->face); |
| 2487 | |
| 9286 | 2488 if (font->fore && (!oldfont->fore || strcmp(font->fore, oldfont->fore) != 0)) |
| 8692 | 2489 gtk_imhtml_toggle_forecolor(imhtml, oldfont->fore); |
| 2490 | |
| 9286 | 2491 if (font->back && (!oldfont->back || strcmp(font->back, oldfont->back) != 0)) |
| 8692 | 2492 gtk_imhtml_toggle_backcolor(imhtml, oldfont->back); |
| 8686 | 2493 } |
| 8692 | 2494 |
| 2495 g_free (font->face); | |
| 2496 g_free (font->fore); | |
| 2497 g_free (font->back); | |
| 2498 g_free (font->sml); | |
| 2499 | |
| 8118 | 2500 g_free (font); |
| 2501 } | |
| 2502 break; | |
| 8026 | 2503 case 60: /* SPAN */ |
| 2993 | 2504 break; |
| 8061 | 2505 case 62: /* comment */ |
| 8177 | 2506 /* NEW_BIT (NEW_TEXT_BIT); */ |
| 8317 | 2507 ws[wpos] = '\0'; |
| 9465 | 2508 |
| 8677 | 2509 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
| 2510 | |
| 9465 | 2511 if (imhtml->show_comments && !(options & GTK_IMHTML_NO_COMMENTS)) |
| 6124 | 2512 wpos = g_snprintf (ws, len, "%s", tag); |
| 8177 | 2513 /* NEW_BIT (NEW_COMMENT_BIT); */ |
| 3922 | 2514 break; |
| 2515 default: | |
| 6882 | 2516 break; |
| 2993 | 2517 } |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2518 c += tlen; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2519 pos += tlen; |
| 4138 | 2520 if(tag) |
| 2521 g_free(tag); /* This was allocated back in VALID_TAG() */ | |
| 9029 | 2522 } else if (gtk_imhtml_is_smiley(imhtml, fonts, c, &smilelen)) { |
| 8473 | 2523 GtkIMHtmlFontDetail *fd; |
| 2524 | |
| 2525 gchar *sml = NULL; | |
| 2526 if (fonts) { | |
| 2527 fd = fonts->data; | |
| 2528 sml = fd->sml; | |
| 2529 } | |
| 9029 | 2530 if (!sml) |
| 2531 sml = imhtml->protocol_name; | |
| 2532 | |
| 8677 | 2533 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
| 8505 | 2534 wpos = g_snprintf (ws, smilelen + 1, "%s", c); |
| 8473 | 2535 |
| 8677 | 2536 gtk_imhtml_insert_smiley_at_iter(imhtml, sml, ws, iter); |
| 8473 | 2537 |
| 8505 | 2538 c += smilelen; |
| 2539 pos += smilelen; | |
| 8473 | 2540 wpos = 0; |
| 2541 ws[0] = 0; | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2542 } else if (*c == '&' && gtk_imhtml_is_amp_escape (c, &, &tlen)) { |
| 7280 | 2543 while(*amp) { |
| 2544 ws [wpos++] = *amp++; | |
| 2545 } | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2546 c += tlen; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2547 pos += tlen; |
| 1428 | 2548 } else if (*c == '\n') { |
| 2549 if (!(options & GTK_IMHTML_NO_NEWLINE)) { | |
| 3922 | 2550 ws[wpos] = '\n'; |
| 2551 wpos++; | |
| 8677 | 2552 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
| 8061 | 2553 ws[0] = '\0'; |
| 2554 wpos = 0; | |
| 8177 | 2555 /* NEW_BIT (NEW_TEXT_BIT); */ |
| 9621 | 2556 } else { |
| 2557 /* A newline is defined by HTML as whitespace, which means we have to replace it with a word boundary. | |
| 2558 * word breaks vary depending on the language used, so the correct thing to do is to use Pango to determine | |
| 2559 * what language this is, determine the proper word boundary to use, and insert that. I'm just going to insert | |
| 2560 * a space instead. What are the non-English speakers going to do? Complain in a language I'll understand? | |
| 2561 * Bu-wahaha! */ | |
| 2562 ws[wpos] = ' '; | |
| 2563 wpos++; | |
| 2564 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); | |
| 2565 ws[0] = '\0'; | |
| 2566 wpos = 0; | |
| 1428 | 2567 } |
| 2568 c++; | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2569 pos++; |
| 8334 | 2570 } else if ((len_protocol = gtk_imhtml_is_protocol(c)) > 0){ |
| 2571 while(len_protocol--){ | |
| 8677 | 2572 /* Skip the next len_protocol characters, but make sure they're |
| 8334 | 2573 copied into the ws array. |
| 2574 */ | |
| 2575 ws [wpos++] = *c++; | |
| 2576 pos++; | |
| 2577 } | |
| 8061 | 2578 } else if (*c) { |
| 1428 | 2579 ws [wpos++] = *c++; |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2580 pos++; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2581 } else { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2582 break; |
| 1428 | 2583 } |
| 2584 } | |
| 8677 | 2585 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
| 8061 | 2586 ws[0] = '\0'; wpos = 0; |
| 2587 | |
| 8177 | 2588 /* NEW_BIT(NEW_TEXT_BIT); */ |
| 8061 | 2589 |
| 4032 | 2590 while (fonts) { |
| 5967 | 2591 GtkIMHtmlFontDetail *font = fonts->data; |
| 4032 | 2592 fonts = g_slist_remove (fonts, font); |
| 2593 if (font->face) | |
| 2594 g_free (font->face); | |
| 2595 if (font->fore) | |
| 2596 g_free (font->fore); | |
| 2597 if (font->back) | |
| 2598 g_free (font->back); | |
| 2599 if (font->sml) | |
| 2600 g_free (font->sml); | |
| 2601 g_free (font); | |
| 2602 } | |
| 8932 | 2603 |
| 2604 g_free(ws); | |
| 2605 if (bg) | |
| 4630 | 2606 g_free(bg); |
| 8677 | 2607 |
| 2608 if (!imhtml->wbfo) | |
| 8698 | 2609 gtk_imhtml_close_tags(imhtml, iter); |
| 8506 | 2610 |
| 2611 object = g_object_ref(G_OBJECT(imhtml)); | |
| 2612 g_signal_emit(object, signals[UPDATE_FORMAT], 0); | |
| 2613 g_object_unref(object); | |
| 2614 | |
| 3922 | 2615 } |
| 2616 | |
| 4892 | 2617 void gtk_imhtml_remove_smileys(GtkIMHtml *imhtml) |
| 2618 { | |
| 4288 | 2619 g_hash_table_destroy(imhtml->smiley_data); |
| 2620 gtk_smiley_tree_destroy(imhtml->default_smilies); | |
| 4892 | 2621 imhtml->smiley_data = g_hash_table_new_full(g_str_hash, g_str_equal, |
| 4902 | 2622 g_free, (GDestroyNotify)gtk_smiley_tree_destroy); |
| 4288 | 2623 imhtml->default_smilies = gtk_smiley_tree_new(); |
| 2624 } | |
| 8481 | 2625 |
| 3922 | 2626 void gtk_imhtml_show_comments (GtkIMHtml *imhtml, |
| 4253 | 2627 gboolean show) |
| 2628 { | |
| 6124 | 2629 imhtml->show_comments = show; |
| 4253 | 2630 } |
|
1780
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
2631 |
| 8456 | 2632 void gtk_imhtml_html_shortcuts (GtkIMHtml *imhtml, |
| 2633 gboolean allow) | |
| 2634 { | |
| 2635 imhtml->html_shortcuts = allow; | |
| 2636 } | |
| 2637 | |
| 2638 void gtk_imhtml_smiley_shortcuts (GtkIMHtml *imhtml, | |
| 2639 gboolean allow) | |
| 2640 { | |
| 2641 imhtml->smiley_shortcuts = allow; | |
| 2642 } | |
| 2643 | |
| 8962 | 2644 void |
| 9029 | 2645 gtk_imhtml_set_protocol_name(GtkIMHtml *imhtml, const gchar *protocol_name) { |
| 2646 if (imhtml->protocol_name) | |
| 2647 g_free(imhtml->protocol_name); | |
| 2648 imhtml->protocol_name = protocol_name ? g_strdup(protocol_name) : NULL; | |
| 8456 | 2649 } |
| 2650 | |
|
1780
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
2651 void |
|
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
2652 gtk_imhtml_clear (GtkIMHtml *imhtml) |
|
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
2653 { |
| 7991 | 2654 GList *del; |
| 3922 | 2655 GtkTextIter start, end; |
| 8427 | 2656 GObject *object = g_object_ref(G_OBJECT(imhtml)); |
| 7991 | 2657 |
| 3922 | 2658 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start); |
| 2659 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end); | |
| 2660 gtk_text_buffer_delete(imhtml->text_buffer, &start, &end); | |
| 7991 | 2661 |
| 2662 for(del = imhtml->scalables; del; del = del->next) { | |
| 2663 GtkIMHtmlScalable *scale = del->data; | |
| 2664 scale->free(scale); | |
| 2665 } | |
| 2666 g_list_free(imhtml->scalables); | |
| 2667 imhtml->scalables = NULL; | |
| 8061 | 2668 |
| 8719 | 2669 gtk_imhtml_close_tags(imhtml, &start); |
| 8481 | 2670 |
| 8427 | 2671 g_signal_emit(object, signals[CLEAR_FORMAT], 0); |
| 2672 g_object_unref(object); | |
|
1780
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
2673 } |
|
2363
08c66712364c
[gaim-migrate @ 2376]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2349
diff
changeset
|
2674 |
| 4046 | 2675 void gtk_imhtml_page_up (GtkIMHtml *imhtml) |
| 2676 { | |
| 5282 | 2677 GdkRectangle rect; |
| 2678 GtkTextIter iter; | |
| 4046 | 2679 |
| 5282 | 2680 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); |
| 2681 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(imhtml), &iter, rect.x, | |
| 2682 rect.y - rect.height); | |
| 2683 gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(imhtml), &iter, 0, TRUE, 0, 0); | |
| 8061 | 2684 |
| 4046 | 2685 } |
| 5282 | 2686 void gtk_imhtml_page_down (GtkIMHtml *imhtml) |
| 2687 { | |
| 2688 GdkRectangle rect; | |
| 2689 GtkTextIter iter; | |
| 2690 | |
| 2691 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); | |
| 2692 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(imhtml), &iter, rect.x, | |
| 2693 rect.y + rect.height); | |
| 2694 gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(imhtml), &iter, 0, TRUE, 0, 0); | |
| 2695 } | |
| 4735 | 2696 |
| 5967 | 2697 /* GtkIMHtmlScalable, gtk_imhtml_image, gtk_imhtml_hr */ |
| 8962 | 2698 GtkIMHtmlScalable *gtk_imhtml_image_new(GdkPixbuf *img, const gchar *filename, int id) |
| 4735 | 2699 { |
| 5967 | 2700 GtkIMHtmlImage *im_image = g_malloc(sizeof(GtkIMHtmlImage)); |
| 5012 | 2701 GtkImage *image = GTK_IMAGE(gtk_image_new_from_pixbuf(img)); |
| 4895 | 2702 |
| 5967 | 2703 GTK_IMHTML_SCALABLE(im_image)->scale = gtk_imhtml_image_scale; |
| 2704 GTK_IMHTML_SCALABLE(im_image)->add_to = gtk_imhtml_image_add_to; | |
| 2705 GTK_IMHTML_SCALABLE(im_image)->free = gtk_imhtml_image_free; | |
| 5046 | 2706 |
| 2707 im_image->pixbuf = img; | |
| 5012 | 2708 im_image->image = image; |
| 4895 | 2709 im_image->width = gdk_pixbuf_get_width(img); |
| 2710 im_image->height = gdk_pixbuf_get_height(img); | |
| 2711 im_image->mark = NULL; | |
| 6982 | 2712 im_image->filename = filename ? g_strdup(filename) : NULL; |
| 8962 | 2713 im_image->id = id; |
| 9573 | 2714 im_image->filesel = NULL; |
| 4895 | 2715 |
| 5046 | 2716 g_object_ref(img); |
| 4895 | 2717 return GTK_IMHTML_SCALABLE(im_image); |
| 2718 } | |
| 2719 | |
| 5967 | 2720 void gtk_imhtml_image_scale(GtkIMHtmlScalable *scale, int width, int height) |
| 4895 | 2721 { |
| 5967 | 2722 GtkIMHtmlImage *image = (GtkIMHtmlImage *)scale; |
| 4895 | 2723 |
| 2724 if(image->width > width || image->height > height){ | |
| 2725 GdkPixbuf *new_image = NULL; | |
| 2726 float factor; | |
| 2727 int new_width = image->width, new_height = image->height; | |
| 2728 | |
| 8588 | 2729 if(image->width > (width - 2)){ |
| 4895 | 2730 factor = (float)(width)/image->width; |
| 2731 new_width = width; | |
| 2732 new_height = image->height * factor; | |
| 2733 } | |
| 8588 | 2734 if(new_height >= (height - 2)){ |
| 4895 | 2735 factor = (float)(height)/new_height; |
| 2736 new_height = height; | |
| 2737 new_width = new_width * factor; | |
| 2738 } | |
| 2739 | |
| 5046 | 2740 new_image = gdk_pixbuf_scale_simple(image->pixbuf, new_width, new_height, GDK_INTERP_BILINEAR); |
| 5012 | 2741 gtk_image_set_from_pixbuf(image->image, new_image); |
| 4895 | 2742 g_object_unref(G_OBJECT(new_image)); |
| 2743 } | |
| 2744 } | |
| 2745 | |
| 9573 | 2746 static void |
| 2747 image_save_yes_cb(GtkIMHtmlImage *image, const char *filename) | |
| 5012 | 2748 { |
| 2749 gchar *type = NULL; | |
| 5019 | 2750 GError *error = NULL; |
| 5015 | 2751 #if GTK_CHECK_VERSION(2,2,0) |
| 5012 | 2752 GSList *formats = gdk_pixbuf_get_formats(); |
| 6162 | 2753 #else |
| 2754 char *basename = g_path_get_basename(filename); | |
| 2755 char *ext = strrchr(basename, '.'); | |
| 5959 | 2756 #endif |
| 5012 | 2757 |
| 9573 | 2758 gtk_widget_destroy(image->filesel); |
| 2759 image->filesel = NULL; | |
| 5959 | 2760 |
| 2761 #if GTK_CHECK_VERSION(2,2,0) | |
| 9573 | 2762 while (formats) { |
| 5012 | 2763 GdkPixbufFormat *format = formats->data; |
| 2764 gchar **extensions = gdk_pixbuf_format_get_extensions(format); | |
| 2765 gpointer p = extensions; | |
| 2766 | |
| 2767 while(gdk_pixbuf_format_is_writable(format) && extensions && extensions[0]){ | |
| 2768 gchar *fmt_ext = extensions[0]; | |
| 2769 const gchar* file_ext = filename + strlen(filename) - strlen(fmt_ext); | |
| 2770 | |
| 2771 if(!strcmp(fmt_ext, file_ext)){ | |
| 2772 type = gdk_pixbuf_format_get_name(format); | |
| 2773 break; | |
| 2774 } | |
| 2775 | |
| 2776 extensions++; | |
| 2777 } | |
| 2778 | |
| 2779 g_strfreev(p); | |
| 2780 | |
| 9573 | 2781 if (type) |
| 5012 | 2782 break; |
| 2783 | |
| 2784 formats = formats->next; | |
| 2785 } | |
| 2786 | |
| 5020 | 2787 g_slist_free(formats); |
| 2788 #else | |
| 2789 /* this is really ugly code, but I think it will work */ | |
| 9573 | 2790 if (ext) { |
| 5020 | 2791 ext++; |
| 9573 | 2792 if (!g_ascii_strcasecmp(ext, "jpeg") || !g_ascii_strcasecmp(ext, "jpg")) |
| 5020 | 2793 type = g_strdup("jpeg"); |
| 9573 | 2794 else if (!g_ascii_strcasecmp(ext, "png")) |
| 5020 | 2795 type = g_strdup("png"); |
| 2796 } | |
| 2797 | |
| 2798 g_free(basename); | |
| 2799 #endif | |
| 2800 | |
| 5012 | 2801 /* If I can't find a valid type, I will just tell the user about it and then assume |
| 2802 it's a png */ | |
| 9573 | 2803 if (!type){ |
| 5012 | 2804 gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, |
| 5967 | 2805 _("Unable to guess the image type based on the file extension supplied. Defaulting to PNG.")); |
| 5012 | 2806 type = g_strdup("png"); |
| 2807 } | |
| 2808 | |
| 5046 | 2809 gdk_pixbuf_save(image->pixbuf, filename, type, &error, NULL); |
| 5012 | 2810 |
| 9573 | 2811 if (error){ |
| 5012 | 2812 gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, |
| 2813 _("Error saving image: %s"), error->message); | |
| 2814 g_error_free(error); | |
| 2815 } | |
| 2816 | |
| 2817 g_free(type); | |
| 2818 } | |
| 2819 | |
| 9573 | 2820 #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */ |
| 2821 static void | |
| 2822 image_save_check_if_exists_cb(GtkWidget *widget, gint response, GtkIMHtmlImage *image) | |
| 2823 { | |
| 2824 gchar *filename; | |
| 2825 | |
| 2826 if (response != GTK_RESPONSE_ACCEPT) { | |
| 2827 gtk_widget_destroy(widget); | |
| 2828 image->filesel = NULL; | |
| 2829 return; | |
| 2830 } | |
| 2831 | |
| 2832 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(widget)); | |
| 2833 #else /* FILECHOOSER */ | |
| 2834 static void | |
| 2835 image_save_check_if_exists_cb(GtkWidget *button, GtkIMHtmlImage *image) | |
| 5012 | 2836 { |
| 9573 | 2837 gchar *filename; |
| 2838 | |
| 2839 filename = g_strdup(gtk_file_selection_get_filename(GTK_FILE_SELECTION(image->filesel))); | |
| 2840 | |
| 2841 if (g_file_test(filename, G_FILE_TEST_IS_DIR)) { | |
| 2842 gchar *dirname; | |
| 2843 /* append a / is needed */ | |
| 2844 if (filename[strlen(filename) - 1] != G_DIR_SEPARATOR) { | |
| 2845 dirname = g_strconcat(filename, G_DIR_SEPARATOR_S, NULL); | |
| 2846 } else { | |
| 2847 dirname = g_strdup(filename); | |
| 2848 } | |
| 9574 | 2849 gtk_file_selection_set_filename(GTK_FILE_SELECTION(image->filesel), dirname); |
| 9573 | 2850 g_free(dirname); |
| 2851 g_free(filename); | |
| 2852 return; | |
| 2853 } | |
| 2854 #endif /* FILECHOOSER */ | |
| 2855 | |
| 2856 /* | |
| 2857 * XXX - We should probably prompt the user to determine if they really | |
| 2858 * want to overwrite the file or not. However, I don't feel like doing | |
| 2859 * that, so we're just always going to overwrite if the file exists. | |
| 2860 */ | |
| 2861 /* | |
| 2862 if (g_file_test(filename, G_FILE_TEST_EXISTS)) { | |
| 2863 } else | |
| 2864 image_save_yes_cb(image, filename); | |
| 2865 */ | |
| 2866 | |
| 2867 image_save_yes_cb(image, filename); | |
| 2868 | |
| 2869 g_free(filename); | |
| 2870 } | |
| 2871 | |
| 2872 #if !GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */ | |
| 2873 static void | |
| 2874 image_save_cancel_cb(GtkIMHtmlImage *image) | |
| 2875 { | |
| 2876 gtk_widget_destroy(image->filesel); | |
| 2877 image->filesel = NULL; | |
| 2878 } | |
| 2879 #endif /* FILECHOOSER */ | |
| 2880 | |
| 2881 static void | |
| 2882 gtk_imhtml_image_save(GtkWidget *w, GtkIMHtmlImage *image) | |
| 2883 { | |
| 2884 if (image->filesel != NULL) { | |
| 2885 gtk_window_present(GTK_WINDOW(image->filesel)); | |
| 2886 return; | |
| 2887 } | |
| 2888 | |
| 2889 #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */ | |
| 2890 image->filesel = gtk_file_chooser_dialog_new(_("Save Image"), | |
| 2891 NULL, | |
| 2892 GTK_FILE_CHOOSER_ACTION_SAVE, | |
| 2893 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, | |
| 2894 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, | |
| 2895 NULL); | |
| 2896 gtk_dialog_set_default_response(GTK_DIALOG(image->filesel), GTK_RESPONSE_ACCEPT); | |
| 2897 if (image->filename != NULL) | |
| 2898 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(image->filesel), image->filename); | |
| 2899 g_signal_connect(G_OBJECT(GTK_FILE_CHOOSER(image->filesel)), "response", | |
| 2900 G_CALLBACK(image_save_check_if_exists_cb), image); | |
| 2901 #else /* FILECHOOSER */ | |
| 2902 image->filesel = gtk_file_selection_new(_("Save Image")); | |
| 2903 if (image->filename != NULL) | |
| 2904 gtk_file_selection_set_filename(GTK_FILE_SELECTION(image->filesel), image->filename); | |
| 9574 | 2905 g_signal_connect_swapped(G_OBJECT(GTK_FILE_SELECTION(image->filesel)), "delete_event", |
| 2906 G_CALLBACK(image_save_cancel_cb), image); | |
| 2907 g_signal_connect_swapped(G_OBJECT(GTK_FILE_SELECTION(image->filesel)->cancel_button), | |
| 2908 "clicked", G_CALLBACK(image_save_cancel_cb), image); | |
| 9573 | 2909 g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(image->filesel)->ok_button), "clicked", |
| 2910 G_CALLBACK(image_save_check_if_exists_cb), image); | |
| 2911 #endif /* FILECHOOSER */ | |
| 2912 | |
| 2913 gtk_widget_show(image->filesel); | |
| 5012 | 2914 } |
| 2915 | |
| 5967 | 2916 static gboolean gtk_imhtml_image_clicked(GtkWidget *w, GdkEvent *event, GtkIMHtmlImage *image) |
| 5012 | 2917 { |
| 2918 GdkEventButton *event_button = (GdkEventButton *) event; | |
| 2919 | |
| 2920 if (event->type == GDK_BUTTON_RELEASE) { | |
| 2921 if(event_button->button == 3) { | |
| 2922 GtkWidget *img, *item, *menu; | |
| 2923 gchar *text = g_strdup_printf(_("_Save Image...")); | |
| 2924 menu = gtk_menu_new(); | |
| 2925 | |
| 2926 /* buttons and such */ | |
| 2927 img = gtk_image_new_from_stock(GTK_STOCK_SAVE, GTK_ICON_SIZE_MENU); | |
| 2928 item = gtk_image_menu_item_new_with_mnemonic(text); | |
| 2929 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), img); | |
| 5967 | 2930 g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(gtk_imhtml_image_save), image); |
| 5012 | 2931 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); |
| 2932 | |
| 2933 gtk_widget_show_all(menu); | |
| 2934 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, | |
| 2935 event_button->button, event_button->time); | |
| 2936 | |
| 2937 g_free(text); | |
| 2938 return TRUE; | |
| 2939 } | |
| 2940 } | |
| 2941 if(event->type == GDK_BUTTON_PRESS && event_button->button == 3) | |
| 2942 return TRUE; /* Clicking the right mouse button on a link shouldn't | |
| 2943 be caught by the regular GtkTextView menu */ | |
| 2944 else | |
| 2945 return FALSE; /* Let clicks go through if we didn't catch anything */ | |
| 2946 | |
| 2947 } | |
| 5967 | 2948 void gtk_imhtml_image_free(GtkIMHtmlScalable *scale) |
| 2949 { | |
| 2950 GtkIMHtmlImage *image = (GtkIMHtmlImage *)scale; | |
| 2951 | |
| 2952 g_object_unref(image->pixbuf); | |
| 6982 | 2953 if (image->filename) |
| 2954 g_free(image->filename); | |
| 9573 | 2955 if (image->filesel) |
| 2956 gtk_widget_destroy(image->filesel); | |
| 5967 | 2957 g_free(scale); |
| 2958 } | |
| 2959 | |
| 2960 void gtk_imhtml_image_add_to(GtkIMHtmlScalable *scale, GtkIMHtml *imhtml, GtkTextIter *iter) | |
| 2961 { | |
| 2962 GtkIMHtmlImage *image = (GtkIMHtmlImage *)scale; | |
| 2963 GtkWidget *box = gtk_event_box_new(); | |
| 8962 | 2964 char *tag; |
| 5967 | 2965 GtkTextChildAnchor *anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, iter); |
| 2966 | |
| 2967 gtk_container_add(GTK_CONTAINER(box), GTK_WIDGET(image->image)); | |
| 9229 | 2968 |
| 2969 if(!gtk_check_version(2, 4, 0)) | |
| 2970 g_object_set(G_OBJECT(box), "visible-window", FALSE, NULL); | |
| 5967 | 2971 |
| 2972 gtk_widget_show(GTK_WIDGET(image->image)); | |
| 2973 gtk_widget_show(box); | |
| 2974 | |
| 8962 | 2975 tag = g_strdup_printf("<IMG ID=\"%d\">", image->id); |
| 2976 g_object_set_data_full(G_OBJECT(anchor), "gtkimhtml_htmltext", tag, g_free); | |
| 2977 g_object_set_data(G_OBJECT(anchor), "gtkimhtml_plaintext", "[Image]"); | |
| 2978 | |
| 5967 | 2979 gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(imhtml), box, anchor); |
| 2980 g_signal_connect(G_OBJECT(box), "event", G_CALLBACK(gtk_imhtml_image_clicked), image); | |
| 2981 } | |
| 2982 | |
| 2983 GtkIMHtmlScalable *gtk_imhtml_hr_new() | |
| 2984 { | |
| 2985 GtkIMHtmlHr *hr = g_malloc(sizeof(GtkIMHtmlHr)); | |
| 2986 | |
| 2987 GTK_IMHTML_SCALABLE(hr)->scale = gtk_imhtml_hr_scale; | |
| 2988 GTK_IMHTML_SCALABLE(hr)->add_to = gtk_imhtml_hr_add_to; | |
| 2989 GTK_IMHTML_SCALABLE(hr)->free = gtk_imhtml_hr_free; | |
| 2990 | |
| 2991 hr->sep = gtk_hseparator_new(); | |
| 2992 gtk_widget_set_size_request(hr->sep, 5000, 2); | |
| 2993 gtk_widget_show(hr->sep); | |
| 2994 | |
| 2995 return GTK_IMHTML_SCALABLE(hr); | |
| 2996 } | |
| 2997 | |
| 2998 void gtk_imhtml_hr_scale(GtkIMHtmlScalable *scale, int width, int height) | |
| 2999 { | |
| 8588 | 3000 gtk_widget_set_size_request(((GtkIMHtmlHr *)scale)->sep, width - 2, 2); |
| 5967 | 3001 } |
| 3002 | |
| 3003 void gtk_imhtml_hr_add_to(GtkIMHtmlScalable *scale, GtkIMHtml *imhtml, GtkTextIter *iter) | |
| 3004 { | |
| 3005 GtkIMHtmlHr *hr = (GtkIMHtmlHr *)scale; | |
| 3006 GtkTextChildAnchor *anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, iter); | |
| 8698 | 3007 g_object_set_data(G_OBJECT(anchor), "gtkimhtml_htmltext", "<hr>"); |
| 3008 g_object_set_data(G_OBJECT(anchor), "gtkimhtml_plaintext", "\n---\n"); | |
| 5967 | 3009 gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(imhtml), hr->sep, anchor); |
| 3010 } | |
| 3011 | |
| 3012 void gtk_imhtml_hr_free(GtkIMHtmlScalable *scale) | |
| 3013 { | |
| 3014 g_free(scale); | |
| 3015 } | |
| 7295 | 3016 |
| 3017 gboolean gtk_imhtml_search_find(GtkIMHtml *imhtml, const gchar *text) | |
| 3018 { | |
| 3019 GtkTextIter iter, start, end; | |
| 3020 gboolean new_search = TRUE; | |
| 3021 | |
| 3022 g_return_val_if_fail(imhtml != NULL, FALSE); | |
| 3023 g_return_val_if_fail(text != NULL, FALSE); | |
| 8061 | 3024 |
| 7295 | 3025 if (imhtml->search_string && !strcmp(text, imhtml->search_string)) |
| 3026 new_search = FALSE; | |
| 8061 | 3027 |
| 7295 | 3028 if (new_search) { |
| 3029 gtk_imhtml_search_clear(imhtml); | |
| 3030 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &iter); | |
| 3031 } else { | |
| 3032 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, | |
| 8061 | 3033 gtk_text_buffer_get_mark(imhtml->text_buffer, "search")); |
| 7295 | 3034 } |
| 3035 imhtml->search_string = g_strdup(text); | |
| 3036 | |
| 7358 | 3037 if (gtk_source_iter_forward_search(&iter, imhtml->search_string, |
| 3038 GTK_SOURCE_SEARCH_VISIBLE_ONLY | GTK_SOURCE_SEARCH_CASE_INSENSITIVE, | |
| 7295 | 3039 &start, &end, NULL)) { |
| 3040 | |
| 3041 gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(imhtml), &start, 0, TRUE, 0, 0); | |
| 3042 gtk_text_buffer_create_mark(imhtml->text_buffer, "search", &end, FALSE); | |
| 3043 if (new_search) { | |
| 3044 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "search", &iter, &end); | |
| 8061 | 3045 do |
| 7295 | 3046 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "search", &start, &end); |
| 8061 | 3047 while (gtk_source_iter_forward_search(&end, imhtml->search_string, |
| 3048 GTK_SOURCE_SEARCH_VISIBLE_ONLY | | |
| 7358 | 3049 GTK_SOURCE_SEARCH_CASE_INSENSITIVE, |
| 7295 | 3050 &start, &end, NULL)); |
| 3051 } | |
| 3052 return TRUE; | |
| 3053 } | |
| 8061 | 3054 |
| 3055 gtk_imhtml_search_clear(imhtml); | |
| 3056 | |
| 7295 | 3057 return FALSE; |
| 3058 } | |
| 3059 | |
| 3060 void gtk_imhtml_search_clear(GtkIMHtml *imhtml) | |
| 3061 { | |
| 3062 GtkTextIter start, end; | |
| 8061 | 3063 |
| 7295 | 3064 g_return_if_fail(imhtml != NULL); |
| 8061 | 3065 |
| 7295 | 3066 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start); |
| 3067 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end); | |
| 3068 | |
| 3069 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "search", &start, &end); | |
| 3070 if (imhtml->search_string) | |
| 3071 g_free(imhtml->search_string); | |
| 3072 imhtml->search_string = NULL; | |
| 3073 } | |
| 8061 | 3074 |
| 8677 | 3075 static GtkTextTag *find_font_forecolor_tag(GtkIMHtml *imhtml, gchar *color) |
| 3076 { | |
| 3077 gchar str[18]; | |
| 3078 GtkTextTag *tag; | |
| 3079 | |
| 3080 g_snprintf(str, sizeof(str), "FORECOLOR %s", color); | |
| 3081 | |
| 3082 tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), str); | |
| 3083 if (!tag) | |
| 3084 tag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "foreground", color, NULL); | |
| 3085 | |
| 3086 return tag; | |
| 3087 } | |
| 3088 | |
| 3089 static GtkTextTag *find_font_backcolor_tag(GtkIMHtml *imhtml, gchar *color) | |
| 3090 { | |
| 3091 gchar str[18]; | |
| 3092 GtkTextTag *tag; | |
| 3093 | |
| 3094 g_snprintf(str, sizeof(str), "BACKCOLOR %s", color); | |
| 3095 | |
| 3096 tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), str); | |
| 3097 if (!tag) | |
| 3098 tag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "background", color, NULL); | |
| 3099 | |
| 3100 return tag; | |
| 3101 } | |
| 3102 | |
| 3103 static GtkTextTag *find_font_face_tag(GtkIMHtml *imhtml, gchar *face) | |
| 8061 | 3104 { |
| 8677 | 3105 gchar str[256]; |
| 3106 GtkTextTag *tag; | |
| 3107 | |
| 3108 g_snprintf(str, sizeof(str), "FONT FACE %s", face); | |
| 3109 str[255] = '\0'; | |
| 3110 | |
| 3111 tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), str); | |
| 3112 if (!tag) | |
| 3113 tag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "family", face, NULL); | |
| 3114 | |
| 3115 return tag; | |
| 3116 } | |
| 3117 | |
|
8740
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
3118 static void _init_original_fsize(GtkIMHtml *imhtml) |
|
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
3119 { |
|
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
3120 GtkTextAttributes *attr; |
|
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
3121 attr = gtk_text_view_get_default_attributes(GTK_TEXT_VIEW(imhtml)); |
|
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
3122 imhtml->original_fsize = pango_font_description_get_size(attr->font); |
|
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
3123 gtk_text_attributes_unref(attr); |
|
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
3124 } |
|
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
3125 |
|
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
3126 static void _recalculate_font_sizes(GtkTextTag *tag, gpointer imhtml) |
|
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
3127 { |
|
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
3128 if (strncmp(tag->name, "FONT SIZE ", 10) == 0) { |
|
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
3129 int size; |
|
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
3130 |
|
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
3131 size = strtol(tag->name + 10, NULL, 10); |
|
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
3132 g_object_set(G_OBJECT(tag), "size", |
|
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
3133 (gint) (GTK_IMHTML(imhtml)->original_fsize * |
|
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
3134 ((double) _point_sizes[size-1] * GTK_IMHTML(imhtml)->zoom)), NULL); |
|
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
3135 } |
|
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
3136 |
|
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
3137 |
|
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
3138 } |
|
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
3139 |
|
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
3140 void gtk_imhtml_font_zoom(GtkIMHtml *imhtml, double zoom) |
|
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
3141 { |
|
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
3142 GtkRcStyle *s; |
|
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
3143 PangoFontDescription *font_desc = pango_font_description_new(); |
|
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
3144 |
|
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
3145 imhtml->zoom = zoom; |
|
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
3146 |
|
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
3147 if (!imhtml->original_fsize) |
|
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
3148 _init_original_fsize(imhtml); |
|
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
3149 |
|
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
3150 gtk_text_tag_table_foreach(gtk_text_buffer_get_tag_table(imhtml->text_buffer), |
|
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
3151 _recalculate_font_sizes, imhtml); |
|
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
3152 |
|
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
3153 pango_font_description_set_size(font_desc, (gint)((double) imhtml->original_fsize * zoom)); |
|
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
3154 |
|
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
3155 s = gtk_widget_get_modifier_style(GTK_WIDGET(imhtml)); |
|
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
3156 s->font_desc = font_desc; |
|
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
3157 gtk_widget_modify_style(GTK_WIDGET(imhtml), s); |
|
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
3158 } |
|
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
3159 |
| 8677 | 3160 static GtkTextTag *find_font_size_tag(GtkIMHtml *imhtml, int size) |
| 3161 { | |
| 3162 gchar str[24]; | |
| 3163 GtkTextTag *tag; | |
| 3164 | |
|
8740
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
3165 if (!imhtml->original_fsize) |
|
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
3166 _init_original_fsize(imhtml); |
|
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
3167 |
| 8677 | 3168 g_snprintf(str, sizeof(str), "FONT SIZE %d", size); |
| 3169 str[23] = '\0'; | |
| 3170 | |
| 3171 tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), str); | |
| 3172 if (!tag) { | |
| 3173 /* For reasons I don't understand, setting "scale" here scaled based on some default | |
| 3174 * size other than my theme's default size. Our size 4 was actually smaller than | |
| 3175 * our size 3 for me. So this works around that oddity. | |
| 3176 */ | |
| 3177 tag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "size", | |
|
8740
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
3178 (gint) (imhtml->original_fsize * |
|
61a090413b93
[gaim-migrate @ 9495]
Christian Hammond <chipx86@chipx86.com>
parents:
8735
diff
changeset
|
3179 ((double) _point_sizes[size-1] * imhtml->zoom)), NULL); |
| 8061 | 3180 } |
| 3181 | |
| 8677 | 3182 return tag; |
| 3183 } | |
| 3184 | |
| 3185 static void remove_tag_by_prefix(GtkIMHtml *imhtml, const GtkTextIter *i, const GtkTextIter *e, | |
| 3186 const char *prefix, guint len, gboolean homo) | |
| 3187 { | |
| 3188 GSList *tags, *l; | |
| 3189 GtkTextIter iter; | |
| 3190 | |
| 3191 tags = gtk_text_iter_get_tags(i); | |
| 3192 | |
| 3193 for (l = tags; l; l = l->next) { | |
| 3194 GtkTextTag *tag = l->data; | |
| 3195 | |
| 3196 if (tag->name && !strncmp(tag->name, prefix, len)) | |
| 3197 gtk_text_buffer_remove_tag(imhtml->text_buffer, tag, i, e); | |
| 8061 | 3198 } |
| 3199 | |
| 8677 | 3200 g_slist_free(tags); |
| 3201 | |
| 3202 if (homo) | |
| 3203 return; | |
| 3204 | |
| 3205 iter = *i; | |
| 3206 | |
| 3207 while (gtk_text_iter_forward_char(&iter) && !gtk_text_iter_equal(&iter, e)) { | |
| 3208 if (gtk_text_iter_begins_tag(&iter, NULL)) { | |
| 3209 tags = gtk_text_iter_get_toggled_tags(&iter, TRUE); | |
| 3210 | |
| 3211 for (l = tags; l; l = l->next) { | |
| 3212 GtkTextTag *tag = l->data; | |
| 3213 | |
| 3214 if (tag->name && !strncmp(tag->name, prefix, len)) | |
| 3215 gtk_text_buffer_remove_tag(imhtml->text_buffer, tag, &iter, e); | |
| 3216 } | |
| 3217 | |
| 3218 g_slist_free(tags); | |
| 3219 } | |
| 8061 | 3220 } |
| 8677 | 3221 } |
| 3222 | |
| 3223 static void remove_font_size(GtkIMHtml *imhtml, GtkTextIter *i, GtkTextIter *e, gboolean homo) | |
| 3224 { | |
| 3225 remove_tag_by_prefix(imhtml, i, e, "FONT SIZE ", 10, homo); | |
| 3226 } | |
| 3227 | |
| 3228 static void remove_font_face(GtkIMHtml *imhtml, GtkTextIter *i, GtkTextIter *e, gboolean homo) | |
| 3229 { | |
| 3230 remove_tag_by_prefix(imhtml, i, e, "FONT FACE ", 10, homo); | |
| 3231 } | |
| 3232 | |
| 3233 static void remove_font_forecolor(GtkIMHtml *imhtml, GtkTextIter *i, GtkTextIter *e, gboolean homo) | |
| 3234 { | |
| 3235 remove_tag_by_prefix(imhtml, i, e, "FORECOLOR ", 10, homo); | |
| 3236 } | |
| 3237 | |
| 3238 static void remove_font_backcolor(GtkIMHtml *imhtml, GtkTextIter *i, GtkTextIter *e, gboolean homo) | |
| 3239 { | |
| 3240 remove_tag_by_prefix(imhtml, i, e, "BACKCOLOR ", 10, homo); | |
| 3241 } | |
| 3242 | |
| 3243 static void remove_font_link(GtkIMHtml *imhtml, GtkTextIter *i, GtkTextIter *e, gboolean homo) | |
| 3244 { | |
| 3245 remove_tag_by_prefix(imhtml, i, e, "LINK ", 5, homo); | |
| 3246 } | |
| 3247 | |
| 3248 /* Editable stuff */ | |
| 3249 static void preinsert_cb(GtkTextBuffer *buffer, GtkTextIter *iter, gchar *text, gint len, GtkIMHtml *imhtml) | |
| 3250 { | |
| 3251 imhtml->insert_offset = gtk_text_iter_get_offset(iter); | |
| 3252 } | |
| 3253 | |
| 3254 static void insert_cb(GtkTextBuffer *buffer, GtkTextIter *end, gchar *text, gint len, GtkIMHtml *imhtml) | |
| 3255 { | |
| 3256 GtkTextIter start; | |
| 3257 | |
| 3258 if (!len) | |
| 3259 return; | |
| 3260 | |
| 3261 start = *end; | |
| 3262 gtk_text_iter_set_offset(&start, imhtml->insert_offset); | |
| 3263 | |
| 3264 if (imhtml->edit.bold) | |
| 3265 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "BOLD", &start, end); | |
| 3266 else | |
| 3267 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "BOLD", &start, end); | |
| 3268 | |
| 3269 if (imhtml->edit.italic) | |
| 3270 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "ITALICS", &start, end); | |
| 3271 else | |
| 3272 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "ITALICS", &start, end); | |
| 3273 | |
| 3274 if (imhtml->edit.underline) | |
| 3275 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, end); | |
| 3276 else | |
| 3277 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, end); | |
| 3278 | |
| 3279 if (imhtml->edit.forecolor) { | |
| 3280 remove_font_forecolor(imhtml, &start, end, TRUE); | |
| 3281 gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
| 3282 find_font_forecolor_tag(imhtml, imhtml->edit.forecolor), | |
| 3283 &start, end); | |
| 8061 | 3284 } |
| 3285 | |
| 8677 | 3286 if (imhtml->edit.backcolor) { |
| 3287 remove_font_backcolor(imhtml, &start, end, TRUE); | |
| 3288 gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
| 3289 find_font_backcolor_tag(imhtml, imhtml->edit.backcolor), | |
| 3290 &start, end); | |
| 3291 } | |
| 3292 | |
| 3293 if (imhtml->edit.fontface) { | |
| 3294 remove_font_face(imhtml, &start, end, TRUE); | |
| 3295 gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
| 3296 find_font_face_tag(imhtml, imhtml->edit.fontface), | |
| 3297 &start, end); | |
| 8061 | 3298 } |
| 8677 | 3299 |
| 3300 if (imhtml->edit.fontsize) { | |
| 3301 remove_font_size(imhtml, &start, end, TRUE); | |
| 3302 gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
| 3303 find_font_size_tag(imhtml, imhtml->edit.fontsize), | |
| 3304 &start, end); | |
| 3305 } | |
| 3306 | |
| 3307 if (imhtml->edit.link) { | |
| 3308 remove_font_link(imhtml, &start, end, TRUE); | |
| 3309 gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
| 3310 imhtml->edit.link, | |
| 3311 &start, end); | |
| 3312 } | |
| 3313 | |
| 8061 | 3314 } |
| 3315 | |
| 3316 void gtk_imhtml_set_editable(GtkIMHtml *imhtml, gboolean editable) | |
| 3317 { | |
| 3318 gtk_text_view_set_editable(GTK_TEXT_VIEW(imhtml), editable); | |
| 8177 | 3319 /* |
| 3320 * We need a visible caret for accessibility, so mouseless | |
| 3321 * people can highlight stuff. | |
| 3322 */ | |
| 3323 /* gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(imhtml), editable); */ | |
| 8061 | 3324 imhtml->editable = editable; |
| 8677 | 3325 imhtml->format_functions = GTK_IMHTML_ALL; |
| 3326 | |
| 3327 if (editable) | |
| 3328 g_signal_connect_after(G_OBJECT(GTK_IMHTML(imhtml)->text_buffer), "mark-set", | |
| 3329 G_CALLBACK(mark_set_cb), imhtml); | |
| 3330 } | |
| 3331 | |
| 3332 void gtk_imhtml_set_whole_buffer_formatting_only(GtkIMHtml *imhtml, gboolean wbfo) | |
| 3333 { | |
| 3334 g_return_if_fail(imhtml != NULL); | |
| 3335 | |
| 3336 imhtml->wbfo = wbfo; | |
| 8420 | 3337 } |
| 3338 | |
| 3339 void gtk_imhtml_set_format_functions(GtkIMHtml *imhtml, GtkIMHtmlButtons buttons) | |
| 3340 { | |
| 3341 GObject *object = g_object_ref(G_OBJECT(imhtml)); | |
| 8677 | 3342 imhtml->format_functions = buttons; |
| 8420 | 3343 g_signal_emit(object, signals[BUTTONS_UPDATE], 0, buttons); |
| 3344 g_object_unref(object); | |
| 8061 | 3345 } |
| 3346 | |
| 8788 | 3347 GtkIMHtmlButtons gtk_imhtml_get_format_functions(GtkIMHtml *imhtml) |
| 3348 { | |
| 3349 return imhtml->format_functions; | |
| 3350 } | |
| 8516 | 3351 |
| 3352 void gtk_imhtml_get_current_format(GtkIMHtml *imhtml, gboolean *bold, | |
| 3353 gboolean *italic, gboolean *underline) | |
| 8481 | 3354 { |
| 8677 | 3355 if (imhtml->edit.bold) |
| 3356 (*bold) = TRUE; | |
| 3357 if (imhtml->edit.italic) | |
| 3358 (*italic) = TRUE; | |
| 3359 if (imhtml->edit.underline) | |
| 3360 (*underline) = TRUE; | |
| 8481 | 3361 } |
| 3362 | |
| 9025 | 3363 char * |
| 3364 gtk_imhtml_get_current_fontface(GtkIMHtml *imhtml) | |
| 3365 { | |
| 3366 if (imhtml->edit.fontface) | |
| 3367 return g_strdup(imhtml->edit.fontface); | |
| 3368 else | |
| 3369 return NULL; | |
| 3370 } | |
| 3371 | |
| 3372 char * | |
| 3373 gtk_imhtml_get_current_forecolor(GtkIMHtml *imhtml) | |
| 3374 { | |
| 3375 if (imhtml->edit.forecolor) | |
| 3376 return g_strdup(imhtml->edit.forecolor); | |
| 3377 else | |
| 3378 return NULL; | |
| 3379 } | |
| 3380 | |
| 3381 char * | |
| 3382 gtk_imhtml_get_current_backcolor(GtkIMHtml *imhtml) | |
| 3383 { | |
| 3384 if (imhtml->edit.backcolor) | |
| 3385 return g_strdup(imhtml->edit.backcolor); | |
| 3386 else | |
| 3387 return NULL; | |
| 3388 } | |
| 3389 | |
| 3390 gint | |
| 3391 gtk_imhtml_get_current_fontsize(GtkIMHtml *imhtml) | |
| 3392 { | |
| 3393 return imhtml->edit.fontsize; | |
| 3394 } | |
| 3395 | |
| 8061 | 3396 gboolean gtk_imhtml_get_editable(GtkIMHtml *imhtml) |
| 3397 { | |
| 3398 return imhtml->editable; | |
| 3399 } | |
| 3400 | |
| 8677 | 3401 /* |
| 3402 * I had this crazy idea about changing the text cursor color to reflex the foreground color | |
| 3403 * of the text about to be entered. This is the place you'd do it, along with the place where | |
| 3404 * we actually set a new foreground color. | |
| 3405 * I may not do this, because people will bitch about Gaim overriding their gtk theme's cursor | |
| 3406 * colors. | |
| 3407 * | |
| 3408 * Just in case I do do this, I asked about what to set the secondary text cursor to. | |
| 3409 * | |
| 8719 | 3410 * (12:45:27) ?? ???: secondary_cursor_color = (rgb(background) + rgb(primary_cursor_color) ) / 2 |
| 3411 * (12:45:55) ?? ???: understand? | |
| 8677 | 3412 * (12:46:14) Tim: yeah. i didn't know there was an exact formula |
|
8735
92cbf9713795
[gaim-migrate @ 9490]
Christian Hammond <chipx86@chipx86.com>
parents:
8729
diff
changeset
|
3413 * (12:46:56) ?? ???: u might need to extract separate each color from RGB |
| 8677 | 3414 */ |
| 3415 | |
| 3416 static void mark_set_cb(GtkTextBuffer *buffer, GtkTextIter *arg1, GtkTextMark *mark, | |
| 3417 GtkIMHtml *imhtml) | |
| 3418 { | |
| 3419 GSList *tags, *l; | |
| 3420 GtkTextIter iter; | |
| 3421 | |
| 3422 if (mark != gtk_text_buffer_get_insert(buffer)) | |
| 3423 return; | |
| 3424 | |
| 3425 if (!gtk_text_buffer_get_char_count(buffer)) | |
| 3426 return; | |
| 3427 | |
| 3428 imhtml->edit.bold = imhtml->edit.italic = imhtml->edit.underline = FALSE; | |
| 3429 if (imhtml->edit.forecolor) | |
| 3430 g_free(imhtml->edit.forecolor); | |
| 3431 imhtml->edit.forecolor = NULL; | |
| 3432 if (imhtml->edit.backcolor) | |
| 3433 g_free(imhtml->edit.backcolor); | |
| 3434 imhtml->edit.backcolor = NULL; | |
| 3435 if (imhtml->edit.fontface) | |
| 3436 g_free(imhtml->edit.fontface); | |
| 3437 imhtml->edit.fontface = NULL; | |
| 3438 imhtml->edit.fontsize = 0; | |
| 3439 imhtml->edit.link = NULL; | |
| 3440 | |
| 3441 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, mark); | |
| 3442 | |
| 3443 | |
| 3444 if (gtk_text_iter_is_end(&iter)) | |
| 3445 tags = gtk_text_iter_get_toggled_tags(&iter, FALSE); | |
| 3446 else | |
| 3447 tags = gtk_text_iter_get_tags(&iter); | |
| 3448 | |
| 3449 for (l = tags; l != NULL; l = l->next) { | |
| 3450 GtkTextTag *tag = GTK_TEXT_TAG(l->data); | |
| 3451 | |
| 3452 if (tag->name) { | |
| 3453 if (strcmp(tag->name, "BOLD") == 0) | |
| 3454 imhtml->edit.bold = TRUE; | |
| 3455 if (strcmp(tag->name, "ITALICS") == 0) | |
| 3456 imhtml->edit.italic = TRUE; | |
| 3457 if (strcmp(tag->name, "UNDERLINE") == 0) | |
| 3458 imhtml->edit.underline = TRUE; | |
| 3459 if (strncmp(tag->name, "FORECOLOR ", 10) == 0) | |
| 3460 imhtml->edit.forecolor = g_strdup(&(tag->name)[10]); | |
| 3461 if (strncmp(tag->name, "BACKCOLOR ", 10) == 0) | |
| 3462 imhtml->edit.backcolor = g_strdup(&(tag->name)[10]); | |
| 3463 if (strncmp(tag->name, "FONT FACE ", 10) == 0) | |
| 3464 imhtml->edit.fontface = g_strdup(&(tag->name)[10]); | |
| 3465 if (strncmp(tag->name, "FONT SIZE ", 10) == 0) | |
| 3466 imhtml->edit.fontsize = strtol(&(tag->name)[10], NULL, 10); | |
| 8719 | 3467 if ((strncmp(tag->name, "LINK ", 5) == 0) && !gtk_text_iter_is_end(&iter)) |
| 8677 | 3468 imhtml->edit.link = tag; |
| 3469 } | |
| 3470 } | |
| 3471 | |
| 3472 g_slist_free(tags); | |
| 3473 } | |
| 3474 | |
| 8061 | 3475 gboolean gtk_imhtml_toggle_bold(GtkIMHtml *imhtml) |
| 3476 { | |
| 8481 | 3477 GObject *object; |
| 8677 | 3478 GtkTextIter start, end; |
| 3479 | |
| 3480 imhtml->edit.bold = !imhtml->edit.bold; | |
| 3481 | |
| 3482 if (imhtml->wbfo) { | |
| 3483 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
| 3484 if (imhtml->edit.bold) | |
| 3485 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end); | |
| 3486 else | |
| 3487 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end); | |
| 3488 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { | |
| 3489 if (imhtml->edit.bold) | |
| 3490 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end); | |
| 3491 else | |
| 3492 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end); | |
| 3493 | |
| 8061 | 3494 } |
| 8481 | 3495 object = g_object_ref(G_OBJECT(imhtml)); |
| 3496 g_signal_emit(object, signals[TOGGLE_FORMAT], 0, GTK_IMHTML_BOLD); | |
| 3497 g_object_unref(object); | |
| 3498 | |
| 8677 | 3499 return (imhtml->edit.bold != FALSE); |
| 8061 | 3500 } |
| 3501 | |
| 3502 gboolean gtk_imhtml_toggle_italic(GtkIMHtml *imhtml) | |
| 3503 { | |
| 8481 | 3504 GObject *object; |
| 8677 | 3505 GtkTextIter start, end; |
| 3506 | |
| 3507 imhtml->edit.italic = !imhtml->edit.italic; | |
| 3508 | |
| 3509 if (imhtml->wbfo) { | |
| 3510 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
| 3511 if (imhtml->edit.italic) | |
| 3512 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end); | |
| 3513 else | |
| 3514 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end); | |
| 3515 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { | |
| 3516 if (imhtml->edit.italic) | |
| 3517 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end); | |
| 3518 else | |
| 3519 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end); | |
| 8061 | 3520 } |
| 8481 | 3521 object = g_object_ref(G_OBJECT(imhtml)); |
| 3522 g_signal_emit(object, signals[TOGGLE_FORMAT], 0, GTK_IMHTML_ITALIC); | |
| 3523 g_object_unref(object); | |
| 3524 | |
| 8677 | 3525 return imhtml->edit.italic != FALSE; |
| 8061 | 3526 } |
| 3527 | |
| 3528 gboolean gtk_imhtml_toggle_underline(GtkIMHtml *imhtml) | |
| 3529 { | |
| 8481 | 3530 GObject *object; |
| 8677 | 3531 GtkTextIter start, end; |
| 3532 | |
| 3533 imhtml->edit.underline = !imhtml->edit.underline; | |
| 3534 | |
| 3535 if (imhtml->wbfo) { | |
| 3536 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
| 3537 if (imhtml->edit.underline) | |
| 3538 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end); | |
| 3539 else | |
| 3540 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end); | |
| 3541 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { | |
| 3542 if (imhtml->edit.underline) | |
| 3543 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end); | |
| 3544 else | |
| 3545 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end); | |
| 8061 | 3546 } |
| 8481 | 3547 object = g_object_ref(G_OBJECT(imhtml)); |
| 3548 g_signal_emit(object, signals[TOGGLE_FORMAT], 0, GTK_IMHTML_UNDERLINE); | |
| 3549 g_object_unref(object); | |
| 3550 | |
| 8677 | 3551 return imhtml->edit.underline != FALSE; |
| 8061 | 3552 } |
| 3553 | |
| 3554 void gtk_imhtml_font_set_size(GtkIMHtml *imhtml, gint size) | |
| 3555 { | |
| 9025 | 3556 GObject *object; |
| 8677 | 3557 GtkTextIter start, end; |
| 9025 | 3558 GtkIMHtmlButtons b = 0; |
| 8061 | 3559 |
| 3560 imhtml->edit.fontsize = size; | |
| 3561 | |
| 8677 | 3562 |
| 3563 if (imhtml->wbfo) { | |
| 3564 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
| 3565 remove_font_size(imhtml, &start, &end, TRUE); | |
| 3566 gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
| 3567 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); | |
| 3568 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { | |
| 3569 remove_font_size(imhtml, &start, &end, FALSE); | |
| 3570 gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
| 3571 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); | |
| 8061 | 3572 } |
| 8677 | 3573 |
| 9025 | 3574 object = g_object_ref(G_OBJECT(imhtml)); |
| 3575 b |= GTK_IMHTML_SHRINK; | |
| 3576 b |= GTK_IMHTML_GROW; | |
| 3577 g_signal_emit(object, signals[TOGGLE_FORMAT], 0, b); | |
| 3578 g_object_unref(object); | |
| 8061 | 3579 } |
| 3580 | |
| 3581 void gtk_imhtml_font_shrink(GtkIMHtml *imhtml) | |
| 3582 { | |
| 9025 | 3583 GObject *object; |
| 8677 | 3584 GtkTextIter start, end; |
| 3585 | |
| 8061 | 3586 if (imhtml->edit.fontsize == 1) |
| 3587 return; | |
| 3588 | |
| 8677 | 3589 if (!imhtml->edit.fontsize) |
| 3590 imhtml->edit.fontsize = 2; | |
| 3591 else | |
| 3592 imhtml->edit.fontsize--; | |
| 3593 | |
| 3594 if (imhtml->wbfo) { | |
| 3595 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
| 3596 remove_font_size(imhtml, &start, &end, TRUE); | |
| 3597 gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
| 3598 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); | |
| 3599 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { | |
| 3600 remove_font_size(imhtml, &start, &end, FALSE); | |
| 3601 gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
| 3602 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); | |
| 8061 | 3603 } |
| 9025 | 3604 object = g_object_ref(G_OBJECT(imhtml)); |
| 3605 g_signal_emit(object, signals[TOGGLE_FORMAT], 0, GTK_IMHTML_SHRINK); | |
| 3606 g_object_unref(object); | |
| 8061 | 3607 } |
| 3608 | |
| 3609 void gtk_imhtml_font_grow(GtkIMHtml *imhtml) | |
| 3610 { | |
| 9025 | 3611 GObject *object; |
| 8677 | 3612 GtkTextIter start, end; |
| 3613 | |
| 8061 | 3614 if (imhtml->edit.fontsize == MAX_FONT_SIZE) |
| 3615 return; | |
| 3616 | |
| 8677 | 3617 if (!imhtml->edit.fontsize) |
| 3618 imhtml->edit.fontsize = 4; | |
| 3619 else | |
| 3620 imhtml->edit.fontsize++; | |
| 3621 | |
| 3622 if (imhtml->wbfo) { | |
| 3623 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
| 3624 remove_font_size(imhtml, &start, &end, TRUE); | |
| 3625 gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
| 3626 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); | |
| 3627 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { | |
| 3628 remove_font_size(imhtml, &start, &end, FALSE); | |
| 3629 gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
| 3630 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); | |
| 8061 | 3631 } |
| 9025 | 3632 object = g_object_ref(G_OBJECT(imhtml)); |
| 3633 g_signal_emit(object, signals[TOGGLE_FORMAT], 0, GTK_IMHTML_GROW); | |
| 3634 g_object_unref(object); | |
| 8061 | 3635 } |
| 3636 | |
| 3637 gboolean gtk_imhtml_toggle_forecolor(GtkIMHtml *imhtml, const char *color) | |
| 3638 { | |
| 9025 | 3639 GObject *object; |
| 8677 | 3640 GtkTextIter start, end; |
| 3641 | |
| 3642 if (imhtml->edit.forecolor != NULL) | |
| 3643 g_free(imhtml->edit.forecolor); | |
| 3644 | |
| 9025 | 3645 if (color && strcmp(color, "") != 0) { |
| 8677 | 3646 imhtml->edit.forecolor = g_strdup(color); |
| 3647 if (imhtml->wbfo) { | |
| 3648 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
| 3649 remove_font_forecolor(imhtml, &start, &end, TRUE); | |
| 3650 gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
| 3651 find_font_forecolor_tag(imhtml, imhtml->edit.forecolor), &start, &end); | |
| 3652 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { | |
| 3653 remove_font_forecolor(imhtml, &start, &end, FALSE); | |
| 3654 gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
| 3655 find_font_forecolor_tag(imhtml, imhtml->edit.forecolor), | |
| 3656 &start, &end); | |
| 3657 } | |
| 8061 | 3658 } else { |
| 3659 imhtml->edit.forecolor = NULL; | |
| 9025 | 3660 if (imhtml->wbfo) { |
| 3661 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
| 3662 remove_font_forecolor(imhtml, &start, &end, TRUE); | |
| 3663 } | |
| 8061 | 3664 } |
| 3665 | |
| 9025 | 3666 object = g_object_ref(G_OBJECT(imhtml)); |
| 3667 g_signal_emit(object, signals[TOGGLE_FORMAT], 0, GTK_IMHTML_FORECOLOR); | |
| 3668 g_object_unref(object); | |
| 3669 | |
| 8061 | 3670 return imhtml->edit.forecolor != NULL; |
| 3671 } | |
| 3672 | |
| 3673 gboolean gtk_imhtml_toggle_backcolor(GtkIMHtml *imhtml, const char *color) | |
| 3674 { | |
| 9025 | 3675 GObject *object; |
| 8677 | 3676 GtkTextIter start, end; |
| 3677 | |
| 3678 if (imhtml->edit.backcolor != NULL) | |
| 3679 g_free(imhtml->edit.backcolor); | |
| 3680 | |
| 9025 | 3681 if (color && strcmp(color, "") != 0) { |
| 8677 | 3682 imhtml->edit.backcolor = g_strdup(color); |
| 3683 | |
| 3684 if (imhtml->wbfo) { | |
| 3685 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
| 3686 remove_font_backcolor(imhtml, &start, &end, TRUE); | |
| 3687 gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
| 3688 find_font_backcolor_tag(imhtml, imhtml->edit.backcolor), &start, &end); | |
| 3689 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { | |
| 3690 remove_font_backcolor(imhtml, &start, &end, FALSE); | |
| 3691 gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
| 3692 find_font_backcolor_tag(imhtml, | |
| 3693 imhtml->edit.backcolor), &start, &end); | |
| 3694 } | |
| 8061 | 3695 } else { |
| 3696 imhtml->edit.backcolor = NULL; | |
| 9025 | 3697 if (imhtml->wbfo) { |
| 3698 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
| 3699 remove_font_backcolor(imhtml, &start, &end, TRUE); | |
| 3700 } | |
| 8061 | 3701 } |
| 8677 | 3702 |
| 9025 | 3703 object = g_object_ref(G_OBJECT(imhtml)); |
| 3704 g_signal_emit(object, signals[TOGGLE_FORMAT], 0, GTK_IMHTML_BACKCOLOR); | |
| 3705 g_object_unref(object); | |
| 3706 | |
| 8061 | 3707 return imhtml->edit.backcolor != NULL; |
| 3708 } | |
| 3709 | |
| 3710 gboolean gtk_imhtml_toggle_fontface(GtkIMHtml *imhtml, const char *face) | |
| 3711 { | |
| 9025 | 3712 GObject *object; |
| 8677 | 3713 GtkTextIter start, end; |
| 3714 | |
| 3715 if (imhtml->edit.fontface != NULL) | |
| 3716 g_free(imhtml->edit.fontface); | |
| 3717 | |
| 9025 | 3718 if (face && strcmp(face, "") != 0) { |
| 8677 | 3719 imhtml->edit.fontface = g_strdup(face); |
| 3720 | |
| 3721 if (imhtml->wbfo) { | |
| 3722 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
| 3723 remove_font_face(imhtml, &start, &end, TRUE); | |
| 3724 gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
| 3725 find_font_face_tag(imhtml, imhtml->edit.fontface), &start, &end); | |
| 3726 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { | |
| 3727 remove_font_face(imhtml, &start, &end, FALSE); | |
| 3728 gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
| 3729 find_font_face_tag(imhtml, imhtml->edit.fontface), | |
| 3730 &start, &end); | |
| 3731 } | |
| 8061 | 3732 } else { |
| 3733 imhtml->edit.fontface = NULL; | |
| 9025 | 3734 if (imhtml->wbfo) { |
| 3735 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
| 3736 remove_font_face(imhtml, &start, &end, TRUE); | |
| 3737 } | |
| 8061 | 3738 } |
| 8677 | 3739 |
| 9025 | 3740 object = g_object_ref(G_OBJECT(imhtml)); |
| 3741 g_signal_emit(object, signals[TOGGLE_FORMAT], 0, GTK_IMHTML_FACE); | |
| 3742 g_object_unref(object); | |
| 3743 | |
| 8061 | 3744 return imhtml->edit.fontface != NULL; |
| 3745 } | |
| 3746 | |
| 8677 | 3747 void gtk_imhtml_toggle_link(GtkIMHtml *imhtml, const char *url) |
| 8061 | 3748 { |
| 9025 | 3749 GObject *object; |
| 8677 | 3750 GtkTextIter start, end; |
| 3751 GtkTextTag *linktag; | |
| 3752 static guint linkno = 0; | |
| 3753 gchar str[48]; | |
| 9007 | 3754 GdkColor *color = NULL; |
| 8677 | 3755 |
| 3756 imhtml->edit.link = NULL; | |
| 3757 | |
| 3758 | |
| 3759 | |
| 3760 if (url) { | |
| 3761 g_snprintf(str, sizeof(str), "LINK %d", linkno++); | |
| 3762 str[47] = '\0'; | |
| 3763 | |
| 9007 | 3764 gtk_widget_style_get(GTK_WIDGET(imhtml), "hyperlink-color", &color, NULL); |
| 9008 | 3765 if (color) { |
| 9007 | 3766 imhtml->edit.link = linktag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "foreground-gdk", color, "underline", PANGO_UNDERLINE_SINGLE, NULL); |
| 9008 | 3767 gdk_color_free(color); |
| 3768 } else { | |
| 9007 | 3769 imhtml->edit.link = linktag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "foreground", "blue", "underline", PANGO_UNDERLINE_SINGLE, NULL); |
| 9008 | 3770 } |
| 8677 | 3771 g_object_set_data_full(G_OBJECT(linktag), "link_url", g_strdup(url), g_free); |
| 3772 g_signal_connect(G_OBJECT(linktag), "event", G_CALLBACK(tag_event), NULL); | |
| 3773 | |
| 3774 if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { | |
| 3775 remove_font_link(imhtml, &start, &end, FALSE); | |
| 3776 gtk_text_buffer_apply_tag(imhtml->text_buffer, linktag, &start, &end); | |
| 3777 } | |
| 3778 } | |
| 9025 | 3779 |
| 3780 object = g_object_ref(G_OBJECT(imhtml)); | |
| 3781 g_signal_emit(object, signals[TOGGLE_FORMAT], 0, GTK_IMHTML_LINK); | |
| 3782 g_object_unref(object); | |
| 8677 | 3783 } |
| 3784 | |
| 3785 void gtk_imhtml_insert_link(GtkIMHtml *imhtml, GtkTextMark *mark, const char *url, const char *text) | |
| 3786 { | |
| 8061 | 3787 GtkTextIter iter; |
| 8677 | 3788 |
| 9599 | 3789 if (gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, NULL, NULL)) |
| 3790 gtk_text_buffer_delete_selection(imhtml->text_buffer, TRUE, TRUE); | |
| 3791 | |
| 8677 | 3792 gtk_imhtml_toggle_link(imhtml, url); |
| 8061 | 3793 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, mark); |
| 8677 | 3794 gtk_text_buffer_insert(imhtml->text_buffer, &iter, text, -1); |
| 3795 gtk_imhtml_toggle_link(imhtml, NULL); | |
| 8061 | 3796 } |
| 3797 | |
| 3798 void gtk_imhtml_insert_smiley(GtkIMHtml *imhtml, const char *sml, char *smiley) | |
| 3799 { | |
| 8677 | 3800 GtkTextMark *mark; |
| 8061 | 3801 GtkTextIter iter; |
| 8677 | 3802 |
| 3803 mark = gtk_text_buffer_get_insert(imhtml->text_buffer); | |
| 3804 | |
| 3805 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, mark); | |
| 3806 gtk_imhtml_insert_smiley_at_iter(imhtml, sml, smiley, &iter); | |
| 3807 } | |
| 3808 | |
| 3809 void gtk_imhtml_insert_smiley_at_iter(GtkIMHtml *imhtml, const char *sml, char *smiley, GtkTextIter *iter) | |
| 3810 { | |
| 8061 | 3811 GdkPixbuf *pixbuf = NULL; |
| 3812 GdkPixbufAnimation *annipixbuf = NULL; | |
| 3813 GtkWidget *icon = NULL; | |
| 3814 GtkTextChildAnchor *anchor; | |
| 8505 | 3815 char *unescaped = gaim_unescape_html(smiley); |
| 8061 | 3816 |
| 8505 | 3817 annipixbuf = gtk_smiley_tree_image(imhtml, sml, unescaped); |
| 8061 | 3818 if(annipixbuf) { |
| 3819 if(gdk_pixbuf_animation_is_static_image(annipixbuf)) { | |
| 3820 pixbuf = gdk_pixbuf_animation_get_static_image(annipixbuf); | |
| 3821 if(pixbuf) | |
| 3822 icon = gtk_image_new_from_pixbuf(pixbuf); | |
| 3823 } else { | |
| 3824 icon = gtk_image_new_from_animation(annipixbuf); | |
| 3825 } | |
| 3826 } | |
| 3827 | |
| 3828 if (icon) { | |
| 8890 | 3829 anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, iter); |
| 3830 g_object_set_data_full(G_OBJECT(anchor), "gtkimhtml_plaintext", g_strdup(unescaped), g_free); | |
| 3831 g_object_set_data_full(G_OBJECT(anchor), "gtkimhtml_htmltext", g_strdup(smiley), g_free); | |
| 3832 | |
| 8061 | 3833 gtk_widget_show(icon); |
| 3834 gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(imhtml), icon, anchor); | |
| 8890 | 3835 } else { |
| 3836 gtk_text_buffer_insert(imhtml->text_buffer, iter, smiley, -1); | |
| 8061 | 3837 } |
| 8890 | 3838 |
| 3839 g_free(unescaped); | |
| 8061 | 3840 } |
| 3841 | |
| 8962 | 3842 void gtk_imhtml_insert_image_at_iter(GtkIMHtml *imhtml, int id, GtkTextIter *iter) |
| 3843 { | |
| 3844 GdkPixbuf *pixbuf = NULL; | |
| 3845 const char *filename = NULL; | |
| 3846 gpointer image; | |
| 3847 GdkRectangle rect; | |
| 3848 GtkIMHtmlScalable *scalable = NULL; | |
| 3849 int minus; | |
| 3850 | |
| 3851 if (!imhtml->funcs || !imhtml->funcs->image_get || | |
| 3852 !imhtml->funcs->image_get_size || !imhtml->funcs->image_get_data || | |
| 3853 !imhtml->funcs->image_get_filename || !imhtml->funcs->image_ref || | |
| 3854 !imhtml->funcs->image_unref) | |
| 3855 return; | |
| 3856 | |
| 3857 image = imhtml->funcs->image_get(id); | |
| 3858 | |
| 3859 if (image) { | |
| 3860 gpointer data; | |
| 3861 size_t len; | |
| 3862 | |
| 3863 data = imhtml->funcs->image_get_data(image); | |
| 3864 len = imhtml->funcs->image_get_size(image); | |
| 3865 | |
| 3866 if (data && len) { | |
| 3867 GdkPixbufLoader *loader = gdk_pixbuf_loader_new(); | |
| 3868 gdk_pixbuf_loader_write(loader, data, len, NULL); | |
| 3869 pixbuf = gdk_pixbuf_loader_get_pixbuf(loader); | |
| 9337 | 3870 if (pixbuf) |
| 3871 g_object_ref(G_OBJECT(pixbuf)); | |
| 8962 | 3872 gdk_pixbuf_loader_close(loader, NULL); |
| 9337 | 3873 g_object_unref(G_OBJECT(loader)); |
| 8962 | 3874 } |
| 3875 | |
| 3876 } | |
| 3877 | |
| 3878 if (pixbuf) { | |
| 3879 filename = imhtml->funcs->image_get_filename(image); | |
| 3880 imhtml->funcs->image_ref(id); | |
| 3881 imhtml->im_images = g_slist_prepend(imhtml->im_images, GINT_TO_POINTER(id)); | |
| 3882 } else { | |
| 3883 pixbuf = gtk_widget_render_icon(GTK_WIDGET(imhtml), GTK_STOCK_MISSING_IMAGE, | |
| 3884 GTK_ICON_SIZE_BUTTON, "gtkimhtml-missing-image"); | |
| 3885 } | |
| 3886 | |
| 3887 scalable = gtk_imhtml_image_new(pixbuf, filename, id); | |
| 3888 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); | |
| 3889 scalable->add_to(scalable, imhtml, iter); | |
| 3890 minus = gtk_text_view_get_left_margin(GTK_TEXT_VIEW(imhtml)) + | |
| 3891 gtk_text_view_get_right_margin(GTK_TEXT_VIEW(imhtml)); | |
| 3892 scalable->scale(scalable, rect.width - minus, rect.height); | |
| 3893 imhtml->scalables = g_list_append(imhtml->scalables, scalable); | |
| 3894 | |
| 3895 g_object_unref(G_OBJECT(pixbuf)); | |
| 3896 } | |
| 3897 | |
| 8677 | 3898 static const gchar *tag_to_html_start(GtkTextTag *tag) |
| 8061 | 3899 { |
| 8677 | 3900 const gchar *name; |
| 3901 static gchar buf[1024]; | |
| 3902 | |
| 3903 name = tag->name; | |
| 3904 g_return_val_if_fail(name != NULL, ""); | |
| 3905 | |
| 3906 if (strcmp(name, "BOLD") == 0) { | |
| 3907 return "<b>"; | |
| 3908 } else if (strcmp(name, "ITALICS") == 0) { | |
| 3909 return "<i>"; | |
| 3910 } else if (strcmp(name, "UNDERLINE") == 0) { | |
| 3911 return "<u>"; | |
| 3912 } else if (strncmp(name, "LINK ", 5) == 0) { | |
| 3913 char *tmp = g_object_get_data(G_OBJECT(tag), "link_url"); | |
| 3914 if (tmp) { | |
| 3915 g_snprintf(buf, sizeof(buf), "<a href=\"%s\">", tmp); | |
| 3916 buf[sizeof(buf)-1] = '\0'; | |
| 3917 return buf; | |
| 3918 } else { | |
| 3919 return ""; | |
| 3920 } | |
| 3921 } else if (strncmp(name, "FORECOLOR ", 10) == 0) { | |
| 3922 g_snprintf(buf, sizeof(buf), "<font color=\"%s\">", &name[10]); | |
| 3923 return buf; | |
| 3924 } else if (strncmp(name, "BACKCOLOR ", 10) == 0) { | |
| 3925 g_snprintf(buf, sizeof(buf), "<font back=\"%s\">", &name[10]); | |
| 3926 return buf; | |
| 3927 } else if (strncmp(name, "FONT FACE ", 10) == 0) { | |
| 3928 g_snprintf(buf, sizeof(buf), "<font face=\"%s\">", &name[10]); | |
| 3929 return buf; | |
| 3930 } else if (strncmp(name, "FONT SIZE ", 10) == 0) { | |
| 3931 g_snprintf(buf, sizeof(buf), "<font size=\"%s\">", &name[10]); | |
| 3932 return buf; | |
| 3933 } else { | |
| 3934 return ""; | |
| 3935 } | |
| 8061 | 3936 } |
| 3937 | |
| 8677 | 3938 static const gchar *tag_to_html_end(GtkTextTag *tag) |
| 8061 | 3939 { |
| 8677 | 3940 const gchar *name; |
| 3941 | |
| 3942 name = tag->name; | |
| 3943 g_return_val_if_fail(name != NULL, ""); | |
| 3944 | |
| 3945 if (strcmp(name, "BOLD") == 0) { | |
| 3946 return "</b>"; | |
| 3947 } else if (strcmp(name, "ITALICS") == 0) { | |
| 3948 return "</i>"; | |
| 3949 } else if (strcmp(name, "UNDERLINE") == 0) { | |
| 3950 return "</u>"; | |
| 3951 } else if (strncmp(name, "LINK ", 5) == 0) { | |
| 3952 return "</a>"; | |
| 3953 } else if (strncmp(name, "FORECOLOR ", 10) == 0) { | |
| 3954 return "</font>"; | |
| 3955 } else if (strncmp(name, "BACKCOLOR ", 10) == 0) { | |
| 3956 return "</font>"; | |
| 3957 } else if (strncmp(name, "FONT FACE ", 10) == 0) { | |
| 3958 return "</font>"; | |
| 3959 } else if (strncmp(name, "FONT SIZE ", 10) == 0) { | |
| 3960 return "</font>"; | |
| 3961 } else { | |
| 3962 return ""; | |
| 3963 } | |
| 3964 } | |
| 3965 | |
| 3966 static gboolean tag_ends_here(GtkTextTag *tag, GtkTextIter *iter, GtkTextIter *niter) | |
| 3967 { | |
| 3968 return ((gtk_text_iter_has_tag(iter, GTK_TEXT_TAG(tag)) && | |
| 3969 !gtk_text_iter_has_tag(niter, GTK_TEXT_TAG(tag))) || | |
| 3970 gtk_text_iter_is_end(niter)); | |
| 8061 | 3971 } |
| 3972 | |
| 3973 /* Basic notion here: traverse through the text buffer one-by-one, non-character elements, such | |
| 3974 * as smileys and IM images are represented by the Unicode "unknown" character. Handle them. Else | |
| 8677 | 3975 * check for tags that are toggled on, insert their html form, and push them on the queue. Then insert |
| 3976 * the actual text. Then check for tags that are toggled off and insert them, after checking the queue. | |
|
8735
92cbf9713795
[gaim-migrate @ 9490]
Christian Hammond <chipx86@chipx86.com>
parents:
8729
diff
changeset
|
3977 * Finally, replace <, >, &, and " with their HTML equivalent. |
| 8677 | 3978 */ |
| 8061 | 3979 char *gtk_imhtml_get_markup_range(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *end) |
| 3980 { | |
| 3981 gunichar c; | |
| 8677 | 3982 GtkTextIter iter, nextiter; |
| 8061 | 3983 GString *str = g_string_new(""); |
| 8677 | 3984 GSList *tags, *sl; |
| 3985 GQueue *q, *r; | |
| 3986 GtkTextTag *tag; | |
| 3987 | |
| 3988 q = g_queue_new(); | |
| 3989 r = g_queue_new(); | |
| 3990 | |
| 8061 | 3991 |
| 3992 gtk_text_iter_order(start, end); | |
| 8677 | 3993 nextiter = iter = *start; |
| 3994 gtk_text_iter_forward_char(&nextiter); | |
| 3995 | |
| 9071 | 3996 /* First add the tags that are already in progress (we don't care about non-printing tags)*/ |
| 8677 | 3997 tags = gtk_text_iter_get_tags(start); |
| 3998 | |
| 3999 for (sl = tags; sl; sl = sl->next) { | |
| 4000 tag = sl->data; | |
| 4001 if (!gtk_text_iter_toggles_tag(start, GTK_TEXT_TAG(tag))) { | |
| 9071 | 4002 if (strlen(tag_to_html_end(tag)) > 0) |
| 4003 g_string_append(str, tag_to_html_start(tag)); | |
| 8677 | 4004 g_queue_push_tail(q, tag); |
| 8061 | 4005 } |
| 4006 } | |
| 8677 | 4007 g_slist_free(tags); |
| 8061 | 4008 |
| 4009 while ((c = gtk_text_iter_get_char(&iter)) != 0 && !gtk_text_iter_equal(&iter, end)) { | |
| 8677 | 4010 |
| 4011 tags = gtk_text_iter_get_tags(&iter); | |
| 4012 | |
| 4013 for (sl = tags; sl; sl = sl->next) { | |
| 4014 tag = sl->data; | |
| 4015 if (gtk_text_iter_begins_tag(&iter, GTK_TEXT_TAG(tag))) { | |
| 9071 | 4016 if (strlen(tag_to_html_end(tag)) > 0) |
| 4017 g_string_append(str, tag_to_html_start(tag)); | |
| 8677 | 4018 g_queue_push_tail(q, tag); |
| 4019 } | |
| 4020 } | |
| 4021 | |
| 4022 | |
| 8061 | 4023 if (c == 0xFFFC) { |
| 4024 GtkTextChildAnchor* anchor = gtk_text_iter_get_child_anchor(&iter); | |
| 9071 | 4025 if (anchor) { |
| 4026 char *text = g_object_get_data(G_OBJECT(anchor), "gtkimhtml_htmltext"); | |
| 4027 if (text) | |
| 4028 str = g_string_append(str, text); | |
| 4029 } | |
| 8677 | 4030 } else if (c == '<') { |
| 4031 str = g_string_append(str, "<"); | |
| 4032 } else if (c == '>') { | |
| 4033 str = g_string_append(str, ">"); | |
| 4034 } else if (c == '&') { | |
| 4035 str = g_string_append(str, "&"); | |
| 4036 } else if (c == '"') { | |
| 4037 str = g_string_append(str, """); | |
| 4038 } else if (c == '\n') { | |
| 4039 str = g_string_append(str, "<br>"); | |
| 8061 | 4040 } else { |
| 8677 | 4041 str = g_string_append_unichar(str, c); |
| 4042 } | |
| 4043 | |
| 4044 tags = g_slist_reverse(tags); | |
| 4045 for (sl = tags; sl; sl = sl->next) { | |
| 4046 tag = sl->data; | |
| 9071 | 4047 /** don't worry about non-printing tags ending */ |
| 4048 if (tag_ends_here(tag, &iter, &nextiter) && strlen(tag_to_html_end(tag)) > 0) { | |
| 8677 | 4049 |
| 4050 GtkTextTag *tmp; | |
| 4051 | |
| 4052 while ((tmp = g_queue_pop_tail(q)) != tag) { | |
| 4053 if (tmp == NULL) | |
| 4054 break; | |
| 4055 | |
| 9071 | 4056 if (!tag_ends_here(tmp, &iter, &nextiter) && strlen(tag_to_html_end(tmp)) > 0) |
| 8677 | 4057 g_queue_push_tail(r, tmp); |
| 4058 g_string_append(str, tag_to_html_end(GTK_TEXT_TAG(tmp))); | |
| 4059 } | |
| 4060 | |
| 4061 if (tmp == NULL) | |
| 4062 gaim_debug_warning("gtkimhtml", "empty queue, more closing tags than open tags!\n"); | |
| 4063 else | |
| 4064 g_string_append(str, tag_to_html_end(GTK_TEXT_TAG(tag))); | |
| 4065 | |
| 4066 while ((tmp = g_queue_pop_head(r))) { | |
| 4067 g_string_append(str, tag_to_html_start(GTK_TEXT_TAG(tmp))); | |
| 4068 g_queue_push_tail(q, tmp); | |
| 8061 | 4069 } |
| 4070 } | |
| 4071 } | |
| 8677 | 4072 |
| 4073 g_slist_free(tags); | |
| 8061 | 4074 gtk_text_iter_forward_char(&iter); |
| 8677 | 4075 gtk_text_iter_forward_char(&nextiter); |
| 8061 | 4076 } |
| 8677 | 4077 |
| 4078 while ((tag = g_queue_pop_tail(q))) | |
| 4079 g_string_append(str, tag_to_html_end(GTK_TEXT_TAG(tag))); | |
| 4080 | |
| 4081 g_queue_free(q); | |
| 4082 g_queue_free(r); | |
| 8061 | 4083 return g_string_free(str, FALSE); |
| 4084 } | |
| 4085 | |
| 8698 | 4086 void gtk_imhtml_close_tags(GtkIMHtml *imhtml, GtkTextIter *iter) |
| 8061 | 4087 { |
| 4088 if (imhtml->edit.bold) | |
| 4089 gtk_imhtml_toggle_bold(imhtml); | |
| 4090 | |
| 4091 if (imhtml->edit.italic) | |
| 4092 gtk_imhtml_toggle_italic(imhtml); | |
| 4093 | |
| 4094 if (imhtml->edit.underline) | |
| 4095 gtk_imhtml_toggle_underline(imhtml); | |
| 4096 | |
| 4097 if (imhtml->edit.forecolor) | |
| 4098 gtk_imhtml_toggle_forecolor(imhtml, NULL); | |
| 4099 | |
| 4100 if (imhtml->edit.backcolor) | |
| 4101 gtk_imhtml_toggle_backcolor(imhtml, NULL); | |
| 4102 | |
| 4103 if (imhtml->edit.fontface) | |
| 4104 gtk_imhtml_toggle_fontface(imhtml, NULL); | |
| 4105 | |
| 8677 | 4106 imhtml->edit.fontsize = 0; |
| 4107 | |
| 8719 | 4108 if (imhtml->edit.link) |
| 4109 gtk_imhtml_toggle_link(imhtml, NULL); | |
| 4110 | |
| 8698 | 4111 gtk_text_buffer_remove_all_tags(imhtml->text_buffer, iter, iter); |
| 8061 | 4112 |
| 4113 } | |
| 4114 | |
| 4115 char *gtk_imhtml_get_markup(GtkIMHtml *imhtml) | |
| 4116 { | |
| 4117 GtkTextIter start, end; | |
| 4118 | |
| 4119 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start); | |
| 4120 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end); | |
| 4121 return gtk_imhtml_get_markup_range(imhtml, &start, &end); | |
| 4122 } | |
| 4123 | |
| 8677 | 4124 char **gtk_imhtml_get_markup_lines(GtkIMHtml *imhtml) |
| 4125 { | |
| 4126 int i, j, lines; | |
| 4127 GtkTextIter start, end; | |
| 4128 char **ret; | |
| 4129 | |
| 4130 lines = gtk_text_buffer_get_line_count(imhtml->text_buffer); | |
| 4131 ret = g_new0(char *, lines + 1); | |
| 4132 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start); | |
| 4133 end = start; | |
| 4134 gtk_text_iter_forward_to_line_end(&end); | |
| 4135 | |
| 4136 for (i = 0, j = 0; i < lines; i++) { | |
| 9612 | 4137 if (gtk_text_iter_get_char(&start) != '\n') { |
| 4138 ret[j] = gtk_imhtml_get_markup_range(imhtml, &start, &end); | |
| 4139 if (ret[j] != NULL) | |
| 4140 j++; | |
| 4141 } | |
| 4142 | |
| 8677 | 4143 gtk_text_iter_forward_line(&start); |
| 4144 end = start; | |
| 4145 gtk_text_iter_forward_to_line_end(&end); | |
| 4146 } | |
| 4147 | |
| 4148 return ret; | |
| 4149 } | |
| 4150 | |
| 4151 char *gtk_imhtml_get_text(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *stop) | |
| 8061 | 4152 { |
| 8519 | 4153 GString *str = g_string_new(""); |
| 4154 GtkTextIter iter, end; | |
| 4155 gunichar c; | |
| 4156 | |
| 8677 | 4157 if (start == NULL) |
| 4158 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &iter); | |
| 4159 else | |
| 4160 iter = *start; | |
| 4161 | |
| 4162 if (stop == NULL) | |
| 4163 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end); | |
| 4164 else | |
| 4165 end = *stop; | |
| 4166 | |
| 4167 gtk_text_iter_order(&iter, &end); | |
| 8519 | 4168 |
| 4169 while ((c = gtk_text_iter_get_char(&iter)) != 0 && !gtk_text_iter_equal(&iter, &end)) { | |
| 4170 if (c == 0xFFFC) { | |
| 8677 | 4171 GtkTextChildAnchor* anchor; |
| 4172 char *text = NULL; | |
| 4173 | |
| 4174 anchor = gtk_text_iter_get_child_anchor(&iter); | |
| 4175 if (anchor) | |
| 8698 | 4176 text = g_object_get_data(G_OBJECT(anchor), "gtkimhtml_plaintext"); |
| 8677 | 4177 if (text) |
| 4178 str = g_string_append(str, text); | |
| 8519 | 4179 } else { |
| 4180 g_string_append_unichar(str, c); | |
| 4181 } | |
| 4182 gtk_text_iter_forward_char(&iter); | |
| 4183 } | |
| 4184 | |
| 4185 return g_string_free(str, FALSE); | |
| 8061 | 4186 } |
| 8962 | 4187 |
| 4188 void gtk_imhtml_set_funcs(GtkIMHtml *imhtml, GtkIMHtmlFuncs *f) | |
| 4189 { | |
| 4190 g_return_if_fail(imhtml != NULL); | |
| 4191 imhtml->funcs = f; | |
| 4192 } |
