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