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