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