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