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