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