Mercurial > pidgin
annotate src/gtkimhtml.c @ 4420:64d845f2a0fb
[gaim-migrate @ 4693]
accessibility.
committer: Tailor Script <tailor@pidgin.im>
| author | Sean Egan <seanegan@gmail.com> |
|---|---|
| date | Sun, 26 Jan 2003 04:23:20 +0000 |
| parents | 5ddb461d8961 |
| children | 2ea86ba4670b |
| 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(); \ | |
| 730 gtk_widget_set_size_request(GTK_WIDGET(sep), 5000, 2); \ | |
| 3922 | 731 gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(imhtml), sep, anchor); \ |
| 732 gtk_widget_show(sep); \ | |
| 4343 | 733 } \ |
| 3922 | 734 |
| 735 GString* gtk_imhtml_append_text (GtkIMHtml *imhtml, | |
| 736 const gchar *text, | |
| 737 gint len, | |
| 738 GtkIMHtmlOptions options) | |
| 1428 | 739 { |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
740 gint pos = 0; |
| 3922 | 741 GString *str = NULL; |
| 742 GtkTextIter iter, siter; | |
| 743 GtkTextMark *mark, *mark2; | |
| 744 GtkTextTag *texttag; | |
| 745 gchar *ws; | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
746 gchar *tag; |
| 3922 | 747 gchar *url = NULL; |
| 748 gchar *bg = NULL; | |
| 4032 | 749 gint tlen, smilelen, wpos=0; |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
750 gint type; |
| 3922 | 751 const gchar *c; |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
752 gchar amp; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
753 |
| 1428 | 754 guint bold = 0, |
| 755 italics = 0, | |
| 756 underline = 0, | |
| 757 strike = 0, | |
| 758 sub = 0, | |
| 759 sup = 0, | |
|
1691
d802b115800f
[gaim-migrate @ 1701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1647
diff
changeset
|
760 title = 0, |
| 3922 | 761 pre = 0; |
| 1428 | 762 |
| 3922 | 763 GSList *fonts = NULL; |
| 1428 | 764 |
| 765 g_return_val_if_fail (imhtml != NULL, NULL); | |
| 766 g_return_val_if_fail (GTK_IS_IMHTML (imhtml), NULL); | |
| 767 g_return_val_if_fail (text != NULL, NULL); | |
| 3922 | 768 g_return_val_if_fail (len != 0, NULL); |
| 769 | |
| 770 c = text; | |
| 771 if (len == -1) | |
| 772 len = strlen(text); | |
| 773 ws = g_malloc(len + 1); | |
| 774 ws[0] = 0; | |
| 1428 | 775 |
| 776 if (options & GTK_IMHTML_RETURN_LOG) | |
| 3922 | 777 str = g_string_new(""); |
| 1428 | 778 |
| 3922 | 779 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &iter); |
| 780 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
|
781 while (pos < len) { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
782 if (*c == '<' && gtk_imhtml_is_tag (c + 1, &tag, &tlen, &type)) { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
783 c++; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
784 pos++; |
| 3922 | 785 switch (type) |
| 786 { | |
| 787 case 1: /* B */ | |
| 788 case 2: /* BOLD */ | |
| 789 NEW_BIT (NEW_TEXT_BIT); | |
| 790 bold++; | |
| 791 break; | |
| 792 case 3: /* /B */ | |
| 793 case 4: /* /BOLD */ | |
| 794 NEW_BIT (NEW_TEXT_BIT); | |
| 795 if (bold) | |
| 796 bold--; | |
| 797 break; | |
| 798 case 5: /* I */ | |
| 799 case 6: /* ITALIC */ | |
| 800 NEW_BIT (NEW_TEXT_BIT); | |
| 801 italics++; | |
| 802 break; | |
| 803 case 7: /* /I */ | |
| 804 case 8: /* /ITALIC */ | |
| 805 NEW_BIT (NEW_TEXT_BIT); | |
| 806 if (italics) | |
| 807 italics--; | |
| 808 break; | |
| 809 case 9: /* U */ | |
| 810 case 10: /* UNDERLINE */ | |
| 811 NEW_BIT (NEW_TEXT_BIT); | |
| 812 underline++; | |
| 813 break; | |
| 814 case 11: /* /U */ | |
| 815 case 12: /* /UNDERLINE */ | |
| 816 NEW_BIT (NEW_TEXT_BIT); | |
| 817 if (underline) | |
| 818 underline--; | |
| 819 break; | |
| 820 case 13: /* S */ | |
| 821 case 14: /* STRIKE */ | |
| 822 NEW_BIT (NEW_TEXT_BIT); | |
| 823 strike++; | |
| 824 break; | |
| 825 case 15: /* /S */ | |
| 826 case 16: /* /STRIKE */ | |
| 827 NEW_BIT (NEW_TEXT_BIT); | |
| 828 if (strike) | |
| 829 strike--; | |
| 830 break; | |
| 831 case 17: /* SUB */ | |
| 832 NEW_BIT (NEW_TEXT_BIT); | |
| 833 sub++; | |
| 834 break; | |
| 835 case 18: /* /SUB */ | |
| 836 NEW_BIT (NEW_TEXT_BIT); | |
| 837 if (sub) | |
| 838 sub--; | |
| 839 break; | |
| 840 case 19: /* SUP */ | |
| 841 NEW_BIT (NEW_TEXT_BIT); | |
| 842 sup++; | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
843 break; |
| 3922 | 844 case 20: /* /SUP */ |
| 845 NEW_BIT (NEW_TEXT_BIT); | |
| 846 if (sup) | |
| 847 sup--; | |
| 848 break; | |
| 849 case 21: /* PRE */ | |
| 850 NEW_BIT (NEW_TEXT_BIT); | |
| 851 pre++; | |
| 852 break; | |
| 853 case 22: /* /PRE */ | |
| 854 NEW_BIT (NEW_TEXT_BIT); | |
| 855 if (pre) | |
| 856 pre--; | |
| 857 break; | |
| 858 case 23: /* TITLE */ | |
| 859 NEW_BIT (NEW_TEXT_BIT); | |
| 860 title++; | |
| 861 break; | |
| 862 case 24: /* /TITLE */ | |
| 863 if (title) { | |
| 864 if (options & GTK_IMHTML_NO_TITLE) { | |
| 865 wpos = 0; | |
| 866 ws [wpos] = '\0'; | |
| 867 } | |
| 868 title--; | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
869 } |
| 3922 | 870 break; |
| 871 case 25: /* BR */ | |
| 872 ws[wpos] = '\n'; | |
| 873 wpos++; | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
874 NEW_BIT (NEW_TEXT_BIT); |
| 3922 | 875 break; |
| 876 case 26: /* HR */ | |
| 877 case 42: /* HR (opt) */ | |
| 878 ws[wpos++] = '\n'; | |
| 879 NEW_BIT(NEW_HR_BIT); | |
| 4343 | 880 ws[wpos++] = '\n'; |
| 3922 | 881 break; |
| 882 case 27: /* /FONT */ | |
| 883 if (fonts) { | |
| 884 FontDetail *font = fonts->data; | |
| 885 NEW_BIT (NEW_TEXT_BIT); | |
| 886 fonts = g_slist_remove (fonts, font); | |
| 887 if (font->face) | |
| 888 g_free (font->face); | |
| 889 if (font->fore) | |
| 890 g_free (font->fore); | |
| 891 if (font->back) | |
| 892 g_free (font->back); | |
| 4032 | 893 if (font->sml) |
| 894 g_free (font->sml); | |
| 3922 | 895 g_free (font); |
| 896 } | |
| 897 break; | |
| 898 case 28: /* /A */ | |
| 899 if (url) { | |
| 900 NEW_BIT(NEW_TEXT_BIT); | |
| 901 g_free(url); | |
| 902 url = NULL; | |
| 2993 | 903 break; |
| 904 } | |
| 3922 | 905 case 29: /* P */ |
| 906 case 30: /* /P */ | |
| 907 case 31: /* H3 */ | |
| 908 case 32: /* /H3 */ | |
| 909 case 33: /* HTML */ | |
| 910 case 34: /* /HTML */ | |
| 911 case 35: /* BODY */ | |
| 912 case 36: /* /BODY */ | |
| 913 case 37: /* FONT */ | |
| 914 case 38: /* HEAD */ | |
| 915 case 39: /* /HEAD */ | |
| 916 break; | |
| 917 case 40: /* BINARY */ | |
| 918 case 41: /* /BINARY */ | |
| 919 break; | |
| 920 case 43: /* FONT (opt) */ | |
| 921 { | |
| 4032 | 922 gchar *color, *back, *face, *size, *sml; |
| 3922 | 923 FontDetail *font, *oldfont = NULL; |
| 924 color = gtk_imhtml_get_html_opt (tag, "COLOR="); | |
| 925 back = gtk_imhtml_get_html_opt (tag, "BACK="); | |
| 926 face = gtk_imhtml_get_html_opt (tag, "FACE="); | |
| 927 size = gtk_imhtml_get_html_opt (tag, "SIZE="); | |
| 4032 | 928 sml = gtk_imhtml_get_html_opt (tag, "SML="); |
| 929 if (!(color || back || face || size || sml)) | |
| 3922 | 930 break; |
| 931 | |
| 932 NEW_BIT (NEW_TEXT_BIT); | |
| 933 | |
| 934 font = g_new0 (FontDetail, 1); | |
| 935 if (fonts) | |
| 936 oldfont = fonts->data; | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
937 |
| 3922 | 938 if (color && !(options & GTK_IMHTML_NO_COLOURS)) |
| 939 font->fore = color; | |
| 940 else if (oldfont && oldfont->fore) | |
| 941 font->fore = g_strdup(oldfont->fore); | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
942 |
| 3922 | 943 if (back && !(options & GTK_IMHTML_NO_COLOURS)) |
| 944 font->back = back; | |
| 945 else if (oldfont && oldfont->back) | |
| 946 font->back = g_strdup(oldfont->back); | |
| 947 | |
| 948 if (face && !(options & GTK_IMHTML_NO_FONTS)) | |
| 949 font->face = face; | |
| 950 else if (oldfont && oldfont->face) | |
| 951 font->face = g_strdup(oldfont->face); | |
| 4032 | 952 |
| 953 if (sml) | |
| 954 font->sml = sml; | |
| 955 else if (oldfont && oldfont->sml) | |
| 956 font->sml = g_strdup(oldfont->sml); | |
| 957 | |
| 3922 | 958 if (size && !(options & GTK_IMHTML_NO_SIZES)) { |
| 959 if (*size == '+') { | |
| 960 sscanf (size + 1, "%hd", &font->size); | |
| 961 font->size += 3; | |
| 962 } else if (*size == '-') { | |
| 963 sscanf (size + 1, "%hd", &font->size); | |
| 964 font->size = MAX (0, 3 - font->size); | |
| 965 } else if (isdigit (*size)) { | |
| 966 sscanf (size, "%hd", &font->size); | |
| 967 } | |
| 968 } else if (oldfont) | |
| 969 font->size = oldfont->size; | |
| 970 g_free(size); | |
| 971 fonts = g_slist_prepend (fonts, font); | |
| 972 } | |
| 973 break; | |
| 974 case 44: /* BODY (opt) */ | |
| 975 if (!(options & GTK_IMHTML_NO_COLOURS)) { | |
| 976 char *bgcolor = gtk_imhtml_get_html_opt (tag, "BGCOLOR="); | |
| 977 if (bgcolor) { | |
| 978 NEW_BIT(NEW_TEXT_BIT); | |
| 979 if (bg) | |
| 980 g_free(bg); | |
| 981 bg = bgcolor; | |
|
2885
f72efa29c109
[gaim-migrate @ 2898]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2871
diff
changeset
|
982 } |
| 1428 | 983 } |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
984 break; |
| 3922 | 985 case 45: /* A (opt) */ |
| 986 { | |
| 987 gchar *href = gtk_imhtml_get_html_opt (tag, "HREF="); | |
| 988 if (href) { | |
| 989 NEW_BIT (NEW_TEXT_BIT); | |
| 990 if (url) | |
| 991 g_free (url); | |
| 992 url = href; | |
| 993 } | |
| 2993 | 994 } |
| 3922 | 995 break; |
| 996 case 47: /* P (opt) */ | |
| 997 case 48: /* H3 (opt) */ | |
| 2993 | 998 break; |
| 3922 | 999 case 49: /* comment */ |
| 1000 NEW_BIT (NEW_TEXT_BIT); | |
| 4253 | 1001 if (imhtml->show_comments) |
| 1002 wpos = g_snprintf (ws, len, "%s", tag); | |
| 3922 | 1003 NEW_BIT (NEW_COMMENT_BIT); |
| 1004 break; | |
| 1005 default: | |
| 1006 break; | |
| 2993 | 1007 } |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1008 c += tlen; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1009 pos += tlen; |
| 4138 | 1010 if(tag) |
| 1011 g_free(tag); /* This was allocated back in VALID_TAG() */ | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1012 } else if (*c == '&' && gtk_imhtml_is_amp_escape (c, &, &tlen)) { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1013 ws [wpos++] = amp; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1014 c += tlen; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1015 pos += tlen; |
| 1428 | 1016 } else if (*c == '\n') { |
| 1017 if (!(options & GTK_IMHTML_NO_NEWLINE)) { | |
| 3922 | 1018 ws[wpos] = '\n'; |
| 1019 wpos++; | |
| 1428 | 1020 NEW_BIT (NEW_TEXT_BIT); |
| 1021 } | |
| 1022 c++; | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1023 pos++; |
| 4253 | 1024 } else if (imhtml->show_smileys && (gtk_imhtml_is_smiley (imhtml, fonts, c, &smilelen) || gtk_imhtml_is_smiley(imhtml, NULL, c, &smilelen))) { |
| 4032 | 1025 FontDetail *fd; |
| 1026 gchar *sml = NULL; | |
| 1027 if (fonts) { | |
| 1028 fd = fonts->data; | |
| 1029 sml = fd->sml; | |
| 1030 } | |
| 1031 NEW_BIT (NEW_TEXT_BIT); | |
| 1032 wpos = g_snprintf (ws, smilelen + 1, "%s", c); | |
| 4263 | 1033 gtk_text_buffer_insert_pixbuf(imhtml->text_buffer, &iter, gtk_smiley_tree_image (imhtml, sml, ws)); |
| 4032 | 1034 c += smilelen; |
| 1035 pos += smilelen; | |
| 1036 wpos = 0; | |
| 1037 ws[0] = 0; | |
| 1038 } else if (*c) { | |
| 1428 | 1039 ws [wpos++] = *c++; |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1040 pos++; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1041 } else { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1042 break; |
| 1428 | 1043 } |
| 1044 } | |
| 3922 | 1045 |
| 1046 NEW_BIT(NEW_TEXT_BIT); | |
| 1428 | 1047 if (url) { |
| 1048 g_free (url); | |
| 3922 | 1049 if (str) |
| 1050 str = g_string_append (str, "</A>"); | |
| 1428 | 1051 } |
| 3922 | 1052 |
| 4032 | 1053 while (fonts) { |
| 1054 FontDetail *font = fonts->data; | |
| 1055 fonts = g_slist_remove (fonts, font); | |
| 1056 if (font->face) | |
| 1057 g_free (font->face); | |
| 1058 if (font->fore) | |
| 1059 g_free (font->fore); | |
| 1060 if (font->back) | |
| 1061 g_free (font->back); | |
| 1062 if (font->sml) | |
| 1063 g_free (font->sml); | |
| 1064 g_free (font); | |
| 1065 if (str) | |
| 1066 str = g_string_append (str, "</FONT>"); | |
| 1067 } | |
| 1068 | |
| 3922 | 1069 if (str) { |
| 1428 | 1070 while (bold) { |
| 3922 | 1071 str = g_string_append (str, "</B>"); |
| 1428 | 1072 bold--; |
| 1073 } | |
| 1074 while (italics) { | |
| 3922 | 1075 str = g_string_append (str, "</I>"); |
| 1428 | 1076 italics--; |
| 1077 } | |
| 1078 while (underline) { | |
| 3922 | 1079 str = g_string_append (str, "</U>"); |
| 1428 | 1080 underline--; |
| 1081 } | |
| 1082 while (strike) { | |
| 3922 | 1083 str = g_string_append (str, "</S>"); |
| 1428 | 1084 strike--; |
| 1085 } | |
| 1086 while (sub) { | |
| 3922 | 1087 str = g_string_append (str, "</SUB>"); |
| 1428 | 1088 sub--; |
| 1089 } | |
| 1090 while (sup) { | |
| 3922 | 1091 str = g_string_append (str, "</SUP>"); |
| 1428 | 1092 sup--; |
| 1093 } | |
| 1094 while (title) { | |
| 3922 | 1095 str = g_string_append (str, "</TITLE>"); |
| 1428 | 1096 title--; |
| 1097 } | |
|
1691
d802b115800f
[gaim-migrate @ 1701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1647
diff
changeset
|
1098 while (pre) { |
| 3922 | 1099 str = g_string_append (str, "</PRE>"); |
|
1691
d802b115800f
[gaim-migrate @ 1701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1647
diff
changeset
|
1100 pre--; |
|
d802b115800f
[gaim-migrate @ 1701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1647
diff
changeset
|
1101 } |
| 1428 | 1102 } |
| 4032 | 1103 g_free (ws); |
| 1104 if (!(options & GTK_IMHTML_NO_SCROLL)) | |
| 1105 gtk_text_view_scroll_to_mark (GTK_TEXT_VIEW (imhtml), mark, | |
| 1106 0, TRUE, 0.0, 1.0); | |
| 3922 | 1107 gtk_text_buffer_delete_mark (imhtml->text_buffer, mark); |
| 1108 return str; | |
| 1109 } | |
| 1110 | |
| 4288 | 1111 void gtk_imhtml_remove_smileys(GtkIMHtml *imhtml) |
| 1112 { | |
| 1113 g_hash_table_destroy(imhtml->smiley_data); | |
| 1114 gtk_smiley_tree_destroy(imhtml->default_smilies); | |
| 1115 imhtml->smiley_data = g_hash_table_new (g_str_hash, g_str_equal); | |
| 1116 imhtml->default_smilies = gtk_smiley_tree_new(); | |
| 1117 } | |
| 3922 | 1118 void gtk_imhtml_show_smileys (GtkIMHtml *imhtml, |
| 4253 | 1119 gboolean show) |
| 1120 { | |
| 1121 imhtml->show_smileys = show; | |
| 1122 } | |
| 3922 | 1123 |
| 1124 void gtk_imhtml_show_comments (GtkIMHtml *imhtml, | |
| 4253 | 1125 gboolean show) |
| 1126 { | |
| 1127 imhtml->show_comments = show; | |
| 1128 } | |
|
1780
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
1129 |
|
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
1130 void |
|
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
1131 gtk_imhtml_clear (GtkIMHtml *imhtml) |
|
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
1132 { |
| 3922 | 1133 GtkTextIter start, end; |
| 2993 | 1134 |
| 3922 | 1135 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start); |
| 1136 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end); | |
| 1137 gtk_text_buffer_delete(imhtml->text_buffer, &start, &end); | |
|
1780
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
1138 } |
|
2363
08c66712364c
[gaim-migrate @ 2376]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2349
diff
changeset
|
1139 |
| 4046 | 1140 void gtk_imhtml_page_up (GtkIMHtml *imhtml) |
| 1141 { | |
| 1142 | |
| 1143 } | |
| 3922 | 1144 void gtk_imhtml_page_down (GtkIMHtml *imhtml){} |
