Mercurial > pidgin.yaz
annotate src/gtkimhtml.c @ 4567:493f050dc11a
[gaim-migrate @ 4848]
Robot101 made the Docklet menu the way the gaim-devel folks want it.
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Mon, 10 Feb 2003 04:44:54 +0000 |
parents | 2ea86ba4670b |
children | c05e6ecdc902 |
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> | |
4046 | 27 #include <gdk/gdkkeysyms.h> |
1428 | 28 #include <string.h> |
29 #include <ctype.h> | |
30 #include <stdio.h> | |
31 #include <math.h> | |
2541
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
32 #ifdef HAVE_LANGINFO_CODESET |
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
33 #include <langinfo.h> |
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
34 #include <locale.h> |
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
35 #endif |
1428 | 36 |
4417 | 37 #ifdef ENABLE_NLS |
38 # include <libintl.h> | |
39 # define _(x) gettext(x) | |
40 # ifdef gettext_noop | |
41 # define N_(String) gettext_noop (String) | |
42 # else | |
43 # define N_(String) (String) | |
44 # endif | |
45 #else | |
46 # define N_(String) (String) | |
47 # define _(x) (x) | |
48 #endif | |
49 | |
2349
60c716c32c40
[gaim-migrate @ 2362]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2348
diff
changeset
|
50 |
3922 | 51 /* POINT_SIZE converts from AIM font sizes to point sizes. It probably should be redone in such a |
52 * way that it base the sizes off the default font size rather than using arbitrary font sizes. */ | |
53 #define MAX_FONT_SIZE 7 | |
54 #define POINT_SIZE(x) (_point_sizes [MIN ((x), MAX_FONT_SIZE) - 1]) | |
3928 | 55 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
|
56 |
3922 | 57 /* The four elements present in a <FONT> tag contained in a struct */ |
58 typedef struct _FontDetail FontDetail; | |
1428 | 59 struct _FontDetail { |
60 gushort size; | |
61 gchar *face; | |
3922 | 62 gchar *fore; |
63 gchar *back; | |
4032 | 64 gchar *sml; |
1428 | 65 }; |
66 | |
4032 | 67 struct _GtkSmileyTree { |
68 GString *values; | |
69 GtkSmileyTree **children; | |
4263 | 70 GtkIMHtmlSmiley *image; |
4032 | 71 }; |
72 | |
73 static GtkSmileyTree* | |
74 gtk_smiley_tree_new () | |
75 { | |
76 return g_new0 (GtkSmileyTree, 1); | |
77 } | |
78 | |
79 static void | |
80 gtk_smiley_tree_insert (GtkSmileyTree *tree, | |
4263 | 81 GtkIMHtmlSmiley *smiley) |
4032 | 82 { |
83 GtkSmileyTree *t = tree; | |
4263 | 84 const gchar *x = smiley->smile; |
4032 | 85 |
86 if (!strlen (x)) | |
87 return; | |
88 | |
89 while (*x) { | |
90 gchar *pos; | |
91 gint index; | |
92 | |
93 if (!t->values) | |
94 t->values = g_string_new (""); | |
95 | |
96 pos = strchr (t->values->str, *x); | |
97 if (!pos) { | |
98 t->values = g_string_append_c (t->values, *x); | |
99 index = t->values->len - 1; | |
100 t->children = g_realloc (t->children, t->values->len * sizeof (GtkSmileyTree *)); | |
101 t->children [index] = g_new0 (GtkSmileyTree, 1); | |
102 } else | |
103 index = (int) pos - (int) t->values->str; | |
104 | |
105 t = t->children [index]; | |
106 | |
107 x++; | |
108 } | |
109 | |
4263 | 110 t->image = smiley; |
4032 | 111 } |
4041 | 112 |
4263 | 113 |
4264 | 114 void gtk_smiley_tree_destroy (GtkSmileyTree *tree) |
4032 | 115 { |
116 GSList *list = g_slist_append (NULL, tree); | |
117 | |
118 while (list) { | |
119 GtkSmileyTree *t = list->data; | |
120 gint i; | |
121 list = g_slist_remove(list, t); | |
122 if (t->values) { | |
123 for (i = 0; i < t->values->len; i++) | |
124 list = g_slist_append (list, t->children [i]); | |
125 g_string_free (t->values, TRUE); | |
126 g_free (t->children); | |
127 } | |
128 g_free (t); | |
129 } | |
130 } | |
131 | |
4263 | 132 |
4032 | 133 static GtkTextViewClass *parent_class = NULL; |
134 | |
135 | |
3922 | 136 /* GtkIMHtml has one signal--URL_CLICKED */ |
1428 | 137 enum { |
138 URL_CLICKED, | |
139 LAST_SIGNAL | |
140 }; | |
141 static guint signals [LAST_SIGNAL] = { 0 }; | |
142 | |
4264 | 143 static gboolean |
144 gtk_smiley_tree_destroy_from_hash(gpointer key, gpointer value, | |
145 gpointer user_data) | |
146 { | |
147 gtk_smiley_tree_destroy(value); | |
148 return TRUE; | |
149 } | |
150 | |
4032 | 151 static void |
152 gtk_imhtml_finalize (GObject *object) | |
153 { | |
154 GtkIMHtml *imhtml = GTK_IMHTML(object); | |
4264 | 155 g_hash_table_foreach_remove(imhtml->smiley_data, gtk_smiley_tree_destroy_from_hash, NULL); |
4138 | 156 g_hash_table_destroy(imhtml->smiley_data); |
4032 | 157 gtk_smiley_tree_destroy(imhtml->default_smilies); |
4138 | 158 gdk_cursor_unref(imhtml->hand_cursor); |
159 gdk_cursor_unref(imhtml->arrow_cursor); | |
4032 | 160 G_OBJECT_CLASS(parent_class)->finalize (object); |
161 } | |
1428 | 162 |
3922 | 163 /* Boring GTK stuff */ |
164 static void gtk_imhtml_class_init (GtkIMHtmlClass *class) | |
1428 | 165 { |
3922 | 166 GtkObjectClass *object_class; |
4032 | 167 GObjectClass *gobject_class; |
3922 | 168 object_class = (GtkObjectClass*) class; |
4032 | 169 gobject_class = (GObjectClass*) class; |
170 parent_class = gtk_type_class(GTK_TYPE_TEXT_VIEW); | |
4417 | 171 signals[URL_CLICKED] = g_signal_new("url_clicked", |
172 G_TYPE_FROM_CLASS(gobject_class), | |
173 G_SIGNAL_RUN_FIRST, | |
174 G_STRUCT_OFFSET(GtkIMHtmlClass, url_clicked), | |
175 NULL, | |
176 0, | |
177 g_cclosure_marshal_VOID__POINTER, | |
178 G_TYPE_NONE, 1, | |
179 G_TYPE_POINTER); | |
4032 | 180 gobject_class->finalize = gtk_imhtml_finalize; |
1428 | 181 } |
182 | |
3922 | 183 static void gtk_imhtml_init (GtkIMHtml *imhtml) |
1428 | 184 { |
3922 | 185 GtkTextIter iter; |
186 imhtml->text_buffer = gtk_text_buffer_new(NULL); | |
187 gtk_text_buffer_get_end_iter (imhtml->text_buffer, &iter); | |
188 imhtml->end = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, FALSE); | |
189 gtk_text_view_set_buffer(GTK_TEXT_VIEW(imhtml), imhtml->text_buffer); | |
190 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(imhtml), GTK_WRAP_WORD); | |
191 gtk_text_view_set_editable(GTK_TEXT_VIEW(imhtml), FALSE); | |
192 gtk_text_view_set_pixels_below_lines(GTK_TEXT_VIEW(imhtml), 5); | |
193 gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(imhtml), FALSE); | |
194 /*gtk_text_view_set_justification(GTK_TEXT_VIEW(imhtml), GTK_JUSTIFY_FILL);*/ | |
3465 | 195 |
3922 | 196 /* These tags will be used often and can be reused--we create them on init and then apply them by name |
197 * other tags (color, size, face, etc.) will have to be created and applied dynamically */ | |
198 gtk_text_buffer_create_tag(imhtml->text_buffer, "BOLD", "weight", PANGO_WEIGHT_BOLD, NULL); | |
199 gtk_text_buffer_create_tag(imhtml->text_buffer, "ITALICS", "style", PANGO_STYLE_ITALIC, NULL); | |
200 gtk_text_buffer_create_tag(imhtml->text_buffer, "UNDERLINE", "underline", PANGO_UNDERLINE_SINGLE, NULL); | |
201 gtk_text_buffer_create_tag(imhtml->text_buffer, "STRIKE", "strikethrough", TRUE, NULL); | |
202 gtk_text_buffer_create_tag(imhtml->text_buffer, "SUB", "rise", -5000, NULL); | |
203 gtk_text_buffer_create_tag(imhtml->text_buffer, "SUP", "rise", 5000, NULL); | |
204 gtk_text_buffer_create_tag(imhtml->text_buffer, "PRE", "family", "Monospace", NULL); | |
3465 | 205 |
3922 | 206 /* When hovering over a link, we show the hand cursor--elsewhere we show the plain ol' pointer cursor */ |
207 imhtml->hand_cursor = gdk_cursor_new (GDK_HAND2); | |
208 imhtml->arrow_cursor = gdk_cursor_new (GDK_LEFT_PTR); | |
2993 | 209 |
4253 | 210 imhtml->show_smileys = TRUE; |
211 imhtml->show_comments = TRUE; | |
212 | |
4032 | 213 imhtml->smiley_data = g_hash_table_new (g_str_hash, g_str_equal); |
214 imhtml->default_smilies = gtk_smiley_tree_new(); | |
2993 | 215 } |
216 | |
3922 | 217 GtkWidget *gtk_imhtml_new(void *a, void *b) |
1428 | 218 { |
3922 | 219 return GTK_WIDGET(gtk_type_new(gtk_imhtml_get_type())); |
1428 | 220 } |
221 | |
3922 | 222 GtkType gtk_imhtml_get_type() |
1428 | 223 { |
3922 | 224 static guint imhtml_type = 0; |
1428 | 225 |
226 if (!imhtml_type) { | |
3922 | 227 GtkTypeInfo imhtml_info = { |
1428 | 228 "GtkIMHtml", |
229 sizeof (GtkIMHtml), | |
230 sizeof (GtkIMHtmlClass), | |
231 (GtkClassInitFunc) gtk_imhtml_class_init, | |
232 (GtkObjectInitFunc) gtk_imhtml_init, | |
233 NULL, | |
234 NULL | |
235 }; | |
3922 | 236 |
237 imhtml_type = gtk_type_unique (gtk_text_view_get_type (), &imhtml_info); | |
1428 | 238 } |
239 | |
240 return imhtml_type; | |
241 } | |
242 | |
4417 | 243 struct url_data { |
244 GObject *object; | |
245 gchar *url; | |
246 }; | |
247 | |
248 static void url_open(GtkWidget *w, struct url_data *data) { | |
249 if(!data) return; | |
250 | |
251 g_signal_emit(data->object, signals[URL_CLICKED], 0, data->url); | |
252 | |
253 g_object_unref(data->object); | |
254 g_free(data->url); | |
255 g_free(data); | |
256 } | |
257 static void url_copy(GtkWidget *w, gchar *url) { | |
258 GtkClipboard *clipboard; | |
259 | |
4419 | 260 clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); |
4417 | 261 gtk_clipboard_set_text(clipboard, url, -1); |
262 } | |
263 | |
264 /* The callback for an event on a link tag. */ | |
265 gboolean tag_event(GtkTextTag *tag, GObject *arg1, GdkEvent *event, GtkTextIter *arg2, char *url) { | |
266 GdkEventButton *event_button = (GdkEventButton *) event; | |
267 | |
3922 | 268 if (event->type == GDK_BUTTON_RELEASE) { |
4417 | 269 if (event_button->button == 1) { |
270 GtkTextIter start, end; | |
271 /* we shouldn't open a URL if the user has selected something: */ | |
272 gtk_text_buffer_get_selection_bounds( | |
273 gtk_text_iter_get_buffer(arg2), &start, &end); | |
274 if(gtk_text_iter_get_offset(&start) != | |
275 gtk_text_iter_get_offset(&end)) | |
276 return FALSE; | |
277 | |
278 /* A link was clicked--we emit the "url_clicked" signal | |
279 * with the URL as the argument */ | |
280 g_signal_emit(arg1, signals[URL_CLICKED], 0, url); | |
281 return FALSE; | |
282 } else if(event_button->button == 3) { | |
283 GtkWidget *img, *item, *label, *menu; | |
284 struct url_data *tempdata = g_new(struct url_data, 1); | |
285 tempdata->object = g_object_ref(arg1); | |
286 tempdata->url = g_strdup(url); | |
287 | |
288 menu = gtk_menu_new(); | |
289 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, | |
290 event_button->button, event_button->time); | |
291 | |
292 /* URL of link, desensitized */ | |
293 item = gtk_menu_item_new(); | |
294 label = gtk_label_new(url); | |
295 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); | |
296 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT); | |
297 gtk_container_add(GTK_CONTAINER(item), label); | |
298 gtk_widget_set_sensitive(item, FALSE); | |
299 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); | |
300 | |
301 /* seperator */ | |
302 item = gtk_menu_item_new(); | |
303 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); | |
304 | |
305 /* buttons and such */ | |
306 img = gtk_image_new_from_stock(GTK_STOCK_COPY, GTK_ICON_SIZE_MENU); | |
4420 | 307 item = gtk_image_menu_item_new_with_mnemonic(_("_Copy Link Location")); |
4417 | 308 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), img); |
309 g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(url_copy), | |
310 url); | |
311 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); | |
312 | |
313 img = gtk_image_new_from_stock(GTK_STOCK_JUMP_TO, GTK_ICON_SIZE_MENU); | |
4420 | 314 item = gtk_image_menu_item_new_with_mnemonic(_("_Open Link in Browser")); |
4417 | 315 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), img); |
316 g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(url_open), | |
317 tempdata); | |
318 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); | |
319 gtk_widget_show_all(menu); | |
320 | |
321 return TRUE; | |
322 } | |
3922 | 323 } else if (event->type == GDK_ENTER_NOTIFY) { |
324 /* make a hand cursor and a tooltip timeout -- if GTK worked as it should */ | |
325 } else if (event->type == GDK_LEAVE_NOTIFY) { | |
326 /* clear timeout and make an arrow cursor again --if GTK worked as it should */ | |
1428 | 327 } |
4417 | 328 if(event->type == GDK_BUTTON_PRESS && event_button->button == 3) |
329 return TRUE; /* Clicking the right mouse button on a link shouldn't | |
330 be caught by the regular GtkTextView menu */ | |
331 else | |
332 return FALSE; /* Let clicks go through if we didn't catch anything */ | |
1428 | 333 } |
334 | |
4298 | 335 /* this isn't used yet |
4032 | 336 static void |
4263 | 337 gtk_smiley_tree_remove (GtkSmileyTree *tree, |
338 GtkIMHtmlSmiley *smiley) | |
4032 | 339 { |
340 GtkSmileyTree *t = tree; | |
4263 | 341 const gchar *x = smiley->smile; |
4032 | 342 gint len = 0; |
343 | |
344 while (*x) { | |
345 gchar *pos; | |
346 | |
347 if (!t->values) | |
348 return; | |
349 | |
350 pos = strchr (t->values->str, *x); | |
351 if (pos) | |
352 t = t->children [(int) pos - (int) t->values->str]; | |
353 else | |
354 return; | |
355 | |
356 x++; len++; | |
357 } | |
358 | |
4141
ccec4fde84f4
[gaim-migrate @ 4359]
Christian Hammond <chipx86@chipx86.com>
parents:
4140
diff
changeset
|
359 if (t->image) { |
4032 | 360 t->image = NULL; |
4141
ccec4fde84f4
[gaim-migrate @ 4359]
Christian Hammond <chipx86@chipx86.com>
parents:
4140
diff
changeset
|
361 } |
4032 | 362 } |
4298 | 363 */ |
364 | |
4032 | 365 |
366 static gint | |
367 gtk_smiley_tree_lookup (GtkSmileyTree *tree, | |
368 const gchar *text) | |
369 { | |
370 GtkSmileyTree *t = tree; | |
371 const gchar *x = text; | |
372 gint len = 0; | |
373 | |
374 while (*x) { | |
375 gchar *pos; | |
376 | |
377 if (!t->values) | |
378 break; | |
379 | |
380 pos = strchr (t->values->str, *x); | |
381 if (pos) | |
382 t = t->children [(int) pos - (int) t->values->str]; | |
383 else | |
384 break; | |
385 | |
386 x++; len++; | |
387 } | |
388 | |
389 if (t->image) | |
390 return len; | |
391 | |
392 return 0; | |
393 } | |
394 | |
395 void | |
4263 | 396 gtk_imhtml_associate_smiley (GtkIMHtml *imhtml, |
397 gchar *sml, | |
398 GtkIMHtmlSmiley *smiley) | |
4032 | 399 { |
400 GtkSmileyTree *tree; | |
401 g_return_if_fail (imhtml != NULL); | |
402 g_return_if_fail (GTK_IS_IMHTML (imhtml)); | |
4263 | 403 |
4032 | 404 if (sml == NULL) |
405 tree = imhtml->default_smilies; | |
406 else if ((tree = g_hash_table_lookup(imhtml->smiley_data, sml))) { | |
407 } else { | |
408 tree = gtk_smiley_tree_new(); | |
409 g_hash_table_insert(imhtml->smiley_data, sml, tree); | |
410 } | |
411 | |
4263 | 412 gtk_smiley_tree_insert (tree, smiley); |
4032 | 413 } |
414 | |
415 static gboolean | |
416 gtk_imhtml_is_smiley (GtkIMHtml *imhtml, | |
417 GSList *fonts, | |
418 const gchar *text, | |
419 gint *len) | |
420 { | |
421 GtkSmileyTree *tree; | |
422 FontDetail *font; | |
423 char *sml = NULL; | |
424 | |
425 if (fonts) { | |
426 font = fonts->data; | |
427 sml = font->sml; | |
428 } | |
429 | |
430 if (sml == NULL) | |
431 tree = imhtml->default_smilies; | |
432 else { | |
433 tree = g_hash_table_lookup(imhtml->smiley_data, sml); | |
434 } | |
435 if (tree == NULL) | |
436 return FALSE; | |
437 | |
438 *len = gtk_smiley_tree_lookup (tree, text); | |
439 return (*len > 0); | |
440 } | |
441 | |
4263 | 442 GdkPixbuf* |
4032 | 443 gtk_smiley_tree_image (GtkIMHtml *imhtml, |
444 const gchar *sml, | |
445 const gchar *text) | |
446 { | |
447 GtkSmileyTree *t; | |
448 const gchar *x = text; | |
449 if (sml == NULL) | |
450 t = imhtml->default_smilies; | |
451 else | |
452 t = g_hash_table_lookup(imhtml->smiley_data, sml); | |
453 | |
454 | |
455 if (t == NULL) | |
456 return sml ? gtk_smiley_tree_image(imhtml, NULL, text) : NULL; | |
457 | |
458 while (*x) { | |
459 gchar *pos; | |
460 | |
461 if (!t->values) { | |
462 return sml ? gtk_smiley_tree_image(imhtml, NULL, text) : NULL; | |
463 } | |
464 | |
465 pos = strchr (t->values->str, *x); | |
466 if (pos) { | |
467 t = t->children [(int) pos - (int) t->values->str]; | |
468 } else { | |
469 return sml ? gtk_smiley_tree_image(imhtml, NULL, text) : NULL; | |
470 } | |
471 x++; | |
472 } | |
473 | |
4263 | 474 if (!t->image->icon) |
475 t->image->icon = gdk_pixbuf_new_from_file(t->image->file, NULL); | |
476 | |
477 return t->image->icon; | |
4032 | 478 } |
3922 | 479 #define VALID_TAG(x) if (!g_strncasecmp (string, x ">", strlen (x ">"))) { \ |
480 *tag = g_strndup (string, strlen (x)); \ | |
481 *len = strlen (x) + 1; \ | |
482 return TRUE; \ | |
483 } \ | |
484 (*type)++ | |
1428 | 485 |
3922 | 486 #define VALID_OPT_TAG(x) if (!g_strncasecmp (string, x " ", strlen (x " "))) { \ |
487 const gchar *c = string + strlen (x " "); \ | |
488 gchar e = '"'; \ | |
489 gboolean quote = FALSE; \ | |
490 while (*c) { \ | |
491 if (*c == '"' || *c == '\'') { \ | |
492 if (quote && (*c == e)) \ | |
493 quote = !quote; \ | |
494 else if (!quote) { \ | |
495 quote = !quote; \ | |
496 e = *c; \ | |
497 } \ | |
498 } else if (!quote && (*c == '>')) \ | |
499 break; \ | |
500 c++; \ | |
501 } \ | |
502 if (*c) { \ | |
503 *tag = g_strndup (string, c - string); \ | |
504 *len = c - string + 1; \ | |
505 return TRUE; \ | |
506 } \ | |
507 } \ | |
508 (*type)++ | |
1428 | 509 |
510 | |
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
511 static gboolean |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
512 gtk_imhtml_is_amp_escape (const gchar *string, |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
513 gchar *replace, |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
514 gint *length) |
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
515 { |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
516 g_return_val_if_fail (string != NULL, FALSE); |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
517 g_return_val_if_fail (replace != NULL, FALSE); |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
518 g_return_val_if_fail (length != NULL, FALSE); |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
519 |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
520 if (!g_strncasecmp (string, "&", 5)) { |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
521 *replace = '&'; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
522 *length = 5; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
523 } else if (!g_strncasecmp (string, "<", 4)) { |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
524 *replace = '<'; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
525 *length = 4; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
526 } else if (!g_strncasecmp (string, ">", 4)) { |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
527 *replace = '>'; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
528 *length = 4; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
529 } else if (!g_strncasecmp (string, " ", 6)) { |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
530 *replace = ' '; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
531 *length = 6; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
532 } else if (!g_strncasecmp (string, "©", 6)) { |
3717
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3705
diff
changeset
|
533 *replace = '©'; /* was: '©' */ |
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
534 *length = 6; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
535 } else if (!g_strncasecmp (string, """, 6)) { |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
536 *replace = '\"'; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
537 *length = 6; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
538 } else if (!g_strncasecmp (string, "®", 5)) { |
3717
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3705
diff
changeset
|
539 *replace = '®'; /* was: '®' */ |
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
540 *length = 5; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
541 } else if (*(string + 1) == '#') { |
2022
199ba82faacb
[gaim-migrate @ 2032]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2002
diff
changeset
|
542 guint pound = 0; |
3004 | 543 if ((sscanf (string, "&#%u;", £) == 1) && pound != 0) { |
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
544 if (*(string + 3 + (gint)log10 (pound)) != ';') |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
545 return FALSE; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
546 *replace = (gchar)pound; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
547 *length = 2; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
548 while (isdigit ((gint) string [*length])) (*length)++; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
549 if (string [*length] == ';') (*length)++; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
550 } else { |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
551 return FALSE; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
552 } |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
553 } else { |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
554 return FALSE; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
555 } |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
556 |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
557 return TRUE; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
558 } |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
559 |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
560 static gboolean |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
561 gtk_imhtml_is_tag (const gchar *string, |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
562 gchar **tag, |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
563 gint *len, |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
564 gint *type) |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
565 { |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
566 *type = 1; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
567 |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
568 if (!strchr (string, '>')) |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
569 return FALSE; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
570 |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
571 VALID_TAG ("B"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
572 VALID_TAG ("BOLD"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
573 VALID_TAG ("/B"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
574 VALID_TAG ("/BOLD"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
575 VALID_TAG ("I"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
576 VALID_TAG ("ITALIC"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
577 VALID_TAG ("/I"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
578 VALID_TAG ("/ITALIC"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
579 VALID_TAG ("U"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
580 VALID_TAG ("UNDERLINE"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
581 VALID_TAG ("/U"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
582 VALID_TAG ("/UNDERLINE"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
583 VALID_TAG ("S"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
584 VALID_TAG ("STRIKE"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
585 VALID_TAG ("/S"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
586 VALID_TAG ("/STRIKE"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
587 VALID_TAG ("SUB"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
588 VALID_TAG ("/SUB"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
589 VALID_TAG ("SUP"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
590 VALID_TAG ("/SUP"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
591 VALID_TAG ("PRE"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
592 VALID_TAG ("/PRE"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
593 VALID_TAG ("TITLE"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
594 VALID_TAG ("/TITLE"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
595 VALID_TAG ("BR"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
596 VALID_TAG ("HR"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
597 VALID_TAG ("/FONT"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
598 VALID_TAG ("/A"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
599 VALID_TAG ("P"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
600 VALID_TAG ("/P"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
601 VALID_TAG ("H3"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
602 VALID_TAG ("/H3"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
603 VALID_TAG ("HTML"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
604 VALID_TAG ("/HTML"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
605 VALID_TAG ("BODY"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
606 VALID_TAG ("/BODY"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
607 VALID_TAG ("FONT"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
608 VALID_TAG ("HEAD"); |
2993 | 609 VALID_TAG ("/HEAD"); |
610 VALID_TAG ("BINARY"); | |
611 VALID_TAG ("/BINARY"); | |
612 | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
613 VALID_OPT_TAG ("HR"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
614 VALID_OPT_TAG ("FONT"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
615 VALID_OPT_TAG ("BODY"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
616 VALID_OPT_TAG ("A"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
617 VALID_OPT_TAG ("IMG"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
618 VALID_OPT_TAG ("P"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
619 VALID_OPT_TAG ("H3"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
620 |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
621 if (!g_strncasecmp(string, "!--", strlen ("!--"))) { |
2954
f6c4f2187c08
[gaim-migrate @ 2967]
Christian Hammond <chipx86@chipx86.com>
parents:
2898
diff
changeset
|
622 gchar *e = strstr (string + strlen("!--"), "-->"); |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
623 if (e) { |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
624 *len = e - string + strlen ("-->"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
625 *tag = g_strndup (string + strlen ("!--"), *len - strlen ("!---->")); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
626 return TRUE; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
627 } |
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 |
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 |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
633 static gchar* |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
634 gtk_imhtml_get_html_opt (gchar *tag, |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
635 const gchar *opt) |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
636 { |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
637 gchar *t = tag; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
638 gchar *e, *a; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
639 |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
640 while (g_strncasecmp (t, opt, strlen (opt))) { |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
641 gboolean quote = FALSE; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
642 if (*t == '\0') break; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
643 while (*t && !((*t == ' ') && !quote)) { |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
644 if (*t == '\"') |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
645 quote = ! quote; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
646 t++; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
647 } |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
648 while (*t && (*t == ' ')) t++; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
649 } |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
650 |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
651 if (!g_strncasecmp (t, opt, strlen (opt))) { |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
652 t += strlen (opt); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
653 } else { |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
654 return NULL; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
655 } |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
656 |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
657 if ((*t == '\"') || (*t == '\'')) { |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
658 e = a = ++t; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
659 while (*e && (*e != *(t - 1))) e++; |
2993 | 660 if (*e == '\0') { |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
661 return NULL; |
2993 | 662 } else |
663 return g_strndup (a, e - a); | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
664 } else { |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
665 e = a = t; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
666 while (*e && !isspace ((gint) *e)) e++; |
2993 | 667 return g_strndup (a, e - a); |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
668 } |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
669 } |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
670 |
3922 | 671 |
672 | |
673 #define NEW_TEXT_BIT 0 | |
674 #define NEW_HR_BIT 1 | |
4343 | 675 #define NEW_COMMENT_BIT 2 |
3922 | 676 #define NEW_BIT(x) ws [wpos] = '\0'; \ |
677 mark2 = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); \ | |
678 gtk_text_buffer_insert(imhtml->text_buffer, &iter, ws, -1); \ | |
679 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &iter); \ | |
680 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &siter, mark2); \ | |
681 gtk_text_buffer_delete_mark(imhtml->text_buffer, mark2); \ | |
682 if (bold) \ | |
683 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "BOLD", &siter, &iter); \ | |
684 if (italics) \ | |
685 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "ITALICS", &siter, &iter); \ | |
686 if (underline) \ | |
687 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "UNDERLINE", &siter, &iter); \ | |
688 if (strike) \ | |
689 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "STRIKE", &siter, &iter); \ | |
690 if (sub) \ | |
691 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "SUB", &siter, &iter); \ | |
692 if (sup) \ | |
693 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "SUP", &siter, &iter); \ | |
694 if (pre) \ | |
695 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "PRE", &siter, &iter); \ | |
696 if (bg) { \ | |
697 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "background", bg, NULL); \ | |
698 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &siter, &iter); \ | |
699 } \ | |
700 if (fonts) { \ | |
701 FontDetail *fd = fonts->data; \ | |
702 if (fd->fore) { \ | |
703 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "foreground", fd->fore, NULL); \ | |
704 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &siter, &iter); \ | |
705 } \ | |
706 if (fd->back) { \ | |
707 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "background", fd->back, NULL); \ | |
708 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &siter, &iter); \ | |
709 } \ | |
710 if (fd->face) { \ | |
711 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "font", fd->face, NULL); \ | |
712 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &siter, &iter); \ | |
713 } \ | |
714 if (fd->size) { \ | |
715 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "size-points", (double)POINT_SIZE(fd->size), NULL); \ | |
716 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &siter, &iter); \ | |
717 } \ | |
718 } \ | |
719 if (url) { \ | |
720 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "foreground", "blue", "underline", PANGO_UNDERLINE_SINGLE, NULL); \ | |
721 g_signal_connect(G_OBJECT(texttag), "event", G_CALLBACK(tag_event), strdup(url)); \ | |
722 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &siter, &iter); \ | |
723 } \ | |
724 wpos = 0; \ | |
725 ws[0] = 0; \ | |
726 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &iter); \ | |
4343 | 727 if (x == NEW_HR_BIT) { \ |
728 GtkTextChildAnchor *anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, &iter); \ | |
729 GtkWidget *sep = gtk_hseparator_new(); \ | |
4477 | 730 GdkRectangle rect; \ |
731 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); \ | |
732 gtk_widget_set_size_request(GTK_WIDGET(sep), rect.width, 2); \ | |
3922 | 733 gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(imhtml), sep, anchor); \ |
734 gtk_widget_show(sep); \ | |
4343 | 735 } \ |
3922 | 736 |
737 GString* gtk_imhtml_append_text (GtkIMHtml *imhtml, | |
738 const gchar *text, | |
739 gint len, | |
740 GtkIMHtmlOptions options) | |
1428 | 741 { |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
742 gint pos = 0; |
3922 | 743 GString *str = NULL; |
744 GtkTextIter iter, siter; | |
745 GtkTextMark *mark, *mark2; | |
746 GtkTextTag *texttag; | |
747 gchar *ws; | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
748 gchar *tag; |
3922 | 749 gchar *url = NULL; |
750 gchar *bg = NULL; | |
4032 | 751 gint tlen, smilelen, wpos=0; |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
752 gint type; |
3922 | 753 const gchar *c; |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
754 gchar amp; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
755 |
1428 | 756 guint bold = 0, |
757 italics = 0, | |
758 underline = 0, | |
759 strike = 0, | |
760 sub = 0, | |
761 sup = 0, | |
1691
d802b115800f
[gaim-migrate @ 1701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1647
diff
changeset
|
762 title = 0, |
3922 | 763 pre = 0; |
1428 | 764 |
3922 | 765 GSList *fonts = NULL; |
1428 | 766 |
767 g_return_val_if_fail (imhtml != NULL, NULL); | |
768 g_return_val_if_fail (GTK_IS_IMHTML (imhtml), NULL); | |
769 g_return_val_if_fail (text != NULL, NULL); | |
3922 | 770 g_return_val_if_fail (len != 0, NULL); |
771 | |
772 c = text; | |
773 if (len == -1) | |
774 len = strlen(text); | |
775 ws = g_malloc(len + 1); | |
776 ws[0] = 0; | |
1428 | 777 |
778 if (options & GTK_IMHTML_RETURN_LOG) | |
3922 | 779 str = g_string_new(""); |
1428 | 780 |
3922 | 781 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &iter); |
782 mark = gtk_text_buffer_create_mark (imhtml->text_buffer, NULL, &iter, /* right grav */ FALSE); | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
783 while (pos < len) { |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
784 if (*c == '<' && gtk_imhtml_is_tag (c + 1, &tag, &tlen, &type)) { |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
785 c++; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
786 pos++; |
3922 | 787 switch (type) |
788 { | |
789 case 1: /* B */ | |
790 case 2: /* BOLD */ | |
791 NEW_BIT (NEW_TEXT_BIT); | |
792 bold++; | |
793 break; | |
794 case 3: /* /B */ | |
795 case 4: /* /BOLD */ | |
796 NEW_BIT (NEW_TEXT_BIT); | |
797 if (bold) | |
798 bold--; | |
799 break; | |
800 case 5: /* I */ | |
801 case 6: /* ITALIC */ | |
802 NEW_BIT (NEW_TEXT_BIT); | |
803 italics++; | |
804 break; | |
805 case 7: /* /I */ | |
806 case 8: /* /ITALIC */ | |
807 NEW_BIT (NEW_TEXT_BIT); | |
808 if (italics) | |
809 italics--; | |
810 break; | |
811 case 9: /* U */ | |
812 case 10: /* UNDERLINE */ | |
813 NEW_BIT (NEW_TEXT_BIT); | |
814 underline++; | |
815 break; | |
816 case 11: /* /U */ | |
817 case 12: /* /UNDERLINE */ | |
818 NEW_BIT (NEW_TEXT_BIT); | |
819 if (underline) | |
820 underline--; | |
821 break; | |
822 case 13: /* S */ | |
823 case 14: /* STRIKE */ | |
824 NEW_BIT (NEW_TEXT_BIT); | |
825 strike++; | |
826 break; | |
827 case 15: /* /S */ | |
828 case 16: /* /STRIKE */ | |
829 NEW_BIT (NEW_TEXT_BIT); | |
830 if (strike) | |
831 strike--; | |
832 break; | |
833 case 17: /* SUB */ | |
834 NEW_BIT (NEW_TEXT_BIT); | |
835 sub++; | |
836 break; | |
837 case 18: /* /SUB */ | |
838 NEW_BIT (NEW_TEXT_BIT); | |
839 if (sub) | |
840 sub--; | |
841 break; | |
842 case 19: /* SUP */ | |
843 NEW_BIT (NEW_TEXT_BIT); | |
844 sup++; | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
845 break; |
3922 | 846 case 20: /* /SUP */ |
847 NEW_BIT (NEW_TEXT_BIT); | |
848 if (sup) | |
849 sup--; | |
850 break; | |
851 case 21: /* PRE */ | |
852 NEW_BIT (NEW_TEXT_BIT); | |
853 pre++; | |
854 break; | |
855 case 22: /* /PRE */ | |
856 NEW_BIT (NEW_TEXT_BIT); | |
857 if (pre) | |
858 pre--; | |
859 break; | |
860 case 23: /* TITLE */ | |
861 NEW_BIT (NEW_TEXT_BIT); | |
862 title++; | |
863 break; | |
864 case 24: /* /TITLE */ | |
865 if (title) { | |
866 if (options & GTK_IMHTML_NO_TITLE) { | |
867 wpos = 0; | |
868 ws [wpos] = '\0'; | |
869 } | |
870 title--; | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
871 } |
3922 | 872 break; |
873 case 25: /* BR */ | |
874 ws[wpos] = '\n'; | |
875 wpos++; | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
876 NEW_BIT (NEW_TEXT_BIT); |
3922 | 877 break; |
878 case 26: /* HR */ | |
879 case 42: /* HR (opt) */ | |
880 ws[wpos++] = '\n'; | |
881 NEW_BIT(NEW_HR_BIT); | |
4343 | 882 ws[wpos++] = '\n'; |
3922 | 883 break; |
884 case 27: /* /FONT */ | |
885 if (fonts) { | |
886 FontDetail *font = fonts->data; | |
887 NEW_BIT (NEW_TEXT_BIT); | |
888 fonts = g_slist_remove (fonts, font); | |
889 if (font->face) | |
890 g_free (font->face); | |
891 if (font->fore) | |
892 g_free (font->fore); | |
893 if (font->back) | |
894 g_free (font->back); | |
4032 | 895 if (font->sml) |
896 g_free (font->sml); | |
3922 | 897 g_free (font); |
898 } | |
899 break; | |
900 case 28: /* /A */ | |
901 if (url) { | |
902 NEW_BIT(NEW_TEXT_BIT); | |
903 g_free(url); | |
904 url = NULL; | |
2993 | 905 break; |
906 } | |
3922 | 907 case 29: /* P */ |
908 case 30: /* /P */ | |
909 case 31: /* H3 */ | |
910 case 32: /* /H3 */ | |
911 case 33: /* HTML */ | |
912 case 34: /* /HTML */ | |
913 case 35: /* BODY */ | |
914 case 36: /* /BODY */ | |
915 case 37: /* FONT */ | |
916 case 38: /* HEAD */ | |
917 case 39: /* /HEAD */ | |
918 break; | |
919 case 40: /* BINARY */ | |
920 case 41: /* /BINARY */ | |
921 break; | |
922 case 43: /* FONT (opt) */ | |
923 { | |
4032 | 924 gchar *color, *back, *face, *size, *sml; |
3922 | 925 FontDetail *font, *oldfont = NULL; |
926 color = gtk_imhtml_get_html_opt (tag, "COLOR="); | |
927 back = gtk_imhtml_get_html_opt (tag, "BACK="); | |
928 face = gtk_imhtml_get_html_opt (tag, "FACE="); | |
929 size = gtk_imhtml_get_html_opt (tag, "SIZE="); | |
4032 | 930 sml = gtk_imhtml_get_html_opt (tag, "SML="); |
931 if (!(color || back || face || size || sml)) | |
3922 | 932 break; |
933 | |
934 NEW_BIT (NEW_TEXT_BIT); | |
935 | |
936 font = g_new0 (FontDetail, 1); | |
937 if (fonts) | |
938 oldfont = fonts->data; | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
939 |
3922 | 940 if (color && !(options & GTK_IMHTML_NO_COLOURS)) |
941 font->fore = color; | |
942 else if (oldfont && oldfont->fore) | |
943 font->fore = g_strdup(oldfont->fore); | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
944 |
3922 | 945 if (back && !(options & GTK_IMHTML_NO_COLOURS)) |
946 font->back = back; | |
947 else if (oldfont && oldfont->back) | |
948 font->back = g_strdup(oldfont->back); | |
949 | |
950 if (face && !(options & GTK_IMHTML_NO_FONTS)) | |
951 font->face = face; | |
952 else if (oldfont && oldfont->face) | |
953 font->face = g_strdup(oldfont->face); | |
4032 | 954 |
955 if (sml) | |
956 font->sml = sml; | |
957 else if (oldfont && oldfont->sml) | |
958 font->sml = g_strdup(oldfont->sml); | |
959 | |
3922 | 960 if (size && !(options & GTK_IMHTML_NO_SIZES)) { |
961 if (*size == '+') { | |
962 sscanf (size + 1, "%hd", &font->size); | |
963 font->size += 3; | |
964 } else if (*size == '-') { | |
965 sscanf (size + 1, "%hd", &font->size); | |
966 font->size = MAX (0, 3 - font->size); | |
967 } else if (isdigit (*size)) { | |
968 sscanf (size, "%hd", &font->size); | |
969 } | |
970 } else if (oldfont) | |
971 font->size = oldfont->size; | |
972 g_free(size); | |
973 fonts = g_slist_prepend (fonts, font); | |
974 } | |
975 break; | |
976 case 44: /* BODY (opt) */ | |
977 if (!(options & GTK_IMHTML_NO_COLOURS)) { | |
978 char *bgcolor = gtk_imhtml_get_html_opt (tag, "BGCOLOR="); | |
979 if (bgcolor) { | |
980 NEW_BIT(NEW_TEXT_BIT); | |
981 if (bg) | |
982 g_free(bg); | |
983 bg = bgcolor; | |
2885
f72efa29c109
[gaim-migrate @ 2898]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2871
diff
changeset
|
984 } |
1428 | 985 } |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
986 break; |
3922 | 987 case 45: /* A (opt) */ |
988 { | |
989 gchar *href = gtk_imhtml_get_html_opt (tag, "HREF="); | |
990 if (href) { | |
991 NEW_BIT (NEW_TEXT_BIT); | |
992 if (url) | |
993 g_free (url); | |
994 url = href; | |
995 } | |
2993 | 996 } |
3922 | 997 break; |
998 case 47: /* P (opt) */ | |
999 case 48: /* H3 (opt) */ | |
2993 | 1000 break; |
3922 | 1001 case 49: /* comment */ |
1002 NEW_BIT (NEW_TEXT_BIT); | |
4253 | 1003 if (imhtml->show_comments) |
1004 wpos = g_snprintf (ws, len, "%s", tag); | |
3922 | 1005 NEW_BIT (NEW_COMMENT_BIT); |
1006 break; | |
1007 default: | |
1008 break; | |
2993 | 1009 } |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1010 c += tlen; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1011 pos += tlen; |
4138 | 1012 if(tag) |
1013 g_free(tag); /* This was allocated back in VALID_TAG() */ | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1014 } else if (*c == '&' && gtk_imhtml_is_amp_escape (c, &, &tlen)) { |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1015 ws [wpos++] = amp; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1016 c += tlen; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1017 pos += tlen; |
1428 | 1018 } else if (*c == '\n') { |
1019 if (!(options & GTK_IMHTML_NO_NEWLINE)) { | |
3922 | 1020 ws[wpos] = '\n'; |
1021 wpos++; | |
1428 | 1022 NEW_BIT (NEW_TEXT_BIT); |
1023 } | |
1024 c++; | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1025 pos++; |
4253 | 1026 } else if (imhtml->show_smileys && (gtk_imhtml_is_smiley (imhtml, fonts, c, &smilelen) || gtk_imhtml_is_smiley(imhtml, NULL, c, &smilelen))) { |
4032 | 1027 FontDetail *fd; |
1028 gchar *sml = NULL; | |
1029 if (fonts) { | |
1030 fd = fonts->data; | |
1031 sml = fd->sml; | |
1032 } | |
1033 NEW_BIT (NEW_TEXT_BIT); | |
1034 wpos = g_snprintf (ws, smilelen + 1, "%s", c); | |
4263 | 1035 gtk_text_buffer_insert_pixbuf(imhtml->text_buffer, &iter, gtk_smiley_tree_image (imhtml, sml, ws)); |
4032 | 1036 c += smilelen; |
1037 pos += smilelen; | |
1038 wpos = 0; | |
1039 ws[0] = 0; | |
1040 } else if (*c) { | |
1428 | 1041 ws [wpos++] = *c++; |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1042 pos++; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1043 } else { |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1044 break; |
1428 | 1045 } |
1046 } | |
3922 | 1047 |
1048 NEW_BIT(NEW_TEXT_BIT); | |
1428 | 1049 if (url) { |
1050 g_free (url); | |
3922 | 1051 if (str) |
1052 str = g_string_append (str, "</A>"); | |
1428 | 1053 } |
3922 | 1054 |
4032 | 1055 while (fonts) { |
1056 FontDetail *font = fonts->data; | |
1057 fonts = g_slist_remove (fonts, font); | |
1058 if (font->face) | |
1059 g_free (font->face); | |
1060 if (font->fore) | |
1061 g_free (font->fore); | |
1062 if (font->back) | |
1063 g_free (font->back); | |
1064 if (font->sml) | |
1065 g_free (font->sml); | |
1066 g_free (font); | |
1067 if (str) | |
1068 str = g_string_append (str, "</FONT>"); | |
1069 } | |
1070 | |
3922 | 1071 if (str) { |
1428 | 1072 while (bold) { |
3922 | 1073 str = g_string_append (str, "</B>"); |
1428 | 1074 bold--; |
1075 } | |
1076 while (italics) { | |
3922 | 1077 str = g_string_append (str, "</I>"); |
1428 | 1078 italics--; |
1079 } | |
1080 while (underline) { | |
3922 | 1081 str = g_string_append (str, "</U>"); |
1428 | 1082 underline--; |
1083 } | |
1084 while (strike) { | |
3922 | 1085 str = g_string_append (str, "</S>"); |
1428 | 1086 strike--; |
1087 } | |
1088 while (sub) { | |
3922 | 1089 str = g_string_append (str, "</SUB>"); |
1428 | 1090 sub--; |
1091 } | |
1092 while (sup) { | |
3922 | 1093 str = g_string_append (str, "</SUP>"); |
1428 | 1094 sup--; |
1095 } | |
1096 while (title) { | |
3922 | 1097 str = g_string_append (str, "</TITLE>"); |
1428 | 1098 title--; |
1099 } | |
1691
d802b115800f
[gaim-migrate @ 1701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1647
diff
changeset
|
1100 while (pre) { |
3922 | 1101 str = g_string_append (str, "</PRE>"); |
1691
d802b115800f
[gaim-migrate @ 1701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1647
diff
changeset
|
1102 pre--; |
d802b115800f
[gaim-migrate @ 1701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1647
diff
changeset
|
1103 } |
1428 | 1104 } |
4032 | 1105 g_free (ws); |
1106 if (!(options & GTK_IMHTML_NO_SCROLL)) | |
1107 gtk_text_view_scroll_to_mark (GTK_TEXT_VIEW (imhtml), mark, | |
1108 0, TRUE, 0.0, 1.0); | |
3922 | 1109 gtk_text_buffer_delete_mark (imhtml->text_buffer, mark); |
1110 return str; | |
1111 } | |
1112 | |
4288 | 1113 void gtk_imhtml_remove_smileys(GtkIMHtml *imhtml) |
1114 { | |
1115 g_hash_table_destroy(imhtml->smiley_data); | |
1116 gtk_smiley_tree_destroy(imhtml->default_smilies); | |
1117 imhtml->smiley_data = g_hash_table_new (g_str_hash, g_str_equal); | |
1118 imhtml->default_smilies = gtk_smiley_tree_new(); | |
1119 } | |
3922 | 1120 void gtk_imhtml_show_smileys (GtkIMHtml *imhtml, |
4253 | 1121 gboolean show) |
1122 { | |
1123 imhtml->show_smileys = show; | |
1124 } | |
3922 | 1125 |
1126 void gtk_imhtml_show_comments (GtkIMHtml *imhtml, | |
4253 | 1127 gboolean show) |
1128 { | |
1129 imhtml->show_comments = show; | |
1130 } | |
1780
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
1131 |
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
1132 void |
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
1133 gtk_imhtml_clear (GtkIMHtml *imhtml) |
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
1134 { |
3922 | 1135 GtkTextIter start, end; |
2993 | 1136 |
3922 | 1137 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start); |
1138 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end); | |
1139 gtk_text_buffer_delete(imhtml->text_buffer, &start, &end); | |
1780
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
1140 } |
2363
08c66712364c
[gaim-migrate @ 2376]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2349
diff
changeset
|
1141 |
4046 | 1142 void gtk_imhtml_page_up (GtkIMHtml *imhtml) |
1143 { | |
1144 | |
1145 } | |
3922 | 1146 void gtk_imhtml_page_down (GtkIMHtml *imhtml){} |