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