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