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