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