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