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