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