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