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