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