Mercurial > pidgin.yaz
annotate src/gtkhtml.c @ 860:a8633715fb5b
[gaim-migrate @ 870]
bgcolors work better. hopefully we can get them to smileys eventually
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Fri, 08 Sep 2000 05:05:06 +0000 |
parents | 050f244b6829 |
children | d828bdc3854b |
rev | line source |
---|---|
12 | 1 |
1 | 2 /* |
3 * gaim | |
4 * | |
5 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net> | |
6 * | |
7 * This program is free software; you can redistribute it and/or modify | |
8 * it under the terms of the GNU General Public License as published by | |
9 * the Free Software Foundation; either version 2 of the License, or | |
10 * (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, | |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 * GNU General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU General Public License | |
18 * along with this program; if not, write to the Free Software | |
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
20 * | |
21 */ | |
22 | |
349
b402a23f35df
[gaim-migrate @ 359]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
337
diff
changeset
|
23 #ifdef HAVE_CONFIG_H |
b402a23f35df
[gaim-migrate @ 359]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
337
diff
changeset
|
24 #include "../config.h" |
b402a23f35df
[gaim-migrate @ 359]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
337
diff
changeset
|
25 #endif |
1 | 26 #include <stdio.h> |
27 #include <stdlib.h> | |
28 #include <string.h> | |
29 #include <gtk/gtk.h> | |
30 #include <gdk/gdkprivate.h> | |
31 #include <gdk/gdkx.h> | |
32 #include <gdk/gdkkeysyms.h> | |
604
0b1a132e0f75
[gaim-migrate @ 614]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
574
diff
changeset
|
33 #include <ctype.h> |
12 | 34 |
35 #ifndef _WIN32 | |
1 | 36 #include <X11/Xlib.h> |
37 #include <X11/Xatom.h> | |
12 | 38 #endif |
39 | |
69 | 40 #include "gaim.h" |
1 | 41 #include "gtkhtml.h" |
42 | |
549 | 43 #include "pixmaps/aol_icon.xpm" |
44 #include "pixmaps/admin_icon.xpm" | |
45 #include "pixmaps/free_icon.xpm" | |
46 #include "pixmaps/dt_icon.xpm" | |
1 | 47 #define MAX_SIZE 7 |
48 #define MIN_HTML_WIDTH_LINES 20 | |
49 #define MIN_HTML_HEIGHT_LINES 10 | |
50 #define BORDER_WIDTH 2 | |
51 #define SCROLL_TIME 100 | |
52 #define SCROLL_PIXELS 5 | |
53 #define KEY_SCROLL_PIXELS 10 | |
54 | |
55 int font_sizes[] = { 80, 100, 120, 140, 200, 300, 400 }; | |
56 | |
12 | 57 /* |
1 | 58 GdkFont *fixed_font[] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL }; |
59 GdkFont *fixed_bold_font[] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL }; | |
60 GdkFont *fixed_italic_font[] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL }; | |
12 | 61 GdkFont *fixed_bold_italic_font[] = |
62 { NULL, NULL, NULL, NULL, NULL, NULL, NULL }; | |
1 | 63 GdkFont *prop_font[] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL }; |
64 GdkFont *prop_bold_font[] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL }; | |
65 GdkFont *prop_italic_font[] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL }; | |
66 GdkFont *prop_bold_italic_font[] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL }; | |
12 | 67 */ |
68 | |
69 GData * font_cache; | |
70 static gboolean cache_init = FALSE; | |
71 | |
72 struct font_state | |
73 { | |
74 int size; | |
75 int owncolor; | |
76 int ownbg; | |
77 gchar font[1024]; | |
78 GdkColor *color; | |
79 GdkColor *bgcol; | |
80 struct font_state *next; | |
1 | 81 }; |
82 | |
83 struct font_state *push_state(struct font_state *current) | |
84 { | |
12 | 85 struct font_state *tmp; |
86 tmp = (struct font_state *) g_new0(struct font_state, 1); | |
1 | 87 tmp->next = current; |
88 tmp->color = current->color; | |
89 tmp->bgcol = current->bgcol; | |
90 tmp->size = current->size; | |
91 tmp->owncolor = 0; | |
92 tmp->ownbg = 0; | |
12 | 93 strcpy( tmp->font, current->font ); |
1 | 94 return tmp; |
95 } | |
96 | |
12 | 97 enum |
98 { | |
99 ARG_0, | |
100 ARG_HADJUSTMENT, | |
101 ARG_VADJUSTMENT, | |
1 | 102 }; |
103 | |
104 | |
12 | 105 enum |
106 { | |
107 TARGET_STRING, | |
108 TARGET_TEXT, | |
109 TARGET_COMPOUND_TEXT | |
1 | 110 }; |
111 | |
112 | |
12 | 113 static void gtk_html_class_init(GtkHtmlClass * klass); |
114 static void gtk_html_set_arg(GtkObject * object, GtkArg * arg, guint arg_id); | |
115 static void gtk_html_get_arg(GtkObject * object, GtkArg * arg, guint arg_id); | |
116 static void gtk_html_init(GtkHtml * html); | |
117 static void gtk_html_destroy(GtkObject * object); | |
118 static void gtk_html_finalize(GtkObject * object); | |
119 static void gtk_html_realize(GtkWidget * widget); | |
120 static void gtk_html_unrealize(GtkWidget * widget); | |
121 static void gtk_html_style_set(GtkWidget * widget, GtkStyle * previous_style); | |
122 static void gtk_html_draw_focus(GtkWidget * widget); | |
123 static void gtk_html_size_request(GtkWidget * widget, | |
124 GtkRequisition * requisition); | |
125 static void gtk_html_size_allocate(GtkWidget * widget, | |
126 GtkAllocation * allocation); | |
127 static void gtk_html_adjustment(GtkAdjustment * adjustment, GtkHtml * html); | |
128 static void gtk_html_disconnect(GtkAdjustment * adjustment, GtkHtml * html); | |
129 static void gtk_html_add_seperator(GtkHtml * html); | |
337 | 130 // static void gtk_html_add_pixmap(GtkHtml * html, GdkPixmap * pm, gint fit); |
12 | 131 static void gtk_html_add_text(GtkHtml * html, |
132 GdkFont * font, | |
133 GdkColor * fore, | |
134 GdkColor * back, | |
135 gchar * chars, | |
136 gint length, | |
137 gint uline, gint strike, gchar * url); | |
138 static void gtk_html_draw_bit(GtkHtml * html, | |
139 GtkHtmlBit * htmlbit, gint redraw); | |
140 static void gtk_html_selection_get(GtkWidget * widget, | |
141 GtkSelectionData * selection_data, | |
142 guint sel_info, guint32 time); | |
143 static gint gtk_html_selection_clear(GtkWidget * widget, | |
144 GdkEventSelection * event); | |
145 static gint gtk_html_visibility_notify(GtkWidget * widget, | |
146 GdkEventVisibility * event); | |
1 | 147 |
148 | |
149 /* Event handlers */ | |
12 | 150 static void gtk_html_draw(GtkWidget * widget, GdkRectangle * area); |
151 static gint gtk_html_expose(GtkWidget * widget, GdkEventExpose * event); | |
152 static gint gtk_html_button_press(GtkWidget * widget, GdkEventButton * event); | |
153 static gint gtk_html_button_release(GtkWidget * widget, GdkEventButton * event); | |
154 static gint gtk_html_motion_notify(GtkWidget * widget, GdkEventMotion * event); | |
155 static gint gtk_html_key_press(GtkWidget * widget, GdkEventKey * event); | |
156 static gint gtk_html_leave_notify(GtkWidget * widget, GdkEventCrossing * event); | |
1 | 157 |
158 static gint gtk_html_tooltip_timeout(gpointer data); | |
159 | |
160 | |
12 | 161 static void clear_area(GtkHtml * html, GdkRectangle * area); |
162 static void expose_html(GtkHtml * html, GdkRectangle * area, gboolean cursor); | |
163 static void scroll_down(GtkHtml * html, gint diff0); | |
164 static void scroll_up(GtkHtml * html, gint diff0); | |
165 | |
166 static void adjust_adj(GtkHtml * html, GtkAdjustment * adj); | |
167 static void resize_html(GtkHtml * html); | |
168 static gint html_bit_is_onscreen(GtkHtml * html, GtkHtmlBit * hb); | |
169 static void draw_cursor(GtkHtml * html); | |
170 static void undraw_cursor(GtkHtml * html); | |
1 | 171 |
172 static GtkWidgetClass *parent_class = NULL; | |
173 | |
174 GtkType gtk_html_get_type(void) | |
175 { | |
12 | 176 static GtkType html_type = 0; |
177 | |
178 if (!html_type) | |
179 { | |
180 static const GtkTypeInfo html_info = { | |
181 "GtkHtml", | |
182 sizeof(GtkHtml), | |
183 sizeof(GtkHtmlClass), | |
184 (GtkClassInitFunc) gtk_html_class_init, | |
185 (GtkObjectInitFunc) gtk_html_init, | |
186 NULL, | |
187 NULL, | |
188 NULL, | |
189 }; | |
190 html_type = gtk_type_unique(GTK_TYPE_WIDGET, &html_info); | |
191 } | |
192 return html_type; | |
1 | 193 } |
194 | |
195 | |
12 | 196 static void gtk_html_class_init(GtkHtmlClass * class) |
1 | 197 { |
12 | 198 GtkObjectClass *object_class; |
199 GtkWidgetClass *widget_class; | |
200 | |
201 object_class = (GtkObjectClass *) class; | |
202 widget_class = (GtkWidgetClass *) class; | |
203 parent_class = gtk_type_class(GTK_TYPE_WIDGET); | |
204 | |
205 | |
206 gtk_object_add_arg_type("GtkHtml::hadjustment", | |
207 GTK_TYPE_ADJUSTMENT, | |
208 GTK_ARG_READWRITE | GTK_ARG_CONSTRUCT, | |
209 ARG_HADJUSTMENT); | |
210 | |
211 gtk_object_add_arg_type("GtkHtml::vadjustment", | |
212 GTK_TYPE_ADJUSTMENT, | |
213 GTK_ARG_READWRITE | GTK_ARG_CONSTRUCT, | |
214 ARG_VADJUSTMENT); | |
215 | |
216 object_class->set_arg = gtk_html_set_arg; | |
217 object_class->get_arg = gtk_html_get_arg; | |
218 object_class->destroy = gtk_html_destroy; | |
219 object_class->finalize = gtk_html_finalize; | |
220 | |
221 widget_class->realize = gtk_html_realize; | |
222 widget_class->unrealize = gtk_html_unrealize; | |
223 widget_class->style_set = gtk_html_style_set; | |
224 widget_class->draw_focus = gtk_html_draw_focus; | |
225 widget_class->size_request = gtk_html_size_request; | |
226 widget_class->size_allocate = gtk_html_size_allocate; | |
227 widget_class->draw = gtk_html_draw; | |
228 widget_class->expose_event = gtk_html_expose; | |
229 widget_class->button_press_event = gtk_html_button_press; | |
230 widget_class->button_release_event = gtk_html_button_release; | |
1 | 231 widget_class->motion_notify_event = gtk_html_motion_notify; |
232 widget_class->leave_notify_event = gtk_html_leave_notify; | |
12 | 233 widget_class->selection_get = gtk_html_selection_get; |
1 | 234 widget_class->selection_clear_event = gtk_html_selection_clear; |
235 widget_class->key_press_event = gtk_html_key_press; | |
236 widget_class->visibility_notify_event = gtk_html_visibility_notify; | |
12 | 237 |
238 | |
239 widget_class->set_scroll_adjustments_signal = | |
240 gtk_signal_new("set_scroll_adjustments", | |
241 GTK_RUN_LAST, | |
242 object_class->type, | |
243 GTK_SIGNAL_OFFSET(GtkHtmlClass, set_scroll_adjustments), | |
244 gtk_marshal_NONE__POINTER_POINTER, | |
245 GTK_TYPE_NONE, 2, GTK_TYPE_ADJUSTMENT, | |
246 GTK_TYPE_ADJUSTMENT); | |
247 | |
248 | |
249 class->set_scroll_adjustments = gtk_html_set_adjustments; | |
1 | 250 |
251 } | |
252 | |
12 | 253 static void gtk_html_set_arg(GtkObject * object, GtkArg * arg, guint arg_id) |
1 | 254 { |
12 | 255 GtkHtml *html; |
256 | |
257 html = GTK_HTML(object); | |
258 | |
259 switch (arg_id) | |
260 { | |
261 case ARG_HADJUSTMENT: | |
262 gtk_html_set_adjustments(html, GTK_VALUE_POINTER(*arg), html->vadj); | |
263 break; | |
264 case ARG_VADJUSTMENT: | |
265 gtk_html_set_adjustments(html, html->hadj, GTK_VALUE_POINTER(*arg)); | |
266 break; | |
267 default: | |
268 break; | |
269 } | |
1 | 270 } |
271 | |
12 | 272 static void gtk_html_get_arg(GtkObject * object, GtkArg * arg, guint arg_id) |
1 | 273 { |
12 | 274 GtkHtml *html; |
275 | |
276 html = GTK_HTML(object); | |
277 | |
278 switch (arg_id) | |
279 { | |
280 case ARG_HADJUSTMENT: | |
281 GTK_VALUE_POINTER(*arg) = html->hadj; | |
282 break; | |
283 case ARG_VADJUSTMENT: | |
284 GTK_VALUE_POINTER(*arg) = html->vadj; | |
285 break; | |
286 default: | |
287 arg->type = GTK_TYPE_INVALID; | |
288 break; | |
289 } | |
1 | 290 } |
291 | |
12 | 292 static void gtk_html_init(GtkHtml * html) |
1 | 293 { |
12 | 294 static const GtkTargetEntry targets[] = { |
295 {"STRING", 0, TARGET_STRING}, | |
296 {"TEXT", 0, TARGET_TEXT}, | |
297 {"COMPOUND_TEXT", 0, TARGET_COMPOUND_TEXT} | |
298 }; | |
299 | |
300 static const gint n_targets = sizeof(targets) / sizeof(targets[0]); | |
301 | |
302 GTK_WIDGET_SET_FLAGS(html, GTK_CAN_FOCUS); | |
303 | |
304 html->html_area = NULL; | |
305 html->hadj = NULL; | |
306 html->vadj = NULL; | |
1 | 307 html->current_x = 0; |
308 html->current_y = 0; | |
12 | 309 html->start_sel = html->end_sel = NULL; |
310 html->start_sel_x = html->start_sel_y = -1; | |
311 html->num_end = html->num_start = -1; | |
312 | |
1 | 313 html->html_bits = NULL; |
314 html->urls = NULL; | |
315 html->selected_text = NULL; | |
316 html->tooltip_hb = NULL; | |
317 html->tooltip_timer = -1; | |
318 html->tooltip_window = NULL; | |
12 | 319 html->cursor_hb = NULL; |
1 | 320 html->cursor_pos = 0; |
321 | |
322 html->pm = NULL; | |
323 | |
324 html->editable = 0; | |
325 html->transparent = 0; | |
326 | |
12 | 327 html->frozen = 0; |
328 | |
329 gtk_selection_add_targets(GTK_WIDGET(html), GDK_SELECTION_PRIMARY, | |
330 targets, n_targets); | |
331 | |
332 | |
333 | |
1 | 334 } |
335 | |
336 | |
12 | 337 GtkWidget *gtk_html_new(GtkAdjustment * hadj, GtkAdjustment * vadj) |
1 | 338 { |
12 | 339 GtkWidget *html; |
340 if(!cache_init) | |
341 { | |
342 g_datalist_init(&font_cache); | |
343 cache_init = TRUE; | |
344 } | |
345 | |
346 if (hadj) | |
347 g_return_val_if_fail(GTK_IS_ADJUSTMENT(hadj), NULL); | |
348 if (vadj) | |
349 g_return_val_if_fail(GTK_IS_ADJUSTMENT(vadj), NULL); | |
350 | |
351 html = gtk_widget_new(GTK_TYPE_HTML, | |
352 "hadjustment", hadj, "vadjustment", vadj, NULL); | |
353 | |
354 return html; | |
1 | 355 } |
356 | |
357 | |
12 | 358 void gtk_html_set_editable(GtkHtml * html, gboolean is_editable) |
1 | 359 { |
12 | 360 g_return_if_fail(html != NULL); |
361 g_return_if_fail(GTK_IS_HTML(html)); | |
362 | |
363 | |
364 html->editable = (is_editable != FALSE); | |
365 | |
366 if (is_editable) | |
367 draw_cursor(html); | |
368 else | |
369 undraw_cursor(html); | |
1 | 370 |
371 } | |
372 | |
12 | 373 void gtk_html_set_transparent(GtkHtml * html, gboolean is_transparent) |
1 | 374 { |
12 | 375 GdkRectangle rect; |
376 gint width, | |
377 height; | |
378 GtkWidget *widget; | |
379 | |
380 g_return_if_fail(html != NULL); | |
381 g_return_if_fail(GTK_IS_HTML(html)); | |
382 | |
383 | |
384 widget = GTK_WIDGET(html); | |
385 html->transparent = (is_transparent != FALSE); | |
386 | |
387 if (!GTK_WIDGET_REALIZED(widget)) | |
388 return; | |
389 | |
390 html->bg_gc = NULL; | |
391 gdk_window_get_size(widget->window, &width, &height); | |
392 rect.x = 0; | |
393 rect.y = 0; | |
394 rect.width = width; | |
395 rect.height = height; | |
396 gdk_window_clear_area(widget->window, rect.x, rect.y, rect.width, | |
397 rect.height); | |
398 | |
399 expose_html(html, &rect, FALSE); | |
400 gtk_html_draw_focus((GtkWidget *) html); | |
1 | 401 } |
402 | |
403 | |
12 | 404 void gtk_html_set_adjustments(GtkHtml * html, |
405 GtkAdjustment * hadj, GtkAdjustment * vadj) | |
1 | 406 { |
12 | 407 g_return_if_fail(html != NULL); |
408 g_return_if_fail(GTK_IS_HTML(html)); | |
409 if (hadj) | |
410 g_return_if_fail(GTK_IS_ADJUSTMENT(hadj)); | |
411 else | |
412 hadj = GTK_ADJUSTMENT(gtk_adjustment_new(0.0, 0.0, 0.0, 0.0, 0.0, 0.0)); | |
413 if (vadj) | |
414 g_return_if_fail(GTK_IS_ADJUSTMENT(vadj)); | |
415 else | |
416 vadj = GTK_ADJUSTMENT(gtk_adjustment_new(0.0, 0.0, 0.0, 0.0, 0.0, 0.0)); | |
417 | |
418 if (html->hadj && (html->hadj != hadj)) | |
419 { | |
420 gtk_signal_disconnect_by_data(GTK_OBJECT(html->hadj), html); | |
421 gtk_object_unref(GTK_OBJECT(html->hadj)); | |
422 } | |
423 | |
424 if (html->vadj && (html->vadj != vadj)) | |
425 { | |
426 gtk_signal_disconnect_by_data(GTK_OBJECT(html->vadj), html); | |
427 gtk_object_unref(GTK_OBJECT(html->vadj)); | |
428 } | |
429 | |
430 if (html->hadj != hadj) | |
431 { | |
432 html->hadj = hadj; | |
433 gtk_object_ref(GTK_OBJECT(html->hadj)); | |
434 gtk_object_sink(GTK_OBJECT(html->hadj)); | |
435 | |
436 gtk_signal_connect(GTK_OBJECT(html->hadj), "changed", | |
437 (GtkSignalFunc) gtk_html_adjustment, html); | |
438 gtk_signal_connect(GTK_OBJECT(html->hadj), "value_changed", | |
439 (GtkSignalFunc) gtk_html_adjustment, html); | |
440 gtk_signal_connect(GTK_OBJECT(html->hadj), "disconnect", | |
441 (GtkSignalFunc) gtk_html_disconnect, html); | |
442 gtk_html_adjustment(hadj, html); | |
443 } | |
444 | |
445 if (html->vadj != vadj) | |
446 { | |
447 html->vadj = vadj; | |
448 gtk_object_ref(GTK_OBJECT(html->vadj)); | |
449 gtk_object_sink(GTK_OBJECT(html->vadj)); | |
450 | |
451 gtk_signal_connect(GTK_OBJECT(html->vadj), "changed", | |
452 (GtkSignalFunc) gtk_html_adjustment, html); | |
453 gtk_signal_connect(GTK_OBJECT(html->vadj), "value_changed", | |
454 (GtkSignalFunc) gtk_html_adjustment, html); | |
455 gtk_signal_connect(GTK_OBJECT(html->vadj), "disconnect", | |
456 (GtkSignalFunc) gtk_html_disconnect, html); | |
457 gtk_html_adjustment(vadj, html); | |
458 } | |
1 | 459 } |
460 | |
461 | |
462 | |
12 | 463 GdkColor *get_color(int colorv, GdkColormap * map) |
1 | 464 { |
465 GdkColor *color; | |
12 | 466 #if 0 |
467 fprintf(stdout, "color is %x\n", colorv); | |
468 #endif | |
469 color = (GdkColor *) g_new0(GdkColor, 1); | |
1 | 470 color->red = ((colorv & 0xff0000) >> 16) * 256; |
471 color->green = ((colorv & 0xff00) >> 8) * 256; | |
472 color->blue = ((colorv & 0xff)) * 256; | |
473 #if 0 | |
12 | 474 fprintf(stdout, "Colors are %d, %d, %d\n", color->red, color->green, |
475 color->blue); | |
1 | 476 #endif |
477 gdk_color_alloc(map, color); | |
478 return color; | |
479 } | |
480 | |
481 | |
286 | 482 int load_font_with_cache(const char *name, const char *weight, char slant, |
483 int size, GdkFont **font_return) | |
1 | 484 { |
286 | 485 gchar font_spec[1024]; |
486 | |
306
a8f964718837
[gaim-migrate @ 316]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
305
diff
changeset
|
487 if (size > 0) |
a8f964718837
[gaim-migrate @ 316]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
305
diff
changeset
|
488 g_snprintf(font_spec, sizeof font_spec, |
a8f964718837
[gaim-migrate @ 316]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
305
diff
changeset
|
489 "-*-%s-%s-%c-*-*-*-%d-*-*-*-*-*-*", |
a8f964718837
[gaim-migrate @ 316]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
305
diff
changeset
|
490 name, weight, slant, size); |
852
836d5a02a35c
[gaim-migrate @ 862]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
851
diff
changeset
|
491 else |
791
678bdc430df7
[gaim-migrate @ 801]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
740
diff
changeset
|
492 g_snprintf(font_spec, sizeof font_spec, |
678bdc430df7
[gaim-migrate @ 801]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
740
diff
changeset
|
493 "-*-%s-%s-%c-*-*-*-*-*-*-*-*-*-*", |
678bdc430df7
[gaim-migrate @ 801]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
740
diff
changeset
|
494 name, weight, slant); |
286 | 495 |
496 if((*font_return = g_datalist_id_get_data(&font_cache, | |
497 g_quark_from_string(font_spec)))) { | |
498 return TRUE; | |
499 } else if ((*font_return = gdk_font_load(font_spec))) { | |
500 g_datalist_id_set_data(&font_cache, | |
501 g_quark_from_string(font_spec), *font_return); | |
502 return TRUE; | |
503 } else { | |
504 return FALSE; | |
12 | 505 } |
286 | 506 } |
507 | |
508 | |
509 GdkFont *getfont(const char *font, int bold, int italic, int fixed, int size) | |
510 { | |
511 GdkFont *my_font = NULL; | |
512 gchar *weight, slant; | |
513 | |
514 if (!font || !strlen(font)) font = fixed ? "courier" : "helvetica"; | |
515 weight = bold ? "bold" : "medium"; | |
516 slant = italic ? 'i' : 'r'; | |
517 | |
518 if (size > MAX_SIZE) size = MAX_SIZE; | |
519 if (size < 1) size = 1; | |
520 size = font_sizes[size-1]; | |
521 | |
852
836d5a02a35c
[gaim-migrate @ 862]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
851
diff
changeset
|
522 /* try both 'i'talic and 'o'blique for italic fonts */ |
286 | 523 |
791
678bdc430df7
[gaim-migrate @ 801]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
740
diff
changeset
|
524 if (load_font_with_cache(font, weight, slant, size, &my_font)) |
678bdc430df7
[gaim-migrate @ 801]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
740
diff
changeset
|
525 return my_font; |
852
836d5a02a35c
[gaim-migrate @ 862]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
851
diff
changeset
|
526 if (load_font_with_cache(font, weight, 'o', size, &my_font)) |
836d5a02a35c
[gaim-migrate @ 862]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
851
diff
changeset
|
527 return my_font; |
836d5a02a35c
[gaim-migrate @ 862]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
851
diff
changeset
|
528 if (italic && load_font_with_cache(font, weight, slant, 0, &my_font)) |
836d5a02a35c
[gaim-migrate @ 862]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
851
diff
changeset
|
529 return my_font; |
791
678bdc430df7
[gaim-migrate @ 801]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
740
diff
changeset
|
530 if (italic && load_font_with_cache(font, weight, 'o', 0, &my_font)) |
678bdc430df7
[gaim-migrate @ 801]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
740
diff
changeset
|
531 return my_font; |
678bdc430df7
[gaim-migrate @ 801]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
740
diff
changeset
|
532 |
678bdc430df7
[gaim-migrate @ 801]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
740
diff
changeset
|
533 /* since we couldn't get the right font, fall back to the default fonts. */ |
286 | 534 |
535 font = fixed ? "courier" : "helvetica"; | |
791
678bdc430df7
[gaim-migrate @ 801]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
740
diff
changeset
|
536 if (load_font_with_cache(font, weight, slant, size, &my_font)) |
678bdc430df7
[gaim-migrate @ 801]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
740
diff
changeset
|
537 return my_font; |
678bdc430df7
[gaim-migrate @ 801]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
740
diff
changeset
|
538 if (load_font_with_cache(font, weight, slant, 0, &my_font)) |
678bdc430df7
[gaim-migrate @ 801]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
740
diff
changeset
|
539 return my_font; |
305
77404a4692b1
[gaim-migrate @ 315]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
286
diff
changeset
|
540 |
77404a4692b1
[gaim-migrate @ 315]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
286
diff
changeset
|
541 font = fixed ? "helvetica" : "courier"; |
791
678bdc430df7
[gaim-migrate @ 801]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
740
diff
changeset
|
542 if (load_font_with_cache(font, weight, slant, size, &my_font)) |
678bdc430df7
[gaim-migrate @ 801]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
740
diff
changeset
|
543 return my_font; |
678bdc430df7
[gaim-migrate @ 801]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
740
diff
changeset
|
544 if (load_font_with_cache(font, weight, slant, 0, &my_font)) |
678bdc430df7
[gaim-migrate @ 801]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
740
diff
changeset
|
545 return my_font; |
305
77404a4692b1
[gaim-migrate @ 315]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
286
diff
changeset
|
546 |
721
8e7ad10b5f26
[gaim-migrate @ 731]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
720
diff
changeset
|
547 /* whoops, couldn't do any of those. maybe they have a default outgoing |
8e7ad10b5f26
[gaim-migrate @ 731]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
720
diff
changeset
|
548 * font? maybe we can use that. */ |
8e7ad10b5f26
[gaim-migrate @ 731]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
720
diff
changeset
|
549 if (fontface[0]) { |
8e7ad10b5f26
[gaim-migrate @ 731]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
720
diff
changeset
|
550 /* woohoo! */ |
791
678bdc430df7
[gaim-migrate @ 801]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
740
diff
changeset
|
551 if (load_font_with_cache(fontface, "medium", 'r', size, &my_font)) |
678bdc430df7
[gaim-migrate @ 801]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
740
diff
changeset
|
552 return my_font; |
678bdc430df7
[gaim-migrate @ 801]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
740
diff
changeset
|
553 if (load_font_with_cache(fontface, "medium", 'r', 0, &my_font)) |
678bdc430df7
[gaim-migrate @ 801]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
740
diff
changeset
|
554 return my_font; |
721
8e7ad10b5f26
[gaim-migrate @ 731]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
720
diff
changeset
|
555 } |
8e7ad10b5f26
[gaim-migrate @ 731]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
720
diff
changeset
|
556 |
305
77404a4692b1
[gaim-migrate @ 315]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
286
diff
changeset
|
557 /* ok, now we're in a pickle. if we can't do any of the above, let's |
77404a4692b1
[gaim-migrate @ 315]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
286
diff
changeset
|
558 * try doing the most boring font we can find. */ |
791
678bdc430df7
[gaim-migrate @ 801]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
740
diff
changeset
|
559 if (load_font_with_cache("helvetica", "medium", 'r', size, &my_font)) |
678bdc430df7
[gaim-migrate @ 801]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
740
diff
changeset
|
560 return my_font; |
678bdc430df7
[gaim-migrate @ 801]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
740
diff
changeset
|
561 if (load_font_with_cache("helvetica", "medium", 'r', 0, &my_font)) |
678bdc430df7
[gaim-migrate @ 801]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
740
diff
changeset
|
562 return my_font; |
678bdc430df7
[gaim-migrate @ 801]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
740
diff
changeset
|
563 |
678bdc430df7
[gaim-migrate @ 801]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
740
diff
changeset
|
564 if (load_font_with_cache("courier", "medium", 'r', size, &my_font)) |
678bdc430df7
[gaim-migrate @ 801]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
740
diff
changeset
|
565 return my_font; |
678bdc430df7
[gaim-migrate @ 801]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
740
diff
changeset
|
566 if (load_font_with_cache("courier", "medium", 'r', 0, &my_font)) |
678bdc430df7
[gaim-migrate @ 801]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
740
diff
changeset
|
567 return my_font; |
678bdc430df7
[gaim-migrate @ 801]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
740
diff
changeset
|
568 |
678bdc430df7
[gaim-migrate @ 801]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
740
diff
changeset
|
569 if (load_font_with_cache("times", "medium", 'r', size, &my_font)) |
678bdc430df7
[gaim-migrate @ 801]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
740
diff
changeset
|
570 return my_font; |
678bdc430df7
[gaim-migrate @ 801]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
740
diff
changeset
|
571 if (load_font_with_cache("times", "medium", 'r', 0, &my_font)) |
678bdc430df7
[gaim-migrate @ 801]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
740
diff
changeset
|
572 return my_font; |
305
77404a4692b1
[gaim-migrate @ 315]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
286
diff
changeset
|
573 |
77404a4692b1
[gaim-migrate @ 315]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
286
diff
changeset
|
574 /* my god, how did we end up here. is there a 'generic font' function |
77404a4692b1
[gaim-migrate @ 315]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
286
diff
changeset
|
575 * in gdk? that would be incredibly useful here. there's gotta be a |
77404a4692b1
[gaim-migrate @ 315]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
286
diff
changeset
|
576 * better way to do this. */ |
77404a4692b1
[gaim-migrate @ 315]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
286
diff
changeset
|
577 |
306
a8f964718837
[gaim-migrate @ 316]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
305
diff
changeset
|
578 /* well, if they can't do any of the fonts above, they'll take whatever |
a8f964718837
[gaim-migrate @ 316]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
305
diff
changeset
|
579 * they can get, and be happy about it, damn it. :) */ |
852
836d5a02a35c
[gaim-migrate @ 862]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
851
diff
changeset
|
580 load_font_with_cache("*", "*", '*', 0, &my_font); |
306
a8f964718837
[gaim-migrate @ 316]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
305
diff
changeset
|
581 return my_font; |
1 | 582 } |
583 | |
584 | |
585 /* 'Borrowed' from ETerm */ | |
12 | 586 GdkWindow *get_desktop_window(GtkWidget * widget) |
1 | 587 { |
12 | 588 #ifndef _WIN32 |
589 GdkAtom prop, | |
590 type, | |
591 prop2; | |
592 int format; | |
593 gint length; | |
594 guchar *data; | |
1 | 595 GtkWidget *w; |
596 | |
12 | 597 prop = gdk_atom_intern("_XROOTPMAP_ID", 1); |
598 prop2 = gdk_atom_intern("_XROOTCOLOR_PIXEL", 1); | |
599 | |
600 if (prop == None && prop2 == None) | |
601 { | |
602 return NULL; | |
603 } | |
604 | |
605 | |
606 | |
607 for (w = widget; w; w = w->parent) | |
608 { | |
609 | |
610 if (prop != None) | |
611 { | |
1 | 612 gdk_property_get(w->window, prop, AnyPropertyType, 0L, 1L, 0, |
12 | 613 &type, &format, &length, &data); |
614 } | |
615 else if (prop2 != None) | |
616 { | |
1 | 617 gdk_property_get(w->window, prop2, AnyPropertyType, 0L, 1L, 0, |
12 | 618 &type, &format, &length, &data); |
619 } | |
620 else | |
621 { | |
1 | 622 continue; |
623 } | |
12 | 624 if (type != None) |
625 { | |
1 | 626 return (w->window); |
627 } | |
628 } | |
12 | 629 #endif |
1 | 630 return NULL; |
631 | |
632 } | |
633 | |
634 | |
635 | |
12 | 636 GdkPixmap *get_desktop_pixmap(GtkWidget * widget) |
1 | 637 { |
12 | 638 #ifndef _WIN32 |
639 GdkPixmap *p; | |
640 GdkAtom prop, | |
641 type, | |
642 prop2; | |
643 int format; | |
644 gint length; | |
645 guint32 id; | |
646 guchar *data; | |
647 | |
648 prop = gdk_atom_intern("_XROOTPMAP_ID", 1); | |
649 prop2 = gdk_atom_intern("_XROOTCOLOR_PIXEL", 1); | |
650 | |
651 | |
652 if (prop == None && prop2 == None) | |
653 { | |
654 return NULL; | |
655 } | |
656 | |
657 if (prop != None) | |
658 { | |
659 gdk_property_get(get_desktop_window(widget), prop, AnyPropertyType, 0L, | |
660 1L, 0, &type, &format, &length, &data); | |
661 if (type == XA_PIXMAP) | |
662 { | |
1 | 663 id = data[0]; |
664 id += data[1] << 8; | |
665 id += data[2] << 16; | |
666 id += data[3] << 24; | |
12 | 667 p = gdk_pixmap_foreign_new(id); |
668 return p; | |
669 } | |
670 } | |
671 if (prop2 != None) | |
672 { | |
673 | |
1 | 674 /* XGetWindowProperty(Xdisplay, desktop_window, prop2, 0L, 1L, False, AnyPropertyType, |
675 &type, &format, &length, &after, &data);*/ | |
12 | 676 |
1 | 677 /* if (type == XA_CARDINAL) {*/ |
12 | 678 /* |
679 * D_PIXMAP((" Solid color not yet supported.\n")); | |
680 */ | |
681 | |
1 | 682 /* return NULL; |
683 }*/ | |
12 | 684 } |
685 /* | |
686 * D_PIXMAP(("No suitable attribute found.\n")); | |
687 */ | |
688 #endif | |
689 return NULL; | |
1 | 690 } |
691 | |
692 | |
12 | 693 static void clear_focus_area(GtkHtml * html, |
694 gint area_x, | |
695 gint area_y, gint area_width, gint area_height) | |
1 | 696 { |
12 | 697 GtkWidget *widget = GTK_WIDGET(html); |
698 gint x, | |
699 y; | |
700 | |
701 gint ythick = BORDER_WIDTH + widget->style->klass->ythickness; | |
702 gint xthick = BORDER_WIDTH + widget->style->klass->xthickness; | |
703 | |
704 gint width, | |
705 height; | |
706 | |
707 if (html->frozen > 0) | |
708 return; | |
709 | |
710 if (html->transparent) | |
711 { | |
1 | 712 if (html->pm == NULL) |
713 html->pm = get_desktop_pixmap(widget); | |
714 | |
12 | 715 if (html->pm == NULL) |
716 return; | |
717 | |
718 if (html->bg_gc == NULL) | |
719 { | |
1 | 720 GdkGCValues values; |
721 | |
12 | 722 values.tile = html->pm; |
723 values.fill = GDK_TILED; | |
724 | |
725 html->bg_gc = gdk_gc_new_with_values(html->html_area, &values, | |
726 GDK_GC_FILL | GDK_GC_TILE); | |
727 | |
728 } | |
729 | |
730 gdk_window_get_deskrelative_origin(widget->window, &x, &y); | |
1 | 731 |
732 gdk_draw_pixmap(widget->window, html->bg_gc, html->pm, | |
12 | 733 x + area_x, y + area_y, area_x, area_y, area_width, |
734 area_height); | |
735 | |
736 | |
737 } | |
738 else | |
739 { | |
740 gdk_window_get_size(widget->style->bg_pixmap[GTK_STATE_NORMAL], &width, | |
741 &height); | |
742 | |
743 gdk_gc_set_ts_origin(html->bg_gc, | |
744 (-html->xoffset + xthick) % width, | |
745 (-html->yoffset + ythick) % height); | |
746 | |
747 gdk_draw_rectangle(widget->window, html->bg_gc, TRUE, | |
748 area_x, area_y, area_width, area_height); | |
749 } | |
1 | 750 } |
751 | |
12 | 752 static void gtk_html_draw_focus(GtkWidget * widget) |
1 | 753 { |
12 | 754 GtkHtml *html; |
755 gint width, | |
756 height; | |
757 gint x, | |
758 y; | |
759 | |
760 g_return_if_fail(widget != NULL); | |
761 g_return_if_fail(GTK_IS_HTML(widget)); | |
1 | 762 |
763 html = GTK_HTML(widget); | |
764 | |
12 | 765 if (GTK_WIDGET_DRAWABLE(widget)) |
766 { | |
767 gint ythick = widget->style->klass->ythickness; | |
768 gint xthick = widget->style->klass->xthickness; | |
769 gint xextra = BORDER_WIDTH; | |
770 gint yextra = BORDER_WIDTH; | |
771 | |
772 x = 0; | |
773 y = 0; | |
774 width = widget->allocation.width; | |
775 height = widget->allocation.height; | |
776 | |
777 if (GTK_WIDGET_HAS_FOCUS(widget)) | |
778 { | |
779 x += 1; | |
780 y += 1; | |
781 width -= 2; | |
782 height -= 2; | |
783 xextra -= 1; | |
784 yextra -= 1; | |
785 | |
786 gtk_paint_focus(widget->style, widget->window, | |
787 NULL, widget, "text", | |
788 0, 0, | |
789 widget->allocation.width - 1, | |
790 widget->allocation.height - 1); | |
791 } | |
792 | |
793 gtk_paint_shadow(widget->style, widget->window, | |
794 GTK_STATE_NORMAL, GTK_SHADOW_IN, | |
795 NULL, widget, "text", x, y, width, height); | |
796 | |
797 x += xthick; | |
798 y += ythick; | |
799 width -= 2 * xthick; | |
800 height -= 2 * ythick; | |
801 | |
802 | |
803 if (widget->style->bg_pixmap[GTK_STATE_NORMAL] || html->transparent) | |
804 { | |
805 /* | |
806 * top rect | |
807 */ | |
808 clear_focus_area(html, x, y, width, yextra); | |
809 /* | |
810 * left rect | |
811 */ | |
812 clear_focus_area(html, x, y + yextra, | |
813 xextra, y + height - 2 * yextra); | |
814 /* | |
815 * right rect | |
816 */ | |
817 clear_focus_area(html, x + width - xextra, y + yextra, | |
818 xextra, height - 2 * ythick); | |
819 /* | |
820 * bottom rect | |
821 */ | |
822 clear_focus_area(html, x, x + height - yextra, width, yextra); | |
823 } | |
824 } | |
1 | 825 } |
826 | |
12 | 827 static void gtk_html_size_request(GtkWidget * widget, |
828 GtkRequisition * requisition) | |
1 | 829 { |
12 | 830 gint xthickness; |
831 gint ythickness; | |
832 gint char_height; | |
833 gint char_width; | |
834 | |
835 g_return_if_fail(widget != NULL); | |
836 g_return_if_fail(GTK_IS_HTML(widget)); | |
837 g_return_if_fail(requisition != NULL); | |
838 | |
839 xthickness = widget->style->klass->xthickness + BORDER_WIDTH; | |
840 ythickness = widget->style->klass->ythickness + BORDER_WIDTH; | |
841 | |
842 char_height = MIN_HTML_HEIGHT_LINES * (widget->style->font->ascent + | |
843 widget->style->font->descent); | |
844 | |
845 char_width = MIN_HTML_WIDTH_LINES * (gdk_text_width(widget->style->font, | |
846 "ABCDEFGHIJKLMNOPQRSTUVWXYZ", | |
847 26) / 26); | |
848 | |
849 requisition->width = char_width + xthickness * 2; | |
850 requisition->height = char_height + ythickness * 2; | |
1 | 851 } |
852 | |
12 | 853 static void gtk_html_size_allocate(GtkWidget * widget, |
854 GtkAllocation * allocation) | |
1 | 855 { |
12 | 856 GtkHtml *html; |
857 | |
858 g_return_if_fail(widget != NULL); | |
859 g_return_if_fail(GTK_IS_HTML(widget)); | |
860 g_return_if_fail(allocation != NULL); | |
861 | |
862 html = GTK_HTML(widget); | |
863 | |
864 widget->allocation = *allocation; | |
865 if (GTK_WIDGET_REALIZED(widget)) | |
866 { | |
867 gdk_window_move_resize(widget->window, | |
868 allocation->x, allocation->y, | |
869 allocation->width, allocation->height); | |
870 | |
871 gdk_window_move_resize(html->html_area, | |
872 widget->style->klass->xthickness + BORDER_WIDTH, | |
873 widget->style->klass->ythickness + BORDER_WIDTH, | |
874 MAX(1, (gint) widget->allocation.width - | |
875 (gint) (widget->style->klass->xthickness + | |
876 (gint) BORDER_WIDTH) * 2), | |
877 MAX(1, (gint) widget->allocation.height - | |
878 (gint) (widget->style->klass->ythickness + | |
879 (gint) BORDER_WIDTH) * 2)); | |
880 | |
881 resize_html(html); | |
882 } | |
883 } | |
884 | |
885 static void gtk_html_draw(GtkWidget * widget, GdkRectangle * area) | |
886 { | |
887 g_return_if_fail(widget != NULL); | |
888 g_return_if_fail(GTK_IS_HTML(widget)); | |
889 g_return_if_fail(area != NULL); | |
890 | |
891 if (GTK_WIDGET_DRAWABLE(widget)) | |
892 { | |
893 expose_html(GTK_HTML(widget), area, TRUE); | |
894 gtk_widget_draw_focus(widget); | |
895 } | |
896 } | |
897 | |
898 | |
899 static gint gtk_html_expose(GtkWidget * widget, GdkEventExpose * event) | |
900 { | |
901 GtkHtml *html; | |
902 | |
903 g_return_val_if_fail(widget != NULL, FALSE); | |
904 g_return_val_if_fail(GTK_IS_HTML(widget), FALSE); | |
905 g_return_val_if_fail(event != NULL, FALSE); | |
906 | |
907 html = GTK_HTML(widget); | |
908 | |
909 if (event->window == html->html_area) | |
910 { | |
911 expose_html(html, &event->area, TRUE); | |
912 } | |
913 else if (event->count == 0) | |
914 { | |
915 gtk_widget_draw_focus(widget); | |
916 } | |
917 | |
918 return FALSE; | |
1 | 919 |
920 } | |
921 | |
922 | |
12 | 923 static gint gtk_html_selection_clear(GtkWidget * widget, |
924 GdkEventSelection * event) | |
1 | 925 { |
12 | 926 GtkHtml *html; |
927 | |
928 g_return_val_if_fail(widget != NULL, FALSE); | |
929 g_return_val_if_fail(GTK_IS_HTML(widget), FALSE); | |
930 g_return_val_if_fail(event != NULL, FALSE); | |
931 | |
932 /* | |
933 * Let the selection handling code know that the selection | |
934 * * has been changed, since we've overriden the default handler | |
935 */ | |
936 if (!gtk_selection_clear(widget, event)) | |
937 return FALSE; | |
938 | |
939 html = GTK_HTML(widget); | |
940 | |
941 if (event->selection == GDK_SELECTION_PRIMARY) | |
942 { | |
943 if (html->selected_text) | |
944 { | |
945 GList *hbits = html->html_bits; | |
946 GtkHtmlBit *hb; | |
947 | |
1 | 948 g_free(html->selected_text); |
949 html->selected_text = NULL; | |
950 html->start_sel = NULL; | |
951 html->end_sel = NULL; | |
952 html->num_start = 0; | |
953 html->num_end = 0; | |
12 | 954 while (hbits) |
955 { | |
956 hb = (GtkHtmlBit *) hbits->data; | |
1 | 957 if (hb->was_selected) |
958 gtk_html_draw_bit(html, hb, 1); | |
959 hbits = hbits->prev; | |
960 } | |
961 hbits = g_list_last(html->html_bits); | |
962 } | |
12 | 963 } |
964 | |
965 return TRUE; | |
1 | 966 } |
967 | |
968 | |
969 | |
12 | 970 static void gtk_html_selection_get(GtkWidget * widget, |
971 GtkSelectionData * selection_data, | |
972 guint sel_info, guint32 time) | |
1 | 973 { |
974 gchar *str; | |
12 | 975 gint len; |
976 GtkHtml *html; | |
977 | |
978 g_return_if_fail(widget != NULL); | |
979 g_return_if_fail(GTK_IS_HTML(widget)); | |
980 | |
981 html = GTK_HTML(widget); | |
982 | |
983 | |
1 | 984 if (selection_data->selection != GDK_SELECTION_PRIMARY) |
985 return; | |
986 | |
987 str = html->selected_text; | |
988 | |
989 if (!str) | |
990 return; | |
12 | 991 |
1 | 992 len = strlen(str); |
993 | |
12 | 994 if (sel_info == TARGET_STRING) |
995 { | |
1 | 996 gtk_selection_data_set(selection_data, |
12 | 997 GDK_SELECTION_TYPE_STRING, |
998 8 * sizeof(gchar), (guchar *) str, len); | |
999 } | |
1000 else if ((sel_info == TARGET_TEXT) || (sel_info == TARGET_COMPOUND_TEXT)) | |
1001 { | |
1 | 1002 guchar *text; |
1003 GdkAtom encoding; | |
1004 gint format; | |
1005 gint new_length; | |
1006 | |
12 | 1007 gdk_string_to_compound_text(str, &encoding, &format, &text, |
1008 &new_length); | |
1009 gtk_selection_data_set(selection_data, encoding, format, text, | |
1010 new_length); | |
1011 gdk_free_compound_text(text); | |
1 | 1012 } |
1013 | |
1014 | |
1015 | |
1016 } | |
1017 | |
12 | 1018 static void do_select(GtkHtml * html, int x, int y) |
1 | 1019 { |
1020 GList *hbits = g_list_last(html->html_bits); | |
12 | 1021 int epos, |
1022 spos; | |
1 | 1023 GtkHtmlBit *hb; |
12 | 1024 |
1 | 1025 if (!hbits) |
1026 return; | |
12 | 1027 |
1028 hb = (GtkHtmlBit *) hbits->data; | |
1029 | |
1030 while (hbits) | |
1031 { | |
1032 hb = (GtkHtmlBit *) hbits->data; | |
1033 if (hb->type == HTML_BIT_TEXT) | |
1 | 1034 break; |
1035 hbits = hbits->prev; | |
12 | 1036 } |
1037 | |
1 | 1038 if (!hb) |
12 | 1039 return; |
1040 | |
1041 | |
1042 if (y > hb->y) | |
1043 { | |
1 | 1044 html->num_end = strlen(hb->text) - 1; |
1045 html->end_sel = hb; | |
12 | 1046 } |
1047 else if (y < 0) | |
1048 { | |
1 | 1049 html->num_end = 0; |
12 | 1050 html->end_sel = (GtkHtmlBit *) html->html_bits->data; |
1051 } | |
1052 else | |
1053 while (hbits) | |
1054 { | |
1055 hb = (GtkHtmlBit *) hbits->data; | |
1056 if ((y < hb->y && y > (hb->y - hb->height)) && | |
1057 (x > hb->x + hb->width)) | |
1058 { | |
1059 if (hb->type != HTML_BIT_TEXT) | |
1060 { | |
1061 html->num_end = 0; | |
1062 html->end_sel = hb; | |
1063 break; | |
1064 } | |
1065 | |
1066 html->num_end = strlen(hb->text) - 1; | |
1 | 1067 html->end_sel = hb; |
1068 break; | |
1069 } | |
12 | 1070 else if ((x > hb->x && x < (hb->x + hb->width)) && |
1071 (y < hb->y && y > (hb->y - hb->height))) | |
1072 { | |
1073 int i, | |
1074 len; | |
1075 int w = x - hb->x; | |
1076 | |
1077 if (hb->type != HTML_BIT_TEXT) | |
1078 { | |
1079 html->num_end = 0; | |
1 | 1080 html->end_sel = hb; |
1081 break; | |
1082 } | |
12 | 1083 |
1084 len = strlen(hb->text); | |
1085 | |
1086 for (i = 1; i <= len; i++) | |
1087 { | |
1088 if (gdk_text_measure(hb->font, hb->text, i) > w) | |
1089 { | |
1090 html->num_end = i - 1; | |
1091 html->end_sel = hb; | |
1092 break; | |
1093 } | |
1094 } | |
1095 break; | |
1 | 1096 } |
12 | 1097 hbits = hbits->prev; |
1 | 1098 } |
1099 | |
1100 if (html->end_sel == NULL) | |
1101 return; | |
12 | 1102 if (html->start_sel == NULL) |
1103 { | |
1 | 1104 html->start_sel = html->end_sel; |
1105 html->num_start = html->num_end; | |
1106 } | |
12 | 1107 |
1 | 1108 epos = g_list_index(html->html_bits, html->end_sel); |
1109 spos = g_list_index(html->html_bits, html->start_sel); | |
1110 g_free(html->selected_text); | |
1111 html->selected_text = NULL; | |
1112 | |
12 | 1113 if (epos == spos) |
1114 { | |
1 | 1115 char *str; |
12 | 1116 if (html->start_sel->type != HTML_BIT_TEXT) |
1117 { | |
1 | 1118 html->selected_text = NULL; |
1119 return; | |
1120 } | |
12 | 1121 if (html->num_end == html->num_start) |
1122 { | |
1 | 1123 str = g_malloc(2); |
12 | 1124 if (strlen(html->start_sel->text)) |
1 | 1125 str[0] = html->start_sel->text[html->num_end]; |
1126 else | |
12 | 1127 str[0] = 0; |
1 | 1128 str[1] = 0; |
1129 gtk_html_draw_bit(html, html->start_sel, 0); | |
1130 html->selected_text = str; | |
12 | 1131 } |
1132 else | |
1133 { | |
79 | 1134 size_t st, |
12 | 1135 en; |
1 | 1136 char *str; |
12 | 1137 if (html->num_end > html->num_start) |
1138 { | |
1 | 1139 en = html->num_end; |
1140 st = html->num_start; | |
12 | 1141 } |
1142 else | |
1143 { | |
1 | 1144 en = html->num_start; |
1145 st = html->num_end; | |
1146 } | |
1147 | |
1148 str = g_malloc(en - st + 2); | |
1149 strncpy(str, html->start_sel->text + st, (en - st + 1)); | |
1150 str[en - st + 1] = 0; | |
12 | 1151 gtk_html_draw_bit(html, html->start_sel, 0); |
1 | 1152 html->selected_text = str; |
12 | 1153 |
1 | 1154 } |
12 | 1155 } |
1156 else | |
1157 { | |
1158 GtkHtmlBit *shb, | |
1159 *ehb; | |
79 | 1160 size_t en, |
12 | 1161 st; |
1162 int len, | |
1163 nlen; | |
1 | 1164 char *str; |
12 | 1165 if (epos > spos) |
1166 { | |
1 | 1167 shb = html->start_sel; |
1168 ehb = html->end_sel; | |
1169 en = html->num_end; | |
1170 st = html->num_start; | |
12 | 1171 } |
1172 else | |
1173 { | |
1 | 1174 shb = html->end_sel; |
1175 ehb = html->start_sel; | |
1176 en = html->num_start; | |
1177 st = html->num_end; | |
1178 } | |
12 | 1179 |
1 | 1180 hbits = g_list_find(html->html_bits, shb); |
1181 | |
1182 if (!hbits) | |
1183 return; | |
12 | 1184 |
1185 if (shb->type == HTML_BIT_TEXT) | |
1186 { | |
1 | 1187 len = strlen(shb->text) - st + 1; |
1188 str = g_malloc(len); | |
1189 strcpy(str, shb->text + st); | |
1190 str[len - 1] = 0; | |
1191 gtk_html_draw_bit(html, shb, 0); | |
12 | 1192 if (shb->newline) |
1193 { | |
1194 len += 1; | |
1 | 1195 str = g_realloc(str, len); |
1196 str[len - 2] = '\n'; | |
1197 str[len - 1] = 0; | |
1198 } | |
12 | 1199 } |
1200 else | |
1201 { | |
1 | 1202 len = 1; |
1203 str = g_malloc(1); | |
1204 str[0] = 0; | |
1205 } | |
12 | 1206 if (hbits->next == NULL) |
1207 { | |
1 | 1208 html->selected_text = str; |
1209 return; | |
1210 } | |
1211 | |
12 | 1212 |
1213 hbits = hbits->next; | |
1214 while (1) | |
1215 { /* | |
1216 * Yah I know is dangerous :P | |
1217 */ | |
1218 hb = (GtkHtmlBit *) hbits->data; | |
1219 if (hb->type != HTML_BIT_TEXT) | |
1220 { | |
1 | 1221 if (hb == ehb) |
1222 break; | |
1223 hbits = hbits->next; | |
1224 continue; | |
1225 } | |
12 | 1226 if (hb != ehb) |
1227 { | |
1 | 1228 nlen = len + strlen(hb->text); |
1229 str = g_realloc(str, nlen); | |
1230 strcpy(str + (len - 1), hb->text); | |
1231 len = nlen; | |
1232 str[len - 1] = 0; | |
1233 gtk_html_draw_bit(html, hb, 0); | |
12 | 1234 if (hb->newline) |
1235 { | |
1236 len += 1; | |
1 | 1237 str = g_realloc(str, len); |
1238 str[len - 2] = '\n'; | |
1239 str[len - 1] = 0; | |
1240 } | |
12 | 1241 } |
1242 else | |
1243 { | |
1 | 1244 nlen = len + en + 1; |
1245 str = g_realloc(str, nlen); | |
1246 strncpy(str + (len - 1), hb->text, en + 1); | |
1247 len = nlen; | |
1248 str[len - 1] = 0; | |
12 | 1249 |
1 | 1250 gtk_html_draw_bit(html, hb, 0); |
12 | 1251 if (hb->newline && en == strlen(hb->text)) |
1252 { | |
1253 len += 1; | |
1 | 1254 str = g_realloc(str, len); |
1255 str[len - 2] = '\n'; | |
1256 str[len - 1] = 0; | |
1257 } | |
1258 break; | |
1259 } | |
1260 hbits = hbits->next; | |
1261 } | |
1262 html->selected_text = str; | |
1263 } | |
1264 | |
1265 } | |
1266 | |
12 | 1267 static gint scroll_timeout(GtkHtml * html) |
1 | 1268 { |
12 | 1269 GdkEventMotion event; |
1270 gint x, | |
1271 y; | |
1272 GdkModifierType mask; | |
1 | 1273 |
1274 html->timer = 0; | |
12 | 1275 gdk_window_get_pointer(html->html_area, &x, &y, &mask); |
1276 | |
1 | 1277 if (mask & GDK_BUTTON1_MASK) |
1278 { | |
1279 event.is_hint = 0; | |
1280 event.x = x; | |
1281 event.y = y; | |
1282 event.state = mask; | |
1283 | |
12 | 1284 gtk_html_motion_notify(GTK_WIDGET(html), &event); |
1 | 1285 } |
1286 | |
1287 return FALSE; | |
1288 | |
1289 } | |
1290 | |
1291 | |
12 | 1292 static gint gtk_html_tooltip_paint_window(GtkHtml * html) |
1 | 1293 { |
1294 GtkStyle *style; | |
12 | 1295 gint y, |
1296 baseline_skip, | |
1297 gap; | |
1 | 1298 |
1299 style = html->tooltip_window->style; | |
1300 | |
1301 gap = (style->font->ascent + style->font->descent) / 4; | |
1302 if (gap < 2) | |
1303 gap = 2; | |
1304 baseline_skip = style->font->ascent + style->font->descent + gap; | |
1305 | |
1306 if (!html->tooltip_hb) | |
1307 return FALSE; | |
1308 | |
1309 gtk_paint_flat_box(style, html->tooltip_window->window, | |
12 | 1310 GTK_STATE_NORMAL, GTK_SHADOW_OUT, |
1311 NULL, GTK_WIDGET(html->tooltip_window), "tooltip", | |
1312 0, 0, -1, -1); | |
1 | 1313 |
1314 y = style->font->ascent + 4; | |
1315 | |
12 | 1316 gtk_paint_string(style, html->tooltip_window->window, |
1317 GTK_STATE_NORMAL, | |
1318 NULL, GTK_WIDGET(html->tooltip_window), "tooltip", | |
1319 4, y, "HTML Link:"); | |
1 | 1320 y += baseline_skip; |
12 | 1321 gtk_paint_string(style, html->tooltip_window->window, |
1322 GTK_STATE_NORMAL, | |
1323 NULL, GTK_WIDGET(html->tooltip_window), "tooltip", | |
1324 4, y, html->tooltip_hb->url); | |
1325 | |
1 | 1326 return FALSE; |
1327 | |
1328 | |
1329 } | |
1330 | |
1331 static gint gtk_html_tooltip_timeout(gpointer data) | |
1332 { | |
12 | 1333 GtkHtml *html = (GtkHtml *) data; |
1334 | |
1335 | |
1 | 1336 GDK_THREADS_ENTER(); |
1337 | |
12 | 1338 if (html->tooltip_hb && GTK_WIDGET_DRAWABLE(GTK_WIDGET(html))) |
1339 { | |
1 | 1340 GtkWidget *widget; |
1341 GtkStyle *style; | |
12 | 1342 gint gap, |
1343 x, | |
1344 y, | |
1345 w, | |
1346 h, | |
1347 scr_w, | |
1348 scr_h, | |
1349 baseline_skip; | |
1 | 1350 |
1351 if (html->tooltip_window) | |
1352 gtk_widget_destroy(html->tooltip_window); | |
12 | 1353 |
1354 html->tooltip_window = gtk_window_new(GTK_WINDOW_POPUP); | |
1355 gtk_widget_set_app_paintable(html->tooltip_window, TRUE); | |
1356 gtk_window_set_policy(GTK_WINDOW(html->tooltip_window), FALSE, FALSE, | |
1357 TRUE); | |
1358 gtk_widget_set_name(html->tooltip_window, "gtk-tooltips"); | |
1359 gtk_signal_connect_object(GTK_OBJECT(html->tooltip_window), | |
1360 "expose_event", | |
1361 GTK_SIGNAL_FUNC | |
1362 (gtk_html_tooltip_paint_window), | |
1363 GTK_OBJECT(html)); | |
1364 gtk_signal_connect_object(GTK_OBJECT(html->tooltip_window), "draw", | |
1365 GTK_SIGNAL_FUNC | |
1366 (gtk_html_tooltip_paint_window), | |
1367 GTK_OBJECT(html)); | |
1368 | |
1369 gtk_widget_ensure_style(html->tooltip_window); | |
1 | 1370 style = html->tooltip_window->style; |
12 | 1371 |
1 | 1372 widget = GTK_WIDGET(html); |
1373 | |
12 | 1374 scr_w = gdk_screen_width(); |
1375 scr_h = gdk_screen_height(); | |
1 | 1376 |
1377 gap = (style->font->ascent + style->font->descent) / 4; | |
1378 if (gap < 2) | |
1379 gap = 2; | |
1380 baseline_skip = style->font->ascent + style->font->descent + gap; | |
1381 | |
353
a4df8f1cc61a
[gaim-migrate @ 363]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
349
diff
changeset
|
1382 w = 8 + MAX(gdk_string_width(style->font, _("HTML Link:")), |
12 | 1383 gdk_string_width(style->font, html->tooltip_hb->url)); |
1384 ; | |
1 | 1385 h = 8 - gap; |
12 | 1386 h += (baseline_skip * 2); |
1387 | |
1388 gdk_window_get_pointer(NULL, &x, &y, NULL); | |
1389 /* | |
1390 * gdk_window_get_origin (widget->window, NULL, &y); | |
1391 */ | |
1392 if (GTK_WIDGET_NO_WINDOW(widget)) | |
1 | 1393 y += widget->allocation.y; |
1394 | |
1395 x -= ((w >> 1) + 4); | |
1396 | |
1397 if ((x + w) > scr_w) | |
1398 x -= (x + w) - scr_w; | |
1399 else if (x < 0) | |
1400 x = 0; | |
1401 | |
1402 if ((y + h + 4) > scr_h) | |
12 | 1403 y = |
1404 y - html->tooltip_hb->font->ascent + | |
1405 html->tooltip_hb->font->descent; | |
1 | 1406 else |
12 | 1407 y = |
1408 y + html->tooltip_hb->font->ascent + | |
1409 html->tooltip_hb->font->descent; | |
1410 | |
1411 gtk_widget_set_usize(html->tooltip_window, w, h); | |
1412 gtk_widget_popup(html->tooltip_window, x, y); | |
1413 | |
1 | 1414 } |
1415 | |
1416 html->tooltip_timer = -1; | |
12 | 1417 |
1 | 1418 GDK_THREADS_LEAVE(); |
1419 | |
1420 return FALSE; | |
1421 } | |
1422 | |
1423 | |
12 | 1424 static gint gtk_html_leave_notify(GtkWidget * widget, GdkEventCrossing * event) |
1 | 1425 { |
12 | 1426 GtkHtml *html; |
1427 | |
1428 html = GTK_HTML(widget); | |
1429 | |
1430 if (html->tooltip_timer != -1) | |
1431 gtk_timeout_remove(html->tooltip_timer); | |
1432 if (html->tooltip_window) | |
1433 { | |
1434 gtk_widget_destroy(html->tooltip_window); | |
1435 html->tooltip_window = NULL; | |
1436 } | |
1437 | |
1438 | |
1439 html->tooltip_hb = NULL; | |
1440 return TRUE; | |
1 | 1441 } |
1442 | |
1443 | |
12 | 1444 static gint gtk_html_motion_notify(GtkWidget * widget, GdkEventMotion * event) |
1 | 1445 { |
12 | 1446 int x, |
1447 y; | |
1448 gint width, | |
1449 height; | |
1450 GdkModifierType state; | |
1451 int realx, | |
1452 realy; | |
1453 GtkHtml *html = GTK_HTML(widget); | |
1454 | |
1455 if (event->is_hint) | |
1456 gdk_window_get_pointer(event->window, &x, &y, &state); | |
1457 else | |
1458 { | |
1459 x = event->x; | |
1460 y = event->y; | |
1461 state = event->state; | |
1462 } | |
1463 | |
1464 gdk_window_get_size(html->html_area, &width, &height); | |
1465 | |
1 | 1466 realx = x; |
1467 realy = y + html->yoffset; | |
1468 | |
1469 | |
12 | 1470 if (state & GDK_BUTTON1_MASK) |
1471 { | |
1472 if (realx != html->start_sel_x || realy != html->start_sel_y) | |
1473 { | |
1 | 1474 char *tmp = NULL; |
1475 | |
12 | 1476 if (y < 0 || y > height) |
1477 { | |
1 | 1478 int diff; |
12 | 1479 if (html->timer == 0) |
1480 { | |
1 | 1481 html->timer = gtk_timeout_add(100, |
12 | 1482 (GtkFunction) scroll_timeout, |
1483 html); | |
1 | 1484 if (y < 0) |
1485 diff = y / 2; | |
1486 else | |
1487 diff = (y - height) / 2; | |
1488 | |
1489 if (html->vadj->value + diff > | |
12 | 1490 html->vadj->upper - height + 20) |
1 | 1491 gtk_adjustment_set_value(html->vadj, |
12 | 1492 html->vadj->upper - height + |
1493 20); | |
1 | 1494 else |
1495 gtk_adjustment_set_value(html->vadj, | |
12 | 1496 html->vadj->value + diff); |
1 | 1497 |
1498 } | |
1499 } | |
12 | 1500 |
1 | 1501 if (html->selected_text != NULL) |
1502 tmp = g_strdup(html->selected_text); | |
1503 do_select(html, realx, realy); | |
12 | 1504 if (tmp) |
1505 { | |
1506 if (!html->selected_text || strcmp(tmp, html->selected_text)) | |
1507 { | |
1 | 1508 GtkHtmlBit *hb; |
1509 GList *hbits = html->html_bits; | |
12 | 1510 while (hbits) |
1511 { | |
1512 hb = (GtkHtmlBit *) hbits->data; | |
1 | 1513 if (hb->was_selected) |
1514 gtk_html_draw_bit(html, hb, 0); | |
1515 hbits = hbits->next; | |
1516 } | |
1517 } | |
1518 g_free(tmp); | |
1519 } | |
1520 } | |
12 | 1521 } |
1522 else | |
1523 { | |
1 | 1524 GtkHtmlBit *hb; |
1525 GList *urls; | |
1526 | |
1527 urls = html->urls; | |
12 | 1528 while (urls) |
1529 { | |
1530 hb = (GtkHtmlBit *) urls->data; | |
1 | 1531 if ((realx > hb->x && realx < (hb->x + hb->width)) && |
12 | 1532 (realy < hb->y && realy > (hb->y - hb->height))) |
1533 { | |
26 | 1534 GdkCursor *cursor = NULL; |
1535 | |
12 | 1536 if (html->tooltip_hb != hb) |
1537 { | |
1 | 1538 html->tooltip_hb = hb; |
1539 if (html->tooltip_timer != -1) | |
1540 gtk_timeout_remove(html->tooltip_timer); | |
12 | 1541 if (html->tooltip_window) |
1542 { | |
1 | 1543 gtk_widget_destroy(html->tooltip_window); |
1544 html->tooltip_window = NULL; | |
1545 } | |
12 | 1546 html->tooltip_timer = |
1547 gtk_timeout_add(HTML_TOOLTIP_DELAY, | |
1548 gtk_html_tooltip_timeout, html); | |
1 | 1549 } |
26 | 1550 |
1551 cursor = gdk_cursor_new(GDK_HAND2); | |
1552 gdk_window_set_cursor(html->html_area, cursor); | |
1553 gdk_cursor_destroy(cursor); | |
1554 | |
1 | 1555 return TRUE; |
1556 } | |
12 | 1557 urls = urls->next; |
1 | 1558 } |
1559 if (html->tooltip_timer != -1) | |
1560 gtk_timeout_remove(html->tooltip_timer); | |
12 | 1561 if (html->tooltip_window) |
1562 { | |
1 | 1563 gtk_widget_destroy(html->tooltip_window); |
1564 html->tooltip_window = NULL; | |
1565 } | |
12 | 1566 |
1567 | |
1568 html->tooltip_hb = NULL; | |
1 | 1569 gdk_window_set_cursor(html->html_area, NULL); |
1570 | |
1571 | |
1572 } | |
1573 | |
1574 return TRUE; | |
1575 } | |
1576 | |
12 | 1577 static gint gtk_html_button_release(GtkWidget * widget, GdkEventButton * event) |
1 | 1578 { |
12 | 1579 GtkHtml *html; |
1580 | |
1581 html = GTK_HTML(widget); | |
1582 | |
1583 if (html->frozen > 0) | |
1584 return TRUE; | |
1585 | |
1586 if (event->button == 1) | |
1587 { | |
1588 int realx, | |
1589 realy; | |
1590 GtkHtmlBit *hb; | |
1591 GList *urls = html->urls; | |
1592 | |
1593 realx = event->x; | |
1594 realy = event->y + html->yoffset; | |
1595 if (realx != html->start_sel_x || realy != html->start_sel_y) | |
1596 { | |
1597 if (gtk_selection_owner_set(widget, | |
1598 GDK_SELECTION_PRIMARY, event->time)) | |
1599 { | |
1600 } | |
1601 else | |
1602 { | |
1603 } | |
1604 } | |
1605 else | |
1606 { | |
1607 if (gdk_selection_owner_get(GDK_SELECTION_PRIMARY) == | |
1608 widget->window) | |
1 | 1609 gtk_selection_owner_set(NULL, GDK_SELECTION_PRIMARY, |
12 | 1610 event->time); |
1611 | |
1612 | |
1613 while (urls) | |
1614 { | |
1615 void open_url_nw(GtkWidget * w, char *url); | |
1616 hb = (GtkHtmlBit *) urls->data; | |
1 | 1617 if ((realx > hb->x && realx < (hb->x + hb->width)) && |
12 | 1618 (realy < hb->y && realy > (hb->y - hb->height))) |
1619 { | |
1620 open_url_nw(NULL, hb->url); | |
1621 // else | |
1622 // open_url(NULL, hb->url); | |
1 | 1623 break; |
1624 } | |
1625 urls = urls->next; | |
1626 } | |
1627 } | |
1628 } | |
1629 return TRUE; | |
1630 } | |
1631 | |
1632 | |
1633 | |
12 | 1634 static gint gtk_html_button_press(GtkWidget * widget, GdkEventButton * event) |
1 | 1635 { |
12 | 1636 GtkHtml *html; |
1637 gfloat value; | |
1638 | |
1639 | |
1640 html = GTK_HTML(widget); | |
1641 value = html->vadj->value; | |
1642 | |
1643 if (html->frozen > 0) | |
1644 return TRUE; | |
1645 | |
1646 if (event->button == 4) | |
1647 { | |
1 | 1648 value -= html->vadj->step_increment; |
1649 if (value < html->vadj->lower) | |
1650 value = html->vadj->lower; | |
12 | 1651 gtk_adjustment_set_value(html->vadj, value); |
1652 } | |
1653 else if (event->button == 5) | |
1654 { | |
1 | 1655 value += html->vadj->step_increment; |
1656 if (value > html->vadj->upper) | |
1657 value = html->vadj->upper; | |
12 | 1658 gtk_adjustment_set_value(html->vadj, value); |
1659 | |
1660 } | |
1661 else if (event->button == 1) | |
1662 { | |
1663 GList *hbits = g_list_last(html->html_bits); | |
1664 int realx, | |
1665 realy; | |
1 | 1666 GtkHtmlBit *hb; |
1667 | |
1668 realx = event->x; | |
1669 realy = event->y + html->yoffset; | |
1670 | |
1671 html->start_sel_x = realx; | |
1672 html->start_sel_y = realy; | |
1673 | |
1674 if (!hbits) | |
1675 return TRUE; | |
1676 | |
12 | 1677 if (html->selected_text) |
1678 { | |
1 | 1679 g_free(html->selected_text); |
1680 html->selected_text = NULL; | |
1681 html->start_sel = NULL; | |
1682 html->end_sel = NULL; | |
1683 html->num_start = 0; | |
1684 html->num_end = 0; | |
12 | 1685 while (hbits) |
1686 { | |
1687 hb = (GtkHtmlBit *) hbits->data; | |
1 | 1688 if (hb->was_selected) |
1689 gtk_html_draw_bit(html, hb, 1); | |
1690 hbits = hbits->prev; | |
1691 } | |
1692 hbits = g_list_last(html->html_bits); | |
1693 } | |
1694 | |
12 | 1695 hb = (GtkHtmlBit *) hbits->data; |
1696 if (realy > hb->y) | |
1697 { | |
1 | 1698 if (hb->text) |
1699 html->num_start = strlen(hb->text) - 1; | |
1700 else | |
12 | 1701 html->num_start = 0; |
1 | 1702 html->start_sel = hb; |
12 | 1703 } |
1704 else | |
1705 while (hbits) | |
1706 { | |
1707 hb = (GtkHtmlBit *) hbits->data; | |
1708 if ((realy < hb->y && realy > (hb->y - hb->height)) && | |
1709 (realx > hb->x + hb->width)) | |
1710 { | |
1711 if (hb->type != HTML_BIT_TEXT) | |
1712 { | |
1713 html->num_end = 0; | |
1714 html->end_sel = hb; | |
1715 break; | |
1716 } | |
1717 | |
1718 if (hb->text) | |
1719 html->num_start = strlen(hb->text) - 1; | |
1720 else | |
1721 html->num_start = 0; | |
1722 | |
1723 html->start_sel = hb; | |
1 | 1724 break; |
1725 } | |
12 | 1726 else if ((realx > hb->x && realx < (hb->x + hb->width)) && |
1727 (realy < hb->y && realy > (hb->y - hb->height))) | |
1728 { | |
1729 int i, | |
1730 len; | |
1731 int w = realx - hb->x; | |
1732 | |
1733 if (hb->type != HTML_BIT_TEXT) | |
1734 { | |
1735 html->num_end = 0; | |
1736 html->end_sel = hb; | |
1737 break; | |
1738 } | |
1739 | |
1740 if (hb->text) | |
1741 len = strlen(hb->text); | |
1742 else | |
1743 len = 0; | |
1744 | |
1745 for (i = 1; i <= len; i++) | |
1746 { | |
1747 if (gdk_text_measure(hb->font, hb->text, i) > w) | |
1748 { | |
1749 html->num_start = i - 1; | |
1750 html->start_sel = hb; | |
1751 break; | |
1752 } | |
1753 } | |
1 | 1754 break; |
1755 } | |
12 | 1756 hbits = hbits->prev; |
1 | 1757 } |
12 | 1758 } |
1759 else if (event->button == 3 && event->type == GDK_BUTTON_PRESS) | |
1760 { | |
1 | 1761 GtkHtmlBit *hb = NULL; |
12 | 1762 int realx, |
1763 realy; | |
1764 GList *urls; | |
1765 | |
1 | 1766 realx = event->x; |
1767 realy = event->y + html->yoffset; | |
12 | 1768 |
1 | 1769 urls = html->urls; |
12 | 1770 while (urls) |
1771 { | |
1772 hb = (GtkHtmlBit *) urls->data; | |
1 | 1773 if ((realx > hb->x && realx < (hb->x + hb->width)) && |
12 | 1774 (realy < hb->y && realy > (hb->y - hb->height))) |
1775 { | |
1 | 1776 break; |
1777 } | |
12 | 1778 urls = urls->next; |
1 | 1779 hb = NULL; |
1780 } | |
12 | 1781 |
1782 if (hb != NULL) | |
1783 { | |
69 | 1784 |
1785 GtkWidget *menu, *button; | |
1786 | |
1787 menu = gtk_menu_new(); | |
1788 | |
1789 if (web_browser == BROWSER_NETSCAPE) { | |
1790 | |
353
a4df8f1cc61a
[gaim-migrate @ 363]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
349
diff
changeset
|
1791 button = gtk_menu_item_new_with_label(_("Open URL in existing window")); |
69 | 1792 gtk_signal_connect(GTK_OBJECT(button), "activate", |
1793 GTK_SIGNAL_FUNC(open_url), hb->url); | |
1794 gtk_menu_append(GTK_MENU(menu), button); | |
1795 gtk_widget_show(button); | |
1796 | |
1797 } | |
1798 | |
1799 | |
353
a4df8f1cc61a
[gaim-migrate @ 363]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
349
diff
changeset
|
1800 button = gtk_menu_item_new_with_label(_("Open URL in new window")); |
69 | 1801 gtk_signal_connect(GTK_OBJECT(button), "activate", |
1802 GTK_SIGNAL_FUNC(open_url_nw), hb->url); | |
1803 gtk_menu_append(GTK_MENU(menu), button); | |
1804 gtk_widget_show(button); | |
1805 | |
1806 if (web_browser == BROWSER_NETSCAPE) { | |
1807 | |
353
a4df8f1cc61a
[gaim-migrate @ 363]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
349
diff
changeset
|
1808 button = gtk_menu_item_new_with_label(_("Add URL as bookmark")); |
69 | 1809 gtk_signal_connect(GTK_OBJECT(button), "activate", |
1810 GTK_SIGNAL_FUNC(add_bookmark), hb->url); | |
1811 gtk_menu_append(GTK_MENU(menu), button); | |
1812 gtk_widget_show(button); | |
1813 | |
1814 } | |
1815 | |
1816 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, | |
1817 event->button, event->time); | |
1818 | |
12 | 1819 } |
1 | 1820 } |
12 | 1821 |
1 | 1822 return TRUE; |
1823 } | |
1824 | |
1825 | |
12 | 1826 static void gtk_html_draw_bit(GtkHtml * html, GtkHtmlBit * hb, int redraw) |
1 | 1827 { |
12 | 1828 int mypos, |
1829 epos, | |
1830 spos; | |
1831 GdkGC *gc = html->gc; | |
1 | 1832 int shift; |
12 | 1833 GtkStateType selected_state; |
1834 GtkWidget *widget = GTK_WIDGET(html); | |
1 | 1835 GdkRectangle area; |
1836 | |
1837 if (html->frozen > 0) | |
1838 return; | |
1839 | |
12 | 1840 if (hb->type == HTML_BIT_TEXT) |
1841 { | |
1 | 1842 |
716 | 1843 if (!(hb->text)) |
1 | 1844 return; |
720
8b3412f3ac2a
[gaim-migrate @ 730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
716
diff
changeset
|
1845 /* this is possible, don't comment it out >:P */ |
8b3412f3ac2a
[gaim-migrate @ 730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
716
diff
changeset
|
1846 if (!strlen(hb->text)) |
8b3412f3ac2a
[gaim-migrate @ 730]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
716
diff
changeset
|
1847 return; |
12 | 1848 |
1 | 1849 mypos = g_list_index(html->html_bits, hb); |
1850 epos = g_list_index(html->html_bits, html->end_sel); | |
1851 spos = g_list_index(html->html_bits, html->start_sel); | |
1852 | |
12 | 1853 if (((html->end_sel == NULL) || (html->start_sel == NULL)) || |
1854 ((epos < mypos) && (spos < mypos)) || | |
1855 ((epos > mypos) && (spos > mypos))) | |
1856 { | |
1857 selected_state = GTK_STATE_NORMAL; | |
1858 } | |
1859 else | |
1860 { | |
1 | 1861 selected_state = GTK_STATE_SELECTED; |
1862 } | |
1863 | |
1864 | |
1865 gdk_text_extents(hb->font, hb->text, 1, &shift, NULL, NULL, NULL, NULL); | |
1866 | |
12 | 1867 if (selected_state == GTK_STATE_SELECTED) |
1868 { | |
1869 int schar = 0, | |
1870 echar = 0; | |
1871 int startx = 0, | |
1872 xwidth = 0; | |
1873 | |
1874 if (epos > spos || | |
1875 (epos == spos && html->num_end >= html->num_start)) | |
1876 { | |
1877 if (mypos == epos) | |
1878 { | |
1 | 1879 echar = html->num_end; |
12 | 1880 xwidth = |
1881 gdk_text_width(hb->font, hb->text, html->num_end + 1); | |
1882 } | |
1883 else | |
1884 { | |
1 | 1885 echar = strlen(hb->text); |
1886 xwidth = hb->width; | |
1887 } | |
12 | 1888 if (mypos == spos) |
1889 { | |
1 | 1890 schar = html->num_start; |
12 | 1891 startx = |
1892 gdk_text_width(hb->font, hb->text, html->num_start); | |
1 | 1893 xwidth -= startx; |
1894 } | |
12 | 1895 } |
1896 else | |
1897 { | |
1898 if (mypos == spos) | |
1899 { | |
1 | 1900 echar = html->num_start; |
12 | 1901 xwidth = |
1902 gdk_text_width(hb->font, hb->text, | |
1903 html->num_start + 1); | |
1904 } | |
1905 else | |
1906 { | |
1 | 1907 echar = strlen(hb->text); |
1908 xwidth = hb->width; | |
1909 } | |
12 | 1910 if (mypos == epos) |
1911 { | |
1 | 1912 schar = html->num_end; |
12 | 1913 startx = |
1914 gdk_text_width(hb->font, hb->text, html->num_end); | |
1 | 1915 xwidth -= startx; |
1916 } | |
1917 } | |
1918 | |
1919 if (!redraw && echar == hb->sel_e && schar == hb->sel_s) | |
1920 return; | |
12 | 1921 |
1 | 1922 hb->sel_e = echar; |
1923 hb->sel_s = schar; | |
12 | 1924 |
1 | 1925 startx += hb->x; |
1926 | |
1927 | |
12 | 1928 area.x = hb->x - html->xoffset; |
1929 area.y = hb->y - hb->height + 3 - html->yoffset; | |
1930 area.width = hb->width + 2; | |
1931 area.height = hb->height; | |
1932 clear_area(html, &area); | |
1933 | |
1934 gtk_paint_flat_box(widget->style, html->html_area, | |
1935 selected_state, GTK_SHADOW_NONE, | |
1936 NULL, widget, "text", | |
1937 startx, | |
1938 hb->y - hb->height + 3 - html->yoffset, | |
1939 xwidth + 2, hb->height); | |
1940 hb->was_selected = 1; | |
1941 } | |
1942 else if (hb->was_selected) | |
1943 { | |
1944 area.x = hb->x - html->xoffset; | |
1945 area.y = hb->y - hb->height + 3 - html->yoffset; | |
1946 area.width = hb->width + 2; | |
1947 area.height = hb->height; | |
1948 clear_area(html, &area); | |
1949 | |
1950 hb->sel_e = -1; | |
1951 hb->sel_s = -1; | |
1952 | |
1 | 1953 hb->was_selected = 0; |
1954 } | |
12 | 1955 |
1956 | |
1957 | |
1958 | |
1959 if (selected_state == GTK_STATE_SELECTED && (mypos == epos | |
1960 || mypos == spos)) | |
1961 { | |
1 | 1962 char *s = hb->text; |
12 | 1963 int num = 0, |
1964 width = 0, | |
1965 fsel = 0, | |
1966 esel = strlen(hb->text); | |
1967 int lbearing, | |
1968 rbearing, | |
1969 w; | |
1970 | |
1971 if (epos > spos || | |
1972 (epos == spos && html->num_end >= html->num_start)) | |
1973 { | |
1 | 1974 if (mypos == epos) |
1975 esel = html->num_end; | |
1976 if (mypos == spos) | |
1977 fsel = html->num_start; | |
12 | 1978 } |
1979 else | |
1980 { | |
1 | 1981 if (mypos == spos) |
1982 esel = html->num_start; | |
12 | 1983 if (mypos == epos) |
1984 fsel = html->num_end; | |
1 | 1985 } |
1986 | |
12 | 1987 while (*s) |
1988 { | |
1 | 1989 |
1990 if (num < fsel || num > esel) | |
1991 selected_state = GTK_STATE_NORMAL; | |
1992 else | |
1993 selected_state = GTK_STATE_SELECTED; | |
1994 if (hb->fore != NULL) | |
1995 gdk_gc_set_foreground(gc, hb->fore); | |
1996 else | |
12 | 1997 gdk_gc_set_foreground(gc, |
1998 &widget->style->fg[selected_state]); | |
1 | 1999 if (hb->back != NULL) |
2000 gdk_gc_set_background(gc, hb->back); | |
2001 else | |
12 | 2002 gdk_gc_set_background(gc, |
2003 &widget->style->bg[selected_state]); | |
1 | 2004 |
2005 | |
2006 gdk_gc_set_font(gc, hb->font); | |
2007 | |
12 | 2008 gdk_text_extents(hb->font, s, 1, &lbearing, &rbearing, &w, NULL, |
2009 NULL); | |
2010 | |
2011 gdk_draw_text(html->html_area, hb->font, gc, | |
2012 shift + hb->x + width, hb->y - html->yoffset, s, | |
2013 1); | |
2014 | |
2015 if (hb->uline) | |
2016 gdk_draw_line(html->html_area, gc, shift + hb->x + width, | |
2017 hb->y - html->yoffset, | |
2018 shift + hb->x + width + w, | |
2019 hb->y - html->yoffset); | |
1 | 2020 |
2021 if (hb->strike) | |
12 | 2022 gdk_draw_line(html->html_area, gc, shift + hb->x + width, |
2023 hb->y - html->yoffset - (hb->height / 3), | |
2024 shift + hb->x + width + w, | |
2025 hb->y - html->yoffset - (hb->height / 3)); | |
1 | 2026 |
2027 width += w; | |
12 | 2028 |
1 | 2029 s++; |
2030 num++; | |
2031 } | |
2032 | |
2033 | |
12 | 2034 } |
2035 else | |
2036 { | |
2037 /*my stuff here*/ | |
2038 | |
2039 if(!hb->was_selected) | |
2040 { | |
2041 area.x = hb->x - html->xoffset; | |
2042 area.y = hb->y - hb->height + 3 - html->yoffset; | |
2043 area.width = hb->width + 2; | |
2044 area.height = hb->height; | |
2045 clear_area(html, &area); | |
2046 } | |
2047 | |
2048 /*end my stuff*/ | |
2049 | |
1 | 2050 |
674
b68c592829a6
[gaim-migrate @ 684]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
669
diff
changeset
|
2051 if (hb->text && hb->back != NULL && selected_state != GTK_STATE_SELECTED) { |
860
a8633715fb5b
[gaim-migrate @ 870]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
853
diff
changeset
|
2052 int hwidth, hheight; |
a8633715fb5b
[gaim-migrate @ 870]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
853
diff
changeset
|
2053 int hei = gdk_text_height(hb->font, "C", 1); |
a8633715fb5b
[gaim-migrate @ 870]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
853
diff
changeset
|
2054 gdk_window_get_size(html->html_area, &hwidth, &hheight); |
629
ce8d8608d05b
[gaim-migrate @ 639]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
627
diff
changeset
|
2055 gdk_gc_set_foreground(gc, hb->back); |
635
2ad1a8234ef1
[gaim-migrate @ 645]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
632
diff
changeset
|
2056 gdk_draw_rectangle(html->html_area, gc, TRUE /* filled */, |
2ad1a8234ef1
[gaim-migrate @ 645]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
632
diff
changeset
|
2057 shift + hb->x, |
860
a8633715fb5b
[gaim-migrate @ 870]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
853
diff
changeset
|
2058 hb->y - html->yoffset - hei - 6, |
a8633715fb5b
[gaim-migrate @ 870]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
853
diff
changeset
|
2059 hwidth - shift - hb->x + 1, hei + hei + 2); |
629
ce8d8608d05b
[gaim-migrate @ 639]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
627
diff
changeset
|
2060 } |
ce8d8608d05b
[gaim-migrate @ 639]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
627
diff
changeset
|
2061 |
1 | 2062 if (hb->fore != NULL) |
2063 gdk_gc_set_foreground(gc, hb->fore); | |
2064 else | |
12 | 2065 gdk_gc_set_foreground(gc, &widget->style->fg[selected_state]); |
1 | 2066 if (hb->back != NULL) |
2067 gdk_gc_set_background(gc, hb->back); | |
2068 else | |
2069 gdk_gc_set_background(gc, &widget->style->bg[selected_state]); | |
2070 | |
2071 | |
2072 gdk_gc_set_font(gc, hb->font); | |
2073 | |
12 | 2074 |
2075 gdk_draw_string(html->html_area, hb->font, gc, shift + hb->x, | |
2076 hb->y - html->yoffset, hb->text); | |
1 | 2077 if (hb->uline) |
12 | 2078 gdk_draw_line(html->html_area, gc, shift + hb->x, |
2079 hb->y - html->yoffset, | |
2080 hb->x + gdk_string_measure(hb->font, hb->text), | |
2081 hb->y - html->yoffset); | |
1 | 2082 |
2083 if (hb->strike) | |
12 | 2084 gdk_draw_line(html->html_area, gc, shift + hb->x, |
2085 hb->y - html->yoffset - (hb->height / 3), | |
2086 hb->x + gdk_string_measure(hb->font, hb->text), | |
2087 hb->y - html->yoffset - (hb->height / 3)); | |
1 | 2088 |
2089 } | |
12 | 2090 } |
2091 else if (hb->type == HTML_BIT_SEP) | |
2092 { | |
2093 | |
2094 gdk_draw_line(html->html_area, gc, hb->x + 2, | |
2095 hb->y - html->yoffset - (hb->height / 2 - 1), | |
2096 hb->x + hb->width, | |
2097 hb->y - html->yoffset - (hb->height / 2 - 1)); | |
2098 | |
2099 } | |
2100 else if (hb->type == HTML_BIT_PIXMAP) | |
2101 { | |
1 | 2102 gdk_gc_set_background(gc, &widget->style->base[GTK_STATE_NORMAL]); |
12 | 2103 gdk_draw_pixmap(html->html_area, gc, hb->pm, 0, 0, hb->x, |
492
56399273ed8d
[gaim-migrate @ 502]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
481
diff
changeset
|
2104 hb->y - html->yoffset - (hb->height) + 4, -1, -1); |
1 | 2105 } |
2106 } | |
2107 | |
2108 | |
2109 | |
12 | 2110 gint compare_types(GtkHtmlBit * hb, GtkHtmlBit * hb2) |
1 | 2111 { |
12 | 2112 /* |
2113 * In this function, it's OK to accidently return a | |
2114 * * 0, but will cause problems on an accidental 1 | |
2115 */ | |
1 | 2116 |
2117 if (!hb || !hb2) | |
2118 return 0; | |
12 | 2119 |
2120 | |
1 | 2121 if (hb->uline != hb2->uline) |
2122 return 0; | |
2123 if (hb->strike != hb2->strike) | |
12 | 2124 return 0; |
2125 if (hb->font && hb2->font) | |
2126 { | |
1 | 2127 if (!gdk_font_equal(hb->font, hb2->font)) |
2128 return 0; | |
12 | 2129 } |
2130 else if (hb->font && !hb2->font) | |
2131 { | |
1 | 2132 return 0; |
12 | 2133 } |
2134 else if (!hb->font && hb2->font) | |
2135 { | |
1 | 2136 return 0; |
2137 } | |
2138 if (hb->type != hb2->type) | |
2139 return 0; | |
12 | 2140 |
2141 if (hb->fore && hb2->fore) | |
2142 { | |
1 | 2143 if (!gdk_color_equal(hb->fore, hb2->fore)) |
2144 return 0; | |
12 | 2145 } |
2146 else if (hb->fore && !hb2->fore) | |
2147 { | |
1 | 2148 return 0; |
12 | 2149 } |
2150 else if (!hb->fore && hb2->fore) | |
2151 { | |
1 | 2152 return 0; |
2153 } | |
2154 | |
12 | 2155 if (hb->back && hb2->back) |
2156 { | |
1 | 2157 if (!gdk_color_equal(hb->back, hb2->back)) |
2158 return 0; | |
12 | 2159 } |
2160 else if (hb->back && !hb2->back) | |
2161 { | |
1 | 2162 return 0; |
12 | 2163 } |
2164 else if (!hb->back && hb2->back) | |
2165 { | |
1 | 2166 return 0; |
2167 } | |
2168 | |
2169 if ((hb->url != NULL && hb2->url == NULL) || | |
12 | 2170 (hb->url == NULL && hb2->url != NULL)) |
1 | 2171 return 0; |
12 | 2172 |
2173 if (hb->url != NULL && hb2->url != NULL) | |
1 | 2174 if (strcasecmp(hb->url, hb2->url)) |
2175 return 0; | |
12 | 2176 |
1 | 2177 return 1; |
2178 } | |
2179 | |
12 | 2180 static gint html_bit_is_onscreen(GtkHtml * html, GtkHtmlBit * hb) |
1 | 2181 { |
12 | 2182 gint width, |
2183 height; | |
1 | 2184 |
2185 gdk_window_get_size(html->html_area, &width, &height); | |
12 | 2186 |
2187 if (hb->y < html->yoffset) | |
2188 { | |
1 | 2189 return 0; |
2190 } | |
2191 | |
12 | 2192 if ((hb->y - hb->height) > (html->yoffset + height)) |
2193 { | |
1 | 2194 return 0; |
2195 } | |
2196 return 1; | |
2197 } | |
2198 | |
12 | 2199 static void draw_cursor(GtkHtml * html) |
1 | 2200 { |
12 | 2201 if (html->editable && |
2202 html->cursor_hb && | |
2203 GTK_WIDGET_DRAWABLE(html) && | |
2204 html_bit_is_onscreen(html, html->cursor_hb)) | |
2205 { | |
2206 gint x, | |
2207 y; | |
1 | 2208 gint width; |
2209 | |
2210 GdkFont *font = html->cursor_hb->font; | |
2211 | |
12 | 2212 gdk_text_extents(font, html->cursor_hb->text, html->cursor_pos, NULL, |
2213 NULL, &width, NULL, NULL); | |
2214 | |
2215 gdk_gc_set_foreground(html->gc, | |
2216 >K_WIDGET(html)->style->text[GTK_STATE_NORMAL]); | |
1 | 2217 |
2218 y = html->cursor_hb->y - html->yoffset; | |
2219 x = html->cursor_hb->x + width; | |
2220 | |
2221 | |
12 | 2222 gdk_draw_line(html->html_area, html->gc, x, y, x, y - font->ascent); |
1 | 2223 |
2224 } | |
2225 } | |
2226 | |
12 | 2227 static void undraw_cursor(GtkHtml * html) |
1 | 2228 { |
12 | 2229 if (html->editable && |
2230 html->cursor_hb && | |
2231 GTK_WIDGET_DRAWABLE(html) && | |
2232 html_bit_is_onscreen(html, html->cursor_hb)) | |
2233 { | |
2234 gint x, | |
2235 y; | |
1 | 2236 gint width; |
12 | 2237 GdkRectangle area; |
2238 | |
1 | 2239 GdkFont *font = html->cursor_hb->font; |
2240 | |
12 | 2241 gdk_text_extents(font, html->cursor_hb->text, html->cursor_pos, NULL, |
2242 NULL, &width, NULL, NULL); | |
1 | 2243 |
2244 y = html->cursor_hb->y - html->yoffset; | |
2245 x = html->cursor_hb->x + width; | |
2246 | |
2247 area.x = x; | |
2248 area.y = y - font->ascent; | |
2249 area.height = font->ascent + 1; | |
2250 area.width = 1; | |
2251 | |
2252 | |
12 | 2253 clear_area(html, &area); |
1 | 2254 |
2255 gtk_html_draw_bit(html, html->cursor_hb, 1); | |
12 | 2256 |
2257 | |
2258 } | |
1 | 2259 } |
2260 | |
2261 | |
12 | 2262 static void expose_html(GtkHtml * html, GdkRectangle * area, gboolean cursor) |
1 | 2263 { |
12 | 2264 GList *hbits; |
2265 GtkHtmlBit *hb; | |
2266 gint width, | |
2267 height; | |
2268 gint realy; | |
2269 | |
2270 | |
2271 if (html->frozen > 0) | |
2272 return; | |
2273 | |
2274 | |
2275 hbits = html->html_bits; | |
1 | 2276 |
2277 gdk_window_get_size(html->html_area, &width, &height); | |
2278 | |
12 | 2279 realy = area->y + html->yoffset; |
2280 | |
2281 clear_area(html, area); | |
2282 | |
2283 while (hbits) | |
2284 { | |
2285 | |
2286 hb = (GtkHtmlBit *) hbits->data; | |
1 | 2287 |
2288 if (html_bit_is_onscreen(html, hb)) | |
12 | 2289 gtk_html_draw_bit(html, hb, 1); |
2290 | |
2291 | |
2292 hbits = hbits->next; | |
2293 } | |
1 | 2294 } |
2295 | |
12 | 2296 static void resize_html(GtkHtml * html) |
1 | 2297 { |
2298 GList *hbits = html->html_bits; | |
2299 GList *html_bits = html->html_bits; | |
12 | 2300 GtkHtmlBit *hb, |
2301 *hb2; | |
1 | 2302 char *str; |
2303 gint height; | |
2304 | |
12 | 2305 if (!hbits) |
2306 return; | |
2307 | |
2308 | |
2309 html->html_bits = NULL; | |
2310 | |
2311 html->current_x = 0; | |
1 | 2312 html->current_y = 0; |
2313 | |
12 | 2314 html->vadj->upper = 0; |
2315 | |
2316 gtk_html_freeze(html); | |
2317 | |
2318 while (hbits) | |
2319 { | |
2320 hb = (GtkHtmlBit *) hbits->data; | |
2321 if (hb->type == HTML_BIT_SEP) | |
2322 { | |
2323 | |
1 | 2324 gtk_html_add_seperator(html); |
2325 | |
2326 g_free(hb); | |
2327 | |
2328 hbits = hbits->next; | |
2329 continue; | |
2330 } | |
12 | 2331 if (hb->type == HTML_BIT_PIXMAP) |
2332 { | |
1 | 2333 |
536
c9f994ea5833
[gaim-migrate @ 546]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
526
diff
changeset
|
2334 gtk_html_add_pixmap(html, hb->pm, hb->fit, hb->newline); |
1 | 2335 |
2336 g_free(hb); | |
2337 | |
2338 hbits = hbits->next; | |
2339 continue; | |
2340 } | |
12 | 2341 |
2342 if (hb->newline) | |
2343 { | |
1 | 2344 int i; |
2345 | |
12 | 2346 if (!hb->text) |
2347 { | |
1 | 2348 hb->text = g_malloc(1); |
2349 hb->text[0] = 0; | |
2350 } | |
12 | 2351 for (i = 0; i < hb->newline; i++) |
2352 { | |
2353 str = hb->text; | |
1 | 2354 hb->text = g_strconcat(str, "\n", NULL); |
506
58af37870fdd
[gaim-migrate @ 516]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
499
diff
changeset
|
2355 if (str) g_free(str); |
1 | 2356 } |
2357 } | |
2358 | |
12 | 2359 if (hbits->next) |
2360 { | |
2361 hb2 = (GtkHtmlBit *) hbits->next->data; | |
2362 } | |
2363 else | |
2364 { | |
2365 hb2 = NULL; | |
2366 } | |
2367 | |
2368 | |
2369 | |
2370 if (!hb->newline && compare_types(hb, hb2)) | |
2371 { | |
1 | 2372 str = hb2->text; |
2373 hb2->text = g_strconcat(hb->text, hb2->text, NULL); | |
537
d050f88321a1
[gaim-migrate @ 547]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
536
diff
changeset
|
2374 if (str) g_free(str); |
1 | 2375 hb2 = NULL; |
12 | 2376 } |
2377 else if (hb->text) | |
2378 { | |
1 | 2379 gtk_html_add_text(html, hb->font, hb->fore, hb->back, |
12 | 2380 hb->text, strlen(hb->text), hb->uline, hb->strike, |
2381 hb->url); | |
1 | 2382 } |
2383 | |
12 | 2384 |
2385 | |
2386 /* | |
2387 * Font stays, so do colors (segfaults if I free) | |
2388 */ | |
1 | 2389 if (hb->fore) |
2390 gdk_color_free(hb->fore); | |
2391 if (hb->back) | |
2392 gdk_color_free(hb->back); | |
2393 if (hb->text) | |
2394 g_free(hb->text); | |
2395 if (hb->url) | |
2396 g_free(hb->url); | |
2397 | |
12 | 2398 g_free(hb); |
1 | 2399 |
2400 hbits = hbits->next; | |
2401 } | |
2402 | |
12 | 2403 g_list_free(html_bits); |
2404 | |
2405 | |
2406 gtk_html_thaw(html); | |
2407 | |
1 | 2408 gdk_window_get_size(html->html_area, NULL, &height); |
12 | 2409 gtk_adjustment_set_value(html->vadj, html->vadj->upper - height); |
1 | 2410 |
2411 } | |
2412 | |
12 | 2413 static GdkGC *create_bg_gc(GtkHtml * html) |
1 | 2414 { |
12 | 2415 GdkGCValues values; |
2416 | |
2417 values.tile = GTK_WIDGET(html)->style->bg_pixmap[GTK_STATE_NORMAL]; | |
2418 values.fill = GDK_TILED; | |
2419 | |
2420 return gdk_gc_new_with_values(html->html_area, &values, | |
2421 GDK_GC_FILL | GDK_GC_TILE); | |
1 | 2422 } |
2423 | |
12 | 2424 static void clear_area(GtkHtml * html, GdkRectangle * area) |
1 | 2425 { |
12 | 2426 GtkWidget *widget = GTK_WIDGET(html); |
2427 gint x, | |
2428 y; | |
2429 | |
2430 | |
2431 if (html->transparent) | |
2432 { | |
1 | 2433 if (html->pm == NULL) |
2434 html->pm = get_desktop_pixmap(widget); | |
2435 | |
12 | 2436 if (html->pm == NULL) |
2437 return; | |
2438 | |
2439 if (html->bg_gc == NULL) | |
2440 { | |
2441 GdkGCValues values; | |
2442 | |
2443 values.tile = html->pm; | |
2444 values.fill = GDK_TILED; | |
2445 | |
2446 html->bg_gc = gdk_gc_new_with_values(html->html_area, &values, | |
2447 GDK_GC_FILL | GDK_GC_TILE); | |
2448 | |
2449 } | |
2450 | |
1 | 2451 gdk_window_get_deskrelative_origin(html->html_area, &x, &y); |
2452 | |
12 | 2453 gdk_draw_pixmap(html->html_area, html->bg_gc, html->pm, |
2454 x + area->x, y + area->y, area->x, area->y, area->width, | |
2455 area->height); | |
1 | 2456 |
2457 return; | |
2458 | |
2459 } | |
12 | 2460 if (html->bg_gc) |
2461 { | |
2462 | |
2463 gint width, | |
2464 height; | |
2465 | |
2466 gdk_window_get_size(widget->style->bg_pixmap[GTK_STATE_NORMAL], &width, | |
2467 &height); | |
2468 | |
2469 gdk_gc_set_ts_origin(html->bg_gc, | |
2470 (-html->xoffset) % width, | |
2471 (-html->yoffset) % height); | |
2472 | |
2473 gdk_draw_rectangle(html->html_area, html->bg_gc, TRUE, | |
2474 area->x, area->y, area->width, area->height); | |
2475 } | |
2476 else | |
2477 gdk_window_clear_area(html->html_area, area->x, area->y, area->width, | |
2478 area->height); | |
1 | 2479 } |
2480 | |
2481 | |
2482 | |
2483 | |
12 | 2484 static void gtk_html_destroy(GtkObject * object) |
1 | 2485 { |
12 | 2486 GtkHtml *html; |
2487 | |
2488 g_return_if_fail(object != NULL); | |
2489 g_return_if_fail(GTK_IS_HTML(object)); | |
2490 | |
2491 html = (GtkHtml *) object; | |
2492 | |
2493 | |
2494 gtk_signal_disconnect_by_data(GTK_OBJECT(html->hadj), html); | |
2495 gtk_signal_disconnect_by_data(GTK_OBJECT(html->vadj), html); | |
2496 | |
2497 if (html->timer) | |
2498 { | |
2499 gtk_timeout_remove(html->timer); | |
2500 html->timer = 0; | |
1 | 2501 } |
2502 | |
12 | 2503 if (html->tooltip_timer) |
2504 { | |
2505 gtk_timeout_remove(html->tooltip_timer); | |
1 | 2506 html->tooltip_timer = -1; |
2507 } | |
2508 | |
12 | 2509 |
2510 GTK_OBJECT_CLASS(parent_class)->destroy(object); | |
2511 | |
1 | 2512 } |
2513 | |
12 | 2514 static void gtk_html_finalize(GtkObject * object) |
1 | 2515 { |
12 | 2516 GList *hbits; |
2517 GtkHtml *html; | |
1 | 2518 GtkHtmlBit *hb; |
2519 | |
2520 | |
12 | 2521 g_return_if_fail(object != NULL); |
2522 g_return_if_fail(GTK_IS_HTML(object)); | |
2523 | |
2524 html = (GtkHtml *) object; | |
2525 | |
2526 gtk_object_unref(GTK_OBJECT(html->hadj)); | |
2527 gtk_object_unref(GTK_OBJECT(html->vadj)); | |
2528 | |
2529 hbits = html->html_bits; | |
2530 | |
2531 while (hbits) | |
2532 { | |
2533 hb = (GtkHtmlBit *) hbits->data; | |
2534 if (hb->fore) | |
2535 gdk_color_free(hb->fore); | |
2536 if (hb->back) | |
2537 gdk_color_free(hb->back); | |
2538 if (hb->text) | |
2539 g_free(hb->text); | |
2540 if (hb->url) | |
2541 g_free(hb->url); | |
2542 if (hb->pm) | |
2543 gdk_pixmap_unref(hb->pm); | |
2544 | |
2545 g_free(hb); | |
2546 hbits = hbits->next; | |
2547 } | |
2548 if (html->html_bits) | |
2549 g_list_free(html->html_bits); | |
2550 | |
2551 if (html->urls) | |
2552 g_list_free(html->urls); | |
2553 | |
2554 if (html->selected_text) | |
2555 g_free(html->selected_text); | |
2556 | |
2557 if (html->gc) | |
2558 gdk_gc_destroy(html->gc); | |
2559 | |
2560 if (html->bg_gc) | |
2561 gdk_gc_destroy(html->bg_gc); | |
1 | 2562 |
2563 if (html->tooltip_window) | |
2564 gtk_widget_destroy(html->tooltip_window); | |
12 | 2565 |
2566 GTK_OBJECT_CLASS(parent_class)->finalize(object); | |
1 | 2567 } |
2568 | |
12 | 2569 static void gtk_html_realize(GtkWidget * widget) |
1 | 2570 { |
12 | 2571 GtkHtml *html; |
2572 GdkWindowAttr attributes; | |
2573 gint attributes_mask; | |
2574 | |
2575 g_return_if_fail(widget != NULL); | |
2576 g_return_if_fail(GTK_IS_HTML(widget)); | |
2577 | |
2578 html = GTK_HTML(widget); | |
2579 GTK_WIDGET_SET_FLAGS(html, GTK_REALIZED); | |
2580 | |
2581 attributes.window_type = GDK_WINDOW_CHILD; | |
2582 attributes.x = widget->allocation.x; | |
2583 attributes.y = widget->allocation.y; | |
2584 attributes.width = widget->allocation.width; | |
2585 attributes.height = widget->allocation.height; | |
2586 attributes.wclass = GDK_INPUT_OUTPUT; | |
2587 attributes.visual = gtk_widget_get_visual(widget); | |
2588 attributes.colormap = gtk_widget_get_colormap(widget); | |
2589 attributes.event_mask = gtk_widget_get_events(widget); | |
2590 attributes.event_mask |= (GDK_EXPOSURE_MASK | | |
2591 GDK_BUTTON_PRESS_MASK | | |
2592 GDK_BUTTON_RELEASE_MASK | | |
2593 GDK_BUTTON_MOTION_MASK | | |
2594 GDK_ENTER_NOTIFY_MASK | | |
2595 GDK_LEAVE_NOTIFY_MASK | | |
2596 GDK_POINTER_MOTION_MASK | | |
2597 GDK_POINTER_MOTION_HINT_MASK | | |
2598 GDK_VISIBILITY_NOTIFY_MASK | GDK_KEY_PRESS_MASK); | |
2599 | |
2600 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; | |
2601 | |
2602 widget->window = | |
2603 gdk_window_new(gtk_widget_get_parent_window(widget), &attributes, | |
2604 attributes_mask); | |
2605 gdk_window_set_user_data(widget->window, html); | |
2606 | |
2607 attributes.x = (widget->style->klass->xthickness + BORDER_WIDTH); | |
2608 attributes.y = (widget->style->klass->ythickness + BORDER_WIDTH); | |
2609 attributes.width = | |
2610 MAX(1, (gint) widget->allocation.width - (gint) attributes.x * 2); | |
2611 attributes.height = | |
2612 MAX(1, (gint) widget->allocation.height - (gint) attributes.y * 2); | |
2613 | |
2614 html->html_area = | |
2615 gdk_window_new(widget->window, &attributes, attributes_mask); | |
2616 gdk_window_set_user_data(html->html_area, html); | |
2617 | |
2618 widget->style = gtk_style_attach(widget->style, widget->window); | |
2619 | |
2620 /* | |
2621 * Can't call gtk_style_set_background here because it's handled specially | |
2622 */ | |
2623 gdk_window_set_background(widget->window, | |
2624 &widget->style->base[GTK_STATE_NORMAL]); | |
2625 gdk_window_set_background(html->html_area, | |
2626 &widget->style->base[GTK_STATE_NORMAL]); | |
2627 | |
2628 if (widget->style->bg_pixmap[GTK_STATE_NORMAL]) | |
2629 html->bg_gc = create_bg_gc(html); | |
2630 | |
2631 html->gc = gdk_gc_new(html->html_area); | |
2632 gdk_gc_set_exposures(html->gc, TRUE); | |
2633 gdk_gc_set_foreground(html->gc, &widget->style->text[GTK_STATE_NORMAL]); | |
2634 | |
2635 gdk_window_show(html->html_area); | |
1 | 2636 |
2637 } | |
2638 | |
12 | 2639 static void gtk_html_style_set(GtkWidget * widget, GtkStyle * previous_style) |
1 | 2640 { |
12 | 2641 GtkHtml *html; |
2642 | |
2643 g_return_if_fail(widget != NULL); | |
2644 g_return_if_fail(GTK_IS_HTML(widget)); | |
2645 | |
2646 html = GTK_HTML(widget); | |
2647 if (GTK_WIDGET_REALIZED(widget)) | |
2648 { | |
2649 gdk_window_set_background(widget->window, | |
2650 &widget->style->base[GTK_STATE_NORMAL]); | |
2651 gdk_window_set_background(html->html_area, | |
2652 &widget->style->base[GTK_STATE_NORMAL]); | |
2653 | |
2654 if (html->bg_gc) | |
2655 { | |
2656 gdk_gc_destroy(html->bg_gc); | |
2657 html->bg_gc = NULL; | |
2658 } | |
2659 | |
2660 if (widget->style->bg_pixmap[GTK_STATE_NORMAL]) | |
2661 { | |
2662 html->bg_gc = create_bg_gc(html); | |
2663 } | |
2664 | |
2665 } | |
1 | 2666 } |
2667 | |
12 | 2668 static void gtk_html_unrealize(GtkWidget * widget) |
1 | 2669 { |
12 | 2670 GtkHtml *html; |
2671 | |
2672 g_return_if_fail(widget != NULL); | |
2673 g_return_if_fail(GTK_IS_HTML(widget)); | |
2674 | |
2675 html = GTK_HTML(widget); | |
2676 | |
2677 gdk_window_set_user_data(html->html_area, NULL); | |
2678 gdk_window_destroy(html->html_area); | |
2679 html->html_area = NULL; | |
2680 | |
2681 gdk_gc_destroy(html->gc); | |
2682 html->gc = NULL; | |
2683 | |
2684 if (html->bg_gc) | |
2685 { | |
2686 gdk_gc_destroy(html->bg_gc); | |
2687 html->bg_gc = NULL; | |
2688 } | |
2689 | |
2690 if (GTK_WIDGET_CLASS(parent_class)->unrealize) | |
2691 (*GTK_WIDGET_CLASS(parent_class)->unrealize) (widget); | |
1 | 2692 } |
2693 | |
2694 | |
536
c9f994ea5833
[gaim-migrate @ 546]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
526
diff
changeset
|
2695 void gtk_html_add_pixmap(GtkHtml * html, GdkPixmap * pm, int fit, int newline) |
1 | 2696 { |
12 | 2697 GtkHtmlBit *last_hb; |
2698 GtkHtmlBit *hb = g_new0(GtkHtmlBit, 1); | |
2699 GdkWindowPrivate *private = (GdkWindowPrivate *) pm; | |
536
c9f994ea5833
[gaim-migrate @ 546]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
526
diff
changeset
|
2700 int width, height; |
12 | 2701 |
2702 last_hb = (GtkHtmlBit *) g_list_last(html->html_bits)->data; | |
1 | 2703 |
536
c9f994ea5833
[gaim-migrate @ 546]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
526
diff
changeset
|
2704 /* wrap pixmaps */ |
c9f994ea5833
[gaim-migrate @ 546]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
526
diff
changeset
|
2705 gdk_window_get_size(html->html_area, &width, &height); |
c9f994ea5833
[gaim-migrate @ 546]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
526
diff
changeset
|
2706 if ((html->current_x + private->width) >= width) { |
c9f994ea5833
[gaim-migrate @ 546]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
526
diff
changeset
|
2707 html->current_x = 0; |
c9f994ea5833
[gaim-migrate @ 546]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
526
diff
changeset
|
2708 } |
499
3ebd3ca4c3d4
[gaim-migrate @ 509]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
492
diff
changeset
|
2709 |
1 | 2710 hb->fit = fit; |
542
872d68495410
[gaim-migrate @ 552]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
540
diff
changeset
|
2711 html->current_x += 2; |
1 | 2712 hb->x = html->current_x; |
2713 hb->y = html->current_y; | |
12 | 2714 if (fit) |
1 | 2715 hb->height = last_hb->height; |
2716 else | |
2717 hb->height = private->height; | |
2718 hb->type = HTML_BIT_PIXMAP; | |
2719 hb->width = private->width; | |
2720 hb->text = NULL; | |
2721 hb->url = NULL; | |
2722 hb->fore = NULL; | |
2723 hb->back = NULL; | |
2724 hb->font = NULL; | |
12 | 2725 hb->uline = 0; |
2726 hb->strike = 0; | |
1 | 2727 hb->was_selected = 0; |
536
c9f994ea5833
[gaim-migrate @ 546]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
526
diff
changeset
|
2728 hb->newline = newline; |
12 | 2729 hb->pm = pm; |
2730 | |
2731 if (html->current_x == BORDER_WIDTH) | |
2732 { | |
540
f586c3819574
[gaim-migrate @ 550]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
537
diff
changeset
|
2733 html->current_y += hb->height + 3; |
f586c3819574
[gaim-migrate @ 550]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
537
diff
changeset
|
2734 hb->y += hb->height + 3; |
1 | 2735 } |
2736 | |
2737 | |
542
872d68495410
[gaim-migrate @ 552]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
540
diff
changeset
|
2738 html->current_x += hb->width + 1; |
12 | 2739 |
1 | 2740 gtk_html_draw_bit(html, hb, 1); |
2741 | |
536
c9f994ea5833
[gaim-migrate @ 546]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
526
diff
changeset
|
2742 if (hb->newline) |
c9f994ea5833
[gaim-migrate @ 546]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
526
diff
changeset
|
2743 html->current_x = 0; |
c9f994ea5833
[gaim-migrate @ 546]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
526
diff
changeset
|
2744 |
1 | 2745 html->html_bits = g_list_append(html->html_bits, hb); |
2746 | |
2747 | |
2748 } | |
2749 | |
12 | 2750 static void gtk_html_add_seperator(GtkHtml * html) |
1 | 2751 { |
12 | 2752 GtkHtmlBit *hb = g_new0(GtkHtmlBit, 1); |
2753 gint width, | |
2754 height; | |
2755 | |
1 | 2756 html->current_x = 0; |
2757 html->current_y += 5; | |
2758 | |
12 | 2759 gdk_window_get_size(html->html_area, &width, &height); |
2760 | |
1 | 2761 hb->x = html->current_x; |
2762 hb->y = html->current_y; | |
2763 hb->height = 5; | |
2764 hb->type = HTML_BIT_SEP; | |
12 | 2765 hb->width = |
2766 width - | |
2767 GTK_SCROLLED_WINDOW(GTK_WIDGET(html)->parent)->vscrollbar->allocation. | |
2768 width - 10; | |
1 | 2769 hb->text = NULL; |
2770 hb->url = NULL; | |
2771 hb->fore = NULL; | |
2772 hb->back = NULL; | |
2773 hb->font = NULL; | |
12 | 2774 hb->uline = 0; |
2775 hb->strike = 0; | |
1 | 2776 hb->was_selected = 0; |
12 | 2777 hb->newline = 0; |
2778 hb->pm = NULL; | |
1 | 2779 |
2780 gtk_html_draw_bit(html, hb, 1); | |
2781 | |
2782 html->html_bits = g_list_append(html->html_bits, hb); | |
2783 | |
2784 } | |
2785 | |
12 | 2786 static void gtk_html_add_text(GtkHtml * html, |
2787 GdkFont * cfont, | |
2788 GdkColor * fore, | |
2789 GdkColor * back, | |
2790 char *chars, | |
2791 gint length, gint uline, gint strike, char *url) | |
1 | 2792 { |
12 | 2793 char *nextline = NULL, |
2794 *c, | |
2795 *text, | |
2796 *tmp; | |
2797 GdkGC *gc; | |
2798 int nl = 0, | |
2799 nl2 = 0; | |
2800 int maxwidth; | |
2801 gint lb; | |
2802 GList *hbits; | |
79 | 2803 size_t num = 0; |
2804 int i, | |
12 | 2805 height; |
2806 GtkHtmlBit *hb; | |
2807 gint hwidth, | |
2808 hheight; | |
2809 | |
2810 if (length == 1 && chars[0] == '\n') | |
2811 { | |
2812 GtkHtmlBit *h; | |
2813 hbits = g_list_last(html->html_bits); | |
2814 if (!hbits) | |
2815 return; | |
2816 /* | |
2817 * I realize this loses a \n sometimes | |
2818 * * if it's the first thing in the widget. | |
2819 * * so fucking what. | |
2820 */ | |
2821 | |
2822 h = (GtkHtmlBit *) hbits->data; | |
2823 h->newline++; | |
2824 if (html->current_x > 0) | |
2825 html->current_x = 0; | |
2826 else | |
540
f586c3819574
[gaim-migrate @ 550]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
537
diff
changeset
|
2827 html->current_y += cfont->ascent + cfont->descent + 5; |
12 | 2828 return; |
2829 } | |
2830 | |
2831 | |
2832 | |
2833 c = text = g_malloc(length + 2); | |
2834 strncpy(text, chars, length); | |
2835 text[length] = 0; | |
2836 | |
2837 | |
2838 gc = html->gc; | |
2839 | |
2840 if (gc == NULL) | |
2841 gc = html->gc = gdk_gc_new(html->html_area); | |
2842 | |
2843 gdk_gc_set_font(gc, cfont); | |
2844 | |
2845 | |
2846 while (*c) | |
2847 { | |
2848 if (*c == '\n') | |
2849 { | |
2850 if (*(c + 1) == '\0') | |
2851 { | |
2852 nl = 1; | |
2853 length--; | |
2854 c[0] = '\0'; | |
2855 break; | |
2856 } | |
2857 if (*c) | |
2858 { | |
2859 gtk_html_add_text(html, cfont, fore, back, text, num + 1, uline, | |
2860 strike, url); | |
2861 tmp = text; | |
2862 length -= (num + 1); | |
2863 text = g_malloc(length + 2); | |
2864 strncpy(text, (c + 1), length); | |
2865 text[length] = 0; | |
2866 c = text; | |
2867 num = 0; | |
2868 g_free(tmp); | |
1 | 2869 continue; |
12 | 2870 } |
2871 } | |
2872 | |
2873 num++; | |
2874 c++; | |
2875 } | |
2876 | |
2877 /* | |
2878 * Note, yG is chosen because G is damn high, and y is damn low, | |
2879 */ | |
2880 /* | |
2881 * it should be just fine. :) | |
2882 */ | |
2883 | |
2884 gdk_window_get_size(html->html_area, &hwidth, &hheight); | |
2885 | |
2886 num = strlen(text); | |
2887 | |
2888 while (GTK_WIDGET(html)->allocation.width < 20) | |
2889 { | |
2890 while (gtk_events_pending()) | |
1 | 2891 gtk_main_iteration(); |
2892 } | |
2893 | |
12 | 2894 maxwidth = (hwidth - html->current_x - 8); |
2895 /* | |
2896 * HTK_SCROLLED_WINDOW(GTK_WIDGET(layout)->parent)->vscrollbar->allocation.width) - 8; | |
2897 */ | |
2898 | |
851
2cee5577224b
[gaim-migrate @ 861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
850
diff
changeset
|
2899 if ((maxwidth == (hwidth - 8) && gdk_text_measure(cfont, text, num) > 2 * maxwidth) || |
2cee5577224b
[gaim-migrate @ 861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
850
diff
changeset
|
2900 gdk_text_measure(cfont, text, num) < 0) { |
847
430a88eb4a68
[gaim-migrate @ 857]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
842
diff
changeset
|
2901 int pos = num / 2; |
842
2804dc8e9ba0
[gaim-migrate @ 852]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
829
diff
changeset
|
2902 static int count = 0; |
2804dc8e9ba0
[gaim-migrate @ 852]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
829
diff
changeset
|
2903 count ++; |
850
902be73a6a43
[gaim-migrate @ 860]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
847
diff
changeset
|
2904 while (pos < num && (!isspace(text[pos]) || text[pos] == '\n')) pos++; |
847
430a88eb4a68
[gaim-migrate @ 857]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
842
diff
changeset
|
2905 if (pos == num) { |
430a88eb4a68
[gaim-migrate @ 857]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
842
diff
changeset
|
2906 pos = num/2; |
850
902be73a6a43
[gaim-migrate @ 860]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
847
diff
changeset
|
2907 while (pos > 0 && (!isspace(text[pos]) || text[pos] == '\n')) pos--; |
847
430a88eb4a68
[gaim-migrate @ 857]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
842
diff
changeset
|
2908 if (!pos) pos = num / 2; |
430a88eb4a68
[gaim-migrate @ 857]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
842
diff
changeset
|
2909 } |
850
902be73a6a43
[gaim-migrate @ 860]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
847
diff
changeset
|
2910 gtk_html_add_text(html, cfont, fore, back, text, pos + 1, uline, strike, url); |
902be73a6a43
[gaim-migrate @ 860]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
847
diff
changeset
|
2911 gtk_html_add_text(html, cfont, fore, back, &text[pos+1], 1, uline, strike, url); |
902be73a6a43
[gaim-migrate @ 860]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
847
diff
changeset
|
2912 gtk_html_add_text(html, cfont, fore, back, &text[pos+2], num - pos + 1, uline, strike, url); |
842
2804dc8e9ba0
[gaim-migrate @ 852]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
829
diff
changeset
|
2913 g_free(text); |
2804dc8e9ba0
[gaim-migrate @ 852]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
829
diff
changeset
|
2914 count--; |
2804dc8e9ba0
[gaim-migrate @ 852]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
829
diff
changeset
|
2915 if (!count) { |
853
050f244b6829
[gaim-migrate @ 863]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
852
diff
changeset
|
2916 /* FIXME : sometimes we need to add newline, sometimes we don't */ |
842
2804dc8e9ba0
[gaim-migrate @ 852]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
829
diff
changeset
|
2917 hbits = g_list_last(html->html_bits); |
2804dc8e9ba0
[gaim-migrate @ 852]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
829
diff
changeset
|
2918 if (!hbits) return; /* does this ever happen? */ |
2804dc8e9ba0
[gaim-migrate @ 852]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
829
diff
changeset
|
2919 hb = (GtkHtmlBit *)hbits->data; |
850
902be73a6a43
[gaim-migrate @ 860]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
847
diff
changeset
|
2920 hb->newline++; |
842
2804dc8e9ba0
[gaim-migrate @ 852]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
829
diff
changeset
|
2921 } |
2804dc8e9ba0
[gaim-migrate @ 852]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
829
diff
changeset
|
2922 return; |
2804dc8e9ba0
[gaim-migrate @ 852]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
829
diff
changeset
|
2923 } |
2804dc8e9ba0
[gaim-migrate @ 852]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
829
diff
changeset
|
2924 |
12 | 2925 while (gdk_text_measure(cfont, text, num) > maxwidth) |
2926 { | |
2927 if (num > 1) | |
2928 num--; | |
2929 else | |
2930 { | |
26 | 2931 if (html->current_x != 0) { |
2932 html->current_x = 0; | |
2933 if (nl) { | |
2934 text[length] = '\n'; | |
2935 length++; | |
2936 } | |
2937 gtk_html_add_text(html, cfont, fore, back, text, length, uline, strike, url); | |
2938 g_free(text); | |
2939 return; | |
2940 } else { | |
2941 num = strlen (text); | |
2942 break; | |
1 | 2943 } |
2944 } | |
2945 | |
2946 } | |
2947 | |
12 | 2948 height = cfont->ascent + cfont->descent + 2; |
2949 | |
2950 | |
2951 if ((int) (html->vadj->upper - html->current_y) < (int) (height * 2)) | |
2952 { | |
2953 int val; | |
2954 val = (height * 2) + html->current_y; | |
2955 html->vadj->upper = val; | |
2956 adjust_adj(html, html->vadj); | |
1 | 2957 } |
2958 | |
12 | 2959 |
2960 if (html->current_x == 0) | |
2961 { | |
540
f586c3819574
[gaim-migrate @ 550]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
537
diff
changeset
|
2962 html->current_y += height + 3; |
12 | 2963 gdk_text_extents(cfont, text, 1, &lb, NULL, NULL, NULL, NULL); |
2964 html->current_x += (2 - lb); | |
2965 } | |
2966 else if ((hbits = g_list_last(html->html_bits)) != NULL) | |
2967 { | |
2968 int diff, | |
2969 y; | |
2970 hb = (GtkHtmlBit *) hbits->data; | |
2971 if (height > hb->height) | |
2972 { | |
1 | 2973 diff = height - hb->height; |
2974 y = hb->y; | |
2975 html->current_y += diff; | |
12 | 2976 while (hbits) |
2977 { | |
2978 hb = (GtkHtmlBit *) hbits->data; | |
1 | 2979 if (hb->y != y) |
12 | 2980 break; |
492
56399273ed8d
[gaim-migrate @ 502]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
481
diff
changeset
|
2981 if (hb->type != HTML_BIT_PIXMAP) |
56399273ed8d
[gaim-migrate @ 502]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
481
diff
changeset
|
2982 hb->height = height; |
12 | 2983 hb->y += diff; ////////////my thing here ///////////////// |
2984 gtk_html_draw_bit(html, hb, FALSE); | |
2985 | |
2986 hbits = hbits->prev; | |
1 | 2987 } |
2988 } | |
2989 } | |
2990 | |
2991 | |
2992 | |
2993 | |
12 | 2994 if (num != strlen(text)) |
2995 { | |
2996 /* | |
2997 * This is kinda cheesy but it may make things | |
2998 * * much better lookin | |
2999 */ | |
26 | 3000 |
842
2804dc8e9ba0
[gaim-migrate @ 852]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
829
diff
changeset
|
3001 for (i=2; (num > i); i++) { |
26 | 3002 if (text[num - i] == ' ') { |
12 | 3003 num = num - (i - 1); |
1 | 3004 nl2 = 1; |
3005 break; | |
3006 } | |
3007 } | |
3008 | |
3009 nextline = g_malloc(length - num + 2); | |
12 | 3010 strncpy(nextline, (char *) (text + num), length - num); |
1 | 3011 nextline[length - num] = 0; |
12 | 3012 if (nl) |
3013 { | |
1 | 3014 nextline[length - num] = '\n'; |
3015 nextline[length - num + 1] = 0; | |
3016 nl = 0; | |
3017 } | |
3018 | |
3019 | |
3020 text[num] = 0; | |
3021 } | |
3022 | |
3023 | |
52 | 3024 if (url != NULL) { |
53 | 3025 fore = get_color(3355647, gdk_window_get_colormap(html->html_area)); |
52 | 3026 } |
1 | 3027 |
3028 hb = g_new0(GtkHtmlBit, 1); | |
3029 | |
3030 hb->text = g_strdup(text); | |
3031 | |
52 | 3032 if (fore) |
3033 hb->fore = gdk_color_copy(fore); | |
3034 else | |
3035 hb->fore = NULL; | |
49 | 3036 |
1 | 3037 if (back) |
3038 hb->back = gdk_color_copy(back); | |
3039 else | |
3040 hb->back = NULL; | |
3041 hb->font = cfont; | |
3042 hb->uline = uline; | |
3043 hb->strike = strike; | |
3044 hb->height = height; | |
3045 gdk_text_extents(cfont, text, num, &lb, NULL, &hb->width, NULL, NULL); | |
3046 hb->x = html->current_x; | |
3047 hb->y = html->current_y; | |
12 | 3048 hb->type = HTML_BIT_TEXT; |
3049 hb->pm = NULL; | |
3050 if (url != NULL) | |
3051 { | |
1 | 3052 uline = 1; |
3053 hb->uline = 1; | |
3054 hb->url = g_strdup(url); | |
12 | 3055 } |
3056 else | |
3057 { | |
1 | 3058 hb->url = NULL; |
3059 } | |
3060 html->current_x += hb->width; | |
3061 | |
3062 html->html_bits = g_list_append(html->html_bits, hb); | |
12 | 3063 if (url != NULL) |
3064 { | |
3065 html->urls = g_list_append(html->urls, hb); | |
3066 } | |
3067 | |
3068 | |
3069 | |
3070 gtk_html_draw_bit(html, hb, 1); | |
3071 | |
3072 if (nl || nl2) | |
3073 { | |
3074 if (nl) | |
3075 hb->newline = 1; | |
3076 html->current_x = 0; | |
3077 } | |
3078 else | |
3079 hb->newline = 0; | |
3080 | |
3081 | |
3082 if (nextline != NULL) | |
3083 { | |
3084 gtk_html_add_text(html, cfont, fore, back, nextline, strlen(nextline), | |
3085 uline, strike, url); | |
3086 g_free(nextline); | |
3087 } | |
3088 | |
3089 g_free(text); | |
137 | 3090 if (url != NULL) |
3091 g_free(fore); | |
1 | 3092 } |
3093 | |
12 | 3094 static char * html_strtok( char * input, char delim ) |
1 | 3095 { |
12 | 3096 static char * end; |
3097 static char * curr_offset; | |
3098 int i; | |
3099 int num_quotes=0; | |
3100 | |
3101 if( input != NULL) | |
3102 { | |
3103 curr_offset = input; | |
3104 end = input+strlen(input); | |
3105 } | |
3106 else | |
3107 { | |
3108 if( curr_offset + strlen(curr_offset) < end ) | |
3109 { | |
3110 curr_offset += strlen(curr_offset) + 1; | |
3111 } | |
3112 else | |
3113 { | |
3114 return NULL; | |
3115 } | |
3116 } | |
3117 for( i=0; curr_offset+i < end && | |
3118 (curr_offset[i] != delim || num_quotes != 0) | |
3119 ; i++ ) | |
3120 { | |
3121 if( curr_offset[i] == '\"' ) | |
3122 { | |
3123 num_quotes = (num_quotes+1)%2; | |
3124 } | |
3125 } | |
3126 curr_offset[i] = '\0'; | |
3127 return curr_offset; | |
3128 } | |
3129 | |
3130 | |
3131 void gtk_html_append_text(GtkHtml * html, char *text, gint options) | |
3132 { | |
3133 GdkColormap *map; | |
1 | 3134 GdkFont *cfont; |
12 | 3135 GdkRectangle area; |
829
9a123b171f46
[gaim-migrate @ 839]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
791
diff
changeset
|
3136 char *ws, |
12 | 3137 tag[BUF_LONG], |
3138 *c, | |
3139 *url = NULL; | |
3140 gint intag = 0, | |
3141 wpos = 0, | |
481
64afc8f41bcb
[gaim-migrate @ 491]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
353
diff
changeset
|
3142 tpos = 0; |
64afc8f41bcb
[gaim-migrate @ 491]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
353
diff
changeset
|
3143 static gint colorv, |
12 | 3144 bold = 0, |
3145 italic = 0, | |
3146 fixed = 0, | |
3147 uline = 0, | |
3148 strike = 0, | |
481
64afc8f41bcb
[gaim-migrate @ 491]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
353
diff
changeset
|
3149 title = 0, |
64afc8f41bcb
[gaim-migrate @ 491]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
353
diff
changeset
|
3150 height; |
64afc8f41bcb
[gaim-migrate @ 491]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
353
diff
changeset
|
3151 static struct font_state *current = NULL, |
12 | 3152 *tmp; |
481
64afc8f41bcb
[gaim-migrate @ 491]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
353
diff
changeset
|
3153 static struct font_state def_state = { 3, 0, 0, "", NULL, NULL, NULL }; |
64afc8f41bcb
[gaim-migrate @ 491]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
353
diff
changeset
|
3154 |
64afc8f41bcb
[gaim-migrate @ 491]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
353
diff
changeset
|
3155 if (text == NULL) { |
740
01d3c96867e2
[gaim-migrate @ 750]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
737
diff
changeset
|
3156 bold = 0; |
01d3c96867e2
[gaim-migrate @ 750]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
737
diff
changeset
|
3157 italic = 0; |
01d3c96867e2
[gaim-migrate @ 750]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
737
diff
changeset
|
3158 fixed = 0; |
01d3c96867e2
[gaim-migrate @ 750]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
737
diff
changeset
|
3159 uline = 0; |
01d3c96867e2
[gaim-migrate @ 750]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
737
diff
changeset
|
3160 strike = 0; |
01d3c96867e2
[gaim-migrate @ 750]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
737
diff
changeset
|
3161 title = 0; |
481
64afc8f41bcb
[gaim-migrate @ 491]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
353
diff
changeset
|
3162 while (current->next) |
64afc8f41bcb
[gaim-migrate @ 491]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
353
diff
changeset
|
3163 { |
64afc8f41bcb
[gaim-migrate @ 491]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
353
diff
changeset
|
3164 if (current->ownbg) |
64afc8f41bcb
[gaim-migrate @ 491]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
353
diff
changeset
|
3165 g_free(current->bgcol); |
64afc8f41bcb
[gaim-migrate @ 491]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
353
diff
changeset
|
3166 if (current->owncolor) |
64afc8f41bcb
[gaim-migrate @ 491]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
353
diff
changeset
|
3167 g_free(current->color); |
64afc8f41bcb
[gaim-migrate @ 491]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
353
diff
changeset
|
3168 tmp = current; |
64afc8f41bcb
[gaim-migrate @ 491]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
353
diff
changeset
|
3169 current = current->next; |
64afc8f41bcb
[gaim-migrate @ 491]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
353
diff
changeset
|
3170 g_free(tmp); |
64afc8f41bcb
[gaim-migrate @ 491]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
353
diff
changeset
|
3171 } |
64afc8f41bcb
[gaim-migrate @ 491]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
353
diff
changeset
|
3172 return; |
64afc8f41bcb
[gaim-migrate @ 491]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
353
diff
changeset
|
3173 } |
64afc8f41bcb
[gaim-migrate @ 491]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
353
diff
changeset
|
3174 |
64afc8f41bcb
[gaim-migrate @ 491]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
353
diff
changeset
|
3175 if (!current) current = &def_state; |
12 | 3176 map = gdk_window_get_colormap(html->html_area); |
3177 cfont = getfont(current->font, bold, italic, fixed, current->size); | |
1 | 3178 c = text; |
3179 | |
829
9a123b171f46
[gaim-migrate @ 839]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
791
diff
changeset
|
3180 ws = g_malloc(strlen(text) + 2); |
1 | 3181 |
12 | 3182 while (*c) |
3183 { | |
3184 if (*c == '<') | |
3185 { | |
3186 if (!intag) | |
3187 { | |
3188 ws[wpos] = 0; | |
3189 if (wpos) | |
3190 { | |
3191 if (title) | |
3192 { | |
3193 if (html->title) | |
3194 g_free(html->title); | |
3195 html->title = g_strdup(ws); | |
3196 } | |
3197 else | |
3198 gtk_html_add_text(html, cfont, current->color, | |
3199 current->bgcol, ws, strlen(ws), uline, | |
3200 strike, url); | |
3201 } | |
3202 wpos = 0; | |
3203 intag = 1; | |
3204 } | |
3205 else | |
3206 { | |
3207 /* | |
3208 * Assuming you NEVER have nested tags | |
3209 * * (and I mean <tag <tag>> by this, not | |
3210 * * <tag><tag2></tag2><tag>.. | |
3211 */ | |
3212 tag[tpos] = 0; | |
3213 gtk_html_add_text(html, cfont, current->color, current->bgcol, | |
3214 "<", 1, 0, 0, NULL); | |
3215 gtk_html_add_text(html, cfont, current->color, current->bgcol, | |
3216 tag, strlen(tag), 0, 0, NULL); | |
1 | 3217 tpos = 0; |
12 | 3218 |
3219 tag[0] = *c; | |
1 | 3220 } |
12 | 3221 } |
3222 else if (*c == '>') | |
3223 { | |
3224 if (intag) | |
3225 { | |
3226 tag[tpos] = 0; | |
1 | 3227 if (!strcasecmp(tag, "B")) |
3228 bold = 1; | |
732 | 3229 else if (!strcasecmp(tag, "STRIKE") || !strcasecmp(tag, "S")) |
1 | 3230 strike = 1; |
3231 else if (!strcasecmp(tag, "I")) | |
3232 italic = 1; | |
3233 else if (!strcasecmp(tag, "U")) | |
3234 uline = 1; | |
3235 else if (!strcasecmp(tag, "PRE")) | |
3236 fixed = 1; | |
3237 else if (!strcasecmp(tag, "HR")) | |
3238 gtk_html_add_seperator(html); | |
3239 else if (!strcasecmp(tag, "/B")) | |
3240 bold = 0; | |
732 | 3241 else if (!strcasecmp(tag, "/STRIKE") || !strcasecmp(tag, "/S")) |
1 | 3242 strike = 0; |
3243 else if (!strcasecmp(tag, "/I")) | |
3244 italic = 0; | |
3245 else if (!strcasecmp(tag, "/U")) | |
3246 uline = 0; | |
3247 else if (!strcasecmp(tag, "/PRE")) | |
3248 fixed = 0; | |
3249 else if (!strcasecmp(tag, "TITLE")) | |
3250 title = 1; | |
3251 else if (!strcasecmp(tag, "/TITLE")) | |
3252 title = 0; | |
12 | 3253 else if (!strncasecmp(tag, "IMG", 3)) |
3254 { | |
549 | 3255 GdkPixmap *legend_i; |
3256 GdkBitmap *legend_m; | |
3257 | |
3258 if (strstr(tag, "SRC=\"aol_icon.gif\"") != NULL) | |
3259 { | |
3260 legend_i = gdk_pixmap_create_from_xpm_d(GTK_WIDGET(html)->window, &legend_m, NULL, aol_icon_xpm); | |
3261 gtk_html_add_pixmap(html, legend_i, 0, 0); | |
3262 } | |
3263 | |
3264 if (strstr(tag, "SRC=\"admin_icon.gif\"") != NULL) | |
3265 { | |
3266 legend_i = gdk_pixmap_create_from_xpm_d(GTK_WIDGET(html)->window, &legend_m, NULL, admin_icon_xpm); | |
3267 gtk_html_add_pixmap(html, legend_i, 0, 0); | |
3268 } | |
3269 if (strstr(tag, "SRC=\"dt_icon.gif\"") != NULL) | |
3270 { | |
3271 legend_i = gdk_pixmap_create_from_xpm_d(GTK_WIDGET(html)->window, &legend_m, NULL, dt_icon_xpm); | |
3272 gtk_html_add_pixmap(html, legend_i, 0, 0); | |
3273 } | |
3274 if (strstr(tag, "SRC=\"free_icon.gif\"") != NULL) | |
3275 { | |
3276 legend_i = gdk_pixmap_create_from_xpm_d(GTK_WIDGET(html)->window, &legend_m, NULL, free_icon_xpm); | |
3277 gtk_html_add_pixmap(html, legend_i, 0, 0); | |
3278 } | |
12 | 3279 } |
3280 else if (!strcasecmp(tag, "H3")) | |
3281 { | |
1 | 3282 current = push_state(current); |
3283 current->size = 4; | |
12 | 3284 } |
3285 else if (!strcasecmp(tag, "/H3")) | |
3286 { | |
3287 gtk_html_add_text(html, cfont, current->color, | |
3288 current->bgcol, "\n", 1, 0, 0, NULL); | |
3289 | |
3290 if (current->next) | |
3291 { | |
1 | 3292 if (current->ownbg) |
3293 g_free(current->bgcol); | |
3294 if (current->owncolor) | |
3295 g_free(current->color); | |
12 | 3296 tmp = current; |
3297 current = current->next; | |
3298 g_free(tmp); | |
1 | 3299 } |
12 | 3300 } |
3301 else if (!strcasecmp(tag, "TABLE")) | |
3302 { | |
3303 } | |
3304 else if (!strcasecmp(tag, "/TABLE")) | |
3305 { | |
3306 } | |
3307 else if (!strcasecmp(tag, "TR")) | |
3308 { | |
3309 } | |
3310 else if (!strcasecmp(tag, "/TR")) | |
3311 { | |
3312 } | |
3313 else if (!strcasecmp(tag, "/TD")) | |
3314 { | |
3315 } | |
3316 else if (!strcasecmp(tag, "TD")) | |
3317 { | |
3318 gtk_html_add_text(html, cfont, current->color, | |
3319 current->bgcol, " ", 2, 0, 0, NULL); | |
3320 } | |
3321 else if (!strncasecmp(tag, "A ", 2)) | |
3322 { | |
1 | 3323 char *d; |
3324 char *temp = d = g_strdup(tag); | |
3325 int flag = 0; | |
12 | 3326 strtok(tag, " "); |
3327 while ((d = strtok(NULL, " "))) | |
3328 { | |
1 | 3329 if (strlen(d) < 7) |
3330 break; | |
12 | 3331 if (!strncasecmp(d, "HREF=\"", strlen("HREF=\""))) |
3332 { | |
3333 d += strlen("HREF=\""); | |
1 | 3334 d[strlen(d) - 1] = 0; |
3335 url = g_malloc(strlen(d) + 1); | |
3336 strcpy(url, d); | |
3337 flag = 1; | |
12 | 3338 } |
3339 } | |
1 | 3340 g_free(temp); |
12 | 3341 if (!flag) |
3342 { | |
3343 gtk_html_add_text(html, cfont, current->color, | |
3344 current->bgcol, "<", 1, 0, 0, NULL); | |
3345 gtk_html_add_text(html, cfont, current->color, | |
3346 current->bgcol, tag, strlen(tag), 0, | |
3347 0, NULL); | |
3348 gtk_html_add_text(html, cfont, current->color, | |
3349 current->bgcol, ">", 1, 0, 0, NULL); | |
1 | 3350 } |
12 | 3351 } |
3352 else if (!strcasecmp(tag, "/A")) | |
3353 { | |
3354 if (url) | |
3355 { | |
1 | 3356 g_free(url); |
3357 url = NULL; | |
3358 } | |
12 | 3359 } |
3360 else if (!strncasecmp(tag, "FONT", strlen("FONT"))) | |
3361 { | |
3362 char *d; | |
3363 /* | |
3364 * Push a new state onto the stack, based on the old state | |
3365 */ | |
3366 current = push_state(current); | |
3367 html_strtok(tag, ' '); | |
3368 while ((d = html_strtok(NULL, ' '))) | |
3369 { | |
3370 if (!strncasecmp(d, "COLOR=", strlen("COLOR="))) | |
3371 { | |
3372 d += strlen("COLOR="); | |
3373 if (*d == '\"') | |
3374 { | |
3375 d++; | |
3376 } | |
3377 if (*d == '#') | |
3378 d++; | |
3379 if (d[strlen(d) - 1] == '\"') | |
3380 d[strlen(d) - 1] = 0; | |
3381 if (sscanf(d, "%x", &colorv) | |
3382 && !(options & HTML_OPTION_NO_COLOURS)) | |
3383 { | |
677
05f6f7dabb7e
[gaim-migrate @ 687]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
674
diff
changeset
|
3384 current->color = get_color(colorv, map); |
05f6f7dabb7e
[gaim-migrate @ 687]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
674
diff
changeset
|
3385 current->owncolor = 1; |
12 | 3386 } |
3387 else | |
3388 { | |
1 | 3389 } |
12 | 3390 } |
3391 if (!strncasecmp(d, "FACE=", strlen("FACE="))) | |
3392 { | |
3393 d += strlen("FACE="); | |
3394 if (*d == '\"') | |
3395 { | |
3396 d++; | |
3397 } | |
1 | 3398 if (d[strlen(d) - 1] == '\"') |
3399 d[strlen(d) - 1] = 0; | |
12 | 3400 strcpy(current->font, d); |
3401 } | |
3402 else if (!strncasecmp(d, "BACK=", strlen("BACK="))) | |
3403 { | |
3404 d += strlen("BACK="); | |
3405 if (*d == '\"') | |
3406 d++; | |
3407 if (*d == '#') | |
3408 d++; | |
3409 if (d[strlen(d) - 1] == '\"') | |
3410 d[strlen(d) - 1] = 0; | |
3411 if (sscanf(d, "%x", &colorv) | |
3412 && !(options & HTML_OPTION_NO_COLOURS)) | |
3413 { | |
1 | 3414 current->bgcol = get_color(colorv, map); |
3415 current->ownbg = 1; | |
12 | 3416 } |
3417 else | |
3418 { | |
3419 } | |
3420 } | |
3421 else if (!strncasecmp(d, "SIZE=", strlen("SIZE="))) | |
3422 { | |
3423 d += strlen("SIZE="); | |
3424 if (*d == '\"') | |
3425 d++; | |
3426 if (*d == '+') | |
3427 d++; | |
3428 if (sscanf(d, "%d", &colorv)) | |
3429 { | |
3430 current->size = colorv; | |
3431 } | |
3432 else | |
3433 { | |
1 | 3434 } |
12 | 3435 } |
3436 else if (strncasecmp(d, "PTSIZE=", strlen("PTSIZE="))) | |
3437 { | |
3438 } | |
1 | 3439 } |
12 | 3440 } |
669
e871081839d0
[gaim-migrate @ 679]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
667
diff
changeset
|
3441 else if (!strncasecmp(tag, "BODY", strlen("BODY"))) |
12 | 3442 { |
3443 | |
669
e871081839d0
[gaim-migrate @ 679]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
667
diff
changeset
|
3444 char *d; |
632
21c63b26c604
[gaim-migrate @ 642]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
629
diff
changeset
|
3445 current = push_state(current); |
669
e871081839d0
[gaim-migrate @ 679]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
667
diff
changeset
|
3446 html_strtok(tag, ' '); |
e871081839d0
[gaim-migrate @ 679]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
667
diff
changeset
|
3447 while ((d = html_strtok(NULL, ' '))) |
12 | 3448 { |
669
e871081839d0
[gaim-migrate @ 679]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
667
diff
changeset
|
3449 if (!strncasecmp(d, "BGCOLOR=", strlen("BGCOLOR="))) |
e871081839d0
[gaim-migrate @ 679]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
667
diff
changeset
|
3450 { |
677
05f6f7dabb7e
[gaim-migrate @ 687]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
674
diff
changeset
|
3451 d += strlen("BGCOLOR="); |
669
e871081839d0
[gaim-migrate @ 679]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
667
diff
changeset
|
3452 if (*d == '\"') |
e871081839d0
[gaim-migrate @ 679]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
667
diff
changeset
|
3453 d++; |
e871081839d0
[gaim-migrate @ 679]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
667
diff
changeset
|
3454 if (*d == '#') |
e871081839d0
[gaim-migrate @ 679]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
667
diff
changeset
|
3455 d++; |
e871081839d0
[gaim-migrate @ 679]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
667
diff
changeset
|
3456 if (d[strlen(d) - 1] == '\"') |
e871081839d0
[gaim-migrate @ 679]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
667
diff
changeset
|
3457 d[strlen(d) - 1] = 0; |
e871081839d0
[gaim-migrate @ 679]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
667
diff
changeset
|
3458 if (sscanf(d, "%x", &colorv) |
e871081839d0
[gaim-migrate @ 679]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
667
diff
changeset
|
3459 && !(options & HTML_OPTION_NO_COLOURS)) |
e871081839d0
[gaim-migrate @ 679]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
667
diff
changeset
|
3460 { |
677
05f6f7dabb7e
[gaim-migrate @ 687]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
674
diff
changeset
|
3461 if (colorv != 0xffffff || |
669
e871081839d0
[gaim-migrate @ 679]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
667
diff
changeset
|
3462 !(display_options & OPT_DISP_IGN_WHITE)) { |
e871081839d0
[gaim-migrate @ 679]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
667
diff
changeset
|
3463 current->bgcol = get_color(colorv, map); |
e871081839d0
[gaim-migrate @ 679]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
667
diff
changeset
|
3464 current->ownbg = 1; |
e871081839d0
[gaim-migrate @ 679]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
667
diff
changeset
|
3465 } |
e871081839d0
[gaim-migrate @ 679]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
667
diff
changeset
|
3466 } |
667
45ed2ca0756e
[gaim-migrate @ 677]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
666
diff
changeset
|
3467 } |
12 | 3468 } |
3469 } | |
3470 else if (!strncasecmp(tag, "/FONT", strlen("/FONT"))) | |
3471 { | |
3472 /* | |
3473 * Pop a font state off the list if possible, freeing | |
3474 * any resources it used | |
3475 */ | |
3476 if (current->next) | |
3477 { | |
1 | 3478 if (current->ownbg) |
3479 g_free(current->bgcol); | |
3480 if (current->owncolor) | |
3481 g_free(current->color); | |
12 | 3482 tmp = current; |
3483 current = current->next; | |
3484 g_free(tmp); | |
3485 } | |
3486 | |
3487 } | |
3488 else if (!strcasecmp(tag, "/BODY")) | |
3489 { | |
3490 if (current->next) | |
3491 { | |
3492 if (current->ownbg) | |
3493 g_free(current->bgcol); | |
3494 if (current->owncolor) | |
3495 g_free(current->color); | |
3496 tmp = current; | |
3497 current = current->next; | |
1 | 3498 g_free(tmp); |
12 | 3499 } /* |
3500 * tags we ignore below | |
3501 */ | |
3502 } | |
3503 else if (!strncasecmp(tag, "BR", 2)) | |
3504 { | |
3505 gtk_html_add_text(html, cfont, current->color, | |
3506 current->bgcol, "\n", 1, 0, 0, NULL); | |
3507 } | |
3508 else if (strncasecmp(tag, "HTML", 4) | |
3509 && strncasecmp(tag, "/HTML", 5) | |
3510 && strncasecmp(tag, "BODY", 4) | |
3511 && strncasecmp(tag, "/BODY", 5) | |
627
da0a1238874d
[gaim-migrate @ 637]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
604
diff
changeset
|
3512 && (strncasecmp(tag, "P", 1) || tag[1] != '>') |
da0a1238874d
[gaim-migrate @ 637]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
604
diff
changeset
|
3513 && (strncasecmp(tag, "/P", 2) || tag[3] != '>') |
12 | 3514 && strncasecmp(tag, "HEAD", 4) |
3515 && strncasecmp(tag, "/HEAD", 5)) | |
3516 { | |
3517 if (tpos) | |
3518 { | |
3519 gtk_html_add_text(html, cfont, current->color, | |
3520 current->bgcol, "<", 1, 0, 0, NULL); | |
3521 gtk_html_add_text(html, cfont, current->color, | |
3522 current->bgcol, tag, strlen(tag), 0, | |
3523 0, NULL); | |
3524 gtk_html_add_text(html, cfont, current->color, | |
3525 current->bgcol, ">", 1, 0, 0, NULL); | |
1 | 3526 |
3527 } | |
3528 } | |
12 | 3529 cfont = getfont(current->font, bold, italic, fixed, current->size); |
3530 tpos = 0; | |
1 | 3531 intag = 0; |
3532 } | |
12 | 3533 else |
3534 { | |
1 | 3535 ws[wpos++] = *c; |
3536 } | |
12 | 3537 } |
3538 else if (!intag && *c == '&') | |
3539 { | |
3540 if (!strncasecmp(c, "&", 5)) | |
3541 { | |
3542 ws[wpos++] = '&'; | |
3543 c += 4; | |
3544 } | |
3545 else if (!strncasecmp(c, "<", 4)) | |
3546 { | |
3547 ws[wpos++] = '<'; | |
3548 c += 3; | |
3549 } | |
3550 else if (!strncasecmp(c, ">", 4)) | |
3551 { | |
3552 ws[wpos++] = '>'; | |
3553 c += 3; | |
3554 } | |
3555 else if (!strncasecmp(c, " ", 6)) | |
3556 { | |
3557 ws[wpos++] = ' '; | |
3558 c += 5; | |
3559 } | |
526
5bf71b39cba2
[gaim-migrate @ 536]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
523
diff
changeset
|
3560 else if (!strncasecmp(c, "©", 6)) |
5bf71b39cba2
[gaim-migrate @ 536]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
523
diff
changeset
|
3561 { |
5bf71b39cba2
[gaim-migrate @ 536]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
523
diff
changeset
|
3562 ws[wpos++] = '©'; |
5bf71b39cba2
[gaim-migrate @ 536]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
523
diff
changeset
|
3563 c += 5; |
5bf71b39cba2
[gaim-migrate @ 536]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
523
diff
changeset
|
3564 } |
737
c3a920cee3fc
[gaim-migrate @ 747]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
732
diff
changeset
|
3565 else if (!strncasecmp(c, """, 6)) |
c3a920cee3fc
[gaim-migrate @ 747]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
732
diff
changeset
|
3566 { |
c3a920cee3fc
[gaim-migrate @ 747]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
732
diff
changeset
|
3567 ws[wpos++] = '\"'; |
c3a920cee3fc
[gaim-migrate @ 747]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
732
diff
changeset
|
3568 c += 5; |
c3a920cee3fc
[gaim-migrate @ 747]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
732
diff
changeset
|
3569 } |
c3a920cee3fc
[gaim-migrate @ 747]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
732
diff
changeset
|
3570 else if (!strncasecmp(c, "®", 5)) |
c3a920cee3fc
[gaim-migrate @ 747]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
732
diff
changeset
|
3571 { |
c3a920cee3fc
[gaim-migrate @ 747]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
732
diff
changeset
|
3572 ws[wpos++] = 174; |
c3a920cee3fc
[gaim-migrate @ 747]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
732
diff
changeset
|
3573 c += 4; |
c3a920cee3fc
[gaim-migrate @ 747]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
732
diff
changeset
|
3574 } |
526
5bf71b39cba2
[gaim-migrate @ 536]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
523
diff
changeset
|
3575 else if (*(c + 1) == '#') |
5bf71b39cba2
[gaim-migrate @ 536]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
523
diff
changeset
|
3576 { |
5bf71b39cba2
[gaim-migrate @ 536]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
523
diff
changeset
|
3577 int pound = 0; |
5bf71b39cba2
[gaim-migrate @ 536]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
523
diff
changeset
|
3578 debug_print("got &#;\n"); |
5bf71b39cba2
[gaim-migrate @ 536]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
523
diff
changeset
|
3579 if (sscanf(c, "&#%d;", £) > 0) { |
5bf71b39cba2
[gaim-migrate @ 536]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
523
diff
changeset
|
3580 ws[wpos++] = (char)pound; |
5bf71b39cba2
[gaim-migrate @ 536]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
523
diff
changeset
|
3581 c += 2; |
5bf71b39cba2
[gaim-migrate @ 536]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
523
diff
changeset
|
3582 while (isdigit(*c)) c++; |
5bf71b39cba2
[gaim-migrate @ 536]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
523
diff
changeset
|
3583 if (*c != ';') c--; |
5bf71b39cba2
[gaim-migrate @ 536]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
523
diff
changeset
|
3584 } else { |
5bf71b39cba2
[gaim-migrate @ 536]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
523
diff
changeset
|
3585 ws[wpos++] = *c; |
5bf71b39cba2
[gaim-migrate @ 536]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
523
diff
changeset
|
3586 } |
5bf71b39cba2
[gaim-migrate @ 536]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
523
diff
changeset
|
3587 } |
12 | 3588 else |
3589 { | |
3590 ws[wpos++] = *c; | |
3591 } | |
3592 } | |
3593 else | |
3594 { | |
3595 if (intag) | |
3596 { | |
3597 tag[tpos++] = *c; | |
3598 } | |
3599 else | |
3600 { | |
3601 ws[wpos++] = *c; | |
1 | 3602 } |
3603 } | |
3604 c++; | |
3605 } | |
12 | 3606 ws[wpos] = 0; |
3607 tag[tpos] = 0; | |
3608 if (wpos) | |
3609 { | |
3610 gtk_html_add_text(html, cfont, current->color, current->bgcol, ws, | |
3611 strlen(ws), uline, strike, url); | |
1 | 3612 } |
12 | 3613 if (tpos) |
3614 { | |
3615 gtk_html_add_text(html, cfont, current->color, current->bgcol, "<", 1, | |
3616 0, 0, NULL); | |
3617 gtk_html_add_text(html, cfont, current->color, current->bgcol, tag, | |
3618 strlen(tag), 0, 0, NULL); | |
523
023c3851db0a
[gaim-migrate @ 533]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
506
diff
changeset
|
3619 /* gtk_html_add_text(html, cfont, current->color, current->bgcol, ">", 1, |
12 | 3620 0, 0, NULL); |
523
023c3851db0a
[gaim-migrate @ 533]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
506
diff
changeset
|
3621 */ } |
12 | 3622 |
3623 | |
829
9a123b171f46
[gaim-migrate @ 839]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
791
diff
changeset
|
3624 g_free(ws); |
12 | 3625 |
3626 gdk_window_get_size(html->html_area, NULL, &height); | |
3627 area.height = height; | |
1 | 3628 gtk_adjustment_set_value(html->vadj, html->vadj->upper - area.height); |
3629 | |
12 | 3630 return; |
1 | 3631 } |
3632 | |
3633 | |
12 | 3634 static void adjust_adj(GtkHtml * html, GtkAdjustment * adj) |
1 | 3635 { |
12 | 3636 gint height; |
3637 | |
3638 gdk_window_get_size(html->html_area, NULL, &height); | |
3639 | |
3640 adj->step_increment = MIN(adj->upper, (float) SCROLL_PIXELS); | |
3641 adj->page_increment = MIN(adj->upper, height - (float) KEY_SCROLL_PIXELS); | |
3642 adj->page_size = MIN(adj->upper, height); | |
3643 adj->value = MIN(adj->value, adj->upper - adj->page_size); | |
3644 adj->value = MAX(adj->value, 0.0); | |
3645 | |
3646 gtk_signal_emit_by_name(GTK_OBJECT(adj), "changed"); | |
1 | 3647 } |
3648 | |
3649 | |
12 | 3650 static void scroll_down(GtkHtml * html, gint diff0) |
1 | 3651 { |
12 | 3652 GdkRectangle rect; |
3653 gint width, | |
3654 height; | |
3655 | |
3656 html->yoffset += diff0; | |
3657 | |
3658 gdk_window_get_size(html->html_area, &width, &height); | |
3659 | |
3660 if (html->transparent) | |
3661 { | |
1 | 3662 rect.x = 0; |
3663 rect.y = 0; | |
3664 rect.width = width; | |
3665 rect.height = height; | |
12 | 3666 } |
3667 else | |
3668 { | |
3669 | |
1 | 3670 |
3671 if (height > diff0 && !html->transparent) | |
12 | 3672 gdk_draw_pixmap(html->html_area, |
3673 html->gc, | |
3674 html->html_area, | |
3675 0, diff0, 0, 0, width, height - diff0); | |
3676 | |
3677 rect.x = 0; | |
3678 rect.y = MAX(0, height - diff0); | |
3679 rect.width = width; | |
3680 rect.height = MIN(height, diff0); | |
1 | 3681 } |
12 | 3682 |
3683 expose_html(html, &rect, FALSE); | |
3684 gtk_html_draw_focus((GtkWidget *) html); | |
1 | 3685 |
3686 } | |
3687 | |
12 | 3688 static void scroll_up(GtkHtml * html, gint diff0) |
1 | 3689 { |
12 | 3690 GdkRectangle rect; |
3691 gint width, | |
3692 height; | |
3693 | |
1 | 3694 html->yoffset -= diff0; |
3695 | |
3696 | |
12 | 3697 gdk_window_get_size(html->html_area, &width, &height); |
3698 | |
3699 if (html->transparent) | |
3700 { | |
1 | 3701 rect.x = 0; |
3702 rect.y = 0; | |
3703 rect.width = width; | |
3704 rect.height = height; | |
12 | 3705 } |
3706 else | |
3707 { | |
3708 | |
1 | 3709 if (height > diff0) |
12 | 3710 gdk_draw_pixmap(html->html_area, |
3711 html->gc, | |
3712 html->html_area, | |
3713 0, 0, 0, diff0, width, height - diff0); | |
3714 | |
3715 rect.x = 0; | |
3716 rect.y = 0; | |
3717 rect.width = width; | |
3718 rect.height = MIN(height, diff0); | |
1 | 3719 } |
3720 | |
12 | 3721 expose_html(html, &rect, FALSE); |
3722 gtk_html_draw_focus((GtkWidget *) html); | |
1 | 3723 |
3724 } | |
3725 | |
3726 | |
3727 | |
12 | 3728 static void gtk_html_adjustment(GtkAdjustment * adjustment, GtkHtml * html) |
1 | 3729 { |
12 | 3730 g_return_if_fail(adjustment != NULL); |
3731 g_return_if_fail(GTK_IS_ADJUSTMENT(adjustment)); | |
3732 g_return_if_fail(html != NULL); | |
3733 g_return_if_fail(GTK_IS_HTML(html)); | |
3734 | |
3735 /* | |
3736 * Just ignore it if we haven't been size-allocated and realized yet | |
3737 */ | |
3738 if (html->html_area == NULL) | |
3739 return; | |
3740 | |
3741 if (adjustment == html->hadj) | |
3742 { | |
3743 g_warning("horizontal scrolling not implemented"); | |
3744 } | |
3745 else | |
3746 { | |
3747 gint diff = ((gint) adjustment->value) - html->last_ver_value; | |
3748 | |
3749 if (diff != 0) | |
3750 { | |
3751 /* | |
3752 * undraw_cursor (text, FALSE); | |
3753 */ | |
3754 | |
3755 if (diff > 0) | |
3756 { | |
3757 scroll_down(html, diff); | |
3758 } | |
3759 else | |
3760 { /* | |
3761 * if (diff < 0) | |
3762 */ | |
3763 scroll_up(html, -diff); | |
3764 } | |
3765 /* | |
3766 * draw_cursor (text, FALSE); | |
3767 */ | |
3768 | |
3769 html->last_ver_value = adjustment->value; | |
3770 } | |
3771 } | |
1 | 3772 } |
12 | 3773 |
3774 static gint gtk_html_visibility_notify(GtkWidget * widget, | |
3775 GdkEventVisibility * event) | |
1 | 3776 { |
3777 GtkHtml *html; | |
3778 GdkRectangle rect; | |
12 | 3779 gint width, |
3780 height; | |
3781 | |
3782 g_return_val_if_fail(widget != NULL, FALSE); | |
3783 g_return_val_if_fail(GTK_IS_HTML(widget), FALSE); | |
3784 | |
3785 html = GTK_HTML(widget); | |
3786 | |
3787 if (GTK_WIDGET_REALIZED(widget) && html->transparent) | |
3788 { | |
3789 gdk_window_get_size(html->html_area, &width, &height); | |
3790 rect.x = 0; | |
3791 rect.y = 0; | |
3792 rect.width = width; | |
3793 rect.height = height; | |
3794 expose_html(html, &rect, FALSE); | |
3795 gtk_html_draw_focus((GtkWidget *) html); | |
3796 } | |
3797 else | |
3798 { | |
1 | 3799 } |
3800 | |
3801 | |
12 | 3802 return FALSE; |
1 | 3803 } |
3804 | |
3805 | |
3806 | |
12 | 3807 static void gtk_html_disconnect(GtkAdjustment * adjustment, GtkHtml * html) |
1 | 3808 { |
12 | 3809 g_return_if_fail(adjustment != NULL); |
3810 g_return_if_fail(GTK_IS_ADJUSTMENT(adjustment)); | |
3811 g_return_if_fail(html != NULL); | |
3812 g_return_if_fail(GTK_IS_HTML(html)); | |
3813 | |
3814 if (adjustment == html->hadj) | |
3815 gtk_html_set_adjustments(html, NULL, html->vadj); | |
3816 if (adjustment == html->vadj) | |
3817 gtk_html_set_adjustments(html, html->hadj, NULL); | |
1 | 3818 } |
3819 | |
12 | 3820 static void move_cursor_ver(GtkHtml * html, int count) |
1 | 3821 { |
3822 GList *hbits = g_list_find(html->html_bits, html->cursor_hb); | |
12 | 3823 GtkHtmlBit *hb = NULL, |
3824 *hb2 = NULL; | |
1 | 3825 gint y; |
79 | 3826 size_t len, |
12 | 3827 len2 = 0; |
3828 | |
1 | 3829 undraw_cursor(html); |
3830 | |
3831 if (!html->html_bits) | |
3832 return; | |
12 | 3833 |
1 | 3834 if (!html->cursor_hb) |
12 | 3835 html->cursor_hb = (GtkHtmlBit *) html->html_bits->data; |
1 | 3836 |
3837 hb = html->cursor_hb; | |
3838 | |
3839 len = html->cursor_pos; | |
3840 hbits = hbits->prev; | |
12 | 3841 while (hbits) |
3842 { | |
3843 hb2 = (GtkHtmlBit *) hbits->data; | |
1 | 3844 |
3845 if (hb2->y != hb->y) | |
3846 break; | |
3847 | |
12 | 3848 len += strlen(hb2->text); |
3849 | |
1 | 3850 hbits = hbits->prev; |
3851 } | |
3852 | |
12 | 3853 hbits = g_list_find(html->html_bits, html->cursor_hb); |
3854 | |
3855 if (count < 0) | |
3856 { | |
3857 while (hbits) | |
3858 { | |
3859 hb2 = (GtkHtmlBit *) hbits->data; | |
1 | 3860 |
3861 if (hb2->y != hb->y) | |
3862 break; | |
12 | 3863 |
1 | 3864 hbits = hbits->prev; |
3865 } | |
12 | 3866 if (!hbits) |
3867 { | |
1 | 3868 draw_cursor(html); |
3869 return; | |
3870 } | |
3871 y = hb2->y; | |
3872 hb = hb2; | |
12 | 3873 while (hbits) |
3874 { | |
3875 hb2 = (GtkHtmlBit *) hbits->data; | |
1 | 3876 |
3877 if (hb2->y != y) | |
3878 break; | |
3879 | |
3880 hb = hb2; | |
12 | 3881 |
1 | 3882 hbits = hbits->prev; |
3883 } | |
3884 hbits = g_list_find(html->html_bits, hb); | |
12 | 3885 while (hbits) |
3886 { | |
3887 hb2 = (GtkHtmlBit *) hbits->data; | |
3888 | |
3889 if (hb->y != hb2->y) | |
3890 { | |
1 | 3891 html->cursor_hb = hb; |
3892 html->cursor_pos = strlen(hb->text); | |
12 | 3893 break; |
1 | 3894 } |
3895 | |
3896 | |
12 | 3897 if (len < len2 + strlen(hb2->text)) |
3898 { | |
1 | 3899 html->cursor_hb = hb2; |
3900 html->cursor_pos = len - len2; | |
3901 break; | |
3902 } | |
3903 | |
3904 len2 += strlen(hb2->text); | |
3905 | |
3906 hb = hb2; | |
3907 | |
12 | 3908 hbits = hbits->next; |
1 | 3909 } |
12 | 3910 } |
3911 else | |
3912 { | |
3913 while (hbits) | |
3914 { | |
3915 hb2 = (GtkHtmlBit *) hbits->data; | |
1 | 3916 |
3917 if (hb2->y != hb->y) | |
3918 break; | |
12 | 3919 |
1 | 3920 hbits = hbits->next; |
3921 } | |
12 | 3922 if (!hbits) |
3923 { | |
1 | 3924 draw_cursor(html); |
3925 return; | |
3926 } | |
3927 hb = hb2; | |
12 | 3928 while (hbits) |
3929 { | |
3930 hb2 = (GtkHtmlBit *) hbits->data; | |
3931 | |
3932 if (hb->y != hb2->y) | |
3933 { | |
1 | 3934 html->cursor_hb = hb; |
3935 html->cursor_pos = strlen(hb->text); | |
12 | 3936 break; |
1 | 3937 } |
3938 | |
3939 | |
12 | 3940 if (len < len2 + strlen(hb2->text)) |
3941 { | |
1 | 3942 html->cursor_hb = hb2; |
3943 html->cursor_pos = len - len2; | |
3944 break; | |
3945 } | |
3946 | |
3947 len2 += strlen(hb2->text); | |
3948 | |
3949 hb = hb2; | |
3950 | |
12 | 3951 hbits = hbits->next; |
1 | 3952 } |
3953 } | |
3954 | |
3955 draw_cursor(html); | |
3956 | |
3957 } | |
3958 | |
12 | 3959 static void move_cursor_hor(GtkHtml * html, int count) |
1 | 3960 { |
3961 GList *hbits = g_list_find(html->html_bits, html->cursor_hb); | |
12 | 3962 GtkHtmlBit *hb, |
3963 *hb2; | |
1 | 3964 |
3965 undraw_cursor(html); | |
3966 | |
3967 if (!html->html_bits) | |
3968 return; | |
12 | 3969 |
1 | 3970 if (!html->cursor_hb) |
12 | 3971 html->cursor_hb = (GtkHtmlBit *) html->html_bits->data; |
3972 | |
3973 html->cursor_pos += count; | |
3974 | |
3975 if (html->cursor_pos < 0) | |
3976 { | |
3977 if (hbits->prev) | |
3978 { | |
1 | 3979 gint diff; |
3980 hb = html->cursor_hb; | |
12 | 3981 hb2 = (GtkHtmlBit *) hbits->prev->data; |
1 | 3982 diff = html->cursor_pos + strlen(hb2->text) + 1; |
3983 if (hb->y == hb2->y) | |
3984 --diff; | |
12 | 3985 |
1 | 3986 html->cursor_pos = diff; |
12 | 3987 |
3988 html->cursor_hb = (GtkHtmlBit *) hbits->prev->data; | |
3989 } | |
3990 else | |
3991 { | |
1 | 3992 html->cursor_pos = 0; |
3993 } | |
12 | 3994 } |
79 | 3995 else if ((unsigned) html->cursor_pos > strlen(html->cursor_hb->text)) |
12 | 3996 { |
3997 if (hbits->next) | |
3998 { | |
1 | 3999 gint diff; |
4000 hb = html->cursor_hb; | |
12 | 4001 hb2 = (GtkHtmlBit *) hbits->next->data; |
1 | 4002 |
4003 diff = html->cursor_pos - strlen(html->cursor_hb->text) - 1; | |
4004 if (hb->y == hb2->y) | |
12 | 4005 ++diff; |
1 | 4006 html->cursor_pos = diff; |
12 | 4007 html->cursor_hb = (GtkHtmlBit *) hbits->next->data; |
4008 } | |
4009 else | |
4010 { | |
1 | 4011 html->cursor_pos = strlen(html->cursor_hb->text); |
4012 } | |
4013 | |
4014 } | |
4015 | |
4016 draw_cursor(html); | |
4017 } | |
4018 | |
12 | 4019 static void move_beginning_of_line(GtkHtml * html) |
1 | 4020 { |
4021 GList *hbits = g_list_find(html->html_bits, html->cursor_hb); | |
4022 GtkHtmlBit *hb = NULL; | |
12 | 4023 gint y; |
4024 | |
1 | 4025 undraw_cursor(html); |
4026 | |
4027 if (!html->html_bits) | |
4028 return; | |
4029 | |
4030 if (!html->cursor_hb) | |
12 | 4031 html->cursor_hb = (GtkHtmlBit *) html->html_bits->data; |
1 | 4032 |
4033 y = html->cursor_hb->y; | |
12 | 4034 |
4035 while (hbits) | |
4036 { | |
4037 hb = (GtkHtmlBit *) hbits->data; | |
4038 | |
4039 if (y != hb->y) | |
4040 { | |
4041 hb = (GtkHtmlBit *) hbits->next->data; | |
1 | 4042 break; |
4043 } | |
12 | 4044 |
1 | 4045 hbits = hbits->prev; |
4046 } | |
4047 if (!hbits) | |
12 | 4048 html->cursor_hb = (GtkHtmlBit *) html->html_bits->data; |
1 | 4049 else |
4050 html->cursor_hb = hb; | |
4051 | |
4052 html->cursor_pos = 0; | |
4053 | |
4054 | |
4055 draw_cursor(html); | |
4056 | |
4057 | |
4058 } | |
4059 | |
12 | 4060 static void move_end_of_line(GtkHtml * html) |
1 | 4061 { |
4062 GList *hbits = g_list_find(html->html_bits, html->cursor_hb); | |
4063 GtkHtmlBit *hb = NULL; | |
12 | 4064 gint y; |
4065 | |
1 | 4066 undraw_cursor(html); |
4067 | |
4068 if (!html->html_bits) | |
4069 return; | |
4070 | |
4071 if (!html->cursor_hb) | |
12 | 4072 html->cursor_hb = (GtkHtmlBit *) html->html_bits->data; |
1 | 4073 |
4074 y = html->cursor_hb->y; | |
12 | 4075 |
4076 while (hbits) | |
4077 { | |
4078 hb = (GtkHtmlBit *) hbits->data; | |
4079 | |
4080 if (y != hb->y) | |
4081 { | |
4082 hb = (GtkHtmlBit *) hbits->prev->data; | |
1 | 4083 break; |
4084 } | |
12 | 4085 |
1 | 4086 hbits = hbits->next; |
4087 } | |
4088 if (!hbits) | |
12 | 4089 html->cursor_hb = (GtkHtmlBit *) g_list_last(html->html_bits)->data; |
1 | 4090 else |
4091 html->cursor_hb = hb; | |
4092 | |
4093 html->cursor_pos = strlen(html->cursor_hb->text); | |
4094 | |
4095 | |
4096 draw_cursor(html); | |
4097 | |
4098 | |
4099 } | |
4100 | |
4101 | |
4102 | |
12 | 4103 static gint gtk_html_key_press(GtkWidget * widget, GdkEventKey * event) |
1 | 4104 { |
4105 GtkHtml *html; | |
4106 gchar key; | |
4107 gint return_val; | |
12 | 4108 |
4109 g_return_val_if_fail(widget != NULL, FALSE); | |
4110 g_return_val_if_fail(GTK_IS_HTML(widget), FALSE); | |
4111 g_return_val_if_fail(event != NULL, FALSE); | |
4112 | |
1 | 4113 return_val = FALSE; |
12 | 4114 |
4115 html = GTK_HTML(widget); | |
4116 | |
1 | 4117 key = event->keyval; |
4118 return_val = TRUE; | |
4119 | |
4120 | |
12 | 4121 if (html->editable == FALSE) |
4122 { | |
4123 /* | |
4124 * switch (event->keyval) { | |
4125 * case GDK_Home: | |
4126 * if (event->state & GDK_CONTROL_MASK) | |
4127 * scroll_int (text, -text->vadj->value); | |
4128 * else | |
4129 * return_val = FALSE; | |
4130 * break; | |
4131 * case GDK_End: | |
4132 * if (event->state & GDK_CONTROL_MASK) | |
4133 * scroll_int (text, +text->vadj->upper); | |
4134 * else | |
4135 * return_val = FALSE; | |
4136 * break; | |
4137 * case GDK_Page_Up: scroll_int (text, -text->vadj->page_increment); break; | |
4138 * case GDK_Page_Down: scroll_int (text, +text->vadj->page_increment); break; | |
4139 * case GDK_Up: scroll_int (text, -KEY_SCROLL_PIXELS); break; | |
4140 * case GDK_Down: scroll_int (text, +KEY_SCROLL_PIXELS); break; | |
4141 * case GDK_Return: | |
4142 * if (event->state & GDK_CONTROL_MASK) | |
4143 * gtk_signal_emit_by_name (GTK_OBJECT (text), "activate"); | |
4144 * else | |
4145 * return_val = FALSE; | |
4146 * break; | |
4147 * default: | |
4148 * return_val = FALSE; | |
4149 * break; | |
4150 * } | |
4151 */ | |
4152 } | |
4153 else | |
4154 { | |
4155 | |
4156 switch (event->keyval) | |
4157 { | |
1 | 4158 case GDK_Home: |
12 | 4159 move_beginning_of_line(html); |
1 | 4160 break; |
4161 case GDK_End: | |
12 | 4162 move_end_of_line(html); |
1 | 4163 break; |
4164 /* | |
12 | 4165 * case GDK_Page_Up: |
4166 * move_cursor_page_ver (html, -1); | |
4167 * break; | |
4168 * case GDK_Page_Down: | |
4169 * move_cursor_page_ver (html, +1); | |
4170 * break; | |
4171 */ | |
4172 /* | |
4173 * CUA has Ctrl-Up/Ctrl-Down as paragraph up down | |
4174 */ | |
1 | 4175 case GDK_Up: |
12 | 4176 move_cursor_ver(html, -1); |
1 | 4177 break; |
4178 case GDK_Down: | |
12 | 4179 move_cursor_ver(html, +1); |
1 | 4180 break; |
4181 case GDK_Left: | |
12 | 4182 move_cursor_hor(html, -1); |
1 | 4183 break; |
4184 case GDK_Right: | |
12 | 4185 move_cursor_hor(html, +1); |
1 | 4186 break; |
4187 #if 0 | |
4188 case GDK_BackSpace: | |
4189 if (event->state & GDK_CONTROL_MASK) | |
12 | 4190 gtk_text_delete_backward_word(text); |
1 | 4191 else |
12 | 4192 gtk_text_delete_backward_character(text); |
1 | 4193 break; |
4194 case GDK_Clear: | |
12 | 4195 gtk_text_delete_line(text); |
1 | 4196 break; |
4197 case GDK_Insert: | |
4198 if (event->state & GDK_SHIFT_MASK) | |
4199 { | |
4200 extend_selection = FALSE; | |
12 | 4201 gtk_editable_paste_clipboard(editable); |
1 | 4202 } |
4203 else if (event->state & GDK_CONTROL_MASK) | |
4204 { | |
12 | 4205 gtk_editable_copy_clipboard(editable); |
1 | 4206 } |
4207 else | |
4208 { | |
12 | 4209 /* |
4210 * gtk_toggle_insert(text) -- IMPLEMENT | |
4211 */ | |
1 | 4212 } |
4213 break; | |
4214 case GDK_Delete: | |
4215 if (event->state & GDK_CONTROL_MASK) | |
12 | 4216 gtk_text_delete_forward_word(text); |
1 | 4217 else if (event->state & GDK_SHIFT_MASK) |
4218 { | |
4219 extend_selection = FALSE; | |
12 | 4220 gtk_editable_cut_clipboard(editable); |
1 | 4221 } |
4222 else | |
12 | 4223 gtk_text_delete_forward_character(text); |
1 | 4224 break; |
4225 case GDK_Tab: | |
4226 position = text->point.index; | |
12 | 4227 gtk_editable_insert_text(editable, "\t", 1, &position); |
1 | 4228 break; |
4229 case GDK_Return: | |
4230 if (event->state & GDK_CONTROL_MASK) | |
12 | 4231 gtk_signal_emit_by_name(GTK_OBJECT(text), "activate"); |
1 | 4232 else |
4233 { | |
4234 position = text->point.index; | |
12 | 4235 gtk_editable_insert_text(editable, "\n", 1, &position); |
1 | 4236 } |
4237 break; | |
4238 case GDK_Escape: | |
12 | 4239 /* |
4240 * Don't insert literally | |
4241 */ | |
1 | 4242 return_val = FALSE; |
4243 break; | |
4244 #endif | |
4245 default: | |
4246 return_val = FALSE; | |
4247 | |
4248 #if 0 | |
12 | 4249 if (event->state & GDK_CONTROL_MASK) |
4250 { | |
1 | 4251 if ((key >= 'A') && (key <= 'Z')) |
4252 key -= 'A' - 'a'; | |
4253 | |
12 | 4254 if ((key >= 'a') && (key <= 'z') |
4255 && control_keys[(int) (key - 'a')]) | |
1 | 4256 { |
12 | 4257 (*control_keys[(int) (key - 'a')]) (editable, event->time); |
1 | 4258 return_val = TRUE; |
4259 } | |
4260 | |
4261 break; | |
4262 } | |
4263 else if (event->state & GDK_MOD1_MASK) | |
4264 { | |
4265 if ((key >= 'A') && (key <= 'Z')) | |
4266 key -= 'A' - 'a'; | |
4267 | |
4268 if ((key >= 'a') && (key <= 'z') && alt_keys[(int) (key - 'a')]) | |
4269 { | |
12 | 4270 (*alt_keys[(int) (key - 'a')]) (editable, event->time); |
1 | 4271 return_val = TRUE; |
4272 } | |
4273 break; | |
4274 } | |
4275 #endif | |
4276 /* | |
12 | 4277 * if (event->length > 0) { |
4278 * html->cursor_pos++; | |
4279 * gtk_editable_insert_text (editable, event->string, event->length, &position); | |
4280 * | |
4281 * return_val = TRUE; | |
4282 * } | |
4283 * else | |
4284 * return_val = FALSE; | |
4285 */ | |
1 | 4286 } |
4287 | |
4288 } | |
4289 | |
4290 return return_val; | |
4291 } | |
12 | 4292 |
4293 void gtk_html_freeze(GtkHtml * html) | |
1 | 4294 { |
12 | 4295 g_return_if_fail(html != NULL); |
4296 g_return_if_fail(GTK_IS_HTML(html)); | |
1 | 4297 |
4298 html->frozen++; | |
4299 } | |
4300 | |
12 | 4301 void gtk_html_thaw(GtkHtml * html) |
1 | 4302 { |
4303 GdkRectangle area; | |
12 | 4304 |
4305 g_return_if_fail(html != NULL); | |
4306 g_return_if_fail(GTK_IS_HTML(html)); | |
1 | 4307 |
481
64afc8f41bcb
[gaim-migrate @ 491]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
353
diff
changeset
|
4308 gtk_html_append_text(html, NULL, 0); |
64afc8f41bcb
[gaim-migrate @ 491]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
353
diff
changeset
|
4309 |
1 | 4310 html->frozen--; |
4311 | |
4312 if (html->frozen < 0) | |
12 | 4313 html->frozen = 0; |
4314 | |
4315 if (html->frozen == 0) | |
4316 { | |
4317 if (html->html_area) | |
4318 { | |
4319 gint width, | |
4320 height; | |
1 | 4321 area.x = 0; |
4322 area.y = 0; | |
4323 | |
4324 gdk_window_get_size(html->html_area, &width, &height); | |
4325 | |
12 | 4326 area.width = width; |
4327 area.height = height; | |
4328 | |
1 | 4329 expose_html(html, &area, TRUE); |
4330 } | |
4331 } | |
4332 } |