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