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