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