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