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