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