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