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