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