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