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