Mercurial > pidgin
annotate src/gtkimhtml.c @ 8622:ffed55cbdd67
[gaim-migrate @ 9373]
Any objections to this?
committer: Tailor Script <tailor@pidgin.im>
| author | Mark Doliner <mark@kingant.net> |
|---|---|
| date | Fri, 09 Apr 2004 02:49:30 +0000 |
| parents | 7f7679853f7b |
| children | 44d6285a87af |
| rev | line source |
|---|---|
| 1428 | 1 /* |
| 2 * GtkIMHtml | |
| 3 * | |
| 8046 | 4 * Gaim is the legal property of its developers, whose names are too numerous |
| 5 * to list here. Please refer to the COPYRIGHT file distributed with this | |
| 6 * source distribution. | |
| 1428 | 7 * |
| 8 * This program is free software; you can redistribute it and/or modify | |
| 9 * under the terms of the GNU General Public License as published by | |
| 10 * the Free Software Foundation; either version 2 of the License, or | |
| 11 * (at your option) any later version. | |
| 12 * | |
| 13 * This program is distributed in the hope that it will be useful, | |
| 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 16 * GNU General Public License for more details. | |
| 17 * | |
| 18 * You should have received a copy of the GNU General Public License | |
| 19 * along with this program; if not, write to the Free Software | |
| 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 21 * | |
| 22 */ | |
| 23 | |
|
2541
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
24 #ifdef HAVE_CONFIG_H |
|
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
25 #include <config.h> |
|
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
26 #endif |
| 8526 | 27 #include "debug.h" |
| 8091 | 28 #include "util.h" |
| 1428 | 29 #include "gtkimhtml.h" |
| 7358 | 30 #include "gtksourceiter.h" |
| 1428 | 31 #include <gtk/gtk.h> |
| 4895 | 32 #include <glib/gerror.h> |
| 4046 | 33 #include <gdk/gdkkeysyms.h> |
| 1428 | 34 #include <string.h> |
| 35 #include <ctype.h> | |
| 36 #include <stdio.h> | |
| 4629 | 37 #include <stdlib.h> |
| 1428 | 38 #include <math.h> |
|
2541
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
39 #ifdef HAVE_LANGINFO_CODESET |
|
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
40 #include <langinfo.h> |
|
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
41 #include <locale.h> |
|
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2365
diff
changeset
|
42 #endif |
| 1428 | 43 |
| 4417 | 44 #ifdef ENABLE_NLS |
| 45 # include <libintl.h> | |
| 46 # define _(x) gettext(x) | |
| 47 # ifdef gettext_noop | |
| 48 # define N_(String) gettext_noop (String) | |
| 49 # else | |
| 50 # define N_(String) (String) | |
| 51 # endif | |
| 52 #else | |
| 53 # define N_(String) (String) | |
| 54 # define _(x) (x) | |
| 55 #endif | |
| 56 | |
| 4735 | 57 #include <pango/pango-font.h> |
| 58 | |
| 5105 | 59 /* GTK+ < 2.2.2 hack, see ui.h for details. */ |
| 60 #ifndef GTK_WRAP_WORD_CHAR | |
| 61 #define GTK_WRAP_WORD_CHAR GTK_WRAP_WORD | |
| 62 #endif | |
| 63 | |
| 4735 | 64 #define TOOLTIP_TIMEOUT 500 |
| 65 | |
| 8061 | 66 static void insert_cb(GtkTextBuffer *buffer, GtkTextIter *iter, gchar *text, gint len, GtkIMHtml *imhtml); |
| 8505 | 67 static gboolean gtk_imhtml_is_amp_escape (const gchar *string, gchar **replace, gint *length); |
| 8061 | 68 void gtk_imhtml_close_tags(GtkIMHtml *imhtml); |
| 8091 | 69 static void gtk_imhtml_link_drag_rcv_cb(GtkWidget *widget, GdkDragContext *dc, guint x, guint y, GtkSelectionData *sd, guint info, guint t, GtkIMHtml *imhtml); |
| 8061 | 70 |
| 3922 | 71 /* POINT_SIZE converts from AIM font sizes to point sizes. It probably should be redone in such a |
| 72 * way that it base the sizes off the default font size rather than using arbitrary font sizes. */ | |
| 73 #define MAX_FONT_SIZE 7 | |
| 5367 | 74 #define POINT_SIZE(x) (options & GTK_IMHTML_USE_POINTSIZE ? x : _point_sizes [MIN ((x), MAX_FONT_SIZE) - 1]) |
| 8380 | 75 static gdouble _point_sizes [] = { .69444444, .8333333, 1, 1.2, 1.44, 1.728, 2.0736}; |
|
2349
60c716c32c40
[gaim-migrate @ 2362]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2348
diff
changeset
|
76 |
| 8498 | 77 enum { |
| 78 TARGET_HTML, | |
| 8061 | 79 TARGET_UTF8_STRING, |
| 80 TARGET_COMPOUND_TEXT, | |
| 81 TARGET_STRING, | |
| 82 TARGET_TEXT | |
| 83 }; | |
| 84 | |
| 8091 | 85 enum { |
| 86 DRAG_URL | |
| 87 }; | |
| 88 | |
| 8420 | 89 enum { |
| 90 URL_CLICKED, | |
| 91 BUTTONS_UPDATE, | |
| 92 TOGGLE_FORMAT, | |
| 8427 | 93 CLEAR_FORMAT, |
| 8506 | 94 UPDATE_FORMAT, |
| 8420 | 95 LAST_SIGNAL |
| 96 }; | |
| 97 static guint signals [LAST_SIGNAL] = { 0 }; | |
| 98 | |
| 8061 | 99 GtkTargetEntry selection_targets[] = { |
| 8566 | 100 { "text/html", 0, TARGET_HTML }, |
| 8061 | 101 { "UTF8_STRING", 0, TARGET_UTF8_STRING }, |
| 102 { "COMPOUND_TEXT", 0, TARGET_COMPOUND_TEXT }, | |
| 103 { "STRING", 0, TARGET_STRING }, | |
| 104 { "TEXT", 0, TARGET_TEXT}}; | |
| 105 | |
| 8091 | 106 GtkTargetEntry link_drag_drop_targets[] = { |
| 107 {"x-url/ftp", 0, DRAG_URL}, | |
| 108 {"x-url/http", 0, DRAG_URL}, | |
| 109 {"text/uri-list", 0, DRAG_URL}, | |
| 110 {"_NETSCAPE_URL", 0, DRAG_URL}}; | |
| 111 | |
| 4032 | 112 static GtkSmileyTree* |
| 113 gtk_smiley_tree_new () | |
| 114 { | |
| 115 return g_new0 (GtkSmileyTree, 1); | |
| 116 } | |
| 117 | |
| 118 static void | |
| 119 gtk_smiley_tree_insert (GtkSmileyTree *tree, | |
| 4263 | 120 GtkIMHtmlSmiley *smiley) |
| 4032 | 121 { |
| 122 GtkSmileyTree *t = tree; | |
| 4263 | 123 const gchar *x = smiley->smile; |
| 4032 | 124 |
| 125 if (!strlen (x)) | |
| 126 return; | |
| 127 | |
| 128 while (*x) { | |
| 129 gchar *pos; | |
| 130 gint index; | |
| 131 | |
| 132 if (!t->values) | |
| 133 t->values = g_string_new (""); | |
| 134 | |
| 135 pos = strchr (t->values->str, *x); | |
| 136 if (!pos) { | |
| 137 t->values = g_string_append_c (t->values, *x); | |
| 138 index = t->values->len - 1; | |
| 139 t->children = g_realloc (t->children, t->values->len * sizeof (GtkSmileyTree *)); | |
| 140 t->children [index] = g_new0 (GtkSmileyTree, 1); | |
| 141 } else | |
| 7386 | 142 index = GPOINTER_TO_INT(pos) - GPOINTER_TO_INT(t->values->str); |
| 8061 | 143 |
| 4032 | 144 t = t->children [index]; |
| 8061 | 145 |
| 4032 | 146 x++; |
| 147 } | |
| 8061 | 148 |
| 4263 | 149 t->image = smiley; |
| 4032 | 150 } |
| 4041 | 151 |
| 4263 | 152 |
| 4264 | 153 void gtk_smiley_tree_destroy (GtkSmileyTree *tree) |
| 4032 | 154 { |
| 155 GSList *list = g_slist_append (NULL, tree); | |
| 156 | |
| 157 while (list) { | |
| 158 GtkSmileyTree *t = list->data; | |
| 159 gint i; | |
| 160 list = g_slist_remove(list, t); | |
| 7384 | 161 if (t && t->values) { |
| 4032 | 162 for (i = 0; i < t->values->len; i++) |
| 163 list = g_slist_append (list, t->children [i]); | |
| 164 g_string_free (t->values, TRUE); | |
| 165 g_free (t->children); | |
| 166 } | |
| 167 g_free (t); | |
| 168 } | |
| 169 } | |
| 170 | |
| 5967 | 171 static gboolean gtk_size_allocate_cb(GtkIMHtml *widget, GtkAllocation *alloc, gpointer user_data) |
| 172 { | |
| 173 GdkRectangle rect; | |
| 174 | |
| 175 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(widget), &rect); | |
| 176 if(widget->old_rect.width != rect.width || widget->old_rect.height != rect.height){ | |
| 177 GList *iter = GTK_IMHTML(widget)->scalables; | |
| 178 | |
| 179 while(iter){ | |
| 180 GtkIMHtmlScalable *scale = GTK_IMHTML_SCALABLE(iter->data); | |
| 181 scale->scale(scale, rect.width, rect.height); | |
| 182 | |
| 183 iter = iter->next; | |
| 184 } | |
| 185 } | |
| 186 | |
| 187 widget->old_rect = rect; | |
| 188 return FALSE; | |
| 189 } | |
| 190 | |
| 191 static gint | |
| 192 gtk_imhtml_tip_paint (GtkIMHtml *imhtml) | |
| 193 { | |
| 194 PangoLayout *layout; | |
| 195 | |
| 196 g_return_val_if_fail(GTK_IS_IMHTML(imhtml), FALSE); | |
| 197 | |
| 198 layout = gtk_widget_create_pango_layout(imhtml->tip_window, imhtml->tip); | |
| 199 | |
| 8061 | 200 gtk_paint_flat_box (imhtml->tip_window->style, imhtml->tip_window->window, |
| 5967 | 201 GTK_STATE_NORMAL, GTK_SHADOW_OUT, NULL, imhtml->tip_window, |
| 202 "tooltip", 0, 0, -1, -1); | |
| 203 | |
| 204 gtk_paint_layout (imhtml->tip_window->style, imhtml->tip_window->window, GTK_STATE_NORMAL, | |
| 205 FALSE, NULL, imhtml->tip_window, NULL, 4, 4, layout); | |
| 206 | |
| 207 g_object_unref(layout); | |
| 208 return FALSE; | |
| 209 } | |
| 210 | |
| 211 static gint | |
| 212 gtk_imhtml_tip (gpointer data) | |
| 213 { | |
| 214 GtkIMHtml *imhtml = data; | |
| 8526 | 215 PangoFontMetrics *font_metrics; |
| 5967 | 216 PangoLayout *layout; |
| 8526 | 217 PangoFont *font; |
| 5967 | 218 |
| 219 gint gap, x, y, h, w, scr_w, baseline_skip; | |
| 220 | |
| 221 g_return_val_if_fail(GTK_IS_IMHTML(imhtml), FALSE); | |
| 222 | |
| 223 if (!imhtml->tip || !GTK_WIDGET_DRAWABLE (GTK_WIDGET(imhtml))) { | |
| 224 imhtml->tip_timer = 0; | |
| 225 return FALSE; | |
| 226 } | |
| 8061 | 227 |
| 5967 | 228 if (imhtml->tip_window){ |
| 229 gtk_widget_destroy (imhtml->tip_window); | |
| 230 imhtml->tip_window = NULL; | |
| 231 } | |
| 232 | |
| 233 imhtml->tip_timer = 0; | |
| 234 imhtml->tip_window = gtk_window_new (GTK_WINDOW_POPUP); | |
| 235 gtk_widget_set_app_paintable (imhtml->tip_window, TRUE); | |
| 236 gtk_window_set_resizable (GTK_WINDOW (imhtml->tip_window), FALSE); | |
| 237 gtk_widget_set_name (imhtml->tip_window, "gtk-tooltips"); | |
| 238 g_signal_connect_swapped (G_OBJECT (imhtml->tip_window), "expose_event", | |
| 239 G_CALLBACK (gtk_imhtml_tip_paint), imhtml); | |
| 240 | |
| 241 gtk_widget_ensure_style (imhtml->tip_window); | |
| 242 layout = gtk_widget_create_pango_layout(imhtml->tip_window, imhtml->tip); | |
| 8526 | 243 font = pango_context_load_font(pango_layout_get_context(layout), |
| 244 imhtml->tip_window->style->font_desc); | |
| 245 | |
| 246 if (font == NULL) { | |
| 247 char *tmp = pango_font_description_to_string( | |
| 248 imhtml->tip_window->style->font_desc); | |
| 249 | |
| 250 gaim_debug(GAIM_DEBUG_ERROR, "gtk_imhtml_tip", | |
| 251 "pango_context_load_font() couldn't load font: '%s'\n", | |
| 252 tmp); | |
| 253 g_free(tmp); | |
| 254 | |
| 255 return FALSE; | |
| 256 | |
| 257 } | |
| 258 | |
| 259 font_metrics = pango_font_get_metrics(font, NULL); | |
| 8309 | 260 |
| 5967 | 261 |
| 262 pango_layout_get_pixel_size(layout, &scr_w, NULL); | |
| 8526 | 263 gap = PANGO_PIXELS((pango_font_metrics_get_ascent(font_metrics) + |
| 264 pango_font_metrics_get_descent(font_metrics))/ 4); | |
| 5967 | 265 |
| 266 if (gap < 2) | |
| 267 gap = 2; | |
| 8526 | 268 baseline_skip = PANGO_PIXELS(pango_font_metrics_get_ascent(font_metrics) + |
| 269 pango_font_metrics_get_descent(font_metrics)); | |
| 5967 | 270 w = 8 + scr_w; |
| 271 h = 8 + baseline_skip; | |
| 272 | |
| 273 gdk_window_get_pointer (NULL, &x, &y, NULL); | |
| 274 if (GTK_WIDGET_NO_WINDOW (GTK_WIDGET(imhtml))) | |
| 275 y += GTK_WIDGET(imhtml)->allocation.y; | |
| 276 | |
| 277 scr_w = gdk_screen_width(); | |
| 278 | |
| 279 x -= ((w >> 1) + 4); | |
| 280 | |
| 281 if ((x + w) > scr_w) | |
| 282 x -= (x + w) - scr_w; | |
| 283 else if (x < 0) | |
| 284 x = 0; | |
| 285 | |
| 8526 | 286 y = y + PANGO_PIXELS(pango_font_metrics_get_ascent(font_metrics) + |
| 287 pango_font_metrics_get_descent(font_metrics)); | |
| 5967 | 288 |
| 289 gtk_widget_set_size_request (imhtml->tip_window, w, h); | |
| 290 gtk_widget_show (imhtml->tip_window); | |
| 291 gtk_window_move (GTK_WINDOW(imhtml->tip_window), x, y); | |
| 292 | |
| 8526 | 293 pango_font_metrics_unref(font_metrics); |
| 5967 | 294 g_object_unref(layout); |
| 295 | |
| 296 return FALSE; | |
| 297 } | |
| 298 | |
| 299 gboolean gtk_motion_event_notify(GtkWidget *imhtml, GdkEventMotion *event, gpointer data) | |
| 8061 | 300 { |
| 5967 | 301 GtkTextIter iter; |
| 302 GdkWindow *win = event->window; | |
| 303 int x, y; | |
| 304 char *tip = NULL; | |
| 305 GSList *tags = NULL, *templist = NULL; | |
| 306 gdk_window_get_pointer(GTK_WIDGET(imhtml)->window, NULL, NULL, NULL); | |
| 307 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(imhtml), GTK_TEXT_WINDOW_WIDGET, | |
| 308 event->x, event->y, &x, &y); | |
| 309 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(imhtml), &iter, x, y); | |
| 310 tags = gtk_text_iter_get_tags(&iter); | |
| 311 | |
| 312 templist = tags; | |
| 313 while (templist) { | |
| 314 GtkTextTag *tag = templist->data; | |
| 315 tip = g_object_get_data(G_OBJECT(tag), "link_url"); | |
| 316 if (tip) | |
| 317 break; | |
| 318 templist = templist->next; | |
| 319 } | |
| 8061 | 320 |
| 5967 | 321 if (GTK_IMHTML(imhtml)->tip) { |
| 322 if ((tip == GTK_IMHTML(imhtml)->tip)) { | |
| 323 return FALSE; | |
| 324 } | |
| 325 /* We've left the cell. Remove the timeout and create a new one below */ | |
| 326 if (GTK_IMHTML(imhtml)->tip_window) { | |
| 327 gtk_widget_destroy(GTK_IMHTML(imhtml)->tip_window); | |
| 328 GTK_IMHTML(imhtml)->tip_window = NULL; | |
| 329 } | |
| 8061 | 330 if (GTK_IMHTML(imhtml)->editable) |
| 331 gdk_window_set_cursor(win, GTK_IMHTML(imhtml)->text_cursor); | |
| 332 else | |
| 333 gdk_window_set_cursor(win, GTK_IMHTML(imhtml)->arrow_cursor); | |
| 5967 | 334 if (GTK_IMHTML(imhtml)->tip_timer) |
| 335 g_source_remove(GTK_IMHTML(imhtml)->tip_timer); | |
| 336 GTK_IMHTML(imhtml)->tip_timer = 0; | |
| 337 } | |
| 8061 | 338 |
| 5967 | 339 if(tip){ |
| 8061 | 340 if (!GTK_IMHTML(imhtml)->editable) |
| 341 gdk_window_set_cursor(win, GTK_IMHTML(imhtml)->hand_cursor); | |
| 342 GTK_IMHTML(imhtml)->tip_timer = g_timeout_add (TOOLTIP_TIMEOUT, | |
| 5967 | 343 gtk_imhtml_tip, imhtml); |
| 344 } | |
| 8061 | 345 |
| 5967 | 346 GTK_IMHTML(imhtml)->tip = tip; |
| 347 g_slist_free(tags); | |
| 348 return FALSE; | |
| 349 } | |
| 350 | |
| 351 gboolean gtk_leave_event_notify(GtkWidget *imhtml, GdkEventCrossing *event, gpointer data) | |
| 352 { | |
| 353 /* when leaving the widget, clear any current & pending tooltips and restore the cursor */ | |
| 354 if (GTK_IMHTML(imhtml)->tip_window) { | |
| 355 gtk_widget_destroy(GTK_IMHTML(imhtml)->tip_window); | |
| 356 GTK_IMHTML(imhtml)->tip_window = NULL; | |
| 357 } | |
| 358 if (GTK_IMHTML(imhtml)->tip_timer) { | |
| 359 g_source_remove(GTK_IMHTML(imhtml)->tip_timer); | |
| 360 GTK_IMHTML(imhtml)->tip_timer = 0; | |
| 361 } | |
| 8061 | 362 if (GTK_IMHTML(imhtml)->editable) |
| 363 gdk_window_set_cursor(event->window, GTK_IMHTML(imhtml)->text_cursor); | |
| 364 else | |
| 365 gdk_window_set_cursor(event->window, GTK_IMHTML(imhtml)->arrow_cursor); | |
| 5967 | 366 |
| 8568 | 367 /* propagate the event normally */ |
| 5967 | 368 return FALSE; |
| 369 } | |
| 370 | |
| 6066 | 371 /* |
| 372 * XXX - This should be removed eventually. | |
| 373 * | |
| 8061 | 374 * This function exists to work around a gross bug in GtkTextView. |
| 375 * Basically, we short circuit ctrl+a and ctrl+end because they make | |
| 6066 | 376 * el program go boom. |
| 377 * | |
| 8061 | 378 * It's supposed to be fixed in gtk2.2. You can view the bug report at |
| 6066 | 379 * http://bugzilla.gnome.org/show_bug.cgi?id=107939 |
| 380 */ | |
| 8317 | 381 |
| 382 /* | |
| 383 * I'm adding some keyboard shortcuts too. | |
| 384 */ | |
| 385 | |
| 386 gboolean gtk_key_pressed_cb(GtkIMHtml *imhtml, GdkEventKey *event, gpointer data) | |
| 387 { | |
| 388 char buf[7]; | |
| 389 buf[0] = '\0'; | |
| 390 | |
| 6066 | 391 if (event->state & GDK_CONTROL_MASK) |
| 392 switch (event->keyval) { | |
| 8539 | 393 #if (!GTK_CHECK_VERSION(2,2,0)) |
| 8317 | 394 case 'a': |
| 395 return TRUE; | |
| 396 break; | |
| 397 | |
| 398 case GDK_Home: | |
| 399 return TRUE; | |
| 400 break; | |
| 401 | |
| 402 case GDK_End: | |
| 403 return TRUE; | |
| 404 break; | |
| 8539 | 405 #endif /* Gtk+ >= 2.2.0 */ |
| 8317 | 406 |
| 407 case 'b': /* ctrl-b is GDK_Left, which moves backwards. */ | |
| 408 case 'B': | |
| 8420 | 409 if (imhtml->format_functions & GTK_IMHTML_BOLD) { |
| 8456 | 410 if(imhtml->html_shortcuts) { |
| 411 gtk_imhtml_toggle_bold(imhtml); | |
| 8466 | 412 return TRUE; |
| 8456 | 413 } |
| 8420 | 414 } |
| 8466 | 415 return FALSE; |
| 8317 | 416 break; |
| 417 | |
| 418 case 'f': | |
| 419 case 'F': | |
| 420 /*set_toggle(gtkconv->toolbar.font, | |
| 421 !gtk_toggle_button_get_active( | |
| 422 GTK_TOGGLE_BUTTON(gtkconv->toolbar.font)));*/ | |
| 423 | |
| 424 return TRUE; | |
| 425 break; | |
| 426 | |
| 427 case 'i': | |
| 428 case 'I': | |
| 8481 | 429 if (imhtml->format_functions & GTK_IMHTML_ITALIC) { |
| 8466 | 430 if(imhtml->html_shortcuts) { |
| 8456 | 431 gtk_imhtml_toggle_italic(imhtml); |
| 8466 | 432 return TRUE; |
| 433 } | |
| 8481 | 434 } |
| 8466 | 435 return FALSE; |
| 8317 | 436 break; |
| 437 | |
| 438 case 'u': /* ctrl-u is GDK_Clear, which clears the line. */ | |
| 439 case 'U': | |
| 8481 | 440 if (imhtml->format_functions & GTK_IMHTML_UNDERLINE) { |
| 8466 | 441 if(imhtml->html_shortcuts) { |
| 8456 | 442 gtk_imhtml_toggle_underline(imhtml); |
| 8466 | 443 return TRUE; |
| 444 } | |
| 8481 | 445 } |
| 8466 | 446 return FALSE; |
| 8317 | 447 break; |
| 448 | |
| 449 case '-': | |
| 8420 | 450 if (imhtml->format_functions & GTK_IMHTML_SHRINK) |
| 451 gtk_imhtml_font_shrink(imhtml); | |
| 8317 | 452 return TRUE; |
| 453 break; | |
| 454 | |
| 455 case '=': | |
| 456 case '+': | |
| 8420 | 457 if (imhtml->format_functions & GTK_IMHTML_GROW) |
| 458 gtk_imhtml_font_grow(imhtml); | |
| 8317 | 459 return TRUE; |
| 460 break; | |
| 461 | |
| 462 case '1': strcpy(buf, ":-)"); break; | |
| 463 case '2': strcpy(buf, ":-("); break; | |
| 464 case '3': strcpy(buf, ";-)"); break; | |
| 465 case '4': strcpy(buf, ":-P"); break; | |
| 466 case '5': strcpy(buf, "=-O"); break; | |
| 467 case '6': strcpy(buf, ":-*"); break; | |
| 468 case '7': strcpy(buf, ">:o"); break; | |
| 469 case '8': strcpy(buf, "8-)"); break; | |
| 470 case '!': strcpy(buf, ":-$"); break; | |
| 471 case '@': strcpy(buf, ":-!"); break; | |
| 472 case '#': strcpy(buf, ":-["); break; | |
| 473 case '$': strcpy(buf, "O:-)"); break; | |
| 474 case '%': strcpy(buf, ":-/"); break; | |
| 475 case '^': strcpy(buf, ":'("); break; | |
| 476 case '&': strcpy(buf, ":-X"); break; | |
| 477 case '*': strcpy(buf, ":-D"); break; | |
| 6066 | 478 } |
| 8456 | 479 if (*buf && imhtml->smiley_shortcuts) { |
| 480 gtk_imhtml_insert_smiley(imhtml, imhtml->protocol_name, buf); | |
| 8317 | 481 return TRUE; |
| 482 } | |
| 6066 | 483 return FALSE; |
| 484 } | |
| 485 | |
|
7404
d889a99e0eb1
[gaim-migrate @ 8000]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
486 #if GTK_CHECK_VERSION(2,2,0) |
| 8061 | 487 static void gtk_imhtml_clipboard_get(GtkClipboard *clipboard, GtkSelectionData *selection_data, guint info, GtkIMHtml *imhtml) { |
| 488 GtkTextIter start, end; | |
| 489 GtkTextMark *sel = gtk_text_buffer_get_selection_bound(imhtml->text_buffer); | |
| 490 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); | |
| 491 char *text; | |
| 492 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &start, sel); | |
| 493 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &end, ins); | |
| 494 | |
| 495 | |
| 496 if (info == TARGET_HTML) { | |
| 8149 | 497 int len; |
| 8148 | 498 char *selection; |
| 8061 | 499 GString *str = g_string_new(NULL); |
| 500 text = gtk_imhtml_get_markup_range(imhtml, &start, &end); | |
| 501 | |
| 502 /* Mozilla asks that we start our text/html with the Unicode byte order mark */ | |
| 503 str = g_string_append_unichar(str, 0xfeff); | |
| 504 str = g_string_append(str, text); | |
| 505 str = g_string_append_unichar(str, 0x0000); | |
| 8148 | 506 selection = g_convert(str->str, str->len, "UCS-2", "UTF-8", NULL, &len, NULL); |
| 8061 | 507 gtk_selection_data_set (selection_data, gdk_atom_intern("text/html", FALSE), 16, selection, len); |
| 508 g_string_free(str, TRUE); | |
| 509 g_free(selection); | |
| 510 } else { | |
| 511 text = gtk_text_buffer_get_text(imhtml->text_buffer, &start, &end, FALSE); | |
| 512 gtk_selection_data_set_text(selection_data, text, strlen(text)); | |
| 513 } | |
| 514 g_free(text); | |
| 515 } | |
| 516 | |
| 517 static void gtk_imhtml_primary_clipboard_clear(GtkClipboard *clipboard, GtkIMHtml *imhtml) | |
| 7749 | 518 { |
| 8061 | 519 GtkTextIter insert; |
| 520 GtkTextIter selection_bound; | |
| 521 | |
| 522 gtk_text_buffer_get_iter_at_mark (imhtml->text_buffer, &insert, | |
| 523 gtk_text_buffer_get_mark (imhtml->text_buffer, "insert")); | |
| 524 gtk_text_buffer_get_iter_at_mark (imhtml->text_buffer, &selection_bound, | |
| 525 gtk_text_buffer_get_mark (imhtml->text_buffer, "selection_bound")); | |
| 526 | |
| 527 if (!gtk_text_iter_equal (&insert, &selection_bound)) | |
| 528 gtk_text_buffer_move_mark (imhtml->text_buffer, | |
| 529 gtk_text_buffer_get_mark (imhtml->text_buffer, "selection_bound"), | |
| 530 &insert); | |
| 7749 | 531 } |
| 7742 | 532 |
| 7749 | 533 static void copy_clipboard_cb(GtkIMHtml *imhtml, GtkClipboard *clipboard) |
| 534 { | |
| 8061 | 535 gtk_clipboard_set_with_owner(gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_CLIPBOARD), |
| 536 selection_targets, sizeof(selection_targets) / sizeof(GtkTargetEntry), | |
| 537 (GtkClipboardGetFunc)gtk_imhtml_clipboard_get, | |
| 538 (GtkClipboardClearFunc)NULL, G_OBJECT(imhtml)); | |
| 7346 | 539 |
| 8061 | 540 g_signal_stop_emission_by_name(imhtml, "copy-clipboard"); |
| 541 } | |
| 542 | |
| 543 static void paste_received_cb (GtkClipboard *clipboard, GtkSelectionData *selection_data, gpointer data) | |
| 544 { | |
| 545 char *text; | |
| 546 guint16 c; | |
| 547 GtkIMHtml *imhtml = data; | |
| 7809 | 548 |
| 8123 | 549 if (!gtk_text_view_get_editable(GTK_TEXT_VIEW(imhtml))) |
| 8105 | 550 return; |
| 551 | |
| 8061 | 552 if (selection_data->length < 0) { |
| 553 text = gtk_clipboard_wait_for_text(clipboard); | |
|
8128
9aafd344230d
[gaim-migrate @ 8833]
Christian Hammond <chipx86@chipx86.com>
parents:
8123
diff
changeset
|
554 |
|
9aafd344230d
[gaim-migrate @ 8833]
Christian Hammond <chipx86@chipx86.com>
parents:
8123
diff
changeset
|
555 if (text == NULL) |
|
9aafd344230d
[gaim-migrate @ 8833]
Christian Hammond <chipx86@chipx86.com>
parents:
8123
diff
changeset
|
556 return; |
|
9aafd344230d
[gaim-migrate @ 8833]
Christian Hammond <chipx86@chipx86.com>
parents:
8123
diff
changeset
|
557 |
| 8061 | 558 } else { |
| 559 text = g_malloc((selection_data->format / 8) * selection_data->length); | |
| 560 memcpy(text, selection_data->data, selection_data->length * (selection_data->format / 8)); | |
| 7766 | 561 } |
| 8061 | 562 |
| 563 memcpy (&c, text, 2); | |
| 564 if (c == 0xfeff) { | |
| 565 /* This is UCS2 */ | |
| 566 char *utf8 = g_convert(text+2, (selection_data->length * (selection_data->format / 8)) - 2, "UTF-8", "UCS-2", NULL, NULL, NULL); | |
| 567 g_free(text); | |
| 568 text = utf8; | |
| 569 } | |
| 570 gtk_imhtml_close_tags(imhtml); | |
| 571 gtk_imhtml_append_text_with_images(imhtml, text, GTK_IMHTML_NO_NEWLINE, NULL); | |
| 572 } | |
| 573 | |
| 574 | |
| 575 static void paste_clipboard_cb(GtkIMHtml *imhtml, gpointer blah) | |
| 576 { | |
| 577 | |
| 578 GtkClipboard *clipboard = gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_CLIPBOARD); | |
| 579 gtk_clipboard_request_contents(clipboard, gdk_atom_intern("text/html", FALSE), | |
| 580 paste_received_cb, imhtml); | |
| 581 g_signal_stop_emission_by_name(imhtml, "paste-clipboard"); | |
| 7766 | 582 } |
| 583 | |
| 7346 | 584 static gboolean button_release_cb(GtkIMHtml *imhtml, GdkEventButton event, gpointer the_foibles_of_man) |
| 585 { | |
| 8061 | 586 GtkClipboard *clipboard; |
| 587 if (event.button == 1) { | |
| 588 if ((clipboard = gtk_widget_get_clipboard (GTK_WIDGET (imhtml), | |
| 589 GDK_SELECTION_PRIMARY))) | |
| 590 gtk_text_buffer_remove_selection_clipboard (imhtml->text_buffer, clipboard); | |
| 591 gtk_clipboard_set_with_owner(gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_PRIMARY), | |
| 592 selection_targets, sizeof(selection_targets) / sizeof(GtkTargetEntry), | |
| 593 (GtkClipboardGetFunc)gtk_imhtml_clipboard_get, | |
| 594 (GtkClipboardClearFunc)gtk_imhtml_primary_clipboard_clear, G_OBJECT(imhtml)); | |
| 595 } | |
| 7346 | 596 return FALSE; |
| 597 } | |
|
7404
d889a99e0eb1
[gaim-migrate @ 8000]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
598 #endif |
| 5967 | 599 |
| 4263 | 600 |
| 4032 | 601 static GtkTextViewClass *parent_class = NULL; |
| 602 | |
| 603 static void | |
| 604 gtk_imhtml_finalize (GObject *object) | |
| 605 { | |
| 606 GtkIMHtml *imhtml = GTK_IMHTML(object); | |
| 4895 | 607 GList *scalables; |
| 8061 | 608 |
| 4138 | 609 g_hash_table_destroy(imhtml->smiley_data); |
| 4032 | 610 gtk_smiley_tree_destroy(imhtml->default_smilies); |
| 4138 | 611 gdk_cursor_unref(imhtml->hand_cursor); |
| 612 gdk_cursor_unref(imhtml->arrow_cursor); | |
| 8061 | 613 gdk_cursor_unref(imhtml->text_cursor); |
| 8456 | 614 |
| 4735 | 615 if(imhtml->tip_window){ |
| 616 gtk_widget_destroy(imhtml->tip_window); | |
| 617 } | |
| 618 if(imhtml->tip_timer) | |
| 619 gtk_timeout_remove(imhtml->tip_timer); | |
| 620 | |
| 4895 | 621 for(scalables = imhtml->scalables; scalables; scalables = scalables->next) { |
| 622 GtkIMHtmlScalable *scale = GTK_IMHTML_SCALABLE(scalables->data); | |
| 623 scale->free(scale); | |
| 624 } | |
| 7991 | 625 |
| 4895 | 626 g_list_free(imhtml->scalables); |
| 4032 | 627 G_OBJECT_CLASS(parent_class)->finalize (object); |
| 628 } | |
| 1428 | 629 |
| 3922 | 630 /* Boring GTK stuff */ |
| 8519 | 631 static void gtk_imhtml_class_init (GtkIMHtmlClass *klass) |
| 1428 | 632 { |
| 3922 | 633 GtkObjectClass *object_class; |
| 4032 | 634 GObjectClass *gobject_class; |
| 8519 | 635 object_class = (GtkObjectClass*) klass; |
| 636 gobject_class = (GObjectClass*) klass; | |
| 4032 | 637 parent_class = gtk_type_class(GTK_TYPE_TEXT_VIEW); |
| 4417 | 638 signals[URL_CLICKED] = g_signal_new("url_clicked", |
| 639 G_TYPE_FROM_CLASS(gobject_class), | |
| 640 G_SIGNAL_RUN_FIRST, | |
| 641 G_STRUCT_OFFSET(GtkIMHtmlClass, url_clicked), | |
| 642 NULL, | |
| 643 0, | |
| 644 g_cclosure_marshal_VOID__POINTER, | |
| 645 G_TYPE_NONE, 1, | |
| 646 G_TYPE_POINTER); | |
| 8506 | 647 signals[BUTTONS_UPDATE] = g_signal_new("format_buttons_update", |
| 8420 | 648 G_TYPE_FROM_CLASS(gobject_class), |
| 649 G_SIGNAL_RUN_FIRST, | |
| 650 G_STRUCT_OFFSET(GtkIMHtmlClass, buttons_update), | |
| 651 NULL, | |
| 652 0, | |
| 653 g_cclosure_marshal_VOID__POINTER, | |
| 654 G_TYPE_NONE, 1, | |
| 655 G_TYPE_INT); | |
| 656 signals[TOGGLE_FORMAT] = g_signal_new("format_function_toggle", | |
| 657 G_TYPE_FROM_CLASS(gobject_class), | |
| 658 G_SIGNAL_RUN_FIRST, | |
| 659 G_STRUCT_OFFSET(GtkIMHtmlClass, toggle_format), | |
| 660 NULL, | |
| 661 0, | |
| 662 g_cclosure_marshal_VOID__POINTER, | |
| 8427 | 663 G_TYPE_NONE, 1, |
| 8420 | 664 G_TYPE_INT); |
| 8427 | 665 signals[CLEAR_FORMAT] = g_signal_new("format_function_clear", |
| 666 G_TYPE_FROM_CLASS(gobject_class), | |
| 667 G_SIGNAL_RUN_FIRST, | |
| 668 G_STRUCT_OFFSET(GtkIMHtmlClass, clear_format), | |
| 669 NULL, | |
| 670 0, | |
| 8481 | 671 g_cclosure_marshal_VOID__VOID, |
| 672 G_TYPE_NONE, 0); | |
| 8506 | 673 signals[UPDATE_FORMAT] = g_signal_new("format_function_update", |
| 674 G_TYPE_FROM_CLASS(gobject_class), | |
| 675 G_SIGNAL_RUN_FIRST, | |
| 676 G_STRUCT_OFFSET(GtkIMHtmlClass, update_format), | |
| 677 NULL, | |
| 678 0, | |
| 679 g_cclosure_marshal_VOID__VOID, | |
| 680 G_TYPE_NONE, 0); | |
| 4032 | 681 gobject_class->finalize = gtk_imhtml_finalize; |
| 1428 | 682 } |
| 683 | |
| 3922 | 684 static void gtk_imhtml_init (GtkIMHtml *imhtml) |
| 1428 | 685 { |
| 3922 | 686 GtkTextIter iter; |
| 687 imhtml->text_buffer = gtk_text_buffer_new(NULL); | |
| 688 gtk_text_buffer_get_end_iter (imhtml->text_buffer, &iter); | |
| 689 imhtml->end = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, FALSE); | |
| 690 gtk_text_view_set_buffer(GTK_TEXT_VIEW(imhtml), imhtml->text_buffer); | |
| 5105 | 691 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(imhtml), GTK_WRAP_WORD_CHAR); |
| 3922 | 692 gtk_text_view_set_pixels_below_lines(GTK_TEXT_VIEW(imhtml), 5); |
| 8061 | 693 /*gtk_text_view_set_indent(GTK_TEXT_VIEW(imhtml), -15);*/ |
| 3922 | 694 /*gtk_text_view_set_justification(GTK_TEXT_VIEW(imhtml), GTK_JUSTIFY_FILL);*/ |
| 8061 | 695 |
| 3922 | 696 /* These tags will be used often and can be reused--we create them on init and then apply them by name |
| 8061 | 697 * other tags (color, size, face, etc.) will have to be created and applied dynamically */ |
| 3922 | 698 gtk_text_buffer_create_tag(imhtml->text_buffer, "BOLD", "weight", PANGO_WEIGHT_BOLD, NULL); |
| 699 gtk_text_buffer_create_tag(imhtml->text_buffer, "ITALICS", "style", PANGO_STYLE_ITALIC, NULL); | |
| 700 gtk_text_buffer_create_tag(imhtml->text_buffer, "UNDERLINE", "underline", PANGO_UNDERLINE_SINGLE, NULL); | |
| 701 gtk_text_buffer_create_tag(imhtml->text_buffer, "STRIKE", "strikethrough", TRUE, NULL); | |
| 702 gtk_text_buffer_create_tag(imhtml->text_buffer, "SUB", "rise", -5000, NULL); | |
| 703 gtk_text_buffer_create_tag(imhtml->text_buffer, "SUP", "rise", 5000, NULL); | |
| 704 gtk_text_buffer_create_tag(imhtml->text_buffer, "PRE", "family", "Monospace", NULL); | |
| 7295 | 705 gtk_text_buffer_create_tag(imhtml->text_buffer, "search", "background", "#22ff00", "weight", "bold", NULL); |
| 8061 | 706 gtk_text_buffer_create_tag(imhtml->text_buffer, "LINK", "foreground", "blue", "underline", PANGO_UNDERLINE_SINGLE, NULL); |
| 3922 | 707 /* When hovering over a link, we show the hand cursor--elsewhere we show the plain ol' pointer cursor */ |
| 708 imhtml->hand_cursor = gdk_cursor_new (GDK_HAND2); | |
| 709 imhtml->arrow_cursor = gdk_cursor_new (GDK_LEFT_PTR); | |
| 8061 | 710 imhtml->text_cursor = gdk_cursor_new (GDK_XTERM); |
| 2993 | 711 |
| 4253 | 712 imhtml->show_smileys = TRUE; |
| 6124 | 713 imhtml->show_comments = TRUE; |
| 4253 | 714 |
| 4892 | 715 imhtml->smiley_data = g_hash_table_new_full(g_str_hash, g_str_equal, |
| 4902 | 716 g_free, (GDestroyNotify)gtk_smiley_tree_destroy); |
| 4032 | 717 imhtml->default_smilies = gtk_smiley_tree_new(); |
| 4735 | 718 |
| 4944 | 719 g_signal_connect(G_OBJECT(imhtml), "size-allocate", G_CALLBACK(gtk_size_allocate_cb), NULL); |
| 4735 | 720 g_signal_connect(G_OBJECT(imhtml), "motion-notify-event", G_CALLBACK(gtk_motion_event_notify), NULL); |
| 4944 | 721 g_signal_connect(G_OBJECT(imhtml), "leave-notify-event", G_CALLBACK(gtk_leave_event_notify), NULL); |
| 6066 | 722 g_signal_connect(G_OBJECT(imhtml), "key_press_event", G_CALLBACK(gtk_key_pressed_cb), NULL); |
| 8061 | 723 g_signal_connect_after(G_OBJECT(imhtml->text_buffer), "insert-text", G_CALLBACK(insert_cb), imhtml); |
| 8091 | 724 |
| 725 gtk_drag_dest_set(GTK_WIDGET(imhtml), 0, | |
| 726 link_drag_drop_targets, sizeof(link_drag_drop_targets) / sizeof(GtkTargetEntry), | |
| 727 GDK_ACTION_COPY); | |
| 728 g_signal_connect(G_OBJECT(imhtml), "drag_data_received", G_CALLBACK(gtk_imhtml_link_drag_rcv_cb), imhtml); | |
| 729 | |
|
7404
d889a99e0eb1
[gaim-migrate @ 8000]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
730 #if GTK_CHECK_VERSION(2,2,0) |
| 7353 | 731 g_signal_connect(G_OBJECT(imhtml), "copy-clipboard", G_CALLBACK(copy_clipboard_cb), NULL); |
| 8061 | 732 g_signal_connect(G_OBJECT(imhtml), "paste-clipboard", G_CALLBACK(paste_clipboard_cb), NULL); |
| 7346 | 733 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
|
734 #endif |
| 4944 | 735 gtk_widget_add_events(GTK_WIDGET(imhtml), GDK_LEAVE_NOTIFY_MASK); |
| 4735 | 736 |
| 737 imhtml->tip = NULL; | |
| 738 imhtml->tip_timer = 0; | |
| 739 imhtml->tip_window = NULL; | |
| 4895 | 740 |
| 8061 | 741 imhtml->edit.bold = NULL; |
| 742 imhtml->edit.italic = NULL; | |
| 743 imhtml->edit.underline = NULL; | |
| 744 imhtml->edit.forecolor = NULL; | |
| 745 imhtml->edit.backcolor = NULL; | |
| 746 imhtml->edit.fontface = NULL; | |
| 747 imhtml->edit.sizespan = NULL; | |
| 748 imhtml->edit.fontsize = 3; | |
| 749 | |
| 750 imhtml->format_spans = NULL; | |
| 751 | |
| 4895 | 752 imhtml->scalables = NULL; |
| 8061 | 753 |
| 754 gtk_imhtml_set_editable(imhtml, FALSE); | |
| 2993 | 755 } |
| 756 | |
| 3922 | 757 GtkWidget *gtk_imhtml_new(void *a, void *b) |
| 1428 | 758 { |
| 4635 | 759 return GTK_WIDGET(g_object_new(gtk_imhtml_get_type(), NULL)); |
| 1428 | 760 } |
| 761 | |
| 4635 | 762 GType gtk_imhtml_get_type() |
| 1428 | 763 { |
| 4635 | 764 static GType imhtml_type = 0; |
| 1428 | 765 |
| 766 if (!imhtml_type) { | |
| 4635 | 767 static const GTypeInfo imhtml_info = { |
| 768 sizeof(GtkIMHtmlClass), | |
| 769 NULL, | |
| 770 NULL, | |
| 771 (GClassInitFunc) gtk_imhtml_class_init, | |
| 772 NULL, | |
| 773 NULL, | |
| 1428 | 774 sizeof (GtkIMHtml), |
| 4635 | 775 0, |
| 776 (GInstanceInitFunc) gtk_imhtml_init | |
| 1428 | 777 }; |
| 4635 | 778 |
| 779 imhtml_type = g_type_register_static(gtk_text_view_get_type(), | |
| 780 "GtkIMHtml", &imhtml_info, 0); | |
| 1428 | 781 } |
| 782 | |
| 783 return imhtml_type; | |
| 784 } | |
| 785 | |
| 4417 | 786 struct url_data { |
| 787 GObject *object; | |
| 788 gchar *url; | |
| 789 }; | |
| 790 | |
| 791 static void url_open(GtkWidget *w, struct url_data *data) { | |
| 792 if(!data) return; | |
| 8061 | 793 g_signal_emit(data->object, signals[URL_CLICKED], 0, data->url); |
| 7988 | 794 |
| 4417 | 795 g_object_unref(data->object); |
| 796 g_free(data->url); | |
| 797 g_free(data); | |
| 798 } | |
| 5582 | 799 |
| 4417 | 800 static void url_copy(GtkWidget *w, gchar *url) { |
| 801 GtkClipboard *clipboard; | |
| 802 | |
|
5293
ead927e2543f
[gaim-migrate @ 5665]
Christian Hammond <chipx86@chipx86.com>
parents:
5282
diff
changeset
|
803 clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY); |
| 4417 | 804 gtk_clipboard_set_text(clipboard, url, -1); |
| 5582 | 805 |
| 806 clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); | |
| 807 gtk_clipboard_set_text(clipboard, url, -1); | |
| 4417 | 808 } |
| 809 | |
| 810 /* The callback for an event on a link tag. */ | |
| 5091 | 811 gboolean tag_event(GtkTextTag *tag, GObject *imhtml, GdkEvent *event, GtkTextIter *arg2, char *url) { |
| 4417 | 812 GdkEventButton *event_button = (GdkEventButton *) event; |
| 8061 | 813 if (GTK_IMHTML(imhtml)->editable) |
| 814 return FALSE; | |
| 3922 | 815 if (event->type == GDK_BUTTON_RELEASE) { |
| 8061 | 816 if (event_button->button == 1) { |
| 4417 | 817 GtkTextIter start, end; |
| 818 /* we shouldn't open a URL if the user has selected something: */ | |
| 819 gtk_text_buffer_get_selection_bounds( | |
| 820 gtk_text_iter_get_buffer(arg2), &start, &end); | |
| 821 if(gtk_text_iter_get_offset(&start) != | |
| 822 gtk_text_iter_get_offset(&end)) | |
| 823 return FALSE; | |
| 824 | |
| 825 /* A link was clicked--we emit the "url_clicked" signal | |
| 826 * with the URL as the argument */ | |
| 5091 | 827 g_signal_emit(imhtml, signals[URL_CLICKED], 0, url); |
| 4417 | 828 return FALSE; |
| 829 } else if(event_button->button == 3) { | |
| 4745 | 830 GtkWidget *img, *item, *menu; |
| 4417 | 831 struct url_data *tempdata = g_new(struct url_data, 1); |
| 5091 | 832 tempdata->object = g_object_ref(imhtml); |
| 4417 | 833 tempdata->url = g_strdup(url); |
| 4745 | 834 |
| 5091 | 835 /* Don't want the tooltip around if user right-clicked on link */ |
| 836 if (GTK_IMHTML(imhtml)->tip_window) { | |
| 837 gtk_widget_destroy(GTK_IMHTML(imhtml)->tip_window); | |
| 838 GTK_IMHTML(imhtml)->tip_window = NULL; | |
| 839 } | |
| 840 if (GTK_IMHTML(imhtml)->tip_timer) { | |
| 841 g_source_remove(GTK_IMHTML(imhtml)->tip_timer); | |
| 842 GTK_IMHTML(imhtml)->tip_timer = 0; | |
| 843 } | |
| 8061 | 844 if (GTK_IMHTML(imhtml)->editable) |
| 845 gdk_window_set_cursor(event_button->window, GTK_IMHTML(imhtml)->text_cursor); | |
| 846 else | |
| 847 gdk_window_set_cursor(event_button->window, GTK_IMHTML(imhtml)->arrow_cursor); | |
| 4417 | 848 menu = gtk_menu_new(); |
| 4745 | 849 |
| 4417 | 850 /* buttons and such */ |
| 851 | |
|
7140
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
852 if (!strncmp(url, "mailto:", 7)) |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
853 { |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
854 /* Copy E-Mail Address */ |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
855 img = gtk_image_new_from_stock(GTK_STOCK_COPY, |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
856 GTK_ICON_SIZE_MENU); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
857 item = gtk_image_menu_item_new_with_mnemonic( |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
858 _("_Copy E-Mail Address")); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
859 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
|
860 g_signal_connect(G_OBJECT(item), "activate", |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
861 G_CALLBACK(url_copy), url + 7); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
862 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
863 } |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
864 else |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
865 { |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
866 /* Copy Link Location */ |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
867 img = gtk_image_new_from_stock(GTK_STOCK_COPY, |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
868 GTK_ICON_SIZE_MENU); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
869 item = gtk_image_menu_item_new_with_mnemonic( |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
870 _("_Copy Link Location")); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
871 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
|
872 g_signal_connect(G_OBJECT(item), "activate", |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
873 G_CALLBACK(url_copy), url); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
874 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
875 |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
876 /* Open Link in Browser */ |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
877 img = gtk_image_new_from_stock(GTK_STOCK_JUMP_TO, |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
878 GTK_ICON_SIZE_MENU); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
879 item = gtk_image_menu_item_new_with_mnemonic( |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
880 _("_Open Link in Browser")); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
881 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
|
882 g_signal_connect(G_OBJECT(item), "activate", |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
883 G_CALLBACK(url_open), tempdata); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
884 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
885 } |
|
48cc5d5d5a6c
[gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
886 |
| 4756 | 887 |
| 4417 | 888 gtk_widget_show_all(menu); |
| 4756 | 889 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, |
| 890 event_button->button, event_button->time); | |
| 4745 | 891 |
| 4417 | 892 return TRUE; |
| 893 } | |
| 1428 | 894 } |
| 4417 | 895 if(event->type == GDK_BUTTON_PRESS && event_button->button == 3) |
| 896 return TRUE; /* Clicking the right mouse button on a link shouldn't | |
| 897 be caught by the regular GtkTextView menu */ | |
| 898 else | |
| 899 return FALSE; /* Let clicks go through if we didn't catch anything */ | |
| 1428 | 900 } |
| 901 | |
| 8091 | 902 static void |
| 903 gtk_imhtml_link_drag_rcv_cb(GtkWidget *widget, GdkDragContext *dc, guint x, guint y, | |
| 904 GtkSelectionData *sd, guint info, guint t, GtkIMHtml *imhtml) | |
| 905 { | |
| 906 if(gtk_imhtml_get_editable(imhtml) && sd->data){ | |
| 907 gchar **links; | |
| 908 gchar *link; | |
| 909 | |
| 910 gaim_str_strip_cr(sd->data); | |
| 911 | |
| 912 links = g_strsplit(sd->data, "\n", 0); | |
| 913 while((link = *links++) != NULL){ | |
| 914 if(gaim_str_has_prefix(link, "http://") || | |
| 915 gaim_str_has_prefix(link, "https://") || | |
| 916 gaim_str_has_prefix(link, "ftp://")){ | |
| 917 gtk_imhtml_insert_link(imhtml, link, link); | |
| 918 } else if (link=='\0') { | |
| 8177 | 919 /* Ignore blank lines */ |
| 8091 | 920 } else { |
| 8177 | 921 /* Special reasons, aka images being put in via other tag, etc. */ |
| 8091 | 922 } |
| 923 } | |
| 924 | |
| 925 gtk_drag_finish(dc, TRUE, (dc->action == GDK_ACTION_MOVE), t); | |
| 926 } else { | |
| 927 gtk_drag_finish(dc, FALSE, FALSE, t); | |
| 928 } | |
| 929 } | |
| 930 | |
| 4298 | 931 /* this isn't used yet |
| 4032 | 932 static void |
| 4263 | 933 gtk_smiley_tree_remove (GtkSmileyTree *tree, |
| 934 GtkIMHtmlSmiley *smiley) | |
| 4032 | 935 { |
| 936 GtkSmileyTree *t = tree; | |
| 4263 | 937 const gchar *x = smiley->smile; |
| 4032 | 938 gint len = 0; |
| 939 | |
| 940 while (*x) { | |
| 941 gchar *pos; | |
| 942 | |
| 943 if (!t->values) | |
| 944 return; | |
| 945 | |
| 946 pos = strchr (t->values->str, *x); | |
| 947 if (pos) | |
| 948 t = t->children [(int) pos - (int) t->values->str]; | |
| 949 else | |
| 950 return; | |
| 951 | |
| 952 x++; len++; | |
| 953 } | |
| 954 | |
|
4141
ccec4fde84f4
[gaim-migrate @ 4359]
Christian Hammond <chipx86@chipx86.com>
parents:
4140
diff
changeset
|
955 if (t->image) { |
| 4032 | 956 t->image = NULL; |
|
4141
ccec4fde84f4
[gaim-migrate @ 4359]
Christian Hammond <chipx86@chipx86.com>
parents:
4140
diff
changeset
|
957 } |
| 4032 | 958 } |
| 4298 | 959 */ |
| 960 | |
| 4032 | 961 |
| 962 static gint | |
| 963 gtk_smiley_tree_lookup (GtkSmileyTree *tree, | |
| 964 const gchar *text) | |
| 965 { | |
| 966 GtkSmileyTree *t = tree; | |
| 967 const gchar *x = text; | |
| 968 gint len = 0; | |
| 8505 | 969 gchar *amp; |
| 970 gint alen; | |
| 4032 | 971 |
| 972 while (*x) { | |
| 973 gchar *pos; | |
| 974 | |
| 975 if (!t->values) | |
| 976 break; | |
| 977 | |
| 8505 | 978 if(*x == '&' && gtk_imhtml_is_amp_escape(x, &, &alen)) { |
| 979 len += alen - strlen(amp); | |
| 980 x += alen - strlen(amp); | |
| 981 pos = strchr (t->values->str, *amp); | |
| 982 } | |
| 983 else | |
| 984 pos = strchr (t->values->str, *x); | |
| 985 | |
| 4032 | 986 if (pos) |
| 7371 | 987 t = t->children [GPOINTER_TO_INT(pos) - GPOINTER_TO_INT(t->values->str)]; |
| 4032 | 988 else |
| 989 break; | |
| 990 | |
| 991 x++; len++; | |
| 992 } | |
| 993 | |
| 994 if (t->image) | |
| 995 return len; | |
| 996 | |
| 997 return 0; | |
| 998 } | |
| 999 | |
| 1000 void | |
| 4263 | 1001 gtk_imhtml_associate_smiley (GtkIMHtml *imhtml, |
| 1002 gchar *sml, | |
| 1003 GtkIMHtmlSmiley *smiley) | |
| 4032 | 1004 { |
| 1005 GtkSmileyTree *tree; | |
| 1006 g_return_if_fail (imhtml != NULL); | |
| 1007 g_return_if_fail (GTK_IS_IMHTML (imhtml)); | |
| 7371 | 1008 |
| 4032 | 1009 if (sml == NULL) |
| 1010 tree = imhtml->default_smilies; | |
| 1011 else if ((tree = g_hash_table_lookup(imhtml->smiley_data, sml))) { | |
| 1012 } else { | |
| 1013 tree = gtk_smiley_tree_new(); | |
| 4892 | 1014 g_hash_table_insert(imhtml->smiley_data, g_strdup(sml), tree); |
| 4032 | 1015 } |
| 1016 | |
| 4263 | 1017 gtk_smiley_tree_insert (tree, smiley); |
| 4032 | 1018 } |
| 1019 | |
| 1020 static gboolean | |
| 1021 gtk_imhtml_is_smiley (GtkIMHtml *imhtml, | |
| 1022 GSList *fonts, | |
| 1023 const gchar *text, | |
| 1024 gint *len) | |
| 1025 { | |
| 1026 GtkSmileyTree *tree; | |
| 5967 | 1027 GtkIMHtmlFontDetail *font; |
| 4032 | 1028 char *sml = NULL; |
| 1029 | |
| 1030 if (fonts) { | |
| 1031 font = fonts->data; | |
| 1032 sml = font->sml; | |
| 1033 } | |
| 1034 | |
| 1035 if (sml == NULL) | |
| 1036 tree = imhtml->default_smilies; | |
| 1037 else { | |
| 1038 tree = g_hash_table_lookup(imhtml->smiley_data, sml); | |
| 1039 } | |
| 1040 if (tree == NULL) | |
| 1041 return FALSE; | |
| 7371 | 1042 |
| 8505 | 1043 *len = gtk_smiley_tree_lookup (tree, text); |
| 4032 | 1044 return (*len > 0); |
| 1045 } | |
| 1046 | |
|
6814
782907a6ae65
[gaim-migrate @ 7354]
Christian Hammond <chipx86@chipx86.com>
parents:
6648
diff
changeset
|
1047 GdkPixbufAnimation * |
| 4032 | 1048 gtk_smiley_tree_image (GtkIMHtml *imhtml, |
| 1049 const gchar *sml, | |
| 1050 const gchar *text) | |
| 1051 { | |
| 1052 GtkSmileyTree *t; | |
| 1053 const gchar *x = text; | |
| 1054 if (sml == NULL) | |
| 1055 t = imhtml->default_smilies; | |
| 7371 | 1056 else |
| 4032 | 1057 t = g_hash_table_lookup(imhtml->smiley_data, sml); |
| 7371 | 1058 |
| 4032 | 1059 |
| 1060 if (t == NULL) | |
| 1061 return sml ? gtk_smiley_tree_image(imhtml, NULL, text) : NULL; | |
| 1062 | |
| 1063 while (*x) { | |
| 1064 gchar *pos; | |
| 1065 | |
| 1066 if (!t->values) { | |
| 1067 return sml ? gtk_smiley_tree_image(imhtml, NULL, text) : NULL; | |
| 1068 } | |
| 7371 | 1069 |
| 4032 | 1070 pos = strchr (t->values->str, *x); |
| 1071 if (pos) { | |
| 7371 | 1072 t = t->children [GPOINTER_TO_INT(pos) - GPOINTER_TO_INT(t->values->str)]; |
| 4032 | 1073 } else { |
| 1074 return sml ? gtk_smiley_tree_image(imhtml, NULL, text) : NULL; | |
| 1075 } | |
| 1076 x++; | |
| 1077 } | |
| 1078 | |
| 4263 | 1079 if (!t->image->icon) |
|
6814
782907a6ae65
[gaim-migrate @ 7354]
Christian Hammond <chipx86@chipx86.com>
parents:
6648
diff
changeset
|
1080 t->image->icon = gdk_pixbuf_animation_new_from_file(t->image->file, NULL); |
| 4263 | 1081 |
| 1082 return t->image->icon; | |
| 4032 | 1083 } |
| 4793 | 1084 #define VALID_TAG(x) if (!g_ascii_strncasecmp (string, x ">", strlen (x ">"))) { \ |
| 3922 | 1085 *tag = g_strndup (string, strlen (x)); \ |
| 1086 *len = strlen (x) + 1; \ | |
| 1087 return TRUE; \ | |
| 1088 } \ | |
| 1089 (*type)++ | |
| 1428 | 1090 |
| 4793 | 1091 #define VALID_OPT_TAG(x) if (!g_ascii_strncasecmp (string, x " ", strlen (x " "))) { \ |
| 3922 | 1092 const gchar *c = string + strlen (x " "); \ |
| 1093 gchar e = '"'; \ | |
| 1094 gboolean quote = FALSE; \ | |
| 1095 while (*c) { \ | |
| 1096 if (*c == '"' || *c == '\'') { \ | |
| 1097 if (quote && (*c == e)) \ | |
| 1098 quote = !quote; \ | |
| 1099 else if (!quote) { \ | |
| 1100 quote = !quote; \ | |
| 1101 e = *c; \ | |
| 1102 } \ | |
| 1103 } else if (!quote && (*c == '>')) \ | |
| 1104 break; \ | |
| 1105 c++; \ | |
| 1106 } \ | |
| 1107 if (*c) { \ | |
| 1108 *tag = g_strndup (string, c - string); \ | |
| 1109 *len = c - string + 1; \ | |
| 1110 return TRUE; \ | |
| 1111 } \ | |
| 1112 } \ | |
| 1113 (*type)++ | |
| 1428 | 1114 |
| 1115 | |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1116 static gboolean |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1117 gtk_imhtml_is_amp_escape (const gchar *string, |
| 7280 | 1118 gchar **replace, |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1119 gint *length) |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1120 { |
| 7287 | 1121 static char buf[7]; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1122 g_return_val_if_fail (string != NULL, FALSE); |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1123 g_return_val_if_fail (replace != NULL, FALSE); |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1124 g_return_val_if_fail (length != NULL, FALSE); |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1125 |
| 4793 | 1126 if (!g_ascii_strncasecmp (string, "&", 5)) { |
| 7280 | 1127 *replace = "&"; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1128 *length = 5; |
| 4793 | 1129 } else if (!g_ascii_strncasecmp (string, "<", 4)) { |
| 7280 | 1130 *replace = "<"; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1131 *length = 4; |
| 4793 | 1132 } else if (!g_ascii_strncasecmp (string, ">", 4)) { |
| 7280 | 1133 *replace = ">"; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1134 *length = 4; |
| 4793 | 1135 } else if (!g_ascii_strncasecmp (string, " ", 6)) { |
| 7280 | 1136 *replace = " "; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1137 *length = 6; |
| 4793 | 1138 } else if (!g_ascii_strncasecmp (string, "©", 6)) { |
| 7280 | 1139 *replace = "©"; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1140 *length = 6; |
| 4793 | 1141 } else if (!g_ascii_strncasecmp (string, """, 6)) { |
| 7280 | 1142 *replace = "\""; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1143 *length = 6; |
| 4793 | 1144 } else if (!g_ascii_strncasecmp (string, "®", 5)) { |
| 7280 | 1145 *replace = "®"; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1146 *length = 5; |
| 5093 | 1147 } else if (!g_ascii_strncasecmp (string, "'", 6)) { |
| 7280 | 1148 *replace = "\'"; |
| 5093 | 1149 *length = 6; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1150 } else if (*(string + 1) == '#') { |
|
2022
199ba82faacb
[gaim-migrate @ 2032]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2002
diff
changeset
|
1151 guint pound = 0; |
| 3004 | 1152 if ((sscanf (string, "&#%u;", £) == 1) && pound != 0) { |
| 7287 | 1153 int buflen; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1154 if (*(string + 3 + (gint)log10 (pound)) != ';') |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1155 return FALSE; |
| 7287 | 1156 buflen = g_unichar_to_utf8((gunichar)pound, buf); |
| 1157 buf[buflen] = '\0'; | |
| 7280 | 1158 *replace = buf; |
|
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1159 *length = 2; |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1160 while (isdigit ((gint) string [*length])) (*length)++; |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1161 if (string [*length] == ';') (*length)++; |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1162 } else { |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1163 return FALSE; |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1164 } |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1165 } else { |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1166 return FALSE; |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1167 } |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1168 |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1169 return TRUE; |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1170 } |
|
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
1171 |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1172 static gboolean |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1173 gtk_imhtml_is_tag (const gchar *string, |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1174 gchar **tag, |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1175 gint *len, |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1176 gint *type) |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1177 { |
| 8061 | 1178 char *close; |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1179 *type = 1; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1180 |
| 8118 | 1181 |
| 8061 | 1182 if (!(close = strchr (string, '>'))) |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1183 return FALSE; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1184 |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1185 VALID_TAG ("B"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1186 VALID_TAG ("BOLD"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1187 VALID_TAG ("/B"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1188 VALID_TAG ("/BOLD"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1189 VALID_TAG ("I"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1190 VALID_TAG ("ITALIC"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1191 VALID_TAG ("/I"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1192 VALID_TAG ("/ITALIC"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1193 VALID_TAG ("U"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1194 VALID_TAG ("UNDERLINE"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1195 VALID_TAG ("/U"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1196 VALID_TAG ("/UNDERLINE"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1197 VALID_TAG ("S"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1198 VALID_TAG ("STRIKE"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1199 VALID_TAG ("/S"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1200 VALID_TAG ("/STRIKE"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1201 VALID_TAG ("SUB"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1202 VALID_TAG ("/SUB"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1203 VALID_TAG ("SUP"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1204 VALID_TAG ("/SUP"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1205 VALID_TAG ("PRE"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1206 VALID_TAG ("/PRE"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1207 VALID_TAG ("TITLE"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1208 VALID_TAG ("/TITLE"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1209 VALID_TAG ("BR"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1210 VALID_TAG ("HR"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1211 VALID_TAG ("/FONT"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1212 VALID_TAG ("/A"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1213 VALID_TAG ("P"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1214 VALID_TAG ("/P"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1215 VALID_TAG ("H3"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1216 VALID_TAG ("/H3"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1217 VALID_TAG ("HTML"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1218 VALID_TAG ("/HTML"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1219 VALID_TAG ("BODY"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1220 VALID_TAG ("/BODY"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1221 VALID_TAG ("FONT"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1222 VALID_TAG ("HEAD"); |
| 2993 | 1223 VALID_TAG ("/HEAD"); |
| 1224 VALID_TAG ("BINARY"); | |
| 1225 VALID_TAG ("/BINARY"); | |
| 5093 | 1226 |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1227 VALID_OPT_TAG ("HR"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1228 VALID_OPT_TAG ("FONT"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1229 VALID_OPT_TAG ("BODY"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1230 VALID_OPT_TAG ("A"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1231 VALID_OPT_TAG ("IMG"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1232 VALID_OPT_TAG ("P"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1233 VALID_OPT_TAG ("H3"); |
| 5093 | 1234 VALID_OPT_TAG ("HTML"); |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1235 |
| 5101 | 1236 VALID_TAG ("CITE"); |
| 1237 VALID_TAG ("/CITE"); | |
| 1238 VALID_TAG ("EM"); | |
| 1239 VALID_TAG ("/EM"); | |
| 1240 VALID_TAG ("STRONG"); | |
| 1241 VALID_TAG ("/STRONG"); | |
| 1242 | |
| 5104 | 1243 VALID_OPT_TAG ("SPAN"); |
| 1244 VALID_TAG ("/SPAN"); | |
| 5174 | 1245 VALID_TAG ("BR/"); /* hack until gtkimhtml handles things better */ |
| 6982 | 1246 VALID_TAG ("IMG"); |
| 8026 | 1247 VALID_TAG("SPAN"); |
| 8061 | 1248 VALID_OPT_TAG("BR"); |
| 7988 | 1249 |
| 4793 | 1250 if (!g_ascii_strncasecmp(string, "!--", strlen ("!--"))) { |
|
2954
f6c4f2187c08
[gaim-migrate @ 2967]
Christian Hammond <chipx86@chipx86.com>
parents:
2898
diff
changeset
|
1251 gchar *e = strstr (string + strlen("!--"), "-->"); |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1252 if (e) { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1253 *len = e - string + strlen ("-->"); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1254 *tag = g_strndup (string + strlen ("!--"), *len - strlen ("!---->")); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1255 return TRUE; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1256 } |
| 8118 | 1257 } |
| 1258 | |
| 8061 | 1259 *type = -1; |
| 1260 *len = close - string + 1; | |
| 1261 *tag = g_strndup(string, *len - 1); | |
| 1262 return TRUE; | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1263 } |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1264 |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1265 static gchar* |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1266 gtk_imhtml_get_html_opt (gchar *tag, |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1267 const gchar *opt) |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1268 { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1269 gchar *t = tag; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1270 gchar *e, *a; |
| 5177 | 1271 gchar *val; |
| 1272 gint len; | |
| 7280 | 1273 gchar *c; |
| 5177 | 1274 GString *ret; |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1275 |
| 4793 | 1276 while (g_ascii_strncasecmp (t, opt, strlen (opt))) { |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1277 gboolean quote = FALSE; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1278 if (*t == '\0') break; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1279 while (*t && !((*t == ' ') && !quote)) { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1280 if (*t == '\"') |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1281 quote = ! quote; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1282 t++; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1283 } |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1284 while (*t && (*t == ' ')) t++; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1285 } |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1286 |
| 4793 | 1287 if (!g_ascii_strncasecmp (t, opt, strlen (opt))) { |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1288 t += strlen (opt); |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1289 } else { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1290 return NULL; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1291 } |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1292 |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1293 if ((*t == '\"') || (*t == '\'')) { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1294 e = a = ++t; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1295 while (*e && (*e != *(t - 1))) e++; |
| 2993 | 1296 if (*e == '\0') { |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1297 return NULL; |
| 5177 | 1298 } else |
| 1299 val = g_strndup(a, e - a); | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1300 } else { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1301 e = a = t; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1302 while (*e && !isspace ((gint) *e)) e++; |
| 5177 | 1303 val = g_strndup(a, e - a); |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1304 } |
| 5177 | 1305 |
| 1306 ret = g_string_new(""); | |
| 1307 e = val; | |
| 1308 while(*e) { | |
| 1309 if(gtk_imhtml_is_amp_escape(e, &c, &len)) { | |
| 7280 | 1310 ret = g_string_append(ret, c); |
| 5177 | 1311 e += len; |
| 1312 } else { | |
| 1313 ret = g_string_append_c(ret, *e); | |
| 1314 e++; | |
| 1315 } | |
| 1316 } | |
| 1317 | |
| 1318 g_free(val); | |
| 8568 | 1319 |
| 1320 return g_string_free(ret, FALSE); | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1321 } |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1322 |
| 8118 | 1323 /* Inline CSS Support - Douglas Thrift */ |
| 1324 static gchar* | |
| 1325 gtk_imhtml_get_css_opt (gchar *style, | |
| 1326 const gchar *opt) | |
| 1327 { | |
| 1328 gchar *t = style; | |
| 1329 gchar *e, *a; | |
| 1330 gchar *val; | |
| 1331 gint len; | |
| 1332 gchar *c; | |
| 1333 GString *ret; | |
| 1334 | |
| 1335 while (g_ascii_strncasecmp (t, opt, strlen (opt))) { | |
| 8177 | 1336 /* gboolean quote = FALSE; */ |
| 8118 | 1337 if (*t == '\0') break; |
| 1338 while (*t && !((*t == ' ') /*&& !quote*/)) { | |
| 1339 /* if (*t == '\"') | |
| 8177 | 1340 quote = ! quote; */ |
| 8118 | 1341 t++; |
| 1342 } | |
| 1343 while (*t && (*t == ' ')) t++; | |
| 1344 } | |
| 1345 | |
| 1346 if (!g_ascii_strncasecmp (t, opt, strlen (opt))) { | |
| 1347 t += strlen (opt); | |
| 1348 } else { | |
| 1349 return NULL; | |
| 1350 } | |
| 1351 | |
| 1352 /* if ((*t == '\"') || (*t == '\'')) { | |
| 1353 e = a = ++t; | |
| 1354 while (*e && (*e != *(t - 1))) e++; | |
| 1355 if (*e == '\0') { | |
| 1356 return NULL; | |
| 1357 } else | |
| 1358 val = g_strndup(a, e - a); | |
| 1359 } else { | |
| 1360 e = a = t; | |
| 1361 while (*e && !isspace ((gint) *e)) e++; | |
| 1362 val = g_strndup(a, e - a); | |
| 1363 }*/ | |
| 1364 | |
| 1365 e = a = t; | |
| 1366 while (*e && *e != ';') e++; | |
| 1367 val = g_strndup(a, e - a); | |
| 1368 | |
| 1369 ret = g_string_new(""); | |
| 1370 e = val; | |
| 1371 while(*e) { | |
| 1372 if(gtk_imhtml_is_amp_escape(e, &c, &len)) { | |
| 1373 ret = g_string_append(ret, c); | |
| 1374 e += len; | |
| 1375 } else { | |
| 1376 ret = g_string_append_c(ret, *e); | |
| 1377 e++; | |
| 1378 } | |
| 1379 } | |
| 1380 | |
| 1381 g_free(val); | |
| 1382 val = ret->str; | |
| 1383 g_string_free(ret, FALSE); | |
| 1384 return val; | |
| 1385 } | |
| 3922 | 1386 |
| 8334 | 1387 static const char *accepted_protocols[] = { |
| 1388 "http://", | |
| 1389 "https://", | |
| 1390 "ftp://" | |
| 1391 }; | |
| 1392 | |
| 1393 static const int accepted_protocols_size = 3; | |
| 1394 | |
| 1395 /* returns if the beginning of the text is a protocol. If it is the protocol, returns the length so | |
| 1396 the caller knows how long the protocol string is. */ | |
| 1397 int gtk_imhtml_is_protocol(const char *text) | |
| 1398 { | |
| 1399 gint i; | |
| 1400 | |
| 1401 for(i=0; i<accepted_protocols_size; i++){ | |
| 1402 if( strncasecmp(text, accepted_protocols[i], strlen(accepted_protocols[i])) == 0 ){ | |
| 1403 return strlen(accepted_protocols[i]); | |
| 1404 } | |
| 1405 } | |
| 1406 return 0; | |
| 1407 } | |
| 1408 | |
| 6982 | 1409 GString* gtk_imhtml_append_text_with_images (GtkIMHtml *imhtml, |
| 1410 const gchar *text, | |
| 1411 GtkIMHtmlOptions options, | |
| 1412 GSList *images) | |
| 1428 | 1413 { |
| 8061 | 1414 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); |
| 1415 GtkTextIter insert; | |
| 1416 GdkRectangle rect; | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1417 gint pos = 0; |
| 3922 | 1418 GString *str = NULL; |
| 8061 | 1419 GtkTextIter iter; |
| 1420 GtkTextMark *mark; | |
| 3922 | 1421 gchar *ws; |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1422 gchar *tag; |
| 3922 | 1423 gchar *url = NULL; |
| 1424 gchar *bg = NULL; | |
| 6982 | 1425 gint len; |
| 4032 | 1426 gint tlen, smilelen, wpos=0; |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1427 gint type; |
| 3922 | 1428 const gchar *c; |
| 7280 | 1429 gchar *amp; |
| 8334 | 1430 gint len_protocol; |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1431 |
| 1428 | 1432 guint bold = 0, |
| 1433 italics = 0, | |
| 1434 underline = 0, | |
| 1435 strike = 0, | |
| 1436 sub = 0, | |
| 1437 sup = 0, | |
|
1691
d802b115800f
[gaim-migrate @ 1701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1647
diff
changeset
|
1438 title = 0, |
| 8061 | 1439 pre = 0; |
| 1428 | 1440 |
| 3922 | 1441 GSList *fonts = NULL; |
| 8506 | 1442 GObject *object; |
| 8061 | 1443 GtkIMHtmlScalable *scalable = NULL; |
| 4612 | 1444 int y, height; |
| 1445 | |
| 1428 | 1446 g_return_val_if_fail (imhtml != NULL, NULL); |
| 1447 g_return_val_if_fail (GTK_IS_IMHTML (imhtml), NULL); | |
| 1448 g_return_val_if_fail (text != NULL, NULL); | |
| 3922 | 1449 c = text; |
| 6982 | 1450 len = strlen(text); |
| 3922 | 1451 ws = g_malloc(len + 1); |
| 1452 ws[0] = 0; | |
| 1428 | 1453 |
| 1454 if (options & GTK_IMHTML_RETURN_LOG) | |
| 3922 | 1455 str = g_string_new(""); |
| 1428 | 1456 |
| 8061 | 1457 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &insert, ins); |
| 1458 | |
| 3922 | 1459 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &iter); |
| 1460 mark = gtk_text_buffer_create_mark (imhtml->text_buffer, NULL, &iter, /* right grav */ FALSE); | |
| 4612 | 1461 |
| 8061 | 1462 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); |
| 4612 | 1463 gtk_text_view_get_line_yrange(GTK_TEXT_VIEW(imhtml), &iter, &y, &height); |
| 1464 | |
| 8061 | 1465 #if GTK_CHECK_VERSION(2,2,0) |
| 1466 gtk_imhtml_primary_clipboard_clear(NULL, imhtml); | |
| 1467 #endif | |
| 1468 gtk_text_buffer_move_mark (imhtml->text_buffer, | |
| 1469 gtk_text_buffer_get_mark (imhtml->text_buffer, "insert"), | |
| 1470 &iter); | |
| 1471 | |
| 1472 if(((y + height) - (rect.y + rect.height)) > height | |
| 4612 | 1473 && gtk_text_buffer_get_char_count(imhtml->text_buffer)){ |
| 1474 options |= GTK_IMHTML_NO_SCROLL; | |
| 1475 } | |
| 1476 | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1477 while (pos < len) { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1478 if (*c == '<' && gtk_imhtml_is_tag (c + 1, &tag, &tlen, &type)) { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1479 c++; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1480 pos++; |
| 8061 | 1481 ws[wpos] = '\0'; |
| 1482 switch (type) | |
| 3922 | 1483 { |
| 1484 case 1: /* B */ | |
| 1485 case 2: /* BOLD */ | |
| 5101 | 1486 case 54: /* STRONG */ |
| 8061 | 1487 if (url) |
| 1488 gtk_imhtml_insert_link(imhtml, url, ws); | |
| 1489 else | |
| 1490 gtk_text_buffer_insert(imhtml->text_buffer, &iter, ws, wpos); | |
| 1491 if (bold == 0) | |
| 1492 gtk_imhtml_toggle_bold(imhtml); | |
| 3922 | 1493 bold++; |
| 8061 | 1494 ws[0] = '\0'; wpos = 0; |
| 3922 | 1495 break; |
| 1496 case 3: /* /B */ | |
| 1497 case 4: /* /BOLD */ | |
| 5101 | 1498 case 55: /* /STRONG */ |
| 8061 | 1499 if (url) |
| 1500 gtk_imhtml_insert_link(imhtml, url, ws); | |
| 1501 else | |
| 1502 gtk_text_buffer_insert(imhtml->text_buffer, &iter, ws, wpos); | |
| 1503 ws[0] = '\0'; wpos = 0; | |
| 1504 | |
| 3922 | 1505 if (bold) |
| 1506 bold--; | |
| 8061 | 1507 if (bold == 0) |
| 1508 gtk_imhtml_toggle_bold(imhtml); | |
| 3922 | 1509 break; |
| 1510 case 5: /* I */ | |
| 1511 case 6: /* ITALIC */ | |
| 5101 | 1512 case 52: /* EM */ |
| 8061 | 1513 if (url) |
| 1514 gtk_imhtml_insert_link(imhtml, url, ws); | |
| 1515 else | |
| 1516 gtk_text_buffer_insert(imhtml->text_buffer, &iter, ws, wpos); | |
| 1517 ws[0] = '\0'; wpos = 0; | |
| 1518 if (italics == 0) | |
| 1519 gtk_imhtml_toggle_italic(imhtml); | |
| 3922 | 1520 italics++; |
| 1521 break; | |
| 1522 case 7: /* /I */ | |
| 1523 case 8: /* /ITALIC */ | |
| 5101 | 1524 case 53: /* /EM */ |
| 8061 | 1525 if (url) |
| 1526 gtk_imhtml_insert_link(imhtml, url, ws); | |
| 1527 else | |
| 1528 gtk_text_buffer_insert(imhtml->text_buffer, &iter, ws, wpos); | |
| 1529 ws[0] = '\0'; wpos = 0; | |
| 3922 | 1530 if (italics) |
| 1531 italics--; | |
| 8061 | 1532 if (italics == 0) |
| 1533 gtk_imhtml_toggle_italic(imhtml); | |
| 3922 | 1534 break; |
| 1535 case 9: /* U */ | |
| 1536 case 10: /* UNDERLINE */ | |
| 8061 | 1537 if (url) |
| 1538 gtk_imhtml_insert_link(imhtml, url, ws); | |
| 1539 else | |
| 1540 gtk_text_buffer_insert(imhtml->text_buffer, &iter, ws, wpos); | |
| 1541 ws[0] = '\0'; wpos = 0; | |
| 1542 if (underline == 0) | |
| 1543 gtk_imhtml_toggle_underline(imhtml); | |
| 3922 | 1544 underline++; |
| 1545 break; | |
| 1546 case 11: /* /U */ | |
| 1547 case 12: /* /UNDERLINE */ | |
| 8061 | 1548 if (url) |
| 1549 gtk_imhtml_insert_link(imhtml, url, ws); | |
| 1550 else | |
| 1551 gtk_text_buffer_insert(imhtml->text_buffer, &iter, ws, wpos); | |
| 1552 ws[0] = '\0'; wpos = 0; | |
| 3922 | 1553 if (underline) |
| 1554 underline--; | |
| 8061 | 1555 if (underline == 0) |
| 1556 gtk_imhtml_toggle_underline(imhtml); | |
| 3922 | 1557 break; |
| 1558 case 13: /* S */ | |
| 1559 case 14: /* STRIKE */ | |
| 8177 | 1560 /* NEW_BIT (NEW_TEXT_BIT); */ |
| 3922 | 1561 strike++; |
| 1562 break; | |
| 1563 case 15: /* /S */ | |
| 1564 case 16: /* /STRIKE */ | |
| 8177 | 1565 /* NEW_BIT (NEW_TEXT_BIT); */ |
| 3922 | 1566 if (strike) |
| 1567 strike--; | |
| 1568 break; | |
| 1569 case 17: /* SUB */ | |
| 8177 | 1570 /* NEW_BIT (NEW_TEXT_BIT); */ |
| 3922 | 1571 sub++; |
| 1572 break; | |
| 1573 case 18: /* /SUB */ | |
| 8177 | 1574 /* NEW_BIT (NEW_TEXT_BIT); */ |
| 3922 | 1575 if (sub) |
| 1576 sub--; | |
| 1577 break; | |
| 1578 case 19: /* SUP */ | |
| 8177 | 1579 /* NEW_BIT (NEW_TEXT_BIT); */ |
| 3922 | 1580 sup++; |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1581 break; |
| 3922 | 1582 case 20: /* /SUP */ |
| 8177 | 1583 /* NEW_BIT (NEW_TEXT_BIT); */ |
| 3922 | 1584 if (sup) |
| 1585 sup--; | |
| 1586 break; | |
| 1587 case 21: /* PRE */ | |
| 8177 | 1588 /* NEW_BIT (NEW_TEXT_BIT); */ |
| 3922 | 1589 pre++; |
| 1590 break; | |
| 1591 case 22: /* /PRE */ | |
| 8177 | 1592 /* NEW_BIT (NEW_TEXT_BIT); */ |
| 3922 | 1593 if (pre) |
| 1594 pre--; | |
| 1595 break; | |
| 1596 case 23: /* TITLE */ | |
| 8177 | 1597 /* NEW_BIT (NEW_TEXT_BIT); */ |
| 3922 | 1598 title++; |
| 1599 break; | |
| 1600 case 24: /* /TITLE */ | |
| 1601 if (title) { | |
| 1602 if (options & GTK_IMHTML_NO_TITLE) { | |
| 1603 wpos = 0; | |
| 1604 ws [wpos] = '\0'; | |
| 1605 } | |
| 1606 title--; | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1607 } |
| 3922 | 1608 break; |
| 1609 case 25: /* BR */ | |
| 5174 | 1610 case 58: /* BR/ */ |
| 8061 | 1611 case 61: /* BR (opt) */ |
| 3922 | 1612 ws[wpos] = '\n'; |
| 1613 wpos++; | |
| 8177 | 1614 /* NEW_BIT (NEW_TEXT_BIT); */ |
| 6982 | 1615 break; |
| 3922 | 1616 case 26: /* HR */ |
| 1617 case 42: /* HR (opt) */ | |
| 1618 ws[wpos++] = '\n'; | |
| 8061 | 1619 if (url) |
| 1620 gtk_imhtml_insert_link(imhtml, url, ws); | |
| 1621 else | |
| 1622 gtk_text_buffer_insert(imhtml->text_buffer, &iter, ws, wpos); | |
| 5967 | 1623 scalable = gtk_imhtml_hr_new(); |
| 8061 | 1624 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); |
| 1625 scalable->add_to(scalable, imhtml, &iter); | |
| 1626 scalable->scale(scalable, rect.width, rect.height); | |
| 1627 imhtml->scalables = g_list_append(imhtml->scalables, scalable); | |
| 1628 ws[0] = '\0'; wpos = 0; | |
| 7942 | 1629 ws[wpos++] = '\n'; |
| 8061 | 1630 |
| 3922 | 1631 break; |
| 1632 case 27: /* /FONT */ | |
| 1633 if (fonts) { | |
| 5967 | 1634 GtkIMHtmlFontDetail *font = fonts->data; |
| 8061 | 1635 if (url) |
| 1636 gtk_imhtml_insert_link(imhtml, url, ws); | |
| 1637 else | |
| 1638 gtk_text_buffer_insert(imhtml->text_buffer, &iter, ws, wpos); | |
| 1639 ws[0] = '\0'; wpos = 0; | |
| 8177 | 1640 /* NEW_BIT (NEW_TEXT_BIT); */ |
| 8309 | 1641 |
| 8061 | 1642 if (font->face) { |
| 1643 gtk_imhtml_toggle_fontface(imhtml, NULL); | |
| 3922 | 1644 g_free (font->face); |
| 8061 | 1645 } |
| 1646 if (font->fore) { | |
| 1647 gtk_imhtml_toggle_forecolor(imhtml, NULL); | |
| 3922 | 1648 g_free (font->fore); |
| 8061 | 1649 } |
| 1650 if (font->back) { | |
| 1651 gtk_imhtml_toggle_backcolor(imhtml, NULL); | |
| 3922 | 1652 g_free (font->back); |
| 8061 | 1653 } |
| 4032 | 1654 if (font->sml) |
| 1655 g_free (font->sml); | |
| 3922 | 1656 g_free (font); |
| 8309 | 1657 |
| 1658 if (font->size != 3) | |
| 1659 gtk_imhtml_font_set_size(imhtml, 3); | |
| 1660 | |
| 1661 fonts = fonts->next; | |
| 1662 if (fonts) { | |
| 1663 GtkIMHtmlFontDetail *font = fonts->data; | |
| 1664 | |
| 1665 if (font->face) | |
| 1666 gtk_imhtml_toggle_fontface(imhtml, font->face); | |
| 1667 if (font->fore) | |
| 1668 gtk_imhtml_toggle_forecolor(imhtml, font->fore); | |
| 1669 if (font->back) | |
| 1670 gtk_imhtml_toggle_backcolor(imhtml, font->back); | |
| 1671 if (font->size != 3) | |
| 1672 gtk_imhtml_font_set_size(imhtml, font->size); | |
| 1673 } | |
| 3922 | 1674 } |
| 8309 | 1675 break; |
| 3922 | 1676 case 28: /* /A */ |
| 1677 if (url) { | |
| 8061 | 1678 gtk_imhtml_insert_link(imhtml, url, ws); |
| 3922 | 1679 g_free(url); |
| 8061 | 1680 ws[0] = '\0'; wpos = 0; |
| 3922 | 1681 url = NULL; |
| 8061 | 1682 ins = gtk_text_buffer_get_insert(imhtml->text_buffer); |
| 1683 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins); | |
| 2993 | 1684 } |
| 8061 | 1685 break; |
| 8118 | 1686 |
| 3922 | 1687 case 29: /* P */ |
| 1688 case 30: /* /P */ | |
| 1689 case 31: /* H3 */ | |
| 1690 case 32: /* /H3 */ | |
| 1691 case 33: /* HTML */ | |
| 1692 case 34: /* /HTML */ | |
| 1693 case 35: /* BODY */ | |
| 1694 case 36: /* /BODY */ | |
| 1695 case 37: /* FONT */ | |
| 1696 case 38: /* HEAD */ | |
| 1697 case 39: /* /HEAD */ | |
| 6982 | 1698 case 40: /* BINARY */ |
| 1699 case 41: /* /BINARY */ | |
| 3922 | 1700 break; |
| 1701 case 43: /* FONT (opt) */ | |
| 1702 { | |
| 4032 | 1703 gchar *color, *back, *face, *size, *sml; |
| 5967 | 1704 GtkIMHtmlFontDetail *font, *oldfont = NULL; |
| 3922 | 1705 color = gtk_imhtml_get_html_opt (tag, "COLOR="); |
| 1706 back = gtk_imhtml_get_html_opt (tag, "BACK="); | |
| 1707 face = gtk_imhtml_get_html_opt (tag, "FACE="); | |
| 1708 size = gtk_imhtml_get_html_opt (tag, "SIZE="); | |
| 4032 | 1709 sml = gtk_imhtml_get_html_opt (tag, "SML="); |
| 1710 if (!(color || back || face || size || sml)) | |
| 3922 | 1711 break; |
| 8061 | 1712 |
| 1713 if (url) | |
| 1714 gtk_imhtml_insert_link(imhtml, url, ws); | |
| 1715 else | |
| 1716 gtk_text_buffer_insert(imhtml->text_buffer, &iter, ws, wpos); | |
| 1717 ws[0] = '\0'; wpos = 0; | |
| 1718 | |
| 5967 | 1719 font = g_new0 (GtkIMHtmlFontDetail, 1); |
| 3922 | 1720 if (fonts) |
| 1721 oldfont = fonts->data; | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1722 |
| 8309 | 1723 if (color && !(options & GTK_IMHTML_NO_COLOURS)) { |
| 3922 | 1724 font->fore = color; |
| 8061 | 1725 gtk_imhtml_toggle_forecolor(imhtml, font->fore); |
| 8309 | 1726 } |
| 1727 //else if (oldfont && oldfont->fore) | |
| 1728 // font->fore = g_strdup(oldfont->fore); | |
| 1729 | |
| 1730 if (back && !(options & GTK_IMHTML_NO_COLOURS)) { | |
| 3922 | 1731 font->back = back; |
| 8061 | 1732 gtk_imhtml_toggle_backcolor(imhtml, font->back); |
| 8309 | 1733 } |
| 1734 //else if (oldfont && oldfont->back) | |
| 1735 // font->back = g_strdup(oldfont->back); | |
| 1736 | |
| 1737 if (face && !(options & GTK_IMHTML_NO_FONTS)) { | |
| 3922 | 1738 font->face = face; |
| 8061 | 1739 gtk_imhtml_toggle_fontface(imhtml, font->face); |
| 8309 | 1740 } |
| 1741 //else if (oldfont && oldfont->face) | |
| 1742 // font->face = g_strdup(oldfont->face); | |
| 4032 | 1743 |
| 1744 if (sml) | |
| 1745 font->sml = sml; | |
| 1746 else if (oldfont && oldfont->sml) | |
| 1747 font->sml = g_strdup(oldfont->sml); | |
| 1748 | |
| 3922 | 1749 if (size && !(options & GTK_IMHTML_NO_SIZES)) { |
| 1750 if (*size == '+') { | |
| 1751 sscanf (size + 1, "%hd", &font->size); | |
| 1752 font->size += 3; | |
| 1753 } else if (*size == '-') { | |
| 1754 sscanf (size + 1, "%hd", &font->size); | |
| 1755 font->size = MAX (0, 3 - font->size); | |
| 1756 } else if (isdigit (*size)) { | |
| 1757 sscanf (size, "%hd", &font->size); | |
| 8061 | 1758 } |
| 6042 | 1759 if (font->size > 100) |
| 1760 font->size = 100; | |
| 3922 | 1761 } else if (oldfont) |
| 1762 font->size = oldfont->size; | |
| 8309 | 1763 else |
| 1764 font->size = 3; | |
| 1765 gtk_imhtml_font_set_size(imhtml, font->size); | |
| 3922 | 1766 g_free(size); |
| 1767 fonts = g_slist_prepend (fonts, font); | |
| 1768 } | |
| 1769 break; | |
| 1770 case 44: /* BODY (opt) */ | |
| 1771 if (!(options & GTK_IMHTML_NO_COLOURS)) { | |
| 1772 char *bgcolor = gtk_imhtml_get_html_opt (tag, "BGCOLOR="); | |
| 1773 if (bgcolor) { | |
| 8061 | 1774 if (url) |
| 1775 gtk_imhtml_insert_link(imhtml, url, ws); | |
| 1776 else | |
| 1777 gtk_text_buffer_insert(imhtml->text_buffer, &iter, ws, wpos); | |
| 1778 ws[0] = '\0'; wpos = 0; | |
| 8177 | 1779 /* NEW_BIT(NEW_TEXT_BIT); */ |
| 3922 | 1780 if (bg) |
| 1781 g_free(bg); | |
| 1782 bg = bgcolor; | |
| 8061 | 1783 gtk_imhtml_toggle_backcolor(imhtml, bg); |
|
2885
f72efa29c109
[gaim-migrate @ 2898]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2871
diff
changeset
|
1784 } |
| 1428 | 1785 } |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1786 break; |
| 3922 | 1787 case 45: /* A (opt) */ |
| 1788 { | |
| 1789 gchar *href = gtk_imhtml_get_html_opt (tag, "HREF="); | |
| 1790 if (href) { | |
| 8061 | 1791 if (url) { |
| 1792 gtk_imhtml_insert_link(imhtml, url, ws); | |
| 1793 g_free(url); | |
| 1794 } else | |
| 1795 gtk_text_buffer_insert(imhtml->text_buffer, &iter, ws, wpos); | |
| 1796 ws[0] = '\0'; wpos = 0; | |
| 3922 | 1797 url = href; |
| 1798 } | |
| 2993 | 1799 } |
| 3922 | 1800 break; |
| 4895 | 1801 case 46: /* IMG (opt) */ |
| 6982 | 1802 case 59: /* IMG */ |
| 4895 | 1803 { |
| 6982 | 1804 GdkPixbuf *img = NULL; |
| 1805 const gchar *filename = NULL; | |
| 4895 | 1806 |
| 6982 | 1807 if (images && images->data) { |
| 1808 img = images->data; | |
| 1809 images = images->next; | |
| 1810 filename = g_object_get_data(G_OBJECT(img), "filename"); | |
| 1811 g_object_ref(G_OBJECT(img)); | |
| 1812 } else { | |
| 1813 img = gtk_widget_render_icon(GTK_WIDGET(imhtml), | |
| 1814 GTK_STOCK_MISSING_IMAGE, GTK_ICON_SIZE_BUTTON, | |
| 1815 "gtkimhtml-missing-image"); | |
| 1816 } | |
| 4895 | 1817 |
| 6982 | 1818 scalable = gtk_imhtml_image_new(img, filename); |
| 8177 | 1819 /* NEW_BIT(NEW_SCALABLE_BIT); */ |
| 6982 | 1820 g_object_unref(G_OBJECT(img)); |
| 4895 | 1821 } |
| 3922 | 1822 case 47: /* P (opt) */ |
| 1823 case 48: /* H3 (opt) */ | |
| 5093 | 1824 case 49: /* HTML (opt) */ |
| 5101 | 1825 case 50: /* CITE */ |
| 1826 case 51: /* /CITE */ | |
| 8026 | 1827 case 56: /* SPAN (opt) */ |
| 8118 | 1828 /* Inline CSS Support - Douglas Thrift |
| 1829 * | |
| 1830 * color | |
| 1831 * font-family | |
| 1832 * font-size | |
| 1833 */ | |
| 1834 { | |
| 1835 gchar *style, *color, *family, *size; | |
| 1836 GtkIMHtmlFontDetail *font, *oldfont = NULL; | |
| 1837 style = gtk_imhtml_get_html_opt (tag, "style="); | |
| 1838 | |
| 1839 if (!style) break; | |
| 1840 | |
| 1841 color = gtk_imhtml_get_css_opt (style, "color: "); | |
| 1842 family = gtk_imhtml_get_css_opt (style, | |
| 1843 "font-family: "); | |
| 1844 size = gtk_imhtml_get_css_opt (style, "font-size: "); | |
| 1845 | |
| 8120 | 1846 if (!(color || family || size)) { |
| 1847 g_free(style); | |
| 1848 break; | |
| 1849 } | |
| 8118 | 1850 |
| 1851 if (url) | |
| 1852 gtk_imhtml_insert_link(imhtml, url, ws); | |
| 1853 else | |
| 1854 gtk_text_buffer_insert(imhtml->text_buffer, &iter, ws, wpos); | |
| 1855 ws[0] = '\0'; wpos = 0; | |
| 8177 | 1856 /* NEW_BIT (NEW_TEXT_BIT); */ |
| 8118 | 1857 |
| 1858 font = g_new0 (GtkIMHtmlFontDetail, 1); | |
| 1859 if (fonts) | |
| 1860 oldfont = fonts->data; | |
| 1861 | |
| 1862 if (color && !(options & GTK_IMHTML_NO_COLOURS)) | |
| 1863 font->fore = color; | |
| 1864 else if (oldfont && oldfont->fore) | |
| 1865 font->fore = g_strdup(oldfont->fore); | |
| 1866 | |
| 1867 if (oldfont && oldfont->back) | |
| 1868 font->back = g_strdup(oldfont->back); | |
| 1869 | |
| 1870 if (family && !(options & GTK_IMHTML_NO_FONTS)) | |
| 1871 font->face = family; | |
| 1872 else if (oldfont && oldfont->face) | |
| 1873 font->face = g_strdup(oldfont->face); | |
| 1874 if (font->face && (atoi(font->face) > 100)) { | |
| 1875 g_free(font->face); | |
| 1876 font->face = g_strdup("100"); | |
| 1877 } | |
| 1878 | |
| 1879 if (oldfont && oldfont->sml) | |
| 1880 font->sml = g_strdup(oldfont->sml); | |
| 1881 | |
| 1882 if (size && !(options & GTK_IMHTML_NO_SIZES)) { | |
| 1883 if (g_ascii_strcasecmp(size, "smaller") == 0) | |
| 1884 { | |
| 1885 font->size = 2; | |
| 1886 } | |
| 1887 else if (g_ascii_strcasecmp(size, "larger") == 0) | |
| 1888 { | |
| 1889 font->size = 4; | |
| 1890 } | |
| 1891 else | |
| 1892 { | |
| 1893 font->size = 3; | |
| 1894 } | |
| 1895 } else if (oldfont) | |
| 1896 font->size = oldfont->size; | |
| 1897 | |
| 1898 g_free(style); | |
| 1899 g_free(size); | |
| 1900 fonts = g_slist_prepend (fonts, font); | |
| 1901 } | |
| 1902 break; | |
| 5104 | 1903 case 57: /* /SPAN */ |
| 8118 | 1904 /* Inline CSS Support - Douglas Thrift */ |
| 1905 if (fonts) { | |
| 1906 GtkIMHtmlFontDetail *font = fonts->data; | |
| 1907 if (url) | |
| 1908 gtk_imhtml_insert_link(imhtml, url, ws); | |
| 1909 else | |
| 1910 gtk_text_buffer_insert(imhtml->text_buffer, &iter, ws, wpos); | |
| 1911 ws[0] = '\0'; wpos = 0; | |
| 8177 | 1912 /* NEW_BIT (NEW_TEXT_BIT); */ |
| 8118 | 1913 fonts = g_slist_remove (fonts, font); |
| 1914 if (font->face) | |
| 1915 g_free (font->face); | |
| 1916 if (font->fore) | |
| 1917 g_free (font->fore); | |
| 1918 if (font->back) | |
| 1919 g_free (font->back); | |
| 1920 if (font->sml) | |
| 1921 g_free (font->sml); | |
| 1922 g_free (font); | |
| 1923 } | |
| 1924 break; | |
| 8026 | 1925 case 60: /* SPAN */ |
| 2993 | 1926 break; |
| 8061 | 1927 case 62: /* comment */ |
| 8177 | 1928 /* NEW_BIT (NEW_TEXT_BIT); */ |
| 8317 | 1929 ws[wpos] = '\0'; |
| 1930 if (url) | |
| 1931 gtk_imhtml_insert_link(imhtml, url, ws); | |
| 1932 else | |
| 1933 gtk_text_buffer_insert(imhtml->text_buffer, &iter, ws, wpos); | |
| 6124 | 1934 if (imhtml->show_comments) |
| 1935 wpos = g_snprintf (ws, len, "%s", tag); | |
| 8177 | 1936 /* NEW_BIT (NEW_COMMENT_BIT); */ |
| 3922 | 1937 break; |
| 1938 default: | |
| 6882 | 1939 break; |
| 2993 | 1940 } |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1941 c += tlen; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1942 pos += tlen; |
| 4138 | 1943 if(tag) |
| 1944 g_free(tag); /* This was allocated back in VALID_TAG() */ | |
| 8473 | 1945 } else if (imhtml->show_smileys && (gtk_imhtml_is_smiley (imhtml, fonts, c, &smilelen) || gtk_imhtml_is_smiley(imhtml, NULL, c, &smilelen))) { |
| 1946 GtkIMHtmlFontDetail *fd; | |
| 1947 | |
| 1948 gchar *sml = NULL; | |
| 1949 if (fonts) { | |
| 1950 fd = fonts->data; | |
| 1951 sml = fd->sml; | |
| 1952 } | |
| 1953 if (url) | |
| 1954 gtk_imhtml_insert_link(imhtml, url, ws); | |
| 1955 else { | |
| 1956 gtk_text_buffer_insert(imhtml->text_buffer, &iter, ws, wpos); | |
| 1957 } | |
| 8505 | 1958 wpos = g_snprintf (ws, smilelen + 1, "%s", c); |
| 8473 | 1959 |
| 1960 gtk_imhtml_insert_smiley(imhtml, sml, ws); | |
| 1961 | |
| 1962 ins = gtk_text_buffer_get_insert(imhtml->text_buffer); | |
| 1963 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins); | |
| 1964 | |
| 8505 | 1965 c += smilelen; |
| 1966 pos += smilelen; | |
| 8473 | 1967 wpos = 0; |
| 1968 ws[0] = 0; | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1969 } else if (*c == '&' && gtk_imhtml_is_amp_escape (c, &, &tlen)) { |
| 7280 | 1970 while(*amp) { |
| 1971 ws [wpos++] = *amp++; | |
| 1972 } | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1973 c += tlen; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1974 pos += tlen; |
| 1428 | 1975 } else if (*c == '\n') { |
| 1976 if (!(options & GTK_IMHTML_NO_NEWLINE)) { | |
| 3922 | 1977 ws[wpos] = '\n'; |
| 1978 wpos++; | |
| 8061 | 1979 if (url) |
| 1980 gtk_imhtml_insert_link(imhtml, url, ws); | |
| 1981 else | |
| 1982 gtk_text_buffer_insert(imhtml->text_buffer, &iter, ws, wpos); | |
| 1983 ws[0] = '\0'; | |
| 1984 wpos = 0; | |
| 8177 | 1985 /* NEW_BIT (NEW_TEXT_BIT); */ |
| 1428 | 1986 } |
| 1987 c++; | |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1988 pos++; |
| 8334 | 1989 } else if ((len_protocol = gtk_imhtml_is_protocol(c)) > 0){ |
| 1990 while(len_protocol--){ | |
| 1991 /* Skip the next len_protocol characters, but make sure they're | |
| 1992 copied into the ws array. | |
| 1993 */ | |
| 1994 ws [wpos++] = *c++; | |
| 1995 pos++; | |
| 1996 } | |
| 8061 | 1997 } else if (*c) { |
| 1428 | 1998 ws [wpos++] = *c++; |
|
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1999 pos++; |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2000 } else { |
|
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2001 break; |
| 1428 | 2002 } |
| 2003 } | |
| 8061 | 2004 if (url) |
| 2005 gtk_imhtml_insert_link(imhtml, url, ws); | |
| 2006 else | |
| 2007 gtk_text_buffer_insert(imhtml->text_buffer, &iter, ws, wpos); | |
| 2008 ws[0] = '\0'; wpos = 0; | |
| 2009 | |
| 8177 | 2010 /* NEW_BIT(NEW_TEXT_BIT); */ |
| 1428 | 2011 if (url) { |
| 2012 g_free (url); | |
| 3922 | 2013 if (str) |
| 2014 str = g_string_append (str, "</A>"); | |
| 1428 | 2015 } |
| 8061 | 2016 |
| 4032 | 2017 while (fonts) { |
| 5967 | 2018 GtkIMHtmlFontDetail *font = fonts->data; |
| 4032 | 2019 fonts = g_slist_remove (fonts, font); |
| 2020 if (font->face) | |
| 2021 g_free (font->face); | |
| 2022 if (font->fore) | |
| 2023 g_free (font->fore); | |
| 2024 if (font->back) | |
| 2025 g_free (font->back); | |
| 2026 if (font->sml) | |
| 2027 g_free (font->sml); | |
| 2028 g_free (font); | |
| 2029 if (str) | |
| 2030 str = g_string_append (str, "</FONT>"); | |
| 2031 } | |
| 2032 | |
| 3922 | 2033 if (str) { |
| 1428 | 2034 while (bold) { |
| 3922 | 2035 str = g_string_append (str, "</B>"); |
| 1428 | 2036 bold--; |
| 2037 } | |
| 2038 while (italics) { | |
| 3922 | 2039 str = g_string_append (str, "</I>"); |
| 1428 | 2040 italics--; |
| 2041 } | |
| 2042 while (underline) { | |
| 3922 | 2043 str = g_string_append (str, "</U>"); |
| 1428 | 2044 underline--; |
| 2045 } | |
| 2046 while (strike) { | |
| 3922 | 2047 str = g_string_append (str, "</S>"); |
| 1428 | 2048 strike--; |
| 2049 } | |
| 2050 while (sub) { | |
| 3922 | 2051 str = g_string_append (str, "</SUB>"); |
| 1428 | 2052 sub--; |
| 2053 } | |
| 2054 while (sup) { | |
| 3922 | 2055 str = g_string_append (str, "</SUP>"); |
| 1428 | 2056 sup--; |
| 2057 } | |
| 2058 while (title) { | |
| 3922 | 2059 str = g_string_append (str, "</TITLE>"); |
| 1428 | 2060 title--; |
| 2061 } | |
|
1691
d802b115800f
[gaim-migrate @ 1701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1647
diff
changeset
|
2062 while (pre) { |
| 3922 | 2063 str = g_string_append (str, "</PRE>"); |
|
1691
d802b115800f
[gaim-migrate @ 1701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1647
diff
changeset
|
2064 pre--; |
|
d802b115800f
[gaim-migrate @ 1701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1647
diff
changeset
|
2065 } |
| 1428 | 2066 } |
| 4032 | 2067 g_free (ws); |
| 4630 | 2068 if(bg) |
| 2069 g_free(bg); | |
| 8506 | 2070 /* this shouldn't be necessary if we want to be able to continue |
| 2071 * using the format if it was unclosed. But seeing as removing this | |
| 2072 * line does not help the ctrl-up/down from enabling open tags, I'm | |
| 2073 * leaving it up to sean, or unless I find some time to look into it | |
| 2074 * more -Gary */ | |
| 2075 gtk_imhtml_close_tags(imhtml); | |
| 4032 | 2076 if (!(options & GTK_IMHTML_NO_SCROLL)) |
| 2077 gtk_text_view_scroll_to_mark (GTK_TEXT_VIEW (imhtml), mark, | |
| 2078 0, TRUE, 0.0, 1.0); | |
| 3922 | 2079 gtk_text_buffer_delete_mark (imhtml->text_buffer, mark); |
| 8061 | 2080 gtk_text_buffer_move_mark (imhtml->text_buffer, |
| 2081 gtk_text_buffer_get_mark (imhtml->text_buffer, "insert"), | |
| 2082 &iter); | |
| 8506 | 2083 |
| 2084 object = g_object_ref(G_OBJECT(imhtml)); | |
| 2085 g_signal_emit(object, signals[UPDATE_FORMAT], 0); | |
| 2086 g_object_unref(object); | |
| 2087 | |
| 3922 | 2088 return str; |
| 2089 } | |
| 2090 | |
| 4892 | 2091 void gtk_imhtml_remove_smileys(GtkIMHtml *imhtml) |
| 2092 { | |
| 4288 | 2093 g_hash_table_destroy(imhtml->smiley_data); |
| 2094 gtk_smiley_tree_destroy(imhtml->default_smilies); | |
| 4892 | 2095 imhtml->smiley_data = g_hash_table_new_full(g_str_hash, g_str_equal, |
| 4902 | 2096 g_free, (GDestroyNotify)gtk_smiley_tree_destroy); |
| 4288 | 2097 imhtml->default_smilies = gtk_smiley_tree_new(); |
| 2098 } | |
| 8481 | 2099 |
| 3922 | 2100 void gtk_imhtml_show_smileys (GtkIMHtml *imhtml, |
| 4253 | 2101 gboolean show) |
| 2102 { | |
| 2103 imhtml->show_smileys = show; | |
| 2104 } | |
| 3922 | 2105 |
| 2106 void gtk_imhtml_show_comments (GtkIMHtml *imhtml, | |
| 4253 | 2107 gboolean show) |
| 2108 { | |
| 6124 | 2109 imhtml->show_comments = show; |
| 4253 | 2110 } |
|
1780
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
2111 |
| 8456 | 2112 void gtk_imhtml_html_shortcuts (GtkIMHtml *imhtml, |
| 2113 gboolean allow) | |
| 2114 { | |
| 2115 imhtml->html_shortcuts = allow; | |
| 2116 } | |
| 2117 | |
| 2118 void gtk_imhtml_smiley_shortcuts (GtkIMHtml *imhtml, | |
| 2119 gboolean allow) | |
| 2120 { | |
| 2121 imhtml->smiley_shortcuts = allow; | |
| 2122 } | |
| 2123 | |
| 2124 void | |
| 2125 gtk_imhtml_set_protocol_name(GtkIMHtml *imhtml, gchar *protocol_name) { | |
| 2126 imhtml->protocol_name = protocol_name; | |
| 2127 } | |
| 2128 | |
|
1780
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
2129 void |
|
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
2130 gtk_imhtml_clear (GtkIMHtml *imhtml) |
|
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
2131 { |
| 7991 | 2132 GList *del; |
| 3922 | 2133 GtkTextIter start, end; |
| 8427 | 2134 GObject *object = g_object_ref(G_OBJECT(imhtml)); |
| 7991 | 2135 |
| 3922 | 2136 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start); |
| 2137 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end); | |
| 2138 gtk_text_buffer_delete(imhtml->text_buffer, &start, &end); | |
| 7991 | 2139 |
| 8061 | 2140 for(del = imhtml->format_spans; del; del = del->next) { |
| 2141 GtkIMHtmlFormatSpan *span = del->data; | |
| 2142 if (span->start_tag) | |
| 2143 g_free(span->start_tag); | |
| 2144 if (span->end_tag) | |
| 2145 g_free(span->end_tag); | |
| 2146 g_free(span); | |
| 2147 } | |
| 2148 g_list_free(imhtml->format_spans); | |
| 2149 imhtml->format_spans = NULL; | |
| 2150 | |
| 7991 | 2151 for(del = imhtml->scalables; del; del = del->next) { |
| 2152 GtkIMHtmlScalable *scale = del->data; | |
| 2153 scale->free(scale); | |
| 2154 } | |
| 2155 g_list_free(imhtml->scalables); | |
| 2156 imhtml->scalables = NULL; | |
| 8061 | 2157 |
| 2158 imhtml->edit.bold = NULL; | |
| 2159 imhtml->edit.italic = NULL; | |
| 2160 imhtml->edit.underline = NULL; | |
| 2161 imhtml->edit.fontface = NULL; | |
| 2162 imhtml->edit.forecolor = NULL; | |
| 2163 imhtml->edit.backcolor = NULL; | |
| 2164 imhtml->edit.sizespan = NULL; | |
| 2165 imhtml->edit.fontsize = 3; | |
| 8481 | 2166 |
| 8427 | 2167 g_signal_emit(object, signals[CLEAR_FORMAT], 0); |
| 2168 g_object_unref(object); | |
|
1780
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
2169 } |
|
2363
08c66712364c
[gaim-migrate @ 2376]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2349
diff
changeset
|
2170 |
| 4046 | 2171 void gtk_imhtml_page_up (GtkIMHtml *imhtml) |
| 2172 { | |
| 5282 | 2173 GdkRectangle rect; |
| 2174 GtkTextIter iter; | |
| 4046 | 2175 |
| 5282 | 2176 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); |
| 2177 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(imhtml), &iter, rect.x, | |
| 2178 rect.y - rect.height); | |
| 2179 gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(imhtml), &iter, 0, TRUE, 0, 0); | |
| 8061 | 2180 |
| 4046 | 2181 } |
| 5282 | 2182 void gtk_imhtml_page_down (GtkIMHtml *imhtml) |
| 2183 { | |
| 2184 GdkRectangle rect; | |
| 2185 GtkTextIter iter; | |
| 2186 | |
| 2187 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); | |
| 2188 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(imhtml), &iter, rect.x, | |
| 2189 rect.y + rect.height); | |
| 2190 gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(imhtml), &iter, 0, TRUE, 0, 0); | |
| 2191 } | |
| 4735 | 2192 |
| 5967 | 2193 /* GtkIMHtmlScalable, gtk_imhtml_image, gtk_imhtml_hr */ |
| 6982 | 2194 GtkIMHtmlScalable *gtk_imhtml_image_new(GdkPixbuf *img, const gchar *filename) |
| 4735 | 2195 { |
| 5967 | 2196 GtkIMHtmlImage *im_image = g_malloc(sizeof(GtkIMHtmlImage)); |
| 5012 | 2197 GtkImage *image = GTK_IMAGE(gtk_image_new_from_pixbuf(img)); |
| 4895 | 2198 |
| 5967 | 2199 GTK_IMHTML_SCALABLE(im_image)->scale = gtk_imhtml_image_scale; |
| 2200 GTK_IMHTML_SCALABLE(im_image)->add_to = gtk_imhtml_image_add_to; | |
| 2201 GTK_IMHTML_SCALABLE(im_image)->free = gtk_imhtml_image_free; | |
| 5046 | 2202 |
| 2203 im_image->pixbuf = img; | |
| 5012 | 2204 im_image->image = image; |
| 4895 | 2205 im_image->width = gdk_pixbuf_get_width(img); |
| 2206 im_image->height = gdk_pixbuf_get_height(img); | |
| 2207 im_image->mark = NULL; | |
| 6982 | 2208 im_image->filename = filename ? g_strdup(filename) : NULL; |
| 4895 | 2209 |
| 5046 | 2210 g_object_ref(img); |
| 4895 | 2211 return GTK_IMHTML_SCALABLE(im_image); |
| 2212 } | |
| 2213 | |
| 5967 | 2214 void gtk_imhtml_image_scale(GtkIMHtmlScalable *scale, int width, int height) |
| 4895 | 2215 { |
| 5967 | 2216 GtkIMHtmlImage *image = (GtkIMHtmlImage *)scale; |
| 4895 | 2217 |
| 2218 if(image->width > width || image->height > height){ | |
| 2219 GdkPixbuf *new_image = NULL; | |
| 2220 float factor; | |
| 2221 int new_width = image->width, new_height = image->height; | |
| 2222 | |
| 8588 | 2223 if(image->width > (width - 2)){ |
| 4895 | 2224 factor = (float)(width)/image->width; |
| 2225 new_width = width; | |
| 2226 new_height = image->height * factor; | |
| 2227 } | |
| 8588 | 2228 if(new_height >= (height - 2)){ |
| 4895 | 2229 factor = (float)(height)/new_height; |
| 2230 new_height = height; | |
| 2231 new_width = new_width * factor; | |
| 2232 } | |
| 2233 | |
| 5046 | 2234 new_image = gdk_pixbuf_scale_simple(image->pixbuf, new_width, new_height, GDK_INTERP_BILINEAR); |
| 5012 | 2235 gtk_image_set_from_pixbuf(image->image, new_image); |
| 4895 | 2236 g_object_unref(G_OBJECT(new_image)); |
| 2237 } | |
| 2238 } | |
| 2239 | |
| 5012 | 2240 static void write_img_to_file(GtkWidget *w, GtkFileSelection *sel) |
| 2241 { | |
| 2242 const gchar *filename = gtk_file_selection_get_filename(sel); | |
| 5967 | 2243 gchar *dirname; |
| 2244 GtkIMHtmlImage *image = g_object_get_data(G_OBJECT(sel), "GtkIMHtmlImage"); | |
| 5012 | 2245 gchar *type = NULL; |
| 5019 | 2246 GError *error = NULL; |
| 5015 | 2247 #if GTK_CHECK_VERSION(2,2,0) |
| 5012 | 2248 GSList *formats = gdk_pixbuf_get_formats(); |
| 6162 | 2249 #else |
| 2250 char *basename = g_path_get_basename(filename); | |
| 2251 char *ext = strrchr(basename, '.'); | |
| 5959 | 2252 #endif |
| 5012 | 2253 |
| 5967 | 2254 if (g_file_test(filename, G_FILE_TEST_IS_DIR)) { |
| 2255 /* append a / if needed */ | |
| 2256 if (filename[strlen(filename) - 1] != '/') { | |
| 2257 dirname = g_strconcat(filename, "/", NULL); | |
| 2258 } else { | |
| 2259 dirname = g_strdup(filename); | |
| 2260 } | |
| 2261 gtk_file_selection_set_filename(sel, dirname); | |
| 2262 g_free(dirname); | |
| 5959 | 2263 return; |
| 5967 | 2264 } |
| 5959 | 2265 |
| 2266 #if GTK_CHECK_VERSION(2,2,0) | |
| 5012 | 2267 while(formats){ |
| 2268 GdkPixbufFormat *format = formats->data; | |
| 2269 gchar **extensions = gdk_pixbuf_format_get_extensions(format); | |
| 2270 gpointer p = extensions; | |
| 2271 | |
| 2272 while(gdk_pixbuf_format_is_writable(format) && extensions && extensions[0]){ | |
| 2273 gchar *fmt_ext = extensions[0]; | |
| 2274 const gchar* file_ext = filename + strlen(filename) - strlen(fmt_ext); | |
| 2275 | |
| 2276 if(!strcmp(fmt_ext, file_ext)){ | |
| 2277 type = gdk_pixbuf_format_get_name(format); | |
| 2278 break; | |
| 2279 } | |
| 2280 | |
| 2281 extensions++; | |
| 2282 } | |
| 2283 | |
| 2284 g_strfreev(p); | |
| 2285 | |
| 2286 if(type) | |
| 2287 break; | |
| 2288 | |
| 2289 formats = formats->next; | |
| 2290 } | |
| 2291 | |
| 5020 | 2292 g_slist_free(formats); |
| 2293 #else | |
| 2294 /* this is really ugly code, but I think it will work */ | |
| 2295 if(ext) { | |
| 2296 ext++; | |
| 2297 if(!g_ascii_strcasecmp(ext, "jpeg") || !g_ascii_strcasecmp(ext, "jpg")) | |
| 2298 type = g_strdup("jpeg"); | |
| 2299 else if(!g_ascii_strcasecmp(ext, "png")) | |
| 2300 type = g_strdup("png"); | |
| 2301 } | |
| 2302 | |
| 2303 g_free(basename); | |
| 2304 #endif | |
| 2305 | |
| 5012 | 2306 /* If I can't find a valid type, I will just tell the user about it and then assume |
| 2307 it's a png */ | |
| 2308 if(!type){ | |
| 2309 gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, | |
| 5967 | 2310 _("Unable to guess the image type based on the file extension supplied. Defaulting to PNG.")); |
| 5012 | 2311 type = g_strdup("png"); |
| 2312 } | |
| 2313 | |
| 5046 | 2314 gdk_pixbuf_save(image->pixbuf, filename, type, &error, NULL); |
| 5012 | 2315 |
| 2316 if(error){ | |
| 2317 gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, | |
| 2318 _("Error saving image: %s"), error->message); | |
| 2319 g_error_free(error); | |
| 2320 } | |
| 2321 | |
| 2322 g_free(type); | |
| 2323 } | |
| 2324 | |
| 5967 | 2325 static void gtk_imhtml_image_save(GtkWidget *w, GtkIMHtmlImage *image) |
| 5012 | 2326 { |
| 5967 | 2327 GtkWidget *sel = gtk_file_selection_new(_("Save Image")); |
| 5012 | 2328 |
| 6982 | 2329 if (image->filename) |
| 2330 gtk_file_selection_set_filename(GTK_FILE_SELECTION(sel), image->filename); | |
| 5967 | 2331 g_object_set_data(G_OBJECT(sel), "GtkIMHtmlImage", image); |
| 5012 | 2332 g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(sel)->ok_button), "clicked", |
| 2333 G_CALLBACK(write_img_to_file), sel); | |
| 2334 | |
| 2335 g_signal_connect_swapped(G_OBJECT(GTK_FILE_SELECTION(sel)->ok_button), "clicked", | |
| 2336 G_CALLBACK(gtk_widget_destroy), sel); | |
| 2337 g_signal_connect_swapped(G_OBJECT(GTK_FILE_SELECTION(sel)->cancel_button), "clicked", | |
| 8061 | 2338 G_CALLBACK(gtk_widget_destroy), sel); |
| 5012 | 2339 |
| 2340 gtk_widget_show(sel); | |
| 2341 } | |
| 2342 | |
| 5967 | 2343 static gboolean gtk_imhtml_image_clicked(GtkWidget *w, GdkEvent *event, GtkIMHtmlImage *image) |
| 5012 | 2344 { |
| 2345 GdkEventButton *event_button = (GdkEventButton *) event; | |
| 2346 | |
| 2347 if (event->type == GDK_BUTTON_RELEASE) { | |
| 2348 if(event_button->button == 3) { | |
| 2349 GtkWidget *img, *item, *menu; | |
| 2350 gchar *text = g_strdup_printf(_("_Save Image...")); | |
| 2351 menu = gtk_menu_new(); | |
| 2352 | |
| 2353 /* buttons and such */ | |
| 2354 img = gtk_image_new_from_stock(GTK_STOCK_SAVE, GTK_ICON_SIZE_MENU); | |
| 2355 item = gtk_image_menu_item_new_with_mnemonic(text); | |
| 2356 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), img); | |
| 5967 | 2357 g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(gtk_imhtml_image_save), image); |
| 5012 | 2358 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); |
| 2359 | |
| 2360 gtk_widget_show_all(menu); | |
| 2361 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, | |
| 2362 event_button->button, event_button->time); | |
| 2363 | |
| 2364 g_free(text); | |
| 2365 return TRUE; | |
| 2366 } | |
| 2367 } | |
| 2368 if(event->type == GDK_BUTTON_PRESS && event_button->button == 3) | |
| 2369 return TRUE; /* Clicking the right mouse button on a link shouldn't | |
| 2370 be caught by the regular GtkTextView menu */ | |
| 2371 else | |
| 2372 return FALSE; /* Let clicks go through if we didn't catch anything */ | |
| 2373 | |
| 2374 } | |
| 5967 | 2375 void gtk_imhtml_image_free(GtkIMHtmlScalable *scale) |
| 2376 { | |
| 2377 GtkIMHtmlImage *image = (GtkIMHtmlImage *)scale; | |
| 2378 | |
| 2379 g_object_unref(image->pixbuf); | |
| 6982 | 2380 if (image->filename) |
| 2381 g_free(image->filename); | |
| 5967 | 2382 g_free(scale); |
| 2383 } | |
| 2384 | |
| 2385 void gtk_imhtml_image_add_to(GtkIMHtmlScalable *scale, GtkIMHtml *imhtml, GtkTextIter *iter) | |
| 2386 { | |
| 2387 GtkIMHtmlImage *image = (GtkIMHtmlImage *)scale; | |
| 2388 GtkWidget *box = gtk_event_box_new(); | |
| 2389 GtkTextChildAnchor *anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, iter); | |
| 2390 | |
| 2391 gtk_container_add(GTK_CONTAINER(box), GTK_WIDGET(image->image)); | |
| 2392 | |
| 2393 gtk_widget_show(GTK_WIDGET(image->image)); | |
| 2394 gtk_widget_show(box); | |
| 2395 | |
| 2396 gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(imhtml), box, anchor); | |
| 2397 g_signal_connect(G_OBJECT(box), "event", G_CALLBACK(gtk_imhtml_image_clicked), image); | |
| 2398 } | |
| 2399 | |
| 2400 GtkIMHtmlScalable *gtk_imhtml_hr_new() | |
| 2401 { | |
| 2402 GtkIMHtmlHr *hr = g_malloc(sizeof(GtkIMHtmlHr)); | |
| 2403 | |
| 2404 GTK_IMHTML_SCALABLE(hr)->scale = gtk_imhtml_hr_scale; | |
| 2405 GTK_IMHTML_SCALABLE(hr)->add_to = gtk_imhtml_hr_add_to; | |
| 2406 GTK_IMHTML_SCALABLE(hr)->free = gtk_imhtml_hr_free; | |
| 2407 | |
| 2408 hr->sep = gtk_hseparator_new(); | |
| 2409 gtk_widget_set_size_request(hr->sep, 5000, 2); | |
| 2410 gtk_widget_show(hr->sep); | |
| 2411 | |
| 2412 return GTK_IMHTML_SCALABLE(hr); | |
| 2413 } | |
| 2414 | |
| 2415 void gtk_imhtml_hr_scale(GtkIMHtmlScalable *scale, int width, int height) | |
| 2416 { | |
| 8588 | 2417 gtk_widget_set_size_request(((GtkIMHtmlHr *)scale)->sep, width - 2, 2); |
| 5967 | 2418 } |
| 2419 | |
| 2420 void gtk_imhtml_hr_add_to(GtkIMHtmlScalable *scale, GtkIMHtml *imhtml, GtkTextIter *iter) | |
| 2421 { | |
| 2422 GtkIMHtmlHr *hr = (GtkIMHtmlHr *)scale; | |
| 2423 GtkTextChildAnchor *anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, iter); | |
| 8061 | 2424 g_object_set_data(G_OBJECT(anchor), "text_tag", "<hr>"); |
| 5967 | 2425 gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(imhtml), hr->sep, anchor); |
| 2426 } | |
| 2427 | |
| 2428 void gtk_imhtml_hr_free(GtkIMHtmlScalable *scale) | |
| 2429 { | |
| 2430 g_free(scale); | |
| 2431 } | |
| 7295 | 2432 |
| 2433 gboolean gtk_imhtml_search_find(GtkIMHtml *imhtml, const gchar *text) | |
| 2434 { | |
| 2435 GtkTextIter iter, start, end; | |
| 2436 gboolean new_search = TRUE; | |
| 2437 | |
| 2438 g_return_val_if_fail(imhtml != NULL, FALSE); | |
| 2439 g_return_val_if_fail(text != NULL, FALSE); | |
| 8061 | 2440 |
| 7295 | 2441 if (imhtml->search_string && !strcmp(text, imhtml->search_string)) |
| 2442 new_search = FALSE; | |
| 8061 | 2443 |
| 7295 | 2444 if (new_search) { |
| 2445 gtk_imhtml_search_clear(imhtml); | |
| 2446 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &iter); | |
| 2447 } else { | |
| 2448 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, | |
| 8061 | 2449 gtk_text_buffer_get_mark(imhtml->text_buffer, "search")); |
| 7295 | 2450 } |
| 2451 imhtml->search_string = g_strdup(text); | |
| 2452 | |
| 7358 | 2453 if (gtk_source_iter_forward_search(&iter, imhtml->search_string, |
| 2454 GTK_SOURCE_SEARCH_VISIBLE_ONLY | GTK_SOURCE_SEARCH_CASE_INSENSITIVE, | |
| 7295 | 2455 &start, &end, NULL)) { |
| 2456 | |
| 2457 gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(imhtml), &start, 0, TRUE, 0, 0); | |
| 2458 gtk_text_buffer_create_mark(imhtml->text_buffer, "search", &end, FALSE); | |
| 2459 if (new_search) { | |
| 2460 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "search", &iter, &end); | |
| 8061 | 2461 do |
| 7295 | 2462 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "search", &start, &end); |
| 8061 | 2463 while (gtk_source_iter_forward_search(&end, imhtml->search_string, |
| 2464 GTK_SOURCE_SEARCH_VISIBLE_ONLY | | |
| 7358 | 2465 GTK_SOURCE_SEARCH_CASE_INSENSITIVE, |
| 7295 | 2466 &start, &end, NULL)); |
| 2467 } | |
| 2468 return TRUE; | |
| 2469 } | |
| 8061 | 2470 |
| 2471 gtk_imhtml_search_clear(imhtml); | |
| 2472 | |
| 7295 | 2473 return FALSE; |
| 2474 } | |
| 2475 | |
| 2476 void gtk_imhtml_search_clear(GtkIMHtml *imhtml) | |
| 2477 { | |
| 2478 GtkTextIter start, end; | |
| 8061 | 2479 |
| 7295 | 2480 g_return_if_fail(imhtml != NULL); |
| 8061 | 2481 |
| 7295 | 2482 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start); |
| 2483 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end); | |
| 2484 | |
| 2485 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "search", &start, &end); | |
| 2486 if (imhtml->search_string) | |
| 2487 g_free(imhtml->search_string); | |
| 2488 imhtml->search_string = NULL; | |
| 2489 } | |
| 8061 | 2490 |
| 2491 /* Editable stuff */ | |
| 2492 static void insert_cb(GtkTextBuffer *buffer, GtkTextIter *iter, gchar *text, gint len, GtkIMHtml *imhtml) | |
| 2493 { | |
| 2494 GtkIMHtmlFormatSpan *span = NULL; | |
| 2495 GtkTextIter end; | |
| 2496 | |
| 2497 gtk_text_iter_forward_chars(iter, len); | |
| 2498 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end); | |
| 2499 gtk_text_iter_forward_char(&end); | |
| 2500 | |
| 2501 if (!gtk_text_iter_equal(&end, iter)) | |
| 2502 return; | |
| 2503 | |
| 2504 | |
| 2505 if ((span = imhtml->edit.bold)) { | |
| 2506 GtkTextIter bold; | |
| 2507 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &bold, span->start); | |
| 2508 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "BOLD", &bold, iter); | |
| 2509 } | |
| 2510 | |
| 2511 if ((span = imhtml->edit.italic)) { | |
| 2512 GtkTextIter italic; | |
| 2513 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &italic, span->start); | |
| 2514 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "ITALICS", &italic, | |
| 2515 iter); | |
| 2516 } | |
| 2517 | |
| 2518 if ((span = imhtml->edit.underline)) { | |
| 2519 GtkTextIter underline; | |
| 2520 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &underline, span->start); | |
| 2521 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "UNDERLINE", &underline, | |
| 2522 iter); | |
| 2523 } | |
| 2524 | |
| 2525 if ((span = imhtml->edit.forecolor)) { | |
| 2526 GtkTextIter fore; | |
| 2527 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &fore, span->start); | |
| 2528 gtk_text_buffer_apply_tag(imhtml->text_buffer, span->tag, &fore, iter); | |
| 2529 } | |
| 2530 | |
| 2531 if ((span = imhtml->edit.backcolor)) { | |
| 2532 GtkTextIter back; | |
| 2533 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &back, span->start); | |
| 2534 gtk_text_buffer_apply_tag(imhtml->text_buffer, span->tag, &back, iter); | |
| 2535 } | |
| 2536 | |
| 2537 if ((span = imhtml->edit.fontface)) { | |
| 2538 GtkTextIter face; | |
| 2539 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &face, span->start); | |
| 2540 gtk_text_buffer_apply_tag(imhtml->text_buffer, span->tag, &face, iter); | |
| 2541 } | |
| 2542 | |
| 2543 if ((span = imhtml->edit.sizespan)) { | |
| 2544 GtkTextIter size; | |
| 2545 /* We create the tags here so that one can grow font or shrink font several times | |
| 2546 * in a row without creating unnecessary tags */ | |
| 2547 if (span->tag == NULL) { | |
| 2548 span->tag = gtk_text_buffer_create_tag | |
| 8309 | 2549 (imhtml->text_buffer, NULL, "scale", (double)_point_sizes [imhtml->edit.fontsize-1], NULL); |
| 8061 | 2550 span->start_tag = g_strdup_printf("<font size=\"%d\">", imhtml->edit.fontsize); |
| 2551 span->end_tag = g_strdup("</font>"); | |
| 2552 } | |
| 2553 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &size, span->start); | |
| 2554 gtk_text_buffer_apply_tag(imhtml->text_buffer, span->tag, &size, iter); | |
| 2555 } | |
| 2556 } | |
| 2557 | |
| 2558 void gtk_imhtml_set_editable(GtkIMHtml *imhtml, gboolean editable) | |
| 2559 { | |
| 2560 gtk_text_view_set_editable(GTK_TEXT_VIEW(imhtml), editable); | |
| 8177 | 2561 /* |
| 2562 * We need a visible caret for accessibility, so mouseless | |
| 2563 * people can highlight stuff. | |
| 2564 */ | |
| 2565 /* gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(imhtml), editable); */ | |
| 8061 | 2566 imhtml->editable = editable; |
| 8420 | 2567 imhtml->format_functions = !editable ? 0 : -1; |
| 2568 } | |
| 2569 | |
| 2570 void gtk_imhtml_set_format_functions(GtkIMHtml *imhtml, GtkIMHtmlButtons buttons) | |
| 2571 { | |
| 2572 GObject *object = g_object_ref(G_OBJECT(imhtml)); | |
| 2573 g_signal_emit(object, signals[BUTTONS_UPDATE], 0, buttons); | |
| 2574 imhtml->format_functions = buttons; | |
| 2575 g_object_unref(object); | |
| 8061 | 2576 } |
| 2577 | |
| 8516 | 2578 static gboolean |
| 2579 gtk_imhtml_has_open_tags(GtkIMHtml *imhtml) { | |
| 2580 if(imhtml->edit.bold && imhtml->edit.bold->end == NULL) | |
| 2581 return TRUE; | |
| 2582 | |
| 2583 if(imhtml->edit.italic && imhtml->edit.italic->end == NULL) | |
| 2584 return TRUE; | |
| 2585 | |
| 2586 if(imhtml->edit.underline && imhtml->edit.underline->end == NULL) | |
| 2587 return TRUE; | |
| 2588 | |
| 2589 if(imhtml->edit.forecolor && imhtml->edit.forecolor->end == NULL) | |
| 2590 return TRUE; | |
| 2591 | |
| 2592 if(imhtml->edit.backcolor && imhtml->edit.backcolor->end == NULL) | |
| 2593 return TRUE; | |
| 2594 | |
| 2595 if(imhtml->edit.fontface && imhtml->edit.fontface->end == NULL) | |
| 2596 return TRUE; | |
| 2597 | |
| 2598 if(imhtml->edit.sizespan && imhtml->edit.sizespan->end == NULL) | |
| 2599 return TRUE; | |
| 2600 | |
| 2601 return FALSE; | |
| 2602 } | |
| 2603 | |
| 2604 void gtk_imhtml_get_current_format(GtkIMHtml *imhtml, gboolean *bold, | |
| 2605 gboolean *italic, gboolean *underline) | |
| 8481 | 2606 { |
| 2607 GtkTextMark *ins_mark; | |
| 8516 | 2608 GtkTextIter ins_iter; |
| 8481 | 2609 GSList *tags; |
| 8516 | 2610 |
| 8481 | 2611 ins_mark = gtk_text_buffer_get_insert(imhtml->text_buffer); |
| 2612 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &ins_iter, ins_mark); | |
| 8516 | 2613 |
| 2614 if(gtk_imhtml_has_open_tags(imhtml)) { | |
| 2615 GtkTextIter end_iter; | |
| 2616 gint position, length; | |
| 2617 | |
| 2618 position = gtk_text_iter_get_offset(&ins_iter); | |
| 2619 | |
| 2620 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end_iter); | |
| 2621 length = gtk_text_iter_get_offset(&end_iter); | |
| 2622 | |
| 2623 if(position == length) | |
| 2624 gtk_text_buffer_get_iter_at_offset(imhtml->text_buffer, &ins_iter, | |
| 2625 length - 1); | |
| 8481 | 2626 } |
| 8516 | 2627 |
| 2628 for(tags = gtk_text_iter_get_tags(&ins_iter); | |
| 8481 | 2629 tags != NULL; tags = tags->next) |
| 2630 { | |
| 2631 GtkTextTag *tag = GTK_TEXT_TAG(tags->data); | |
| 2632 if(tag->name) { | |
| 2633 if(g_ascii_strcasecmp(tag->name, "BOLD") == 0) | |
| 2634 (*bold) = TRUE; | |
| 2635 if(g_ascii_strcasecmp(tag->name, "ITALICS") == 0) | |
| 2636 (*italic) = TRUE; | |
| 2637 if(g_ascii_strcasecmp(tag->name, "UNDERLINE") == 0) | |
| 2638 (*underline) = TRUE; | |
| 2639 } | |
| 2640 } | |
| 2641 } | |
| 2642 | |
| 8061 | 2643 gboolean gtk_imhtml_get_editable(GtkIMHtml *imhtml) |
| 2644 { | |
| 2645 return imhtml->editable; | |
| 2646 } | |
| 2647 | |
| 2648 gboolean gtk_imhtml_toggle_bold(GtkIMHtml *imhtml) | |
| 2649 { | |
| 2650 GtkIMHtmlFormatSpan *span; | |
| 8481 | 2651 GObject *object; |
| 8061 | 2652 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); |
| 2653 GtkTextIter iter; | |
| 8481 | 2654 |
| 8061 | 2655 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins); |
| 8481 | 2656 |
| 8061 | 2657 if (!imhtml->edit.bold) { |
| 8481 | 2658 span = g_new0(GtkIMHtmlFormatSpan, 1); |
| 8061 | 2659 span->start = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); |
| 2660 span->start_tag = g_strdup("<b>"); | |
| 2661 span->end = NULL; | |
| 2662 span->end_tag = g_strdup("</b>"); | |
| 2663 span->buffer = imhtml->text_buffer; | |
| 8481 | 2664 span->tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), "BOLD"); |
| 8061 | 2665 imhtml->edit.bold = span; |
| 2666 imhtml->format_spans = g_list_append(imhtml->format_spans, span); | |
| 2667 } else { | |
| 8428 | 2668 GtkTextIter start; |
| 8061 | 2669 span = imhtml->edit.bold; |
| 2670 span->end = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); | |
| 8428 | 2671 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &start, span->start); |
| 8568 | 2672 if (gtk_text_iter_equal(&start, &iter)) { |
| 2673 /* Format turned off before any text was entered, so remove the tag */ | |
| 8428 | 2674 imhtml->format_spans = g_list_remove(imhtml->format_spans, span); |
| 2675 if (span->start_tag) | |
| 2676 g_free(span->start_tag); | |
| 2677 if (span->end_tag) | |
| 2678 g_free(span->end_tag); | |
| 2679 g_free(span); | |
| 2680 } | |
| 8061 | 2681 imhtml->edit.bold = NULL; |
| 2682 } | |
| 8481 | 2683 |
| 2684 object = g_object_ref(G_OBJECT(imhtml)); | |
| 2685 g_signal_emit(object, signals[TOGGLE_FORMAT], 0, GTK_IMHTML_BOLD); | |
| 2686 g_object_unref(object); | |
| 2687 | |
| 2688 return (imhtml->edit.bold != NULL); | |
| 8061 | 2689 } |
| 2690 | |
| 2691 gboolean gtk_imhtml_toggle_italic(GtkIMHtml *imhtml) | |
| 2692 { | |
| 2693 GtkIMHtmlFormatSpan *span; | |
| 8481 | 2694 GObject *object; |
| 8061 | 2695 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); |
| 2696 GtkTextIter iter; | |
| 8481 | 2697 |
| 8061 | 2698 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins); |
| 8481 | 2699 |
| 8061 | 2700 if (!imhtml->edit.italic) { |
| 8481 | 2701 span = g_new0(GtkIMHtmlFormatSpan, 1); |
| 8061 | 2702 span->start = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); |
| 2703 span->start_tag = g_strdup("<i>"); | |
| 2704 span->end = NULL; | |
| 2705 span->end_tag = g_strdup("</i>"); | |
| 2706 span->buffer = imhtml->text_buffer; | |
| 2707 span->tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), "ITALIC"); | |
| 2708 imhtml->edit.italic = span; | |
| 2709 imhtml->format_spans = g_list_append(imhtml->format_spans, span); | |
| 2710 } else { | |
| 8428 | 2711 GtkTextIter start; |
| 8061 | 2712 span = imhtml->edit.italic; |
| 2713 span->end = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); | |
| 8428 | 2714 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &start, span->start); |
| 2715 if (gtk_text_iter_equal(&start, &iter)) { /* Format turned off before any text was entered, so remove the tag */ | |
| 2716 imhtml->format_spans = g_list_remove(imhtml->format_spans, span); | |
| 2717 if (span->start_tag) | |
| 2718 g_free(span->start_tag); | |
| 2719 if (span->end_tag) | |
| 2720 g_free(span->end_tag); | |
| 2721 g_free(span); | |
| 2722 } | |
| 8061 | 2723 imhtml->edit.italic = NULL; |
| 2724 } | |
| 8481 | 2725 |
| 2726 object = g_object_ref(G_OBJECT(imhtml)); | |
| 2727 g_signal_emit(object, signals[TOGGLE_FORMAT], 0, GTK_IMHTML_ITALIC); | |
| 2728 g_object_unref(object); | |
| 2729 | |
| 8061 | 2730 return imhtml->edit.italic != NULL; |
| 2731 } | |
| 2732 | |
| 2733 gboolean gtk_imhtml_toggle_underline(GtkIMHtml *imhtml) | |
| 2734 { | |
| 2735 GtkIMHtmlFormatSpan *span; | |
| 8481 | 2736 GObject *object; |
| 8061 | 2737 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); |
| 2738 GtkTextIter iter; | |
| 8481 | 2739 |
| 8061 | 2740 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins); |
| 8481 | 2741 |
| 8061 | 2742 if (!imhtml->edit.underline) { |
| 8481 | 2743 span = g_new0(GtkIMHtmlFormatSpan, 1); |
| 8061 | 2744 span->start = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); |
| 2745 span->start_tag = g_strdup("<u>"); | |
| 2746 span->end = NULL; | |
| 2747 span->end_tag = g_strdup("</u>"); | |
| 2748 span->buffer = imhtml->text_buffer; | |
| 2749 span->tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), "UNDERLINE"); | |
| 2750 imhtml->edit.underline = span; | |
| 2751 imhtml->format_spans = g_list_append(imhtml->format_spans, span); | |
| 2752 } else { | |
| 8428 | 2753 GtkTextIter start; |
| 8061 | 2754 span = imhtml->edit.underline; |
| 2755 span->end = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); | |
| 8428 | 2756 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &start, span->start); |
| 2757 if (gtk_text_iter_equal(&start, &iter)) { /* Format turned off before any text was entered, so remove the tag */ | |
| 2758 imhtml->format_spans = g_list_remove(imhtml->format_spans, span); | |
| 2759 if (span->start_tag) | |
| 2760 g_free(span->start_tag); | |
| 2761 if (span->end_tag) | |
| 2762 g_free(span->end_tag); | |
| 2763 g_free(span); | |
| 2764 } | |
| 8061 | 2765 imhtml->edit.underline = NULL; |
| 2766 } | |
| 8481 | 2767 |
| 2768 object = g_object_ref(G_OBJECT(imhtml)); | |
| 2769 g_signal_emit(object, signals[TOGGLE_FORMAT], 0, GTK_IMHTML_UNDERLINE); | |
| 2770 g_object_unref(object); | |
| 2771 | |
| 8061 | 2772 return imhtml->edit.underline != NULL; |
| 2773 } | |
| 2774 | |
| 2775 void gtk_imhtml_font_set_size(GtkIMHtml *imhtml, gint size) | |
| 2776 { | |
| 2777 GtkIMHtmlFormatSpan *span; | |
| 2778 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); | |
| 2779 GtkTextIter iter; | |
| 2780 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins); | |
| 2781 | |
| 2782 imhtml->edit.fontsize = size; | |
| 2783 | |
| 2784 if (imhtml->edit.sizespan) { | |
| 2785 GtkTextIter iter2; | |
| 2786 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter2, imhtml->edit.sizespan->start); | |
| 2787 if (gtk_text_iter_equal(&iter2, &iter)) | |
| 2788 return; | |
| 2789 span = imhtml->edit.sizespan; | |
| 2790 span->end = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); | |
| 2791 } | |
| 2792 if (size != -1) { | |
| 8250 | 2793 span = g_malloc0(sizeof(GtkIMHtmlFormatSpan)); |
| 8061 | 2794 span->start = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); |
| 2795 span->end = NULL; | |
| 2796 span->buffer = imhtml->text_buffer; | |
| 2797 span->tag = NULL; | |
| 2798 imhtml->edit.sizespan = span; | |
| 2799 imhtml->format_spans = g_list_append(imhtml->format_spans, span); | |
| 2800 } | |
| 2801 } | |
| 2802 | |
| 2803 void gtk_imhtml_font_shrink(GtkIMHtml *imhtml) | |
| 2804 { | |
| 2805 GtkIMHtmlFormatSpan *span; | |
| 2806 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); | |
| 2807 GtkTextIter iter; | |
| 2808 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins); | |
| 2809 if (imhtml->edit.fontsize == 1) | |
| 2810 return; | |
| 2811 | |
| 2812 imhtml->edit.fontsize--; | |
| 2813 | |
| 2814 if (imhtml->edit.sizespan) { | |
| 2815 GtkTextIter iter2; | |
| 2816 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter2, imhtml->edit.sizespan->start); | |
| 2817 if (gtk_text_iter_equal(&iter2, &iter)) | |
| 2818 return; | |
| 2819 span = imhtml->edit.sizespan; | |
| 2820 span->end = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); | |
| 2821 } | |
| 2822 | |
| 8250 | 2823 span = g_malloc0(sizeof(GtkIMHtmlFormatSpan)); |
| 8061 | 2824 span->start = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); |
| 2825 span->end = NULL; | |
| 2826 span->buffer = imhtml->text_buffer; | |
| 2827 span->tag = NULL; | |
| 2828 imhtml->edit.sizespan = span; | |
| 2829 imhtml->format_spans = g_list_append(imhtml->format_spans, span); | |
| 2830 } | |
| 2831 | |
| 2832 void gtk_imhtml_font_grow(GtkIMHtml *imhtml) | |
| 2833 { | |
| 2834 GtkIMHtmlFormatSpan *span; | |
| 2835 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); | |
| 2836 GtkTextIter iter; | |
| 2837 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins); | |
| 2838 if (imhtml->edit.fontsize == MAX_FONT_SIZE) | |
| 2839 return; | |
| 2840 | |
| 2841 imhtml->edit.fontsize++; | |
| 2842 if (imhtml->edit.sizespan) { | |
| 2843 GtkTextIter iter2; | |
| 2844 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter2, imhtml->edit.sizespan->start); | |
| 2845 if (gtk_text_iter_equal(&iter2, &iter)) | |
| 2846 return; | |
| 2847 span = imhtml->edit.sizespan; | |
| 2848 span->end = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); | |
| 2849 } | |
| 2850 | |
| 8250 | 2851 span = g_malloc0(sizeof(GtkIMHtmlFormatSpan)); |
| 8061 | 2852 span->start = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); |
| 2853 span->end = NULL; | |
| 2854 span->tag = NULL; | |
| 2855 span->buffer = imhtml->text_buffer; | |
| 2856 imhtml->edit.sizespan = span; | |
| 2857 imhtml->format_spans = g_list_append(imhtml->format_spans, span); | |
| 2858 } | |
| 2859 | |
| 2860 gboolean gtk_imhtml_toggle_forecolor(GtkIMHtml *imhtml, const char *color) | |
| 2861 { | |
| 2862 GtkIMHtmlFormatSpan *span; | |
| 2863 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); | |
| 2864 GtkTextIter iter; | |
| 2865 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins); | |
| 8429 | 2866 if (color) { |
| 8061 | 2867 span = g_malloc(sizeof(GtkIMHtmlFormatSpan)); |
| 2868 span->start = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); | |
| 2869 span->start_tag = g_strdup_printf("<font color=\"%s\">", color); | |
| 2870 span->end = NULL; | |
| 2871 span->end_tag = g_strdup("</font>"); | |
| 2872 span->buffer = imhtml->text_buffer; | |
| 2873 span->tag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "foreground", color, NULL); | |
| 2874 imhtml->edit.forecolor = span; | |
| 2875 imhtml->format_spans = g_list_append(imhtml->format_spans, span); | |
| 2876 } else { | |
| 2877 span = imhtml->edit.forecolor; | |
| 2878 span->end = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); | |
| 2879 imhtml->edit.forecolor = NULL; | |
| 2880 } | |
| 2881 | |
| 2882 | |
| 2883 return imhtml->edit.forecolor != NULL; | |
| 2884 } | |
| 2885 | |
| 2886 gboolean gtk_imhtml_toggle_backcolor(GtkIMHtml *imhtml, const char *color) | |
| 2887 { | |
| 2888 GtkIMHtmlFormatSpan *span; | |
| 2889 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); | |
| 2890 GtkTextIter iter; | |
| 2891 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins); | |
| 8429 | 2892 if (color) { |
| 8061 | 2893 span = g_malloc(sizeof(GtkIMHtmlFormatSpan)); |
| 2894 span->start = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); | |
| 2895 span->start_tag = g_strdup_printf("<font back=\"%s\">", color); | |
| 2896 span->end = NULL; | |
| 2897 span->end_tag = g_strdup("</font>"); | |
| 2898 span->buffer = imhtml->text_buffer; | |
| 2899 span->tag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "background", color, NULL); | |
| 2900 imhtml->edit.backcolor = span; | |
| 2901 imhtml->format_spans = g_list_append(imhtml->format_spans, span); | |
| 2902 } else { | |
| 2903 span = imhtml->edit.backcolor; | |
| 2904 span->end = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); | |
| 2905 imhtml->edit.backcolor = NULL; | |
| 2906 } | |
| 2907 return imhtml->edit.backcolor != NULL; | |
| 2908 } | |
| 2909 | |
| 2910 gboolean gtk_imhtml_toggle_fontface(GtkIMHtml *imhtml, const char *face) | |
| 2911 { | |
| 2912 GtkIMHtmlFormatSpan *span; | |
| 2913 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); | |
| 2914 GtkTextIter iter; | |
| 2915 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins); | |
| 8429 | 2916 if (face) { |
| 8061 | 2917 span = g_malloc(sizeof(GtkIMHtmlFormatSpan)); |
| 2918 span->start = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); | |
| 2919 span->start_tag = g_strdup_printf("<font face=\"%s\">", face); | |
| 2920 span->end = NULL; | |
| 2921 span->end_tag = g_strdup("</font>"); | |
| 2922 span->buffer = imhtml->text_buffer; | |
| 2923 span->tag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "family", face, NULL); | |
| 2924 imhtml->edit.fontface = span; | |
| 2925 imhtml->format_spans = g_list_append(imhtml->format_spans, span); | |
| 2926 } else { | |
| 2927 span = imhtml->edit.fontface; | |
| 2928 span->end = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); | |
| 2929 imhtml->edit.fontface = NULL; | |
| 2930 } | |
| 2931 return imhtml->edit.fontface != NULL; | |
| 2932 } | |
| 2933 | |
| 2934 void gtk_imhtml_insert_link(GtkIMHtml *imhtml, const char *url, const char *text) | |
| 2935 { | |
| 2936 GtkIMHtmlFormatSpan *span = g_malloc(sizeof(GtkIMHtmlFormatSpan)); | |
| 2937 GtkTextMark *mark = gtk_text_buffer_get_insert(imhtml->text_buffer); | |
| 2938 GtkTextIter iter; | |
| 2939 GtkTextTag *tag, *linktag; | |
| 2940 | |
| 2941 tag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, NULL); | |
| 2942 g_object_set_data(G_OBJECT(tag), "link_url", g_strdup(url)); | |
| 2943 | |
| 2944 linktag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), "LINK"); | |
| 2945 | |
| 2946 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, mark); | |
| 2947 span->start = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); | |
| 2948 span->buffer = imhtml->text_buffer; | |
| 2949 span->start_tag = g_strdup_printf("<a href=\"%s\">", url); | |
| 2950 span->end_tag = g_strdup("</a>"); | |
| 2951 g_signal_connect(G_OBJECT(tag), "event", G_CALLBACK(tag_event), g_strdup(url)); | |
| 2952 | |
| 2953 gtk_text_buffer_insert_with_tags(imhtml->text_buffer, &iter, text, strlen(text), linktag, tag, NULL); | |
| 2954 span->end = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); | |
| 2955 imhtml->format_spans = g_list_append(imhtml->format_spans, span); | |
| 2956 } | |
| 2957 | |
| 2958 void gtk_imhtml_insert_smiley(GtkIMHtml *imhtml, const char *sml, char *smiley) | |
| 2959 { | |
| 2960 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer); | |
| 2961 GtkTextIter iter; | |
| 2962 GdkPixbuf *pixbuf = NULL; | |
| 2963 GdkPixbufAnimation *annipixbuf = NULL; | |
| 2964 GtkWidget *icon = NULL; | |
| 2965 GtkTextChildAnchor *anchor; | |
| 8505 | 2966 char *unescaped = gaim_unescape_html(smiley); |
| 8061 | 2967 |
| 8515 | 2968 if (!imhtml->show_smileys) { |
| 2969 gtk_text_buffer_insert_at_cursor(imhtml->text_buffer, smiley, strlen(smiley)); | |
| 2970 return; | |
| 2971 } | |
| 2972 | |
| 8061 | 2973 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins); |
| 2974 anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, &iter); | |
| 8505 | 2975 g_object_set_data(G_OBJECT(anchor), "text_tag", unescaped); |
| 2976 | |
| 2977 annipixbuf = gtk_smiley_tree_image(imhtml, sml, unescaped); | |
| 8061 | 2978 if(annipixbuf) { |
| 2979 if(gdk_pixbuf_animation_is_static_image(annipixbuf)) { | |
| 2980 pixbuf = gdk_pixbuf_animation_get_static_image(annipixbuf); | |
| 2981 if(pixbuf) | |
| 2982 icon = gtk_image_new_from_pixbuf(pixbuf); | |
| 2983 } else { | |
| 2984 icon = gtk_image_new_from_animation(annipixbuf); | |
| 2985 } | |
| 2986 } | |
| 2987 | |
| 2988 if (icon) { | |
| 2989 gtk_widget_show(icon); | |
| 2990 gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(imhtml), icon, anchor); | |
| 2991 } | |
| 2992 } | |
| 2993 | |
| 2994 int span_compare_begin(const GtkIMHtmlFormatSpan *a, const GtkIMHtmlFormatSpan *b, GtkTextBuffer *buffer) | |
| 2995 { | |
| 2996 GtkTextIter ia, ib; | |
| 2997 gtk_text_buffer_get_iter_at_mark(buffer, &ia, a->start); | |
| 2998 gtk_text_buffer_get_iter_at_mark(buffer, &ib, b->start); | |
| 2999 return gtk_text_iter_compare(&ia, &ib); | |
| 3000 } | |
| 3001 | |
| 3002 int span_compare_end(GtkIMHtmlFormatSpan *a, GtkIMHtmlFormatSpan *b) | |
| 3003 { | |
| 3004 GtkTextIter ia, ib; | |
| 3005 gtk_text_buffer_get_iter_at_mark(a->buffer, &ia, a->start); | |
| 3006 gtk_text_buffer_get_iter_at_mark(b->buffer, &ib, b->start); | |
| 3007 /* The -1 here makes it so that if I have two spans that close at the same point, the | |
| 3008 * span added second will be closed first, as in <b><i>Hello</i></b>. Without this, | |
| 8548 | 3009 * it would be <b><i>Hello</b></i> I took it out. It started breaking things, and I don't know why*/ |
| 3010 return gtk_text_iter_compare(&ia, &ib); | |
| 8061 | 3011 } |
| 3012 | |
| 3013 /* Basic notion here: traverse through the text buffer one-by-one, non-character elements, such | |
| 3014 * as smileys and IM images are represented by the Unicode "unknown" character. Handle them. Else | |
| 3015 * check the list of formatted strings, sorted by the position of the starting tags and apply them as | |
| 3016 * needed. After applying the start tags, add the end tags to the "closers" list, which is sorted by | |
| 3017 * location of ending tags. These get applied in a similar fashion. Finally, replace <, >, &, and " | |
| 3018 * with their HTML equivilent. */ | |
| 3019 char *gtk_imhtml_get_markup_range(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *end) | |
| 3020 { | |
| 3021 gunichar c; | |
| 3022 GtkIMHtmlFormatSpan *sspan = NULL, *espan = NULL; | |
| 3023 GtkTextIter iter, siter, eiter; | |
| 3024 GList *starters = imhtml->format_spans; | |
| 3025 GList *closers = NULL; | |
| 3026 GString *str = g_string_new(""); | |
| 8481 | 3027 |
| 8061 | 3028 g_list_sort_with_data(starters, (GCompareDataFunc)span_compare_begin, imhtml->text_buffer); |
| 3029 | |
| 3030 gtk_text_iter_order(start, end); | |
| 3031 iter = *start; | |
| 3032 | |
| 3033 | |
| 3034 /* Initialize these to the end iter */ | |
| 3035 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &siter); | |
| 3036 eiter = siter; | |
| 3037 | |
| 8429 | 3038 if (starters) { |
| 8061 | 3039 while (starters) { |
| 3040 GtkTextIter tagend; | |
| 3041 sspan = (GtkIMHtmlFormatSpan*)starters->data; | |
| 3042 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &siter, sspan->start); | |
| 3043 if (gtk_text_iter_compare(&siter, start) > 0) | |
| 3044 break; | |
| 3045 if (sspan->end) | |
| 3046 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &tagend, sspan->end); | |
| 3047 if (sspan->end == NULL || gtk_text_iter_compare(&tagend, start) > 0) { | |
| 3048 str = g_string_append(str, sspan->start_tag); | |
| 3049 closers = g_list_insert_sorted(closers, sspan, (GCompareFunc)span_compare_end); | |
| 3050 espan = (GtkIMHtmlFormatSpan*)closers->data; | |
| 8365 | 3051 /* |
| 3052 * When sending an IM, the following line causes the following warning: | |
| 3053 * Gtk: file gtktextbuffer.c: line 1794 | |
| 3054 * (gtk_text_buffer_get_iter_at_mark): assertion `GTK_IS_TEXT_MARK (mark)' failed | |
| 3055 * | |
| 3056 * The callback path thingy to get here is: | |
| 3057 * gtkconv.c, send(), "buf = gtk_imhtml_get_markup(GTK_IMHTML(gtkconv->entry));" | |
| 3058 * gtkimhtml.c, gtk_imthml_get_markup(), "return gtk_imhtml_get_markup_range(imhtml, &start, &end);" | |
| 3059 * | |
| 3060 * I don't really know anything about gtkimhtml, but it almost seems like | |
| 3061 * the line above this comments expects to find a closing html tag, but | |
| 3062 * can't, for some reason. The warning depends on how much HTML I send | |
| 3063 * in my message, kind of. | |
| 3064 */ | |
| 8061 | 3065 } |
| 3066 sspan = (GtkIMHtmlFormatSpan*)starters->data; | |
| 3067 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &siter, sspan->start); | |
| 3068 starters = starters->next; | |
| 3069 } | |
| 3070 if (!starters) { | |
| 3071 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &siter); | |
| 3072 sspan = NULL; | |
| 3073 } | |
| 3074 } | |
| 3075 | |
| 3076 while ((c = gtk_text_iter_get_char(&iter)) != 0 && !gtk_text_iter_equal(&iter, end)) { | |
| 3077 if (c == 0xFFFC) { | |
| 3078 GtkTextChildAnchor* anchor = gtk_text_iter_get_child_anchor(&iter); | |
| 3079 char *text = g_object_get_data(G_OBJECT(anchor), "text_tag"); | |
| 3080 str = g_string_append(str, text); | |
| 3081 } else { | |
| 3082 while (gtk_text_iter_equal(&eiter, &iter)) { | |
| 3083 /* This is where we shall insert the ending tag of | |
| 3084 * this format span */ | |
| 3085 str = g_string_append(str, espan->end_tag); | |
| 3086 closers = g_list_remove(closers, espan); | |
| 3087 if (!closers) { | |
| 3088 espan = NULL; | |
| 3089 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &eiter); | |
| 3090 } else { | |
| 3091 espan = (GtkIMHtmlFormatSpan*)closers->data; | |
| 8429 | 3092 if (espan->end) |
| 3093 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &eiter, espan->end); | |
| 8548 | 3094 else { |
| 8429 | 3095 gtk_text_iter_forward_to_end(&eiter); |
| 8548 | 3096 } |
| 8061 | 3097 } |
| 3098 } | |
| 3099 while (gtk_text_iter_equal(&siter, &iter)) { | |
| 3100 /* This is where we shall insert the starting tag of | |
| 3101 * this format span */ | |
| 3102 str = g_string_append(str, sspan->start_tag); | |
| 3103 if (sspan->end) { | |
| 3104 closers = g_list_insert_sorted(closers, sspan, (GCompareFunc)span_compare_end); | |
| 3105 espan = (GtkIMHtmlFormatSpan*)closers->data; | |
| 3106 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &eiter, espan->end); | |
| 3107 | |
| 3108 } | |
| 3109 starters = starters->next; | |
| 3110 if (starters) { | |
| 3111 sspan = (GtkIMHtmlFormatSpan*)starters->data; | |
| 3112 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &siter, sspan->start); | |
| 3113 } else { | |
| 3114 sspan = NULL; | |
| 3115 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &siter); | |
| 3116 } | |
| 3117 | |
| 3118 } | |
| 3119 | |
| 3120 if (c == '<') | |
| 3121 str = g_string_append(str, "<"); | |
| 3122 else if (c == '>') | |
| 3123 str = g_string_append(str, ">"); | |
| 3124 else if (c == '&') | |
| 3125 str = g_string_append(str, "&"); | |
| 3126 else if (c == '"') | |
| 3127 str = g_string_append(str, """); | |
| 3128 else if (c == '\n') | |
| 3129 str = g_string_append(str, "<br>"); | |
| 3130 else | |
| 3131 str = g_string_append_unichar(str, c); | |
| 3132 } | |
| 3133 gtk_text_iter_forward_char(&iter); | |
| 3134 } | |
| 3135 while (closers) { | |
| 3136 GtkIMHtmlFormatSpan *span = (GtkIMHtmlFormatSpan*)closers->data; | |
| 3137 str = g_string_append(str, span->end_tag); | |
| 3138 closers = g_list_remove(closers, span); | |
| 3139 | |
| 3140 } | |
| 3141 return g_string_free(str, FALSE); | |
| 3142 } | |
| 3143 | |
| 3144 void gtk_imhtml_close_tags(GtkIMHtml *imhtml) | |
| 3145 { | |
| 3146 | |
| 3147 if (imhtml->edit.bold) | |
| 3148 gtk_imhtml_toggle_bold(imhtml); | |
| 3149 | |
| 3150 if (imhtml->edit.italic) | |
| 3151 gtk_imhtml_toggle_italic(imhtml); | |
| 3152 | |
| 3153 if (imhtml->edit.underline) | |
| 3154 gtk_imhtml_toggle_underline(imhtml); | |
| 3155 | |
| 3156 if (imhtml->edit.forecolor) | |
| 3157 gtk_imhtml_toggle_forecolor(imhtml, NULL); | |
| 3158 | |
| 3159 if (imhtml->edit.backcolor) | |
| 3160 gtk_imhtml_toggle_backcolor(imhtml, NULL); | |
| 3161 | |
| 3162 if (imhtml->edit.fontface) | |
| 3163 gtk_imhtml_toggle_fontface(imhtml, NULL); | |
| 3164 | |
| 3165 if (imhtml->edit.sizespan) | |
| 3166 gtk_imhtml_font_set_size(imhtml, -1); | |
| 3167 | |
| 3168 } | |
| 3169 | |
| 3170 char *gtk_imhtml_get_markup(GtkIMHtml *imhtml) | |
| 3171 { | |
| 3172 GtkTextIter start, end; | |
| 3173 | |
| 3174 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start); | |
| 3175 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end); | |
| 3176 return gtk_imhtml_get_markup_range(imhtml, &start, &end); | |
| 3177 } | |
| 3178 | |
| 3179 char *gtk_imhtml_get_text(GtkIMHtml *imhtml) | |
| 3180 { | |
| 8519 | 3181 GString *str = g_string_new(""); |
| 3182 GtkTextIter iter, end; | |
| 3183 gunichar c; | |
| 3184 | |
| 3185 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &iter); | |
| 3186 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end); | |
| 3187 | |
| 3188 while ((c = gtk_text_iter_get_char(&iter)) != 0 && !gtk_text_iter_equal(&iter, &end)) { | |
| 3189 if (c == 0xFFFC) { | |
| 3190 GtkTextChildAnchor* anchor = gtk_text_iter_get_child_anchor(&iter); | |
| 3191 char *text = g_object_get_data(G_OBJECT(anchor), "text_tag"); | |
| 3192 str = g_string_append(str, text); | |
| 3193 } else { | |
| 3194 g_string_append_unichar(str, c); | |
| 3195 } | |
| 3196 gtk_text_iter_forward_char(&iter); | |
| 3197 } | |
| 3198 | |
| 3199 return g_string_free(str, FALSE); | |
| 8061 | 3200 } |
