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