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