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