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