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