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