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