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