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