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