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