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