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