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