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