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