annotate src/gtkimhtml.c @ 7416:daa81bdefef5

[gaim-migrate @ 8018] call me crazy, but I think this might be noteworthy committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Mon, 03 Nov 2003 04:37:41 +0000
parents d889a99e0eb1
children 6a9acef3b867
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1 /*
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2 * GtkIMHtml
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3 *
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4 * Copyright (C) 2000, Eric Warmenhoven <warmenhoven@yahoo.com>
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
5 *
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
7 * under the terms of the GNU General Public License as published by
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
9 * (at your option) any later version.
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
10 *
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful,
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
14 * GNU General Public License for more details.
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
15 *
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
19 *
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
20 */
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
21
2541
8229710b343b [gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2365
diff changeset
22 #ifdef HAVE_CONFIG_H
8229710b343b [gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2365
diff changeset
23 #include <config.h>
8229710b343b [gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2365
diff changeset
24 #endif
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
25 #include "gtkimhtml.h"
7358
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents: 7354
diff changeset
26 #include "gtksourceiter.h"
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
27 #include <gtk/gtk.h>
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
28 #include <glib/gerror.h>
4046
4a3f863b041f [gaim-migrate @ 4254]
Sean Egan <seanegan@gmail.com>
parents: 4041
diff changeset
29 #include <gdk/gdkkeysyms.h>
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
30 #include <string.h>
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
31 #include <ctype.h>
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
32 #include <stdio.h>
4629
86fd0f6eaa1a [gaim-migrate @ 4920]
Mark Doliner <mark@kingant.net>
parents: 4612
diff changeset
33 #include <stdlib.h>
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
34 #include <math.h>
2541
8229710b343b [gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2365
diff changeset
35 #ifdef HAVE_LANGINFO_CODESET
8229710b343b [gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2365
diff changeset
36 #include <langinfo.h>
8229710b343b [gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2365
diff changeset
37 #include <locale.h>
8229710b343b [gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2365
diff changeset
38 #endif
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
39
4417
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
40 #ifdef ENABLE_NLS
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
41 # include <libintl.h>
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
42 # define _(x) gettext(x)
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
43 # ifdef gettext_noop
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
44 # define N_(String) gettext_noop (String)
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
45 # else
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
46 # define N_(String) (String)
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
47 # endif
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
48 #else
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
49 # define N_(String) (String)
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
50 # define _(x) (x)
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
51 #endif
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
52
4735
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
53 #include <pango/pango-font.h>
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
54
5105
4cfc49e31c2e [gaim-migrate @ 5468]
Luke Schierer <lschiere@pidgin.im>
parents: 5104
diff changeset
55 /* GTK+ < 2.2.2 hack, see ui.h for details. */
4cfc49e31c2e [gaim-migrate @ 5468]
Luke Schierer <lschiere@pidgin.im>
parents: 5104
diff changeset
56 #ifndef GTK_WRAP_WORD_CHAR
4cfc49e31c2e [gaim-migrate @ 5468]
Luke Schierer <lschiere@pidgin.im>
parents: 5104
diff changeset
57 #define GTK_WRAP_WORD_CHAR GTK_WRAP_WORD
4cfc49e31c2e [gaim-migrate @ 5468]
Luke Schierer <lschiere@pidgin.im>
parents: 5104
diff changeset
58 #endif
4cfc49e31c2e [gaim-migrate @ 5468]
Luke Schierer <lschiere@pidgin.im>
parents: 5104
diff changeset
59
4735
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
60 #define TOOLTIP_TIMEOUT 500
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
61
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
62 /* POINT_SIZE converts from AIM font sizes to point sizes. It probably should be redone in such a
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
63 * way that it base the sizes off the default font size rather than using arbitrary font sizes. */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
64 #define MAX_FONT_SIZE 7
5367
fc0441fbf159 [gaim-migrate @ 5743]
Luke Schierer <lschiere@pidgin.im>
parents: 5293
diff changeset
65 #define POINT_SIZE(x) (options & GTK_IMHTML_USE_POINTSIZE ? x : _point_sizes [MIN ((x), MAX_FONT_SIZE) - 1])
3928
fb60cd7a2506 [gaim-migrate @ 4100]
Sean Egan <seanegan@gmail.com>
parents: 3922
diff changeset
66 static gint _point_sizes [] = { 8, 10, 12, 14, 20, 30, 40 };
2349
60c716c32c40 [gaim-migrate @ 2362]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2348
diff changeset
67
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
68 static GtkSmileyTree*
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
69 gtk_smiley_tree_new ()
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
70 {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
71 return g_new0 (GtkSmileyTree, 1);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
72 }
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
73
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
74 static void
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
75 gtk_smiley_tree_insert (GtkSmileyTree *tree,
4263
74f65a3d2a1f [gaim-migrate @ 4514]
Sean Egan <seanegan@gmail.com>
parents: 4253
diff changeset
76 GtkIMHtmlSmiley *smiley)
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
77 {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
78 GtkSmileyTree *t = tree;
4263
74f65a3d2a1f [gaim-migrate @ 4514]
Sean Egan <seanegan@gmail.com>
parents: 4253
diff changeset
79 const gchar *x = smiley->smile;
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
80
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
81 if (!strlen (x))
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
82 return;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
83
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
84 while (*x) {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
85 gchar *pos;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
86 gint index;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
87
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
88 if (!t->values)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
89 t->values = g_string_new ("");
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
90
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
91 pos = strchr (t->values->str, *x);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
92 if (!pos) {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
93 t->values = g_string_append_c (t->values, *x);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
94 index = t->values->len - 1;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
95 t->children = g_realloc (t->children, t->values->len * sizeof (GtkSmileyTree *));
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
96 t->children [index] = g_new0 (GtkSmileyTree, 1);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
97 } else
7386
414c701ef1ff [gaim-migrate @ 7981]
Luke Schierer <lschiere@pidgin.im>
parents: 7384
diff changeset
98 index = GPOINTER_TO_INT(pos) - GPOINTER_TO_INT(t->values->str);
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
99
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
100 t = t->children [index];
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
101
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
102 x++;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
103 }
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
104
4263
74f65a3d2a1f [gaim-migrate @ 4514]
Sean Egan <seanegan@gmail.com>
parents: 4253
diff changeset
105 t->image = smiley;
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
106 }
4041
3a36ec242415 [gaim-migrate @ 4249]
Sean Egan <seanegan@gmail.com>
parents: 4032
diff changeset
107
4263
74f65a3d2a1f [gaim-migrate @ 4514]
Sean Egan <seanegan@gmail.com>
parents: 4253
diff changeset
108
4264
f1876640e568 [gaim-migrate @ 4515]
Sean Egan <seanegan@gmail.com>
parents: 4263
diff changeset
109 void gtk_smiley_tree_destroy (GtkSmileyTree *tree)
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
110 {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
111 GSList *list = g_slist_append (NULL, tree);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
112
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
113 while (list) {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
114 GtkSmileyTree *t = list->data;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
115 gint i;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
116 list = g_slist_remove(list, t);
7384
dc573236dc8b [gaim-migrate @ 7979]
Nathan Walp <nwalp@pidgin.im>
parents: 7371
diff changeset
117 if (t && t->values) {
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
118 for (i = 0; i < t->values->len; i++)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
119 list = g_slist_append (list, t->children [i]);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
120 g_string_free (t->values, TRUE);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
121 g_free (t->children);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
122 }
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
123 g_free (t);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
124 }
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
125 }
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
126
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
127 static gboolean gtk_size_allocate_cb(GtkIMHtml *widget, GtkAllocation *alloc, gpointer user_data)
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
128 {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
129 GdkRectangle rect;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
130
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
131 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(widget), &rect);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
132 if(widget->old_rect.width != rect.width || widget->old_rect.height != rect.height){
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
133 GList *iter = GTK_IMHTML(widget)->scalables;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
134
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
135 while(iter){
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
136 GtkIMHtmlScalable *scale = GTK_IMHTML_SCALABLE(iter->data);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
137 scale->scale(scale, rect.width, rect.height);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
138
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
139 iter = iter->next;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
140 }
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
141 }
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
142
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
143 widget->old_rect = rect;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
144 return FALSE;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
145 }
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
146
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
147 static gint
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
148 gtk_imhtml_tip_paint (GtkIMHtml *imhtml)
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
149 {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
150 PangoLayout *layout;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
151
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
152 g_return_val_if_fail(GTK_IS_IMHTML(imhtml), FALSE);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
153
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
154 layout = gtk_widget_create_pango_layout(imhtml->tip_window, imhtml->tip);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
155
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
156 gtk_paint_flat_box (imhtml->tip_window->style, imhtml->tip_window->window,
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
157 GTK_STATE_NORMAL, GTK_SHADOW_OUT, NULL, imhtml->tip_window,
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
158 "tooltip", 0, 0, -1, -1);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
159
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
160 gtk_paint_layout (imhtml->tip_window->style, imhtml->tip_window->window, GTK_STATE_NORMAL,
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
161 FALSE, NULL, imhtml->tip_window, NULL, 4, 4, layout);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
162
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
163 g_object_unref(layout);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
164 return FALSE;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
165 }
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
166
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
167 static gint
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
168 gtk_imhtml_tip (gpointer data)
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
169 {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
170 GtkIMHtml *imhtml = data;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
171 PangoFontMetrics *font;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
172 PangoLayout *layout;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
173
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
174 gint gap, x, y, h, w, scr_w, baseline_skip;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
175
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
176 g_return_val_if_fail(GTK_IS_IMHTML(imhtml), FALSE);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
177
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
178 if (!imhtml->tip || !GTK_WIDGET_DRAWABLE (GTK_WIDGET(imhtml))) {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
179 imhtml->tip_timer = 0;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
180 return FALSE;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
181 }
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
182
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
183 if (imhtml->tip_window){
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
184 gtk_widget_destroy (imhtml->tip_window);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
185 imhtml->tip_window = NULL;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
186 }
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
187
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
188 imhtml->tip_timer = 0;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
189 imhtml->tip_window = gtk_window_new (GTK_WINDOW_POPUP);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
190 gtk_widget_set_app_paintable (imhtml->tip_window, TRUE);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
191 gtk_window_set_resizable (GTK_WINDOW (imhtml->tip_window), FALSE);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
192 gtk_widget_set_name (imhtml->tip_window, "gtk-tooltips");
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
193 g_signal_connect_swapped (G_OBJECT (imhtml->tip_window), "expose_event",
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
194 G_CALLBACK (gtk_imhtml_tip_paint), imhtml);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
195
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
196 gtk_widget_ensure_style (imhtml->tip_window);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
197 layout = gtk_widget_create_pango_layout(imhtml->tip_window, imhtml->tip);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
198 font = pango_font_get_metrics(pango_context_load_font(pango_layout_get_context(layout),
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
199 imhtml->tip_window->style->font_desc),
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
200 NULL);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
201
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
202
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
203 pango_layout_get_pixel_size(layout, &scr_w, NULL);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
204 gap = PANGO_PIXELS((pango_font_metrics_get_ascent(font) +
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
205 pango_font_metrics_get_descent(font))/ 4);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
206
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
207 if (gap < 2)
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
208 gap = 2;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
209 baseline_skip = PANGO_PIXELS(pango_font_metrics_get_ascent(font) +
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
210 pango_font_metrics_get_descent(font));
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
211 w = 8 + scr_w;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
212 h = 8 + baseline_skip;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
213
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
214 gdk_window_get_pointer (NULL, &x, &y, NULL);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
215 if (GTK_WIDGET_NO_WINDOW (GTK_WIDGET(imhtml)))
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
216 y += GTK_WIDGET(imhtml)->allocation.y;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
217
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
218 scr_w = gdk_screen_width();
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
219
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
220 x -= ((w >> 1) + 4);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
221
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
222 if ((x + w) > scr_w)
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
223 x -= (x + w) - scr_w;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
224 else if (x < 0)
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
225 x = 0;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
226
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
227 y = y + PANGO_PIXELS(pango_font_metrics_get_ascent(font) +
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
228 pango_font_metrics_get_descent(font));
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
229
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
230 gtk_widget_set_size_request (imhtml->tip_window, w, h);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
231 gtk_widget_show (imhtml->tip_window);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
232 gtk_window_move (GTK_WINDOW(imhtml->tip_window), x, y);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
233
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
234 pango_font_metrics_unref(font);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
235 g_object_unref(layout);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
236
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
237 return FALSE;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
238 }
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
239
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
240 gboolean gtk_motion_event_notify(GtkWidget *imhtml, GdkEventMotion *event, gpointer data)
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
241 {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
242 GtkTextIter iter;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
243 GdkWindow *win = event->window;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
244 int x, y;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
245 char *tip = NULL;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
246 GSList *tags = NULL, *templist = NULL;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
247 gdk_window_get_pointer(GTK_WIDGET(imhtml)->window, NULL, NULL, NULL);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
248 gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(imhtml), GTK_TEXT_WINDOW_WIDGET,
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
249 event->x, event->y, &x, &y);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
250 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(imhtml), &iter, x, y);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
251 tags = gtk_text_iter_get_tags(&iter);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
252
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
253 templist = tags;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
254 while (templist) {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
255 GtkTextTag *tag = templist->data;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
256 tip = g_object_get_data(G_OBJECT(tag), "link_url");
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
257 if (tip)
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
258 break;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
259 templist = templist->next;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
260 }
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
261
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
262 if (GTK_IMHTML(imhtml)->tip) {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
263 if ((tip == GTK_IMHTML(imhtml)->tip)) {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
264 return FALSE;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
265 }
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
266 /* We've left the cell. Remove the timeout and create a new one below */
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
267 if (GTK_IMHTML(imhtml)->tip_window) {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
268 gtk_widget_destroy(GTK_IMHTML(imhtml)->tip_window);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
269 GTK_IMHTML(imhtml)->tip_window = NULL;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
270 }
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
271 gdk_window_set_cursor(win, GTK_IMHTML(imhtml)->arrow_cursor);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
272 if (GTK_IMHTML(imhtml)->tip_timer)
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
273 g_source_remove(GTK_IMHTML(imhtml)->tip_timer);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
274 GTK_IMHTML(imhtml)->tip_timer = 0;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
275 }
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
276
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
277 if(tip){
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
278 gdk_window_set_cursor(win, GTK_IMHTML(imhtml)->hand_cursor);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
279 GTK_IMHTML(imhtml)->tip_timer = g_timeout_add (TOOLTIP_TIMEOUT,
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
280 gtk_imhtml_tip, imhtml);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
281 }
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
282
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
283 GTK_IMHTML(imhtml)->tip = tip;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
284 g_slist_free(tags);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
285 return FALSE;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
286 }
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
287
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
288 gboolean gtk_leave_event_notify(GtkWidget *imhtml, GdkEventCrossing *event, gpointer data)
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
289 {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
290 /* when leaving the widget, clear any current & pending tooltips and restore the cursor */
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
291 if (GTK_IMHTML(imhtml)->tip_window) {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
292 gtk_widget_destroy(GTK_IMHTML(imhtml)->tip_window);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
293 GTK_IMHTML(imhtml)->tip_window = NULL;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
294 }
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
295 if (GTK_IMHTML(imhtml)->tip_timer) {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
296 g_source_remove(GTK_IMHTML(imhtml)->tip_timer);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
297 GTK_IMHTML(imhtml)->tip_timer = 0;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
298 }
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
299 gdk_window_set_cursor(event->window, GTK_IMHTML(imhtml)->arrow_cursor);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
300
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
301 /* propogate the event normally */
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
302 return FALSE;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
303 }
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
304
6066
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
305 /*
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
306 * XXX - This should be removed eventually.
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
307 *
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
308 * This function exists to work around a gross bug in GtkTextView.
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
309 * Basically, we short circuit ctrl+a and ctrl+end because they make
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
310 * el program go boom.
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
311 *
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
312 * It's supposed to be fixed in gtk2.2. You can view the bug report at
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
313 * http://bugzilla.gnome.org/show_bug.cgi?id=107939
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
314 */
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
315 gboolean gtk_key_pressed_cb(GtkWidget *imhtml, GdkEventKey *event, gpointer data)
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
316 {
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
317 if (event->state & GDK_CONTROL_MASK)
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
318 switch (event->keyval) {
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
319 case 'a':
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
320 return TRUE;
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
321 break;
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
322
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
323 case GDK_Home:
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
324 return TRUE;
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
325 break;
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
326
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
327 case GDK_End:
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
328 return TRUE;
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
329 break;
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
330 }
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
331
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
332 return FALSE;
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
333 }
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
334
7404
d889a99e0eb1 [gaim-migrate @ 8000]
Christian Hammond <chipx86@chipx86.com>
parents: 7386
diff changeset
335 #if GTK_CHECK_VERSION(2,2,0)
7346
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
336 static GtkIMHtmlCopyable *gtk_imhtml_copyable_new(GtkIMHtml *imhtml, GtkTextMark *mark, const gchar *text)
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
337 {
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
338 GtkIMHtmlCopyable *copy = g_malloc(sizeof(GtkIMHtmlCopyable));
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
339 copy->mark = mark;
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
340 copy->text = g_strdup(text);
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
341 imhtml->copyables = g_slist_append(imhtml->copyables, copy);
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
342 return copy;
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
343 }
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
344
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
345 static void copy_clipboard_cb(GtkIMHtml *imhtml, GtkClipboard *clipboard)
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
346 {
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
347 GtkTextMark *sel = gtk_text_buffer_get_selection_bound(imhtml->text_buffer);
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
348 GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer);
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
349 GtkTextIter start, end, smiley, last;
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
350 GString *str = g_string_new(NULL);
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
351 char *text;
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
352
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
353 GSList *copyables;
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
354
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
355 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &start, sel);
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
356 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &end, ins);
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
357
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
358 if (gtk_text_iter_equal(&start, &end))
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
359 return;
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
360
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
361 gtk_text_iter_order(&start, &end);
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
362 last = start;
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
363
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
364 for (copyables = imhtml->copyables; copyables != NULL; copyables = copyables->next) {
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
365 GtkIMHtmlCopyable *copy = GTK_IMHTML_COPYABLE(copyables->data);
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
366 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &smiley, copy->mark);
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
367 if (gtk_text_iter_compare(&end, &smiley) < 0) {
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
368 break;
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
369 }
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
370 if (gtk_text_iter_compare(&last, &smiley) <= 0) {
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
371 text = gtk_text_buffer_get_text(imhtml->text_buffer, &last, &smiley, FALSE);
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
372 str = g_string_append(str, text);
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
373 str = g_string_append(str, copy->text);
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
374 last = smiley;
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
375 g_free(text);
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
376 }
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
377 }
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
378 text = gtk_text_buffer_get_text(imhtml->text_buffer, &last, &end, FALSE);
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
379 str = g_string_append(str, text);
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
380 g_free(text);
7353
dc35b4a42fea [gaim-migrate @ 7944]
Sean Egan <seanegan@gmail.com>
parents: 7346
diff changeset
381
7354
5a35881e9e89 [gaim-migrate @ 7945]
Sean Egan <seanegan@gmail.com>
parents: 7353
diff changeset
382 if (!gtk_text_iter_equal(&start, &last))
5a35881e9e89 [gaim-migrate @ 7945]
Sean Egan <seanegan@gmail.com>
parents: 7353
diff changeset
383 gtk_clipboard_set_text(clipboard ? clipboard :
5a35881e9e89 [gaim-migrate @ 7945]
Sean Egan <seanegan@gmail.com>
parents: 7353
diff changeset
384 gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_CLIPBOARD),
5a35881e9e89 [gaim-migrate @ 7945]
Sean Egan <seanegan@gmail.com>
parents: 7353
diff changeset
385 str->str, str->len);
7346
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
386 g_string_free(str, TRUE);
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
387 }
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
388
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
389 static gboolean button_release_cb(GtkIMHtml *imhtml, GdkEventButton event, gpointer the_foibles_of_man)
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
390 {
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
391 copy_clipboard_cb(imhtml, gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_PRIMARY));
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
392 return FALSE;
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
393 }
7404
d889a99e0eb1 [gaim-migrate @ 8000]
Christian Hammond <chipx86@chipx86.com>
parents: 7386
diff changeset
394 #endif
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
395
4263
74f65a3d2a1f [gaim-migrate @ 4514]
Sean Egan <seanegan@gmail.com>
parents: 4253
diff changeset
396
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
397 static GtkTextViewClass *parent_class = NULL;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
398
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
399 /* GtkIMHtml has one signal--URL_CLICKED */
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
400 enum {
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
401 URL_CLICKED,
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
402 LAST_SIGNAL
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
403 };
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
404 static guint signals [LAST_SIGNAL] = { 0 };
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
405
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
406 static void
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
407 gtk_imhtml_finalize (GObject *object)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
408 {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
409 GtkIMHtml *imhtml = GTK_IMHTML(object);
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
410 GList *scalables;
7404
d889a99e0eb1 [gaim-migrate @ 8000]
Christian Hammond <chipx86@chipx86.com>
parents: 7386
diff changeset
411 #if GTK_CHECK_VERSION(2,2,0)
7346
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
412 GSList *copyables;
7404
d889a99e0eb1 [gaim-migrate @ 8000]
Christian Hammond <chipx86@chipx86.com>
parents: 7386
diff changeset
413 #endif
7346
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
414
4138
6b2d0ce7fb18 [gaim-migrate @ 4356]
Luke Schierer <lschiere@pidgin.im>
parents: 4046
diff changeset
415 g_hash_table_destroy(imhtml->smiley_data);
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
416 gtk_smiley_tree_destroy(imhtml->default_smilies);
4138
6b2d0ce7fb18 [gaim-migrate @ 4356]
Luke Schierer <lschiere@pidgin.im>
parents: 4046
diff changeset
417 gdk_cursor_unref(imhtml->hand_cursor);
6b2d0ce7fb18 [gaim-migrate @ 4356]
Luke Schierer <lschiere@pidgin.im>
parents: 4046
diff changeset
418 gdk_cursor_unref(imhtml->arrow_cursor);
4735
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
419 if(imhtml->tip_window){
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
420 gtk_widget_destroy(imhtml->tip_window);
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
421 }
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
422 if(imhtml->tip_timer)
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
423 gtk_timeout_remove(imhtml->tip_timer);
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
424
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
425 for(scalables = imhtml->scalables; scalables; scalables = scalables->next) {
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
426 GtkIMHtmlScalable *scale = GTK_IMHTML_SCALABLE(scalables->data);
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
427 scale->free(scale);
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
428 }
7346
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
429
7404
d889a99e0eb1 [gaim-migrate @ 8000]
Christian Hammond <chipx86@chipx86.com>
parents: 7386
diff changeset
430 #if GTK_CHECK_VERSION(2,2,0)
7346
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
431 for (copyables = imhtml->copyables; copyables; copyables = copyables->next) {
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
432 GtkIMHtmlCopyable *copy = GTK_IMHTML_COPYABLE(copyables->data);
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
433 g_free(copy->text);
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
434 g_free(copy);
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
435 }
7404
d889a99e0eb1 [gaim-migrate @ 8000]
Christian Hammond <chipx86@chipx86.com>
parents: 7386
diff changeset
436 #endif
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
437 g_list_free(imhtml->scalables);
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
438 G_OBJECT_CLASS(parent_class)->finalize (object);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
439 }
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
440
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
441 /* Boring GTK stuff */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
442 static void gtk_imhtml_class_init (GtkIMHtmlClass *class)
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
443 {
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
444 GtkObjectClass *object_class;
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
445 GObjectClass *gobject_class;
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
446 object_class = (GtkObjectClass*) class;
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
447 gobject_class = (GObjectClass*) class;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
448 parent_class = gtk_type_class(GTK_TYPE_TEXT_VIEW);
4417
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
449 signals[URL_CLICKED] = g_signal_new("url_clicked",
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
450 G_TYPE_FROM_CLASS(gobject_class),
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
451 G_SIGNAL_RUN_FIRST,
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
452 G_STRUCT_OFFSET(GtkIMHtmlClass, url_clicked),
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
453 NULL,
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
454 0,
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
455 g_cclosure_marshal_VOID__POINTER,
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
456 G_TYPE_NONE, 1,
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
457 G_TYPE_POINTER);
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
458 gobject_class->finalize = gtk_imhtml_finalize;
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
459 }
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
460
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
461 static void gtk_imhtml_init (GtkIMHtml *imhtml)
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
462 {
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
463 GtkTextIter iter;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
464 imhtml->text_buffer = gtk_text_buffer_new(NULL);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
465 gtk_text_buffer_get_end_iter (imhtml->text_buffer, &iter);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
466 imhtml->end = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, FALSE);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
467 gtk_text_view_set_buffer(GTK_TEXT_VIEW(imhtml), imhtml->text_buffer);
5105
4cfc49e31c2e [gaim-migrate @ 5468]
Luke Schierer <lschiere@pidgin.im>
parents: 5104
diff changeset
468 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(imhtml), GTK_WRAP_WORD_CHAR);
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
469 gtk_text_view_set_editable(GTK_TEXT_VIEW(imhtml), FALSE);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
470 gtk_text_view_set_pixels_below_lines(GTK_TEXT_VIEW(imhtml), 5);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
471 gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(imhtml), FALSE);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
472 /*gtk_text_view_set_justification(GTK_TEXT_VIEW(imhtml), GTK_JUSTIFY_FILL);*/
3465
ec437d73b2ee [gaim-migrate @ 3515]
Sean Egan <seanegan@gmail.com>
parents: 3460
diff changeset
473
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
474 /* These tags will be used often and can be reused--we create them on init and then apply them by name
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
475 * other tags (color, size, face, etc.) will have to be created and applied dynamically */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
476 gtk_text_buffer_create_tag(imhtml->text_buffer, "BOLD", "weight", PANGO_WEIGHT_BOLD, NULL);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
477 gtk_text_buffer_create_tag(imhtml->text_buffer, "ITALICS", "style", PANGO_STYLE_ITALIC, NULL);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
478 gtk_text_buffer_create_tag(imhtml->text_buffer, "UNDERLINE", "underline", PANGO_UNDERLINE_SINGLE, NULL);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
479 gtk_text_buffer_create_tag(imhtml->text_buffer, "STRIKE", "strikethrough", TRUE, NULL);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
480 gtk_text_buffer_create_tag(imhtml->text_buffer, "SUB", "rise", -5000, NULL);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
481 gtk_text_buffer_create_tag(imhtml->text_buffer, "SUP", "rise", 5000, NULL);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
482 gtk_text_buffer_create_tag(imhtml->text_buffer, "PRE", "family", "Monospace", NULL);
7295
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
483 gtk_text_buffer_create_tag(imhtml->text_buffer, "search", "background", "#22ff00", "weight", "bold", NULL);
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
484
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
485 /* When hovering over a link, we show the hand cursor--elsewhere we show the plain ol' pointer cursor */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
486 imhtml->hand_cursor = gdk_cursor_new (GDK_HAND2);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
487 imhtml->arrow_cursor = gdk_cursor_new (GDK_LEFT_PTR);
2993
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2982
diff changeset
488
4253
6c8ea04270e1 [gaim-migrate @ 4504]
Sean Egan <seanegan@gmail.com>
parents: 4201
diff changeset
489 imhtml->show_smileys = TRUE;
6124
16fd7811effd [gaim-migrate @ 6598]
Mark Doliner <mark@kingant.net>
parents: 6066
diff changeset
490 imhtml->show_comments = TRUE;
4253
6c8ea04270e1 [gaim-migrate @ 4504]
Sean Egan <seanegan@gmail.com>
parents: 4201
diff changeset
491
4892
dc6de8ad81ae [gaim-migrate @ 5222]
Nathan Walp <nwalp@pidgin.im>
parents: 4793
diff changeset
492 imhtml->smiley_data = g_hash_table_new_full(g_str_hash, g_str_equal,
4902
0bbccc88bc67 [gaim-migrate @ 5236]
Nathan Walp <nwalp@pidgin.im>
parents: 4895
diff changeset
493 g_free, (GDestroyNotify)gtk_smiley_tree_destroy);
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
494 imhtml->default_smilies = gtk_smiley_tree_new();
4735
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
495
4944
5fe846b7603f [gaim-migrate @ 5278]
Sean Egan <seanegan@gmail.com>
parents: 4926
diff changeset
496 g_signal_connect(G_OBJECT(imhtml), "size-allocate", G_CALLBACK(gtk_size_allocate_cb), NULL);
4735
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
497 g_signal_connect(G_OBJECT(imhtml), "motion-notify-event", G_CALLBACK(gtk_motion_event_notify), NULL);
4944
5fe846b7603f [gaim-migrate @ 5278]
Sean Egan <seanegan@gmail.com>
parents: 4926
diff changeset
498 g_signal_connect(G_OBJECT(imhtml), "leave-notify-event", G_CALLBACK(gtk_leave_event_notify), NULL);
6066
c99959f1bb73 [gaim-migrate @ 6516]
Mark Doliner <mark@kingant.net>
parents: 6056
diff changeset
499 g_signal_connect(G_OBJECT(imhtml), "key_press_event", G_CALLBACK(gtk_key_pressed_cb), NULL);
7404
d889a99e0eb1 [gaim-migrate @ 8000]
Christian Hammond <chipx86@chipx86.com>
parents: 7386
diff changeset
500 #if GTK_CHECK_VERSION(2,2,0)
7353
dc35b4a42fea [gaim-migrate @ 7944]
Sean Egan <seanegan@gmail.com>
parents: 7346
diff changeset
501 g_signal_connect(G_OBJECT(imhtml), "copy-clipboard", G_CALLBACK(copy_clipboard_cb), NULL);
7346
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
502 g_signal_connect(G_OBJECT(imhtml), "button-release-event", G_CALLBACK(button_release_cb), imhtml);
7404
d889a99e0eb1 [gaim-migrate @ 8000]
Christian Hammond <chipx86@chipx86.com>
parents: 7386
diff changeset
503 #endif
4944
5fe846b7603f [gaim-migrate @ 5278]
Sean Egan <seanegan@gmail.com>
parents: 4926
diff changeset
504 gtk_widget_add_events(GTK_WIDGET(imhtml), GDK_LEAVE_NOTIFY_MASK);
4735
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
505
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
506 imhtml->tip = NULL;
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
507 imhtml->tip_timer = 0;
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
508 imhtml->tip_window = NULL;
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
509
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
510 imhtml->scalables = NULL;
7404
d889a99e0eb1 [gaim-migrate @ 8000]
Christian Hammond <chipx86@chipx86.com>
parents: 7386
diff changeset
511 #if GTK_CHECK_VERSION(2,2,0)
7346
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
512 imhtml->copyables = NULL;
7404
d889a99e0eb1 [gaim-migrate @ 8000]
Christian Hammond <chipx86@chipx86.com>
parents: 7386
diff changeset
513 #endif
2993
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2982
diff changeset
514 }
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2982
diff changeset
515
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
516 GtkWidget *gtk_imhtml_new(void *a, void *b)
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
517 {
4635
42d53c416bb9 [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4630
diff changeset
518 return GTK_WIDGET(g_object_new(gtk_imhtml_get_type(), NULL));
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
519 }
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
520
4635
42d53c416bb9 [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4630
diff changeset
521 GType gtk_imhtml_get_type()
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
522 {
4635
42d53c416bb9 [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4630
diff changeset
523 static GType imhtml_type = 0;
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
524
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
525 if (!imhtml_type) {
4635
42d53c416bb9 [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4630
diff changeset
526 static const GTypeInfo imhtml_info = {
42d53c416bb9 [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4630
diff changeset
527 sizeof(GtkIMHtmlClass),
42d53c416bb9 [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4630
diff changeset
528 NULL,
42d53c416bb9 [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4630
diff changeset
529 NULL,
42d53c416bb9 [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4630
diff changeset
530 (GClassInitFunc) gtk_imhtml_class_init,
42d53c416bb9 [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4630
diff changeset
531 NULL,
42d53c416bb9 [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4630
diff changeset
532 NULL,
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
533 sizeof (GtkIMHtml),
4635
42d53c416bb9 [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4630
diff changeset
534 0,
42d53c416bb9 [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4630
diff changeset
535 (GInstanceInitFunc) gtk_imhtml_init
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
536 };
4635
42d53c416bb9 [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4630
diff changeset
537
42d53c416bb9 [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4630
diff changeset
538 imhtml_type = g_type_register_static(gtk_text_view_get_type(),
42d53c416bb9 [gaim-migrate @ 4942]
Nathan Walp <nwalp@pidgin.im>
parents: 4630
diff changeset
539 "GtkIMHtml", &imhtml_info, 0);
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
540 }
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
541
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
542 return imhtml_type;
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
543 }
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
544
4417
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
545 struct url_data {
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
546 GObject *object;
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
547 gchar *url;
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
548 };
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
549
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
550 static void url_open(GtkWidget *w, struct url_data *data) {
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
551 if(!data) return;
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
552
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
553 g_signal_emit(data->object, signals[URL_CLICKED], 0, data->url);
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
554
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
555 g_object_unref(data->object);
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
556 g_free(data->url);
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
557 g_free(data);
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
558 }
5582
e2f2d8857f9f [gaim-migrate @ 5986]
Luke Schierer <lschiere@pidgin.im>
parents: 5367
diff changeset
559
4417
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
560 static void url_copy(GtkWidget *w, gchar *url) {
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
561 GtkClipboard *clipboard;
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
562
5293
ead927e2543f [gaim-migrate @ 5665]
Christian Hammond <chipx86@chipx86.com>
parents: 5282
diff changeset
563 clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
4417
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
564 gtk_clipboard_set_text(clipboard, url, -1);
5582
e2f2d8857f9f [gaim-migrate @ 5986]
Luke Schierer <lschiere@pidgin.im>
parents: 5367
diff changeset
565
e2f2d8857f9f [gaim-migrate @ 5986]
Luke Schierer <lschiere@pidgin.im>
parents: 5367
diff changeset
566 clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
e2f2d8857f9f [gaim-migrate @ 5986]
Luke Schierer <lschiere@pidgin.im>
parents: 5367
diff changeset
567 gtk_clipboard_set_text(clipboard, url, -1);
4417
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
568 }
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
569
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
570 /* The callback for an event on a link tag. */
5091
04ded2f7253c [gaim-migrate @ 5453]
Luke Schierer <lschiere@pidgin.im>
parents: 5046
diff changeset
571 gboolean tag_event(GtkTextTag *tag, GObject *imhtml, GdkEvent *event, GtkTextIter *arg2, char *url) {
4417
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
572 GdkEventButton *event_button = (GdkEventButton *) event;
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
573
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
574 if (event->type == GDK_BUTTON_RELEASE) {
4417
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
575 if (event_button->button == 1) {
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
576 GtkTextIter start, end;
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
577 /* we shouldn't open a URL if the user has selected something: */
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
578 gtk_text_buffer_get_selection_bounds(
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
579 gtk_text_iter_get_buffer(arg2), &start, &end);
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
580 if(gtk_text_iter_get_offset(&start) !=
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
581 gtk_text_iter_get_offset(&end))
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
582 return FALSE;
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
583
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
584 /* A link was clicked--we emit the "url_clicked" signal
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
585 * with the URL as the argument */
5091
04ded2f7253c [gaim-migrate @ 5453]
Luke Schierer <lschiere@pidgin.im>
parents: 5046
diff changeset
586 g_signal_emit(imhtml, signals[URL_CLICKED], 0, url);
4417
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
587 return FALSE;
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
588 } else if(event_button->button == 3) {
4745
01cae9259e2f [gaim-migrate @ 5060]
Nathan Walp <nwalp@pidgin.im>
parents: 4740
diff changeset
589 GtkWidget *img, *item, *menu;
4417
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
590 struct url_data *tempdata = g_new(struct url_data, 1);
5091
04ded2f7253c [gaim-migrate @ 5453]
Luke Schierer <lschiere@pidgin.im>
parents: 5046
diff changeset
591 tempdata->object = g_object_ref(imhtml);
4417
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
592 tempdata->url = g_strdup(url);
4745
01cae9259e2f [gaim-migrate @ 5060]
Nathan Walp <nwalp@pidgin.im>
parents: 4740
diff changeset
593
5091
04ded2f7253c [gaim-migrate @ 5453]
Luke Schierer <lschiere@pidgin.im>
parents: 5046
diff changeset
594 /* Don't want the tooltip around if user right-clicked on link */
04ded2f7253c [gaim-migrate @ 5453]
Luke Schierer <lschiere@pidgin.im>
parents: 5046
diff changeset
595 if (GTK_IMHTML(imhtml)->tip_window) {
04ded2f7253c [gaim-migrate @ 5453]
Luke Schierer <lschiere@pidgin.im>
parents: 5046
diff changeset
596 gtk_widget_destroy(GTK_IMHTML(imhtml)->tip_window);
04ded2f7253c [gaim-migrate @ 5453]
Luke Schierer <lschiere@pidgin.im>
parents: 5046
diff changeset
597 GTK_IMHTML(imhtml)->tip_window = NULL;
04ded2f7253c [gaim-migrate @ 5453]
Luke Schierer <lschiere@pidgin.im>
parents: 5046
diff changeset
598 }
04ded2f7253c [gaim-migrate @ 5453]
Luke Schierer <lschiere@pidgin.im>
parents: 5046
diff changeset
599 if (GTK_IMHTML(imhtml)->tip_timer) {
04ded2f7253c [gaim-migrate @ 5453]
Luke Schierer <lschiere@pidgin.im>
parents: 5046
diff changeset
600 g_source_remove(GTK_IMHTML(imhtml)->tip_timer);
04ded2f7253c [gaim-migrate @ 5453]
Luke Schierer <lschiere@pidgin.im>
parents: 5046
diff changeset
601 GTK_IMHTML(imhtml)->tip_timer = 0;
04ded2f7253c [gaim-migrate @ 5453]
Luke Schierer <lschiere@pidgin.im>
parents: 5046
diff changeset
602 }
04ded2f7253c [gaim-migrate @ 5453]
Luke Schierer <lschiere@pidgin.im>
parents: 5046
diff changeset
603 gdk_window_set_cursor(event_button->window, GTK_IMHTML(imhtml)->arrow_cursor);
4417
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
604 menu = gtk_menu_new();
4745
01cae9259e2f [gaim-migrate @ 5060]
Nathan Walp <nwalp@pidgin.im>
parents: 4740
diff changeset
605
4417
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
606 /* buttons and such */
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
607
7140
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
608 if (!strncmp(url, "mailto:", 7))
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
609 {
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
610 /* Copy E-Mail Address */
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
611 img = gtk_image_new_from_stock(GTK_STOCK_COPY,
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
612 GTK_ICON_SIZE_MENU);
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
613 item = gtk_image_menu_item_new_with_mnemonic(
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
614 _("_Copy E-Mail Address"));
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
615 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
616 g_signal_connect(G_OBJECT(item), "activate",
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
617 G_CALLBACK(url_copy), url + 7);
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
618 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
619 }
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
620 else
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
621 {
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
622 /* Copy Link Location */
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
623 img = gtk_image_new_from_stock(GTK_STOCK_COPY,
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
624 GTK_ICON_SIZE_MENU);
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
625 item = gtk_image_menu_item_new_with_mnemonic(
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
626 _("_Copy Link Location"));
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
627 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
628 g_signal_connect(G_OBJECT(item), "activate",
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
629 G_CALLBACK(url_copy), url);
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
630 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
631
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
632 /* Open Link in Browser */
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
633 img = gtk_image_new_from_stock(GTK_STOCK_JUMP_TO,
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
634 GTK_ICON_SIZE_MENU);
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
635 item = gtk_image_menu_item_new_with_mnemonic(
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
636 _("_Open Link in Browser"));
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
637 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
638 g_signal_connect(G_OBJECT(item), "activate",
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
639 G_CALLBACK(url_open), tempdata);
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
640 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
641 }
48cc5d5d5a6c [gaim-migrate @ 7707]
Christian Hammond <chipx86@chipx86.com>
parents: 6982
diff changeset
642
4756
85637881b342 [gaim-migrate @ 5073]
Mark Doliner <mark@kingant.net>
parents: 4745
diff changeset
643
4417
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
644 gtk_widget_show_all(menu);
4756
85637881b342 [gaim-migrate @ 5073]
Mark Doliner <mark@kingant.net>
parents: 4745
diff changeset
645 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL,
85637881b342 [gaim-migrate @ 5073]
Mark Doliner <mark@kingant.net>
parents: 4745
diff changeset
646 event_button->button, event_button->time);
4745
01cae9259e2f [gaim-migrate @ 5060]
Nathan Walp <nwalp@pidgin.im>
parents: 4740
diff changeset
647
4417
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
648 return TRUE;
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
649 }
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
650 }
4417
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
651 if(event->type == GDK_BUTTON_PRESS && event_button->button == 3)
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
652 return TRUE; /* Clicking the right mouse button on a link shouldn't
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
653 be caught by the regular GtkTextView menu */
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
654 else
fff9c1292fa1 [gaim-migrate @ 4690]
Sean Egan <seanegan@gmail.com>
parents: 4371
diff changeset
655 return FALSE; /* Let clicks go through if we didn't catch anything */
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
656 }
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
657
4298
cddb50734169 [gaim-migrate @ 4552]
Sean Egan <seanegan@gmail.com>
parents: 4288
diff changeset
658 /* this isn't used yet
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
659 static void
4263
74f65a3d2a1f [gaim-migrate @ 4514]
Sean Egan <seanegan@gmail.com>
parents: 4253
diff changeset
660 gtk_smiley_tree_remove (GtkSmileyTree *tree,
74f65a3d2a1f [gaim-migrate @ 4514]
Sean Egan <seanegan@gmail.com>
parents: 4253
diff changeset
661 GtkIMHtmlSmiley *smiley)
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
662 {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
663 GtkSmileyTree *t = tree;
4263
74f65a3d2a1f [gaim-migrate @ 4514]
Sean Egan <seanegan@gmail.com>
parents: 4253
diff changeset
664 const gchar *x = smiley->smile;
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
665 gint len = 0;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
666
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
667 while (*x) {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
668 gchar *pos;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
669
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
670 if (!t->values)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
671 return;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
672
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
673 pos = strchr (t->values->str, *x);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
674 if (pos)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
675 t = t->children [(int) pos - (int) t->values->str];
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
676 else
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
677 return;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
678
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
679 x++; len++;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
680 }
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
681
4141
ccec4fde84f4 [gaim-migrate @ 4359]
Christian Hammond <chipx86@chipx86.com>
parents: 4140
diff changeset
682 if (t->image) {
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
683 t->image = NULL;
4141
ccec4fde84f4 [gaim-migrate @ 4359]
Christian Hammond <chipx86@chipx86.com>
parents: 4140
diff changeset
684 }
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
685 }
4298
cddb50734169 [gaim-migrate @ 4552]
Sean Egan <seanegan@gmail.com>
parents: 4288
diff changeset
686 */
cddb50734169 [gaim-migrate @ 4552]
Sean Egan <seanegan@gmail.com>
parents: 4288
diff changeset
687
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
688
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
689 static gint
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
690 gtk_smiley_tree_lookup (GtkSmileyTree *tree,
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
691 const gchar *text)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
692 {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
693 GtkSmileyTree *t = tree;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
694 const gchar *x = text;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
695 gint len = 0;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
696
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
697 while (*x) {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
698 gchar *pos;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
699
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
700 if (!t->values)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
701 break;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
702
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
703 pos = strchr (t->values->str, *x);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
704 if (pos)
7371
2ec21bff351b [gaim-migrate @ 7966]
Nathan Walp <nwalp@pidgin.im>
parents: 7358
diff changeset
705 t = t->children [GPOINTER_TO_INT(pos) - GPOINTER_TO_INT(t->values->str)];
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
706 else
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
707 break;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
708
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
709 x++; len++;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
710 }
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
711
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
712 if (t->image)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
713 return len;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
714
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
715 return 0;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
716 }
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
717
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
718 void
4263
74f65a3d2a1f [gaim-migrate @ 4514]
Sean Egan <seanegan@gmail.com>
parents: 4253
diff changeset
719 gtk_imhtml_associate_smiley (GtkIMHtml *imhtml,
74f65a3d2a1f [gaim-migrate @ 4514]
Sean Egan <seanegan@gmail.com>
parents: 4253
diff changeset
720 gchar *sml,
74f65a3d2a1f [gaim-migrate @ 4514]
Sean Egan <seanegan@gmail.com>
parents: 4253
diff changeset
721 GtkIMHtmlSmiley *smiley)
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
722 {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
723 GtkSmileyTree *tree;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
724 g_return_if_fail (imhtml != NULL);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
725 g_return_if_fail (GTK_IS_IMHTML (imhtml));
7371
2ec21bff351b [gaim-migrate @ 7966]
Nathan Walp <nwalp@pidgin.im>
parents: 7358
diff changeset
726
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
727 if (sml == NULL)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
728 tree = imhtml->default_smilies;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
729 else if ((tree = g_hash_table_lookup(imhtml->smiley_data, sml))) {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
730 } else {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
731 tree = gtk_smiley_tree_new();
4892
dc6de8ad81ae [gaim-migrate @ 5222]
Nathan Walp <nwalp@pidgin.im>
parents: 4793
diff changeset
732 g_hash_table_insert(imhtml->smiley_data, g_strdup(sml), tree);
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
733 }
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
734
4263
74f65a3d2a1f [gaim-migrate @ 4514]
Sean Egan <seanegan@gmail.com>
parents: 4253
diff changeset
735 gtk_smiley_tree_insert (tree, smiley);
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
736 }
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
737
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
738 static gboolean
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
739 gtk_imhtml_is_smiley (GtkIMHtml *imhtml,
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
740 GSList *fonts,
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
741 const gchar *text,
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
742 gint *len)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
743 {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
744 GtkSmileyTree *tree;
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
745 GtkIMHtmlFontDetail *font;
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
746 char *sml = NULL;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
747
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
748 if (fonts) {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
749 font = fonts->data;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
750 sml = font->sml;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
751 }
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
752
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
753 if (sml == NULL)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
754 tree = imhtml->default_smilies;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
755 else {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
756 tree = g_hash_table_lookup(imhtml->smiley_data, sml);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
757 }
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
758 if (tree == NULL)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
759 return FALSE;
7371
2ec21bff351b [gaim-migrate @ 7966]
Nathan Walp <nwalp@pidgin.im>
parents: 7358
diff changeset
760
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
761 *len = gtk_smiley_tree_lookup (tree, text);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
762 return (*len > 0);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
763 }
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
764
6814
782907a6ae65 [gaim-migrate @ 7354]
Christian Hammond <chipx86@chipx86.com>
parents: 6648
diff changeset
765 GdkPixbufAnimation *
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
766 gtk_smiley_tree_image (GtkIMHtml *imhtml,
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
767 const gchar *sml,
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
768 const gchar *text)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
769 {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
770 GtkSmileyTree *t;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
771 const gchar *x = text;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
772 if (sml == NULL)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
773 t = imhtml->default_smilies;
7371
2ec21bff351b [gaim-migrate @ 7966]
Nathan Walp <nwalp@pidgin.im>
parents: 7358
diff changeset
774 else
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
775 t = g_hash_table_lookup(imhtml->smiley_data, sml);
7371
2ec21bff351b [gaim-migrate @ 7966]
Nathan Walp <nwalp@pidgin.im>
parents: 7358
diff changeset
776
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
777
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
778 if (t == NULL)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
779 return sml ? gtk_smiley_tree_image(imhtml, NULL, text) : NULL;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
780
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
781 while (*x) {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
782 gchar *pos;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
783
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
784 if (!t->values) {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
785 return sml ? gtk_smiley_tree_image(imhtml, NULL, text) : NULL;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
786 }
7371
2ec21bff351b [gaim-migrate @ 7966]
Nathan Walp <nwalp@pidgin.im>
parents: 7358
diff changeset
787
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
788 pos = strchr (t->values->str, *x);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
789 if (pos) {
7371
2ec21bff351b [gaim-migrate @ 7966]
Nathan Walp <nwalp@pidgin.im>
parents: 7358
diff changeset
790 t = t->children [GPOINTER_TO_INT(pos) - GPOINTER_TO_INT(t->values->str)];
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
791 } else {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
792 return sml ? gtk_smiley_tree_image(imhtml, NULL, text) : NULL;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
793 }
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
794 x++;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
795 }
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
796
4263
74f65a3d2a1f [gaim-migrate @ 4514]
Sean Egan <seanegan@gmail.com>
parents: 4253
diff changeset
797 if (!t->image->icon)
6814
782907a6ae65 [gaim-migrate @ 7354]
Christian Hammond <chipx86@chipx86.com>
parents: 6648
diff changeset
798 t->image->icon = gdk_pixbuf_animation_new_from_file(t->image->file, NULL);
4263
74f65a3d2a1f [gaim-migrate @ 4514]
Sean Egan <seanegan@gmail.com>
parents: 4253
diff changeset
799
74f65a3d2a1f [gaim-migrate @ 4514]
Sean Egan <seanegan@gmail.com>
parents: 4253
diff changeset
800 return t->image->icon;
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
801 }
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4764
diff changeset
802 #define VALID_TAG(x) if (!g_ascii_strncasecmp (string, x ">", strlen (x ">"))) { \
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
803 *tag = g_strndup (string, strlen (x)); \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
804 *len = strlen (x) + 1; \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
805 return TRUE; \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
806 } \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
807 (*type)++
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
808
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4764
diff changeset
809 #define VALID_OPT_TAG(x) if (!g_ascii_strncasecmp (string, x " ", strlen (x " "))) { \
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
810 const gchar *c = string + strlen (x " "); \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
811 gchar e = '"'; \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
812 gboolean quote = FALSE; \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
813 while (*c) { \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
814 if (*c == '"' || *c == '\'') { \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
815 if (quote && (*c == e)) \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
816 quote = !quote; \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
817 else if (!quote) { \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
818 quote = !quote; \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
819 e = *c; \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
820 } \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
821 } else if (!quote && (*c == '>')) \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
822 break; \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
823 c++; \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
824 } \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
825 if (*c) { \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
826 *tag = g_strndup (string, c - string); \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
827 *len = c - string + 1; \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
828 return TRUE; \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
829 } \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
830 } \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
831 (*type)++
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
832
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
833
1472
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
834 static gboolean
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
835 gtk_imhtml_is_amp_escape (const gchar *string,
7280
f946af3b0039 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7140
diff changeset
836 gchar **replace,
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
837 gint *length)
1472
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
838 {
7287
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7281
diff changeset
839 static char buf[7];
1472
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
840 g_return_val_if_fail (string != NULL, FALSE);
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
841 g_return_val_if_fail (replace != NULL, FALSE);
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
842 g_return_val_if_fail (length != NULL, FALSE);
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
843
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4764
diff changeset
844 if (!g_ascii_strncasecmp (string, "&amp;", 5)) {
7280
f946af3b0039 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7140
diff changeset
845 *replace = "&";
1472
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
846 *length = 5;
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4764
diff changeset
847 } else if (!g_ascii_strncasecmp (string, "&lt;", 4)) {
7280
f946af3b0039 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7140
diff changeset
848 *replace = "<";
1472
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
849 *length = 4;
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4764
diff changeset
850 } else if (!g_ascii_strncasecmp (string, "&gt;", 4)) {
7280
f946af3b0039 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7140
diff changeset
851 *replace = ">";
1472
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
852 *length = 4;
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4764
diff changeset
853 } else if (!g_ascii_strncasecmp (string, "&nbsp;", 6)) {
7280
f946af3b0039 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7140
diff changeset
854 *replace = " ";
1472
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
855 *length = 6;
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4764
diff changeset
856 } else if (!g_ascii_strncasecmp (string, "&copy;", 6)) {
7280
f946af3b0039 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7140
diff changeset
857 *replace = "©";
1472
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
858 *length = 6;
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4764
diff changeset
859 } else if (!g_ascii_strncasecmp (string, "&quot;", 6)) {
7280
f946af3b0039 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7140
diff changeset
860 *replace = "\"";
1472
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
861 *length = 6;
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4764
diff changeset
862 } else if (!g_ascii_strncasecmp (string, "&reg;", 5)) {
7280
f946af3b0039 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7140
diff changeset
863 *replace = "®";
1472
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
864 *length = 5;
5093
89c0c811befa [gaim-migrate @ 5455]
Nathan Walp <nwalp@pidgin.im>
parents: 5091
diff changeset
865 } else if (!g_ascii_strncasecmp (string, "&apos;", 6)) {
7280
f946af3b0039 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7140
diff changeset
866 *replace = "\'";
5093
89c0c811befa [gaim-migrate @ 5455]
Nathan Walp <nwalp@pidgin.im>
parents: 5091
diff changeset
867 *length = 6;
1472
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
868 } else if (*(string + 1) == '#') {
2022
199ba82faacb [gaim-migrate @ 2032]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2002
diff changeset
869 guint pound = 0;
3004
bfd2b1ef907c [gaim-migrate @ 3017]
Sean Egan <seanegan@gmail.com>
parents: 3000
diff changeset
870 if ((sscanf (string, "&#%u;", &pound) == 1) && pound != 0) {
7287
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7281
diff changeset
871 int buflen;
1472
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
872 if (*(string + 3 + (gint)log10 (pound)) != ';')
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
873 return FALSE;
7287
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7281
diff changeset
874 buflen = g_unichar_to_utf8((gunichar)pound, buf);
3a41c3f80228 [gaim-migrate @ 7868]
Nathan Walp <nwalp@pidgin.im>
parents: 7281
diff changeset
875 buf[buflen] = '\0';
7280
f946af3b0039 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7140
diff changeset
876 *replace = buf;
1472
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
877 *length = 2;
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
878 while (isdigit ((gint) string [*length])) (*length)++;
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
879 if (string [*length] == ';') (*length)++;
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
880 } else {
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
881 return FALSE;
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
882 }
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
883 } else {
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
884 return FALSE;
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
885 }
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
886
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
887 return TRUE;
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
888 }
be620a051d6d [gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1463
diff changeset
889
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
890 static gboolean
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
891 gtk_imhtml_is_tag (const gchar *string,
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
892 gchar **tag,
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
893 gint *len,
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
894 gint *type)
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
895 {
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
896 *type = 1;
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
897
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
898 if (!strchr (string, '>'))
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
899 return FALSE;
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
900
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
901 VALID_TAG ("B");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
902 VALID_TAG ("BOLD");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
903 VALID_TAG ("/B");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
904 VALID_TAG ("/BOLD");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
905 VALID_TAG ("I");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
906 VALID_TAG ("ITALIC");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
907 VALID_TAG ("/I");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
908 VALID_TAG ("/ITALIC");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
909 VALID_TAG ("U");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
910 VALID_TAG ("UNDERLINE");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
911 VALID_TAG ("/U");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
912 VALID_TAG ("/UNDERLINE");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
913 VALID_TAG ("S");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
914 VALID_TAG ("STRIKE");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
915 VALID_TAG ("/S");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
916 VALID_TAG ("/STRIKE");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
917 VALID_TAG ("SUB");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
918 VALID_TAG ("/SUB");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
919 VALID_TAG ("SUP");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
920 VALID_TAG ("/SUP");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
921 VALID_TAG ("PRE");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
922 VALID_TAG ("/PRE");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
923 VALID_TAG ("TITLE");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
924 VALID_TAG ("/TITLE");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
925 VALID_TAG ("BR");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
926 VALID_TAG ("HR");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
927 VALID_TAG ("/FONT");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
928 VALID_TAG ("/A");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
929 VALID_TAG ("P");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
930 VALID_TAG ("/P");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
931 VALID_TAG ("H3");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
932 VALID_TAG ("/H3");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
933 VALID_TAG ("HTML");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
934 VALID_TAG ("/HTML");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
935 VALID_TAG ("BODY");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
936 VALID_TAG ("/BODY");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
937 VALID_TAG ("FONT");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
938 VALID_TAG ("HEAD");
2993
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2982
diff changeset
939 VALID_TAG ("/HEAD");
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2982
diff changeset
940 VALID_TAG ("BINARY");
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2982
diff changeset
941 VALID_TAG ("/BINARY");
5093
89c0c811befa [gaim-migrate @ 5455]
Nathan Walp <nwalp@pidgin.im>
parents: 5091
diff changeset
942
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
943 VALID_OPT_TAG ("HR");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
944 VALID_OPT_TAG ("FONT");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
945 VALID_OPT_TAG ("BODY");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
946 VALID_OPT_TAG ("A");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
947 VALID_OPT_TAG ("IMG");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
948 VALID_OPT_TAG ("P");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
949 VALID_OPT_TAG ("H3");
5093
89c0c811befa [gaim-migrate @ 5455]
Nathan Walp <nwalp@pidgin.im>
parents: 5091
diff changeset
950 VALID_OPT_TAG ("HTML");
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
951
5101
a7e9036cd46f [gaim-migrate @ 5464]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
952 VALID_TAG ("CITE");
a7e9036cd46f [gaim-migrate @ 5464]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
953 VALID_TAG ("/CITE");
a7e9036cd46f [gaim-migrate @ 5464]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
954 VALID_TAG ("EM");
a7e9036cd46f [gaim-migrate @ 5464]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
955 VALID_TAG ("/EM");
a7e9036cd46f [gaim-migrate @ 5464]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
956 VALID_TAG ("STRONG");
a7e9036cd46f [gaim-migrate @ 5464]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
957 VALID_TAG ("/STRONG");
a7e9036cd46f [gaim-migrate @ 5464]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
958
5104
a20a644e0da4 [gaim-migrate @ 5467]
Nathan Walp <nwalp@pidgin.im>
parents: 5101
diff changeset
959 VALID_OPT_TAG ("SPAN");
a20a644e0da4 [gaim-migrate @ 5467]
Nathan Walp <nwalp@pidgin.im>
parents: 5101
diff changeset
960 VALID_TAG ("/SPAN");
5174
376349b04123 [gaim-migrate @ 5538]
Nathan Walp <nwalp@pidgin.im>
parents: 5118
diff changeset
961 VALID_TAG ("BR/"); /* hack until gtkimhtml handles things better */
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
962 VALID_TAG ("IMG");
5104
a20a644e0da4 [gaim-migrate @ 5467]
Nathan Walp <nwalp@pidgin.im>
parents: 5101
diff changeset
963
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4764
diff changeset
964 if (!g_ascii_strncasecmp(string, "!--", strlen ("!--"))) {
2954
f6c4f2187c08 [gaim-migrate @ 2967]
Christian Hammond <chipx86@chipx86.com>
parents: 2898
diff changeset
965 gchar *e = strstr (string + strlen("!--"), "-->");
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
966 if (e) {
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
967 *len = e - string + strlen ("-->");
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
968 *tag = g_strndup (string + strlen ("!--"), *len - strlen ("!---->"));
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
969 return TRUE;
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
970 }
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
971 }
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
972
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
973 return FALSE;
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
974 }
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
975
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
976 static gchar*
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
977 gtk_imhtml_get_html_opt (gchar *tag,
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
978 const gchar *opt)
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
979 {
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
980 gchar *t = tag;
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
981 gchar *e, *a;
5177
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
982 gchar *val;
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
983 gint len;
7280
f946af3b0039 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7140
diff changeset
984 gchar *c;
5177
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
985 GString *ret;
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
986
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4764
diff changeset
987 while (g_ascii_strncasecmp (t, opt, strlen (opt))) {
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
988 gboolean quote = FALSE;
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
989 if (*t == '\0') break;
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
990 while (*t && !((*t == ' ') && !quote)) {
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
991 if (*t == '\"')
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
992 quote = ! quote;
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
993 t++;
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
994 }
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
995 while (*t && (*t == ' ')) t++;
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
996 }
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
997
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4764
diff changeset
998 if (!g_ascii_strncasecmp (t, opt, strlen (opt))) {
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
999 t += strlen (opt);
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1000 } else {
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1001 return NULL;
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1002 }
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1003
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1004 if ((*t == '\"') || (*t == '\'')) {
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1005 e = a = ++t;
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1006 while (*e && (*e != *(t - 1))) e++;
2993
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2982
diff changeset
1007 if (*e == '\0') {
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1008 return NULL;
5177
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
1009 } else
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
1010 val = g_strndup(a, e - a);
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1011 } else {
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1012 e = a = t;
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1013 while (*e && !isspace ((gint) *e)) e++;
5177
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
1014 val = g_strndup(a, e - a);
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1015 }
5177
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
1016
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
1017 ret = g_string_new("");
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
1018 e = val;
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
1019 while(*e) {
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
1020 if(gtk_imhtml_is_amp_escape(e, &c, &len)) {
7280
f946af3b0039 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7140
diff changeset
1021 ret = g_string_append(ret, c);
5177
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
1022 e += len;
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
1023 } else {
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
1024 ret = g_string_append_c(ret, *e);
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
1025 e++;
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
1026 }
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
1027 }
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
1028
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
1029 g_free(val);
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
1030 val = ret->str;
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
1031 g_string_free(ret, FALSE);
1c739f2ce94f [gaim-migrate @ 5541]
Nathan Walp <nwalp@pidgin.im>
parents: 5174
diff changeset
1032 return val;
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1033 }
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1034
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1035
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1036
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1037 #define NEW_TEXT_BIT 0
4343
36cb0bb95b9c [gaim-migrate @ 4608]
Rob Flynn <gaim@robflynn.com>
parents: 4298
diff changeset
1038 #define NEW_COMMENT_BIT 2
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1039 #define NEW_SCALABLE_BIT 1
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1040 #define NEW_BIT(x) ws [wpos] = '\0'; \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1041 mark2 = gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE); \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1042 gtk_text_buffer_insert(imhtml->text_buffer, &iter, ws, -1); \
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1043 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &iter); \
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1044 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &siter, mark2); \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1045 gtk_text_buffer_delete_mark(imhtml->text_buffer, mark2); \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1046 if (bold) \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1047 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "BOLD", &siter, &iter); \
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1048 if (italics) \
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1049 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "ITALICS", &siter, &iter); \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1050 if (underline) \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1051 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "UNDERLINE", &siter, &iter); \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1052 if (strike) \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1053 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "STRIKE", &siter, &iter); \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1054 if (sub) \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1055 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "SUB", &siter, &iter); \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1056 if (sup) \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1057 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "SUP", &siter, &iter); \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1058 if (pre) \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1059 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "PRE", &siter, &iter); \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1060 if (bg) { \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1061 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "background", bg, NULL); \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1062 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &siter, &iter); \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1063 } \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1064 if (fonts) { \
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1065 GtkIMHtmlFontDetail *fd = fonts->data; \
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1066 if (fd->fore) { \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1067 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "foreground", fd->fore, NULL); \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1068 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &siter, &iter); \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1069 } \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1070 if (fd->back) { \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1071 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "background", fd->back, NULL); \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1072 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &siter, &iter); \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1073 } \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1074 if (fd->face) { \
6648
adf49a9bb9a0 [gaim-migrate @ 7173]
Luke Schierer <lschiere@pidgin.im>
parents: 6478
diff changeset
1075 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "family", fd->face, NULL); \
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1076 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &siter, &iter); \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1077 } \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1078 if (fd->size) { \
5118
c4664c2bfbf8 [gaim-migrate @ 5481]
Luke Schierer <lschiere@pidgin.im>
parents: 5117
diff changeset
1079 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "size-points", (double)POINT_SIZE(fd->size), NULL); \
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1080 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &siter, &iter); \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1081 } \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1082 } \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1083 if (url) { \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1084 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "foreground", "blue", "underline", PANGO_UNDERLINE_SINGLE, NULL); \
5012
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1085 g_signal_connect(G_OBJECT(texttag), "event", G_CALLBACK(tag_event), g_strdup(url)); \
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1086 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &siter, &iter); \
4735
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
1087 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, NULL); \
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
1088 g_object_set_data(G_OBJECT(texttag), "link_url", g_strdup(url)); \
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
1089 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &siter, &iter); \
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1090 } \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1091 wpos = 0; \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1092 ws[0] = 0; \
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1093 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &iter); \
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1094 if (x == NEW_SCALABLE_BIT) { \
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1095 GdkRectangle rect; \
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1096 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect); \
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1097 scalable->add_to(scalable, imhtml, &iter); \
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1098 scalable->scale(scalable, rect.width, rect.height); \
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1099 imhtml->scalables = g_list_append(imhtml->scalables, scalable); \
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1100 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &iter); \
4343
36cb0bb95b9c [gaim-migrate @ 4608]
Rob Flynn <gaim@robflynn.com>
parents: 4298
diff changeset
1101 } \
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1102
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1103
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1104
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
1105 GString* gtk_imhtml_append_text_with_images (GtkIMHtml *imhtml,
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
1106 const gchar *text,
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
1107 GtkIMHtmlOptions options,
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
1108 GSList *images)
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1109 {
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1110 gint pos = 0;
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1111 GString *str = NULL;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1112 GtkTextIter iter, siter;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1113 GtkTextMark *mark, *mark2;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1114 GtkTextTag *texttag;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1115 gchar *ws;
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1116 gchar *tag;
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1117 gchar *url = NULL;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1118 gchar *bg = NULL;
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
1119 gint len;
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1120 gint tlen, smilelen, wpos=0;
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1121 gint type;
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1122 const gchar *c;
7280
f946af3b0039 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7140
diff changeset
1123 gchar *amp;
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1124
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1125 guint bold = 0,
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1126 italics = 0,
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1127 underline = 0,
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1128 strike = 0,
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1129 sub = 0,
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1130 sup = 0,
1691
d802b115800f [gaim-migrate @ 1701]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1647
diff changeset
1131 title = 0,
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1132 pre = 0;
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1133
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1134 GSList *fonts = NULL;
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1135
4612
c05e6ecdc902 [gaim-migrate @ 4901]
Luke Schierer <lschiere@pidgin.im>
parents: 4477
diff changeset
1136 GdkRectangle rect;
c05e6ecdc902 [gaim-migrate @ 4901]
Luke Schierer <lschiere@pidgin.im>
parents: 4477
diff changeset
1137 int y, height;
c05e6ecdc902 [gaim-migrate @ 4901]
Luke Schierer <lschiere@pidgin.im>
parents: 4477
diff changeset
1138
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1139 GtkIMHtmlScalable *scalable = NULL;
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1140
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1141 g_return_val_if_fail (imhtml != NULL, NULL);
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1142 g_return_val_if_fail (GTK_IS_IMHTML (imhtml), NULL);
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1143 g_return_val_if_fail (text != NULL, NULL);
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
1144
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1145 c = text;
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
1146 len = strlen(text);
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1147 ws = g_malloc(len + 1);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1148 ws[0] = 0;
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1149
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1150 if (options & GTK_IMHTML_RETURN_LOG)
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1151 str = g_string_new("");
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1152
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1153 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &iter);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1154 mark = gtk_text_buffer_create_mark (imhtml->text_buffer, NULL, &iter, /* right grav */ FALSE);
4612
c05e6ecdc902 [gaim-migrate @ 4901]
Luke Schierer <lschiere@pidgin.im>
parents: 4477
diff changeset
1155
c05e6ecdc902 [gaim-migrate @ 4901]
Luke Schierer <lschiere@pidgin.im>
parents: 4477
diff changeset
1156 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect);
c05e6ecdc902 [gaim-migrate @ 4901]
Luke Schierer <lschiere@pidgin.im>
parents: 4477
diff changeset
1157 gtk_text_view_get_line_yrange(GTK_TEXT_VIEW(imhtml), &iter, &y, &height);
c05e6ecdc902 [gaim-migrate @ 4901]
Luke Schierer <lschiere@pidgin.im>
parents: 4477
diff changeset
1158
c05e6ecdc902 [gaim-migrate @ 4901]
Luke Schierer <lschiere@pidgin.im>
parents: 4477
diff changeset
1159 if(((y + height) - (rect.y + rect.height)) > height
c05e6ecdc902 [gaim-migrate @ 4901]
Luke Schierer <lschiere@pidgin.im>
parents: 4477
diff changeset
1160 && gtk_text_buffer_get_char_count(imhtml->text_buffer)){
c05e6ecdc902 [gaim-migrate @ 4901]
Luke Schierer <lschiere@pidgin.im>
parents: 4477
diff changeset
1161 options |= GTK_IMHTML_NO_SCROLL;
c05e6ecdc902 [gaim-migrate @ 4901]
Luke Schierer <lschiere@pidgin.im>
parents: 4477
diff changeset
1162 }
c05e6ecdc902 [gaim-migrate @ 4901]
Luke Schierer <lschiere@pidgin.im>
parents: 4477
diff changeset
1163
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1164 while (pos < len) {
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1165 if (*c == '<' && gtk_imhtml_is_tag (c + 1, &tag, &tlen, &type)) {
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1166 c++;
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1167 pos++;
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1168 switch (type)
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1169 {
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1170 case 1: /* B */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1171 case 2: /* BOLD */
5101
a7e9036cd46f [gaim-migrate @ 5464]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
1172 case 54: /* STRONG */
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1173 NEW_BIT (NEW_TEXT_BIT);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1174 bold++;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1175 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1176 case 3: /* /B */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1177 case 4: /* /BOLD */
5101
a7e9036cd46f [gaim-migrate @ 5464]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
1178 case 55: /* /STRONG */
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1179 NEW_BIT (NEW_TEXT_BIT);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1180 if (bold)
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1181 bold--;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1182 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1183 case 5: /* I */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1184 case 6: /* ITALIC */
5101
a7e9036cd46f [gaim-migrate @ 5464]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
1185 case 52: /* EM */
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1186 NEW_BIT (NEW_TEXT_BIT);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1187 italics++;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1188 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1189 case 7: /* /I */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1190 case 8: /* /ITALIC */
5101
a7e9036cd46f [gaim-migrate @ 5464]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
1191 case 53: /* /EM */
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1192 NEW_BIT (NEW_TEXT_BIT);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1193 if (italics)
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1194 italics--;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1195 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1196 case 9: /* U */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1197 case 10: /* UNDERLINE */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1198 NEW_BIT (NEW_TEXT_BIT);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1199 underline++;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1200 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1201 case 11: /* /U */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1202 case 12: /* /UNDERLINE */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1203 NEW_BIT (NEW_TEXT_BIT);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1204 if (underline)
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1205 underline--;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1206 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1207 case 13: /* S */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1208 case 14: /* STRIKE */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1209 NEW_BIT (NEW_TEXT_BIT);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1210 strike++;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1211 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1212 case 15: /* /S */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1213 case 16: /* /STRIKE */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1214 NEW_BIT (NEW_TEXT_BIT);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1215 if (strike)
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1216 strike--;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1217 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1218 case 17: /* SUB */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1219 NEW_BIT (NEW_TEXT_BIT);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1220 sub++;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1221 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1222 case 18: /* /SUB */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1223 NEW_BIT (NEW_TEXT_BIT);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1224 if (sub)
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1225 sub--;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1226 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1227 case 19: /* SUP */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1228 NEW_BIT (NEW_TEXT_BIT);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1229 sup++;
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1230 break;
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1231 case 20: /* /SUP */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1232 NEW_BIT (NEW_TEXT_BIT);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1233 if (sup)
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1234 sup--;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1235 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1236 case 21: /* PRE */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1237 NEW_BIT (NEW_TEXT_BIT);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1238 pre++;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1239 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1240 case 22: /* /PRE */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1241 NEW_BIT (NEW_TEXT_BIT);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1242 if (pre)
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1243 pre--;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1244 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1245 case 23: /* TITLE */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1246 NEW_BIT (NEW_TEXT_BIT);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1247 title++;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1248 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1249 case 24: /* /TITLE */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1250 if (title) {
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1251 if (options & GTK_IMHTML_NO_TITLE) {
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1252 wpos = 0;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1253 ws [wpos] = '\0';
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1254 }
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1255 title--;
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1256 }
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1257 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1258 case 25: /* BR */
5174
376349b04123 [gaim-migrate @ 5538]
Nathan Walp <nwalp@pidgin.im>
parents: 5118
diff changeset
1259 case 58: /* BR/ */
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1260 ws[wpos] = '\n';
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1261 wpos++;
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1262 NEW_BIT (NEW_TEXT_BIT);
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
1263 break;
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1264 case 26: /* HR */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1265 case 42: /* HR (opt) */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1266 ws[wpos++] = '\n';
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1267 scalable = gtk_imhtml_hr_new();
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1268 NEW_BIT(NEW_SCALABLE_BIT);
4343
36cb0bb95b9c [gaim-migrate @ 4608]
Rob Flynn <gaim@robflynn.com>
parents: 4298
diff changeset
1269 ws[wpos++] = '\n';
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1270 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1271 case 27: /* /FONT */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1272 if (fonts) {
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1273 GtkIMHtmlFontDetail *font = fonts->data;
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1274 NEW_BIT (NEW_TEXT_BIT);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1275 fonts = g_slist_remove (fonts, font);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1276 if (font->face)
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1277 g_free (font->face);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1278 if (font->fore)
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1279 g_free (font->fore);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1280 if (font->back)
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1281 g_free (font->back);
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1282 if (font->sml)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1283 g_free (font->sml);
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1284 g_free (font);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1285 }
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1286 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1287 case 28: /* /A */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1288 if (url) {
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1289 NEW_BIT(NEW_TEXT_BIT);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1290 g_free(url);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1291 url = NULL;
2993
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2982
diff changeset
1292 break;
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2982
diff changeset
1293 }
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1294 case 29: /* P */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1295 case 30: /* /P */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1296 case 31: /* H3 */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1297 case 32: /* /H3 */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1298 case 33: /* HTML */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1299 case 34: /* /HTML */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1300 case 35: /* BODY */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1301 case 36: /* /BODY */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1302 case 37: /* FONT */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1303 case 38: /* HEAD */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1304 case 39: /* /HEAD */
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
1305 case 40: /* BINARY */
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
1306 case 41: /* /BINARY */
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1307 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1308 case 43: /* FONT (opt) */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1309 {
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1310 gchar *color, *back, *face, *size, *sml;
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1311 GtkIMHtmlFontDetail *font, *oldfont = NULL;
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1312 color = gtk_imhtml_get_html_opt (tag, "COLOR=");
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1313 back = gtk_imhtml_get_html_opt (tag, "BACK=");
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1314 face = gtk_imhtml_get_html_opt (tag, "FACE=");
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1315 size = gtk_imhtml_get_html_opt (tag, "SIZE=");
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1316 sml = gtk_imhtml_get_html_opt (tag, "SML=");
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1317 if (!(color || back || face || size || sml))
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1318 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1319
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1320 NEW_BIT (NEW_TEXT_BIT);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1321
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1322 font = g_new0 (GtkIMHtmlFontDetail, 1);
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1323 if (fonts)
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1324 oldfont = fonts->data;
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1325
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1326 if (color && !(options & GTK_IMHTML_NO_COLOURS))
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1327 font->fore = color;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1328 else if (oldfont && oldfont->fore)
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1329 font->fore = g_strdup(oldfont->fore);
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1330
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1331 if (back && !(options & GTK_IMHTML_NO_COLOURS))
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1332 font->back = back;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1333 else if (oldfont && oldfont->back)
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1334 font->back = g_strdup(oldfont->back);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1335
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1336 if (face && !(options & GTK_IMHTML_NO_FONTS))
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1337 font->face = face;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1338 else if (oldfont && oldfont->face)
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1339 font->face = g_strdup(oldfont->face);
4629
86fd0f6eaa1a [gaim-migrate @ 4920]
Mark Doliner <mark@kingant.net>
parents: 4612
diff changeset
1340 if (font->face && (atoi(font->face) > 100)) {
86fd0f6eaa1a [gaim-migrate @ 4920]
Mark Doliner <mark@kingant.net>
parents: 4612
diff changeset
1341 g_free(font->face);
86fd0f6eaa1a [gaim-migrate @ 4920]
Mark Doliner <mark@kingant.net>
parents: 4612
diff changeset
1342 font->face = g_strdup("100");
86fd0f6eaa1a [gaim-migrate @ 4920]
Mark Doliner <mark@kingant.net>
parents: 4612
diff changeset
1343 }
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1344
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1345 if (sml)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1346 font->sml = sml;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1347 else if (oldfont && oldfont->sml)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1348 font->sml = g_strdup(oldfont->sml);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1349
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1350 if (size && !(options & GTK_IMHTML_NO_SIZES)) {
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1351 if (*size == '+') {
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1352 sscanf (size + 1, "%hd", &font->size);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1353 font->size += 3;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1354 } else if (*size == '-') {
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1355 sscanf (size + 1, "%hd", &font->size);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1356 font->size = MAX (0, 3 - font->size);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1357 } else if (isdigit (*size)) {
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1358 sscanf (size, "%hd", &font->size);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1359 }
6042
460b4ba2d452 [gaim-migrate @ 6492]
Mark Doliner <mark@kingant.net>
parents: 5967
diff changeset
1360 if (font->size > 100)
460b4ba2d452 [gaim-migrate @ 6492]
Mark Doliner <mark@kingant.net>
parents: 5967
diff changeset
1361 font->size = 100;
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1362 } else if (oldfont)
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1363 font->size = oldfont->size;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1364 g_free(size);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1365 fonts = g_slist_prepend (fonts, font);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1366 }
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1367 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1368 case 44: /* BODY (opt) */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1369 if (!(options & GTK_IMHTML_NO_COLOURS)) {
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1370 char *bgcolor = gtk_imhtml_get_html_opt (tag, "BGCOLOR=");
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1371 if (bgcolor) {
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1372 NEW_BIT(NEW_TEXT_BIT);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1373 if (bg)
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1374 g_free(bg);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1375 bg = bgcolor;
2885
f72efa29c109 [gaim-migrate @ 2898]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2871
diff changeset
1376 }
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1377 }
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1378 break;
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1379 case 45: /* A (opt) */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1380 {
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1381 gchar *href = gtk_imhtml_get_html_opt (tag, "HREF=");
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1382 if (href) {
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1383 NEW_BIT (NEW_TEXT_BIT);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1384 if (url)
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1385 g_free (url);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1386 url = href;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1387 }
2993
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2982
diff changeset
1388 }
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1389 break;
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1390 case 46: /* IMG (opt) */
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
1391 case 59: /* IMG */
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1392 {
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
1393 GdkPixbuf *img = NULL;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
1394 const gchar *filename = NULL;
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1395
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
1396 if (images && images->data) {
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
1397 img = images->data;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
1398 images = images->next;
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
1399 filename = g_object_get_data(G_OBJECT(img), "filename");
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
1400 g_object_ref(G_OBJECT(img));
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
1401 } else {
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
1402 img = gtk_widget_render_icon(GTK_WIDGET(imhtml),
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
1403 GTK_STOCK_MISSING_IMAGE, GTK_ICON_SIZE_BUTTON,
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
1404 "gtkimhtml-missing-image");
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
1405 }
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1406
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
1407 scalable = gtk_imhtml_image_new(img, filename);
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
1408 NEW_BIT(NEW_SCALABLE_BIT);
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
1409 g_object_unref(G_OBJECT(img));
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1410 }
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1411 case 47: /* P (opt) */
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1412 case 48: /* H3 (opt) */
5093
89c0c811befa [gaim-migrate @ 5455]
Nathan Walp <nwalp@pidgin.im>
parents: 5091
diff changeset
1413 case 49: /* HTML (opt) */
5101
a7e9036cd46f [gaim-migrate @ 5464]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
1414 case 50: /* CITE */
a7e9036cd46f [gaim-migrate @ 5464]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
1415 case 51: /* /CITE */
5104
a20a644e0da4 [gaim-migrate @ 5467]
Nathan Walp <nwalp@pidgin.im>
parents: 5101
diff changeset
1416 case 56: /* SPAN */
a20a644e0da4 [gaim-migrate @ 5467]
Nathan Walp <nwalp@pidgin.im>
parents: 5101
diff changeset
1417 case 57: /* /SPAN */
2993
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2982
diff changeset
1418 break;
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
1419 case 60: /* comment */
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1420 NEW_BIT (NEW_TEXT_BIT);
6124
16fd7811effd [gaim-migrate @ 6598]
Mark Doliner <mark@kingant.net>
parents: 6066
diff changeset
1421 if (imhtml->show_comments)
16fd7811effd [gaim-migrate @ 6598]
Mark Doliner <mark@kingant.net>
parents: 6066
diff changeset
1422 wpos = g_snprintf (ws, len, "%s", tag);
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1423 NEW_BIT (NEW_COMMENT_BIT);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1424 break;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1425 default:
6882
4f8258b2bb8d [gaim-migrate @ 7428]
Luke Schierer <lschiere@pidgin.im>
parents: 6839
diff changeset
1426 break;
2993
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2982
diff changeset
1427 }
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1428 c += tlen;
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1429 pos += tlen;
4138
6b2d0ce7fb18 [gaim-migrate @ 4356]
Luke Schierer <lschiere@pidgin.im>
parents: 4046
diff changeset
1430 if(tag)
6b2d0ce7fb18 [gaim-migrate @ 4356]
Luke Schierer <lschiere@pidgin.im>
parents: 4046
diff changeset
1431 g_free(tag); /* This was allocated back in VALID_TAG() */
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1432 } else if (*c == '&' && gtk_imhtml_is_amp_escape (c, &amp, &tlen)) {
7280
f946af3b0039 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7140
diff changeset
1433 while(*amp) {
f946af3b0039 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7140
diff changeset
1434 ws [wpos++] = *amp++;
f946af3b0039 [gaim-migrate @ 7859]
Nathan Walp <nwalp@pidgin.im>
parents: 7140
diff changeset
1435 }
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1436 c += tlen;
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1437 pos += tlen;
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1438 } else if (*c == '\n') {
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1439 if (!(options & GTK_IMHTML_NO_NEWLINE)) {
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1440 ws[wpos] = '\n';
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1441 wpos++;
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1442 NEW_BIT (NEW_TEXT_BIT);
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1443 }
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1444 c++;
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1445 pos++;
4253
6c8ea04270e1 [gaim-migrate @ 4504]
Sean Egan <seanegan@gmail.com>
parents: 4201
diff changeset
1446 } else if (imhtml->show_smileys && (gtk_imhtml_is_smiley (imhtml, fonts, c, &smilelen) || gtk_imhtml_is_smiley(imhtml, NULL, c, &smilelen))) {
6814
782907a6ae65 [gaim-migrate @ 7354]
Christian Hammond <chipx86@chipx86.com>
parents: 6648
diff changeset
1447 GtkTextChildAnchor *anchor;
6882
4f8258b2bb8d [gaim-migrate @ 7428]
Luke Schierer <lschiere@pidgin.im>
parents: 6839
diff changeset
1448 GtkWidget *icon = NULL;
7344
7ba7fedc1d8b [gaim-migrate @ 7935]
Sean Egan <seanegan@gmail.com>
parents: 7295
diff changeset
1449 GtkTextIter copy;
6882
4f8258b2bb8d [gaim-migrate @ 7428]
Luke Schierer <lschiere@pidgin.im>
parents: 6839
diff changeset
1450 GdkPixbufAnimation *annipixbuf = NULL;
4f8258b2bb8d [gaim-migrate @ 7428]
Luke Schierer <lschiere@pidgin.im>
parents: 6839
diff changeset
1451 GdkPixbuf *pixbuf = NULL;
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1452 GtkIMHtmlFontDetail *fd;
7346
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
1453
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1454 gchar *sml = NULL;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1455 if (fonts) {
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1456 fd = fonts->data;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1457 sml = fd->sml;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1458 }
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1459 NEW_BIT (NEW_TEXT_BIT);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1460 wpos = g_snprintf (ws, smilelen + 1, "%s", c);
6814
782907a6ae65 [gaim-migrate @ 7354]
Christian Hammond <chipx86@chipx86.com>
parents: 6648
diff changeset
1461 anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, &iter);
6882
4f8258b2bb8d [gaim-migrate @ 7428]
Luke Schierer <lschiere@pidgin.im>
parents: 6839
diff changeset
1462 annipixbuf = gtk_smiley_tree_image(imhtml, sml, ws);
4f8258b2bb8d [gaim-migrate @ 7428]
Luke Schierer <lschiere@pidgin.im>
parents: 6839
diff changeset
1463 if(annipixbuf) {
4f8258b2bb8d [gaim-migrate @ 7428]
Luke Schierer <lschiere@pidgin.im>
parents: 6839
diff changeset
1464 if(gdk_pixbuf_animation_is_static_image(annipixbuf)) {
4f8258b2bb8d [gaim-migrate @ 7428]
Luke Schierer <lschiere@pidgin.im>
parents: 6839
diff changeset
1465 pixbuf = gdk_pixbuf_animation_get_static_image(annipixbuf);
4f8258b2bb8d [gaim-migrate @ 7428]
Luke Schierer <lschiere@pidgin.im>
parents: 6839
diff changeset
1466 if(pixbuf)
4f8258b2bb8d [gaim-migrate @ 7428]
Luke Schierer <lschiere@pidgin.im>
parents: 6839
diff changeset
1467 icon = gtk_image_new_from_pixbuf(pixbuf);
4f8258b2bb8d [gaim-migrate @ 7428]
Luke Schierer <lschiere@pidgin.im>
parents: 6839
diff changeset
1468 } else {
4f8258b2bb8d [gaim-migrate @ 7428]
Luke Schierer <lschiere@pidgin.im>
parents: 6839
diff changeset
1469 icon = gtk_image_new_from_animation(annipixbuf);
4f8258b2bb8d [gaim-migrate @ 7428]
Luke Schierer <lschiere@pidgin.im>
parents: 6839
diff changeset
1470 }
4f8258b2bb8d [gaim-migrate @ 7428]
Luke Schierer <lschiere@pidgin.im>
parents: 6839
diff changeset
1471 }
4f8258b2bb8d [gaim-migrate @ 7428]
Luke Schierer <lschiere@pidgin.im>
parents: 6839
diff changeset
1472
4f8258b2bb8d [gaim-migrate @ 7428]
Luke Schierer <lschiere@pidgin.im>
parents: 6839
diff changeset
1473 if (icon) {
6839
bdc4e73f354d [gaim-migrate @ 7384]
Christian Hammond <chipx86@chipx86.com>
parents: 6814
diff changeset
1474 gtk_widget_show(icon);
bdc4e73f354d [gaim-migrate @ 7384]
Christian Hammond <chipx86@chipx86.com>
parents: 6814
diff changeset
1475 gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(imhtml), icon, anchor);
7404
d889a99e0eb1 [gaim-migrate @ 8000]
Christian Hammond <chipx86@chipx86.com>
parents: 7386
diff changeset
1476 #if GTK_CHECK_VERSION(2,2,0)
7346
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
1477 gtk_imhtml_copyable_new(imhtml,
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
1478 gtk_text_buffer_create_mark(imhtml->text_buffer, NULL, &iter, TRUE),
15155dbc768a [gaim-migrate @ 7937]
Sean Egan <seanegan@gmail.com>
parents: 7344
diff changeset
1479 ws);
7404
d889a99e0eb1 [gaim-migrate @ 8000]
Christian Hammond <chipx86@chipx86.com>
parents: 7386
diff changeset
1480 #endif
6839
bdc4e73f354d [gaim-migrate @ 7384]
Christian Hammond <chipx86@chipx86.com>
parents: 6814
diff changeset
1481 }
7344
7ba7fedc1d8b [gaim-migrate @ 7935]
Sean Egan <seanegan@gmail.com>
parents: 7295
diff changeset
1482
7ba7fedc1d8b [gaim-migrate @ 7935]
Sean Egan <seanegan@gmail.com>
parents: 7295
diff changeset
1483 copy = iter;
7ba7fedc1d8b [gaim-migrate @ 7935]
Sean Egan <seanegan@gmail.com>
parents: 7295
diff changeset
1484 gtk_text_iter_backward_char(&copy);
7ba7fedc1d8b [gaim-migrate @ 7935]
Sean Egan <seanegan@gmail.com>
parents: 7295
diff changeset
1485 if (bg) {
7ba7fedc1d8b [gaim-migrate @ 7935]
Sean Egan <seanegan@gmail.com>
parents: 7295
diff changeset
1486 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "background", bg, NULL);
7ba7fedc1d8b [gaim-migrate @ 7935]
Sean Egan <seanegan@gmail.com>
parents: 7295
diff changeset
1487 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &iter, &copy);
7ba7fedc1d8b [gaim-migrate @ 7935]
Sean Egan <seanegan@gmail.com>
parents: 7295
diff changeset
1488 }
7ba7fedc1d8b [gaim-migrate @ 7935]
Sean Egan <seanegan@gmail.com>
parents: 7295
diff changeset
1489 if (fonts) {
7ba7fedc1d8b [gaim-migrate @ 7935]
Sean Egan <seanegan@gmail.com>
parents: 7295
diff changeset
1490 GtkIMHtmlFontDetail *fd = fonts->data;
7ba7fedc1d8b [gaim-migrate @ 7935]
Sean Egan <seanegan@gmail.com>
parents: 7295
diff changeset
1491 if (fd->back) {
7ba7fedc1d8b [gaim-migrate @ 7935]
Sean Egan <seanegan@gmail.com>
parents: 7295
diff changeset
1492 texttag = gtk_text_buffer_create_tag(imhtml->text_buffer, NULL, "background", fd->back, NULL);
7ba7fedc1d8b [gaim-migrate @ 7935]
Sean Egan <seanegan@gmail.com>
parents: 7295
diff changeset
1493 gtk_text_buffer_apply_tag(imhtml->text_buffer, texttag, &iter, &copy);
7ba7fedc1d8b [gaim-migrate @ 7935]
Sean Egan <seanegan@gmail.com>
parents: 7295
diff changeset
1494 }
7ba7fedc1d8b [gaim-migrate @ 7935]
Sean Egan <seanegan@gmail.com>
parents: 7295
diff changeset
1495 }
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1496 c += smilelen;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1497 pos += smilelen;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1498 wpos = 0;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1499 ws[0] = 0;
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1500 } else if (*c) {
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1501 ws [wpos++] = *c++;
2856
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1502 pos++;
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1503 } else {
b1e300a85678 [gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2826
diff changeset
1504 break;
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1505 }
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1506 }
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1507
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1508 NEW_BIT(NEW_TEXT_BIT);
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1509 if (url) {
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1510 g_free (url);
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1511 if (str)
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1512 str = g_string_append (str, "</A>");
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1513 }
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1514
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1515 while (fonts) {
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1516 GtkIMHtmlFontDetail *font = fonts->data;
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1517 fonts = g_slist_remove (fonts, font);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1518 if (font->face)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1519 g_free (font->face);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1520 if (font->fore)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1521 g_free (font->fore);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1522 if (font->back)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1523 g_free (font->back);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1524 if (font->sml)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1525 g_free (font->sml);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1526 g_free (font);
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1527 if (str)
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1528 str = g_string_append (str, "</FONT>");
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1529 }
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1530
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1531 if (str) {
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1532 while (bold) {
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1533 str = g_string_append (str, "</B>");
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1534 bold--;
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1535 }
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1536 while (italics) {
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1537 str = g_string_append (str, "</I>");
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1538 italics--;
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1539 }
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1540 while (underline) {
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1541 str = g_string_append (str, "</U>");
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1542 underline--;
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1543 }
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1544 while (strike) {
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1545 str = g_string_append (str, "</S>");
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1546 strike--;
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1547 }
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1548 while (sub) {
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1549 str = g_string_append (str, "</SUB>");
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1550 sub--;
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1551 }
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1552 while (sup) {
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1553 str = g_string_append (str, "</SUP>");
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1554 sup--;
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1555 }
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1556 while (title) {
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1557 str = g_string_append (str, "</TITLE>");
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1558 title--;
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1559 }
1691
d802b115800f [gaim-migrate @ 1701]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1647
diff changeset
1560 while (pre) {
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1561 str = g_string_append (str, "</PRE>");
1691
d802b115800f [gaim-migrate @ 1701]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1647
diff changeset
1562 pre--;
d802b115800f [gaim-migrate @ 1701]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1647
diff changeset
1563 }
1428
00b3d02a2168 [gaim-migrate @ 1438]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1564 }
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1565 g_free (ws);
4630
5cdfd20daa07 [gaim-migrate @ 4921]
Sean Egan <seanegan@gmail.com>
parents: 4629
diff changeset
1566 if(bg)
5cdfd20daa07 [gaim-migrate @ 4921]
Sean Egan <seanegan@gmail.com>
parents: 4629
diff changeset
1567 g_free(bg);
4032
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1568 if (!(options & GTK_IMHTML_NO_SCROLL))
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1569 gtk_text_view_scroll_to_mark (GTK_TEXT_VIEW (imhtml), mark,
2b3a9d8f168e [gaim-migrate @ 4238]
Sean Egan <seanegan@gmail.com>
parents: 3941
diff changeset
1570 0, TRUE, 0.0, 1.0);
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1571 gtk_text_buffer_delete_mark (imhtml->text_buffer, mark);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1572 return str;
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1573 }
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1574
4892
dc6de8ad81ae [gaim-migrate @ 5222]
Nathan Walp <nwalp@pidgin.im>
parents: 4793
diff changeset
1575 void gtk_imhtml_remove_smileys(GtkIMHtml *imhtml)
dc6de8ad81ae [gaim-migrate @ 5222]
Nathan Walp <nwalp@pidgin.im>
parents: 4793
diff changeset
1576 {
4288
a723d060620a [gaim-migrate @ 4541]
Sean Egan <seanegan@gmail.com>
parents: 4264
diff changeset
1577 g_hash_table_destroy(imhtml->smiley_data);
a723d060620a [gaim-migrate @ 4541]
Sean Egan <seanegan@gmail.com>
parents: 4264
diff changeset
1578 gtk_smiley_tree_destroy(imhtml->default_smilies);
4892
dc6de8ad81ae [gaim-migrate @ 5222]
Nathan Walp <nwalp@pidgin.im>
parents: 4793
diff changeset
1579 imhtml->smiley_data = g_hash_table_new_full(g_str_hash, g_str_equal,
4902
0bbccc88bc67 [gaim-migrate @ 5236]
Nathan Walp <nwalp@pidgin.im>
parents: 4895
diff changeset
1580 g_free, (GDestroyNotify)gtk_smiley_tree_destroy);
4288
a723d060620a [gaim-migrate @ 4541]
Sean Egan <seanegan@gmail.com>
parents: 4264
diff changeset
1581 imhtml->default_smilies = gtk_smiley_tree_new();
a723d060620a [gaim-migrate @ 4541]
Sean Egan <seanegan@gmail.com>
parents: 4264
diff changeset
1582 }
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1583 void gtk_imhtml_show_smileys (GtkIMHtml *imhtml,
4253
6c8ea04270e1 [gaim-migrate @ 4504]
Sean Egan <seanegan@gmail.com>
parents: 4201
diff changeset
1584 gboolean show)
6c8ea04270e1 [gaim-migrate @ 4504]
Sean Egan <seanegan@gmail.com>
parents: 4201
diff changeset
1585 {
6c8ea04270e1 [gaim-migrate @ 4504]
Sean Egan <seanegan@gmail.com>
parents: 4201
diff changeset
1586 imhtml->show_smileys = show;
6c8ea04270e1 [gaim-migrate @ 4504]
Sean Egan <seanegan@gmail.com>
parents: 4201
diff changeset
1587 }
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1588
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1589 void gtk_imhtml_show_comments (GtkIMHtml *imhtml,
4253
6c8ea04270e1 [gaim-migrate @ 4504]
Sean Egan <seanegan@gmail.com>
parents: 4201
diff changeset
1590 gboolean show)
6c8ea04270e1 [gaim-migrate @ 4504]
Sean Egan <seanegan@gmail.com>
parents: 4201
diff changeset
1591 {
6124
16fd7811effd [gaim-migrate @ 6598]
Mark Doliner <mark@kingant.net>
parents: 6066
diff changeset
1592 imhtml->show_comments = show;
4253
6c8ea04270e1 [gaim-migrate @ 4504]
Sean Egan <seanegan@gmail.com>
parents: 4201
diff changeset
1593 }
1780
d7cbedd1d651 [gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1738
diff changeset
1594
d7cbedd1d651 [gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1738
diff changeset
1595 void
d7cbedd1d651 [gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1738
diff changeset
1596 gtk_imhtml_clear (GtkIMHtml *imhtml)
d7cbedd1d651 [gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1738
diff changeset
1597 {
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1598 GtkTextIter start, end;
2993
7239a392486c [gaim-migrate @ 3006]
Rob Flynn <gaim@robflynn.com>
parents: 2982
diff changeset
1599
3922
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1600 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1601 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end);
30f52e7afd1d [gaim-migrate @ 4094]
Sean Egan <seanegan@gmail.com>
parents: 3717
diff changeset
1602 gtk_text_buffer_delete(imhtml->text_buffer, &start, &end);
1780
d7cbedd1d651 [gaim-migrate @ 1790]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1738
diff changeset
1603 }
2363
08c66712364c [gaim-migrate @ 2376]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2349
diff changeset
1604
4046
4a3f863b041f [gaim-migrate @ 4254]
Sean Egan <seanegan@gmail.com>
parents: 4041
diff changeset
1605 void gtk_imhtml_page_up (GtkIMHtml *imhtml)
4a3f863b041f [gaim-migrate @ 4254]
Sean Egan <seanegan@gmail.com>
parents: 4041
diff changeset
1606 {
5282
2d7f9a092b81 [gaim-migrate @ 5654]
Luke Schierer <lschiere@pidgin.im>
parents: 5177
diff changeset
1607 GdkRectangle rect;
2d7f9a092b81 [gaim-migrate @ 5654]
Luke Schierer <lschiere@pidgin.im>
parents: 5177
diff changeset
1608 GtkTextIter iter;
4046
4a3f863b041f [gaim-migrate @ 4254]
Sean Egan <seanegan@gmail.com>
parents: 4041
diff changeset
1609
5282
2d7f9a092b81 [gaim-migrate @ 5654]
Luke Schierer <lschiere@pidgin.im>
parents: 5177
diff changeset
1610 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect);
2d7f9a092b81 [gaim-migrate @ 5654]
Luke Schierer <lschiere@pidgin.im>
parents: 5177
diff changeset
1611 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(imhtml), &iter, rect.x,
2d7f9a092b81 [gaim-migrate @ 5654]
Luke Schierer <lschiere@pidgin.im>
parents: 5177
diff changeset
1612 rect.y - rect.height);
2d7f9a092b81 [gaim-migrate @ 5654]
Luke Schierer <lschiere@pidgin.im>
parents: 5177
diff changeset
1613 gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(imhtml), &iter, 0, TRUE, 0, 0);
2d7f9a092b81 [gaim-migrate @ 5654]
Luke Schierer <lschiere@pidgin.im>
parents: 5177
diff changeset
1614
4046
4a3f863b041f [gaim-migrate @ 4254]
Sean Egan <seanegan@gmail.com>
parents: 4041
diff changeset
1615 }
5282
2d7f9a092b81 [gaim-migrate @ 5654]
Luke Schierer <lschiere@pidgin.im>
parents: 5177
diff changeset
1616 void gtk_imhtml_page_down (GtkIMHtml *imhtml)
2d7f9a092b81 [gaim-migrate @ 5654]
Luke Schierer <lschiere@pidgin.im>
parents: 5177
diff changeset
1617 {
2d7f9a092b81 [gaim-migrate @ 5654]
Luke Schierer <lschiere@pidgin.im>
parents: 5177
diff changeset
1618 GdkRectangle rect;
2d7f9a092b81 [gaim-migrate @ 5654]
Luke Schierer <lschiere@pidgin.im>
parents: 5177
diff changeset
1619 GtkTextIter iter;
2d7f9a092b81 [gaim-migrate @ 5654]
Luke Schierer <lschiere@pidgin.im>
parents: 5177
diff changeset
1620
2d7f9a092b81 [gaim-migrate @ 5654]
Luke Schierer <lschiere@pidgin.im>
parents: 5177
diff changeset
1621 gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(imhtml), &rect);
2d7f9a092b81 [gaim-migrate @ 5654]
Luke Schierer <lschiere@pidgin.im>
parents: 5177
diff changeset
1622 gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(imhtml), &iter, rect.x,
2d7f9a092b81 [gaim-migrate @ 5654]
Luke Schierer <lschiere@pidgin.im>
parents: 5177
diff changeset
1623 rect.y + rect.height);
2d7f9a092b81 [gaim-migrate @ 5654]
Luke Schierer <lschiere@pidgin.im>
parents: 5177
diff changeset
1624 gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(imhtml), &iter, 0, TRUE, 0, 0);
2d7f9a092b81 [gaim-migrate @ 5654]
Luke Schierer <lschiere@pidgin.im>
parents: 5177
diff changeset
1625 }
4735
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
1626
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1627 /* GtkIMHtmlScalable, gtk_imhtml_image, gtk_imhtml_hr */
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
1628 GtkIMHtmlScalable *gtk_imhtml_image_new(GdkPixbuf *img, const gchar *filename)
4735
66c2388046fb [gaim-migrate @ 5050]
Sean Egan <seanegan@gmail.com>
parents: 4635
diff changeset
1629 {
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1630 GtkIMHtmlImage *im_image = g_malloc(sizeof(GtkIMHtmlImage));
5012
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1631 GtkImage *image = GTK_IMAGE(gtk_image_new_from_pixbuf(img));
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1632
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1633 GTK_IMHTML_SCALABLE(im_image)->scale = gtk_imhtml_image_scale;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1634 GTK_IMHTML_SCALABLE(im_image)->add_to = gtk_imhtml_image_add_to;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1635 GTK_IMHTML_SCALABLE(im_image)->free = gtk_imhtml_image_free;
5046
44945824ba60 [gaim-migrate @ 5394]
Nathan Walp <nwalp@pidgin.im>
parents: 5020
diff changeset
1636
44945824ba60 [gaim-migrate @ 5394]
Nathan Walp <nwalp@pidgin.im>
parents: 5020
diff changeset
1637 im_image->pixbuf = img;
5012
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1638 im_image->image = image;
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1639 im_image->width = gdk_pixbuf_get_width(img);
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1640 im_image->height = gdk_pixbuf_get_height(img);
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1641 im_image->mark = NULL;
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
1642 im_image->filename = filename ? g_strdup(filename) : NULL;
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1643
5046
44945824ba60 [gaim-migrate @ 5394]
Nathan Walp <nwalp@pidgin.im>
parents: 5020
diff changeset
1644 g_object_ref(img);
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1645 return GTK_IMHTML_SCALABLE(im_image);
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1646 }
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1647
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1648 void gtk_imhtml_image_scale(GtkIMHtmlScalable *scale, int width, int height)
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1649 {
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1650 GtkIMHtmlImage *image = (GtkIMHtmlImage *)scale;
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1651
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1652 if(image->width > width || image->height > height){
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1653 GdkPixbuf *new_image = NULL;
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1654 float factor;
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1655 int new_width = image->width, new_height = image->height;
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1656
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1657 if(image->width > width){
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1658 factor = (float)(width)/image->width;
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1659 new_width = width;
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1660 new_height = image->height * factor;
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1661 }
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1662 if(new_height > height){
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1663 factor = (float)(height)/new_height;
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1664 new_height = height;
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1665 new_width = new_width * factor;
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1666 }
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1667
5046
44945824ba60 [gaim-migrate @ 5394]
Nathan Walp <nwalp@pidgin.im>
parents: 5020
diff changeset
1668 new_image = gdk_pixbuf_scale_simple(image->pixbuf, new_width, new_height, GDK_INTERP_BILINEAR);
5012
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1669 gtk_image_set_from_pixbuf(image->image, new_image);
4895
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1670 g_object_unref(G_OBJECT(new_image));
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1671 }
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1672 }
9e50494f63a1 [gaim-migrate @ 5227]
Nathan Walp <nwalp@pidgin.im>
parents: 4892
diff changeset
1673
5012
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1674 static void write_img_to_file(GtkWidget *w, GtkFileSelection *sel)
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1675 {
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1676 const gchar *filename = gtk_file_selection_get_filename(sel);
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1677 gchar *dirname;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1678 GtkIMHtmlImage *image = g_object_get_data(G_OBJECT(sel), "GtkIMHtmlImage");
5012
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1679 gchar *type = NULL;
5019
eb1d45bffe66 [gaim-migrate @ 5355]
Luke Schierer <lschiere@pidgin.im>
parents: 5015
diff changeset
1680 GError *error = NULL;
5015
a17a84895585 [gaim-migrate @ 5351]
Nathan Walp <nwalp@pidgin.im>
parents: 5012
diff changeset
1681 #if GTK_CHECK_VERSION(2,2,0)
5012
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1682 GSList *formats = gdk_pixbuf_get_formats();
6162
7e967f2d6721 [gaim-migrate @ 6642]
Mark Doliner <mark@kingant.net>
parents: 6124
diff changeset
1683 #else
7e967f2d6721 [gaim-migrate @ 6642]
Mark Doliner <mark@kingant.net>
parents: 6124
diff changeset
1684 char *basename = g_path_get_basename(filename);
7e967f2d6721 [gaim-migrate @ 6642]
Mark Doliner <mark@kingant.net>
parents: 6124
diff changeset
1685 char *ext = strrchr(basename, '.');
5959
0a2a32b1917c [gaim-migrate @ 6405]
Mark Doliner <mark@kingant.net>
parents: 5582
diff changeset
1686 #endif
5012
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1687
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1688 if (g_file_test(filename, G_FILE_TEST_IS_DIR)) {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1689 /* append a / if needed */
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1690 if (filename[strlen(filename) - 1] != '/') {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1691 dirname = g_strconcat(filename, "/", NULL);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1692 } else {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1693 dirname = g_strdup(filename);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1694 }
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1695 gtk_file_selection_set_filename(sel, dirname);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1696 g_free(dirname);
5959
0a2a32b1917c [gaim-migrate @ 6405]
Mark Doliner <mark@kingant.net>
parents: 5582
diff changeset
1697 return;
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1698 }
5959
0a2a32b1917c [gaim-migrate @ 6405]
Mark Doliner <mark@kingant.net>
parents: 5582
diff changeset
1699
0a2a32b1917c [gaim-migrate @ 6405]
Mark Doliner <mark@kingant.net>
parents: 5582
diff changeset
1700 #if GTK_CHECK_VERSION(2,2,0)
5012
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1701 while(formats){
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1702 GdkPixbufFormat *format = formats->data;
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1703 gchar **extensions = gdk_pixbuf_format_get_extensions(format);
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1704 gpointer p = extensions;
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1705
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1706 while(gdk_pixbuf_format_is_writable(format) && extensions && extensions[0]){
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1707 gchar *fmt_ext = extensions[0];
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1708 const gchar* file_ext = filename + strlen(filename) - strlen(fmt_ext);
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1709
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1710 if(!strcmp(fmt_ext, file_ext)){
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1711 type = gdk_pixbuf_format_get_name(format);
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1712 break;
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1713 }
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1714
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1715 extensions++;
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1716 }
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1717
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1718 g_strfreev(p);
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1719
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1720 if(type)
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1721 break;
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1722
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1723 formats = formats->next;
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1724 }
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1725
5020
29c87c6e75d9 [gaim-migrate @ 5356]
Nathan Walp <nwalp@pidgin.im>
parents: 5019
diff changeset
1726 g_slist_free(formats);
29c87c6e75d9 [gaim-migrate @ 5356]
Nathan Walp <nwalp@pidgin.im>
parents: 5019
diff changeset
1727 #else
29c87c6e75d9 [gaim-migrate @ 5356]
Nathan Walp <nwalp@pidgin.im>
parents: 5019
diff changeset
1728 /* this is really ugly code, but I think it will work */
29c87c6e75d9 [gaim-migrate @ 5356]
Nathan Walp <nwalp@pidgin.im>
parents: 5019
diff changeset
1729 if(ext) {
29c87c6e75d9 [gaim-migrate @ 5356]
Nathan Walp <nwalp@pidgin.im>
parents: 5019
diff changeset
1730 ext++;
29c87c6e75d9 [gaim-migrate @ 5356]
Nathan Walp <nwalp@pidgin.im>
parents: 5019
diff changeset
1731 if(!g_ascii_strcasecmp(ext, "jpeg") || !g_ascii_strcasecmp(ext, "jpg"))
29c87c6e75d9 [gaim-migrate @ 5356]
Nathan Walp <nwalp@pidgin.im>
parents: 5019
diff changeset
1732 type = g_strdup("jpeg");
29c87c6e75d9 [gaim-migrate @ 5356]
Nathan Walp <nwalp@pidgin.im>
parents: 5019
diff changeset
1733 else if(!g_ascii_strcasecmp(ext, "png"))
29c87c6e75d9 [gaim-migrate @ 5356]
Nathan Walp <nwalp@pidgin.im>
parents: 5019
diff changeset
1734 type = g_strdup("png");
29c87c6e75d9 [gaim-migrate @ 5356]
Nathan Walp <nwalp@pidgin.im>
parents: 5019
diff changeset
1735 }
29c87c6e75d9 [gaim-migrate @ 5356]
Nathan Walp <nwalp@pidgin.im>
parents: 5019
diff changeset
1736
29c87c6e75d9 [gaim-migrate @ 5356]
Nathan Walp <nwalp@pidgin.im>
parents: 5019
diff changeset
1737 g_free(basename);
29c87c6e75d9 [gaim-migrate @ 5356]
Nathan Walp <nwalp@pidgin.im>
parents: 5019
diff changeset
1738 #endif
29c87c6e75d9 [gaim-migrate @ 5356]
Nathan Walp <nwalp@pidgin.im>
parents: 5019
diff changeset
1739
5012
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1740 /* If I can't find a valid type, I will just tell the user about it and then assume
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1741 it's a png */
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1742 if(!type){
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1743 gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1744 _("Unable to guess the image type based on the file extension supplied. Defaulting to PNG."));
5012
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1745 type = g_strdup("png");
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1746 }
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1747
5046
44945824ba60 [gaim-migrate @ 5394]
Nathan Walp <nwalp@pidgin.im>
parents: 5020
diff changeset
1748 gdk_pixbuf_save(image->pixbuf, filename, type, &error, NULL);
5012
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1749
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1750 if(error){
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1751 gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1752 _("Error saving image: %s"), error->message);
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1753 g_error_free(error);
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1754 }
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1755
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1756 g_free(type);
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1757 }
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1758
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1759 static void gtk_imhtml_image_save(GtkWidget *w, GtkIMHtmlImage *image)
5012
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1760 {
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1761 GtkWidget *sel = gtk_file_selection_new(_("Save Image"));
5012
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1762
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
1763 if (image->filename)
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
1764 gtk_file_selection_set_filename(GTK_FILE_SELECTION(sel), image->filename);
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1765 g_object_set_data(G_OBJECT(sel), "GtkIMHtmlImage", image);
5012
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1766 g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(sel)->ok_button), "clicked",
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1767 G_CALLBACK(write_img_to_file), sel);
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1768
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1769 g_signal_connect_swapped(G_OBJECT(GTK_FILE_SELECTION(sel)->ok_button), "clicked",
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1770 G_CALLBACK(gtk_widget_destroy), sel);
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1771 g_signal_connect_swapped(G_OBJECT(GTK_FILE_SELECTION(sel)->cancel_button), "clicked",
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1772 G_CALLBACK(gtk_widget_destroy), sel);
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1773
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1774 gtk_widget_show(sel);
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1775 }
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1776
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1777 static gboolean gtk_imhtml_image_clicked(GtkWidget *w, GdkEvent *event, GtkIMHtmlImage *image)
5012
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1778 {
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1779 GdkEventButton *event_button = (GdkEventButton *) event;
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1780
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1781 if (event->type == GDK_BUTTON_RELEASE) {
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1782 if(event_button->button == 3) {
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1783 GtkWidget *img, *item, *menu;
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1784 gchar *text = g_strdup_printf(_("_Save Image..."));
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1785 menu = gtk_menu_new();
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1786
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1787 /* buttons and such */
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1788 img = gtk_image_new_from_stock(GTK_STOCK_SAVE, GTK_ICON_SIZE_MENU);
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1789 item = gtk_image_menu_item_new_with_mnemonic(text);
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1790 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), img);
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1791 g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(gtk_imhtml_image_save), image);
5012
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1792 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1793
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1794 gtk_widget_show_all(menu);
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1795 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL,
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1796 event_button->button, event_button->time);
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1797
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1798 g_free(text);
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1799 return TRUE;
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1800 }
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1801 }
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1802 if(event->type == GDK_BUTTON_PRESS && event_button->button == 3)
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1803 return TRUE; /* Clicking the right mouse button on a link shouldn't
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1804 be caught by the regular GtkTextView menu */
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1805 else
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1806 return FALSE; /* Let clicks go through if we didn't catch anything */
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1807
3ee1b1409660 [gaim-migrate @ 5348]
Nathan Walp <nwalp@pidgin.im>
parents: 4997
diff changeset
1808 }
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1809 void gtk_imhtml_image_free(GtkIMHtmlScalable *scale)
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1810 {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1811 GtkIMHtmlImage *image = (GtkIMHtmlImage *)scale;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1812
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1813 g_object_unref(image->pixbuf);
6982
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
1814 if (image->filename)
083d1e4a9c78 [gaim-migrate @ 7538]
Mark Doliner <mark@kingant.net>
parents: 6882
diff changeset
1815 g_free(image->filename);
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1816 g_free(scale);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1817 }
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1818
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1819 void gtk_imhtml_image_add_to(GtkIMHtmlScalable *scale, GtkIMHtml *imhtml, GtkTextIter *iter)
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1820 {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1821 GtkIMHtmlImage *image = (GtkIMHtmlImage *)scale;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1822 GtkWidget *box = gtk_event_box_new();
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1823 GtkTextChildAnchor *anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, iter);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1824
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1825 gtk_container_add(GTK_CONTAINER(box), GTK_WIDGET(image->image));
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1826
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1827 gtk_widget_show(GTK_WIDGET(image->image));
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1828 gtk_widget_show(box);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1829
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1830 gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(imhtml), box, anchor);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1831 g_signal_connect(G_OBJECT(box), "event", G_CALLBACK(gtk_imhtml_image_clicked), image);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1832 }
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1833
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1834 GtkIMHtmlScalable *gtk_imhtml_hr_new()
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1835 {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1836 GtkIMHtmlHr *hr = g_malloc(sizeof(GtkIMHtmlHr));
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1837
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1838 GTK_IMHTML_SCALABLE(hr)->scale = gtk_imhtml_hr_scale;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1839 GTK_IMHTML_SCALABLE(hr)->add_to = gtk_imhtml_hr_add_to;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1840 GTK_IMHTML_SCALABLE(hr)->free = gtk_imhtml_hr_free;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1841
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1842 hr->sep = gtk_hseparator_new();
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1843 gtk_widget_set_size_request(hr->sep, 5000, 2);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1844 gtk_widget_show(hr->sep);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1845
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1846 return GTK_IMHTML_SCALABLE(hr);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1847 }
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1848
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1849 void gtk_imhtml_hr_scale(GtkIMHtmlScalable *scale, int width, int height)
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1850 {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1851 gtk_widget_set_size_request(((GtkIMHtmlHr *)scale)->sep, width, 2);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1852 }
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1853
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1854 void gtk_imhtml_hr_add_to(GtkIMHtmlScalable *scale, GtkIMHtml *imhtml, GtkTextIter *iter)
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1855 {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1856 GtkIMHtmlHr *hr = (GtkIMHtmlHr *)scale;
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1857 GtkTextChildAnchor *anchor = gtk_text_buffer_create_child_anchor(imhtml->text_buffer, iter);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1858
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1859 gtk_text_view_add_child_at_anchor(GTK_TEXT_VIEW(imhtml), hr->sep, anchor);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1860 }
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1861
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1862 void gtk_imhtml_hr_free(GtkIMHtmlScalable *scale)
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1863 {
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1864 g_free(scale);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
1865 }
7295
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
1866
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
1867 gboolean gtk_imhtml_search_find(GtkIMHtml *imhtml, const gchar *text)
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
1868 {
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
1869 GtkTextIter iter, start, end;
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
1870 gboolean new_search = TRUE;
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
1871
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
1872 g_return_val_if_fail(imhtml != NULL, FALSE);
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
1873 g_return_val_if_fail(text != NULL, FALSE);
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
1874
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
1875 if (imhtml->search_string && !strcmp(text, imhtml->search_string))
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
1876 new_search = FALSE;
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
1877
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
1878
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
1879 if (new_search) {
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
1880 gtk_imhtml_search_clear(imhtml);
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
1881 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &iter);
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
1882 } else {
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
1883 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter,
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
1884 gtk_text_buffer_get_mark(imhtml->text_buffer, "search"));
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
1885 }
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
1886 imhtml->search_string = g_strdup(text);
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
1887
7358
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents: 7354
diff changeset
1888 if (gtk_source_iter_forward_search(&iter, imhtml->search_string,
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents: 7354
diff changeset
1889 GTK_SOURCE_SEARCH_VISIBLE_ONLY | GTK_SOURCE_SEARCH_CASE_INSENSITIVE,
7295
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
1890 &start, &end, NULL)) {
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
1891
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
1892 gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(imhtml), &start, 0, TRUE, 0, 0);
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
1893 gtk_text_buffer_create_mark(imhtml->text_buffer, "search", &end, FALSE);
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
1894 if (new_search) {
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
1895 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "search", &iter, &end);
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
1896 do
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
1897 gtk_text_buffer_apply_tag_by_name(imhtml->text_buffer, "search", &start, &end);
7358
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents: 7354
diff changeset
1898 while (gtk_source_iter_forward_search(&end, imhtml->search_string,
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents: 7354
diff changeset
1899 GTK_SOURCE_SEARCH_VISIBLE_ONLY |
78c1fc730dc4 [gaim-migrate @ 7951]
Sean Egan <seanegan@gmail.com>
parents: 7354
diff changeset
1900 GTK_SOURCE_SEARCH_CASE_INSENSITIVE,
7295
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
1901 &start, &end, NULL));
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
1902 }
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
1903 return TRUE;
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
1904 }
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
1905 return FALSE;
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
1906 }
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
1907
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
1908 void gtk_imhtml_search_clear(GtkIMHtml *imhtml)
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
1909 {
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
1910 GtkTextIter start, end;
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
1911
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
1912 g_return_if_fail(imhtml != NULL);
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
1913
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
1914 gtk_text_buffer_get_start_iter(imhtml->text_buffer, &start);
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
1915 gtk_text_buffer_get_end_iter(imhtml->text_buffer, &end);
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
1916
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
1917 gtk_text_buffer_remove_tag_by_name(imhtml->text_buffer, "search", &start, &end);
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
1918 if (imhtml->search_string)
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
1919 g_free(imhtml->search_string);
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
1920 imhtml->search_string = NULL;
c7f0a4397d9e [gaim-migrate @ 7879]
Sean Egan <seanegan@gmail.com>
parents: 7287
diff changeset
1921 }