Mercurial > pidgin
annotate src/gtkimhtml.c @ 1453:ecf700f23852
[gaim-migrate @ 1463]
bugfixes
committer: Tailor Script <tailor@pidgin.im>
| author | Eric Warmenhoven <eric@warmenhoven.org> |
|---|---|
| date | Wed, 31 Jan 2001 11:25:18 +0000 |
| parents | 91d84e2073de |
| children | 637592eb8b24 |
| 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; |
|
1449
91d84e2073de
[gaim-migrate @ 1459]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1447
diff
changeset
|
532 chunk->sel_start = chunk->text; |
|
91d84e2073de
[gaim-migrate @ 1459]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1447
diff
changeset
|
533 chunk->sel_end = NULL; |
|
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
534 if (DRAW_IMG (bit)) |
|
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
535 draw_img (imhtml, chunk); |
|
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
536 else |
|
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
537 draw_text (imhtml, chunk); |
|
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
538 } |
| 1428 | 539 |
| 540 chunks = g_list_next (chunks); | |
| 541 } | |
| 542 | |
| 543 bits = g_list_next (bits); | |
| 544 } | |
| 545 } | |
| 546 | |
| 547 static gchar* | |
| 548 get_position (struct line_info *chunk, | |
| 549 gint x, | |
| 550 gboolean smileys) | |
| 551 { | |
| 552 gint width = x - chunk->x; | |
| 553 gchar *text; | |
| 554 gchar *pos; | |
| 555 guint total = 0; | |
| 556 | |
| 557 switch (chunk->bit->type) { | |
| 558 case TYPE_TEXT: | |
| 559 case TYPE_COMMENT: | |
| 560 text = chunk->text; | |
| 561 break; | |
| 562 case TYPE_SMILEY: | |
| 563 if (smileys) | |
| 564 return NULL; | |
| 565 else | |
| 566 text = chunk->text; | |
| 567 break; | |
| 568 default: | |
| 569 return NULL; | |
| 570 break; | |
| 571 } | |
| 572 | |
| 573 if (width <= 0) | |
| 574 return text; | |
| 575 | |
| 576 for (pos = text; *pos != '\0'; pos++) { | |
| 577 gint char_width = gdk_text_width (chunk->bit->font, pos, 1); | |
| 578 if ((width > total) && (width <= total + char_width)) { | |
| 579 if (width < total + (char_width >> 1)) | |
| 580 return pos; | |
| 581 else | |
| 582 return ++pos; | |
| 583 } | |
| 584 total += char_width; | |
| 585 } | |
| 586 | |
| 587 return pos; | |
| 588 } | |
| 589 | |
| 590 static GString* | |
| 591 append_to_sel (GString *string, | |
| 592 struct line_info *chunk, | |
| 593 gboolean smileys) | |
| 594 { | |
| 595 GString *new_string; | |
| 596 gchar *buf; | |
| 597 gchar *start; | |
| 598 gint length; | |
| 599 | |
| 600 switch (chunk->bit->type) { | |
| 601 case TYPE_TEXT: | |
| 602 case TYPE_COMMENT: | |
| 603 start = (chunk->sel_start == NULL) ? chunk->text : chunk->sel_start; | |
| 604 length = (chunk->sel_end == NULL) ? strlen (start) : chunk->sel_end - start; | |
| 605 if (length <= 0) | |
| 606 return string; | |
| 607 buf = g_strndup (start, length); | |
| 608 break; | |
| 609 case TYPE_SMILEY: | |
| 610 if (smileys) { | |
| 611 start = (chunk->sel_start == NULL) ? chunk->bit->text : chunk->sel_start; | |
| 612 length = (chunk->sel_end == NULL) ? strlen (start) : chunk->sel_end - start; | |
| 613 if (length <= 0) | |
| 614 return string; | |
| 615 buf = g_strndup (start, length); | |
| 616 } else { | |
| 617 start = (chunk->sel_start == NULL) ? chunk->text : chunk->sel_start; | |
| 618 length = (chunk->sel_end == NULL) ? strlen (start) : chunk->sel_end - start; | |
| 619 if (length <= 0) | |
| 620 return string; | |
| 621 buf = g_strndup (start, length); | |
| 622 } | |
| 623 break; | |
| 624 case TYPE_BR: | |
| 625 buf = g_strdup ("\n"); | |
| 626 break; | |
| 627 default: | |
| 628 return string; | |
| 629 break; | |
| 630 } | |
| 631 | |
| 632 new_string = g_string_append (string, buf); | |
| 633 g_free (buf); | |
| 634 | |
| 635 return new_string; | |
| 636 } | |
| 637 | |
| 638 #define COORDS_IN_CHUNK(xx, yy) (((xx) < chunk->x + chunk->width) && \ | |
| 639 ((yy) < chunk->y + chunk->height)) | |
| 640 | |
| 641 static void | |
| 642 gtk_imhtml_select_bits (GtkIMHtml *imhtml) | |
| 643 { | |
| 644 GList *bits; | |
| 645 GList *chunks; | |
| 646 GtkIMHtmlBit *bit; | |
| 647 struct line_info *chunk; | |
| 648 | |
| 649 guint startx = imhtml->sel_startx, | |
| 650 starty = imhtml->sel_starty, | |
| 651 endx = imhtml->sel_endx, | |
| 652 endy = imhtml->sel_endy; | |
| 653 gchar *new_pos; | |
| 654 gint selection = 0; | |
| 655 gboolean smileys = imhtml->smileys; | |
| 656 gboolean redraw = FALSE; | |
| 657 gboolean got_start = FALSE; | |
| 658 gboolean got_end = FALSE; | |
| 659 | |
| 660 g_return_if_fail (GTK_IS_IMHTML (imhtml)); | |
| 661 | |
| 662 if (!imhtml->selection) | |
| 663 return; | |
| 664 | |
| 665 if (imhtml->selected_text) { | |
| 666 g_string_free (imhtml->selected_text, TRUE); | |
| 667 imhtml->selected_text = g_string_new (""); | |
| 668 } | |
| 669 | |
| 670 bits = imhtml->bits; | |
| 671 while (bits) { | |
| 672 bit = bits->data; | |
| 673 chunks = bit->chunks; | |
| 674 | |
| 675 while (chunks) { | |
|
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
676 chunk = chunks->data; |
| 1428 | 677 |
| 678 switch (selection) { | |
| 679 case 0: | |
| 680 if (COORDS_IN_CHUNK (startx, starty)) { | |
| 681 new_pos = get_position (chunk, startx, smileys); | |
| 682 if ( !chunk->selected || | |
| 683 (chunk->sel_start != new_pos) || | |
| 684 (chunk->sel_end != NULL)) | |
| 685 redraw = TRUE; | |
| 686 chunk->selected = TRUE; | |
| 687 chunk->sel_start = new_pos; | |
| 688 chunk->sel_end = NULL; | |
| 689 selection++; | |
| 690 got_start = TRUE; | |
| 691 } | |
| 692 | |
| 693 if (COORDS_IN_CHUNK (endx, endy)) { | |
| 694 if (got_start) { | |
| 695 new_pos = get_position (chunk, endx, smileys); | |
| 696 if (chunk->sel_end != new_pos) | |
| 697 redraw = TRUE; | |
| 698 if (chunk->sel_start > new_pos) { | |
| 699 chunk->sel_end = chunk->sel_start; | |
| 700 chunk->sel_start = new_pos; | |
| 701 } else | |
| 702 chunk->sel_end = new_pos; | |
| 703 selection = 2; | |
| 704 got_end = TRUE; | |
| 705 } else { | |
| 706 new_pos = get_position (chunk, endx, smileys); | |
| 707 if ( !chunk->selected || | |
| 708 (chunk->sel_start != new_pos) || | |
| 709 (chunk->sel_end != NULL)) | |
| 710 redraw = TRUE; | |
| 711 chunk->selected = TRUE; | |
| 712 chunk->sel_start = new_pos; | |
| 713 chunk->sel_end = NULL; | |
| 714 selection++; | |
| 715 got_end = TRUE; | |
| 716 } | |
| 717 } else if (!COORDS_IN_CHUNK (startx, starty) && !got_start) { | |
| 718 if (chunk->selected) | |
| 719 redraw = TRUE; | |
| 720 chunk->selected = FALSE; | |
| 721 chunk->sel_start = chunk->text; | |
| 722 chunk->sel_end = NULL; | |
| 723 } | |
| 724 | |
| 725 break; | |
| 726 case 1: | |
| 727 if (!got_start && COORDS_IN_CHUNK (startx, starty)) { | |
| 728 new_pos = get_position (chunk, startx, smileys); | |
| 729 if ( !chunk->selected || | |
| 730 (chunk->sel_end != new_pos) || | |
| 731 (chunk->sel_start != chunk->text)) | |
| 732 redraw = TRUE; | |
| 733 chunk->selected = TRUE; | |
| 734 chunk->sel_start = chunk->text; | |
| 735 chunk->sel_end = new_pos; | |
| 736 selection++; | |
| 737 got_start = TRUE; | |
| 738 } else if (!got_end && COORDS_IN_CHUNK (endx, endy)) { | |
| 739 new_pos = get_position (chunk, endx, smileys); | |
| 740 if ( !chunk->selected || | |
| 741 (chunk->sel_end != new_pos) || | |
| 742 (chunk->sel_start != chunk->text)) | |
| 743 redraw = TRUE; | |
| 744 chunk->selected = TRUE; | |
| 745 chunk->sel_start = chunk->text; | |
| 746 chunk->sel_end = new_pos; | |
| 747 selection++; | |
| 748 got_end = TRUE; | |
| 749 } else { | |
| 750 if ( !chunk->selected || | |
|
1449
91d84e2073de
[gaim-migrate @ 1459]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1447
diff
changeset
|
751 (chunk->sel_end != NULL) || |
|
91d84e2073de
[gaim-migrate @ 1459]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1447
diff
changeset
|
752 (chunk->sel_start != chunk->text)) |
| 1428 | 753 redraw = TRUE; |
| 754 chunk->selected = TRUE; | |
| 755 chunk->sel_start = chunk->text; | |
| 756 chunk->sel_end = NULL; | |
| 757 } | |
| 758 | |
| 759 break; | |
| 760 case 2: | |
|
1449
91d84e2073de
[gaim-migrate @ 1459]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1447
diff
changeset
|
761 if (chunk->selected) |
| 1428 | 762 redraw = TRUE; |
| 763 chunk->selected = FALSE; | |
| 764 chunk->sel_start = chunk->text; | |
| 765 chunk->sel_end = NULL; | |
| 766 break; | |
| 767 } | |
| 768 | |
| 769 if (chunk->selected == TRUE) | |
| 770 imhtml->selected_text = append_to_sel (imhtml->selected_text, | |
| 771 chunk, smileys); | |
| 772 | |
| 773 if (redraw) { | |
|
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
774 if (DRAW_IMG (bit)) |
|
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
775 draw_img (imhtml, chunk); |
|
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
776 else |
|
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
777 draw_text (imhtml, chunk); |
| 1428 | 778 redraw = FALSE; |
| 779 } | |
| 780 | |
| 781 chunks = g_list_next (chunks); | |
| 782 } | |
| 783 | |
| 784 bits = g_list_next (bits); | |
| 785 } | |
| 786 } | |
| 787 | |
| 788 static gint | |
| 789 scroll_timeout (GtkIMHtml *imhtml) | |
| 790 { | |
| 791 GdkEventMotion event; | |
| 792 gint x, y; | |
| 793 GdkModifierType mask; | |
| 794 | |
| 795 imhtml->scroll_timer = 0; | |
| 796 | |
| 797 gdk_window_get_pointer (imhtml->layout.bin_window, &x, &y, &mask); | |
| 798 | |
| 799 if (mask & GDK_BUTTON1_MASK) { | |
| 800 event.is_hint = 0; | |
| 801 event.x = x; | |
| 802 event.y = y; | |
| 803 event.state = mask; | |
| 804 | |
| 805 gtk_imhtml_motion_notify_event (GTK_WIDGET (imhtml), &event); | |
| 806 } | |
| 807 | |
| 808 return FALSE; | |
| 809 } | |
| 810 | |
| 811 static gint | |
| 812 gtk_imhtml_motion_notify_event (GtkWidget *widget, | |
| 813 GdkEventMotion *event) | |
| 814 { | |
| 815 gint x, y; | |
| 816 GdkModifierType state; | |
| 817 GtkIMHtml *imhtml = GTK_IMHTML (widget); | |
| 818 GtkAdjustment *vadj = GTK_LAYOUT (widget)->vadjustment; | |
| 819 GtkAdjustment *hadj = GTK_LAYOUT (widget)->hadjustment; | |
| 820 | |
| 821 if (event->is_hint) | |
| 822 gdk_window_get_pointer (event->window, &x, &y, &state); | |
| 823 else { | |
| 824 x = event->x + hadj->value; | |
| 825 y = event->y + vadj->value; | |
| 826 state = event->state; | |
| 827 } | |
| 828 | |
| 829 if (state & GDK_BUTTON1_MASK) { | |
| 830 gint diff; | |
| 831 gint height = vadj->page_size; | |
| 832 gint yy = y - vadj->value; | |
| 833 | |
| 834 if (((yy < 0) || (yy > height)) && | |
| 835 (imhtml->scroll_timer == 0) && | |
| 836 (vadj->upper > vadj->page_size)) { | |
| 837 imhtml->scroll_timer = gtk_timeout_add (100, | |
| 838 (GtkFunction) scroll_timeout, | |
| 839 imhtml); | |
| 840 diff = (yy < 0) ? (yy >> 1) : ((yy - height) >> 1); | |
| 841 gtk_adjustment_set_value (vadj, | |
| 842 MIN (vadj->value + diff, vadj->upper - height + 20)); | |
| 843 } | |
| 844 | |
| 845 if (imhtml->selection) { | |
| 846 imhtml->sel_endx = MAX (x, 0); | |
| 847 imhtml->sel_endy = MAX (y, 0); | |
| 848 gtk_imhtml_select_bits (imhtml); | |
| 849 } | |
| 850 } else { | |
| 851 GList *urls = imhtml->urls; | |
| 852 struct url_widget *uw; | |
| 853 | |
| 854 while (urls) { | |
| 855 uw = (struct url_widget *) urls->data; | |
| 856 if ((x > uw->x) && (x < uw->x + uw->width) && | |
| 857 (y > uw->y) && (y < uw->y + uw->height)) { | |
| 858 gdk_window_set_cursor (imhtml->layout.bin_window, imhtml->hand_cursor); | |
| 859 return TRUE; | |
| 860 } | |
| 861 urls = g_list_next (urls); | |
| 862 } | |
| 863 } | |
| 864 | |
| 865 gdk_window_set_cursor (imhtml->layout.bin_window, imhtml->arrow_cursor); | |
| 866 | |
| 867 return TRUE; | |
| 868 } | |
| 869 | |
| 870 static gint | |
| 871 gtk_imhtml_button_press_event (GtkWidget *widget, | |
| 872 GdkEventButton *event) | |
| 873 { | |
| 874 GtkIMHtml *imhtml = GTK_IMHTML (widget); | |
| 875 GtkAdjustment *vadj = GTK_LAYOUT (widget)->vadjustment; | |
| 876 GtkAdjustment *hadj = GTK_LAYOUT (widget)->hadjustment; | |
| 877 gint x, y; | |
| 878 | |
| 879 if (event->button == 1) { | |
| 880 x = event->x + hadj->value; | |
| 881 y = event->y + vadj->value; | |
| 882 | |
| 883 imhtml->sel_startx = x; | |
| 884 imhtml->sel_starty = y; | |
| 885 imhtml->selection = TRUE; | |
| 886 gtk_imhtml_select_none (imhtml); | |
| 887 } | |
| 888 | |
| 889 return TRUE; | |
| 890 } | |
| 891 | |
| 892 static gint | |
| 893 gtk_imhtml_button_release_event (GtkWidget *widget, | |
| 894 GdkEventButton *event) | |
| 895 { | |
| 896 GtkIMHtml *imhtml = GTK_IMHTML (widget); | |
| 897 GtkAdjustment *vadj = GTK_LAYOUT (widget)->vadjustment; | |
| 898 GtkAdjustment *hadj = GTK_LAYOUT (widget)->hadjustment; | |
| 899 gint x, y; | |
| 900 | |
| 901 if ((event->button == 1) && imhtml->selection) { | |
| 902 x = event->x + hadj->value; | |
| 903 y = event->y + vadj->value; | |
| 904 | |
| 905 if ((x == imhtml->sel_startx) && (y == imhtml->sel_starty)) { | |
| 906 imhtml->sel_startx = imhtml->sel_starty = 0; | |
| 907 imhtml->selection = FALSE; | |
| 908 gtk_imhtml_select_none (imhtml); | |
| 909 } else { | |
| 910 imhtml->sel_endx = MAX (x, 0); | |
| 911 imhtml->sel_endy = MAX (y, 0); | |
| 912 gtk_imhtml_select_bits (imhtml); | |
| 913 } | |
| 914 | |
| 915 gtk_selection_owner_set (widget, GDK_SELECTION_PRIMARY, event->time); | |
| 916 } | |
| 917 | |
|
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
918 if ((event->button == 1) && (imhtml->selected_text->len == 0)) { |
|
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
919 GList *urls = imhtml->urls; |
|
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
920 struct url_widget *uw; |
|
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
921 |
|
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
922 while (urls) { |
|
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
923 uw = (struct url_widget *) urls->data; |
|
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
924 if ((x > uw->x) && (x < uw->x + uw->width) && |
|
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
925 (y > uw->y) && (y < uw->y + uw->height)) { |
|
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
926 gtk_signal_emit (GTK_OBJECT (imhtml), signals [URL_CLICKED], uw->url); |
|
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
927 return TRUE; |
|
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
928 } |
|
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
929 urls = g_list_next (urls); |
|
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
930 } |
|
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
931 } |
|
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
932 |
| 1428 | 933 return TRUE; |
| 934 } | |
| 935 | |
| 936 static void | |
| 937 gtk_imhtml_selection_get (GtkWidget *widget, | |
| 938 GtkSelectionData *sel_data, | |
| 939 guint sel_info, | |
| 940 guint32 time) | |
| 941 { | |
| 942 GtkIMHtml *imhtml; | |
| 943 gchar *string; | |
| 944 gint length; | |
| 945 | |
| 946 g_return_if_fail (widget != NULL); | |
| 947 g_return_if_fail (GTK_IS_IMHTML (widget)); | |
| 948 g_return_if_fail (sel_data->selection == GDK_SELECTION_PRIMARY); | |
| 949 | |
| 950 imhtml = GTK_IMHTML (widget); | |
| 951 | |
| 952 g_return_if_fail (imhtml->selected_text != NULL); | |
| 953 g_return_if_fail (imhtml->selected_text->str != NULL); | |
| 954 | |
| 955 if (imhtml->selected_text->len <= 0) { | |
| 956 string = NULL; | |
| 957 length = 0; | |
| 958 } else { | |
| 959 string = g_strdup (imhtml->selected_text->str); | |
| 960 length = strlen (string); | |
| 961 } | |
| 962 | |
| 963 if (sel_info == TARGET_STRING) { | |
| 964 gtk_selection_data_set (sel_data, | |
| 965 GDK_SELECTION_TYPE_STRING, | |
| 966 8 * sizeof (gchar), | |
| 967 (guchar *) string, | |
| 968 length); | |
| 969 } else if ((sel_info == TARGET_TEXT) || (sel_info == TARGET_COMPOUND_TEXT)) { | |
| 970 guchar *text; | |
| 971 GdkAtom encoding; | |
| 972 gint format; | |
| 973 gint new_length; | |
| 974 | |
| 975 gdk_string_to_compound_text (string, &encoding, &format, &text, &new_length); | |
| 976 gtk_selection_data_set (sel_data, encoding, format, text, new_length); | |
| 977 gdk_free_compound_text (text); | |
| 978 } | |
| 979 | |
| 980 if (string) | |
| 981 g_free (string); | |
| 982 } | |
| 983 | |
| 984 static gint | |
| 985 gtk_imhtml_selection_clear_event (GtkWidget *widget, | |
| 986 GdkEventSelection *event) | |
| 987 { | |
| 988 GtkIMHtml *imhtml; | |
| 989 | |
| 990 g_return_val_if_fail (widget != NULL, FALSE); | |
| 991 g_return_val_if_fail (GTK_IS_IMHTML (widget), FALSE); | |
| 992 g_return_val_if_fail (event != NULL, FALSE); | |
| 993 g_return_val_if_fail (event->selection == GDK_SELECTION_PRIMARY, TRUE); | |
| 994 | |
| 995 if (!gtk_selection_clear (widget, event)) | |
| 996 return FALSE; | |
| 997 | |
| 998 imhtml = GTK_IMHTML (widget); | |
| 999 | |
| 1000 gtk_imhtml_select_none (imhtml); | |
| 1001 | |
| 1002 return TRUE; | |
| 1003 } | |
| 1004 | |
| 1005 static void | |
| 1006 gtk_imhtml_set_scroll_adjustments (GtkLayout *layout, | |
| 1007 GtkAdjustment *hadj, | |
| 1008 GtkAdjustment *vadj) | |
| 1009 { | |
| 1010 if (parent_class->set_scroll_adjustments) | |
| 1011 (* parent_class->set_scroll_adjustments) (layout, hadj, vadj); | |
| 1012 } | |
| 1013 | |
| 1014 static void | |
| 1015 gtk_imhtml_class_init (GtkIMHtmlClass *class) | |
| 1016 { | |
| 1017 GtkObjectClass *object_class; | |
| 1018 GtkWidgetClass *widget_class; | |
| 1019 GtkLayoutClass *layout_class; | |
| 1020 | |
| 1021 object_class = (GtkObjectClass*) class; | |
| 1022 widget_class = (GtkWidgetClass*) class; | |
| 1023 layout_class = (GtkLayoutClass*) class; | |
| 1024 | |
| 1025 parent_class = gtk_type_class (GTK_TYPE_LAYOUT); | |
| 1026 | |
| 1027 signals [URL_CLICKED] = | |
| 1028 gtk_signal_new ("url_clicked", | |
| 1029 GTK_RUN_FIRST, | |
| 1030 object_class->type, | |
| 1031 GTK_SIGNAL_OFFSET (GtkIMHtmlClass, url_clicked), | |
| 1032 gtk_marshal_NONE__POINTER, | |
| 1033 GTK_TYPE_NONE, 1, | |
| 1034 GTK_TYPE_POINTER); | |
| 1035 | |
| 1036 gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL); | |
| 1037 | |
| 1038 object_class->destroy = gtk_imhtml_destroy; | |
| 1039 | |
| 1040 widget_class->realize = gtk_imhtml_realize; | |
| 1041 widget_class->draw = gtk_imhtml_draw; | |
| 1042 widget_class->style_set = gtk_imhtml_style_set; | |
|
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
1043 widget_class->expose_event = gtk_imhtml_expose_event; |
| 1428 | 1044 widget_class->size_allocate = gtk_imhtml_size_allocate; |
| 1045 widget_class->motion_notify_event = gtk_imhtml_motion_notify_event; | |
| 1046 widget_class->button_press_event = gtk_imhtml_button_press_event; | |
| 1047 widget_class->button_release_event = gtk_imhtml_button_release_event; | |
| 1048 widget_class->selection_get = gtk_imhtml_selection_get; | |
| 1049 widget_class->selection_clear_event = gtk_imhtml_selection_clear_event; | |
| 1050 | |
| 1051 layout_class->set_scroll_adjustments = gtk_imhtml_set_scroll_adjustments; | |
| 1052 } | |
| 1053 | |
| 1054 static GdkFont* | |
| 1055 gtk_imhtml_font_load (GtkIMHtml *imhtml, | |
| 1056 gchar *name, | |
| 1057 gboolean bold, | |
| 1058 gboolean italics, | |
| 1059 gint fontsize) | |
| 1060 { | |
| 1061 gchar buf [16 * 1024]; | |
| 1062 GdkFont *font; | |
| 1063 gint size = fontsize ? font_sizes [MIN (fontsize, MAX_SIZE) - 1] : 120; | |
| 1064 | |
| 1065 g_snprintf (buf, sizeof (buf), "-*-%s-%s-%c-*-*-*-%d-*-*-*-*-*-*", | |
| 1066 name ? name : DEFAULT_FONT_NAME, | |
| 1067 bold ? "bold" : "medium", | |
| 1068 italics ? 'i' : 'r', | |
| 1069 size); | |
| 1070 font = gdk_font_load (buf); | |
| 1071 if (font) | |
| 1072 return font; | |
| 1073 | |
| 1074 if (italics) { | |
| 1075 g_snprintf (buf, sizeof (buf), "-*-%s-%s-%c-*-*-*-%d-*-*-*-*-*-*", | |
| 1076 name ? name : DEFAULT_FONT_NAME, | |
| 1077 bold ? "bold" : "medium", | |
| 1078 'o', | |
| 1079 size); | |
| 1080 font = gdk_font_load (buf); | |
| 1081 if (font) | |
| 1082 return font; | |
| 1083 | |
| 1084 if (bold) { | |
| 1085 g_snprintf (buf, sizeof (buf), "-*-%s-%s-%c-*-*-*-%d-*-*-*-*-*-*", | |
| 1086 name ? name : DEFAULT_FONT_NAME, | |
| 1087 "bold", | |
| 1088 'r', | |
| 1089 size); | |
| 1090 font = gdk_font_load (buf); | |
| 1091 if (font) | |
| 1092 return font; | |
| 1093 } | |
| 1094 } | |
| 1095 | |
| 1096 if (bold) { | |
| 1097 g_snprintf (buf, sizeof (buf), "-*-%s-%s-%c-*-*-*-%d-*-*-*-*-*-*", | |
| 1098 name ? name : DEFAULT_FONT_NAME, | |
| 1099 "medium", | |
| 1100 italics ? 'i' : 'r', | |
| 1101 size); | |
| 1102 font = gdk_font_load (buf); | |
| 1103 if (font) | |
| 1104 return font; | |
| 1105 | |
| 1106 if (italics) { | |
| 1107 g_snprintf (buf, sizeof (buf), "-*-%s-%s-%c-*-*-*-%d-*-*-*-*-*-*", | |
| 1108 name ? name : DEFAULT_FONT_NAME, | |
| 1109 "medium", | |
| 1110 'o', | |
| 1111 size); | |
| 1112 font = gdk_font_load (buf); | |
| 1113 if (font) | |
| 1114 return font; | |
| 1115 } | |
| 1116 } | |
| 1117 | |
| 1118 if (!bold && !italics) { | |
| 1119 g_snprintf (buf, sizeof (buf), "-*-%s-medium-r-*-*-*-%d-*-*-*-*-*-*", | |
| 1120 name ? name : DEFAULT_FONT_NAME, | |
| 1121 size); | |
| 1122 font = gdk_font_load (buf); | |
| 1123 if (font) | |
| 1124 return font; | |
| 1125 } | |
| 1126 | |
| 1127 g_snprintf (buf, sizeof (buf), "-*-%s-medium-r-*-*-*-%d-*-*-*-*-*-*", | |
| 1128 DEFAULT_FONT_NAME, | |
| 1129 size); | |
| 1130 font = gdk_font_load (buf); | |
| 1131 if (font) | |
| 1132 return font; | |
| 1133 | |
| 1134 if (imhtml->default_font) | |
| 1135 return gdk_font_ref (imhtml->default_font); | |
| 1136 | |
| 1137 return NULL; | |
| 1138 } | |
| 1139 | |
| 1140 static void | |
| 1141 gtk_imhtml_init (GtkIMHtml *imhtml) | |
| 1142 { | |
| 1143 static const GtkTargetEntry targets [] = { | |
| 1144 { "STRING", 0, TARGET_STRING }, | |
| 1145 { "TEXT", 0, TARGET_TEXT }, | |
| 1146 { "COMPOUND_TEXT", 0, TARGET_COMPOUND_TEXT } | |
| 1147 }; | |
| 1148 | |
| 1149 imhtml->default_font = gtk_imhtml_font_load (imhtml, NULL, FALSE, FALSE, 0); | |
| 1150 if (imhtml->default_font == NULL) | |
| 1151 g_warning ("GtkIMHtml: Could not load default font!"); | |
| 1152 imhtml->default_fg_color = gdk_color_copy (>K_WIDGET (imhtml)->style->black); | |
| 1153 imhtml->hand_cursor = gdk_cursor_new (GDK_HAND2); | |
| 1154 imhtml->arrow_cursor = gdk_cursor_new (GDK_LEFT_PTR); | |
| 1155 | |
| 1156 GTK_WIDGET_SET_FLAGS (GTK_WIDGET (imhtml), GTK_CAN_FOCUS); | |
| 1157 gtk_selection_add_targets (GTK_WIDGET (imhtml), GDK_SELECTION_PRIMARY, targets, 3); | |
| 1158 } | |
| 1159 | |
| 1160 GtkType | |
| 1161 gtk_imhtml_get_type (void) | |
| 1162 { | |
| 1163 static GtkType imhtml_type = 0; | |
| 1164 | |
| 1165 if (!imhtml_type) { | |
| 1166 static const GtkTypeInfo imhtml_info = { | |
| 1167 "GtkIMHtml", | |
| 1168 sizeof (GtkIMHtml), | |
| 1169 sizeof (GtkIMHtmlClass), | |
| 1170 (GtkClassInitFunc) gtk_imhtml_class_init, | |
| 1171 (GtkObjectInitFunc) gtk_imhtml_init, | |
| 1172 NULL, | |
| 1173 NULL, | |
| 1174 NULL | |
| 1175 }; | |
| 1176 | |
| 1177 imhtml_type = gtk_type_unique (GTK_TYPE_LAYOUT, &imhtml_info); | |
| 1178 } | |
| 1179 | |
| 1180 return imhtml_type; | |
| 1181 } | |
| 1182 | |
| 1183 static void | |
| 1184 gtk_imhtml_init_smiley_hash (GtkIMHtml *imhtml) | |
| 1185 { | |
| 1186 g_return_if_fail (imhtml != NULL); | |
| 1187 g_return_if_fail (GTK_IS_IMHTML (imhtml)); | |
| 1188 | |
| 1189 imhtml->smiley_hash = g_hash_table_new (g_str_hash, g_str_equal); | |
| 1190 | |
| 1191 gtk_imhtml_associate_smiley (imhtml, ":)", smile_xpm); | |
| 1192 gtk_imhtml_associate_smiley (imhtml, ":-)", smile_xpm); | |
| 1193 | |
| 1194 gtk_imhtml_associate_smiley (imhtml, ":(", sad_xpm); | |
| 1195 gtk_imhtml_associate_smiley (imhtml, ":-(", sad_xpm); | |
| 1196 | |
| 1197 gtk_imhtml_associate_smiley (imhtml, ";)", wink_xpm); | |
| 1198 gtk_imhtml_associate_smiley (imhtml, ";-)", wink_xpm); | |
| 1199 | |
| 1200 gtk_imhtml_associate_smiley (imhtml, ":-p", tongue_xpm); | |
| 1201 gtk_imhtml_associate_smiley (imhtml, ":-P", tongue_xpm); | |
| 1202 | |
| 1203 gtk_imhtml_associate_smiley (imhtml, "=-O", scream_xpm); | |
| 1204 gtk_imhtml_associate_smiley (imhtml, ":-*", kiss_xpm); | |
| 1205 gtk_imhtml_associate_smiley (imhtml, ">:o", yell_xpm); | |
| 1206 gtk_imhtml_associate_smiley (imhtml, "8-)", smile8_xpm); | |
| 1207 gtk_imhtml_associate_smiley (imhtml, ":-$", moneymouth_xpm); | |
| 1208 gtk_imhtml_associate_smiley (imhtml, ":-!", burp_xpm); | |
| 1209 gtk_imhtml_associate_smiley (imhtml, ":-[", embarrassed_xpm); | |
| 1210 gtk_imhtml_associate_smiley (imhtml, ":'(", cry_xpm); | |
| 1211 | |
| 1212 gtk_imhtml_associate_smiley (imhtml, ":-/", think_xpm); | |
| 1213 gtk_imhtml_associate_smiley (imhtml, ":-\\", think_xpm); | |
| 1214 | |
| 1215 gtk_imhtml_associate_smiley (imhtml, ":-X", crossedlips_xpm); | |
| 1216 gtk_imhtml_associate_smiley (imhtml, ":-D", bigsmile_xpm); | |
| 1217 gtk_imhtml_associate_smiley (imhtml, "O:-)", angel_xpm); | |
| 1218 } | |
| 1219 | |
| 1220 GtkWidget* | |
| 1221 gtk_imhtml_new (GtkAdjustment *hadj, | |
| 1222 GtkAdjustment *vadj) | |
| 1223 { | |
| 1224 GtkIMHtml *imhtml = gtk_type_new (GTK_TYPE_IMHTML); | |
| 1225 | |
| 1226 gtk_imhtml_set_adjustments (imhtml, hadj, vadj); | |
| 1227 | |
| 1228 imhtml->bits = NULL; | |
| 1229 imhtml->urls = NULL; | |
| 1230 | |
| 1231 imhtml->x = BORDER_SIZE; | |
| 1232 imhtml->y = BORDER_SIZE + 10; | |
| 1233 imhtml->llheight = 0; | |
| 1234 imhtml->llascent = 0; | |
| 1235 imhtml->line = NULL; | |
| 1236 | |
| 1237 imhtml->selected_text = g_string_new (""); | |
| 1238 imhtml->scroll_timer = 0; | |
| 1239 | |
| 1240 imhtml->img = NULL; | |
| 1241 | |
| 1242 imhtml->smileys = TRUE; | |
| 1243 imhtml->comments = FALSE; | |
| 1244 | |
| 1245 imhtml->smin = G_MAXINT; | |
| 1246 imhtml->smax = 0; | |
| 1247 gtk_imhtml_init_smiley_hash (imhtml); | |
| 1248 | |
| 1249 return GTK_WIDGET (imhtml); | |
| 1250 } | |
| 1251 | |
| 1252 void | |
| 1253 gtk_imhtml_set_adjustments (GtkIMHtml *imhtml, | |
| 1254 GtkAdjustment *hadj, | |
| 1255 GtkAdjustment *vadj) | |
| 1256 { | |
| 1257 gtk_layout_set_hadjustment (GTK_LAYOUT (imhtml), hadj); | |
| 1258 gtk_layout_set_vadjustment (GTK_LAYOUT (imhtml), vadj); | |
| 1259 } | |
| 1260 | |
| 1261 void | |
| 1262 gtk_imhtml_set_defaults (GtkIMHtml *imhtml, | |
| 1263 GdkFont *font, | |
| 1264 GdkColor *fg_color) | |
| 1265 { | |
| 1266 g_return_if_fail (imhtml != NULL); | |
| 1267 g_return_if_fail (GTK_IS_IMHTML (imhtml)); | |
| 1268 | |
| 1269 if (font) { | |
| 1270 if (imhtml->default_font) | |
| 1271 gdk_font_unref (imhtml->default_font); | |
| 1272 imhtml->default_font = gdk_font_ref (font); | |
| 1273 } | |
| 1274 | |
| 1275 if (fg_color) { | |
| 1276 if (imhtml->default_fg_color) | |
| 1277 gdk_color_free (imhtml->default_fg_color); | |
| 1278 imhtml->default_fg_color = gdk_color_copy (fg_color); | |
| 1279 } | |
| 1280 } | |
| 1281 | |
| 1282 void | |
| 1283 gtk_imhtml_set_img_handler (GtkIMHtml *imhtml, | |
| 1284 GtkIMHtmlImage handler) | |
| 1285 { | |
| 1286 g_return_if_fail (imhtml != NULL); | |
| 1287 g_return_if_fail (GTK_IS_IMHTML (imhtml)); | |
| 1288 | |
| 1289 imhtml->img = handler; | |
| 1290 } | |
| 1291 | |
| 1292 void | |
| 1293 gtk_imhtml_associate_smiley (GtkIMHtml *imhtml, | |
| 1294 gchar *text, | |
| 1295 gchar **xpm) | |
| 1296 { | |
| 1297 g_return_if_fail (imhtml != NULL); | |
| 1298 g_return_if_fail (GTK_IS_IMHTML (imhtml)); | |
| 1299 g_return_if_fail (text != NULL); | |
| 1300 | |
| 1301 if (strlen (text) < imhtml->smin) | |
| 1302 imhtml->smin = strlen (text); | |
| 1303 | |
| 1304 if (strlen (text) > imhtml->smax) | |
| 1305 imhtml->smax = strlen (text); | |
| 1306 | |
| 1307 if (xpm == NULL) | |
| 1308 g_hash_table_remove (imhtml->smiley_hash, text); | |
| 1309 else | |
| 1310 g_hash_table_insert (imhtml->smiley_hash, text, xpm); | |
| 1311 } | |
| 1312 | |
|
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
1313 /* |
| 1428 | 1314 static gint |
| 1315 draw_line (GtkWidget *widget, | |
| 1316 GdkEvent *event, | |
| 1317 gpointer data) | |
| 1318 { | |
| 1319 GtkIMHtmlBit *bit; | |
| 1320 GdkDrawable *drawable; | |
| 1321 GdkColormap *cmap; | |
| 1322 GdkGC *gc; | |
| 1323 guint max_width; | |
| 1324 guint max_height; | |
| 1325 | |
| 1326 bit = data; | |
| 1327 drawable = widget->window; | |
| 1328 cmap = gdk_colormap_new (gdk_visual_get_best (), FALSE); | |
| 1329 gc = gdk_gc_new (drawable); | |
| 1330 | |
| 1331 if (bit->bg != NULL) { | |
| 1332 gdk_color_alloc (cmap, bit->bg); | |
| 1333 gdk_gc_set_foreground (gc, bit->bg); | |
| 1334 | |
| 1335 gdk_draw_rectangle (widget->window, gc, TRUE, 0, 0, | |
| 1336 widget->allocation.width, | |
| 1337 widget->allocation.height); | |
| 1338 } | |
| 1339 | |
| 1340 gdk_gc_copy (gc, widget->style->black_gc); | |
| 1341 | |
| 1342 max_width = widget->allocation.width; | |
| 1343 max_height = widget->allocation.height / 2; | |
| 1344 | |
| 1345 gdk_draw_rectangle (drawable, gc, | |
| 1346 TRUE, | |
| 1347 0, max_height / 2, | |
| 1348 max_width, max_height); | |
| 1349 | |
| 1350 gdk_colormap_unref (cmap); | |
| 1351 gdk_gc_unref (gc); | |
| 1352 | |
| 1353 return TRUE; | |
| 1354 } | |
|
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
1355 */ |
| 1428 | 1356 |
| 1357 static void | |
| 1358 new_line (GtkIMHtml *imhtml) | |
| 1359 { | |
| 1360 GList *last = g_list_last (imhtml->line); | |
| 1361 struct line_info *li; | |
| 1362 | |
| 1363 if (last) { | |
|
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
1364 li = last->data; |
|
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
1365 if (li->x + li->width != imhtml->xsize - BORDER_SIZE) |
| 1428 | 1366 li->width = imhtml->xsize - BORDER_SIZE - li->x; |
| 1367 } | |
| 1368 | |
| 1369 last = imhtml->line; | |
| 1370 if (last) { | |
|
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
1371 li = last->data; |
| 1428 | 1372 if (li->height < MIN_HEIGHT) { |
| 1373 while (last) { | |
| 1374 gint diff; | |
|
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
1375 li = last->data; |
| 1428 | 1376 diff = MIN_HEIGHT - li->height; |
| 1377 li->height = MIN_HEIGHT; | |
| 1378 li->ascent += diff >> 1; | |
| 1379 last = g_list_next (last); | |
| 1380 } | |
| 1381 imhtml->llheight = MIN_HEIGHT; | |
| 1382 } | |
| 1383 } | |
| 1384 | |
| 1385 g_list_free (imhtml->line); | |
| 1386 imhtml->line = NULL; | |
| 1387 | |
| 1388 imhtml->x = BORDER_SIZE; | |
| 1389 imhtml->y += imhtml->llheight; | |
| 1390 } | |
| 1391 | |
| 1392 static void | |
| 1393 backwards_update (GtkIMHtml *imhtml, | |
| 1394 GtkIMHtmlBit *bit, | |
| 1395 gint height, | |
| 1396 gint ascent) | |
| 1397 { | |
| 1398 gint diff; | |
| 1399 GList *ls = NULL; | |
| 1400 struct line_info *li; | |
| 1401 struct url_widget *uw; | |
| 1402 | |
| 1403 if (height > imhtml->llheight) { | |
| 1404 diff = height - imhtml->llheight; | |
| 1405 | |
| 1406 ls = imhtml->line; | |
| 1407 while (ls) { | |
|
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
1408 li = ls->data; |
| 1428 | 1409 li->height += diff; |
| 1410 if (ascent) | |
| 1411 li->ascent = ascent; | |
| 1412 else | |
| 1413 li->ascent += diff >> 1; | |
| 1414 ls = g_list_next (ls); | |
| 1415 } | |
| 1416 | |
| 1417 ls = imhtml->urls; | |
| 1418 while (ls) { | |
| 1419 uw = ls->data; | |
| 1420 if (uw->y + diff > imhtml->y) | |
| 1421 uw->y += diff; | |
| 1422 ls = g_list_next (ls); | |
| 1423 } | |
| 1424 | |
| 1425 imhtml->llheight = height; | |
| 1426 if (ascent) | |
| 1427 imhtml->llascent = ascent; | |
| 1428 else | |
| 1429 imhtml->llascent += diff >> 1; | |
| 1430 } | |
| 1431 } | |
| 1432 | |
|
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
1433 /* |
| 1428 | 1434 static GtkTooltips *tips = NULL; |
|
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
1435 */ |
| 1428 | 1436 |
| 1437 static void | |
| 1438 add_text_renderer (GtkIMHtml *imhtml, | |
| 1439 GtkIMHtmlBit *bit, | |
| 1440 gchar *text) | |
| 1441 { | |
| 1442 struct line_info *li; | |
| 1443 struct url_widget *uw; | |
| 1444 gint width; | |
| 1445 | |
| 1446 if (text) | |
| 1447 width = gdk_string_width (bit->font, text); | |
| 1448 else | |
| 1449 width = 0; | |
| 1450 | |
| 1451 li = g_new0 (struct line_info, 1); | |
| 1452 li->x = imhtml->x; | |
| 1453 li->y = imhtml->y; | |
| 1454 li->width = width; | |
| 1455 li->height = imhtml->llheight; | |
| 1456 if (text) | |
| 1457 li->ascent = MAX (imhtml->llascent, bit->font->ascent); | |
| 1458 else | |
| 1459 li->ascent = 0; | |
| 1460 li->text = text; | |
| 1461 li->bit = bit; | |
| 1462 | |
| 1463 if (bit->url) { | |
|
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
1464 /* FIXME |
| 1428 | 1465 eventbox = gtk_event_box_new (); |
| 1466 gtk_layout_put (GTK_LAYOUT (imhtml), eventbox, imhtml->x, imhtml->y); | |
| 1467 gtk_signal_connect (GTK_OBJECT (eventbox), "button_press_event", | |
| 1468 GTK_SIGNAL_FUNC (click_event_box), imhtml); | |
| 1469 gtk_widget_show (eventbox); | |
| 1470 | |
| 1471 gtk_container_add (GTK_CONTAINER (eventbox), darea); | |
|
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
1472 */ |
| 1428 | 1473 |
| 1474 uw = g_new0 (struct url_widget, 1); | |
| 1475 uw->x = imhtml->x; | |
| 1476 uw->y = imhtml->y; | |
| 1477 uw->width = width; | |
| 1478 uw->height = imhtml->llheight; | |
| 1479 uw->url = bit->url; | |
| 1480 imhtml->urls = g_list_append (imhtml->urls, uw); | |
| 1481 | |
|
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
1482 /* |
| 1428 | 1483 if (!tips) |
| 1484 tips = gtk_tooltips_new (); | |
| 1485 gtk_tooltips_set_tip (tips, eventbox, bit->url, ""); | |
|
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
1486 */ |
| 1428 | 1487 } |
| 1488 | |
|
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
1489 bit->chunks = g_list_append (bit->chunks, li); |
|
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
1490 imhtml->line = g_list_append (imhtml->line, li); |
| 1428 | 1491 } |
| 1492 | |
| 1493 static void | |
| 1494 add_img_renderer (GtkIMHtml *imhtml, | |
| 1495 GtkIMHtmlBit *bit) | |
| 1496 { | |
| 1497 struct line_info *li; | |
| 1498 struct url_widget *uw; | |
| 1499 gint width; | |
| 1500 | |
| 1501 gdk_window_get_size (bit->pm, &width, NULL); | |
| 1502 | |
| 1503 li = g_new0 (struct line_info, 1); | |
| 1504 li->x = imhtml->x; | |
| 1505 li->y = imhtml->y; | |
| 1506 li->width = width; | |
| 1507 li->height = imhtml->llheight; | |
| 1508 li->ascent = 0; | |
| 1509 li->bit = bit; | |
| 1510 | |
| 1511 if (bit->url) { | |
|
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
1512 /* FIXME |
| 1428 | 1513 eventbox = gtk_event_box_new (); |
| 1514 gtk_layout_put (GTK_LAYOUT (imhtml), eventbox, imhtml->x, imhtml->y); | |
| 1515 gtk_signal_connect (GTK_OBJECT (eventbox), "button_press_event", | |
| 1516 GTK_SIGNAL_FUNC (click_event_box), imhtml); | |
| 1517 gtk_widget_show (eventbox); | |
| 1518 | |
| 1519 gtk_container_add (GTK_CONTAINER (eventbox), darea); | |
|
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
1520 */ |
| 1428 | 1521 |
| 1522 uw = g_new0 (struct url_widget, 1); | |
| 1523 uw->x = imhtml->x; | |
| 1524 uw->y = imhtml->y; | |
| 1525 uw->width = width; | |
| 1526 uw->height = imhtml->llheight; | |
| 1527 uw->url = bit->url; | |
| 1528 imhtml->urls = g_list_append (imhtml->urls, uw); | |
| 1529 | |
|
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
1530 /* |
| 1428 | 1531 if (!tips) |
| 1532 tips = gtk_tooltips_new (); | |
| 1533 gtk_tooltips_set_tip (tips, eventbox, bit->url, ""); | |
|
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
1534 */ |
| 1428 | 1535 } |
| 1536 | |
|
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
1537 bit->chunks = g_list_append (bit->chunks, li); |
|
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
1538 imhtml->line = g_list_append (imhtml->line, li); |
| 1428 | 1539 |
| 1540 imhtml->x += width; | |
| 1541 } | |
| 1542 | |
| 1543 static void | |
| 1544 gtk_imhtml_draw_bit (GtkIMHtml *imhtml, | |
| 1545 GtkIMHtmlBit *bit) | |
| 1546 { | |
| 1547 gint width, height; | |
| 1548 GdkWindow *window; | |
| 1549 GdkGC *gc; | |
| 1550 | |
| 1551 g_return_if_fail (imhtml != NULL); | |
| 1552 g_return_if_fail (GTK_IS_IMHTML (imhtml)); | |
| 1553 g_return_if_fail (bit != NULL); | |
| 1554 | |
| 1555 window = GTK_LAYOUT (imhtml)->bin_window; | |
| 1556 gc = gdk_gc_new (window); | |
| 1557 | |
| 1558 if ( (bit->type == TYPE_TEXT) || | |
| 1559 ((bit->type == TYPE_SMILEY) && !imhtml->smileys) || | |
| 1560 ((bit->type == TYPE_COMMENT) && imhtml->comments)) { | |
| 1561 gchar *copy = g_strdup (bit->text); | |
| 1562 gint pos = 0; | |
| 1563 gboolean seenspace = FALSE; | |
| 1564 gchar *tmp; | |
| 1565 | |
| 1566 height = bit->font->ascent + bit->font->descent; | |
| 1567 width = gdk_string_width (bit->font, bit->text); | |
| 1568 | |
| 1569 if ((imhtml->x != BORDER_SIZE) && | |
| 1570 ((imhtml->x + width + BORDER_SIZE + BORDER_SIZE + 5) > imhtml->xsize)) { | |
| 1571 gint remain = imhtml->xsize - imhtml->x - BORDER_SIZE - BORDER_SIZE - 5; | |
| 1572 while (gdk_text_width (bit->font, copy, pos) < remain) { | |
| 1573 if (copy [pos] == ' ') | |
| 1574 seenspace = TRUE; | |
| 1575 pos++; | |
| 1576 } | |
| 1577 if (seenspace) { | |
| 1578 while (copy [pos - 1] != ' ') pos--; | |
| 1579 | |
| 1580 tmp = g_strndup (copy, pos); | |
| 1581 | |
| 1582 backwards_update (imhtml, bit, height, bit->font->ascent); | |
| 1583 add_text_renderer (imhtml, bit, tmp); | |
| 1584 } else | |
| 1585 pos = 0; | |
| 1586 seenspace = FALSE; | |
| 1587 new_line (imhtml); | |
| 1588 imhtml->llheight = 0; | |
| 1589 imhtml->llascent = 0; | |
| 1590 } | |
| 1591 | |
| 1592 backwards_update (imhtml, bit, height, bit->font->ascent); | |
| 1593 | |
| 1594 while (pos < strlen (bit->text)) { | |
| 1595 width = gdk_string_width (bit->font, copy + pos); | |
| 1596 if (imhtml->x + width + BORDER_SIZE + BORDER_SIZE + 5 > imhtml->xsize) { | |
| 1597 gint newpos = 0; | |
| 1598 gint remain = imhtml->xsize - imhtml->x - BORDER_SIZE - BORDER_SIZE - 5; | |
| 1599 while (gdk_text_width (bit->font, copy + pos, newpos) < remain) { | |
| 1600 if (copy [pos + newpos] == ' ') | |
| 1601 seenspace = TRUE; | |
| 1602 newpos++; | |
| 1603 } | |
| 1604 | |
| 1605 if (seenspace) | |
| 1606 while (copy [pos + newpos - 1] != ' ') newpos--; | |
| 1607 | |
| 1608 if (newpos == 0) | |
| 1609 break; | |
| 1610 | |
| 1611 tmp = g_strndup (copy + pos, newpos); | |
| 1612 pos += newpos; | |
| 1613 | |
| 1614 add_text_renderer (imhtml, bit, tmp); | |
| 1615 | |
| 1616 seenspace = FALSE; | |
| 1617 new_line (imhtml); | |
| 1618 } else { | |
| 1619 tmp = g_strdup (copy + pos); | |
| 1620 | |
| 1621 add_text_renderer (imhtml, bit, tmp); | |
| 1622 | |
| 1623 pos = strlen (bit->text); | |
| 1624 | |
| 1625 imhtml->x += width; | |
| 1626 } | |
| 1627 } | |
| 1628 | |
| 1629 g_free (copy); | |
| 1630 } else if ((bit->type == TYPE_SMILEY) || (bit->type == TYPE_IMG)) { | |
| 1631 gdk_window_get_size (bit->pm, &width, &height); | |
| 1632 | |
| 1633 if ((imhtml->x != BORDER_SIZE) && | |
| 1634 ((imhtml->x + width + BORDER_SIZE + BORDER_SIZE + 5) > imhtml->xsize)) { | |
| 1635 new_line (imhtml); | |
| 1636 imhtml->llheight = 0; | |
| 1637 imhtml->llascent = 0; | |
| 1638 } else | |
| 1639 backwards_update (imhtml, bit, height, height * 3 / 4); | |
| 1640 | |
| 1641 add_img_renderer (imhtml, bit); | |
| 1642 } else if (bit->type == TYPE_BR) { | |
| 1643 new_line (imhtml); | |
| 1644 imhtml->llheight = 0; | |
| 1645 imhtml->llascent = 0; | |
| 1646 add_text_renderer (imhtml, bit, NULL); | |
| 1647 } else if (bit->type == TYPE_SEP) { | |
| 1648 if (imhtml->llheight) { | |
| 1649 new_line (imhtml); | |
| 1650 imhtml->llheight = 0; | |
| 1651 imhtml->llascent = 0; | |
| 1652 } | |
|
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
1653 /* FIXME |
| 1428 | 1654 darea = gtk_drawing_area_new (); |
| 1655 gtk_widget_set_usize (darea, imhtml->xsize - (BORDER_SIZE * 2), HR_HEIGHT * 2); | |
| 1656 gtk_layout_put (GTK_LAYOUT (imhtml), darea, imhtml->x, imhtml->y); | |
| 1657 gtk_signal_connect (GTK_OBJECT (darea), "expose_event", | |
| 1658 GTK_SIGNAL_FUNC (draw_line), bit); | |
| 1659 gtk_widget_show (darea); | |
|
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
1660 */ |
| 1428 | 1661 imhtml->llheight = HR_HEIGHT * 2; |
| 1662 new_line (imhtml); | |
| 1663 imhtml->llheight = 0; | |
| 1664 imhtml->llascent = 0; | |
| 1665 add_text_renderer (imhtml, bit, NULL); | |
| 1666 } | |
| 1667 | |
| 1668 gtk_layout_set_size (GTK_LAYOUT (imhtml), imhtml->xsize, imhtml->y + 5); | |
| 1669 | |
| 1670 gdk_gc_destroy (gc); | |
| 1671 } | |
| 1672 | |
| 1673 void | |
| 1674 gtk_imhtml_show_smileys (GtkIMHtml *imhtml, | |
| 1675 gboolean show) | |
| 1676 { | |
| 1677 g_return_if_fail (imhtml != NULL); | |
| 1678 g_return_if_fail (GTK_IS_IMHTML (imhtml)); | |
| 1679 | |
| 1680 imhtml->smileys = show; | |
| 1681 | |
| 1682 if (GTK_WIDGET_VISIBLE (GTK_WIDGET (imhtml))) | |
| 1683 gtk_imhtml_redraw_all (imhtml); | |
| 1684 } | |
| 1685 | |
| 1686 void | |
| 1687 gtk_imhtml_show_comments (GtkIMHtml *imhtml, | |
| 1688 gboolean show) | |
| 1689 { | |
| 1690 g_return_if_fail (imhtml != NULL); | |
| 1691 g_return_if_fail (GTK_IS_IMHTML (imhtml)); | |
| 1692 | |
| 1693 imhtml->comments = show; | |
| 1694 | |
| 1695 if (GTK_WIDGET_VISIBLE (GTK_WIDGET (imhtml))) | |
| 1696 gtk_imhtml_redraw_all (imhtml); | |
| 1697 } | |
| 1698 | |
| 1699 static GdkColor * | |
| 1700 gtk_imhtml_get_color (const gchar *color) | |
| 1701 { | |
| 1702 GdkColor c; | |
| 1703 | |
|
1453
ecf700f23852
[gaim-migrate @ 1463]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1449
diff
changeset
|
1704 if (!gdk_color_parse (color, &c)) |
|
ecf700f23852
[gaim-migrate @ 1463]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1449
diff
changeset
|
1705 return NULL; |
| 1428 | 1706 |
|
1449
91d84e2073de
[gaim-migrate @ 1459]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1447
diff
changeset
|
1707 return gdk_color_copy (&c); |
| 1428 | 1708 } |
| 1709 | |
| 1710 static gint | |
| 1711 gtk_imhtml_is_smiley (GtkIMHtml *imhtml, | |
| 1712 const gchar *text) | |
| 1713 { | |
| 1714 gchar *tmp; | |
| 1715 gint i; | |
| 1716 | |
| 1717 g_return_val_if_fail (imhtml != NULL, 0); | |
| 1718 g_return_val_if_fail (GTK_IS_IMHTML (imhtml), 0); | |
| 1719 g_return_val_if_fail (text != NULL, 0); | |
| 1720 | |
| 1721 tmp = g_malloc (imhtml->smax + 1); | |
| 1722 | |
| 1723 for (i = imhtml->smin; i <= imhtml->smax; i++) { | |
| 1724 if (strlen (text) < i) { | |
| 1725 g_free (tmp); | |
| 1726 return 0; | |
| 1727 } | |
| 1728 g_snprintf (tmp, i + 1, "%s", text); | |
| 1729 if (g_hash_table_lookup (imhtml->smiley_hash, tmp)) { | |
| 1730 g_free (tmp); | |
| 1731 return i; | |
| 1732 } | |
| 1733 } | |
| 1734 | |
| 1735 g_free (tmp); | |
| 1736 return 0; | |
| 1737 } | |
| 1738 | |
| 1739 static GtkIMHtmlBit * | |
| 1740 gtk_imhtml_new_bit (GtkIMHtml *imhtml, | |
| 1741 gint type, | |
| 1742 gchar *text, | |
| 1743 gint bold, | |
| 1744 gint italics, | |
| 1745 gint underline, | |
| 1746 gint strike, | |
| 1747 FontDetail *font, | |
| 1748 GdkColor *bg, | |
| 1749 gchar *url) | |
| 1750 { | |
| 1751 GtkIMHtmlBit *bit = NULL; | |
| 1752 | |
| 1753 g_return_val_if_fail (imhtml != NULL, NULL); | |
| 1754 g_return_val_if_fail (GTK_IS_IMHTML (imhtml), NULL); | |
| 1755 | |
| 1756 if ((type == TYPE_TEXT) && ((text == NULL) || (strlen (text) == 0))) | |
| 1757 return NULL; | |
| 1758 | |
| 1759 bit = g_new0 (GtkIMHtmlBit, 1); | |
| 1760 bit->type = type; | |
| 1761 | |
| 1762 if ((text != NULL) && (strlen (text) != 0)) | |
| 1763 bit->text = g_strdup (text); | |
| 1764 | |
| 1765 if ((font != NULL) || bold || italics) { | |
| 1766 if (font && (bold || italics || font->size || font->face)) { | |
| 1767 bit->font = gtk_imhtml_font_load (imhtml, font->face, bold, italics, font->size); | |
| 1768 } else if (bold || italics) { | |
| 1769 bit->font = gtk_imhtml_font_load (imhtml, NULL, bold, italics, 0); | |
| 1770 } | |
| 1771 | |
| 1772 if (font && (type != TYPE_BR)) { | |
| 1773 if (font->fore != NULL) | |
| 1774 bit->fore = gdk_color_copy (font->fore); | |
| 1775 | |
| 1776 if (font->back != NULL) | |
| 1777 bit->back = gdk_color_copy (font->back); | |
| 1778 } | |
| 1779 } | |
| 1780 | |
| 1781 if (((bit->type == TYPE_TEXT) || (bit->type == TYPE_SMILEY) || (bit->type == TYPE_COMMENT)) && | |
| 1782 (bit->font == NULL)) | |
| 1783 bit->font = gdk_font_ref (imhtml->default_font); | |
| 1784 | |
| 1785 if (bg != NULL) | |
| 1786 bit->bg = gdk_color_copy (bg); | |
| 1787 | |
| 1788 bit->underline = underline; | |
| 1789 bit->strike = strike; | |
| 1790 | |
| 1791 if (url != NULL) | |
| 1792 bit->url = g_strdup (url); | |
| 1793 | |
| 1794 if (type == TYPE_SMILEY) { | |
| 1795 GdkColor *clr; | |
| 1796 | |
| 1797 if ((font != NULL) && (font->back != NULL)) | |
| 1798 clr = font->back; | |
| 1799 else | |
| 1800 clr = (bg != NULL) ? bg : >K_WIDGET (imhtml)->style->white; | |
| 1801 | |
| 1802 bit->pm = gdk_pixmap_create_from_xpm_d (GTK_WIDGET (imhtml)->window, | |
| 1803 &bit->bm, | |
| 1804 clr, | |
| 1805 g_hash_table_lookup (imhtml->smiley_hash, text)); | |
| 1806 } | |
| 1807 | |
| 1808 return bit; | |
| 1809 } | |
| 1810 | |
| 1811 #define NEW_TEXT_BIT gtk_imhtml_new_bit (imhtml, TYPE_TEXT, ws, bold, italics, underline, strike, \ | |
| 1812 fonts ? fonts->data : NULL, bg, url) | |
| 1813 #define NEW_SMILEY_BIT gtk_imhtml_new_bit (imhtml, TYPE_SMILEY, ws, bold, italics, underline, strike, \ | |
| 1814 fonts ? fonts->data : NULL, bg, url) | |
| 1815 #define NEW_SEP_BIT gtk_imhtml_new_bit (imhtml, TYPE_SEP, NULL, 0, 0, 0, 0, NULL, bg, NULL) | |
| 1816 #define NEW_BR_BIT gtk_imhtml_new_bit (imhtml, TYPE_BR, NULL, 0, 0, 0, 0, \ | |
| 1817 fonts ? fonts->data : NULL, bg, NULL) | |
| 1818 #define NEW_COMMENT_BIT gtk_imhtml_new_bit (imhtml, TYPE_COMMENT, ws, bold, italics, underline, strike, \ | |
| 1819 fonts ? fonts->data : NULL, bg, url) | |
| 1820 | |
| 1821 #define NEW_BIT(bit) { GtkIMHtmlBit *tmp = bit; if (tmp != NULL) \ | |
| 1822 newbits = g_list_append (newbits, tmp); } | |
| 1823 | |
| 1824 #define UPDATE_BG_COLORS \ | |
| 1825 { \ | |
| 1826 GdkColormap *cmap; \ | |
| 1827 GList *rev; \ | |
| 1828 cmap = gdk_colormap_new (gdk_visual_get_best (), FALSE); \ | |
| 1829 rev = g_list_last (newbits); \ | |
| 1830 while (rev) { \ | |
| 1831 GtkIMHtmlBit *bit = rev->data; \ | |
| 1832 if (bit->type == TYPE_BR) \ | |
| 1833 break; \ | |
| 1834 if (bit->bg) \ | |
| 1835 gdk_color_free (bit->bg); \ | |
| 1836 bit->bg = gdk_color_copy (bg); \ | |
| 1837 rev = g_list_previous (rev); \ | |
| 1838 } \ | |
| 1839 if (!rev) { \ | |
| 1840 rev = g_list_last (imhtml->bits); \ | |
| 1841 while (rev) { \ | |
| 1842 GtkIMHtmlBit *bit = rev->data; \ | |
| 1843 if (bit->type == TYPE_BR) \ | |
| 1844 break; \ | |
| 1845 if (bit->bg) \ | |
| 1846 gdk_color_free (bit->bg); \ | |
| 1847 bit->bg = gdk_color_copy (bg); \ | |
| 1848 gdk_color_alloc (cmap, bit->bg); \ | |
| 1849 rev = g_list_previous (rev); \ | |
| 1850 } \ | |
| 1851 gdk_colormap_unref (cmap); \ | |
| 1852 } \ | |
| 1853 } | |
| 1854 | |
| 1855 GString* | |
| 1856 gtk_imhtml_append_text (GtkIMHtml *imhtml, | |
| 1857 const gchar *text, | |
| 1858 GtkIMHtmlOptions options) | |
| 1859 { | |
| 1860 const gchar *c; | |
| 1861 gboolean intag = FALSE; | |
| 1862 gboolean tagquote = FALSE; | |
| 1863 gboolean incomment = FALSE; | |
| 1864 gchar *ws; | |
| 1865 gchar *tag; | |
| 1866 gint wpos = 0; | |
| 1867 gint tpos = 0; | |
| 1868 int smilelen; | |
| 1869 GList *newbits = NULL; | |
| 1870 | |
| 1871 guint bold = 0, | |
| 1872 italics = 0, | |
| 1873 underline = 0, | |
| 1874 strike = 0, | |
| 1875 sub = 0, | |
| 1876 sup = 0, | |
| 1877 title = 0; | |
| 1878 GSList *fonts = NULL; | |
| 1879 GdkColor *bg = NULL; | |
| 1880 gchar *url = NULL; | |
| 1881 | |
| 1882 GtkAdjustment *vadj; | |
| 1883 gboolean scrolldown = TRUE; | |
| 1884 | |
| 1885 GString *retval = NULL; | |
| 1886 | |
| 1887 g_return_val_if_fail (imhtml != NULL, NULL); | |
| 1888 g_return_val_if_fail (GTK_IS_IMHTML (imhtml), NULL); | |
| 1889 g_return_val_if_fail (text != NULL, NULL); | |
| 1890 | |
| 1891 if (options & GTK_IMHTML_RETURN_LOG) | |
| 1892 retval = g_string_new (""); | |
| 1893 | |
| 1894 vadj = GTK_LAYOUT (imhtml)->vadjustment; | |
| 1895 if ((vadj->value < imhtml->y + 5 - GTK_WIDGET (imhtml)->allocation.height) && | |
| 1896 (vadj->upper >= GTK_WIDGET (imhtml)->allocation.height)) | |
| 1897 scrolldown = FALSE; | |
| 1898 | |
| 1899 c = text; | |
| 1900 ws = g_malloc (strlen (text) + 1); | |
| 1901 tag = g_malloc (strlen (text) + 1); | |
| 1902 | |
| 1903 ws [0] = '\0'; | |
| 1904 | |
| 1905 while (*c) { | |
| 1906 if (*c == '<') { | |
| 1907 if (intag) { | |
| 1908 ws [wpos] = 0; | |
| 1909 tag [tpos] = 0; | |
| 1910 tpos = 0; | |
| 1911 strcat (ws, tag); | |
| 1912 wpos = strlen (ws); | |
| 1913 } | |
| 1914 | |
| 1915 if (incomment) { | |
| 1916 ws [wpos++] = *c++; | |
| 1917 continue; | |
| 1918 } | |
| 1919 | |
| 1920 if (!g_strncasecmp (c, "<!--", strlen ("<!--"))) { | |
| 1921 if (!(options & GTK_IMHTML_NO_COMMENTS)) { | |
| 1922 ws [wpos] = 0; | |
| 1923 wpos = 0; | |
| 1924 tag [tpos] = 0; | |
| 1925 strcat (tag, ws); | |
| 1926 incomment = TRUE; | |
| 1927 intag = FALSE; | |
| 1928 } | |
| 1929 ws [wpos++] = *c++; | |
| 1930 ws [wpos++] = *c++; | |
| 1931 ws [wpos++] = *c++; | |
| 1932 ws [wpos++] = *c++; | |
| 1933 continue; | |
| 1934 } | |
| 1935 | |
| 1936 tag [tpos++] = *c++; | |
| 1937 intag = TRUE; | |
| 1938 } else if (incomment && (*c == '-') && !g_strncasecmp (c, "-->", strlen ("-->"))) { | |
| 1939 gchar *tmp; | |
| 1940 ws [wpos] = 0; | |
| 1941 wpos = 0; | |
| 1942 tmp = g_strdup (ws); | |
| 1943 ws [wpos] = 0; | |
| 1944 strcat (ws, tag); | |
| 1945 NEW_BIT (NEW_TEXT_BIT); | |
| 1946 ws [wpos] = 0; | |
| 1947 strcat (ws, tmp + strlen ("<!--")); | |
| 1948 g_free (tmp); | |
| 1949 NEW_BIT (NEW_COMMENT_BIT); | |
| 1950 incomment = FALSE; | |
| 1951 c += strlen ("-->"); | |
| 1952 } else if (*c == '>' && intag && !tagquote) { | |
| 1953 gboolean got_tag = FALSE; | |
| 1954 tag [tpos++] = *c++; | |
| 1955 tag [tpos] = 0; | |
| 1956 ws [wpos] = 0; | |
| 1957 | |
| 1958 if (!g_strcasecmp (tag, "<B>") || !g_strcasecmp (tag, "<BOLD>")) { | |
| 1959 got_tag = TRUE; | |
| 1960 NEW_BIT (NEW_TEXT_BIT); | |
| 1961 bold++; | |
| 1962 } else if (!g_strcasecmp (tag, "</B>") || !g_strcasecmp (tag, "</BOLD>")) { | |
| 1963 got_tag = TRUE; | |
| 1964 if (bold) { | |
| 1965 NEW_BIT (NEW_TEXT_BIT); | |
| 1966 bold--; | |
| 1967 } | |
| 1968 } else if (!g_strcasecmp (tag, "<I>") || !g_strcasecmp (tag, "<ITALIC>")) { | |
| 1969 got_tag = TRUE; | |
| 1970 NEW_BIT (NEW_TEXT_BIT); | |
| 1971 italics++; | |
| 1972 } else if (!g_strcasecmp (tag, "</I>") || !g_strcasecmp (tag, "</ITALIC>")) { | |
| 1973 got_tag = TRUE; | |
| 1974 if (italics) { | |
| 1975 NEW_BIT (NEW_TEXT_BIT); | |
| 1976 italics--; | |
| 1977 } | |
| 1978 } else if (!g_strcasecmp (tag, "<U>") || !g_strcasecmp (tag, "<UNDERLINE>")) { | |
| 1979 got_tag = TRUE; | |
| 1980 NEW_BIT (NEW_TEXT_BIT); | |
| 1981 underline++; | |
| 1982 } else if (!g_strcasecmp (tag, "</U>") || !g_strcasecmp (tag, "</UNDERLINE>")) { | |
| 1983 got_tag = TRUE; | |
| 1984 if (underline) { | |
| 1985 NEW_BIT (NEW_TEXT_BIT); | |
| 1986 underline--; | |
| 1987 } | |
| 1988 } else if (!g_strcasecmp (tag, "<S>") || !g_strcasecmp (tag, "<STRIKE>")) { | |
| 1989 got_tag = TRUE; | |
| 1990 NEW_BIT (NEW_TEXT_BIT); | |
| 1991 strike++; | |
| 1992 } else if (!g_strcasecmp (tag, "</S>") || !g_strcasecmp (tag, "</STRIKE>")) { | |
| 1993 got_tag = TRUE; | |
| 1994 if (strike) { | |
| 1995 NEW_BIT (NEW_TEXT_BIT); | |
| 1996 strike--; | |
| 1997 } | |
| 1998 } else if (!g_strcasecmp (tag, "<SUB>")) { | |
| 1999 got_tag = TRUE; | |
| 2000 sub++; | |
| 2001 } else if (!g_strcasecmp (tag, "</SUB>")) { | |
| 2002 got_tag = TRUE; | |
| 2003 if (sub) { | |
| 2004 sub--; | |
| 2005 } | |
| 2006 } else if (!g_strcasecmp (tag, "<SUP>")) { | |
| 2007 got_tag = TRUE; | |
| 2008 sup++; | |
| 2009 } else if (!g_strcasecmp (tag, "</SUP>")) { | |
| 2010 got_tag = TRUE; | |
| 2011 if (sup) { | |
| 2012 sup--; | |
| 2013 } | |
| 2014 } else if (!g_strcasecmp (tag, "<TITLE>")) { | |
| 2015 if (options & GTK_IMHTML_NO_TITLE) { | |
| 2016 got_tag = TRUE; | |
| 2017 title++; | |
| 2018 } else { | |
| 2019 intag = FALSE; | |
| 2020 tpos = 0; | |
| 2021 continue; | |
| 2022 } | |
| 2023 } else if (!g_strcasecmp (tag, "</TITLE>")) { | |
| 2024 if (title) { | |
| 2025 got_tag = TRUE; | |
| 2026 wpos = 0; | |
| 2027 ws [wpos] = '\0'; | |
| 2028 title--; | |
| 2029 } else { | |
| 2030 intag = FALSE; | |
| 2031 tpos = 0; | |
| 2032 continue; | |
| 2033 } | |
| 2034 } else if (!g_strcasecmp (tag, "<BR>")) { | |
| 2035 got_tag = TRUE; | |
| 2036 NEW_BIT (NEW_TEXT_BIT); | |
| 2037 NEW_BIT (NEW_BR_BIT); | |
| 2038 } else if (!g_strcasecmp (tag, "<HR>") || | |
| 2039 !g_strncasecmp (tag, "<HR ", strlen ("<HR "))) { | |
| 2040 got_tag = TRUE; | |
| 2041 NEW_BIT (NEW_TEXT_BIT); | |
| 2042 NEW_BIT (NEW_SEP_BIT); | |
| 2043 } else if (!g_strncasecmp (tag, "<FONT ", strlen ("<FONT "))) { | |
| 2044 gchar *t, *e, *a, *value; | |
| 2045 FontDetail *font = NULL; | |
| 2046 GdkColor *clr; | |
| 2047 gint saw; | |
| 2048 gint i; | |
| 2049 | |
| 2050 t = tag + strlen ("<FONT "); | |
| 2051 | |
| 2052 while (*t != '\0') { | |
| 2053 value = NULL; | |
| 2054 saw = 0; | |
| 2055 | |
| 2056 while (g_strncasecmp (t, "COLOR=", strlen ("COLOR=")) | |
| 2057 && g_strncasecmp (t, "BACK=", strlen ("BACK=")) | |
| 2058 && g_strncasecmp (t, "FACE=", strlen ("FACE=")) | |
| 2059 && g_strncasecmp (t, "SIZE=", strlen ("SIZE="))) { | |
| 2060 gboolean quote = FALSE; | |
| 2061 if (*t == '\0') break; | |
| 2062 while (*t && !((*t == ' ') && !quote)) { | |
| 2063 if (*t == '\"') | |
| 2064 quote = ! quote; | |
| 2065 t++; | |
| 2066 } | |
| 2067 while (*t && (*t == ' ')) t++; | |
| 2068 } | |
| 2069 | |
| 2070 if (!g_strncasecmp (t, "COLOR=", strlen ("COLOR="))) { | |
| 2071 t += strlen ("COLOR="); | |
| 2072 saw = 1; | |
| 2073 } else if (!g_strncasecmp (t, "BACK=", strlen ("BACK="))) { | |
| 2074 t += strlen ("BACK="); | |
| 2075 saw = 2; | |
| 2076 } else if (!g_strncasecmp (t, "FACE=", strlen ("FACE="))) { | |
| 2077 t += strlen ("FACE="); | |
| 2078 saw = 3; | |
| 2079 } else if (!g_strncasecmp (t, "SIZE=", strlen ("SIZE="))) { | |
| 2080 t += strlen ("SIZE="); | |
| 2081 saw = 4; | |
| 2082 } | |
| 2083 | |
| 2084 if (!saw) | |
| 2085 continue; | |
| 2086 | |
| 2087 if ((*t == '\"') || (*t == '\'')) { | |
| 2088 e = a = ++t; | |
| 2089 while (*e && (*e != *(t - 1))) e++; | |
| 2090 if (*e != '\0') { | |
| 2091 *e = '\0'; | |
| 2092 t = e + 1; | |
| 2093 value = g_strdup (a); | |
| 2094 } else { | |
| 2095 *t = '\0'; | |
| 2096 } | |
| 2097 } else { | |
| 2098 e = a = t; | |
| 2099 while (*e && !isspace ((gint) *e)) e++; | |
| 2100 if (*e == '\0') e--; | |
| 2101 *e = '\0'; | |
| 2102 t = e + 1; | |
| 2103 value = g_strdup (a); | |
| 2104 } | |
| 2105 | |
| 2106 if (value == NULL) | |
| 2107 continue; | |
| 2108 | |
| 2109 if (font == NULL) | |
| 2110 font = g_new0 (FontDetail, 1); | |
| 2111 | |
| 2112 switch (saw) { | |
| 2113 case 1: | |
| 2114 clr = gtk_imhtml_get_color (value); | |
| 2115 if (clr != NULL) { | |
| 2116 if ( (font->fore == NULL) && | |
| 2117 !(options & GTK_IMHTML_NO_COLOURS)) | |
| 2118 font->fore = clr; | |
| 2119 } | |
| 2120 break; | |
| 2121 case 2: | |
| 2122 clr = gtk_imhtml_get_color (value); | |
| 2123 if (clr != NULL) { | |
| 2124 if ( (font->back == NULL) && | |
| 2125 !(options & GTK_IMHTML_NO_COLOURS)) | |
| 2126 font->back = clr; | |
| 2127 } | |
| 2128 break; | |
| 2129 case 3: | |
| 2130 if ( (font->face == NULL) && | |
| 2131 !(options & GTK_IMHTML_NO_FONTS)) | |
| 2132 font->face = g_strdup (value); | |
| 2133 break; | |
| 2134 case 4: | |
| 2135 if ((font->size != 0) || | |
| 2136 (options & GTK_IMHTML_NO_SIZES)) | |
| 2137 break; | |
| 2138 | |
| 2139 if (isdigit ((gint) value [0])) { | |
| 2140 for (i = 0; i < strlen (value); i++) | |
| 2141 if (!isdigit ((gint) value [i])) | |
| 2142 break; | |
| 2143 if (i != strlen (value)) | |
| 2144 break; | |
| 2145 | |
| 2146 sscanf (value, "%hd", &font->size); | |
| 2147 break; | |
| 2148 } | |
| 2149 | |
| 2150 if ((value [0] == '+') && (value [1] != '\0')) { | |
| 2151 for (i = 1; i < strlen (value); i++) | |
| 2152 if (!isdigit ((gint) value [i])) | |
| 2153 break; | |
| 2154 if (i != strlen (value)) | |
| 2155 break; | |
| 2156 | |
| 2157 sscanf (value + 1, "%hd", &font->size); | |
| 2158 font->size += 3; | |
| 2159 break; | |
| 2160 } | |
| 2161 | |
| 2162 if ((value [0] == '-') && (value [1] != '\0')) { | |
| 2163 for (i = 1; i < strlen (value); i++) | |
| 2164 if (!isdigit ((gint) value [i])) | |
| 2165 break; | |
| 2166 if (i != strlen (value)) | |
| 2167 break; | |
| 2168 | |
| 2169 sscanf (value + 1, "%hd", &font->size); | |
| 2170 font->size = MIN (font->size, 2); | |
| 2171 font->size = 3 - font->size; | |
| 2172 break; | |
| 2173 } | |
| 2174 | |
| 2175 break; | |
| 2176 } | |
| 2177 | |
| 2178 g_free (value); | |
| 2179 } | |
| 2180 | |
| 2181 if (!font) { | |
| 2182 intag = FALSE; | |
| 2183 tpos = 0; | |
| 2184 continue; | |
| 2185 } | |
| 2186 | |
| 2187 if (!(font->size || font->face || font->fore || font->back)) { | |
| 2188 g_free (font); | |
| 2189 intag = FALSE; | |
| 2190 tpos = 0; | |
| 2191 continue; | |
| 2192 } | |
| 2193 | |
| 2194 NEW_BIT (NEW_TEXT_BIT); | |
| 2195 | |
| 2196 if (fonts) { | |
| 2197 FontDetail *oldfont = fonts->data; | |
| 2198 if (!font->size) | |
| 2199 font->size = oldfont->size; | |
| 2200 if (!font->face) | |
| 2201 font->face = g_strdup (oldfont->face); | |
| 2202 if (!font->fore && oldfont->fore) | |
| 2203 font->fore = gdk_color_copy (oldfont->fore); | |
| 2204 if (!font->back && oldfont->back) | |
| 2205 font->back = gdk_color_copy (oldfont->back); | |
| 2206 } else { | |
| 2207 if (!font->size) | |
| 2208 font->size = 3; | |
| 2209 if (!font->face) | |
| 2210 font->face = g_strdup ("helvetica"); | |
| 2211 } | |
| 2212 | |
| 2213 fonts = g_slist_prepend (fonts, font); | |
| 2214 got_tag = TRUE; | |
| 2215 } else if (!g_strcasecmp (tag, "</FONT>")) { | |
| 2216 FontDetail *font; | |
| 2217 | |
| 2218 if (fonts) { | |
| 2219 got_tag = TRUE; | |
| 2220 NEW_BIT (NEW_TEXT_BIT); | |
| 2221 font = fonts->data; | |
| 2222 fonts = g_slist_remove (fonts, font); | |
| 2223 g_free (font->face); | |
| 2224 if (font->fore) | |
| 2225 gdk_color_free (font->fore); | |
| 2226 if (font->back) | |
| 2227 gdk_color_free (font->back); | |
| 2228 g_free (font); | |
| 2229 } else { | |
| 2230 intag = FALSE; | |
| 2231 tpos = 0; | |
| 2232 continue; | |
| 2233 } | |
| 2234 } else if (!g_strncasecmp (tag, "<BODY ", strlen ("<BODY "))) { | |
| 2235 gchar *t, *e, *color = NULL; | |
| 2236 GdkColor *tmp; | |
| 2237 | |
| 2238 got_tag = TRUE; | |
| 2239 | |
| 2240 if (!(options & GTK_IMHTML_NO_COLOURS)) { | |
| 2241 t = tag + strlen ("<BODY"); | |
| 2242 do { | |
| 2243 gboolean quote = FALSE; | |
| 2244 if (*t == '\0') break; | |
| 2245 while (*t && !((*t == ' ') && !quote)) { | |
| 2246 if (*t == '\"') | |
| 2247 quote = ! quote; | |
| 2248 t++; | |
| 2249 } | |
| 2250 while (*t && (*t == ' ')) t++; | |
| 2251 } while (g_strncasecmp (t, "BGCOLOR=", strlen ("BGCOLOR="))); | |
| 2252 | |
| 2253 if (!g_strncasecmp (t, "BGCOLOR=", strlen ("BGCOLOR="))) { | |
| 2254 t += strlen ("BGCOLOR="); | |
| 2255 if ((*t == '\"') || (*t == '\'')) { | |
| 2256 e = ++t; | |
| 2257 while (*e && (*e != *(t - 1))) e++; | |
| 2258 if (*e != '\0') { | |
| 2259 *e = '\0'; | |
| 2260 color = g_strdup (t); | |
| 2261 } | |
| 2262 } else { | |
| 2263 e = t; | |
| 2264 while (*e && !isspace ((gint) *e)) e++; | |
| 2265 if (*e == '\0') e--; | |
| 2266 *e = '\0'; | |
| 2267 color = g_strdup (t); | |
| 2268 } | |
| 2269 | |
| 2270 if (color != NULL) { | |
| 2271 tmp = gtk_imhtml_get_color (color); | |
| 2272 g_free (color); | |
| 2273 if (tmp != NULL) { | |
| 2274 NEW_BIT (NEW_TEXT_BIT); | |
| 2275 bg = tmp; | |
| 2276 UPDATE_BG_COLORS; | |
| 2277 } | |
| 2278 } | |
| 2279 } | |
| 2280 } | |
| 2281 } else if (!g_strncasecmp (tag, "<A ", strlen ("<A "))) { | |
| 2282 gchar *t, *e; | |
| 2283 | |
| 2284 got_tag = TRUE; | |
| 2285 NEW_BIT (NEW_TEXT_BIT); | |
| 2286 | |
| 2287 if (url != NULL) | |
| 2288 g_free (url); | |
| 2289 url = NULL; | |
| 2290 | |
| 2291 t = tag + strlen ("<A"); | |
| 2292 do { | |
| 2293 gboolean quote = FALSE; | |
| 2294 if (*t == '\0') break; | |
| 2295 while (*t && !((*t == ' ') && !quote)) { | |
| 2296 if (*t == '\"') | |
| 2297 quote = ! quote; | |
| 2298 t++; | |
| 2299 } | |
| 2300 while (*t && (*t == ' ')) t++; | |
| 2301 } while (g_strncasecmp (t, "HREF=", strlen ("HREF="))); | |
| 2302 | |
| 2303 if (!g_strncasecmp (t, "HREF=", strlen ("HREF="))) { | |
| 2304 t += strlen ("HREF="); | |
| 2305 if ((*t == '\"') || (*t == '\'')) { | |
| 2306 e = ++t; | |
| 2307 while (*e && (*e != *(t - 1))) e++; | |
| 2308 if (*e != '\0') { | |
| 2309 *e = '\0'; | |
| 2310 url = g_strdup (t); | |
| 2311 } | |
| 2312 } else { | |
| 2313 e = t; | |
| 2314 while (*e && !isspace ((gint) *e)) e++; | |
| 2315 if (*e == '\0') e--; | |
| 2316 *e = '\0'; | |
| 2317 url = g_strdup (t); | |
| 2318 } | |
| 2319 } | |
| 2320 } else if (!g_strcasecmp (tag, "</A>")) { | |
| 2321 got_tag = TRUE; | |
| 2322 if (url != NULL) { | |
| 2323 NEW_BIT (NEW_TEXT_BIT); | |
| 2324 g_free (url); | |
| 2325 } | |
| 2326 url = NULL; | |
| 2327 } else if (!g_strncasecmp (tag, "<IMG ", strlen ("<IMG "))) { | |
| 2328 gchar *t, *e, *src = NULL; | |
| 2329 gchar *copy = g_strdup (tag); | |
| 2330 gchar **xpm; | |
| 2331 GdkColor *clr = NULL; | |
| 2332 GtkIMHtmlBit *bit; | |
| 2333 | |
| 2334 intag = FALSE; | |
| 2335 tpos = 0; | |
| 2336 | |
|
1453
ecf700f23852
[gaim-migrate @ 1463]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1449
diff
changeset
|
2337 if (imhtml->img == NULL) { |
|
ecf700f23852
[gaim-migrate @ 1463]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1449
diff
changeset
|
2338 ws [wpos] = 0; |
|
ecf700f23852
[gaim-migrate @ 1463]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1449
diff
changeset
|
2339 strcat (ws, copy); |
|
ecf700f23852
[gaim-migrate @ 1463]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1449
diff
changeset
|
2340 wpos = strlen (ws); |
|
ecf700f23852
[gaim-migrate @ 1463]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1449
diff
changeset
|
2341 g_free (copy); |
| 1428 | 2342 continue; |
|
1453
ecf700f23852
[gaim-migrate @ 1463]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1449
diff
changeset
|
2343 } |
| 1428 | 2344 |
| 2345 t = tag + strlen ("<IMG"); | |
| 2346 do { | |
| 2347 gboolean quote = FALSE; | |
| 2348 if (*t == '\0') break; | |
| 2349 while (*t && !((*t == ' ') && !quote)) { | |
| 2350 if (*t == '\"') | |
| 2351 quote = ! quote; | |
| 2352 t++; | |
| 2353 } | |
| 2354 while (*t && (*t == ' ')) t++; | |
| 2355 } while (g_strncasecmp (t, "SRC=", strlen ("SRC="))); | |
| 2356 | |
| 2357 if (!g_strncasecmp (t, "SRC=", strlen ("SRC="))) { | |
| 2358 t += strlen ("SRC="); | |
| 2359 if ((*t == '\"') || (*t == '\'')) { | |
| 2360 e = ++t; | |
| 2361 while (*e && (*e != *(t - 1))) e++; | |
| 2362 if (*e != '\0') { | |
| 2363 *e = '\0'; | |
| 2364 src = g_strdup (t); | |
| 2365 } | |
| 2366 } else { | |
| 2367 e = t; | |
| 2368 while (*e && !isspace ((gint) *e)) e++; | |
| 2369 if (*e == '\0') e--; | |
| 2370 *e = '\0'; | |
| 2371 src = g_strdup (t); | |
| 2372 } | |
| 2373 } | |
| 2374 | |
| 2375 if (src == NULL) { | |
| 2376 ws [wpos] = 0; | |
| 2377 strcat (ws, copy); | |
| 2378 wpos = strlen (ws); | |
| 2379 g_free (copy); | |
| 2380 continue; | |
| 2381 } | |
| 2382 | |
| 2383 xpm = (* imhtml->img) (src); | |
| 2384 if (xpm == NULL) { | |
| 2385 g_free (src); | |
| 2386 ws [wpos] = 0; | |
| 2387 strcat (ws, copy); | |
| 2388 wpos = strlen (ws); | |
| 2389 g_free (copy); | |
| 2390 continue; | |
| 2391 } | |
| 2392 | |
| 2393 g_free (copy); | |
| 2394 | |
| 2395 if (!fonts || ((clr = ((FontDetail *)fonts->data)->back) == NULL)) | |
| 2396 clr = (bg != NULL) ? bg : >K_WIDGET (imhtml)->style->white; | |
| 2397 | |
| 2398 if (!GTK_WIDGET_REALIZED (imhtml)) | |
| 2399 gtk_widget_realize (GTK_WIDGET (imhtml)); | |
| 2400 | |
| 2401 bit = g_new0 (GtkIMHtmlBit, 1); | |
| 2402 bit->type = TYPE_IMG; | |
| 2403 bit->pm = gdk_pixmap_create_from_xpm_d (GTK_WIDGET (imhtml)->window, | |
| 2404 &bit->bm, | |
| 2405 clr, | |
| 2406 xpm); | |
| 2407 if (url) | |
| 2408 bit->url = g_strdup (url); | |
| 2409 | |
| 2410 NEW_BIT (bit); | |
| 2411 | |
| 2412 g_free (src); | |
| 2413 | |
| 2414 continue; | |
| 2415 } else if (!g_strcasecmp (tag, "<P>") || | |
| 2416 !g_strcasecmp (tag, "</P>") || | |
| 2417 !g_strncasecmp (tag, "<P ", strlen ("<P ")) || | |
| 2418 !g_strcasecmp (tag, "<PRE>") || | |
| 2419 !g_strcasecmp (tag, "</PRE>") || | |
|
1447
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
2420 !g_strcasecmp (tag, "<H3>") || |
|
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
2421 !g_strcasecmp (tag, "<H3 ") || |
|
5df631739769
[gaim-migrate @ 1457]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1428
diff
changeset
|
2422 !g_strcasecmp (tag, "</H3>") || |
| 1428 | 2423 !g_strcasecmp (tag, "<HTML>") || |
| 2424 !g_strcasecmp (tag, "</HTML>") || | |
| 2425 !g_strcasecmp (tag, "<BODY>") || | |
| 2426 !g_strcasecmp (tag, "</BODY>") || | |
| 2427 !g_strcasecmp (tag, "<FONT>") || | |
| 2428 !g_strcasecmp (tag, "<HEAD>") || | |
| 2429 !g_strcasecmp (tag, "</HEAD>")) { | |
| 2430 intag = FALSE; | |
| 2431 tpos = 0; | |
| 2432 continue; | |
| 2433 } | |
| 2434 | |
| 2435 if (!got_tag) { | |
| 2436 ws [wpos] = 0; | |
| 2437 strcat (ws, tag); | |
| 2438 wpos = strlen (ws); | |
| 2439 } else { | |
| 2440 wpos = 0; | |
| 2441 } | |
| 2442 intag = FALSE; | |
| 2443 tpos = 0; | |
| 2444 } else if (*c == '&' && !intag) { | |
| 2445 if (!g_strncasecmp (c, "&", 5)) { | |
| 2446 ws [wpos++] = '&'; | |
| 2447 c += 5; | |
| 2448 } else if (!g_strncasecmp (c, "<", 4)) { | |
| 2449 ws [wpos++] = '<'; | |
| 2450 c += 4; | |
| 2451 } else if (!g_strncasecmp (c, ">", 4)) { | |
| 2452 ws [wpos++] = '>'; | |
| 2453 c += 4; | |
| 2454 } else if (!g_strncasecmp (c, " ", 6)) { | |
| 2455 ws [wpos++] = ' '; | |
| 2456 c += 6; | |
| 2457 } else if (!g_strncasecmp (c, "©", 6)) { | |
| 2458 ws [wpos++] = '©'; | |
| 2459 c += 6; | |
| 2460 } else if (!g_strncasecmp (c, """, 6)) { | |
| 2461 ws [wpos++] = '\"'; | |
| 2462 c += 6; | |
| 2463 } else if (!g_strncasecmp (c, "®", 5)) { | |
| 2464 ws [wpos++] = '®'; | |
| 2465 c += 5; | |
| 2466 } else if (*(c + 1) == '#') { | |
| 2467 gint pound = 0; | |
| 2468 if (sscanf (c, "&#%d;", £) == 1) { | |
| 2469 if (*(c + 3 + (gint)log10 (pound)) != ';') { | |
| 2470 ws [wpos++] = *c++; | |
| 2471 continue; | |
| 2472 } | |
| 2473 ws [wpos++] = (gchar)pound; | |
| 2474 c += 2; | |
| 2475 while (isdigit ((gint) *c)) c++; | |
| 2476 if (*c == ';') c++; | |
| 2477 } else { | |
| 2478 ws [wpos++] = *c++; | |
| 2479 } | |
| 2480 } else { | |
| 2481 ws [wpos++] = *c++; | |
| 2482 } | |
| 2483 } else if (intag) { | |
| 2484 if (*c == '\"') | |
| 2485 tagquote = !tagquote; | |
| 2486 tag [tpos++] = *c++; | |
| 2487 } else if (incomment) { | |
| 2488 ws [wpos++] = *c++; | |
| 2489 } else if (((smilelen = gtk_imhtml_is_smiley (imhtml, c)) != 0)) { | |
| 2490 ws [wpos] = 0; | |
| 2491 wpos = 0; | |
| 2492 NEW_BIT (NEW_TEXT_BIT); | |
| 2493 g_snprintf (ws, smilelen + 1, "%s", c); | |
| 2494 NEW_BIT (NEW_SMILEY_BIT); | |
| 2495 c += smilelen; | |
| 2496 } else if (*c == '\n') { | |
| 2497 if (!(options & GTK_IMHTML_NO_NEWLINE)) { | |
| 2498 ws [wpos] = 0; | |
| 2499 wpos = 0; | |
| 2500 NEW_BIT (NEW_TEXT_BIT); | |
| 2501 NEW_BIT (NEW_BR_BIT); | |
| 2502 } | |
| 2503 c++; | |
| 2504 } else { | |
| 2505 ws [wpos++] = *c++; | |
| 2506 } | |
| 2507 } | |
| 2508 | |
| 2509 if (intag) { | |
| 2510 tag [tpos] = 0; | |
| 2511 c = tag; | |
| 2512 while (*c) { | |
| 2513 if ((smilelen = gtk_imhtml_is_smiley (imhtml, c)) != 0) { | |
| 2514 ws [wpos] = 0; | |
| 2515 wpos = 0; | |
| 2516 NEW_BIT (NEW_TEXT_BIT); | |
| 2517 g_snprintf (ws, smilelen + 1, "%s", c); | |
| 2518 NEW_BIT (NEW_SMILEY_BIT); | |
| 2519 c += smilelen; | |
| 2520 } else { | |
| 2521 ws [wpos++] = *c++; | |
| 2522 } | |
| 2523 } | |
| 2524 } else if (incomment) { | |
| 2525 ws [wpos] = 0; | |
| 2526 wpos = 0; | |
| 2527 strcat (tag, ws); | |
| 2528 ws [wpos] = 0; | |
| 2529 c = tag; | |
| 2530 while (*c) { | |
| 2531 if ((smilelen = gtk_imhtml_is_smiley (imhtml, c)) != 0) { | |
| 2532 ws [wpos] = 0; | |
| 2533 wpos = 0; | |
| 2534 NEW_BIT (NEW_TEXT_BIT); | |
| 2535 g_snprintf (ws, smilelen + 1, "%s", c); | |
| 2536 NEW_BIT (NEW_SMILEY_BIT); | |
| 2537 c += smilelen; | |
| 2538 } else { | |
| 2539 ws [wpos++] = *c++; | |
| 2540 } | |
| 2541 } | |
| 2542 } | |
| 2543 | |
| 2544 ws [wpos] = 0; | |
| 2545 NEW_BIT (NEW_TEXT_BIT); | |
| 2546 | |
| 2547 while (newbits) { | |
| 2548 GtkIMHtmlBit *bit = newbits->data; | |
| 2549 imhtml->bits = g_list_append (imhtml->bits, bit); | |
| 2550 newbits = g_list_remove (newbits, bit); | |
| 2551 gtk_imhtml_draw_bit (imhtml, bit); | |
| 2552 } | |
| 2553 | |
| 2554 gtk_widget_set_usize (GTK_WIDGET (imhtml), -1, imhtml->y + 5); | |
| 2555 | |
| 2556 if (!(options & GTK_IMHTML_NO_SCROLL) && | |
| 2557 scrolldown && | |
| 2558 (imhtml->y + 5 >= GTK_WIDGET (imhtml)->allocation.height)) | |
| 2559 gtk_adjustment_set_value (vadj, imhtml->y + 5 - GTK_WIDGET (imhtml)->allocation.height); | |
| 2560 | |
| 2561 if (url) { | |
| 2562 g_free (url); | |
| 2563 if (retval) | |
| 2564 retval = g_string_append (retval, "</A>"); | |
| 2565 } | |
| 2566 if (bg) | |
| 2567 gdk_color_free (bg); | |
| 2568 while (fonts) { | |
| 2569 FontDetail *font = fonts->data; | |
| 2570 fonts = g_slist_remove (fonts, font); | |
| 2571 g_free (font->face); | |
| 2572 if (font->fore) | |
| 2573 gdk_color_free (font->fore); | |
| 2574 if (font->back) | |
| 2575 gdk_color_free (font->back); | |
| 2576 g_free (font); | |
| 2577 if (retval) | |
| 2578 retval = g_string_append (retval, "</FONT>"); | |
| 2579 } | |
| 2580 if (retval) { | |
| 2581 while (bold) { | |
| 2582 retval = g_string_append (retval, "</B>"); | |
| 2583 bold--; | |
| 2584 } | |
| 2585 while (italics) { | |
| 2586 retval = g_string_append (retval, "</I>"); | |
| 2587 italics--; | |
| 2588 } | |
| 2589 while (underline) { | |
| 2590 retval = g_string_append (retval, "</U>"); | |
| 2591 underline--; | |
| 2592 } | |
| 2593 while (strike) { | |
| 2594 retval = g_string_append (retval, "</S>"); | |
| 2595 strike--; | |
| 2596 } | |
| 2597 while (sub) { | |
| 2598 retval = g_string_append (retval, "</SUB>"); | |
| 2599 sub--; | |
| 2600 } | |
| 2601 while (sup) { | |
| 2602 retval = g_string_append (retval, "</SUP>"); | |
| 2603 sup--; | |
| 2604 } | |
| 2605 while (title) { | |
| 2606 retval = g_string_append (retval, "</TITLE>"); | |
| 2607 title--; | |
| 2608 } | |
| 2609 } | |
| 2610 g_free (ws); | |
| 2611 g_free (tag); | |
| 2612 | |
| 2613 return retval; | |
| 2614 } |
