Mercurial > pidgin.yaz
annotate src/gtkimhtml.c @ 7394:c6ff3c1fb1b3
[gaim-migrate @ 7989]
NEWS is embarrassing when you don't do anything
committer: Tailor Script <tailor@pidgin.im>
author | Ethan Blanton <elb@pidgin.im> |
---|---|
date | Fri, 31 Oct 2003 01:38:46 +0000 |
parents | 414c701ef1ff |
children | d889a99e0eb1 |
rev | line source |
---|---|
1428 | 1 /* |
2 * GtkIMHtml | |
3 * | |
4 * Copyright (C) 2000, Eric Warmenhoven <warmenhoven@yahoo.com> | |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 * | |
20 */ | |
21 | |
2541
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
22 #ifdef HAVE_CONFIG_H |
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
23 #include <config.h> |
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
24 #endif |
1428 | 25 #include "gtkimhtml.h" |
7358 | 26 #include "gtksourceiter.h" |
1428 | 27 #include <gtk/gtk.h> |
4895 | 28 #include <glib/gerror.h> |
4046 | 29 #include <gdk/gdkkeysyms.h> |
1428 | 30 #include <string.h> |
31 #include <ctype.h> | |
32 #include <stdio.h> | |
4629 | 33 #include <stdlib.h> |
1428 | 34 #include <math.h> |
2541
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
35 #ifdef HAVE_LANGINFO_CODESET |
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
36 #include <langinfo.h> |
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
37 #include <locale.h> |
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
38 #endif |
1428 | 39 |
4417 | 40 #ifdef ENABLE_NLS |
41 # include <libintl.h> | |
42 # define _(x) gettext(x) | |
43 # ifdef gettext_noop | |
44 # define N_(String) gettext_noop (String) | |
45 # else | |
46 # define N_(String) (String) | |
47 # endif | |
48 #else | |
49 # define N_(String) (String) | |
50 # define _(x) (x) | |
51 #endif | |
52 | |
4735 | 53 #include <pango/pango-font.h> |
54 | |
5105 | 55 /* GTK+ < 2.2.2 hack, see ui.h for details. */ |
56 #ifndef GTK_WRAP_WORD_CHAR | |
57 #define GTK_WRAP_WORD_CHAR GTK_WRAP_WORD | |
58 #endif | |
59 | |
4735 | 60 #define TOOLTIP_TIMEOUT 500 |
61 | |
3922 | 62 /* POINT_SIZE converts from AIM font sizes to point sizes. It probably should be redone in such a |
63 * way that it base the sizes off the default font size rather than using arbitrary font sizes. */ | |
64 #define MAX_FONT_SIZE 7 | |
5367 | 65 #define POINT_SIZE(x) (options & GTK_IMHTML_USE_POINTSIZE ? x : _point_sizes [MIN ((x), MAX_FONT_SIZE) - 1]) |
3928 | 66 static gint _point_sizes [] = { 8, 10, 12, 14, 20, 30, 40 }; |
2349
60c716c32c40
[gaim-migrate @ 2362]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2348
diff
changeset
|
67 |
4032 | 68 static GtkSmileyTree* |
69 gtk_smiley_tree_new () | |
70 { | |
71 return g_new0 (GtkSmileyTree, 1); | |
72 } | |
73 | |
74 static void | |
75 gtk_smiley_tree_insert (GtkSmileyTree *tree, | |
4263 | 76 GtkIMHtmlSmiley *smiley) |
4032 | 77 { |
78 GtkSmileyTree *t = tree; | |
4263 | 79 const gchar *x = smiley->smile; |
4032 | 80 |
81 if (!strlen (x)) | |
82 return; | |
83 | |
84 while (*x) { | |
85 gchar *pos; | |
86 gint index; | |
87 | |
88 if (!t->values) | |
89 t->values = g_string_new (""); | |
90 | |
91 pos = strchr (t->values->str, *x); | |
92 if (!pos) { | |
93 t->values = g_string_append_c (t->values, *x); | |
94 index = t->values->len - 1; | |
95 t->children = g_realloc (t->children, t->values->len * sizeof (GtkSmileyTree *)); | |
96 t->children [index] = g_new0 (GtkSmileyTree, 1); | |
97 } else | |
7386 | 98 index = GPOINTER_TO_INT(pos) - GPOINTER_TO_INT(t->values->str); |
4032 | 99 |
100 t = t->children [index]; | |
101 | |
102 x++; | |
103 } | |
104 | |
4263 | 105 t->image = smiley; |
4032 | 106 } |
4041 | 107 |
4263 | 108 |
4264 | 109 void gtk_smiley_tree_destroy (GtkSmileyTree *tree) |
4032 | 110 { |
111 GSList *list = g_slist_append (NULL, tree); | |
112 | |
113 while (list) { | |
114 GtkSmileyTree *t = list->data; | |
115 gint i; | |
116 list = g_slist_remove(list, t); | |
7384 | 117 if (t && t->values) { |
4032 | 118 for (i = 0; i < t->values->len; i++) |
119 list = g_slist_append (list, t->children [i]); | |
120 g_string_free (t->values, TRUE); | |
121 g_free (t->children); | |
122 } | |
123 g_free (t); | |
124 } | |
125 } | |
126 | |
5967 | 127 static gboolean gtk_size_allocate_cb(GtkIMHtml *widget, GtkAllocation *alloc, gpointer user_data) |
128 { | |
129 GdkRectangle rect; | |
130 | |
131 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(widget), &rect); | |
132 if(widget->old_rect.width != rect.width || widget->old_rect.height != rect.height){ | |
133 GList *iter = GTK_IMHTML(widget)->scalables; | |
134 | |
135 while(iter){ | |
136 GtkIMHtmlScalable *scale = GTK_IMHTML_SCALABLE(iter->data); | |
137 scale->scale(scale, rect.width, rect.height); | |
138 | |
139 iter = iter->next; | |
140 } | |
141 } | |
142 | |
143 widget->old_rect = rect; | |
144 return FALSE; | |
145 } | |
146 | |
147 static gint | |
148 gtk_imhtml_tip_paint (GtkIMHtml *imhtml) | |
149 { | |
150 PangoLayout *layout; | |
151 | |
152 g_return_val_if_fail(GTK_IS_IMHTML(imhtml), FALSE); | |
153 | |
154 layout = gtk_widget_create_pango_layout(imhtml->tip_window, imhtml->tip); | |
155 | |
156 gtk_paint_flat_box (imhtml->tip_window->style, imhtml->tip_window->window, | |
157 GTK_STATE_NORMAL, GTK_SHADOW_OUT, NULL, imhtml->tip_window, | |
158 "tooltip", 0, 0, -1, -1); | |
159 | |
160 gtk_paint_layout (imhtml->tip_window->style, imhtml->tip_window->window, GTK_STATE_NORMAL, | |
161 FALSE, NULL, imhtml->tip_window, NULL, 4, 4, layout); | |
162 | |
163 g_object_unref(layout); | |
164 return FALSE; | |
165 } | |
166 | |
167 static gint | |
168 gtk_imhtml_tip (gpointer data) | |
169 { | |
170 GtkIMHtml *imhtml = data; | |
171 PangoFontMetrics *font; | |
172 PangoLayout *layout; | |
173 | |
174 gint gap, x, y, h, w, scr_w, baseline_skip; | |
175 | |
176 g_return_val_if_fail(GTK_IS_IMHTML(imhtml), FALSE); | |
177 | |
178 if (!imhtml->tip || !GTK_WIDGET_DRAWABLE (GTK_WIDGET(imhtml))) { | |
179 imhtml->tip_timer = 0; | |
180 return FALSE; | |
181 } | |
182 | |
183 if (imhtml->tip_window){ | |
184 gtk_widget_destroy (imhtml->tip_window); | |
185 imhtml->tip_window = NULL; | |
186 } | |
187 | |
188 imhtml->tip_timer = 0; | |
189 imhtml->tip_window = gtk_window_new (GTK_WINDOW_POPUP); | |
190 gtk_widget_set_app_paintable (imhtml->tip_window, TRUE); | |
191 gtk_window_set_resizable (GTK_WINDOW (imhtml->tip_window), FALSE); | |
192 gtk_widget_set_name (imhtml->tip_window, "gtk-tooltips"); | |
193 g_signal_connect_swapped (G_OBJECT (imhtml->tip_window), "expose_event", | |
194 G_CALLBACK (gtk_imhtml_tip_paint), imhtml); | |
195 | |
196 gtk_widget_ensure_style (imhtml->tip_window); | |
197 layout = gtk_widget_create_pango_layout(imhtml->tip_window, imhtml->tip); | |
198 font = pango_font_get_metrics(pango_context_load_font(pango_layout_get_context(layout), | |
199 imhtml->tip_window->style->font_desc), | |
200 NULL); | |
201 | |
202 | |
203 pango_layout_get_pixel_size(layout, &scr_w, NULL); | |
204 gap = PANGO_PIXELS((pango_font_metrics_get_ascent(font) + | |
205 pango_font_metrics_get_descent(font))/ 4); | |
206 | |
207 if (gap < 2) | |
208 gap = 2; | |
209 baseline_skip = PANGO_PIXELS(pango_font_metrics_get_ascent(font) + | |
210 pango_font_metrics_get_descent(font)); | |
211 w = 8 + scr_w; | |
212 h = 8 + baseline_skip; | |
213 | |
214 gdk_window_get_pointer (NULL, &x, &y, NULL); | |
215 if (GTK_WIDGET_NO_WINDOW (GTK_WIDGET(imhtml))) | |
216 y += GTK_WIDGET(imhtml)->allocation.y; | |
217 | |
218 scr_w = gdk_screen_width(); | |
219 | |
220 x -= ((w >> 1) + 4); | |
221 | |
222 if ((x + w) > scr_w) | |
223 x -= (x + w) - scr_w; | |
224 else if (x < 0) | |
225 x = 0; | |
226 | |
227 y = y + PANGO_PIXELS(pango_font_metrics_get_ascent(font) + | |
228 pango_font_metrics_get_descent(font)); | |
229 | |
230 gtk_widget_set_size_request (imhtml->tip_window, w, h); | |
231 gtk_widget_show (imhtml->tip_window); | |
232 gtk_window_move (GTK_WINDOW(imhtml->tip_window), x, y); | |
233 | |
234 pango_font_metrics_unref(font); | |
235 g_object_unref(layout); | |
236 | |
237 return FALSE; | |
238 } | |
239 | |
240 gboolean gtk_motion_event_notify(GtkWidget *imhtml, GdkEventMotion *event, gpointer data) | |
241 { | |
242 GtkTextIter iter; | |
243 GdkWindow *win = event->window; | |
244 int x, y; | |
245 char *tip = NULL; | |
246 GSList *tags = NULL, *templist = NULL; | |
247 gdk_window_get_pointer(GTK_WIDGET(imhtml)->window, NULL, NULL, NULL); | |
248 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(imhtml), GTK_TEXT_WINDOW_WIDGET, | |
249 event->x, event->y, &x, &y); | |
250 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(imhtml), &iter, x, y); | |
251 tags = gtk_text_iter_get_tags(&iter); | |
252 | |
253 templist = tags; | |
254 while (templist) { | |
255 GtkTextTag *tag = templist->data; | |
256 tip = g_object_get_data(G_OBJECT(tag), "link_url"); | |
257 if (tip) | |
258 break; | |
259 templist = templist->next; | |
260 } | |
261 | |
262 if (GTK_IMHTML(imhtml)->tip) { | |
263 if ((tip == GTK_IMHTML(imhtml)->tip)) { | |
264 return FALSE; | |
265 } | |
266 /* We've left the cell. Remove the timeout and create a new one below */ | |
267 if (GTK_IMHTML(imhtml)->tip_window) { | |
268 gtk_widget_destroy(GTK_IMHTML(imhtml)->tip_window); | |
269 GTK_IMHTML(imhtml)->tip_window = NULL; | |
270 } | |
271 gdk_window_set_cursor(win, GTK_IMHTML(imhtml)->arrow_cursor); | |
272 if (GTK_IMHTML(imhtml)->tip_timer) | |
273 g_source_remove(GTK_IMHTML(imhtml)->tip_timer); | |
274 GTK_IMHTML(imhtml)->tip_timer = 0; | |
275 } | |
276 | |
277 if(tip){ | |
278 gdk_window_set_cursor(win, GTK_IMHTML(imhtml)->hand_cursor); | |
279 GTK_IMHTML(imhtml)->tip_timer = g_timeout_add (TOOLTIP_TIMEOUT, | |
280 gtk_imhtml_tip, imhtml); | |
281 } | |
282 | |
283 GTK_IMHTML(imhtml)->tip = tip; | |
284 g_slist_free(tags); | |
285 return FALSE; | |
286 } | |
287 | |
288 gboolean gtk_leave_event_notify(GtkWidget *imhtml, GdkEventCrossing *event, gpointer data) | |
289 { | |
290 /* when leaving the widget, clear any current & pending tooltips and restore the cursor */ | |
291 if (GTK_IMHTML(imhtml)->tip_window) { | |
292 gtk_widget_destroy(GTK_IMHTML(imhtml)->tip_window); | |
293 GTK_IMHTML(imhtml)->tip_window = NULL; | |
294 } | |
295 if (GTK_IMHTML(imhtml)->tip_timer) { | |
296 g_source_remove(GTK_IMHTML(imhtml)->tip_timer); | |
297 GTK_IMHTML(imhtml)->tip_timer = 0; | |
298 } | |
299 gdk_window_set_cursor(event->window, GTK_IMHTML(imhtml)->arrow_cursor); | |
300 | |
301 /* propogate the event normally */ | |
302 return FALSE; | |
303 } | |
304 | |
6066 | 305 /* |
306 * XXX - This should be removed eventually. | |
307 * | |
308 * This function exists to work around a gross bug in GtkTextView. | |
309 * Basically, we short circuit ctrl+a and ctrl+end because they make | |
310 * el program go boom. | |
311 * | |
312 * It's supposed to be fixed in gtk2.2. You can view the bug report at | |
313 * http://bugzilla.gnome.org/show_bug.cgi?id=107939 | |
314 */ | |
315 gboolean gtk_key_pressed_cb(GtkWidget *imhtml, GdkEventKey *event, gpointer data) | |
316 { | |
317 if (event->state & GDK_CONTROL_MASK) | |
318 switch (event->keyval) { | |
319 case 'a': | |
320 return TRUE; | |
321 break; | |
322 | |
323 case GDK_Home: | |
324 return TRUE; | |
325 break; | |
326 | |
327 case GDK_End: | |
328 return TRUE; | |
329 break; | |
330 } | |
331 | |
332 return FALSE; | |
333 } | |
334 | |
7346 | 335 static GtkIMHtmlCopyable *gtk_imhtml_copyable_new(GtkIMHtml *imhtml, GtkTextMark *mark, const gchar *text) |
336 { | |
337 GtkIMHtmlCopyable *copy = g_malloc(sizeof(GtkIMHtmlCopyable)); | |
338 copy->mark = mark; | |
339 copy->text = g_strdup(text); | |
340 imhtml->copyables = g_slist_append(imhtml->copyables, copy); | |
341 return copy; | |
342 } | |
343 | |
344 static void copy_clipboard_cb(GtkIMHtml *imhtml, GtkClipboard *clipboard) | |
345 { | |
346 GtkTextMark *sel = gtk_text_buffer_get_selection_bound(imhtml->text_buffer); | |
347 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); | |
348 GtkTextIter start, end, smiley, last; | |
349 GString *str = g_string_new(NULL); | |
350 char *text; | |
351 | |
352 GSList *copyables; | |
353 | |
354 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &start, sel); | |
355 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &end, ins); | |
356 | |
357 if (gtk_text_iter_equal(&start, &end)) | |
358 return; | |
359 | |
360 gtk_text_iter_order(&start, &end); | |
361 last = start; | |
362 | |
363 for (copyables = imhtml->copyables; copyables != NULL; copyables = copyables->next) { | |
364 GtkIMHtmlCopyable *copy = GTK_IMHTML_COPYABLE(copyables->data); | |
365 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &smiley, copy->mark); | |
366 if (gtk_text_iter_compare(&end, &smiley) < 0) { | |
367 break; | |
368 } | |
369 if (gtk_text_iter_compare(&last, &smiley) <= 0) { | |
370 text = gtk_text_buffer_get_text(imhtml->text_buffer, &last, &smiley, FALSE); | |
371 str = g_string_append(str, text); | |
372 str = g_string_append(str, copy->text); | |
373 last = smiley; | |
374 g_free(text); | |
375 } | |
376 } | |
377 text = gtk_text_buffer_get_text(imhtml->text_buffer, &last, &end, FALSE); | |
378 str = g_string_append(str, text); | |
379 g_free(text); | |
7353 | 380 |
7354 | 381 if (!gtk_text_iter_equal(&start, &last)) |
382 gtk_clipboard_set_text(clipboard ? clipboard : | |
383 gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_CLIPBOARD), | |
384 str->str, str->len); | |
7346 | 385 g_string_free(str, TRUE); |
386 } | |
387 | |
388 static gboolean button_release_cb(GtkIMHtml *imhtml, GdkEventButton event, gpointer the_foibles_of_man) | |
389 { | |
390 copy_clipboard_cb(imhtml, gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_PRIMARY)); | |
391 return FALSE; | |
392 } | |
5967 | 393 |
4263 | 394 |
4032 | 395 static GtkTextViewClass *parent_class = NULL; |
396 | |
3922 | 397 /* GtkIMHtml has one signal--URL_CLICKED */ |
1428 | 398 enum { |
399 URL_CLICKED, | |
400 LAST_SIGNAL | |
401 }; | |
402 static guint signals [LAST_SIGNAL] = { 0 }; | |
403 | |
4032 | 404 static void |
405 gtk_imhtml_finalize (GObject *object) | |
406 { | |
407 GtkIMHtml *imhtml = GTK_IMHTML(object); | |
4895 | 408 GList *scalables; |
7346 | 409 GSList *copyables; |
410 | |
4138 | 411 g_hash_table_destroy(imhtml->smiley_data); |
4032 | 412 gtk_smiley_tree_destroy(imhtml->default_smilies); |
4138 | 413 gdk_cursor_unref(imhtml->hand_cursor); |
414 gdk_cursor_unref(imhtml->arrow_cursor); | |
4735 | 415 if(imhtml->tip_window){ |
416 gtk_widget_destroy(imhtml->tip_window); | |
417 } | |
418 if(imhtml->tip_timer) | |
419 gtk_timeout_remove(imhtml->tip_timer); | |
420 | |
4895 | 421 for(scalables = imhtml->scalables; scalables; scalables = scalables->next) { |
422 GtkIMHtmlScalable *scale = GTK_IMHTML_SCALABLE(scalables->data); | |
423 scale->free(scale); | |
424 } | |
7346 | 425 |
426 for (copyables = imhtml->copyables; copyables; copyables = copyables->next) { | |
427 GtkIMHtmlCopyable *copy = GTK_IMHTML_COPYABLE(copyables->data); | |
428 g_free(copy->text); | |
429 g_free(copy); | |
430 } | |
431 | |
4895 | 432 g_list_free(imhtml->scalables); |
4032 | 433 G_OBJECT_CLASS(parent_class)->finalize (object); |
434 } | |
1428 | 435 |
3922 | 436 /* Boring GTK stuff */ |
437 static void gtk_imhtml_class_init (GtkIMHtmlClass *class) | |
1428 | 438 { |
3922 | 439 GtkObjectClass *object_class; |
4032 | 440 GObjectClass *gobject_class; |
3922 | 441 object_class = (GtkObjectClass*) class; |
4032 | 442 gobject_class = (GObjectClass*) class; |
443 parent_class = gtk_type_class(GTK_TYPE_TEXT_VIEW); | |
4417 | 444 signals[URL_CLICKED] = g_signal_new("url_clicked", |
445 G_TYPE_FROM_CLASS(gobject_class), | |
446 G_SIGNAL_RUN_FIRST, | |
447 G_STRUCT_OFFSET(GtkIMHtmlClass, url_clicked), | |
448 NULL, | |
449 0, | |
450 g_cclosure_marshal_VOID__POINTER, | |
451 G_TYPE_NONE, 1, | |
452 G_TYPE_POINTER); | |
4032 | 453 gobject_class->finalize = gtk_imhtml_finalize; |
1428 | 454 } |
455 | |
3922 | 456 static void gtk_imhtml_init (GtkIMHtml *imhtml) |
1428 | 457 { |
3922 | 458 GtkTextIter iter; |
459 imhtml->text_buffer = gtk_text_buffer_new(NULL); | |
460 gtk_text_buffer_get_end_iter (imhtml->text_buffer, &iter); | |
461 imhtml->end = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, FALSE); | |
462 gtk_text_view_set_buffer(GTK_TEXT_VIEW(imhtml), imhtml->text_buffer); | |
5105 | 463 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(imhtml), GTK_WRAP_WORD_CHAR); |
3922 | 464 gtk_text_view_set_editable(GTK_TEXT_VIEW(imhtml), FALSE); |
465 gtk_text_view_set_pixels_below_lines(GTK_TEXT_VIEW(imhtml), 5); | |
466 gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(imhtml), FALSE); | |
467 /*gtk_text_view_set_justification(GTK_TEXT_VIEW(imhtml), GTK_JUSTIFY_FILL);*/ | |
3465 | 468 |
3922 | 469 /* These tags will be used often and can be reused--we create them on init and then apply them by name |
470 * other tags (color, size, face, etc.) will have to be created and applied dynamically */ | |
471 gtk_text_buffer_create_tag(imhtml->text_buffer, "BOLD", "weight", PANGO_WEIGHT_BOLD, NULL); | |
472 gtk_text_buffer_create_tag(imhtml->text_buffer, "ITALICS", "style", PANGO_STYLE_ITALIC, NULL); | |
473 gtk_text_buffer_create_tag(imhtml->text_buffer, "UNDERLINE", "underline", PANGO_UNDERLINE_SINGLE, NULL); | |
474 gtk_text_buffer_create_tag(imhtml->text_buffer, "STRIKE", "strikethrough", TRUE, NULL); | |
475 gtk_text_buffer_create_tag(imhtml->text_buffer, "SUB", "rise", -5000, NULL); | |
476 gtk_text_buffer_create_tag(imhtml->text_buffer, "SUP", "rise", 5000, NULL); | |
477 gtk_text_buffer_create_tag(imhtml->text_buffer, "PRE", "family", "Monospace", NULL); | |
7295 | 478 gtk_text_buffer_create_tag(imhtml->text_buffer, "search", "background", "#22ff00", "weight", "bold", NULL); |
479 | |
3922 | 480 /* When hovering over a link, we show the hand cursor--elsewhere we show the plain ol' pointer cursor */ |
481 imhtml->hand_cursor = gdk_cursor_new (GDK_HAND2); | |
482 imhtml->arrow_cursor = gdk_cursor_new (GDK_LEFT_PTR); | |
2993 | 483 |
4253 | 484 imhtml->show_smileys = TRUE; |
6124 | 485 imhtml->show_comments = TRUE; |
4253 | 486 |
4892 | 487 imhtml->smiley_data = g_hash_table_new_full(g_str_hash, g_str_equal, |
4902 | 488 g_free, (GDestroyNotify)gtk_smiley_tree_destroy); |
4032 | 489 imhtml->default_smilies = gtk_smiley_tree_new(); |
4735 | 490 |
4944 | 491 g_signal_connect(G_OBJECT(imhtml), "size-allocate", G_CALLBACK(gtk_size_allocate_cb), NULL); |
4735 | 492 g_signal_connect(G_OBJECT(imhtml), "motion-notify-event", G_CALLBACK(gtk_motion_event_notify), NULL); |
4944 | 493 g_signal_connect(G_OBJECT(imhtml), "leave-notify-event", G_CALLBACK(gtk_leave_event_notify), NULL); |
6066 | 494 g_signal_connect(G_OBJECT(imhtml), "key_press_event", G_CALLBACK(gtk_key_pressed_cb), NULL); |
7353 | 495 g_signal_connect(G_OBJECT(imhtml), "copy-clipboard", G_CALLBACK(copy_clipboard_cb), NULL); |
7346 | 496 g_signal_connect(G_OBJECT(imhtml), "button-release-event", G_CALLBACK(button_release_cb), imhtml); |
4944 | 497 gtk_widget_add_events(GTK_WIDGET(imhtml), GDK_LEAVE_NOTIFY_MASK); |
4735 | 498 |
499 imhtml->tip = NULL; | |
500 imhtml->tip_timer = 0; | |
501 imhtml->tip_window = NULL; | |
4895 | 502 |
503 imhtml->scalables = NULL; | |
7346 | 504 imhtml->copyables = NULL; |
2993 | 505 } |
506 | |
3922 | 507 GtkWidget *gtk_imhtml_new(void *a, void *b) |
1428 | 508 { |
4635 | 509 return GTK_WIDGET(g_object_new(gtk_imhtml_get_type(), NULL)); |
1428 | 510 } |
511 | |
4635 | 512 GType gtk_imhtml_get_type() |
1428 | 513 { |
4635 | 514 static GType imhtml_type = 0; |
1428 | 515 |
516 if (!imhtml_type) { | |
4635 | 517 static const GTypeInfo imhtml_info = { |
518 sizeof(GtkIMHtmlClass), | |
519 NULL, | |
520 NULL, | |
521 (GClassInitFunc) gtk_imhtml_class_init, | |
522 NULL, | |
523 NULL, | |
1428 | 524 sizeof (GtkIMHtml), |
4635 | 525 0, |
526 (GInstanceInitFunc) gtk_imhtml_init | |
1428 | 527 }; |
4635 | 528 |
529 imhtml_type = g_type_register_static(gtk_text_view_get_type(), | |
530 "GtkIMHtml", &imhtml_info, 0); | |
1428 | 531 } |
532 | |
533 return imhtml_type; | |
534 } | |
535 | |
4417 | 536 struct url_data { |
537 GObject *object; | |
538 gchar *url; | |
539 }; | |
540 | |
541 static void url_open(GtkWidget *w, struct url_data *data) { | |
542 if(!data) return; | |
543 | |
544 g_signal_emit(data->object, signals[URL_CLICKED], 0, data->url); | |
545 | |
546 g_object_unref(data->object); | |
547 g_free(data->url); | |
548 g_free(data); | |
549 } | |
5582 | 550 |
4417 | 551 static void url_copy(GtkWidget *w, gchar *url) { |
552 GtkClipboard *clipboard; | |
553 | |
5293
ead927e2543f
[gaim-migrate @ 5665]
Christian Hammond <chipx86@chipx86.com>
parents:
5282
diff
changeset
|
554 clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY); |
4417 | 555 gtk_clipboard_set_text(clipboard, url, -1); |
5582 | 556 |
557 clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); | |
558 gtk_clipboard_set_text(clipboard, url, -1); | |
4417 | 559 } |
560 | |
561 /* The callback for an event on a link tag. */ | |
5091 | 562 gboolean tag_event(GtkTextTag *tag, GObject *imhtml, GdkEvent *event, GtkTextIter *arg2, char *url) { |
4417 | 563 GdkEventButton *event_button = (GdkEventButton *) event; |
564 | |
3922 | 565 if (event->type == GDK_BUTTON_RELEASE) { |
4417 | 566 if (event_button->button == 1) { |
567 GtkTextIter start, end; | |
568 /* we shouldn't open a URL if the user has selected something: */ | |
569 gtk_text_buffer_get_selection_bounds( | |
570 gtk_text_iter_get_buffer(arg2), &start, &end); | |
571 if(gtk_text_iter_get_offset(&start) != | |
572 gtk_text_iter_get_offset(&end)) | |
573 return FALSE; | |
574 | |
575 /* A link was clicked--we emit the "url_clicked" signal | |
576 * with the URL as the argument */ | |
5091 | 577 g_signal_emit(imhtml, signals[URL_CLICKED], 0, url); |
4417 | 578 return FALSE; |
579 } else if(event_button->button == 3) { | |
4745 | 580 GtkWidget *img, *item, *menu; |
4417 | 581 struct url_data *tempdata = g_new(struct url_data, 1); |
5091 | 582 tempdata->object = g_object_ref(imhtml); |
4417 | 583 tempdata->url = g_strdup(url); |
4745 | 584 |
5091 | 585 /* Don't want the tooltip around if user right-clicked on link */ |
586 if (GTK_IMHTML(imhtml)->tip_window) { | |
587 gtk_widget_destroy(GTK_IMHTML(imhtml)->tip_window); | |
588 GTK_IMHTML(imhtml)->tip_window = NULL; | |
589 } | |
590 if (GTK_IMHTML(imhtml)->tip_timer) { | |
591 g_source_remove(GTK_IMHTML(imhtml)->tip_timer); | |
592 GTK_IMHTML(imhtml)->tip_timer = 0; | |
593 } | |
594 gdk_window_set_cursor(event_button->window, GTK_IMHTML(imhtml)->arrow_cursor); | |
4417 | 595 menu = gtk_menu_new(); |
4745 | 596 |
4417 | 597 /* buttons and such */ |
598 | |
7140
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
599 if (!strncmp(url, "mailto:", 7)) |
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
600 { |
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
601 /* Copy E-Mail Address */ |
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
602 img = gtk_image_new_from_stock(GTK_STOCK_COPY, |
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
603 GTK_ICON_SIZE_MENU); |
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
604 item = gtk_image_menu_item_new_with_mnemonic( |
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
605 _("_Copy E-Mail Address")); |
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
606 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
|
607 g_signal_connect(G_OBJECT(item), "activate", |
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
608 G_CALLBACK(url_copy), url + 7); |
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
609 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); |
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
610 } |
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
611 else |
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
612 { |
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
613 /* Copy Link Location */ |
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
614 img = gtk_image_new_from_stock(GTK_STOCK_COPY, |
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
615 GTK_ICON_SIZE_MENU); |
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
616 item = gtk_image_menu_item_new_with_mnemonic( |
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
617 _("_Copy Link Location")); |
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
618 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
|
619 g_signal_connect(G_OBJECT(item), "activate", |
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
620 G_CALLBACK(url_copy), url); |
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
621 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); |
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
622 |
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
623 /* Open Link in Browser */ |
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
624 img = gtk_image_new_from_stock(GTK_STOCK_JUMP_TO, |
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
625 GTK_ICON_SIZE_MENU); |
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
626 item = gtk_image_menu_item_new_with_mnemonic( |
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
627 _("_Open Link in Browser")); |
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
628 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
|
629 g_signal_connect(G_OBJECT(item), "activate", |
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
630 G_CALLBACK(url_open), tempdata); |
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
631 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); |
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
632 } |
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
633 |
4756 | 634 |
4417 | 635 gtk_widget_show_all(menu); |
4756 | 636 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, |
637 event_button->button, event_button->time); | |
4745 | 638 |
4417 | 639 return TRUE; |
640 } | |
1428 | 641 } |
4417 | 642 if(event->type == GDK_BUTTON_PRESS && event_button->button == 3) |
643 return TRUE; /* Clicking the right mouse button on a link shouldn't | |
644 be caught by the regular GtkTextView menu */ | |
645 else | |
646 return FALSE; /* Let clicks go through if we didn't catch anything */ | |
1428 | 647 } |
648 | |
4298 | 649 /* this isn't used yet |
4032 | 650 static void |
4263 | 651 gtk_smiley_tree_remove (GtkSmileyTree *tree, |
652 GtkIMHtmlSmiley *smiley) | |
4032 | 653 { |
654 GtkSmileyTree *t = tree; | |
4263 | 655 const gchar *x = smiley->smile; |
4032 | 656 gint len = 0; |
657 | |
658 while (*x) { | |
659 gchar *pos; | |
660 | |
661 if (!t->values) | |
662 return; | |
663 | |
664 pos = strchr (t->values->str, *x); | |
665 if (pos) | |
666 t = t->children [(int) pos - (int) t->values->str]; | |
667 else | |
668 return; | |
669 | |
670 x++; len++; | |
671 } | |
672 | |
4141
ccec4fde84f4
[gaim-migrate @ 4359]
Christian Hammond <chipx86@chipx86.com>
parents:
4140
diff
changeset
|
673 if (t->image) { |
4032 | 674 t->image = NULL; |
4141
ccec4fde84f4
[gaim-migrate @ 4359]
Christian Hammond <chipx86@chipx86.com>
parents:
4140
diff
changeset
|
675 } |
4032 | 676 } |
4298 | 677 */ |
678 | |
4032 | 679 |
680 static gint | |
681 gtk_smiley_tree_lookup (GtkSmileyTree *tree, | |
682 const gchar *text) | |
683 { | |
684 GtkSmileyTree *t = tree; | |
685 const gchar *x = text; | |
686 gint len = 0; | |
687 | |
688 while (*x) { | |
689 gchar *pos; | |
690 | |
691 if (!t->values) | |
692 break; | |
693 | |
694 pos = strchr (t->values->str, *x); | |
695 if (pos) | |
7371 | 696 t = t->children [GPOINTER_TO_INT(pos) - GPOINTER_TO_INT(t->values->str)]; |
4032 | 697 else |
698 break; | |
699 | |
700 x++; len++; | |
701 } | |
702 | |
703 if (t->image) | |
704 return len; | |
705 | |
706 return 0; | |
707 } | |
708 | |
709 void | |
4263 | 710 gtk_imhtml_associate_smiley (GtkIMHtml *imhtml, |
711 gchar *sml, | |
712 GtkIMHtmlSmiley *smiley) | |
4032 | 713 { |
714 GtkSmileyTree *tree; | |
715 g_return_if_fail (imhtml != NULL); | |
716 g_return_if_fail (GTK_IS_IMHTML (imhtml)); | |
7371 | 717 |
4032 | 718 if (sml == NULL) |
719 tree = imhtml->default_smilies; | |
720 else if ((tree = g_hash_table_lookup(imhtml->smiley_data, sml))) { | |
721 } else { | |
722 tree = gtk_smiley_tree_new(); | |
4892 | 723 g_hash_table_insert(imhtml->smiley_data, g_strdup(sml), tree); |
4032 | 724 } |
725 | |
4263 | 726 gtk_smiley_tree_insert (tree, smiley); |
4032 | 727 } |
728 | |
729 static gboolean | |
730 gtk_imhtml_is_smiley (GtkIMHtml *imhtml, | |
731 GSList *fonts, | |
732 const gchar *text, | |
733 gint *len) | |
734 { | |
735 GtkSmileyTree *tree; | |
5967 | 736 GtkIMHtmlFontDetail *font; |
4032 | 737 char *sml = NULL; |
738 | |
739 if (fonts) { | |
740 font = fonts->data; | |
741 sml = font->sml; | |
742 } | |
743 | |
744 if (sml == NULL) | |
745 tree = imhtml->default_smilies; | |
746 else { | |
747 tree = g_hash_table_lookup(imhtml->smiley_data, sml); | |
748 } | |
749 if (tree == NULL) | |
750 return FALSE; | |
7371 | 751 |
4032 | 752 *len = gtk_smiley_tree_lookup (tree, text); |
753 return (*len > 0); | |
754 } | |
755 | |
6814
782907a6ae65
[gaim-migrate @ 7354]
Christian Hammond <chipx86@chipx86.com>
parents:
6648
diff
changeset
|
756 GdkPixbufAnimation * |
4032 | 757 gtk_smiley_tree_image (GtkIMHtml *imhtml, |
758 const gchar *sml, | |
759 const gchar *text) | |
760 { | |
761 GtkSmileyTree *t; | |
762 const gchar *x = text; | |
763 if (sml == NULL) | |
764 t = imhtml->default_smilies; | |
7371 | 765 else |
4032 | 766 t = g_hash_table_lookup(imhtml->smiley_data, sml); |
7371 | 767 |
4032 | 768 |
769 if (t == NULL) | |
770 return sml ? gtk_smiley_tree_image(imhtml, NULL, text) : NULL; | |
771 | |
772 while (*x) { | |
773 gchar *pos; | |
774 | |
775 if (!t->values) { | |
776 return sml ? gtk_smiley_tree_image(imhtml, NULL, text) : NULL; | |
777 } | |
7371 | 778 |
4032 | 779 pos = strchr (t->values->str, *x); |
780 if (pos) { | |
7371 | 781 t = t->children [GPOINTER_TO_INT(pos) - GPOINTER_TO_INT(t->values->str)]; |
4032 | 782 } else { |
783 return sml ? gtk_smiley_tree_image(imhtml, NULL, text) : NULL; | |
784 } | |
785 x++; | |
786 } | |
787 | |
4263 | 788 if (!t->image->icon) |
6814
782907a6ae65
[gaim-migrate @ 7354]
Christian Hammond <chipx86@chipx86.com>
parents:
6648
diff
changeset
|
789 t->image->icon = gdk_pixbuf_animation_new_from_file(t->image->file, NULL); |
4263 | 790 |
791 return t->image->icon; | |
4032 | 792 } |
4793 | 793 #define VALID_TAG(x) if (!g_ascii_strncasecmp (string, x ">", strlen (x ">"))) { \ |
3922 | 794 *tag = g_strndup (string, strlen (x)); \ |
795 *len = strlen (x) + 1; \ | |
796 return TRUE; \ | |
797 } \ | |
798 (*type)++ | |
1428 | 799 |
4793 | 800 #define VALID_OPT_TAG(x) if (!g_ascii_strncasecmp (string, x " ", strlen (x " "))) { \ |
3922 | 801 const gchar *c = string + strlen (x " "); \ |
802 gchar e = '"'; \ | |
803 gboolean quote = FALSE; \ | |
804 while (*c) { \ | |
805 if (*c == '"' || *c == '\'') { \ | |
806 if (quote && (*c == e)) \ | |
807 quote = !quote; \ | |
808 else if (!quote) { \ | |
809 quote = !quote; \ | |
810 e = *c; \ | |
811 } \ | |
812 } else if (!quote && (*c == '>')) \ | |
813 break; \ | |
814 c++; \ | |
815 } \ | |
816 if (*c) { \ | |
817 *tag = g_strndup (string, c - string); \ | |
818 *len = c - string + 1; \ | |
819 return TRUE; \ | |
820 } \ | |
821 } \ | |
822 (*type)++ | |
1428 | 823 |
824 | |
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
825 static gboolean |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
826 gtk_imhtml_is_amp_escape (const gchar *string, |
7280 | 827 gchar **replace, |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
828 gint *length) |
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
829 { |
7287 | 830 static char buf[7]; |
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
831 g_return_val_if_fail (string != NULL, FALSE); |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
832 g_return_val_if_fail (replace != NULL, FALSE); |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
833 g_return_val_if_fail (length != NULL, FALSE); |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
834 |
4793 | 835 if (!g_ascii_strncasecmp (string, "&", 5)) { |
7280 | 836 *replace = "&"; |
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
837 *length = 5; |
4793 | 838 } else if (!g_ascii_strncasecmp (string, "<", 4)) { |
7280 | 839 *replace = "<"; |
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
840 *length = 4; |
4793 | 841 } else if (!g_ascii_strncasecmp (string, ">", 4)) { |
7280 | 842 *replace = ">"; |
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
843 *length = 4; |
4793 | 844 } else if (!g_ascii_strncasecmp (string, " ", 6)) { |
7280 | 845 *replace = " "; |
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
846 *length = 6; |
4793 | 847 } else if (!g_ascii_strncasecmp (string, "©", 6)) { |
7280 | 848 *replace = "©"; |
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
849 *length = 6; |
4793 | 850 } else if (!g_ascii_strncasecmp (string, """, 6)) { |
7280 | 851 *replace = "\""; |
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
852 *length = 6; |
4793 | 853 } else if (!g_ascii_strncasecmp (string, "®", 5)) { |
7280 | 854 *replace = "®"; |
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
855 *length = 5; |
5093 | 856 } else if (!g_ascii_strncasecmp (string, "'", 6)) { |
7280 | 857 *replace = "\'"; |
5093 | 858 *length = 6; |
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
859 } else if (*(string + 1) == '#') { |
2022
199ba82faacb
[gaim-migrate @ 2032]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2002
diff
changeset
|
860 guint pound = 0; |
3004 | 861 if ((sscanf (string, "&#%u;", £) == 1) && pound != 0) { |
7287 | 862 int buflen; |
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
863 if (*(string + 3 + (gint)log10 (pound)) != ';') |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
864 return FALSE; |
7287 | 865 buflen = g_unichar_to_utf8((gunichar)pound, buf); |
866 buf[buflen] = '\0'; | |
7280 | 867 *replace = buf; |
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
868 *length = 2; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
869 while (isdigit ((gint) string [*length])) (*length)++; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
870 if (string [*length] == ';') (*length)++; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
871 } else { |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
872 return FALSE; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
873 } |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
874 } else { |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
875 return FALSE; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
876 } |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
877 |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
878 return TRUE; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
879 } |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
880 |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
881 static gboolean |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
882 gtk_imhtml_is_tag (const gchar *string, |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
883 gchar **tag, |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
884 gint *len, |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
885 gint *type) |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
886 { |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
887 *type = 1; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
888 |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
889 if (!strchr (string, '>')) |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
890 return FALSE; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
891 |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
892 VALID_TAG ("B"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
893 VALID_TAG ("BOLD"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
894 VALID_TAG ("/B"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
895 VALID_TAG ("/BOLD"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
896 VALID_TAG ("I"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
897 VALID_TAG ("ITALIC"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
898 VALID_TAG ("/I"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
899 VALID_TAG ("/ITALIC"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
900 VALID_TAG ("U"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
901 VALID_TAG ("UNDERLINE"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
902 VALID_TAG ("/U"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
903 VALID_TAG ("/UNDERLINE"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
904 VALID_TAG ("S"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
905 VALID_TAG ("STRIKE"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
906 VALID_TAG ("/S"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
907 VALID_TAG ("/STRIKE"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
908 VALID_TAG ("SUB"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
909 VALID_TAG ("/SUB"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
910 VALID_TAG ("SUP"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
911 VALID_TAG ("/SUP"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
912 VALID_TAG ("PRE"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
913 VALID_TAG ("/PRE"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
914 VALID_TAG ("TITLE"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
915 VALID_TAG ("/TITLE"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
916 VALID_TAG ("BR"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
917 VALID_TAG ("HR"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
918 VALID_TAG ("/FONT"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
919 VALID_TAG ("/A"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
920 VALID_TAG ("P"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
921 VALID_TAG ("/P"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
922 VALID_TAG ("H3"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
923 VALID_TAG ("/H3"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
924 VALID_TAG ("HTML"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
925 VALID_TAG ("/HTML"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
926 VALID_TAG ("BODY"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
927 VALID_TAG ("/BODY"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
928 VALID_TAG ("FONT"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
929 VALID_TAG ("HEAD"); |
2993 | 930 VALID_TAG ("/HEAD"); |
931 VALID_TAG ("BINARY"); | |
932 VALID_TAG ("/BINARY"); | |
5093 | 933 |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
934 VALID_OPT_TAG ("HR"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
935 VALID_OPT_TAG ("FONT"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
936 VALID_OPT_TAG ("BODY"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
937 VALID_OPT_TAG ("A"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
938 VALID_OPT_TAG ("IMG"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
939 VALID_OPT_TAG ("P"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
940 VALID_OPT_TAG ("H3"); |
5093 | 941 VALID_OPT_TAG ("HTML"); |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
942 |
5101 | 943 VALID_TAG ("CITE"); |
944 VALID_TAG ("/CITE"); | |
945 VALID_TAG ("EM"); | |
946 VALID_TAG ("/EM"); | |
947 VALID_TAG ("STRONG"); | |
948 VALID_TAG ("/STRONG"); | |
949 | |
5104 | 950 VALID_OPT_TAG ("SPAN"); |
951 VALID_TAG ("/SPAN"); | |
5174 | 952 VALID_TAG ("BR/"); /* hack until gtkimhtml handles things better */ |
6982 | 953 VALID_TAG ("IMG"); |
5104 | 954 |
4793 | 955 if (!g_ascii_strncasecmp(string, "!--", strlen ("!--"))) { |
2954
f6c4f2187c08
[gaim-migrate @ 2967]
Christian Hammond <chipx86@chipx86.com>
parents:
2898
diff
changeset
|
956 gchar *e = strstr (string + strlen("!--"), "-->"); |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
957 if (e) { |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
958 *len = e - string + strlen ("-->"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
959 *tag = g_strndup (string + strlen ("!--"), *len - strlen ("!---->")); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
960 return TRUE; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
961 } |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
962 } |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
963 |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
964 return FALSE; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
965 } |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
966 |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
967 static gchar* |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
968 gtk_imhtml_get_html_opt (gchar *tag, |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
969 const gchar *opt) |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
970 { |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
971 gchar *t = tag; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
972 gchar *e, *a; |
5177 | 973 gchar *val; |
974 gint len; | |
7280 | 975 gchar *c; |
5177 | 976 GString *ret; |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
977 |
4793 | 978 while (g_ascii_strncasecmp (t, opt, strlen (opt))) { |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
979 gboolean quote = FALSE; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
980 if (*t == '\0') break; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
981 while (*t && !((*t == ' ') && !quote)) { |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
982 if (*t == '\"') |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
983 quote = ! quote; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
984 t++; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
985 } |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
986 while (*t && (*t == ' ')) t++; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
987 } |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
988 |
4793 | 989 if (!g_ascii_strncasecmp (t, opt, strlen (opt))) { |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
990 t += strlen (opt); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
991 } else { |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
992 return NULL; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
993 } |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
994 |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
995 if ((*t == '\"') || (*t == '\'')) { |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
996 e = a = ++t; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
997 while (*e && (*e != *(t - 1))) e++; |
2993 | 998 if (*e == '\0') { |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
999 return NULL; |
5177 | 1000 } else |
1001 val = g_strndup(a, e - a); | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1002 } else { |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1003 e = a = t; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1004 while (*e && !isspace ((gint) *e)) e++; |
5177 | 1005 val = g_strndup(a, e - a); |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1006 } |
5177 | 1007 |
1008 ret = g_string_new(""); | |
1009 e = val; | |
1010 while(*e) { | |
1011 if(gtk_imhtml_is_amp_escape(e, &c, &len)) { | |
7280 | 1012 ret = g_string_append(ret, c); |
5177 | 1013 e += len; |
1014 } else { | |
1015 ret = g_string_append_c(ret, *e); | |
1016 e++; | |
1017 } | |
1018 } | |
1019 | |
1020 g_free(val); | |
1021 val = ret->str; | |
1022 g_string_free(ret, FALSE); | |
1023 return val; | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1024 } |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1025 |
3922 | 1026 |
1027 | |
1028 #define NEW_TEXT_BIT 0 | |
4343 | 1029 #define NEW_COMMENT_BIT 2 |
4895 | 1030 #define NEW_SCALABLE_BIT 1 |
3922 | 1031 #define NEW_BIT(x) ws [wpos] = '\0'; \ |
1032 mark2 = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); \ | |
1033 gtk_text_buffer_insert(imhtml->text_buffer, &iter, ws, -1); \ | |
4895 | 1034 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &iter); \ |
3922 | 1035 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &siter, mark2); \ |
1036 gtk_text_buffer_delete_mark(imhtml->text_buffer, mark2); \ | |
1037 if (bold) \ | |
1038 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "BOLD", &siter, &iter); \ | |
4895 | 1039 if (italics) \ |
3922 | 1040 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "ITALICS", &siter, &iter); \ |
1041 if (underline) \ | |
1042 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "UNDERLINE", &siter, &iter); \ | |
1043 if (strike) \ | |
1044 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "STRIKE", &siter, &iter); \ | |
1045 if (sub) \ | |
1046 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "SUB", &siter, &iter); \ | |
1047 if (sup) \ | |
1048 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "SUP", &siter, &iter); \ | |
1049 if (pre) \ | |
1050 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "PRE", &siter, &iter); \ | |
1051 if (bg) { \ | |
1052 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "background", bg, NULL); \ | |
1053 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &siter, &iter); \ | |
1054 } \ | |
1055 if (fonts) { \ | |
5967 | 1056 GtkIMHtmlFontDetail *fd = fonts->data; \ |
3922 | 1057 if (fd->fore) { \ |
1058 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "foreground", fd->fore, NULL); \ | |
1059 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &siter, &iter); \ | |
1060 } \ | |
1061 if (fd->back) { \ | |
1062 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "background", fd->back, NULL); \ | |
1063 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &siter, &iter); \ | |
1064 } \ | |
1065 if (fd->face) { \ | |
6648 | 1066 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "family", fd->face, NULL); \ |
3922 | 1067 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &siter, &iter); \ |
1068 } \ | |
1069 if (fd->size) { \ | |
5118 | 1070 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "size-points", (double)POINT_SIZE(fd->size), NULL); \ |
3922 | 1071 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &siter, &iter); \ |
1072 } \ | |
1073 } \ | |
1074 if (url) { \ | |
1075 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "foreground", "blue", "underline", PANGO_UNDERLINE_SINGLE, NULL); \ | |
5012 | 1076 g_signal_connect(G_OBJECT(texttag), "event", G_CALLBACK(tag_event), g_strdup(url)); \ |
3922 | 1077 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &siter, &iter); \ |
4735 | 1078 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, NULL); \ |
1079 g_object_set_data(G_OBJECT(texttag), "link_url", g_strdup(url)); \ | |
1080 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &siter, &iter); \ | |
3922 | 1081 } \ |
1082 wpos = 0; \ | |
1083 ws[0] = 0; \ | |
1084 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &iter); \ | |
4895 | 1085 if (x == NEW_SCALABLE_BIT) { \ |
1086 GdkRectangle rect; \ | |
1087 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); \ | |
1088 scalable->add_to(scalable, imhtml, &iter); \ | |
1089 scalable->scale(scalable, rect.width, rect.height); \ | |
1090 imhtml->scalables = g_list_append(imhtml->scalables, scalable); \ | |
1091 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &iter); \ | |
4343 | 1092 } \ |
3922 | 1093 |
4895 | 1094 |
1095 | |
6982 | 1096 GString* gtk_imhtml_append_text_with_images (GtkIMHtml *imhtml, |
1097 const gchar *text, | |
1098 GtkIMHtmlOptions options, | |
1099 GSList *images) | |
1428 | 1100 { |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1101 gint pos = 0; |
3922 | 1102 GString *str = NULL; |
1103 GtkTextIter iter, siter; | |
1104 GtkTextMark *mark, *mark2; | |
1105 GtkTextTag *texttag; | |
1106 gchar *ws; | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1107 gchar *tag; |
3922 | 1108 gchar *url = NULL; |
1109 gchar *bg = NULL; | |
6982 | 1110 gint len; |
4032 | 1111 gint tlen, smilelen, wpos=0; |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1112 gint type; |
3922 | 1113 const gchar *c; |
7280 | 1114 gchar *amp; |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1115 |
1428 | 1116 guint bold = 0, |
1117 italics = 0, | |
1118 underline = 0, | |
1119 strike = 0, | |
1120 sub = 0, | |
1121 sup = 0, | |
1691
d802b115800f
[gaim-migrate @ 1701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1647
diff
changeset
|
1122 title = 0, |
3922 | 1123 pre = 0; |
1428 | 1124 |
3922 | 1125 GSList *fonts = NULL; |
1428 | 1126 |
4612 | 1127 GdkRectangle rect; |
1128 int y, height; | |
1129 | |
4895 | 1130 GtkIMHtmlScalable *scalable = NULL; |
1131 | |
1428 | 1132 g_return_val_if_fail (imhtml != NULL, NULL); |
1133 g_return_val_if_fail (GTK_IS_IMHTML (imhtml), NULL); | |
1134 g_return_val_if_fail (text != NULL, NULL); | |
6982 | 1135 |
3922 | 1136 c = text; |
6982 | 1137 len = strlen(text); |
3922 | 1138 ws = g_malloc(len + 1); |
1139 ws[0] = 0; | |
1428 | 1140 |
1141 if (options & GTK_IMHTML_RETURN_LOG) | |
3922 | 1142 str = g_string_new(""); |
1428 | 1143 |
3922 | 1144 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &iter); |
1145 mark = gtk_text_buffer_create_mark (imhtml->text_buffer, NULL, &iter, /* right grav */ FALSE); | |
4612 | 1146 |
1147 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); | |
1148 gtk_text_view_get_line_yrange(GTK_TEXT_VIEW(imhtml), &iter, &y, &height); | |
1149 | |
1150 if(((y + height) - (rect.y + rect.height)) > height | |
1151 && gtk_text_buffer_get_char_count(imhtml->text_buffer)){ | |
1152 options |= GTK_IMHTML_NO_SCROLL; | |
1153 } | |
1154 | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1155 while (pos < len) { |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1156 if (*c == '<' && gtk_imhtml_is_tag (c + 1, &tag, &tlen, &type)) { |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1157 c++; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1158 pos++; |
3922 | 1159 switch (type) |
1160 { | |
1161 case 1: /* B */ | |
1162 case 2: /* BOLD */ | |
5101 | 1163 case 54: /* STRONG */ |
3922 | 1164 NEW_BIT (NEW_TEXT_BIT); |
1165 bold++; | |
1166 break; | |
1167 case 3: /* /B */ | |
1168 case 4: /* /BOLD */ | |
5101 | 1169 case 55: /* /STRONG */ |
3922 | 1170 NEW_BIT (NEW_TEXT_BIT); |
1171 if (bold) | |
1172 bold--; | |
1173 break; | |
1174 case 5: /* I */ | |
1175 case 6: /* ITALIC */ | |
5101 | 1176 case 52: /* EM */ |
3922 | 1177 NEW_BIT (NEW_TEXT_BIT); |
1178 italics++; | |
1179 break; | |
1180 case 7: /* /I */ | |
1181 case 8: /* /ITALIC */ | |
5101 | 1182 case 53: /* /EM */ |
3922 | 1183 NEW_BIT (NEW_TEXT_BIT); |
1184 if (italics) | |
1185 italics--; | |
1186 break; | |
1187 case 9: /* U */ | |
1188 case 10: /* UNDERLINE */ | |
1189 NEW_BIT (NEW_TEXT_BIT); | |
1190 underline++; | |
1191 break; | |
1192 case 11: /* /U */ | |
1193 case 12: /* /UNDERLINE */ | |
1194 NEW_BIT (NEW_TEXT_BIT); | |
1195 if (underline) | |
1196 underline--; | |
1197 break; | |
1198 case 13: /* S */ | |
1199 case 14: /* STRIKE */ | |
1200 NEW_BIT (NEW_TEXT_BIT); | |
1201 strike++; | |
1202 break; | |
1203 case 15: /* /S */ | |
1204 case 16: /* /STRIKE */ | |
1205 NEW_BIT (NEW_TEXT_BIT); | |
1206 if (strike) | |
1207 strike--; | |
1208 break; | |
1209 case 17: /* SUB */ | |
1210 NEW_BIT (NEW_TEXT_BIT); | |
1211 sub++; | |
1212 break; | |
1213 case 18: /* /SUB */ | |
1214 NEW_BIT (NEW_TEXT_BIT); | |
1215 if (sub) | |
1216 sub--; | |
1217 break; | |
1218 case 19: /* SUP */ | |
1219 NEW_BIT (NEW_TEXT_BIT); | |
1220 sup++; | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1221 break; |
3922 | 1222 case 20: /* /SUP */ |
1223 NEW_BIT (NEW_TEXT_BIT); | |
1224 if (sup) | |
1225 sup--; | |
1226 break; | |
1227 case 21: /* PRE */ | |
1228 NEW_BIT (NEW_TEXT_BIT); | |
1229 pre++; | |
1230 break; | |
1231 case 22: /* /PRE */ | |
1232 NEW_BIT (NEW_TEXT_BIT); | |
1233 if (pre) | |
1234 pre--; | |
1235 break; | |
1236 case 23: /* TITLE */ | |
1237 NEW_BIT (NEW_TEXT_BIT); | |
1238 title++; | |
1239 break; | |
1240 case 24: /* /TITLE */ | |
1241 if (title) { | |
1242 if (options & GTK_IMHTML_NO_TITLE) { | |
1243 wpos = 0; | |
1244 ws [wpos] = '\0'; | |
1245 } | |
1246 title--; | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1247 } |
3922 | 1248 break; |
1249 case 25: /* BR */ | |
5174 | 1250 case 58: /* BR/ */ |
3922 | 1251 ws[wpos] = '\n'; |
1252 wpos++; | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1253 NEW_BIT (NEW_TEXT_BIT); |
6982 | 1254 break; |
3922 | 1255 case 26: /* HR */ |
1256 case 42: /* HR (opt) */ | |
1257 ws[wpos++] = '\n'; | |
5967 | 1258 scalable = gtk_imhtml_hr_new(); |
4895 | 1259 NEW_BIT(NEW_SCALABLE_BIT); |
4343 | 1260 ws[wpos++] = '\n'; |
3922 | 1261 break; |
1262 case 27: /* /FONT */ | |
1263 if (fonts) { | |
5967 | 1264 GtkIMHtmlFontDetail *font = fonts->data; |
3922 | 1265 NEW_BIT (NEW_TEXT_BIT); |
1266 fonts = g_slist_remove (fonts, font); | |
1267 if (font->face) | |
1268 g_free (font->face); | |
1269 if (font->fore) | |
1270 g_free (font->fore); | |
1271 if (font->back) | |
1272 g_free (font->back); | |
4032 | 1273 if (font->sml) |
1274 g_free (font->sml); | |
3922 | 1275 g_free (font); |
1276 } | |
1277 break; | |
1278 case 28: /* /A */ | |
1279 if (url) { | |
1280 NEW_BIT(NEW_TEXT_BIT); | |
1281 g_free(url); | |
1282 url = NULL; | |
2993 | 1283 break; |
1284 } | |
3922 | 1285 case 29: /* P */ |
1286 case 30: /* /P */ | |
1287 case 31: /* H3 */ | |
1288 case 32: /* /H3 */ | |
1289 case 33: /* HTML */ | |
1290 case 34: /* /HTML */ | |
1291 case 35: /* BODY */ | |
1292 case 36: /* /BODY */ | |
1293 case 37: /* FONT */ | |
1294 case 38: /* HEAD */ | |
1295 case 39: /* /HEAD */ | |
6982 | 1296 case 40: /* BINARY */ |
1297 case 41: /* /BINARY */ | |
3922 | 1298 break; |
1299 case 43: /* FONT (opt) */ | |
1300 { | |
4032 | 1301 gchar *color, *back, *face, *size, *sml; |
5967 | 1302 GtkIMHtmlFontDetail *font, *oldfont = NULL; |
3922 | 1303 color = gtk_imhtml_get_html_opt (tag, "COLOR="); |
1304 back = gtk_imhtml_get_html_opt (tag, "BACK="); | |
1305 face = gtk_imhtml_get_html_opt (tag, "FACE="); | |
1306 size = gtk_imhtml_get_html_opt (tag, "SIZE="); | |
4032 | 1307 sml = gtk_imhtml_get_html_opt (tag, "SML="); |
1308 if (!(color || back || face || size || sml)) | |
3922 | 1309 break; |
1310 | |
1311 NEW_BIT (NEW_TEXT_BIT); | |
1312 | |
5967 | 1313 font = g_new0 (GtkIMHtmlFontDetail, 1); |
3922 | 1314 if (fonts) |
1315 oldfont = fonts->data; | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1316 |
3922 | 1317 if (color && !(options & GTK_IMHTML_NO_COLOURS)) |
1318 font->fore = color; | |
1319 else if (oldfont && oldfont->fore) | |
1320 font->fore = g_strdup(oldfont->fore); | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1321 |
3922 | 1322 if (back && !(options & GTK_IMHTML_NO_COLOURS)) |
1323 font->back = back; | |
1324 else if (oldfont && oldfont->back) | |
1325 font->back = g_strdup(oldfont->back); | |
1326 | |
1327 if (face && !(options & GTK_IMHTML_NO_FONTS)) | |
1328 font->face = face; | |
1329 else if (oldfont && oldfont->face) | |
1330 font->face = g_strdup(oldfont->face); | |
4629 | 1331 if (font->face && (atoi(font->face) > 100)) { |
1332 g_free(font->face); | |
1333 font->face = g_strdup("100"); | |
1334 } | |
4032 | 1335 |
1336 if (sml) | |
1337 font->sml = sml; | |
1338 else if (oldfont && oldfont->sml) | |
1339 font->sml = g_strdup(oldfont->sml); | |
1340 | |
3922 | 1341 if (size && !(options & GTK_IMHTML_NO_SIZES)) { |
1342 if (*size == '+') { | |
1343 sscanf (size + 1, "%hd", &font->size); | |
1344 font->size += 3; | |
1345 } else if (*size == '-') { | |
1346 sscanf (size + 1, "%hd", &font->size); | |
1347 font->size = MAX (0, 3 - font->size); | |
1348 } else if (isdigit (*size)) { | |
1349 sscanf (size, "%hd", &font->size); | |
1350 } | |
6042 | 1351 if (font->size > 100) |
1352 font->size = 100; | |
3922 | 1353 } else if (oldfont) |
1354 font->size = oldfont->size; | |
1355 g_free(size); | |
1356 fonts = g_slist_prepend (fonts, font); | |
1357 } | |
1358 break; | |
1359 case 44: /* BODY (opt) */ | |
1360 if (!(options & GTK_IMHTML_NO_COLOURS)) { | |
1361 char *bgcolor = gtk_imhtml_get_html_opt (tag, "BGCOLOR="); | |
1362 if (bgcolor) { | |
1363 NEW_BIT(NEW_TEXT_BIT); | |
1364 if (bg) | |
1365 g_free(bg); | |
1366 bg = bgcolor; | |
2885
f72efa29c109
[gaim-migrate @ 2898]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2871
diff
changeset
|
1367 } |
1428 | 1368 } |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1369 break; |
3922 | 1370 case 45: /* A (opt) */ |
1371 { | |
1372 gchar *href = gtk_imhtml_get_html_opt (tag, "HREF="); | |
1373 if (href) { | |
1374 NEW_BIT (NEW_TEXT_BIT); | |
1375 if (url) | |
1376 g_free (url); | |
1377 url = href; | |
1378 } | |
2993 | 1379 } |
3922 | 1380 break; |
4895 | 1381 case 46: /* IMG (opt) */ |
6982 | 1382 case 59: /* IMG */ |
4895 | 1383 { |
6982 | 1384 GdkPixbuf *img = NULL; |
1385 const gchar *filename = NULL; | |
4895 | 1386 |
6982 | 1387 if (images && images->data) { |
1388 img = images->data; | |
1389 images = images->next; | |
1390 filename = g_object_get_data(G_OBJECT(img), "filename"); | |
1391 g_object_ref(G_OBJECT(img)); | |
1392 } else { | |
1393 img = gtk_widget_render_icon(GTK_WIDGET(imhtml), | |
1394 GTK_STOCK_MISSING_IMAGE, GTK_ICON_SIZE_BUTTON, | |
1395 "gtkimhtml-missing-image"); | |
1396 } | |
4895 | 1397 |
6982 | 1398 scalable = gtk_imhtml_image_new(img, filename); |
1399 NEW_BIT(NEW_SCALABLE_BIT); | |
1400 g_object_unref(G_OBJECT(img)); | |
4895 | 1401 } |
3922 | 1402 case 47: /* P (opt) */ |
1403 case 48: /* H3 (opt) */ | |
5093 | 1404 case 49: /* HTML (opt) */ |
5101 | 1405 case 50: /* CITE */ |
1406 case 51: /* /CITE */ | |
5104 | 1407 case 56: /* SPAN */ |
1408 case 57: /* /SPAN */ | |
2993 | 1409 break; |
6982 | 1410 case 60: /* comment */ |
3922 | 1411 NEW_BIT (NEW_TEXT_BIT); |
6124 | 1412 if (imhtml->show_comments) |
1413 wpos = g_snprintf (ws, len, "%s", tag); | |
3922 | 1414 NEW_BIT (NEW_COMMENT_BIT); |
1415 break; | |
1416 default: | |
6882 | 1417 break; |
2993 | 1418 } |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1419 c += tlen; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1420 pos += tlen; |
4138 | 1421 if(tag) |
1422 g_free(tag); /* This was allocated back in VALID_TAG() */ | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1423 } else if (*c == '&' && gtk_imhtml_is_amp_escape (c, &, &tlen)) { |
7280 | 1424 while(*amp) { |
1425 ws [wpos++] = *amp++; | |
1426 } | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1427 c += tlen; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1428 pos += tlen; |
1428 | 1429 } else if (*c == '\n') { |
1430 if (!(options & GTK_IMHTML_NO_NEWLINE)) { | |
3922 | 1431 ws[wpos] = '\n'; |
1432 wpos++; | |
1428 | 1433 NEW_BIT (NEW_TEXT_BIT); |
1434 } | |
1435 c++; | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1436 pos++; |
4253 | 1437 } else if (imhtml->show_smileys && (gtk_imhtml_is_smiley (imhtml, fonts, c, &smilelen) || gtk_imhtml_is_smiley(imhtml, NULL, c, &smilelen))) { |
6814
782907a6ae65
[gaim-migrate @ 7354]
Christian Hammond <chipx86@chipx86.com>
parents:
6648
diff
changeset
|
1438 GtkTextChildAnchor *anchor; |
6882 | 1439 GtkWidget *icon = NULL; |
7344 | 1440 GtkTextIter copy; |
6882 | 1441 GdkPixbufAnimation *annipixbuf = NULL; |
1442 GdkPixbuf *pixbuf = NULL; | |
5967 | 1443 GtkIMHtmlFontDetail *fd; |
7346 | 1444 |
4032 | 1445 gchar *sml = NULL; |
1446 if (fonts) { | |
1447 fd = fonts->data; | |
1448 sml = fd->sml; | |
1449 } | |
1450 NEW_BIT (NEW_TEXT_BIT); | |
1451 wpos = g_snprintf (ws, smilelen + 1, "%s", c); | |
6814
782907a6ae65
[gaim-migrate @ 7354]
Christian Hammond <chipx86@chipx86.com>
parents:
6648
diff
changeset
|
1452 anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, &iter); |
6882 | 1453 annipixbuf = gtk_smiley_tree_image(imhtml, sml, ws); |
1454 if(annipixbuf) { | |
1455 if(gdk_pixbuf_animation_is_static_image(annipixbuf)) { | |
1456 pixbuf = gdk_pixbuf_animation_get_static_image(annipixbuf); | |
1457 if(pixbuf) | |
1458 icon = gtk_image_new_from_pixbuf(pixbuf); | |
1459 } else { | |
1460 icon = gtk_image_new_from_animation(annipixbuf); | |
1461 } | |
1462 } | |
1463 | |
1464 if (icon) { | |
6839
bdc4e73f354d
[gaim-migrate @ 7384]
Christian Hammond <chipx86@chipx86.com>
parents:
6814
diff
changeset
|
1465 gtk_widget_show(icon); |
bdc4e73f354d
[gaim-migrate @ 7384]
Christian Hammond <chipx86@chipx86.com>
parents:
6814
diff
changeset
|
1466 gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(imhtml), icon, anchor); |
7346 | 1467 gtk_imhtml_copyable_new(imhtml, |
1468 gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE), | |
1469 ws); | |
6839
bdc4e73f354d
[gaim-migrate @ 7384]
Christian Hammond <chipx86@chipx86.com>
parents:
6814
diff
changeset
|
1470 } |
7344 | 1471 |
1472 copy = iter; | |
1473 gtk_text_iter_backward_char(©); | |
1474 if (bg) { | |
1475 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "background", bg, NULL); | |
1476 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &iter, ©); | |
1477 } | |
1478 if (fonts) { | |
1479 GtkIMHtmlFontDetail *fd = fonts->data; | |
1480 if (fd->back) { | |
1481 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "background", fd->back, NULL); | |
1482 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &iter, ©); | |
1483 } | |
1484 } | |
4032 | 1485 c += smilelen; |
1486 pos += smilelen; | |
1487 wpos = 0; | |
1488 ws[0] = 0; | |
1489 } else if (*c) { | |
1428 | 1490 ws [wpos++] = *c++; |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1491 pos++; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1492 } else { |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1493 break; |
1428 | 1494 } |
1495 } | |
3922 | 1496 |
1497 NEW_BIT(NEW_TEXT_BIT); | |
1428 | 1498 if (url) { |
1499 g_free (url); | |
3922 | 1500 if (str) |
1501 str = g_string_append (str, "</A>"); | |
1428 | 1502 } |
3922 | 1503 |
4032 | 1504 while (fonts) { |
5967 | 1505 GtkIMHtmlFontDetail *font = fonts->data; |
4032 | 1506 fonts = g_slist_remove (fonts, font); |
1507 if (font->face) | |
1508 g_free (font->face); | |
1509 if (font->fore) | |
1510 g_free (font->fore); | |
1511 if (font->back) | |
1512 g_free (font->back); | |
1513 if (font->sml) | |
1514 g_free (font->sml); | |
1515 g_free (font); | |
1516 if (str) | |
1517 str = g_string_append (str, "</FONT>"); | |
1518 } | |
1519 | |
3922 | 1520 if (str) { |
1428 | 1521 while (bold) { |
3922 | 1522 str = g_string_append (str, "</B>"); |
1428 | 1523 bold--; |
1524 } | |
1525 while (italics) { | |
3922 | 1526 str = g_string_append (str, "</I>"); |
1428 | 1527 italics--; |
1528 } | |
1529 while (underline) { | |
3922 | 1530 str = g_string_append (str, "</U>"); |
1428 | 1531 underline--; |
1532 } | |
1533 while (strike) { | |
3922 | 1534 str = g_string_append (str, "</S>"); |
1428 | 1535 strike--; |
1536 } | |
1537 while (sub) { | |
3922 | 1538 str = g_string_append (str, "</SUB>"); |
1428 | 1539 sub--; |
1540 } | |
1541 while (sup) { | |
3922 | 1542 str = g_string_append (str, "</SUP>"); |
1428 | 1543 sup--; |
1544 } | |
1545 while (title) { | |
3922 | 1546 str = g_string_append (str, "</TITLE>"); |
1428 | 1547 title--; |
1548 } | |
1691
d802b115800f
[gaim-migrate @ 1701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1647
diff
changeset
|
1549 while (pre) { |
3922 | 1550 str = g_string_append (str, "</PRE>"); |
1691
d802b115800f
[gaim-migrate @ 1701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1647
diff
changeset
|
1551 pre--; |
d802b115800f
[gaim-migrate @ 1701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1647
diff
changeset
|
1552 } |
1428 | 1553 } |
4032 | 1554 g_free (ws); |
4630 | 1555 if(bg) |
1556 g_free(bg); | |
4032 | 1557 if (!(options & GTK_IMHTML_NO_SCROLL)) |
1558 gtk_text_view_scroll_to_mark (GTK_TEXT_VIEW (imhtml), mark, | |
1559 0, TRUE, 0.0, 1.0); | |
3922 | 1560 gtk_text_buffer_delete_mark (imhtml->text_buffer, mark); |
1561 return str; | |
1562 } | |
1563 | |
4892 | 1564 void gtk_imhtml_remove_smileys(GtkIMHtml *imhtml) |
1565 { | |
4288 | 1566 g_hash_table_destroy(imhtml->smiley_data); |
1567 gtk_smiley_tree_destroy(imhtml->default_smilies); | |
4892 | 1568 imhtml->smiley_data = g_hash_table_new_full(g_str_hash, g_str_equal, |
4902 | 1569 g_free, (GDestroyNotify)gtk_smiley_tree_destroy); |
4288 | 1570 imhtml->default_smilies = gtk_smiley_tree_new(); |
1571 } | |
3922 | 1572 void gtk_imhtml_show_smileys (GtkIMHtml *imhtml, |
4253 | 1573 gboolean show) |
1574 { | |
1575 imhtml->show_smileys = show; | |
1576 } | |
3922 | 1577 |
1578 void gtk_imhtml_show_comments (GtkIMHtml *imhtml, | |
4253 | 1579 gboolean show) |
1580 { | |
6124 | 1581 imhtml->show_comments = show; |
4253 | 1582 } |
1780
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
1583 |
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
1584 void |
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
1585 gtk_imhtml_clear (GtkIMHtml *imhtml) |
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
1586 { |
3922 | 1587 GtkTextIter start, end; |
2993 | 1588 |
3922 | 1589 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start); |
1590 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end); | |
1591 gtk_text_buffer_delete(imhtml->text_buffer, &start, &end); | |
1780
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
1592 } |
2363
08c66712364c
[gaim-migrate @ 2376]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2349
diff
changeset
|
1593 |
4046 | 1594 void gtk_imhtml_page_up (GtkIMHtml *imhtml) |
1595 { | |
5282 | 1596 GdkRectangle rect; |
1597 GtkTextIter iter; | |
4046 | 1598 |
5282 | 1599 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); |
1600 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(imhtml), &iter, rect.x, | |
1601 rect.y - rect.height); | |
1602 gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(imhtml), &iter, 0, TRUE, 0, 0); | |
1603 | |
4046 | 1604 } |
5282 | 1605 void gtk_imhtml_page_down (GtkIMHtml *imhtml) |
1606 { | |
1607 GdkRectangle rect; | |
1608 GtkTextIter iter; | |
1609 | |
1610 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); | |
1611 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(imhtml), &iter, rect.x, | |
1612 rect.y + rect.height); | |
1613 gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(imhtml), &iter, 0, TRUE, 0, 0); | |
1614 } | |
4735 | 1615 |
5967 | 1616 /* GtkIMHtmlScalable, gtk_imhtml_image, gtk_imhtml_hr */ |
6982 | 1617 GtkIMHtmlScalable *gtk_imhtml_image_new(GdkPixbuf *img, const gchar *filename) |
4735 | 1618 { |
5967 | 1619 GtkIMHtmlImage *im_image = g_malloc(sizeof(GtkIMHtmlImage)); |
5012 | 1620 GtkImage *image = GTK_IMAGE(gtk_image_new_from_pixbuf(img)); |
4895 | 1621 |
5967 | 1622 GTK_IMHTML_SCALABLE(im_image)->scale = gtk_imhtml_image_scale; |
1623 GTK_IMHTML_SCALABLE(im_image)->add_to = gtk_imhtml_image_add_to; | |
1624 GTK_IMHTML_SCALABLE(im_image)->free = gtk_imhtml_image_free; | |
5046 | 1625 |
1626 im_image->pixbuf = img; | |
5012 | 1627 im_image->image = image; |
4895 | 1628 im_image->width = gdk_pixbuf_get_width(img); |
1629 im_image->height = gdk_pixbuf_get_height(img); | |
1630 im_image->mark = NULL; | |
6982 | 1631 im_image->filename = filename ? g_strdup(filename) : NULL; |
4895 | 1632 |
5046 | 1633 g_object_ref(img); |
4895 | 1634 return GTK_IMHTML_SCALABLE(im_image); |
1635 } | |
1636 | |
5967 | 1637 void gtk_imhtml_image_scale(GtkIMHtmlScalable *scale, int width, int height) |
4895 | 1638 { |
5967 | 1639 GtkIMHtmlImage *image = (GtkIMHtmlImage *)scale; |
4895 | 1640 |
1641 if(image->width > width || image->height > height){ | |
1642 GdkPixbuf *new_image = NULL; | |
1643 float factor; | |
1644 int new_width = image->width, new_height = image->height; | |
1645 | |
1646 if(image->width > width){ | |
1647 factor = (float)(width)/image->width; | |
1648 new_width = width; | |
1649 new_height = image->height * factor; | |
1650 } | |
1651 if(new_height > height){ | |
1652 factor = (float)(height)/new_height; | |
1653 new_height = height; | |
1654 new_width = new_width * factor; | |
1655 } | |
1656 | |
5046 | 1657 new_image = gdk_pixbuf_scale_simple(image->pixbuf, new_width, new_height, GDK_INTERP_BILINEAR); |
5012 | 1658 gtk_image_set_from_pixbuf(image->image, new_image); |
4895 | 1659 g_object_unref(G_OBJECT(new_image)); |
1660 } | |
1661 } | |
1662 | |
5012 | 1663 static void write_img_to_file(GtkWidget *w, GtkFileSelection *sel) |
1664 { | |
1665 const gchar *filename = gtk_file_selection_get_filename(sel); | |
5967 | 1666 gchar *dirname; |
1667 GtkIMHtmlImage *image = g_object_get_data(G_OBJECT(sel), "GtkIMHtmlImage"); | |
5012 | 1668 gchar *type = NULL; |
5019 | 1669 GError *error = NULL; |
5015 | 1670 #if GTK_CHECK_VERSION(2,2,0) |
5012 | 1671 GSList *formats = gdk_pixbuf_get_formats(); |
6162 | 1672 #else |
1673 char *basename = g_path_get_basename(filename); | |
1674 char *ext = strrchr(basename, '.'); | |
5959 | 1675 #endif |
5012 | 1676 |
5967 | 1677 if (g_file_test(filename, G_FILE_TEST_IS_DIR)) { |
1678 /* append a / if needed */ | |
1679 if (filename[strlen(filename) - 1] != '/') { | |
1680 dirname = g_strconcat(filename, "/", NULL); | |
1681 } else { | |
1682 dirname = g_strdup(filename); | |
1683 } | |
1684 gtk_file_selection_set_filename(sel, dirname); | |
1685 g_free(dirname); | |
5959 | 1686 return; |
5967 | 1687 } |
5959 | 1688 |
1689 #if GTK_CHECK_VERSION(2,2,0) | |
5012 | 1690 while(formats){ |
1691 GdkPixbufFormat *format = formats->data; | |
1692 gchar **extensions = gdk_pixbuf_format_get_extensions(format); | |
1693 gpointer p = extensions; | |
1694 | |
1695 while(gdk_pixbuf_format_is_writable(format) && extensions && extensions[0]){ | |
1696 gchar *fmt_ext = extensions[0]; | |
1697 const gchar* file_ext = filename + strlen(filename) - strlen(fmt_ext); | |
1698 | |
1699 if(!strcmp(fmt_ext, file_ext)){ | |
1700 type = gdk_pixbuf_format_get_name(format); | |
1701 break; | |
1702 } | |
1703 | |
1704 extensions++; | |
1705 } | |
1706 | |
1707 g_strfreev(p); | |
1708 | |
1709 if(type) | |
1710 break; | |
1711 | |
1712 formats = formats->next; | |
1713 } | |
1714 | |
5020 | 1715 g_slist_free(formats); |
1716 #else | |
1717 /* this is really ugly code, but I think it will work */ | |
1718 if(ext) { | |
1719 ext++; | |
1720 if(!g_ascii_strcasecmp(ext, "jpeg") || !g_ascii_strcasecmp(ext, "jpg")) | |
1721 type = g_strdup("jpeg"); | |
1722 else if(!g_ascii_strcasecmp(ext, "png")) | |
1723 type = g_strdup("png"); | |
1724 } | |
1725 | |
1726 g_free(basename); | |
1727 #endif | |
1728 | |
5012 | 1729 /* If I can't find a valid type, I will just tell the user about it and then assume |
1730 it's a png */ | |
1731 if(!type){ | |
1732 gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, | |
5967 | 1733 _("Unable to guess the image type based on the file extension supplied. Defaulting to PNG.")); |
5012 | 1734 type = g_strdup("png"); |
1735 } | |
1736 | |
5046 | 1737 gdk_pixbuf_save(image->pixbuf, filename, type, &error, NULL); |
5012 | 1738 |
1739 if(error){ | |
1740 gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, | |
1741 _("Error saving image: %s"), error->message); | |
1742 g_error_free(error); | |
1743 } | |
1744 | |
1745 g_free(type); | |
1746 } | |
1747 | |
5967 | 1748 static void gtk_imhtml_image_save(GtkWidget *w, GtkIMHtmlImage *image) |
5012 | 1749 { |
5967 | 1750 GtkWidget *sel = gtk_file_selection_new(_("Save Image")); |
5012 | 1751 |
6982 | 1752 if (image->filename) |
1753 gtk_file_selection_set_filename(GTK_FILE_SELECTION(sel), image->filename); | |
5967 | 1754 g_object_set_data(G_OBJECT(sel), "GtkIMHtmlImage", image); |
5012 | 1755 g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(sel)->ok_button), "clicked", |
1756 G_CALLBACK(write_img_to_file), sel); | |
1757 | |
1758 g_signal_connect_swapped(G_OBJECT(GTK_FILE_SELECTION(sel)->ok_button), "clicked", | |
1759 G_CALLBACK(gtk_widget_destroy), sel); | |
1760 g_signal_connect_swapped(G_OBJECT(GTK_FILE_SELECTION(sel)->cancel_button), "clicked", | |
1761 G_CALLBACK(gtk_widget_destroy), sel); | |
1762 | |
1763 gtk_widget_show(sel); | |
1764 } | |
1765 | |
5967 | 1766 static gboolean gtk_imhtml_image_clicked(GtkWidget *w, GdkEvent *event, GtkIMHtmlImage *image) |
5012 | 1767 { |
1768 GdkEventButton *event_button = (GdkEventButton *) event; | |
1769 | |
1770 if (event->type == GDK_BUTTON_RELEASE) { | |
1771 if(event_button->button == 3) { | |
1772 GtkWidget *img, *item, *menu; | |
1773 gchar *text = g_strdup_printf(_("_Save Image...")); | |
1774 menu = gtk_menu_new(); | |
1775 | |
1776 /* buttons and such */ | |
1777 img = gtk_image_new_from_stock(GTK_STOCK_SAVE, GTK_ICON_SIZE_MENU); | |
1778 item = gtk_image_menu_item_new_with_mnemonic(text); | |
1779 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), img); | |
5967 | 1780 g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(gtk_imhtml_image_save), image); |
5012 | 1781 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); |
1782 | |
1783 gtk_widget_show_all(menu); | |
1784 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, | |
1785 event_button->button, event_button->time); | |
1786 | |
1787 g_free(text); | |
1788 return TRUE; | |
1789 } | |
1790 } | |
1791 if(event->type == GDK_BUTTON_PRESS && event_button->button == 3) | |
1792 return TRUE; /* Clicking the right mouse button on a link shouldn't | |
1793 be caught by the regular GtkTextView menu */ | |
1794 else | |
1795 return FALSE; /* Let clicks go through if we didn't catch anything */ | |
1796 | |
1797 } | |
5967 | 1798 void gtk_imhtml_image_free(GtkIMHtmlScalable *scale) |
1799 { | |
1800 GtkIMHtmlImage *image = (GtkIMHtmlImage *)scale; | |
1801 | |
1802 g_object_unref(image->pixbuf); | |
6982 | 1803 if (image->filename) |
1804 g_free(image->filename); | |
5967 | 1805 g_free(scale); |
1806 } | |
1807 | |
1808 void gtk_imhtml_image_add_to(GtkIMHtmlScalable *scale, GtkIMHtml *imhtml, GtkTextIter *iter) | |
1809 { | |
1810 GtkIMHtmlImage *image = (GtkIMHtmlImage *)scale; | |
1811 GtkWidget *box = gtk_event_box_new(); | |
1812 GtkTextChildAnchor *anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, iter); | |
1813 | |
1814 gtk_container_add(GTK_CONTAINER(box), GTK_WIDGET(image->image)); | |
1815 | |
1816 gtk_widget_show(GTK_WIDGET(image->image)); | |
1817 gtk_widget_show(box); | |
1818 | |
1819 gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(imhtml), box, anchor); | |
1820 g_signal_connect(G_OBJECT(box), "event", G_CALLBACK(gtk_imhtml_image_clicked), image); | |
1821 } | |
1822 | |
1823 GtkIMHtmlScalable *gtk_imhtml_hr_new() | |
1824 { | |
1825 GtkIMHtmlHr *hr = g_malloc(sizeof(GtkIMHtmlHr)); | |
1826 | |
1827 GTK_IMHTML_SCALABLE(hr)->scale = gtk_imhtml_hr_scale; | |
1828 GTK_IMHTML_SCALABLE(hr)->add_to = gtk_imhtml_hr_add_to; | |
1829 GTK_IMHTML_SCALABLE(hr)->free = gtk_imhtml_hr_free; | |
1830 | |
1831 hr->sep = gtk_hseparator_new(); | |
1832 gtk_widget_set_size_request(hr->sep, 5000, 2); | |
1833 gtk_widget_show(hr->sep); | |
1834 | |
1835 return GTK_IMHTML_SCALABLE(hr); | |
1836 } | |
1837 | |
1838 void gtk_imhtml_hr_scale(GtkIMHtmlScalable *scale, int width, int height) | |
1839 { | |
1840 gtk_widget_set_size_request(((GtkIMHtmlHr *)scale)->sep, width, 2); | |
1841 } | |
1842 | |
1843 void gtk_imhtml_hr_add_to(GtkIMHtmlScalable *scale, GtkIMHtml *imhtml, GtkTextIter *iter) | |
1844 { | |
1845 GtkIMHtmlHr *hr = (GtkIMHtmlHr *)scale; | |
1846 GtkTextChildAnchor *anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, iter); | |
1847 | |
1848 gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(imhtml), hr->sep, anchor); | |
1849 } | |
1850 | |
1851 void gtk_imhtml_hr_free(GtkIMHtmlScalable *scale) | |
1852 { | |
1853 g_free(scale); | |
1854 } | |
7295 | 1855 |
1856 gboolean gtk_imhtml_search_find(GtkIMHtml *imhtml, const gchar *text) | |
1857 { | |
1858 GtkTextIter iter, start, end; | |
1859 gboolean new_search = TRUE; | |
1860 | |
1861 g_return_val_if_fail(imhtml != NULL, FALSE); | |
1862 g_return_val_if_fail(text != NULL, FALSE); | |
1863 | |
1864 if (imhtml->search_string && !strcmp(text, imhtml->search_string)) | |
1865 new_search = FALSE; | |
1866 | |
1867 | |
1868 if (new_search) { | |
1869 gtk_imhtml_search_clear(imhtml); | |
1870 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &iter); | |
1871 } else { | |
1872 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, | |
1873 gtk_text_buffer_get_mark(imhtml->text_buffer, "search")); | |
1874 } | |
1875 imhtml->search_string = g_strdup(text); | |
1876 | |
7358 | 1877 if (gtk_source_iter_forward_search(&iter, imhtml->search_string, |
1878 GTK_SOURCE_SEARCH_VISIBLE_ONLY | GTK_SOURCE_SEARCH_CASE_INSENSITIVE, | |
7295 | 1879 &start, &end, NULL)) { |
1880 | |
1881 gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(imhtml), &start, 0, TRUE, 0, 0); | |
1882 gtk_text_buffer_create_mark(imhtml->text_buffer, "search", &end, FALSE); | |
1883 if (new_search) { | |
1884 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "search", &iter, &end); | |
1885 do | |
1886 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "search", &start, &end); | |
7358 | 1887 while (gtk_source_iter_forward_search(&end, imhtml->search_string, |
1888 GTK_SOURCE_SEARCH_VISIBLE_ONLY | | |
1889 GTK_SOURCE_SEARCH_CASE_INSENSITIVE, | |
7295 | 1890 &start, &end, NULL)); |
1891 } | |
1892 return TRUE; | |
1893 } | |
1894 return FALSE; | |
1895 } | |
1896 | |
1897 void gtk_imhtml_search_clear(GtkIMHtml *imhtml) | |
1898 { | |
1899 GtkTextIter start, end; | |
1900 | |
1901 g_return_if_fail(imhtml != NULL); | |
1902 | |
1903 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start); | |
1904 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end); | |
1905 | |
1906 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "search", &start, &end); | |
1907 if (imhtml->search_string) | |
1908 g_free(imhtml->search_string); | |
1909 imhtml->search_string = NULL; | |
1910 } |