Mercurial > pidgin
annotate src/gtkimhtml.c @ 7746:d7fd01f7bdcb
[gaim-migrate @ 8391]
" These patches fix the raw plugin and the gaiminc plugins so that
they compile and function correctly." --Paul A (darkrain)
committer: Tailor Script <tailor@pidgin.im>
| author | Luke Schierer <lschiere@pidgin.im> |
|---|---|
| date | Thu, 04 Dec 2003 12:12:11 +0000 |
| parents | 9cc221f68107 |
| children | ddda7537918e |
| 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" |
| 7358 | 26 #include "gtksourceiter.h" |
| 1428 | 27 #include <gtk/gtk.h> |
| 4895 | 28 #include <glib/gerror.h> |
| 4046 | 29 #include <gdk/gdkkeysyms.h> |
| 1428 | 30 #include <string.h> |
| 31 #include <ctype.h> | |
| 32 #include <stdio.h> | |
| 4629 | 33 #include <stdlib.h> |
| 1428 | 34 #include <math.h> |
|
2541
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
35 #ifdef HAVE_LANGINFO_CODESET |
|
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
36 #include <langinfo.h> |
|
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
37 #include <locale.h> |
|
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
38 #endif |
| 1428 | 39 |
| 4417 | 40 #ifdef ENABLE_NLS |
| 41 # include <libintl.h> | |
| 42 # define _(x) gettext(x) | |
| 43 # ifdef gettext_noop | |
| 44 # define N_(String) gettext_noop (String) | |
| 45 # else | |
| 46 # define N_(String) (String) | |
| 47 # endif | |
| 48 #else | |
| 49 # define N_(String) (String) | |
| 50 # define _(x) (x) | |
| 51 #endif | |
| 52 | |
| 4735 | 53 #include <pango/pango-font.h> |
| 54 | |
| 5105 | 55 /* GTK+ < 2.2.2 hack, see ui.h for details. */ |
| 56 #ifndef GTK_WRAP_WORD_CHAR | |
| 57 #define GTK_WRAP_WORD_CHAR GTK_WRAP_WORD | |
| 58 #endif | |
| 59 | |
| 4735 | 60 #define TOOLTIP_TIMEOUT 500 |
| 61 | |
| 7694 | 62 static void insert_cb(GtkTextBuffer *buffer, GtkTextIter *iter, gchar *text, gint len, GtkIMHtml *imhtml); |
| 63 | |
| 3922 | 64 /* POINT_SIZE converts from AIM font sizes to point sizes. It probably should be redone in such a |
| 65 * way that it base the sizes off the default font size rather than using arbitrary font sizes. */ | |
| 66 #define MAX_FONT_SIZE 7 | |
| 5367 | 67 #define POINT_SIZE(x) (options & GTK_IMHTML_USE_POINTSIZE ? x : _point_sizes [MIN ((x), MAX_FONT_SIZE) - 1]) |
| 3928 | 68 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
|
69 |
| 4032 | 70 static GtkSmileyTree* |
| 71 gtk_smiley_tree_new () | |
| 72 { | |
| 73 return g_new0 (GtkSmileyTree, 1); | |
| 74 } | |
| 75 | |
| 76 static void | |
| 77 gtk_smiley_tree_insert (GtkSmileyTree *tree, | |
| 4263 | 78 GtkIMHtmlSmiley *smiley) |
| 4032 | 79 { |
| 80 GtkSmileyTree *t = tree; | |
| 4263 | 81 const gchar *x = smiley->smile; |
| 4032 | 82 |
| 83 if (!strlen (x)) | |
| 84 return; | |
| 85 | |
| 86 while (*x) { | |
| 87 gchar *pos; | |
| 88 gint index; | |
| 89 | |
| 90 if (!t->values) | |
| 91 t->values = g_string_new (""); | |
| 92 | |
| 93 pos = strchr (t->values->str, *x); | |
| 94 if (!pos) { | |
| 95 t->values = g_string_append_c (t->values, *x); | |
| 96 index = t->values->len - 1; | |
| 97 t->children = g_realloc (t->children, t->values->len * sizeof (GtkSmileyTree *)); | |
| 98 t->children [index] = g_new0 (GtkSmileyTree, 1); | |
| 99 } else | |
| 7386 | 100 index = GPOINTER_TO_INT(pos) - GPOINTER_TO_INT(t->values->str); |
| 4032 | 101 |
| 102 t = t->children [index]; | |
| 103 | |
| 104 x++; | |
| 105 } | |
| 106 | |
| 4263 | 107 t->image = smiley; |
| 4032 | 108 } |
| 4041 | 109 |
| 4263 | 110 |
| 4264 | 111 void gtk_smiley_tree_destroy (GtkSmileyTree *tree) |
| 4032 | 112 { |
| 113 GSList *list = g_slist_append (NULL, tree); | |
| 114 | |
| 115 while (list) { | |
| 116 GtkSmileyTree *t = list->data; | |
| 117 gint i; | |
| 118 list = g_slist_remove(list, t); | |
| 7384 | 119 if (t && t->values) { |
| 4032 | 120 for (i = 0; i < t->values->len; i++) |
| 121 list = g_slist_append (list, t->children [i]); | |
| 122 g_string_free (t->values, TRUE); | |
| 123 g_free (t->children); | |
| 124 } | |
| 125 g_free (t); | |
| 126 } | |
| 127 } | |
| 128 | |
| 5967 | 129 static gboolean gtk_size_allocate_cb(GtkIMHtml *widget, GtkAllocation *alloc, gpointer user_data) |
| 130 { | |
| 131 GdkRectangle rect; | |
| 132 | |
| 133 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(widget), &rect); | |
| 134 if(widget->old_rect.width != rect.width || widget->old_rect.height != rect.height){ | |
| 135 GList *iter = GTK_IMHTML(widget)->scalables; | |
| 136 | |
| 137 while(iter){ | |
| 138 GtkIMHtmlScalable *scale = GTK_IMHTML_SCALABLE(iter->data); | |
| 139 scale->scale(scale, rect.width, rect.height); | |
| 140 | |
| 141 iter = iter->next; | |
| 142 } | |
| 143 } | |
| 144 | |
| 145 widget->old_rect = rect; | |
| 146 return FALSE; | |
| 147 } | |
| 148 | |
| 149 static gint | |
| 150 gtk_imhtml_tip_paint (GtkIMHtml *imhtml) | |
| 151 { | |
| 152 PangoLayout *layout; | |
| 153 | |
| 154 g_return_val_if_fail(GTK_IS_IMHTML(imhtml), FALSE); | |
| 155 | |
| 156 layout = gtk_widget_create_pango_layout(imhtml->tip_window, imhtml->tip); | |
| 157 | |
| 158 gtk_paint_flat_box (imhtml->tip_window->style, imhtml->tip_window->window, | |
| 159 GTK_STATE_NORMAL, GTK_SHADOW_OUT, NULL, imhtml->tip_window, | |
| 160 "tooltip", 0, 0, -1, -1); | |
| 161 | |
| 162 gtk_paint_layout (imhtml->tip_window->style, imhtml->tip_window->window, GTK_STATE_NORMAL, | |
| 163 FALSE, NULL, imhtml->tip_window, NULL, 4, 4, layout); | |
| 164 | |
| 165 g_object_unref(layout); | |
| 166 return FALSE; | |
| 167 } | |
| 168 | |
| 169 static gint | |
| 170 gtk_imhtml_tip (gpointer data) | |
| 171 { | |
| 172 GtkIMHtml *imhtml = data; | |
| 173 PangoFontMetrics *font; | |
| 174 PangoLayout *layout; | |
| 175 | |
| 176 gint gap, x, y, h, w, scr_w, baseline_skip; | |
| 177 | |
| 178 g_return_val_if_fail(GTK_IS_IMHTML(imhtml), FALSE); | |
| 179 | |
| 180 if (!imhtml->tip || !GTK_WIDGET_DRAWABLE (GTK_WIDGET(imhtml))) { | |
| 181 imhtml->tip_timer = 0; | |
| 182 return FALSE; | |
| 183 } | |
| 184 | |
| 185 if (imhtml->tip_window){ | |
| 186 gtk_widget_destroy (imhtml->tip_window); | |
| 187 imhtml->tip_window = NULL; | |
| 188 } | |
| 189 | |
| 190 imhtml->tip_timer = 0; | |
| 191 imhtml->tip_window = gtk_window_new (GTK_WINDOW_POPUP); | |
| 192 gtk_widget_set_app_paintable (imhtml->tip_window, TRUE); | |
| 193 gtk_window_set_resizable (GTK_WINDOW (imhtml->tip_window), FALSE); | |
| 194 gtk_widget_set_name (imhtml->tip_window, "gtk-tooltips"); | |
| 195 g_signal_connect_swapped (G_OBJECT (imhtml->tip_window), "expose_event", | |
| 196 G_CALLBACK (gtk_imhtml_tip_paint), imhtml); | |
| 197 | |
| 198 gtk_widget_ensure_style (imhtml->tip_window); | |
| 199 layout = gtk_widget_create_pango_layout(imhtml->tip_window, imhtml->tip); | |
| 200 font = pango_font_get_metrics(pango_context_load_font(pango_layout_get_context(layout), | |
| 201 imhtml->tip_window->style->font_desc), | |
| 202 NULL); | |
| 203 | |
| 204 | |
| 205 pango_layout_get_pixel_size(layout, &scr_w, NULL); | |
| 206 gap = PANGO_PIXELS((pango_font_metrics_get_ascent(font) + | |
| 207 pango_font_metrics_get_descent(font))/ 4); | |
| 208 | |
| 209 if (gap < 2) | |
| 210 gap = 2; | |
| 211 baseline_skip = PANGO_PIXELS(pango_font_metrics_get_ascent(font) + | |
| 212 pango_font_metrics_get_descent(font)); | |
| 213 w = 8 + scr_w; | |
| 214 h = 8 + baseline_skip; | |
| 215 | |
| 216 gdk_window_get_pointer (NULL, &x, &y, NULL); | |
| 217 if (GTK_WIDGET_NO_WINDOW (GTK_WIDGET(imhtml))) | |
| 218 y += GTK_WIDGET(imhtml)->allocation.y; | |
| 219 | |
| 220 scr_w = gdk_screen_width(); | |
| 221 | |
| 222 x -= ((w >> 1) + 4); | |
| 223 | |
| 224 if ((x + w) > scr_w) | |
| 225 x -= (x + w) - scr_w; | |
| 226 else if (x < 0) | |
| 227 x = 0; | |
| 228 | |
| 229 y = y + PANGO_PIXELS(pango_font_metrics_get_ascent(font) + | |
| 230 pango_font_metrics_get_descent(font)); | |
| 231 | |
| 232 gtk_widget_set_size_request (imhtml->tip_window, w, h); | |
| 233 gtk_widget_show (imhtml->tip_window); | |
| 234 gtk_window_move (GTK_WINDOW(imhtml->tip_window), x, y); | |
| 235 | |
| 236 pango_font_metrics_unref(font); | |
| 237 g_object_unref(layout); | |
| 238 | |
| 239 return FALSE; | |
| 240 } | |
| 241 | |
| 242 gboolean gtk_motion_event_notify(GtkWidget *imhtml, GdkEventMotion *event, gpointer data) | |
| 243 { | |
| 244 GtkTextIter iter; | |
| 245 GdkWindow *win = event->window; | |
| 246 int x, y; | |
| 247 char *tip = NULL; | |
| 248 GSList *tags = NULL, *templist = NULL; | |
| 249 gdk_window_get_pointer(GTK_WIDGET(imhtml)->window, NULL, NULL, NULL); | |
| 250 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(imhtml), GTK_TEXT_WINDOW_WIDGET, | |
| 251 event->x, event->y, &x, &y); | |
| 252 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(imhtml), &iter, x, y); | |
| 253 tags = gtk_text_iter_get_tags(&iter); | |
| 254 | |
| 255 templist = tags; | |
| 256 while (templist) { | |
| 257 GtkTextTag *tag = templist->data; | |
| 258 tip = g_object_get_data(G_OBJECT(tag), "link_url"); | |
| 259 if (tip) | |
| 260 break; | |
| 261 templist = templist->next; | |
| 262 } | |
| 263 | |
| 264 if (GTK_IMHTML(imhtml)->tip) { | |
| 265 if ((tip == GTK_IMHTML(imhtml)->tip)) { | |
| 266 return FALSE; | |
| 267 } | |
| 268 /* We've left the cell. Remove the timeout and create a new one below */ | |
| 269 if (GTK_IMHTML(imhtml)->tip_window) { | |
| 270 gtk_widget_destroy(GTK_IMHTML(imhtml)->tip_window); | |
| 271 GTK_IMHTML(imhtml)->tip_window = NULL; | |
| 272 } | |
| 7694 | 273 if (GTK_IMHTML(imhtml)->editable) |
| 274 gdk_window_set_cursor(win, GTK_IMHTML(imhtml)->text_cursor); | |
| 275 else | |
| 276 gdk_window_set_cursor(win, GTK_IMHTML(imhtml)->arrow_cursor); | |
| 5967 | 277 if (GTK_IMHTML(imhtml)->tip_timer) |
| 278 g_source_remove(GTK_IMHTML(imhtml)->tip_timer); | |
| 279 GTK_IMHTML(imhtml)->tip_timer = 0; | |
| 280 } | |
| 281 | |
| 282 if(tip){ | |
| 7709 | 283 if (!GTK_IMHTML(imhtml)->editable) |
| 7707 | 284 gdk_window_set_cursor(win, GTK_IMHTML(imhtml)->hand_cursor); |
| 5967 | 285 GTK_IMHTML(imhtml)->tip_timer = g_timeout_add (TOOLTIP_TIMEOUT, |
| 286 gtk_imhtml_tip, imhtml); | |
| 287 } | |
| 288 | |
| 289 GTK_IMHTML(imhtml)->tip = tip; | |
| 290 g_slist_free(tags); | |
| 291 return FALSE; | |
| 292 } | |
| 293 | |
| 294 gboolean gtk_leave_event_notify(GtkWidget *imhtml, GdkEventCrossing *event, gpointer data) | |
| 295 { | |
| 296 /* when leaving the widget, clear any current & pending tooltips and restore the cursor */ | |
| 297 if (GTK_IMHTML(imhtml)->tip_window) { | |
| 298 gtk_widget_destroy(GTK_IMHTML(imhtml)->tip_window); | |
| 299 GTK_IMHTML(imhtml)->tip_window = NULL; | |
| 300 } | |
| 301 if (GTK_IMHTML(imhtml)->tip_timer) { | |
| 302 g_source_remove(GTK_IMHTML(imhtml)->tip_timer); | |
| 303 GTK_IMHTML(imhtml)->tip_timer = 0; | |
| 304 } | |
| 7694 | 305 if (GTK_IMHTML(imhtml)->editable) |
| 306 gdk_window_set_cursor(event->window, GTK_IMHTML(imhtml)->text_cursor); | |
| 307 else | |
| 308 gdk_window_set_cursor(event->window, GTK_IMHTML(imhtml)->arrow_cursor); | |
| 5967 | 309 |
| 310 /* propogate the event normally */ | |
| 311 return FALSE; | |
| 312 } | |
| 313 | |
| 6066 | 314 /* |
| 315 * XXX - This should be removed eventually. | |
| 316 * | |
| 317 * This function exists to work around a gross bug in GtkTextView. | |
| 318 * Basically, we short circuit ctrl+a and ctrl+end because they make | |
| 319 * el program go boom. | |
| 320 * | |
| 321 * It's supposed to be fixed in gtk2.2. You can view the bug report at | |
| 322 * http://bugzilla.gnome.org/show_bug.cgi?id=107939 | |
| 323 */ | |
| 324 gboolean gtk_key_pressed_cb(GtkWidget *imhtml, GdkEventKey *event, gpointer data) | |
| 325 { | |
| 326 if (event->state & GDK_CONTROL_MASK) | |
| 327 switch (event->keyval) { | |
| 328 case 'a': | |
| 329 return TRUE; | |
| 330 break; | |
| 331 | |
| 332 case GDK_Home: | |
| 333 return TRUE; | |
| 334 break; | |
| 335 | |
| 336 case GDK_End: | |
| 337 return TRUE; | |
| 338 break; | |
| 339 } | |
| 340 | |
| 341 return FALSE; | |
| 342 } | |
| 343 | |
|
7404
d889a99e0eb1
[gaim-migrate @ 8000]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
344 #if GTK_CHECK_VERSION(2,2,0) |
| 7346 | 345 static GtkIMHtmlCopyable *gtk_imhtml_copyable_new(GtkIMHtml *imhtml, GtkTextMark *mark, const gchar *text) |
| 346 { | |
| 347 GtkIMHtmlCopyable *copy = g_malloc(sizeof(GtkIMHtmlCopyable)); | |
| 348 copy->mark = mark; | |
| 349 copy->text = g_strdup(text); | |
| 350 imhtml->copyables = g_slist_append(imhtml->copyables, copy); | |
| 351 return copy; | |
| 352 } | |
| 353 | |
| 354 static void copy_clipboard_cb(GtkIMHtml *imhtml, GtkClipboard *clipboard) | |
| 355 { | |
| 356 GtkTextMark *sel = gtk_text_buffer_get_selection_bound(imhtml->text_buffer); | |
| 357 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); | |
| 358 GtkTextIter start, end, smiley, last; | |
| 359 GString *str = g_string_new(NULL); | |
| 360 char *text; | |
| 361 | |
| 362 GSList *copyables; | |
| 363 | |
| 364 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &start, sel); | |
| 365 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &end, ins); | |
| 366 | |
| 367 if (gtk_text_iter_equal(&start, &end)) | |
| 368 return; | |
| 369 | |
| 370 gtk_text_iter_order(&start, &end); | |
| 371 last = start; | |
| 372 | |
| 373 for (copyables = imhtml->copyables; copyables != NULL; copyables = copyables->next) { | |
| 374 GtkIMHtmlCopyable *copy = GTK_IMHTML_COPYABLE(copyables->data); | |
| 375 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &smiley, copy->mark); | |
| 376 if (gtk_text_iter_compare(&end, &smiley) < 0) { | |
| 377 break; | |
| 378 } | |
| 379 if (gtk_text_iter_compare(&last, &smiley) <= 0) { | |
| 380 text = gtk_text_buffer_get_text(imhtml->text_buffer, &last, &smiley, FALSE); | |
| 381 str = g_string_append(str, text); | |
| 382 str = g_string_append(str, copy->text); | |
| 383 last = smiley; | |
| 384 g_free(text); | |
| 385 } | |
| 386 } | |
| 387 text = gtk_text_buffer_get_text(imhtml->text_buffer, &last, &end, FALSE); | |
| 388 str = g_string_append(str, text); | |
| 389 g_free(text); | |
| 7353 | 390 |
| 7354 | 391 if (!gtk_text_iter_equal(&start, &last)) |
| 7745 | 392 #ifdef _WIN32 |
| 7742 | 393 gtk_clipboard_set_text(gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_CLIPBOARD), |
| 394 str->str, str->len); | |
| 395 #endif | |
| 7354 | 396 gtk_clipboard_set_text(clipboard ? clipboard : |
| 397 gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_CLIPBOARD), | |
| 398 str->str, str->len); | |
| 7742 | 399 |
| 7346 | 400 g_string_free(str, TRUE); |
| 401 } | |
| 402 | |
| 403 static gboolean button_release_cb(GtkIMHtml *imhtml, GdkEventButton event, gpointer the_foibles_of_man) | |
| 404 { | |
| 405 copy_clipboard_cb(imhtml, gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_PRIMARY)); | |
| 406 return FALSE; | |
| 407 } | |
|
7404
d889a99e0eb1
[gaim-migrate @ 8000]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
408 #endif |
| 5967 | 409 |
| 4263 | 410 |
| 4032 | 411 static GtkTextViewClass *parent_class = NULL; |
| 412 | |
| 3922 | 413 /* GtkIMHtml has one signal--URL_CLICKED */ |
| 1428 | 414 enum { |
| 415 URL_CLICKED, | |
| 416 LAST_SIGNAL | |
| 417 }; | |
| 418 static guint signals [LAST_SIGNAL] = { 0 }; | |
| 419 | |
| 4032 | 420 static void |
| 421 gtk_imhtml_finalize (GObject *object) | |
| 422 { | |
| 423 GtkIMHtml *imhtml = GTK_IMHTML(object); | |
| 4895 | 424 GList *scalables; |
|
7404
d889a99e0eb1
[gaim-migrate @ 8000]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
425 #if GTK_CHECK_VERSION(2,2,0) |
| 7346 | 426 GSList *copyables; |
|
7404
d889a99e0eb1
[gaim-migrate @ 8000]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
427 #endif |
| 7346 | 428 |
| 4138 | 429 g_hash_table_destroy(imhtml->smiley_data); |
| 4032 | 430 gtk_smiley_tree_destroy(imhtml->default_smilies); |
| 4138 | 431 gdk_cursor_unref(imhtml->hand_cursor); |
| 432 gdk_cursor_unref(imhtml->arrow_cursor); | |
| 7694 | 433 gdk_cursor_unref(imhtml->text_cursor); |
| 4735 | 434 if(imhtml->tip_window){ |
| 435 gtk_widget_destroy(imhtml->tip_window); | |
| 436 } | |
| 437 if(imhtml->tip_timer) | |
| 438 gtk_timeout_remove(imhtml->tip_timer); | |
| 439 | |
| 4895 | 440 for(scalables = imhtml->scalables; scalables; scalables = scalables->next) { |
| 441 GtkIMHtmlScalable *scale = GTK_IMHTML_SCALABLE(scalables->data); | |
| 442 scale->free(scale); | |
| 443 } | |
| 7346 | 444 |
|
7404
d889a99e0eb1
[gaim-migrate @ 8000]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
445 #if GTK_CHECK_VERSION(2,2,0) |
| 7346 | 446 for (copyables = imhtml->copyables; copyables; copyables = copyables->next) { |
| 447 GtkIMHtmlCopyable *copy = GTK_IMHTML_COPYABLE(copyables->data); | |
| 448 g_free(copy->text); | |
| 449 g_free(copy); | |
| 450 } | |
|
7404
d889a99e0eb1
[gaim-migrate @ 8000]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
451 #endif |
| 4895 | 452 g_list_free(imhtml->scalables); |
| 4032 | 453 G_OBJECT_CLASS(parent_class)->finalize (object); |
| 454 } | |
| 1428 | 455 |
| 3922 | 456 /* Boring GTK stuff */ |
| 457 static void gtk_imhtml_class_init (GtkIMHtmlClass *class) | |
| 1428 | 458 { |
| 3922 | 459 GtkObjectClass *object_class; |
| 4032 | 460 GObjectClass *gobject_class; |
| 3922 | 461 object_class = (GtkObjectClass*) class; |
| 4032 | 462 gobject_class = (GObjectClass*) class; |
| 463 parent_class = gtk_type_class(GTK_TYPE_TEXT_VIEW); | |
| 4417 | 464 signals[URL_CLICKED] = g_signal_new("url_clicked", |
| 465 G_TYPE_FROM_CLASS(gobject_class), | |
| 466 G_SIGNAL_RUN_FIRST, | |
| 467 G_STRUCT_OFFSET(GtkIMHtmlClass, url_clicked), | |
| 468 NULL, | |
| 469 0, | |
| 470 g_cclosure_marshal_VOID__POINTER, | |
| 471 G_TYPE_NONE, 1, | |
| 472 G_TYPE_POINTER); | |
| 4032 | 473 gobject_class->finalize = gtk_imhtml_finalize; |
| 1428 | 474 } |
| 475 | |
| 3922 | 476 static void gtk_imhtml_init (GtkIMHtml *imhtml) |
| 1428 | 477 { |
| 3922 | 478 GtkTextIter iter; |
| 479 imhtml->text_buffer = gtk_text_buffer_new(NULL); | |
| 480 gtk_text_buffer_get_end_iter (imhtml->text_buffer, &iter); | |
| 481 imhtml->end = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, FALSE); | |
| 482 gtk_text_view_set_buffer(GTK_TEXT_VIEW(imhtml), imhtml->text_buffer); | |
| 5105 | 483 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(imhtml), GTK_WRAP_WORD_CHAR); |
| 3922 | 484 gtk_text_view_set_pixels_below_lines(GTK_TEXT_VIEW(imhtml), 5); |
| 485 /*gtk_text_view_set_justification(GTK_TEXT_VIEW(imhtml), GTK_JUSTIFY_FILL);*/ | |
| 3465 | 486 |
| 3922 | 487 /* These tags will be used often and can be reused--we create them on init and then apply them by name |
| 488 * other tags (color, size, face, etc.) will have to be created and applied dynamically */ | |
| 489 gtk_text_buffer_create_tag(imhtml->text_buffer, "BOLD", "weight", PANGO_WEIGHT_BOLD, NULL); | |
| 490 gtk_text_buffer_create_tag(imhtml->text_buffer, "ITALICS", "style", PANGO_STYLE_ITALIC, NULL); | |
| 491 gtk_text_buffer_create_tag(imhtml->text_buffer, "UNDERLINE", "underline", PANGO_UNDERLINE_SINGLE, NULL); | |
| 492 gtk_text_buffer_create_tag(imhtml->text_buffer, "STRIKE", "strikethrough", TRUE, NULL); | |
| 493 gtk_text_buffer_create_tag(imhtml->text_buffer, "SUB", "rise", -5000, NULL); | |
| 494 gtk_text_buffer_create_tag(imhtml->text_buffer, "SUP", "rise", 5000, NULL); | |
| 495 gtk_text_buffer_create_tag(imhtml->text_buffer, "PRE", "family", "Monospace", NULL); | |
| 7295 | 496 gtk_text_buffer_create_tag(imhtml->text_buffer, "search", "background", "#22ff00", "weight", "bold", NULL); |
| 7707 | 497 gtk_text_buffer_create_tag(imhtml->text_buffer, "LINK", "foreground", "blue", "underline", PANGO_UNDERLINE_SINGLE, NULL); |
| 3922 | 498 /* When hovering over a link, we show the hand cursor--elsewhere we show the plain ol' pointer cursor */ |
| 499 imhtml->hand_cursor = gdk_cursor_new (GDK_HAND2); | |
| 500 imhtml->arrow_cursor = gdk_cursor_new (GDK_LEFT_PTR); | |
| 7694 | 501 imhtml->text_cursor = gdk_cursor_new (GDK_XTERM); |
| 2993 | 502 |
| 4253 | 503 imhtml->show_smileys = TRUE; |
| 6124 | 504 imhtml->show_comments = TRUE; |
| 4253 | 505 |
| 4892 | 506 imhtml->smiley_data = g_hash_table_new_full(g_str_hash, g_str_equal, |
| 4902 | 507 g_free, (GDestroyNotify)gtk_smiley_tree_destroy); |
| 4032 | 508 imhtml->default_smilies = gtk_smiley_tree_new(); |
| 4735 | 509 |
| 4944 | 510 g_signal_connect(G_OBJECT(imhtml), "size-allocate", G_CALLBACK(gtk_size_allocate_cb), NULL); |
| 4735 | 511 g_signal_connect(G_OBJECT(imhtml), "motion-notify-event", G_CALLBACK(gtk_motion_event_notify), NULL); |
| 4944 | 512 g_signal_connect(G_OBJECT(imhtml), "leave-notify-event", G_CALLBACK(gtk_leave_event_notify), NULL); |
| 6066 | 513 g_signal_connect(G_OBJECT(imhtml), "key_press_event", G_CALLBACK(gtk_key_pressed_cb), NULL); |
| 7694 | 514 g_signal_connect_after(G_OBJECT(imhtml->text_buffer), "insert-text", G_CALLBACK(insert_cb), imhtml); |
|
7404
d889a99e0eb1
[gaim-migrate @ 8000]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
515 #if GTK_CHECK_VERSION(2,2,0) |
| 7353 | 516 g_signal_connect(G_OBJECT(imhtml), "copy-clipboard", G_CALLBACK(copy_clipboard_cb), NULL); |
| 7346 | 517 g_signal_connect(G_OBJECT(imhtml), "button-release-event", G_CALLBACK(button_release_cb), imhtml); |
|
7404
d889a99e0eb1
[gaim-migrate @ 8000]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
518 #endif |
| 4944 | 519 gtk_widget_add_events(GTK_WIDGET(imhtml), GDK_LEAVE_NOTIFY_MASK); |
| 4735 | 520 |
| 521 imhtml->tip = NULL; | |
| 522 imhtml->tip_timer = 0; | |
| 523 imhtml->tip_window = NULL; | |
| 4895 | 524 |
| 7694 | 525 imhtml->edit.bold = NULL; |
| 526 imhtml->edit.italic = NULL; | |
| 527 imhtml->edit.underline = NULL; | |
| 7714 | 528 imhtml->edit.forecolor = NULL; |
| 529 imhtml->edit.backcolor = NULL; | |
| 7717 | 530 imhtml->edit.fontface = NULL; |
| 7740 | 531 imhtml->edit.sizespan = NULL; |
| 532 imhtml->edit.fontsize = 3; | |
| 7714 | 533 |
| 7694 | 534 imhtml->format_spans = NULL; |
| 535 | |
| 4895 | 536 imhtml->scalables = NULL; |
|
7404
d889a99e0eb1
[gaim-migrate @ 8000]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
537 #if GTK_CHECK_VERSION(2,2,0) |
| 7346 | 538 imhtml->copyables = NULL; |
|
7404
d889a99e0eb1
[gaim-migrate @ 8000]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
539 #endif |
| 7694 | 540 gtk_imhtml_set_editable(imhtml, FALSE); |
| 2993 | 541 } |
| 542 | |
| 3922 | 543 GtkWidget *gtk_imhtml_new(void *a, void *b) |
| 1428 | 544 { |
| 4635 | 545 return GTK_WIDGET(g_object_new(gtk_imhtml_get_type(), NULL)); |
| 1428 | 546 } |
| 547 | |
| 4635 | 548 GType gtk_imhtml_get_type() |
| 1428 | 549 { |
| 4635 | 550 static GType imhtml_type = 0; |
| 1428 | 551 |
| 552 if (!imhtml_type) { | |
| 4635 | 553 static const GTypeInfo imhtml_info = { |
| 554 sizeof(GtkIMHtmlClass), | |
| 555 NULL, | |
| 556 NULL, | |
| 557 (GClassInitFunc) gtk_imhtml_class_init, | |
| 558 NULL, | |
| 559 NULL, | |
| 1428 | 560 sizeof (GtkIMHtml), |
| 4635 | 561 0, |
| 562 (GInstanceInitFunc) gtk_imhtml_init | |
| 1428 | 563 }; |
| 4635 | 564 |
| 565 imhtml_type = g_type_register_static(gtk_text_view_get_type(), | |
| 566 "GtkIMHtml", &imhtml_info, 0); | |
| 1428 | 567 } |
| 568 | |
| 569 return imhtml_type; | |
| 570 } | |
| 571 | |
| 4417 | 572 struct url_data { |
| 573 GObject *object; | |
| 574 gchar *url; | |
| 575 }; | |
| 576 | |
| 577 static void url_open(GtkWidget *w, struct url_data *data) { | |
| 578 if(!data) return; | |
| 579 | |
| 580 g_signal_emit(data->object, signals[URL_CLICKED], 0, data->url); | |
| 581 | |
| 582 g_object_unref(data->object); | |
| 583 g_free(data->url); | |
| 584 g_free(data); | |
| 585 } | |
| 5582 | 586 |
| 4417 | 587 static void url_copy(GtkWidget *w, gchar *url) { |
| 588 GtkClipboard *clipboard; | |
| 589 | |
|
5293
ead927e2543f
[gaim-migrate @ 5665]
Christian Hammond <chipx86@chipx86.com>
parents:
5282
diff
changeset
|
590 clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY); |
| 4417 | 591 gtk_clipboard_set_text(clipboard, url, -1); |
| 5582 | 592 |
| 593 clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); | |
| 594 gtk_clipboard_set_text(clipboard, url, -1); | |
| 4417 | 595 } |
| 596 | |
| 597 /* The callback for an event on a link tag. */ | |
| 5091 | 598 gboolean tag_event(GtkTextTag *tag, GObject *imhtml, GdkEvent *event, GtkTextIter *arg2, char *url) { |
| 4417 | 599 GdkEventButton *event_button = (GdkEventButton *) event; |
| 600 | |
| 3922 | 601 if (event->type == GDK_BUTTON_RELEASE) { |
| 4417 | 602 if (event_button->button == 1) { |
| 603 GtkTextIter start, end; | |
| 604 /* we shouldn't open a URL if the user has selected something: */ | |
| 605 gtk_text_buffer_get_selection_bounds( | |
| 606 gtk_text_iter_get_buffer(arg2), &start, &end); | |
| 607 if(gtk_text_iter_get_offset(&start) != | |
| 608 gtk_text_iter_get_offset(&end)) | |
| 609 return FALSE; | |
| 610 | |
| 611 /* A link was clicked--we emit the "url_clicked" signal | |
| 612 * with the URL as the argument */ | |
| 5091 | 613 g_signal_emit(imhtml, signals[URL_CLICKED], 0, url); |
| 4417 | 614 return FALSE; |
| 615 } else if(event_button->button == 3) { | |
| 4745 | 616 GtkWidget *img, *item, *menu; |
| 4417 | 617 struct url_data *tempdata = g_new(struct url_data, 1); |
| 5091 | 618 tempdata->object = g_object_ref(imhtml); |
| 4417 | 619 tempdata->url = g_strdup(url); |
| 4745 | 620 |
| 5091 | 621 /* Don't want the tooltip around if user right-clicked on link */ |
| 622 if (GTK_IMHTML(imhtml)->tip_window) { | |
| 623 gtk_widget_destroy(GTK_IMHTML(imhtml)->tip_window); | |
| 624 GTK_IMHTML(imhtml)->tip_window = NULL; | |
| 625 } | |
| 626 if (GTK_IMHTML(imhtml)->tip_timer) { | |
| 627 g_source_remove(GTK_IMHTML(imhtml)->tip_timer); | |
| 628 GTK_IMHTML(imhtml)->tip_timer = 0; | |
| 629 } | |
| 7694 | 630 if (GTK_IMHTML(imhtml)->editable) |
| 631 gdk_window_set_cursor(event_button->window, GTK_IMHTML(imhtml)->text_cursor); | |
| 632 else | |
| 633 gdk_window_set_cursor(event_button->window, GTK_IMHTML(imhtml)->arrow_cursor); | |
| 4417 | 634 menu = gtk_menu_new(); |
| 4745 | 635 |
| 4417 | 636 /* buttons and such */ |
| 637 | |
|
7140
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
638 if (!strncmp(url, "mailto:", 7)) |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
639 { |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
640 /* Copy E-Mail Address */ |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
641 img = gtk_image_new_from_stock(GTK_STOCK_COPY, |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
642 GTK_ICON_SIZE_MENU); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
643 item = gtk_image_menu_item_new_with_mnemonic( |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
644 _("_Copy E-Mail Address")); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
645 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
|
646 g_signal_connect(G_OBJECT(item), "activate", |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
647 G_CALLBACK(url_copy), url + 7); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
648 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
649 } |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
650 else |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
651 { |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
652 /* Copy Link Location */ |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
653 img = gtk_image_new_from_stock(GTK_STOCK_COPY, |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
654 GTK_ICON_SIZE_MENU); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
655 item = gtk_image_menu_item_new_with_mnemonic( |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
656 _("_Copy Link Location")); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
657 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
|
658 g_signal_connect(G_OBJECT(item), "activate", |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
659 G_CALLBACK(url_copy), url); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
660 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
661 |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
662 /* Open Link in Browser */ |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
663 img = gtk_image_new_from_stock(GTK_STOCK_JUMP_TO, |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
664 GTK_ICON_SIZE_MENU); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
665 item = gtk_image_menu_item_new_with_mnemonic( |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
666 _("_Open Link in Browser")); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
667 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
|
668 g_signal_connect(G_OBJECT(item), "activate", |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
669 G_CALLBACK(url_open), tempdata); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
670 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
671 } |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
672 |
| 4756 | 673 |
| 4417 | 674 gtk_widget_show_all(menu); |
| 4756 | 675 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, |
| 676 event_button->button, event_button->time); | |
| 4745 | 677 |
| 4417 | 678 return TRUE; |
| 679 } | |
| 1428 | 680 } |
| 4417 | 681 if(event->type == GDK_BUTTON_PRESS && event_button->button == 3) |
| 682 return TRUE; /* Clicking the right mouse button on a link shouldn't | |
| 683 be caught by the regular GtkTextView menu */ | |
| 684 else | |
| 685 return FALSE; /* Let clicks go through if we didn't catch anything */ | |
| 1428 | 686 } |
| 687 | |
| 4298 | 688 /* this isn't used yet |
| 4032 | 689 static void |
| 4263 | 690 gtk_smiley_tree_remove (GtkSmileyTree *tree, |
| 691 GtkIMHtmlSmiley *smiley) | |
| 4032 | 692 { |
| 693 GtkSmileyTree *t = tree; | |
| 4263 | 694 const gchar *x = smiley->smile; |
| 4032 | 695 gint len = 0; |
| 696 | |
| 697 while (*x) { | |
| 698 gchar *pos; | |
| 699 | |
| 700 if (!t->values) | |
| 701 return; | |
| 702 | |
| 703 pos = strchr (t->values->str, *x); | |
| 704 if (pos) | |
| 705 t = t->children [(int) pos - (int) t->values->str]; | |
| 706 else | |
| 707 return; | |
| 708 | |
| 709 x++; len++; | |
| 710 } | |
| 711 | |
|
4141
ccec4fde84f4
[gaim-migrate @ 4359]
Christian Hammond <chipx86@chipx86.com>
parents:
4140
diff
changeset
|
712 if (t->image) { |
| 4032 | 713 t->image = NULL; |
|
4141
ccec4fde84f4
[gaim-migrate @ 4359]
Christian Hammond <chipx86@chipx86.com>
parents:
4140
diff
changeset
|
714 } |
| 4032 | 715 } |
| 4298 | 716 */ |
| 717 | |
| 4032 | 718 |
| 719 static gint | |
| 720 gtk_smiley_tree_lookup (GtkSmileyTree *tree, | |
| 721 const gchar *text) | |
| 722 { | |
| 723 GtkSmileyTree *t = tree; | |
| 724 const gchar *x = text; | |
| 725 gint len = 0; | |
| 726 | |
| 727 while (*x) { | |
| 728 gchar *pos; | |
| 729 | |
| 730 if (!t->values) | |
| 731 break; | |
| 732 | |
| 733 pos = strchr (t->values->str, *x); | |
| 734 if (pos) | |
| 7371 | 735 t = t->children [GPOINTER_TO_INT(pos) - GPOINTER_TO_INT(t->values->str)]; |
| 4032 | 736 else |
| 737 break; | |
| 738 | |
| 739 x++; len++; | |
| 740 } | |
| 741 | |
| 742 if (t->image) | |
| 743 return len; | |
| 744 | |
| 745 return 0; | |
| 746 } | |
| 747 | |
| 748 void | |
| 4263 | 749 gtk_imhtml_associate_smiley (GtkIMHtml *imhtml, |
| 750 gchar *sml, | |
| 751 GtkIMHtmlSmiley *smiley) | |
| 4032 | 752 { |
| 753 GtkSmileyTree *tree; | |
| 754 g_return_if_fail (imhtml != NULL); | |
| 755 g_return_if_fail (GTK_IS_IMHTML (imhtml)); | |
| 7371 | 756 |
| 4032 | 757 if (sml == NULL) |
| 758 tree = imhtml->default_smilies; | |
| 759 else if ((tree = g_hash_table_lookup(imhtml->smiley_data, sml))) { | |
| 760 } else { | |
| 761 tree = gtk_smiley_tree_new(); | |
| 4892 | 762 g_hash_table_insert(imhtml->smiley_data, g_strdup(sml), tree); |
| 4032 | 763 } |
| 764 | |
| 4263 | 765 gtk_smiley_tree_insert (tree, smiley); |
| 4032 | 766 } |
| 767 | |
| 768 static gboolean | |
| 769 gtk_imhtml_is_smiley (GtkIMHtml *imhtml, | |
| 770 GSList *fonts, | |
| 771 const gchar *text, | |
| 772 gint *len) | |
| 773 { | |
| 774 GtkSmileyTree *tree; | |
| 5967 | 775 GtkIMHtmlFontDetail *font; |
| 4032 | 776 char *sml = NULL; |
| 777 | |
| 778 if (fonts) { | |
| 779 font = fonts->data; | |
| 780 sml = font->sml; | |
| 781 } | |
| 782 | |
| 783 if (sml == NULL) | |
| 784 tree = imhtml->default_smilies; | |
| 785 else { | |
| 786 tree = g_hash_table_lookup(imhtml->smiley_data, sml); | |
| 787 } | |
| 788 if (tree == NULL) | |
| 789 return FALSE; | |
| 7371 | 790 |
| 4032 | 791 *len = gtk_smiley_tree_lookup (tree, text); |
| 792 return (*len > 0); | |
| 793 } | |
| 794 | |
|
6814
782907a6ae65
[gaim-migrate @ 7354]
Christian Hammond <chipx86@chipx86.com>
parents:
6648
diff
changeset
|
795 GdkPixbufAnimation * |
| 4032 | 796 gtk_smiley_tree_image (GtkIMHtml *imhtml, |
| 797 const gchar *sml, | |
| 798 const gchar *text) | |
| 799 { | |
| 800 GtkSmileyTree *t; | |
| 801 const gchar *x = text; | |
| 802 if (sml == NULL) | |
| 803 t = imhtml->default_smilies; | |
| 7371 | 804 else |
| 4032 | 805 t = g_hash_table_lookup(imhtml->smiley_data, sml); |
| 7371 | 806 |
| 4032 | 807 |
| 808 if (t == NULL) | |
| 809 return sml ? gtk_smiley_tree_image(imhtml, NULL, text) : NULL; | |
| 810 | |
| 811 while (*x) { | |
| 812 gchar *pos; | |
| 813 | |
| 814 if (!t->values) { | |
| 815 return sml ? gtk_smiley_tree_image(imhtml, NULL, text) : NULL; | |
| 816 } | |
| 7371 | 817 |
| 4032 | 818 pos = strchr (t->values->str, *x); |
| 819 if (pos) { | |
| 7371 | 820 t = t->children [GPOINTER_TO_INT(pos) - GPOINTER_TO_INT(t->values->str)]; |
| 4032 | 821 } else { |
| 822 return sml ? gtk_smiley_tree_image(imhtml, NULL, text) : NULL; | |
| 823 } | |
| 824 x++; | |
| 825 } | |
| 826 | |
| 4263 | 827 if (!t->image->icon) |
|
6814
782907a6ae65
[gaim-migrate @ 7354]
Christian Hammond <chipx86@chipx86.com>
parents:
6648
diff
changeset
|
828 t->image->icon = gdk_pixbuf_animation_new_from_file(t->image->file, NULL); |
| 4263 | 829 |
| 830 return t->image->icon; | |
| 4032 | 831 } |
| 4793 | 832 #define VALID_TAG(x) if (!g_ascii_strncasecmp (string, x ">", strlen (x ">"))) { \ |
| 3922 | 833 *tag = g_strndup (string, strlen (x)); \ |
| 834 *len = strlen (x) + 1; \ | |
| 835 return TRUE; \ | |
| 836 } \ | |
| 837 (*type)++ | |
| 1428 | 838 |
| 4793 | 839 #define VALID_OPT_TAG(x) if (!g_ascii_strncasecmp (string, x " ", strlen (x " "))) { \ |
| 3922 | 840 const gchar *c = string + strlen (x " "); \ |
| 841 gchar e = '"'; \ | |
| 842 gboolean quote = FALSE; \ | |
| 843 while (*c) { \ | |
| 844 if (*c == '"' || *c == '\'') { \ | |
| 845 if (quote && (*c == e)) \ | |
| 846 quote = !quote; \ | |
| 847 else if (!quote) { \ | |
| 848 quote = !quote; \ | |
| 849 e = *c; \ | |
| 850 } \ | |
| 851 } else if (!quote && (*c == '>')) \ | |
| 852 break; \ | |
| 853 c++; \ | |
| 854 } \ | |
| 855 if (*c) { \ | |
| 856 *tag = g_strndup (string, c - string); \ | |
| 857 *len = c - string + 1; \ | |
| 858 return TRUE; \ | |
| 859 } \ | |
| 860 } \ | |
| 861 (*type)++ | |
| 1428 | 862 |
| 863 | |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
864 static gboolean |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
865 gtk_imhtml_is_amp_escape (const gchar *string, |
| 7280 | 866 gchar **replace, |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
867 gint *length) |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
868 { |
| 7287 | 869 static char buf[7]; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
870 g_return_val_if_fail (string != NULL, FALSE); |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
871 g_return_val_if_fail (replace != NULL, FALSE); |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
872 g_return_val_if_fail (length != NULL, FALSE); |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
873 |
| 4793 | 874 if (!g_ascii_strncasecmp (string, "&", 5)) { |
| 7280 | 875 *replace = "&"; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
876 *length = 5; |
| 4793 | 877 } else if (!g_ascii_strncasecmp (string, "<", 4)) { |
| 7280 | 878 *replace = "<"; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
879 *length = 4; |
| 4793 | 880 } else if (!g_ascii_strncasecmp (string, ">", 4)) { |
| 7280 | 881 *replace = ">"; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
882 *length = 4; |
| 4793 | 883 } else if (!g_ascii_strncasecmp (string, " ", 6)) { |
| 7280 | 884 *replace = " "; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
885 *length = 6; |
| 4793 | 886 } else if (!g_ascii_strncasecmp (string, "©", 6)) { |
| 7280 | 887 *replace = "©"; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
888 *length = 6; |
| 4793 | 889 } else if (!g_ascii_strncasecmp (string, """, 6)) { |
| 7280 | 890 *replace = "\""; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
891 *length = 6; |
| 4793 | 892 } else if (!g_ascii_strncasecmp (string, "®", 5)) { |
| 7280 | 893 *replace = "®"; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
894 *length = 5; |
| 5093 | 895 } else if (!g_ascii_strncasecmp (string, "'", 6)) { |
| 7280 | 896 *replace = "\'"; |
| 5093 | 897 *length = 6; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
898 } else if (*(string + 1) == '#') { |
|
2022
199ba82faacb
[gaim-migrate @ 2032]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2002
diff
changeset
|
899 guint pound = 0; |
| 3004 | 900 if ((sscanf (string, "&#%u;", £) == 1) && pound != 0) { |
| 7287 | 901 int buflen; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
902 if (*(string + 3 + (gint)log10 (pound)) != ';') |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
903 return FALSE; |
| 7287 | 904 buflen = g_unichar_to_utf8((gunichar)pound, buf); |
| 905 buf[buflen] = '\0'; | |
| 7280 | 906 *replace = buf; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
907 *length = 2; |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
908 while (isdigit ((gint) string [*length])) (*length)++; |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
909 if (string [*length] == ';') (*length)++; |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
910 } else { |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
911 return FALSE; |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
912 } |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
913 } else { |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
914 return FALSE; |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
915 } |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
916 |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
917 return TRUE; |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
918 } |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
919 |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
920 static gboolean |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
921 gtk_imhtml_is_tag (const gchar *string, |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
922 gchar **tag, |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
923 gint *len, |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
924 gint *type) |
|
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 *type = 1; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
927 |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
928 if (!strchr (string, '>')) |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
929 return FALSE; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
930 |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
931 VALID_TAG ("B"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
932 VALID_TAG ("BOLD"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
933 VALID_TAG ("/B"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
934 VALID_TAG ("/BOLD"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
935 VALID_TAG ("I"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
936 VALID_TAG ("ITALIC"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
937 VALID_TAG ("/I"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
938 VALID_TAG ("/ITALIC"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
939 VALID_TAG ("U"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
940 VALID_TAG ("UNDERLINE"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
941 VALID_TAG ("/U"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
942 VALID_TAG ("/UNDERLINE"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
943 VALID_TAG ("S"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
944 VALID_TAG ("STRIKE"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
945 VALID_TAG ("/S"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
946 VALID_TAG ("/STRIKE"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
947 VALID_TAG ("SUB"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
948 VALID_TAG ("/SUB"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
949 VALID_TAG ("SUP"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
950 VALID_TAG ("/SUP"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
951 VALID_TAG ("PRE"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
952 VALID_TAG ("/PRE"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
953 VALID_TAG ("TITLE"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
954 VALID_TAG ("/TITLE"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
955 VALID_TAG ("BR"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
956 VALID_TAG ("HR"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
957 VALID_TAG ("/FONT"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
958 VALID_TAG ("/A"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
959 VALID_TAG ("P"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
960 VALID_TAG ("/P"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
961 VALID_TAG ("H3"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
962 VALID_TAG ("/H3"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
963 VALID_TAG ("HTML"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
964 VALID_TAG ("/HTML"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
965 VALID_TAG ("BODY"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
966 VALID_TAG ("/BODY"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
967 VALID_TAG ("FONT"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
968 VALID_TAG ("HEAD"); |
| 2993 | 969 VALID_TAG ("/HEAD"); |
| 970 VALID_TAG ("BINARY"); | |
| 971 VALID_TAG ("/BINARY"); | |
| 5093 | 972 |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
973 VALID_OPT_TAG ("HR"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
974 VALID_OPT_TAG ("FONT"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
975 VALID_OPT_TAG ("BODY"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
976 VALID_OPT_TAG ("A"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
977 VALID_OPT_TAG ("IMG"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
978 VALID_OPT_TAG ("P"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
979 VALID_OPT_TAG ("H3"); |
| 5093 | 980 VALID_OPT_TAG ("HTML"); |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
981 |
| 5101 | 982 VALID_TAG ("CITE"); |
| 983 VALID_TAG ("/CITE"); | |
| 984 VALID_TAG ("EM"); | |
| 985 VALID_TAG ("/EM"); | |
| 986 VALID_TAG ("STRONG"); | |
| 987 VALID_TAG ("/STRONG"); | |
| 988 | |
| 5104 | 989 VALID_OPT_TAG ("SPAN"); |
| 990 VALID_TAG ("/SPAN"); | |
| 5174 | 991 VALID_TAG ("BR/"); /* hack until gtkimhtml handles things better */ |
| 6982 | 992 VALID_TAG ("IMG"); |
| 5104 | 993 |
| 4793 | 994 if (!g_ascii_strncasecmp(string, "!--", strlen ("!--"))) { |
|
2954
f6c4f2187c08
[gaim-migrate @ 2967]
Christian Hammond <chipx86@chipx86.com>
parents:
2898
diff
changeset
|
995 gchar *e = strstr (string + strlen("!--"), "-->"); |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
996 if (e) { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
997 *len = e - string + strlen ("-->"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
998 *tag = g_strndup (string + strlen ("!--"), *len - strlen ("!---->")); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
999 return TRUE; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1000 } |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1001 } |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1002 |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1003 return FALSE; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1004 } |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1005 |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1006 static gchar* |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1007 gtk_imhtml_get_html_opt (gchar *tag, |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1008 const gchar *opt) |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1009 { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1010 gchar *t = tag; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1011 gchar *e, *a; |
| 5177 | 1012 gchar *val; |
| 1013 gint len; | |
| 7280 | 1014 gchar *c; |
| 5177 | 1015 GString *ret; |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1016 |
| 4793 | 1017 while (g_ascii_strncasecmp (t, opt, strlen (opt))) { |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1018 gboolean quote = FALSE; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1019 if (*t == '\0') break; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1020 while (*t && !((*t == ' ') && !quote)) { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1021 if (*t == '\"') |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1022 quote = ! quote; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1023 t++; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1024 } |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1025 while (*t && (*t == ' ')) t++; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1026 } |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1027 |
| 4793 | 1028 if (!g_ascii_strncasecmp (t, opt, strlen (opt))) { |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1029 t += strlen (opt); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1030 } else { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1031 return NULL; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1032 } |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1033 |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1034 if ((*t == '\"') || (*t == '\'')) { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1035 e = a = ++t; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1036 while (*e && (*e != *(t - 1))) e++; |
| 2993 | 1037 if (*e == '\0') { |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1038 return NULL; |
| 5177 | 1039 } else |
| 1040 val = g_strndup(a, e - a); | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1041 } else { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1042 e = a = t; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1043 while (*e && !isspace ((gint) *e)) e++; |
| 5177 | 1044 val = g_strndup(a, e - a); |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1045 } |
| 5177 | 1046 |
| 1047 ret = g_string_new(""); | |
| 1048 e = val; | |
| 1049 while(*e) { | |
| 1050 if(gtk_imhtml_is_amp_escape(e, &c, &len)) { | |
| 7280 | 1051 ret = g_string_append(ret, c); |
| 5177 | 1052 e += len; |
| 1053 } else { | |
| 1054 ret = g_string_append_c(ret, *e); | |
| 1055 e++; | |
| 1056 } | |
| 1057 } | |
| 1058 | |
| 1059 g_free(val); | |
| 1060 val = ret->str; | |
| 1061 g_string_free(ret, FALSE); | |
| 1062 return val; | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1063 } |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1064 |
| 3922 | 1065 |
| 1066 | |
| 1067 #define NEW_TEXT_BIT 0 | |
| 4343 | 1068 #define NEW_COMMENT_BIT 2 |
| 4895 | 1069 #define NEW_SCALABLE_BIT 1 |
| 3922 | 1070 #define NEW_BIT(x) ws [wpos] = '\0'; \ |
| 1071 mark2 = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); \ | |
| 1072 gtk_text_buffer_insert(imhtml->text_buffer, &iter, ws, -1); \ | |
| 4895 | 1073 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &iter); \ |
| 3922 | 1074 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &siter, mark2); \ |
| 1075 gtk_text_buffer_delete_mark(imhtml->text_buffer, mark2); \ | |
| 1076 if (bold) \ | |
| 1077 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "BOLD", &siter, &iter); \ | |
| 4895 | 1078 if (italics) \ |
| 3922 | 1079 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "ITALICS", &siter, &iter); \ |
| 1080 if (underline) \ | |
| 1081 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "UNDERLINE", &siter, &iter); \ | |
| 1082 if (strike) \ | |
| 1083 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "STRIKE", &siter, &iter); \ | |
| 1084 if (sub) \ | |
| 1085 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "SUB", &siter, &iter); \ | |
| 1086 if (sup) \ | |
| 1087 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "SUP", &siter, &iter); \ | |
| 1088 if (pre) \ | |
| 1089 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "PRE", &siter, &iter); \ | |
| 1090 if (bg) { \ | |
| 1091 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "background", bg, NULL); \ | |
| 1092 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &siter, &iter); \ | |
| 1093 } \ | |
| 1094 if (fonts) { \ | |
| 5967 | 1095 GtkIMHtmlFontDetail *fd = fonts->data; \ |
| 3922 | 1096 if (fd->fore) { \ |
| 1097 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "foreground", fd->fore, NULL); \ | |
| 1098 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &siter, &iter); \ | |
| 1099 } \ | |
| 1100 if (fd->back) { \ | |
| 1101 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "background", fd->back, NULL); \ | |
| 1102 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &siter, &iter); \ | |
| 1103 } \ | |
| 1104 if (fd->face) { \ | |
| 6648 | 1105 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "family", fd->face, NULL); \ |
| 3922 | 1106 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &siter, &iter); \ |
| 1107 } \ | |
| 1108 if (fd->size) { \ | |
| 5118 | 1109 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "size-points", (double)POINT_SIZE(fd->size), NULL); \ |
| 3922 | 1110 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &siter, &iter); \ |
| 1111 } \ | |
| 1112 } \ | |
| 1113 if (url) { \ | |
| 7732 | 1114 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "LINK", &siter, &iter); \ |
| 1115 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "foreground", "blue", "underline", PANGO_UNDERLINE_SINGLE, NULL); \ | |
| 5012 | 1116 g_signal_connect(G_OBJECT(texttag), "event", G_CALLBACK(tag_event), g_strdup(url)); \ |
| 7732 | 1117 g_object_set_data(G_OBJECT(texttag), "link_url", g_strdup(url)); \ |
| 4735 | 1118 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &siter, &iter); \ |
| 3922 | 1119 } \ |
| 1120 wpos = 0; \ | |
| 1121 ws[0] = 0; \ | |
| 1122 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &iter); \ | |
| 4895 | 1123 if (x == NEW_SCALABLE_BIT) { \ |
| 1124 GdkRectangle rect; \ | |
| 1125 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); \ | |
| 1126 scalable->add_to(scalable, imhtml, &iter); \ | |
| 1127 scalable->scale(scalable, rect.width, rect.height); \ | |
| 1128 imhtml->scalables = g_list_append(imhtml->scalables, scalable); \ | |
| 1129 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &iter); \ | |
| 4343 | 1130 } \ |
| 3922 | 1131 |
| 4895 | 1132 |
| 1133 | |
| 6982 | 1134 GString* gtk_imhtml_append_text_with_images (GtkIMHtml *imhtml, |
| 1135 const gchar *text, | |
| 1136 GtkIMHtmlOptions options, | |
| 1137 GSList *images) | |
| 1428 | 1138 { |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1139 gint pos = 0; |
| 3922 | 1140 GString *str = NULL; |
| 1141 GtkTextIter iter, siter; | |
| 1142 GtkTextMark *mark, *mark2; | |
| 7707 | 1143 GtkTextTag *texttag = NULL; |
| 3922 | 1144 gchar *ws; |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1145 gchar *tag; |
| 3922 | 1146 gchar *url = NULL; |
| 1147 gchar *bg = NULL; | |
| 6982 | 1148 gint len; |
| 4032 | 1149 gint tlen, smilelen, wpos=0; |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1150 gint type; |
| 3922 | 1151 const gchar *c; |
| 7280 | 1152 gchar *amp; |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1153 |
| 1428 | 1154 guint bold = 0, |
| 1155 italics = 0, | |
| 1156 underline = 0, | |
| 1157 strike = 0, | |
| 1158 sub = 0, | |
| 1159 sup = 0, | |
|
1691
d802b115800f
[gaim-migrate @ 1701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1647
diff
changeset
|
1160 title = 0, |
| 3922 | 1161 pre = 0; |
| 1428 | 1162 |
| 3922 | 1163 GSList *fonts = NULL; |
| 1428 | 1164 |
| 4612 | 1165 GdkRectangle rect; |
| 1166 int y, height; | |
| 1167 | |
| 4895 | 1168 GtkIMHtmlScalable *scalable = NULL; |
| 1169 | |
| 1428 | 1170 g_return_val_if_fail (imhtml != NULL, NULL); |
| 1171 g_return_val_if_fail (GTK_IS_IMHTML (imhtml), NULL); | |
| 1172 g_return_val_if_fail (text != NULL, NULL); | |
| 6982 | 1173 |
| 3922 | 1174 c = text; |
| 6982 | 1175 len = strlen(text); |
| 3922 | 1176 ws = g_malloc(len + 1); |
| 1177 ws[0] = 0; | |
| 1428 | 1178 |
| 1179 if (options & GTK_IMHTML_RETURN_LOG) | |
| 3922 | 1180 str = g_string_new(""); |
| 1428 | 1181 |
| 3922 | 1182 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &iter); |
| 1183 mark = gtk_text_buffer_create_mark (imhtml->text_buffer, NULL, &iter, /* right grav */ FALSE); | |
| 4612 | 1184 |
| 1185 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); | |
| 1186 gtk_text_view_get_line_yrange(GTK_TEXT_VIEW(imhtml), &iter, &y, &height); | |
| 1187 | |
| 1188 if(((y + height) - (rect.y + rect.height)) > height | |
| 1189 && gtk_text_buffer_get_char_count(imhtml->text_buffer)){ | |
| 1190 options |= GTK_IMHTML_NO_SCROLL; | |
| 1191 } | |
| 1192 | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1193 while (pos < len) { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1194 if (*c == '<' && gtk_imhtml_is_tag (c + 1, &tag, &tlen, &type)) { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1195 c++; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1196 pos++; |
| 3922 | 1197 switch (type) |
| 1198 { | |
| 1199 case 1: /* B */ | |
| 1200 case 2: /* BOLD */ | |
| 5101 | 1201 case 54: /* STRONG */ |
| 3922 | 1202 NEW_BIT (NEW_TEXT_BIT); |
| 1203 bold++; | |
| 1204 break; | |
| 1205 case 3: /* /B */ | |
| 1206 case 4: /* /BOLD */ | |
| 5101 | 1207 case 55: /* /STRONG */ |
| 3922 | 1208 NEW_BIT (NEW_TEXT_BIT); |
| 1209 if (bold) | |
| 1210 bold--; | |
| 1211 break; | |
| 1212 case 5: /* I */ | |
| 1213 case 6: /* ITALIC */ | |
| 5101 | 1214 case 52: /* EM */ |
| 3922 | 1215 NEW_BIT (NEW_TEXT_BIT); |
| 1216 italics++; | |
| 1217 break; | |
| 1218 case 7: /* /I */ | |
| 1219 case 8: /* /ITALIC */ | |
| 5101 | 1220 case 53: /* /EM */ |
| 3922 | 1221 NEW_BIT (NEW_TEXT_BIT); |
| 1222 if (italics) | |
| 1223 italics--; | |
| 1224 break; | |
| 1225 case 9: /* U */ | |
| 1226 case 10: /* UNDERLINE */ | |
| 1227 NEW_BIT (NEW_TEXT_BIT); | |
| 1228 underline++; | |
| 1229 break; | |
| 1230 case 11: /* /U */ | |
| 1231 case 12: /* /UNDERLINE */ | |
| 1232 NEW_BIT (NEW_TEXT_BIT); | |
| 1233 if (underline) | |
| 1234 underline--; | |
| 1235 break; | |
| 1236 case 13: /* S */ | |
| 1237 case 14: /* STRIKE */ | |
| 1238 NEW_BIT (NEW_TEXT_BIT); | |
| 1239 strike++; | |
| 1240 break; | |
| 1241 case 15: /* /S */ | |
| 1242 case 16: /* /STRIKE */ | |
| 1243 NEW_BIT (NEW_TEXT_BIT); | |
| 1244 if (strike) | |
| 1245 strike--; | |
| 1246 break; | |
| 1247 case 17: /* SUB */ | |
| 1248 NEW_BIT (NEW_TEXT_BIT); | |
| 1249 sub++; | |
| 1250 break; | |
| 1251 case 18: /* /SUB */ | |
| 1252 NEW_BIT (NEW_TEXT_BIT); | |
| 1253 if (sub) | |
| 1254 sub--; | |
| 1255 break; | |
| 1256 case 19: /* SUP */ | |
| 1257 NEW_BIT (NEW_TEXT_BIT); | |
| 1258 sup++; | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1259 break; |
| 3922 | 1260 case 20: /* /SUP */ |
| 1261 NEW_BIT (NEW_TEXT_BIT); | |
| 1262 if (sup) | |
| 1263 sup--; | |
| 1264 break; | |
| 1265 case 21: /* PRE */ | |
| 1266 NEW_BIT (NEW_TEXT_BIT); | |
| 1267 pre++; | |
| 1268 break; | |
| 1269 case 22: /* /PRE */ | |
| 1270 NEW_BIT (NEW_TEXT_BIT); | |
| 1271 if (pre) | |
| 1272 pre--; | |
| 1273 break; | |
| 1274 case 23: /* TITLE */ | |
| 1275 NEW_BIT (NEW_TEXT_BIT); | |
| 1276 title++; | |
| 1277 break; | |
| 1278 case 24: /* /TITLE */ | |
| 1279 if (title) { | |
| 1280 if (options & GTK_IMHTML_NO_TITLE) { | |
| 1281 wpos = 0; | |
| 1282 ws [wpos] = '\0'; | |
| 1283 } | |
| 1284 title--; | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1285 } |
| 3922 | 1286 break; |
| 1287 case 25: /* BR */ | |
| 5174 | 1288 case 58: /* BR/ */ |
| 3922 | 1289 ws[wpos] = '\n'; |
| 1290 wpos++; | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1291 NEW_BIT (NEW_TEXT_BIT); |
| 6982 | 1292 break; |
| 3922 | 1293 case 26: /* HR */ |
| 1294 case 42: /* HR (opt) */ | |
| 1295 ws[wpos++] = '\n'; | |
| 5967 | 1296 scalable = gtk_imhtml_hr_new(); |
| 4895 | 1297 NEW_BIT(NEW_SCALABLE_BIT); |
| 4343 | 1298 ws[wpos++] = '\n'; |
| 3922 | 1299 break; |
| 1300 case 27: /* /FONT */ | |
| 1301 if (fonts) { | |
| 5967 | 1302 GtkIMHtmlFontDetail *font = fonts->data; |
| 3922 | 1303 NEW_BIT (NEW_TEXT_BIT); |
| 1304 fonts = g_slist_remove (fonts, font); | |
| 1305 if (font->face) | |
| 1306 g_free (font->face); | |
| 1307 if (font->fore) | |
| 1308 g_free (font->fore); | |
| 1309 if (font->back) | |
| 1310 g_free (font->back); | |
| 4032 | 1311 if (font->sml) |
| 1312 g_free (font->sml); | |
| 3922 | 1313 g_free (font); |
| 1314 } | |
| 1315 break; | |
| 1316 case 28: /* /A */ | |
| 1317 if (url) { | |
| 1318 NEW_BIT(NEW_TEXT_BIT); | |
| 1319 g_free(url); | |
| 1320 url = NULL; | |
| 2993 | 1321 break; |
| 1322 } | |
| 3922 | 1323 case 29: /* P */ |
| 1324 case 30: /* /P */ | |
| 1325 case 31: /* H3 */ | |
| 1326 case 32: /* /H3 */ | |
| 1327 case 33: /* HTML */ | |
| 1328 case 34: /* /HTML */ | |
| 1329 case 35: /* BODY */ | |
| 1330 case 36: /* /BODY */ | |
| 1331 case 37: /* FONT */ | |
| 1332 case 38: /* HEAD */ | |
| 1333 case 39: /* /HEAD */ | |
| 6982 | 1334 case 40: /* BINARY */ |
| 1335 case 41: /* /BINARY */ | |
| 3922 | 1336 break; |
| 1337 case 43: /* FONT (opt) */ | |
| 1338 { | |
| 4032 | 1339 gchar *color, *back, *face, *size, *sml; |
| 5967 | 1340 GtkIMHtmlFontDetail *font, *oldfont = NULL; |
| 3922 | 1341 color = gtk_imhtml_get_html_opt (tag, "COLOR="); |
| 1342 back = gtk_imhtml_get_html_opt (tag, "BACK="); | |
| 1343 face = gtk_imhtml_get_html_opt (tag, "FACE="); | |
| 1344 size = gtk_imhtml_get_html_opt (tag, "SIZE="); | |
| 4032 | 1345 sml = gtk_imhtml_get_html_opt (tag, "SML="); |
| 1346 if (!(color || back || face || size || sml)) | |
| 3922 | 1347 break; |
| 1348 | |
| 1349 NEW_BIT (NEW_TEXT_BIT); | |
| 1350 | |
| 5967 | 1351 font = g_new0 (GtkIMHtmlFontDetail, 1); |
| 3922 | 1352 if (fonts) |
| 1353 oldfont = fonts->data; | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1354 |
| 3922 | 1355 if (color && !(options & GTK_IMHTML_NO_COLOURS)) |
| 1356 font->fore = color; | |
| 1357 else if (oldfont && oldfont->fore) | |
| 1358 font->fore = g_strdup(oldfont->fore); | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1359 |
| 3922 | 1360 if (back && !(options & GTK_IMHTML_NO_COLOURS)) |
| 1361 font->back = back; | |
| 1362 else if (oldfont && oldfont->back) | |
| 1363 font->back = g_strdup(oldfont->back); | |
| 1364 | |
| 1365 if (face && !(options & GTK_IMHTML_NO_FONTS)) | |
| 1366 font->face = face; | |
| 1367 else if (oldfont && oldfont->face) | |
| 1368 font->face = g_strdup(oldfont->face); | |
| 4629 | 1369 if (font->face && (atoi(font->face) > 100)) { |
| 1370 g_free(font->face); | |
| 1371 font->face = g_strdup("100"); | |
| 1372 } | |
| 4032 | 1373 |
| 1374 if (sml) | |
| 1375 font->sml = sml; | |
| 1376 else if (oldfont && oldfont->sml) | |
| 1377 font->sml = g_strdup(oldfont->sml); | |
| 1378 | |
| 3922 | 1379 if (size && !(options & GTK_IMHTML_NO_SIZES)) { |
| 1380 if (*size == '+') { | |
| 1381 sscanf (size + 1, "%hd", &font->size); | |
| 1382 font->size += 3; | |
| 1383 } else if (*size == '-') { | |
| 1384 sscanf (size + 1, "%hd", &font->size); | |
| 1385 font->size = MAX (0, 3 - font->size); | |
| 1386 } else if (isdigit (*size)) { | |
| 1387 sscanf (size, "%hd", &font->size); | |
| 1388 } | |
| 6042 | 1389 if (font->size > 100) |
| 1390 font->size = 100; | |
| 3922 | 1391 } else if (oldfont) |
| 1392 font->size = oldfont->size; | |
| 1393 g_free(size); | |
| 1394 fonts = g_slist_prepend (fonts, font); | |
| 1395 } | |
| 1396 break; | |
| 1397 case 44: /* BODY (opt) */ | |
| 1398 if (!(options & GTK_IMHTML_NO_COLOURS)) { | |
| 1399 char *bgcolor = gtk_imhtml_get_html_opt (tag, "BGCOLOR="); | |
| 1400 if (bgcolor) { | |
| 1401 NEW_BIT(NEW_TEXT_BIT); | |
| 1402 if (bg) | |
| 1403 g_free(bg); | |
| 1404 bg = bgcolor; | |
|
2885
f72efa29c109
[gaim-migrate @ 2898]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2871
diff
changeset
|
1405 } |
| 1428 | 1406 } |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1407 break; |
| 3922 | 1408 case 45: /* A (opt) */ |
| 1409 { | |
| 1410 gchar *href = gtk_imhtml_get_html_opt (tag, "HREF="); | |
| 1411 if (href) { | |
| 1412 NEW_BIT (NEW_TEXT_BIT); | |
| 1413 if (url) | |
| 1414 g_free (url); | |
| 1415 url = href; | |
| 1416 } | |
| 2993 | 1417 } |
| 3922 | 1418 break; |
| 4895 | 1419 case 46: /* IMG (opt) */ |
| 6982 | 1420 case 59: /* IMG */ |
| 4895 | 1421 { |
| 6982 | 1422 GdkPixbuf *img = NULL; |
| 1423 const gchar *filename = NULL; | |
| 4895 | 1424 |
| 6982 | 1425 if (images && images->data) { |
| 1426 img = images->data; | |
| 1427 images = images->next; | |
| 1428 filename = g_object_get_data(G_OBJECT(img), "filename"); | |
| 1429 g_object_ref(G_OBJECT(img)); | |
| 1430 } else { | |
| 1431 img = gtk_widget_render_icon(GTK_WIDGET(imhtml), | |
| 1432 GTK_STOCK_MISSING_IMAGE, GTK_ICON_SIZE_BUTTON, | |
| 1433 "gtkimhtml-missing-image"); | |
| 1434 } | |
| 4895 | 1435 |
| 6982 | 1436 scalable = gtk_imhtml_image_new(img, filename); |
| 1437 NEW_BIT(NEW_SCALABLE_BIT); | |
| 1438 g_object_unref(G_OBJECT(img)); | |
| 4895 | 1439 } |
| 3922 | 1440 case 47: /* P (opt) */ |
| 1441 case 48: /* H3 (opt) */ | |
| 5093 | 1442 case 49: /* HTML (opt) */ |
| 5101 | 1443 case 50: /* CITE */ |
| 1444 case 51: /* /CITE */ | |
| 5104 | 1445 case 56: /* SPAN */ |
| 1446 case 57: /* /SPAN */ | |
| 2993 | 1447 break; |
| 6982 | 1448 case 60: /* comment */ |
| 3922 | 1449 NEW_BIT (NEW_TEXT_BIT); |
| 6124 | 1450 if (imhtml->show_comments) |
| 1451 wpos = g_snprintf (ws, len, "%s", tag); | |
| 3922 | 1452 NEW_BIT (NEW_COMMENT_BIT); |
| 1453 break; | |
| 1454 default: | |
| 6882 | 1455 break; |
| 2993 | 1456 } |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1457 c += tlen; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1458 pos += tlen; |
| 4138 | 1459 if(tag) |
| 1460 g_free(tag); /* This was allocated back in VALID_TAG() */ | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1461 } else if (*c == '&' && gtk_imhtml_is_amp_escape (c, &, &tlen)) { |
| 7280 | 1462 while(*amp) { |
| 1463 ws [wpos++] = *amp++; | |
| 1464 } | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1465 c += tlen; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1466 pos += tlen; |
| 1428 | 1467 } else if (*c == '\n') { |
| 1468 if (!(options & GTK_IMHTML_NO_NEWLINE)) { | |
| 3922 | 1469 ws[wpos] = '\n'; |
| 1470 wpos++; | |
| 1428 | 1471 NEW_BIT (NEW_TEXT_BIT); |
| 1472 } | |
| 1473 c++; | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1474 pos++; |
| 4253 | 1475 } 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
|
1476 GtkTextChildAnchor *anchor; |
| 6882 | 1477 GtkWidget *icon = NULL; |
| 7344 | 1478 GtkTextIter copy; |
| 6882 | 1479 GdkPixbufAnimation *annipixbuf = NULL; |
| 1480 GdkPixbuf *pixbuf = NULL; | |
| 5967 | 1481 GtkIMHtmlFontDetail *fd; |
| 7346 | 1482 |
| 4032 | 1483 gchar *sml = NULL; |
| 1484 if (fonts) { | |
| 1485 fd = fonts->data; | |
| 1486 sml = fd->sml; | |
| 1487 } | |
| 1488 NEW_BIT (NEW_TEXT_BIT); | |
| 1489 wpos = g_snprintf (ws, smilelen + 1, "%s", c); | |
|
6814
782907a6ae65
[gaim-migrate @ 7354]
Christian Hammond <chipx86@chipx86.com>
parents:
6648
diff
changeset
|
1490 anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, &iter); |
| 6882 | 1491 annipixbuf = gtk_smiley_tree_image(imhtml, sml, ws); |
| 1492 if(annipixbuf) { | |
| 1493 if(gdk_pixbuf_animation_is_static_image(annipixbuf)) { | |
| 1494 pixbuf = gdk_pixbuf_animation_get_static_image(annipixbuf); | |
| 1495 if(pixbuf) | |
| 1496 icon = gtk_image_new_from_pixbuf(pixbuf); | |
| 1497 } else { | |
| 1498 icon = gtk_image_new_from_animation(annipixbuf); | |
| 1499 } | |
| 1500 } | |
| 1501 | |
| 1502 if (icon) { | |
|
6839
bdc4e73f354d
[gaim-migrate @ 7384]
Christian Hammond <chipx86@chipx86.com>
parents:
6814
diff
changeset
|
1503 gtk_widget_show(icon); |
|
bdc4e73f354d
[gaim-migrate @ 7384]
Christian Hammond <chipx86@chipx86.com>
parents:
6814
diff
changeset
|
1504 gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(imhtml), icon, anchor); |
|
7404
d889a99e0eb1
[gaim-migrate @ 8000]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
1505 #if GTK_CHECK_VERSION(2,2,0) |
| 7346 | 1506 gtk_imhtml_copyable_new(imhtml, |
| 1507 gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE), | |
| 1508 ws); | |
|
7404
d889a99e0eb1
[gaim-migrate @ 8000]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
1509 #endif |
|
6839
bdc4e73f354d
[gaim-migrate @ 7384]
Christian Hammond <chipx86@chipx86.com>
parents:
6814
diff
changeset
|
1510 } |
| 7344 | 1511 |
| 1512 copy = iter; | |
| 1513 gtk_text_iter_backward_char(©); | |
| 1514 if (bg) { | |
| 1515 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "background", bg, NULL); | |
| 1516 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &iter, ©); | |
| 1517 } | |
| 1518 if (fonts) { | |
| 1519 GtkIMHtmlFontDetail *fd = fonts->data; | |
| 1520 if (fd->back) { | |
| 1521 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "background", fd->back, NULL); | |
| 1522 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &iter, ©); | |
| 1523 } | |
| 1524 } | |
| 4032 | 1525 c += smilelen; |
| 1526 pos += smilelen; | |
| 1527 wpos = 0; | |
| 1528 ws[0] = 0; | |
| 1529 } else if (*c) { | |
| 1428 | 1530 ws [wpos++] = *c++; |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1531 pos++; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1532 } else { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1533 break; |
| 1428 | 1534 } |
| 1535 } | |
| 3922 | 1536 |
| 1537 NEW_BIT(NEW_TEXT_BIT); | |
| 1428 | 1538 if (url) { |
| 1539 g_free (url); | |
| 3922 | 1540 if (str) |
| 1541 str = g_string_append (str, "</A>"); | |
| 1428 | 1542 } |
| 3922 | 1543 |
| 4032 | 1544 while (fonts) { |
| 5967 | 1545 GtkIMHtmlFontDetail *font = fonts->data; |
| 4032 | 1546 fonts = g_slist_remove (fonts, font); |
| 1547 if (font->face) | |
| 1548 g_free (font->face); | |
| 1549 if (font->fore) | |
| 1550 g_free (font->fore); | |
| 1551 if (font->back) | |
| 1552 g_free (font->back); | |
| 1553 if (font->sml) | |
| 1554 g_free (font->sml); | |
| 1555 g_free (font); | |
| 1556 if (str) | |
| 1557 str = g_string_append (str, "</FONT>"); | |
| 1558 } | |
| 1559 | |
| 3922 | 1560 if (str) { |
| 1428 | 1561 while (bold) { |
| 3922 | 1562 str = g_string_append (str, "</B>"); |
| 1428 | 1563 bold--; |
| 1564 } | |
| 1565 while (italics) { | |
| 3922 | 1566 str = g_string_append (str, "</I>"); |
| 1428 | 1567 italics--; |
| 1568 } | |
| 1569 while (underline) { | |
| 3922 | 1570 str = g_string_append (str, "</U>"); |
| 1428 | 1571 underline--; |
| 1572 } | |
| 1573 while (strike) { | |
| 3922 | 1574 str = g_string_append (str, "</S>"); |
| 1428 | 1575 strike--; |
| 1576 } | |
| 1577 while (sub) { | |
| 3922 | 1578 str = g_string_append (str, "</SUB>"); |
| 1428 | 1579 sub--; |
| 1580 } | |
| 1581 while (sup) { | |
| 3922 | 1582 str = g_string_append (str, "</SUP>"); |
| 1428 | 1583 sup--; |
| 1584 } | |
| 1585 while (title) { | |
| 3922 | 1586 str = g_string_append (str, "</TITLE>"); |
| 1428 | 1587 title--; |
| 1588 } | |
|
1691
d802b115800f
[gaim-migrate @ 1701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1647
diff
changeset
|
1589 while (pre) { |
| 3922 | 1590 str = g_string_append (str, "</PRE>"); |
|
1691
d802b115800f
[gaim-migrate @ 1701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1647
diff
changeset
|
1591 pre--; |
|
d802b115800f
[gaim-migrate @ 1701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1647
diff
changeset
|
1592 } |
| 1428 | 1593 } |
| 4032 | 1594 g_free (ws); |
| 4630 | 1595 if(bg) |
| 1596 g_free(bg); | |
| 4032 | 1597 if (!(options & GTK_IMHTML_NO_SCROLL)) |
| 1598 gtk_text_view_scroll_to_mark (GTK_TEXT_VIEW (imhtml), mark, | |
| 1599 0, TRUE, 0.0, 1.0); | |
| 3922 | 1600 gtk_text_buffer_delete_mark (imhtml->text_buffer, mark); |
| 1601 return str; | |
| 1602 } | |
| 1603 | |
| 4892 | 1604 void gtk_imhtml_remove_smileys(GtkIMHtml *imhtml) |
| 1605 { | |
| 4288 | 1606 g_hash_table_destroy(imhtml->smiley_data); |
| 1607 gtk_smiley_tree_destroy(imhtml->default_smilies); | |
| 4892 | 1608 imhtml->smiley_data = g_hash_table_new_full(g_str_hash, g_str_equal, |
| 4902 | 1609 g_free, (GDestroyNotify)gtk_smiley_tree_destroy); |
| 4288 | 1610 imhtml->default_smilies = gtk_smiley_tree_new(); |
| 1611 } | |
| 3922 | 1612 void gtk_imhtml_show_smileys (GtkIMHtml *imhtml, |
| 4253 | 1613 gboolean show) |
| 1614 { | |
| 1615 imhtml->show_smileys = show; | |
| 1616 } | |
| 3922 | 1617 |
| 1618 void gtk_imhtml_show_comments (GtkIMHtml *imhtml, | |
| 4253 | 1619 gboolean show) |
| 1620 { | |
| 6124 | 1621 imhtml->show_comments = show; |
| 4253 | 1622 } |
|
1780
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
1623 |
|
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
1624 void |
|
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
1625 gtk_imhtml_clear (GtkIMHtml *imhtml) |
|
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
1626 { |
| 3922 | 1627 GtkTextIter start, end; |
| 7700 | 1628 GList *del = imhtml->format_spans; |
| 2993 | 1629 |
| 3922 | 1630 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start); |
| 1631 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end); | |
| 1632 gtk_text_buffer_delete(imhtml->text_buffer, &start, &end); | |
| 7694 | 1633 |
| 1634 while (imhtml->format_spans) { | |
| 1635 GtkIMHtmlFormatSpan *span = imhtml->format_spans->data; | |
| 1636 if (span->start_tag) | |
| 1637 g_free(span->start_tag); | |
| 1638 if (span->end_tag) | |
| 1639 g_free(span->end_tag); | |
| 1640 g_free(span); | |
| 1641 imhtml->format_spans = imhtml->format_spans->next; | |
| 1642 } | |
| 7700 | 1643 g_list_free(del); |
| 7694 | 1644 imhtml->edit.bold = NULL; |
| 1645 imhtml->edit.italic = NULL; | |
| 1646 imhtml->edit.underline = NULL; | |
| 7717 | 1647 imhtml->edit.fontface = NULL; |
| 7728 | 1648 imhtml->edit.forecolor = NULL; |
| 1649 imhtml->edit.backcolor = NULL; | |
| 7740 | 1650 imhtml->edit.sizespan = NULL; |
| 1651 imhtml->edit.fontsize = 3; | |
|
1780
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
1652 } |
|
2363
08c66712364c
[gaim-migrate @ 2376]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2349
diff
changeset
|
1653 |
| 4046 | 1654 void gtk_imhtml_page_up (GtkIMHtml *imhtml) |
| 1655 { | |
| 5282 | 1656 GdkRectangle rect; |
| 1657 GtkTextIter iter; | |
| 4046 | 1658 |
| 5282 | 1659 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); |
| 1660 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(imhtml), &iter, rect.x, | |
| 1661 rect.y - rect.height); | |
| 1662 gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(imhtml), &iter, 0, TRUE, 0, 0); | |
| 1663 | |
| 4046 | 1664 } |
| 5282 | 1665 void gtk_imhtml_page_down (GtkIMHtml *imhtml) |
| 1666 { | |
| 1667 GdkRectangle rect; | |
| 1668 GtkTextIter iter; | |
| 1669 | |
| 1670 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); | |
| 1671 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(imhtml), &iter, rect.x, | |
| 1672 rect.y + rect.height); | |
| 1673 gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(imhtml), &iter, 0, TRUE, 0, 0); | |
| 1674 } | |
| 4735 | 1675 |
| 5967 | 1676 /* GtkIMHtmlScalable, gtk_imhtml_image, gtk_imhtml_hr */ |
| 6982 | 1677 GtkIMHtmlScalable *gtk_imhtml_image_new(GdkPixbuf *img, const gchar *filename) |
| 4735 | 1678 { |
| 5967 | 1679 GtkIMHtmlImage *im_image = g_malloc(sizeof(GtkIMHtmlImage)); |
| 5012 | 1680 GtkImage *image = GTK_IMAGE(gtk_image_new_from_pixbuf(img)); |
| 4895 | 1681 |
| 5967 | 1682 GTK_IMHTML_SCALABLE(im_image)->scale = gtk_imhtml_image_scale; |
| 1683 GTK_IMHTML_SCALABLE(im_image)->add_to = gtk_imhtml_image_add_to; | |
| 1684 GTK_IMHTML_SCALABLE(im_image)->free = gtk_imhtml_image_free; | |
| 5046 | 1685 |
| 1686 im_image->pixbuf = img; | |
| 5012 | 1687 im_image->image = image; |
| 4895 | 1688 im_image->width = gdk_pixbuf_get_width(img); |
| 1689 im_image->height = gdk_pixbuf_get_height(img); | |
| 1690 im_image->mark = NULL; | |
| 6982 | 1691 im_image->filename = filename ? g_strdup(filename) : NULL; |
| 4895 | 1692 |
| 5046 | 1693 g_object_ref(img); |
| 4895 | 1694 return GTK_IMHTML_SCALABLE(im_image); |
| 1695 } | |
| 1696 | |
| 5967 | 1697 void gtk_imhtml_image_scale(GtkIMHtmlScalable *scale, int width, int height) |
| 4895 | 1698 { |
| 5967 | 1699 GtkIMHtmlImage *image = (GtkIMHtmlImage *)scale; |
| 4895 | 1700 |
| 1701 if(image->width > width || image->height > height){ | |
| 1702 GdkPixbuf *new_image = NULL; | |
| 1703 float factor; | |
| 1704 int new_width = image->width, new_height = image->height; | |
| 1705 | |
| 1706 if(image->width > width){ | |
| 1707 factor = (float)(width)/image->width; | |
| 1708 new_width = width; | |
| 1709 new_height = image->height * factor; | |
| 1710 } | |
| 1711 if(new_height > height){ | |
| 1712 factor = (float)(height)/new_height; | |
| 1713 new_height = height; | |
| 1714 new_width = new_width * factor; | |
| 1715 } | |
| 1716 | |
| 5046 | 1717 new_image = gdk_pixbuf_scale_simple(image->pixbuf, new_width, new_height, GDK_INTERP_BILINEAR); |
| 5012 | 1718 gtk_image_set_from_pixbuf(image->image, new_image); |
| 4895 | 1719 g_object_unref(G_OBJECT(new_image)); |
| 1720 } | |
| 1721 } | |
| 1722 | |
| 5012 | 1723 static void write_img_to_file(GtkWidget *w, GtkFileSelection *sel) |
| 1724 { | |
| 1725 const gchar *filename = gtk_file_selection_get_filename(sel); | |
| 5967 | 1726 gchar *dirname; |
| 1727 GtkIMHtmlImage *image = g_object_get_data(G_OBJECT(sel), "GtkIMHtmlImage"); | |
| 5012 | 1728 gchar *type = NULL; |
| 5019 | 1729 GError *error = NULL; |
| 5015 | 1730 #if GTK_CHECK_VERSION(2,2,0) |
| 5012 | 1731 GSList *formats = gdk_pixbuf_get_formats(); |
| 6162 | 1732 #else |
| 1733 char *basename = g_path_get_basename(filename); | |
| 1734 char *ext = strrchr(basename, '.'); | |
| 5959 | 1735 #endif |
| 5012 | 1736 |
| 5967 | 1737 if (g_file_test(filename, G_FILE_TEST_IS_DIR)) { |
| 1738 /* append a / if needed */ | |
| 1739 if (filename[strlen(filename) - 1] != '/') { | |
| 1740 dirname = g_strconcat(filename, "/", NULL); | |
| 1741 } else { | |
| 1742 dirname = g_strdup(filename); | |
| 1743 } | |
| 1744 gtk_file_selection_set_filename(sel, dirname); | |
| 1745 g_free(dirname); | |
| 5959 | 1746 return; |
| 5967 | 1747 } |
| 5959 | 1748 |
| 1749 #if GTK_CHECK_VERSION(2,2,0) | |
| 5012 | 1750 while(formats){ |
| 1751 GdkPixbufFormat *format = formats->data; | |
| 1752 gchar **extensions = gdk_pixbuf_format_get_extensions(format); | |
| 1753 gpointer p = extensions; | |
| 1754 | |
| 1755 while(gdk_pixbuf_format_is_writable(format) && extensions && extensions[0]){ | |
| 1756 gchar *fmt_ext = extensions[0]; | |
| 1757 const gchar* file_ext = filename + strlen(filename) - strlen(fmt_ext); | |
| 1758 | |
| 1759 if(!strcmp(fmt_ext, file_ext)){ | |
| 1760 type = gdk_pixbuf_format_get_name(format); | |
| 1761 break; | |
| 1762 } | |
| 1763 | |
| 1764 extensions++; | |
| 1765 } | |
| 1766 | |
| 1767 g_strfreev(p); | |
| 1768 | |
| 1769 if(type) | |
| 1770 break; | |
| 1771 | |
| 1772 formats = formats->next; | |
| 1773 } | |
| 1774 | |
| 5020 | 1775 g_slist_free(formats); |
| 1776 #else | |
| 1777 /* this is really ugly code, but I think it will work */ | |
| 1778 if(ext) { | |
| 1779 ext++; | |
| 1780 if(!g_ascii_strcasecmp(ext, "jpeg") || !g_ascii_strcasecmp(ext, "jpg")) | |
| 1781 type = g_strdup("jpeg"); | |
| 1782 else if(!g_ascii_strcasecmp(ext, "png")) | |
| 1783 type = g_strdup("png"); | |
| 1784 } | |
| 1785 | |
| 1786 g_free(basename); | |
| 1787 #endif | |
| 1788 | |
| 5012 | 1789 /* If I can't find a valid type, I will just tell the user about it and then assume |
| 1790 it's a png */ | |
| 1791 if(!type){ | |
| 1792 gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, | |
| 5967 | 1793 _("Unable to guess the image type based on the file extension supplied. Defaulting to PNG.")); |
| 5012 | 1794 type = g_strdup("png"); |
| 1795 } | |
| 1796 | |
| 5046 | 1797 gdk_pixbuf_save(image->pixbuf, filename, type, &error, NULL); |
| 5012 | 1798 |
| 1799 if(error){ | |
| 1800 gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, | |
| 1801 _("Error saving image: %s"), error->message); | |
| 1802 g_error_free(error); | |
| 1803 } | |
| 1804 | |
| 1805 g_free(type); | |
| 1806 } | |
| 1807 | |
| 5967 | 1808 static void gtk_imhtml_image_save(GtkWidget *w, GtkIMHtmlImage *image) |
| 5012 | 1809 { |
| 5967 | 1810 GtkWidget *sel = gtk_file_selection_new(_("Save Image")); |
| 5012 | 1811 |
| 6982 | 1812 if (image->filename) |
| 1813 gtk_file_selection_set_filename(GTK_FILE_SELECTION(sel), image->filename); | |
| 5967 | 1814 g_object_set_data(G_OBJECT(sel), "GtkIMHtmlImage", image); |
| 5012 | 1815 g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(sel)->ok_button), "clicked", |
| 1816 G_CALLBACK(write_img_to_file), sel); | |
| 1817 | |
| 1818 g_signal_connect_swapped(G_OBJECT(GTK_FILE_SELECTION(sel)->ok_button), "clicked", | |
| 1819 G_CALLBACK(gtk_widget_destroy), sel); | |
| 1820 g_signal_connect_swapped(G_OBJECT(GTK_FILE_SELECTION(sel)->cancel_button), "clicked", | |
| 1821 G_CALLBACK(gtk_widget_destroy), sel); | |
| 1822 | |
| 1823 gtk_widget_show(sel); | |
| 1824 } | |
| 1825 | |
| 5967 | 1826 static gboolean gtk_imhtml_image_clicked(GtkWidget *w, GdkEvent *event, GtkIMHtmlImage *image) |
| 5012 | 1827 { |
| 1828 GdkEventButton *event_button = (GdkEventButton *) event; | |
| 1829 | |
| 1830 if (event->type == GDK_BUTTON_RELEASE) { | |
| 1831 if(event_button->button == 3) { | |
| 1832 GtkWidget *img, *item, *menu; | |
| 1833 gchar *text = g_strdup_printf(_("_Save Image...")); | |
| 1834 menu = gtk_menu_new(); | |
| 1835 | |
| 1836 /* buttons and such */ | |
| 1837 img = gtk_image_new_from_stock(GTK_STOCK_SAVE, GTK_ICON_SIZE_MENU); | |
| 1838 item = gtk_image_menu_item_new_with_mnemonic(text); | |
| 1839 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), img); | |
| 5967 | 1840 g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(gtk_imhtml_image_save), image); |
| 5012 | 1841 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); |
| 1842 | |
| 1843 gtk_widget_show_all(menu); | |
| 1844 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, | |
| 1845 event_button->button, event_button->time); | |
| 1846 | |
| 1847 g_free(text); | |
| 1848 return TRUE; | |
| 1849 } | |
| 1850 } | |
| 1851 if(event->type == GDK_BUTTON_PRESS && event_button->button == 3) | |
| 1852 return TRUE; /* Clicking the right mouse button on a link shouldn't | |
| 1853 be caught by the regular GtkTextView menu */ | |
| 1854 else | |
| 1855 return FALSE; /* Let clicks go through if we didn't catch anything */ | |
| 1856 | |
| 1857 } | |
| 5967 | 1858 void gtk_imhtml_image_free(GtkIMHtmlScalable *scale) |
| 1859 { | |
| 1860 GtkIMHtmlImage *image = (GtkIMHtmlImage *)scale; | |
| 1861 | |
| 1862 g_object_unref(image->pixbuf); | |
| 6982 | 1863 if (image->filename) |
| 1864 g_free(image->filename); | |
| 5967 | 1865 g_free(scale); |
| 1866 } | |
| 1867 | |
| 1868 void gtk_imhtml_image_add_to(GtkIMHtmlScalable *scale, GtkIMHtml *imhtml, GtkTextIter *iter) | |
| 1869 { | |
| 1870 GtkIMHtmlImage *image = (GtkIMHtmlImage *)scale; | |
| 1871 GtkWidget *box = gtk_event_box_new(); | |
| 1872 GtkTextChildAnchor *anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, iter); | |
| 1873 | |
| 1874 gtk_container_add(GTK_CONTAINER(box), GTK_WIDGET(image->image)); | |
| 1875 | |
| 1876 gtk_widget_show(GTK_WIDGET(image->image)); | |
| 1877 gtk_widget_show(box); | |
| 1878 | |
| 1879 gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(imhtml), box, anchor); | |
| 1880 g_signal_connect(G_OBJECT(box), "event", G_CALLBACK(gtk_imhtml_image_clicked), image); | |
| 1881 } | |
| 1882 | |
| 1883 GtkIMHtmlScalable *gtk_imhtml_hr_new() | |
| 1884 { | |
| 1885 GtkIMHtmlHr *hr = g_malloc(sizeof(GtkIMHtmlHr)); | |
| 1886 | |
| 1887 GTK_IMHTML_SCALABLE(hr)->scale = gtk_imhtml_hr_scale; | |
| 1888 GTK_IMHTML_SCALABLE(hr)->add_to = gtk_imhtml_hr_add_to; | |
| 1889 GTK_IMHTML_SCALABLE(hr)->free = gtk_imhtml_hr_free; | |
| 1890 | |
| 1891 hr->sep = gtk_hseparator_new(); | |
| 1892 gtk_widget_set_size_request(hr->sep, 5000, 2); | |
| 1893 gtk_widget_show(hr->sep); | |
| 1894 | |
| 1895 return GTK_IMHTML_SCALABLE(hr); | |
| 1896 } | |
| 1897 | |
| 1898 void gtk_imhtml_hr_scale(GtkIMHtmlScalable *scale, int width, int height) | |
| 1899 { | |
| 1900 gtk_widget_set_size_request(((GtkIMHtmlHr *)scale)->sep, width, 2); | |
| 1901 } | |
| 1902 | |
| 1903 void gtk_imhtml_hr_add_to(GtkIMHtmlScalable *scale, GtkIMHtml *imhtml, GtkTextIter *iter) | |
| 1904 { | |
| 1905 GtkIMHtmlHr *hr = (GtkIMHtmlHr *)scale; | |
| 1906 GtkTextChildAnchor *anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, iter); | |
| 1907 | |
| 1908 gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(imhtml), hr->sep, anchor); | |
| 1909 } | |
| 1910 | |
| 1911 void gtk_imhtml_hr_free(GtkIMHtmlScalable *scale) | |
| 1912 { | |
| 1913 g_free(scale); | |
| 1914 } | |
| 7295 | 1915 |
| 1916 gboolean gtk_imhtml_search_find(GtkIMHtml *imhtml, const gchar *text) | |
| 1917 { | |
| 1918 GtkTextIter iter, start, end; | |
| 1919 gboolean new_search = TRUE; | |
| 1920 | |
| 1921 g_return_val_if_fail(imhtml != NULL, FALSE); | |
| 1922 g_return_val_if_fail(text != NULL, FALSE); | |
| 1923 | |
| 1924 if (imhtml->search_string && !strcmp(text, imhtml->search_string)) | |
| 1925 new_search = FALSE; | |
| 1926 | |
| 1927 | |
| 1928 if (new_search) { | |
| 1929 gtk_imhtml_search_clear(imhtml); | |
| 1930 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &iter); | |
| 1931 } else { | |
| 1932 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, | |
| 1933 gtk_text_buffer_get_mark(imhtml->text_buffer, "search")); | |
| 1934 } | |
| 1935 imhtml->search_string = g_strdup(text); | |
| 1936 | |
| 7358 | 1937 if (gtk_source_iter_forward_search(&iter, imhtml->search_string, |
| 1938 GTK_SOURCE_SEARCH_VISIBLE_ONLY | GTK_SOURCE_SEARCH_CASE_INSENSITIVE, | |
| 7295 | 1939 &start, &end, NULL)) { |
| 1940 | |
| 1941 gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(imhtml), &start, 0, TRUE, 0, 0); | |
| 1942 gtk_text_buffer_create_mark(imhtml->text_buffer, "search", &end, FALSE); | |
| 1943 if (new_search) { | |
| 1944 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "search", &iter, &end); | |
| 1945 do | |
| 1946 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "search", &start, &end); | |
| 7358 | 1947 while (gtk_source_iter_forward_search(&end, imhtml->search_string, |
| 1948 GTK_SOURCE_SEARCH_VISIBLE_ONLY | | |
| 1949 GTK_SOURCE_SEARCH_CASE_INSENSITIVE, | |
| 7295 | 1950 &start, &end, NULL)); |
| 1951 } | |
| 1952 return TRUE; | |
| 1953 } | |
| 1954 return FALSE; | |
| 1955 } | |
| 1956 | |
| 1957 void gtk_imhtml_search_clear(GtkIMHtml *imhtml) | |
| 1958 { | |
| 1959 GtkTextIter start, end; | |
| 1960 | |
| 1961 g_return_if_fail(imhtml != NULL); | |
| 1962 | |
| 1963 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start); | |
| 1964 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end); | |
| 1965 | |
| 1966 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "search", &start, &end); | |
| 1967 if (imhtml->search_string) | |
| 1968 g_free(imhtml->search_string); | |
| 1969 imhtml->search_string = NULL; | |
| 1970 } | |
| 7694 | 1971 |
| 1972 /* Editable stuff */ | |
| 1973 static void insert_cb(GtkTextBuffer *buffer, GtkTextIter *iter, gchar *text, gint len, GtkIMHtml *imhtml) | |
| 1974 { | |
| 1975 GtkIMHtmlFormatSpan *span = NULL; | |
| 7734 | 1976 GtkTextIter end; |
| 1977 | |
| 7717 | 1978 gtk_text_iter_forward_chars(iter, len); |
| 7734 | 1979 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end); |
| 1980 gtk_text_iter_forward_char(&end); | |
| 1981 | |
| 1982 if (!gtk_text_iter_equal(&end, iter)) | |
| 1983 return; | |
| 7694 | 1984 |
| 1985 if (!imhtml->editable) | |
| 1986 return; | |
| 1987 | |
| 1988 if ((span = imhtml->edit.bold)) { | |
| 1989 GtkTextIter bold; | |
| 1990 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &bold, span->start); | |
| 1991 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "BOLD", &bold, iter); | |
| 1992 } | |
| 7729 | 1993 |
| 7694 | 1994 if ((span = imhtml->edit.italic)) { |
| 1995 GtkTextIter italic; | |
| 1996 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &italic, span->start); | |
| 7729 | 1997 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "ITALICS", &italic, |
| 1998 iter); | |
| 7694 | 1999 } |
| 7729 | 2000 |
| 2001 if ((span = imhtml->edit.underline)) { | |
| 2002 GtkTextIter underline; | |
| 2003 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &underline, span->start); | |
| 2004 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "UNDERLINE", &underline, | |
| 2005 iter); | |
| 2006 } | |
| 2007 | |
| 7714 | 2008 if ((span = imhtml->edit.forecolor)) { |
| 2009 GtkTextIter fore; | |
| 2010 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &fore, span->start); | |
| 2011 gtk_text_buffer_apply_tag(imhtml->text_buffer, span->tag, &fore, iter); | |
| 7694 | 2012 } |
| 7729 | 2013 |
| 7714 | 2014 if ((span = imhtml->edit.backcolor)) { |
| 2015 GtkTextIter back; | |
| 2016 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &back, span->start); | |
| 2017 gtk_text_buffer_apply_tag(imhtml->text_buffer, span->tag, &back, iter); | |
| 2018 } | |
| 7729 | 2019 |
| 7717 | 2020 if ((span = imhtml->edit.fontface)) { |
| 2021 GtkTextIter face; | |
| 2022 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &face, span->start); | |
| 2023 gtk_text_buffer_apply_tag(imhtml->text_buffer, span->tag, &face, iter); | |
| 2024 } | |
| 7740 | 2025 |
| 2026 if ((span = imhtml->edit.sizespan)) { | |
| 2027 GtkTextIter size; | |
| 2028 /* We create the tags here so that one can grow font or shrink font several times | |
| 2029 * in a row without creating unnecessary tags */ | |
| 2030 if (span->tag == NULL) { | |
| 2031 span->tag = gtk_text_buffer_create_tag | |
| 2032 (imhtml->text_buffer, NULL, "size-points", (double)_point_sizes [imhtml->edit.fontsize-1], NULL); | |
| 2033 span->start_tag = g_strdup_printf("<font size='%d'>", imhtml->edit.fontsize); | |
| 2034 span->end_tag = g_strdup("</font>"); | |
| 2035 } | |
| 2036 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &size, span->start); | |
| 2037 gtk_text_buffer_apply_tag(imhtml->text_buffer, span->tag, &size, iter); | |
| 2038 } | |
| 7694 | 2039 } |
| 2040 | |
| 2041 void gtk_imhtml_set_editable(GtkIMHtml *imhtml, gboolean editable) | |
| 2042 { | |
| 2043 gtk_text_view_set_editable(GTK_TEXT_VIEW(imhtml), editable); | |
| 2044 gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(imhtml), editable); | |
| 2045 imhtml->editable = editable; | |
| 2046 } | |
| 2047 | |
| 2048 gboolean gtk_imhtml_get_editable(GtkIMHtml *imhtml) | |
| 2049 { | |
| 2050 return imhtml->editable; | |
| 2051 } | |
| 2052 | |
| 2053 gboolean gtk_imhtml_toggle_bold(GtkIMHtml *imhtml) | |
| 2054 { | |
| 7707 | 2055 GtkIMHtmlFormatSpan *span; |
| 7694 | 2056 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); |
| 2057 GtkTextIter iter; | |
| 2058 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins); | |
| 2059 if (!imhtml->edit.bold) { | |
| 7707 | 2060 span = g_malloc(sizeof(GtkIMHtmlFormatSpan)); |
| 7694 | 2061 span->start = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); |
| 2062 span->start_tag = g_strdup("<b>"); | |
| 2063 span->end = NULL; | |
| 2064 span->end_tag = g_strdup("</b>"); | |
| 2065 span->buffer = imhtml->text_buffer; | |
| 7714 | 2066 span->tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), "BOLD"); |
| 7694 | 2067 imhtml->edit.bold = span; |
| 2068 imhtml->format_spans = g_list_append(imhtml->format_spans, span); | |
| 2069 } else { | |
| 2070 span = imhtml->edit.bold; | |
| 2071 span->end = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); | |
| 2072 imhtml->edit.bold = NULL; | |
| 2073 } | |
| 2074 return imhtml->edit.bold != NULL; | |
| 2075 } | |
| 2076 | |
| 2077 gboolean gtk_imhtml_toggle_italic(GtkIMHtml *imhtml) | |
| 2078 { | |
| 7707 | 2079 GtkIMHtmlFormatSpan *span; |
| 7694 | 2080 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); |
| 2081 GtkTextIter iter; | |
| 2082 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins); | |
| 2083 if (!imhtml->edit.italic) { | |
| 7707 | 2084 span = g_malloc(sizeof(GtkIMHtmlFormatSpan)); |
| 7694 | 2085 span->start = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); |
| 2086 span->start_tag = g_strdup("<i>"); | |
| 2087 span->end = NULL; | |
| 2088 span->end_tag = g_strdup("</i>"); | |
| 2089 span->buffer = imhtml->text_buffer; | |
| 7714 | 2090 span->tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), "ITALIC"); |
| 7694 | 2091 imhtml->edit.italic = span; |
| 2092 imhtml->format_spans = g_list_append(imhtml->format_spans, span); | |
| 2093 } else { | |
| 2094 span = imhtml->edit.italic; | |
| 2095 span->end = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); | |
| 2096 imhtml->edit.italic = NULL; | |
| 2097 } | |
| 2098 return imhtml->edit.italic != NULL; | |
| 2099 } | |
| 7714 | 2100 |
| 7694 | 2101 gboolean gtk_imhtml_toggle_underline(GtkIMHtml *imhtml) |
| 2102 { | |
| 7707 | 2103 GtkIMHtmlFormatSpan *span; |
| 7694 | 2104 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); |
| 2105 GtkTextIter iter; | |
| 2106 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins); | |
| 2107 if (!imhtml->edit.underline) { | |
| 7707 | 2108 span = g_malloc(sizeof(GtkIMHtmlFormatSpan)); |
| 7694 | 2109 span->start = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); |
| 2110 span->start_tag = g_strdup("<u>"); | |
| 2111 span->end = NULL; | |
| 2112 span->end_tag = g_strdup("</u>"); | |
| 2113 span->buffer = imhtml->text_buffer; | |
| 7714 | 2114 span->tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), "UNDERLINE"); |
| 7694 | 2115 imhtml->edit.underline = span; |
| 2116 imhtml->format_spans = g_list_append(imhtml->format_spans, span); | |
| 2117 } else { | |
| 7697 | 2118 span = imhtml->edit.underline; |
| 7694 | 2119 span->end = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); |
| 2120 imhtml->edit.underline = NULL; | |
| 2121 } | |
| 2122 return imhtml->edit.underline != NULL; | |
| 2123 } | |
| 2124 | |
| 7740 | 2125 void gtk_imhtml_font_shrink(GtkIMHtml *imhtml) |
| 2126 { | |
| 2127 GtkIMHtmlFormatSpan *span; | |
| 2128 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); | |
| 2129 GtkTextIter iter; | |
| 2130 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins); | |
| 2131 if (imhtml->edit.fontsize == 1) | |
| 2132 return; | |
| 2133 | |
| 2134 imhtml->edit.fontsize--; | |
| 2135 | |
| 2136 if (imhtml->edit.sizespan) { | |
| 2137 GtkTextIter iter2; | |
| 2138 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter2, imhtml->edit.sizespan->start); | |
| 2139 if (gtk_text_iter_equal(&iter2, &iter)) | |
| 2140 return; | |
| 2141 span = imhtml->edit.sizespan; | |
| 2142 span->end = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); | |
| 2143 } | |
| 2144 | |
| 2145 span = g_malloc(sizeof(GtkIMHtmlFormatSpan)); | |
| 2146 span->start = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); | |
| 2147 span->end = NULL; | |
| 2148 span->buffer = imhtml->text_buffer; | |
| 2149 span->tag = NULL; | |
| 2150 imhtml->edit.sizespan = span; | |
| 2151 imhtml->format_spans = g_list_append(imhtml->format_spans, span); | |
| 2152 } | |
| 2153 | |
| 2154 void gtk_imhtml_font_grow(GtkIMHtml *imhtml) | |
| 2155 { | |
| 2156 GtkIMHtmlFormatSpan *span; | |
| 2157 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); | |
| 2158 GtkTextIter iter; | |
| 2159 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins); | |
| 2160 if (imhtml->edit.fontsize == MAX_FONT_SIZE) | |
| 2161 return; | |
| 2162 | |
| 2163 imhtml->edit.fontsize++; | |
| 2164 | |
| 2165 if (imhtml->edit.sizespan) { | |
| 2166 GtkTextIter iter2; | |
| 2167 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter2, imhtml->edit.sizespan->start); | |
| 2168 if (gtk_text_iter_equal(&iter2, &iter)) | |
| 2169 return; | |
| 2170 span = imhtml->edit.sizespan; | |
| 2171 span->end = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); | |
| 2172 } | |
| 2173 | |
| 2174 span = g_malloc(sizeof(GtkIMHtmlFormatSpan)); | |
| 2175 span->start = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); | |
| 2176 span->end = NULL; | |
| 2177 span->tag = NULL; | |
| 2178 span->buffer = imhtml->text_buffer; | |
| 2179 imhtml->edit.sizespan = span; | |
| 2180 imhtml->format_spans = g_list_append(imhtml->format_spans, span); | |
| 2181 } | |
| 2182 | |
| 7714 | 2183 gboolean gtk_imhtml_toggle_forecolor(GtkIMHtml *imhtml, const char *color) |
| 2184 { | |
| 2185 GtkIMHtmlFormatSpan *span; | |
| 2186 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); | |
| 2187 GtkTextIter iter; | |
| 2188 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins); | |
| 2189 if (!imhtml->edit.forecolor) { | |
| 2190 span = g_malloc(sizeof(GtkIMHtmlFormatSpan)); | |
| 2191 span->start = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); | |
| 2192 span->start_tag = g_strdup_printf("<font color='%s'>", color); | |
| 2193 span->end = NULL; | |
| 2194 span->end_tag = g_strdup("</font>"); | |
| 2195 span->buffer = imhtml->text_buffer; | |
| 2196 span->tag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "foreground", color, NULL); | |
| 2197 imhtml->edit.forecolor = span; | |
| 2198 imhtml->format_spans = g_list_append(imhtml->format_spans, span); | |
| 2199 } else { | |
| 2200 span = imhtml->edit.forecolor; | |
| 2201 span->end = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); | |
| 2202 imhtml->edit.forecolor = NULL; | |
| 2203 } | |
| 2204 return imhtml->edit.forecolor != NULL; | |
| 2205 } | |
| 2206 | |
| 2207 gboolean gtk_imhtml_toggle_backcolor(GtkIMHtml *imhtml, const char *color) | |
| 2208 { | |
| 2209 GtkIMHtmlFormatSpan *span; | |
| 2210 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); | |
| 2211 GtkTextIter iter; | |
| 2212 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins); | |
| 2213 if (!imhtml->edit.backcolor) { | |
| 2214 span = g_malloc(sizeof(GtkIMHtmlFormatSpan)); | |
| 2215 span->start = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); | |
| 2216 span->start_tag = g_strdup_printf("<body bgcolor='%s'>", color); | |
| 2217 span->end = NULL; | |
| 2218 span->end_tag = g_strdup("</font>"); | |
| 2219 span->buffer = imhtml->text_buffer; | |
| 2220 span->tag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "background", color, NULL); | |
| 2221 imhtml->edit.backcolor = span; | |
| 2222 imhtml->format_spans = g_list_append(imhtml->format_spans, span); | |
| 2223 } else { | |
| 2224 span = imhtml->edit.backcolor; | |
| 2225 span->end = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); | |
| 2226 imhtml->edit.backcolor = NULL; | |
| 2227 } | |
| 2228 return imhtml->edit.backcolor != NULL; | |
| 2229 } | |
| 2230 | |
| 7717 | 2231 gboolean gtk_imhtml_toggle_fontface(GtkIMHtml *imhtml, const char *face) |
| 2232 { | |
| 2233 GtkIMHtmlFormatSpan *span; | |
| 2234 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); | |
| 2235 GtkTextIter iter; | |
| 2236 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins); | |
| 2237 if (!imhtml->edit.fontface) { | |
| 2238 span = g_malloc(sizeof(GtkIMHtmlFormatSpan)); | |
| 2239 span->start = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); | |
| 2240 span->start_tag = g_strdup_printf("<font face='%s'>", face); | |
| 2241 span->end = NULL; | |
| 2242 span->end_tag = g_strdup("</font>"); | |
| 2243 span->buffer = imhtml->text_buffer; | |
| 2244 span->tag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "family", face, NULL); | |
| 2245 imhtml->edit.fontface = span; | |
| 2246 imhtml->format_spans = g_list_append(imhtml->format_spans, span); | |
| 2247 } else { | |
| 2248 span = imhtml->edit.fontface; | |
| 2249 span->end = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); | |
| 2250 imhtml->edit.fontface = NULL; | |
| 2251 } | |
| 2252 return imhtml->edit.fontface != NULL; | |
| 2253 } | |
| 2254 | |
| 7707 | 2255 void gtk_imhtml_insert_link(GtkIMHtml *imhtml, const char *url, const char *text) |
| 2256 { | |
| 2257 GtkIMHtmlFormatSpan *span = g_malloc(sizeof(GtkIMHtmlFormatSpan)); | |
| 2258 GtkTextMark *mark = gtk_text_buffer_get_insert(imhtml->text_buffer); | |
| 2259 GtkTextIter iter; | |
| 2260 GtkTextTag *tag, *linktag; | |
| 2261 | |
| 2262 tag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, NULL); | |
| 2263 g_object_set_data(G_OBJECT(tag), "link_url", g_strdup(url)); | |
| 2264 | |
| 2265 linktag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), "LINK"); | |
| 2266 | |
| 2267 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, mark); | |
| 2268 span->start = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); | |
| 2269 span->buffer = imhtml->text_buffer; | |
| 2270 span->start_tag = g_strdup_printf("<a href='%s'>", url); | |
| 2271 span->end_tag = g_strdup("</a>"); | |
| 2272 | |
| 2273 gtk_text_buffer_insert_with_tags(imhtml->text_buffer, &iter, text, strlen(text), linktag, tag, NULL); | |
| 2274 span->end = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); | |
| 2275 imhtml->format_spans = g_list_append(imhtml->format_spans, span); | |
| 2276 } | |
| 2277 | |
| 7736 | 2278 void gtk_imhtml_insert_smiley(GtkIMHtml *imhtml, const char *sml, char *smiley) |
| 7735 | 2279 { |
| 2280 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); | |
| 2281 GtkTextIter iter; | |
| 2282 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins); | |
| 2283 GdkPixbuf *pixbuf = NULL; | |
| 2284 GdkPixbufAnimation *annipixbuf = NULL; | |
| 2285 GtkWidget *icon = NULL; | |
| 2286 | |
| 2287 GtkTextChildAnchor *anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, &iter); | |
| 2288 g_object_set_data(G_OBJECT(anchor), "text_tag", smiley); | |
| 7736 | 2289 annipixbuf = gtk_smiley_tree_image(imhtml, sml, smiley); |
| 7735 | 2290 if(annipixbuf) { |
| 2291 if(gdk_pixbuf_animation_is_static_image(annipixbuf)) { | |
| 2292 pixbuf = gdk_pixbuf_animation_get_static_image(annipixbuf); | |
| 2293 if(pixbuf) | |
| 2294 icon = gtk_image_new_from_pixbuf(pixbuf); | |
| 2295 } else { | |
| 2296 icon = gtk_image_new_from_animation(annipixbuf); | |
| 2297 } | |
| 2298 } | |
| 2299 | |
| 2300 if (icon) { | |
| 2301 gtk_widget_show(icon); | |
| 2302 gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(imhtml), icon, anchor); | |
| 2303 #if GTK_CHECK_VERSION(2,2,0) | |
| 2304 gtk_imhtml_copyable_new(imhtml, | |
| 2305 gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE), | |
| 2306 smiley); | |
| 2307 #endif | |
| 2308 } | |
| 2309 } | |
| 2310 | |
| 7694 | 2311 int span_compare_begin(const GtkIMHtmlFormatSpan *a, const GtkIMHtmlFormatSpan *b, GtkTextBuffer *buffer) |
| 2312 { | |
| 2313 GtkTextIter ia, ib; | |
| 2314 gtk_text_buffer_get_iter_at_mark(buffer, &ia, a->start); | |
| 2315 gtk_text_buffer_get_iter_at_mark(buffer, &ib, b->start); | |
| 2316 return gtk_text_iter_compare(&ia, &ib); | |
| 2317 } | |
| 2318 | |
| 2319 int span_compare_end(GtkIMHtmlFormatSpan *a, GtkIMHtmlFormatSpan *b) | |
| 2320 { | |
| 2321 GtkTextIter ia, ib; | |
| 2322 gtk_text_buffer_get_iter_at_mark(a->buffer, &ia, a->start); | |
| 2323 gtk_text_buffer_get_iter_at_mark(b->buffer, &ib, b->start); | |
| 2324 return gtk_text_iter_compare(&ia, &ib); | |
| 2325 } | |
| 2326 | |
| 2327 /* Basic notion here: traverse through the text buffer one-by-one, non-character elements, such | |
| 2328 * as smileys and IM images are represented by the Unicode "unknown" character. Handle them. Else | |
| 2329 * check the list of formatted strings, sorted by the position of the starting tags and apply them as | |
| 2330 * needed. After applying the start tags, add the end tags to the "closers" list, which is sorted by | |
| 2331 * location of ending tags. These get applied in a similar fashion. Finally, replace <, >, &, and " | |
| 2332 * with their HTML equivilent. */ | |
| 2333 char *gtk_imhtml_get_markup(GtkIMHtml *imhtml) | |
| 2334 { | |
| 2335 gunichar c; | |
| 2336 GtkIMHtmlFormatSpan *sspan = NULL, *espan = NULL; | |
| 2337 GtkTextIter iter, siter, eiter; | |
| 2338 GList *starters = imhtml->format_spans; | |
| 2339 GList *closers = NULL;; | |
| 2340 GString *str = g_string_new(""); | |
| 2341 g_list_sort_with_data(starters, (GCompareDataFunc)span_compare_begin, imhtml->text_buffer); | |
| 2342 | |
| 2343 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &iter); | |
| 2344 | |
| 2345 /* Initialize these to the end iter */ | |
| 2346 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &siter); | |
| 2347 eiter = siter; | |
| 2348 | |
| 2349 if (starters) { | |
| 2350 sspan = (GtkIMHtmlFormatSpan*)starters->data; | |
| 2351 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &siter, sspan->start); | |
| 2352 } | |
| 2353 | |
| 2354 while ((c = gtk_text_iter_get_char(&iter)) != 0) { | |
| 2355 if (c == 0xFFFC) { | |
| 7735 | 2356 GtkTextChildAnchor* anchor = gtk_text_iter_get_child_anchor(&iter); |
| 2357 char *text = g_object_get_data(G_OBJECT(anchor), "text_tag"); | |
| 2358 str = g_string_append(str, text); | |
| 7694 | 2359 } else { |
| 2360 while (gtk_text_iter_equal(&eiter, &iter)) { | |
| 2361 /* This is where we shall insert the ending tag of | |
| 2362 * this format span */ | |
| 2363 str = g_string_append(str, espan->end_tag); | |
| 2364 closers = g_list_remove(closers, espan); | |
| 2365 if (closers) { | |
| 2366 espan = (GtkIMHtmlFormatSpan*)closers->data; | |
| 2367 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &eiter, espan->end); | |
| 2368 } else { | |
| 2369 espan = NULL; | |
| 2370 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &eiter); | |
| 2371 } | |
| 2372 } | |
| 2373 while (gtk_text_iter_equal(&siter, &iter)) { | |
| 2374 /* This is where we shall insert the starting tag of | |
| 2375 * this format span */ | |
| 2376 str = g_string_append(str, sspan->start_tag); | |
| 2377 if (sspan->end) { | |
| 2378 espan = sspan; | |
| 2379 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &eiter, espan->end); | |
| 2380 closers = g_list_insert_sorted(closers, sspan, (GCompareFunc)span_compare_end); | |
| 2381 } | |
| 2382 starters = starters->next; | |
| 2383 if (starters) { | |
| 2384 sspan = (GtkIMHtmlFormatSpan*)starters->data; | |
| 2385 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &siter, sspan->start); | |
| 2386 } else { | |
| 2387 sspan = NULL; | |
| 2388 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &siter); | |
| 2389 } | |
| 2390 | |
| 2391 } | |
| 7715 | 2392 |
| 2393 if (c == '<') | |
| 2394 str = g_string_append(str, "<"); | |
| 2395 else if (c == '>') | |
| 2396 str = g_string_append(str, ">"); | |
| 2397 else if (c == '&') | |
| 2398 str = g_string_append(str, "&"); | |
| 2399 else if (c == '"') | |
| 2400 str = g_string_append(str, """); | |
| 7716 | 2401 else |
| 2402 str = g_string_append_unichar(str, c); | |
| 7694 | 2403 } |
| 2404 gtk_text_iter_forward_char(&iter); | |
| 2405 } | |
| 2406 return g_string_free(str, FALSE); | |
| 2407 } | |
| 2408 | |
| 2409 char *gtk_imhtml_get_text(GtkIMHtml *imhtml) | |
| 2410 { | |
| 2411 GtkTextIter start_iter, end_iter; | |
| 2412 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start_iter); | |
| 2413 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end_iter); | |
| 2414 return gtk_text_buffer_get_text(imhtml->text_buffer, &start_iter, &end_iter, FALSE); | |
| 2415 | |
| 2416 } |
