Mercurial > pidgin
annotate src/gtkimhtml.c @ 4933:34448ffab4f1
[gaim-migrate @ 5267]
someone noticed that:
" X alignment wasn't set on the status icon, causing it
to be displayed out of the column. "
btw, i hate patches from the po directory or the src directory. please
create your patches from the gaim directory.
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Mon, 31 Mar 2003 23:47:45 +0000 |
parents | 20c737bc03d7 |
children | 5fe846b7603f |
rev | line source |
---|---|
1428 | 1 /* |
2 * GtkIMHtml | |
3 * | |
4 * Copyright (C) 2000, Eric Warmenhoven <warmenhoven@yahoo.com> | |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 * | |
20 */ | |
21 | |
2541
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
22 #ifdef HAVE_CONFIG_H |
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
23 #include <config.h> |
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
24 #endif |
1428 | 25 #include "gtkimhtml.h" |
26 #include <gtk/gtk.h> | |
4895 | 27 #include <glib/gerror.h> |
4046 | 28 #include <gdk/gdkkeysyms.h> |
1428 | 29 #include <string.h> |
30 #include <ctype.h> | |
31 #include <stdio.h> | |
4629 | 32 #include <stdlib.h> |
1428 | 33 #include <math.h> |
2541
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
34 #ifdef HAVE_LANGINFO_CODESET |
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
35 #include <langinfo.h> |
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
36 #include <locale.h> |
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
37 #endif |
1428 | 38 |
4417 | 39 #ifdef ENABLE_NLS |
40 # include <libintl.h> | |
41 # define _(x) gettext(x) | |
42 # ifdef gettext_noop | |
43 # define N_(String) gettext_noop (String) | |
44 # else | |
45 # define N_(String) (String) | |
46 # endif | |
47 #else | |
48 # define N_(String) (String) | |
49 # define _(x) (x) | |
50 #endif | |
51 | |
4735 | 52 #include <pango/pango-font.h> |
53 | |
54 #define TOOLTIP_TIMEOUT 500 | |
55 | |
4764 | 56 static gboolean gtk_motion_event_notify(GtkWidget *imhtml, GdkEventMotion *event, gpointer user_data); |
57 | |
4895 | 58 static gboolean gtk_size_allocate_cb(GtkWidget *widget, GtkAllocation *alloc, gpointer user_data); |
59 static gint gtk_imhtml_tip (gpointer data); | |
4764 | 60 |
4735 | 61 |
3922 | 62 /* POINT_SIZE converts from AIM font sizes to point sizes. It probably should be redone in such a |
63 * way that it base the sizes off the default font size rather than using arbitrary font sizes. */ | |
64 #define MAX_FONT_SIZE 7 | |
65 #define POINT_SIZE(x) (_point_sizes [MIN ((x), MAX_FONT_SIZE) - 1]) | |
3928 | 66 static gint _point_sizes [] = { 8, 10, 12, 14, 20, 30, 40 }; |
2349
60c716c32c40
[gaim-migrate @ 2362]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2348
diff
changeset
|
67 |
3922 | 68 /* The four elements present in a <FONT> tag contained in a struct */ |
69 typedef struct _FontDetail FontDetail; | |
1428 | 70 struct _FontDetail { |
71 gushort size; | |
72 gchar *face; | |
3922 | 73 gchar *fore; |
74 gchar *back; | |
4032 | 75 gchar *sml; |
1428 | 76 }; |
77 | |
4032 | 78 struct _GtkSmileyTree { |
79 GString *values; | |
80 GtkSmileyTree **children; | |
4263 | 81 GtkIMHtmlSmiley *image; |
4032 | 82 }; |
83 | |
84 static GtkSmileyTree* | |
85 gtk_smiley_tree_new () | |
86 { | |
87 return g_new0 (GtkSmileyTree, 1); | |
88 } | |
89 | |
90 static void | |
91 gtk_smiley_tree_insert (GtkSmileyTree *tree, | |
4263 | 92 GtkIMHtmlSmiley *smiley) |
4032 | 93 { |
94 GtkSmileyTree *t = tree; | |
4263 | 95 const gchar *x = smiley->smile; |
4032 | 96 |
97 if (!strlen (x)) | |
98 return; | |
99 | |
100 while (*x) { | |
101 gchar *pos; | |
102 gint index; | |
103 | |
104 if (!t->values) | |
105 t->values = g_string_new (""); | |
106 | |
107 pos = strchr (t->values->str, *x); | |
108 if (!pos) { | |
109 t->values = g_string_append_c (t->values, *x); | |
110 index = t->values->len - 1; | |
111 t->children = g_realloc (t->children, t->values->len * sizeof (GtkSmileyTree *)); | |
112 t->children [index] = g_new0 (GtkSmileyTree, 1); | |
113 } else | |
114 index = (int) pos - (int) t->values->str; | |
115 | |
116 t = t->children [index]; | |
117 | |
118 x++; | |
119 } | |
120 | |
4263 | 121 t->image = smiley; |
4032 | 122 } |
4041 | 123 |
4263 | 124 |
4264 | 125 void gtk_smiley_tree_destroy (GtkSmileyTree *tree) |
4032 | 126 { |
127 GSList *list = g_slist_append (NULL, tree); | |
128 | |
129 while (list) { | |
130 GtkSmileyTree *t = list->data; | |
131 gint i; | |
132 list = g_slist_remove(list, t); | |
133 if (t->values) { | |
134 for (i = 0; i < t->values->len; i++) | |
135 list = g_slist_append (list, t->children [i]); | |
136 g_string_free (t->values, TRUE); | |
137 g_free (t->children); | |
138 } | |
139 g_free (t); | |
140 } | |
141 } | |
142 | |
4263 | 143 |
4032 | 144 static GtkTextViewClass *parent_class = NULL; |
145 | |
146 | |
3922 | 147 /* GtkIMHtml has one signal--URL_CLICKED */ |
1428 | 148 enum { |
149 URL_CLICKED, | |
150 LAST_SIGNAL | |
151 }; | |
152 static guint signals [LAST_SIGNAL] = { 0 }; | |
153 | |
4032 | 154 static void |
155 gtk_imhtml_finalize (GObject *object) | |
156 { | |
157 GtkIMHtml *imhtml = GTK_IMHTML(object); | |
4895 | 158 GList *scalables; |
159 | |
4138 | 160 g_hash_table_destroy(imhtml->smiley_data); |
4032 | 161 gtk_smiley_tree_destroy(imhtml->default_smilies); |
4138 | 162 gdk_cursor_unref(imhtml->hand_cursor); |
163 gdk_cursor_unref(imhtml->arrow_cursor); | |
4735 | 164 if(imhtml->tip_window){ |
165 gtk_widget_destroy(imhtml->tip_window); | |
166 } | |
167 if(imhtml->tip_timer) | |
168 gtk_timeout_remove(imhtml->tip_timer); | |
169 | |
4895 | 170 for(scalables = imhtml->scalables; scalables; scalables = scalables->next) { |
171 GtkIMHtmlScalable *scale = GTK_IMHTML_SCALABLE(scalables->data); | |
172 scale->free(scale); | |
173 } | |
174 | |
175 g_list_free(imhtml->scalables); | |
4032 | 176 G_OBJECT_CLASS(parent_class)->finalize (object); |
177 } | |
1428 | 178 |
3922 | 179 /* Boring GTK stuff */ |
180 static void gtk_imhtml_class_init (GtkIMHtmlClass *class) | |
1428 | 181 { |
3922 | 182 GtkObjectClass *object_class; |
4032 | 183 GObjectClass *gobject_class; |
3922 | 184 object_class = (GtkObjectClass*) class; |
4032 | 185 gobject_class = (GObjectClass*) class; |
186 parent_class = gtk_type_class(GTK_TYPE_TEXT_VIEW); | |
4417 | 187 signals[URL_CLICKED] = g_signal_new("url_clicked", |
188 G_TYPE_FROM_CLASS(gobject_class), | |
189 G_SIGNAL_RUN_FIRST, | |
190 G_STRUCT_OFFSET(GtkIMHtmlClass, url_clicked), | |
191 NULL, | |
192 0, | |
193 g_cclosure_marshal_VOID__POINTER, | |
194 G_TYPE_NONE, 1, | |
195 G_TYPE_POINTER); | |
4032 | 196 gobject_class->finalize = gtk_imhtml_finalize; |
1428 | 197 } |
198 | |
3922 | 199 static void gtk_imhtml_init (GtkIMHtml *imhtml) |
1428 | 200 { |
3922 | 201 GtkTextIter iter; |
202 imhtml->text_buffer = gtk_text_buffer_new(NULL); | |
203 gtk_text_buffer_get_end_iter (imhtml->text_buffer, &iter); | |
204 imhtml->end = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, FALSE); | |
205 gtk_text_view_set_buffer(GTK_TEXT_VIEW(imhtml), imhtml->text_buffer); | |
206 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(imhtml), GTK_WRAP_WORD); | |
207 gtk_text_view_set_editable(GTK_TEXT_VIEW(imhtml), FALSE); | |
208 gtk_text_view_set_pixels_below_lines(GTK_TEXT_VIEW(imhtml), 5); | |
209 gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(imhtml), FALSE); | |
210 /*gtk_text_view_set_justification(GTK_TEXT_VIEW(imhtml), GTK_JUSTIFY_FILL);*/ | |
3465 | 211 |
3922 | 212 /* These tags will be used often and can be reused--we create them on init and then apply them by name |
213 * other tags (color, size, face, etc.) will have to be created and applied dynamically */ | |
214 gtk_text_buffer_create_tag(imhtml->text_buffer, "BOLD", "weight", PANGO_WEIGHT_BOLD, NULL); | |
215 gtk_text_buffer_create_tag(imhtml->text_buffer, "ITALICS", "style", PANGO_STYLE_ITALIC, NULL); | |
216 gtk_text_buffer_create_tag(imhtml->text_buffer, "UNDERLINE", "underline", PANGO_UNDERLINE_SINGLE, NULL); | |
217 gtk_text_buffer_create_tag(imhtml->text_buffer, "STRIKE", "strikethrough", TRUE, NULL); | |
218 gtk_text_buffer_create_tag(imhtml->text_buffer, "SUB", "rise", -5000, NULL); | |
219 gtk_text_buffer_create_tag(imhtml->text_buffer, "SUP", "rise", 5000, NULL); | |
220 gtk_text_buffer_create_tag(imhtml->text_buffer, "PRE", "family", "Monospace", NULL); | |
3465 | 221 |
3922 | 222 /* When hovering over a link, we show the hand cursor--elsewhere we show the plain ol' pointer cursor */ |
223 imhtml->hand_cursor = gdk_cursor_new (GDK_HAND2); | |
224 imhtml->arrow_cursor = gdk_cursor_new (GDK_LEFT_PTR); | |
2993 | 225 |
4253 | 226 imhtml->show_smileys = TRUE; |
227 imhtml->show_comments = TRUE; | |
228 | |
4892 | 229 imhtml->smiley_data = g_hash_table_new_full(g_str_hash, g_str_equal, |
4902 | 230 g_free, (GDestroyNotify)gtk_smiley_tree_destroy); |
4032 | 231 imhtml->default_smilies = gtk_smiley_tree_new(); |
4735 | 232 |
233 g_signal_connect(G_OBJECT(imhtml), "motion-notify-event", G_CALLBACK(gtk_motion_event_notify), NULL); | |
4895 | 234 g_signal_connect(G_OBJECT(imhtml), "size-allocate", G_CALLBACK(gtk_size_allocate_cb), NULL); |
4735 | 235 |
236 imhtml->tip = NULL; | |
237 imhtml->tip_timer = 0; | |
238 imhtml->tip_window = NULL; | |
4895 | 239 |
240 imhtml->scalables = NULL; | |
2993 | 241 } |
242 | |
3922 | 243 GtkWidget *gtk_imhtml_new(void *a, void *b) |
1428 | 244 { |
4635 | 245 return GTK_WIDGET(g_object_new(gtk_imhtml_get_type(), NULL)); |
1428 | 246 } |
247 | |
4635 | 248 GType gtk_imhtml_get_type() |
1428 | 249 { |
4635 | 250 static GType imhtml_type = 0; |
1428 | 251 |
252 if (!imhtml_type) { | |
4635 | 253 static const GTypeInfo imhtml_info = { |
254 sizeof(GtkIMHtmlClass), | |
255 NULL, | |
256 NULL, | |
257 (GClassInitFunc) gtk_imhtml_class_init, | |
258 NULL, | |
259 NULL, | |
1428 | 260 sizeof (GtkIMHtml), |
4635 | 261 0, |
262 (GInstanceInitFunc) gtk_imhtml_init | |
1428 | 263 }; |
4635 | 264 |
265 imhtml_type = g_type_register_static(gtk_text_view_get_type(), | |
266 "GtkIMHtml", &imhtml_info, 0); | |
1428 | 267 } |
268 | |
269 return imhtml_type; | |
270 } | |
271 | |
4417 | 272 struct url_data { |
273 GObject *object; | |
274 gchar *url; | |
275 }; | |
276 | |
277 static void url_open(GtkWidget *w, struct url_data *data) { | |
278 if(!data) return; | |
279 | |
280 g_signal_emit(data->object, signals[URL_CLICKED], 0, data->url); | |
281 | |
282 g_object_unref(data->object); | |
283 g_free(data->url); | |
284 g_free(data); | |
285 } | |
286 static void url_copy(GtkWidget *w, gchar *url) { | |
287 GtkClipboard *clipboard; | |
288 | |
4419 | 289 clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); |
4417 | 290 gtk_clipboard_set_text(clipboard, url, -1); |
291 } | |
292 | |
293 /* The callback for an event on a link tag. */ | |
294 gboolean tag_event(GtkTextTag *tag, GObject *arg1, GdkEvent *event, GtkTextIter *arg2, char *url) { | |
295 GdkEventButton *event_button = (GdkEventButton *) event; | |
296 | |
3922 | 297 if (event->type == GDK_BUTTON_RELEASE) { |
4417 | 298 if (event_button->button == 1) { |
299 GtkTextIter start, end; | |
300 /* we shouldn't open a URL if the user has selected something: */ | |
301 gtk_text_buffer_get_selection_bounds( | |
302 gtk_text_iter_get_buffer(arg2), &start, &end); | |
303 if(gtk_text_iter_get_offset(&start) != | |
304 gtk_text_iter_get_offset(&end)) | |
305 return FALSE; | |
306 | |
307 /* A link was clicked--we emit the "url_clicked" signal | |
308 * with the URL as the argument */ | |
309 g_signal_emit(arg1, signals[URL_CLICKED], 0, url); | |
310 return FALSE; | |
311 } else if(event_button->button == 3) { | |
4745 | 312 GtkWidget *img, *item, *menu; |
4417 | 313 struct url_data *tempdata = g_new(struct url_data, 1); |
314 tempdata->object = g_object_ref(arg1); | |
315 tempdata->url = g_strdup(url); | |
4745 | 316 |
4417 | 317 menu = gtk_menu_new(); |
4745 | 318 |
4417 | 319 /* buttons and such */ |
320 img = gtk_image_new_from_stock(GTK_STOCK_COPY, GTK_ICON_SIZE_MENU); | |
4420 | 321 item = gtk_image_menu_item_new_with_mnemonic(_("_Copy Link Location")); |
4417 | 322 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), img); |
323 g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(url_copy), | |
324 url); | |
325 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); | |
326 | |
327 img = gtk_image_new_from_stock(GTK_STOCK_JUMP_TO, GTK_ICON_SIZE_MENU); | |
4420 | 328 item = gtk_image_menu_item_new_with_mnemonic(_("_Open Link in Browser")); |
4417 | 329 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), img); |
330 g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(url_open), | |
331 tempdata); | |
332 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); | |
4756 | 333 |
4417 | 334 gtk_widget_show_all(menu); |
4756 | 335 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, |
336 event_button->button, event_button->time); | |
4745 | 337 |
4417 | 338 return TRUE; |
339 } | |
1428 | 340 } |
4417 | 341 if(event->type == GDK_BUTTON_PRESS && event_button->button == 3) |
342 return TRUE; /* Clicking the right mouse button on a link shouldn't | |
343 be caught by the regular GtkTextView menu */ | |
344 else | |
345 return FALSE; /* Let clicks go through if we didn't catch anything */ | |
1428 | 346 } |
347 | |
4735 | 348 gboolean gtk_motion_event_notify(GtkWidget *imhtml, GdkEventMotion *event, gpointer data) |
349 { | |
350 GtkTextIter iter; | |
351 GdkWindow *win = event->window; | |
352 int x, y; | |
4740 | 353 char *tip = NULL; |
4735 | 354 GSList *tags = NULL, *templist = NULL; |
355 gdk_window_get_pointer(GTK_WIDGET(imhtml)->window, NULL, NULL, NULL); | |
356 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(imhtml), GTK_TEXT_WINDOW_WIDGET, | |
357 event->x, event->y, &x, &y); | |
358 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(imhtml), &iter, x, y); | |
359 tags = gtk_text_iter_get_tags(&iter); | |
360 | |
4740 | 361 templist = tags; |
362 while (templist) { | |
4735 | 363 GtkTextTag *tag = templist->data; |
4740 | 364 tip = g_object_get_data(G_OBJECT(tag), "link_url"); |
365 if (tip) | |
366 break; | |
367 templist = templist->next; | |
4735 | 368 } |
4740 | 369 |
370 if (GTK_IMHTML(imhtml)->tip) { | |
371 if ((tip == GTK_IMHTML(imhtml)->tip)) { | |
372 return FALSE; | |
373 } | |
374 /* We've left the cell. Remove the timeout and create a new one below */ | |
375 if (GTK_IMHTML(imhtml)->tip_window) { | |
376 gtk_widget_destroy(GTK_IMHTML(imhtml)->tip_window); | |
377 GTK_IMHTML(imhtml)->tip_window = NULL; | |
378 } | |
379 gdk_window_set_cursor(win, GTK_IMHTML(imhtml)->arrow_cursor); | |
380 if (GTK_IMHTML(imhtml)->tip_timer) | |
381 g_source_remove(GTK_IMHTML(imhtml)->tip_timer); | |
382 GTK_IMHTML(imhtml)->tip_timer = 0; | |
383 } | |
384 | |
385 if(tip){ | |
4735 | 386 gdk_window_set_cursor(win, GTK_IMHTML(imhtml)->hand_cursor); |
4740 | 387 GTK_IMHTML(imhtml)->tip_timer = g_timeout_add (TOOLTIP_TIMEOUT, |
388 gtk_imhtml_tip, imhtml); | |
4735 | 389 } |
4740 | 390 |
391 GTK_IMHTML(imhtml)->tip = tip; | |
4735 | 392 g_slist_free(tags); |
393 return FALSE; | |
394 } | |
395 | |
4298 | 396 /* this isn't used yet |
4032 | 397 static void |
4263 | 398 gtk_smiley_tree_remove (GtkSmileyTree *tree, |
399 GtkIMHtmlSmiley *smiley) | |
4032 | 400 { |
401 GtkSmileyTree *t = tree; | |
4263 | 402 const gchar *x = smiley->smile; |
4032 | 403 gint len = 0; |
404 | |
405 while (*x) { | |
406 gchar *pos; | |
407 | |
408 if (!t->values) | |
409 return; | |
410 | |
411 pos = strchr (t->values->str, *x); | |
412 if (pos) | |
413 t = t->children [(int) pos - (int) t->values->str]; | |
414 else | |
415 return; | |
416 | |
417 x++; len++; | |
418 } | |
419 | |
4141
ccec4fde84f4
[gaim-migrate @ 4359]
Christian Hammond <chipx86@chipx86.com>
parents:
4140
diff
changeset
|
420 if (t->image) { |
4032 | 421 t->image = NULL; |
4141
ccec4fde84f4
[gaim-migrate @ 4359]
Christian Hammond <chipx86@chipx86.com>
parents:
4140
diff
changeset
|
422 } |
4032 | 423 } |
4298 | 424 */ |
425 | |
4032 | 426 |
427 static gint | |
428 gtk_smiley_tree_lookup (GtkSmileyTree *tree, | |
429 const gchar *text) | |
430 { | |
431 GtkSmileyTree *t = tree; | |
432 const gchar *x = text; | |
433 gint len = 0; | |
434 | |
435 while (*x) { | |
436 gchar *pos; | |
437 | |
438 if (!t->values) | |
439 break; | |
440 | |
441 pos = strchr (t->values->str, *x); | |
442 if (pos) | |
443 t = t->children [(int) pos - (int) t->values->str]; | |
444 else | |
445 break; | |
446 | |
447 x++; len++; | |
448 } | |
449 | |
450 if (t->image) | |
451 return len; | |
452 | |
453 return 0; | |
454 } | |
455 | |
456 void | |
4263 | 457 gtk_imhtml_associate_smiley (GtkIMHtml *imhtml, |
458 gchar *sml, | |
459 GtkIMHtmlSmiley *smiley) | |
4032 | 460 { |
461 GtkSmileyTree *tree; | |
462 g_return_if_fail (imhtml != NULL); | |
463 g_return_if_fail (GTK_IS_IMHTML (imhtml)); | |
4263 | 464 |
4032 | 465 if (sml == NULL) |
466 tree = imhtml->default_smilies; | |
467 else if ((tree = g_hash_table_lookup(imhtml->smiley_data, sml))) { | |
468 } else { | |
469 tree = gtk_smiley_tree_new(); | |
4892 | 470 g_hash_table_insert(imhtml->smiley_data, g_strdup(sml), tree); |
4032 | 471 } |
472 | |
4263 | 473 gtk_smiley_tree_insert (tree, smiley); |
4032 | 474 } |
475 | |
476 static gboolean | |
477 gtk_imhtml_is_smiley (GtkIMHtml *imhtml, | |
478 GSList *fonts, | |
479 const gchar *text, | |
480 gint *len) | |
481 { | |
482 GtkSmileyTree *tree; | |
483 FontDetail *font; | |
484 char *sml = NULL; | |
485 | |
486 if (fonts) { | |
487 font = fonts->data; | |
488 sml = font->sml; | |
489 } | |
490 | |
491 if (sml == NULL) | |
492 tree = imhtml->default_smilies; | |
493 else { | |
494 tree = g_hash_table_lookup(imhtml->smiley_data, sml); | |
495 } | |
496 if (tree == NULL) | |
497 return FALSE; | |
498 | |
499 *len = gtk_smiley_tree_lookup (tree, text); | |
500 return (*len > 0); | |
501 } | |
502 | |
4263 | 503 GdkPixbuf* |
4032 | 504 gtk_smiley_tree_image (GtkIMHtml *imhtml, |
505 const gchar *sml, | |
506 const gchar *text) | |
507 { | |
508 GtkSmileyTree *t; | |
509 const gchar *x = text; | |
510 if (sml == NULL) | |
511 t = imhtml->default_smilies; | |
512 else | |
513 t = g_hash_table_lookup(imhtml->smiley_data, sml); | |
514 | |
515 | |
516 if (t == NULL) | |
517 return sml ? gtk_smiley_tree_image(imhtml, NULL, text) : NULL; | |
518 | |
519 while (*x) { | |
520 gchar *pos; | |
521 | |
522 if (!t->values) { | |
523 return sml ? gtk_smiley_tree_image(imhtml, NULL, text) : NULL; | |
524 } | |
525 | |
526 pos = strchr (t->values->str, *x); | |
527 if (pos) { | |
528 t = t->children [(int) pos - (int) t->values->str]; | |
529 } else { | |
530 return sml ? gtk_smiley_tree_image(imhtml, NULL, text) : NULL; | |
531 } | |
532 x++; | |
533 } | |
534 | |
4263 | 535 if (!t->image->icon) |
536 t->image->icon = gdk_pixbuf_new_from_file(t->image->file, NULL); | |
537 | |
538 return t->image->icon; | |
4032 | 539 } |
4793 | 540 #define VALID_TAG(x) if (!g_ascii_strncasecmp (string, x ">", strlen (x ">"))) { \ |
3922 | 541 *tag = g_strndup (string, strlen (x)); \ |
542 *len = strlen (x) + 1; \ | |
543 return TRUE; \ | |
544 } \ | |
545 (*type)++ | |
1428 | 546 |
4793 | 547 #define VALID_OPT_TAG(x) if (!g_ascii_strncasecmp (string, x " ", strlen (x " "))) { \ |
3922 | 548 const gchar *c = string + strlen (x " "); \ |
549 gchar e = '"'; \ | |
550 gboolean quote = FALSE; \ | |
551 while (*c) { \ | |
552 if (*c == '"' || *c == '\'') { \ | |
553 if (quote && (*c == e)) \ | |
554 quote = !quote; \ | |
555 else if (!quote) { \ | |
556 quote = !quote; \ | |
557 e = *c; \ | |
558 } \ | |
559 } else if (!quote && (*c == '>')) \ | |
560 break; \ | |
561 c++; \ | |
562 } \ | |
563 if (*c) { \ | |
564 *tag = g_strndup (string, c - string); \ | |
565 *len = c - string + 1; \ | |
566 return TRUE; \ | |
567 } \ | |
568 } \ | |
569 (*type)++ | |
1428 | 570 |
571 | |
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
572 static gboolean |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
573 gtk_imhtml_is_amp_escape (const gchar *string, |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
574 gchar *replace, |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
575 gint *length) |
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
576 { |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
577 g_return_val_if_fail (string != NULL, FALSE); |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
578 g_return_val_if_fail (replace != NULL, FALSE); |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
579 g_return_val_if_fail (length != NULL, FALSE); |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
580 |
4793 | 581 if (!g_ascii_strncasecmp (string, "&", 5)) { |
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
582 *replace = '&'; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
583 *length = 5; |
4793 | 584 } else if (!g_ascii_strncasecmp (string, "<", 4)) { |
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
585 *replace = '<'; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
586 *length = 4; |
4793 | 587 } else if (!g_ascii_strncasecmp (string, ">", 4)) { |
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
588 *replace = '>'; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
589 *length = 4; |
4793 | 590 } else if (!g_ascii_strncasecmp (string, " ", 6)) { |
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
591 *replace = ' '; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
592 *length = 6; |
4793 | 593 } else if (!g_ascii_strncasecmp (string, "©", 6)) { |
3717
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3705
diff
changeset
|
594 *replace = '©'; /* was: '©' */ |
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
595 *length = 6; |
4793 | 596 } else if (!g_ascii_strncasecmp (string, """, 6)) { |
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
597 *replace = '\"'; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
598 *length = 6; |
4793 | 599 } else if (!g_ascii_strncasecmp (string, "®", 5)) { |
3717
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3705
diff
changeset
|
600 *replace = '®'; /* was: '®' */ |
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
601 *length = 5; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
602 } else if (*(string + 1) == '#') { |
2022
199ba82faacb
[gaim-migrate @ 2032]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2002
diff
changeset
|
603 guint pound = 0; |
3004 | 604 if ((sscanf (string, "&#%u;", £) == 1) && pound != 0) { |
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
605 if (*(string + 3 + (gint)log10 (pound)) != ';') |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
606 return FALSE; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
607 *replace = (gchar)pound; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
608 *length = 2; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
609 while (isdigit ((gint) string [*length])) (*length)++; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
610 if (string [*length] == ';') (*length)++; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
611 } else { |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
612 return FALSE; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
613 } |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
614 } else { |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
615 return FALSE; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
616 } |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
617 |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
618 return TRUE; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
619 } |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
620 |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
621 static gboolean |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
622 gtk_imhtml_is_tag (const gchar *string, |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
623 gchar **tag, |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
624 gint *len, |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
625 gint *type) |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
626 { |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
627 *type = 1; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
628 |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
629 if (!strchr (string, '>')) |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
630 return FALSE; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
631 |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
632 VALID_TAG ("B"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
633 VALID_TAG ("BOLD"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
634 VALID_TAG ("/B"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
635 VALID_TAG ("/BOLD"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
636 VALID_TAG ("I"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
637 VALID_TAG ("ITALIC"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
638 VALID_TAG ("/I"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
639 VALID_TAG ("/ITALIC"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
640 VALID_TAG ("U"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
641 VALID_TAG ("UNDERLINE"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
642 VALID_TAG ("/U"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
643 VALID_TAG ("/UNDERLINE"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
644 VALID_TAG ("S"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
645 VALID_TAG ("STRIKE"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
646 VALID_TAG ("/S"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
647 VALID_TAG ("/STRIKE"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
648 VALID_TAG ("SUB"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
649 VALID_TAG ("/SUB"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
650 VALID_TAG ("SUP"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
651 VALID_TAG ("/SUP"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
652 VALID_TAG ("PRE"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
653 VALID_TAG ("/PRE"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
654 VALID_TAG ("TITLE"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
655 VALID_TAG ("/TITLE"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
656 VALID_TAG ("BR"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
657 VALID_TAG ("HR"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
658 VALID_TAG ("/FONT"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
659 VALID_TAG ("/A"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
660 VALID_TAG ("P"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
661 VALID_TAG ("/P"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
662 VALID_TAG ("H3"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
663 VALID_TAG ("/H3"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
664 VALID_TAG ("HTML"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
665 VALID_TAG ("/HTML"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
666 VALID_TAG ("BODY"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
667 VALID_TAG ("/BODY"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
668 VALID_TAG ("FONT"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
669 VALID_TAG ("HEAD"); |
2993 | 670 VALID_TAG ("/HEAD"); |
671 VALID_TAG ("BINARY"); | |
672 VALID_TAG ("/BINARY"); | |
673 | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
674 VALID_OPT_TAG ("HR"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
675 VALID_OPT_TAG ("FONT"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
676 VALID_OPT_TAG ("BODY"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
677 VALID_OPT_TAG ("A"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
678 VALID_OPT_TAG ("IMG"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
679 VALID_OPT_TAG ("P"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
680 VALID_OPT_TAG ("H3"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
681 |
4793 | 682 if (!g_ascii_strncasecmp(string, "!--", strlen ("!--"))) { |
2954
f6c4f2187c08
[gaim-migrate @ 2967]
Christian Hammond <chipx86@chipx86.com>
parents:
2898
diff
changeset
|
683 gchar *e = strstr (string + strlen("!--"), "-->"); |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
684 if (e) { |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
685 *len = e - string + strlen ("-->"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
686 *tag = g_strndup (string + strlen ("!--"), *len - strlen ("!---->")); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
687 return TRUE; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
688 } |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
689 } |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
690 |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
691 return FALSE; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
692 } |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
693 |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
694 static gchar* |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
695 gtk_imhtml_get_html_opt (gchar *tag, |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
696 const gchar *opt) |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
697 { |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
698 gchar *t = tag; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
699 gchar *e, *a; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
700 |
4793 | 701 while (g_ascii_strncasecmp (t, opt, strlen (opt))) { |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
702 gboolean quote = FALSE; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
703 if (*t == '\0') break; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
704 while (*t && !((*t == ' ') && !quote)) { |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
705 if (*t == '\"') |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
706 quote = ! quote; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
707 t++; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
708 } |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
709 while (*t && (*t == ' ')) t++; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
710 } |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
711 |
4793 | 712 if (!g_ascii_strncasecmp (t, opt, strlen (opt))) { |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
713 t += strlen (opt); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
714 } else { |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
715 return NULL; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
716 } |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
717 |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
718 if ((*t == '\"') || (*t == '\'')) { |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
719 e = a = ++t; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
720 while (*e && (*e != *(t - 1))) e++; |
2993 | 721 if (*e == '\0') { |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
722 return NULL; |
2993 | 723 } else |
724 return g_strndup (a, e - a); | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
725 } else { |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
726 e = a = t; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
727 while (*e && !isspace ((gint) *e)) e++; |
2993 | 728 return g_strndup (a, e - a); |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
729 } |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
730 } |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
731 |
3922 | 732 |
733 | |
734 #define NEW_TEXT_BIT 0 | |
4343 | 735 #define NEW_COMMENT_BIT 2 |
4895 | 736 #define NEW_SCALABLE_BIT 1 |
3922 | 737 #define NEW_BIT(x) ws [wpos] = '\0'; \ |
738 mark2 = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); \ | |
739 gtk_text_buffer_insert(imhtml->text_buffer, &iter, ws, -1); \ | |
4895 | 740 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &iter); \ |
3922 | 741 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &siter, mark2); \ |
742 gtk_text_buffer_delete_mark(imhtml->text_buffer, mark2); \ | |
743 if (bold) \ | |
744 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "BOLD", &siter, &iter); \ | |
4895 | 745 if (italics) \ |
3922 | 746 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "ITALICS", &siter, &iter); \ |
747 if (underline) \ | |
748 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "UNDERLINE", &siter, &iter); \ | |
749 if (strike) \ | |
750 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "STRIKE", &siter, &iter); \ | |
751 if (sub) \ | |
752 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "SUB", &siter, &iter); \ | |
753 if (sup) \ | |
754 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "SUP", &siter, &iter); \ | |
755 if (pre) \ | |
756 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "PRE", &siter, &iter); \ | |
757 if (bg) { \ | |
758 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "background", bg, NULL); \ | |
759 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &siter, &iter); \ | |
760 } \ | |
761 if (fonts) { \ | |
762 FontDetail *fd = fonts->data; \ | |
763 if (fd->fore) { \ | |
764 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "foreground", fd->fore, NULL); \ | |
765 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &siter, &iter); \ | |
766 } \ | |
767 if (fd->back) { \ | |
768 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "background", fd->back, NULL); \ | |
769 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &siter, &iter); \ | |
770 } \ | |
771 if (fd->face) { \ | |
772 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "font", fd->face, NULL); \ | |
773 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &siter, &iter); \ | |
774 } \ | |
775 if (fd->size) { \ | |
776 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "size-points", (double)POINT_SIZE(fd->size), NULL); \ | |
777 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &siter, &iter); \ | |
778 } \ | |
779 } \ | |
780 if (url) { \ | |
781 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "foreground", "blue", "underline", PANGO_UNDERLINE_SINGLE, NULL); \ | |
782 g_signal_connect(G_OBJECT(texttag), "event", G_CALLBACK(tag_event), strdup(url)); \ | |
783 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &siter, &iter); \ | |
4735 | 784 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, NULL); \ |
785 g_object_set_data(G_OBJECT(texttag), "link_url", g_strdup(url)); \ | |
786 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &siter, &iter); \ | |
3922 | 787 } \ |
788 wpos = 0; \ | |
789 ws[0] = 0; \ | |
790 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &iter); \ | |
4895 | 791 if (x == NEW_SCALABLE_BIT) { \ |
792 GdkRectangle rect; \ | |
793 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); \ | |
794 scalable->add_to(scalable, imhtml, &iter); \ | |
795 scalable->scale(scalable, rect.width, rect.height); \ | |
796 imhtml->scalables = g_list_append(imhtml->scalables, scalable); \ | |
797 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &iter); \ | |
4343 | 798 } \ |
3922 | 799 |
4895 | 800 |
801 | |
3922 | 802 GString* gtk_imhtml_append_text (GtkIMHtml *imhtml, |
803 const gchar *text, | |
804 gint len, | |
805 GtkIMHtmlOptions options) | |
1428 | 806 { |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
807 gint pos = 0; |
3922 | 808 GString *str = NULL; |
809 GtkTextIter iter, siter; | |
810 GtkTextMark *mark, *mark2; | |
811 GtkTextTag *texttag; | |
812 gchar *ws; | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
813 gchar *tag; |
3922 | 814 gchar *url = NULL; |
815 gchar *bg = NULL; | |
4032 | 816 gint tlen, smilelen, wpos=0; |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
817 gint type; |
3922 | 818 const gchar *c; |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
819 gchar amp; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
820 |
1428 | 821 guint bold = 0, |
822 italics = 0, | |
823 underline = 0, | |
824 strike = 0, | |
825 sub = 0, | |
826 sup = 0, | |
1691
d802b115800f
[gaim-migrate @ 1701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1647
diff
changeset
|
827 title = 0, |
3922 | 828 pre = 0; |
1428 | 829 |
3922 | 830 GSList *fonts = NULL; |
1428 | 831 |
4612 | 832 GdkRectangle rect; |
833 int y, height; | |
834 | |
4895 | 835 GtkIMHtmlScalable *scalable = NULL; |
836 | |
1428 | 837 g_return_val_if_fail (imhtml != NULL, NULL); |
838 g_return_val_if_fail (GTK_IS_IMHTML (imhtml), NULL); | |
839 g_return_val_if_fail (text != NULL, NULL); | |
3922 | 840 g_return_val_if_fail (len != 0, NULL); |
841 | |
842 c = text; | |
843 if (len == -1) | |
844 len = strlen(text); | |
845 ws = g_malloc(len + 1); | |
846 ws[0] = 0; | |
1428 | 847 |
848 if (options & GTK_IMHTML_RETURN_LOG) | |
3922 | 849 str = g_string_new(""); |
1428 | 850 |
3922 | 851 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &iter); |
852 mark = gtk_text_buffer_create_mark (imhtml->text_buffer, NULL, &iter, /* right grav */ FALSE); | |
4612 | 853 |
854 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); | |
855 gtk_text_view_get_line_yrange(GTK_TEXT_VIEW(imhtml), &iter, &y, &height); | |
856 | |
857 if(((y + height) - (rect.y + rect.height)) > height | |
858 && gtk_text_buffer_get_char_count(imhtml->text_buffer)){ | |
859 options |= GTK_IMHTML_NO_SCROLL; | |
860 } | |
861 | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
862 while (pos < len) { |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
863 if (*c == '<' && gtk_imhtml_is_tag (c + 1, &tag, &tlen, &type)) { |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
864 c++; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
865 pos++; |
3922 | 866 switch (type) |
867 { | |
868 case 1: /* B */ | |
869 case 2: /* BOLD */ | |
870 NEW_BIT (NEW_TEXT_BIT); | |
871 bold++; | |
872 break; | |
873 case 3: /* /B */ | |
874 case 4: /* /BOLD */ | |
875 NEW_BIT (NEW_TEXT_BIT); | |
876 if (bold) | |
877 bold--; | |
878 break; | |
879 case 5: /* I */ | |
880 case 6: /* ITALIC */ | |
881 NEW_BIT (NEW_TEXT_BIT); | |
882 italics++; | |
883 break; | |
884 case 7: /* /I */ | |
885 case 8: /* /ITALIC */ | |
886 NEW_BIT (NEW_TEXT_BIT); | |
887 if (italics) | |
888 italics--; | |
889 break; | |
890 case 9: /* U */ | |
891 case 10: /* UNDERLINE */ | |
892 NEW_BIT (NEW_TEXT_BIT); | |
893 underline++; | |
894 break; | |
895 case 11: /* /U */ | |
896 case 12: /* /UNDERLINE */ | |
897 NEW_BIT (NEW_TEXT_BIT); | |
898 if (underline) | |
899 underline--; | |
900 break; | |
901 case 13: /* S */ | |
902 case 14: /* STRIKE */ | |
903 NEW_BIT (NEW_TEXT_BIT); | |
904 strike++; | |
905 break; | |
906 case 15: /* /S */ | |
907 case 16: /* /STRIKE */ | |
908 NEW_BIT (NEW_TEXT_BIT); | |
909 if (strike) | |
910 strike--; | |
911 break; | |
912 case 17: /* SUB */ | |
913 NEW_BIT (NEW_TEXT_BIT); | |
914 sub++; | |
915 break; | |
916 case 18: /* /SUB */ | |
917 NEW_BIT (NEW_TEXT_BIT); | |
918 if (sub) | |
919 sub--; | |
920 break; | |
921 case 19: /* SUP */ | |
922 NEW_BIT (NEW_TEXT_BIT); | |
923 sup++; | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
924 break; |
3922 | 925 case 20: /* /SUP */ |
926 NEW_BIT (NEW_TEXT_BIT); | |
927 if (sup) | |
928 sup--; | |
929 break; | |
930 case 21: /* PRE */ | |
931 NEW_BIT (NEW_TEXT_BIT); | |
932 pre++; | |
933 break; | |
934 case 22: /* /PRE */ | |
935 NEW_BIT (NEW_TEXT_BIT); | |
936 if (pre) | |
937 pre--; | |
938 break; | |
939 case 23: /* TITLE */ | |
940 NEW_BIT (NEW_TEXT_BIT); | |
941 title++; | |
942 break; | |
943 case 24: /* /TITLE */ | |
944 if (title) { | |
945 if (options & GTK_IMHTML_NO_TITLE) { | |
946 wpos = 0; | |
947 ws [wpos] = '\0'; | |
948 } | |
949 title--; | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
950 } |
3922 | 951 break; |
952 case 25: /* BR */ | |
953 ws[wpos] = '\n'; | |
954 wpos++; | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
955 NEW_BIT (NEW_TEXT_BIT); |
3922 | 956 break; |
957 case 26: /* HR */ | |
958 case 42: /* HR (opt) */ | |
959 ws[wpos++] = '\n'; | |
4895 | 960 scalable = gaim_hr_new(); |
961 NEW_BIT(NEW_SCALABLE_BIT); | |
4343 | 962 ws[wpos++] = '\n'; |
3922 | 963 break; |
964 case 27: /* /FONT */ | |
965 if (fonts) { | |
966 FontDetail *font = fonts->data; | |
967 NEW_BIT (NEW_TEXT_BIT); | |
968 fonts = g_slist_remove (fonts, font); | |
969 if (font->face) | |
970 g_free (font->face); | |
971 if (font->fore) | |
972 g_free (font->fore); | |
973 if (font->back) | |
974 g_free (font->back); | |
4032 | 975 if (font->sml) |
976 g_free (font->sml); | |
3922 | 977 g_free (font); |
978 } | |
979 break; | |
980 case 28: /* /A */ | |
981 if (url) { | |
982 NEW_BIT(NEW_TEXT_BIT); | |
983 g_free(url); | |
984 url = NULL; | |
2993 | 985 break; |
986 } | |
3922 | 987 case 29: /* P */ |
988 case 30: /* /P */ | |
989 case 31: /* H3 */ | |
990 case 32: /* /H3 */ | |
991 case 33: /* HTML */ | |
992 case 34: /* /HTML */ | |
993 case 35: /* BODY */ | |
994 case 36: /* /BODY */ | |
995 case 37: /* FONT */ | |
996 case 38: /* HEAD */ | |
997 case 39: /* /HEAD */ | |
998 break; | |
999 case 40: /* BINARY */ | |
4895 | 1000 NEW_BIT (NEW_TEXT_BIT); |
1001 break; | |
3922 | 1002 case 41: /* /BINARY */ |
1003 break; | |
1004 case 43: /* FONT (opt) */ | |
1005 { | |
4032 | 1006 gchar *color, *back, *face, *size, *sml; |
3922 | 1007 FontDetail *font, *oldfont = NULL; |
1008 color = gtk_imhtml_get_html_opt (tag, "COLOR="); | |
1009 back = gtk_imhtml_get_html_opt (tag, "BACK="); | |
1010 face = gtk_imhtml_get_html_opt (tag, "FACE="); | |
1011 size = gtk_imhtml_get_html_opt (tag, "SIZE="); | |
4032 | 1012 sml = gtk_imhtml_get_html_opt (tag, "SML="); |
1013 if (!(color || back || face || size || sml)) | |
3922 | 1014 break; |
1015 | |
1016 NEW_BIT (NEW_TEXT_BIT); | |
1017 | |
1018 font = g_new0 (FontDetail, 1); | |
1019 if (fonts) | |
1020 oldfont = fonts->data; | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1021 |
3922 | 1022 if (color && !(options & GTK_IMHTML_NO_COLOURS)) |
1023 font->fore = color; | |
1024 else if (oldfont && oldfont->fore) | |
1025 font->fore = g_strdup(oldfont->fore); | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1026 |
3922 | 1027 if (back && !(options & GTK_IMHTML_NO_COLOURS)) |
1028 font->back = back; | |
1029 else if (oldfont && oldfont->back) | |
1030 font->back = g_strdup(oldfont->back); | |
1031 | |
1032 if (face && !(options & GTK_IMHTML_NO_FONTS)) | |
1033 font->face = face; | |
1034 else if (oldfont && oldfont->face) | |
1035 font->face = g_strdup(oldfont->face); | |
4629 | 1036 if (font->face && (atoi(font->face) > 100)) { |
1037 g_free(font->face); | |
1038 font->face = g_strdup("100"); | |
1039 } | |
4032 | 1040 |
1041 if (sml) | |
1042 font->sml = sml; | |
1043 else if (oldfont && oldfont->sml) | |
1044 font->sml = g_strdup(oldfont->sml); | |
1045 | |
3922 | 1046 if (size && !(options & GTK_IMHTML_NO_SIZES)) { |
1047 if (*size == '+') { | |
1048 sscanf (size + 1, "%hd", &font->size); | |
1049 font->size += 3; | |
1050 } else if (*size == '-') { | |
1051 sscanf (size + 1, "%hd", &font->size); | |
1052 font->size = MAX (0, 3 - font->size); | |
1053 } else if (isdigit (*size)) { | |
1054 sscanf (size, "%hd", &font->size); | |
1055 } | |
1056 } else if (oldfont) | |
1057 font->size = oldfont->size; | |
1058 g_free(size); | |
1059 fonts = g_slist_prepend (fonts, font); | |
1060 } | |
1061 break; | |
1062 case 44: /* BODY (opt) */ | |
1063 if (!(options & GTK_IMHTML_NO_COLOURS)) { | |
1064 char *bgcolor = gtk_imhtml_get_html_opt (tag, "BGCOLOR="); | |
1065 if (bgcolor) { | |
1066 NEW_BIT(NEW_TEXT_BIT); | |
1067 if (bg) | |
1068 g_free(bg); | |
1069 bg = bgcolor; | |
2885
f72efa29c109
[gaim-migrate @ 2898]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2871
diff
changeset
|
1070 } |
1428 | 1071 } |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1072 break; |
3922 | 1073 case 45: /* A (opt) */ |
1074 { | |
1075 gchar *href = gtk_imhtml_get_html_opt (tag, "HREF="); | |
1076 if (href) { | |
1077 NEW_BIT (NEW_TEXT_BIT); | |
1078 if (url) | |
1079 g_free (url); | |
1080 url = href; | |
1081 } | |
2993 | 1082 } |
3922 | 1083 break; |
4895 | 1084 case 46: /* IMG (opt) */ |
1085 { | |
1086 gchar *src = gtk_imhtml_get_html_opt (tag, "SRC="); | |
1087 gchar *id = gtk_imhtml_get_html_opt (tag, "ID="); | |
1088 gchar *datasize = gtk_imhtml_get_html_opt (tag, "DATASIZE="); | |
1089 gint im_len = datasize?atoi(datasize):0; | |
1090 | |
1091 if (src && id && im_len && im_len <= len - pos) { | |
1092 /* This is an embedded IM image, or is it? */ | |
1093 char *tmp = NULL; | |
1094 const char *alltext; | |
1095 guchar *imagedata = NULL; | |
1096 | |
1097 GdkPixbufLoader *load; | |
1098 GdkPixbuf *imagepb = NULL; | |
1099 GError *error = NULL; | |
1100 | |
1101 tmp = g_strdup_printf("<DATA ID=\"%s\" SIZE=\"%s\">", id, datasize); | |
1102 alltext = strstr(c, tmp); | |
1103 imagedata = g_memdup(alltext + strlen(tmp), im_len); | |
1104 | |
1105 g_free(tmp); | |
1106 | |
1107 load = gdk_pixbuf_loader_new(); | |
1108 if (!gdk_pixbuf_loader_write(load, imagedata, im_len, &error)){ | |
1109 fprintf(stderr, "IM Image corrupted or unreadable.: %s\n", error->message); | |
1110 } else { | |
1111 imagepb = gdk_pixbuf_loader_get_pixbuf(load); | |
1112 if (imagepb) { | |
1113 scalable = gaim_im_image_new(imagepb); | |
1114 NEW_BIT(NEW_SCALABLE_BIT); | |
1115 } | |
1116 } | |
1117 | |
1118 gdk_pixbuf_loader_close(load, NULL); | |
1119 | |
1120 | |
1121 g_free(imagedata); | |
1122 g_free(id); | |
1123 g_free(datasize); | |
1124 g_free(src); | |
1125 | |
1126 break; | |
1127 } | |
1128 g_free(id); | |
1129 g_free(datasize); | |
1130 g_free(src); | |
1131 } | |
3922 | 1132 case 47: /* P (opt) */ |
1133 case 48: /* H3 (opt) */ | |
2993 | 1134 break; |
3922 | 1135 case 49: /* comment */ |
1136 NEW_BIT (NEW_TEXT_BIT); | |
4253 | 1137 if (imhtml->show_comments) |
1138 wpos = g_snprintf (ws, len, "%s", tag); | |
3922 | 1139 NEW_BIT (NEW_COMMENT_BIT); |
1140 break; | |
1141 default: | |
1142 break; | |
2993 | 1143 } |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1144 c += tlen; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1145 pos += tlen; |
4138 | 1146 if(tag) |
1147 g_free(tag); /* This was allocated back in VALID_TAG() */ | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1148 } else if (*c == '&' && gtk_imhtml_is_amp_escape (c, &, &tlen)) { |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1149 ws [wpos++] = amp; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1150 c += tlen; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1151 pos += tlen; |
1428 | 1152 } else if (*c == '\n') { |
1153 if (!(options & GTK_IMHTML_NO_NEWLINE)) { | |
3922 | 1154 ws[wpos] = '\n'; |
1155 wpos++; | |
1428 | 1156 NEW_BIT (NEW_TEXT_BIT); |
1157 } | |
1158 c++; | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1159 pos++; |
4253 | 1160 } else if (imhtml->show_smileys && (gtk_imhtml_is_smiley (imhtml, fonts, c, &smilelen) || gtk_imhtml_is_smiley(imhtml, NULL, c, &smilelen))) { |
4032 | 1161 FontDetail *fd; |
1162 gchar *sml = NULL; | |
1163 if (fonts) { | |
1164 fd = fonts->data; | |
1165 sml = fd->sml; | |
1166 } | |
1167 NEW_BIT (NEW_TEXT_BIT); | |
1168 wpos = g_snprintf (ws, smilelen + 1, "%s", c); | |
4263 | 1169 gtk_text_buffer_insert_pixbuf(imhtml->text_buffer, &iter, gtk_smiley_tree_image (imhtml, sml, ws)); |
4032 | 1170 c += smilelen; |
1171 pos += smilelen; | |
1172 wpos = 0; | |
1173 ws[0] = 0; | |
1174 } else if (*c) { | |
1428 | 1175 ws [wpos++] = *c++; |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1176 pos++; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1177 } else { |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1178 break; |
1428 | 1179 } |
1180 } | |
3922 | 1181 |
1182 NEW_BIT(NEW_TEXT_BIT); | |
1428 | 1183 if (url) { |
1184 g_free (url); | |
3922 | 1185 if (str) |
1186 str = g_string_append (str, "</A>"); | |
1428 | 1187 } |
3922 | 1188 |
4032 | 1189 while (fonts) { |
1190 FontDetail *font = fonts->data; | |
1191 fonts = g_slist_remove (fonts, font); | |
1192 if (font->face) | |
1193 g_free (font->face); | |
1194 if (font->fore) | |
1195 g_free (font->fore); | |
1196 if (font->back) | |
1197 g_free (font->back); | |
1198 if (font->sml) | |
1199 g_free (font->sml); | |
1200 g_free (font); | |
1201 if (str) | |
1202 str = g_string_append (str, "</FONT>"); | |
1203 } | |
1204 | |
3922 | 1205 if (str) { |
1428 | 1206 while (bold) { |
3922 | 1207 str = g_string_append (str, "</B>"); |
1428 | 1208 bold--; |
1209 } | |
1210 while (italics) { | |
3922 | 1211 str = g_string_append (str, "</I>"); |
1428 | 1212 italics--; |
1213 } | |
1214 while (underline) { | |
3922 | 1215 str = g_string_append (str, "</U>"); |
1428 | 1216 underline--; |
1217 } | |
1218 while (strike) { | |
3922 | 1219 str = g_string_append (str, "</S>"); |
1428 | 1220 strike--; |
1221 } | |
1222 while (sub) { | |
3922 | 1223 str = g_string_append (str, "</SUB>"); |
1428 | 1224 sub--; |
1225 } | |
1226 while (sup) { | |
3922 | 1227 str = g_string_append (str, "</SUP>"); |
1428 | 1228 sup--; |
1229 } | |
1230 while (title) { | |
3922 | 1231 str = g_string_append (str, "</TITLE>"); |
1428 | 1232 title--; |
1233 } | |
1691
d802b115800f
[gaim-migrate @ 1701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1647
diff
changeset
|
1234 while (pre) { |
3922 | 1235 str = g_string_append (str, "</PRE>"); |
1691
d802b115800f
[gaim-migrate @ 1701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1647
diff
changeset
|
1236 pre--; |
d802b115800f
[gaim-migrate @ 1701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1647
diff
changeset
|
1237 } |
1428 | 1238 } |
4032 | 1239 g_free (ws); |
4630 | 1240 if(bg) |
1241 g_free(bg); | |
4032 | 1242 if (!(options & GTK_IMHTML_NO_SCROLL)) |
1243 gtk_text_view_scroll_to_mark (GTK_TEXT_VIEW (imhtml), mark, | |
1244 0, TRUE, 0.0, 1.0); | |
3922 | 1245 gtk_text_buffer_delete_mark (imhtml->text_buffer, mark); |
1246 return str; | |
1247 } | |
1248 | |
4892 | 1249 void gtk_imhtml_remove_smileys(GtkIMHtml *imhtml) |
1250 { | |
4288 | 1251 g_hash_table_destroy(imhtml->smiley_data); |
1252 gtk_smiley_tree_destroy(imhtml->default_smilies); | |
4892 | 1253 imhtml->smiley_data = g_hash_table_new_full(g_str_hash, g_str_equal, |
4902 | 1254 g_free, (GDestroyNotify)gtk_smiley_tree_destroy); |
4288 | 1255 imhtml->default_smilies = gtk_smiley_tree_new(); |
1256 } | |
3922 | 1257 void gtk_imhtml_show_smileys (GtkIMHtml *imhtml, |
4253 | 1258 gboolean show) |
1259 { | |
1260 imhtml->show_smileys = show; | |
1261 } | |
3922 | 1262 |
1263 void gtk_imhtml_show_comments (GtkIMHtml *imhtml, | |
4253 | 1264 gboolean show) |
1265 { | |
1266 imhtml->show_comments = show; | |
1267 } | |
1780
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
1268 |
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
1269 void |
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
1270 gtk_imhtml_clear (GtkIMHtml *imhtml) |
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
1271 { |
3922 | 1272 GtkTextIter start, end; |
2993 | 1273 |
3922 | 1274 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start); |
1275 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end); | |
1276 gtk_text_buffer_delete(imhtml->text_buffer, &start, &end); | |
1780
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
1277 } |
2363
08c66712364c
[gaim-migrate @ 2376]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2349
diff
changeset
|
1278 |
4046 | 1279 void gtk_imhtml_page_up (GtkIMHtml *imhtml) |
1280 { | |
1281 | |
1282 } | |
3922 | 1283 void gtk_imhtml_page_down (GtkIMHtml *imhtml){} |
4735 | 1284 |
1285 static gint | |
1286 gtk_imhtml_tip_paint (GtkIMHtml *imhtml) | |
1287 { | |
1288 PangoLayout *layout; | |
1289 | |
1290 g_return_val_if_fail(GTK_IS_IMHTML(imhtml), FALSE); | |
1291 | |
1292 layout = gtk_widget_create_pango_layout(imhtml->tip_window, imhtml->tip); | |
1293 | |
1294 gtk_paint_flat_box (imhtml->tip_window->style, imhtml->tip_window->window, | |
1295 GTK_STATE_NORMAL, GTK_SHADOW_OUT, NULL, imhtml->tip_window, | |
1296 "tooltip", 0, 0, -1, -1); | |
1297 | |
1298 gtk_paint_layout (imhtml->tip_window->style, imhtml->tip_window->window, GTK_STATE_NORMAL, | |
1299 FALSE, NULL, imhtml->tip_window, NULL, 4, 4, layout); | |
1300 | |
4764 | 1301 g_object_unref(layout); |
4735 | 1302 return FALSE; |
1303 } | |
1304 | |
1305 static gint | |
1306 gtk_imhtml_tip (gpointer data) | |
1307 { | |
1308 GtkIMHtml *imhtml = data; | |
1309 PangoFontMetrics *font; | |
1310 PangoLayout *layout; | |
1311 | |
1312 gint gap, x, y, h, w, scr_w, baseline_skip; | |
1313 | |
1314 g_return_val_if_fail(GTK_IS_IMHTML(imhtml), FALSE); | |
1315 | |
1316 if (!imhtml->tip || !GTK_WIDGET_DRAWABLE (GTK_WIDGET(imhtml))) { | |
1317 imhtml->tip_timer = 0; | |
1318 return FALSE; | |
1319 } | |
1320 | |
1321 if (imhtml->tip_window){ | |
1322 gtk_widget_destroy (imhtml->tip_window); | |
1323 imhtml->tip_window = NULL; | |
1324 } | |
1325 | |
1326 imhtml->tip_timer = 0; | |
1327 imhtml->tip_window = gtk_window_new (GTK_WINDOW_POPUP); | |
1328 gtk_widget_set_app_paintable (imhtml->tip_window, TRUE); | |
1329 gtk_window_set_resizable (GTK_WINDOW (imhtml->tip_window), FALSE); | |
1330 gtk_widget_set_name (imhtml->tip_window, "gtk-tooltips"); | |
1331 g_signal_connect_swapped (G_OBJECT (imhtml->tip_window), "expose_event", | |
1332 G_CALLBACK (gtk_imhtml_tip_paint), imhtml); | |
1333 | |
1334 gtk_widget_ensure_style (imhtml->tip_window); | |
1335 layout = gtk_widget_create_pango_layout(imhtml->tip_window, imhtml->tip); | |
1336 font = pango_font_get_metrics(pango_context_load_font(pango_layout_get_context(layout), | |
1337 imhtml->tip_window->style->font_desc), | |
1338 NULL); | |
1339 | |
1340 | |
1341 pango_layout_get_pixel_size(layout, &scr_w, NULL); | |
1342 gap = PANGO_PIXELS((pango_font_metrics_get_ascent(font) + | |
1343 pango_font_metrics_get_descent(font))/ 4); | |
1344 | |
1345 if (gap < 2) | |
1346 gap = 2; | |
1347 baseline_skip = PANGO_PIXELS(pango_font_metrics_get_ascent(font) + | |
1348 pango_font_metrics_get_descent(font)); | |
1349 w = 8 + scr_w; | |
1350 h = 8 + baseline_skip; | |
1351 | |
1352 gdk_window_get_pointer (NULL, &x, &y, NULL); | |
1353 if (GTK_WIDGET_NO_WINDOW (GTK_WIDGET(imhtml))) | |
1354 y += GTK_WIDGET(imhtml)->allocation.y; | |
1355 | |
1356 scr_w = gdk_screen_width(); | |
1357 | |
1358 x -= ((w >> 1) + 4); | |
1359 | |
1360 if ((x + w) > scr_w) | |
1361 x -= (x + w) - scr_w; | |
1362 else if (x < 0) | |
1363 x = 0; | |
1364 | |
1365 y = y + PANGO_PIXELS(pango_font_metrics_get_ascent(font) + | |
1366 pango_font_metrics_get_descent(font)); | |
1367 | |
1368 gtk_widget_set_size_request (imhtml->tip_window, w, h); | |
1369 gtk_widget_show (imhtml->tip_window); | |
1370 gtk_window_move (GTK_WINDOW(imhtml->tip_window), x, y); | |
1371 | |
1372 pango_font_metrics_unref(font); | |
4895 | 1373 g_object_unref(layout); |
4735 | 1374 |
1375 return FALSE; | |
1376 } | |
4895 | 1377 |
1378 static gboolean gtk_size_allocate_cb(GtkWidget *widget, GtkAllocation *alloc, gpointer user_data) | |
1379 { | |
4903 | 1380 static GdkRectangle old_rect = {0,0,0,0}; |
1381 GdkRectangle rect; | |
4895 | 1382 |
4903 | 1383 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(widget), &rect); |
1384 | |
1385 if(old_rect.width && (old_rect.width != rect.width || old_rect.height != rect.height)){ | |
4902 | 1386 GList *iter = GTK_IMHTML(widget)->scalables; |
4895 | 1387 |
1388 while(iter){ | |
1389 GtkIMHtmlScalable *scale = GTK_IMHTML_SCALABLE(iter->data); | |
4903 | 1390 scale->scale(scale, rect.width, rect.height); |
4895 | 1391 |
1392 iter = iter->next; | |
1393 } | |
1394 } | |
1395 | |
4903 | 1396 old_rect = rect; |
4895 | 1397 return FALSE; |
1398 } | |
1399 | |
1400 /* GtkIMHtmlScalable, gaim_im_image, gaim_hr */ | |
1401 GtkIMHtmlScalable *gaim_im_image_new(GdkPixbuf *img) | |
1402 { | |
1403 gaim_im_image *im_image = g_malloc(sizeof(gaim_im_image)); | |
1404 | |
1405 GTK_IMHTML_SCALABLE(im_image)->scale = gaim_im_image_scale; | |
1406 GTK_IMHTML_SCALABLE(im_image)->add_to = gaim_im_image_add_to; | |
1407 GTK_IMHTML_SCALABLE(im_image)->free = gaim_im_image_free; | |
1408 im_image->image = img; | |
1409 im_image->width = gdk_pixbuf_get_width(img); | |
1410 im_image->height = gdk_pixbuf_get_height(img); | |
1411 im_image->imhtml = NULL; | |
1412 im_image->mark = NULL; | |
1413 | |
1414 return GTK_IMHTML_SCALABLE(im_image); | |
1415 } | |
1416 | |
1417 void gaim_im_image_scale(GtkIMHtmlScalable *scale, int width, int height) | |
1418 { | |
1419 gaim_im_image *image = (gaim_im_image *)scale; | |
1420 | |
1421 if(image->width > width || image->height > height){ | |
1422 GdkPixbuf *new_image = NULL; | |
1423 GtkTextIter start, end; | |
1424 float factor; | |
1425 int new_width = image->width, new_height = image->height; | |
1426 | |
1427 gtk_text_buffer_get_iter_at_mark(image->imhtml->text_buffer, &start, image->mark); | |
1428 end = start; | |
1429 gtk_text_iter_forward_char(&end); | |
1430 gtk_text_buffer_delete(image->imhtml->text_buffer, &start, &end); | |
1431 | |
1432 if(image->width > width){ | |
1433 factor = (float)(width)/image->width; | |
1434 new_width = width; | |
1435 new_height = image->height * factor; | |
1436 } | |
1437 if(new_height > height){ | |
1438 factor = (float)(height)/new_height; | |
1439 new_height = height; | |
1440 new_width = new_width * factor; | |
1441 } | |
1442 | |
1443 gtk_text_buffer_get_iter_at_mark(image->imhtml->text_buffer, &start, image->mark); | |
1444 new_image = gdk_pixbuf_scale_simple(image->image, new_width, new_height, GDK_INTERP_BILINEAR); | |
1445 gtk_text_buffer_insert_pixbuf(image->imhtml->text_buffer, &start, new_image); | |
1446 | |
1447 g_object_unref(G_OBJECT(new_image)); | |
1448 } | |
1449 } | |
1450 | |
1451 void gaim_im_image_free(GtkIMHtmlScalable *scale) | |
1452 { | |
1453 gaim_im_image *image = (gaim_im_image *)scale; | |
1454 | |
1455 g_object_unref(image->image); | |
1456 g_free(scale); | |
1457 } | |
1458 | |
1459 void gaim_im_image_add_to(GtkIMHtmlScalable *scale, GtkIMHtml *imhtml, GtkTextIter *iter) | |
1460 { | |
1461 gaim_im_image *image = (gaim_im_image *)scale; | |
1462 | |
1463 image->mark = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, iter, TRUE); | |
1464 gtk_text_buffer_insert_pixbuf(imhtml->text_buffer, iter, image->image); | |
1465 image->imhtml = imhtml; | |
1466 } | |
1467 | |
1468 GtkIMHtmlScalable *gaim_hr_new() | |
1469 { | |
1470 gaim_hr *hr = g_malloc(sizeof(gaim_hr)); | |
1471 | |
1472 GTK_IMHTML_SCALABLE(hr)->scale = gaim_hr_scale; | |
1473 GTK_IMHTML_SCALABLE(hr)->add_to = gaim_hr_add_to; | |
1474 GTK_IMHTML_SCALABLE(hr)->free = gaim_hr_free; | |
1475 | |
1476 hr->sep = gtk_hseparator_new(); | |
1477 gtk_widget_set_size_request(hr->sep, 5000, 2); | |
1478 gtk_widget_show(hr->sep); | |
1479 | |
1480 return GTK_IMHTML_SCALABLE(hr); | |
1481 } | |
1482 | |
1483 void gaim_hr_scale(GtkIMHtmlScalable *scale, int width, int height) | |
1484 { | |
4926 | 1485 /* FIXME: we need to figure out why this causes infinite looping |
4895 | 1486 gtk_widget_set_size_request(((gaim_hr *)scale)->sep, width, 2); |
4926 | 1487 */ |
4895 | 1488 } |
1489 | |
1490 void gaim_hr_add_to(GtkIMHtmlScalable *scale, GtkIMHtml *imhtml, GtkTextIter *iter) | |
1491 { | |
1492 gaim_hr *hr = (gaim_hr *)scale; | |
1493 GtkTextChildAnchor *anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, iter); | |
1494 | |
1495 gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(imhtml), hr->sep, anchor); | |
1496 } | |
1497 | |
1498 void gaim_hr_free(GtkIMHtmlScalable *scale) | |
1499 { | |
1500 /* gtk_widget_destroy(((gaim_hr *)scale)->sep); */ | |
1501 g_free(scale); | |
1502 } |