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