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