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