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