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