Mercurial > pidgin
annotate src/gtkimhtml.c @ 1671:86c71ca7c90f
[gaim-migrate @ 1681]
if you want
to destroy
my sweater
pull this thread
as i walk
away
watch me unravel
i'll soon
be naked
lying on the floor
i've come
undone
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Fri, 30 Mar 2001 23:08:50 +0000 |
parents | 23b734cf1161 |
children | d802b115800f |
rev | line source |
---|---|
1428 | 1 /* |
2 * GtkIMHtml | |
3 * | |
4 * Copyright (C) 2000, Eric Warmenhoven <warmenhoven@yahoo.com> | |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 * | |
20 */ | |
21 | |
22 #include "gtkimhtml.h" | |
23 #include <gtk/gtk.h> | |
24 #include <string.h> | |
25 #include <ctype.h> | |
26 #include <stdio.h> | |
27 #include <math.h> | |
28 | |
29 #include "pixmaps/angel.xpm" | |
30 #include "pixmaps/bigsmile.xpm" | |
31 #include "pixmaps/burp.xpm" | |
32 #include "pixmaps/crossedlips.xpm" | |
33 #include "pixmaps/cry.xpm" | |
34 #include "pixmaps/embarrassed.xpm" | |
35 #include "pixmaps/kiss.xpm" | |
36 #include "pixmaps/moneymouth.xpm" | |
37 #include "pixmaps/sad.xpm" | |
38 #include "pixmaps/scream.xpm" | |
39 #include "pixmaps/smile.xpm" | |
40 #include "pixmaps/smile8.xpm" | |
41 #include "pixmaps/think.xpm" | |
42 #include "pixmaps/tongue.xpm" | |
43 #include "pixmaps/wink.xpm" | |
44 #include "pixmaps/yell.xpm" | |
45 | |
46 #define DEFAULT_FONT_NAME "helvetica" | |
47 #define MAX_SIZE 7 | |
48 | |
49 gint font_sizes [] = { 80, 100, 120, 140, 200, 300, 400 }; | |
50 | |
51 #define BORDER_SIZE 3 | |
52 #define MIN_HEIGHT 20 | |
53 #define HR_HEIGHT 2 | |
1574
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
54 #define TOOLTIP_TIMEOUT 500 |
1428 | 55 |
1460
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
56 #define DIFF(a, b) (((a) > (b)) ? ((a) - (b)) : ((b) - (a))) |
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
57 #define COLOR_MOD 0x8000 |
1647
23b734cf1161
[gaim-migrate @ 1657]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1626
diff
changeset
|
58 #define COLOR_DIFF 0x800 |
1460
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
59 |
1428 | 60 #define TYPE_TEXT 0 |
61 #define TYPE_SMILEY 1 | |
62 #define TYPE_IMG 2 | |
63 #define TYPE_SEP 3 | |
64 #define TYPE_BR 4 | |
65 #define TYPE_COMMENT 5 | |
66 | |
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
67 #define DRAW_IMG(x) (((x)->type == TYPE_IMG) || (imhtml->smileys && ((x)->type == TYPE_SMILEY))) |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
68 |
1428 | 69 typedef struct _GtkIMHtmlBit GtkIMHtmlBit; |
70 typedef struct _FontDetail FontDetail; | |
71 | |
72 struct _GtkIMHtmlBit { | |
73 gint type; | |
74 | |
75 gchar *text; | |
76 GdkPixmap *pm; | |
77 GdkBitmap *bm; | |
78 | |
79 GdkFont *font; | |
80 GdkColor *fore; | |
81 GdkColor *back; | |
82 GdkColor *bg; | |
83 gboolean underline; | |
84 gboolean strike; | |
85 gchar *url; | |
86 | |
87 GList *chunks; | |
88 }; | |
89 | |
90 struct _FontDetail { | |
91 gushort size; | |
92 gchar *face; | |
93 GdkColor *fore; | |
94 GdkColor *back; | |
95 }; | |
96 | |
97 struct line_info { | |
98 gint x; | |
99 gint y; | |
100 gint width; | |
101 gint height; | |
102 gint ascent; | |
103 | |
104 gboolean selected; | |
105 gchar *sel_start; | |
106 gchar *sel_end; | |
107 | |
108 gchar *text; | |
109 GtkIMHtmlBit *bit; | |
110 }; | |
111 | |
112 struct url_widget { | |
113 gint x; | |
114 gint y; | |
115 gint width; | |
116 gint height; | |
1574
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
117 GtkIMHtmlBit *bit; |
1428 | 118 }; |
119 | |
120 static GtkLayoutClass *parent_class = NULL; | |
121 | |
122 enum { | |
123 TARGET_STRING, | |
124 TARGET_TEXT, | |
125 TARGET_COMPOUND_TEXT | |
126 }; | |
127 | |
128 enum { | |
129 URL_CLICKED, | |
130 LAST_SIGNAL | |
131 }; | |
132 static guint signals [LAST_SIGNAL] = { 0 }; | |
133 | |
134 static void gtk_imhtml_draw_bit (GtkIMHtml *, GtkIMHtmlBit *); | |
135 static GdkColor *gtk_imhtml_get_color (const gchar *); | |
136 static gint gtk_imhtml_motion_notify_event (GtkWidget *, GdkEventMotion *); | |
137 | |
138 static void | |
139 gtk_imhtml_destroy (GtkObject *object) | |
140 { | |
141 GtkIMHtml *imhtml; | |
142 | |
143 imhtml = GTK_IMHTML (object); | |
144 | |
145 while (imhtml->bits) { | |
146 GtkIMHtmlBit *bit = imhtml->bits->data; | |
147 imhtml->bits = g_list_remove (imhtml->bits, bit); | |
148 if (bit->text) | |
149 g_free (bit->text); | |
150 if (bit->font) | |
151 gdk_font_unref (bit->font); | |
152 if (bit->fore) | |
153 gdk_color_free (bit->fore); | |
154 if (bit->back) | |
155 gdk_color_free (bit->back); | |
156 if (bit->bg) | |
157 gdk_color_free (bit->bg); | |
158 if (bit->url) | |
159 g_free (bit->url); | |
160 if (bit->pm) | |
161 gdk_pixmap_unref (bit->pm); | |
162 if (bit->bm) | |
163 gdk_bitmap_unref (bit->bm); | |
164 while (bit->chunks) { | |
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
165 struct line_info *li = bit->chunks->data; |
1428 | 166 if (li->text) |
167 g_free (li->text); | |
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
168 bit->chunks = g_list_remove (bit->chunks, li); |
1428 | 169 g_free (li); |
170 } | |
171 g_free (bit); | |
172 } | |
173 | |
174 while (imhtml->urls) { | |
175 g_free (imhtml->urls->data); | |
176 imhtml->urls = g_list_remove (imhtml->urls, imhtml->urls->data); | |
177 } | |
178 | |
179 if (imhtml->selected_text) | |
180 g_string_free (imhtml->selected_text, TRUE); | |
181 | |
182 gdk_font_unref (imhtml->default_font); | |
183 gdk_color_free (imhtml->default_fg_color); | |
1460
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
184 gdk_color_free (imhtml->default_bg_color); |
1428 | 185 |
186 gdk_cursor_destroy (imhtml->hand_cursor); | |
187 gdk_cursor_destroy (imhtml->arrow_cursor); | |
188 | |
189 g_hash_table_destroy (imhtml->smiley_hash); | |
1519
d3ff7d80b8fb
[gaim-migrate @ 1529]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1515
diff
changeset
|
190 if (imhtml->smiley_start) |
d3ff7d80b8fb
[gaim-migrate @ 1529]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1515
diff
changeset
|
191 g_string_free (imhtml->smiley_start, TRUE); |
1428 | 192 |
193 if (GTK_OBJECT_CLASS (parent_class)->destroy != NULL) | |
194 (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); | |
195 } | |
196 | |
197 static void | |
198 gtk_imhtml_realize (GtkWidget *widget) | |
199 { | |
200 GtkIMHtml *imhtml; | |
201 | |
202 g_return_if_fail (widget != NULL); | |
203 g_return_if_fail (GTK_IS_IMHTML (widget)); | |
204 | |
205 imhtml = GTK_IMHTML (widget); | |
206 | |
207 if (GTK_WIDGET_CLASS (parent_class)->realize) | |
208 (* GTK_WIDGET_CLASS (parent_class)->realize) (widget); | |
209 | |
210 widget->style = gtk_style_attach (widget->style, widget->window); | |
1476
721cd9b73704
[gaim-migrate @ 1486]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1473
diff
changeset
|
211 gdk_window_set_events (GTK_LAYOUT (imhtml)->bin_window, |
721cd9b73704
[gaim-migrate @ 1486]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1473
diff
changeset
|
212 (gdk_window_get_events (GTK_LAYOUT (imhtml)->bin_window) |
1428 | 213 | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
1613
35a13ece3a9c
[gaim-migrate @ 1623]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1582
diff
changeset
|
214 | GDK_POINTER_MOTION_MASK | GDK_EXPOSURE_MASK | GDK_LEAVE_NOTIFY_MASK)); |
1428 | 215 |
216 gdk_window_set_cursor (widget->window, imhtml->arrow_cursor); | |
217 | |
1476
721cd9b73704
[gaim-migrate @ 1486]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1473
diff
changeset
|
218 gdk_color_alloc (gtk_widget_get_colormap (widget), imhtml->default_bg_color); |
1460
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
219 gdk_window_set_background (GTK_LAYOUT (imhtml)->bin_window, imhtml->default_bg_color); |
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
220 } |
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
221 |
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
222 static gboolean |
1476
721cd9b73704
[gaim-migrate @ 1486]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1473
diff
changeset
|
223 similar_colors (GdkColor *bg, |
1460
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
224 GdkColor *fg) |
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
225 { |
1476
721cd9b73704
[gaim-migrate @ 1486]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1473
diff
changeset
|
226 if ((DIFF (bg->red, fg->red) < COLOR_DIFF) && |
721cd9b73704
[gaim-migrate @ 1486]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1473
diff
changeset
|
227 (DIFF (bg->green, fg->green) < COLOR_DIFF) && |
721cd9b73704
[gaim-migrate @ 1486]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1473
diff
changeset
|
228 (DIFF (bg->blue, fg->blue) < COLOR_DIFF)) { |
721cd9b73704
[gaim-migrate @ 1486]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1473
diff
changeset
|
229 fg->red = (0xff00 - COLOR_MOD > bg->red) ? |
721cd9b73704
[gaim-migrate @ 1486]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1473
diff
changeset
|
230 bg->red + COLOR_MOD : bg->red - COLOR_MOD; |
721cd9b73704
[gaim-migrate @ 1486]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1473
diff
changeset
|
231 fg->green = (0xff00 - COLOR_MOD > bg->green) ? |
721cd9b73704
[gaim-migrate @ 1486]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1473
diff
changeset
|
232 bg->green + COLOR_MOD : bg->green - COLOR_MOD; |
721cd9b73704
[gaim-migrate @ 1486]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1473
diff
changeset
|
233 fg->blue = (0xff00 - COLOR_MOD > bg->blue) ? |
721cd9b73704
[gaim-migrate @ 1486]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1473
diff
changeset
|
234 bg->blue + COLOR_MOD : bg->blue - COLOR_MOD; |
1460
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
235 return TRUE; |
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
236 } |
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
237 return FALSE; |
1428 | 238 } |
239 | |
240 static void | |
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
241 draw_text (GtkIMHtml *imhtml, |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
242 struct line_info *line) |
1428 | 243 { |
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
244 GtkIMHtmlBit *bit; |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
245 GdkGC *gc; |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
246 GdkColormap *cmap; |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
247 GdkWindow *window = GTK_LAYOUT (imhtml)->bin_window; |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
248 gfloat xoff, yoff; |
1476
721cd9b73704
[gaim-migrate @ 1486]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1473
diff
changeset
|
249 GdkColor *bg, *fg; |
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
250 |
1515
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
251 if (GTK_LAYOUT (imhtml)->freeze_count) |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
252 return; |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
253 |
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
254 bit = line->bit; |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
255 gc = gdk_gc_new (window); |
1476
721cd9b73704
[gaim-migrate @ 1486]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1473
diff
changeset
|
256 cmap = gtk_widget_get_colormap (GTK_WIDGET (imhtml)); |
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
257 xoff = GTK_LAYOUT (imhtml)->hadjustment->value; |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
258 yoff = GTK_LAYOUT (imhtml)->vadjustment->value; |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
259 |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
260 if (bit->bg != NULL) { |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
261 gdk_color_alloc (cmap, bit->bg); |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
262 gdk_gc_set_foreground (gc, bit->bg); |
1476
721cd9b73704
[gaim-migrate @ 1486]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1473
diff
changeset
|
263 bg = bit->bg; |
1460
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
264 } else { |
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
265 gdk_color_alloc (cmap, imhtml->default_bg_color); |
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
266 gdk_gc_set_foreground (gc, imhtml->default_bg_color); |
1476
721cd9b73704
[gaim-migrate @ 1486]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1473
diff
changeset
|
267 bg = imhtml->default_bg_color; |
1460
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
268 } |
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
269 |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
270 gdk_draw_rectangle (window, gc, TRUE, line->x - xoff, line->y - yoff, line->width, line->height); |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
271 |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
272 if (!line->text) { |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
273 gdk_gc_unref (gc); |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
274 return; |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
275 } |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
276 |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
277 if (bit->back != NULL) { |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
278 gdk_color_alloc (cmap, bit->back); |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
279 gdk_gc_set_foreground (gc, bit->back); |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
280 gdk_draw_rectangle (window, gc, TRUE, line->x - xoff, line->y - yoff, |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
281 gdk_string_width (bit->font, line->text), line->height); |
1476
721cd9b73704
[gaim-migrate @ 1486]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1473
diff
changeset
|
282 bg = bit->back; |
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
283 } |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
284 |
1476
721cd9b73704
[gaim-migrate @ 1486]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1473
diff
changeset
|
285 bg = gdk_color_copy (bg); |
1460
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
286 |
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
287 if (line->selected) { |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
288 gint width, x; |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
289 gchar *start, *end; |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
290 GdkColor col; |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
291 |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
292 if ((line->sel_start > line->sel_end) && (line->sel_end != NULL)) { |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
293 start = line->sel_end; |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
294 end = line->sel_start; |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
295 } else { |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
296 start = line->sel_start; |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
297 end = line->sel_end; |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
298 } |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
299 |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
300 if (start == NULL) |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
301 x = 0; |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
302 else |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
303 x = gdk_text_width (bit->font, line->text, start - line->text); |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
304 |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
305 if (end == NULL) |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
306 width = gdk_string_width (bit->font, line->text) - x; |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
307 else |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
308 width = gdk_text_width (bit->font, line->text, end - line->text) - x; |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
309 |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
310 col.red = col.green = col.blue = 0xc000; |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
311 gdk_color_alloc (cmap, &col); |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
312 gdk_gc_set_foreground (gc, &col); |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
313 |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
314 gdk_draw_rectangle (window, gc, TRUE, x + line->x - xoff, line->y - yoff, |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
315 width, line->height); |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
316 } |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
317 |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
318 if (bit->url) { |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
319 GdkColor *tc = gtk_imhtml_get_color ("#0000a0"); |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
320 gdk_color_alloc (cmap, tc); |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
321 gdk_gc_set_foreground (gc, tc); |
1476
721cd9b73704
[gaim-migrate @ 1486]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1473
diff
changeset
|
322 fg = gdk_color_copy (tc); |
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
323 gdk_color_free (tc); |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
324 } else if (bit->fore) { |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
325 gdk_color_alloc (cmap, bit->fore); |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
326 gdk_gc_set_foreground (gc, bit->fore); |
1476
721cd9b73704
[gaim-migrate @ 1486]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1473
diff
changeset
|
327 fg = gdk_color_copy (bit->fore); |
1460
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
328 } else { |
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
329 gdk_color_alloc (cmap, imhtml->default_fg_color); |
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
330 gdk_gc_set_foreground (gc, imhtml->default_fg_color); |
1476
721cd9b73704
[gaim-migrate @ 1486]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1473
diff
changeset
|
331 fg = gdk_color_copy (imhtml->default_fg_color); |
1460
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
332 } |
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
333 |
1476
721cd9b73704
[gaim-migrate @ 1486]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1473
diff
changeset
|
334 if (similar_colors (bg, fg)) { |
721cd9b73704
[gaim-migrate @ 1486]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1473
diff
changeset
|
335 gdk_color_alloc (cmap, fg); |
721cd9b73704
[gaim-migrate @ 1486]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1473
diff
changeset
|
336 gdk_gc_set_foreground (gc, fg); |
1460
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
337 } |
1476
721cd9b73704
[gaim-migrate @ 1486]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1473
diff
changeset
|
338 gdk_color_free (bg); |
721cd9b73704
[gaim-migrate @ 1486]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1473
diff
changeset
|
339 gdk_color_free (fg); |
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
340 |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
341 gdk_draw_string (window, bit->font, gc, line->x - xoff, |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
342 line->y - yoff + line->ascent, line->text); |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
343 |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
344 if (bit->underline || bit->url) |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
345 gdk_draw_rectangle (window, gc, TRUE, line->x - xoff, line->y - yoff + line->ascent + 1, |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
346 gdk_string_width (bit->font, line->text), 1); |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
347 if (bit->strike) |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
348 gdk_draw_rectangle (window, gc, TRUE, line->x - xoff, |
1476
721cd9b73704
[gaim-migrate @ 1486]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1473
diff
changeset
|
349 line->y - yoff + line->ascent - (bit->font->ascent / 2), |
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
350 gdk_string_width (bit->font, line->text), 1); |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
351 |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
352 gdk_gc_unref (gc); |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
353 } |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
354 |
1515
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
355 static void |
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
356 draw_img (GtkIMHtml *imhtml, |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
357 struct line_info *line) |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
358 { |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
359 GtkIMHtmlBit *bit; |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
360 GdkGC *gc; |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
361 GdkColormap *cmap; |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
362 gint width, height, hoff; |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
363 GdkWindow *window = GTK_LAYOUT (imhtml)->bin_window; |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
364 gfloat xoff, yoff; |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
365 |
1515
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
366 if (GTK_LAYOUT (imhtml)->freeze_count) |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
367 return; |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
368 |
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
369 bit = line->bit; |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
370 gdk_window_get_size (bit->pm, &width, &height); |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
371 hoff = (line->height - height) / 2; |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
372 xoff = GTK_LAYOUT (imhtml)->hadjustment->value; |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
373 yoff = GTK_LAYOUT (imhtml)->vadjustment->value; |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
374 gc = gdk_gc_new (window); |
1476
721cd9b73704
[gaim-migrate @ 1486]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1473
diff
changeset
|
375 cmap = gtk_widget_get_colormap (GTK_WIDGET (imhtml)); |
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
376 |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
377 if (bit->bg != NULL) { |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
378 gdk_color_alloc (cmap, bit->bg); |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
379 gdk_gc_set_foreground (gc, bit->bg); |
1460
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
380 } else { |
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
381 gdk_color_alloc (cmap, imhtml->default_bg_color); |
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
382 gdk_gc_set_foreground (gc, imhtml->default_bg_color); |
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
383 } |
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
384 |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
385 gdk_draw_rectangle (window, gc, TRUE, line->x - xoff, line->y - yoff, line->width, line->height); |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
386 |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
387 if (bit->back != NULL) { |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
388 gdk_color_alloc (cmap, bit->back); |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
389 gdk_gc_set_foreground (gc, bit->back); |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
390 gdk_draw_rectangle (window, gc, TRUE, line->x - xoff, line->y - yoff, |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
391 width, line->height); |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
392 } |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
393 |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
394 gdk_draw_pixmap (window, gc, bit->pm, 0, 0, line->x - xoff, line->y - yoff + hoff, -1, -1); |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
395 |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
396 gdk_gc_unref (gc); |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
397 } |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
398 |
1515
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
399 static void |
1454
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
400 draw_line (GtkIMHtml *imhtml, |
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
401 struct line_info *line) |
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
402 { |
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
403 GtkIMHtmlBit *bit; |
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
404 GdkDrawable *drawable; |
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
405 GdkColormap *cmap; |
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
406 GdkGC *gc; |
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
407 guint line_height; |
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
408 gfloat xoff, yoff; |
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
409 |
1515
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
410 if (GTK_LAYOUT (imhtml)->freeze_count) |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
411 return; |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
412 |
1454
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
413 xoff = GTK_LAYOUT (imhtml)->hadjustment->value; |
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
414 yoff = GTK_LAYOUT (imhtml)->vadjustment->value; |
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
415 bit = line->bit; |
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
416 drawable = GTK_LAYOUT (imhtml)->bin_window; |
1476
721cd9b73704
[gaim-migrate @ 1486]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1473
diff
changeset
|
417 cmap = gtk_widget_get_colormap (GTK_WIDGET (imhtml)); |
1454
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
418 gc = gdk_gc_new (drawable); |
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
419 |
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
420 if (bit->bg != NULL) { |
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
421 gdk_color_alloc (cmap, bit->bg); |
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
422 gdk_gc_set_foreground (gc, bit->bg); |
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
423 |
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
424 gdk_draw_rectangle (drawable, gc, TRUE, line->x - xoff, line->y - yoff, |
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
425 line->width, line->height); |
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
426 } |
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
427 |
1460
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
428 gdk_color_alloc (cmap, imhtml->default_fg_color); |
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
429 gdk_gc_set_foreground (gc, imhtml->default_fg_color); |
1454
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
430 |
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
431 line_height = line->height / 2; |
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
432 |
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
433 gdk_draw_rectangle (drawable, gc, TRUE, line->x - xoff, line->y - yoff + line_height / 2, |
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
434 line->width, line_height); |
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
435 |
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
436 gdk_gc_unref (gc); |
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
437 } |
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
438 |
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
439 static void |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
440 gtk_imhtml_draw_exposed (GtkIMHtml *imhtml) |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
441 { |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
442 GList *bits; |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
443 GtkIMHtmlBit *bit; |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
444 GList *chunks; |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
445 struct line_info *line; |
1454
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
446 gfloat x, y; |
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
447 guint32 width, height; |
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
448 |
1454
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
449 x = GTK_LAYOUT (imhtml)->hadjustment->value; |
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
450 y = GTK_LAYOUT (imhtml)->vadjustment->value; |
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
451 width = GTK_WIDGET (imhtml)->allocation.width; |
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
452 height = GTK_WIDGET (imhtml)->allocation.height; |
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
453 |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
454 bits = imhtml->bits; |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
455 |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
456 while (bits) { |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
457 bit = bits->data; |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
458 chunks = bit->chunks; |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
459 if (DRAW_IMG (bit)) { |
1461
9774a0a304c4
[gaim-migrate @ 1471]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1460
diff
changeset
|
460 if (chunks) { |
9774a0a304c4
[gaim-migrate @ 1471]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1460
diff
changeset
|
461 line = chunks->data; |
9774a0a304c4
[gaim-migrate @ 1471]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1460
diff
changeset
|
462 if ((line->x <= x + width) && |
9774a0a304c4
[gaim-migrate @ 1471]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1460
diff
changeset
|
463 (line->y <= y + height) && |
9774a0a304c4
[gaim-migrate @ 1471]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1460
diff
changeset
|
464 (x <= line->x + line->width) && |
9774a0a304c4
[gaim-migrate @ 1471]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1460
diff
changeset
|
465 (y <= line->y + line->height)) |
9774a0a304c4
[gaim-migrate @ 1471]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1460
diff
changeset
|
466 draw_img (imhtml, line); |
9774a0a304c4
[gaim-migrate @ 1471]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1460
diff
changeset
|
467 } |
1454
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
468 } else if (bit->type == TYPE_SEP) { |
1461
9774a0a304c4
[gaim-migrate @ 1471]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1460
diff
changeset
|
469 if (chunks) { |
9774a0a304c4
[gaim-migrate @ 1471]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1460
diff
changeset
|
470 line = chunks->data; |
9774a0a304c4
[gaim-migrate @ 1471]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1460
diff
changeset
|
471 if ((line->x <= x + width) && |
9774a0a304c4
[gaim-migrate @ 1471]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1460
diff
changeset
|
472 (line->y <= y + height) && |
9774a0a304c4
[gaim-migrate @ 1471]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1460
diff
changeset
|
473 (x <= line->x + line->width) && |
9774a0a304c4
[gaim-migrate @ 1471]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1460
diff
changeset
|
474 (y <= line->y + line->height)) |
9774a0a304c4
[gaim-migrate @ 1471]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1460
diff
changeset
|
475 draw_line (imhtml, line); |
9774a0a304c4
[gaim-migrate @ 1471]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1460
diff
changeset
|
476 |
9774a0a304c4
[gaim-migrate @ 1471]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1460
diff
changeset
|
477 line = chunks->next->data; |
9774a0a304c4
[gaim-migrate @ 1471]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1460
diff
changeset
|
478 if ((line->x <= x + width) && |
9774a0a304c4
[gaim-migrate @ 1471]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1460
diff
changeset
|
479 (line->y <= y + height) && |
9774a0a304c4
[gaim-migrate @ 1471]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1460
diff
changeset
|
480 (x <= line->x + line->width) && |
9774a0a304c4
[gaim-migrate @ 1471]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1460
diff
changeset
|
481 (y <= line->y + line->height)) |
9774a0a304c4
[gaim-migrate @ 1471]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1460
diff
changeset
|
482 draw_text (imhtml, line); |
9774a0a304c4
[gaim-migrate @ 1471]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1460
diff
changeset
|
483 } |
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
484 } else { |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
485 while (chunks) { |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
486 line = chunks->data; |
1454
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
487 if ((line->x <= x + width) && |
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
488 (line->y <= y + height) && |
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
489 (x <= line->x + line->width) && |
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
490 (y <= line->y + line->height)) |
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
491 draw_text (imhtml, line); |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
492 chunks = g_list_next (chunks); |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
493 } |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
494 } |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
495 bits = g_list_next (bits); |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
496 } |
1428 | 497 } |
498 | |
499 static void | |
500 gtk_imhtml_draw (GtkWidget *widget, | |
501 GdkRectangle *area) | |
502 { | |
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
503 GtkIMHtml *imhtml; |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
504 |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
505 imhtml = GTK_IMHTML (widget); |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
506 gtk_imhtml_draw_exposed (imhtml); |
1428 | 507 } |
508 | |
509 static void | |
510 gtk_imhtml_style_set (GtkWidget *widget, | |
511 GtkStyle *style) | |
512 { | |
513 GtkIMHtml *imhtml; | |
514 | |
515 g_return_if_fail (widget != NULL); | |
516 g_return_if_fail (GTK_IS_IMHTML (widget)); | |
1460
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
517 |
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
518 if (GTK_WIDGET_CLASS (parent_class)->style_set) |
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
519 (* GTK_WIDGET_CLASS (parent_class)->style_set) (widget, style); |
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
520 |
1428 | 521 if (!GTK_WIDGET_REALIZED (widget)) |
522 return; | |
523 | |
524 imhtml = GTK_IMHTML (widget); | |
1460
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
525 gtk_imhtml_draw_exposed (imhtml); |
1428 | 526 } |
527 | |
528 static gint | |
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
529 gtk_imhtml_expose_event (GtkWidget *widget, |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
530 GdkEventExpose *event) |
1428 | 531 { |
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
532 GtkIMHtml *imhtml; |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
533 |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
534 g_return_val_if_fail (widget != NULL, FALSE); |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
535 g_return_val_if_fail (GTK_IS_IMHTML (widget), FALSE); |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
536 |
1428 | 537 if (GTK_WIDGET_CLASS (parent_class)->expose_event) |
538 (* GTK_WIDGET_CLASS (parent_class)->expose_event) (widget, event); | |
539 | |
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
540 imhtml = GTK_IMHTML (widget); |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
541 gtk_imhtml_draw_exposed (imhtml); |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
542 |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
543 return FALSE; |
1428 | 544 } |
545 | |
546 static void | |
547 gtk_imhtml_redraw_all (GtkIMHtml *imhtml) | |
548 { | |
549 GList *b; | |
550 GtkIMHtmlBit *bit; | |
551 GtkAdjustment *vadj; | |
552 gfloat oldvalue; | |
1527
11977dd0fd29
[gaim-migrate @ 1537]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1524
diff
changeset
|
553 gint oldy; |
1428 | 554 |
555 vadj = GTK_LAYOUT (imhtml)->vadjustment; | |
556 oldvalue = vadj->value / vadj->upper; | |
1527
11977dd0fd29
[gaim-migrate @ 1537]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1524
diff
changeset
|
557 oldy = imhtml->y; |
1428 | 558 |
1515
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
559 gtk_layout_freeze (GTK_LAYOUT (imhtml)); |
1428 | 560 |
561 g_list_free (imhtml->line); | |
562 imhtml->line = NULL; | |
563 | |
564 while (imhtml->urls) { | |
565 g_free (imhtml->urls->data); | |
566 imhtml->urls = g_list_remove (imhtml->urls, imhtml->urls->data); | |
567 } | |
568 | |
569 imhtml->x = BORDER_SIZE; | |
570 imhtml->y = BORDER_SIZE + 10; | |
571 imhtml->llheight = 0; | |
572 imhtml->llascent = 0; | |
573 | |
574 b = imhtml->bits; | |
575 while (b) { | |
1515
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
576 bit = b->data; |
1428 | 577 b = g_list_next (b); |
1515
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
578 while (bit->chunks) { |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
579 struct line_info *li = bit->chunks->data; |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
580 if (li->text) |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
581 g_free (li->text); |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
582 bit->chunks = g_list_remove (bit->chunks, li); |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
583 g_free (li); |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
584 } |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
585 gtk_imhtml_draw_bit (imhtml, bit); |
1428 | 586 } |
587 | |
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
588 gtk_widget_set_usize (GTK_WIDGET (imhtml), -1, imhtml->y + 5); |
1428 | 589 gtk_adjustment_set_value (vadj, vadj->upper * oldvalue); |
1515
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
590 |
1527
11977dd0fd29
[gaim-migrate @ 1537]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1524
diff
changeset
|
591 if (GTK_LAYOUT (imhtml)->bin_window && (imhtml->y < oldy)) { |
11977dd0fd29
[gaim-migrate @ 1537]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1524
diff
changeset
|
592 GdkGC *gc; |
11977dd0fd29
[gaim-migrate @ 1537]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1524
diff
changeset
|
593 GdkColormap *cmap; |
11977dd0fd29
[gaim-migrate @ 1537]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1524
diff
changeset
|
594 |
11977dd0fd29
[gaim-migrate @ 1537]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1524
diff
changeset
|
595 gc = gdk_gc_new (GTK_LAYOUT (imhtml)->bin_window); |
11977dd0fd29
[gaim-migrate @ 1537]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1524
diff
changeset
|
596 cmap = gtk_widget_get_colormap (GTK_WIDGET (imhtml)); |
11977dd0fd29
[gaim-migrate @ 1537]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1524
diff
changeset
|
597 |
11977dd0fd29
[gaim-migrate @ 1537]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1524
diff
changeset
|
598 gdk_color_alloc (cmap, imhtml->default_bg_color); |
11977dd0fd29
[gaim-migrate @ 1537]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1524
diff
changeset
|
599 gdk_gc_set_foreground (gc, imhtml->default_bg_color); |
11977dd0fd29
[gaim-migrate @ 1537]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1524
diff
changeset
|
600 |
11977dd0fd29
[gaim-migrate @ 1537]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1524
diff
changeset
|
601 gdk_draw_rectangle (GTK_LAYOUT (imhtml)->bin_window, gc, TRUE, |
11977dd0fd29
[gaim-migrate @ 1537]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1524
diff
changeset
|
602 0, imhtml->y - GTK_LAYOUT (imhtml)->vadjustment->value, |
11977dd0fd29
[gaim-migrate @ 1537]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1524
diff
changeset
|
603 GTK_WIDGET (imhtml)->allocation.width, |
11977dd0fd29
[gaim-migrate @ 1537]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1524
diff
changeset
|
604 oldy - imhtml->y); |
11977dd0fd29
[gaim-migrate @ 1537]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1524
diff
changeset
|
605 |
11977dd0fd29
[gaim-migrate @ 1537]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1524
diff
changeset
|
606 gdk_gc_unref (gc); |
11977dd0fd29
[gaim-migrate @ 1537]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1524
diff
changeset
|
607 } |
11977dd0fd29
[gaim-migrate @ 1537]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1524
diff
changeset
|
608 |
1515
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
609 gtk_layout_thaw (GTK_LAYOUT (imhtml)); |
1428 | 610 } |
611 | |
612 static void | |
613 gtk_imhtml_size_allocate (GtkWidget *widget, | |
614 GtkAllocation *allocation) | |
615 { | |
616 GtkIMHtml *imhtml; | |
617 | |
618 g_return_if_fail (widget != NULL); | |
619 g_return_if_fail (GTK_IS_IMHTML (widget)); | |
620 g_return_if_fail (allocation != NULL); | |
621 | |
622 imhtml = GTK_IMHTML (widget); | |
623 | |
624 if (GTK_WIDGET_CLASS (parent_class)->size_allocate) | |
625 ( *GTK_WIDGET_CLASS (parent_class)->size_allocate) (widget, allocation); | |
626 | |
1460
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
627 if (allocation->width == imhtml->xsize) { |
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
628 if ((GTK_LAYOUT (imhtml)->vadjustment->value > imhtml->y + 5 - allocation->height)) { |
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
629 if (imhtml->y + 5 > allocation->height) |
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
630 gtk_adjustment_set_value (GTK_LAYOUT (imhtml)->vadjustment, |
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
631 imhtml->y + 5 - allocation->height); |
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
632 else |
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
633 gtk_adjustment_set_value (GTK_LAYOUT (imhtml)->vadjustment, 0); |
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
634 } |
1428 | 635 return; |
1460
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
636 } |
1428 | 637 |
638 imhtml->xsize = allocation->width; | |
639 | |
640 gtk_imhtml_redraw_all (imhtml); | |
641 } | |
642 | |
643 static void | |
644 gtk_imhtml_select_none (GtkIMHtml *imhtml) | |
645 { | |
646 GList *bits; | |
647 GList *chunks; | |
648 GtkIMHtmlBit *bit; | |
649 struct line_info *chunk; | |
650 | |
651 g_return_if_fail (GTK_IS_IMHTML (imhtml)); | |
652 | |
653 bits = imhtml->bits; | |
654 while (bits) { | |
655 bit = bits->data; | |
656 chunks = bit->chunks; | |
657 | |
658 while (chunks) { | |
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
659 chunk = chunks->data; |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
660 |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
661 if (chunk->selected) { |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
662 chunk->selected = FALSE; |
1449
91d84e2073de
[gaim-migrate @ 1459]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1447
diff
changeset
|
663 chunk->sel_start = chunk->text; |
91d84e2073de
[gaim-migrate @ 1459]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1447
diff
changeset
|
664 chunk->sel_end = NULL; |
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
665 if (DRAW_IMG (bit)) |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
666 draw_img (imhtml, chunk); |
1454
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
667 else if ((bit->type == TYPE_SEP) && (bit->chunks->data == chunk)) |
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
668 draw_line (imhtml, chunk); |
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
669 else |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
670 draw_text (imhtml, chunk); |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
671 } |
1428 | 672 |
673 chunks = g_list_next (chunks); | |
674 } | |
675 | |
676 bits = g_list_next (bits); | |
677 } | |
1515
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
678 imhtml->sel_endchunk = NULL; |
1428 | 679 } |
680 | |
681 static gchar* | |
682 get_position (struct line_info *chunk, | |
683 gint x, | |
684 gboolean smileys) | |
685 { | |
686 gint width = x - chunk->x; | |
687 gchar *text; | |
688 gchar *pos; | |
689 guint total = 0; | |
690 | |
691 switch (chunk->bit->type) { | |
692 case TYPE_TEXT: | |
693 case TYPE_COMMENT: | |
694 text = chunk->text; | |
695 break; | |
696 case TYPE_SMILEY: | |
697 if (smileys) | |
698 return NULL; | |
699 else | |
700 text = chunk->text; | |
701 break; | |
702 default: | |
703 return NULL; | |
704 break; | |
705 } | |
706 | |
707 if (width <= 0) | |
708 return text; | |
709 | |
710 for (pos = text; *pos != '\0'; pos++) { | |
711 gint char_width = gdk_text_width (chunk->bit->font, pos, 1); | |
712 if ((width > total) && (width <= total + char_width)) { | |
1476
721cd9b73704
[gaim-migrate @ 1486]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1473
diff
changeset
|
713 if (width < total + (char_width / 2)) |
1428 | 714 return pos; |
715 else | |
716 return ++pos; | |
717 } | |
718 total += char_width; | |
719 } | |
720 | |
721 return pos; | |
722 } | |
723 | |
724 static GString* | |
725 append_to_sel (GString *string, | |
726 struct line_info *chunk, | |
727 gboolean smileys) | |
728 { | |
729 GString *new_string; | |
730 gchar *buf; | |
731 gchar *start; | |
732 gint length; | |
733 | |
734 switch (chunk->bit->type) { | |
735 case TYPE_TEXT: | |
736 case TYPE_COMMENT: | |
737 start = (chunk->sel_start == NULL) ? chunk->text : chunk->sel_start; | |
738 length = (chunk->sel_end == NULL) ? strlen (start) : chunk->sel_end - start; | |
739 if (length <= 0) | |
740 return string; | |
741 buf = g_strndup (start, length); | |
742 break; | |
743 case TYPE_SMILEY: | |
744 if (smileys) { | |
745 start = (chunk->sel_start == NULL) ? chunk->bit->text : chunk->sel_start; | |
746 length = (chunk->sel_end == NULL) ? strlen (start) : chunk->sel_end - start; | |
747 if (length <= 0) | |
748 return string; | |
749 buf = g_strndup (start, length); | |
750 } else { | |
751 start = (chunk->sel_start == NULL) ? chunk->text : chunk->sel_start; | |
752 length = (chunk->sel_end == NULL) ? strlen (start) : chunk->sel_end - start; | |
753 if (length <= 0) | |
754 return string; | |
755 buf = g_strndup (start, length); | |
756 } | |
757 break; | |
758 case TYPE_BR: | |
759 buf = g_strdup ("\n"); | |
760 break; | |
761 default: | |
762 return string; | |
763 break; | |
764 } | |
765 | |
766 new_string = g_string_append (string, buf); | |
767 g_free (buf); | |
768 | |
769 return new_string; | |
770 } | |
771 | |
772 #define COORDS_IN_CHUNK(xx, yy) (((xx) < chunk->x + chunk->width) && \ | |
773 ((yy) < chunk->y + chunk->height)) | |
774 | |
775 static void | |
776 gtk_imhtml_select_bits (GtkIMHtml *imhtml) | |
777 { | |
778 GList *bits; | |
779 GList *chunks; | |
780 GtkIMHtmlBit *bit; | |
781 struct line_info *chunk; | |
782 | |
783 guint startx = imhtml->sel_startx, | |
784 starty = imhtml->sel_starty, | |
785 endx = imhtml->sel_endx, | |
786 endy = imhtml->sel_endy; | |
787 gchar *new_pos; | |
788 gint selection = 0; | |
789 gboolean smileys = imhtml->smileys; | |
790 gboolean redraw = FALSE; | |
791 gboolean got_start = FALSE; | |
792 gboolean got_end = FALSE; | |
793 | |
794 g_return_if_fail (GTK_IS_IMHTML (imhtml)); | |
795 | |
796 if (!imhtml->selection) | |
797 return; | |
798 | |
799 if (imhtml->selected_text) { | |
800 g_string_free (imhtml->selected_text, TRUE); | |
801 imhtml->selected_text = g_string_new (""); | |
802 } | |
803 | |
804 bits = imhtml->bits; | |
805 while (bits) { | |
806 bit = bits->data; | |
807 chunks = bit->chunks; | |
808 | |
809 while (chunks) { | |
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
810 chunk = chunks->data; |
1428 | 811 |
812 switch (selection) { | |
813 case 0: | |
814 if (COORDS_IN_CHUNK (startx, starty)) { | |
815 new_pos = get_position (chunk, startx, smileys); | |
816 if ( !chunk->selected || | |
817 (chunk->sel_start != new_pos) || | |
818 (chunk->sel_end != NULL)) | |
819 redraw = TRUE; | |
820 chunk->selected = TRUE; | |
821 chunk->sel_start = new_pos; | |
822 chunk->sel_end = NULL; | |
823 selection++; | |
824 got_start = TRUE; | |
825 } | |
826 | |
827 if (COORDS_IN_CHUNK (endx, endy)) { | |
828 if (got_start) { | |
829 new_pos = get_position (chunk, endx, smileys); | |
830 if (chunk->sel_end != new_pos) | |
831 redraw = TRUE; | |
832 if (chunk->sel_start > new_pos) { | |
833 chunk->sel_end = chunk->sel_start; | |
834 chunk->sel_start = new_pos; | |
835 } else | |
836 chunk->sel_end = new_pos; | |
837 selection = 2; | |
1515
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
838 imhtml->sel_endchunk = chunk; |
1428 | 839 got_end = TRUE; |
840 } else { | |
841 new_pos = get_position (chunk, endx, smileys); | |
842 if ( !chunk->selected || | |
843 (chunk->sel_start != new_pos) || | |
844 (chunk->sel_end != NULL)) | |
845 redraw = TRUE; | |
846 chunk->selected = TRUE; | |
847 chunk->sel_start = new_pos; | |
848 chunk->sel_end = NULL; | |
849 selection++; | |
1515
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
850 imhtml->sel_endchunk = chunk; |
1428 | 851 got_end = TRUE; |
852 } | |
853 } else if (!COORDS_IN_CHUNK (startx, starty) && !got_start) { | |
854 if (chunk->selected) | |
855 redraw = TRUE; | |
856 chunk->selected = FALSE; | |
857 chunk->sel_start = chunk->text; | |
858 chunk->sel_end = NULL; | |
859 } | |
860 | |
861 break; | |
862 case 1: | |
863 if (!got_start && COORDS_IN_CHUNK (startx, starty)) { | |
864 new_pos = get_position (chunk, startx, smileys); | |
865 if ( !chunk->selected || | |
866 (chunk->sel_end != new_pos) || | |
867 (chunk->sel_start != chunk->text)) | |
868 redraw = TRUE; | |
869 chunk->selected = TRUE; | |
870 chunk->sel_start = chunk->text; | |
871 chunk->sel_end = new_pos; | |
872 selection++; | |
873 got_start = TRUE; | |
874 } else if (!got_end && COORDS_IN_CHUNK (endx, endy)) { | |
875 new_pos = get_position (chunk, endx, smileys); | |
876 if ( !chunk->selected || | |
877 (chunk->sel_end != new_pos) || | |
878 (chunk->sel_start != chunk->text)) | |
879 redraw = TRUE; | |
880 chunk->selected = TRUE; | |
881 chunk->sel_start = chunk->text; | |
882 chunk->sel_end = new_pos; | |
883 selection++; | |
1515
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
884 imhtml->sel_endchunk = chunk; |
1428 | 885 got_end = TRUE; |
886 } else { | |
887 if ( !chunk->selected || | |
1449
91d84e2073de
[gaim-migrate @ 1459]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1447
diff
changeset
|
888 (chunk->sel_end != NULL) || |
91d84e2073de
[gaim-migrate @ 1459]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1447
diff
changeset
|
889 (chunk->sel_start != chunk->text)) |
1428 | 890 redraw = TRUE; |
891 chunk->selected = TRUE; | |
892 chunk->sel_start = chunk->text; | |
893 chunk->sel_end = NULL; | |
894 } | |
895 | |
896 break; | |
897 case 2: | |
1449
91d84e2073de
[gaim-migrate @ 1459]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1447
diff
changeset
|
898 if (chunk->selected) |
1428 | 899 redraw = TRUE; |
900 chunk->selected = FALSE; | |
901 chunk->sel_start = chunk->text; | |
902 chunk->sel_end = NULL; | |
903 break; | |
904 } | |
905 | |
906 if (chunk->selected == TRUE) | |
907 imhtml->selected_text = append_to_sel (imhtml->selected_text, | |
908 chunk, smileys); | |
909 | |
910 if (redraw) { | |
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
911 if (DRAW_IMG (bit)) |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
912 draw_img (imhtml, chunk); |
1454
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
913 else if ((bit->type == TYPE_SEP) && (bit->chunks->data == chunk)) |
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
914 draw_line (imhtml, chunk); |
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
915 else |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
916 draw_text (imhtml, chunk); |
1428 | 917 redraw = FALSE; |
918 } | |
919 | |
920 chunks = g_list_next (chunks); | |
921 } | |
922 | |
923 bits = g_list_next (bits); | |
924 } | |
925 } | |
926 | |
1515
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
927 static void |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
928 gtk_imhtml_select_in_chunk (GtkIMHtml *imhtml, |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
929 struct line_info *chunk) |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
930 { |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
931 GtkIMHtmlBit *bit = chunk->bit; |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
932 gchar *new_pos; |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
933 guint endx = imhtml->sel_endx; |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
934 guint startx = imhtml->sel_startx; |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
935 guint starty = imhtml->sel_starty; |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
936 gboolean smileys = imhtml->smileys; |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
937 gboolean redraw = FALSE; |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
938 |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
939 new_pos = get_position (chunk, endx, smileys); |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
940 if ((starty < chunk->y) || |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
941 ((starty < chunk->y + chunk->height) && (startx < endx))) { |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
942 if (chunk->sel_end != new_pos) |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
943 redraw = TRUE; |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
944 chunk->sel_end = new_pos; |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
945 } else { |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
946 if (chunk->sel_start != new_pos) |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
947 redraw = TRUE; |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
948 chunk->sel_start = new_pos; |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
949 } |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
950 |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
951 if (redraw) { |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
952 if (DRAW_IMG (bit)) |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
953 draw_img (imhtml, chunk); |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
954 else if ((bit->type == TYPE_SEP) && |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
955 (bit->chunks->data == chunk)) |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
956 draw_line (imhtml, chunk); |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
957 else |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
958 draw_text (imhtml, chunk); |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
959 } |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
960 } |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
961 |
1428 | 962 static gint |
963 scroll_timeout (GtkIMHtml *imhtml) | |
964 { | |
965 GdkEventMotion event; | |
966 gint x, y; | |
967 GdkModifierType mask; | |
968 | |
969 imhtml->scroll_timer = 0; | |
970 | |
1476
721cd9b73704
[gaim-migrate @ 1486]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1473
diff
changeset
|
971 gdk_window_get_pointer (GTK_LAYOUT (imhtml)->bin_window, &x, &y, &mask); |
1428 | 972 |
973 if (mask & GDK_BUTTON1_MASK) { | |
974 event.is_hint = 0; | |
975 event.x = x; | |
976 event.y = y; | |
977 event.state = mask; | |
978 | |
979 gtk_imhtml_motion_notify_event (GTK_WIDGET (imhtml), &event); | |
980 } | |
981 | |
982 return FALSE; | |
983 } | |
984 | |
985 static gint | |
1574
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
986 gtk_imhtml_tip_paint (GtkIMHtml *imhtml) |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
987 { |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
988 GtkStyle *style; |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
989 gint y, baseline_skip, gap; |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
990 |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
991 style = imhtml->tip_window->style; |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
992 |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
993 gap = (style->font->ascent + style->font->descent) / 4; |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
994 if (gap < 2) |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
995 gap = 2; |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
996 baseline_skip = style->font->ascent + style->font->descent + gap; |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
997 |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
998 if (!imhtml->tip_bit) |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
999 return FALSE; |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1000 |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1001 gtk_paint_flat_box(style, imhtml->tip_window->window, GTK_STATE_NORMAL, GTK_SHADOW_OUT, |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1002 NULL, imhtml->tip_window, "tooltip", 0, 0, -1, -1); |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1003 |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1004 y = style->font->ascent + 4; |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1005 gtk_paint_string (style, imhtml->tip_window->window, GTK_STATE_NORMAL, NULL, |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1006 imhtml->tip_window, "tooltip", 4, y, imhtml->tip_bit->url); |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1007 |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1008 return FALSE; |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1009 } |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1010 |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1011 static gint |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1012 gtk_imhtml_tip (gpointer data) |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1013 { |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1014 GtkIMHtml *imhtml = data; |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1015 GtkWidget *widget = GTK_WIDGET (imhtml); |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1016 GtkStyle *style; |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1017 gint gap, x, y, w, h, scr_w, scr_h, baseline_skip; |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1018 |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1019 if (!imhtml->tip_bit || !GTK_WIDGET_DRAWABLE (widget)) { |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1020 imhtml->tip_timer = 0; |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1021 return FALSE; |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1022 } |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1023 |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1024 if (imhtml->tip_window) |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1025 gtk_widget_destroy (imhtml->tip_window); |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1026 |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1027 imhtml->tip_window = gtk_window_new (GTK_WINDOW_POPUP); |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1028 gtk_widget_set_app_paintable (imhtml->tip_window, TRUE); |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1029 gtk_window_set_policy (GTK_WINDOW (imhtml->tip_window), FALSE, FALSE, TRUE); |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1030 gtk_widget_set_name (imhtml->tip_window, "gtk-tooltips"); |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1031 gtk_signal_connect_object (GTK_OBJECT (imhtml->tip_window), "expose_event", |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1032 GTK_SIGNAL_FUNC (gtk_imhtml_tip_paint), GTK_OBJECT (imhtml)); |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1033 gtk_signal_connect_object (GTK_OBJECT (imhtml->tip_window), "draw", |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1034 GTK_SIGNAL_FUNC (gtk_imhtml_tip_paint), GTK_OBJECT (imhtml)); |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1035 |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1036 gtk_widget_ensure_style (imhtml->tip_window); |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1037 style = imhtml->tip_window->style; |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1038 |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1039 scr_w = gdk_screen_width (); |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1040 scr_h = gdk_screen_height (); |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1041 |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1042 gap = (style->font->ascent + style->font->descent) / 4; |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1043 if (gap < 2) |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1044 gap = 2; |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1045 baseline_skip = style->font->ascent + style->font->descent + gap; |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1046 |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1047 w = 8 + gdk_string_width (style->font, imhtml->tip_bit->url); |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1048 h = 8 - gap + baseline_skip; |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1049 |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1050 gdk_window_get_pointer (NULL, &x, &y, NULL); |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1051 if (GTK_WIDGET_NO_WINDOW (widget)) |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1052 y += widget->allocation.y; |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1053 |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1054 x -= ((w >> 1) + 4); |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1055 |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1056 if ((x + w) > scr_w) |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1057 x -= (x + w) - scr_w; |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1058 else if (x < 0) |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1059 x = 0; |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1060 |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1061 if ((y + h + + 4) > scr_h) |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1062 y = y - imhtml->tip_bit->font->ascent + imhtml->tip_bit->font->descent; |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1063 else |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1064 y = y + imhtml->tip_bit->font->ascent + imhtml->tip_bit->font->descent; |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1065 |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1066 gtk_widget_set_usize (imhtml->tip_window, w, h); |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1067 gtk_widget_popup (imhtml->tip_window, x, y); |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1068 |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1069 imhtml->tip_timer = 0; |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1070 return FALSE; |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1071 } |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1072 |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1073 static gint |
1428 | 1074 gtk_imhtml_motion_notify_event (GtkWidget *widget, |
1075 GdkEventMotion *event) | |
1076 { | |
1077 gint x, y; | |
1078 GdkModifierType state; | |
1079 GtkIMHtml *imhtml = GTK_IMHTML (widget); | |
1080 GtkAdjustment *vadj = GTK_LAYOUT (widget)->vadjustment; | |
1081 GtkAdjustment *hadj = GTK_LAYOUT (widget)->hadjustment; | |
1082 | |
1083 if (event->is_hint) | |
1084 gdk_window_get_pointer (event->window, &x, &y, &state); | |
1085 else { | |
1086 x = event->x + hadj->value; | |
1087 y = event->y + vadj->value; | |
1088 state = event->state; | |
1089 } | |
1090 | |
1091 if (state & GDK_BUTTON1_MASK) { | |
1092 gint diff; | |
1093 gint height = vadj->page_size; | |
1094 gint yy = y - vadj->value; | |
1095 | |
1096 if (((yy < 0) || (yy > height)) && | |
1097 (imhtml->scroll_timer == 0) && | |
1098 (vadj->upper > vadj->page_size)) { | |
1099 imhtml->scroll_timer = gtk_timeout_add (100, | |
1100 (GtkFunction) scroll_timeout, | |
1101 imhtml); | |
1476
721cd9b73704
[gaim-migrate @ 1486]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1473
diff
changeset
|
1102 diff = (yy < 0) ? (yy / 2) : ((yy - height) / 2); |
1428 | 1103 gtk_adjustment_set_value (vadj, |
1104 MIN (vadj->value + diff, vadj->upper - height + 20)); | |
1105 } | |
1106 | |
1107 if (imhtml->selection) { | |
1515
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
1108 struct line_info *chunk = imhtml->sel_endchunk; |
1428 | 1109 imhtml->sel_endx = MAX (x, 0); |
1110 imhtml->sel_endy = MAX (y, 0); | |
1515
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
1111 if ((chunk == NULL) || |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
1112 (x < chunk->x) || |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
1113 (x > chunk->x + chunk->width) || |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
1114 (y < chunk->y) || |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
1115 (y > chunk->y + chunk->height)) |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
1116 gtk_imhtml_select_bits (imhtml); |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
1117 else |
206f995a33f3
[gaim-migrate @ 1525]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1482
diff
changeset
|
1118 gtk_imhtml_select_in_chunk (imhtml, chunk); |
1428 | 1119 } |
1120 } else { | |
1121 GList *urls = imhtml->urls; | |
1122 struct url_widget *uw; | |
1123 | |
1124 while (urls) { | |
1125 uw = (struct url_widget *) urls->data; | |
1126 if ((x > uw->x) && (x < uw->x + uw->width) && | |
1127 (y > uw->y) && (y < uw->y + uw->height)) { | |
1574
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1128 if (imhtml->tip_bit != uw->bit) { |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1129 imhtml->tip_bit = uw->bit; |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1130 if (imhtml->tip_timer != 0) |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1131 gtk_timeout_remove (imhtml->tip_timer); |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1132 if (imhtml->tip_window) { |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1133 gtk_widget_destroy (imhtml->tip_window); |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1134 imhtml->tip_window = NULL; |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1135 } |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1136 imhtml->tip_timer = gtk_timeout_add (TOOLTIP_TIMEOUT, |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1137 gtk_imhtml_tip, |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1138 imhtml); |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1139 } |
1476
721cd9b73704
[gaim-migrate @ 1486]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1473
diff
changeset
|
1140 gdk_window_set_cursor (GTK_LAYOUT (imhtml)->bin_window, |
721cd9b73704
[gaim-migrate @ 1486]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1473
diff
changeset
|
1141 imhtml->hand_cursor); |
1428 | 1142 return TRUE; |
1143 } | |
1144 urls = g_list_next (urls); | |
1145 } | |
1146 } | |
1147 | |
1574
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1148 if (imhtml->tip_timer) { |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1149 gtk_timeout_remove (imhtml->tip_timer); |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1150 imhtml->tip_timer = 0; |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1151 } |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1152 if (imhtml->tip_window) { |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1153 gtk_widget_destroy (imhtml->tip_window); |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1154 imhtml->tip_window = NULL; |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1155 } |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1156 imhtml->tip_bit = NULL; |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1157 |
1476
721cd9b73704
[gaim-migrate @ 1486]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1473
diff
changeset
|
1158 gdk_window_set_cursor (GTK_LAYOUT (imhtml)->bin_window, imhtml->arrow_cursor); |
1428 | 1159 |
1160 return TRUE; | |
1161 } | |
1162 | |
1163 static gint | |
1613
35a13ece3a9c
[gaim-migrate @ 1623]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1582
diff
changeset
|
1164 gtk_imhtml_leave_notify_event (GtkWidget *widget, |
35a13ece3a9c
[gaim-migrate @ 1623]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1582
diff
changeset
|
1165 GdkEventCrossing *event) |
35a13ece3a9c
[gaim-migrate @ 1623]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1582
diff
changeset
|
1166 { |
35a13ece3a9c
[gaim-migrate @ 1623]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1582
diff
changeset
|
1167 GtkIMHtml *imhtml = GTK_IMHTML (widget); |
35a13ece3a9c
[gaim-migrate @ 1623]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1582
diff
changeset
|
1168 |
35a13ece3a9c
[gaim-migrate @ 1623]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1582
diff
changeset
|
1169 if (imhtml->tip_timer) { |
35a13ece3a9c
[gaim-migrate @ 1623]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1582
diff
changeset
|
1170 gtk_timeout_remove (imhtml->tip_timer); |
35a13ece3a9c
[gaim-migrate @ 1623]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1582
diff
changeset
|
1171 imhtml->tip_timer = 0; |
35a13ece3a9c
[gaim-migrate @ 1623]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1582
diff
changeset
|
1172 } |
35a13ece3a9c
[gaim-migrate @ 1623]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1582
diff
changeset
|
1173 if (imhtml->tip_window) { |
35a13ece3a9c
[gaim-migrate @ 1623]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1582
diff
changeset
|
1174 gtk_widget_destroy (imhtml->tip_window); |
35a13ece3a9c
[gaim-migrate @ 1623]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1582
diff
changeset
|
1175 imhtml->tip_window = NULL; |
35a13ece3a9c
[gaim-migrate @ 1623]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1582
diff
changeset
|
1176 } |
35a13ece3a9c
[gaim-migrate @ 1623]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1582
diff
changeset
|
1177 imhtml->tip_bit = NULL; |
35a13ece3a9c
[gaim-migrate @ 1623]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1582
diff
changeset
|
1178 |
35a13ece3a9c
[gaim-migrate @ 1623]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1582
diff
changeset
|
1179 return TRUE; |
35a13ece3a9c
[gaim-migrate @ 1623]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1582
diff
changeset
|
1180 } |
35a13ece3a9c
[gaim-migrate @ 1623]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1582
diff
changeset
|
1181 |
35a13ece3a9c
[gaim-migrate @ 1623]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1582
diff
changeset
|
1182 static gint |
1428 | 1183 gtk_imhtml_button_press_event (GtkWidget *widget, |
1184 GdkEventButton *event) | |
1185 { | |
1186 GtkIMHtml *imhtml = GTK_IMHTML (widget); | |
1187 GtkAdjustment *vadj = GTK_LAYOUT (widget)->vadjustment; | |
1188 GtkAdjustment *hadj = GTK_LAYOUT (widget)->hadjustment; | |
1189 gint x, y; | |
1190 | |
1191 if (event->button == 1) { | |
1192 x = event->x + hadj->value; | |
1193 y = event->y + vadj->value; | |
1194 | |
1195 imhtml->sel_startx = x; | |
1196 imhtml->sel_starty = y; | |
1197 imhtml->selection = TRUE; | |
1198 gtk_imhtml_select_none (imhtml); | |
1199 } | |
1200 | |
1201 return TRUE; | |
1202 } | |
1203 | |
1204 static gint | |
1205 gtk_imhtml_button_release_event (GtkWidget *widget, | |
1206 GdkEventButton *event) | |
1207 { | |
1208 GtkIMHtml *imhtml = GTK_IMHTML (widget); | |
1209 GtkAdjustment *vadj = GTK_LAYOUT (widget)->vadjustment; | |
1210 GtkAdjustment *hadj = GTK_LAYOUT (widget)->hadjustment; | |
1211 gint x, y; | |
1212 | |
1456
6650776468b3
[gaim-migrate @ 1466]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1454
diff
changeset
|
1213 x = event->x + hadj->value; |
6650776468b3
[gaim-migrate @ 1466]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1454
diff
changeset
|
1214 y = event->y + vadj->value; |
6650776468b3
[gaim-migrate @ 1466]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1454
diff
changeset
|
1215 |
1428 | 1216 if ((event->button == 1) && imhtml->selection) { |
1217 if ((x == imhtml->sel_startx) && (y == imhtml->sel_starty)) { | |
1218 imhtml->sel_startx = imhtml->sel_starty = 0; | |
1219 imhtml->selection = FALSE; | |
1220 gtk_imhtml_select_none (imhtml); | |
1221 } else { | |
1222 imhtml->sel_endx = MAX (x, 0); | |
1223 imhtml->sel_endy = MAX (y, 0); | |
1224 gtk_imhtml_select_bits (imhtml); | |
1225 } | |
1226 | |
1227 gtk_selection_owner_set (widget, GDK_SELECTION_PRIMARY, event->time); | |
1228 } | |
1229 | |
1547
7b50a08090a2
[gaim-migrate @ 1557]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1528
diff
changeset
|
1230 if ((event->button == 1) && (imhtml->sel_startx == 0)) { |
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
1231 GList *urls = imhtml->urls; |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
1232 struct url_widget *uw; |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
1233 |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
1234 while (urls) { |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
1235 uw = (struct url_widget *) urls->data; |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
1236 if ((x > uw->x) && (x < uw->x + uw->width) && |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
1237 (y > uw->y) && (y < uw->y + uw->height)) { |
1574
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1238 gtk_signal_emit (GTK_OBJECT (imhtml), signals [URL_CLICKED], |
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1239 uw->bit->url); |
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
1240 return TRUE; |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
1241 } |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
1242 urls = g_list_next (urls); |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
1243 } |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
1244 } |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
1245 |
1428 | 1246 return TRUE; |
1247 } | |
1248 | |
1249 static void | |
1250 gtk_imhtml_selection_get (GtkWidget *widget, | |
1251 GtkSelectionData *sel_data, | |
1252 guint sel_info, | |
1253 guint32 time) | |
1254 { | |
1255 GtkIMHtml *imhtml; | |
1256 gchar *string; | |
1257 gint length; | |
1258 | |
1259 g_return_if_fail (widget != NULL); | |
1260 g_return_if_fail (GTK_IS_IMHTML (widget)); | |
1261 g_return_if_fail (sel_data->selection == GDK_SELECTION_PRIMARY); | |
1262 | |
1263 imhtml = GTK_IMHTML (widget); | |
1264 | |
1265 g_return_if_fail (imhtml->selected_text != NULL); | |
1266 g_return_if_fail (imhtml->selected_text->str != NULL); | |
1267 | |
1268 if (imhtml->selected_text->len <= 0) { | |
1269 string = NULL; | |
1270 length = 0; | |
1271 } else { | |
1272 string = g_strdup (imhtml->selected_text->str); | |
1273 length = strlen (string); | |
1274 } | |
1275 | |
1276 if (sel_info == TARGET_STRING) { | |
1277 gtk_selection_data_set (sel_data, | |
1278 GDK_SELECTION_TYPE_STRING, | |
1279 8 * sizeof (gchar), | |
1280 (guchar *) string, | |
1281 length); | |
1282 } else if ((sel_info == TARGET_TEXT) || (sel_info == TARGET_COMPOUND_TEXT)) { | |
1283 guchar *text; | |
1284 GdkAtom encoding; | |
1285 gint format; | |
1286 gint new_length; | |
1287 | |
1288 gdk_string_to_compound_text (string, &encoding, &format, &text, &new_length); | |
1289 gtk_selection_data_set (sel_data, encoding, format, text, new_length); | |
1290 gdk_free_compound_text (text); | |
1291 } | |
1292 | |
1293 if (string) | |
1294 g_free (string); | |
1295 } | |
1296 | |
1297 static gint | |
1298 gtk_imhtml_selection_clear_event (GtkWidget *widget, | |
1299 GdkEventSelection *event) | |
1300 { | |
1301 GtkIMHtml *imhtml; | |
1302 | |
1303 g_return_val_if_fail (widget != NULL, FALSE); | |
1304 g_return_val_if_fail (GTK_IS_IMHTML (widget), FALSE); | |
1305 g_return_val_if_fail (event != NULL, FALSE); | |
1306 g_return_val_if_fail (event->selection == GDK_SELECTION_PRIMARY, TRUE); | |
1307 | |
1308 if (!gtk_selection_clear (widget, event)) | |
1309 return FALSE; | |
1310 | |
1311 imhtml = GTK_IMHTML (widget); | |
1312 | |
1313 gtk_imhtml_select_none (imhtml); | |
1314 | |
1315 return TRUE; | |
1316 } | |
1317 | |
1318 static void | |
1319 gtk_imhtml_set_scroll_adjustments (GtkLayout *layout, | |
1320 GtkAdjustment *hadj, | |
1321 GtkAdjustment *vadj) | |
1322 { | |
1323 if (parent_class->set_scroll_adjustments) | |
1324 (* parent_class->set_scroll_adjustments) (layout, hadj, vadj); | |
1325 } | |
1326 | |
1327 static void | |
1328 gtk_imhtml_class_init (GtkIMHtmlClass *class) | |
1329 { | |
1330 GtkObjectClass *object_class; | |
1331 GtkWidgetClass *widget_class; | |
1332 GtkLayoutClass *layout_class; | |
1333 | |
1334 object_class = (GtkObjectClass*) class; | |
1335 widget_class = (GtkWidgetClass*) class; | |
1336 layout_class = (GtkLayoutClass*) class; | |
1337 | |
1338 parent_class = gtk_type_class (GTK_TYPE_LAYOUT); | |
1339 | |
1340 signals [URL_CLICKED] = | |
1341 gtk_signal_new ("url_clicked", | |
1342 GTK_RUN_FIRST, | |
1343 object_class->type, | |
1344 GTK_SIGNAL_OFFSET (GtkIMHtmlClass, url_clicked), | |
1345 gtk_marshal_NONE__POINTER, | |
1346 GTK_TYPE_NONE, 1, | |
1347 GTK_TYPE_POINTER); | |
1348 | |
1349 gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL); | |
1350 | |
1351 object_class->destroy = gtk_imhtml_destroy; | |
1352 | |
1353 widget_class->realize = gtk_imhtml_realize; | |
1354 widget_class->draw = gtk_imhtml_draw; | |
1355 widget_class->style_set = gtk_imhtml_style_set; | |
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
1356 widget_class->expose_event = gtk_imhtml_expose_event; |
1428 | 1357 widget_class->size_allocate = gtk_imhtml_size_allocate; |
1358 widget_class->motion_notify_event = gtk_imhtml_motion_notify_event; | |
1613
35a13ece3a9c
[gaim-migrate @ 1623]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1582
diff
changeset
|
1359 widget_class->leave_notify_event = gtk_imhtml_leave_notify_event; |
1428 | 1360 widget_class->button_press_event = gtk_imhtml_button_press_event; |
1361 widget_class->button_release_event = gtk_imhtml_button_release_event; | |
1362 widget_class->selection_get = gtk_imhtml_selection_get; | |
1363 widget_class->selection_clear_event = gtk_imhtml_selection_clear_event; | |
1364 | |
1365 layout_class->set_scroll_adjustments = gtk_imhtml_set_scroll_adjustments; | |
1366 } | |
1367 | |
1368 static GdkFont* | |
1369 gtk_imhtml_font_load (GtkIMHtml *imhtml, | |
1370 gchar *name, | |
1371 gboolean bold, | |
1372 gboolean italics, | |
1373 gint fontsize) | |
1374 { | |
1375 gchar buf [16 * 1024]; | |
1376 GdkFont *font; | |
1377 gint size = fontsize ? font_sizes [MIN (fontsize, MAX_SIZE) - 1] : 120; | |
1378 | |
1379 g_snprintf (buf, sizeof (buf), "-*-%s-%s-%c-*-*-*-%d-*-*-*-*-*-*", | |
1380 name ? name : DEFAULT_FONT_NAME, | |
1381 bold ? "bold" : "medium", | |
1382 italics ? 'i' : 'r', | |
1383 size); | |
1384 font = gdk_font_load (buf); | |
1385 if (font) | |
1386 return font; | |
1387 | |
1388 if (italics) { | |
1389 g_snprintf (buf, sizeof (buf), "-*-%s-%s-%c-*-*-*-%d-*-*-*-*-*-*", | |
1390 name ? name : DEFAULT_FONT_NAME, | |
1391 bold ? "bold" : "medium", | |
1392 'o', | |
1393 size); | |
1394 font = gdk_font_load (buf); | |
1395 if (font) | |
1396 return font; | |
1397 | |
1398 if (bold) { | |
1399 g_snprintf (buf, sizeof (buf), "-*-%s-%s-%c-*-*-*-%d-*-*-*-*-*-*", | |
1400 name ? name : DEFAULT_FONT_NAME, | |
1401 "bold", | |
1402 'r', | |
1403 size); | |
1404 font = gdk_font_load (buf); | |
1405 if (font) | |
1406 return font; | |
1407 } | |
1408 } | |
1409 | |
1410 if (bold) { | |
1411 g_snprintf (buf, sizeof (buf), "-*-%s-%s-%c-*-*-*-%d-*-*-*-*-*-*", | |
1412 name ? name : DEFAULT_FONT_NAME, | |
1413 "medium", | |
1414 italics ? 'i' : 'r', | |
1415 size); | |
1416 font = gdk_font_load (buf); | |
1417 if (font) | |
1418 return font; | |
1419 | |
1420 if (italics) { | |
1421 g_snprintf (buf, sizeof (buf), "-*-%s-%s-%c-*-*-*-%d-*-*-*-*-*-*", | |
1422 name ? name : DEFAULT_FONT_NAME, | |
1423 "medium", | |
1424 'o', | |
1425 size); | |
1426 font = gdk_font_load (buf); | |
1427 if (font) | |
1428 return font; | |
1429 } | |
1430 } | |
1431 | |
1432 if (!bold && !italics) { | |
1433 g_snprintf (buf, sizeof (buf), "-*-%s-medium-r-*-*-*-%d-*-*-*-*-*-*", | |
1434 name ? name : DEFAULT_FONT_NAME, | |
1435 size); | |
1436 font = gdk_font_load (buf); | |
1437 if (font) | |
1438 return font; | |
1439 } | |
1440 | |
1441 g_snprintf (buf, sizeof (buf), "-*-%s-medium-r-*-*-*-%d-*-*-*-*-*-*", | |
1442 DEFAULT_FONT_NAME, | |
1443 size); | |
1444 font = gdk_font_load (buf); | |
1445 if (font) | |
1446 return font; | |
1447 | |
1448 if (imhtml->default_font) | |
1449 return gdk_font_ref (imhtml->default_font); | |
1450 | |
1451 return NULL; | |
1452 } | |
1453 | |
1454 static void | |
1455 gtk_imhtml_init (GtkIMHtml *imhtml) | |
1456 { | |
1457 static const GtkTargetEntry targets [] = { | |
1458 { "STRING", 0, TARGET_STRING }, | |
1459 { "TEXT", 0, TARGET_TEXT }, | |
1460 { "COMPOUND_TEXT", 0, TARGET_COMPOUND_TEXT } | |
1461 }; | |
1462 | |
1463 imhtml->default_font = gtk_imhtml_font_load (imhtml, NULL, FALSE, FALSE, 0); | |
1464 if (imhtml->default_font == NULL) | |
1465 g_warning ("GtkIMHtml: Could not load default font!"); | |
1466 imhtml->default_fg_color = gdk_color_copy (>K_WIDGET (imhtml)->style->black); | |
1460
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
1467 imhtml->default_bg_color = gdk_color_copy (>K_WIDGET (imhtml)->style->white); |
1428 | 1468 imhtml->hand_cursor = gdk_cursor_new (GDK_HAND2); |
1469 imhtml->arrow_cursor = gdk_cursor_new (GDK_LEFT_PTR); | |
1470 | |
1471 GTK_WIDGET_SET_FLAGS (GTK_WIDGET (imhtml), GTK_CAN_FOCUS); | |
1472 gtk_selection_add_targets (GTK_WIDGET (imhtml), GDK_SELECTION_PRIMARY, targets, 3); | |
1473 } | |
1474 | |
1475 GtkType | |
1476 gtk_imhtml_get_type (void) | |
1477 { | |
1478 static GtkType imhtml_type = 0; | |
1479 | |
1480 if (!imhtml_type) { | |
1481 static const GtkTypeInfo imhtml_info = { | |
1482 "GtkIMHtml", | |
1483 sizeof (GtkIMHtml), | |
1484 sizeof (GtkIMHtmlClass), | |
1485 (GtkClassInitFunc) gtk_imhtml_class_init, | |
1486 (GtkObjectInitFunc) gtk_imhtml_init, | |
1487 NULL, | |
1488 NULL, | |
1489 NULL | |
1490 }; | |
1491 | |
1492 imhtml_type = gtk_type_unique (GTK_TYPE_LAYOUT, &imhtml_info); | |
1493 } | |
1494 | |
1495 return imhtml_type; | |
1496 } | |
1497 | |
1498 static void | |
1499 gtk_imhtml_init_smiley_hash (GtkIMHtml *imhtml) | |
1500 { | |
1501 g_return_if_fail (imhtml != NULL); | |
1502 g_return_if_fail (GTK_IS_IMHTML (imhtml)); | |
1503 | |
1504 imhtml->smiley_hash = g_hash_table_new (g_str_hash, g_str_equal); | |
1505 | |
1506 gtk_imhtml_associate_smiley (imhtml, ":)", smile_xpm); | |
1507 gtk_imhtml_associate_smiley (imhtml, ":-)", smile_xpm); | |
1508 | |
1509 gtk_imhtml_associate_smiley (imhtml, ":(", sad_xpm); | |
1510 gtk_imhtml_associate_smiley (imhtml, ":-(", sad_xpm); | |
1511 | |
1512 gtk_imhtml_associate_smiley (imhtml, ";)", wink_xpm); | |
1513 gtk_imhtml_associate_smiley (imhtml, ";-)", wink_xpm); | |
1514 | |
1515 gtk_imhtml_associate_smiley (imhtml, ":-p", tongue_xpm); | |
1516 gtk_imhtml_associate_smiley (imhtml, ":-P", tongue_xpm); | |
1517 | |
1518 gtk_imhtml_associate_smiley (imhtml, "=-O", scream_xpm); | |
1519 gtk_imhtml_associate_smiley (imhtml, ":-*", kiss_xpm); | |
1520 gtk_imhtml_associate_smiley (imhtml, ">:o", yell_xpm); | |
1521 gtk_imhtml_associate_smiley (imhtml, "8-)", smile8_xpm); | |
1522 gtk_imhtml_associate_smiley (imhtml, ":-$", moneymouth_xpm); | |
1523 gtk_imhtml_associate_smiley (imhtml, ":-!", burp_xpm); | |
1524 gtk_imhtml_associate_smiley (imhtml, ":-[", embarrassed_xpm); | |
1525 gtk_imhtml_associate_smiley (imhtml, ":'(", cry_xpm); | |
1526 | |
1527 gtk_imhtml_associate_smiley (imhtml, ":-/", think_xpm); | |
1528 gtk_imhtml_associate_smiley (imhtml, ":-\\", think_xpm); | |
1529 | |
1530 gtk_imhtml_associate_smiley (imhtml, ":-X", crossedlips_xpm); | |
1531 gtk_imhtml_associate_smiley (imhtml, ":-D", bigsmile_xpm); | |
1532 gtk_imhtml_associate_smiley (imhtml, "O:-)", angel_xpm); | |
1533 } | |
1534 | |
1535 GtkWidget* | |
1536 gtk_imhtml_new (GtkAdjustment *hadj, | |
1537 GtkAdjustment *vadj) | |
1538 { | |
1539 GtkIMHtml *imhtml = gtk_type_new (GTK_TYPE_IMHTML); | |
1540 | |
1541 gtk_imhtml_set_adjustments (imhtml, hadj, vadj); | |
1542 | |
1543 imhtml->bits = NULL; | |
1544 imhtml->urls = NULL; | |
1545 | |
1546 imhtml->x = BORDER_SIZE; | |
1547 imhtml->y = BORDER_SIZE + 10; | |
1548 imhtml->llheight = 0; | |
1549 imhtml->llascent = 0; | |
1550 imhtml->line = NULL; | |
1551 | |
1552 imhtml->selected_text = g_string_new (""); | |
1553 imhtml->scroll_timer = 0; | |
1554 | |
1555 imhtml->img = NULL; | |
1556 | |
1557 imhtml->smileys = TRUE; | |
1558 imhtml->comments = FALSE; | |
1559 | |
1560 imhtml->smin = G_MAXINT; | |
1561 imhtml->smax = 0; | |
1562 gtk_imhtml_init_smiley_hash (imhtml); | |
1563 | |
1564 return GTK_WIDGET (imhtml); | |
1565 } | |
1566 | |
1567 void | |
1568 gtk_imhtml_set_adjustments (GtkIMHtml *imhtml, | |
1569 GtkAdjustment *hadj, | |
1570 GtkAdjustment *vadj) | |
1571 { | |
1572 gtk_layout_set_hadjustment (GTK_LAYOUT (imhtml), hadj); | |
1573 gtk_layout_set_vadjustment (GTK_LAYOUT (imhtml), vadj); | |
1574 } | |
1575 | |
1576 void | |
1577 gtk_imhtml_set_defaults (GtkIMHtml *imhtml, | |
1578 GdkFont *font, | |
1460
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
1579 GdkColor *fg_color, |
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
1580 GdkColor *bg_color) |
1428 | 1581 { |
1582 g_return_if_fail (imhtml != NULL); | |
1583 g_return_if_fail (GTK_IS_IMHTML (imhtml)); | |
1584 | |
1585 if (font) { | |
1586 if (imhtml->default_font) | |
1587 gdk_font_unref (imhtml->default_font); | |
1588 imhtml->default_font = gdk_font_ref (font); | |
1589 } | |
1590 | |
1591 if (fg_color) { | |
1592 if (imhtml->default_fg_color) | |
1593 gdk_color_free (imhtml->default_fg_color); | |
1594 imhtml->default_fg_color = gdk_color_copy (fg_color); | |
1595 } | |
1460
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
1596 |
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
1597 if (bg_color) { |
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
1598 if (imhtml->default_bg_color) |
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
1599 gdk_color_free (imhtml->default_bg_color); |
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
1600 imhtml->default_bg_color = gdk_color_copy (bg_color); |
1647
23b734cf1161
[gaim-migrate @ 1657]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1626
diff
changeset
|
1601 gdk_window_set_background (GTK_LAYOUT (imhtml)->bin_window, imhtml->default_bg_color); |
1460
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
1602 } |
1428 | 1603 } |
1604 | |
1605 void | |
1606 gtk_imhtml_set_img_handler (GtkIMHtml *imhtml, | |
1607 GtkIMHtmlImage handler) | |
1608 { | |
1609 g_return_if_fail (imhtml != NULL); | |
1610 g_return_if_fail (GTK_IS_IMHTML (imhtml)); | |
1611 | |
1612 imhtml->img = handler; | |
1613 } | |
1614 | |
1615 void | |
1616 gtk_imhtml_associate_smiley (GtkIMHtml *imhtml, | |
1617 gchar *text, | |
1618 gchar **xpm) | |
1619 { | |
1620 g_return_if_fail (imhtml != NULL); | |
1621 g_return_if_fail (GTK_IS_IMHTML (imhtml)); | |
1622 g_return_if_fail (text != NULL); | |
1623 | |
1624 if (strlen (text) < imhtml->smin) | |
1625 imhtml->smin = strlen (text); | |
1626 | |
1627 if (strlen (text) > imhtml->smax) | |
1628 imhtml->smax = strlen (text); | |
1629 | |
1519
d3ff7d80b8fb
[gaim-migrate @ 1529]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1515
diff
changeset
|
1630 if (!imhtml->smiley_start) |
d3ff7d80b8fb
[gaim-migrate @ 1529]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1515
diff
changeset
|
1631 imhtml->smiley_start = g_string_new (""); |
d3ff7d80b8fb
[gaim-migrate @ 1529]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1515
diff
changeset
|
1632 |
d3ff7d80b8fb
[gaim-migrate @ 1529]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1515
diff
changeset
|
1633 if (!strchr (imhtml->smiley_start->str, text [0])) |
d3ff7d80b8fb
[gaim-migrate @ 1529]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1515
diff
changeset
|
1634 imhtml->smiley_start = g_string_append_c (imhtml->smiley_start, text [0]); |
d3ff7d80b8fb
[gaim-migrate @ 1529]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1515
diff
changeset
|
1635 |
1428 | 1636 if (xpm == NULL) |
1637 g_hash_table_remove (imhtml->smiley_hash, text); | |
1638 else | |
1639 g_hash_table_insert (imhtml->smiley_hash, text, xpm); | |
1640 } | |
1641 | |
1642 static void | |
1643 new_line (GtkIMHtml *imhtml) | |
1644 { | |
1645 GList *last = g_list_last (imhtml->line); | |
1646 struct line_info *li; | |
1647 | |
1648 if (last) { | |
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
1649 li = last->data; |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
1650 if (li->x + li->width != imhtml->xsize - BORDER_SIZE) |
1428 | 1651 li->width = imhtml->xsize - BORDER_SIZE - li->x; |
1652 } | |
1653 | |
1654 last = imhtml->line; | |
1655 if (last) { | |
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
1656 li = last->data; |
1428 | 1657 if (li->height < MIN_HEIGHT) { |
1658 while (last) { | |
1659 gint diff; | |
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
1660 li = last->data; |
1428 | 1661 diff = MIN_HEIGHT - li->height; |
1662 li->height = MIN_HEIGHT; | |
1476
721cd9b73704
[gaim-migrate @ 1486]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1473
diff
changeset
|
1663 li->ascent += diff / 2; |
1428 | 1664 last = g_list_next (last); |
1665 } | |
1666 imhtml->llheight = MIN_HEIGHT; | |
1667 } | |
1668 } | |
1669 | |
1670 g_list_free (imhtml->line); | |
1671 imhtml->line = NULL; | |
1672 | |
1673 imhtml->x = BORDER_SIZE; | |
1674 imhtml->y += imhtml->llheight; | |
1462
1ac49082e099
[gaim-migrate @ 1472]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1461
diff
changeset
|
1675 imhtml->llheight = 0; |
1ac49082e099
[gaim-migrate @ 1472]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1461
diff
changeset
|
1676 imhtml->llascent = 0; |
1428 | 1677 } |
1678 | |
1679 static void | |
1680 backwards_update (GtkIMHtml *imhtml, | |
1681 GtkIMHtmlBit *bit, | |
1682 gint height, | |
1683 gint ascent) | |
1684 { | |
1685 gint diff; | |
1686 GList *ls = NULL; | |
1687 struct line_info *li; | |
1688 struct url_widget *uw; | |
1689 | |
1690 if (height > imhtml->llheight) { | |
1691 diff = height - imhtml->llheight; | |
1692 | |
1693 ls = imhtml->line; | |
1694 while (ls) { | |
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
1695 li = ls->data; |
1428 | 1696 li->height += diff; |
1697 if (ascent) | |
1698 li->ascent = ascent; | |
1699 else | |
1476
721cd9b73704
[gaim-migrate @ 1486]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1473
diff
changeset
|
1700 li->ascent += diff / 2; |
1428 | 1701 ls = g_list_next (ls); |
1702 } | |
1703 | |
1704 ls = imhtml->urls; | |
1705 while (ls) { | |
1706 uw = ls->data; | |
1707 if (uw->y + diff > imhtml->y) | |
1708 uw->y += diff; | |
1709 ls = g_list_next (ls); | |
1710 } | |
1711 | |
1712 imhtml->llheight = height; | |
1713 if (ascent) | |
1714 imhtml->llascent = ascent; | |
1715 else | |
1476
721cd9b73704
[gaim-migrate @ 1486]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1473
diff
changeset
|
1716 imhtml->llascent += diff / 2; |
1428 | 1717 } |
1718 } | |
1719 | |
1720 static void | |
1721 add_text_renderer (GtkIMHtml *imhtml, | |
1722 GtkIMHtmlBit *bit, | |
1723 gchar *text) | |
1724 { | |
1725 struct line_info *li; | |
1726 struct url_widget *uw; | |
1727 gint width; | |
1728 | |
1729 if (text) | |
1730 width = gdk_string_width (bit->font, text); | |
1731 else | |
1732 width = 0; | |
1733 | |
1734 li = g_new0 (struct line_info, 1); | |
1735 li->x = imhtml->x; | |
1736 li->y = imhtml->y; | |
1737 li->width = width; | |
1738 li->height = imhtml->llheight; | |
1739 if (text) | |
1740 li->ascent = MAX (imhtml->llascent, bit->font->ascent); | |
1741 else | |
1742 li->ascent = 0; | |
1743 li->text = text; | |
1744 li->bit = bit; | |
1745 | |
1746 if (bit->url) { | |
1747 uw = g_new0 (struct url_widget, 1); | |
1748 uw->x = imhtml->x; | |
1749 uw->y = imhtml->y; | |
1750 uw->width = width; | |
1751 uw->height = imhtml->llheight; | |
1574
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1752 uw->bit = bit; |
1428 | 1753 imhtml->urls = g_list_append (imhtml->urls, uw); |
1754 } | |
1755 | |
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
1756 bit->chunks = g_list_append (bit->chunks, li); |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
1757 imhtml->line = g_list_append (imhtml->line, li); |
1428 | 1758 } |
1759 | |
1760 static void | |
1761 add_img_renderer (GtkIMHtml *imhtml, | |
1762 GtkIMHtmlBit *bit) | |
1763 { | |
1764 struct line_info *li; | |
1765 struct url_widget *uw; | |
1766 gint width; | |
1767 | |
1768 gdk_window_get_size (bit->pm, &width, NULL); | |
1769 | |
1770 li = g_new0 (struct line_info, 1); | |
1771 li->x = imhtml->x; | |
1772 li->y = imhtml->y; | |
1773 li->width = width; | |
1774 li->height = imhtml->llheight; | |
1775 li->ascent = 0; | |
1776 li->bit = bit; | |
1777 | |
1778 if (bit->url) { | |
1779 uw = g_new0 (struct url_widget, 1); | |
1780 uw->x = imhtml->x; | |
1781 uw->y = imhtml->y; | |
1782 uw->width = width; | |
1783 uw->height = imhtml->llheight; | |
1574
7ad82fa9e6ce
[gaim-migrate @ 1584]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1547
diff
changeset
|
1784 uw->bit = bit; |
1428 | 1785 imhtml->urls = g_list_append (imhtml->urls, uw); |
1786 } | |
1787 | |
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
1788 bit->chunks = g_list_append (bit->chunks, li); |
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
1789 imhtml->line = g_list_append (imhtml->line, li); |
1428 | 1790 |
1791 imhtml->x += width; | |
1792 } | |
1793 | |
1794 static void | |
1795 gtk_imhtml_draw_bit (GtkIMHtml *imhtml, | |
1796 GtkIMHtmlBit *bit) | |
1797 { | |
1798 gint width, height; | |
1799 | |
1800 g_return_if_fail (imhtml != NULL); | |
1801 g_return_if_fail (GTK_IS_IMHTML (imhtml)); | |
1802 g_return_if_fail (bit != NULL); | |
1803 | |
1804 if ( (bit->type == TYPE_TEXT) || | |
1805 ((bit->type == TYPE_SMILEY) && !imhtml->smileys) || | |
1806 ((bit->type == TYPE_COMMENT) && imhtml->comments)) { | |
1807 gchar *copy = g_strdup (bit->text); | |
1808 gint pos = 0; | |
1809 gboolean seenspace = FALSE; | |
1810 gchar *tmp; | |
1811 | |
1812 height = bit->font->ascent + bit->font->descent; | |
1813 width = gdk_string_width (bit->font, bit->text); | |
1814 | |
1815 if ((imhtml->x != BORDER_SIZE) && | |
1816 ((imhtml->x + width + BORDER_SIZE + BORDER_SIZE + 5) > imhtml->xsize)) { | |
1817 gint remain = imhtml->xsize - imhtml->x - BORDER_SIZE - BORDER_SIZE - 5; | |
1818 while (gdk_text_width (bit->font, copy, pos) < remain) { | |
1819 if (copy [pos] == ' ') | |
1820 seenspace = TRUE; | |
1821 pos++; | |
1822 } | |
1823 if (seenspace) { | |
1824 while (copy [pos - 1] != ' ') pos--; | |
1825 | |
1826 tmp = g_strndup (copy, pos); | |
1827 | |
1828 backwards_update (imhtml, bit, height, bit->font->ascent); | |
1829 add_text_renderer (imhtml, bit, tmp); | |
1830 } else | |
1831 pos = 0; | |
1832 seenspace = FALSE; | |
1833 new_line (imhtml); | |
1834 } | |
1835 | |
1836 backwards_update (imhtml, bit, height, bit->font->ascent); | |
1837 | |
1838 while (pos < strlen (bit->text)) { | |
1839 width = gdk_string_width (bit->font, copy + pos); | |
1840 if (imhtml->x + width + BORDER_SIZE + BORDER_SIZE + 5 > imhtml->xsize) { | |
1841 gint newpos = 0; | |
1842 gint remain = imhtml->xsize - imhtml->x - BORDER_SIZE - BORDER_SIZE - 5; | |
1843 while (gdk_text_width (bit->font, copy + pos, newpos) < remain) { | |
1844 if (copy [pos + newpos] == ' ') | |
1845 seenspace = TRUE; | |
1846 newpos++; | |
1847 } | |
1848 | |
1849 if (seenspace) | |
1850 while (copy [pos + newpos - 1] != ' ') newpos--; | |
1851 | |
1852 if (newpos == 0) | |
1853 break; | |
1854 | |
1855 tmp = g_strndup (copy + pos, newpos); | |
1856 pos += newpos; | |
1857 | |
1462
1ac49082e099
[gaim-migrate @ 1472]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1461
diff
changeset
|
1858 backwards_update (imhtml, bit, height, bit->font->ascent); |
1428 | 1859 add_text_renderer (imhtml, bit, tmp); |
1860 | |
1861 seenspace = FALSE; | |
1862 new_line (imhtml); | |
1863 } else { | |
1864 tmp = g_strdup (copy + pos); | |
1865 | |
1462
1ac49082e099
[gaim-migrate @ 1472]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1461
diff
changeset
|
1866 backwards_update (imhtml, bit, height, bit->font->ascent); |
1428 | 1867 add_text_renderer (imhtml, bit, tmp); |
1868 | |
1869 pos = strlen (bit->text); | |
1870 | |
1871 imhtml->x += width; | |
1872 } | |
1873 } | |
1874 | |
1875 g_free (copy); | |
1876 } else if ((bit->type == TYPE_SMILEY) || (bit->type == TYPE_IMG)) { | |
1877 gdk_window_get_size (bit->pm, &width, &height); | |
1878 | |
1879 if ((imhtml->x != BORDER_SIZE) && | |
1462
1ac49082e099
[gaim-migrate @ 1472]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1461
diff
changeset
|
1880 ((imhtml->x + width + BORDER_SIZE + BORDER_SIZE + 5) > imhtml->xsize)) |
1428 | 1881 new_line (imhtml); |
1462
1ac49082e099
[gaim-migrate @ 1472]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1461
diff
changeset
|
1882 else |
1454
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
1883 backwards_update (imhtml, bit, height, 0); |
1428 | 1884 |
1885 add_img_renderer (imhtml, bit); | |
1886 } else if (bit->type == TYPE_BR) { | |
1887 new_line (imhtml); | |
1888 add_text_renderer (imhtml, bit, NULL); | |
1889 } else if (bit->type == TYPE_SEP) { | |
1454
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
1890 struct line_info *li; |
1462
1ac49082e099
[gaim-migrate @ 1472]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1461
diff
changeset
|
1891 if (imhtml->llheight) |
1428 | 1892 new_line (imhtml); |
1454
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
1893 |
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
1894 li = g_new0 (struct line_info, 1); |
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
1895 li->x = imhtml->x; |
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
1896 li->y = imhtml->y; |
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
1897 li->width = imhtml->xsize - BORDER_SIZE - BORDER_SIZE; |
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
1898 li->height = HR_HEIGHT * 2; |
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
1899 li->ascent = 0; |
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
1900 li->text = NULL; |
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
1901 li->bit = bit; |
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
1902 |
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
1903 bit->chunks = g_list_append (bit->chunks, li); |
637592eb8b24
[gaim-migrate @ 1464]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1453
diff
changeset
|
1904 |
1428 | 1905 imhtml->llheight = HR_HEIGHT * 2; |
1906 new_line (imhtml); | |
1907 add_text_renderer (imhtml, bit, NULL); | |
1908 } | |
1909 | |
1910 gtk_layout_set_size (GTK_LAYOUT (imhtml), imhtml->xsize, imhtml->y + 5); | |
1911 } | |
1912 | |
1913 void | |
1914 gtk_imhtml_show_smileys (GtkIMHtml *imhtml, | |
1915 gboolean show) | |
1916 { | |
1917 g_return_if_fail (imhtml != NULL); | |
1918 g_return_if_fail (GTK_IS_IMHTML (imhtml)); | |
1919 | |
1920 imhtml->smileys = show; | |
1921 | |
1922 if (GTK_WIDGET_VISIBLE (GTK_WIDGET (imhtml))) | |
1923 gtk_imhtml_redraw_all (imhtml); | |
1924 } | |
1925 | |
1926 void | |
1927 gtk_imhtml_show_comments (GtkIMHtml *imhtml, | |
1928 gboolean show) | |
1929 { | |
1930 g_return_if_fail (imhtml != NULL); | |
1931 g_return_if_fail (GTK_IS_IMHTML (imhtml)); | |
1932 | |
1933 imhtml->comments = show; | |
1934 | |
1935 if (GTK_WIDGET_VISIBLE (GTK_WIDGET (imhtml))) | |
1936 gtk_imhtml_redraw_all (imhtml); | |
1937 } | |
1938 | |
1939 static GdkColor * | |
1940 gtk_imhtml_get_color (const gchar *color) | |
1941 { | |
1942 GdkColor c; | |
1943 | |
1453
ecf700f23852
[gaim-migrate @ 1463]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1449
diff
changeset
|
1944 if (!gdk_color_parse (color, &c)) |
ecf700f23852
[gaim-migrate @ 1463]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1449
diff
changeset
|
1945 return NULL; |
1428 | 1946 |
1449
91d84e2073de
[gaim-migrate @ 1459]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1447
diff
changeset
|
1947 return gdk_color_copy (&c); |
1428 | 1948 } |
1949 | |
1950 static gint | |
1951 gtk_imhtml_is_smiley (GtkIMHtml *imhtml, | |
1952 const gchar *text) | |
1953 { | |
1954 gchar *tmp; | |
1955 gint i; | |
1956 | |
1957 g_return_val_if_fail (imhtml != NULL, 0); | |
1958 g_return_val_if_fail (GTK_IS_IMHTML (imhtml), 0); | |
1959 g_return_val_if_fail (text != NULL, 0); | |
1960 | |
1519
d3ff7d80b8fb
[gaim-migrate @ 1529]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1515
diff
changeset
|
1961 if (!imhtml->smiley_start || !strchr (imhtml->smiley_start->str, text [0])) |
d3ff7d80b8fb
[gaim-migrate @ 1529]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1515
diff
changeset
|
1962 return 0; |
d3ff7d80b8fb
[gaim-migrate @ 1529]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1515
diff
changeset
|
1963 |
1428 | 1964 tmp = g_malloc (imhtml->smax + 1); |
1965 | |
1966 for (i = imhtml->smin; i <= imhtml->smax; i++) { | |
1967 if (strlen (text) < i) { | |
1968 g_free (tmp); | |
1969 return 0; | |
1970 } | |
1971 g_snprintf (tmp, i + 1, "%s", text); | |
1972 if (g_hash_table_lookup (imhtml->smiley_hash, tmp)) { | |
1973 g_free (tmp); | |
1974 return i; | |
1975 } | |
1976 } | |
1977 | |
1978 g_free (tmp); | |
1979 return 0; | |
1980 } | |
1981 | |
1982 static GtkIMHtmlBit * | |
1983 gtk_imhtml_new_bit (GtkIMHtml *imhtml, | |
1984 gint type, | |
1985 gchar *text, | |
1986 gint bold, | |
1987 gint italics, | |
1988 gint underline, | |
1989 gint strike, | |
1990 FontDetail *font, | |
1991 GdkColor *bg, | |
1992 gchar *url) | |
1993 { | |
1994 GtkIMHtmlBit *bit = NULL; | |
1995 | |
1996 g_return_val_if_fail (imhtml != NULL, NULL); | |
1997 g_return_val_if_fail (GTK_IS_IMHTML (imhtml), NULL); | |
1998 | |
1999 if ((type == TYPE_TEXT) && ((text == NULL) || (strlen (text) == 0))) | |
2000 return NULL; | |
2001 | |
2002 bit = g_new0 (GtkIMHtmlBit, 1); | |
2003 bit->type = type; | |
2004 | |
2005 if ((text != NULL) && (strlen (text) != 0)) | |
2006 bit->text = g_strdup (text); | |
2007 | |
2008 if ((font != NULL) || bold || italics) { | |
2009 if (font && (bold || italics || font->size || font->face)) { | |
2010 bit->font = gtk_imhtml_font_load (imhtml, font->face, bold, italics, font->size); | |
2011 } else if (bold || italics) { | |
2012 bit->font = gtk_imhtml_font_load (imhtml, NULL, bold, italics, 0); | |
2013 } | |
2014 | |
2015 if (font && (type != TYPE_BR)) { | |
2016 if (font->fore != NULL) | |
2017 bit->fore = gdk_color_copy (font->fore); | |
2018 | |
2019 if (font->back != NULL) | |
2020 bit->back = gdk_color_copy (font->back); | |
2021 } | |
2022 } | |
2023 | |
2024 if (((bit->type == TYPE_TEXT) || (bit->type == TYPE_SMILEY) || (bit->type == TYPE_COMMENT)) && | |
2025 (bit->font == NULL)) | |
2026 bit->font = gdk_font_ref (imhtml->default_font); | |
2027 | |
2028 if (bg != NULL) | |
2029 bit->bg = gdk_color_copy (bg); | |
2030 | |
2031 bit->underline = underline; | |
2032 bit->strike = strike; | |
2033 | |
2034 if (url != NULL) | |
2035 bit->url = g_strdup (url); | |
2036 | |
2037 if (type == TYPE_SMILEY) { | |
2038 GdkColor *clr; | |
2039 | |
2040 if ((font != NULL) && (font->back != NULL)) | |
2041 clr = font->back; | |
2042 else | |
1460
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
2043 clr = (bg != NULL) ? bg : imhtml->default_bg_color; |
1428 | 2044 |
2045 bit->pm = gdk_pixmap_create_from_xpm_d (GTK_WIDGET (imhtml)->window, | |
2046 &bit->bm, | |
2047 clr, | |
2048 g_hash_table_lookup (imhtml->smiley_hash, text)); | |
2049 } | |
2050 | |
2051 return bit; | |
2052 } | |
2053 | |
2054 #define NEW_TEXT_BIT gtk_imhtml_new_bit (imhtml, TYPE_TEXT, ws, bold, italics, underline, strike, \ | |
2055 fonts ? fonts->data : NULL, bg, url) | |
2056 #define NEW_SMILEY_BIT gtk_imhtml_new_bit (imhtml, TYPE_SMILEY, ws, bold, italics, underline, strike, \ | |
2057 fonts ? fonts->data : NULL, bg, url) | |
2058 #define NEW_SEP_BIT gtk_imhtml_new_bit (imhtml, TYPE_SEP, NULL, 0, 0, 0, 0, NULL, bg, NULL) | |
2059 #define NEW_BR_BIT gtk_imhtml_new_bit (imhtml, TYPE_BR, NULL, 0, 0, 0, 0, \ | |
2060 fonts ? fonts->data : NULL, bg, NULL) | |
2061 #define NEW_COMMENT_BIT gtk_imhtml_new_bit (imhtml, TYPE_COMMENT, ws, bold, italics, underline, strike, \ | |
2062 fonts ? fonts->data : NULL, bg, url) | |
2063 | |
2064 #define NEW_BIT(bit) { GtkIMHtmlBit *tmp = bit; if (tmp != NULL) \ | |
2065 newbits = g_list_append (newbits, tmp); } | |
2066 | |
2067 #define UPDATE_BG_COLORS \ | |
2068 { \ | |
2069 GdkColormap *cmap; \ | |
2070 GList *rev; \ | |
1476
721cd9b73704
[gaim-migrate @ 1486]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1473
diff
changeset
|
2071 cmap = gtk_widget_get_colormap (GTK_WIDGET (imhtml)); \ |
1428 | 2072 rev = g_list_last (newbits); \ |
2073 while (rev) { \ | |
2074 GtkIMHtmlBit *bit = rev->data; \ | |
2075 if (bit->bg) \ | |
2076 gdk_color_free (bit->bg); \ | |
2077 bit->bg = gdk_color_copy (bg); \ | |
1582
4fcd012c0a6a
[gaim-migrate @ 1592]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1574
diff
changeset
|
2078 if (bit->type == TYPE_BR) \ |
4fcd012c0a6a
[gaim-migrate @ 1592]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1574
diff
changeset
|
2079 break; \ |
1428 | 2080 rev = g_list_previous (rev); \ |
2081 } \ | |
2082 if (!rev) { \ | |
2083 rev = g_list_last (imhtml->bits); \ | |
2084 while (rev) { \ | |
2085 GtkIMHtmlBit *bit = rev->data; \ | |
2086 if (bit->bg) \ | |
2087 gdk_color_free (bit->bg); \ | |
2088 bit->bg = gdk_color_copy (bg); \ | |
2089 gdk_color_alloc (cmap, bit->bg); \ | |
1582
4fcd012c0a6a
[gaim-migrate @ 1592]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1574
diff
changeset
|
2090 if (bit->type == TYPE_BR) \ |
4fcd012c0a6a
[gaim-migrate @ 1592]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1574
diff
changeset
|
2091 break; \ |
1428 | 2092 rev = g_list_previous (rev); \ |
2093 } \ | |
2094 } \ | |
2095 } | |
2096 | |
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2097 static gboolean |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2098 is_amp_escape (const gchar *string, |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2099 gchar *replace, |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2100 gint *length) |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2101 { |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2102 g_return_val_if_fail (string != NULL, FALSE); |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2103 g_return_val_if_fail (replace != NULL, FALSE); |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2104 g_return_val_if_fail (length != NULL, FALSE); |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2105 |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2106 if (!g_strncasecmp (string, "&", 5)) { |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2107 *replace = '&'; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2108 *length = 5; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2109 } else if (!g_strncasecmp (string, "<", 4)) { |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2110 *replace = '<'; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2111 *length = 4; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2112 } else if (!g_strncasecmp (string, ">", 4)) { |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2113 *replace = '>'; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2114 *length = 4; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2115 } else if (!g_strncasecmp (string, " ", 6)) { |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2116 *replace = ' '; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2117 *length = 6; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2118 } else if (!g_strncasecmp (string, "©", 6)) { |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2119 *replace = '©'; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2120 *length = 6; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2121 } else if (!g_strncasecmp (string, """, 6)) { |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2122 *replace = '\"'; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2123 *length = 6; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2124 } else if (!g_strncasecmp (string, "®", 5)) { |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2125 *replace = '®'; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2126 *length = 5; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2127 } else if (*(string + 1) == '#') { |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2128 gint pound = 0; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2129 if (sscanf (string, "&#%d;", £) == 1) { |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2130 if (*(string + 3 + (gint)log10 (pound)) != ';') |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2131 return FALSE; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2132 *replace = (gchar)pound; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2133 *length = 2; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2134 while (isdigit ((gint) string [*length])) (*length)++; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2135 if (string [*length] == ';') (*length)++; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2136 } else { |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2137 return FALSE; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2138 } |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2139 } else { |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2140 return FALSE; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2141 } |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2142 |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2143 return TRUE; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2144 } |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2145 |
1428 | 2146 GString* |
2147 gtk_imhtml_append_text (GtkIMHtml *imhtml, | |
2148 const gchar *text, | |
2149 GtkIMHtmlOptions options) | |
2150 { | |
2151 const gchar *c; | |
2152 gboolean intag = FALSE; | |
2153 gboolean tagquote = FALSE; | |
2154 gboolean incomment = FALSE; | |
2155 gchar *ws; | |
2156 gchar *tag; | |
2157 gint wpos = 0; | |
2158 gint tpos = 0; | |
2159 int smilelen; | |
2160 GList *newbits = NULL; | |
2161 | |
2162 guint bold = 0, | |
2163 italics = 0, | |
2164 underline = 0, | |
2165 strike = 0, | |
2166 sub = 0, | |
2167 sup = 0, | |
2168 title = 0; | |
2169 GSList *fonts = NULL; | |
2170 GdkColor *bg = NULL; | |
2171 gchar *url = NULL; | |
2172 | |
2173 GtkAdjustment *vadj; | |
2174 gboolean scrolldown = TRUE; | |
2175 | |
2176 GString *retval = NULL; | |
2177 | |
2178 g_return_val_if_fail (imhtml != NULL, NULL); | |
2179 g_return_val_if_fail (GTK_IS_IMHTML (imhtml), NULL); | |
2180 g_return_val_if_fail (text != NULL, NULL); | |
2181 | |
2182 if (options & GTK_IMHTML_RETURN_LOG) | |
2183 retval = g_string_new (""); | |
2184 | |
2185 vadj = GTK_LAYOUT (imhtml)->vadjustment; | |
2186 if ((vadj->value < imhtml->y + 5 - GTK_WIDGET (imhtml)->allocation.height) && | |
2187 (vadj->upper >= GTK_WIDGET (imhtml)->allocation.height)) | |
2188 scrolldown = FALSE; | |
2189 | |
2190 c = text; | |
2191 ws = g_malloc (strlen (text) + 1); | |
2192 tag = g_malloc (strlen (text) + 1); | |
2193 | |
2194 ws [0] = '\0'; | |
2195 | |
2196 while (*c) { | |
2197 if (*c == '<') { | |
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2198 if (intag && !tagquote) { |
1460
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
2199 char *d; |
1428 | 2200 tag [tpos] = 0; |
1460
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
2201 d = tag; |
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
2202 while (*d) { |
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
2203 if ((smilelen = gtk_imhtml_is_smiley (imhtml, d)) != 0) { |
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
2204 ws [wpos] = 0; |
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
2205 wpos = 0; |
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
2206 NEW_BIT (NEW_TEXT_BIT); |
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
2207 g_snprintf (ws, smilelen + 1, "%s", d); |
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
2208 NEW_BIT (NEW_SMILEY_BIT); |
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
2209 d += smilelen; |
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2210 } else if (*d == '&') { |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2211 gchar replace; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2212 gint length; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2213 if (is_amp_escape (d, &replace, &length)) { |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2214 ws [wpos++] = replace; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2215 d += length; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2216 } else { |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2217 ws [wpos++] = *d++; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2218 } |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2219 } else if (*d == '\n') { |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2220 if (!(options & GTK_IMHTML_NO_NEWLINE)) { |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2221 ws [wpos] = 0; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2222 wpos = 0; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2223 NEW_BIT (NEW_TEXT_BIT); |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2224 NEW_BIT (NEW_BR_BIT); |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2225 } |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2226 d++; |
1460
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
2227 } else { |
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
2228 ws [wpos++] = *d++; |
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
2229 } |
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
2230 } |
1428 | 2231 tpos = 0; |
2232 } | |
2233 | |
2234 if (incomment) { | |
2235 ws [wpos++] = *c++; | |
2236 continue; | |
2237 } | |
2238 | |
2239 if (!g_strncasecmp (c, "<!--", strlen ("<!--"))) { | |
2240 if (!(options & GTK_IMHTML_NO_COMMENTS)) { | |
2241 ws [wpos] = 0; | |
2242 wpos = 0; | |
2243 tag [tpos] = 0; | |
2244 strcat (tag, ws); | |
2245 incomment = TRUE; | |
2246 intag = FALSE; | |
2247 } | |
2248 ws [wpos++] = *c++; | |
2249 ws [wpos++] = *c++; | |
2250 ws [wpos++] = *c++; | |
2251 ws [wpos++] = *c++; | |
2252 continue; | |
2253 } | |
2254 | |
2255 tag [tpos++] = *c++; | |
2256 intag = TRUE; | |
2257 } else if (incomment && (*c == '-') && !g_strncasecmp (c, "-->", strlen ("-->"))) { | |
2258 gchar *tmp; | |
2259 ws [wpos] = 0; | |
2260 wpos = 0; | |
2261 tmp = g_strdup (ws); | |
2262 ws [wpos] = 0; | |
2263 strcat (ws, tag); | |
2264 NEW_BIT (NEW_TEXT_BIT); | |
2265 ws [wpos] = 0; | |
2266 strcat (ws, tmp + strlen ("<!--")); | |
2267 g_free (tmp); | |
2268 NEW_BIT (NEW_COMMENT_BIT); | |
2269 incomment = FALSE; | |
2270 c += strlen ("-->"); | |
2271 } else if (*c == '>' && intag && !tagquote) { | |
2272 gboolean got_tag = FALSE; | |
2273 tag [tpos++] = *c++; | |
2274 tag [tpos] = 0; | |
2275 ws [wpos] = 0; | |
2276 | |
2277 if (!g_strcasecmp (tag, "<B>") || !g_strcasecmp (tag, "<BOLD>")) { | |
2278 got_tag = TRUE; | |
2279 NEW_BIT (NEW_TEXT_BIT); | |
2280 bold++; | |
2281 } else if (!g_strcasecmp (tag, "</B>") || !g_strcasecmp (tag, "</BOLD>")) { | |
2282 got_tag = TRUE; | |
1626
59c7e7831ccd
[gaim-migrate @ 1636]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1613
diff
changeset
|
2283 NEW_BIT (NEW_TEXT_BIT); |
1428 | 2284 if (bold) { |
2285 bold--; | |
2286 } | |
2287 } else if (!g_strcasecmp (tag, "<I>") || !g_strcasecmp (tag, "<ITALIC>")) { | |
2288 got_tag = TRUE; | |
2289 NEW_BIT (NEW_TEXT_BIT); | |
2290 italics++; | |
2291 } else if (!g_strcasecmp (tag, "</I>") || !g_strcasecmp (tag, "</ITALIC>")) { | |
2292 got_tag = TRUE; | |
1626
59c7e7831ccd
[gaim-migrate @ 1636]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1613
diff
changeset
|
2293 NEW_BIT (NEW_TEXT_BIT); |
1428 | 2294 if (italics) { |
2295 italics--; | |
2296 } | |
2297 } else if (!g_strcasecmp (tag, "<U>") || !g_strcasecmp (tag, "<UNDERLINE>")) { | |
2298 got_tag = TRUE; | |
2299 NEW_BIT (NEW_TEXT_BIT); | |
2300 underline++; | |
2301 } else if (!g_strcasecmp (tag, "</U>") || !g_strcasecmp (tag, "</UNDERLINE>")) { | |
2302 got_tag = TRUE; | |
1626
59c7e7831ccd
[gaim-migrate @ 1636]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1613
diff
changeset
|
2303 NEW_BIT (NEW_TEXT_BIT); |
1428 | 2304 if (underline) { |
2305 underline--; | |
2306 } | |
2307 } else if (!g_strcasecmp (tag, "<S>") || !g_strcasecmp (tag, "<STRIKE>")) { | |
2308 got_tag = TRUE; | |
2309 NEW_BIT (NEW_TEXT_BIT); | |
2310 strike++; | |
2311 } else if (!g_strcasecmp (tag, "</S>") || !g_strcasecmp (tag, "</STRIKE>")) { | |
2312 got_tag = TRUE; | |
1626
59c7e7831ccd
[gaim-migrate @ 1636]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1613
diff
changeset
|
2313 NEW_BIT (NEW_TEXT_BIT); |
1428 | 2314 if (strike) { |
2315 strike--; | |
2316 } | |
2317 } else if (!g_strcasecmp (tag, "<SUB>")) { | |
2318 got_tag = TRUE; | |
1626
59c7e7831ccd
[gaim-migrate @ 1636]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1613
diff
changeset
|
2319 NEW_BIT (NEW_TEXT_BIT); |
1428 | 2320 sub++; |
2321 } else if (!g_strcasecmp (tag, "</SUB>")) { | |
2322 got_tag = TRUE; | |
1626
59c7e7831ccd
[gaim-migrate @ 1636]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1613
diff
changeset
|
2323 NEW_BIT (NEW_TEXT_BIT); |
1428 | 2324 if (sub) { |
2325 sub--; | |
2326 } | |
2327 } else if (!g_strcasecmp (tag, "<SUP>")) { | |
2328 got_tag = TRUE; | |
1626
59c7e7831ccd
[gaim-migrate @ 1636]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1613
diff
changeset
|
2329 NEW_BIT (NEW_TEXT_BIT); |
1428 | 2330 sup++; |
2331 } else if (!g_strcasecmp (tag, "</SUP>")) { | |
2332 got_tag = TRUE; | |
1626
59c7e7831ccd
[gaim-migrate @ 1636]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1613
diff
changeset
|
2333 NEW_BIT (NEW_TEXT_BIT); |
1428 | 2334 if (sup) { |
2335 sup--; | |
2336 } | |
2337 } else if (!g_strcasecmp (tag, "<TITLE>")) { | |
2338 if (options & GTK_IMHTML_NO_TITLE) { | |
2339 got_tag = TRUE; | |
1626
59c7e7831ccd
[gaim-migrate @ 1636]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1613
diff
changeset
|
2340 NEW_BIT (NEW_TEXT_BIT); |
1428 | 2341 title++; |
2342 } else { | |
2343 intag = FALSE; | |
2344 tpos = 0; | |
2345 continue; | |
2346 } | |
2347 } else if (!g_strcasecmp (tag, "</TITLE>")) { | |
2348 if (title) { | |
2349 got_tag = TRUE; | |
2350 wpos = 0; | |
2351 ws [wpos] = '\0'; | |
2352 title--; | |
2353 } else { | |
2354 intag = FALSE; | |
2355 tpos = 0; | |
2356 continue; | |
2357 } | |
2358 } else if (!g_strcasecmp (tag, "<BR>")) { | |
2359 got_tag = TRUE; | |
2360 NEW_BIT (NEW_TEXT_BIT); | |
2361 NEW_BIT (NEW_BR_BIT); | |
2362 } else if (!g_strcasecmp (tag, "<HR>") || | |
2363 !g_strncasecmp (tag, "<HR ", strlen ("<HR "))) { | |
2364 got_tag = TRUE; | |
2365 NEW_BIT (NEW_TEXT_BIT); | |
2366 NEW_BIT (NEW_SEP_BIT); | |
2367 } else if (!g_strncasecmp (tag, "<FONT ", strlen ("<FONT "))) { | |
2368 gchar *t, *e, *a, *value; | |
2369 FontDetail *font = NULL; | |
2370 GdkColor *clr; | |
2371 gint saw; | |
2372 gint i; | |
2373 | |
2374 t = tag + strlen ("<FONT "); | |
2375 | |
2376 while (*t != '\0') { | |
2377 value = NULL; | |
2378 saw = 0; | |
2379 | |
2380 while (g_strncasecmp (t, "COLOR=", strlen ("COLOR=")) | |
2381 && g_strncasecmp (t, "BACK=", strlen ("BACK=")) | |
2382 && g_strncasecmp (t, "FACE=", strlen ("FACE=")) | |
2383 && g_strncasecmp (t, "SIZE=", strlen ("SIZE="))) { | |
2384 gboolean quote = FALSE; | |
2385 if (*t == '\0') break; | |
2386 while (*t && !((*t == ' ') && !quote)) { | |
2387 if (*t == '\"') | |
2388 quote = ! quote; | |
2389 t++; | |
2390 } | |
2391 while (*t && (*t == ' ')) t++; | |
2392 } | |
2393 | |
2394 if (!g_strncasecmp (t, "COLOR=", strlen ("COLOR="))) { | |
2395 t += strlen ("COLOR="); | |
2396 saw = 1; | |
2397 } else if (!g_strncasecmp (t, "BACK=", strlen ("BACK="))) { | |
2398 t += strlen ("BACK="); | |
2399 saw = 2; | |
2400 } else if (!g_strncasecmp (t, "FACE=", strlen ("FACE="))) { | |
2401 t += strlen ("FACE="); | |
2402 saw = 3; | |
2403 } else if (!g_strncasecmp (t, "SIZE=", strlen ("SIZE="))) { | |
2404 t += strlen ("SIZE="); | |
2405 saw = 4; | |
2406 } | |
2407 | |
2408 if (!saw) | |
2409 continue; | |
2410 | |
2411 if ((*t == '\"') || (*t == '\'')) { | |
2412 e = a = ++t; | |
2413 while (*e && (*e != *(t - 1))) e++; | |
2414 if (*e != '\0') { | |
2415 *e = '\0'; | |
2416 t = e + 1; | |
2417 value = g_strdup (a); | |
2418 } else { | |
2419 *t = '\0'; | |
2420 } | |
2421 } else { | |
2422 e = a = t; | |
2423 while (*e && !isspace ((gint) *e)) e++; | |
2424 if (*e == '\0') e--; | |
2425 *e = '\0'; | |
2426 t = e + 1; | |
2427 value = g_strdup (a); | |
2428 } | |
2429 | |
2430 if (value == NULL) | |
2431 continue; | |
2432 | |
2433 if (font == NULL) | |
2434 font = g_new0 (FontDetail, 1); | |
2435 | |
2436 switch (saw) { | |
2437 case 1: | |
2438 clr = gtk_imhtml_get_color (value); | |
2439 if (clr != NULL) { | |
2440 if ( (font->fore == NULL) && | |
2441 !(options & GTK_IMHTML_NO_COLOURS)) | |
2442 font->fore = clr; | |
2443 } | |
2444 break; | |
2445 case 2: | |
2446 clr = gtk_imhtml_get_color (value); | |
2447 if (clr != NULL) { | |
2448 if ( (font->back == NULL) && | |
2449 !(options & GTK_IMHTML_NO_COLOURS)) | |
2450 font->back = clr; | |
2451 } | |
2452 break; | |
2453 case 3: | |
2454 if ( (font->face == NULL) && | |
2455 !(options & GTK_IMHTML_NO_FONTS)) | |
2456 font->face = g_strdup (value); | |
2457 break; | |
2458 case 4: | |
2459 if ((font->size != 0) || | |
2460 (options & GTK_IMHTML_NO_SIZES)) | |
2461 break; | |
2462 | |
2463 if (isdigit ((gint) value [0])) { | |
2464 for (i = 0; i < strlen (value); i++) | |
2465 if (!isdigit ((gint) value [i])) | |
2466 break; | |
2467 if (i != strlen (value)) | |
2468 break; | |
2469 | |
2470 sscanf (value, "%hd", &font->size); | |
2471 break; | |
2472 } | |
2473 | |
2474 if ((value [0] == '+') && (value [1] != '\0')) { | |
2475 for (i = 1; i < strlen (value); i++) | |
2476 if (!isdigit ((gint) value [i])) | |
2477 break; | |
2478 if (i != strlen (value)) | |
2479 break; | |
2480 | |
2481 sscanf (value + 1, "%hd", &font->size); | |
2482 font->size += 3; | |
2483 break; | |
2484 } | |
2485 | |
2486 if ((value [0] == '-') && (value [1] != '\0')) { | |
2487 for (i = 1; i < strlen (value); i++) | |
2488 if (!isdigit ((gint) value [i])) | |
2489 break; | |
2490 if (i != strlen (value)) | |
2491 break; | |
2492 | |
2493 sscanf (value + 1, "%hd", &font->size); | |
2494 font->size = MIN (font->size, 2); | |
2495 font->size = 3 - font->size; | |
2496 break; | |
2497 } | |
2498 | |
2499 break; | |
2500 } | |
2501 | |
2502 g_free (value); | |
2503 } | |
2504 | |
2505 if (!font) { | |
2506 intag = FALSE; | |
2507 tpos = 0; | |
2508 continue; | |
2509 } | |
2510 | |
1482
68d44466c0b0
[gaim-migrate @ 1492]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1476
diff
changeset
|
2511 if (font->size || font->face || font->fore || font->back) |
68d44466c0b0
[gaim-migrate @ 1492]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1476
diff
changeset
|
2512 NEW_BIT (NEW_TEXT_BIT); |
1428 | 2513 |
2514 if (fonts) { | |
2515 FontDetail *oldfont = fonts->data; | |
2516 if (!font->size) | |
2517 font->size = oldfont->size; | |
2518 if (!font->face) | |
2519 font->face = g_strdup (oldfont->face); | |
2520 if (!font->fore && oldfont->fore) | |
2521 font->fore = gdk_color_copy (oldfont->fore); | |
2522 if (!font->back && oldfont->back) | |
2523 font->back = gdk_color_copy (oldfont->back); | |
2524 } else { | |
2525 if (!font->size) | |
2526 font->size = 3; | |
2527 if (!font->face) | |
2528 font->face = g_strdup ("helvetica"); | |
2529 } | |
2530 | |
2531 fonts = g_slist_prepend (fonts, font); | |
2532 got_tag = TRUE; | |
2533 } else if (!g_strcasecmp (tag, "</FONT>")) { | |
2534 FontDetail *font; | |
2535 | |
2536 if (fonts) { | |
2537 got_tag = TRUE; | |
2538 NEW_BIT (NEW_TEXT_BIT); | |
2539 font = fonts->data; | |
2540 fonts = g_slist_remove (fonts, font); | |
2541 g_free (font->face); | |
2542 if (font->fore) | |
2543 gdk_color_free (font->fore); | |
2544 if (font->back) | |
2545 gdk_color_free (font->back); | |
2546 g_free (font); | |
2547 } else { | |
2548 intag = FALSE; | |
2549 tpos = 0; | |
2550 continue; | |
2551 } | |
2552 } else if (!g_strncasecmp (tag, "<BODY ", strlen ("<BODY "))) { | |
2553 gchar *t, *e, *color = NULL; | |
2554 GdkColor *tmp; | |
2555 | |
2556 got_tag = TRUE; | |
2557 | |
2558 if (!(options & GTK_IMHTML_NO_COLOURS)) { | |
2559 t = tag + strlen ("<BODY"); | |
2560 do { | |
2561 gboolean quote = FALSE; | |
2562 if (*t == '\0') break; | |
2563 while (*t && !((*t == ' ') && !quote)) { | |
2564 if (*t == '\"') | |
2565 quote = ! quote; | |
2566 t++; | |
2567 } | |
2568 while (*t && (*t == ' ')) t++; | |
2569 } while (g_strncasecmp (t, "BGCOLOR=", strlen ("BGCOLOR="))); | |
2570 | |
2571 if (!g_strncasecmp (t, "BGCOLOR=", strlen ("BGCOLOR="))) { | |
2572 t += strlen ("BGCOLOR="); | |
2573 if ((*t == '\"') || (*t == '\'')) { | |
2574 e = ++t; | |
2575 while (*e && (*e != *(t - 1))) e++; | |
2576 if (*e != '\0') { | |
2577 *e = '\0'; | |
2578 color = g_strdup (t); | |
2579 } | |
2580 } else { | |
2581 e = t; | |
2582 while (*e && !isspace ((gint) *e)) e++; | |
2583 if (*e == '\0') e--; | |
2584 *e = '\0'; | |
2585 color = g_strdup (t); | |
2586 } | |
2587 | |
2588 if (color != NULL) { | |
2589 tmp = gtk_imhtml_get_color (color); | |
2590 g_free (color); | |
2591 if (tmp != NULL) { | |
2592 NEW_BIT (NEW_TEXT_BIT); | |
2593 bg = tmp; | |
2594 UPDATE_BG_COLORS; | |
2595 } | |
2596 } | |
2597 } | |
2598 } | |
2599 } else if (!g_strncasecmp (tag, "<A ", strlen ("<A "))) { | |
2600 gchar *t, *e; | |
2601 | |
2602 got_tag = TRUE; | |
2603 NEW_BIT (NEW_TEXT_BIT); | |
2604 | |
2605 if (url != NULL) | |
2606 g_free (url); | |
2607 url = NULL; | |
2608 | |
2609 t = tag + strlen ("<A"); | |
2610 do { | |
2611 gboolean quote = FALSE; | |
2612 if (*t == '\0') break; | |
2613 while (*t && !((*t == ' ') && !quote)) { | |
2614 if (*t == '\"') | |
2615 quote = ! quote; | |
2616 t++; | |
2617 } | |
2618 while (*t && (*t == ' ')) t++; | |
2619 } while (g_strncasecmp (t, "HREF=", strlen ("HREF="))); | |
2620 | |
2621 if (!g_strncasecmp (t, "HREF=", strlen ("HREF="))) { | |
2622 t += strlen ("HREF="); | |
2623 if ((*t == '\"') || (*t == '\'')) { | |
2624 e = ++t; | |
2625 while (*e && (*e != *(t - 1))) e++; | |
2626 if (*e != '\0') { | |
2627 *e = '\0'; | |
2628 url = g_strdup (t); | |
2629 } | |
2630 } else { | |
2631 e = t; | |
2632 while (*e && !isspace ((gint) *e)) e++; | |
2633 if (*e == '\0') e--; | |
2634 *e = '\0'; | |
2635 url = g_strdup (t); | |
2636 } | |
2637 } | |
2638 } else if (!g_strcasecmp (tag, "</A>")) { | |
2639 if (url != NULL) { | |
1524
a5c87ada5143
[gaim-migrate @ 1534]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1519
diff
changeset
|
2640 got_tag = TRUE; |
1428 | 2641 NEW_BIT (NEW_TEXT_BIT); |
2642 g_free (url); | |
1524
a5c87ada5143
[gaim-migrate @ 1534]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1519
diff
changeset
|
2643 url = NULL; |
a5c87ada5143
[gaim-migrate @ 1534]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1519
diff
changeset
|
2644 } else { |
a5c87ada5143
[gaim-migrate @ 1534]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1519
diff
changeset
|
2645 intag = FALSE; |
a5c87ada5143
[gaim-migrate @ 1534]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1519
diff
changeset
|
2646 tpos = 0; |
a5c87ada5143
[gaim-migrate @ 1534]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1519
diff
changeset
|
2647 continue; |
1428 | 2648 } |
2649 } else if (!g_strncasecmp (tag, "<IMG ", strlen ("<IMG "))) { | |
2650 gchar *t, *e, *src = NULL; | |
2651 gchar *copy = g_strdup (tag); | |
2652 gchar **xpm; | |
2653 GdkColor *clr = NULL; | |
2654 GtkIMHtmlBit *bit; | |
2655 | |
2656 intag = FALSE; | |
2657 tpos = 0; | |
2658 | |
1453
ecf700f23852
[gaim-migrate @ 1463]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1449
diff
changeset
|
2659 if (imhtml->img == NULL) { |
ecf700f23852
[gaim-migrate @ 1463]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1449
diff
changeset
|
2660 ws [wpos] = 0; |
ecf700f23852
[gaim-migrate @ 1463]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1449
diff
changeset
|
2661 strcat (ws, copy); |
ecf700f23852
[gaim-migrate @ 1463]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1449
diff
changeset
|
2662 wpos = strlen (ws); |
ecf700f23852
[gaim-migrate @ 1463]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1449
diff
changeset
|
2663 g_free (copy); |
1428 | 2664 continue; |
1453
ecf700f23852
[gaim-migrate @ 1463]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1449
diff
changeset
|
2665 } |
1428 | 2666 |
2667 t = tag + strlen ("<IMG"); | |
2668 do { | |
2669 gboolean quote = FALSE; | |
2670 if (*t == '\0') break; | |
2671 while (*t && !((*t == ' ') && !quote)) { | |
2672 if (*t == '\"') | |
2673 quote = ! quote; | |
2674 t++; | |
2675 } | |
2676 while (*t && (*t == ' ')) t++; | |
2677 } while (g_strncasecmp (t, "SRC=", strlen ("SRC="))); | |
2678 | |
2679 if (!g_strncasecmp (t, "SRC=", strlen ("SRC="))) { | |
2680 t += strlen ("SRC="); | |
2681 if ((*t == '\"') || (*t == '\'')) { | |
2682 e = ++t; | |
2683 while (*e && (*e != *(t - 1))) e++; | |
2684 if (*e != '\0') { | |
2685 *e = '\0'; | |
2686 src = g_strdup (t); | |
2687 } | |
2688 } else { | |
2689 e = t; | |
2690 while (*e && !isspace ((gint) *e)) e++; | |
2691 if (*e == '\0') e--; | |
2692 *e = '\0'; | |
2693 src = g_strdup (t); | |
2694 } | |
2695 } | |
2696 | |
2697 if (src == NULL) { | |
2698 ws [wpos] = 0; | |
2699 strcat (ws, copy); | |
2700 wpos = strlen (ws); | |
2701 g_free (copy); | |
2702 continue; | |
2703 } | |
2704 | |
2705 xpm = (* imhtml->img) (src); | |
2706 if (xpm == NULL) { | |
2707 g_free (src); | |
2708 ws [wpos] = 0; | |
2709 strcat (ws, copy); | |
2710 wpos = strlen (ws); | |
2711 g_free (copy); | |
2712 continue; | |
2713 } | |
2714 | |
2715 g_free (copy); | |
2716 | |
2717 if (!fonts || ((clr = ((FontDetail *)fonts->data)->back) == NULL)) | |
1460
36c56d591674
[gaim-migrate @ 1470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1456
diff
changeset
|
2718 clr = (bg != NULL) ? bg : imhtml->default_bg_color; |
1428 | 2719 |
2720 if (!GTK_WIDGET_REALIZED (imhtml)) | |
2721 gtk_widget_realize (GTK_WIDGET (imhtml)); | |
2722 | |
2723 bit = g_new0 (GtkIMHtmlBit, 1); | |
2724 bit->type = TYPE_IMG; | |
2725 bit->pm = gdk_pixmap_create_from_xpm_d (GTK_WIDGET (imhtml)->window, | |
2726 &bit->bm, | |
2727 clr, | |
2728 xpm); | |
2729 if (url) | |
2730 bit->url = g_strdup (url); | |
2731 | |
2732 NEW_BIT (bit); | |
2733 | |
2734 g_free (src); | |
2735 | |
2736 continue; | |
2737 } else if (!g_strcasecmp (tag, "<P>") || | |
2738 !g_strcasecmp (tag, "</P>") || | |
2739 !g_strncasecmp (tag, "<P ", strlen ("<P ")) || | |
2740 !g_strcasecmp (tag, "<PRE>") || | |
2741 !g_strcasecmp (tag, "</PRE>") || | |
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
2742 !g_strcasecmp (tag, "<H3>") || |
1473
38e8391aa563
[gaim-migrate @ 1483]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1472
diff
changeset
|
2743 !g_strncasecmp (tag, "<H3 ", strlen ("<H3 ")) || |
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
2744 !g_strcasecmp (tag, "</H3>") || |
1428 | 2745 !g_strcasecmp (tag, "<HTML>") || |
2746 !g_strcasecmp (tag, "</HTML>") || | |
2747 !g_strcasecmp (tag, "<BODY>") || | |
2748 !g_strcasecmp (tag, "</BODY>") || | |
2749 !g_strcasecmp (tag, "<FONT>") || | |
2750 !g_strcasecmp (tag, "<HEAD>") || | |
2751 !g_strcasecmp (tag, "</HEAD>")) { | |
2752 intag = FALSE; | |
2753 tpos = 0; | |
2754 continue; | |
2755 } | |
2756 | |
2757 if (!got_tag) { | |
1463
2f317467d2f9
[gaim-migrate @ 1473]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1462
diff
changeset
|
2758 char *d; |
2f317467d2f9
[gaim-migrate @ 1473]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1462
diff
changeset
|
2759 tag [tpos] = 0; |
2f317467d2f9
[gaim-migrate @ 1473]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1462
diff
changeset
|
2760 d = tag; |
2f317467d2f9
[gaim-migrate @ 1473]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1462
diff
changeset
|
2761 while (*d) { |
2f317467d2f9
[gaim-migrate @ 1473]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1462
diff
changeset
|
2762 if ((smilelen = gtk_imhtml_is_smiley (imhtml, d)) != 0) { |
2f317467d2f9
[gaim-migrate @ 1473]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1462
diff
changeset
|
2763 ws [wpos] = 0; |
2f317467d2f9
[gaim-migrate @ 1473]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1462
diff
changeset
|
2764 wpos = 0; |
2f317467d2f9
[gaim-migrate @ 1473]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1462
diff
changeset
|
2765 NEW_BIT (NEW_TEXT_BIT); |
2f317467d2f9
[gaim-migrate @ 1473]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1462
diff
changeset
|
2766 g_snprintf (ws, smilelen + 1, "%s", d); |
2f317467d2f9
[gaim-migrate @ 1473]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1462
diff
changeset
|
2767 NEW_BIT (NEW_SMILEY_BIT); |
2f317467d2f9
[gaim-migrate @ 1473]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1462
diff
changeset
|
2768 d += smilelen; |
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2769 } else if (*d == '&') { |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2770 gchar replace; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2771 gint length; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2772 if (is_amp_escape (d, &replace, &length)) { |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2773 ws [wpos++] = replace; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2774 d += length; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2775 } else { |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2776 ws [wpos++] = *d++; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2777 } |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2778 } else if (*d == '\n') { |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2779 if (!(options & GTK_IMHTML_NO_NEWLINE)) { |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2780 ws [wpos] = 0; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2781 wpos = 0; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2782 NEW_BIT (NEW_TEXT_BIT); |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2783 NEW_BIT (NEW_BR_BIT); |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2784 } |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2785 d++; |
1463
2f317467d2f9
[gaim-migrate @ 1473]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1462
diff
changeset
|
2786 } else { |
2f317467d2f9
[gaim-migrate @ 1473]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1462
diff
changeset
|
2787 ws [wpos++] = *d++; |
2f317467d2f9
[gaim-migrate @ 1473]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1462
diff
changeset
|
2788 } |
2f317467d2f9
[gaim-migrate @ 1473]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1462
diff
changeset
|
2789 } |
2f317467d2f9
[gaim-migrate @ 1473]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1462
diff
changeset
|
2790 tpos = 0; |
1428 | 2791 } else { |
2792 wpos = 0; | |
2793 } | |
2794 intag = FALSE; | |
2795 tpos = 0; | |
2796 } else if (*c == '&' && !intag) { | |
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2797 gchar replace; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2798 gint length; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2799 if (is_amp_escape (c, &replace, &length)) { |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2800 ws [wpos++] = replace; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2801 c += length; |
1428 | 2802 } else { |
2803 ws [wpos++] = *c++; | |
2804 } | |
2805 } else if (intag) { | |
2806 if (*c == '\"') | |
2807 tagquote = !tagquote; | |
2808 tag [tpos++] = *c++; | |
2809 } else if (incomment) { | |
2810 ws [wpos++] = *c++; | |
2811 } else if (((smilelen = gtk_imhtml_is_smiley (imhtml, c)) != 0)) { | |
2812 ws [wpos] = 0; | |
2813 wpos = 0; | |
2814 NEW_BIT (NEW_TEXT_BIT); | |
2815 g_snprintf (ws, smilelen + 1, "%s", c); | |
2816 NEW_BIT (NEW_SMILEY_BIT); | |
2817 c += smilelen; | |
2818 } else if (*c == '\n') { | |
2819 if (!(options & GTK_IMHTML_NO_NEWLINE)) { | |
2820 ws [wpos] = 0; | |
2821 wpos = 0; | |
2822 NEW_BIT (NEW_TEXT_BIT); | |
2823 NEW_BIT (NEW_BR_BIT); | |
2824 } | |
2825 c++; | |
2826 } else { | |
2827 ws [wpos++] = *c++; | |
2828 } | |
2829 } | |
2830 | |
2831 if (intag) { | |
2832 tag [tpos] = 0; | |
2833 c = tag; | |
2834 while (*c) { | |
2835 if ((smilelen = gtk_imhtml_is_smiley (imhtml, c)) != 0) { | |
2836 ws [wpos] = 0; | |
2837 wpos = 0; | |
2838 NEW_BIT (NEW_TEXT_BIT); | |
2839 g_snprintf (ws, smilelen + 1, "%s", c); | |
2840 NEW_BIT (NEW_SMILEY_BIT); | |
2841 c += smilelen; | |
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2842 } else if (*c == '&') { |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2843 gchar replace; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2844 gint length; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2845 if (is_amp_escape (c, &replace, &length)) { |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2846 ws [wpos++] = replace; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2847 c += length; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2848 } else { |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2849 ws [wpos++] = *c++; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2850 } |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2851 } else if (*c == '\n') { |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2852 if (!(options & GTK_IMHTML_NO_NEWLINE)) { |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2853 ws [wpos] = 0; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2854 wpos = 0; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2855 NEW_BIT (NEW_TEXT_BIT); |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2856 NEW_BIT (NEW_BR_BIT); |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2857 } |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2858 c++; |
1428 | 2859 } else { |
2860 ws [wpos++] = *c++; | |
2861 } | |
2862 } | |
2863 } else if (incomment) { | |
2864 ws [wpos] = 0; | |
2865 wpos = 0; | |
2866 strcat (tag, ws); | |
2867 ws [wpos] = 0; | |
2868 c = tag; | |
2869 while (*c) { | |
2870 if ((smilelen = gtk_imhtml_is_smiley (imhtml, c)) != 0) { | |
2871 ws [wpos] = 0; | |
2872 wpos = 0; | |
2873 NEW_BIT (NEW_TEXT_BIT); | |
2874 g_snprintf (ws, smilelen + 1, "%s", c); | |
2875 NEW_BIT (NEW_SMILEY_BIT); | |
2876 c += smilelen; | |
1472
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2877 } else if (*c == '&') { |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2878 gchar replace; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2879 gint length; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2880 if (is_amp_escape (c, &replace, &length)) { |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2881 ws [wpos++] = replace; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2882 c += length; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2883 } else { |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2884 ws [wpos++] = *c++; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2885 } |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2886 } else if (*c == '\n') { |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2887 if (!(options & GTK_IMHTML_NO_NEWLINE)) { |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2888 ws [wpos] = 0; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2889 wpos = 0; |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2890 NEW_BIT (NEW_TEXT_BIT); |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2891 NEW_BIT (NEW_BR_BIT); |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2892 } |
be620a051d6d
[gaim-migrate @ 1482]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1463
diff
changeset
|
2893 c++; |
1428 | 2894 } else { |
2895 ws [wpos++] = *c++; | |
2896 } | |
2897 } | |
2898 } | |
2899 | |
2900 ws [wpos] = 0; | |
2901 NEW_BIT (NEW_TEXT_BIT); | |
2902 | |
2903 while (newbits) { | |
2904 GtkIMHtmlBit *bit = newbits->data; | |
2905 imhtml->bits = g_list_append (imhtml->bits, bit); | |
2906 newbits = g_list_remove (newbits, bit); | |
2907 gtk_imhtml_draw_bit (imhtml, bit); | |
2908 } | |
2909 | |
2910 gtk_widget_set_usize (GTK_WIDGET (imhtml), -1, imhtml->y + 5); | |
2911 | |
2912 if (!(options & GTK_IMHTML_NO_SCROLL) && | |
2913 scrolldown && | |
2914 (imhtml->y + 5 >= GTK_WIDGET (imhtml)->allocation.height)) | |
2915 gtk_adjustment_set_value (vadj, imhtml->y + 5 - GTK_WIDGET (imhtml)->allocation.height); | |
2916 | |
2917 if (url) { | |
2918 g_free (url); | |
2919 if (retval) | |
2920 retval = g_string_append (retval, "</A>"); | |
2921 } | |
2922 if (bg) | |
2923 gdk_color_free (bg); | |
2924 while (fonts) { | |
2925 FontDetail *font = fonts->data; | |
2926 fonts = g_slist_remove (fonts, font); | |
2927 g_free (font->face); | |
2928 if (font->fore) | |
2929 gdk_color_free (font->fore); | |
2930 if (font->back) | |
2931 gdk_color_free (font->back); | |
2932 g_free (font); | |
2933 if (retval) | |
2934 retval = g_string_append (retval, "</FONT>"); | |
2935 } | |
2936 if (retval) { | |
2937 while (bold) { | |
2938 retval = g_string_append (retval, "</B>"); | |
2939 bold--; | |
2940 } | |
2941 while (italics) { | |
2942 retval = g_string_append (retval, "</I>"); | |
2943 italics--; | |
2944 } | |
2945 while (underline) { | |
2946 retval = g_string_append (retval, "</U>"); | |
2947 underline--; | |
2948 } | |
2949 while (strike) { | |
2950 retval = g_string_append (retval, "</S>"); | |
2951 strike--; | |
2952 } | |
2953 while (sub) { | |
2954 retval = g_string_append (retval, "</SUB>"); | |
2955 sub--; | |
2956 } | |
2957 while (sup) { | |
2958 retval = g_string_append (retval, "</SUP>"); | |
2959 sup--; | |
2960 } | |
2961 while (title) { | |
2962 retval = g_string_append (retval, "</TITLE>"); | |
2963 title--; | |
2964 } | |
2965 } | |
2966 g_free (ws); | |
2967 g_free (tag); | |
2968 | |
2969 return retval; | |
2970 } |