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