Mercurial > pidgin
annotate src/gtkimhtml.c @ 4417:fff9c1292fa1
[gaim-migrate @ 4690]
A right-click gtkimhtml link menu from Ari Pollak. Thanks, Ari.
committer: Tailor Script <tailor@pidgin.im>
| author | Sean Egan <seanegan@gmail.com> |
|---|---|
| date | Sun, 26 Jan 2003 03:52:58 +0000 |
| parents | 8299114f5693 |
| children | 5ddb461d8961 |
| 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 | |
| 260 clipboard = gtk_clipboard_get_for_display(gdk_display_get_default(), | |
| 261 GDK_SELECTION_CLIPBOARD); | |
| 262 gtk_clipboard_set_text(clipboard, url, -1); | |
| 263 } | |
| 264 | |
| 265 /* The callback for an event on a link tag. */ | |
| 266 gboolean tag_event(GtkTextTag *tag, GObject *arg1, GdkEvent *event, GtkTextIter *arg2, char *url) { | |
| 267 GdkEventButton *event_button = (GdkEventButton *) event; | |
| 268 | |
| 3922 | 269 if (event->type == GDK_BUTTON_RELEASE) { |
| 4417 | 270 if (event_button->button == 1) { |
| 271 GtkTextIter start, end; | |
| 272 /* we shouldn't open a URL if the user has selected something: */ | |
| 273 gtk_text_buffer_get_selection_bounds( | |
| 274 gtk_text_iter_get_buffer(arg2), &start, &end); | |
| 275 if(gtk_text_iter_get_offset(&start) != | |
| 276 gtk_text_iter_get_offset(&end)) | |
| 277 return FALSE; | |
| 278 | |
| 279 /* A link was clicked--we emit the "url_clicked" signal | |
| 280 * with the URL as the argument */ | |
| 281 g_signal_emit(arg1, signals[URL_CLICKED], 0, url); | |
| 282 return FALSE; | |
| 283 } else if(event_button->button == 3) { | |
| 284 GtkWidget *img, *item, *label, *menu; | |
| 285 struct url_data *tempdata = g_new(struct url_data, 1); | |
| 286 tempdata->object = g_object_ref(arg1); | |
| 287 tempdata->url = g_strdup(url); | |
| 288 | |
| 289 menu = gtk_menu_new(); | |
| 290 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, | |
| 291 event_button->button, event_button->time); | |
| 292 | |
| 293 /* URL of link, desensitized */ | |
| 294 item = gtk_menu_item_new(); | |
| 295 label = gtk_label_new(url); | |
| 296 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); | |
| 297 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT); | |
| 298 gtk_container_add(GTK_CONTAINER(item), label); | |
| 299 gtk_widget_set_sensitive(item, FALSE); | |
| 300 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); | |
| 301 | |
| 302 /* seperator */ | |
| 303 item = gtk_menu_item_new(); | |
| 304 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); | |
| 305 | |
| 306 /* buttons and such */ | |
| 307 img = gtk_image_new_from_stock(GTK_STOCK_COPY, GTK_ICON_SIZE_MENU); | |
| 308 item = gtk_image_menu_item_new_with_label(_("Copy Link Location")); | |
| 309 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), img); | |
| 310 g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(url_copy), | |
| 311 url); | |
| 312 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); | |
| 313 | |
| 314 img = gtk_image_new_from_stock(GTK_STOCK_JUMP_TO, GTK_ICON_SIZE_MENU); | |
| 315 item = gtk_image_menu_item_new_with_label(_("Open Link in Browser")); | |
| 316 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), img); | |
| 317 g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(url_open), | |
| 318 tempdata); | |
| 319 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); | |
| 320 gtk_widget_show_all(menu); | |
| 321 | |
| 322 return TRUE; | |
| 323 } | |
| 3922 | 324 } else if (event->type == GDK_ENTER_NOTIFY) { |
| 325 /* make a hand cursor and a tooltip timeout -- if GTK worked as it should */ | |
| 326 } else if (event->type == GDK_LEAVE_NOTIFY) { | |
| 327 /* clear timeout and make an arrow cursor again --if GTK worked as it should */ | |
| 1428 | 328 } |
| 4417 | 329 if(event->type == GDK_BUTTON_PRESS && event_button->button == 3) |
| 330 return TRUE; /* Clicking the right mouse button on a link shouldn't | |
| 331 be caught by the regular GtkTextView menu */ | |
| 332 else | |
| 333 return FALSE; /* Let clicks go through if we didn't catch anything */ | |
| 1428 | 334 } |
| 335 | |
| 4298 | 336 /* this isn't used yet |
| 4032 | 337 static void |
| 4263 | 338 gtk_smiley_tree_remove (GtkSmileyTree *tree, |
| 339 GtkIMHtmlSmiley *smiley) | |
| 4032 | 340 { |
| 341 GtkSmileyTree *t = tree; | |
| 4263 | 342 const gchar *x = smiley->smile; |
| 4032 | 343 gint len = 0; |
| 344 | |
| 345 while (*x) { | |
| 346 gchar *pos; | |
| 347 | |
| 348 if (!t->values) | |
| 349 return; | |
| 350 | |
| 351 pos = strchr (t->values->str, *x); | |
| 352 if (pos) | |
| 353 t = t->children [(int) pos - (int) t->values->str]; | |
| 354 else | |
| 355 return; | |
| 356 | |
| 357 x++; len++; | |
| 358 } | |
| 359 | |
|
4141
ccec4fde84f4
[gaim-migrate @ 4359]
Christian Hammond <chipx86@chipx86.com>
parents:
4140
diff
changeset
|
360 if (t->image) { |
| 4032 | 361 t->image = NULL; |
|
4141
ccec4fde84f4
[gaim-migrate @ 4359]
Christian Hammond <chipx86@chipx86.com>
parents:
4140
diff
changeset
|
362 } |
| 4032 | 363 } |
| 4298 | 364 */ |
| 365 | |
| 4032 | 366 |
| 367 static gint | |
| 368 gtk_smiley_tree_lookup (GtkSmileyTree *tree, | |
| 369 const gchar *text) | |
| 370 { | |
| 371 GtkSmileyTree *t = tree; | |
| 372 const gchar *x = text; | |
| 373 gint len = 0; | |
| 374 | |
| 375 while (*x) { | |
| 376 gchar *pos; | |
| 377 | |
| 378 if (!t->values) | |
| 379 break; | |
| 380 | |
| 381 pos = strchr (t->values->str, *x); | |
| 382 if (pos) | |
| 383 t = t->children [(int) pos - (int) t->values->str]; | |
| 384 else | |
| 385 break; | |
| 386 | |
| 387 x++; len++; | |
| 388 } | |
| 389 | |
| 390 if (t->image) | |
| 391 return len; | |
| 392 | |
| 393 return 0; | |
| 394 } | |
| 395 | |
| 396 void | |
| 4263 | 397 gtk_imhtml_associate_smiley (GtkIMHtml *imhtml, |
| 398 gchar *sml, | |
| 399 GtkIMHtmlSmiley *smiley) | |
| 4032 | 400 { |
| 401 GtkSmileyTree *tree; | |
| 402 g_return_if_fail (imhtml != NULL); | |
| 403 g_return_if_fail (GTK_IS_IMHTML (imhtml)); | |
| 4263 | 404 |
| 4032 | 405 if (sml == NULL) |
| 406 tree = imhtml->default_smilies; | |
| 407 else if ((tree = g_hash_table_lookup(imhtml->smiley_data, sml))) { | |
| 408 } else { | |
| 409 tree = gtk_smiley_tree_new(); | |
| 410 g_hash_table_insert(imhtml->smiley_data, sml, tree); | |
| 411 } | |
| 412 | |
| 4263 | 413 gtk_smiley_tree_insert (tree, smiley); |
| 4032 | 414 } |
| 415 | |
| 416 static gboolean | |
| 417 gtk_imhtml_is_smiley (GtkIMHtml *imhtml, | |
| 418 GSList *fonts, | |
| 419 const gchar *text, | |
| 420 gint *len) | |
| 421 { | |
| 422 GtkSmileyTree *tree; | |
| 423 FontDetail *font; | |
| 424 char *sml = NULL; | |
| 425 | |
| 426 if (fonts) { | |
| 427 font = fonts->data; | |
| 428 sml = font->sml; | |
| 429 } | |
| 430 | |
| 431 if (sml == NULL) | |
| 432 tree = imhtml->default_smilies; | |
| 433 else { | |
| 434 tree = g_hash_table_lookup(imhtml->smiley_data, sml); | |
| 435 } | |
| 436 if (tree == NULL) | |
| 437 return FALSE; | |
| 438 | |
| 439 *len = gtk_smiley_tree_lookup (tree, text); | |
| 440 return (*len > 0); | |
| 441 } | |
| 442 | |
| 4263 | 443 GdkPixbuf* |
| 4032 | 444 gtk_smiley_tree_image (GtkIMHtml *imhtml, |
| 445 const gchar *sml, | |
| 446 const gchar *text) | |
| 447 { | |
| 448 GtkSmileyTree *t; | |
| 449 const gchar *x = text; | |
| 450 if (sml == NULL) | |
| 451 t = imhtml->default_smilies; | |
| 452 else | |
| 453 t = g_hash_table_lookup(imhtml->smiley_data, sml); | |
| 454 | |
| 455 | |
| 456 if (t == NULL) | |
| 457 return sml ? gtk_smiley_tree_image(imhtml, NULL, text) : NULL; | |
| 458 | |
| 459 while (*x) { | |
| 460 gchar *pos; | |
| 461 | |
| 462 if (!t->values) { | |
| 463 return sml ? gtk_smiley_tree_image(imhtml, NULL, text) : NULL; | |
| 464 } | |
| 465 | |
| 466 pos = strchr (t->values->str, *x); | |
| 467 if (pos) { | |
| 468 t = t->children [(int) pos - (int) t->values->str]; | |
| 469 } else { | |
| 470 return sml ? gtk_smiley_tree_image(imhtml, NULL, text) : NULL; | |
| 471 } | |
| 472 x++; | |
| 473 } | |
| 474 | |
| 4263 | 475 if (!t->image->icon) |
| 476 t->image->icon = gdk_pixbuf_new_from_file(t->image->file, NULL); | |
| 477 | |
| 478 return t->image->icon; | |
| 4032 | 479 } |
| 3922 | 480 #define VALID_TAG(x) if (!g_strncasecmp (string, x ">", strlen (x ">"))) { \ |
| 481 *tag = g_strndup (string, strlen (x)); \ | |
| 482 *len = strlen (x) + 1; \ | |
| 483 return TRUE; \ | |
| 484 } \ | |
| 485 (*type)++ | |
| 1428 | 486 |
| 3922 | 487 #define VALID_OPT_TAG(x) if (!g_strncasecmp (string, x " ", strlen (x " "))) { \ |
| 488 const gchar *c = string + strlen (x " "); \ | |
| 489 gchar e = '"'; \ | |
| 490 gboolean quote = FALSE; \ | |
| 491 while (*c) { \ | |
| 492 if (*c == '"' || *c == '\'') { \ | |
| 493 if (quote && (*c == e)) \ | |
| 494 quote = !quote; \ | |
| 495 else if (!quote) { \ | |
| 496 quote = !quote; \ | |
| 497 e = *c; \ | |
| 498 } \ | |
| 499 } else if (!quote && (*c == '>')) \ | |
| 500 break; \ | |
| 501 c++; \ | |
| 502 } \ | |
| 503 if (*c) { \ | |
| 504 *tag = g_strndup (string, c - string); \ | |
| 505 *len = c - string + 1; \ | |
| 506 return TRUE; \ | |
| 507 } \ | |
| 508 } \ | |
| 509 (*type)++ | |
| 1428 | 510 |
| 511 | |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
512 static gboolean |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
513 gtk_imhtml_is_amp_escape (const gchar *string, |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
514 gchar *replace, |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
515 gint *length) |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
516 { |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
517 g_return_val_if_fail (string != NULL, FALSE); |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
518 g_return_val_if_fail (replace != NULL, FALSE); |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
519 g_return_val_if_fail (length != NULL, FALSE); |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
520 |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
521 if (!g_strncasecmp (string, "&", 5)) { |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
522 *replace = '&'; |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
523 *length = 5; |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
524 } else if (!g_strncasecmp (string, "<", 4)) { |
|
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 = 4; |
|
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, " ", 6)) { |
|
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 = 6; |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
533 } else if (!g_strncasecmp (string, "©", 6)) { |
|
3717
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3705
diff
changeset
|
534 *replace = '©'; /* was: '©' */ |
|
1472
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)) { |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
537 *replace = '\"'; |
|
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, "®", 5)) { |
|
3717
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3705
diff
changeset
|
540 *replace = '®'; /* was: '®' */ |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
541 *length = 5; |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
542 } else if (*(string + 1) == '#') { |
|
2022
199ba82faacb
[gaim-migrate @ 2032]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2002
diff
changeset
|
543 guint pound = 0; |
| 3004 | 544 if ((sscanf (string, "&#%u;", £) == 1) && pound != 0) { |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
545 if (*(string + 3 + (gint)log10 (pound)) != ';') |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
546 return FALSE; |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
547 *replace = (gchar)pound; |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
548 *length = 2; |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
549 while (isdigit ((gint) string [*length])) (*length)++; |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
550 if (string [*length] == ';') (*length)++; |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
551 } else { |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
552 return FALSE; |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
553 } |
|
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 |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
558 return TRUE; |
|
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 |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
561 static gboolean |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
562 gtk_imhtml_is_tag (const gchar *string, |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
563 gchar **tag, |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
564 gint *len, |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
565 gint *type) |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
566 { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
567 *type = 1; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
568 |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
569 if (!strchr (string, '>')) |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
570 return FALSE; |
|
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 VALID_TAG ("B"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
573 VALID_TAG ("BOLD"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
574 VALID_TAG ("/B"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
575 VALID_TAG ("/BOLD"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
576 VALID_TAG ("I"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
577 VALID_TAG ("ITALIC"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
578 VALID_TAG ("/I"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
579 VALID_TAG ("/ITALIC"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
580 VALID_TAG ("U"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
581 VALID_TAG ("UNDERLINE"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
582 VALID_TAG ("/U"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
583 VALID_TAG ("/UNDERLINE"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
584 VALID_TAG ("S"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
585 VALID_TAG ("STRIKE"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
586 VALID_TAG ("/S"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
587 VALID_TAG ("/STRIKE"); |
|
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 ("/SUB"); |
|
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 ("/SUP"); |
|
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 ("/PRE"); |
|
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 ("/TITLE"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
596 VALID_TAG ("BR"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
597 VALID_TAG ("HR"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
598 VALID_TAG ("/FONT"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
599 VALID_TAG ("/A"); |
|
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 ("/P"); |
|
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 ("/H3"); |
|
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 ("/HTML"); |
|
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 ("/BODY"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
608 VALID_TAG ("FONT"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
609 VALID_TAG ("HEAD"); |
| 2993 | 610 VALID_TAG ("/HEAD"); |
| 611 VALID_TAG ("BINARY"); | |
| 612 VALID_TAG ("/BINARY"); | |
| 613 | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
614 VALID_OPT_TAG ("HR"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
615 VALID_OPT_TAG ("FONT"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
616 VALID_OPT_TAG ("BODY"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
617 VALID_OPT_TAG ("A"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
618 VALID_OPT_TAG ("IMG"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
619 VALID_OPT_TAG ("P"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
620 VALID_OPT_TAG ("H3"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
621 |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
622 if (!g_strncasecmp(string, "!--", strlen ("!--"))) { |
|
2954
f6c4f2187c08
[gaim-migrate @ 2967]
Christian Hammond <chipx86@chipx86.com>
parents:
2898
diff
changeset
|
623 gchar *e = strstr (string + strlen("!--"), "-->"); |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
624 if (e) { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
625 *len = e - string + strlen ("-->"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
626 *tag = g_strndup (string + strlen ("!--"), *len - strlen ("!---->")); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
627 return TRUE; |
|
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 |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
631 return FALSE; |
|
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 static gchar* |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
635 gtk_imhtml_get_html_opt (gchar *tag, |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
636 const gchar *opt) |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
637 { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
638 gchar *t = tag; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
639 gchar *e, *a; |
|
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 while (g_strncasecmp (t, opt, strlen (opt))) { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
642 gboolean quote = FALSE; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
643 if (*t == '\0') break; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
644 while (*t && !((*t == ' ') && !quote)) { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
645 if (*t == '\"') |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
646 quote = ! quote; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
647 t++; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
648 } |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
649 while (*t && (*t == ' ')) t++; |
|
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 |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
652 if (!g_strncasecmp (t, opt, strlen (opt))) { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
653 t += strlen (opt); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
654 } else { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
655 return NULL; |
|
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 |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
658 if ((*t == '\"') || (*t == '\'')) { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
659 e = a = ++t; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
660 while (*e && (*e != *(t - 1))) e++; |
| 2993 | 661 if (*e == '\0') { |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
662 return NULL; |
| 2993 | 663 } else |
| 664 return g_strndup (a, e - a); | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
665 } else { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
666 e = a = t; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
667 while (*e && !isspace ((gint) *e)) e++; |
| 2993 | 668 return g_strndup (a, e - a); |
|
2856
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 } |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
671 |
| 3922 | 672 |
| 673 | |
| 674 #define NEW_TEXT_BIT 0 | |
| 675 #define NEW_HR_BIT 1 | |
| 4343 | 676 #define NEW_COMMENT_BIT 2 |
| 3922 | 677 #define NEW_BIT(x) ws [wpos] = '\0'; \ |
| 678 mark2 = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); \ | |
| 679 gtk_text_buffer_insert(imhtml->text_buffer, &iter, ws, -1); \ | |
| 680 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &iter); \ | |
| 681 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &siter, mark2); \ | |
| 682 gtk_text_buffer_delete_mark(imhtml->text_buffer, mark2); \ | |
| 683 if (bold) \ | |
| 684 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "BOLD", &siter, &iter); \ | |
| 685 if (italics) \ | |
| 686 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "ITALICS", &siter, &iter); \ | |
| 687 if (underline) \ | |
| 688 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "UNDERLINE", &siter, &iter); \ | |
| 689 if (strike) \ | |
| 690 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "STRIKE", &siter, &iter); \ | |
| 691 if (sub) \ | |
| 692 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "SUB", &siter, &iter); \ | |
| 693 if (sup) \ | |
| 694 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "SUP", &siter, &iter); \ | |
| 695 if (pre) \ | |
| 696 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "PRE", &siter, &iter); \ | |
| 697 if (bg) { \ | |
| 698 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "background", bg, NULL); \ | |
| 699 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &siter, &iter); \ | |
| 700 } \ | |
| 701 if (fonts) { \ | |
| 702 FontDetail *fd = fonts->data; \ | |
| 703 if (fd->fore) { \ | |
| 704 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "foreground", fd->fore, NULL); \ | |
| 705 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &siter, &iter); \ | |
| 706 } \ | |
| 707 if (fd->back) { \ | |
| 708 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "background", fd->back, NULL); \ | |
| 709 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &siter, &iter); \ | |
| 710 } \ | |
| 711 if (fd->face) { \ | |
| 712 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "font", fd->face, NULL); \ | |
| 713 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &siter, &iter); \ | |
| 714 } \ | |
| 715 if (fd->size) { \ | |
| 716 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "size-points", (double)POINT_SIZE(fd->size), NULL); \ | |
| 717 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &siter, &iter); \ | |
| 718 } \ | |
| 719 } \ | |
| 720 if (url) { \ | |
| 721 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "foreground", "blue", "underline", PANGO_UNDERLINE_SINGLE, NULL); \ | |
| 722 g_signal_connect(G_OBJECT(texttag), "event", G_CALLBACK(tag_event), strdup(url)); \ | |
| 723 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &siter, &iter); \ | |
| 724 } \ | |
| 725 wpos = 0; \ | |
| 726 ws[0] = 0; \ | |
| 727 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &iter); \ | |
| 4343 | 728 if (x == NEW_HR_BIT) { \ |
| 729 GtkTextChildAnchor *anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, &iter); \ | |
| 730 GtkWidget *sep = gtk_hseparator_new(); \ | |
| 731 gtk_widget_set_size_request(GTK_WIDGET(sep), 5000, 2); \ | |
| 3922 | 732 gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(imhtml), sep, anchor); \ |
| 733 gtk_widget_show(sep); \ | |
| 4343 | 734 } \ |
| 3922 | 735 |
| 736 GString* gtk_imhtml_append_text (GtkIMHtml *imhtml, | |
| 737 const gchar *text, | |
| 738 gint len, | |
| 739 GtkIMHtmlOptions options) | |
| 1428 | 740 { |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
741 gint pos = 0; |
| 3922 | 742 GString *str = NULL; |
| 743 GtkTextIter iter, siter; | |
| 744 GtkTextMark *mark, *mark2; | |
| 745 GtkTextTag *texttag; | |
| 746 gchar *ws; | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
747 gchar *tag; |
| 3922 | 748 gchar *url = NULL; |
| 749 gchar *bg = NULL; | |
| 4032 | 750 gint tlen, smilelen, wpos=0; |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
751 gint type; |
| 3922 | 752 const gchar *c; |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
753 gchar amp; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
754 |
| 1428 | 755 guint bold = 0, |
| 756 italics = 0, | |
| 757 underline = 0, | |
| 758 strike = 0, | |
| 759 sub = 0, | |
| 760 sup = 0, | |
|
1691
d802b115800f
[gaim-migrate @ 1701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1647
diff
changeset
|
761 title = 0, |
| 3922 | 762 pre = 0; |
| 1428 | 763 |
| 3922 | 764 GSList *fonts = NULL; |
| 1428 | 765 |
| 766 g_return_val_if_fail (imhtml != NULL, NULL); | |
| 767 g_return_val_if_fail (GTK_IS_IMHTML (imhtml), NULL); | |
| 768 g_return_val_if_fail (text != NULL, NULL); | |
| 3922 | 769 g_return_val_if_fail (len != 0, NULL); |
| 770 | |
| 771 c = text; | |
| 772 if (len == -1) | |
| 773 len = strlen(text); | |
| 774 ws = g_malloc(len + 1); | |
| 775 ws[0] = 0; | |
| 1428 | 776 |
| 777 if (options & GTK_IMHTML_RETURN_LOG) | |
| 3922 | 778 str = g_string_new(""); |
| 1428 | 779 |
| 3922 | 780 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &iter); |
| 781 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
|
782 while (pos < len) { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
783 if (*c == '<' && gtk_imhtml_is_tag (c + 1, &tag, &tlen, &type)) { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
784 c++; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
785 pos++; |
| 3922 | 786 switch (type) |
| 787 { | |
| 788 case 1: /* B */ | |
| 789 case 2: /* BOLD */ | |
| 790 NEW_BIT (NEW_TEXT_BIT); | |
| 791 bold++; | |
| 792 break; | |
| 793 case 3: /* /B */ | |
| 794 case 4: /* /BOLD */ | |
| 795 NEW_BIT (NEW_TEXT_BIT); | |
| 796 if (bold) | |
| 797 bold--; | |
| 798 break; | |
| 799 case 5: /* I */ | |
| 800 case 6: /* ITALIC */ | |
| 801 NEW_BIT (NEW_TEXT_BIT); | |
| 802 italics++; | |
| 803 break; | |
| 804 case 7: /* /I */ | |
| 805 case 8: /* /ITALIC */ | |
| 806 NEW_BIT (NEW_TEXT_BIT); | |
| 807 if (italics) | |
| 808 italics--; | |
| 809 break; | |
| 810 case 9: /* U */ | |
| 811 case 10: /* UNDERLINE */ | |
| 812 NEW_BIT (NEW_TEXT_BIT); | |
| 813 underline++; | |
| 814 break; | |
| 815 case 11: /* /U */ | |
| 816 case 12: /* /UNDERLINE */ | |
| 817 NEW_BIT (NEW_TEXT_BIT); | |
| 818 if (underline) | |
| 819 underline--; | |
| 820 break; | |
| 821 case 13: /* S */ | |
| 822 case 14: /* STRIKE */ | |
| 823 NEW_BIT (NEW_TEXT_BIT); | |
| 824 strike++; | |
| 825 break; | |
| 826 case 15: /* /S */ | |
| 827 case 16: /* /STRIKE */ | |
| 828 NEW_BIT (NEW_TEXT_BIT); | |
| 829 if (strike) | |
| 830 strike--; | |
| 831 break; | |
| 832 case 17: /* SUB */ | |
| 833 NEW_BIT (NEW_TEXT_BIT); | |
| 834 sub++; | |
| 835 break; | |
| 836 case 18: /* /SUB */ | |
| 837 NEW_BIT (NEW_TEXT_BIT); | |
| 838 if (sub) | |
| 839 sub--; | |
| 840 break; | |
| 841 case 19: /* SUP */ | |
| 842 NEW_BIT (NEW_TEXT_BIT); | |
| 843 sup++; | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
844 break; |
| 3922 | 845 case 20: /* /SUP */ |
| 846 NEW_BIT (NEW_TEXT_BIT); | |
| 847 if (sup) | |
| 848 sup--; | |
| 849 break; | |
| 850 case 21: /* PRE */ | |
| 851 NEW_BIT (NEW_TEXT_BIT); | |
| 852 pre++; | |
| 853 break; | |
| 854 case 22: /* /PRE */ | |
| 855 NEW_BIT (NEW_TEXT_BIT); | |
| 856 if (pre) | |
| 857 pre--; | |
| 858 break; | |
| 859 case 23: /* TITLE */ | |
| 860 NEW_BIT (NEW_TEXT_BIT); | |
| 861 title++; | |
| 862 break; | |
| 863 case 24: /* /TITLE */ | |
| 864 if (title) { | |
| 865 if (options & GTK_IMHTML_NO_TITLE) { | |
| 866 wpos = 0; | |
| 867 ws [wpos] = '\0'; | |
| 868 } | |
| 869 title--; | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
870 } |
| 3922 | 871 break; |
| 872 case 25: /* BR */ | |
| 873 ws[wpos] = '\n'; | |
| 874 wpos++; | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
875 NEW_BIT (NEW_TEXT_BIT); |
| 3922 | 876 break; |
| 877 case 26: /* HR */ | |
| 878 case 42: /* HR (opt) */ | |
| 879 ws[wpos++] = '\n'; | |
| 880 NEW_BIT(NEW_HR_BIT); | |
| 4343 | 881 ws[wpos++] = '\n'; |
| 3922 | 882 break; |
| 883 case 27: /* /FONT */ | |
| 884 if (fonts) { | |
| 885 FontDetail *font = fonts->data; | |
| 886 NEW_BIT (NEW_TEXT_BIT); | |
| 887 fonts = g_slist_remove (fonts, font); | |
| 888 if (font->face) | |
| 889 g_free (font->face); | |
| 890 if (font->fore) | |
| 891 g_free (font->fore); | |
| 892 if (font->back) | |
| 893 g_free (font->back); | |
| 4032 | 894 if (font->sml) |
| 895 g_free (font->sml); | |
| 3922 | 896 g_free (font); |
| 897 } | |
| 898 break; | |
| 899 case 28: /* /A */ | |
| 900 if (url) { | |
| 901 NEW_BIT(NEW_TEXT_BIT); | |
| 902 g_free(url); | |
| 903 url = NULL; | |
| 2993 | 904 break; |
| 905 } | |
| 3922 | 906 case 29: /* P */ |
| 907 case 30: /* /P */ | |
| 908 case 31: /* H3 */ | |
| 909 case 32: /* /H3 */ | |
| 910 case 33: /* HTML */ | |
| 911 case 34: /* /HTML */ | |
| 912 case 35: /* BODY */ | |
| 913 case 36: /* /BODY */ | |
| 914 case 37: /* FONT */ | |
| 915 case 38: /* HEAD */ | |
| 916 case 39: /* /HEAD */ | |
| 917 break; | |
| 918 case 40: /* BINARY */ | |
| 919 case 41: /* /BINARY */ | |
| 920 break; | |
| 921 case 43: /* FONT (opt) */ | |
| 922 { | |
| 4032 | 923 gchar *color, *back, *face, *size, *sml; |
| 3922 | 924 FontDetail *font, *oldfont = NULL; |
| 925 color = gtk_imhtml_get_html_opt (tag, "COLOR="); | |
| 926 back = gtk_imhtml_get_html_opt (tag, "BACK="); | |
| 927 face = gtk_imhtml_get_html_opt (tag, "FACE="); | |
| 928 size = gtk_imhtml_get_html_opt (tag, "SIZE="); | |
| 4032 | 929 sml = gtk_imhtml_get_html_opt (tag, "SML="); |
| 930 if (!(color || back || face || size || sml)) | |
| 3922 | 931 break; |
| 932 | |
| 933 NEW_BIT (NEW_TEXT_BIT); | |
| 934 | |
| 935 font = g_new0 (FontDetail, 1); | |
| 936 if (fonts) | |
| 937 oldfont = fonts->data; | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
938 |
| 3922 | 939 if (color && !(options & GTK_IMHTML_NO_COLOURS)) |
| 940 font->fore = color; | |
| 941 else if (oldfont && oldfont->fore) | |
| 942 font->fore = g_strdup(oldfont->fore); | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
943 |
| 3922 | 944 if (back && !(options & GTK_IMHTML_NO_COLOURS)) |
| 945 font->back = back; | |
| 946 else if (oldfont && oldfont->back) | |
| 947 font->back = g_strdup(oldfont->back); | |
| 948 | |
| 949 if (face && !(options & GTK_IMHTML_NO_FONTS)) | |
| 950 font->face = face; | |
| 951 else if (oldfont && oldfont->face) | |
| 952 font->face = g_strdup(oldfont->face); | |
| 4032 | 953 |
| 954 if (sml) | |
| 955 font->sml = sml; | |
| 956 else if (oldfont && oldfont->sml) | |
| 957 font->sml = g_strdup(oldfont->sml); | |
| 958 | |
| 3922 | 959 if (size && !(options & GTK_IMHTML_NO_SIZES)) { |
| 960 if (*size == '+') { | |
| 961 sscanf (size + 1, "%hd", &font->size); | |
| 962 font->size += 3; | |
| 963 } else if (*size == '-') { | |
| 964 sscanf (size + 1, "%hd", &font->size); | |
| 965 font->size = MAX (0, 3 - font->size); | |
| 966 } else if (isdigit (*size)) { | |
| 967 sscanf (size, "%hd", &font->size); | |
| 968 } | |
| 969 } else if (oldfont) | |
| 970 font->size = oldfont->size; | |
| 971 g_free(size); | |
| 972 fonts = g_slist_prepend (fonts, font); | |
| 973 } | |
| 974 break; | |
| 975 case 44: /* BODY (opt) */ | |
| 976 if (!(options & GTK_IMHTML_NO_COLOURS)) { | |
| 977 char *bgcolor = gtk_imhtml_get_html_opt (tag, "BGCOLOR="); | |
| 978 if (bgcolor) { | |
| 979 NEW_BIT(NEW_TEXT_BIT); | |
| 980 if (bg) | |
| 981 g_free(bg); | |
| 982 bg = bgcolor; | |
|
2885
f72efa29c109
[gaim-migrate @ 2898]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2871
diff
changeset
|
983 } |
| 1428 | 984 } |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
985 break; |
| 3922 | 986 case 45: /* A (opt) */ |
| 987 { | |
| 988 gchar *href = gtk_imhtml_get_html_opt (tag, "HREF="); | |
| 989 if (href) { | |
| 990 NEW_BIT (NEW_TEXT_BIT); | |
| 991 if (url) | |
| 992 g_free (url); | |
| 993 url = href; | |
| 994 } | |
| 2993 | 995 } |
| 3922 | 996 break; |
| 997 case 47: /* P (opt) */ | |
| 998 case 48: /* H3 (opt) */ | |
| 2993 | 999 break; |
| 3922 | 1000 case 49: /* comment */ |
| 1001 NEW_BIT (NEW_TEXT_BIT); | |
| 4253 | 1002 if (imhtml->show_comments) |
| 1003 wpos = g_snprintf (ws, len, "%s", tag); | |
| 3922 | 1004 NEW_BIT (NEW_COMMENT_BIT); |
| 1005 break; | |
| 1006 default: | |
| 1007 break; | |
| 2993 | 1008 } |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1009 c += tlen; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1010 pos += tlen; |
| 4138 | 1011 if(tag) |
| 1012 g_free(tag); /* This was allocated back in VALID_TAG() */ | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1013 } else if (*c == '&' && gtk_imhtml_is_amp_escape (c, &, &tlen)) { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1014 ws [wpos++] = amp; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1015 c += tlen; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1016 pos += tlen; |
| 1428 | 1017 } else if (*c == '\n') { |
| 1018 if (!(options & GTK_IMHTML_NO_NEWLINE)) { | |
| 3922 | 1019 ws[wpos] = '\n'; |
| 1020 wpos++; | |
| 1428 | 1021 NEW_BIT (NEW_TEXT_BIT); |
| 1022 } | |
| 1023 c++; | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1024 pos++; |
| 4253 | 1025 } else if (imhtml->show_smileys && (gtk_imhtml_is_smiley (imhtml, fonts, c, &smilelen) || gtk_imhtml_is_smiley(imhtml, NULL, c, &smilelen))) { |
| 4032 | 1026 FontDetail *fd; |
| 1027 gchar *sml = NULL; | |
| 1028 if (fonts) { | |
| 1029 fd = fonts->data; | |
| 1030 sml = fd->sml; | |
| 1031 } | |
| 1032 NEW_BIT (NEW_TEXT_BIT); | |
| 1033 wpos = g_snprintf (ws, smilelen + 1, "%s", c); | |
| 4263 | 1034 gtk_text_buffer_insert_pixbuf(imhtml->text_buffer, &iter, gtk_smiley_tree_image (imhtml, sml, ws)); |
| 4032 | 1035 c += smilelen; |
| 1036 pos += smilelen; | |
| 1037 wpos = 0; | |
| 1038 ws[0] = 0; | |
| 1039 } else if (*c) { | |
| 1428 | 1040 ws [wpos++] = *c++; |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1041 pos++; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1042 } else { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1043 break; |
| 1428 | 1044 } |
| 1045 } | |
| 3922 | 1046 |
| 1047 NEW_BIT(NEW_TEXT_BIT); | |
| 1428 | 1048 if (url) { |
| 1049 g_free (url); | |
| 3922 | 1050 if (str) |
| 1051 str = g_string_append (str, "</A>"); | |
| 1428 | 1052 } |
| 3922 | 1053 |
| 4032 | 1054 while (fonts) { |
| 1055 FontDetail *font = fonts->data; | |
| 1056 fonts = g_slist_remove (fonts, font); | |
| 1057 if (font->face) | |
| 1058 g_free (font->face); | |
| 1059 if (font->fore) | |
| 1060 g_free (font->fore); | |
| 1061 if (font->back) | |
| 1062 g_free (font->back); | |
| 1063 if (font->sml) | |
| 1064 g_free (font->sml); | |
| 1065 g_free (font); | |
| 1066 if (str) | |
| 1067 str = g_string_append (str, "</FONT>"); | |
| 1068 } | |
| 1069 | |
| 3922 | 1070 if (str) { |
| 1428 | 1071 while (bold) { |
| 3922 | 1072 str = g_string_append (str, "</B>"); |
| 1428 | 1073 bold--; |
| 1074 } | |
| 1075 while (italics) { | |
| 3922 | 1076 str = g_string_append (str, "</I>"); |
| 1428 | 1077 italics--; |
| 1078 } | |
| 1079 while (underline) { | |
| 3922 | 1080 str = g_string_append (str, "</U>"); |
| 1428 | 1081 underline--; |
| 1082 } | |
| 1083 while (strike) { | |
| 3922 | 1084 str = g_string_append (str, "</S>"); |
| 1428 | 1085 strike--; |
| 1086 } | |
| 1087 while (sub) { | |
| 3922 | 1088 str = g_string_append (str, "</SUB>"); |
| 1428 | 1089 sub--; |
| 1090 } | |
| 1091 while (sup) { | |
| 3922 | 1092 str = g_string_append (str, "</SUP>"); |
| 1428 | 1093 sup--; |
| 1094 } | |
| 1095 while (title) { | |
| 3922 | 1096 str = g_string_append (str, "</TITLE>"); |
| 1428 | 1097 title--; |
| 1098 } | |
|
1691
d802b115800f
[gaim-migrate @ 1701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1647
diff
changeset
|
1099 while (pre) { |
| 3922 | 1100 str = g_string_append (str, "</PRE>"); |
|
1691
d802b115800f
[gaim-migrate @ 1701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1647
diff
changeset
|
1101 pre--; |
|
d802b115800f
[gaim-migrate @ 1701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1647
diff
changeset
|
1102 } |
| 1428 | 1103 } |
| 4032 | 1104 g_free (ws); |
| 1105 if (!(options & GTK_IMHTML_NO_SCROLL)) | |
| 1106 gtk_text_view_scroll_to_mark (GTK_TEXT_VIEW (imhtml), mark, | |
| 1107 0, TRUE, 0.0, 1.0); | |
| 3922 | 1108 gtk_text_buffer_delete_mark (imhtml->text_buffer, mark); |
| 1109 return str; | |
| 1110 } | |
| 1111 | |
| 4288 | 1112 void gtk_imhtml_remove_smileys(GtkIMHtml *imhtml) |
| 1113 { | |
| 1114 g_hash_table_destroy(imhtml->smiley_data); | |
| 1115 gtk_smiley_tree_destroy(imhtml->default_smilies); | |
| 1116 imhtml->smiley_data = g_hash_table_new (g_str_hash, g_str_equal); | |
| 1117 imhtml->default_smilies = gtk_smiley_tree_new(); | |
| 1118 } | |
| 3922 | 1119 void gtk_imhtml_show_smileys (GtkIMHtml *imhtml, |
| 4253 | 1120 gboolean show) |
| 1121 { | |
| 1122 imhtml->show_smileys = show; | |
| 1123 } | |
| 3922 | 1124 |
| 1125 void gtk_imhtml_show_comments (GtkIMHtml *imhtml, | |
| 4253 | 1126 gboolean show) |
| 1127 { | |
| 1128 imhtml->show_comments = show; | |
| 1129 } | |
|
1780
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
1130 |
|
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
1131 void |
|
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
1132 gtk_imhtml_clear (GtkIMHtml *imhtml) |
|
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
1133 { |
| 3922 | 1134 GtkTextIter start, end; |
| 2993 | 1135 |
| 3922 | 1136 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start); |
| 1137 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end); | |
| 1138 gtk_text_buffer_delete(imhtml->text_buffer, &start, &end); | |
|
1780
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
1139 } |
|
2363
08c66712364c
[gaim-migrate @ 2376]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2349
diff
changeset
|
1140 |
| 4046 | 1141 void gtk_imhtml_page_up (GtkIMHtml *imhtml) |
| 1142 { | |
| 1143 | |
| 1144 } | |
| 3922 | 1145 void gtk_imhtml_page_down (GtkIMHtml *imhtml){} |
