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