Mercurial > pidgin
annotate src/gtkhtml.c @ 888:38ffd1faa31a
[gaim-migrate @ 898]
"New Conversation" is logged in chatroom log files.
committer: Tailor Script <tailor@pidgin.im>
author | Rob Flynn <gaim@robflynn.com> |
---|---|
date | Tue, 12 Sep 2000 17:56:39 +0000 |
parents | 75b05911234a |
children | b5b3aa06111d |
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 | |
871
75b05911234a
[gaim-migrate @ 881]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
869
diff
changeset
|
1825 |
12 | 1826 static void gtk_html_draw_bit(GtkHtml * html, GtkHtmlBit * hb, int redraw) |
1 | 1827 { |
12 | 1828 int mypos, |
1829 epos, | |
871
75b05911234a
[gaim-migrate @ 881]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
869
diff
changeset
|
1830 spos; |
12 | 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 |
871
75b05911234a
[gaim-migrate @ 881]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
869
diff
changeset
|
2051 if (hb->text && hb->back != NULL && selected_state != GTK_STATE_SELECTED) { |
75b05911234a
[gaim-migrate @ 881]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
869
diff
changeset
|
2052 int hwidth, hheight; |
75b05911234a
[gaim-migrate @ 881]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
869
diff
changeset
|
2053 int hei = gdk_text_height(hb->font, "C", 1); |
860
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 */, |
868
d828bdc3854b
[gaim-migrate @ 878]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
860
diff
changeset
|
2057 hb->x, hb->y - html->yoffset - hei - 6, |
860
a8633715fb5b
[gaim-migrate @ 870]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
853
diff
changeset
|
2058 hwidth - shift - hb->x + 1, hei + hei + 2); |
629
ce8d8608d05b
[gaim-migrate @ 639]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
627
diff
changeset
|
2059 } |
ce8d8608d05b
[gaim-migrate @ 639]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
627
diff
changeset
|
2060 |
1 | 2061 if (hb->fore != NULL) |
2062 gdk_gc_set_foreground(gc, hb->fore); | |
2063 else | |
12 | 2064 gdk_gc_set_foreground(gc, &widget->style->fg[selected_state]); |
1 | 2065 if (hb->back != NULL) |
2066 gdk_gc_set_background(gc, hb->back); | |
2067 else | |
2068 gdk_gc_set_background(gc, &widget->style->bg[selected_state]); | |
2069 | |
2070 | |
2071 gdk_gc_set_font(gc, hb->font); | |
2072 | |
12 | 2073 |
2074 gdk_draw_string(html->html_area, hb->font, gc, shift + hb->x, | |
2075 hb->y - html->yoffset, hb->text); | |
1 | 2076 if (hb->uline) |
12 | 2077 gdk_draw_line(html->html_area, gc, shift + hb->x, |
2078 hb->y - html->yoffset, | |
2079 hb->x + gdk_string_measure(hb->font, hb->text), | |
2080 hb->y - html->yoffset); | |
1 | 2081 |
2082 if (hb->strike) | |
12 | 2083 gdk_draw_line(html->html_area, gc, shift + hb->x, |
2084 hb->y - html->yoffset - (hb->height / 3), | |
2085 hb->x + gdk_string_measure(hb->font, hb->text), | |
2086 hb->y - html->yoffset - (hb->height / 3)); | |
1 | 2087 |
2088 } | |
12 | 2089 } |
2090 else if (hb->type == HTML_BIT_SEP) | |
2091 { | |
871
75b05911234a
[gaim-migrate @ 881]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
869
diff
changeset
|
2092 |
12 | 2093 gdk_draw_line(html->html_area, gc, hb->x + 2, |
2094 hb->y - html->yoffset - (hb->height / 2 - 1), | |
2095 hb->x + hb->width, | |
2096 hb->y - html->yoffset - (hb->height / 2 - 1)); | |
2097 | |
2098 } | |
2099 else if (hb->type == HTML_BIT_PIXMAP) | |
2100 { | |
1 | 2101 gdk_gc_set_background(gc, &widget->style->base[GTK_STATE_NORMAL]); |
12 | 2102 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
|
2103 hb->y - html->yoffset - (hb->height) + 4, -1, -1); |
1 | 2104 } |
2105 } | |
2106 | |
2107 | |
2108 | |
12 | 2109 gint compare_types(GtkHtmlBit * hb, GtkHtmlBit * hb2) |
1 | 2110 { |
12 | 2111 /* |
2112 * In this function, it's OK to accidently return a | |
2113 * * 0, but will cause problems on an accidental 1 | |
2114 */ | |
1 | 2115 |
2116 if (!hb || !hb2) | |
2117 return 0; | |
12 | 2118 |
2119 | |
1 | 2120 if (hb->uline != hb2->uline) |
2121 return 0; | |
2122 if (hb->strike != hb2->strike) | |
12 | 2123 return 0; |
2124 if (hb->font && hb2->font) | |
2125 { | |
1 | 2126 if (!gdk_font_equal(hb->font, hb2->font)) |
2127 return 0; | |
12 | 2128 } |
2129 else if (hb->font && !hb2->font) | |
2130 { | |
1 | 2131 return 0; |
12 | 2132 } |
2133 else if (!hb->font && hb2->font) | |
2134 { | |
1 | 2135 return 0; |
2136 } | |
2137 if (hb->type != hb2->type) | |
2138 return 0; | |
12 | 2139 |
2140 if (hb->fore && hb2->fore) | |
2141 { | |
1 | 2142 if (!gdk_color_equal(hb->fore, hb2->fore)) |
2143 return 0; | |
12 | 2144 } |
2145 else if (hb->fore && !hb2->fore) | |
2146 { | |
1 | 2147 return 0; |
12 | 2148 } |
2149 else if (!hb->fore && hb2->fore) | |
2150 { | |
1 | 2151 return 0; |
2152 } | |
2153 | |
12 | 2154 if (hb->back && hb2->back) |
2155 { | |
1 | 2156 if (!gdk_color_equal(hb->back, hb2->back)) |
2157 return 0; | |
12 | 2158 } |
2159 else if (hb->back && !hb2->back) | |
2160 { | |
1 | 2161 return 0; |
12 | 2162 } |
2163 else if (!hb->back && hb2->back) | |
2164 { | |
1 | 2165 return 0; |
2166 } | |
2167 | |
2168 if ((hb->url != NULL && hb2->url == NULL) || | |
12 | 2169 (hb->url == NULL && hb2->url != NULL)) |
1 | 2170 return 0; |
12 | 2171 |
2172 if (hb->url != NULL && hb2->url != NULL) | |
1 | 2173 if (strcasecmp(hb->url, hb2->url)) |
2174 return 0; | |
12 | 2175 |
1 | 2176 return 1; |
2177 } | |
2178 | |
12 | 2179 static gint html_bit_is_onscreen(GtkHtml * html, GtkHtmlBit * hb) |
1 | 2180 { |
12 | 2181 gint width, |
2182 height; | |
1 | 2183 |
2184 gdk_window_get_size(html->html_area, &width, &height); | |
12 | 2185 |
2186 if (hb->y < html->yoffset) | |
2187 { | |
1 | 2188 return 0; |
2189 } | |
2190 | |
12 | 2191 if ((hb->y - hb->height) > (html->yoffset + height)) |
2192 { | |
1 | 2193 return 0; |
2194 } | |
2195 return 1; | |
2196 } | |
2197 | |
12 | 2198 static void draw_cursor(GtkHtml * html) |
1 | 2199 { |
12 | 2200 if (html->editable && |
2201 html->cursor_hb && | |
2202 GTK_WIDGET_DRAWABLE(html) && | |
2203 html_bit_is_onscreen(html, html->cursor_hb)) | |
2204 { | |
2205 gint x, | |
2206 y; | |
1 | 2207 gint width; |
2208 | |
2209 GdkFont *font = html->cursor_hb->font; | |
2210 | |
12 | 2211 gdk_text_extents(font, html->cursor_hb->text, html->cursor_pos, NULL, |
2212 NULL, &width, NULL, NULL); | |
2213 | |
2214 gdk_gc_set_foreground(html->gc, | |
2215 >K_WIDGET(html)->style->text[GTK_STATE_NORMAL]); | |
1 | 2216 |
2217 y = html->cursor_hb->y - html->yoffset; | |
2218 x = html->cursor_hb->x + width; | |
2219 | |
2220 | |
12 | 2221 gdk_draw_line(html->html_area, html->gc, x, y, x, y - font->ascent); |
1 | 2222 |
2223 } | |
2224 } | |
2225 | |
12 | 2226 static void undraw_cursor(GtkHtml * html) |
1 | 2227 { |
12 | 2228 if (html->editable && |
2229 html->cursor_hb && | |
2230 GTK_WIDGET_DRAWABLE(html) && | |
2231 html_bit_is_onscreen(html, html->cursor_hb)) | |
2232 { | |
2233 gint x, | |
2234 y; | |
1 | 2235 gint width; |
12 | 2236 GdkRectangle area; |
2237 | |
1 | 2238 GdkFont *font = html->cursor_hb->font; |
2239 | |
12 | 2240 gdk_text_extents(font, html->cursor_hb->text, html->cursor_pos, NULL, |
2241 NULL, &width, NULL, NULL); | |
1 | 2242 |
2243 y = html->cursor_hb->y - html->yoffset; | |
2244 x = html->cursor_hb->x + width; | |
2245 | |
2246 area.x = x; | |
2247 area.y = y - font->ascent; | |
2248 area.height = font->ascent + 1; | |
2249 area.width = 1; | |
2250 | |
2251 | |
12 | 2252 clear_area(html, &area); |
1 | 2253 |
2254 gtk_html_draw_bit(html, html->cursor_hb, 1); | |
12 | 2255 |
2256 | |
2257 } | |
1 | 2258 } |
2259 | |
2260 | |
12 | 2261 static void expose_html(GtkHtml * html, GdkRectangle * area, gboolean cursor) |
1 | 2262 { |
12 | 2263 GList *hbits; |
2264 GtkHtmlBit *hb; | |
2265 gint width, | |
2266 height; | |
2267 gint realy; | |
2268 | |
2269 | |
2270 if (html->frozen > 0) | |
2271 return; | |
2272 | |
2273 | |
2274 hbits = html->html_bits; | |
1 | 2275 |
2276 gdk_window_get_size(html->html_area, &width, &height); | |
2277 | |
12 | 2278 realy = area->y + html->yoffset; |
2279 | |
2280 clear_area(html, area); | |
2281 | |
2282 while (hbits) | |
2283 { | |
2284 | |
2285 hb = (GtkHtmlBit *) hbits->data; | |
1 | 2286 |
2287 if (html_bit_is_onscreen(html, hb)) | |
12 | 2288 gtk_html_draw_bit(html, hb, 1); |
2289 | |
2290 | |
2291 hbits = hbits->next; | |
2292 } | |
1 | 2293 } |
2294 | |
12 | 2295 static void resize_html(GtkHtml * html) |
1 | 2296 { |
2297 GList *hbits = html->html_bits; | |
2298 GList *html_bits = html->html_bits; | |
12 | 2299 GtkHtmlBit *hb, |
2300 *hb2; | |
1 | 2301 char *str; |
2302 gint height; | |
2303 | |
12 | 2304 if (!hbits) |
2305 return; | |
2306 | |
2307 | |
2308 html->html_bits = NULL; | |
2309 | |
2310 html->current_x = 0; | |
1 | 2311 html->current_y = 0; |
2312 | |
12 | 2313 html->vadj->upper = 0; |
2314 | |
2315 gtk_html_freeze(html); | |
2316 | |
2317 while (hbits) | |
2318 { | |
2319 hb = (GtkHtmlBit *) hbits->data; | |
2320 if (hb->type == HTML_BIT_SEP) | |
2321 { | |
2322 | |
1 | 2323 gtk_html_add_seperator(html); |
2324 | |
2325 g_free(hb); | |
2326 | |
2327 hbits = hbits->next; | |
2328 continue; | |
2329 } | |
12 | 2330 if (hb->type == HTML_BIT_PIXMAP) |
2331 { | |
1 | 2332 |
536
c9f994ea5833
[gaim-migrate @ 546]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
526
diff
changeset
|
2333 gtk_html_add_pixmap(html, hb->pm, hb->fit, hb->newline); |
1 | 2334 |
2335 g_free(hb); | |
2336 | |
2337 hbits = hbits->next; | |
2338 continue; | |
2339 } | |
12 | 2340 |
2341 if (hb->newline) | |
2342 { | |
1 | 2343 int i; |
2344 | |
12 | 2345 if (!hb->text) |
2346 { | |
1 | 2347 hb->text = g_malloc(1); |
2348 hb->text[0] = 0; | |
2349 } | |
12 | 2350 for (i = 0; i < hb->newline; i++) |
2351 { | |
2352 str = hb->text; | |
1 | 2353 hb->text = g_strconcat(str, "\n", NULL); |
506
58af37870fdd
[gaim-migrate @ 516]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
499
diff
changeset
|
2354 if (str) g_free(str); |
1 | 2355 } |
2356 } | |
2357 | |
12 | 2358 if (hbits->next) |
2359 { | |
2360 hb2 = (GtkHtmlBit *) hbits->next->data; | |
2361 } | |
2362 else | |
2363 { | |
2364 hb2 = NULL; | |
2365 } | |
2366 | |
2367 | |
2368 | |
2369 if (!hb->newline && compare_types(hb, hb2)) | |
2370 { | |
1 | 2371 str = hb2->text; |
2372 hb2->text = g_strconcat(hb->text, hb2->text, NULL); | |
537
d050f88321a1
[gaim-migrate @ 547]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
536
diff
changeset
|
2373 if (str) g_free(str); |
1 | 2374 hb2 = NULL; |
12 | 2375 } |
2376 else if (hb->text) | |
2377 { | |
1 | 2378 gtk_html_add_text(html, hb->font, hb->fore, hb->back, |
12 | 2379 hb->text, strlen(hb->text), hb->uline, hb->strike, |
2380 hb->url); | |
1 | 2381 } |
2382 | |
12 | 2383 |
2384 | |
2385 /* | |
2386 * Font stays, so do colors (segfaults if I free) | |
2387 */ | |
1 | 2388 if (hb->fore) |
2389 gdk_color_free(hb->fore); | |
2390 if (hb->back) | |
2391 gdk_color_free(hb->back); | |
2392 if (hb->text) | |
2393 g_free(hb->text); | |
2394 if (hb->url) | |
2395 g_free(hb->url); | |
2396 | |
12 | 2397 g_free(hb); |
1 | 2398 |
2399 hbits = hbits->next; | |
2400 } | |
2401 | |
12 | 2402 g_list_free(html_bits); |
2403 | |
2404 | |
2405 gtk_html_thaw(html); | |
2406 | |
1 | 2407 gdk_window_get_size(html->html_area, NULL, &height); |
12 | 2408 gtk_adjustment_set_value(html->vadj, html->vadj->upper - height); |
1 | 2409 |
2410 } | |
2411 | |
12 | 2412 static GdkGC *create_bg_gc(GtkHtml * html) |
1 | 2413 { |
12 | 2414 GdkGCValues values; |
2415 | |
2416 values.tile = GTK_WIDGET(html)->style->bg_pixmap[GTK_STATE_NORMAL]; | |
2417 values.fill = GDK_TILED; | |
2418 | |
2419 return gdk_gc_new_with_values(html->html_area, &values, | |
2420 GDK_GC_FILL | GDK_GC_TILE); | |
1 | 2421 } |
2422 | |
12 | 2423 static void clear_area(GtkHtml * html, GdkRectangle * area) |
1 | 2424 { |
12 | 2425 GtkWidget *widget = GTK_WIDGET(html); |
2426 gint x, | |
2427 y; | |
2428 | |
2429 | |
2430 if (html->transparent) | |
2431 { | |
1 | 2432 if (html->pm == NULL) |
2433 html->pm = get_desktop_pixmap(widget); | |
2434 | |
12 | 2435 if (html->pm == NULL) |
2436 return; | |
2437 | |
2438 if (html->bg_gc == NULL) | |
2439 { | |
2440 GdkGCValues values; | |
2441 | |
2442 values.tile = html->pm; | |
2443 values.fill = GDK_TILED; | |
2444 | |
2445 html->bg_gc = gdk_gc_new_with_values(html->html_area, &values, | |
2446 GDK_GC_FILL | GDK_GC_TILE); | |
2447 | |
2448 } | |
2449 | |
1 | 2450 gdk_window_get_deskrelative_origin(html->html_area, &x, &y); |
2451 | |
12 | 2452 gdk_draw_pixmap(html->html_area, html->bg_gc, html->pm, |
2453 x + area->x, y + area->y, area->x, area->y, area->width, | |
2454 area->height); | |
1 | 2455 |
2456 return; | |
2457 | |
2458 } | |
12 | 2459 if (html->bg_gc) |
2460 { | |
2461 | |
2462 gint width, | |
2463 height; | |
2464 | |
2465 gdk_window_get_size(widget->style->bg_pixmap[GTK_STATE_NORMAL], &width, | |
2466 &height); | |
2467 | |
2468 gdk_gc_set_ts_origin(html->bg_gc, | |
2469 (-html->xoffset) % width, | |
2470 (-html->yoffset) % height); | |
2471 | |
2472 gdk_draw_rectangle(html->html_area, html->bg_gc, TRUE, | |
2473 area->x, area->y, area->width, area->height); | |
2474 } | |
2475 else | |
2476 gdk_window_clear_area(html->html_area, area->x, area->y, area->width, | |
2477 area->height); | |
1 | 2478 } |
2479 | |
2480 | |
2481 | |
2482 | |
12 | 2483 static void gtk_html_destroy(GtkObject * object) |
1 | 2484 { |
12 | 2485 GtkHtml *html; |
2486 | |
2487 g_return_if_fail(object != NULL); | |
2488 g_return_if_fail(GTK_IS_HTML(object)); | |
2489 | |
2490 html = (GtkHtml *) object; | |
2491 | |
2492 | |
2493 gtk_signal_disconnect_by_data(GTK_OBJECT(html->hadj), html); | |
2494 gtk_signal_disconnect_by_data(GTK_OBJECT(html->vadj), html); | |
2495 | |
2496 if (html->timer) | |
2497 { | |
2498 gtk_timeout_remove(html->timer); | |
2499 html->timer = 0; | |
1 | 2500 } |
2501 | |
12 | 2502 if (html->tooltip_timer) |
2503 { | |
2504 gtk_timeout_remove(html->tooltip_timer); | |
1 | 2505 html->tooltip_timer = -1; |
2506 } | |
2507 | |
12 | 2508 |
2509 GTK_OBJECT_CLASS(parent_class)->destroy(object); | |
2510 | |
1 | 2511 } |
2512 | |
12 | 2513 static void gtk_html_finalize(GtkObject * object) |
1 | 2514 { |
12 | 2515 GList *hbits; |
2516 GtkHtml *html; | |
1 | 2517 GtkHtmlBit *hb; |
2518 | |
2519 | |
12 | 2520 g_return_if_fail(object != NULL); |
2521 g_return_if_fail(GTK_IS_HTML(object)); | |
2522 | |
2523 html = (GtkHtml *) object; | |
2524 | |
2525 gtk_object_unref(GTK_OBJECT(html->hadj)); | |
2526 gtk_object_unref(GTK_OBJECT(html->vadj)); | |
2527 | |
2528 hbits = html->html_bits; | |
2529 | |
2530 while (hbits) | |
2531 { | |
2532 hb = (GtkHtmlBit *) hbits->data; | |
2533 if (hb->fore) | |
2534 gdk_color_free(hb->fore); | |
2535 if (hb->back) | |
2536 gdk_color_free(hb->back); | |
2537 if (hb->text) | |
2538 g_free(hb->text); | |
2539 if (hb->url) | |
2540 g_free(hb->url); | |
2541 if (hb->pm) | |
2542 gdk_pixmap_unref(hb->pm); | |
2543 | |
2544 g_free(hb); | |
2545 hbits = hbits->next; | |
2546 } | |
2547 if (html->html_bits) | |
2548 g_list_free(html->html_bits); | |
2549 | |
2550 if (html->urls) | |
2551 g_list_free(html->urls); | |
2552 | |
2553 if (html->selected_text) | |
2554 g_free(html->selected_text); | |
2555 | |
2556 if (html->gc) | |
2557 gdk_gc_destroy(html->gc); | |
2558 | |
2559 if (html->bg_gc) | |
2560 gdk_gc_destroy(html->bg_gc); | |
1 | 2561 |
2562 if (html->tooltip_window) | |
2563 gtk_widget_destroy(html->tooltip_window); | |
12 | 2564 |
2565 GTK_OBJECT_CLASS(parent_class)->finalize(object); | |
1 | 2566 } |
2567 | |
12 | 2568 static void gtk_html_realize(GtkWidget * widget) |
1 | 2569 { |
12 | 2570 GtkHtml *html; |
2571 GdkWindowAttr attributes; | |
2572 gint attributes_mask; | |
2573 | |
2574 g_return_if_fail(widget != NULL); | |
2575 g_return_if_fail(GTK_IS_HTML(widget)); | |
2576 | |
2577 html = GTK_HTML(widget); | |
2578 GTK_WIDGET_SET_FLAGS(html, GTK_REALIZED); | |
2579 | |
2580 attributes.window_type = GDK_WINDOW_CHILD; | |
2581 attributes.x = widget->allocation.x; | |
2582 attributes.y = widget->allocation.y; | |
2583 attributes.width = widget->allocation.width; | |
2584 attributes.height = widget->allocation.height; | |
2585 attributes.wclass = GDK_INPUT_OUTPUT; | |
2586 attributes.visual = gtk_widget_get_visual(widget); | |
2587 attributes.colormap = gtk_widget_get_colormap(widget); | |
2588 attributes.event_mask = gtk_widget_get_events(widget); | |
2589 attributes.event_mask |= (GDK_EXPOSURE_MASK | | |
2590 GDK_BUTTON_PRESS_MASK | | |
2591 GDK_BUTTON_RELEASE_MASK | | |
2592 GDK_BUTTON_MOTION_MASK | | |
2593 GDK_ENTER_NOTIFY_MASK | | |
2594 GDK_LEAVE_NOTIFY_MASK | | |
2595 GDK_POINTER_MOTION_MASK | | |
2596 GDK_POINTER_MOTION_HINT_MASK | | |
2597 GDK_VISIBILITY_NOTIFY_MASK | GDK_KEY_PRESS_MASK); | |
2598 | |
2599 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; | |
2600 | |
2601 widget->window = | |
2602 gdk_window_new(gtk_widget_get_parent_window(widget), &attributes, | |
2603 attributes_mask); | |
2604 gdk_window_set_user_data(widget->window, html); | |
2605 | |
2606 attributes.x = (widget->style->klass->xthickness + BORDER_WIDTH); | |
2607 attributes.y = (widget->style->klass->ythickness + BORDER_WIDTH); | |
2608 attributes.width = | |
2609 MAX(1, (gint) widget->allocation.width - (gint) attributes.x * 2); | |
2610 attributes.height = | |
2611 MAX(1, (gint) widget->allocation.height - (gint) attributes.y * 2); | |
2612 | |
2613 html->html_area = | |
2614 gdk_window_new(widget->window, &attributes, attributes_mask); | |
2615 gdk_window_set_user_data(html->html_area, html); | |
2616 | |
2617 widget->style = gtk_style_attach(widget->style, widget->window); | |
2618 | |
2619 /* | |
2620 * Can't call gtk_style_set_background here because it's handled specially | |
2621 */ | |
2622 gdk_window_set_background(widget->window, | |
2623 &widget->style->base[GTK_STATE_NORMAL]); | |
2624 gdk_window_set_background(html->html_area, | |
2625 &widget->style->base[GTK_STATE_NORMAL]); | |
2626 | |
2627 if (widget->style->bg_pixmap[GTK_STATE_NORMAL]) | |
2628 html->bg_gc = create_bg_gc(html); | |
2629 | |
2630 html->gc = gdk_gc_new(html->html_area); | |
2631 gdk_gc_set_exposures(html->gc, TRUE); | |
2632 gdk_gc_set_foreground(html->gc, &widget->style->text[GTK_STATE_NORMAL]); | |
2633 | |
2634 gdk_window_show(html->html_area); | |
1 | 2635 |
2636 } | |
2637 | |
12 | 2638 static void gtk_html_style_set(GtkWidget * widget, GtkStyle * previous_style) |
1 | 2639 { |
12 | 2640 GtkHtml *html; |
2641 | |
2642 g_return_if_fail(widget != NULL); | |
2643 g_return_if_fail(GTK_IS_HTML(widget)); | |
2644 | |
2645 html = GTK_HTML(widget); | |
2646 if (GTK_WIDGET_REALIZED(widget)) | |
2647 { | |
2648 gdk_window_set_background(widget->window, | |
2649 &widget->style->base[GTK_STATE_NORMAL]); | |
2650 gdk_window_set_background(html->html_area, | |
2651 &widget->style->base[GTK_STATE_NORMAL]); | |
2652 | |
2653 if (html->bg_gc) | |
2654 { | |
2655 gdk_gc_destroy(html->bg_gc); | |
2656 html->bg_gc = NULL; | |
2657 } | |
2658 | |
2659 if (widget->style->bg_pixmap[GTK_STATE_NORMAL]) | |
2660 { | |
2661 html->bg_gc = create_bg_gc(html); | |
2662 } | |
2663 | |
2664 } | |
1 | 2665 } |
2666 | |
12 | 2667 static void gtk_html_unrealize(GtkWidget * widget) |
1 | 2668 { |
12 | 2669 GtkHtml *html; |
2670 | |
2671 g_return_if_fail(widget != NULL); | |
2672 g_return_if_fail(GTK_IS_HTML(widget)); | |
2673 | |
2674 html = GTK_HTML(widget); | |
2675 | |
2676 gdk_window_set_user_data(html->html_area, NULL); | |
2677 gdk_window_destroy(html->html_area); | |
2678 html->html_area = NULL; | |
2679 | |
2680 gdk_gc_destroy(html->gc); | |
2681 html->gc = NULL; | |
2682 | |
2683 if (html->bg_gc) | |
2684 { | |
2685 gdk_gc_destroy(html->bg_gc); | |
2686 html->bg_gc = NULL; | |
2687 } | |
2688 | |
2689 if (GTK_WIDGET_CLASS(parent_class)->unrealize) | |
2690 (*GTK_WIDGET_CLASS(parent_class)->unrealize) (widget); | |
1 | 2691 } |
2692 | |
2693 | |
536
c9f994ea5833
[gaim-migrate @ 546]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
526
diff
changeset
|
2694 void gtk_html_add_pixmap(GtkHtml * html, GdkPixmap * pm, int fit, int newline) |
1 | 2695 { |
12 | 2696 GtkHtmlBit *last_hb; |
2697 GtkHtmlBit *hb = g_new0(GtkHtmlBit, 1); | |
2698 GdkWindowPrivate *private = (GdkWindowPrivate *) pm; | |
536
c9f994ea5833
[gaim-migrate @ 546]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
526
diff
changeset
|
2699 int width, height; |
12 | 2700 |
2701 last_hb = (GtkHtmlBit *) g_list_last(html->html_bits)->data; | |
1 | 2702 |
536
c9f994ea5833
[gaim-migrate @ 546]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
526
diff
changeset
|
2703 /* wrap pixmaps */ |
c9f994ea5833
[gaim-migrate @ 546]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
526
diff
changeset
|
2704 gdk_window_get_size(html->html_area, &width, &height); |
c9f994ea5833
[gaim-migrate @ 546]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
526
diff
changeset
|
2705 if ((html->current_x + private->width) >= width) { |
c9f994ea5833
[gaim-migrate @ 546]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
526
diff
changeset
|
2706 html->current_x = 0; |
c9f994ea5833
[gaim-migrate @ 546]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
526
diff
changeset
|
2707 } |
499
3ebd3ca4c3d4
[gaim-migrate @ 509]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
492
diff
changeset
|
2708 |
1 | 2709 hb->fit = fit; |
542
872d68495410
[gaim-migrate @ 552]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
540
diff
changeset
|
2710 html->current_x += 2; |
1 | 2711 hb->x = html->current_x; |
2712 hb->y = html->current_y; | |
12 | 2713 if (fit) |
1 | 2714 hb->height = last_hb->height; |
2715 else | |
2716 hb->height = private->height; | |
2717 hb->type = HTML_BIT_PIXMAP; | |
2718 hb->width = private->width; | |
2719 hb->text = NULL; | |
2720 hb->url = NULL; | |
2721 hb->fore = NULL; | |
2722 hb->back = NULL; | |
2723 hb->font = NULL; | |
12 | 2724 hb->uline = 0; |
2725 hb->strike = 0; | |
1 | 2726 hb->was_selected = 0; |
536
c9f994ea5833
[gaim-migrate @ 546]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
526
diff
changeset
|
2727 hb->newline = newline; |
12 | 2728 hb->pm = pm; |
2729 | |
2730 if (html->current_x == BORDER_WIDTH) | |
2731 { | |
540
f586c3819574
[gaim-migrate @ 550]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
537
diff
changeset
|
2732 html->current_y += hb->height + 3; |
f586c3819574
[gaim-migrate @ 550]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
537
diff
changeset
|
2733 hb->y += hb->height + 3; |
1 | 2734 } |
2735 | |
2736 | |
542
872d68495410
[gaim-migrate @ 552]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
540
diff
changeset
|
2737 html->current_x += hb->width + 1; |
12 | 2738 |
1 | 2739 gtk_html_draw_bit(html, hb, 1); |
2740 | |
536
c9f994ea5833
[gaim-migrate @ 546]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
526
diff
changeset
|
2741 if (hb->newline) |
c9f994ea5833
[gaim-migrate @ 546]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
526
diff
changeset
|
2742 html->current_x = 0; |
c9f994ea5833
[gaim-migrate @ 546]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
526
diff
changeset
|
2743 |
1 | 2744 html->html_bits = g_list_append(html->html_bits, hb); |
2745 | |
2746 | |
2747 } | |
2748 | |
12 | 2749 static void gtk_html_add_seperator(GtkHtml * html) |
1 | 2750 { |
12 | 2751 GtkHtmlBit *hb = g_new0(GtkHtmlBit, 1); |
2752 gint width, | |
2753 height; | |
2754 | |
1 | 2755 html->current_x = 0; |
2756 html->current_y += 5; | |
2757 | |
12 | 2758 gdk_window_get_size(html->html_area, &width, &height); |
2759 | |
1 | 2760 hb->x = html->current_x; |
2761 hb->y = html->current_y; | |
2762 hb->height = 5; | |
2763 hb->type = HTML_BIT_SEP; | |
12 | 2764 hb->width = |
2765 width - | |
2766 GTK_SCROLLED_WINDOW(GTK_WIDGET(html)->parent)->vscrollbar->allocation. | |
2767 width - 10; | |
1 | 2768 hb->text = NULL; |
2769 hb->url = NULL; | |
2770 hb->fore = NULL; | |
2771 hb->back = NULL; | |
2772 hb->font = NULL; | |
12 | 2773 hb->uline = 0; |
2774 hb->strike = 0; | |
1 | 2775 hb->was_selected = 0; |
12 | 2776 hb->newline = 0; |
2777 hb->pm = NULL; | |
1 | 2778 |
2779 gtk_html_draw_bit(html, hb, 1); | |
2780 | |
2781 html->html_bits = g_list_append(html->html_bits, hb); | |
2782 | |
2783 } | |
2784 | |
12 | 2785 static void gtk_html_add_text(GtkHtml * html, |
2786 GdkFont * cfont, | |
2787 GdkColor * fore, | |
2788 GdkColor * back, | |
2789 char *chars, | |
2790 gint length, gint uline, gint strike, char *url) | |
1 | 2791 { |
12 | 2792 char *nextline = NULL, |
2793 *c, | |
2794 *text, | |
2795 *tmp; | |
2796 GdkGC *gc; | |
2797 int nl = 0, | |
2798 nl2 = 0; | |
2799 int maxwidth; | |
2800 gint lb; | |
2801 GList *hbits; | |
79 | 2802 size_t num = 0; |
2803 int i, | |
12 | 2804 height; |
2805 GtkHtmlBit *hb; | |
2806 gint hwidth, | |
2807 hheight; | |
2808 | |
2809 if (length == 1 && chars[0] == '\n') | |
2810 { | |
2811 GtkHtmlBit *h; | |
2812 hbits = g_list_last(html->html_bits); | |
2813 if (!hbits) | |
2814 return; | |
2815 /* | |
2816 * I realize this loses a \n sometimes | |
2817 * * if it's the first thing in the widget. | |
2818 * * so fucking what. | |
2819 */ | |
2820 | |
2821 h = (GtkHtmlBit *) hbits->data; | |
2822 h->newline++; | |
2823 if (html->current_x > 0) | |
2824 html->current_x = 0; | |
2825 else | |
540
f586c3819574
[gaim-migrate @ 550]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
537
diff
changeset
|
2826 html->current_y += cfont->ascent + cfont->descent + 5; |
12 | 2827 return; |
2828 } | |
2829 | |
2830 | |
2831 | |
2832 c = text = g_malloc(length + 2); | |
2833 strncpy(text, chars, length); | |
2834 text[length] = 0; | |
2835 | |
2836 | |
2837 gc = html->gc; | |
2838 | |
2839 if (gc == NULL) | |
2840 gc = html->gc = gdk_gc_new(html->html_area); | |
2841 | |
2842 gdk_gc_set_font(gc, cfont); | |
2843 | |
2844 | |
2845 while (*c) | |
2846 { | |
2847 if (*c == '\n') | |
2848 { | |
2849 if (*(c + 1) == '\0') | |
2850 { | |
2851 nl = 1; | |
2852 length--; | |
2853 c[0] = '\0'; | |
2854 break; | |
2855 } | |
2856 if (*c) | |
2857 { | |
2858 gtk_html_add_text(html, cfont, fore, back, text, num + 1, uline, | |
2859 strike, url); | |
2860 tmp = text; | |
2861 length -= (num + 1); | |
2862 text = g_malloc(length + 2); | |
2863 strncpy(text, (c + 1), length); | |
2864 text[length] = 0; | |
2865 c = text; | |
2866 num = 0; | |
2867 g_free(tmp); | |
1 | 2868 continue; |
12 | 2869 } |
2870 } | |
2871 | |
2872 num++; | |
2873 c++; | |
2874 } | |
2875 | |
2876 /* | |
2877 * Note, yG is chosen because G is damn high, and y is damn low, | |
2878 */ | |
2879 /* | |
2880 * it should be just fine. :) | |
2881 */ | |
2882 | |
2883 gdk_window_get_size(html->html_area, &hwidth, &hheight); | |
2884 | |
2885 num = strlen(text); | |
2886 | |
2887 while (GTK_WIDGET(html)->allocation.width < 20) | |
2888 { | |
2889 while (gtk_events_pending()) | |
1 | 2890 gtk_main_iteration(); |
2891 } | |
2892 | |
12 | 2893 maxwidth = (hwidth - html->current_x - 8); |
2894 /* | |
2895 * HTK_SCROLLED_WINDOW(GTK_WIDGET(layout)->parent)->vscrollbar->allocation.width) - 8; | |
2896 */ | |
2897 | |
851
2cee5577224b
[gaim-migrate @ 861]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
850
diff
changeset
|
2898 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
|
2899 gdk_text_measure(cfont, text, num) < 0) { |
847
430a88eb4a68
[gaim-migrate @ 857]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
842
diff
changeset
|
2900 int pos = num / 2; |
842
2804dc8e9ba0
[gaim-migrate @ 852]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
829
diff
changeset
|
2901 static int count = 0; |
2804dc8e9ba0
[gaim-migrate @ 852]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
829
diff
changeset
|
2902 count ++; |
850
902be73a6a43
[gaim-migrate @ 860]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
847
diff
changeset
|
2903 while (pos < num && (!isspace(text[pos]) || text[pos] == '\n')) pos++; |
847
430a88eb4a68
[gaim-migrate @ 857]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
842
diff
changeset
|
2904 if (pos == num) { |
430a88eb4a68
[gaim-migrate @ 857]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
842
diff
changeset
|
2905 pos = num/2; |
850
902be73a6a43
[gaim-migrate @ 860]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
847
diff
changeset
|
2906 while (pos > 0 && (!isspace(text[pos]) || text[pos] == '\n')) pos--; |
847
430a88eb4a68
[gaim-migrate @ 857]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
842
diff
changeset
|
2907 if (!pos) pos = num / 2; |
430a88eb4a68
[gaim-migrate @ 857]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
842
diff
changeset
|
2908 } |
850
902be73a6a43
[gaim-migrate @ 860]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
847
diff
changeset
|
2909 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
|
2910 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
|
2911 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
|
2912 g_free(text); |
2804dc8e9ba0
[gaim-migrate @ 852]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
829
diff
changeset
|
2913 count--; |
2804dc8e9ba0
[gaim-migrate @ 852]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
829
diff
changeset
|
2914 if (!count) { |
853
050f244b6829
[gaim-migrate @ 863]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
852
diff
changeset
|
2915 /* 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
|
2916 hbits = g_list_last(html->html_bits); |
2804dc8e9ba0
[gaim-migrate @ 852]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
829
diff
changeset
|
2917 if (!hbits) return; /* does this ever happen? */ |
2804dc8e9ba0
[gaim-migrate @ 852]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
829
diff
changeset
|
2918 hb = (GtkHtmlBit *)hbits->data; |
850
902be73a6a43
[gaim-migrate @ 860]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
847
diff
changeset
|
2919 hb->newline++; |
842
2804dc8e9ba0
[gaim-migrate @ 852]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
829
diff
changeset
|
2920 } |
2804dc8e9ba0
[gaim-migrate @ 852]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
829
diff
changeset
|
2921 return; |
2804dc8e9ba0
[gaim-migrate @ 852]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
829
diff
changeset
|
2922 } |
2804dc8e9ba0
[gaim-migrate @ 852]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
829
diff
changeset
|
2923 |
12 | 2924 while (gdk_text_measure(cfont, text, num) > maxwidth) |
2925 { | |
2926 if (num > 1) | |
2927 num--; | |
2928 else | |
2929 { | |
26 | 2930 if (html->current_x != 0) { |
2931 html->current_x = 0; | |
2932 if (nl) { | |
2933 text[length] = '\n'; | |
2934 length++; | |
2935 } | |
2936 gtk_html_add_text(html, cfont, fore, back, text, length, uline, strike, url); | |
2937 g_free(text); | |
2938 return; | |
2939 } else { | |
2940 num = strlen (text); | |
2941 break; | |
1 | 2942 } |
2943 } | |
2944 | |
2945 } | |
2946 | |
12 | 2947 height = cfont->ascent + cfont->descent + 2; |
2948 | |
2949 | |
2950 if ((int) (html->vadj->upper - html->current_y) < (int) (height * 2)) | |
2951 { | |
2952 int val; | |
2953 val = (height * 2) + html->current_y; | |
2954 html->vadj->upper = val; | |
2955 adjust_adj(html, html->vadj); | |
1 | 2956 } |
2957 | |
12 | 2958 |
2959 if (html->current_x == 0) | |
2960 { | |
540
f586c3819574
[gaim-migrate @ 550]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
537
diff
changeset
|
2961 html->current_y += height + 3; |
12 | 2962 gdk_text_extents(cfont, text, 1, &lb, NULL, NULL, NULL, NULL); |
2963 html->current_x += (2 - lb); | |
2964 } | |
2965 else if ((hbits = g_list_last(html->html_bits)) != NULL) | |
2966 { | |
2967 int diff, | |
2968 y; | |
2969 hb = (GtkHtmlBit *) hbits->data; | |
2970 if (height > hb->height) | |
2971 { | |
1 | 2972 diff = height - hb->height; |
2973 y = hb->y; | |
2974 html->current_y += diff; | |
12 | 2975 while (hbits) |
2976 { | |
2977 hb = (GtkHtmlBit *) hbits->data; | |
1 | 2978 if (hb->y != y) |
12 | 2979 break; |
492
56399273ed8d
[gaim-migrate @ 502]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
481
diff
changeset
|
2980 if (hb->type != HTML_BIT_PIXMAP) |
56399273ed8d
[gaim-migrate @ 502]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
481
diff
changeset
|
2981 hb->height = height; |
12 | 2982 hb->y += diff; ////////////my thing here ///////////////// |
2983 gtk_html_draw_bit(html, hb, FALSE); | |
2984 | |
2985 hbits = hbits->prev; | |
1 | 2986 } |
2987 } | |
2988 } | |
2989 | |
2990 | |
2991 | |
2992 | |
12 | 2993 if (num != strlen(text)) |
2994 { | |
2995 /* | |
2996 * This is kinda cheesy but it may make things | |
2997 * * much better lookin | |
2998 */ | |
26 | 2999 |
842
2804dc8e9ba0
[gaim-migrate @ 852]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
829
diff
changeset
|
3000 for (i=2; (num > i); i++) { |
26 | 3001 if (text[num - i] == ' ') { |
12 | 3002 num = num - (i - 1); |
1 | 3003 nl2 = 1; |
3004 break; | |
3005 } | |
3006 } | |
3007 | |
3008 nextline = g_malloc(length - num + 2); | |
12 | 3009 strncpy(nextline, (char *) (text + num), length - num); |
1 | 3010 nextline[length - num] = 0; |
12 | 3011 if (nl) |
3012 { | |
1 | 3013 nextline[length - num] = '\n'; |
3014 nextline[length - num + 1] = 0; | |
3015 nl = 0; | |
3016 } | |
3017 | |
3018 | |
3019 text[num] = 0; | |
3020 } | |
3021 | |
3022 | |
52 | 3023 if (url != NULL) { |
53 | 3024 fore = get_color(3355647, gdk_window_get_colormap(html->html_area)); |
52 | 3025 } |
1 | 3026 |
3027 hb = g_new0(GtkHtmlBit, 1); | |
3028 | |
3029 hb->text = g_strdup(text); | |
3030 | |
52 | 3031 if (fore) |
3032 hb->fore = gdk_color_copy(fore); | |
3033 else | |
3034 hb->fore = NULL; | |
49 | 3035 |
1 | 3036 if (back) |
3037 hb->back = gdk_color_copy(back); | |
3038 else | |
3039 hb->back = NULL; | |
3040 hb->font = cfont; | |
3041 hb->uline = uline; | |
3042 hb->strike = strike; | |
3043 hb->height = height; | |
3044 gdk_text_extents(cfont, text, num, &lb, NULL, &hb->width, NULL, NULL); | |
3045 hb->x = html->current_x; | |
3046 hb->y = html->current_y; | |
12 | 3047 hb->type = HTML_BIT_TEXT; |
3048 hb->pm = NULL; | |
3049 if (url != NULL) | |
3050 { | |
1 | 3051 uline = 1; |
3052 hb->uline = 1; | |
3053 hb->url = g_strdup(url); | |
12 | 3054 } |
3055 else | |
3056 { | |
1 | 3057 hb->url = NULL; |
3058 } | |
3059 html->current_x += hb->width; | |
3060 | |
3061 html->html_bits = g_list_append(html->html_bits, hb); | |
12 | 3062 if (url != NULL) |
3063 { | |
3064 html->urls = g_list_append(html->urls, hb); | |
3065 } | |
3066 | |
3067 | |
3068 | |
3069 gtk_html_draw_bit(html, hb, 1); | |
3070 | |
3071 if (nl || nl2) | |
3072 { | |
3073 if (nl) | |
3074 hb->newline = 1; | |
3075 html->current_x = 0; | |
3076 } | |
3077 else | |
3078 hb->newline = 0; | |
3079 | |
3080 | |
3081 if (nextline != NULL) | |
3082 { | |
3083 gtk_html_add_text(html, cfont, fore, back, nextline, strlen(nextline), | |
3084 uline, strike, url); | |
3085 g_free(nextline); | |
3086 } | |
3087 | |
3088 g_free(text); | |
137 | 3089 if (url != NULL) |
3090 g_free(fore); | |
1 | 3091 } |
3092 | |
12 | 3093 static char * html_strtok( char * input, char delim ) |
1 | 3094 { |
12 | 3095 static char * end; |
3096 static char * curr_offset; | |
3097 int i; | |
3098 int num_quotes=0; | |
3099 | |
3100 if( input != NULL) | |
3101 { | |
3102 curr_offset = input; | |
3103 end = input+strlen(input); | |
3104 } | |
3105 else | |
3106 { | |
3107 if( curr_offset + strlen(curr_offset) < end ) | |
3108 { | |
3109 curr_offset += strlen(curr_offset) + 1; | |
3110 } | |
3111 else | |
3112 { | |
3113 return NULL; | |
3114 } | |
3115 } | |
3116 for( i=0; curr_offset+i < end && | |
3117 (curr_offset[i] != delim || num_quotes != 0) | |
3118 ; i++ ) | |
3119 { | |
3120 if( curr_offset[i] == '\"' ) | |
3121 { | |
3122 num_quotes = (num_quotes+1)%2; | |
3123 } | |
3124 } | |
3125 curr_offset[i] = '\0'; | |
3126 return curr_offset; | |
3127 } | |
3128 | |
3129 | |
3130 void gtk_html_append_text(GtkHtml * html, char *text, gint options) | |
3131 { | |
3132 GdkColormap *map; | |
1 | 3133 GdkFont *cfont; |
12 | 3134 GdkRectangle area; |
829
9a123b171f46
[gaim-migrate @ 839]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
791
diff
changeset
|
3135 char *ws, |
12 | 3136 tag[BUF_LONG], |
3137 *c, | |
3138 *url = NULL; | |
3139 gint intag = 0, | |
3140 wpos = 0, | |
481
64afc8f41bcb
[gaim-migrate @ 491]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
353
diff
changeset
|
3141 tpos = 0; |
64afc8f41bcb
[gaim-migrate @ 491]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
353
diff
changeset
|
3142 static gint colorv, |
12 | 3143 bold = 0, |
3144 italic = 0, | |
3145 fixed = 0, | |
3146 uline = 0, | |
3147 strike = 0, | |
481
64afc8f41bcb
[gaim-migrate @ 491]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
353
diff
changeset
|
3148 title = 0, |
64afc8f41bcb
[gaim-migrate @ 491]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
353
diff
changeset
|
3149 height; |
64afc8f41bcb
[gaim-migrate @ 491]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
353
diff
changeset
|
3150 static struct font_state *current = NULL, |
12 | 3151 *tmp; |
481
64afc8f41bcb
[gaim-migrate @ 491]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
353
diff
changeset
|
3152 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
|
3153 |
64afc8f41bcb
[gaim-migrate @ 491]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
353
diff
changeset
|
3154 if (text == NULL) { |
740
01d3c96867e2
[gaim-migrate @ 750]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
737
diff
changeset
|
3155 bold = 0; |
01d3c96867e2
[gaim-migrate @ 750]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
737
diff
changeset
|
3156 italic = 0; |
01d3c96867e2
[gaim-migrate @ 750]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
737
diff
changeset
|
3157 fixed = 0; |
01d3c96867e2
[gaim-migrate @ 750]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
737
diff
changeset
|
3158 uline = 0; |
01d3c96867e2
[gaim-migrate @ 750]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
737
diff
changeset
|
3159 strike = 0; |
01d3c96867e2
[gaim-migrate @ 750]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
737
diff
changeset
|
3160 title = 0; |
481
64afc8f41bcb
[gaim-migrate @ 491]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
353
diff
changeset
|
3161 while (current->next) |
64afc8f41bcb
[gaim-migrate @ 491]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
353
diff
changeset
|
3162 { |
64afc8f41bcb
[gaim-migrate @ 491]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
353
diff
changeset
|
3163 if (current->ownbg) |
64afc8f41bcb
[gaim-migrate @ 491]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
353
diff
changeset
|
3164 g_free(current->bgcol); |
64afc8f41bcb
[gaim-migrate @ 491]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
353
diff
changeset
|
3165 if (current->owncolor) |
64afc8f41bcb
[gaim-migrate @ 491]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
353
diff
changeset
|
3166 g_free(current->color); |
64afc8f41bcb
[gaim-migrate @ 491]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
353
diff
changeset
|
3167 tmp = current; |
64afc8f41bcb
[gaim-migrate @ 491]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
353
diff
changeset
|
3168 current = current->next; |
64afc8f41bcb
[gaim-migrate @ 491]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
353
diff
changeset
|
3169 g_free(tmp); |
64afc8f41bcb
[gaim-migrate @ 491]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
353
diff
changeset
|
3170 } |
64afc8f41bcb
[gaim-migrate @ 491]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
353
diff
changeset
|
3171 return; |
64afc8f41bcb
[gaim-migrate @ 491]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
353
diff
changeset
|
3172 } |
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 if (!current) current = &def_state; |
12 | 3175 map = gdk_window_get_colormap(html->html_area); |
3176 cfont = getfont(current->font, bold, italic, fixed, current->size); | |
1 | 3177 c = text; |
3178 | |
829
9a123b171f46
[gaim-migrate @ 839]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
791
diff
changeset
|
3179 ws = g_malloc(strlen(text) + 2); |
1 | 3180 |
12 | 3181 while (*c) |
3182 { | |
3183 if (*c == '<') | |
3184 { | |
3185 if (!intag) | |
3186 { | |
3187 ws[wpos] = 0; | |
3188 if (wpos) | |
3189 { | |
3190 if (title) | |
3191 { | |
3192 if (html->title) | |
3193 g_free(html->title); | |
3194 html->title = g_strdup(ws); | |
3195 } | |
3196 else | |
3197 gtk_html_add_text(html, cfont, current->color, | |
3198 current->bgcol, ws, strlen(ws), uline, | |
3199 strike, url); | |
3200 } | |
3201 wpos = 0; | |
3202 intag = 1; | |
3203 } | |
3204 else | |
3205 { | |
3206 /* | |
3207 * Assuming you NEVER have nested tags | |
3208 * * (and I mean <tag <tag>> by this, not | |
3209 * * <tag><tag2></tag2><tag>.. | |
3210 */ | |
3211 tag[tpos] = 0; | |
3212 gtk_html_add_text(html, cfont, current->color, current->bgcol, | |
3213 "<", 1, 0, 0, NULL); | |
3214 gtk_html_add_text(html, cfont, current->color, current->bgcol, | |
3215 tag, strlen(tag), 0, 0, NULL); | |
1 | 3216 tpos = 0; |
12 | 3217 |
3218 tag[0] = *c; | |
1 | 3219 } |
12 | 3220 } |
3221 else if (*c == '>') | |
3222 { | |
3223 if (intag) | |
3224 { | |
3225 tag[tpos] = 0; | |
1 | 3226 if (!strcasecmp(tag, "B")) |
3227 bold = 1; | |
732 | 3228 else if (!strcasecmp(tag, "STRIKE") || !strcasecmp(tag, "S")) |
1 | 3229 strike = 1; |
3230 else if (!strcasecmp(tag, "I")) | |
3231 italic = 1; | |
3232 else if (!strcasecmp(tag, "U")) | |
3233 uline = 1; | |
3234 else if (!strcasecmp(tag, "PRE")) | |
3235 fixed = 1; | |
3236 else if (!strcasecmp(tag, "HR")) | |
3237 gtk_html_add_seperator(html); | |
3238 else if (!strcasecmp(tag, "/B")) | |
3239 bold = 0; | |
732 | 3240 else if (!strcasecmp(tag, "/STRIKE") || !strcasecmp(tag, "/S")) |
1 | 3241 strike = 0; |
3242 else if (!strcasecmp(tag, "/I")) | |
3243 italic = 0; | |
3244 else if (!strcasecmp(tag, "/U")) | |
3245 uline = 0; | |
3246 else if (!strcasecmp(tag, "/PRE")) | |
3247 fixed = 0; | |
3248 else if (!strcasecmp(tag, "TITLE")) | |
3249 title = 1; | |
3250 else if (!strcasecmp(tag, "/TITLE")) | |
3251 title = 0; | |
12 | 3252 else if (!strncasecmp(tag, "IMG", 3)) |
3253 { | |
549 | 3254 GdkPixmap *legend_i; |
3255 GdkBitmap *legend_m; | |
3256 | |
3257 if (strstr(tag, "SRC=\"aol_icon.gif\"") != NULL) | |
3258 { | |
3259 legend_i = gdk_pixmap_create_from_xpm_d(GTK_WIDGET(html)->window, &legend_m, NULL, aol_icon_xpm); | |
3260 gtk_html_add_pixmap(html, legend_i, 0, 0); | |
3261 } | |
3262 | |
3263 if (strstr(tag, "SRC=\"admin_icon.gif\"") != NULL) | |
3264 { | |
3265 legend_i = gdk_pixmap_create_from_xpm_d(GTK_WIDGET(html)->window, &legend_m, NULL, admin_icon_xpm); | |
3266 gtk_html_add_pixmap(html, legend_i, 0, 0); | |
3267 } | |
3268 if (strstr(tag, "SRC=\"dt_icon.gif\"") != NULL) | |
3269 { | |
3270 legend_i = gdk_pixmap_create_from_xpm_d(GTK_WIDGET(html)->window, &legend_m, NULL, dt_icon_xpm); | |
3271 gtk_html_add_pixmap(html, legend_i, 0, 0); | |
3272 } | |
3273 if (strstr(tag, "SRC=\"free_icon.gif\"") != NULL) | |
3274 { | |
3275 legend_i = gdk_pixmap_create_from_xpm_d(GTK_WIDGET(html)->window, &legend_m, NULL, free_icon_xpm); | |
3276 gtk_html_add_pixmap(html, legend_i, 0, 0); | |
3277 } | |
12 | 3278 } |
3279 else if (!strcasecmp(tag, "H3")) | |
3280 { | |
1 | 3281 current = push_state(current); |
3282 current->size = 4; | |
12 | 3283 } |
3284 else if (!strcasecmp(tag, "/H3")) | |
3285 { | |
3286 gtk_html_add_text(html, cfont, current->color, | |
3287 current->bgcol, "\n", 1, 0, 0, NULL); | |
3288 | |
3289 if (current->next) | |
3290 { | |
1 | 3291 if (current->ownbg) |
3292 g_free(current->bgcol); | |
3293 if (current->owncolor) | |
3294 g_free(current->color); | |
12 | 3295 tmp = current; |
3296 current = current->next; | |
3297 g_free(tmp); | |
1 | 3298 } |
12 | 3299 } |
3300 else if (!strcasecmp(tag, "TABLE")) | |
3301 { | |
3302 } | |
3303 else if (!strcasecmp(tag, "/TABLE")) | |
3304 { | |
3305 } | |
3306 else if (!strcasecmp(tag, "TR")) | |
3307 { | |
3308 } | |
3309 else if (!strcasecmp(tag, "/TR")) | |
3310 { | |
3311 } | |
3312 else if (!strcasecmp(tag, "/TD")) | |
3313 { | |
3314 } | |
3315 else if (!strcasecmp(tag, "TD")) | |
3316 { | |
3317 gtk_html_add_text(html, cfont, current->color, | |
3318 current->bgcol, " ", 2, 0, 0, NULL); | |
3319 } | |
3320 else if (!strncasecmp(tag, "A ", 2)) | |
3321 { | |
1 | 3322 char *d; |
3323 char *temp = d = g_strdup(tag); | |
3324 int flag = 0; | |
12 | 3325 strtok(tag, " "); |
3326 while ((d = strtok(NULL, " "))) | |
3327 { | |
1 | 3328 if (strlen(d) < 7) |
3329 break; | |
12 | 3330 if (!strncasecmp(d, "HREF=\"", strlen("HREF=\""))) |
3331 { | |
3332 d += strlen("HREF=\""); | |
1 | 3333 d[strlen(d) - 1] = 0; |
3334 url = g_malloc(strlen(d) + 1); | |
3335 strcpy(url, d); | |
3336 flag = 1; | |
12 | 3337 } |
3338 } | |
1 | 3339 g_free(temp); |
12 | 3340 if (!flag) |
3341 { | |
3342 gtk_html_add_text(html, cfont, current->color, | |
3343 current->bgcol, "<", 1, 0, 0, NULL); | |
3344 gtk_html_add_text(html, cfont, current->color, | |
3345 current->bgcol, tag, strlen(tag), 0, | |
3346 0, NULL); | |
3347 gtk_html_add_text(html, cfont, current->color, | |
3348 current->bgcol, ">", 1, 0, 0, NULL); | |
1 | 3349 } |
12 | 3350 } |
3351 else if (!strcasecmp(tag, "/A")) | |
3352 { | |
3353 if (url) | |
3354 { | |
1 | 3355 g_free(url); |
3356 url = NULL; | |
3357 } | |
12 | 3358 } |
3359 else if (!strncasecmp(tag, "FONT", strlen("FONT"))) | |
3360 { | |
3361 char *d; | |
3362 /* | |
3363 * Push a new state onto the stack, based on the old state | |
3364 */ | |
3365 current = push_state(current); | |
3366 html_strtok(tag, ' '); | |
3367 while ((d = html_strtok(NULL, ' '))) | |
3368 { | |
3369 if (!strncasecmp(d, "COLOR=", strlen("COLOR="))) | |
3370 { | |
3371 d += strlen("COLOR="); | |
3372 if (*d == '\"') | |
3373 { | |
3374 d++; | |
3375 } | |
3376 if (*d == '#') | |
3377 d++; | |
3378 if (d[strlen(d) - 1] == '\"') | |
3379 d[strlen(d) - 1] = 0; | |
3380 if (sscanf(d, "%x", &colorv) | |
3381 && !(options & HTML_OPTION_NO_COLOURS)) | |
3382 { | |
677
05f6f7dabb7e
[gaim-migrate @ 687]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
674
diff
changeset
|
3383 current->color = get_color(colorv, map); |
05f6f7dabb7e
[gaim-migrate @ 687]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
674
diff
changeset
|
3384 current->owncolor = 1; |
12 | 3385 } |
3386 else | |
3387 { | |
1 | 3388 } |
12 | 3389 } |
3390 if (!strncasecmp(d, "FACE=", strlen("FACE="))) | |
3391 { | |
3392 d += strlen("FACE="); | |
3393 if (*d == '\"') | |
3394 { | |
3395 d++; | |
3396 } | |
1 | 3397 if (d[strlen(d) - 1] == '\"') |
3398 d[strlen(d) - 1] = 0; | |
12 | 3399 strcpy(current->font, d); |
3400 } | |
3401 else if (!strncasecmp(d, "BACK=", strlen("BACK="))) | |
3402 { | |
3403 d += strlen("BACK="); | |
3404 if (*d == '\"') | |
3405 d++; | |
3406 if (*d == '#') | |
3407 d++; | |
3408 if (d[strlen(d) - 1] == '\"') | |
3409 d[strlen(d) - 1] = 0; | |
3410 if (sscanf(d, "%x", &colorv) | |
3411 && !(options & HTML_OPTION_NO_COLOURS)) | |
3412 { | |
1 | 3413 current->bgcol = get_color(colorv, map); |
3414 current->ownbg = 1; | |
12 | 3415 } |
3416 else | |
3417 { | |
3418 } | |
3419 } | |
3420 else if (!strncasecmp(d, "SIZE=", strlen("SIZE="))) | |
3421 { | |
3422 d += strlen("SIZE="); | |
3423 if (*d == '\"') | |
3424 d++; | |
3425 if (*d == '+') | |
3426 d++; | |
3427 if (sscanf(d, "%d", &colorv)) | |
3428 { | |
3429 current->size = colorv; | |
3430 } | |
3431 else | |
3432 { | |
1 | 3433 } |
12 | 3434 } |
3435 else if (strncasecmp(d, "PTSIZE=", strlen("PTSIZE="))) | |
3436 { | |
3437 } | |
1 | 3438 } |
12 | 3439 } |
669
e871081839d0
[gaim-migrate @ 679]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
667
diff
changeset
|
3440 else if (!strncasecmp(tag, "BODY", strlen("BODY"))) |
12 | 3441 { |
3442 | |
669
e871081839d0
[gaim-migrate @ 679]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
667
diff
changeset
|
3443 char *d; |
632
21c63b26c604
[gaim-migrate @ 642]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
629
diff
changeset
|
3444 current = push_state(current); |
669
e871081839d0
[gaim-migrate @ 679]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
667
diff
changeset
|
3445 html_strtok(tag, ' '); |
e871081839d0
[gaim-migrate @ 679]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
667
diff
changeset
|
3446 while ((d = html_strtok(NULL, ' '))) |
12 | 3447 { |
669
e871081839d0
[gaim-migrate @ 679]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
667
diff
changeset
|
3448 if (!strncasecmp(d, "BGCOLOR=", strlen("BGCOLOR="))) |
e871081839d0
[gaim-migrate @ 679]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
667
diff
changeset
|
3449 { |
677
05f6f7dabb7e
[gaim-migrate @ 687]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
674
diff
changeset
|
3450 d += strlen("BGCOLOR="); |
669
e871081839d0
[gaim-migrate @ 679]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
667
diff
changeset
|
3451 if (*d == '\"') |
e871081839d0
[gaim-migrate @ 679]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
667
diff
changeset
|
3452 d++; |
e871081839d0
[gaim-migrate @ 679]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
667
diff
changeset
|
3453 if (*d == '#') |
e871081839d0
[gaim-migrate @ 679]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
667
diff
changeset
|
3454 d++; |
e871081839d0
[gaim-migrate @ 679]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
667
diff
changeset
|
3455 if (d[strlen(d) - 1] == '\"') |
e871081839d0
[gaim-migrate @ 679]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
667
diff
changeset
|
3456 d[strlen(d) - 1] = 0; |
e871081839d0
[gaim-migrate @ 679]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
667
diff
changeset
|
3457 if (sscanf(d, "%x", &colorv) |
e871081839d0
[gaim-migrate @ 679]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
667
diff
changeset
|
3458 && !(options & HTML_OPTION_NO_COLOURS)) |
e871081839d0
[gaim-migrate @ 679]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
667
diff
changeset
|
3459 { |
677
05f6f7dabb7e
[gaim-migrate @ 687]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
674
diff
changeset
|
3460 if (colorv != 0xffffff || |
669
e871081839d0
[gaim-migrate @ 679]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
667
diff
changeset
|
3461 !(display_options & OPT_DISP_IGN_WHITE)) { |
e871081839d0
[gaim-migrate @ 679]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
667
diff
changeset
|
3462 current->bgcol = get_color(colorv, map); |
e871081839d0
[gaim-migrate @ 679]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
667
diff
changeset
|
3463 current->ownbg = 1; |
e871081839d0
[gaim-migrate @ 679]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
667
diff
changeset
|
3464 } |
e871081839d0
[gaim-migrate @ 679]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
667
diff
changeset
|
3465 } |
667
45ed2ca0756e
[gaim-migrate @ 677]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
666
diff
changeset
|
3466 } |
12 | 3467 } |
3468 } | |
3469 else if (!strncasecmp(tag, "/FONT", strlen("/FONT"))) | |
3470 { | |
3471 /* | |
3472 * Pop a font state off the list if possible, freeing | |
3473 * any resources it used | |
3474 */ | |
3475 if (current->next) | |
3476 { | |
1 | 3477 if (current->ownbg) |
3478 g_free(current->bgcol); | |
3479 if (current->owncolor) | |
3480 g_free(current->color); | |
12 | 3481 tmp = current; |
3482 current = current->next; | |
3483 g_free(tmp); | |
3484 } | |
3485 | |
3486 } | |
3487 else if (!strcasecmp(tag, "/BODY")) | |
3488 { | |
3489 if (current->next) | |
3490 { | |
3491 if (current->ownbg) | |
3492 g_free(current->bgcol); | |
3493 if (current->owncolor) | |
3494 g_free(current->color); | |
3495 tmp = current; | |
3496 current = current->next; | |
1 | 3497 g_free(tmp); |
12 | 3498 } /* |
3499 * tags we ignore below | |
3500 */ | |
3501 } | |
3502 else if (!strncasecmp(tag, "BR", 2)) | |
3503 { | |
3504 gtk_html_add_text(html, cfont, current->color, | |
3505 current->bgcol, "\n", 1, 0, 0, NULL); | |
3506 } | |
3507 else if (strncasecmp(tag, "HTML", 4) | |
3508 && strncasecmp(tag, "/HTML", 5) | |
3509 && strncasecmp(tag, "BODY", 4) | |
3510 && strncasecmp(tag, "/BODY", 5) | |
627
da0a1238874d
[gaim-migrate @ 637]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
604
diff
changeset
|
3511 && (strncasecmp(tag, "P", 1) || tag[1] != '>') |
da0a1238874d
[gaim-migrate @ 637]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
604
diff
changeset
|
3512 && (strncasecmp(tag, "/P", 2) || tag[3] != '>') |
12 | 3513 && strncasecmp(tag, "HEAD", 4) |
3514 && strncasecmp(tag, "/HEAD", 5)) | |
3515 { | |
3516 if (tpos) | |
3517 { | |
3518 gtk_html_add_text(html, cfont, current->color, | |
3519 current->bgcol, "<", 1, 0, 0, NULL); | |
3520 gtk_html_add_text(html, cfont, current->color, | |
3521 current->bgcol, tag, strlen(tag), 0, | |
3522 0, NULL); | |
3523 gtk_html_add_text(html, cfont, current->color, | |
3524 current->bgcol, ">", 1, 0, 0, NULL); | |
1 | 3525 |
3526 } | |
3527 } | |
12 | 3528 cfont = getfont(current->font, bold, italic, fixed, current->size); |
3529 tpos = 0; | |
1 | 3530 intag = 0; |
3531 } | |
12 | 3532 else |
3533 { | |
1 | 3534 ws[wpos++] = *c; |
3535 } | |
12 | 3536 } |
3537 else if (!intag && *c == '&') | |
3538 { | |
3539 if (!strncasecmp(c, "&", 5)) | |
3540 { | |
3541 ws[wpos++] = '&'; | |
3542 c += 4; | |
3543 } | |
3544 else if (!strncasecmp(c, "<", 4)) | |
3545 { | |
3546 ws[wpos++] = '<'; | |
3547 c += 3; | |
3548 } | |
3549 else if (!strncasecmp(c, ">", 4)) | |
3550 { | |
3551 ws[wpos++] = '>'; | |
3552 c += 3; | |
3553 } | |
3554 else if (!strncasecmp(c, " ", 6)) | |
3555 { | |
3556 ws[wpos++] = ' '; | |
3557 c += 5; | |
3558 } | |
526
5bf71b39cba2
[gaim-migrate @ 536]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
523
diff
changeset
|
3559 else if (!strncasecmp(c, "©", 6)) |
5bf71b39cba2
[gaim-migrate @ 536]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
523
diff
changeset
|
3560 { |
5bf71b39cba2
[gaim-migrate @ 536]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
523
diff
changeset
|
3561 ws[wpos++] = '©'; |
5bf71b39cba2
[gaim-migrate @ 536]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
523
diff
changeset
|
3562 c += 5; |
5bf71b39cba2
[gaim-migrate @ 536]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
523
diff
changeset
|
3563 } |
737
c3a920cee3fc
[gaim-migrate @ 747]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
732
diff
changeset
|
3564 else if (!strncasecmp(c, """, 6)) |
c3a920cee3fc
[gaim-migrate @ 747]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
732
diff
changeset
|
3565 { |
c3a920cee3fc
[gaim-migrate @ 747]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
732
diff
changeset
|
3566 ws[wpos++] = '\"'; |
c3a920cee3fc
[gaim-migrate @ 747]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
732
diff
changeset
|
3567 c += 5; |
c3a920cee3fc
[gaim-migrate @ 747]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
732
diff
changeset
|
3568 } |
c3a920cee3fc
[gaim-migrate @ 747]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
732
diff
changeset
|
3569 else if (!strncasecmp(c, "®", 5)) |
c3a920cee3fc
[gaim-migrate @ 747]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
732
diff
changeset
|
3570 { |
c3a920cee3fc
[gaim-migrate @ 747]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
732
diff
changeset
|
3571 ws[wpos++] = 174; |
c3a920cee3fc
[gaim-migrate @ 747]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
732
diff
changeset
|
3572 c += 4; |
c3a920cee3fc
[gaim-migrate @ 747]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
732
diff
changeset
|
3573 } |
526
5bf71b39cba2
[gaim-migrate @ 536]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
523
diff
changeset
|
3574 else if (*(c + 1) == '#') |
5bf71b39cba2
[gaim-migrate @ 536]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
523
diff
changeset
|
3575 { |
5bf71b39cba2
[gaim-migrate @ 536]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
523
diff
changeset
|
3576 int pound = 0; |
5bf71b39cba2
[gaim-migrate @ 536]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
523
diff
changeset
|
3577 debug_print("got &#;\n"); |
5bf71b39cba2
[gaim-migrate @ 536]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
523
diff
changeset
|
3578 if (sscanf(c, "&#%d;", £) > 0) { |
5bf71b39cba2
[gaim-migrate @ 536]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
523
diff
changeset
|
3579 ws[wpos++] = (char)pound; |
5bf71b39cba2
[gaim-migrate @ 536]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
523
diff
changeset
|
3580 c += 2; |
5bf71b39cba2
[gaim-migrate @ 536]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
523
diff
changeset
|
3581 while (isdigit(*c)) c++; |
5bf71b39cba2
[gaim-migrate @ 536]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
523
diff
changeset
|
3582 if (*c != ';') c--; |
5bf71b39cba2
[gaim-migrate @ 536]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
523
diff
changeset
|
3583 } else { |
5bf71b39cba2
[gaim-migrate @ 536]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
523
diff
changeset
|
3584 ws[wpos++] = *c; |
5bf71b39cba2
[gaim-migrate @ 536]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
523
diff
changeset
|
3585 } |
5bf71b39cba2
[gaim-migrate @ 536]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
523
diff
changeset
|
3586 } |
12 | 3587 else |
3588 { | |
3589 ws[wpos++] = *c; | |
3590 } | |
3591 } | |
3592 else | |
3593 { | |
3594 if (intag) | |
3595 { | |
3596 tag[tpos++] = *c; | |
3597 } | |
3598 else | |
3599 { | |
3600 ws[wpos++] = *c; | |
1 | 3601 } |
3602 } | |
3603 c++; | |
3604 } | |
12 | 3605 ws[wpos] = 0; |
3606 tag[tpos] = 0; | |
3607 if (wpos) | |
3608 { | |
3609 gtk_html_add_text(html, cfont, current->color, current->bgcol, ws, | |
3610 strlen(ws), uline, strike, url); | |
1 | 3611 } |
12 | 3612 if (tpos) |
3613 { | |
3614 gtk_html_add_text(html, cfont, current->color, current->bgcol, "<", 1, | |
3615 0, 0, NULL); | |
3616 gtk_html_add_text(html, cfont, current->color, current->bgcol, tag, | |
3617 strlen(tag), 0, 0, NULL); | |
523
023c3851db0a
[gaim-migrate @ 533]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
506
diff
changeset
|
3618 /* gtk_html_add_text(html, cfont, current->color, current->bgcol, ">", 1, |
12 | 3619 0, 0, NULL); |
523
023c3851db0a
[gaim-migrate @ 533]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
506
diff
changeset
|
3620 */ } |
12 | 3621 |
3622 | |
829
9a123b171f46
[gaim-migrate @ 839]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
791
diff
changeset
|
3623 g_free(ws); |
12 | 3624 |
3625 gdk_window_get_size(html->html_area, NULL, &height); | |
3626 area.height = height; | |
1 | 3627 gtk_adjustment_set_value(html->vadj, html->vadj->upper - area.height); |
3628 | |
12 | 3629 return; |
1 | 3630 } |
3631 | |
3632 | |
12 | 3633 static void adjust_adj(GtkHtml * html, GtkAdjustment * adj) |
1 | 3634 { |
12 | 3635 gint height; |
3636 | |
3637 gdk_window_get_size(html->html_area, NULL, &height); | |
3638 | |
3639 adj->step_increment = MIN(adj->upper, (float) SCROLL_PIXELS); | |
3640 adj->page_increment = MIN(adj->upper, height - (float) KEY_SCROLL_PIXELS); | |
3641 adj->page_size = MIN(adj->upper, height); | |
3642 adj->value = MIN(adj->value, adj->upper - adj->page_size); | |
3643 adj->value = MAX(adj->value, 0.0); | |
3644 | |
3645 gtk_signal_emit_by_name(GTK_OBJECT(adj), "changed"); | |
1 | 3646 } |
3647 | |
3648 | |
12 | 3649 static void scroll_down(GtkHtml * html, gint diff0) |
1 | 3650 { |
12 | 3651 GdkRectangle rect; |
3652 gint width, | |
3653 height; | |
3654 | |
3655 html->yoffset += diff0; | |
3656 | |
3657 gdk_window_get_size(html->html_area, &width, &height); | |
3658 | |
3659 if (html->transparent) | |
3660 { | |
1 | 3661 rect.x = 0; |
3662 rect.y = 0; | |
3663 rect.width = width; | |
3664 rect.height = height; | |
12 | 3665 } |
3666 else | |
3667 { | |
3668 | |
1 | 3669 |
3670 if (height > diff0 && !html->transparent) | |
12 | 3671 gdk_draw_pixmap(html->html_area, |
3672 html->gc, | |
3673 html->html_area, | |
3674 0, diff0, 0, 0, width, height - diff0); | |
3675 | |
3676 rect.x = 0; | |
3677 rect.y = MAX(0, height - diff0); | |
3678 rect.width = width; | |
3679 rect.height = MIN(height, diff0); | |
1 | 3680 } |
12 | 3681 |
3682 expose_html(html, &rect, FALSE); | |
3683 gtk_html_draw_focus((GtkWidget *) html); | |
1 | 3684 |
3685 } | |
3686 | |
12 | 3687 static void scroll_up(GtkHtml * html, gint diff0) |
1 | 3688 { |
12 | 3689 GdkRectangle rect; |
3690 gint width, | |
3691 height; | |
3692 | |
1 | 3693 html->yoffset -= diff0; |
3694 | |
3695 | |
12 | 3696 gdk_window_get_size(html->html_area, &width, &height); |
3697 | |
3698 if (html->transparent) | |
3699 { | |
1 | 3700 rect.x = 0; |
3701 rect.y = 0; | |
3702 rect.width = width; | |
3703 rect.height = height; | |
12 | 3704 } |
3705 else | |
3706 { | |
3707 | |
1 | 3708 if (height > diff0) |
12 | 3709 gdk_draw_pixmap(html->html_area, |
3710 html->gc, | |
3711 html->html_area, | |
3712 0, 0, 0, diff0, width, height - diff0); | |
3713 | |
3714 rect.x = 0; | |
3715 rect.y = 0; | |
3716 rect.width = width; | |
3717 rect.height = MIN(height, diff0); | |
1 | 3718 } |
3719 | |
12 | 3720 expose_html(html, &rect, FALSE); |
3721 gtk_html_draw_focus((GtkWidget *) html); | |
1 | 3722 |
3723 } | |
3724 | |
3725 | |
3726 | |
12 | 3727 static void gtk_html_adjustment(GtkAdjustment * adjustment, GtkHtml * html) |
1 | 3728 { |
12 | 3729 g_return_if_fail(adjustment != NULL); |
3730 g_return_if_fail(GTK_IS_ADJUSTMENT(adjustment)); | |
3731 g_return_if_fail(html != NULL); | |
3732 g_return_if_fail(GTK_IS_HTML(html)); | |
3733 | |
3734 /* | |
3735 * Just ignore it if we haven't been size-allocated and realized yet | |
3736 */ | |
3737 if (html->html_area == NULL) | |
3738 return; | |
3739 | |
3740 if (adjustment == html->hadj) | |
3741 { | |
3742 g_warning("horizontal scrolling not implemented"); | |
3743 } | |
3744 else | |
3745 { | |
3746 gint diff = ((gint) adjustment->value) - html->last_ver_value; | |
3747 | |
3748 if (diff != 0) | |
3749 { | |
3750 /* | |
3751 * undraw_cursor (text, FALSE); | |
3752 */ | |
3753 | |
3754 if (diff > 0) | |
3755 { | |
3756 scroll_down(html, diff); | |
3757 } | |
3758 else | |
3759 { /* | |
3760 * if (diff < 0) | |
3761 */ | |
3762 scroll_up(html, -diff); | |
3763 } | |
3764 /* | |
3765 * draw_cursor (text, FALSE); | |
3766 */ | |
3767 | |
3768 html->last_ver_value = adjustment->value; | |
3769 } | |
3770 } | |
1 | 3771 } |
12 | 3772 |
3773 static gint gtk_html_visibility_notify(GtkWidget * widget, | |
3774 GdkEventVisibility * event) | |
1 | 3775 { |
3776 GtkHtml *html; | |
3777 GdkRectangle rect; | |
12 | 3778 gint width, |
3779 height; | |
3780 | |
3781 g_return_val_if_fail(widget != NULL, FALSE); | |
3782 g_return_val_if_fail(GTK_IS_HTML(widget), FALSE); | |
3783 | |
3784 html = GTK_HTML(widget); | |
3785 | |
3786 if (GTK_WIDGET_REALIZED(widget) && html->transparent) | |
3787 { | |
3788 gdk_window_get_size(html->html_area, &width, &height); | |
3789 rect.x = 0; | |
3790 rect.y = 0; | |
3791 rect.width = width; | |
3792 rect.height = height; | |
3793 expose_html(html, &rect, FALSE); | |
3794 gtk_html_draw_focus((GtkWidget *) html); | |
3795 } | |
3796 else | |
3797 { | |
1 | 3798 } |
3799 | |
3800 | |
12 | 3801 return FALSE; |
1 | 3802 } |
3803 | |
3804 | |
3805 | |
12 | 3806 static void gtk_html_disconnect(GtkAdjustment * adjustment, GtkHtml * html) |
1 | 3807 { |
12 | 3808 g_return_if_fail(adjustment != NULL); |
3809 g_return_if_fail(GTK_IS_ADJUSTMENT(adjustment)); | |
3810 g_return_if_fail(html != NULL); | |
3811 g_return_if_fail(GTK_IS_HTML(html)); | |
3812 | |
3813 if (adjustment == html->hadj) | |
3814 gtk_html_set_adjustments(html, NULL, html->vadj); | |
3815 if (adjustment == html->vadj) | |
3816 gtk_html_set_adjustments(html, html->hadj, NULL); | |
1 | 3817 } |
3818 | |
12 | 3819 static void move_cursor_ver(GtkHtml * html, int count) |
1 | 3820 { |
3821 GList *hbits = g_list_find(html->html_bits, html->cursor_hb); | |
12 | 3822 GtkHtmlBit *hb = NULL, |
3823 *hb2 = NULL; | |
1 | 3824 gint y; |
79 | 3825 size_t len, |
12 | 3826 len2 = 0; |
3827 | |
1 | 3828 undraw_cursor(html); |
3829 | |
3830 if (!html->html_bits) | |
3831 return; | |
12 | 3832 |
1 | 3833 if (!html->cursor_hb) |
12 | 3834 html->cursor_hb = (GtkHtmlBit *) html->html_bits->data; |
1 | 3835 |
3836 hb = html->cursor_hb; | |
3837 | |
3838 len = html->cursor_pos; | |
3839 hbits = hbits->prev; | |
12 | 3840 while (hbits) |
3841 { | |
3842 hb2 = (GtkHtmlBit *) hbits->data; | |
1 | 3843 |
3844 if (hb2->y != hb->y) | |
3845 break; | |
3846 | |
12 | 3847 len += strlen(hb2->text); |
3848 | |
1 | 3849 hbits = hbits->prev; |
3850 } | |
3851 | |
12 | 3852 hbits = g_list_find(html->html_bits, html->cursor_hb); |
3853 | |
3854 if (count < 0) | |
3855 { | |
3856 while (hbits) | |
3857 { | |
3858 hb2 = (GtkHtmlBit *) hbits->data; | |
1 | 3859 |
3860 if (hb2->y != hb->y) | |
3861 break; | |
12 | 3862 |
1 | 3863 hbits = hbits->prev; |
3864 } | |
12 | 3865 if (!hbits) |
3866 { | |
1 | 3867 draw_cursor(html); |
3868 return; | |
3869 } | |
3870 y = hb2->y; | |
3871 hb = hb2; | |
12 | 3872 while (hbits) |
3873 { | |
3874 hb2 = (GtkHtmlBit *) hbits->data; | |
1 | 3875 |
3876 if (hb2->y != y) | |
3877 break; | |
3878 | |
3879 hb = hb2; | |
12 | 3880 |
1 | 3881 hbits = hbits->prev; |
3882 } | |
3883 hbits = g_list_find(html->html_bits, hb); | |
12 | 3884 while (hbits) |
3885 { | |
3886 hb2 = (GtkHtmlBit *) hbits->data; | |
3887 | |
3888 if (hb->y != hb2->y) | |
3889 { | |
1 | 3890 html->cursor_hb = hb; |
3891 html->cursor_pos = strlen(hb->text); | |
12 | 3892 break; |
1 | 3893 } |
3894 | |
3895 | |
12 | 3896 if (len < len2 + strlen(hb2->text)) |
3897 { | |
1 | 3898 html->cursor_hb = hb2; |
3899 html->cursor_pos = len - len2; | |
3900 break; | |
3901 } | |
3902 | |
3903 len2 += strlen(hb2->text); | |
3904 | |
3905 hb = hb2; | |
3906 | |
12 | 3907 hbits = hbits->next; |
1 | 3908 } |
12 | 3909 } |
3910 else | |
3911 { | |
3912 while (hbits) | |
3913 { | |
3914 hb2 = (GtkHtmlBit *) hbits->data; | |
1 | 3915 |
3916 if (hb2->y != hb->y) | |
3917 break; | |
12 | 3918 |
1 | 3919 hbits = hbits->next; |
3920 } | |
12 | 3921 if (!hbits) |
3922 { | |
1 | 3923 draw_cursor(html); |
3924 return; | |
3925 } | |
3926 hb = hb2; | |
12 | 3927 while (hbits) |
3928 { | |
3929 hb2 = (GtkHtmlBit *) hbits->data; | |
3930 | |
3931 if (hb->y != hb2->y) | |
3932 { | |
1 | 3933 html->cursor_hb = hb; |
3934 html->cursor_pos = strlen(hb->text); | |
12 | 3935 break; |
1 | 3936 } |
3937 | |
3938 | |
12 | 3939 if (len < len2 + strlen(hb2->text)) |
3940 { | |
1 | 3941 html->cursor_hb = hb2; |
3942 html->cursor_pos = len - len2; | |
3943 break; | |
3944 } | |
3945 | |
3946 len2 += strlen(hb2->text); | |
3947 | |
3948 hb = hb2; | |
3949 | |
12 | 3950 hbits = hbits->next; |
1 | 3951 } |
3952 } | |
3953 | |
3954 draw_cursor(html); | |
3955 | |
3956 } | |
3957 | |
12 | 3958 static void move_cursor_hor(GtkHtml * html, int count) |
1 | 3959 { |
3960 GList *hbits = g_list_find(html->html_bits, html->cursor_hb); | |
12 | 3961 GtkHtmlBit *hb, |
3962 *hb2; | |
1 | 3963 |
3964 undraw_cursor(html); | |
3965 | |
3966 if (!html->html_bits) | |
3967 return; | |
12 | 3968 |
1 | 3969 if (!html->cursor_hb) |
12 | 3970 html->cursor_hb = (GtkHtmlBit *) html->html_bits->data; |
3971 | |
3972 html->cursor_pos += count; | |
3973 | |
3974 if (html->cursor_pos < 0) | |
3975 { | |
3976 if (hbits->prev) | |
3977 { | |
1 | 3978 gint diff; |
3979 hb = html->cursor_hb; | |
12 | 3980 hb2 = (GtkHtmlBit *) hbits->prev->data; |
1 | 3981 diff = html->cursor_pos + strlen(hb2->text) + 1; |
3982 if (hb->y == hb2->y) | |
3983 --diff; | |
12 | 3984 |
1 | 3985 html->cursor_pos = diff; |
12 | 3986 |
3987 html->cursor_hb = (GtkHtmlBit *) hbits->prev->data; | |
3988 } | |
3989 else | |
3990 { | |
1 | 3991 html->cursor_pos = 0; |
3992 } | |
12 | 3993 } |
79 | 3994 else if ((unsigned) html->cursor_pos > strlen(html->cursor_hb->text)) |
12 | 3995 { |
3996 if (hbits->next) | |
3997 { | |
1 | 3998 gint diff; |
3999 hb = html->cursor_hb; | |
12 | 4000 hb2 = (GtkHtmlBit *) hbits->next->data; |
1 | 4001 |
4002 diff = html->cursor_pos - strlen(html->cursor_hb->text) - 1; | |
4003 if (hb->y == hb2->y) | |
12 | 4004 ++diff; |
1 | 4005 html->cursor_pos = diff; |
12 | 4006 html->cursor_hb = (GtkHtmlBit *) hbits->next->data; |
4007 } | |
4008 else | |
4009 { | |
1 | 4010 html->cursor_pos = strlen(html->cursor_hb->text); |
4011 } | |
4012 | |
4013 } | |
4014 | |
4015 draw_cursor(html); | |
4016 } | |
4017 | |
12 | 4018 static void move_beginning_of_line(GtkHtml * html) |
1 | 4019 { |
4020 GList *hbits = g_list_find(html->html_bits, html->cursor_hb); | |
4021 GtkHtmlBit *hb = NULL; | |
12 | 4022 gint y; |
4023 | |
1 | 4024 undraw_cursor(html); |
4025 | |
4026 if (!html->html_bits) | |
4027 return; | |
4028 | |
4029 if (!html->cursor_hb) | |
12 | 4030 html->cursor_hb = (GtkHtmlBit *) html->html_bits->data; |
1 | 4031 |
4032 y = html->cursor_hb->y; | |
12 | 4033 |
4034 while (hbits) | |
4035 { | |
4036 hb = (GtkHtmlBit *) hbits->data; | |
4037 | |
4038 if (y != hb->y) | |
4039 { | |
4040 hb = (GtkHtmlBit *) hbits->next->data; | |
1 | 4041 break; |
4042 } | |
12 | 4043 |
1 | 4044 hbits = hbits->prev; |
4045 } | |
4046 if (!hbits) | |
12 | 4047 html->cursor_hb = (GtkHtmlBit *) html->html_bits->data; |
1 | 4048 else |
4049 html->cursor_hb = hb; | |
4050 | |
4051 html->cursor_pos = 0; | |
4052 | |
4053 | |
4054 draw_cursor(html); | |
4055 | |
4056 | |
4057 } | |
4058 | |
12 | 4059 static void move_end_of_line(GtkHtml * html) |
1 | 4060 { |
4061 GList *hbits = g_list_find(html->html_bits, html->cursor_hb); | |
4062 GtkHtmlBit *hb = NULL; | |
12 | 4063 gint y; |
4064 | |
1 | 4065 undraw_cursor(html); |
4066 | |
4067 if (!html->html_bits) | |
4068 return; | |
4069 | |
4070 if (!html->cursor_hb) | |
12 | 4071 html->cursor_hb = (GtkHtmlBit *) html->html_bits->data; |
1 | 4072 |
4073 y = html->cursor_hb->y; | |
12 | 4074 |
4075 while (hbits) | |
4076 { | |
4077 hb = (GtkHtmlBit *) hbits->data; | |
4078 | |
4079 if (y != hb->y) | |
4080 { | |
4081 hb = (GtkHtmlBit *) hbits->prev->data; | |
1 | 4082 break; |
4083 } | |
12 | 4084 |
1 | 4085 hbits = hbits->next; |
4086 } | |
4087 if (!hbits) | |
12 | 4088 html->cursor_hb = (GtkHtmlBit *) g_list_last(html->html_bits)->data; |
1 | 4089 else |
4090 html->cursor_hb = hb; | |
4091 | |
4092 html->cursor_pos = strlen(html->cursor_hb->text); | |
4093 | |
4094 | |
4095 draw_cursor(html); | |
4096 | |
4097 | |
4098 } | |
4099 | |
4100 | |
4101 | |
12 | 4102 static gint gtk_html_key_press(GtkWidget * widget, GdkEventKey * event) |
1 | 4103 { |
4104 GtkHtml *html; | |
4105 gchar key; | |
4106 gint return_val; | |
12 | 4107 |
4108 g_return_val_if_fail(widget != NULL, FALSE); | |
4109 g_return_val_if_fail(GTK_IS_HTML(widget), FALSE); | |
4110 g_return_val_if_fail(event != NULL, FALSE); | |
4111 | |
1 | 4112 return_val = FALSE; |
12 | 4113 |
4114 html = GTK_HTML(widget); | |
4115 | |
1 | 4116 key = event->keyval; |
4117 return_val = TRUE; | |
4118 | |
4119 | |
12 | 4120 if (html->editable == FALSE) |
4121 { | |
4122 /* | |
4123 * switch (event->keyval) { | |
4124 * case GDK_Home: | |
4125 * if (event->state & GDK_CONTROL_MASK) | |
4126 * scroll_int (text, -text->vadj->value); | |
4127 * else | |
4128 * return_val = FALSE; | |
4129 * break; | |
4130 * case GDK_End: | |
4131 * if (event->state & GDK_CONTROL_MASK) | |
4132 * scroll_int (text, +text->vadj->upper); | |
4133 * else | |
4134 * return_val = FALSE; | |
4135 * break; | |
4136 * case GDK_Page_Up: scroll_int (text, -text->vadj->page_increment); break; | |
4137 * case GDK_Page_Down: scroll_int (text, +text->vadj->page_increment); break; | |
4138 * case GDK_Up: scroll_int (text, -KEY_SCROLL_PIXELS); break; | |
4139 * case GDK_Down: scroll_int (text, +KEY_SCROLL_PIXELS); break; | |
4140 * case GDK_Return: | |
4141 * if (event->state & GDK_CONTROL_MASK) | |
4142 * gtk_signal_emit_by_name (GTK_OBJECT (text), "activate"); | |
4143 * else | |
4144 * return_val = FALSE; | |
4145 * break; | |
4146 * default: | |
4147 * return_val = FALSE; | |
4148 * break; | |
4149 * } | |
4150 */ | |
4151 } | |
4152 else | |
4153 { | |
4154 | |
4155 switch (event->keyval) | |
4156 { | |
1 | 4157 case GDK_Home: |
12 | 4158 move_beginning_of_line(html); |
1 | 4159 break; |
4160 case GDK_End: | |
12 | 4161 move_end_of_line(html); |
1 | 4162 break; |
4163 /* | |
12 | 4164 * case GDK_Page_Up: |
4165 * move_cursor_page_ver (html, -1); | |
4166 * break; | |
4167 * case GDK_Page_Down: | |
4168 * move_cursor_page_ver (html, +1); | |
4169 * break; | |
4170 */ | |
4171 /* | |
4172 * CUA has Ctrl-Up/Ctrl-Down as paragraph up down | |
4173 */ | |
1 | 4174 case GDK_Up: |
12 | 4175 move_cursor_ver(html, -1); |
1 | 4176 break; |
4177 case GDK_Down: | |
12 | 4178 move_cursor_ver(html, +1); |
1 | 4179 break; |
4180 case GDK_Left: | |
12 | 4181 move_cursor_hor(html, -1); |
1 | 4182 break; |
4183 case GDK_Right: | |
12 | 4184 move_cursor_hor(html, +1); |
1 | 4185 break; |
4186 #if 0 | |
4187 case GDK_BackSpace: | |
4188 if (event->state & GDK_CONTROL_MASK) | |
12 | 4189 gtk_text_delete_backward_word(text); |
1 | 4190 else |
12 | 4191 gtk_text_delete_backward_character(text); |
1 | 4192 break; |
4193 case GDK_Clear: | |
12 | 4194 gtk_text_delete_line(text); |
1 | 4195 break; |
4196 case GDK_Insert: | |
4197 if (event->state & GDK_SHIFT_MASK) | |
4198 { | |
4199 extend_selection = FALSE; | |
12 | 4200 gtk_editable_paste_clipboard(editable); |
1 | 4201 } |
4202 else if (event->state & GDK_CONTROL_MASK) | |
4203 { | |
12 | 4204 gtk_editable_copy_clipboard(editable); |
1 | 4205 } |
4206 else | |
4207 { | |
12 | 4208 /* |
4209 * gtk_toggle_insert(text) -- IMPLEMENT | |
4210 */ | |
1 | 4211 } |
4212 break; | |
4213 case GDK_Delete: | |
4214 if (event->state & GDK_CONTROL_MASK) | |
12 | 4215 gtk_text_delete_forward_word(text); |
1 | 4216 else if (event->state & GDK_SHIFT_MASK) |
4217 { | |
4218 extend_selection = FALSE; | |
12 | 4219 gtk_editable_cut_clipboard(editable); |
1 | 4220 } |
4221 else | |
12 | 4222 gtk_text_delete_forward_character(text); |
1 | 4223 break; |
4224 case GDK_Tab: | |
4225 position = text->point.index; | |
12 | 4226 gtk_editable_insert_text(editable, "\t", 1, &position); |
1 | 4227 break; |
4228 case GDK_Return: | |
4229 if (event->state & GDK_CONTROL_MASK) | |
12 | 4230 gtk_signal_emit_by_name(GTK_OBJECT(text), "activate"); |
1 | 4231 else |
4232 { | |
4233 position = text->point.index; | |
12 | 4234 gtk_editable_insert_text(editable, "\n", 1, &position); |
1 | 4235 } |
4236 break; | |
4237 case GDK_Escape: | |
12 | 4238 /* |
4239 * Don't insert literally | |
4240 */ | |
1 | 4241 return_val = FALSE; |
4242 break; | |
4243 #endif | |
4244 default: | |
4245 return_val = FALSE; | |
4246 | |
4247 #if 0 | |
12 | 4248 if (event->state & GDK_CONTROL_MASK) |
4249 { | |
1 | 4250 if ((key >= 'A') && (key <= 'Z')) |
4251 key -= 'A' - 'a'; | |
4252 | |
12 | 4253 if ((key >= 'a') && (key <= 'z') |
4254 && control_keys[(int) (key - 'a')]) | |
1 | 4255 { |
12 | 4256 (*control_keys[(int) (key - 'a')]) (editable, event->time); |
1 | 4257 return_val = TRUE; |
4258 } | |
4259 | |
4260 break; | |
4261 } | |
4262 else if (event->state & GDK_MOD1_MASK) | |
4263 { | |
4264 if ((key >= 'A') && (key <= 'Z')) | |
4265 key -= 'A' - 'a'; | |
4266 | |
4267 if ((key >= 'a') && (key <= 'z') && alt_keys[(int) (key - 'a')]) | |
4268 { | |
12 | 4269 (*alt_keys[(int) (key - 'a')]) (editable, event->time); |
1 | 4270 return_val = TRUE; |
4271 } | |
4272 break; | |
4273 } | |
4274 #endif | |
4275 /* | |
12 | 4276 * if (event->length > 0) { |
4277 * html->cursor_pos++; | |
4278 * gtk_editable_insert_text (editable, event->string, event->length, &position); | |
4279 * | |
4280 * return_val = TRUE; | |
4281 * } | |
4282 * else | |
4283 * return_val = FALSE; | |
4284 */ | |
1 | 4285 } |
4286 | |
4287 } | |
4288 | |
4289 return return_val; | |
4290 } | |
12 | 4291 |
4292 void gtk_html_freeze(GtkHtml * html) | |
1 | 4293 { |
12 | 4294 g_return_if_fail(html != NULL); |
4295 g_return_if_fail(GTK_IS_HTML(html)); | |
1 | 4296 |
4297 html->frozen++; | |
4298 } | |
4299 | |
12 | 4300 void gtk_html_thaw(GtkHtml * html) |
1 | 4301 { |
4302 GdkRectangle area; | |
12 | 4303 |
4304 g_return_if_fail(html != NULL); | |
4305 g_return_if_fail(GTK_IS_HTML(html)); | |
1 | 4306 |
481
64afc8f41bcb
[gaim-migrate @ 491]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
353
diff
changeset
|
4307 gtk_html_append_text(html, NULL, 0); |
64afc8f41bcb
[gaim-migrate @ 491]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
353
diff
changeset
|
4308 |
1 | 4309 html->frozen--; |
4310 | |
4311 if (html->frozen < 0) | |
12 | 4312 html->frozen = 0; |
4313 | |
4314 if (html->frozen == 0) | |
4315 { | |
4316 if (html->html_area) | |
4317 { | |
4318 gint width, | |
4319 height; | |
1 | 4320 area.x = 0; |
4321 area.y = 0; | |
4322 | |
4323 gdk_window_get_size(html->html_area, &width, &height); | |
4324 | |
12 | 4325 area.width = width; |
4326 area.height = height; | |
4327 | |
1 | 4328 expose_html(html, &area, TRUE); |
4329 } | |
4330 } | |
4331 } |