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