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