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