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