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