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