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