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