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