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