Mercurial > pidgin
annotate src/gtkimhtml.c @ 7779:de9a47ff006a
[gaim-migrate @ 8424]
copy plain text.
committer: Tailor Script <tailor@pidgin.im>
| author | Sean Egan <seanegan@gmail.com> |
|---|---|
| date | Sat, 06 Dec 2003 21:55:22 +0000 |
| parents | 3db18c16f573 |
| children | 666f672a869a |
| rev | line source |
|---|---|
| 1428 | 1 /* |
| 2 * GtkIMHtml | |
| 3 * | |
| 4 * Copyright (C) 2000, Eric Warmenhoven <warmenhoven@yahoo.com> | |
| 5 * | |
| 6 * This program is free software; you can redistribute it and/or modify | |
| 7 * under the terms of the GNU General Public License as published by | |
| 8 * the Free Software Foundation; either version 2 of the License, or | |
| 9 * (at your option) any later version. | |
| 10 * | |
| 11 * This program is distributed in the hope that it will be useful, | |
| 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 * GNU General Public License for more details. | |
| 15 * | |
| 16 * You should have received a copy of the GNU General Public License | |
| 17 * along with this program; if not, write to the Free Software | |
| 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 19 * | |
| 20 */ | |
| 21 | |
|
2541
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
22 #ifdef HAVE_CONFIG_H |
|
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
23 #include <config.h> |
|
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
24 #endif |
| 1428 | 25 #include "gtkimhtml.h" |
| 7358 | 26 #include "gtksourceiter.h" |
| 1428 | 27 #include <gtk/gtk.h> |
| 4895 | 28 #include <glib/gerror.h> |
| 4046 | 29 #include <gdk/gdkkeysyms.h> |
| 1428 | 30 #include <string.h> |
| 31 #include <ctype.h> | |
| 32 #include <stdio.h> | |
| 4629 | 33 #include <stdlib.h> |
| 1428 | 34 #include <math.h> |
|
2541
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
35 #ifdef HAVE_LANGINFO_CODESET |
|
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
36 #include <langinfo.h> |
|
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
37 #include <locale.h> |
|
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
38 #endif |
| 1428 | 39 |
| 4417 | 40 #ifdef ENABLE_NLS |
| 41 # include <libintl.h> | |
| 42 # define _(x) gettext(x) | |
| 43 # ifdef gettext_noop | |
| 44 # define N_(String) gettext_noop (String) | |
| 45 # else | |
| 46 # define N_(String) (String) | |
| 47 # endif | |
| 48 #else | |
| 49 # define N_(String) (String) | |
| 50 # define _(x) (x) | |
| 51 #endif | |
| 52 | |
| 4735 | 53 #include <pango/pango-font.h> |
| 54 | |
| 5105 | 55 /* GTK+ < 2.2.2 hack, see ui.h for details. */ |
| 56 #ifndef GTK_WRAP_WORD_CHAR | |
| 57 #define GTK_WRAP_WORD_CHAR GTK_WRAP_WORD | |
| 58 #endif | |
| 59 | |
| 4735 | 60 #define TOOLTIP_TIMEOUT 500 |
| 61 | |
| 7694 | 62 static void insert_cb(GtkTextBuffer *buffer, GtkTextIter *iter, gchar *text, gint len, GtkIMHtml *imhtml); |
| 63 | |
| 3922 | 64 /* POINT_SIZE converts from AIM font sizes to point sizes. It probably should be redone in such a |
| 65 * way that it base the sizes off the default font size rather than using arbitrary font sizes. */ | |
| 66 #define MAX_FONT_SIZE 7 | |
| 5367 | 67 #define POINT_SIZE(x) (options & GTK_IMHTML_USE_POINTSIZE ? x : _point_sizes [MIN ((x), MAX_FONT_SIZE) - 1]) |
| 3928 | 68 static gint _point_sizes [] = { 8, 10, 12, 14, 20, 30, 40 }; |
|
2349
60c716c32c40
[gaim-migrate @ 2362]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2348
diff
changeset
|
69 |
| 7749 | 70 enum { |
| 71 TARGET_HTML, | |
| 72 TARGET_UTF8_STRING, | |
| 73 TARGET_COMPOUND_TEXT, | |
| 74 TARGET_STRING, | |
| 75 TARGET_TEXT | |
| 76 }; | |
| 77 | |
| 78 GtkTargetEntry selection_targets[] = { | |
| 79 { "text/html", 0, TARGET_HTML }, | |
| 80 { "UTF8_STRING", 0, TARGET_UTF8_STRING }, | |
| 81 { "COMPOUND_TEXT", 0, TARGET_COMPOUND_TEXT }, | |
| 82 { "STRING", 0, TARGET_STRING }, | |
| 83 { "TEXT", 0, TARGET_TEXT}}; | |
| 84 | |
| 4032 | 85 static GtkSmileyTree* |
| 86 gtk_smiley_tree_new () | |
| 87 { | |
| 88 return g_new0 (GtkSmileyTree, 1); | |
| 89 } | |
| 90 | |
| 91 static void | |
| 92 gtk_smiley_tree_insert (GtkSmileyTree *tree, | |
| 4263 | 93 GtkIMHtmlSmiley *smiley) |
| 4032 | 94 { |
| 95 GtkSmileyTree *t = tree; | |
| 4263 | 96 const gchar *x = smiley->smile; |
| 4032 | 97 |
| 98 if (!strlen (x)) | |
| 99 return; | |
| 100 | |
| 101 while (*x) { | |
| 102 gchar *pos; | |
| 103 gint index; | |
| 104 | |
| 105 if (!t->values) | |
| 106 t->values = g_string_new (""); | |
| 107 | |
| 108 pos = strchr (t->values->str, *x); | |
| 109 if (!pos) { | |
| 110 t->values = g_string_append_c (t->values, *x); | |
| 111 index = t->values->len - 1; | |
| 112 t->children = g_realloc (t->children, t->values->len * sizeof (GtkSmileyTree *)); | |
| 113 t->children [index] = g_new0 (GtkSmileyTree, 1); | |
| 114 } else | |
| 7386 | 115 index = GPOINTER_TO_INT(pos) - GPOINTER_TO_INT(t->values->str); |
| 4032 | 116 |
| 117 t = t->children [index]; | |
| 118 | |
| 119 x++; | |
| 120 } | |
| 121 | |
| 4263 | 122 t->image = smiley; |
| 4032 | 123 } |
| 4041 | 124 |
| 4263 | 125 |
| 4264 | 126 void gtk_smiley_tree_destroy (GtkSmileyTree *tree) |
| 4032 | 127 { |
| 128 GSList *list = g_slist_append (NULL, tree); | |
| 129 | |
| 130 while (list) { | |
| 131 GtkSmileyTree *t = list->data; | |
| 132 gint i; | |
| 133 list = g_slist_remove(list, t); | |
| 7384 | 134 if (t && t->values) { |
| 4032 | 135 for (i = 0; i < t->values->len; i++) |
| 136 list = g_slist_append (list, t->children [i]); | |
| 137 g_string_free (t->values, TRUE); | |
| 138 g_free (t->children); | |
| 139 } | |
| 140 g_free (t); | |
| 141 } | |
| 142 } | |
| 143 | |
| 5967 | 144 static gboolean gtk_size_allocate_cb(GtkIMHtml *widget, GtkAllocation *alloc, gpointer user_data) |
| 145 { | |
| 146 GdkRectangle rect; | |
| 147 | |
| 148 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(widget), &rect); | |
| 149 if(widget->old_rect.width != rect.width || widget->old_rect.height != rect.height){ | |
| 150 GList *iter = GTK_IMHTML(widget)->scalables; | |
| 151 | |
| 152 while(iter){ | |
| 153 GtkIMHtmlScalable *scale = GTK_IMHTML_SCALABLE(iter->data); | |
| 154 scale->scale(scale, rect.width, rect.height); | |
| 155 | |
| 156 iter = iter->next; | |
| 157 } | |
| 158 } | |
| 159 | |
| 160 widget->old_rect = rect; | |
| 161 return FALSE; | |
| 162 } | |
| 163 | |
| 164 static gint | |
| 165 gtk_imhtml_tip_paint (GtkIMHtml *imhtml) | |
| 166 { | |
| 167 PangoLayout *layout; | |
| 168 | |
| 169 g_return_val_if_fail(GTK_IS_IMHTML(imhtml), FALSE); | |
| 170 | |
| 171 layout = gtk_widget_create_pango_layout(imhtml->tip_window, imhtml->tip); | |
| 172 | |
| 173 gtk_paint_flat_box (imhtml->tip_window->style, imhtml->tip_window->window, | |
| 174 GTK_STATE_NORMAL, GTK_SHADOW_OUT, NULL, imhtml->tip_window, | |
| 175 "tooltip", 0, 0, -1, -1); | |
| 176 | |
| 177 gtk_paint_layout (imhtml->tip_window->style, imhtml->tip_window->window, GTK_STATE_NORMAL, | |
| 178 FALSE, NULL, imhtml->tip_window, NULL, 4, 4, layout); | |
| 179 | |
| 180 g_object_unref(layout); | |
| 181 return FALSE; | |
| 182 } | |
| 183 | |
| 184 static gint | |
| 185 gtk_imhtml_tip (gpointer data) | |
| 186 { | |
| 187 GtkIMHtml *imhtml = data; | |
| 188 PangoFontMetrics *font; | |
| 189 PangoLayout *layout; | |
| 190 | |
| 191 gint gap, x, y, h, w, scr_w, baseline_skip; | |
| 192 | |
| 193 g_return_val_if_fail(GTK_IS_IMHTML(imhtml), FALSE); | |
| 194 | |
| 195 if (!imhtml->tip || !GTK_WIDGET_DRAWABLE (GTK_WIDGET(imhtml))) { | |
| 196 imhtml->tip_timer = 0; | |
| 197 return FALSE; | |
| 198 } | |
| 199 | |
| 200 if (imhtml->tip_window){ | |
| 201 gtk_widget_destroy (imhtml->tip_window); | |
| 202 imhtml->tip_window = NULL; | |
| 203 } | |
| 204 | |
| 205 imhtml->tip_timer = 0; | |
| 206 imhtml->tip_window = gtk_window_new (GTK_WINDOW_POPUP); | |
| 207 gtk_widget_set_app_paintable (imhtml->tip_window, TRUE); | |
| 208 gtk_window_set_resizable (GTK_WINDOW (imhtml->tip_window), FALSE); | |
| 209 gtk_widget_set_name (imhtml->tip_window, "gtk-tooltips"); | |
| 210 g_signal_connect_swapped (G_OBJECT (imhtml->tip_window), "expose_event", | |
| 211 G_CALLBACK (gtk_imhtml_tip_paint), imhtml); | |
| 212 | |
| 213 gtk_widget_ensure_style (imhtml->tip_window); | |
| 214 layout = gtk_widget_create_pango_layout(imhtml->tip_window, imhtml->tip); | |
| 215 font = pango_font_get_metrics(pango_context_load_font(pango_layout_get_context(layout), | |
| 216 imhtml->tip_window->style->font_desc), | |
| 217 NULL); | |
| 218 | |
| 219 | |
| 220 pango_layout_get_pixel_size(layout, &scr_w, NULL); | |
| 221 gap = PANGO_PIXELS((pango_font_metrics_get_ascent(font) + | |
| 222 pango_font_metrics_get_descent(font))/ 4); | |
| 223 | |
| 224 if (gap < 2) | |
| 225 gap = 2; | |
| 226 baseline_skip = PANGO_PIXELS(pango_font_metrics_get_ascent(font) + | |
| 227 pango_font_metrics_get_descent(font)); | |
| 228 w = 8 + scr_w; | |
| 229 h = 8 + baseline_skip; | |
| 230 | |
| 231 gdk_window_get_pointer (NULL, &x, &y, NULL); | |
| 232 if (GTK_WIDGET_NO_WINDOW (GTK_WIDGET(imhtml))) | |
| 233 y += GTK_WIDGET(imhtml)->allocation.y; | |
| 234 | |
| 235 scr_w = gdk_screen_width(); | |
| 236 | |
| 237 x -= ((w >> 1) + 4); | |
| 238 | |
| 239 if ((x + w) > scr_w) | |
| 240 x -= (x + w) - scr_w; | |
| 241 else if (x < 0) | |
| 242 x = 0; | |
| 243 | |
| 244 y = y + PANGO_PIXELS(pango_font_metrics_get_ascent(font) + | |
| 245 pango_font_metrics_get_descent(font)); | |
| 246 | |
| 247 gtk_widget_set_size_request (imhtml->tip_window, w, h); | |
| 248 gtk_widget_show (imhtml->tip_window); | |
| 249 gtk_window_move (GTK_WINDOW(imhtml->tip_window), x, y); | |
| 250 | |
| 251 pango_font_metrics_unref(font); | |
| 252 g_object_unref(layout); | |
| 253 | |
| 254 return FALSE; | |
| 255 } | |
| 256 | |
| 257 gboolean gtk_motion_event_notify(GtkWidget *imhtml, GdkEventMotion *event, gpointer data) | |
| 258 { | |
| 259 GtkTextIter iter; | |
| 260 GdkWindow *win = event->window; | |
| 261 int x, y; | |
| 262 char *tip = NULL; | |
| 263 GSList *tags = NULL, *templist = NULL; | |
| 264 gdk_window_get_pointer(GTK_WIDGET(imhtml)->window, NULL, NULL, NULL); | |
| 265 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(imhtml), GTK_TEXT_WINDOW_WIDGET, | |
| 266 event->x, event->y, &x, &y); | |
| 267 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(imhtml), &iter, x, y); | |
| 268 tags = gtk_text_iter_get_tags(&iter); | |
| 269 | |
| 270 templist = tags; | |
| 271 while (templist) { | |
| 272 GtkTextTag *tag = templist->data; | |
| 273 tip = g_object_get_data(G_OBJECT(tag), "link_url"); | |
| 274 if (tip) | |
| 275 break; | |
| 276 templist = templist->next; | |
| 277 } | |
| 278 | |
| 279 if (GTK_IMHTML(imhtml)->tip) { | |
| 280 if ((tip == GTK_IMHTML(imhtml)->tip)) { | |
| 281 return FALSE; | |
| 282 } | |
| 283 /* We've left the cell. Remove the timeout and create a new one below */ | |
| 284 if (GTK_IMHTML(imhtml)->tip_window) { | |
| 285 gtk_widget_destroy(GTK_IMHTML(imhtml)->tip_window); | |
| 286 GTK_IMHTML(imhtml)->tip_window = NULL; | |
| 287 } | |
| 7694 | 288 if (GTK_IMHTML(imhtml)->editable) |
| 289 gdk_window_set_cursor(win, GTK_IMHTML(imhtml)->text_cursor); | |
| 290 else | |
| 291 gdk_window_set_cursor(win, GTK_IMHTML(imhtml)->arrow_cursor); | |
| 5967 | 292 if (GTK_IMHTML(imhtml)->tip_timer) |
| 293 g_source_remove(GTK_IMHTML(imhtml)->tip_timer); | |
| 294 GTK_IMHTML(imhtml)->tip_timer = 0; | |
| 295 } | |
| 296 | |
| 297 if(tip){ | |
| 7709 | 298 if (!GTK_IMHTML(imhtml)->editable) |
| 7707 | 299 gdk_window_set_cursor(win, GTK_IMHTML(imhtml)->hand_cursor); |
| 5967 | 300 GTK_IMHTML(imhtml)->tip_timer = g_timeout_add (TOOLTIP_TIMEOUT, |
| 301 gtk_imhtml_tip, imhtml); | |
| 302 } | |
| 303 | |
| 304 GTK_IMHTML(imhtml)->tip = tip; | |
| 305 g_slist_free(tags); | |
| 306 return FALSE; | |
| 307 } | |
| 308 | |
| 309 gboolean gtk_leave_event_notify(GtkWidget *imhtml, GdkEventCrossing *event, gpointer data) | |
| 310 { | |
| 311 /* when leaving the widget, clear any current & pending tooltips and restore the cursor */ | |
| 312 if (GTK_IMHTML(imhtml)->tip_window) { | |
| 313 gtk_widget_destroy(GTK_IMHTML(imhtml)->tip_window); | |
| 314 GTK_IMHTML(imhtml)->tip_window = NULL; | |
| 315 } | |
| 316 if (GTK_IMHTML(imhtml)->tip_timer) { | |
| 317 g_source_remove(GTK_IMHTML(imhtml)->tip_timer); | |
| 318 GTK_IMHTML(imhtml)->tip_timer = 0; | |
| 319 } | |
| 7694 | 320 if (GTK_IMHTML(imhtml)->editable) |
| 321 gdk_window_set_cursor(event->window, GTK_IMHTML(imhtml)->text_cursor); | |
| 322 else | |
| 323 gdk_window_set_cursor(event->window, GTK_IMHTML(imhtml)->arrow_cursor); | |
| 5967 | 324 |
| 325 /* propogate the event normally */ | |
| 326 return FALSE; | |
| 327 } | |
| 328 | |
| 6066 | 329 /* |
| 330 * XXX - This should be removed eventually. | |
| 331 * | |
| 332 * This function exists to work around a gross bug in GtkTextView. | |
| 333 * Basically, we short circuit ctrl+a and ctrl+end because they make | |
| 334 * el program go boom. | |
| 335 * | |
| 336 * It's supposed to be fixed in gtk2.2. You can view the bug report at | |
| 337 * http://bugzilla.gnome.org/show_bug.cgi?id=107939 | |
| 338 */ | |
| 339 gboolean gtk_key_pressed_cb(GtkWidget *imhtml, GdkEventKey *event, gpointer data) | |
| 340 { | |
| 341 if (event->state & GDK_CONTROL_MASK) | |
| 342 switch (event->keyval) { | |
| 343 case 'a': | |
| 344 return TRUE; | |
| 345 break; | |
| 346 | |
| 347 case GDK_Home: | |
| 348 return TRUE; | |
| 349 break; | |
| 350 | |
| 351 case GDK_End: | |
| 352 return TRUE; | |
| 353 break; | |
| 354 } | |
| 355 | |
| 356 return FALSE; | |
| 357 } | |
| 358 | |
|
7404
d889a99e0eb1
[gaim-migrate @ 8000]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
359 #if GTK_CHECK_VERSION(2,2,0) |
| 7749 | 360 static void gtk_imhtml_clipboard_get(GtkClipboard *clipboard, GtkSelectionData *selection_data, guint info, GtkIMHtml *imhtml) { |
| 361 GtkTextIter start, end; | |
| 7346 | 362 GtkTextMark *sel = gtk_text_buffer_get_selection_bound(imhtml->text_buffer); |
| 363 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); | |
| 7779 | 364 char *text; |
| 7346 | 365 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &start, sel); |
| 366 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &end, ins); | |
| 7779 | 367 |
| 7346 | 368 |
| 7749 | 369 if (info == TARGET_HTML) { |
| 370 int len; | |
| 371 GString *str = g_string_new(NULL); | |
| 7779 | 372 text = gtk_imhtml_get_markup_range(imhtml, &start, &end); |
| 7749 | 373 |
| 374 /* Mozilla asks that we start our text/html with the Unicode byte order mark */ | |
| 375 str = g_string_append_unichar(str, 0xfeff); | |
| 376 str = g_string_append(str, text); | |
| 7766 | 377 str = g_string_append_unichar(str, 0x0000); |
| 7749 | 378 char *selection = g_convert(str->str, str->len, "UCS-2", "UTF-8", NULL, &len, NULL); |
| 379 gtk_selection_data_set (selection_data, gdk_atom_intern("text/html", FALSE), 16, selection, len); | |
| 380 g_string_free(str, TRUE); | |
| 381 g_free(selection); | |
| 382 } else { | |
| 7779 | 383 text = gtk_text_buffer_get_text(imhtml, &start, &end, FALSE); |
| 7749 | 384 gtk_selection_data_set_text(selection_data, text, strlen(text)); |
| 7346 | 385 } |
| 7779 | 386 g_free(text); |
| 7749 | 387 } |
| 388 | |
| 389 static void gtk_imhtml_clipboard_clear(GtkClipboard *clipboard, GtkIMHtml *imhtml) | |
| 390 { | |
| 7750 | 391 GtkTextIter insert; |
| 392 GtkTextIter selection_bound; | |
| 393 | |
| 394 gtk_text_buffer_get_iter_at_mark (imhtml->text_buffer, &insert, | |
| 395 gtk_text_buffer_get_mark (imhtml->text_buffer, "insert")); | |
| 396 gtk_text_buffer_get_iter_at_mark (imhtml->text_buffer, &selection_bound, | |
| 397 gtk_text_buffer_get_mark (imhtml->text_buffer, "selection_bound")); | |
| 398 | |
| 399 if (!gtk_text_iter_equal (&insert, &selection_bound)) | |
| 400 gtk_text_buffer_move_mark (imhtml->text_buffer, | |
| 401 gtk_text_buffer_get_mark (imhtml->text_buffer, "selection_bound"), | |
| 402 &insert); | |
| 7749 | 403 } |
| 7742 | 404 |
| 7749 | 405 static void copy_clipboard_cb(GtkIMHtml *imhtml, GtkClipboard *clipboard) |
| 406 { | |
| 7750 | 407 gtk_clipboard_set_with_owner(gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_CLIPBOARD), |
| 7749 | 408 selection_targets, sizeof(selection_targets) / sizeof(GtkTargetEntry), |
| 409 (GtkClipboardGetFunc)gtk_imhtml_clipboard_get, | |
| 7750 | 410 (GtkClipboardClearFunc)NULL, G_OBJECT(imhtml)); |
| 7749 | 411 |
| 412 g_signal_stop_emission_by_name(imhtml, "copy-clipboard"); | |
| 7346 | 413 } |
| 414 | |
| 7766 | 415 static void paste_received_cb (GtkClipboard *clipboard, GtkSelectionData *selection_data, GtkIMHtml *imhtml) |
| 416 { | |
| 417 char *text; | |
| 418 guint16 c; | |
| 419 if (selection_data->length < 0) { | |
| 420 text = gtk_clipboard_wait_for_text(clipboard); | |
| 421 printf("%s\n", text); | |
| 422 } else { | |
| 423 text = g_malloc((selection_data->format / 8) * selection_data->length); | |
| 424 memcpy(text, selection_data->data, selection_data->length * (selection_data->format / 8)); | |
| 425 printf("%s\n", text); | |
| 426 } | |
| 427 | |
| 428 memcpy (&c, text, 2); | |
| 429 if (c == 0xfeff) { | |
| 430 /* This is UCS2 */ | |
| 7778 | 431 char *utf8 = g_convert(text+2, selection_data->length * (selection_data->format / 8), "UTF-8", "UCS-2", NULL, NULL, NULL); |
| 7766 | 432 g_free(text); |
| 433 text = utf8; | |
| 434 } | |
| 7778 | 435 gtk_imhtml_close_tags(imhtml); |
| 7766 | 436 gtk_imhtml_append_text_with_images(imhtml, text, 0, NULL); |
| 437 } | |
| 438 | |
| 439 | |
| 440 static void paste_clipboard_cb(GtkIMHtml *imhtml, gpointer blah) | |
| 441 { | |
| 442 | |
| 443 GtkClipboard *clipboard = gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_CLIPBOARD); | |
| 444 gtk_clipboard_request_contents(clipboard, gdk_atom_intern("text/html", FALSE), | |
| 445 paste_received_cb, imhtml); | |
| 446 g_signal_stop_emission_by_name(imhtml, "paste-clipboard"); | |
| 447 } | |
| 448 | |
| 7346 | 449 static gboolean button_release_cb(GtkIMHtml *imhtml, GdkEventButton event, gpointer the_foibles_of_man) |
| 450 { | |
| 7750 | 451 GtkClipboard *clipboard; |
| 452 if ((clipboard = gtk_widget_get_clipboard (GTK_WIDGET (imhtml), | |
| 453 GDK_SELECTION_PRIMARY))) | |
| 454 gtk_text_buffer_remove_selection_clipboard (imhtml->text_buffer, clipboard); | |
| 455 gtk_clipboard_set_with_owner(gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_PRIMARY), | |
| 456 selection_targets, sizeof(selection_targets) / sizeof(GtkTargetEntry), | |
| 457 (GtkClipboardGetFunc)gtk_imhtml_clipboard_get, | |
| 458 (GtkClipboardClearFunc)gtk_imhtml_clipboard_clear, G_OBJECT(imhtml)); | |
| 7346 | 459 return FALSE; |
| 460 } | |
|
7404
d889a99e0eb1
[gaim-migrate @ 8000]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
461 #endif |
| 5967 | 462 |
| 4263 | 463 |
| 4032 | 464 static GtkTextViewClass *parent_class = NULL; |
| 465 | |
| 3922 | 466 /* GtkIMHtml has one signal--URL_CLICKED */ |
| 1428 | 467 enum { |
| 468 URL_CLICKED, | |
| 469 LAST_SIGNAL | |
| 470 }; | |
| 471 static guint signals [LAST_SIGNAL] = { 0 }; | |
| 472 | |
| 4032 | 473 static void |
| 474 gtk_imhtml_finalize (GObject *object) | |
| 475 { | |
| 476 GtkIMHtml *imhtml = GTK_IMHTML(object); | |
| 4895 | 477 GList *scalables; |
| 7346 | 478 |
| 4138 | 479 g_hash_table_destroy(imhtml->smiley_data); |
| 4032 | 480 gtk_smiley_tree_destroy(imhtml->default_smilies); |
| 4138 | 481 gdk_cursor_unref(imhtml->hand_cursor); |
| 482 gdk_cursor_unref(imhtml->arrow_cursor); | |
| 7694 | 483 gdk_cursor_unref(imhtml->text_cursor); |
| 4735 | 484 if(imhtml->tip_window){ |
| 485 gtk_widget_destroy(imhtml->tip_window); | |
| 486 } | |
| 487 if(imhtml->tip_timer) | |
| 488 gtk_timeout_remove(imhtml->tip_timer); | |
| 489 | |
| 4895 | 490 for(scalables = imhtml->scalables; scalables; scalables = scalables->next) { |
| 491 GtkIMHtmlScalable *scale = GTK_IMHTML_SCALABLE(scalables->data); | |
| 492 scale->free(scale); | |
| 493 } | |
| 7346 | 494 |
| 4895 | 495 g_list_free(imhtml->scalables); |
| 4032 | 496 G_OBJECT_CLASS(parent_class)->finalize (object); |
| 497 } | |
| 1428 | 498 |
| 3922 | 499 /* Boring GTK stuff */ |
| 500 static void gtk_imhtml_class_init (GtkIMHtmlClass *class) | |
| 1428 | 501 { |
| 3922 | 502 GtkObjectClass *object_class; |
| 4032 | 503 GObjectClass *gobject_class; |
| 3922 | 504 object_class = (GtkObjectClass*) class; |
| 4032 | 505 gobject_class = (GObjectClass*) class; |
| 506 parent_class = gtk_type_class(GTK_TYPE_TEXT_VIEW); | |
| 4417 | 507 signals[URL_CLICKED] = g_signal_new("url_clicked", |
| 508 G_TYPE_FROM_CLASS(gobject_class), | |
| 509 G_SIGNAL_RUN_FIRST, | |
| 510 G_STRUCT_OFFSET(GtkIMHtmlClass, url_clicked), | |
| 511 NULL, | |
| 512 0, | |
| 513 g_cclosure_marshal_VOID__POINTER, | |
| 514 G_TYPE_NONE, 1, | |
| 515 G_TYPE_POINTER); | |
| 4032 | 516 gobject_class->finalize = gtk_imhtml_finalize; |
| 1428 | 517 } |
| 518 | |
| 3922 | 519 static void gtk_imhtml_init (GtkIMHtml *imhtml) |
| 1428 | 520 { |
| 3922 | 521 GtkTextIter iter; |
| 522 imhtml->text_buffer = gtk_text_buffer_new(NULL); | |
| 523 gtk_text_buffer_get_end_iter (imhtml->text_buffer, &iter); | |
| 524 imhtml->end = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, FALSE); | |
| 525 gtk_text_view_set_buffer(GTK_TEXT_VIEW(imhtml), imhtml->text_buffer); | |
| 5105 | 526 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(imhtml), GTK_WRAP_WORD_CHAR); |
| 3922 | 527 gtk_text_view_set_pixels_below_lines(GTK_TEXT_VIEW(imhtml), 5); |
| 528 /*gtk_text_view_set_justification(GTK_TEXT_VIEW(imhtml), GTK_JUSTIFY_FILL);*/ | |
| 3465 | 529 |
| 3922 | 530 /* These tags will be used often and can be reused--we create them on init and then apply them by name |
| 531 * other tags (color, size, face, etc.) will have to be created and applied dynamically */ | |
| 532 gtk_text_buffer_create_tag(imhtml->text_buffer, "BOLD", "weight", PANGO_WEIGHT_BOLD, NULL); | |
| 533 gtk_text_buffer_create_tag(imhtml->text_buffer, "ITALICS", "style", PANGO_STYLE_ITALIC, NULL); | |
| 534 gtk_text_buffer_create_tag(imhtml->text_buffer, "UNDERLINE", "underline", PANGO_UNDERLINE_SINGLE, NULL); | |
| 535 gtk_text_buffer_create_tag(imhtml->text_buffer, "STRIKE", "strikethrough", TRUE, NULL); | |
| 536 gtk_text_buffer_create_tag(imhtml->text_buffer, "SUB", "rise", -5000, NULL); | |
| 537 gtk_text_buffer_create_tag(imhtml->text_buffer, "SUP", "rise", 5000, NULL); | |
| 538 gtk_text_buffer_create_tag(imhtml->text_buffer, "PRE", "family", "Monospace", NULL); | |
| 7295 | 539 gtk_text_buffer_create_tag(imhtml->text_buffer, "search", "background", "#22ff00", "weight", "bold", NULL); |
| 7707 | 540 gtk_text_buffer_create_tag(imhtml->text_buffer, "LINK", "foreground", "blue", "underline", PANGO_UNDERLINE_SINGLE, NULL); |
| 3922 | 541 /* When hovering over a link, we show the hand cursor--elsewhere we show the plain ol' pointer cursor */ |
| 542 imhtml->hand_cursor = gdk_cursor_new (GDK_HAND2); | |
| 543 imhtml->arrow_cursor = gdk_cursor_new (GDK_LEFT_PTR); | |
| 7694 | 544 imhtml->text_cursor = gdk_cursor_new (GDK_XTERM); |
| 2993 | 545 |
| 4253 | 546 imhtml->show_smileys = TRUE; |
| 6124 | 547 imhtml->show_comments = TRUE; |
| 4253 | 548 |
| 4892 | 549 imhtml->smiley_data = g_hash_table_new_full(g_str_hash, g_str_equal, |
| 4902 | 550 g_free, (GDestroyNotify)gtk_smiley_tree_destroy); |
| 4032 | 551 imhtml->default_smilies = gtk_smiley_tree_new(); |
| 4735 | 552 |
| 4944 | 553 g_signal_connect(G_OBJECT(imhtml), "size-allocate", G_CALLBACK(gtk_size_allocate_cb), NULL); |
| 4735 | 554 g_signal_connect(G_OBJECT(imhtml), "motion-notify-event", G_CALLBACK(gtk_motion_event_notify), NULL); |
| 4944 | 555 g_signal_connect(G_OBJECT(imhtml), "leave-notify-event", G_CALLBACK(gtk_leave_event_notify), NULL); |
| 6066 | 556 g_signal_connect(G_OBJECT(imhtml), "key_press_event", G_CALLBACK(gtk_key_pressed_cb), NULL); |
| 7694 | 557 g_signal_connect_after(G_OBJECT(imhtml->text_buffer), "insert-text", G_CALLBACK(insert_cb), imhtml); |
|
7404
d889a99e0eb1
[gaim-migrate @ 8000]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
558 #if GTK_CHECK_VERSION(2,2,0) |
| 7353 | 559 g_signal_connect(G_OBJECT(imhtml), "copy-clipboard", G_CALLBACK(copy_clipboard_cb), NULL); |
| 7766 | 560 g_signal_connect(G_OBJECT(imhtml), "paste-clipboard", G_CALLBACK(paste_clipboard_cb), NULL); |
| 7346 | 561 g_signal_connect(G_OBJECT(imhtml), "button-release-event", G_CALLBACK(button_release_cb), imhtml); |
|
7404
d889a99e0eb1
[gaim-migrate @ 8000]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
562 #endif |
| 4944 | 563 gtk_widget_add_events(GTK_WIDGET(imhtml), GDK_LEAVE_NOTIFY_MASK); |
| 4735 | 564 |
| 565 imhtml->tip = NULL; | |
| 566 imhtml->tip_timer = 0; | |
| 567 imhtml->tip_window = NULL; | |
| 4895 | 568 |
| 7694 | 569 imhtml->edit.bold = NULL; |
| 570 imhtml->edit.italic = NULL; | |
| 571 imhtml->edit.underline = NULL; | |
| 7714 | 572 imhtml->edit.forecolor = NULL; |
| 573 imhtml->edit.backcolor = NULL; | |
| 7717 | 574 imhtml->edit.fontface = NULL; |
| 7740 | 575 imhtml->edit.sizespan = NULL; |
| 576 imhtml->edit.fontsize = 3; | |
| 7714 | 577 |
| 7694 | 578 imhtml->format_spans = NULL; |
| 579 | |
| 4895 | 580 imhtml->scalables = NULL; |
| 7750 | 581 |
| 7694 | 582 gtk_imhtml_set_editable(imhtml, FALSE); |
| 7749 | 583 |
| 2993 | 584 } |
| 585 | |
| 3922 | 586 GtkWidget *gtk_imhtml_new(void *a, void *b) |
| 1428 | 587 { |
| 4635 | 588 return GTK_WIDGET(g_object_new(gtk_imhtml_get_type(), NULL)); |
| 1428 | 589 } |
| 590 | |
| 4635 | 591 GType gtk_imhtml_get_type() |
| 1428 | 592 { |
| 4635 | 593 static GType imhtml_type = 0; |
| 1428 | 594 |
| 595 if (!imhtml_type) { | |
| 4635 | 596 static const GTypeInfo imhtml_info = { |
| 597 sizeof(GtkIMHtmlClass), | |
| 598 NULL, | |
| 599 NULL, | |
| 600 (GClassInitFunc) gtk_imhtml_class_init, | |
| 601 NULL, | |
| 602 NULL, | |
| 1428 | 603 sizeof (GtkIMHtml), |
| 4635 | 604 0, |
| 605 (GInstanceInitFunc) gtk_imhtml_init | |
| 1428 | 606 }; |
| 4635 | 607 |
| 608 imhtml_type = g_type_register_static(gtk_text_view_get_type(), | |
| 609 "GtkIMHtml", &imhtml_info, 0); | |
| 1428 | 610 } |
| 611 | |
| 612 return imhtml_type; | |
| 613 } | |
| 614 | |
| 4417 | 615 struct url_data { |
| 616 GObject *object; | |
| 617 gchar *url; | |
| 618 }; | |
| 619 | |
| 620 static void url_open(GtkWidget *w, struct url_data *data) { | |
| 621 if(!data) return; | |
| 622 | |
| 623 g_signal_emit(data->object, signals[URL_CLICKED], 0, data->url); | |
| 624 | |
| 625 g_object_unref(data->object); | |
| 626 g_free(data->url); | |
| 627 g_free(data); | |
| 628 } | |
| 5582 | 629 |
| 4417 | 630 static void url_copy(GtkWidget *w, gchar *url) { |
| 631 GtkClipboard *clipboard; | |
| 632 | |
|
5293
ead927e2543f
[gaim-migrate @ 5665]
Christian Hammond <chipx86@chipx86.com>
parents:
5282
diff
changeset
|
633 clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY); |
| 4417 | 634 gtk_clipboard_set_text(clipboard, url, -1); |
| 5582 | 635 |
| 636 clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); | |
| 637 gtk_clipboard_set_text(clipboard, url, -1); | |
| 4417 | 638 } |
| 639 | |
| 640 /* The callback for an event on a link tag. */ | |
| 5091 | 641 gboolean tag_event(GtkTextTag *tag, GObject *imhtml, GdkEvent *event, GtkTextIter *arg2, char *url) { |
| 4417 | 642 GdkEventButton *event_button = (GdkEventButton *) event; |
| 643 | |
| 3922 | 644 if (event->type == GDK_BUTTON_RELEASE) { |
| 4417 | 645 if (event_button->button == 1) { |
| 646 GtkTextIter start, end; | |
| 647 /* we shouldn't open a URL if the user has selected something: */ | |
| 648 gtk_text_buffer_get_selection_bounds( | |
| 649 gtk_text_iter_get_buffer(arg2), &start, &end); | |
| 650 if(gtk_text_iter_get_offset(&start) != | |
| 651 gtk_text_iter_get_offset(&end)) | |
| 652 return FALSE; | |
| 653 | |
| 654 /* A link was clicked--we emit the "url_clicked" signal | |
| 655 * with the URL as the argument */ | |
| 5091 | 656 g_signal_emit(imhtml, signals[URL_CLICKED], 0, url); |
| 4417 | 657 return FALSE; |
| 658 } else if(event_button->button == 3) { | |
| 4745 | 659 GtkWidget *img, *item, *menu; |
| 4417 | 660 struct url_data *tempdata = g_new(struct url_data, 1); |
| 5091 | 661 tempdata->object = g_object_ref(imhtml); |
| 4417 | 662 tempdata->url = g_strdup(url); |
| 4745 | 663 |
| 5091 | 664 /* Don't want the tooltip around if user right-clicked on link */ |
| 665 if (GTK_IMHTML(imhtml)->tip_window) { | |
| 666 gtk_widget_destroy(GTK_IMHTML(imhtml)->tip_window); | |
| 667 GTK_IMHTML(imhtml)->tip_window = NULL; | |
| 668 } | |
| 669 if (GTK_IMHTML(imhtml)->tip_timer) { | |
| 670 g_source_remove(GTK_IMHTML(imhtml)->tip_timer); | |
| 671 GTK_IMHTML(imhtml)->tip_timer = 0; | |
| 672 } | |
| 7694 | 673 if (GTK_IMHTML(imhtml)->editable) |
| 674 gdk_window_set_cursor(event_button->window, GTK_IMHTML(imhtml)->text_cursor); | |
| 675 else | |
| 676 gdk_window_set_cursor(event_button->window, GTK_IMHTML(imhtml)->arrow_cursor); | |
| 4417 | 677 menu = gtk_menu_new(); |
| 4745 | 678 |
| 4417 | 679 /* buttons and such */ |
| 680 | |
|
7140
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
681 if (!strncmp(url, "mailto:", 7)) |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
682 { |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
683 /* Copy E-Mail Address */ |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
684 img = gtk_image_new_from_stock(GTK_STOCK_COPY, |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
685 GTK_ICON_SIZE_MENU); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
686 item = gtk_image_menu_item_new_with_mnemonic( |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
687 _("_Copy E-Mail Address")); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
688 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
|
689 g_signal_connect(G_OBJECT(item), "activate", |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
690 G_CALLBACK(url_copy), url + 7); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
691 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
692 } |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
693 else |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
694 { |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
695 /* Copy Link Location */ |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
696 img = gtk_image_new_from_stock(GTK_STOCK_COPY, |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
697 GTK_ICON_SIZE_MENU); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
698 item = gtk_image_menu_item_new_with_mnemonic( |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
699 _("_Copy Link Location")); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
700 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
|
701 g_signal_connect(G_OBJECT(item), "activate", |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
702 G_CALLBACK(url_copy), url); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
703 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
704 |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
705 /* Open Link in Browser */ |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
706 img = gtk_image_new_from_stock(GTK_STOCK_JUMP_TO, |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
707 GTK_ICON_SIZE_MENU); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
708 item = gtk_image_menu_item_new_with_mnemonic( |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
709 _("_Open Link in Browser")); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
710 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
|
711 g_signal_connect(G_OBJECT(item), "activate", |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
712 G_CALLBACK(url_open), tempdata); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
713 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
714 } |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
715 |
| 4756 | 716 |
| 4417 | 717 gtk_widget_show_all(menu); |
| 4756 | 718 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, |
| 719 event_button->button, event_button->time); | |
| 4745 | 720 |
| 4417 | 721 return TRUE; |
| 722 } | |
| 1428 | 723 } |
| 4417 | 724 if(event->type == GDK_BUTTON_PRESS && event_button->button == 3) |
| 725 return TRUE; /* Clicking the right mouse button on a link shouldn't | |
| 726 be caught by the regular GtkTextView menu */ | |
| 727 else | |
| 728 return FALSE; /* Let clicks go through if we didn't catch anything */ | |
| 1428 | 729 } |
| 730 | |
| 4298 | 731 /* this isn't used yet |
| 4032 | 732 static void |
| 4263 | 733 gtk_smiley_tree_remove (GtkSmileyTree *tree, |
| 734 GtkIMHtmlSmiley *smiley) | |
| 4032 | 735 { |
| 736 GtkSmileyTree *t = tree; | |
| 4263 | 737 const gchar *x = smiley->smile; |
| 4032 | 738 gint len = 0; |
| 739 | |
| 740 while (*x) { | |
| 741 gchar *pos; | |
| 742 | |
| 743 if (!t->values) | |
| 744 return; | |
| 745 | |
| 746 pos = strchr (t->values->str, *x); | |
| 747 if (pos) | |
| 748 t = t->children [(int) pos - (int) t->values->str]; | |
| 749 else | |
| 750 return; | |
| 751 | |
| 752 x++; len++; | |
| 753 } | |
| 754 | |
|
4141
ccec4fde84f4
[gaim-migrate @ 4359]
Christian Hammond <chipx86@chipx86.com>
parents:
4140
diff
changeset
|
755 if (t->image) { |
| 4032 | 756 t->image = NULL; |
|
4141
ccec4fde84f4
[gaim-migrate @ 4359]
Christian Hammond <chipx86@chipx86.com>
parents:
4140
diff
changeset
|
757 } |
| 4032 | 758 } |
| 4298 | 759 */ |
| 760 | |
| 4032 | 761 |
| 762 static gint | |
| 763 gtk_smiley_tree_lookup (GtkSmileyTree *tree, | |
| 764 const gchar *text) | |
| 765 { | |
| 766 GtkSmileyTree *t = tree; | |
| 767 const gchar *x = text; | |
| 768 gint len = 0; | |
| 769 | |
| 770 while (*x) { | |
| 771 gchar *pos; | |
| 772 | |
| 773 if (!t->values) | |
| 774 break; | |
| 775 | |
| 776 pos = strchr (t->values->str, *x); | |
| 777 if (pos) | |
| 7371 | 778 t = t->children [GPOINTER_TO_INT(pos) - GPOINTER_TO_INT(t->values->str)]; |
| 4032 | 779 else |
| 780 break; | |
| 781 | |
| 782 x++; len++; | |
| 783 } | |
| 784 | |
| 785 if (t->image) | |
| 786 return len; | |
| 787 | |
| 788 return 0; | |
| 789 } | |
| 790 | |
| 791 void | |
| 4263 | 792 gtk_imhtml_associate_smiley (GtkIMHtml *imhtml, |
| 793 gchar *sml, | |
| 794 GtkIMHtmlSmiley *smiley) | |
| 4032 | 795 { |
| 796 GtkSmileyTree *tree; | |
| 797 g_return_if_fail (imhtml != NULL); | |
| 798 g_return_if_fail (GTK_IS_IMHTML (imhtml)); | |
| 7371 | 799 |
| 4032 | 800 if (sml == NULL) |
| 801 tree = imhtml->default_smilies; | |
| 802 else if ((tree = g_hash_table_lookup(imhtml->smiley_data, sml))) { | |
| 803 } else { | |
| 804 tree = gtk_smiley_tree_new(); | |
| 4892 | 805 g_hash_table_insert(imhtml->smiley_data, g_strdup(sml), tree); |
| 4032 | 806 } |
| 807 | |
| 4263 | 808 gtk_smiley_tree_insert (tree, smiley); |
| 4032 | 809 } |
| 810 | |
| 811 static gboolean | |
| 812 gtk_imhtml_is_smiley (GtkIMHtml *imhtml, | |
| 813 GSList *fonts, | |
| 814 const gchar *text, | |
| 815 gint *len) | |
| 816 { | |
| 817 GtkSmileyTree *tree; | |
| 5967 | 818 GtkIMHtmlFontDetail *font; |
| 4032 | 819 char *sml = NULL; |
| 820 | |
| 821 if (fonts) { | |
| 822 font = fonts->data; | |
| 823 sml = font->sml; | |
| 824 } | |
| 825 | |
| 826 if (sml == NULL) | |
| 827 tree = imhtml->default_smilies; | |
| 828 else { | |
| 829 tree = g_hash_table_lookup(imhtml->smiley_data, sml); | |
| 830 } | |
| 831 if (tree == NULL) | |
| 832 return FALSE; | |
| 7371 | 833 |
| 4032 | 834 *len = gtk_smiley_tree_lookup (tree, text); |
| 835 return (*len > 0); | |
| 836 } | |
| 837 | |
|
6814
782907a6ae65
[gaim-migrate @ 7354]
Christian Hammond <chipx86@chipx86.com>
parents:
6648
diff
changeset
|
838 GdkPixbufAnimation * |
| 4032 | 839 gtk_smiley_tree_image (GtkIMHtml *imhtml, |
| 840 const gchar *sml, | |
| 841 const gchar *text) | |
| 842 { | |
| 843 GtkSmileyTree *t; | |
| 844 const gchar *x = text; | |
| 845 if (sml == NULL) | |
| 846 t = imhtml->default_smilies; | |
| 7371 | 847 else |
| 4032 | 848 t = g_hash_table_lookup(imhtml->smiley_data, sml); |
| 7371 | 849 |
| 4032 | 850 |
| 851 if (t == NULL) | |
| 852 return sml ? gtk_smiley_tree_image(imhtml, NULL, text) : NULL; | |
| 853 | |
| 854 while (*x) { | |
| 855 gchar *pos; | |
| 856 | |
| 857 if (!t->values) { | |
| 858 return sml ? gtk_smiley_tree_image(imhtml, NULL, text) : NULL; | |
| 859 } | |
| 7371 | 860 |
| 4032 | 861 pos = strchr (t->values->str, *x); |
| 862 if (pos) { | |
| 7371 | 863 t = t->children [GPOINTER_TO_INT(pos) - GPOINTER_TO_INT(t->values->str)]; |
| 4032 | 864 } else { |
| 865 return sml ? gtk_smiley_tree_image(imhtml, NULL, text) : NULL; | |
| 866 } | |
| 867 x++; | |
| 868 } | |
| 869 | |
| 4263 | 870 if (!t->image->icon) |
|
6814
782907a6ae65
[gaim-migrate @ 7354]
Christian Hammond <chipx86@chipx86.com>
parents:
6648
diff
changeset
|
871 t->image->icon = gdk_pixbuf_animation_new_from_file(t->image->file, NULL); |
| 4263 | 872 |
| 873 return t->image->icon; | |
| 4032 | 874 } |
| 4793 | 875 #define VALID_TAG(x) if (!g_ascii_strncasecmp (string, x ">", strlen (x ">"))) { \ |
| 3922 | 876 *tag = g_strndup (string, strlen (x)); \ |
| 877 *len = strlen (x) + 1; \ | |
| 878 return TRUE; \ | |
| 879 } \ | |
| 880 (*type)++ | |
| 1428 | 881 |
| 4793 | 882 #define VALID_OPT_TAG(x) if (!g_ascii_strncasecmp (string, x " ", strlen (x " "))) { \ |
| 3922 | 883 const gchar *c = string + strlen (x " "); \ |
| 884 gchar e = '"'; \ | |
| 885 gboolean quote = FALSE; \ | |
| 886 while (*c) { \ | |
| 887 if (*c == '"' || *c == '\'') { \ | |
| 888 if (quote && (*c == e)) \ | |
| 889 quote = !quote; \ | |
| 890 else if (!quote) { \ | |
| 891 quote = !quote; \ | |
| 892 e = *c; \ | |
| 893 } \ | |
| 894 } else if (!quote && (*c == '>')) \ | |
| 895 break; \ | |
| 896 c++; \ | |
| 897 } \ | |
| 898 if (*c) { \ | |
| 899 *tag = g_strndup (string, c - string); \ | |
| 900 *len = c - string + 1; \ | |
| 901 return TRUE; \ | |
| 902 } \ | |
| 903 } \ | |
| 904 (*type)++ | |
| 1428 | 905 |
| 906 | |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
907 static gboolean |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
908 gtk_imhtml_is_amp_escape (const gchar *string, |
| 7280 | 909 gchar **replace, |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
910 gint *length) |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
911 { |
| 7287 | 912 static char buf[7]; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
913 g_return_val_if_fail (string != NULL, FALSE); |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
914 g_return_val_if_fail (replace != NULL, FALSE); |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
915 g_return_val_if_fail (length != NULL, FALSE); |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
916 |
| 4793 | 917 if (!g_ascii_strncasecmp (string, "&", 5)) { |
| 7280 | 918 *replace = "&"; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
919 *length = 5; |
| 4793 | 920 } else if (!g_ascii_strncasecmp (string, "<", 4)) { |
| 7280 | 921 *replace = "<"; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
922 *length = 4; |
| 4793 | 923 } else if (!g_ascii_strncasecmp (string, ">", 4)) { |
| 7280 | 924 *replace = ">"; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
925 *length = 4; |
| 4793 | 926 } else if (!g_ascii_strncasecmp (string, " ", 6)) { |
| 7280 | 927 *replace = " "; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
928 *length = 6; |
| 4793 | 929 } else if (!g_ascii_strncasecmp (string, "©", 6)) { |
| 7280 | 930 *replace = "©"; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
931 *length = 6; |
| 4793 | 932 } else if (!g_ascii_strncasecmp (string, """, 6)) { |
| 7280 | 933 *replace = "\""; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
934 *length = 6; |
| 4793 | 935 } else if (!g_ascii_strncasecmp (string, "®", 5)) { |
| 7280 | 936 *replace = "®"; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
937 *length = 5; |
| 5093 | 938 } else if (!g_ascii_strncasecmp (string, "'", 6)) { |
| 7280 | 939 *replace = "\'"; |
| 5093 | 940 *length = 6; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
941 } else if (*(string + 1) == '#') { |
|
2022
199ba82faacb
[gaim-migrate @ 2032]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2002
diff
changeset
|
942 guint pound = 0; |
| 3004 | 943 if ((sscanf (string, "&#%u;", £) == 1) && pound != 0) { |
| 7287 | 944 int buflen; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
945 if (*(string + 3 + (gint)log10 (pound)) != ';') |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
946 return FALSE; |
| 7287 | 947 buflen = g_unichar_to_utf8((gunichar)pound, buf); |
| 948 buf[buflen] = '\0'; | |
| 7280 | 949 *replace = buf; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
950 *length = 2; |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
951 while (isdigit ((gint) string [*length])) (*length)++; |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
952 if (string [*length] == ';') (*length)++; |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
953 } else { |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
954 return FALSE; |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
955 } |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
956 } else { |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
957 return FALSE; |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
958 } |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
959 |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
960 return TRUE; |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
961 } |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
962 |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
963 static gboolean |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
964 gtk_imhtml_is_tag (const gchar *string, |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
965 gchar **tag, |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
966 gint *len, |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
967 gint *type) |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
968 { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
969 *type = 1; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
970 |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
971 if (!strchr (string, '>')) |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
972 return FALSE; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
973 |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
974 VALID_TAG ("B"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
975 VALID_TAG ("BOLD"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
976 VALID_TAG ("/B"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
977 VALID_TAG ("/BOLD"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
978 VALID_TAG ("I"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
979 VALID_TAG ("ITALIC"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
980 VALID_TAG ("/I"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
981 VALID_TAG ("/ITALIC"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
982 VALID_TAG ("U"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
983 VALID_TAG ("UNDERLINE"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
984 VALID_TAG ("/U"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
985 VALID_TAG ("/UNDERLINE"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
986 VALID_TAG ("S"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
987 VALID_TAG ("STRIKE"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
988 VALID_TAG ("/S"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
989 VALID_TAG ("/STRIKE"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
990 VALID_TAG ("SUB"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
991 VALID_TAG ("/SUB"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
992 VALID_TAG ("SUP"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
993 VALID_TAG ("/SUP"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
994 VALID_TAG ("PRE"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
995 VALID_TAG ("/PRE"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
996 VALID_TAG ("TITLE"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
997 VALID_TAG ("/TITLE"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
998 VALID_TAG ("BR"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
999 VALID_TAG ("HR"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1000 VALID_TAG ("/FONT"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1001 VALID_TAG ("/A"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1002 VALID_TAG ("P"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1003 VALID_TAG ("/P"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1004 VALID_TAG ("H3"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1005 VALID_TAG ("/H3"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1006 VALID_TAG ("HTML"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1007 VALID_TAG ("/HTML"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1008 VALID_TAG ("BODY"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1009 VALID_TAG ("/BODY"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1010 VALID_TAG ("FONT"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1011 VALID_TAG ("HEAD"); |
| 2993 | 1012 VALID_TAG ("/HEAD"); |
| 1013 VALID_TAG ("BINARY"); | |
| 1014 VALID_TAG ("/BINARY"); | |
| 5093 | 1015 |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1016 VALID_OPT_TAG ("HR"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1017 VALID_OPT_TAG ("FONT"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1018 VALID_OPT_TAG ("BODY"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1019 VALID_OPT_TAG ("A"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1020 VALID_OPT_TAG ("IMG"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1021 VALID_OPT_TAG ("P"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1022 VALID_OPT_TAG ("H3"); |
| 5093 | 1023 VALID_OPT_TAG ("HTML"); |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1024 |
| 5101 | 1025 VALID_TAG ("CITE"); |
| 1026 VALID_TAG ("/CITE"); | |
| 1027 VALID_TAG ("EM"); | |
| 1028 VALID_TAG ("/EM"); | |
| 1029 VALID_TAG ("STRONG"); | |
| 1030 VALID_TAG ("/STRONG"); | |
| 1031 | |
| 5104 | 1032 VALID_OPT_TAG ("SPAN"); |
| 1033 VALID_TAG ("/SPAN"); | |
| 5174 | 1034 VALID_TAG ("BR/"); /* hack until gtkimhtml handles things better */ |
| 6982 | 1035 VALID_TAG ("IMG"); |
| 5104 | 1036 |
| 4793 | 1037 if (!g_ascii_strncasecmp(string, "!--", strlen ("!--"))) { |
|
2954
f6c4f2187c08
[gaim-migrate @ 2967]
Christian Hammond <chipx86@chipx86.com>
parents:
2898
diff
changeset
|
1038 gchar *e = strstr (string + strlen("!--"), "-->"); |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1039 if (e) { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1040 *len = e - string + strlen ("-->"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1041 *tag = g_strndup (string + strlen ("!--"), *len - strlen ("!---->")); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1042 return TRUE; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1043 } |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1044 } |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1045 |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1046 return FALSE; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1047 } |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1048 |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1049 static gchar* |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1050 gtk_imhtml_get_html_opt (gchar *tag, |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1051 const gchar *opt) |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1052 { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1053 gchar *t = tag; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1054 gchar *e, *a; |
| 5177 | 1055 gchar *val; |
| 1056 gint len; | |
| 7280 | 1057 gchar *c; |
| 5177 | 1058 GString *ret; |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1059 |
| 4793 | 1060 while (g_ascii_strncasecmp (t, opt, strlen (opt))) { |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1061 gboolean quote = FALSE; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1062 if (*t == '\0') break; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1063 while (*t && !((*t == ' ') && !quote)) { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1064 if (*t == '\"') |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1065 quote = ! quote; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1066 t++; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1067 } |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1068 while (*t && (*t == ' ')) t++; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1069 } |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1070 |
| 4793 | 1071 if (!g_ascii_strncasecmp (t, opt, strlen (opt))) { |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1072 t += strlen (opt); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1073 } else { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1074 return NULL; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1075 } |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1076 |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1077 if ((*t == '\"') || (*t == '\'')) { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1078 e = a = ++t; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1079 while (*e && (*e != *(t - 1))) e++; |
| 2993 | 1080 if (*e == '\0') { |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1081 return NULL; |
| 5177 | 1082 } else |
| 1083 val = g_strndup(a, e - a); | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1084 } else { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1085 e = a = t; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1086 while (*e && !isspace ((gint) *e)) e++; |
| 5177 | 1087 val = g_strndup(a, e - a); |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1088 } |
| 5177 | 1089 |
| 1090 ret = g_string_new(""); | |
| 1091 e = val; | |
| 1092 while(*e) { | |
| 1093 if(gtk_imhtml_is_amp_escape(e, &c, &len)) { | |
| 7280 | 1094 ret = g_string_append(ret, c); |
| 5177 | 1095 e += len; |
| 1096 } else { | |
| 1097 ret = g_string_append_c(ret, *e); | |
| 1098 e++; | |
| 1099 } | |
| 1100 } | |
| 1101 | |
| 1102 g_free(val); | |
| 1103 val = ret->str; | |
| 1104 g_string_free(ret, FALSE); | |
| 1105 return val; | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1106 } |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1107 |
| 3922 | 1108 |
| 7778 | 1109 typedef enum { |
| 1110 NEW_TEXT_BIT, | |
| 1111 NEW_COMMENT_BIT, | |
| 1112 NEW_SCALABLE_BIT | |
| 1113 } GtkIMHtmlBitType; | |
| 3922 | 1114 |
| 7778 | 1115 static inline new_bit(GtkIMHtml *imhtml, GtkTextIter *iter, GtkIMHtmlBitType x, char *ws, int *wpos) |
| 1116 { | |
| 1117 GtkTextMark *mark2; | |
| 1118 GtkTextIter siter; | |
| 1119 GtkIMHtmlScalable *scalable = NULL; | |
| 1120 | |
| 1121 ws [*wpos] = '\0'; | |
| 1122 mark2 = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); | |
| 1123 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, -1); | |
| 1124 | |
| 1125 gtk_text_buffer_delete_mark(imhtml->text_buffer, mark2); | |
| 1126 /*if (bold) | |
| 1127 gtk | |
| 4895 | 1128 if (italics) \ |
| 3922 | 1129 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "ITALICS", &siter, &iter); \ |
| 1130 if (underline) \ | |
| 1131 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "UNDERLINE", &siter, &iter); \ | |
| 1132 if (strike) \ | |
| 1133 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "STRIKE", &siter, &iter); \ | |
| 1134 if (sub) \ | |
| 1135 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "SUB", &siter, &iter); \ | |
| 1136 if (sup) \ | |
| 1137 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "SUP", &siter, &iter); \ | |
| 1138 if (pre) \ | |
| 1139 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "PRE", &siter, &iter); \ | |
| 1140 if (bg) { \ | |
| 1141 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "background", bg, NULL); \ | |
| 1142 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &siter, &iter); \ | |
| 1143 } \ | |
| 1144 if (fonts) { \ | |
| 5967 | 1145 GtkIMHtmlFontDetail *fd = fonts->data; \ |
| 3922 | 1146 if (fd->fore) { \ |
| 1147 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "foreground", fd->fore, NULL); \ | |
| 1148 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &siter, &iter); \ | |
| 1149 } \ | |
| 1150 if (fd->back) { \ | |
| 1151 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "background", fd->back, NULL); \ | |
| 1152 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &siter, &iter); \ | |
| 1153 } \ | |
| 1154 if (fd->face) { \ | |
| 6648 | 1155 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "family", fd->face, NULL); \ |
| 3922 | 1156 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &siter, &iter); \ |
| 1157 } \ | |
| 1158 if (fd->size) { \ | |
| 5118 | 1159 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "size-points", (double)POINT_SIZE(fd->size), NULL); \ |
| 3922 | 1160 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &siter, &iter); \ |
| 1161 } \ | |
| 1162 } \ | |
| 1163 if (url) { \ | |
| 7732 | 1164 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "LINK", &siter, &iter); \ |
| 1165 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "foreground", "blue", "underline", PANGO_UNDERLINE_SINGLE, NULL); \ | |
| 5012 | 1166 g_signal_connect(G_OBJECT(texttag), "event", G_CALLBACK(tag_event), g_strdup(url)); \ |
| 7732 | 1167 g_object_set_data(G_OBJECT(texttag), "link_url", g_strdup(url)); \ |
| 4735 | 1168 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &siter, &iter); \ |
| 3922 | 1169 } \ |
| 7778 | 1170 */ |
| 1171 *wpos = 0; | |
| 1172 ws[0] = 0; | |
| 1173 gtk_text_buffer_get_end_iter(imhtml->text_buffer, iter); | |
| 1174 if (x == NEW_SCALABLE_BIT) { | |
| 1175 GdkRectangle rect; | |
| 1176 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); | |
| 1177 scalable->add_to(scalable, imhtml, &iter); | |
| 1178 scalable->scale(scalable, rect.width, rect.height); | |
| 1179 imhtml->scalables = g_list_append(imhtml->scalables, scalable); | |
| 1180 gtk_text_buffer_get_end_iter(imhtml->text_buffer, iter); | |
| 1181 } | |
| 1182 } | |
| 4895 | 1183 |
| 1184 | |
| 6982 | 1185 GString* gtk_imhtml_append_text_with_images (GtkIMHtml *imhtml, |
| 1186 const gchar *text, | |
| 1187 GtkIMHtmlOptions options, | |
| 1188 GSList *images) | |
| 1428 | 1189 { |
| 7778 | 1190 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); |
| 1191 GtkTextIter insert; | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1192 gint pos = 0; |
| 3922 | 1193 GString *str = NULL; |
| 1194 GtkTextIter iter, siter; | |
| 1195 GtkTextMark *mark, *mark2; | |
| 7707 | 1196 GtkTextTag *texttag = NULL; |
| 3922 | 1197 gchar *ws; |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1198 gchar *tag; |
| 3922 | 1199 gchar *url = NULL; |
| 1200 gchar *bg = NULL; | |
| 6982 | 1201 gint len; |
| 4032 | 1202 gint tlen, smilelen, wpos=0; |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1203 gint type; |
| 3922 | 1204 const gchar *c; |
| 7280 | 1205 gchar *amp; |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1206 |
| 1428 | 1207 guint bold = 0, |
| 1208 italics = 0, | |
| 1209 underline = 0, | |
| 1210 strike = 0, | |
| 1211 sub = 0, | |
| 1212 sup = 0, | |
|
1691
d802b115800f
[gaim-migrate @ 1701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1647
diff
changeset
|
1213 title = 0, |
| 3922 | 1214 pre = 0; |
| 1428 | 1215 |
| 3922 | 1216 GSList *fonts = NULL; |
| 7778 | 1217 GtkIMHtmlScalable *scalable = NULL; |
| 4612 | 1218 GdkRectangle rect; |
| 1219 int y, height; | |
| 1220 | |
| 4895 | 1221 |
| 1428 | 1222 g_return_val_if_fail (imhtml != NULL, NULL); |
| 1223 g_return_val_if_fail (GTK_IS_IMHTML (imhtml), NULL); | |
| 1224 g_return_val_if_fail (text != NULL, NULL); | |
| 6982 | 1225 |
| 3922 | 1226 c = text; |
| 6982 | 1227 len = strlen(text); |
| 3922 | 1228 ws = g_malloc(len + 1); |
| 1229 ws[0] = 0; | |
| 1428 | 1230 |
| 1231 if (options & GTK_IMHTML_RETURN_LOG) | |
| 3922 | 1232 str = g_string_new(""); |
| 1428 | 1233 |
| 7778 | 1234 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &insert, ins); |
| 1235 | |
| 3922 | 1236 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &iter); |
| 1237 mark = gtk_text_buffer_create_mark (imhtml->text_buffer, NULL, &iter, /* right grav */ FALSE); | |
| 4612 | 1238 |
| 1239 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); | |
| 1240 gtk_text_view_get_line_yrange(GTK_TEXT_VIEW(imhtml), &iter, &y, &height); | |
| 1241 | |
| 1242 if(((y + height) - (rect.y + rect.height)) > height | |
| 1243 && gtk_text_buffer_get_char_count(imhtml->text_buffer)){ | |
| 1244 options |= GTK_IMHTML_NO_SCROLL; | |
| 1245 } | |
| 1246 | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1247 while (pos < len) { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1248 if (*c == '<' && gtk_imhtml_is_tag (c + 1, &tag, &tlen, &type)) { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1249 c++; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1250 pos++; |
| 3922 | 1251 switch (type) |
| 1252 { | |
| 1253 case 1: /* B */ | |
| 1254 case 2: /* BOLD */ | |
| 5101 | 1255 case 54: /* STRONG */ |
| 7778 | 1256 gtk_text_buffer_insert(imhtml->text_buffer, &iter, ws, wpos); |
| 1257 if (bold == 0) | |
| 1258 gtk_imhtml_toggle_bold(imhtml); | |
| 3922 | 1259 bold++; |
| 7778 | 1260 ws[0] = '\0'; wpos = 0; |
| 3922 | 1261 break; |
| 1262 case 3: /* /B */ | |
| 1263 case 4: /* /BOLD */ | |
| 5101 | 1264 case 55: /* /STRONG */ |
| 7778 | 1265 gtk_text_buffer_insert(imhtml->text_buffer, &iter, ws, wpos); |
| 1266 ws[0] = '\0'; wpos = 0; | |
| 3922 | 1267 if (bold) |
| 1268 bold--; | |
| 7778 | 1269 if (bold == 0) |
| 1270 gtk_imhtml_toggle_bold(imhtml); | |
| 3922 | 1271 break; |
| 1272 case 5: /* I */ | |
| 1273 case 6: /* ITALIC */ | |
| 5101 | 1274 case 52: /* EM */ |
| 7778 | 1275 gtk_text_buffer_insert(imhtml->text_buffer, &iter, ws, wpos); |
| 1276 ws[0] = '\0'; wpos = 0; | |
| 1277 if (italics == 0) | |
| 1278 gtk_imhtml_toggle_italic(imhtml); | |
| 3922 | 1279 italics++; |
| 1280 break; | |
| 1281 case 7: /* /I */ | |
| 1282 case 8: /* /ITALIC */ | |
| 5101 | 1283 case 53: /* /EM */ |
| 7778 | 1284 gtk_text_buffer_insert(imhtml->text_buffer, &iter, ws, wpos); |
| 1285 ws[0] = '\0'; wpos = 0; | |
| 3922 | 1286 if (italics) |
| 1287 italics--; | |
| 7778 | 1288 if (italics == 0) |
| 1289 gtk_imhtml_toggle_italic(imhtml); | |
| 3922 | 1290 break; |
| 1291 case 9: /* U */ | |
| 1292 case 10: /* UNDERLINE */ | |
| 7778 | 1293 gtk_text_buffer_insert(imhtml->text_buffer, &iter, ws, wpos); |
| 1294 ws[0] = '\0'; wpos = 0; | |
| 1295 if (underline == 0) | |
| 1296 gtk_imhtml_toggle_underline(imhtml); | |
| 3922 | 1297 underline++; |
| 1298 break; | |
| 1299 case 11: /* /U */ | |
| 1300 case 12: /* /UNDERLINE */ | |
| 7778 | 1301 gtk_text_buffer_insert(imhtml->text_buffer, &iter, ws, wpos); |
| 1302 ws[0] = '\0'; wpos = 0; | |
| 3922 | 1303 if (underline) |
| 1304 underline--; | |
| 7778 | 1305 if (underline == 0) |
| 1306 gtk_imhtml_toggle_underline(imhtml); | |
| 3922 | 1307 break; |
| 1308 case 13: /* S */ | |
| 1309 case 14: /* STRIKE */ | |
| 7778 | 1310 //NEW_BIT (NEW_TEXT_BIT); |
| 3922 | 1311 strike++; |
| 1312 break; | |
| 1313 case 15: /* /S */ | |
| 1314 case 16: /* /STRIKE */ | |
| 7778 | 1315 //NEW_BIT (NEW_TEXT_BIT); |
| 3922 | 1316 if (strike) |
| 1317 strike--; | |
| 1318 break; | |
| 1319 case 17: /* SUB */ | |
| 7778 | 1320 //NEW_BIT (NEW_TEXT_BIT); |
| 3922 | 1321 sub++; |
| 1322 break; | |
| 1323 case 18: /* /SUB */ | |
| 7778 | 1324 //NEW_BIT (NEW_TEXT_BIT); |
| 3922 | 1325 if (sub) |
| 1326 sub--; | |
| 1327 break; | |
| 1328 case 19: /* SUP */ | |
| 7778 | 1329 //NEW_BIT (NEW_TEXT_BIT); |
| 3922 | 1330 sup++; |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1331 break; |
| 3922 | 1332 case 20: /* /SUP */ |
| 7778 | 1333 //NEW_BIT (NEW_TEXT_BIT); |
| 3922 | 1334 if (sup) |
| 1335 sup--; | |
| 1336 break; | |
| 1337 case 21: /* PRE */ | |
| 7778 | 1338 //NEW_BIT (NEW_TEXT_BIT); |
| 3922 | 1339 pre++; |
| 1340 break; | |
| 1341 case 22: /* /PRE */ | |
| 7778 | 1342 //NEW_BIT (NEW_TEXT_BIT); |
| 3922 | 1343 if (pre) |
| 1344 pre--; | |
| 1345 break; | |
| 1346 case 23: /* TITLE */ | |
| 7778 | 1347 //NEW_BIT (NEW_TEXT_BIT); |
| 3922 | 1348 title++; |
| 1349 break; | |
| 1350 case 24: /* /TITLE */ | |
| 1351 if (title) { | |
| 1352 if (options & GTK_IMHTML_NO_TITLE) { | |
| 1353 wpos = 0; | |
| 1354 ws [wpos] = '\0'; | |
| 1355 } | |
| 1356 title--; | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1357 } |
| 3922 | 1358 break; |
| 1359 case 25: /* BR */ | |
| 5174 | 1360 case 58: /* BR/ */ |
| 3922 | 1361 ws[wpos] = '\n'; |
| 1362 wpos++; | |
| 7778 | 1363 //NEW_BIT (NEW_TEXT_BIT); |
| 6982 | 1364 break; |
| 3922 | 1365 case 26: /* HR */ |
| 1366 case 42: /* HR (opt) */ | |
| 1367 ws[wpos++] = '\n'; | |
| 5967 | 1368 scalable = gtk_imhtml_hr_new(); |
| 7778 | 1369 //NEW_BIT(NEW_SCALABLE_BIT); |
| 4343 | 1370 ws[wpos++] = '\n'; |
| 3922 | 1371 break; |
| 1372 case 27: /* /FONT */ | |
| 1373 if (fonts) { | |
| 5967 | 1374 GtkIMHtmlFontDetail *font = fonts->data; |
| 7778 | 1375 gtk_text_buffer_insert(imhtml->text_buffer, &iter, ws, wpos); |
| 1376 ws[0] = '\0'; wpos = 0; | |
| 1377 //NEW_BIT (NEW_TEXT_BIT); | |
| 3922 | 1378 fonts = g_slist_remove (fonts, font); |
| 7778 | 1379 if (font->face) { |
| 1380 gtk_imhtml_toggle_fontface(imhtml, NULL); | |
| 3922 | 1381 g_free (font->face); |
| 7778 | 1382 } |
| 1383 if (font->fore) { | |
| 1384 gtk_imhtml_toggle_forecolor(imhtml, NULL); | |
| 3922 | 1385 g_free (font->fore); |
| 7778 | 1386 } |
| 1387 if (font->back) { | |
| 1388 gtk_imhtml_toggle_backcolor(imhtml, NULL); | |
| 3922 | 1389 g_free (font->back); |
| 7778 | 1390 } |
| 4032 | 1391 if (font->sml) |
| 1392 g_free (font->sml); | |
| 3922 | 1393 g_free (font); |
| 1394 } | |
| 1395 break; | |
| 1396 case 28: /* /A */ | |
| 1397 if (url) { | |
| 7778 | 1398 //NEW_BIT(NEW_TEXT_BIT); |
| 3922 | 1399 g_free(url); |
| 1400 url = NULL; | |
| 2993 | 1401 break; |
| 1402 } | |
| 3922 | 1403 case 29: /* P */ |
| 1404 case 30: /* /P */ | |
| 1405 case 31: /* H3 */ | |
| 1406 case 32: /* /H3 */ | |
| 1407 case 33: /* HTML */ | |
| 1408 case 34: /* /HTML */ | |
| 1409 case 35: /* BODY */ | |
| 1410 case 36: /* /BODY */ | |
| 1411 case 37: /* FONT */ | |
| 1412 case 38: /* HEAD */ | |
| 1413 case 39: /* /HEAD */ | |
| 6982 | 1414 case 40: /* BINARY */ |
| 1415 case 41: /* /BINARY */ | |
| 3922 | 1416 break; |
| 1417 case 43: /* FONT (opt) */ | |
| 1418 { | |
| 4032 | 1419 gchar *color, *back, *face, *size, *sml; |
| 5967 | 1420 GtkIMHtmlFontDetail *font, *oldfont = NULL; |
| 3922 | 1421 color = gtk_imhtml_get_html_opt (tag, "COLOR="); |
| 1422 back = gtk_imhtml_get_html_opt (tag, "BACK="); | |
| 1423 face = gtk_imhtml_get_html_opt (tag, "FACE="); | |
| 1424 size = gtk_imhtml_get_html_opt (tag, "SIZE="); | |
| 4032 | 1425 sml = gtk_imhtml_get_html_opt (tag, "SML="); |
| 1426 if (!(color || back || face || size || sml)) | |
| 3922 | 1427 break; |
| 1428 | |
| 7778 | 1429 gtk_text_buffer_insert(imhtml->text_buffer, &iter, ws, wpos); |
| 1430 ws[0] = '\0'; wpos = 0; | |
| 3922 | 1431 |
| 5967 | 1432 font = g_new0 (GtkIMHtmlFontDetail, 1); |
| 3922 | 1433 if (fonts) |
| 1434 oldfont = fonts->data; | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1435 |
| 3922 | 1436 if (color && !(options & GTK_IMHTML_NO_COLOURS)) |
| 1437 font->fore = color; | |
| 1438 else if (oldfont && oldfont->fore) | |
| 1439 font->fore = g_strdup(oldfont->fore); | |
| 7778 | 1440 if (font->fore) |
| 1441 gtk_imhtml_toggle_forecolor(imhtml, font->fore); | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1442 |
| 3922 | 1443 if (back && !(options & GTK_IMHTML_NO_COLOURS)) |
| 1444 font->back = back; | |
| 1445 else if (oldfont && oldfont->back) | |
| 1446 font->back = g_strdup(oldfont->back); | |
| 7778 | 1447 if (font->back) |
| 1448 gtk_imhtml_toggle_backcolor(imhtml, font->back); | |
| 3922 | 1449 |
| 1450 if (face && !(options & GTK_IMHTML_NO_FONTS)) | |
| 1451 font->face = face; | |
| 1452 else if (oldfont && oldfont->face) | |
| 1453 font->face = g_strdup(oldfont->face); | |
| 7778 | 1454 if (font->face) |
| 1455 gtk_imhtml_toggle_fontface(imhtml, font->face); | |
| 4032 | 1456 |
| 1457 if (sml) | |
| 1458 font->sml = sml; | |
| 1459 else if (oldfont && oldfont->sml) | |
| 1460 font->sml = g_strdup(oldfont->sml); | |
| 1461 | |
| 3922 | 1462 if (size && !(options & GTK_IMHTML_NO_SIZES)) { |
| 1463 if (*size == '+') { | |
| 1464 sscanf (size + 1, "%hd", &font->size); | |
| 1465 font->size += 3; | |
| 1466 } else if (*size == '-') { | |
| 1467 sscanf (size + 1, "%hd", &font->size); | |
| 1468 font->size = MAX (0, 3 - font->size); | |
| 1469 } else if (isdigit (*size)) { | |
| 1470 sscanf (size, "%hd", &font->size); | |
| 7778 | 1471 } |
| 6042 | 1472 if (font->size > 100) |
| 1473 font->size = 100; | |
| 3922 | 1474 } else if (oldfont) |
| 1475 font->size = oldfont->size; | |
| 7778 | 1476 // gtk_imhtml_font_set_size(imhtml, font->size); |
| 3922 | 1477 g_free(size); |
| 1478 fonts = g_slist_prepend (fonts, font); | |
| 1479 } | |
| 1480 break; | |
| 1481 case 44: /* BODY (opt) */ | |
| 1482 if (!(options & GTK_IMHTML_NO_COLOURS)) { | |
| 1483 char *bgcolor = gtk_imhtml_get_html_opt (tag, "BGCOLOR="); | |
| 1484 if (bgcolor) { | |
| 7778 | 1485 gtk_text_buffer_insert(imhtml->text_buffer, &iter, ws, wpos); |
| 1486 ws[0] = '\0'; wpos = 0; | |
| 1487 // NEW_BIT(NEW_TEXT_BIT); | |
| 3922 | 1488 if (bg) |
| 1489 g_free(bg); | |
| 1490 bg = bgcolor; | |
| 7778 | 1491 gtk_imhtml_toggle_backcolor(imhtml, bg); |
|
2885
f72efa29c109
[gaim-migrate @ 2898]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2871
diff
changeset
|
1492 } |
| 1428 | 1493 } |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1494 break; |
| 3922 | 1495 case 45: /* A (opt) */ |
| 1496 { | |
| 1497 gchar *href = gtk_imhtml_get_html_opt (tag, "HREF="); | |
| 1498 if (href) { | |
| 7778 | 1499 // NEW_BIT (NEW_TEXT_BIT); |
| 3922 | 1500 if (url) |
| 1501 g_free (url); | |
| 1502 url = href; | |
| 1503 } | |
| 2993 | 1504 } |
| 3922 | 1505 break; |
| 4895 | 1506 case 46: /* IMG (opt) */ |
| 6982 | 1507 case 59: /* IMG */ |
| 4895 | 1508 { |
| 6982 | 1509 GdkPixbuf *img = NULL; |
| 1510 const gchar *filename = NULL; | |
| 4895 | 1511 |
| 6982 | 1512 if (images && images->data) { |
| 1513 img = images->data; | |
| 1514 images = images->next; | |
| 1515 filename = g_object_get_data(G_OBJECT(img), "filename"); | |
| 1516 g_object_ref(G_OBJECT(img)); | |
| 1517 } else { | |
| 1518 img = gtk_widget_render_icon(GTK_WIDGET(imhtml), | |
| 1519 GTK_STOCK_MISSING_IMAGE, GTK_ICON_SIZE_BUTTON, | |
| 1520 "gtkimhtml-missing-image"); | |
| 1521 } | |
| 4895 | 1522 |
| 6982 | 1523 scalable = gtk_imhtml_image_new(img, filename); |
| 7778 | 1524 //NEW_BIT(NEW_SCALABLE_BIT); |
| 6982 | 1525 g_object_unref(G_OBJECT(img)); |
| 4895 | 1526 } |
| 3922 | 1527 case 47: /* P (opt) */ |
| 1528 case 48: /* H3 (opt) */ | |
| 5093 | 1529 case 49: /* HTML (opt) */ |
| 5101 | 1530 case 50: /* CITE */ |
| 1531 case 51: /* /CITE */ | |
| 5104 | 1532 case 56: /* SPAN */ |
| 1533 case 57: /* /SPAN */ | |
| 2993 | 1534 break; |
| 6982 | 1535 case 60: /* comment */ |
| 7778 | 1536 //NEW_BIT (NEW_TEXT_BIT); |
| 6124 | 1537 if (imhtml->show_comments) |
| 1538 wpos = g_snprintf (ws, len, "%s", tag); | |
| 7778 | 1539 // NEW_BIT (NEW_COMMENT_BIT); |
| 3922 | 1540 break; |
| 1541 default: | |
| 6882 | 1542 break; |
| 2993 | 1543 } |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1544 c += tlen; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1545 pos += tlen; |
| 4138 | 1546 if(tag) |
| 1547 g_free(tag); /* This was allocated back in VALID_TAG() */ | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1548 } else if (*c == '&' && gtk_imhtml_is_amp_escape (c, &, &tlen)) { |
| 7280 | 1549 while(*amp) { |
| 1550 ws [wpos++] = *amp++; | |
| 1551 } | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1552 c += tlen; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1553 pos += tlen; |
| 1428 | 1554 } else if (*c == '\n') { |
| 1555 if (!(options & GTK_IMHTML_NO_NEWLINE)) { | |
| 3922 | 1556 ws[wpos] = '\n'; |
| 1557 wpos++; | |
| 7778 | 1558 gtk_text_buffer_insert(imhtml->text_buffer, &iter, ws, wpos); |
| 1559 ws[0] = '\0'; | |
| 1560 wpos = 0; | |
| 1561 //NEW_BIT (NEW_TEXT_BIT); | |
| 1428 | 1562 } |
| 1563 c++; | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1564 pos++; |
| 4253 | 1565 } else if (imhtml->show_smileys && (gtk_imhtml_is_smiley (imhtml, fonts, c, &smilelen) || gtk_imhtml_is_smiley(imhtml, NULL, c, &smilelen))) { |
|
6814
782907a6ae65
[gaim-migrate @ 7354]
Christian Hammond <chipx86@chipx86.com>
parents:
6648
diff
changeset
|
1566 GtkTextChildAnchor *anchor; |
| 6882 | 1567 GtkWidget *icon = NULL; |
| 7344 | 1568 GtkTextIter copy; |
| 6882 | 1569 GdkPixbufAnimation *annipixbuf = NULL; |
| 1570 GdkPixbuf *pixbuf = NULL; | |
| 5967 | 1571 GtkIMHtmlFontDetail *fd; |
| 7346 | 1572 |
| 4032 | 1573 gchar *sml = NULL; |
| 1574 if (fonts) { | |
| 1575 fd = fonts->data; | |
| 1576 sml = fd->sml; | |
| 1577 } | |
| 7778 | 1578 gtk_text_buffer_insert(imhtml->text_buffer, &iter, ws, wpos); |
| 1579 ws[0] = '\0'; | |
| 1580 //NEW_BIT (NEW_TEXT_BIT); | |
| 4032 | 1581 wpos = g_snprintf (ws, smilelen + 1, "%s", c); |
| 7778 | 1582 gtk_imhtml_insert_smiley(imhtml, sml, ws); |
| 1583 | |
| 1584 /*anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, &iter); | |
| 6882 | 1585 annipixbuf = gtk_smiley_tree_image(imhtml, sml, ws); |
| 1586 if(annipixbuf) { | |
| 7778 | 1587 if(gdk_pixbuf_animation_is_static_image(annipixbuf)) { |
| 6882 | 1588 pixbuf = gdk_pixbuf_animation_get_static_image(annipixbuf); |
| 1589 if(pixbuf) | |
| 1590 icon = gtk_image_new_from_pixbuf(pixbuf); | |
| 1591 } else { | |
| 1592 icon = gtk_image_new_from_animation(annipixbuf); | |
| 1593 } | |
| 1594 } | |
| 1595 | |
| 1596 if (icon) { | |
|
6839
bdc4e73f354d
[gaim-migrate @ 7384]
Christian Hammond <chipx86@chipx86.com>
parents:
6814
diff
changeset
|
1597 gtk_widget_show(icon); |
|
bdc4e73f354d
[gaim-migrate @ 7384]
Christian Hammond <chipx86@chipx86.com>
parents:
6814
diff
changeset
|
1598 gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(imhtml), icon, anchor); |
|
bdc4e73f354d
[gaim-migrate @ 7384]
Christian Hammond <chipx86@chipx86.com>
parents:
6814
diff
changeset
|
1599 } |
| 7344 | 1600 |
| 1601 copy = iter; | |
| 1602 gtk_text_iter_backward_char(©); | |
| 1603 if (bg) { | |
| 1604 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "background", bg, NULL); | |
| 1605 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &iter, ©); | |
| 1606 } | |
| 1607 if (fonts) { | |
| 1608 GtkIMHtmlFontDetail *fd = fonts->data; | |
| 1609 if (fd->back) { | |
| 1610 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "background", fd->back, NULL); | |
| 1611 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &iter, ©); | |
| 1612 } | |
| 1613 } | |
| 7778 | 1614 */ |
| 4032 | 1615 c += smilelen; |
| 7778 | 1616 pos += smilelen; |
| 4032 | 1617 wpos = 0; |
| 1618 ws[0] = 0; | |
| 1619 } else if (*c) { | |
| 1428 | 1620 ws [wpos++] = *c++; |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1621 pos++; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1622 } else { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1623 break; |
| 1428 | 1624 } |
| 1625 } | |
| 3922 | 1626 |
| 7778 | 1627 gtk_text_buffer_insert(imhtml->text_buffer, &iter, ws, wpos); |
| 1628 ws[0] = '\0'; wpos = 0; | |
| 1629 | |
| 1630 //NEW_BIT(NEW_TEXT_BIT); | |
| 1428 | 1631 if (url) { |
| 1632 g_free (url); | |
| 3922 | 1633 if (str) |
| 1634 str = g_string_append (str, "</A>"); | |
| 1428 | 1635 } |
| 3922 | 1636 |
| 4032 | 1637 while (fonts) { |
| 5967 | 1638 GtkIMHtmlFontDetail *font = fonts->data; |
| 4032 | 1639 fonts = g_slist_remove (fonts, font); |
| 1640 if (font->face) | |
| 1641 g_free (font->face); | |
| 1642 if (font->fore) | |
| 1643 g_free (font->fore); | |
| 1644 if (font->back) | |
| 1645 g_free (font->back); | |
| 1646 if (font->sml) | |
| 1647 g_free (font->sml); | |
| 1648 g_free (font); | |
| 1649 if (str) | |
| 1650 str = g_string_append (str, "</FONT>"); | |
| 1651 } | |
| 1652 | |
| 3922 | 1653 if (str) { |
| 1428 | 1654 while (bold) { |
| 3922 | 1655 str = g_string_append (str, "</B>"); |
| 1428 | 1656 bold--; |
| 1657 } | |
| 1658 while (italics) { | |
| 3922 | 1659 str = g_string_append (str, "</I>"); |
| 1428 | 1660 italics--; |
| 1661 } | |
| 1662 while (underline) { | |
| 3922 | 1663 str = g_string_append (str, "</U>"); |
| 1428 | 1664 underline--; |
| 1665 } | |
| 1666 while (strike) { | |
| 3922 | 1667 str = g_string_append (str, "</S>"); |
| 1428 | 1668 strike--; |
| 1669 } | |
| 1670 while (sub) { | |
| 3922 | 1671 str = g_string_append (str, "</SUB>"); |
| 1428 | 1672 sub--; |
| 1673 } | |
| 1674 while (sup) { | |
| 3922 | 1675 str = g_string_append (str, "</SUP>"); |
| 1428 | 1676 sup--; |
| 1677 } | |
| 1678 while (title) { | |
| 3922 | 1679 str = g_string_append (str, "</TITLE>"); |
| 1428 | 1680 title--; |
| 1681 } | |
|
1691
d802b115800f
[gaim-migrate @ 1701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1647
diff
changeset
|
1682 while (pre) { |
| 3922 | 1683 str = g_string_append (str, "</PRE>"); |
|
1691
d802b115800f
[gaim-migrate @ 1701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1647
diff
changeset
|
1684 pre--; |
|
d802b115800f
[gaim-migrate @ 1701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1647
diff
changeset
|
1685 } |
| 1428 | 1686 } |
| 4032 | 1687 g_free (ws); |
| 4630 | 1688 if(bg) |
| 1689 g_free(bg); | |
| 7778 | 1690 gtk_imhtml_close_tags(imhtml); |
| 4032 | 1691 if (!(options & GTK_IMHTML_NO_SCROLL)) |
| 1692 gtk_text_view_scroll_to_mark (GTK_TEXT_VIEW (imhtml), mark, | |
| 1693 0, TRUE, 0.0, 1.0); | |
| 3922 | 1694 gtk_text_buffer_delete_mark (imhtml->text_buffer, mark); |
| 7778 | 1695 gtk_text_buffer_move_mark (imhtml->text_buffer, |
| 1696 gtk_text_buffer_get_mark (imhtml->text_buffer, "insert"), | |
| 1697 &iter); | |
| 3922 | 1698 return str; |
| 1699 } | |
| 1700 | |
| 4892 | 1701 void gtk_imhtml_remove_smileys(GtkIMHtml *imhtml) |
| 1702 { | |
| 4288 | 1703 g_hash_table_destroy(imhtml->smiley_data); |
| 1704 gtk_smiley_tree_destroy(imhtml->default_smilies); | |
| 4892 | 1705 imhtml->smiley_data = g_hash_table_new_full(g_str_hash, g_str_equal, |
| 4902 | 1706 g_free, (GDestroyNotify)gtk_smiley_tree_destroy); |
| 4288 | 1707 imhtml->default_smilies = gtk_smiley_tree_new(); |
| 1708 } | |
| 3922 | 1709 void gtk_imhtml_show_smileys (GtkIMHtml *imhtml, |
| 4253 | 1710 gboolean show) |
| 1711 { | |
| 1712 imhtml->show_smileys = show; | |
| 1713 } | |
| 3922 | 1714 |
| 1715 void gtk_imhtml_show_comments (GtkIMHtml *imhtml, | |
| 4253 | 1716 gboolean show) |
| 1717 { | |
| 6124 | 1718 imhtml->show_comments = show; |
| 4253 | 1719 } |
|
1780
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
1720 |
|
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
1721 void |
|
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
1722 gtk_imhtml_clear (GtkIMHtml *imhtml) |
|
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
1723 { |
| 3922 | 1724 GtkTextIter start, end; |
| 7700 | 1725 GList *del = imhtml->format_spans; |
| 2993 | 1726 |
| 3922 | 1727 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start); |
| 1728 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end); | |
| 1729 gtk_text_buffer_delete(imhtml->text_buffer, &start, &end); | |
| 7694 | 1730 |
| 1731 while (imhtml->format_spans) { | |
| 1732 GtkIMHtmlFormatSpan *span = imhtml->format_spans->data; | |
| 1733 if (span->start_tag) | |
| 1734 g_free(span->start_tag); | |
| 1735 if (span->end_tag) | |
| 1736 g_free(span->end_tag); | |
| 1737 g_free(span); | |
| 1738 imhtml->format_spans = imhtml->format_spans->next; | |
| 1739 } | |
| 7700 | 1740 g_list_free(del); |
| 7694 | 1741 imhtml->edit.bold = NULL; |
| 1742 imhtml->edit.italic = NULL; | |
| 1743 imhtml->edit.underline = NULL; | |
| 7717 | 1744 imhtml->edit.fontface = NULL; |
| 7728 | 1745 imhtml->edit.forecolor = NULL; |
| 1746 imhtml->edit.backcolor = NULL; | |
| 7740 | 1747 imhtml->edit.sizespan = NULL; |
| 1748 imhtml->edit.fontsize = 3; | |
|
1780
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
1749 } |
|
2363
08c66712364c
[gaim-migrate @ 2376]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2349
diff
changeset
|
1750 |
| 4046 | 1751 void gtk_imhtml_page_up (GtkIMHtml *imhtml) |
| 1752 { | |
| 5282 | 1753 GdkRectangle rect; |
| 1754 GtkTextIter iter; | |
| 4046 | 1755 |
| 5282 | 1756 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); |
| 1757 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(imhtml), &iter, rect.x, | |
| 1758 rect.y - rect.height); | |
| 1759 gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(imhtml), &iter, 0, TRUE, 0, 0); | |
| 1760 | |
| 4046 | 1761 } |
| 5282 | 1762 void gtk_imhtml_page_down (GtkIMHtml *imhtml) |
| 1763 { | |
| 1764 GdkRectangle rect; | |
| 1765 GtkTextIter iter; | |
| 1766 | |
| 1767 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); | |
| 1768 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(imhtml), &iter, rect.x, | |
| 1769 rect.y + rect.height); | |
| 1770 gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(imhtml), &iter, 0, TRUE, 0, 0); | |
| 1771 } | |
| 4735 | 1772 |
| 5967 | 1773 /* GtkIMHtmlScalable, gtk_imhtml_image, gtk_imhtml_hr */ |
| 6982 | 1774 GtkIMHtmlScalable *gtk_imhtml_image_new(GdkPixbuf *img, const gchar *filename) |
| 4735 | 1775 { |
| 5967 | 1776 GtkIMHtmlImage *im_image = g_malloc(sizeof(GtkIMHtmlImage)); |
| 5012 | 1777 GtkImage *image = GTK_IMAGE(gtk_image_new_from_pixbuf(img)); |
| 4895 | 1778 |
| 5967 | 1779 GTK_IMHTML_SCALABLE(im_image)->scale = gtk_imhtml_image_scale; |
| 1780 GTK_IMHTML_SCALABLE(im_image)->add_to = gtk_imhtml_image_add_to; | |
| 1781 GTK_IMHTML_SCALABLE(im_image)->free = gtk_imhtml_image_free; | |
| 5046 | 1782 |
| 1783 im_image->pixbuf = img; | |
| 5012 | 1784 im_image->image = image; |
| 4895 | 1785 im_image->width = gdk_pixbuf_get_width(img); |
| 1786 im_image->height = gdk_pixbuf_get_height(img); | |
| 1787 im_image->mark = NULL; | |
| 6982 | 1788 im_image->filename = filename ? g_strdup(filename) : NULL; |
| 4895 | 1789 |
| 5046 | 1790 g_object_ref(img); |
| 4895 | 1791 return GTK_IMHTML_SCALABLE(im_image); |
| 1792 } | |
| 1793 | |
| 5967 | 1794 void gtk_imhtml_image_scale(GtkIMHtmlScalable *scale, int width, int height) |
| 4895 | 1795 { |
| 5967 | 1796 GtkIMHtmlImage *image = (GtkIMHtmlImage *)scale; |
| 4895 | 1797 |
| 1798 if(image->width > width || image->height > height){ | |
| 1799 GdkPixbuf *new_image = NULL; | |
| 1800 float factor; | |
| 1801 int new_width = image->width, new_height = image->height; | |
| 1802 | |
| 1803 if(image->width > width){ | |
| 1804 factor = (float)(width)/image->width; | |
| 1805 new_width = width; | |
| 1806 new_height = image->height * factor; | |
| 1807 } | |
| 1808 if(new_height > height){ | |
| 1809 factor = (float)(height)/new_height; | |
| 1810 new_height = height; | |
| 1811 new_width = new_width * factor; | |
| 1812 } | |
| 1813 | |
| 5046 | 1814 new_image = gdk_pixbuf_scale_simple(image->pixbuf, new_width, new_height, GDK_INTERP_BILINEAR); |
| 5012 | 1815 gtk_image_set_from_pixbuf(image->image, new_image); |
| 4895 | 1816 g_object_unref(G_OBJECT(new_image)); |
| 1817 } | |
| 1818 } | |
| 1819 | |
| 5012 | 1820 static void write_img_to_file(GtkWidget *w, GtkFileSelection *sel) |
| 1821 { | |
| 1822 const gchar *filename = gtk_file_selection_get_filename(sel); | |
| 5967 | 1823 gchar *dirname; |
| 1824 GtkIMHtmlImage *image = g_object_get_data(G_OBJECT(sel), "GtkIMHtmlImage"); | |
| 5012 | 1825 gchar *type = NULL; |
| 5019 | 1826 GError *error = NULL; |
| 5015 | 1827 #if GTK_CHECK_VERSION(2,2,0) |
| 5012 | 1828 GSList *formats = gdk_pixbuf_get_formats(); |
| 6162 | 1829 #else |
| 1830 char *basename = g_path_get_basename(filename); | |
| 1831 char *ext = strrchr(basename, '.'); | |
| 5959 | 1832 #endif |
| 5012 | 1833 |
| 5967 | 1834 if (g_file_test(filename, G_FILE_TEST_IS_DIR)) { |
| 1835 /* append a / if needed */ | |
| 1836 if (filename[strlen(filename) - 1] != '/') { | |
| 1837 dirname = g_strconcat(filename, "/", NULL); | |
| 1838 } else { | |
| 1839 dirname = g_strdup(filename); | |
| 1840 } | |
| 1841 gtk_file_selection_set_filename(sel, dirname); | |
| 1842 g_free(dirname); | |
| 5959 | 1843 return; |
| 5967 | 1844 } |
| 5959 | 1845 |
| 1846 #if GTK_CHECK_VERSION(2,2,0) | |
| 5012 | 1847 while(formats){ |
| 1848 GdkPixbufFormat *format = formats->data; | |
| 1849 gchar **extensions = gdk_pixbuf_format_get_extensions(format); | |
| 1850 gpointer p = extensions; | |
| 1851 | |
| 1852 while(gdk_pixbuf_format_is_writable(format) && extensions && extensions[0]){ | |
| 1853 gchar *fmt_ext = extensions[0]; | |
| 1854 const gchar* file_ext = filename + strlen(filename) - strlen(fmt_ext); | |
| 1855 | |
| 1856 if(!strcmp(fmt_ext, file_ext)){ | |
| 1857 type = gdk_pixbuf_format_get_name(format); | |
| 1858 break; | |
| 1859 } | |
| 1860 | |
| 1861 extensions++; | |
| 1862 } | |
| 1863 | |
| 1864 g_strfreev(p); | |
| 1865 | |
| 1866 if(type) | |
| 1867 break; | |
| 1868 | |
| 1869 formats = formats->next; | |
| 1870 } | |
| 1871 | |
| 5020 | 1872 g_slist_free(formats); |
| 1873 #else | |
| 1874 /* this is really ugly code, but I think it will work */ | |
| 1875 if(ext) { | |
| 1876 ext++; | |
| 1877 if(!g_ascii_strcasecmp(ext, "jpeg") || !g_ascii_strcasecmp(ext, "jpg")) | |
| 1878 type = g_strdup("jpeg"); | |
| 1879 else if(!g_ascii_strcasecmp(ext, "png")) | |
| 1880 type = g_strdup("png"); | |
| 1881 } | |
| 1882 | |
| 1883 g_free(basename); | |
| 1884 #endif | |
| 1885 | |
| 5012 | 1886 /* If I can't find a valid type, I will just tell the user about it and then assume |
| 1887 it's a png */ | |
| 1888 if(!type){ | |
| 1889 gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, | |
| 5967 | 1890 _("Unable to guess the image type based on the file extension supplied. Defaulting to PNG.")); |
| 5012 | 1891 type = g_strdup("png"); |
| 1892 } | |
| 1893 | |
| 5046 | 1894 gdk_pixbuf_save(image->pixbuf, filename, type, &error, NULL); |
| 5012 | 1895 |
| 1896 if(error){ | |
| 1897 gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, | |
| 1898 _("Error saving image: %s"), error->message); | |
| 1899 g_error_free(error); | |
| 1900 } | |
| 1901 | |
| 1902 g_free(type); | |
| 1903 } | |
| 1904 | |
| 5967 | 1905 static void gtk_imhtml_image_save(GtkWidget *w, GtkIMHtmlImage *image) |
| 5012 | 1906 { |
| 5967 | 1907 GtkWidget *sel = gtk_file_selection_new(_("Save Image")); |
| 5012 | 1908 |
| 6982 | 1909 if (image->filename) |
| 1910 gtk_file_selection_set_filename(GTK_FILE_SELECTION(sel), image->filename); | |
| 5967 | 1911 g_object_set_data(G_OBJECT(sel), "GtkIMHtmlImage", image); |
| 5012 | 1912 g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(sel)->ok_button), "clicked", |
| 1913 G_CALLBACK(write_img_to_file), sel); | |
| 1914 | |
| 1915 g_signal_connect_swapped(G_OBJECT(GTK_FILE_SELECTION(sel)->ok_button), "clicked", | |
| 1916 G_CALLBACK(gtk_widget_destroy), sel); | |
| 1917 g_signal_connect_swapped(G_OBJECT(GTK_FILE_SELECTION(sel)->cancel_button), "clicked", | |
| 1918 G_CALLBACK(gtk_widget_destroy), sel); | |
| 1919 | |
| 1920 gtk_widget_show(sel); | |
| 1921 } | |
| 1922 | |
| 5967 | 1923 static gboolean gtk_imhtml_image_clicked(GtkWidget *w, GdkEvent *event, GtkIMHtmlImage *image) |
| 5012 | 1924 { |
| 1925 GdkEventButton *event_button = (GdkEventButton *) event; | |
| 1926 | |
| 1927 if (event->type == GDK_BUTTON_RELEASE) { | |
| 1928 if(event_button->button == 3) { | |
| 1929 GtkWidget *img, *item, *menu; | |
| 1930 gchar *text = g_strdup_printf(_("_Save Image...")); | |
| 1931 menu = gtk_menu_new(); | |
| 1932 | |
| 1933 /* buttons and such */ | |
| 1934 img = gtk_image_new_from_stock(GTK_STOCK_SAVE, GTK_ICON_SIZE_MENU); | |
| 1935 item = gtk_image_menu_item_new_with_mnemonic(text); | |
| 1936 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), img); | |
| 5967 | 1937 g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(gtk_imhtml_image_save), image); |
| 5012 | 1938 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); |
| 1939 | |
| 1940 gtk_widget_show_all(menu); | |
| 1941 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, | |
| 1942 event_button->button, event_button->time); | |
| 1943 | |
| 1944 g_free(text); | |
| 1945 return TRUE; | |
| 1946 } | |
| 1947 } | |
| 1948 if(event->type == GDK_BUTTON_PRESS && event_button->button == 3) | |
| 1949 return TRUE; /* Clicking the right mouse button on a link shouldn't | |
| 1950 be caught by the regular GtkTextView menu */ | |
| 1951 else | |
| 1952 return FALSE; /* Let clicks go through if we didn't catch anything */ | |
| 1953 | |
| 1954 } | |
| 5967 | 1955 void gtk_imhtml_image_free(GtkIMHtmlScalable *scale) |
| 1956 { | |
| 1957 GtkIMHtmlImage *image = (GtkIMHtmlImage *)scale; | |
| 1958 | |
| 1959 g_object_unref(image->pixbuf); | |
| 6982 | 1960 if (image->filename) |
| 1961 g_free(image->filename); | |
| 5967 | 1962 g_free(scale); |
| 1963 } | |
| 1964 | |
| 1965 void gtk_imhtml_image_add_to(GtkIMHtmlScalable *scale, GtkIMHtml *imhtml, GtkTextIter *iter) | |
| 1966 { | |
| 1967 GtkIMHtmlImage *image = (GtkIMHtmlImage *)scale; | |
| 1968 GtkWidget *box = gtk_event_box_new(); | |
| 1969 GtkTextChildAnchor *anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, iter); | |
| 1970 | |
| 1971 gtk_container_add(GTK_CONTAINER(box), GTK_WIDGET(image->image)); | |
| 1972 | |
| 1973 gtk_widget_show(GTK_WIDGET(image->image)); | |
| 1974 gtk_widget_show(box); | |
| 1975 | |
| 1976 gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(imhtml), box, anchor); | |
| 1977 g_signal_connect(G_OBJECT(box), "event", G_CALLBACK(gtk_imhtml_image_clicked), image); | |
| 1978 } | |
| 1979 | |
| 1980 GtkIMHtmlScalable *gtk_imhtml_hr_new() | |
| 1981 { | |
| 1982 GtkIMHtmlHr *hr = g_malloc(sizeof(GtkIMHtmlHr)); | |
| 1983 | |
| 1984 GTK_IMHTML_SCALABLE(hr)->scale = gtk_imhtml_hr_scale; | |
| 1985 GTK_IMHTML_SCALABLE(hr)->add_to = gtk_imhtml_hr_add_to; | |
| 1986 GTK_IMHTML_SCALABLE(hr)->free = gtk_imhtml_hr_free; | |
| 1987 | |
| 1988 hr->sep = gtk_hseparator_new(); | |
| 1989 gtk_widget_set_size_request(hr->sep, 5000, 2); | |
| 1990 gtk_widget_show(hr->sep); | |
| 1991 | |
| 1992 return GTK_IMHTML_SCALABLE(hr); | |
| 1993 } | |
| 1994 | |
| 1995 void gtk_imhtml_hr_scale(GtkIMHtmlScalable *scale, int width, int height) | |
| 1996 { | |
| 1997 gtk_widget_set_size_request(((GtkIMHtmlHr *)scale)->sep, width, 2); | |
| 1998 } | |
| 1999 | |
| 2000 void gtk_imhtml_hr_add_to(GtkIMHtmlScalable *scale, GtkIMHtml *imhtml, GtkTextIter *iter) | |
| 2001 { | |
| 2002 GtkIMHtmlHr *hr = (GtkIMHtmlHr *)scale; | |
| 2003 GtkTextChildAnchor *anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, iter); | |
| 2004 | |
| 2005 gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(imhtml), hr->sep, anchor); | |
| 2006 } | |
| 2007 | |
| 2008 void gtk_imhtml_hr_free(GtkIMHtmlScalable *scale) | |
| 2009 { | |
| 2010 g_free(scale); | |
| 2011 } | |
| 7295 | 2012 |
| 2013 gboolean gtk_imhtml_search_find(GtkIMHtml *imhtml, const gchar *text) | |
| 2014 { | |
| 2015 GtkTextIter iter, start, end; | |
| 2016 gboolean new_search = TRUE; | |
| 2017 | |
| 2018 g_return_val_if_fail(imhtml != NULL, FALSE); | |
| 2019 g_return_val_if_fail(text != NULL, FALSE); | |
| 7754 | 2020 |
| 7295 | 2021 if (imhtml->search_string && !strcmp(text, imhtml->search_string)) |
| 2022 new_search = FALSE; | |
| 7754 | 2023 |
| 7295 | 2024 if (new_search) { |
| 2025 gtk_imhtml_search_clear(imhtml); | |
| 2026 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &iter); | |
| 2027 } else { | |
| 2028 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, | |
| 2029 gtk_text_buffer_get_mark(imhtml->text_buffer, "search")); | |
| 2030 } | |
| 2031 imhtml->search_string = g_strdup(text); | |
| 2032 | |
| 7358 | 2033 if (gtk_source_iter_forward_search(&iter, imhtml->search_string, |
| 2034 GTK_SOURCE_SEARCH_VISIBLE_ONLY | GTK_SOURCE_SEARCH_CASE_INSENSITIVE, | |
| 7295 | 2035 &start, &end, NULL)) { |
| 2036 | |
| 2037 gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(imhtml), &start, 0, TRUE, 0, 0); | |
| 2038 gtk_text_buffer_create_mark(imhtml->text_buffer, "search", &end, FALSE); | |
| 2039 if (new_search) { | |
| 2040 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "search", &iter, &end); | |
| 2041 do | |
| 2042 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "search", &start, &end); | |
| 7358 | 2043 while (gtk_source_iter_forward_search(&end, imhtml->search_string, |
| 2044 GTK_SOURCE_SEARCH_VISIBLE_ONLY | | |
| 2045 GTK_SOURCE_SEARCH_CASE_INSENSITIVE, | |
| 7295 | 2046 &start, &end, NULL)); |
| 2047 } | |
| 2048 return TRUE; | |
| 2049 } | |
| 7754 | 2050 |
| 2051 gtk_imhtml_search_clear(imhtml); | |
| 2052 | |
| 7295 | 2053 return FALSE; |
| 2054 } | |
| 2055 | |
| 2056 void gtk_imhtml_search_clear(GtkIMHtml *imhtml) | |
| 2057 { | |
| 2058 GtkTextIter start, end; | |
| 2059 | |
| 2060 g_return_if_fail(imhtml != NULL); | |
| 2061 | |
| 2062 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start); | |
| 2063 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end); | |
| 2064 | |
| 2065 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "search", &start, &end); | |
| 2066 if (imhtml->search_string) | |
| 2067 g_free(imhtml->search_string); | |
| 2068 imhtml->search_string = NULL; | |
| 2069 } | |
| 7694 | 2070 |
| 2071 /* Editable stuff */ | |
| 2072 static void insert_cb(GtkTextBuffer *buffer, GtkTextIter *iter, gchar *text, gint len, GtkIMHtml *imhtml) | |
| 2073 { | |
| 2074 GtkIMHtmlFormatSpan *span = NULL; | |
| 7734 | 2075 GtkTextIter end; |
| 2076 | |
| 7717 | 2077 gtk_text_iter_forward_chars(iter, len); |
| 7734 | 2078 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end); |
| 2079 gtk_text_iter_forward_char(&end); | |
| 7694 | 2080 |
| 7778 | 2081 //if (!gtk_text_iter_equal(&end, iter)) |
| 2082 // return; | |
| 7694 | 2083 |
| 7778 | 2084 |
| 7694 | 2085 if ((span = imhtml->edit.bold)) { |
| 2086 GtkTextIter bold; | |
| 2087 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &bold, span->start); | |
| 2088 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "BOLD", &bold, iter); | |
| 2089 } | |
| 7729 | 2090 |
| 7694 | 2091 if ((span = imhtml->edit.italic)) { |
| 2092 GtkTextIter italic; | |
| 2093 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &italic, span->start); | |
| 7729 | 2094 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "ITALICS", &italic, |
| 2095 iter); | |
| 7694 | 2096 } |
| 7729 | 2097 |
| 2098 if ((span = imhtml->edit.underline)) { | |
| 2099 GtkTextIter underline; | |
| 2100 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &underline, span->start); | |
| 2101 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "UNDERLINE", &underline, | |
| 2102 iter); | |
| 2103 } | |
| 2104 | |
| 7714 | 2105 if ((span = imhtml->edit.forecolor)) { |
| 2106 GtkTextIter fore; | |
| 2107 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &fore, span->start); | |
| 2108 gtk_text_buffer_apply_tag(imhtml->text_buffer, span->tag, &fore, iter); | |
| 7694 | 2109 } |
| 7729 | 2110 |
| 7714 | 2111 if ((span = imhtml->edit.backcolor)) { |
| 2112 GtkTextIter back; | |
| 2113 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &back, span->start); | |
| 2114 gtk_text_buffer_apply_tag(imhtml->text_buffer, span->tag, &back, iter); | |
| 2115 } | |
| 7729 | 2116 |
| 7717 | 2117 if ((span = imhtml->edit.fontface)) { |
| 2118 GtkTextIter face; | |
| 2119 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &face, span->start); | |
| 2120 gtk_text_buffer_apply_tag(imhtml->text_buffer, span->tag, &face, iter); | |
| 2121 } | |
| 7740 | 2122 |
| 2123 if ((span = imhtml->edit.sizespan)) { | |
| 2124 GtkTextIter size; | |
| 2125 /* We create the tags here so that one can grow font or shrink font several times | |
| 2126 * in a row without creating unnecessary tags */ | |
| 2127 if (span->tag == NULL) { | |
| 2128 span->tag = gtk_text_buffer_create_tag | |
| 2129 (imhtml->text_buffer, NULL, "size-points", (double)_point_sizes [imhtml->edit.fontsize-1], NULL); | |
| 7778 | 2130 span->start_tag = g_strdup_printf("<font size=\"%d\">", imhtml->edit.fontsize); |
| 7740 | 2131 span->end_tag = g_strdup("</font>"); |
| 2132 } | |
| 2133 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &size, span->start); | |
| 2134 gtk_text_buffer_apply_tag(imhtml->text_buffer, span->tag, &size, iter); | |
| 2135 } | |
| 7694 | 2136 } |
| 2137 | |
| 2138 void gtk_imhtml_set_editable(GtkIMHtml *imhtml, gboolean editable) | |
| 2139 { | |
| 2140 gtk_text_view_set_editable(GTK_TEXT_VIEW(imhtml), editable); | |
| 2141 gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(imhtml), editable); | |
| 2142 imhtml->editable = editable; | |
| 2143 } | |
| 2144 | |
| 2145 gboolean gtk_imhtml_get_editable(GtkIMHtml *imhtml) | |
| 2146 { | |
| 2147 return imhtml->editable; | |
| 2148 } | |
| 2149 | |
| 2150 gboolean gtk_imhtml_toggle_bold(GtkIMHtml *imhtml) | |
| 2151 { | |
| 7707 | 2152 GtkIMHtmlFormatSpan *span; |
| 7694 | 2153 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); |
| 2154 GtkTextIter iter; | |
| 2155 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins); | |
| 2156 if (!imhtml->edit.bold) { | |
| 7707 | 2157 span = g_malloc(sizeof(GtkIMHtmlFormatSpan)); |
| 7694 | 2158 span->start = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); |
| 2159 span->start_tag = g_strdup("<b>"); | |
| 2160 span->end = NULL; | |
| 2161 span->end_tag = g_strdup("</b>"); | |
| 2162 span->buffer = imhtml->text_buffer; | |
| 7714 | 2163 span->tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), "BOLD"); |
| 7694 | 2164 imhtml->edit.bold = span; |
| 2165 imhtml->format_spans = g_list_append(imhtml->format_spans, span); | |
| 2166 } else { | |
| 2167 span = imhtml->edit.bold; | |
| 7778 | 2168 printf("Set end\n"); |
| 7694 | 2169 span->end = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); |
| 2170 imhtml->edit.bold = NULL; | |
| 2171 } | |
| 2172 return imhtml->edit.bold != NULL; | |
| 2173 } | |
| 2174 | |
| 2175 gboolean gtk_imhtml_toggle_italic(GtkIMHtml *imhtml) | |
| 2176 { | |
| 7707 | 2177 GtkIMHtmlFormatSpan *span; |
| 7694 | 2178 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); |
| 2179 GtkTextIter iter; | |
| 2180 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins); | |
| 2181 if (!imhtml->edit.italic) { | |
| 7707 | 2182 span = g_malloc(sizeof(GtkIMHtmlFormatSpan)); |
| 7694 | 2183 span->start = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); |
| 2184 span->start_tag = g_strdup("<i>"); | |
| 2185 span->end = NULL; | |
| 2186 span->end_tag = g_strdup("</i>"); | |
| 2187 span->buffer = imhtml->text_buffer; | |
| 7714 | 2188 span->tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), "ITALIC"); |
| 7694 | 2189 imhtml->edit.italic = span; |
| 2190 imhtml->format_spans = g_list_append(imhtml->format_spans, span); | |
| 2191 } else { | |
| 2192 span = imhtml->edit.italic; | |
| 2193 span->end = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); | |
| 2194 imhtml->edit.italic = NULL; | |
| 2195 } | |
| 2196 return imhtml->edit.italic != NULL; | |
| 2197 } | |
| 7714 | 2198 |
| 7694 | 2199 gboolean gtk_imhtml_toggle_underline(GtkIMHtml *imhtml) |
| 2200 { | |
| 7707 | 2201 GtkIMHtmlFormatSpan *span; |
| 7694 | 2202 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); |
| 2203 GtkTextIter iter; | |
| 2204 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins); | |
| 2205 if (!imhtml->edit.underline) { | |
| 7707 | 2206 span = g_malloc(sizeof(GtkIMHtmlFormatSpan)); |
| 7694 | 2207 span->start = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); |
| 2208 span->start_tag = g_strdup("<u>"); | |
| 2209 span->end = NULL; | |
| 2210 span->end_tag = g_strdup("</u>"); | |
| 2211 span->buffer = imhtml->text_buffer; | |
| 7714 | 2212 span->tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), "UNDERLINE"); |
| 7694 | 2213 imhtml->edit.underline = span; |
| 2214 imhtml->format_spans = g_list_append(imhtml->format_spans, span); | |
| 2215 } else { | |
| 7697 | 2216 span = imhtml->edit.underline; |
| 7694 | 2217 span->end = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); |
| 2218 imhtml->edit.underline = NULL; | |
| 2219 } | |
| 2220 return imhtml->edit.underline != NULL; | |
| 2221 } | |
| 2222 | |
| 7778 | 2223 void gtk_imhtml_font_set_size(GtkIMHtml *imhtml, gint size) |
| 2224 { | |
| 2225 GtkIMHtmlFormatSpan *span; | |
| 2226 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); | |
| 2227 GtkTextIter iter; | |
| 2228 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins); | |
| 2229 | |
| 2230 imhtml->edit.fontsize = size; | |
| 2231 | |
| 2232 if (imhtml->edit.sizespan) { | |
| 2233 GtkTextIter iter2; | |
| 2234 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter2, imhtml->edit.sizespan->start); | |
| 2235 if (gtk_text_iter_equal(&iter2, &iter)) | |
| 2236 return; | |
| 2237 span = imhtml->edit.sizespan; | |
| 2238 span->end = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); | |
| 2239 } | |
| 2240 if (size != -1) { | |
| 2241 span = g_malloc(sizeof(GtkIMHtmlFormatSpan)); | |
| 2242 span->start = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); | |
| 2243 span->end = NULL; | |
| 2244 span->buffer = imhtml->text_buffer; | |
| 2245 span->tag = NULL; | |
| 2246 imhtml->edit.sizespan = span; | |
| 2247 imhtml->format_spans = g_list_append(imhtml->format_spans, span); | |
| 2248 } | |
| 2249 } | |
| 2250 | |
| 7740 | 2251 void gtk_imhtml_font_shrink(GtkIMHtml *imhtml) |
| 2252 { | |
| 2253 GtkIMHtmlFormatSpan *span; | |
| 2254 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); | |
| 2255 GtkTextIter iter; | |
| 2256 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins); | |
| 2257 if (imhtml->edit.fontsize == 1) | |
| 2258 return; | |
| 2259 | |
| 2260 imhtml->edit.fontsize--; | |
| 2261 | |
| 2262 if (imhtml->edit.sizespan) { | |
| 2263 GtkTextIter iter2; | |
| 2264 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter2, imhtml->edit.sizespan->start); | |
| 2265 if (gtk_text_iter_equal(&iter2, &iter)) | |
| 2266 return; | |
| 2267 span = imhtml->edit.sizespan; | |
| 2268 span->end = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); | |
| 2269 } | |
| 2270 | |
| 2271 span = g_malloc(sizeof(GtkIMHtmlFormatSpan)); | |
| 2272 span->start = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); | |
| 2273 span->end = NULL; | |
| 2274 span->buffer = imhtml->text_buffer; | |
| 2275 span->tag = NULL; | |
| 2276 imhtml->edit.sizespan = span; | |
| 2277 imhtml->format_spans = g_list_append(imhtml->format_spans, span); | |
| 2278 } | |
| 2279 | |
| 2280 void gtk_imhtml_font_grow(GtkIMHtml *imhtml) | |
| 2281 { | |
| 2282 GtkIMHtmlFormatSpan *span; | |
| 2283 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); | |
| 2284 GtkTextIter iter; | |
| 2285 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins); | |
| 2286 if (imhtml->edit.fontsize == MAX_FONT_SIZE) | |
| 2287 return; | |
| 2288 | |
| 2289 imhtml->edit.fontsize++; | |
| 2290 | |
| 2291 if (imhtml->edit.sizespan) { | |
| 2292 GtkTextIter iter2; | |
| 2293 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter2, imhtml->edit.sizespan->start); | |
| 2294 if (gtk_text_iter_equal(&iter2, &iter)) | |
| 2295 return; | |
| 2296 span = imhtml->edit.sizespan; | |
| 2297 span->end = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); | |
| 2298 } | |
| 2299 | |
| 2300 span = g_malloc(sizeof(GtkIMHtmlFormatSpan)); | |
| 2301 span->start = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); | |
| 2302 span->end = NULL; | |
| 2303 span->tag = NULL; | |
| 2304 span->buffer = imhtml->text_buffer; | |
| 2305 imhtml->edit.sizespan = span; | |
| 2306 imhtml->format_spans = g_list_append(imhtml->format_spans, span); | |
| 2307 } | |
| 2308 | |
| 7714 | 2309 gboolean gtk_imhtml_toggle_forecolor(GtkIMHtml *imhtml, const char *color) |
| 2310 { | |
| 2311 GtkIMHtmlFormatSpan *span; | |
| 2312 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); | |
| 2313 GtkTextIter iter; | |
| 2314 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins); | |
| 2315 if (!imhtml->edit.forecolor) { | |
| 2316 span = g_malloc(sizeof(GtkIMHtmlFormatSpan)); | |
| 2317 span->start = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); | |
| 7778 | 2318 span->start_tag = g_strdup_printf("<font color=\"%s\">", color); |
| 7714 | 2319 span->end = NULL; |
| 2320 span->end_tag = g_strdup("</font>"); | |
| 2321 span->buffer = imhtml->text_buffer; | |
| 2322 span->tag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "foreground", color, NULL); | |
| 2323 imhtml->edit.forecolor = span; | |
| 2324 imhtml->format_spans = g_list_append(imhtml->format_spans, span); | |
| 2325 } else { | |
| 2326 span = imhtml->edit.forecolor; | |
| 2327 span->end = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); | |
| 2328 imhtml->edit.forecolor = NULL; | |
| 2329 } | |
| 7778 | 2330 |
| 2331 | |
| 7714 | 2332 return imhtml->edit.forecolor != NULL; |
| 2333 } | |
| 2334 | |
| 2335 gboolean gtk_imhtml_toggle_backcolor(GtkIMHtml *imhtml, const char *color) | |
| 2336 { | |
| 2337 GtkIMHtmlFormatSpan *span; | |
| 2338 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); | |
| 2339 GtkTextIter iter; | |
| 2340 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins); | |
| 2341 if (!imhtml->edit.backcolor) { | |
| 2342 span = g_malloc(sizeof(GtkIMHtmlFormatSpan)); | |
| 2343 span->start = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); | |
| 7778 | 2344 span->start_tag = g_strdup_printf("<font back=\"%s\">", color); |
| 7714 | 2345 span->end = NULL; |
| 2346 span->end_tag = g_strdup("</font>"); | |
| 2347 span->buffer = imhtml->text_buffer; | |
| 2348 span->tag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "background", color, NULL); | |
| 2349 imhtml->edit.backcolor = span; | |
| 2350 imhtml->format_spans = g_list_append(imhtml->format_spans, span); | |
| 2351 } else { | |
| 2352 span = imhtml->edit.backcolor; | |
| 2353 span->end = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); | |
| 2354 imhtml->edit.backcolor = NULL; | |
| 2355 } | |
| 2356 return imhtml->edit.backcolor != NULL; | |
| 2357 } | |
| 2358 | |
| 7717 | 2359 gboolean gtk_imhtml_toggle_fontface(GtkIMHtml *imhtml, const char *face) |
| 2360 { | |
| 2361 GtkIMHtmlFormatSpan *span; | |
| 2362 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); | |
| 2363 GtkTextIter iter; | |
| 2364 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins); | |
| 2365 if (!imhtml->edit.fontface) { | |
| 2366 span = g_malloc(sizeof(GtkIMHtmlFormatSpan)); | |
| 2367 span->start = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); | |
| 7778 | 2368 span->start_tag = g_strdup_printf("<font face=\"%s\">", face); |
| 7717 | 2369 span->end = NULL; |
| 2370 span->end_tag = g_strdup("</font>"); | |
| 2371 span->buffer = imhtml->text_buffer; | |
| 2372 span->tag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "family", face, NULL); | |
| 2373 imhtml->edit.fontface = span; | |
| 2374 imhtml->format_spans = g_list_append(imhtml->format_spans, span); | |
| 2375 } else { | |
| 2376 span = imhtml->edit.fontface; | |
| 2377 span->end = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); | |
| 2378 imhtml->edit.fontface = NULL; | |
| 2379 } | |
| 2380 return imhtml->edit.fontface != NULL; | |
| 2381 } | |
| 2382 | |
| 7707 | 2383 void gtk_imhtml_insert_link(GtkIMHtml *imhtml, const char *url, const char *text) |
| 2384 { | |
| 2385 GtkIMHtmlFormatSpan *span = g_malloc(sizeof(GtkIMHtmlFormatSpan)); | |
| 2386 GtkTextMark *mark = gtk_text_buffer_get_insert(imhtml->text_buffer); | |
| 2387 GtkTextIter iter; | |
| 2388 GtkTextTag *tag, *linktag; | |
| 2389 | |
| 2390 tag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, NULL); | |
| 2391 g_object_set_data(G_OBJECT(tag), "link_url", g_strdup(url)); | |
| 2392 | |
| 2393 linktag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), "LINK"); | |
| 2394 | |
| 2395 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, mark); | |
| 2396 span->start = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); | |
| 2397 span->buffer = imhtml->text_buffer; | |
| 2398 span->start_tag = g_strdup_printf("<a href='%s'>", url); | |
| 2399 span->end_tag = g_strdup("</a>"); | |
| 2400 | |
| 2401 gtk_text_buffer_insert_with_tags(imhtml->text_buffer, &iter, text, strlen(text), linktag, tag, NULL); | |
| 2402 span->end = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); | |
| 2403 imhtml->format_spans = g_list_append(imhtml->format_spans, span); | |
| 2404 } | |
| 2405 | |
| 7736 | 2406 void gtk_imhtml_insert_smiley(GtkIMHtml *imhtml, const char *sml, char *smiley) |
| 7735 | 2407 { |
| 2408 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); | |
| 2409 GtkTextIter iter; | |
| 2410 GdkPixbuf *pixbuf = NULL; | |
| 2411 GdkPixbufAnimation *annipixbuf = NULL; | |
| 2412 GtkWidget *icon = NULL; | |
| 7749 | 2413 GtkTextChildAnchor *anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, &iter); |
| 2414 | |
| 2415 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins); | |
| 2416 g_object_set_data(G_OBJECT(anchor), "text_tag", smiley); | |
| 7735 | 2417 |
| 7736 | 2418 annipixbuf = gtk_smiley_tree_image(imhtml, sml, smiley); |
| 7735 | 2419 if(annipixbuf) { |
| 7749 | 2420 if(gdk_pixbuf_animation_is_static_image(annipixbuf)) { |
| 7735 | 2421 pixbuf = gdk_pixbuf_animation_get_static_image(annipixbuf); |
| 2422 if(pixbuf) | |
| 2423 icon = gtk_image_new_from_pixbuf(pixbuf); | |
| 2424 } else { | |
| 2425 icon = gtk_image_new_from_animation(annipixbuf); | |
| 2426 } | |
| 2427 } | |
| 2428 | |
| 2429 if (icon) { | |
| 2430 gtk_widget_show(icon); | |
| 2431 gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(imhtml), icon, anchor); | |
| 2432 } | |
| 2433 } | |
| 2434 | |
| 7694 | 2435 int span_compare_begin(const GtkIMHtmlFormatSpan *a, const GtkIMHtmlFormatSpan *b, GtkTextBuffer *buffer) |
| 2436 { | |
| 2437 GtkTextIter ia, ib; | |
| 2438 gtk_text_buffer_get_iter_at_mark(buffer, &ia, a->start); | |
| 2439 gtk_text_buffer_get_iter_at_mark(buffer, &ib, b->start); | |
| 2440 return gtk_text_iter_compare(&ia, &ib); | |
| 2441 } | |
| 2442 | |
| 2443 int span_compare_end(GtkIMHtmlFormatSpan *a, GtkIMHtmlFormatSpan *b) | |
| 2444 { | |
| 2445 GtkTextIter ia, ib; | |
| 2446 gtk_text_buffer_get_iter_at_mark(a->buffer, &ia, a->start); | |
| 2447 gtk_text_buffer_get_iter_at_mark(b->buffer, &ib, b->start); | |
| 2448 return gtk_text_iter_compare(&ia, &ib); | |
| 2449 } | |
| 2450 | |
| 2451 /* Basic notion here: traverse through the text buffer one-by-one, non-character elements, such | |
| 2452 * as smileys and IM images are represented by the Unicode "unknown" character. Handle them. Else | |
| 2453 * check the list of formatted strings, sorted by the position of the starting tags and apply them as | |
| 2454 * needed. After applying the start tags, add the end tags to the "closers" list, which is sorted by | |
| 2455 * location of ending tags. These get applied in a similar fashion. Finally, replace <, >, &, and " | |
| 2456 * with their HTML equivilent. */ | |
| 7749 | 2457 char *gtk_imhtml_get_markup_range(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *end) |
| 7694 | 2458 { |
| 2459 gunichar c; | |
| 2460 GtkIMHtmlFormatSpan *sspan = NULL, *espan = NULL; | |
| 2461 GtkTextIter iter, siter, eiter; | |
| 2462 GList *starters = imhtml->format_spans; | |
| 7749 | 2463 GList *closers = NULL; |
| 7694 | 2464 GString *str = g_string_new(""); |
| 2465 g_list_sort_with_data(starters, (GCompareDataFunc)span_compare_begin, imhtml->text_buffer); | |
| 7749 | 2466 |
| 2467 gtk_text_iter_order(start, end); | |
| 2468 iter = *start; | |
| 2469 | |
| 7694 | 2470 |
| 2471 /* Initialize these to the end iter */ | |
| 2472 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &siter); | |
| 2473 eiter = siter; | |
| 2474 | |
| 2475 if (starters) { | |
| 7749 | 2476 while (starters) { |
| 2477 GtkTextIter tagend; | |
| 2478 sspan = (GtkIMHtmlFormatSpan*)starters->data; | |
| 2479 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &siter, sspan->start); | |
| 2480 if (gtk_text_iter_compare(&siter, start) > 0) | |
| 2481 break; | |
| 2482 if (sspan->end) | |
| 2483 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &tagend, sspan->end); | |
| 2484 if (sspan->end == NULL || gtk_text_iter_compare(&tagend, start) > 0) { | |
| 2485 str = g_string_append(str, sspan->start_tag); | |
| 2486 closers = g_list_append(closers, sspan); | |
| 2487 } | |
| 2488 sspan = (GtkIMHtmlFormatSpan*)starters->data; | |
| 2489 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &siter, sspan->start); | |
| 2490 starters = starters->next; | |
| 2491 } | |
| 2492 if (!starters) { | |
| 2493 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &siter); | |
| 2494 sspan = NULL; | |
| 2495 } | |
| 7694 | 2496 } |
| 2497 | |
| 7749 | 2498 while ((c = gtk_text_iter_get_char(&iter)) != 0 && !gtk_text_iter_equal(&iter, end)) { |
| 7694 | 2499 if (c == 0xFFFC) { |
| 7735 | 2500 GtkTextChildAnchor* anchor = gtk_text_iter_get_child_anchor(&iter); |
| 2501 char *text = g_object_get_data(G_OBJECT(anchor), "text_tag"); | |
| 2502 str = g_string_append(str, text); | |
| 7694 | 2503 } else { |
| 2504 while (gtk_text_iter_equal(&eiter, &iter)) { | |
| 2505 /* This is where we shall insert the ending tag of | |
| 2506 * this format span */ | |
| 2507 str = g_string_append(str, espan->end_tag); | |
| 2508 closers = g_list_remove(closers, espan); | |
| 7778 | 2509 if (!closers) { |
| 7694 | 2510 espan = NULL; |
| 2511 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &eiter); | |
| 7778 | 2512 } else { |
| 2513 espan = (GtkIMHtmlFormatSpan*)closers->data; | |
| 2514 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &eiter, espan->end); | |
| 7694 | 2515 } |
| 2516 } | |
| 2517 while (gtk_text_iter_equal(&siter, &iter)) { | |
| 2518 /* This is where we shall insert the starting tag of | |
| 2519 * this format span */ | |
| 2520 str = g_string_append(str, sspan->start_tag); | |
| 2521 if (sspan->end) { | |
| 7778 | 2522 //espan = sspan; |
| 2523 //gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &eiter, espan->end); | |
| 7694 | 2524 closers = g_list_insert_sorted(closers, sspan, (GCompareFunc)span_compare_end); |
| 7779 | 2525 espan = (GtkIMHtmlFormatSpan*)closers->data; |
| 2526 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &eiter, espan->end); | |
| 2527 | |
| 7694 | 2528 } |
| 2529 starters = starters->next; | |
| 2530 if (starters) { | |
| 2531 sspan = (GtkIMHtmlFormatSpan*)starters->data; | |
| 2532 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &siter, sspan->start); | |
| 2533 } else { | |
| 2534 sspan = NULL; | |
| 2535 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &siter); | |
| 2536 } | |
| 2537 | |
| 2538 } | |
| 7715 | 2539 |
| 2540 if (c == '<') | |
| 2541 str = g_string_append(str, "<"); | |
| 2542 else if (c == '>') | |
| 2543 str = g_string_append(str, ">"); | |
| 2544 else if (c == '&') | |
| 2545 str = g_string_append(str, "&"); | |
| 2546 else if (c == '"') | |
| 2547 str = g_string_append(str, """); | |
| 7716 | 2548 else |
| 2549 str = g_string_append_unichar(str, c); | |
| 7694 | 2550 } |
| 2551 gtk_text_iter_forward_char(&iter); | |
| 2552 } | |
| 7778 | 2553 while (closers) { |
| 2554 GtkIMHtmlFormatSpan *span = (GtkIMHtmlFormatSpan*)closers->data; | |
| 2555 str = g_string_append(str, span->end_tag); | |
| 2556 closers = g_list_remove(closers, span); | |
| 2557 } | |
| 7694 | 2558 return g_string_free(str, FALSE); |
| 2559 } | |
| 2560 | |
| 7778 | 2561 void gtk_imhtml_close_tags(GtkIMHtml *imhtml) |
| 2562 { | |
| 2563 | |
| 2564 if (imhtml->edit.bold) | |
| 2565 gtk_imhtml_toggle_bold(imhtml); | |
| 2566 | |
| 2567 if (imhtml->edit.italic) | |
| 2568 gtk_imhtml_toggle_italic(imhtml); | |
| 2569 | |
| 2570 if (imhtml->edit.underline) | |
| 2571 gtk_imhtml_toggle_underline(imhtml); | |
| 2572 | |
| 2573 if (imhtml->edit.forecolor) | |
| 2574 gtk_imhtml_toggle_forecolor(imhtml, NULL); | |
| 2575 | |
| 2576 if (imhtml->edit.backcolor) | |
| 2577 gtk_imhtml_toggle_backcolor(imhtml, NULL); | |
| 2578 | |
| 2579 if (imhtml->edit.fontface) | |
| 2580 gtk_imhtml_toggle_fontface(imhtml, NULL); | |
| 2581 | |
| 2582 if (imhtml->edit.sizespan) | |
| 2583 gtk_imhtml_font_set_size(imhtml, -1); | |
| 2584 | |
| 2585 } | |
| 2586 | |
| 7749 | 2587 char *gtk_imhtml_get_markup(GtkIMHtml *imhtml) |
| 2588 { | |
| 7778 | 2589 char *text; |
| 7749 | 2590 GtkTextIter start, end; |
| 7778 | 2591 |
| 7749 | 2592 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start); |
| 7778 | 2593 // gtk_text_iter_backward_char(&start); |
| 7749 | 2594 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end); |
| 7778 | 2595 text = gtk_imhtml_get_markup_range(imhtml, &start, &end); |
| 2596 printf("%s\n", text); | |
| 2597 // return gtk_imhtml_get_markup_range(imhtml, &start, &end); | |
| 2598 return text; | |
| 7749 | 2599 } |
| 2600 | |
| 7694 | 2601 char *gtk_imhtml_get_text(GtkIMHtml *imhtml) |
| 2602 { | |
| 2603 GtkTextIter start_iter, end_iter; | |
| 2604 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start_iter); | |
| 2605 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end_iter); | |
| 2606 return gtk_text_buffer_get_text(imhtml->text_buffer, &start_iter, &end_iter, FALSE); | |
| 2607 | |
| 2608 } | |
| 7778 | 2609 |
