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