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