Mercurial > pidgin.yaz
annotate src/gtkimhtml.c @ 10815:65c818fb218e
[gaim-migrate @ 12470]
Fix the gtkimhtml bug that caused screennames to be duplicated in AIM
profiles containing pasted conversations
committer: Tailor Script <tailor@pidgin.im>
author | Stu Tomlinson <stu@nosnilmot.com> |
---|---|
date | Mon, 11 Apr 2005 15:00:30 +0000 |
parents | 364a2ef907ae |
children | 2a5fe8e67195 |
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 |
10814
364a2ef907ae
[gaim-migrate @ 12468]
Luke Schierer <lschiere@pidgin.im>
parents:
10799
diff
changeset
|
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 | |
10814
364a2ef907ae
[gaim-migrate @ 12468]
Luke Schierer <lschiere@pidgin.im>
parents:
10799
diff
changeset
|
967 clipboard before we try to paste from the GTK+ buffer */ |
8931 | 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 |
10814
364a2ef907ae
[gaim-migrate @ 12468]
Luke Schierer <lschiere@pidgin.im>
parents:
10799
diff
changeset
|
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) { |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1968 *len = e - string + strlen ("-->"); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1969 *tag = g_strndup (string + strlen ("!--"), *len - strlen ("!---->")); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1970 return TRUE; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1971 } |
8118 | 1972 } |
1973 | |
8061 | 1974 *type = -1; |
1975 *len = close - string + 1; | |
1976 *tag = g_strndup(string, *len - 1); | |
1977 return TRUE; | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1978 } |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1979 |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1980 static gchar* |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1981 gtk_imhtml_get_html_opt (gchar *tag, |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1982 const gchar *opt) |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1983 { |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1984 gchar *t = tag; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1985 gchar *e, *a; |
5177 | 1986 gchar *val; |
1987 gint len; | |
7280 | 1988 gchar *c; |
5177 | 1989 GString *ret; |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1990 |
4793 | 1991 while (g_ascii_strncasecmp (t, opt, strlen (opt))) { |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1992 gboolean quote = FALSE; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1993 if (*t == '\0') break; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1994 while (*t && !((*t == ' ') && !quote)) { |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1995 if (*t == '\"') |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1996 quote = ! quote; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1997 t++; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1998 } |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
1999 while (*t && (*t == ' ')) t++; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2000 } |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2001 |
4793 | 2002 if (!g_ascii_strncasecmp (t, opt, strlen (opt))) { |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2003 t += strlen (opt); |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2004 } else { |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2005 return NULL; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2006 } |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2007 |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2008 if ((*t == '\"') || (*t == '\'')) { |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2009 e = a = ++t; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2010 while (*e && (*e != *(t - 1))) e++; |
2993 | 2011 if (*e == '\0') { |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2012 return NULL; |
5177 | 2013 } else |
2014 val = g_strndup(a, e - a); | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2015 } else { |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2016 e = a = t; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2017 while (*e && !isspace ((gint) *e)) e++; |
5177 | 2018 val = g_strndup(a, e - a); |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2019 } |
5177 | 2020 |
2021 ret = g_string_new(""); | |
2022 e = val; | |
2023 while(*e) { | |
2024 if(gtk_imhtml_is_amp_escape(e, &c, &len)) { | |
7280 | 2025 ret = g_string_append(ret, c); |
5177 | 2026 e += len; |
2027 } else { | |
2028 ret = g_string_append_c(ret, *e); | |
2029 e++; | |
2030 } | |
2031 } | |
2032 | |
2033 g_free(val); | |
8568 | 2034 |
2035 return g_string_free(ret, FALSE); | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2036 } |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2037 |
8118 | 2038 /* Inline CSS Support - Douglas Thrift */ |
2039 static gchar* | |
2040 gtk_imhtml_get_css_opt (gchar *style, | |
2041 const gchar *opt) | |
2042 { | |
2043 gchar *t = style; | |
2044 gchar *e, *a; | |
2045 gchar *val; | |
2046 gint len; | |
2047 gchar *c; | |
2048 GString *ret; | |
2049 | |
2050 while (g_ascii_strncasecmp (t, opt, strlen (opt))) { | |
8177 | 2051 /* gboolean quote = FALSE; */ |
8118 | 2052 if (*t == '\0') break; |
2053 while (*t && !((*t == ' ') /*&& !quote*/)) { | |
2054 /* if (*t == '\"') | |
8177 | 2055 quote = ! quote; */ |
8118 | 2056 t++; |
2057 } | |
2058 while (*t && (*t == ' ')) t++; | |
2059 } | |
2060 | |
2061 if (!g_ascii_strncasecmp (t, opt, strlen (opt))) { | |
2062 t += strlen (opt); | |
10457 | 2063 while (*t && (*t == ' ')) t++; |
2064 if (!*t) | |
2065 return NULL; | |
8118 | 2066 } else { |
2067 return NULL; | |
2068 } | |
2069 | |
2070 /* if ((*t == '\"') || (*t == '\'')) { | |
2071 e = a = ++t; | |
2072 while (*e && (*e != *(t - 1))) e++; | |
2073 if (*e == '\0') { | |
2074 return NULL; | |
2075 } else | |
2076 val = g_strndup(a, e - a); | |
2077 } else { | |
2078 e = a = t; | |
2079 while (*e && !isspace ((gint) *e)) e++; | |
2080 val = g_strndup(a, e - a); | |
2081 }*/ | |
2082 | |
2083 e = a = t; | |
2084 while (*e && *e != ';') e++; | |
2085 val = g_strndup(a, e - a); | |
2086 | |
2087 ret = g_string_new(""); | |
2088 e = val; | |
2089 while(*e) { | |
2090 if(gtk_imhtml_is_amp_escape(e, &c, &len)) { | |
2091 ret = g_string_append(ret, c); | |
2092 e += len; | |
2093 } else { | |
2094 ret = g_string_append_c(ret, *e); | |
2095 e++; | |
2096 } | |
2097 } | |
2098 | |
2099 g_free(val); | |
2100 val = ret->str; | |
2101 g_string_free(ret, FALSE); | |
2102 return val; | |
2103 } | |
3922 | 2104 |
8334 | 2105 static const char *accepted_protocols[] = { |
2106 "http://", | |
2107 "https://", | |
2108 "ftp://" | |
2109 }; | |
2110 | |
2111 static const int accepted_protocols_size = 3; | |
2112 | |
2113 /* returns if the beginning of the text is a protocol. If it is the protocol, returns the length so | |
2114 the caller knows how long the protocol string is. */ | |
2115 int gtk_imhtml_is_protocol(const char *text) | |
2116 { | |
2117 gint i; | |
2118 | |
2119 for(i=0; i<accepted_protocols_size; i++){ | |
2120 if( strncasecmp(text, accepted_protocols[i], strlen(accepted_protocols[i])) == 0 ){ | |
2121 return strlen(accepted_protocols[i]); | |
2122 } | |
2123 } | |
2124 return 0; | |
2125 } | |
2126 | |
8677 | 2127 /* |
2128 <KingAnt> marv: The two IM image functions in oscar are gaim_odc_send_im and gaim_odc_incoming | |
2129 | |
2130 | |
2131 [19:58] <Robot101> marv: images go into the imgstore, a refcounted... well.. hash. :) | |
2132 [19:59] <KingAnt> marv: I think the image tag used by the core is something like <img id="#"/> | |
2133 [19:59] Ro0tSiEgE robert42 RobFlynn Robot101 ross22 roz | |
2134 [20:00] <KingAnt> marv: Where the ID is the what is returned when you add the image to the imgstore using gaim_imgstore_add | |
2135 [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? | |
2136 [20:00] <KingAnt> marv: Right | |
2137 [20:00] <marv> alright | |
2138 | |
2139 Here's my plan with IMImages. make gtk_imhtml_[append|insert]_text_with_images instead just | |
2140 gtkimhtml_[append|insert]_text (hrm maybe it should be called html instead of text), add a | |
2141 function for gaim to register for look up images, i.e. gtk_imhtml_set_get_img_fnc, so that | |
2142 images can be looked up like that, instead of passing a GSList of them. | |
2143 */ | |
2144 | |
2145 void gtk_imhtml_append_text_with_images (GtkIMHtml *imhtml, | |
2146 const gchar *text, | |
2147 GtkIMHtmlOptions options, | |
2148 GSList *unused) | |
1428 | 2149 { |
8677 | 2150 GtkTextIter iter, ins, sel; |
2151 GdkRectangle rect; | |
2152 int y, height, ins_offset = 0, sel_offset = 0; | |
2153 gboolean fixins = FALSE, fixsel = FALSE; | |
2154 | |
2155 g_return_if_fail (imhtml != NULL); | |
2156 g_return_if_fail (GTK_IS_IMHTML (imhtml)); | |
2157 g_return_if_fail (text != NULL); | |
2158 | |
2159 | |
2160 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &iter); | |
2161 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &ins, gtk_text_buffer_get_insert(imhtml->text_buffer)); | |
2162 if (gtk_text_iter_equal(&iter, &ins) && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, NULL, NULL)) { | |
2163 fixins = TRUE; | |
2164 ins_offset = gtk_text_iter_get_offset(&ins); | |
2165 } | |
2166 | |
2167 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &sel, gtk_text_buffer_get_selection_bound(imhtml->text_buffer)); | |
2168 if (gtk_text_iter_equal(&iter, &sel) && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, NULL, NULL)) { | |
2169 fixsel = TRUE; | |
2170 sel_offset = gtk_text_iter_get_offset(&sel); | |
2171 } | |
2172 | |
2173 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); | |
2174 gtk_text_view_get_line_yrange(GTK_TEXT_VIEW(imhtml), &iter, &y, &height); | |
2175 | |
2176 | |
2177 if(((y + height) - (rect.y + rect.height)) > height | |
2178 && gtk_text_buffer_get_char_count(imhtml->text_buffer)){ | |
2179 options |= GTK_IMHTML_NO_SCROLL; | |
2180 } | |
2181 | |
2182 gtk_imhtml_insert_html_at_iter(imhtml, text, options, &iter); | |
2183 | |
2184 if (fixins) { | |
2185 gtk_text_buffer_get_iter_at_offset(imhtml->text_buffer, &ins, ins_offset); | |
2186 gtk_text_buffer_move_mark(imhtml->text_buffer, gtk_text_buffer_get_insert(imhtml->text_buffer), &ins); | |
2187 } | |
2188 | |
2189 if (fixsel) { | |
2190 gtk_text_buffer_get_iter_at_offset(imhtml->text_buffer, &sel, sel_offset); | |
2191 gtk_text_buffer_move_mark(imhtml->text_buffer, gtk_text_buffer_get_selection_bound(imhtml->text_buffer), &sel); | |
2192 } | |
2193 | |
2194 if (!(options & GTK_IMHTML_NO_SCROLL)) { | |
8729 | 2195 gtk_imhtml_scroll_to_end(imhtml); |
8677 | 2196 } |
2197 } | |
2198 | |
10798 | 2199 #define MAX_SCROLL_TIME 0.5 |
2200 | |
2201 gboolean scroll_cb(gpointer data) | |
2202 { | |
2203 GtkIMHtml *imhtml = data; | |
2204 GtkAdjustment *adj = GTK_TEXT_VIEW(imhtml)->vadjustment; | |
2205 gdouble val = adj->upper - adj->page_size; | |
2206 gdouble t; | |
2207 | |
2208 t = g_timer_elapsed(imhtml->scroll_time, NULL); | |
2209 | |
2210 | |
2211 gaim_debug_info("gtkimhtml", "in scroll_cb\n"); | |
2212 | |
2213 if (adj->value >= val || t >= MAX_SCROLL_TIME) { | |
2214 gaim_debug_info("gtkimhtml", "scroll_cb: out of time\n"); | |
2215 gtk_adjustment_set_value(adj, val); | |
2216 } else { | |
2217 gtk_adjustment_set_value(adj, | |
2218 adj->value + (((val - adj->value) * t ) / MAX_SCROLL_TIME)); | |
2219 } | |
2220 | |
2221 if (adj->value >= val) { | |
2222 g_timer_destroy(imhtml->scroll_time); | |
2223 imhtml->scroll_time = NULL; | |
2224 return FALSE; | |
2225 } else | |
2226 return TRUE; | |
2227 } | |
2228 | |
10797 | 2229 gboolean scroll_idle_cb(gpointer data) |
2230 { | |
10798 | 2231 GtkIMHtml *imhtml = data; |
2232 imhtml->scroll_src = g_timeout_add(33, scroll_cb, imhtml); | |
10797 | 2233 return FALSE; |
2234 } | |
2235 | |
8729 | 2236 void gtk_imhtml_scroll_to_end(GtkIMHtml *imhtml) |
2237 { | |
10798 | 2238 if (imhtml->scroll_time) |
2239 g_timer_destroy(imhtml->scroll_time); | |
2240 imhtml->scroll_time = g_timer_new(); | |
2241 if (imhtml->scroll_src) | |
2242 g_source_remove(imhtml->scroll_src); | |
2243 imhtml->scroll_src = g_idle_add_full(G_PRIORITY_LOW, scroll_idle_cb, imhtml, NULL); | |
8729 | 2244 } |
2245 | |
8677 | 2246 void gtk_imhtml_insert_html_at_iter(GtkIMHtml *imhtml, |
2247 const gchar *text, | |
2248 GtkIMHtmlOptions options, | |
2249 GtkTextIter *iter) | |
2250 { | |
8061 | 2251 GdkRectangle rect; |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2252 gint pos = 0; |
3922 | 2253 gchar *ws; |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2254 gchar *tag; |
3922 | 2255 gchar *bg = NULL; |
6982 | 2256 gint len; |
4032 | 2257 gint tlen, smilelen, wpos=0; |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2258 gint type; |
3922 | 2259 const gchar *c; |
7280 | 2260 gchar *amp; |
8334 | 2261 gint len_protocol; |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2262 |
1428 | 2263 guint bold = 0, |
2264 italics = 0, | |
2265 underline = 0, | |
2266 strike = 0, | |
2267 sub = 0, | |
2268 sup = 0, | |
1691
d802b115800f
[gaim-migrate @ 1701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1647
diff
changeset
|
2269 title = 0, |
8061 | 2270 pre = 0; |
1428 | 2271 |
10217 | 2272 gboolean br = FALSE; |
2273 | |
3922 | 2274 GSList *fonts = NULL; |
8506 | 2275 GObject *object; |
8061 | 2276 GtkIMHtmlScalable *scalable = NULL; |
8677 | 2277 |
2278 g_return_if_fail (imhtml != NULL); | |
2279 g_return_if_fail (GTK_IS_IMHTML (imhtml)); | |
2280 g_return_if_fail (text != NULL); | |
3922 | 2281 c = text; |
6982 | 2282 len = strlen(text); |
3922 | 2283 ws = g_malloc(len + 1); |
2284 ws[0] = 0; | |
1428 | 2285 |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2286 while (pos < len) { |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2287 if (*c == '<' && gtk_imhtml_is_tag (c + 1, &tag, &tlen, &type)) { |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2288 c++; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2289 pos++; |
8061 | 2290 ws[wpos] = '\0'; |
10217 | 2291 br = FALSE; |
8061 | 2292 switch (type) |
3922 | 2293 { |
2294 case 1: /* B */ | |
2295 case 2: /* BOLD */ | |
5101 | 2296 case 54: /* STRONG */ |
8677 | 2297 |
2298 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); | |
2299 | |
2300 if ((bold == 0) && (imhtml->format_functions & GTK_IMHTML_BOLD)) | |
8061 | 2301 gtk_imhtml_toggle_bold(imhtml); |
3922 | 2302 bold++; |
8061 | 2303 ws[0] = '\0'; wpos = 0; |
3922 | 2304 break; |
2305 case 3: /* /B */ | |
2306 case 4: /* /BOLD */ | |
5101 | 2307 case 55: /* /STRONG */ |
8677 | 2308 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
8061 | 2309 ws[0] = '\0'; wpos = 0; |
2310 | |
3922 | 2311 if (bold) |
2312 bold--; | |
8677 | 2313 if ((bold == 0) && (imhtml->format_functions & GTK_IMHTML_BOLD) && !imhtml->wbfo) |
8061 | 2314 gtk_imhtml_toggle_bold(imhtml); |
3922 | 2315 break; |
2316 case 5: /* I */ | |
2317 case 6: /* ITALIC */ | |
5101 | 2318 case 52: /* EM */ |
8677 | 2319 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
8061 | 2320 ws[0] = '\0'; wpos = 0; |
8677 | 2321 if ((italics == 0) && (imhtml->format_functions & GTK_IMHTML_ITALIC)) |
8061 | 2322 gtk_imhtml_toggle_italic(imhtml); |
3922 | 2323 italics++; |
2324 break; | |
2325 case 7: /* /I */ | |
2326 case 8: /* /ITALIC */ | |
5101 | 2327 case 53: /* /EM */ |
8677 | 2328 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
8061 | 2329 ws[0] = '\0'; wpos = 0; |
3922 | 2330 if (italics) |
2331 italics--; | |
8677 | 2332 if ((italics == 0) && (imhtml->format_functions & GTK_IMHTML_ITALIC) && !imhtml->wbfo) |
8061 | 2333 gtk_imhtml_toggle_italic(imhtml); |
3922 | 2334 break; |
2335 case 9: /* U */ | |
2336 case 10: /* UNDERLINE */ | |
8677 | 2337 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
8061 | 2338 ws[0] = '\0'; wpos = 0; |
8677 | 2339 if ((underline == 0) && (imhtml->format_functions & GTK_IMHTML_UNDERLINE)) |
8061 | 2340 gtk_imhtml_toggle_underline(imhtml); |
3922 | 2341 underline++; |
2342 break; | |
2343 case 11: /* /U */ | |
2344 case 12: /* /UNDERLINE */ | |
8677 | 2345 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
8061 | 2346 ws[0] = '\0'; wpos = 0; |
3922 | 2347 if (underline) |
2348 underline--; | |
8677 | 2349 if ((underline == 0) && (imhtml->format_functions & GTK_IMHTML_UNDERLINE) && !imhtml->wbfo) |
8061 | 2350 gtk_imhtml_toggle_underline(imhtml); |
3922 | 2351 break; |
2352 case 13: /* S */ | |
2353 case 14: /* STRIKE */ | |
9924 | 2354 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
2355 ws[0] = '\0'; wpos = 0; | |
2356 if ((strike == 0) && (imhtml->format_functions & GTK_IMHTML_STRIKE)) | |
2357 gtk_imhtml_toggle_strike(imhtml); | |
3922 | 2358 strike++; |
2359 break; | |
2360 case 15: /* /S */ | |
2361 case 16: /* /STRIKE */ | |
9924 | 2362 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
2363 ws[0] = '\0'; wpos = 0; | |
3922 | 2364 if (strike) |
2365 strike--; | |
9924 | 2366 if ((strike == 0) && (imhtml->format_functions & GTK_IMHTML_STRIKE) && !imhtml->wbfo) |
2367 gtk_imhtml_toggle_strike(imhtml); | |
3922 | 2368 break; |
2369 case 17: /* SUB */ | |
8677 | 2370 /* FIXME: reimpliment this */ |
3922 | 2371 sub++; |
2372 break; | |
2373 case 18: /* /SUB */ | |
8677 | 2374 /* FIXME: reimpliment this */ |
3922 | 2375 if (sub) |
2376 sub--; | |
2377 break; | |
2378 case 19: /* SUP */ | |
8677 | 2379 /* FIXME: reimplement this */ |
3922 | 2380 sup++; |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2381 break; |
3922 | 2382 case 20: /* /SUP */ |
8677 | 2383 /* FIXME: reimplement this */ |
3922 | 2384 if (sup) |
2385 sup--; | |
2386 break; | |
2387 case 21: /* PRE */ | |
8677 | 2388 /* FIXME: reimplement this */ |
3922 | 2389 pre++; |
2390 break; | |
2391 case 22: /* /PRE */ | |
8677 | 2392 /* FIXME: reimplement this */ |
3922 | 2393 if (pre) |
2394 pre--; | |
2395 break; | |
2396 case 23: /* TITLE */ | |
8677 | 2397 /* FIXME: what was this supposed to do anyway? */ |
3922 | 2398 title++; |
2399 break; | |
2400 case 24: /* /TITLE */ | |
8677 | 2401 /* FIXME: make this undo whatever 23 was supposed to do */ |
3922 | 2402 if (title) { |
2403 if (options & GTK_IMHTML_NO_TITLE) { | |
2404 wpos = 0; | |
2405 ws [wpos] = '\0'; | |
2406 } | |
2407 title--; | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2408 } |
3922 | 2409 break; |
2410 case 25: /* BR */ | |
5174 | 2411 case 58: /* BR/ */ |
8061 | 2412 case 61: /* BR (opt) */ |
3922 | 2413 ws[wpos] = '\n'; |
2414 wpos++; | |
10217 | 2415 br = TRUE; |
6982 | 2416 break; |
3922 | 2417 case 26: /* HR */ |
2418 case 42: /* HR (opt) */ | |
8726 | 2419 { |
2420 int minus; | |
2421 | |
3922 | 2422 ws[wpos++] = '\n'; |
8677 | 2423 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
2424 | |
5967 | 2425 scalable = gtk_imhtml_hr_new(); |
8061 | 2426 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); |
8677 | 2427 scalable->add_to(scalable, imhtml, iter); |
8726 | 2428 minus = gtk_text_view_get_left_margin(GTK_TEXT_VIEW(imhtml)) + |
2429 gtk_text_view_get_right_margin(GTK_TEXT_VIEW(imhtml)); | |
2430 scalable->scale(scalable, rect.width - minus, rect.height); | |
8061 | 2431 imhtml->scalables = g_list_append(imhtml->scalables, scalable); |
2432 ws[0] = '\0'; wpos = 0; | |
7942 | 2433 ws[wpos++] = '\n'; |
8061 | 2434 |
3922 | 2435 break; |
8726 | 2436 } |
3922 | 2437 case 27: /* /FONT */ |
8677 | 2438 if (fonts && !imhtml->wbfo) { |
5967 | 2439 GtkIMHtmlFontDetail *font = fonts->data; |
8677 | 2440 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
8061 | 2441 ws[0] = '\0'; wpos = 0; |
8177 | 2442 /* NEW_BIT (NEW_TEXT_BIT); */ |
8677 | 2443 |
8698 | 2444 if (font->face && (imhtml->format_functions & GTK_IMHTML_FACE)) { |
8061 | 2445 gtk_imhtml_toggle_fontface(imhtml, NULL); |
3922 | 2446 g_free (font->face); |
8061 | 2447 } |
8698 | 2448 if (font->fore && (imhtml->format_functions & GTK_IMHTML_FORECOLOR)) { |
8061 | 2449 gtk_imhtml_toggle_forecolor(imhtml, NULL); |
3922 | 2450 g_free (font->fore); |
8061 | 2451 } |
8698 | 2452 if (font->back && (imhtml->format_functions & GTK_IMHTML_BACKCOLOR)) { |
8061 | 2453 gtk_imhtml_toggle_backcolor(imhtml, NULL); |
3922 | 2454 g_free (font->back); |
8061 | 2455 } |
4032 | 2456 if (font->sml) |
2457 g_free (font->sml); | |
8309 | 2458 |
8698 | 2459 if ((font->size != 3) && (imhtml->format_functions & (GTK_IMHTML_GROW|GTK_IMHTML_SHRINK))) |
8309 | 2460 gtk_imhtml_font_set_size(imhtml, 3); |
2461 | |
10761 | 2462 |
2463 fonts = g_slist_remove (fonts, font); | |
9245 | 2464 g_free(font); |
2465 | |
8309 | 2466 if (fonts) { |
2467 GtkIMHtmlFontDetail *font = fonts->data; | |
8677 | 2468 |
8698 | 2469 if (font->face && (imhtml->format_functions & GTK_IMHTML_FACE)) |
8309 | 2470 gtk_imhtml_toggle_fontface(imhtml, font->face); |
8698 | 2471 if (font->fore && (imhtml->format_functions & GTK_IMHTML_FORECOLOR)) |
8309 | 2472 gtk_imhtml_toggle_forecolor(imhtml, font->fore); |
8698 | 2473 if (font->back && (imhtml->format_functions & GTK_IMHTML_BACKCOLOR)) |
8309 | 2474 gtk_imhtml_toggle_backcolor(imhtml, font->back); |
8698 | 2475 if ((font->size != 3) && (imhtml->format_functions & (GTK_IMHTML_GROW|GTK_IMHTML_SHRINK))) |
8309 | 2476 gtk_imhtml_font_set_size(imhtml, font->size); |
2477 } | |
3922 | 2478 } |
8309 | 2479 break; |
3922 | 2480 case 28: /* /A */ |
8677 | 2481 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
2482 gtk_imhtml_toggle_link(imhtml, NULL); | |
2483 ws[0] = '\0'; wpos = 0; | |
8061 | 2484 break; |
8118 | 2485 |
3922 | 2486 case 29: /* P */ |
2487 case 30: /* /P */ | |
2488 case 31: /* H3 */ | |
2489 case 32: /* /H3 */ | |
2490 case 33: /* HTML */ | |
2491 case 34: /* /HTML */ | |
2492 case 35: /* BODY */ | |
10776 | 2493 break; |
3922 | 2494 case 36: /* /BODY */ |
10786 | 2495 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
2496 ws[0] = '\0'; wpos = 0; | |
10776 | 2497 gtk_imhtml_toggle_background(imhtml, NULL); |
2498 break; | |
3922 | 2499 case 37: /* FONT */ |
2500 case 38: /* HEAD */ | |
2501 case 39: /* /HEAD */ | |
6982 | 2502 case 40: /* BINARY */ |
2503 case 41: /* /BINARY */ | |
3922 | 2504 break; |
2505 case 43: /* FONT (opt) */ | |
2506 { | |
4032 | 2507 gchar *color, *back, *face, *size, *sml; |
5967 | 2508 GtkIMHtmlFontDetail *font, *oldfont = NULL; |
3922 | 2509 color = gtk_imhtml_get_html_opt (tag, "COLOR="); |
2510 back = gtk_imhtml_get_html_opt (tag, "BACK="); | |
2511 face = gtk_imhtml_get_html_opt (tag, "FACE="); | |
2512 size = gtk_imhtml_get_html_opt (tag, "SIZE="); | |
4032 | 2513 sml = gtk_imhtml_get_html_opt (tag, "SML="); |
2514 if (!(color || back || face || size || sml)) | |
3922 | 2515 break; |
8061 | 2516 |
8677 | 2517 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
8061 | 2518 ws[0] = '\0'; wpos = 0; |
2519 | |
5967 | 2520 font = g_new0 (GtkIMHtmlFontDetail, 1); |
3922 | 2521 if (fonts) |
2522 oldfont = fonts->data; | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2523 |
8677 | 2524 if (color && !(options & GTK_IMHTML_NO_COLOURS) && (imhtml->format_functions & GTK_IMHTML_FORECOLOR)) { |
3922 | 2525 font->fore = color; |
8061 | 2526 gtk_imhtml_toggle_forecolor(imhtml, font->fore); |
8677 | 2527 } |
8309 | 2528 //else if (oldfont && oldfont->fore) |
2529 // font->fore = g_strdup(oldfont->fore); | |
8677 | 2530 |
2531 if (back && !(options & GTK_IMHTML_NO_COLOURS) && (imhtml->format_functions & GTK_IMHTML_BACKCOLOR)) { | |
3922 | 2532 font->back = back; |
8061 | 2533 gtk_imhtml_toggle_backcolor(imhtml, font->back); |
8309 | 2534 } |
2535 //else if (oldfont && oldfont->back) | |
2536 // font->back = g_strdup(oldfont->back); | |
8677 | 2537 |
2538 if (face && !(options & GTK_IMHTML_NO_FONTS) && (imhtml->format_functions & GTK_IMHTML_FACE)) { | |
3922 | 2539 font->face = face; |
8061 | 2540 gtk_imhtml_toggle_fontface(imhtml, font->face); |
8309 | 2541 } |
2542 //else if (oldfont && oldfont->face) | |
2543 // font->face = g_strdup(oldfont->face); | |
4032 | 2544 |
2545 if (sml) | |
2546 font->sml = sml; | |
2547 else if (oldfont && oldfont->sml) | |
2548 font->sml = g_strdup(oldfont->sml); | |
2549 | |
8677 | 2550 if (size && !(options & GTK_IMHTML_NO_SIZES) && (imhtml->format_functions & (GTK_IMHTML_GROW|GTK_IMHTML_SHRINK))) { |
3922 | 2551 if (*size == '+') { |
2552 sscanf (size + 1, "%hd", &font->size); | |
2553 font->size += 3; | |
2554 } else if (*size == '-') { | |
2555 sscanf (size + 1, "%hd", &font->size); | |
2556 font->size = MAX (0, 3 - font->size); | |
2557 } else if (isdigit (*size)) { | |
2558 sscanf (size, "%hd", &font->size); | |
8061 | 2559 } |
6042 | 2560 if (font->size > 100) |
2561 font->size = 100; | |
3922 | 2562 } else if (oldfont) |
2563 font->size = oldfont->size; | |
8309 | 2564 else |
2565 font->size = 3; | |
8698 | 2566 if ((imhtml->format_functions & (GTK_IMHTML_GROW|GTK_IMHTML_SHRINK))) |
2567 gtk_imhtml_font_set_size(imhtml, font->size); | |
3922 | 2568 g_free(size); |
2569 fonts = g_slist_prepend (fonts, font); | |
2570 } | |
2571 break; | |
2572 case 44: /* BODY (opt) */ | |
2573 if (!(options & GTK_IMHTML_NO_COLOURS)) { | |
2574 char *bgcolor = gtk_imhtml_get_html_opt (tag, "BGCOLOR="); | |
8677 | 2575 if (bgcolor && (imhtml->format_functions & GTK_IMHTML_BACKCOLOR)) { |
2576 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); | |
8061 | 2577 ws[0] = '\0'; wpos = 0; |
8177 | 2578 /* NEW_BIT(NEW_TEXT_BIT); */ |
3922 | 2579 if (bg) |
2580 g_free(bg); | |
2581 bg = bgcolor; | |
10776 | 2582 gtk_imhtml_toggle_background(imhtml, bg); |
2885
f72efa29c109
[gaim-migrate @ 2898]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2871
diff
changeset
|
2583 } |
1428 | 2584 } |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2585 break; |
3922 | 2586 case 45: /* A (opt) */ |
2587 { | |
2588 gchar *href = gtk_imhtml_get_html_opt (tag, "HREF="); | |
8677 | 2589 if (href && (imhtml->format_functions & GTK_IMHTML_LINK)) { |
2590 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); | |
8061 | 2591 ws[0] = '\0'; wpos = 0; |
8677 | 2592 gtk_imhtml_toggle_link(imhtml, href); |
3922 | 2593 } |
10504 | 2594 if (href) |
2595 g_free(href); | |
2993 | 2596 } |
3922 | 2597 break; |
4895 | 2598 case 46: /* IMG (opt) */ |
6982 | 2599 case 59: /* IMG */ |
4895 | 2600 { |
8962 | 2601 const char *id; |
2602 | |
2603 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); | |
2604 ws[0] = '\0'; wpos = 0; | |
4895 | 2605 |
8677 | 2606 if (!(imhtml->format_functions & GTK_IMHTML_IMAGE)) |
2607 break; | |
2608 | |
8962 | 2609 id = gtk_imhtml_get_html_opt(tag, "ID="); |
9186 | 2610 if (!id) |
2611 break; | |
8962 | 2612 gtk_imhtml_insert_image_at_iter(imhtml, atoi(id), iter); |
2613 break; | |
4895 | 2614 } |
3922 | 2615 case 47: /* P (opt) */ |
2616 case 48: /* H3 (opt) */ | |
5093 | 2617 case 49: /* HTML (opt) */ |
5101 | 2618 case 50: /* CITE */ |
2619 case 51: /* /CITE */ | |
8026 | 2620 case 56: /* SPAN (opt) */ |
8118 | 2621 /* Inline CSS Support - Douglas Thrift |
2622 * | |
2623 * color | |
8686 | 2624 * background |
8118 | 2625 * font-family |
2626 * font-size | |
8686 | 2627 * text-decoration: underline |
10483 | 2628 * |
2629 * TODO: | |
2630 * background-color | |
2631 * font-style | |
2632 * font-weight | |
8118 | 2633 */ |
2634 { | |
8686 | 2635 gchar *style, *color, *background, *family, *size; |
2636 gchar *textdec; | |
8118 | 2637 GtkIMHtmlFontDetail *font, *oldfont = NULL; |
2638 style = gtk_imhtml_get_html_opt (tag, "style="); | |
2639 | |
2640 if (!style) break; | |
2641 | |
10457 | 2642 color = gtk_imhtml_get_css_opt (style, "color:"); |
2643 background = gtk_imhtml_get_css_opt (style, "background:"); | |
8118 | 2644 family = gtk_imhtml_get_css_opt (style, |
10457 | 2645 "font-family:"); |
2646 size = gtk_imhtml_get_css_opt (style, "font-size:"); | |
2647 textdec = gtk_imhtml_get_css_opt (style, "text-decoration:"); | |
8686 | 2648 |
2649 if (!(color || family || size || background || textdec)) { | |
8120 | 2650 g_free(style); |
2651 break; | |
2652 } | |
8118 | 2653 |
8677 | 2654 |
2655 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); | |
8118 | 2656 ws[0] = '\0'; wpos = 0; |
8177 | 2657 /* NEW_BIT (NEW_TEXT_BIT); */ |
8118 | 2658 |
2659 font = g_new0 (GtkIMHtmlFontDetail, 1); | |
2660 if (fonts) | |
2661 oldfont = fonts->data; | |
2662 | |
8677 | 2663 if (color && !(options & GTK_IMHTML_NO_COLOURS) && (imhtml->format_functions & GTK_IMHTML_FORECOLOR)) |
8686 | 2664 { |
8118 | 2665 font->fore = color; |
8686 | 2666 gtk_imhtml_toggle_forecolor(imhtml, font->fore); |
2667 } | |
8118 | 2668 else if (oldfont && oldfont->fore) |
2669 font->fore = g_strdup(oldfont->fore); | |
2670 | |
8686 | 2671 if (background && !(options & GTK_IMHTML_NO_COLOURS) && (imhtml->format_functions & GTK_IMHTML_BACKCOLOR)) |
2672 { | |
2673 font->back = background; | |
2674 gtk_imhtml_toggle_backcolor(imhtml, font->back); | |
2675 } | |
2676 else if (oldfont && oldfont->back) | |
8118 | 2677 font->back = g_strdup(oldfont->back); |
2678 | |
8677 | 2679 if (family && !(options & GTK_IMHTML_NO_FONTS) && (imhtml->format_functions & GTK_IMHTML_FACE)) |
8686 | 2680 { |
8118 | 2681 font->face = family; |
8686 | 2682 gtk_imhtml_toggle_fontface(imhtml, font->face); |
2683 } | |
8118 | 2684 else if (oldfont && oldfont->face) |
2685 font->face = g_strdup(oldfont->face); | |
2686 if (font->face && (atoi(font->face) > 100)) { | |
8677 | 2687 /* WTF is this? */ |
9696 | 2688 /* Maybe it sets a max size on the font face? I seem to |
2689 * remember bad things happening if the font size was | |
2690 * 2 billion */ | |
8118 | 2691 g_free(font->face); |
2692 font->face = g_strdup("100"); | |
2693 } | |
2694 | |
2695 if (oldfont && oldfont->sml) | |
2696 font->sml = g_strdup(oldfont->sml); | |
2697 | |
8677 | 2698 if (size && !(options & GTK_IMHTML_NO_SIZES) && (imhtml->format_functions & (GTK_IMHTML_SHRINK|GTK_IMHTML_GROW))) { |
8686 | 2699 if (g_ascii_strcasecmp(size, "xx-small") == 0) |
2700 font->size = 1; | |
2701 else if (g_ascii_strcasecmp(size, "smaller") == 0 | |
2702 || g_ascii_strcasecmp(size, "x-small") == 0) | |
8118 | 2703 font->size = 2; |
8686 | 2704 else if (g_ascii_strcasecmp(size, "larger") == 0 |
2705 || g_ascii_strcasecmp(size, "medium") == 0) | |
8118 | 2706 font->size = 4; |
8686 | 2707 else if (g_ascii_strcasecmp(size, "large") == 0) |
2708 font->size = 5; | |
2709 else if (g_ascii_strcasecmp(size, "x-large") == 0) | |
2710 font->size = 6; | |
2711 else if (g_ascii_strcasecmp(size, "xx-large") == 0) | |
2712 font->size = 7; | |
8118 | 2713 else |
2714 font->size = 3; | |
8686 | 2715 gtk_imhtml_font_set_size(imhtml, font->size); |
2716 } | |
2717 else if (oldfont) | |
2718 { | |
2719 font->size = oldfont->size; | |
2720 } | |
2721 | |
2722 if (oldfont) | |
2723 { | |
2724 font->underline = oldfont->underline; | |
2725 } | |
2726 if (textdec && font->underline != 1 | |
9025 | 2727 && g_ascii_strcasecmp(textdec, "underline") == 0 |
8686 | 2728 && (imhtml->format_functions & GTK_IMHTML_UNDERLINE)) |
2729 { | |
2730 gtk_imhtml_toggle_underline(imhtml); | |
2731 font->underline = 1; | |
2732 } | |
8118 | 2733 |
2734 g_free(style); | |
2735 g_free(size); | |
2736 fonts = g_slist_prepend (fonts, font); | |
2737 } | |
2738 break; | |
5104 | 2739 case 57: /* /SPAN */ |
8118 | 2740 /* Inline CSS Support - Douglas Thrift */ |
8677 | 2741 if (fonts && !imhtml->wbfo) { |
8686 | 2742 GtkIMHtmlFontDetail *oldfont = NULL; |
8118 | 2743 GtkIMHtmlFontDetail *font = fonts->data; |
8677 | 2744 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
8118 | 2745 ws[0] = '\0'; wpos = 0; |
8177 | 2746 /* NEW_BIT (NEW_TEXT_BIT); */ |
8118 | 2747 fonts = g_slist_remove (fonts, font); |
8692 | 2748 if (fonts) |
2749 oldfont = fonts->data; | |
2750 | |
2751 if (!oldfont) { | |
2752 gtk_imhtml_font_set_size(imhtml, 3); | |
2753 if (font->underline) | |
2754 gtk_imhtml_toggle_underline(imhtml); | |
2755 gtk_imhtml_toggle_fontface(imhtml, NULL); | |
2756 gtk_imhtml_toggle_forecolor(imhtml, NULL); | |
2757 gtk_imhtml_toggle_backcolor(imhtml, NULL); | |
8686 | 2758 } |
8692 | 2759 else |
8686 | 2760 { |
8692 | 2761 |
2762 if (font->size != oldfont->size) | |
2763 gtk_imhtml_font_set_size(imhtml, oldfont->size); | |
2764 | |
2765 if (font->underline != oldfont->underline) | |
2766 gtk_imhtml_toggle_underline(imhtml); | |
2767 | |
9286 | 2768 if (font->face && (!oldfont->face || strcmp(font->face, oldfont->face) != 0)) |
8692 | 2769 gtk_imhtml_toggle_fontface(imhtml, oldfont->face); |
2770 | |
9286 | 2771 if (font->fore && (!oldfont->fore || strcmp(font->fore, oldfont->fore) != 0)) |
8692 | 2772 gtk_imhtml_toggle_forecolor(imhtml, oldfont->fore); |
2773 | |
9286 | 2774 if (font->back && (!oldfont->back || strcmp(font->back, oldfont->back) != 0)) |
8692 | 2775 gtk_imhtml_toggle_backcolor(imhtml, oldfont->back); |
8686 | 2776 } |
8692 | 2777 |
2778 g_free (font->face); | |
2779 g_free (font->fore); | |
2780 g_free (font->back); | |
2781 g_free (font->sml); | |
2782 | |
8118 | 2783 g_free (font); |
2784 } | |
2785 break; | |
8026 | 2786 case 60: /* SPAN */ |
2993 | 2787 break; |
8061 | 2788 case 62: /* comment */ |
8177 | 2789 /* NEW_BIT (NEW_TEXT_BIT); */ |
8317 | 2790 ws[wpos] = '\0'; |
9465 | 2791 |
8677 | 2792 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
2793 | |
10815 | 2794 if (imhtml->show_comments && !(options & GTK_IMHTML_NO_COMMENTS)) { |
6124 | 2795 wpos = g_snprintf (ws, len, "%s", tag); |
10815 | 2796 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
2797 } | |
2798 ws[0] = '\0'; wpos = 0; | |
2799 | |
8177 | 2800 /* NEW_BIT (NEW_COMMENT_BIT); */ |
3922 | 2801 break; |
2802 default: | |
6882 | 2803 break; |
2993 | 2804 } |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2805 c += tlen; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2806 pos += tlen; |
4138 | 2807 if(tag) |
2808 g_free(tag); /* This was allocated back in VALID_TAG() */ | |
9029 | 2809 } else if (gtk_imhtml_is_smiley(imhtml, fonts, c, &smilelen)) { |
8473 | 2810 GtkIMHtmlFontDetail *fd; |
2811 | |
2812 gchar *sml = NULL; | |
2813 if (fonts) { | |
2814 fd = fonts->data; | |
2815 sml = fd->sml; | |
2816 } | |
9029 | 2817 if (!sml) |
2818 sml = imhtml->protocol_name; | |
2819 | |
8677 | 2820 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
8505 | 2821 wpos = g_snprintf (ws, smilelen + 1, "%s", c); |
8473 | 2822 |
8677 | 2823 gtk_imhtml_insert_smiley_at_iter(imhtml, sml, ws, iter); |
8473 | 2824 |
8505 | 2825 c += smilelen; |
2826 pos += smilelen; | |
8473 | 2827 wpos = 0; |
2828 ws[0] = 0; | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2829 } else if (*c == '&' && gtk_imhtml_is_amp_escape (c, &, &tlen)) { |
7280 | 2830 while(*amp) { |
2831 ws [wpos++] = *amp++; | |
2832 } | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2833 c += tlen; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2834 pos += tlen; |
1428 | 2835 } else if (*c == '\n') { |
2836 if (!(options & GTK_IMHTML_NO_NEWLINE)) { | |
3922 | 2837 ws[wpos] = '\n'; |
2838 wpos++; | |
8677 | 2839 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
8061 | 2840 ws[0] = '\0'; |
2841 wpos = 0; | |
8177 | 2842 /* NEW_BIT (NEW_TEXT_BIT); */ |
10217 | 2843 } else if (!br) { /* Don't insert a space immediately after an HTML break */ |
9621 | 2844 /* A newline is defined by HTML as whitespace, which means we have to replace it with a word boundary. |
2845 * word breaks vary depending on the language used, so the correct thing to do is to use Pango to determine | |
2846 * what language this is, determine the proper word boundary to use, and insert that. I'm just going to insert | |
2847 * a space instead. What are the non-English speakers going to do? Complain in a language I'll understand? | |
2848 * Bu-wahaha! */ | |
2849 ws[wpos] = ' '; | |
2850 wpos++; | |
2851 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); | |
2852 ws[0] = '\0'; | |
2853 wpos = 0; | |
1428 | 2854 } |
2855 c++; | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2856 pos++; |
8334 | 2857 } else if ((len_protocol = gtk_imhtml_is_protocol(c)) > 0){ |
2858 while(len_protocol--){ | |
8677 | 2859 /* Skip the next len_protocol characters, but make sure they're |
8334 | 2860 copied into the ws array. |
2861 */ | |
2862 ws [wpos++] = *c++; | |
2863 pos++; | |
2864 } | |
8061 | 2865 } else if (*c) { |
1428 | 2866 ws [wpos++] = *c++; |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2867 pos++; |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2868 } else { |
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2826
diff
changeset
|
2869 break; |
1428 | 2870 } |
2871 } | |
8677 | 2872 gtk_text_buffer_insert(imhtml->text_buffer, iter, ws, wpos); |
8061 | 2873 ws[0] = '\0'; wpos = 0; |
2874 | |
8177 | 2875 /* NEW_BIT(NEW_TEXT_BIT); */ |
8061 | 2876 |
4032 | 2877 while (fonts) { |
5967 | 2878 GtkIMHtmlFontDetail *font = fonts->data; |
4032 | 2879 fonts = g_slist_remove (fonts, font); |
2880 if (font->face) | |
2881 g_free (font->face); | |
2882 if (font->fore) | |
2883 g_free (font->fore); | |
2884 if (font->back) | |
2885 g_free (font->back); | |
2886 if (font->sml) | |
2887 g_free (font->sml); | |
2888 g_free (font); | |
2889 } | |
8932 | 2890 |
2891 g_free(ws); | |
2892 if (bg) | |
4630 | 2893 g_free(bg); |
8677 | 2894 |
2895 if (!imhtml->wbfo) | |
8698 | 2896 gtk_imhtml_close_tags(imhtml, iter); |
8506 | 2897 |
2898 object = g_object_ref(G_OBJECT(imhtml)); | |
2899 g_signal_emit(object, signals[UPDATE_FORMAT], 0); | |
2900 g_object_unref(object); | |
2901 | |
3922 | 2902 } |
2903 | |
4892 | 2904 void gtk_imhtml_remove_smileys(GtkIMHtml *imhtml) |
2905 { | |
4288 | 2906 g_hash_table_destroy(imhtml->smiley_data); |
2907 gtk_smiley_tree_destroy(imhtml->default_smilies); | |
4892 | 2908 imhtml->smiley_data = g_hash_table_new_full(g_str_hash, g_str_equal, |
4902 | 2909 g_free, (GDestroyNotify)gtk_smiley_tree_destroy); |
4288 | 2910 imhtml->default_smilies = gtk_smiley_tree_new(); |
2911 } | |
8481 | 2912 |
3922 | 2913 void gtk_imhtml_show_comments (GtkIMHtml *imhtml, |
4253 | 2914 gboolean show) |
2915 { | |
6124 | 2916 imhtml->show_comments = show; |
4253 | 2917 } |
1780
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
2918 |
8962 | 2919 void |
9029 | 2920 gtk_imhtml_set_protocol_name(GtkIMHtml *imhtml, const gchar *protocol_name) { |
2921 if (imhtml->protocol_name) | |
2922 g_free(imhtml->protocol_name); | |
2923 imhtml->protocol_name = protocol_name ? g_strdup(protocol_name) : NULL; | |
8456 | 2924 } |
2925 | |
1780
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
2926 void |
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
2927 gtk_imhtml_clear (GtkIMHtml *imhtml) |
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
2928 { |
7991 | 2929 GList *del; |
3922 | 2930 GtkTextIter start, end; |
8427 | 2931 GObject *object = g_object_ref(G_OBJECT(imhtml)); |
10692 | 2932 |
3922 | 2933 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start); |
2934 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end); | |
2935 gtk_text_buffer_delete(imhtml->text_buffer, &start, &end); | |
7991 | 2936 |
2937 for(del = imhtml->scalables; del; del = del->next) { | |
2938 GtkIMHtmlScalable *scale = del->data; | |
2939 scale->free(scale); | |
2940 } | |
10692 | 2941 |
7991 | 2942 g_list_free(imhtml->scalables); |
2943 imhtml->scalables = NULL; | |
8061 | 2944 |
8427 | 2945 g_object_unref(object); |
1780
d7cbedd1d651
[gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1738
diff
changeset
|
2946 } |
2363
08c66712364c
[gaim-migrate @ 2376]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2349
diff
changeset
|
2947 |
4046 | 2948 void gtk_imhtml_page_up (GtkIMHtml *imhtml) |
2949 { | |
5282 | 2950 GdkRectangle rect; |
2951 GtkTextIter iter; | |
4046 | 2952 |
5282 | 2953 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); |
2954 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(imhtml), &iter, rect.x, | |
2955 rect.y - rect.height); | |
2956 gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(imhtml), &iter, 0, TRUE, 0, 0); | |
8061 | 2957 |
4046 | 2958 } |
5282 | 2959 void gtk_imhtml_page_down (GtkIMHtml *imhtml) |
2960 { | |
2961 GdkRectangle rect; | |
2962 GtkTextIter iter; | |
2963 | |
2964 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); | |
2965 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(imhtml), &iter, rect.x, | |
2966 rect.y + rect.height); | |
2967 gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(imhtml), &iter, 0, TRUE, 0, 0); | |
2968 } | |
4735 | 2969 |
5967 | 2970 /* GtkIMHtmlScalable, gtk_imhtml_image, gtk_imhtml_hr */ |
8962 | 2971 GtkIMHtmlScalable *gtk_imhtml_image_new(GdkPixbuf *img, const gchar *filename, int id) |
4735 | 2972 { |
5967 | 2973 GtkIMHtmlImage *im_image = g_malloc(sizeof(GtkIMHtmlImage)); |
5012 | 2974 GtkImage *image = GTK_IMAGE(gtk_image_new_from_pixbuf(img)); |
4895 | 2975 |
5967 | 2976 GTK_IMHTML_SCALABLE(im_image)->scale = gtk_imhtml_image_scale; |
2977 GTK_IMHTML_SCALABLE(im_image)->add_to = gtk_imhtml_image_add_to; | |
2978 GTK_IMHTML_SCALABLE(im_image)->free = gtk_imhtml_image_free; | |
5046 | 2979 |
2980 im_image->pixbuf = img; | |
5012 | 2981 im_image->image = image; |
4895 | 2982 im_image->width = gdk_pixbuf_get_width(img); |
2983 im_image->height = gdk_pixbuf_get_height(img); | |
2984 im_image->mark = NULL; | |
6982 | 2985 im_image->filename = filename ? g_strdup(filename) : NULL; |
8962 | 2986 im_image->id = id; |
9573 | 2987 im_image->filesel = NULL; |
4895 | 2988 |
5046 | 2989 g_object_ref(img); |
4895 | 2990 return GTK_IMHTML_SCALABLE(im_image); |
2991 } | |
2992 | |
5967 | 2993 void gtk_imhtml_image_scale(GtkIMHtmlScalable *scale, int width, int height) |
4895 | 2994 { |
5967 | 2995 GtkIMHtmlImage *image = (GtkIMHtmlImage *)scale; |
4895 | 2996 |
2997 if(image->width > width || image->height > height){ | |
2998 GdkPixbuf *new_image = NULL; | |
2999 float factor; | |
3000 int new_width = image->width, new_height = image->height; | |
3001 | |
8588 | 3002 if(image->width > (width - 2)){ |
4895 | 3003 factor = (float)(width)/image->width; |
3004 new_width = width; | |
3005 new_height = image->height * factor; | |
3006 } | |
8588 | 3007 if(new_height >= (height - 2)){ |
4895 | 3008 factor = (float)(height)/new_height; |
3009 new_height = height; | |
3010 new_width = new_width * factor; | |
3011 } | |
3012 | |
5046 | 3013 new_image = gdk_pixbuf_scale_simple(image->pixbuf, new_width, new_height, GDK_INTERP_BILINEAR); |
5012 | 3014 gtk_image_set_from_pixbuf(image->image, new_image); |
4895 | 3015 g_object_unref(G_OBJECT(new_image)); |
3016 } | |
3017 } | |
3018 | |
9573 | 3019 static void |
3020 image_save_yes_cb(GtkIMHtmlImage *image, const char *filename) | |
5012 | 3021 { |
3022 gchar *type = NULL; | |
5019 | 3023 GError *error = NULL; |
5015 | 3024 #if GTK_CHECK_VERSION(2,2,0) |
5012 | 3025 GSList *formats = gdk_pixbuf_get_formats(); |
6162 | 3026 #else |
3027 char *basename = g_path_get_basename(filename); | |
3028 char *ext = strrchr(basename, '.'); | |
5959 | 3029 #endif |
5012 | 3030 |
9573 | 3031 gtk_widget_destroy(image->filesel); |
3032 image->filesel = NULL; | |
5959 | 3033 |
3034 #if GTK_CHECK_VERSION(2,2,0) | |
9573 | 3035 while (formats) { |
5012 | 3036 GdkPixbufFormat *format = formats->data; |
3037 gchar **extensions = gdk_pixbuf_format_get_extensions(format); | |
3038 gpointer p = extensions; | |
3039 | |
3040 while(gdk_pixbuf_format_is_writable(format) && extensions && extensions[0]){ | |
3041 gchar *fmt_ext = extensions[0]; | |
3042 const gchar* file_ext = filename + strlen(filename) - strlen(fmt_ext); | |
3043 | |
3044 if(!strcmp(fmt_ext, file_ext)){ | |
3045 type = gdk_pixbuf_format_get_name(format); | |
3046 break; | |
3047 } | |
3048 | |
3049 extensions++; | |
3050 } | |
3051 | |
3052 g_strfreev(p); | |
3053 | |
9573 | 3054 if (type) |
5012 | 3055 break; |
3056 | |
3057 formats = formats->next; | |
3058 } | |
3059 | |
5020 | 3060 g_slist_free(formats); |
3061 #else | |
3062 /* this is really ugly code, but I think it will work */ | |
9573 | 3063 if (ext) { |
5020 | 3064 ext++; |
9573 | 3065 if (!g_ascii_strcasecmp(ext, "jpeg") || !g_ascii_strcasecmp(ext, "jpg")) |
5020 | 3066 type = g_strdup("jpeg"); |
9573 | 3067 else if (!g_ascii_strcasecmp(ext, "png")) |
5020 | 3068 type = g_strdup("png"); |
3069 } | |
3070 | |
3071 g_free(basename); | |
3072 #endif | |
3073 | |
5012 | 3074 /* If I can't find a valid type, I will just tell the user about it and then assume |
3075 it's a png */ | |
9573 | 3076 if (!type){ |
5012 | 3077 gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, |
9717 | 3078 _("Unable to guess the image type based on the file extension supplied. Defaulting to PNG.")); |
3079 type = g_strdup("png"); | |
5012 | 3080 } |
3081 | |
5046 | 3082 gdk_pixbuf_save(image->pixbuf, filename, type, &error, NULL); |
5012 | 3083 |
9573 | 3084 if (error){ |
5012 | 3085 gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, |
3086 _("Error saving image: %s"), error->message); | |
3087 g_error_free(error); | |
3088 } | |
3089 | |
3090 g_free(type); | |
3091 } | |
3092 | |
9573 | 3093 #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */ |
3094 static void | |
3095 image_save_check_if_exists_cb(GtkWidget *widget, gint response, GtkIMHtmlImage *image) | |
3096 { | |
3097 gchar *filename; | |
3098 | |
3099 if (response != GTK_RESPONSE_ACCEPT) { | |
3100 gtk_widget_destroy(widget); | |
3101 image->filesel = NULL; | |
3102 return; | |
3103 } | |
3104 | |
3105 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(widget)); | |
3106 #else /* FILECHOOSER */ | |
3107 static void | |
3108 image_save_check_if_exists_cb(GtkWidget *button, GtkIMHtmlImage *image) | |
5012 | 3109 { |
9573 | 3110 gchar *filename; |
3111 | |
3112 filename = g_strdup(gtk_file_selection_get_filename(GTK_FILE_SELECTION(image->filesel))); | |
3113 | |
3114 if (g_file_test(filename, G_FILE_TEST_IS_DIR)) { | |
3115 gchar *dirname; | |
3116 /* append a / is needed */ | |
3117 if (filename[strlen(filename) - 1] != G_DIR_SEPARATOR) { | |
3118 dirname = g_strconcat(filename, G_DIR_SEPARATOR_S, NULL); | |
3119 } else { | |
3120 dirname = g_strdup(filename); | |
3121 } | |
9574 | 3122 gtk_file_selection_set_filename(GTK_FILE_SELECTION(image->filesel), dirname); |
9573 | 3123 g_free(dirname); |
3124 g_free(filename); | |
3125 return; | |
3126 } | |
3127 #endif /* FILECHOOSER */ | |
3128 | |
3129 /* | |
3130 * XXX - We should probably prompt the user to determine if they really | |
3131 * want to overwrite the file or not. However, I don't feel like doing | |
3132 * that, so we're just always going to overwrite if the file exists. | |
3133 */ | |
3134 /* | |
3135 if (g_file_test(filename, G_FILE_TEST_EXISTS)) { | |
3136 } else | |
3137 image_save_yes_cb(image, filename); | |
3138 */ | |
3139 | |
3140 image_save_yes_cb(image, filename); | |
3141 | |
3142 g_free(filename); | |
3143 } | |
3144 | |
3145 #if !GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */ | |
3146 static void | |
3147 image_save_cancel_cb(GtkIMHtmlImage *image) | |
3148 { | |
3149 gtk_widget_destroy(image->filesel); | |
3150 image->filesel = NULL; | |
3151 } | |
3152 #endif /* FILECHOOSER */ | |
3153 | |
3154 static void | |
3155 gtk_imhtml_image_save(GtkWidget *w, GtkIMHtmlImage *image) | |
3156 { | |
3157 if (image->filesel != NULL) { | |
3158 gtk_window_present(GTK_WINDOW(image->filesel)); | |
3159 return; | |
3160 } | |
3161 | |
3162 #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */ | |
3163 image->filesel = gtk_file_chooser_dialog_new(_("Save Image"), | |
3164 NULL, | |
3165 GTK_FILE_CHOOSER_ACTION_SAVE, | |
3166 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, | |
3167 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, | |
3168 NULL); | |
3169 gtk_dialog_set_default_response(GTK_DIALOG(image->filesel), GTK_RESPONSE_ACCEPT); | |
3170 if (image->filename != NULL) | |
3171 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(image->filesel), image->filename); | |
3172 g_signal_connect(G_OBJECT(GTK_FILE_CHOOSER(image->filesel)), "response", | |
3173 G_CALLBACK(image_save_check_if_exists_cb), image); | |
3174 #else /* FILECHOOSER */ | |
3175 image->filesel = gtk_file_selection_new(_("Save Image")); | |
3176 if (image->filename != NULL) | |
3177 gtk_file_selection_set_filename(GTK_FILE_SELECTION(image->filesel), image->filename); | |
9574 | 3178 g_signal_connect_swapped(G_OBJECT(GTK_FILE_SELECTION(image->filesel)), "delete_event", |
3179 G_CALLBACK(image_save_cancel_cb), image); | |
3180 g_signal_connect_swapped(G_OBJECT(GTK_FILE_SELECTION(image->filesel)->cancel_button), | |
3181 "clicked", G_CALLBACK(image_save_cancel_cb), image); | |
9573 | 3182 g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(image->filesel)->ok_button), "clicked", |
3183 G_CALLBACK(image_save_check_if_exists_cb), image); | |
3184 #endif /* FILECHOOSER */ | |
3185 | |
3186 gtk_widget_show(image->filesel); | |
5012 | 3187 } |
3188 | |
9815 | 3189 /* |
3190 * So, um, AIM Direct IM lets you send any file, not just images. You can | |
3191 * just insert a sound or a file or whatever in a conversation. It's | |
3192 * basically like file transfer, except there is an icon to open the file | |
3193 * embedded in the conversation. Someone should make the Gaim core handle | |
3194 * all of that. | |
3195 */ | |
5967 | 3196 static gboolean gtk_imhtml_image_clicked(GtkWidget *w, GdkEvent *event, GtkIMHtmlImage *image) |
5012 | 3197 { |
3198 GdkEventButton *event_button = (GdkEventButton *) event; | |
3199 | |
3200 if (event->type == GDK_BUTTON_RELEASE) { | |
3201 if(event_button->button == 3) { | |
3202 GtkWidget *img, *item, *menu; | |
3203 gchar *text = g_strdup_printf(_("_Save Image...")); | |
3204 menu = gtk_menu_new(); | |
3205 | |
3206 /* buttons and such */ | |
3207 img = gtk_image_new_from_stock(GTK_STOCK_SAVE, GTK_ICON_SIZE_MENU); | |
3208 item = gtk_image_menu_item_new_with_mnemonic(text); | |
3209 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), img); | |
5967 | 3210 g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(gtk_imhtml_image_save), image); |
5012 | 3211 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); |
3212 | |
3213 gtk_widget_show_all(menu); | |
3214 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, | |
3215 event_button->button, event_button->time); | |
3216 | |
3217 g_free(text); | |
3218 return TRUE; | |
3219 } | |
3220 } | |
3221 if(event->type == GDK_BUTTON_PRESS && event_button->button == 3) | |
3222 return TRUE; /* Clicking the right mouse button on a link shouldn't | |
3223 be caught by the regular GtkTextView menu */ | |
3224 else | |
3225 return FALSE; /* Let clicks go through if we didn't catch anything */ | |
3226 | |
3227 } | |
5967 | 3228 void gtk_imhtml_image_free(GtkIMHtmlScalable *scale) |
3229 { | |
3230 GtkIMHtmlImage *image = (GtkIMHtmlImage *)scale; | |
3231 | |
3232 g_object_unref(image->pixbuf); | |
6982 | 3233 if (image->filename) |
3234 g_free(image->filename); | |
9573 | 3235 if (image->filesel) |
3236 gtk_widget_destroy(image->filesel); | |
5967 | 3237 g_free(scale); |
3238 } | |
3239 | |
3240 void gtk_imhtml_image_add_to(GtkIMHtmlScalable *scale, GtkIMHtml *imhtml, GtkTextIter *iter) | |
3241 { | |
3242 GtkIMHtmlImage *image = (GtkIMHtmlImage *)scale; | |
3243 GtkWidget *box = gtk_event_box_new(); | |
8962 | 3244 char *tag; |
5967 | 3245 GtkTextChildAnchor *anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, iter); |
3246 | |
3247 gtk_container_add(GTK_CONTAINER(box), GTK_WIDGET(image->image)); | |
9229 | 3248 |
3249 if(!gtk_check_version(2, 4, 0)) | |
3250 g_object_set(G_OBJECT(box), "visible-window", FALSE, NULL); | |
5967 | 3251 |
3252 gtk_widget_show(GTK_WIDGET(image->image)); | |
3253 gtk_widget_show(box); | |
3254 | |
8962 | 3255 tag = g_strdup_printf("<IMG ID=\"%d\">", image->id); |
3256 g_object_set_data_full(G_OBJECT(anchor), "gtkimhtml_htmltext", tag, g_free); | |
3257 g_object_set_data(G_OBJECT(anchor), "gtkimhtml_plaintext", "[Image]"); | |
3258 | |
5967 | 3259 gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(imhtml), box, anchor); |
3260 g_signal_connect(G_OBJECT(box), "event", G_CALLBACK(gtk_imhtml_image_clicked), image); | |
3261 } | |
3262 | |
3263 GtkIMHtmlScalable *gtk_imhtml_hr_new() | |
3264 { | |
3265 GtkIMHtmlHr *hr = g_malloc(sizeof(GtkIMHtmlHr)); | |
3266 | |
3267 GTK_IMHTML_SCALABLE(hr)->scale = gtk_imhtml_hr_scale; | |
3268 GTK_IMHTML_SCALABLE(hr)->add_to = gtk_imhtml_hr_add_to; | |
3269 GTK_IMHTML_SCALABLE(hr)->free = gtk_imhtml_hr_free; | |
3270 | |
3271 hr->sep = gtk_hseparator_new(); | |
3272 gtk_widget_set_size_request(hr->sep, 5000, 2); | |
3273 gtk_widget_show(hr->sep); | |
3274 | |
3275 return GTK_IMHTML_SCALABLE(hr); | |
3276 } | |
3277 | |
3278 void gtk_imhtml_hr_scale(GtkIMHtmlScalable *scale, int width, int height) | |
3279 { | |
8588 | 3280 gtk_widget_set_size_request(((GtkIMHtmlHr *)scale)->sep, width - 2, 2); |
5967 | 3281 } |
3282 | |
3283 void gtk_imhtml_hr_add_to(GtkIMHtmlScalable *scale, GtkIMHtml *imhtml, GtkTextIter *iter) | |
3284 { | |
3285 GtkIMHtmlHr *hr = (GtkIMHtmlHr *)scale; | |
3286 GtkTextChildAnchor *anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, iter); | |
8698 | 3287 g_object_set_data(G_OBJECT(anchor), "gtkimhtml_htmltext", "<hr>"); |
3288 g_object_set_data(G_OBJECT(anchor), "gtkimhtml_plaintext", "\n---\n"); | |
5967 | 3289 gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(imhtml), hr->sep, anchor); |
3290 } | |
3291 | |
3292 void gtk_imhtml_hr_free(GtkIMHtmlScalable *scale) | |
3293 { | |
3294 g_free(scale); | |
3295 } | |
7295 | 3296 |
3297 gboolean gtk_imhtml_search_find(GtkIMHtml *imhtml, const gchar *text) | |
3298 { | |
3299 GtkTextIter iter, start, end; | |
3300 gboolean new_search = TRUE; | |
3301 | |
3302 g_return_val_if_fail(imhtml != NULL, FALSE); | |
3303 g_return_val_if_fail(text != NULL, FALSE); | |
8061 | 3304 |
7295 | 3305 if (imhtml->search_string && !strcmp(text, imhtml->search_string)) |
3306 new_search = FALSE; | |
8061 | 3307 |
7295 | 3308 if (new_search) { |
3309 gtk_imhtml_search_clear(imhtml); | |
3310 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &iter); | |
3311 } else { | |
3312 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, | |
8061 | 3313 gtk_text_buffer_get_mark(imhtml->text_buffer, "search")); |
7295 | 3314 } |
10574 | 3315 g_free(imhtml->search_string); |
7295 | 3316 imhtml->search_string = g_strdup(text); |
3317 | |
7358 | 3318 if (gtk_source_iter_forward_search(&iter, imhtml->search_string, |
3319 GTK_SOURCE_SEARCH_VISIBLE_ONLY | GTK_SOURCE_SEARCH_CASE_INSENSITIVE, | |
7295 | 3320 &start, &end, NULL)) { |
3321 | |
3322 gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(imhtml), &start, 0, TRUE, 0, 0); | |
3323 gtk_text_buffer_create_mark(imhtml->text_buffer, "search", &end, FALSE); | |
3324 if (new_search) { | |
3325 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "search", &iter, &end); | |
8061 | 3326 do |
7295 | 3327 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "search", &start, &end); |
8061 | 3328 while (gtk_source_iter_forward_search(&end, imhtml->search_string, |
3329 GTK_SOURCE_SEARCH_VISIBLE_ONLY | | |
7358 | 3330 GTK_SOURCE_SEARCH_CASE_INSENSITIVE, |
7295 | 3331 &start, &end, NULL)); |
3332 } | |
3333 return TRUE; | |
3334 } | |
8061 | 3335 |
3336 gtk_imhtml_search_clear(imhtml); | |
3337 | |
7295 | 3338 return FALSE; |
3339 } | |
3340 | |
3341 void gtk_imhtml_search_clear(GtkIMHtml *imhtml) | |
3342 { | |
3343 GtkTextIter start, end; | |
8061 | 3344 |
7295 | 3345 g_return_if_fail(imhtml != NULL); |
8061 | 3346 |
7295 | 3347 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start); |
3348 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end); | |
3349 | |
3350 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "search", &start, &end); | |
3351 if (imhtml->search_string) | |
3352 g_free(imhtml->search_string); | |
3353 imhtml->search_string = NULL; | |
3354 } | |
8061 | 3355 |
8677 | 3356 static GtkTextTag *find_font_forecolor_tag(GtkIMHtml *imhtml, gchar *color) |
3357 { | |
3358 gchar str[18]; | |
3359 GtkTextTag *tag; | |
3360 | |
3361 g_snprintf(str, sizeof(str), "FORECOLOR %s", color); | |
3362 | |
3363 tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), str); | |
3364 if (!tag) | |
3365 tag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "foreground", color, NULL); | |
3366 | |
3367 return tag; | |
3368 } | |
3369 | |
3370 static GtkTextTag *find_font_backcolor_tag(GtkIMHtml *imhtml, gchar *color) | |
3371 { | |
3372 gchar str[18]; | |
3373 GtkTextTag *tag; | |
3374 | |
3375 g_snprintf(str, sizeof(str), "BACKCOLOR %s", color); | |
3376 | |
3377 tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), str); | |
3378 if (!tag) | |
3379 tag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "background", color, NULL); | |
3380 | |
3381 return tag; | |
3382 } | |
3383 | |
10776 | 3384 static GtkTextTag *find_font_background_tag(GtkIMHtml *imhtml, gchar *color) |
3385 { | |
3386 gchar str[19]; | |
3387 GtkTextTag *tag; | |
3388 | |
3389 g_snprintf(str, sizeof(str), "BACKGROUND %s", color); | |
3390 | |
3391 tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), str); | |
3392 if (!tag) | |
3393 tag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, NULL); | |
3394 | |
3395 return tag; | |
3396 } | |
3397 | |
8677 | 3398 static GtkTextTag *find_font_face_tag(GtkIMHtml *imhtml, gchar *face) |
8061 | 3399 { |
8677 | 3400 gchar str[256]; |
3401 GtkTextTag *tag; | |
3402 | |
3403 g_snprintf(str, sizeof(str), "FONT FACE %s", face); | |
3404 str[255] = '\0'; | |
3405 | |
3406 tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), str); | |
3407 if (!tag) | |
3408 tag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "family", face, NULL); | |
3409 | |
3410 return tag; | |
3411 } | |
3412 | |
3413 static GtkTextTag *find_font_size_tag(GtkIMHtml *imhtml, int size) | |
3414 { | |
3415 gchar str[24]; | |
3416 GtkTextTag *tag; | |
3417 | |
3418 g_snprintf(str, sizeof(str), "FONT SIZE %d", size); | |
3419 str[23] = '\0'; | |
3420 | |
3421 tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(imhtml->text_buffer), str); | |
3422 if (!tag) { | |
10525
ddea15f4cbc2
[gaim-migrate @ 11842]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10524
diff
changeset
|
3423 /* For reasons I don't understand, setting "scale" here scaled |
ddea15f4cbc2
[gaim-migrate @ 11842]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10524
diff
changeset
|
3424 * based on some default size other than my theme's default |
ddea15f4cbc2
[gaim-migrate @ 11842]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10524
diff
changeset
|
3425 * 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
|
3426 * me. So this works around that oddity. |
8677 | 3427 */ |
10525
ddea15f4cbc2
[gaim-migrate @ 11842]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10524
diff
changeset
|
3428 GtkTextAttributes *attr = gtk_text_view_get_default_attributes(GTK_TEXT_VIEW(imhtml)); |
8677 | 3429 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
|
3430 (gint) (pango_font_description_get_size(attr->font) * |
ddea15f4cbc2
[gaim-migrate @ 11842]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10524
diff
changeset
|
3431 (double) _point_sizes[size-1]), NULL); |
ddea15f4cbc2
[gaim-migrate @ 11842]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10524
diff
changeset
|
3432 gtk_text_attributes_unref(attr); |
8061 | 3433 } |
3434 | |
8677 | 3435 return tag; |
3436 } | |
3437 | |
3438 static void remove_tag_by_prefix(GtkIMHtml *imhtml, const GtkTextIter *i, const GtkTextIter *e, | |
3439 const char *prefix, guint len, gboolean homo) | |
3440 { | |
3441 GSList *tags, *l; | |
3442 GtkTextIter iter; | |
3443 | |
3444 tags = gtk_text_iter_get_tags(i); | |
3445 | |
3446 for (l = tags; l; l = l->next) { | |
3447 GtkTextTag *tag = l->data; | |
3448 | |
3449 if (tag->name && !strncmp(tag->name, prefix, len)) | |
3450 gtk_text_buffer_remove_tag(imhtml->text_buffer, tag, i, e); | |
8061 | 3451 } |
3452 | |
8677 | 3453 g_slist_free(tags); |
3454 | |
3455 if (homo) | |
3456 return; | |
3457 | |
3458 iter = *i; | |
3459 | |
3460 while (gtk_text_iter_forward_char(&iter) && !gtk_text_iter_equal(&iter, e)) { | |
3461 if (gtk_text_iter_begins_tag(&iter, NULL)) { | |
3462 tags = gtk_text_iter_get_toggled_tags(&iter, TRUE); | |
3463 | |
3464 for (l = tags; l; l = l->next) { | |
3465 GtkTextTag *tag = l->data; | |
3466 | |
3467 if (tag->name && !strncmp(tag->name, prefix, len)) | |
3468 gtk_text_buffer_remove_tag(imhtml->text_buffer, tag, &iter, e); | |
3469 } | |
3470 | |
3471 g_slist_free(tags); | |
3472 } | |
8061 | 3473 } |
8677 | 3474 } |
3475 | |
3476 static void remove_font_size(GtkIMHtml *imhtml, GtkTextIter *i, GtkTextIter *e, gboolean homo) | |
3477 { | |
3478 remove_tag_by_prefix(imhtml, i, e, "FONT SIZE ", 10, homo); | |
3479 } | |
3480 | |
3481 static void remove_font_face(GtkIMHtml *imhtml, GtkTextIter *i, GtkTextIter *e, gboolean homo) | |
3482 { | |
3483 remove_tag_by_prefix(imhtml, i, e, "FONT FACE ", 10, homo); | |
3484 } | |
3485 | |
3486 static void remove_font_forecolor(GtkIMHtml *imhtml, GtkTextIter *i, GtkTextIter *e, gboolean homo) | |
3487 { | |
3488 remove_tag_by_prefix(imhtml, i, e, "FORECOLOR ", 10, homo); | |
3489 } | |
3490 | |
3491 static void remove_font_backcolor(GtkIMHtml *imhtml, GtkTextIter *i, GtkTextIter *e, gboolean homo) | |
3492 { | |
3493 remove_tag_by_prefix(imhtml, i, e, "BACKCOLOR ", 10, homo); | |
3494 } | |
3495 | |
10776 | 3496 static void remove_font_background(GtkIMHtml *imhtml, GtkTextIter *i, GtkTextIter *e, gboolean homo) |
3497 { | |
3498 remove_tag_by_prefix(imhtml, i, e, "BACKGROUND ", 10, homo); | |
3499 } | |
3500 | |
8677 | 3501 static void remove_font_link(GtkIMHtml *imhtml, GtkTextIter *i, GtkTextIter *e, gboolean homo) |
3502 { | |
3503 remove_tag_by_prefix(imhtml, i, e, "LINK ", 5, homo); | |
3504 } | |
3505 | |
3506 /* Editable stuff */ | |
3507 static void preinsert_cb(GtkTextBuffer *buffer, GtkTextIter *iter, gchar *text, gint len, GtkIMHtml *imhtml) | |
3508 { | |
3509 imhtml->insert_offset = gtk_text_iter_get_offset(iter); | |
3510 } | |
3511 | |
10169 | 3512 static void insert_ca_cb(GtkTextBuffer *buffer, GtkTextIter *arg1, GtkTextChildAnchor *arg2, gpointer user_data) |
3513 { | |
3514 GtkTextIter start; | |
3515 | |
3516 start = *arg1; | |
3517 gtk_text_iter_backward_char(&start); | |
3518 | |
3519 gtk_imhtml_apply_tags_on_insert(user_data, &start, arg1); | |
3520 } | |
3521 | |
8677 | 3522 static void insert_cb(GtkTextBuffer *buffer, GtkTextIter *end, gchar *text, gint len, GtkIMHtml *imhtml) |
3523 { | |
3524 GtkTextIter start; | |
3525 | |
3526 if (!len) | |
3527 return; | |
3528 | |
3529 start = *end; | |
3530 gtk_text_iter_set_offset(&start, imhtml->insert_offset); | |
3531 | |
10169 | 3532 gtk_imhtml_apply_tags_on_insert(imhtml, &start, end); |
3533 } | |
3534 | |
3535 static void gtk_imhtml_apply_tags_on_insert(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *end) | |
3536 { | |
8677 | 3537 if (imhtml->edit.bold) |
10169 | 3538 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "BOLD", start, end); |
8677 | 3539 else |
10169 | 3540 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "BOLD", start, end); |
8677 | 3541 |
3542 if (imhtml->edit.italic) | |
10169 | 3543 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "ITALICS", start, end); |
8677 | 3544 else |
10169 | 3545 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "ITALICS", start, end); |
8677 | 3546 |
3547 if (imhtml->edit.underline) | |
10169 | 3548 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "UNDERLINE", start, end); |
8677 | 3549 else |
10169 | 3550 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "UNDERLINE", start, end); |
8677 | 3551 |
9924 | 3552 if (imhtml->edit.strike) |
10169 | 3553 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "STRIKE", start, end); |
9924 | 3554 else |
10169 | 3555 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "STRIKE", start, end); |
9924 | 3556 |
8677 | 3557 if (imhtml->edit.forecolor) { |
10169 | 3558 remove_font_forecolor(imhtml, start, end, TRUE); |
8677 | 3559 gtk_text_buffer_apply_tag(imhtml->text_buffer, |
3560 find_font_forecolor_tag(imhtml, imhtml->edit.forecolor), | |
10169 | 3561 start, end); |
8061 | 3562 } |
3563 | |
8677 | 3564 if (imhtml->edit.backcolor) { |
10169 | 3565 remove_font_backcolor(imhtml, start, end, TRUE); |
8677 | 3566 gtk_text_buffer_apply_tag(imhtml->text_buffer, |
3567 find_font_backcolor_tag(imhtml, imhtml->edit.backcolor), | |
10169 | 3568 start, end); |
8677 | 3569 } |
3570 | |
10776 | 3571 if (imhtml->edit.background) { |
3572 remove_font_background(imhtml, start, end, TRUE); | |
3573 gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
3574 find_font_background_tag(imhtml, imhtml->edit.background), | |
3575 start, end); | |
3576 } | |
8677 | 3577 if (imhtml->edit.fontface) { |
10169 | 3578 remove_font_face(imhtml, start, end, TRUE); |
8677 | 3579 gtk_text_buffer_apply_tag(imhtml->text_buffer, |
3580 find_font_face_tag(imhtml, imhtml->edit.fontface), | |
10169 | 3581 start, end); |
8061 | 3582 } |
8677 | 3583 |
3584 if (imhtml->edit.fontsize) { | |
10169 | 3585 remove_font_size(imhtml, start, end, TRUE); |
8677 | 3586 gtk_text_buffer_apply_tag(imhtml->text_buffer, |
3587 find_font_size_tag(imhtml, imhtml->edit.fontsize), | |
10169 | 3588 start, end); |
8677 | 3589 } |
3590 | |
3591 if (imhtml->edit.link) { | |
10169 | 3592 remove_font_link(imhtml, start, end, TRUE); |
8677 | 3593 gtk_text_buffer_apply_tag(imhtml->text_buffer, |
3594 imhtml->edit.link, | |
10169 | 3595 start, end); |
8677 | 3596 } |
8061 | 3597 } |
3598 | |
3599 void gtk_imhtml_set_editable(GtkIMHtml *imhtml, gboolean editable) | |
3600 { | |
3601 gtk_text_view_set_editable(GTK_TEXT_VIEW(imhtml), editable); | |
8177 | 3602 /* |
3603 * We need a visible caret for accessibility, so mouseless | |
3604 * people can highlight stuff. | |
3605 */ | |
3606 /* gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(imhtml), editable); */ | |
8061 | 3607 imhtml->editable = editable; |
8677 | 3608 imhtml->format_functions = GTK_IMHTML_ALL; |
3609 | |
3610 if (editable) | |
3611 g_signal_connect_after(G_OBJECT(GTK_IMHTML(imhtml)->text_buffer), "mark-set", | |
3612 G_CALLBACK(mark_set_cb), imhtml); | |
3613 } | |
3614 | |
3615 void gtk_imhtml_set_whole_buffer_formatting_only(GtkIMHtml *imhtml, gboolean wbfo) | |
3616 { | |
3617 g_return_if_fail(imhtml != NULL); | |
3618 | |
3619 imhtml->wbfo = wbfo; | |
8420 | 3620 } |
3621 | |
3622 void gtk_imhtml_set_format_functions(GtkIMHtml *imhtml, GtkIMHtmlButtons buttons) | |
3623 { | |
3624 GObject *object = g_object_ref(G_OBJECT(imhtml)); | |
8677 | 3625 imhtml->format_functions = buttons; |
8420 | 3626 g_signal_emit(object, signals[BUTTONS_UPDATE], 0, buttons); |
3627 g_object_unref(object); | |
8061 | 3628 } |
3629 | |
8788 | 3630 GtkIMHtmlButtons gtk_imhtml_get_format_functions(GtkIMHtml *imhtml) |
3631 { | |
3632 return imhtml->format_functions; | |
3633 } | |
8516 | 3634 |
3635 void gtk_imhtml_get_current_format(GtkIMHtml *imhtml, gboolean *bold, | |
3636 gboolean *italic, gboolean *underline) | |
8481 | 3637 { |
8677 | 3638 if (imhtml->edit.bold) |
3639 (*bold) = TRUE; | |
3640 if (imhtml->edit.italic) | |
3641 (*italic) = TRUE; | |
3642 if (imhtml->edit.underline) | |
3643 (*underline) = TRUE; | |
8481 | 3644 } |
3645 | |
9025 | 3646 char * |
3647 gtk_imhtml_get_current_fontface(GtkIMHtml *imhtml) | |
3648 { | |
3649 if (imhtml->edit.fontface) | |
3650 return g_strdup(imhtml->edit.fontface); | |
3651 else | |
3652 return NULL; | |
3653 } | |
3654 | |
3655 char * | |
3656 gtk_imhtml_get_current_forecolor(GtkIMHtml *imhtml) | |
3657 { | |
3658 if (imhtml->edit.forecolor) | |
3659 return g_strdup(imhtml->edit.forecolor); | |
3660 else | |
3661 return NULL; | |
3662 } | |
3663 | |
3664 char * | |
3665 gtk_imhtml_get_current_backcolor(GtkIMHtml *imhtml) | |
3666 { | |
3667 if (imhtml->edit.backcolor) | |
3668 return g_strdup(imhtml->edit.backcolor); | |
3669 else | |
3670 return NULL; | |
3671 } | |
3672 | |
3673 gint | |
3674 gtk_imhtml_get_current_fontsize(GtkIMHtml *imhtml) | |
3675 { | |
3676 return imhtml->edit.fontsize; | |
3677 } | |
3678 | |
8061 | 3679 gboolean gtk_imhtml_get_editable(GtkIMHtml *imhtml) |
3680 { | |
3681 return imhtml->editable; | |
3682 } | |
3683 | |
8677 | 3684 /* |
3685 * I had this crazy idea about changing the text cursor color to reflex the foreground color | |
3686 * of the text about to be entered. This is the place you'd do it, along with the place where | |
3687 * we actually set a new foreground color. | |
3688 * I may not do this, because people will bitch about Gaim overriding their gtk theme's cursor | |
3689 * colors. | |
3690 * | |
3691 * Just in case I do do this, I asked about what to set the secondary text cursor to. | |
3692 * | |
8719 | 3693 * (12:45:27) ?? ???: secondary_cursor_color = (rgb(background) + rgb(primary_cursor_color) ) / 2 |
3694 * (12:45:55) ?? ???: understand? | |
8677 | 3695 * (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
|
3696 * (12:46:56) ?? ???: u might need to extract separate each color from RGB |
8677 | 3697 */ |
3698 | |
3699 static void mark_set_cb(GtkTextBuffer *buffer, GtkTextIter *arg1, GtkTextMark *mark, | |
3700 GtkIMHtml *imhtml) | |
3701 { | |
3702 GSList *tags, *l; | |
3703 GtkTextIter iter; | |
3704 | |
3705 if (mark != gtk_text_buffer_get_insert(buffer)) | |
3706 return; | |
3707 | |
3708 if (!gtk_text_buffer_get_char_count(buffer)) | |
3709 return; | |
3710 | |
9924 | 3711 imhtml->edit.bold = imhtml->edit.italic = imhtml->edit.underline = imhtml->edit.strike = FALSE; |
8677 | 3712 if (imhtml->edit.forecolor) |
3713 g_free(imhtml->edit.forecolor); | |
3714 imhtml->edit.forecolor = NULL; | |
3715 if (imhtml->edit.backcolor) | |
3716 g_free(imhtml->edit.backcolor); | |
3717 imhtml->edit.backcolor = NULL; | |
3718 if (imhtml->edit.fontface) | |
3719 g_free(imhtml->edit.fontface); | |
3720 imhtml->edit.fontface = NULL; | |
3721 imhtml->edit.fontsize = 0; | |
3722 imhtml->edit.link = NULL; | |
3723 | |
3724 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, mark); | |
3725 | |
3726 | |
3727 if (gtk_text_iter_is_end(&iter)) | |
3728 tags = gtk_text_iter_get_toggled_tags(&iter, FALSE); | |
3729 else | |
3730 tags = gtk_text_iter_get_tags(&iter); | |
3731 | |
3732 for (l = tags; l != NULL; l = l->next) { | |
3733 GtkTextTag *tag = GTK_TEXT_TAG(l->data); | |
3734 | |
3735 if (tag->name) { | |
3736 if (strcmp(tag->name, "BOLD") == 0) | |
3737 imhtml->edit.bold = TRUE; | |
3738 if (strcmp(tag->name, "ITALICS") == 0) | |
3739 imhtml->edit.italic = TRUE; | |
3740 if (strcmp(tag->name, "UNDERLINE") == 0) | |
3741 imhtml->edit.underline = TRUE; | |
9924 | 3742 if (strcmp(tag->name, "STRIKE") == 0) |
3743 imhtml->edit.strike = TRUE; | |
8677 | 3744 if (strncmp(tag->name, "FORECOLOR ", 10) == 0) |
3745 imhtml->edit.forecolor = g_strdup(&(tag->name)[10]); | |
3746 if (strncmp(tag->name, "BACKCOLOR ", 10) == 0) | |
3747 imhtml->edit.backcolor = g_strdup(&(tag->name)[10]); | |
3748 if (strncmp(tag->name, "FONT FACE ", 10) == 0) | |
3749 imhtml->edit.fontface = g_strdup(&(tag->name)[10]); | |
3750 if (strncmp(tag->name, "FONT SIZE ", 10) == 0) | |
3751 imhtml->edit.fontsize = strtol(&(tag->name)[10], NULL, 10); | |
8719 | 3752 if ((strncmp(tag->name, "LINK ", 5) == 0) && !gtk_text_iter_is_end(&iter)) |
8677 | 3753 imhtml->edit.link = tag; |
3754 } | |
3755 } | |
3756 | |
3757 g_slist_free(tags); | |
3758 } | |
3759 | |
8061 | 3760 gboolean gtk_imhtml_toggle_bold(GtkIMHtml *imhtml) |
3761 { | |
8481 | 3762 GObject *object; |
8677 | 3763 GtkTextIter start, end; |
3764 | |
3765 imhtml->edit.bold = !imhtml->edit.bold; | |
3766 | |
3767 if (imhtml->wbfo) { | |
3768 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
3769 if (imhtml->edit.bold) | |
3770 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end); | |
3771 else | |
3772 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end); | |
3773 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { | |
3774 if (imhtml->edit.bold) | |
3775 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end); | |
3776 else | |
3777 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "BOLD", &start, &end); | |
3778 | |
8061 | 3779 } |
8481 | 3780 object = g_object_ref(G_OBJECT(imhtml)); |
3781 g_object_unref(object); | |
3782 | |
8677 | 3783 return (imhtml->edit.bold != FALSE); |
8061 | 3784 } |
3785 | |
3786 gboolean gtk_imhtml_toggle_italic(GtkIMHtml *imhtml) | |
3787 { | |
8481 | 3788 GObject *object; |
8677 | 3789 GtkTextIter start, end; |
3790 | |
3791 imhtml->edit.italic = !imhtml->edit.italic; | |
3792 | |
3793 if (imhtml->wbfo) { | |
3794 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
3795 if (imhtml->edit.italic) | |
3796 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end); | |
3797 else | |
3798 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end); | |
3799 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { | |
3800 if (imhtml->edit.italic) | |
3801 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end); | |
3802 else | |
3803 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "ITALICS", &start, &end); | |
8061 | 3804 } |
8481 | 3805 object = g_object_ref(G_OBJECT(imhtml)); |
3806 g_object_unref(object); | |
3807 | |
8677 | 3808 return imhtml->edit.italic != FALSE; |
8061 | 3809 } |
3810 | |
3811 gboolean gtk_imhtml_toggle_underline(GtkIMHtml *imhtml) | |
3812 { | |
8481 | 3813 GObject *object; |
8677 | 3814 GtkTextIter start, end; |
3815 | |
3816 imhtml->edit.underline = !imhtml->edit.underline; | |
3817 | |
3818 if (imhtml->wbfo) { | |
3819 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
3820 if (imhtml->edit.underline) | |
3821 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end); | |
3822 else | |
3823 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end); | |
3824 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { | |
3825 if (imhtml->edit.underline) | |
3826 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end); | |
3827 else | |
3828 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "UNDERLINE", &start, &end); | |
8061 | 3829 } |
8481 | 3830 object = g_object_ref(G_OBJECT(imhtml)); |
3831 g_object_unref(object); | |
3832 | |
8677 | 3833 return imhtml->edit.underline != FALSE; |
8061 | 3834 } |
3835 | |
9924 | 3836 gboolean gtk_imhtml_toggle_strike(GtkIMHtml *imhtml) |
3837 { | |
3838 GObject *object; | |
3839 GtkTextIter start, end; | |
3840 | |
3841 imhtml->edit.strike = !imhtml->edit.strike; | |
3842 | |
3843 if (imhtml->wbfo) { | |
3844 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
3845 if (imhtml->edit.strike) | |
3846 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end); | |
3847 else | |
3848 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end); | |
3849 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { | |
3850 if (imhtml->edit.strike) | |
3851 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end); | |
3852 else | |
3853 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "STRIKE", &start, &end); | |
3854 } | |
3855 object = g_object_ref(G_OBJECT(imhtml)); | |
3856 g_object_unref(object); | |
3857 | |
3858 return imhtml->edit.strike != FALSE; | |
3859 } | |
3860 | |
8061 | 3861 void gtk_imhtml_font_set_size(GtkIMHtml *imhtml, gint size) |
3862 { | |
9025 | 3863 GObject *object; |
8677 | 3864 GtkTextIter start, end; |
9025 | 3865 GtkIMHtmlButtons b = 0; |
8061 | 3866 |
3867 imhtml->edit.fontsize = size; | |
3868 | |
8677 | 3869 |
3870 if (imhtml->wbfo) { | |
3871 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
3872 remove_font_size(imhtml, &start, &end, TRUE); | |
3873 gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
3874 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); | |
3875 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { | |
3876 remove_font_size(imhtml, &start, &end, FALSE); | |
3877 gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
3878 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); | |
8061 | 3879 } |
8677 | 3880 |
9025 | 3881 object = g_object_ref(G_OBJECT(imhtml)); |
3882 b |= GTK_IMHTML_SHRINK; | |
3883 b |= GTK_IMHTML_GROW; | |
3884 g_object_unref(object); | |
8061 | 3885 } |
3886 | |
3887 void gtk_imhtml_font_shrink(GtkIMHtml *imhtml) | |
3888 { | |
9025 | 3889 GObject *object; |
8677 | 3890 GtkTextIter start, end; |
3891 | |
8061 | 3892 if (imhtml->edit.fontsize == 1) |
3893 return; | |
3894 | |
8677 | 3895 if (!imhtml->edit.fontsize) |
3896 imhtml->edit.fontsize = 2; | |
3897 else | |
3898 imhtml->edit.fontsize--; | |
3899 | |
3900 if (imhtml->wbfo) { | |
3901 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
3902 remove_font_size(imhtml, &start, &end, TRUE); | |
3903 gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
3904 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); | |
3905 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { | |
3906 remove_font_size(imhtml, &start, &end, FALSE); | |
3907 gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
3908 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); | |
8061 | 3909 } |
9025 | 3910 object = g_object_ref(G_OBJECT(imhtml)); |
3911 g_object_unref(object); | |
8061 | 3912 } |
3913 | |
3914 void gtk_imhtml_font_grow(GtkIMHtml *imhtml) | |
3915 { | |
9025 | 3916 GObject *object; |
8677 | 3917 GtkTextIter start, end; |
3918 | |
8061 | 3919 if (imhtml->edit.fontsize == MAX_FONT_SIZE) |
3920 return; | |
3921 | |
8677 | 3922 if (!imhtml->edit.fontsize) |
3923 imhtml->edit.fontsize = 4; | |
3924 else | |
3925 imhtml->edit.fontsize++; | |
3926 | |
3927 if (imhtml->wbfo) { | |
3928 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); | |
3929 remove_font_size(imhtml, &start, &end, TRUE); | |
3930 gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
3931 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); | |
3932 } else if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { | |
3933 remove_font_size(imhtml, &start, &end, FALSE); | |
3934 gtk_text_buffer_apply_tag(imhtml->text_buffer, | |
3935 find_font_size_tag(imhtml, imhtml->edit.fontsize), &start, &end); | |
8061 | 3936 } |
9025 | 3937 object = g_object_ref(G_OBJECT(imhtml)); |
3938 g_object_unref(object); | |
8061 | 3939 } |
3940 | |
10776 | 3941 #define gtk_imhtml_toggle_str_tag(imhtml, color, edit_field, remove_func, find_func) { \ |
3942 GObject *object; \ | |
3943 GtkTextIter start, end; \ | |
3944 \ | |
3945 g_free(edit_field); \ | |
3946 edit_field = NULL; \ | |
3947 \ | |
3948 if (color && strcmp(color, "") != 0) { \ | |
3949 edit_field = g_strdup(color); \ | |
3950 \ | |
3951 if (imhtml->wbfo) { \ | |
3952 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); \ | |
3953 remove_func(imhtml, &start, &end, TRUE); \ | |
3954 gtk_text_buffer_apply_tag(imhtml->text_buffer, \ | |
3955 find_func(imhtml, edit_field), &start, &end); \ | |
3956 } else { \ | |
3957 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &start, \ | |
3958 gtk_text_buffer_get_mark(imhtml->text_buffer, "insert")); \ | |
3959 if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { \ | |
3960 remove_func(imhtml, &start, &end, FALSE); \ | |
3961 gtk_text_buffer_apply_tag(imhtml->text_buffer, \ | |
3962 find_func(imhtml, \ | |
3963 edit_field), \ | |
3964 &start, &end); \ | |
3965 } \ | |
3966 } \ | |
3967 } else { \ | |
3968 if (imhtml->wbfo) { \ | |
3969 gtk_text_buffer_get_bounds(imhtml->text_buffer, &start, &end); \ | |
3970 remove_func(imhtml, &start, &end, TRUE); \ | |
3971 } \ | |
3972 } \ | |
3973 \ | |
3974 object = g_object_ref(G_OBJECT(imhtml)); \ | |
3975 g_object_unref(object); \ | |
3976 \ | |
3977 return edit_field != NULL; \ | |
3978 } | |
3979 | |
8061 | 3980 gboolean gtk_imhtml_toggle_forecolor(GtkIMHtml *imhtml, const char *color) |
3981 { | |
10776 | 3982 gtk_imhtml_toggle_str_tag(imhtml, color, imhtml->edit.forecolor, remove_font_forecolor, find_font_forecolor_tag); |
8061 | 3983 } |
3984 | |
3985 gboolean gtk_imhtml_toggle_backcolor(GtkIMHtml *imhtml, const char *color) | |
3986 { | |
10776 | 3987 gtk_imhtml_toggle_str_tag(imhtml, color, imhtml->edit.backcolor, remove_font_backcolor, find_font_backcolor_tag); |
3988 } | |
3989 | |
3990 gboolean gtk_imhtml_toggle_background(GtkIMHtml *imhtml, const char *color) | |
3991 { | |
3992 gtk_imhtml_toggle_str_tag(imhtml, color, imhtml->edit.background, remove_font_background, find_font_background_tag); | |
8061 | 3993 } |
3994 | |
3995 gboolean gtk_imhtml_toggle_fontface(GtkIMHtml *imhtml, const char *face) | |
3996 { | |
10776 | 3997 gtk_imhtml_toggle_str_tag(imhtml, face, imhtml->edit.fontface, remove_font_face, find_font_face_tag); |
8061 | 3998 } |
3999 | |
8677 | 4000 void gtk_imhtml_toggle_link(GtkIMHtml *imhtml, const char *url) |
8061 | 4001 { |
9025 | 4002 GObject *object; |
8677 | 4003 GtkTextIter start, end; |
4004 GtkTextTag *linktag; | |
4005 static guint linkno = 0; | |
4006 gchar str[48]; | |
9007 | 4007 GdkColor *color = NULL; |
8677 | 4008 |
4009 imhtml->edit.link = NULL; | |
4010 | |
4011 | |
4012 | |
4013 if (url) { | |
4014 g_snprintf(str, sizeof(str), "LINK %d", linkno++); | |
4015 str[47] = '\0'; | |
4016 | |
9007 | 4017 gtk_widget_style_get(GTK_WIDGET(imhtml), "hyperlink-color", &color, NULL); |
9008 | 4018 if (color) { |
9007 | 4019 imhtml->edit.link = linktag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "foreground-gdk", color, "underline", PANGO_UNDERLINE_SINGLE, NULL); |
9008 | 4020 gdk_color_free(color); |
4021 } else { | |
9007 | 4022 imhtml->edit.link = linktag = gtk_text_buffer_create_tag(imhtml->text_buffer, str, "foreground", "blue", "underline", PANGO_UNDERLINE_SINGLE, NULL); |
9008 | 4023 } |
8677 | 4024 g_object_set_data_full(G_OBJECT(linktag), "link_url", g_strdup(url), g_free); |
4025 g_signal_connect(G_OBJECT(linktag), "event", G_CALLBACK(tag_event), NULL); | |
4026 | |
4027 if (imhtml->editable && gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) { | |
4028 remove_font_link(imhtml, &start, &end, FALSE); | |
4029 gtk_text_buffer_apply_tag(imhtml->text_buffer, linktag, &start, &end); | |
4030 } | |
4031 } | |
9025 | 4032 |
4033 object = g_object_ref(G_OBJECT(imhtml)); | |
4034 g_signal_emit(object, signals[TOGGLE_FORMAT], 0, GTK_IMHTML_LINK); | |
4035 g_object_unref(object); | |
8677 | 4036 } |
4037 | |
4038 void gtk_imhtml_insert_link(GtkIMHtml *imhtml, GtkTextMark *mark, const char *url, const char *text) | |
4039 { | |
8061 | 4040 GtkTextIter iter; |
8677 | 4041 |
9599 | 4042 if (gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, NULL, NULL)) |
4043 gtk_text_buffer_delete_selection(imhtml->text_buffer, TRUE, TRUE); | |
4044 | |
8677 | 4045 gtk_imhtml_toggle_link(imhtml, url); |
8061 | 4046 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, mark); |
8677 | 4047 gtk_text_buffer_insert(imhtml->text_buffer, &iter, text, -1); |
4048 gtk_imhtml_toggle_link(imhtml, NULL); | |
8061 | 4049 } |
4050 | |
4051 void gtk_imhtml_insert_smiley(GtkIMHtml *imhtml, const char *sml, char *smiley) | |
4052 { | |
8677 | 4053 GtkTextMark *mark; |
8061 | 4054 GtkTextIter iter; |
8677 | 4055 |
4056 mark = gtk_text_buffer_get_insert(imhtml->text_buffer); | |
4057 | |
4058 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, mark); | |
4059 gtk_imhtml_insert_smiley_at_iter(imhtml, sml, smiley, &iter); | |
4060 } | |
4061 | |
4062 void gtk_imhtml_insert_smiley_at_iter(GtkIMHtml *imhtml, const char *sml, char *smiley, GtkTextIter *iter) | |
4063 { | |
8061 | 4064 GdkPixbuf *pixbuf = NULL; |
4065 GdkPixbufAnimation *annipixbuf = NULL; | |
4066 GtkWidget *icon = NULL; | |
4067 GtkTextChildAnchor *anchor; | |
8505 | 4068 char *unescaped = gaim_unescape_html(smiley); |
8061 | 4069 |
10526 | 4070 if (imhtml->format_functions & GTK_IMHTML_SMILEY) { |
10522 | 4071 annipixbuf = gtk_smiley_tree_image(imhtml, sml, unescaped); |
10526 | 4072 if (annipixbuf) { |
4073 if (gdk_pixbuf_animation_is_static_image(annipixbuf)) { | |
10522 | 4074 pixbuf = gdk_pixbuf_animation_get_static_image(annipixbuf); |
10526 | 4075 if (pixbuf) |
10522 | 4076 icon = gtk_image_new_from_pixbuf(pixbuf); |
4077 } else { | |
4078 icon = gtk_image_new_from_animation(annipixbuf); | |
4079 } | |
8061 | 4080 } |
4081 } | |
10526 | 4082 #if 0 |
4083 else { | |
4084 GtkIMHtmlSmiley *imhtml_smiley; | |
4085 | |
4086 if (imhtml_smiley->loader) { ; } | |
4087 icon = gtk_image_new_from_stock(GTK_STOCK_MISSING_IMAGE, GTK_ICON_SIZE_MENU); | |
4088 imhtml_smiley = gtk_get_imhtml_smiley(imhtml, sml, unescaped); | |
4089 if (!imhtml_smiley) { | |
4090 gaim_debug_info("gtkimhtml", "geezz couldnt find smiley struct\n"); | |
4091 } | |
4092 imhtml_smiley->orphan = g_slist_append(imhtml_smiley->orphan, icon); | |
4093 } | |
4094 #endif | |
8061 | 4095 |
4096 if (icon) { | |
8890 | 4097 anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, iter); |
4098 g_object_set_data_full(G_OBJECT(anchor), "gtkimhtml_plaintext", g_strdup(unescaped), g_free); | |
4099 g_object_set_data_full(G_OBJECT(anchor), "gtkimhtml_htmltext", g_strdup(smiley), g_free); | |
4100 | |
8061 | 4101 gtk_widget_show(icon); |
4102 gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(imhtml), icon, anchor); | |
8890 | 4103 } else { |
4104 gtk_text_buffer_insert(imhtml->text_buffer, iter, smiley, -1); | |
8061 | 4105 } |
8890 | 4106 |
4107 g_free(unescaped); | |
8061 | 4108 } |
4109 | |
8962 | 4110 void gtk_imhtml_insert_image_at_iter(GtkIMHtml *imhtml, int id, GtkTextIter *iter) |
4111 { | |
4112 GdkPixbuf *pixbuf = NULL; | |
4113 const char *filename = NULL; | |
4114 gpointer image; | |
4115 GdkRectangle rect; | |
4116 GtkIMHtmlScalable *scalable = NULL; | |
4117 int minus; | |
4118 | |
4119 if (!imhtml->funcs || !imhtml->funcs->image_get || | |
4120 !imhtml->funcs->image_get_size || !imhtml->funcs->image_get_data || | |
4121 !imhtml->funcs->image_get_filename || !imhtml->funcs->image_ref || | |
4122 !imhtml->funcs->image_unref) | |
4123 return; | |
4124 | |
4125 image = imhtml->funcs->image_get(id); | |
4126 | |
4127 if (image) { | |
4128 gpointer data; | |
4129 size_t len; | |
4130 | |
4131 data = imhtml->funcs->image_get_data(image); | |
4132 len = imhtml->funcs->image_get_size(image); | |
4133 | |
4134 if (data && len) { | |
4135 GdkPixbufLoader *loader = gdk_pixbuf_loader_new(); | |
4136 gdk_pixbuf_loader_write(loader, data, len, NULL); | |
4137 pixbuf = gdk_pixbuf_loader_get_pixbuf(loader); | |
9337 | 4138 if (pixbuf) |
4139 g_object_ref(G_OBJECT(pixbuf)); | |
8962 | 4140 gdk_pixbuf_loader_close(loader, NULL); |
9337 | 4141 g_object_unref(G_OBJECT(loader)); |
8962 | 4142 } |
4143 | |
4144 } | |
4145 | |
4146 if (pixbuf) { | |
4147 filename = imhtml->funcs->image_get_filename(image); | |
4148 imhtml->funcs->image_ref(id); | |
4149 imhtml->im_images = g_slist_prepend(imhtml->im_images, GINT_TO_POINTER(id)); | |
4150 } else { | |
4151 pixbuf = gtk_widget_render_icon(GTK_WIDGET(imhtml), GTK_STOCK_MISSING_IMAGE, | |
4152 GTK_ICON_SIZE_BUTTON, "gtkimhtml-missing-image"); | |
4153 } | |
4154 | |
4155 scalable = gtk_imhtml_image_new(pixbuf, filename, id); | |
4156 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); | |
4157 scalable->add_to(scalable, imhtml, iter); | |
4158 minus = gtk_text_view_get_left_margin(GTK_TEXT_VIEW(imhtml)) + | |
4159 gtk_text_view_get_right_margin(GTK_TEXT_VIEW(imhtml)); | |
4160 scalable->scale(scalable, rect.width - minus, rect.height); | |
4161 imhtml->scalables = g_list_append(imhtml->scalables, scalable); | |
4162 | |
4163 g_object_unref(G_OBJECT(pixbuf)); | |
4164 } | |
4165 | |
8677 | 4166 static const gchar *tag_to_html_start(GtkTextTag *tag) |
8061 | 4167 { |
8677 | 4168 const gchar *name; |
4169 static gchar buf[1024]; | |
4170 | |
4171 name = tag->name; | |
4172 g_return_val_if_fail(name != NULL, ""); | |
4173 | |
4174 if (strcmp(name, "BOLD") == 0) { | |
4175 return "<b>"; | |
4176 } else if (strcmp(name, "ITALICS") == 0) { | |
4177 return "<i>"; | |
4178 } else if (strcmp(name, "UNDERLINE") == 0) { | |
4179 return "<u>"; | |
9924 | 4180 } else if (strcmp(name, "STRIKE") == 0) { |
4181 return "<s>"; | |
8677 | 4182 } else if (strncmp(name, "LINK ", 5) == 0) { |
4183 char *tmp = g_object_get_data(G_OBJECT(tag), "link_url"); | |
4184 if (tmp) { | |
4185 g_snprintf(buf, sizeof(buf), "<a href=\"%s\">", tmp); | |
4186 buf[sizeof(buf)-1] = '\0'; | |
4187 return buf; | |
4188 } else { | |
4189 return ""; | |
4190 } | |
4191 } else if (strncmp(name, "FORECOLOR ", 10) == 0) { | |
4192 g_snprintf(buf, sizeof(buf), "<font color=\"%s\">", &name[10]); | |
4193 return buf; | |
4194 } else if (strncmp(name, "BACKCOLOR ", 10) == 0) { | |
4195 g_snprintf(buf, sizeof(buf), "<font back=\"%s\">", &name[10]); | |
4196 return buf; | |
10776 | 4197 } else if (strncmp(name, "BACKGROUND ", 10) == 0) { |
4198 g_snprintf(buf, sizeof(buf), "<body bgcolor=\"%s\">", &name[11]); | |
4199 return buf; | |
8677 | 4200 } else if (strncmp(name, "FONT FACE ", 10) == 0) { |
4201 g_snprintf(buf, sizeof(buf), "<font face=\"%s\">", &name[10]); | |
4202 return buf; | |
4203 } else if (strncmp(name, "FONT SIZE ", 10) == 0) { | |
4204 g_snprintf(buf, sizeof(buf), "<font size=\"%s\">", &name[10]); | |
4205 return buf; | |
4206 } else { | |
4207 return ""; | |
4208 } | |
8061 | 4209 } |
4210 | |
8677 | 4211 static const gchar *tag_to_html_end(GtkTextTag *tag) |
8061 | 4212 { |
8677 | 4213 const gchar *name; |
4214 | |
4215 name = tag->name; | |
4216 g_return_val_if_fail(name != NULL, ""); | |
4217 | |
4218 if (strcmp(name, "BOLD") == 0) { | |
4219 return "</b>"; | |
4220 } else if (strcmp(name, "ITALICS") == 0) { | |
4221 return "</i>"; | |
4222 } else if (strcmp(name, "UNDERLINE") == 0) { | |
4223 return "</u>"; | |
9924 | 4224 } else if (strcmp(name, "STRIKE") == 0) { |
4225 return "</s>"; | |
8677 | 4226 } else if (strncmp(name, "LINK ", 5) == 0) { |
4227 return "</a>"; | |
4228 } else if (strncmp(name, "FORECOLOR ", 10) == 0) { | |
4229 return "</font>"; | |
4230 } else if (strncmp(name, "BACKCOLOR ", 10) == 0) { | |
4231 return "</font>"; | |
10776 | 4232 } else if (strncmp(name, "BACKGROUND ", 10) == 0) { |
4233 return "</body>"; | |
8677 | 4234 } else if (strncmp(name, "FONT FACE ", 10) == 0) { |
4235 return "</font>"; | |
4236 } else if (strncmp(name, "FONT SIZE ", 10) == 0) { | |
4237 return "</font>"; | |
4238 } else { | |
4239 return ""; | |
4240 } | |
4241 } | |
4242 | |
4243 static gboolean tag_ends_here(GtkTextTag *tag, GtkTextIter *iter, GtkTextIter *niter) | |
4244 { | |
4245 return ((gtk_text_iter_has_tag(iter, GTK_TEXT_TAG(tag)) && | |
4246 !gtk_text_iter_has_tag(niter, GTK_TEXT_TAG(tag))) || | |
4247 gtk_text_iter_is_end(niter)); | |
8061 | 4248 } |
4249 | |
4250 /* Basic notion here: traverse through the text buffer one-by-one, non-character elements, such | |
4251 * as smileys and IM images are represented by the Unicode "unknown" character. Handle them. Else | |
8677 | 4252 * check for tags that are toggled on, insert their html form, and push them on the queue. Then insert |
4253 * 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
|
4254 * Finally, replace <, >, &, and " with their HTML equivalent. |
8677 | 4255 */ |
8061 | 4256 char *gtk_imhtml_get_markup_range(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *end) |
4257 { | |
4258 gunichar c; | |
8677 | 4259 GtkTextIter iter, nextiter; |
8061 | 4260 GString *str = g_string_new(""); |
8677 | 4261 GSList *tags, *sl; |
4262 GQueue *q, *r; | |
4263 GtkTextTag *tag; | |
4264 | |
4265 q = g_queue_new(); | |
4266 r = g_queue_new(); | |
4267 | |
8061 | 4268 |
4269 gtk_text_iter_order(start, end); | |
8677 | 4270 nextiter = iter = *start; |
4271 gtk_text_iter_forward_char(&nextiter); | |
4272 | |
9071 | 4273 /* First add the tags that are already in progress (we don't care about non-printing tags)*/ |
8677 | 4274 tags = gtk_text_iter_get_tags(start); |
4275 | |
4276 for (sl = tags; sl; sl = sl->next) { | |
4277 tag = sl->data; | |
4278 if (!gtk_text_iter_toggles_tag(start, GTK_TEXT_TAG(tag))) { | |
9071 | 4279 if (strlen(tag_to_html_end(tag)) > 0) |
4280 g_string_append(str, tag_to_html_start(tag)); | |
8677 | 4281 g_queue_push_tail(q, tag); |
8061 | 4282 } |
4283 } | |
8677 | 4284 g_slist_free(tags); |
8061 | 4285 |
4286 while ((c = gtk_text_iter_get_char(&iter)) != 0 && !gtk_text_iter_equal(&iter, end)) { | |
8677 | 4287 |
4288 tags = gtk_text_iter_get_tags(&iter); | |
4289 | |
4290 for (sl = tags; sl; sl = sl->next) { | |
4291 tag = sl->data; | |
4292 if (gtk_text_iter_begins_tag(&iter, GTK_TEXT_TAG(tag))) { | |
9071 | 4293 if (strlen(tag_to_html_end(tag)) > 0) |
4294 g_string_append(str, tag_to_html_start(tag)); | |
8677 | 4295 g_queue_push_tail(q, tag); |
4296 } | |
4297 } | |
4298 | |
4299 | |
8061 | 4300 if (c == 0xFFFC) { |
4301 GtkTextChildAnchor* anchor = gtk_text_iter_get_child_anchor(&iter); | |
9071 | 4302 if (anchor) { |
4303 char *text = g_object_get_data(G_OBJECT(anchor), "gtkimhtml_htmltext"); | |
4304 if (text) | |
4305 str = g_string_append(str, text); | |
4306 } | |
8677 | 4307 } else if (c == '<') { |
4308 str = g_string_append(str, "<"); | |
4309 } else if (c == '>') { | |
4310 str = g_string_append(str, ">"); | |
4311 } else if (c == '&') { | |
4312 str = g_string_append(str, "&"); | |
4313 } else if (c == '"') { | |
4314 str = g_string_append(str, """); | |
4315 } else if (c == '\n') { | |
4316 str = g_string_append(str, "<br>"); | |
8061 | 4317 } else { |
8677 | 4318 str = g_string_append_unichar(str, c); |
4319 } | |
4320 | |
4321 tags = g_slist_reverse(tags); | |
4322 for (sl = tags; sl; sl = sl->next) { | |
4323 tag = sl->data; | |
9071 | 4324 /** don't worry about non-printing tags ending */ |
4325 if (tag_ends_here(tag, &iter, &nextiter) && strlen(tag_to_html_end(tag)) > 0) { | |
8677 | 4326 |
4327 GtkTextTag *tmp; | |
4328 | |
4329 while ((tmp = g_queue_pop_tail(q)) != tag) { | |
4330 if (tmp == NULL) | |
4331 break; | |
4332 | |
9071 | 4333 if (!tag_ends_here(tmp, &iter, &nextiter) && strlen(tag_to_html_end(tmp)) > 0) |
8677 | 4334 g_queue_push_tail(r, tmp); |
4335 g_string_append(str, tag_to_html_end(GTK_TEXT_TAG(tmp))); | |
4336 } | |
4337 | |
4338 if (tmp == NULL) | |
4339 gaim_debug_warning("gtkimhtml", "empty queue, more closing tags than open tags!\n"); | |
4340 else | |
4341 g_string_append(str, tag_to_html_end(GTK_TEXT_TAG(tag))); | |
4342 | |
4343 while ((tmp = g_queue_pop_head(r))) { | |
4344 g_string_append(str, tag_to_html_start(GTK_TEXT_TAG(tmp))); | |
4345 g_queue_push_tail(q, tmp); | |
8061 | 4346 } |
4347 } | |
4348 } | |
8677 | 4349 |
4350 g_slist_free(tags); | |
8061 | 4351 gtk_text_iter_forward_char(&iter); |
8677 | 4352 gtk_text_iter_forward_char(&nextiter); |
8061 | 4353 } |
8677 | 4354 |
4355 while ((tag = g_queue_pop_tail(q))) | |
4356 g_string_append(str, tag_to_html_end(GTK_TEXT_TAG(tag))); | |
4357 | |
4358 g_queue_free(q); | |
4359 g_queue_free(r); | |
8061 | 4360 return g_string_free(str, FALSE); |
4361 } | |
4362 | |
8698 | 4363 void gtk_imhtml_close_tags(GtkIMHtml *imhtml, GtkTextIter *iter) |
8061 | 4364 { |
4365 if (imhtml->edit.bold) | |
4366 gtk_imhtml_toggle_bold(imhtml); | |
4367 | |
4368 if (imhtml->edit.italic) | |
4369 gtk_imhtml_toggle_italic(imhtml); | |
4370 | |
4371 if (imhtml->edit.underline) | |
4372 gtk_imhtml_toggle_underline(imhtml); | |
4373 | |
9924 | 4374 if (imhtml->edit.strike) |
4375 gtk_imhtml_toggle_strike(imhtml); | |
4376 | |
8061 | 4377 if (imhtml->edit.forecolor) |
4378 gtk_imhtml_toggle_forecolor(imhtml, NULL); | |
4379 | |
4380 if (imhtml->edit.backcolor) | |
4381 gtk_imhtml_toggle_backcolor(imhtml, NULL); | |
4382 | |
4383 if (imhtml->edit.fontface) | |
4384 gtk_imhtml_toggle_fontface(imhtml, NULL); | |
4385 | |
8677 | 4386 imhtml->edit.fontsize = 0; |
4387 | |
8719 | 4388 if (imhtml->edit.link) |
4389 gtk_imhtml_toggle_link(imhtml, NULL); | |
4390 | |
8698 | 4391 gtk_text_buffer_remove_all_tags(imhtml->text_buffer, iter, iter); |
8061 | 4392 |
4393 } | |
4394 | |
4395 char *gtk_imhtml_get_markup(GtkIMHtml *imhtml) | |
4396 { | |
4397 GtkTextIter start, end; | |
4398 | |
4399 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start); | |
4400 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end); | |
4401 return gtk_imhtml_get_markup_range(imhtml, &start, &end); | |
4402 } | |
4403 | |
8677 | 4404 char **gtk_imhtml_get_markup_lines(GtkIMHtml *imhtml) |
4405 { | |
4406 int i, j, lines; | |
4407 GtkTextIter start, end; | |
4408 char **ret; | |
4409 | |
4410 lines = gtk_text_buffer_get_line_count(imhtml->text_buffer); | |
4411 ret = g_new0(char *, lines + 1); | |
4412 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start); | |
4413 end = start; | |
4414 gtk_text_iter_forward_to_line_end(&end); | |
4415 | |
4416 for (i = 0, j = 0; i < lines; i++) { | |
9612 | 4417 if (gtk_text_iter_get_char(&start) != '\n') { |
4418 ret[j] = gtk_imhtml_get_markup_range(imhtml, &start, &end); | |
4419 if (ret[j] != NULL) | |
4420 j++; | |
4421 } | |
4422 | |
8677 | 4423 gtk_text_iter_forward_line(&start); |
4424 end = start; | |
4425 gtk_text_iter_forward_to_line_end(&end); | |
4426 } | |
4427 | |
4428 return ret; | |
4429 } | |
4430 | |
4431 char *gtk_imhtml_get_text(GtkIMHtml *imhtml, GtkTextIter *start, GtkTextIter *stop) | |
8061 | 4432 { |
8519 | 4433 GString *str = g_string_new(""); |
4434 GtkTextIter iter, end; | |
4435 gunichar c; | |
4436 | |
8677 | 4437 if (start == NULL) |
4438 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &iter); | |
4439 else | |
4440 iter = *start; | |
4441 | |
4442 if (stop == NULL) | |
4443 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end); | |
4444 else | |
4445 end = *stop; | |
4446 | |
4447 gtk_text_iter_order(&iter, &end); | |
8519 | 4448 |
4449 while ((c = gtk_text_iter_get_char(&iter)) != 0 && !gtk_text_iter_equal(&iter, &end)) { | |
4450 if (c == 0xFFFC) { | |
8677 | 4451 GtkTextChildAnchor* anchor; |
4452 char *text = NULL; | |
4453 | |
4454 anchor = gtk_text_iter_get_child_anchor(&iter); | |
4455 if (anchor) | |
8698 | 4456 text = g_object_get_data(G_OBJECT(anchor), "gtkimhtml_plaintext"); |
8677 | 4457 if (text) |
4458 str = g_string_append(str, text); | |
8519 | 4459 } else { |
4460 g_string_append_unichar(str, c); | |
4461 } | |
4462 gtk_text_iter_forward_char(&iter); | |
4463 } | |
4464 | |
4465 return g_string_free(str, FALSE); | |
8061 | 4466 } |
8962 | 4467 |
4468 void gtk_imhtml_set_funcs(GtkIMHtml *imhtml, GtkIMHtmlFuncs *f) | |
4469 { | |
4470 g_return_if_fail(imhtml != NULL); | |
4471 imhtml->funcs = f; | |
4472 } |