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