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