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