Sun, 28 Jan 2001 09:34:22 +0000
[gaim-migrate @ 1446]
this didn't bother me until *SOMEONE* pointed it out ;). and benjamin, if you read the gaim cvs logs, no, i haven't figured out what Qt's problem is, and I run at 75 dpi, not 100. but I bet kaim would look quite a bit different if you developed on my machine ;) Anyway, now close.xpm is only used once, and not for closing, despite the name.
| 1428 | 1 | /* |
| 2 | * GtkIMHtml | |
| 3 | * | |
| 4 | * Copyright (C) 2000, Eric Warmenhoven <warmenhoven@yahoo.com> | |
| 5 | * | |
| 6 | * This program is free software; you can redistribute it and/or modify | |
| 7 | * under the terms of the GNU General Public License as published by | |
| 8 | * the Free Software Foundation; either version 2 of the License, or | |
| 9 | * (at your option) any later version. | |
| 10 | * | |
| 11 | * This program is distributed in the hope that it will be useful, | |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | * GNU General Public License for more details. | |
| 15 | * | |
| 16 | * You should have received a copy of the GNU General Public License | |
| 17 | * along with this program; if not, write to the Free Software | |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 19 | * | |
| 20 | */ | |
| 21 | ||
| 22 | #include "gtkimhtml.h" | |
| 23 | #include <gtk/gtk.h> | |
| 24 | #include <string.h> | |
| 25 | #include <ctype.h> | |
| 26 | #include <stdio.h> | |
| 27 | #include <math.h> | |
| 28 | ||
| 29 | #include "pixmaps/angel.xpm" | |
| 30 | #include "pixmaps/bigsmile.xpm" | |
| 31 | #include "pixmaps/burp.xpm" | |
| 32 | #include "pixmaps/crossedlips.xpm" | |
| 33 | #include "pixmaps/cry.xpm" | |
| 34 | #include "pixmaps/embarrassed.xpm" | |
| 35 | #include "pixmaps/kiss.xpm" | |
| 36 | #include "pixmaps/moneymouth.xpm" | |
| 37 | #include "pixmaps/sad.xpm" | |
| 38 | #include "pixmaps/scream.xpm" | |
| 39 | #include "pixmaps/smile.xpm" | |
| 40 | #include "pixmaps/smile8.xpm" | |
| 41 | #include "pixmaps/think.xpm" | |
| 42 | #include "pixmaps/tongue.xpm" | |
| 43 | #include "pixmaps/wink.xpm" | |
| 44 | #include "pixmaps/yell.xpm" | |
| 45 | ||
| 46 | #define DEFAULT_FONT_NAME "helvetica" | |
| 47 | #define MAX_SIZE 7 | |
| 48 | ||
| 49 | gint font_sizes [] = { 80, 100, 120, 140, 200, 300, 400 }; | |
| 50 | ||
| 51 | #define BORDER_SIZE 3 | |
| 52 | #define MIN_HEIGHT 20 | |
| 53 | #define HR_HEIGHT 2 | |
| 54 | ||
| 55 | #define TYPE_TEXT 0 | |
| 56 | #define TYPE_SMILEY 1 | |
| 57 | #define TYPE_IMG 2 | |
| 58 | #define TYPE_SEP 3 | |
| 59 | #define TYPE_BR 4 | |
| 60 | #define TYPE_COMMENT 5 | |
| 61 | ||
| 62 | typedef struct _GtkIMHtmlBit GtkIMHtmlBit; | |
| 63 | typedef struct _FontDetail FontDetail; | |
| 64 | ||
| 65 | struct _GtkIMHtmlBit { | |
| 66 | gint type; | |
| 67 | ||
| 68 | gchar *text; | |
| 69 | GdkPixmap *pm; | |
| 70 | GdkBitmap *bm; | |
| 71 | ||
| 72 | GdkFont *font; | |
| 73 | GdkColor *fore; | |
| 74 | GdkColor *back; | |
| 75 | GdkColor *bg; | |
| 76 | gboolean underline; | |
| 77 | gboolean strike; | |
| 78 | gchar *url; | |
| 79 | ||
| 80 | GList *chunks; | |
| 81 | }; | |
| 82 | ||
| 83 | struct _FontDetail { | |
| 84 | gushort size; | |
| 85 | gchar *face; | |
| 86 | GdkColor *fore; | |
| 87 | GdkColor *back; | |
| 88 | }; | |
| 89 | ||
| 90 | struct line_info { | |
| 91 | gint x; | |
| 92 | gint y; | |
| 93 | gint width; | |
| 94 | gint height; | |
| 95 | gint ascent; | |
| 96 | ||
| 97 | gboolean selected; | |
| 98 | gchar *sel_start; | |
| 99 | gchar *sel_end; | |
| 100 | ||
| 101 | gchar *text; | |
| 102 | GtkIMHtmlBit *bit; | |
| 103 | }; | |
| 104 | ||
| 105 | struct url_widget { | |
| 106 | gint x; | |
| 107 | gint y; | |
| 108 | gint width; | |
| 109 | gint height; | |
| 110 | gchar *url; | |
| 111 | }; | |
| 112 | ||
| 113 | static GtkLayoutClass *parent_class = NULL; | |
| 114 | ||
| 115 | enum { | |
| 116 | TARGET_STRING, | |
| 117 | TARGET_TEXT, | |
| 118 | TARGET_COMPOUND_TEXT | |
| 119 | }; | |
| 120 | ||
| 121 | enum { | |
| 122 | URL_CLICKED, | |
| 123 | LAST_SIGNAL | |
| 124 | }; | |
| 125 | static guint signals [LAST_SIGNAL] = { 0 }; | |
| 126 | ||
| 127 | static void gtk_imhtml_draw_bit (GtkIMHtml *, GtkIMHtmlBit *); | |
| 128 | static GdkColor *gtk_imhtml_get_color (const gchar *); | |
| 129 | static gint gtk_imhtml_motion_notify_event (GtkWidget *, GdkEventMotion *); | |
| 130 | ||
| 131 | static void | |
| 132 | gtk_imhtml_destroy (GtkObject *object) | |
| 133 | { | |
| 134 | GtkIMHtml *imhtml; | |
| 135 | ||
| 136 | imhtml = GTK_IMHTML (object); | |
| 137 | ||
| 138 | while (imhtml->bits) { | |
| 139 | GtkIMHtmlBit *bit = imhtml->bits->data; | |
| 140 | imhtml->bits = g_list_remove (imhtml->bits, bit); | |
| 141 | if (bit->text) | |
| 142 | g_free (bit->text); | |
| 143 | if (bit->font) | |
| 144 | gdk_font_unref (bit->font); | |
| 145 | if (bit->fore) | |
| 146 | gdk_color_free (bit->fore); | |
| 147 | if (bit->back) | |
| 148 | gdk_color_free (bit->back); | |
| 149 | if (bit->bg) | |
| 150 | gdk_color_free (bit->bg); | |
| 151 | if (bit->url) | |
| 152 | g_free (bit->url); | |
| 153 | if (bit->pm) | |
| 154 | gdk_pixmap_unref (bit->pm); | |
| 155 | if (bit->bm) | |
| 156 | gdk_bitmap_unref (bit->bm); | |
| 157 | while (bit->chunks) { | |
| 158 | GtkObject *obj = bit->chunks->data; | |
| 159 | struct line_info *li = gtk_object_get_user_data (obj); | |
| 160 | if (li->text) | |
| 161 | g_free (li->text); | |
| 162 | g_free (li); | |
| 163 | bit->chunks = g_list_remove (bit->chunks, obj); | |
| 164 | } | |
| 165 | g_free (bit); | |
| 166 | } | |
| 167 | ||
| 168 | while (imhtml->urls) { | |
| 169 | g_free (imhtml->urls->data); | |
| 170 | imhtml->urls = g_list_remove (imhtml->urls, imhtml->urls->data); | |
| 171 | } | |
| 172 | ||
| 173 | if (imhtml->selected_text) | |
| 174 | g_string_free (imhtml->selected_text, TRUE); | |
| 175 | ||
| 176 | gdk_font_unref (imhtml->default_font); | |
| 177 | gdk_color_free (imhtml->default_fg_color); | |
| 178 | ||
| 179 | gdk_cursor_destroy (imhtml->hand_cursor); | |
| 180 | gdk_cursor_destroy (imhtml->arrow_cursor); | |
| 181 | ||
| 182 | g_hash_table_destroy (imhtml->smiley_hash); | |
| 183 | ||
| 184 | if (GTK_OBJECT_CLASS (parent_class)->destroy != NULL) | |
| 185 | (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); | |
| 186 | } | |
| 187 | ||
| 188 | static void | |
| 189 | gtk_imhtml_realize (GtkWidget *widget) | |
| 190 | { | |
| 191 | GtkIMHtml *imhtml; | |
| 192 | ||
| 193 | g_return_if_fail (widget != NULL); | |
| 194 | g_return_if_fail (GTK_IS_IMHTML (widget)); | |
| 195 | ||
| 196 | imhtml = GTK_IMHTML (widget); | |
| 197 | ||
| 198 | if (GTK_WIDGET_CLASS (parent_class)->realize) | |
| 199 | (* GTK_WIDGET_CLASS (parent_class)->realize) (widget); | |
| 200 | ||
| 201 | widget->style = gtk_style_attach (widget->style, widget->window); | |
| 202 | gdk_window_set_events (imhtml->layout.bin_window, | |
| 203 | (gdk_window_get_events (imhtml->layout.bin_window) | |
| 204 | | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | |
| 205 | | GDK_POINTER_MOTION_MASK | GDK_EXPOSURE_MASK)); | |
| 206 | ||
| 207 | gdk_window_set_cursor (widget->window, imhtml->arrow_cursor); | |
| 208 | ||
| 209 | gdk_window_set_background (GTK_LAYOUT (imhtml)->bin_window, >K_WIDGET (imhtml)->style->white); | |
| 210 | } | |
| 211 | ||
| 212 | static void | |
| 213 | gtk_imhtml_unrealize (GtkWidget *widget) | |
| 214 | { | |
| 215 | if (GTK_WIDGET_CLASS (parent_class)->unrealize) | |
| 216 | (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget); | |
| 217 | } | |
| 218 | ||
| 219 | static void | |
| 220 | gtk_imhtml_draw (GtkWidget *widget, | |
| 221 | GdkRectangle *area) | |
| 222 | { | |
| 223 | if (GTK_WIDGET_CLASS (parent_class)->draw) | |
| 224 | (* GTK_WIDGET_CLASS (parent_class)->draw) (widget, area); | |
| 225 | } | |
| 226 | ||
| 227 | static void | |
| 228 | gtk_imhtml_style_set (GtkWidget *widget, | |
| 229 | GtkStyle *style) | |
| 230 | { | |
| 231 | GtkIMHtml *imhtml; | |
| 232 | ||
| 233 | g_return_if_fail (widget != NULL); | |
| 234 | g_return_if_fail (GTK_IS_IMHTML (widget)); | |
| 235 | if (!GTK_WIDGET_REALIZED (widget)) | |
| 236 | return; | |
| 237 | ||
| 238 | imhtml = GTK_IMHTML (widget); | |
| 239 | ||
| 240 | gdk_window_set_background (GTK_LAYOUT (imhtml)->bin_window, >K_WIDGET (imhtml)->style->white); | |
| 241 | } | |
| 242 | ||
| 243 | static gint | |
| 244 | gtk_imhtml_expose (GtkWidget *widget, | |
| 245 | GdkEventExpose *event) | |
| 246 | { | |
| 247 | if (GTK_WIDGET_CLASS (parent_class)->expose_event) | |
| 248 | (* GTK_WIDGET_CLASS (parent_class)->expose_event) (widget, event); | |
| 249 | ||
| 250 | return TRUE; | |
| 251 | } | |
| 252 | ||
| 253 | static void | |
| 254 | gtk_imhtml_redraw_all (GtkIMHtml *imhtml) | |
| 255 | { | |
| 256 | GList *b; | |
| 257 | GtkIMHtmlBit *bit; | |
| 258 | GtkAdjustment *vadj; | |
| 259 | gfloat oldvalue; | |
| 260 | ||
| 261 | vadj = GTK_LAYOUT (imhtml)->vadjustment; | |
| 262 | oldvalue = vadj->value / vadj->upper; | |
| 263 | ||
| 264 | b = imhtml->bits; | |
| 265 | while (b) { | |
| 266 | bit = b->data; | |
| 267 | b = g_list_next (b); | |
| 268 | while (bit->chunks) { | |
| 269 | GtkObject *obj = bit->chunks->data; | |
| 270 | struct line_info *li = gtk_object_get_user_data (obj); | |
| 271 | if (li->text) | |
| 272 | g_free (li->text); | |
| 273 | g_free (li); | |
| 274 | bit->chunks = g_list_remove (bit->chunks, obj); | |
| 275 | } | |
| 276 | } | |
| 277 | ||
| 278 | g_list_free (imhtml->line); | |
| 279 | imhtml->line = NULL; | |
| 280 | ||
| 281 | while (imhtml->urls) { | |
| 282 | g_free (imhtml->urls->data); | |
| 283 | imhtml->urls = g_list_remove (imhtml->urls, imhtml->urls->data); | |
| 284 | } | |
| 285 | ||
| 286 | while (GTK_LAYOUT (imhtml)->children) | |
| 287 | gtk_container_remove (GTK_CONTAINER (imhtml), | |
| 288 | *(GtkWidget **)GTK_LAYOUT (imhtml)->children->data); | |
| 289 | ||
| 290 | imhtml->x = BORDER_SIZE; | |
| 291 | imhtml->y = BORDER_SIZE + 10; | |
| 292 | imhtml->llheight = 0; | |
| 293 | imhtml->llascent = 0; | |
| 294 | ||
| 295 | b = imhtml->bits; | |
| 296 | while (b) { | |
| 297 | gtk_imhtml_draw_bit (imhtml, b->data); | |
| 298 | b = g_list_next (b); | |
| 299 | } | |
| 300 | ||
| 301 | gtk_adjustment_set_value (vadj, vadj->upper * oldvalue); | |
| 302 | } | |
| 303 | ||
| 304 | static void | |
| 305 | gtk_imhtml_size_allocate (GtkWidget *widget, | |
| 306 | GtkAllocation *allocation) | |
| 307 | { | |
| 308 | GtkIMHtml *imhtml; | |
| 309 | ||
| 310 | g_return_if_fail (widget != NULL); | |
| 311 | g_return_if_fail (GTK_IS_IMHTML (widget)); | |
| 312 | g_return_if_fail (allocation != NULL); | |
| 313 | ||
| 314 | imhtml = GTK_IMHTML (widget); | |
| 315 | ||
| 316 | if (GTK_WIDGET_CLASS (parent_class)->size_allocate) | |
| 317 | ( *GTK_WIDGET_CLASS (parent_class)->size_allocate) (widget, allocation); | |
| 318 | ||
| 319 | if (allocation->width == imhtml->xsize) | |
| 320 | return; | |
| 321 | ||
| 322 | imhtml->x = BORDER_SIZE; | |
| 323 | imhtml->y = BORDER_SIZE + 10; | |
| 324 | imhtml->llheight = 0; | |
| 325 | imhtml->llascent = 0; | |
| 326 | ||
| 327 | imhtml->xsize = allocation->width; | |
| 328 | ||
| 329 | gtk_imhtml_redraw_all (imhtml); | |
| 330 | } | |
| 331 | ||
| 332 | static void | |
| 333 | gtk_imhtml_select_none (GtkIMHtml *imhtml) | |
| 334 | { | |
| 335 | GList *bits; | |
| 336 | GList *chunks; | |
| 337 | GtkIMHtmlBit *bit; | |
| 338 | struct line_info *chunk; | |
| 339 | GtkWidget *darea; | |
| 340 | ||
| 341 | g_return_if_fail (GTK_IS_IMHTML (imhtml)); | |
| 342 | ||
| 343 | bits = imhtml->bits; | |
| 344 | while (bits) { | |
| 345 | bit = bits->data; | |
| 346 | chunks = bit->chunks; | |
| 347 | ||
| 348 | while (chunks) { | |
| 349 | darea = chunks->data; | |
| 350 | chunk = gtk_object_get_user_data (GTK_OBJECT (darea)); | |
| 351 | ||
| 352 | if (chunk->selected) | |
| 353 | gtk_widget_queue_draw (darea); | |
| 354 | chunk->selected = FALSE; | |
| 355 | chunk->sel_start = chunk->sel_end = NULL; | |
| 356 | ||
| 357 | chunks = g_list_next (chunks); | |
| 358 | } | |
| 359 | ||
| 360 | bits = g_list_next (bits); | |
| 361 | } | |
| 362 | } | |
| 363 | ||
| 364 | static gchar* | |
| 365 | get_position (struct line_info *chunk, | |
| 366 | gint x, | |
| 367 | gboolean smileys) | |
| 368 | { | |
| 369 | gint width = x - chunk->x; | |
| 370 | gchar *text; | |
| 371 | gchar *pos; | |
| 372 | guint total = 0; | |
| 373 | ||
| 374 | switch (chunk->bit->type) { | |
| 375 | case TYPE_TEXT: | |
| 376 | case TYPE_COMMENT: | |
| 377 | text = chunk->text; | |
| 378 | break; | |
| 379 | case TYPE_SMILEY: | |
| 380 | if (smileys) | |
| 381 | return NULL; | |
| 382 | else | |
| 383 | text = chunk->text; | |
| 384 | break; | |
| 385 | default: | |
| 386 | return NULL; | |
| 387 | break; | |
| 388 | } | |
| 389 | ||
| 390 | if (width <= 0) | |
| 391 | return text; | |
| 392 | ||
| 393 | for (pos = text; *pos != '\0'; pos++) { | |
| 394 | gint char_width = gdk_text_width (chunk->bit->font, pos, 1); | |
| 395 | if ((width > total) && (width <= total + char_width)) { | |
| 396 | if (width < total + (char_width >> 1)) | |
| 397 | return pos; | |
| 398 | else | |
| 399 | return ++pos; | |
| 400 | } | |
| 401 | total += char_width; | |
| 402 | } | |
| 403 | ||
| 404 | return pos; | |
| 405 | } | |
| 406 | ||
| 407 | static GString* | |
| 408 | append_to_sel (GString *string, | |
| 409 | struct line_info *chunk, | |
| 410 | gboolean smileys) | |
| 411 | { | |
| 412 | GString *new_string; | |
| 413 | gchar *buf; | |
| 414 | gchar *start; | |
| 415 | gint length; | |
| 416 | ||
| 417 | switch (chunk->bit->type) { | |
| 418 | case TYPE_TEXT: | |
| 419 | case TYPE_COMMENT: | |
| 420 | start = (chunk->sel_start == NULL) ? chunk->text : chunk->sel_start; | |
| 421 | length = (chunk->sel_end == NULL) ? strlen (start) : chunk->sel_end - start; | |
| 422 | if (length <= 0) | |
| 423 | return string; | |
| 424 | buf = g_strndup (start, length); | |
| 425 | break; | |
| 426 | case TYPE_SMILEY: | |
| 427 | if (smileys) { | |
| 428 | start = (chunk->sel_start == NULL) ? chunk->bit->text : chunk->sel_start; | |
| 429 | length = (chunk->sel_end == NULL) ? strlen (start) : chunk->sel_end - start; | |
| 430 | if (length <= 0) | |
| 431 | return string; | |
| 432 | buf = g_strndup (start, length); | |
| 433 | } else { | |
| 434 | start = (chunk->sel_start == NULL) ? chunk->text : chunk->sel_start; | |
| 435 | length = (chunk->sel_end == NULL) ? strlen (start) : chunk->sel_end - start; | |
| 436 | if (length <= 0) | |
| 437 | return string; | |
| 438 | buf = g_strndup (start, length); | |
| 439 | } | |
| 440 | break; | |
| 441 | case TYPE_BR: | |
| 442 | buf = g_strdup ("\n"); | |
| 443 | break; | |
| 444 | default: | |
| 445 | return string; | |
| 446 | break; | |
| 447 | } | |
| 448 | ||
| 449 | new_string = g_string_append (string, buf); | |
| 450 | g_free (buf); | |
| 451 | ||
| 452 | return new_string; | |
| 453 | } | |
| 454 | ||
| 455 | #define COORDS_IN_CHUNK(xx, yy) (((xx) < chunk->x + chunk->width) && \ | |
| 456 | ((yy) < chunk->y + chunk->height)) | |
| 457 | ||
| 458 | static void | |
| 459 | gtk_imhtml_select_bits (GtkIMHtml *imhtml) | |
| 460 | { | |
| 461 | GList *bits; | |
| 462 | GList *chunks; | |
| 463 | GtkIMHtmlBit *bit; | |
| 464 | struct line_info *chunk; | |
| 465 | GtkWidget *darea; | |
| 466 | ||
| 467 | guint startx = imhtml->sel_startx, | |
| 468 | starty = imhtml->sel_starty, | |
| 469 | endx = imhtml->sel_endx, | |
| 470 | endy = imhtml->sel_endy; | |
| 471 | gchar *new_pos; | |
| 472 | gint selection = 0; | |
| 473 | gboolean smileys = imhtml->smileys; | |
| 474 | gboolean redraw = FALSE; | |
| 475 | gboolean got_start = FALSE; | |
| 476 | gboolean got_end = FALSE; | |
| 477 | ||
| 478 | g_return_if_fail (GTK_IS_IMHTML (imhtml)); | |
| 479 | ||
| 480 | if (!imhtml->selection) | |
| 481 | return; | |
| 482 | ||
| 483 | if (imhtml->selected_text) { | |
| 484 | g_string_free (imhtml->selected_text, TRUE); | |
| 485 | imhtml->selected_text = g_string_new (""); | |
| 486 | } | |
| 487 | ||
| 488 | bits = imhtml->bits; | |
| 489 | while (bits) { | |
| 490 | bit = bits->data; | |
| 491 | chunks = bit->chunks; | |
| 492 | ||
| 493 | while (chunks) { | |
| 494 | darea = chunks->data; | |
| 495 | chunk = gtk_object_get_user_data (GTK_OBJECT (darea)); | |
| 496 | ||
| 497 | switch (selection) { | |
| 498 | case 0: | |
| 499 | if (COORDS_IN_CHUNK (startx, starty)) { | |
| 500 | new_pos = get_position (chunk, startx, smileys); | |
| 501 | if ( !chunk->selected || | |
| 502 | (chunk->sel_start != new_pos) || | |
| 503 | (chunk->sel_end != NULL)) | |
| 504 | redraw = TRUE; | |
| 505 | chunk->selected = TRUE; | |
| 506 | chunk->sel_start = new_pos; | |
| 507 | chunk->sel_end = NULL; | |
| 508 | selection++; | |
| 509 | got_start = TRUE; | |
| 510 | } | |
| 511 | ||
| 512 | if (COORDS_IN_CHUNK (endx, endy)) { | |
| 513 | if (got_start) { | |
| 514 | new_pos = get_position (chunk, endx, smileys); | |
| 515 | if (chunk->sel_end != new_pos) | |
| 516 | redraw = TRUE; | |
| 517 | if (chunk->sel_start > new_pos) { | |
| 518 | chunk->sel_end = chunk->sel_start; | |
| 519 | chunk->sel_start = new_pos; | |
| 520 | } else | |
| 521 | chunk->sel_end = new_pos; | |
| 522 | selection = 2; | |
| 523 | got_end = TRUE; | |
| 524 | } else { | |
| 525 | new_pos = get_position (chunk, endx, smileys); | |
| 526 | if ( !chunk->selected || | |
| 527 | (chunk->sel_start != new_pos) || | |
| 528 | (chunk->sel_end != NULL)) | |
| 529 | redraw = TRUE; | |
| 530 | chunk->selected = TRUE; | |
| 531 | chunk->sel_start = new_pos; | |
| 532 | chunk->sel_end = NULL; | |
| 533 | selection++; | |
| 534 | got_end = TRUE; | |
| 535 | } | |
| 536 | } else if (!COORDS_IN_CHUNK (startx, starty) && !got_start) { | |
| 537 | if (chunk->selected) | |
| 538 | redraw = TRUE; | |
| 539 | chunk->selected = FALSE; | |
| 540 | chunk->sel_start = chunk->text; | |
| 541 | chunk->sel_end = NULL; | |
| 542 | } | |
| 543 | ||
| 544 | break; | |
| 545 | case 1: | |
| 546 | if (!got_start && COORDS_IN_CHUNK (startx, starty)) { | |
| 547 | new_pos = get_position (chunk, startx, smileys); | |
| 548 | if ( !chunk->selected || | |
| 549 | (chunk->sel_end != new_pos) || | |
| 550 | (chunk->sel_start != chunk->text)) | |
| 551 | redraw = TRUE; | |
| 552 | chunk->selected = TRUE; | |
| 553 | chunk->sel_start = chunk->text; | |
| 554 | chunk->sel_end = new_pos; | |
| 555 | selection++; | |
| 556 | got_start = TRUE; | |
| 557 | } else if (!got_end && COORDS_IN_CHUNK (endx, endy)) { | |
| 558 | new_pos = get_position (chunk, endx, smileys); | |
| 559 | if ( !chunk->selected || | |
| 560 | (chunk->sel_end != new_pos) || | |
| 561 | (chunk->sel_start != chunk->text)) | |
| 562 | redraw = TRUE; | |
| 563 | chunk->selected = TRUE; | |
| 564 | chunk->sel_start = chunk->text; | |
| 565 | chunk->sel_end = new_pos; | |
| 566 | selection++; | |
| 567 | got_end = TRUE; | |
| 568 | } else { | |
| 569 | if ( !chunk->selected || | |
| 570 | (chunk->sel_end != new_pos) || | |
| 571 | (chunk->sel_start != NULL)) | |
| 572 | redraw = TRUE; | |
| 573 | chunk->selected = TRUE; | |
| 574 | chunk->sel_start = chunk->text; | |
| 575 | chunk->sel_end = NULL; | |
| 576 | } | |
| 577 | ||
| 578 | break; | |
| 579 | case 2: | |
| 580 | if ( chunk->selected || | |
| 581 | (chunk->sel_start != chunk->text) || | |
| 582 | (chunk->sel_end != NULL)) | |
| 583 | redraw = TRUE; | |
| 584 | chunk->selected = FALSE; | |
| 585 | chunk->sel_start = chunk->text; | |
| 586 | chunk->sel_end = NULL; | |
| 587 | break; | |
| 588 | } | |
| 589 | ||
| 590 | if (chunk->selected == TRUE) | |
| 591 | imhtml->selected_text = append_to_sel (imhtml->selected_text, | |
| 592 | chunk, smileys); | |
| 593 | ||
| 594 | if (redraw) { | |
| 595 | gtk_widget_queue_draw (darea); | |
| 596 | redraw = FALSE; | |
| 597 | } | |
| 598 | ||
| 599 | chunks = g_list_next (chunks); | |
| 600 | } | |
| 601 | ||
| 602 | bits = g_list_next (bits); | |
| 603 | } | |
| 604 | } | |
| 605 | ||
| 606 | static gint | |
| 607 | scroll_timeout (GtkIMHtml *imhtml) | |
| 608 | { | |
| 609 | GdkEventMotion event; | |
| 610 | gint x, y; | |
| 611 | GdkModifierType mask; | |
| 612 | ||
| 613 | imhtml->scroll_timer = 0; | |
| 614 | ||
| 615 | gdk_window_get_pointer (imhtml->layout.bin_window, &x, &y, &mask); | |
| 616 | ||
| 617 | if (mask & GDK_BUTTON1_MASK) { | |
| 618 | event.is_hint = 0; | |
| 619 | event.x = x; | |
| 620 | event.y = y; | |
| 621 | event.state = mask; | |
| 622 | ||
| 623 | gtk_imhtml_motion_notify_event (GTK_WIDGET (imhtml), &event); | |
| 624 | } | |
| 625 | ||
| 626 | return FALSE; | |
| 627 | } | |
| 628 | ||
| 629 | static gint | |
| 630 | gtk_imhtml_motion_notify_event (GtkWidget *widget, | |
| 631 | GdkEventMotion *event) | |
| 632 | { | |
| 633 | gint x, y; | |
| 634 | GdkModifierType state; | |
| 635 | GtkIMHtml *imhtml = GTK_IMHTML (widget); | |
| 636 | GtkAdjustment *vadj = GTK_LAYOUT (widget)->vadjustment; | |
| 637 | GtkAdjustment *hadj = GTK_LAYOUT (widget)->hadjustment; | |
| 638 | ||
| 639 | if (event->is_hint) | |
| 640 | gdk_window_get_pointer (event->window, &x, &y, &state); | |
| 641 | else { | |
| 642 | x = event->x + hadj->value; | |
| 643 | y = event->y + vadj->value; | |
| 644 | state = event->state; | |
| 645 | } | |
| 646 | ||
| 647 | if (state & GDK_BUTTON1_MASK) { | |
| 648 | gint diff; | |
| 649 | gint height = vadj->page_size; | |
| 650 | gint yy = y - vadj->value; | |
| 651 | ||
| 652 | if (((yy < 0) || (yy > height)) && | |
| 653 | (imhtml->scroll_timer == 0) && | |
| 654 | (vadj->upper > vadj->page_size)) { | |
| 655 | imhtml->scroll_timer = gtk_timeout_add (100, | |
| 656 | (GtkFunction) scroll_timeout, | |
| 657 | imhtml); | |
| 658 | diff = (yy < 0) ? (yy >> 1) : ((yy - height) >> 1); | |
| 659 | gtk_adjustment_set_value (vadj, | |
| 660 | MIN (vadj->value + diff, vadj->upper - height + 20)); | |
| 661 | } | |
| 662 | ||
| 663 | if (imhtml->selection) { | |
| 664 | imhtml->sel_endx = MAX (x, 0); | |
| 665 | imhtml->sel_endy = MAX (y, 0); | |
| 666 | gtk_imhtml_select_bits (imhtml); | |
| 667 | } | |
| 668 | } else { | |
| 669 | GList *urls = imhtml->urls; | |
| 670 | struct url_widget *uw; | |
| 671 | ||
| 672 | while (urls) { | |
| 673 | uw = (struct url_widget *) urls->data; | |
| 674 | if ((x > uw->x) && (x < uw->x + uw->width) && | |
| 675 | (y > uw->y) && (y < uw->y + uw->height)) { | |
| 676 | gdk_window_set_cursor (imhtml->layout.bin_window, imhtml->hand_cursor); | |
| 677 | return TRUE; | |
| 678 | } | |
| 679 | urls = g_list_next (urls); | |
| 680 | } | |
| 681 | } | |
| 682 | ||
| 683 | gdk_window_set_cursor (imhtml->layout.bin_window, imhtml->arrow_cursor); | |
| 684 | ||
| 685 | return TRUE; | |
| 686 | } | |
| 687 | ||
| 688 | static gint | |
| 689 | gtk_imhtml_button_press_event (GtkWidget *widget, | |
| 690 | GdkEventButton *event) | |
| 691 | { | |
| 692 | GtkIMHtml *imhtml = GTK_IMHTML (widget); | |
| 693 | GtkAdjustment *vadj = GTK_LAYOUT (widget)->vadjustment; | |
| 694 | GtkAdjustment *hadj = GTK_LAYOUT (widget)->hadjustment; | |
| 695 | gint x, y; | |
| 696 | ||
| 697 | if (event->button == 1) { | |
| 698 | x = event->x + hadj->value; | |
| 699 | y = event->y + vadj->value; | |
| 700 | ||
| 701 | imhtml->sel_startx = x; | |
| 702 | imhtml->sel_starty = y; | |
| 703 | imhtml->selection = TRUE; | |
| 704 | gtk_imhtml_select_none (imhtml); | |
| 705 | } | |
| 706 | ||
| 707 | return TRUE; | |
| 708 | } | |
| 709 | ||
| 710 | static gint | |
| 711 | gtk_imhtml_button_release_event (GtkWidget *widget, | |
| 712 | GdkEventButton *event) | |
| 713 | { | |
| 714 | GtkIMHtml *imhtml = GTK_IMHTML (widget); | |
| 715 | GtkAdjustment *vadj = GTK_LAYOUT (widget)->vadjustment; | |
| 716 | GtkAdjustment *hadj = GTK_LAYOUT (widget)->hadjustment; | |
| 717 | gint x, y; | |
| 718 | ||
| 719 | if ((event->button == 1) && imhtml->selection) { | |
| 720 | x = event->x + hadj->value; | |
| 721 | y = event->y + vadj->value; | |
| 722 | ||
| 723 | if ((x == imhtml->sel_startx) && (y == imhtml->sel_starty)) { | |
| 724 | imhtml->sel_startx = imhtml->sel_starty = 0; | |
| 725 | imhtml->selection = FALSE; | |
| 726 | gtk_imhtml_select_none (imhtml); | |
| 727 | } else { | |
| 728 | imhtml->sel_endx = MAX (x, 0); | |
| 729 | imhtml->sel_endy = MAX (y, 0); | |
| 730 | gtk_imhtml_select_bits (imhtml); | |
| 731 | } | |
| 732 | ||
| 733 | gtk_selection_owner_set (widget, GDK_SELECTION_PRIMARY, event->time); | |
| 734 | } | |
| 735 | ||
| 736 | return TRUE; | |
| 737 | } | |
| 738 | ||
| 739 | static void | |
| 740 | gtk_imhtml_selection_get (GtkWidget *widget, | |
| 741 | GtkSelectionData *sel_data, | |
| 742 | guint sel_info, | |
| 743 | guint32 time) | |
| 744 | { | |
| 745 | GtkIMHtml *imhtml; | |
| 746 | gchar *string; | |
| 747 | gint length; | |
| 748 | ||
| 749 | g_return_if_fail (widget != NULL); | |
| 750 | g_return_if_fail (GTK_IS_IMHTML (widget)); | |
| 751 | g_return_if_fail (sel_data->selection == GDK_SELECTION_PRIMARY); | |
| 752 | ||
| 753 | imhtml = GTK_IMHTML (widget); | |
| 754 | ||
| 755 | g_return_if_fail (imhtml->selected_text != NULL); | |
| 756 | g_return_if_fail (imhtml->selected_text->str != NULL); | |
| 757 | ||
| 758 | if (imhtml->selected_text->len <= 0) { | |
| 759 | string = NULL; | |
| 760 | length = 0; | |
| 761 | } else { | |
| 762 | string = g_strdup (imhtml->selected_text->str); | |
| 763 | length = strlen (string); | |
| 764 | } | |
| 765 | ||
| 766 | if (sel_info == TARGET_STRING) { | |
| 767 | gtk_selection_data_set (sel_data, | |
| 768 | GDK_SELECTION_TYPE_STRING, | |
| 769 | 8 * sizeof (gchar), | |
| 770 | (guchar *) string, | |
| 771 | length); | |
| 772 | } else if ((sel_info == TARGET_TEXT) || (sel_info == TARGET_COMPOUND_TEXT)) { | |
| 773 | guchar *text; | |
| 774 | GdkAtom encoding; | |
| 775 | gint format; | |
| 776 | gint new_length; | |
| 777 | ||
| 778 | gdk_string_to_compound_text (string, &encoding, &format, &text, &new_length); | |
| 779 | gtk_selection_data_set (sel_data, encoding, format, text, new_length); | |
| 780 | gdk_free_compound_text (text); | |
| 781 | } | |
| 782 | ||
| 783 | if (string) | |
| 784 | g_free (string); | |
| 785 | } | |
| 786 | ||
| 787 | static gint | |
| 788 | gtk_imhtml_selection_clear_event (GtkWidget *widget, | |
| 789 | GdkEventSelection *event) | |
| 790 | { | |
| 791 | GtkIMHtml *imhtml; | |
| 792 | ||
| 793 | g_return_val_if_fail (widget != NULL, FALSE); | |
| 794 | g_return_val_if_fail (GTK_IS_IMHTML (widget), FALSE); | |
| 795 | g_return_val_if_fail (event != NULL, FALSE); | |
| 796 | g_return_val_if_fail (event->selection == GDK_SELECTION_PRIMARY, TRUE); | |
| 797 | ||
| 798 | if (!gtk_selection_clear (widget, event)) | |
| 799 | return FALSE; | |
| 800 | ||
| 801 | imhtml = GTK_IMHTML (widget); | |
| 802 | ||
| 803 | gtk_imhtml_select_none (imhtml); | |
| 804 | ||
| 805 | return TRUE; | |
| 806 | } | |
| 807 | ||
| 808 | static void | |
| 809 | gtk_imhtml_set_scroll_adjustments (GtkLayout *layout, | |
| 810 | GtkAdjustment *hadj, | |
| 811 | GtkAdjustment *vadj) | |
| 812 | { | |
| 813 | if (parent_class->set_scroll_adjustments) | |
| 814 | (* parent_class->set_scroll_adjustments) (layout, hadj, vadj); | |
| 815 | } | |
| 816 | ||
| 817 | static void | |
| 818 | gtk_imhtml_class_init (GtkIMHtmlClass *class) | |
| 819 | { | |
| 820 | GtkObjectClass *object_class; | |
| 821 | GtkWidgetClass *widget_class; | |
| 822 | GtkLayoutClass *layout_class; | |
| 823 | ||
| 824 | object_class = (GtkObjectClass*) class; | |
| 825 | widget_class = (GtkWidgetClass*) class; | |
| 826 | layout_class = (GtkLayoutClass*) class; | |
| 827 | ||
| 828 | parent_class = gtk_type_class (GTK_TYPE_LAYOUT); | |
| 829 | ||
| 830 | signals [URL_CLICKED] = | |
| 831 | gtk_signal_new ("url_clicked", | |
| 832 | GTK_RUN_FIRST, | |
| 833 | object_class->type, | |
| 834 | GTK_SIGNAL_OFFSET (GtkIMHtmlClass, url_clicked), | |
| 835 | gtk_marshal_NONE__POINTER, | |
| 836 | GTK_TYPE_NONE, 1, | |
| 837 | GTK_TYPE_POINTER); | |
| 838 | ||
| 839 | gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL); | |
| 840 | ||
| 841 | object_class->destroy = gtk_imhtml_destroy; | |
| 842 | ||
| 843 | widget_class->realize = gtk_imhtml_realize; | |
| 844 | widget_class->unrealize = gtk_imhtml_unrealize; | |
| 845 | widget_class->draw = gtk_imhtml_draw; | |
| 846 | widget_class->style_set = gtk_imhtml_style_set; | |
| 847 | widget_class->expose_event = gtk_imhtml_expose; | |
| 848 | widget_class->size_allocate = gtk_imhtml_size_allocate; | |
| 849 | widget_class->motion_notify_event = gtk_imhtml_motion_notify_event; | |
| 850 | widget_class->button_press_event = gtk_imhtml_button_press_event; | |
| 851 | widget_class->button_release_event = gtk_imhtml_button_release_event; | |
| 852 | widget_class->selection_get = gtk_imhtml_selection_get; | |
| 853 | widget_class->selection_clear_event = gtk_imhtml_selection_clear_event; | |
| 854 | ||
| 855 | layout_class->set_scroll_adjustments = gtk_imhtml_set_scroll_adjustments; | |
| 856 | } | |
| 857 | ||
| 858 | static GdkFont* | |
| 859 | gtk_imhtml_font_load (GtkIMHtml *imhtml, | |
| 860 | gchar *name, | |
| 861 | gboolean bold, | |
| 862 | gboolean italics, | |
| 863 | gint fontsize) | |
| 864 | { | |
| 865 | gchar buf [16 * 1024]; | |
| 866 | GdkFont *font; | |
| 867 | gint size = fontsize ? font_sizes [MIN (fontsize, MAX_SIZE) - 1] : 120; | |
| 868 | ||
| 869 | g_snprintf (buf, sizeof (buf), "-*-%s-%s-%c-*-*-*-%d-*-*-*-*-*-*", | |
| 870 | name ? name : DEFAULT_FONT_NAME, | |
| 871 | bold ? "bold" : "medium", | |
| 872 | italics ? 'i' : 'r', | |
| 873 | size); | |
| 874 | font = gdk_font_load (buf); | |
| 875 | if (font) | |
| 876 | return font; | |
| 877 | ||
| 878 | if (italics) { | |
| 879 | g_snprintf (buf, sizeof (buf), "-*-%s-%s-%c-*-*-*-%d-*-*-*-*-*-*", | |
| 880 | name ? name : DEFAULT_FONT_NAME, | |
| 881 | bold ? "bold" : "medium", | |
| 882 | 'o', | |
| 883 | size); | |
| 884 | font = gdk_font_load (buf); | |
| 885 | if (font) | |
| 886 | return font; | |
| 887 | ||
| 888 | if (bold) { | |
| 889 | g_snprintf (buf, sizeof (buf), "-*-%s-%s-%c-*-*-*-%d-*-*-*-*-*-*", | |
| 890 | name ? name : DEFAULT_FONT_NAME, | |
| 891 | "bold", | |
| 892 | 'r', | |
| 893 | size); | |
| 894 | font = gdk_font_load (buf); | |
| 895 | if (font) | |
| 896 | return font; | |
| 897 | } | |
| 898 | } | |
| 899 | ||
| 900 | if (bold) { | |
| 901 | g_snprintf (buf, sizeof (buf), "-*-%s-%s-%c-*-*-*-%d-*-*-*-*-*-*", | |
| 902 | name ? name : DEFAULT_FONT_NAME, | |
| 903 | "medium", | |
| 904 | italics ? 'i' : 'r', | |
| 905 | size); | |
| 906 | font = gdk_font_load (buf); | |
| 907 | if (font) | |
| 908 | return font; | |
| 909 | ||
| 910 | if (italics) { | |
| 911 | g_snprintf (buf, sizeof (buf), "-*-%s-%s-%c-*-*-*-%d-*-*-*-*-*-*", | |
| 912 | name ? name : DEFAULT_FONT_NAME, | |
| 913 | "medium", | |
| 914 | 'o', | |
| 915 | size); | |
| 916 | font = gdk_font_load (buf); | |
| 917 | if (font) | |
| 918 | return font; | |
| 919 | } | |
| 920 | } | |
| 921 | ||
| 922 | if (!bold && !italics) { | |
| 923 | g_snprintf (buf, sizeof (buf), "-*-%s-medium-r-*-*-*-%d-*-*-*-*-*-*", | |
| 924 | name ? name : DEFAULT_FONT_NAME, | |
| 925 | size); | |
| 926 | font = gdk_font_load (buf); | |
| 927 | if (font) | |
| 928 | return font; | |
| 929 | } | |
| 930 | ||
| 931 | g_snprintf (buf, sizeof (buf), "-*-%s-medium-r-*-*-*-%d-*-*-*-*-*-*", | |
| 932 | DEFAULT_FONT_NAME, | |
| 933 | size); | |
| 934 | font = gdk_font_load (buf); | |
| 935 | if (font) | |
| 936 | return font; | |
| 937 | ||
| 938 | if (imhtml->default_font) | |
| 939 | return gdk_font_ref (imhtml->default_font); | |
| 940 | ||
| 941 | return NULL; | |
| 942 | } | |
| 943 | ||
| 944 | static void | |
| 945 | gtk_imhtml_init (GtkIMHtml *imhtml) | |
| 946 | { | |
| 947 | static const GtkTargetEntry targets [] = { | |
| 948 | { "STRING", 0, TARGET_STRING }, | |
| 949 | { "TEXT", 0, TARGET_TEXT }, | |
| 950 | { "COMPOUND_TEXT", 0, TARGET_COMPOUND_TEXT } | |
| 951 | }; | |
| 952 | ||
| 953 | imhtml->default_font = gtk_imhtml_font_load (imhtml, NULL, FALSE, FALSE, 0); | |
| 954 | if (imhtml->default_font == NULL) | |
| 955 | g_warning ("GtkIMHtml: Could not load default font!"); | |
| 956 | imhtml->default_fg_color = gdk_color_copy (>K_WIDGET (imhtml)->style->black); | |
| 957 | imhtml->hand_cursor = gdk_cursor_new (GDK_HAND2); | |
| 958 | imhtml->arrow_cursor = gdk_cursor_new (GDK_LEFT_PTR); | |
| 959 | ||
| 960 | GTK_WIDGET_SET_FLAGS (GTK_WIDGET (imhtml), GTK_CAN_FOCUS); | |
| 961 | gtk_selection_add_targets (GTK_WIDGET (imhtml), GDK_SELECTION_PRIMARY, targets, 3); | |
| 962 | } | |
| 963 | ||
| 964 | GtkType | |
| 965 | gtk_imhtml_get_type (void) | |
| 966 | { | |
| 967 | static GtkType imhtml_type = 0; | |
| 968 | ||
| 969 | if (!imhtml_type) { | |
| 970 | static const GtkTypeInfo imhtml_info = { | |
| 971 | "GtkIMHtml", | |
| 972 | sizeof (GtkIMHtml), | |
| 973 | sizeof (GtkIMHtmlClass), | |
| 974 | (GtkClassInitFunc) gtk_imhtml_class_init, | |
| 975 | (GtkObjectInitFunc) gtk_imhtml_init, | |
| 976 | NULL, | |
| 977 | NULL, | |
| 978 | NULL | |
| 979 | }; | |
| 980 | ||
| 981 | imhtml_type = gtk_type_unique (GTK_TYPE_LAYOUT, &imhtml_info); | |
| 982 | } | |
| 983 | ||
| 984 | return imhtml_type; | |
| 985 | } | |
| 986 | ||
| 987 | static void | |
| 988 | gtk_imhtml_init_smiley_hash (GtkIMHtml *imhtml) | |
| 989 | { | |
| 990 | g_return_if_fail (imhtml != NULL); | |
| 991 | g_return_if_fail (GTK_IS_IMHTML (imhtml)); | |
| 992 | ||
| 993 | imhtml->smiley_hash = g_hash_table_new (g_str_hash, g_str_equal); | |
| 994 | ||
| 995 | gtk_imhtml_associate_smiley (imhtml, ":)", smile_xpm); | |
| 996 | gtk_imhtml_associate_smiley (imhtml, ":-)", smile_xpm); | |
| 997 | ||
| 998 | gtk_imhtml_associate_smiley (imhtml, ":(", sad_xpm); | |
| 999 | gtk_imhtml_associate_smiley (imhtml, ":-(", sad_xpm); | |
| 1000 | ||
| 1001 | gtk_imhtml_associate_smiley (imhtml, ";)", wink_xpm); | |
| 1002 | gtk_imhtml_associate_smiley (imhtml, ";-)", wink_xpm); | |
| 1003 | ||
| 1004 | gtk_imhtml_associate_smiley (imhtml, ":-p", tongue_xpm); | |
| 1005 | gtk_imhtml_associate_smiley (imhtml, ":-P", tongue_xpm); | |
| 1006 | ||
| 1007 | gtk_imhtml_associate_smiley (imhtml, "=-O", scream_xpm); | |
| 1008 | gtk_imhtml_associate_smiley (imhtml, ":-*", kiss_xpm); | |
| 1009 | gtk_imhtml_associate_smiley (imhtml, ">:o", yell_xpm); | |
| 1010 | gtk_imhtml_associate_smiley (imhtml, "8-)", smile8_xpm); | |
| 1011 | gtk_imhtml_associate_smiley (imhtml, ":-$", moneymouth_xpm); | |
| 1012 | gtk_imhtml_associate_smiley (imhtml, ":-!", burp_xpm); | |
| 1013 | gtk_imhtml_associate_smiley (imhtml, ":-[", embarrassed_xpm); | |
| 1014 | gtk_imhtml_associate_smiley (imhtml, ":'(", cry_xpm); | |
| 1015 | ||
| 1016 | gtk_imhtml_associate_smiley (imhtml, ":-/", think_xpm); | |
| 1017 | gtk_imhtml_associate_smiley (imhtml, ":-\\", think_xpm); | |
| 1018 | ||
| 1019 | gtk_imhtml_associate_smiley (imhtml, ":-X", crossedlips_xpm); | |
| 1020 | gtk_imhtml_associate_smiley (imhtml, ":-D", bigsmile_xpm); | |
| 1021 | gtk_imhtml_associate_smiley (imhtml, "O:-)", angel_xpm); | |
| 1022 | } | |
| 1023 | ||
| 1024 | GtkWidget* | |
| 1025 | gtk_imhtml_new (GtkAdjustment *hadj, | |
| 1026 | GtkAdjustment *vadj) | |
| 1027 | { | |
| 1028 | GtkIMHtml *imhtml = gtk_type_new (GTK_TYPE_IMHTML); | |
| 1029 | ||
| 1030 | gtk_imhtml_set_adjustments (imhtml, hadj, vadj); | |
| 1031 | ||
| 1032 | imhtml->bits = NULL; | |
| 1033 | imhtml->urls = NULL; | |
| 1034 | ||
| 1035 | imhtml->x = BORDER_SIZE; | |
| 1036 | imhtml->y = BORDER_SIZE + 10; | |
| 1037 | imhtml->llheight = 0; | |
| 1038 | imhtml->llascent = 0; | |
| 1039 | imhtml->line = NULL; | |
| 1040 | ||
| 1041 | imhtml->selected_text = g_string_new (""); | |
| 1042 | imhtml->scroll_timer = 0; | |
| 1043 | ||
| 1044 | imhtml->img = NULL; | |
| 1045 | ||
| 1046 | imhtml->smileys = TRUE; | |
| 1047 | imhtml->comments = FALSE; | |
| 1048 | ||
| 1049 | imhtml->smin = G_MAXINT; | |
| 1050 | imhtml->smax = 0; | |
| 1051 | gtk_imhtml_init_smiley_hash (imhtml); | |
| 1052 | ||
| 1053 | return GTK_WIDGET (imhtml); | |
| 1054 | } | |
| 1055 | ||
| 1056 | void | |
| 1057 | gtk_imhtml_set_adjustments (GtkIMHtml *imhtml, | |
| 1058 | GtkAdjustment *hadj, | |
| 1059 | GtkAdjustment *vadj) | |
| 1060 | { | |
| 1061 | gtk_layout_set_hadjustment (GTK_LAYOUT (imhtml), hadj); | |
| 1062 | gtk_layout_set_vadjustment (GTK_LAYOUT (imhtml), vadj); | |
| 1063 | } | |
| 1064 | ||
| 1065 | void | |
| 1066 | gtk_imhtml_set_defaults (GtkIMHtml *imhtml, | |
| 1067 | GdkFont *font, | |
| 1068 | GdkColor *fg_color) | |
| 1069 | { | |
| 1070 | g_return_if_fail (imhtml != NULL); | |
| 1071 | g_return_if_fail (GTK_IS_IMHTML (imhtml)); | |
| 1072 | ||
| 1073 | if (font) { | |
| 1074 | if (imhtml->default_font) | |
| 1075 | gdk_font_unref (imhtml->default_font); | |
| 1076 | imhtml->default_font = gdk_font_ref (font); | |
| 1077 | } | |
| 1078 | ||
| 1079 | if (fg_color) { | |
| 1080 | if (imhtml->default_fg_color) | |
| 1081 | gdk_color_free (imhtml->default_fg_color); | |
| 1082 | imhtml->default_fg_color = gdk_color_copy (fg_color); | |
| 1083 | } | |
| 1084 | } | |
| 1085 | ||
| 1086 | void | |
| 1087 | gtk_imhtml_set_img_handler (GtkIMHtml *imhtml, | |
| 1088 | GtkIMHtmlImage handler) | |
| 1089 | { | |
| 1090 | g_return_if_fail (imhtml != NULL); | |
| 1091 | g_return_if_fail (GTK_IS_IMHTML (imhtml)); | |
| 1092 | ||
| 1093 | imhtml->img = handler; | |
| 1094 | } | |
| 1095 | ||
| 1096 | void | |
| 1097 | gtk_imhtml_associate_smiley (GtkIMHtml *imhtml, | |
| 1098 | gchar *text, | |
| 1099 | gchar **xpm) | |
| 1100 | { | |
| 1101 | g_return_if_fail (imhtml != NULL); | |
| 1102 | g_return_if_fail (GTK_IS_IMHTML (imhtml)); | |
| 1103 | g_return_if_fail (text != NULL); | |
| 1104 | ||
| 1105 | if (strlen (text) < imhtml->smin) | |
| 1106 | imhtml->smin = strlen (text); | |
| 1107 | ||
| 1108 | if (strlen (text) > imhtml->smax) | |
| 1109 | imhtml->smax = strlen (text); | |
| 1110 | ||
| 1111 | if (xpm == NULL) | |
| 1112 | g_hash_table_remove (imhtml->smiley_hash, text); | |
| 1113 | else | |
| 1114 | g_hash_table_insert (imhtml->smiley_hash, text, xpm); | |
| 1115 | } | |
| 1116 | ||
| 1117 | static gint | |
| 1118 | draw_text (GtkWidget *widget, | |
| 1119 | GdkEvent *event, | |
| 1120 | gpointer data) | |
| 1121 | { | |
| 1122 | GtkIMHtmlBit *bit; | |
| 1123 | struct line_info *line; | |
| 1124 | GdkGC *gc; | |
| 1125 | GdkColormap *cmap; | |
| 1126 | ||
| 1127 | line = gtk_object_get_user_data (GTK_OBJECT (widget)); | |
| 1128 | bit = line->bit; | |
| 1129 | gc = gdk_gc_new (widget->window); | |
| 1130 | cmap = gdk_colormap_new (gdk_visual_get_best (), FALSE); | |
| 1131 | ||
| 1132 | if (bit->bg != NULL) { | |
| 1133 | gdk_color_alloc (cmap, bit->bg); | |
| 1134 | gdk_gc_set_foreground (gc, bit->bg); | |
| 1135 | } else | |
| 1136 | gdk_gc_copy (gc, widget->style->white_gc); | |
| 1137 | ||
| 1138 | gdk_draw_rectangle (widget->window, gc, TRUE, 0, 0, | |
| 1139 | widget->allocation.width, | |
| 1140 | widget->allocation.height); | |
| 1141 | ||
| 1142 | if (!line->text) { | |
| 1143 | gdk_colormap_unref (cmap); | |
| 1144 | gdk_gc_unref (gc); | |
| 1145 | return TRUE; | |
| 1146 | } | |
| 1147 | ||
| 1148 | if (bit->back != NULL) { | |
| 1149 | gdk_color_alloc (cmap, bit->back); | |
| 1150 | gdk_gc_set_foreground (gc, bit->back); | |
| 1151 | gdk_draw_rectangle (widget->window, gc, TRUE, 0, 0, | |
| 1152 | gdk_string_width (bit->font, line->text), | |
| 1153 | widget->allocation.height); | |
| 1154 | } | |
| 1155 | ||
| 1156 | if (line->selected) { | |
| 1157 | gint width, x; | |
| 1158 | gchar *start, *end; | |
| 1159 | GdkColor col; | |
| 1160 | ||
| 1161 | if ((line->sel_start > line->sel_end) && (line->sel_end != NULL)) { | |
| 1162 | start = line->sel_end; | |
| 1163 | end = line->sel_start; | |
| 1164 | } else { | |
| 1165 | start = line->sel_start; | |
| 1166 | end = line->sel_end; | |
| 1167 | } | |
| 1168 | ||
| 1169 | if (start == NULL) | |
| 1170 | x = 0; | |
| 1171 | else | |
| 1172 | x = gdk_text_width (bit->font, line->text, start - line->text); | |
| 1173 | ||
| 1174 | if (end == NULL) | |
| 1175 | width = gdk_string_width (bit->font, line->text) - x; | |
| 1176 | else | |
| 1177 | width = gdk_text_width (bit->font, line->text, end - line->text) - x; | |
| 1178 | ||
| 1179 | col.red = col.green = col.blue = 0xc000; | |
| 1180 | gdk_color_alloc (cmap, &col); | |
| 1181 | gdk_gc_set_foreground (gc, &col); | |
| 1182 | ||
| 1183 | gdk_draw_rectangle (widget->window, gc, TRUE, x, 0, | |
| 1184 | width, widget->allocation.height); | |
| 1185 | } | |
| 1186 | ||
| 1187 | if (bit->url) { | |
| 1188 | GdkColor *tc = gtk_imhtml_get_color ("#0000a0"); | |
| 1189 | gdk_color_alloc (cmap, tc); | |
| 1190 | gdk_gc_set_foreground (gc, tc); | |
| 1191 | gdk_color_free (tc); | |
| 1192 | } else if (bit->fore) { | |
| 1193 | gdk_color_alloc (cmap, bit->fore); | |
| 1194 | gdk_gc_set_foreground (gc, bit->fore); | |
| 1195 | } else | |
| 1196 | gdk_gc_copy (gc, widget->style->black_gc); | |
| 1197 | ||
| 1198 | gdk_draw_string (widget->window, bit->font, gc, | |
| 1199 | 0, line->ascent, line->text); | |
| 1200 | ||
| 1201 | if (bit->underline || bit->url) | |
| 1202 | gdk_draw_rectangle (widget->window, gc, TRUE, | |
| 1203 | 0, line->ascent + 1, | |
| 1204 | gdk_string_width (bit->font, line->text), 1); | |
| 1205 | if (bit->strike) | |
| 1206 | gdk_draw_rectangle (widget->window, gc, TRUE, | |
| 1207 | 0, line->ascent - (bit->font->ascent >> 1), | |
| 1208 | gdk_string_width (bit->font, line->text), 1); | |
| 1209 | ||
| 1210 | gdk_colormap_unref (cmap); | |
| 1211 | gdk_gc_unref (gc); | |
| 1212 | ||
| 1213 | return TRUE; | |
| 1214 | } | |
| 1215 | ||
| 1216 | static gint | |
| 1217 | draw_img (GtkWidget *widget, | |
| 1218 | GdkEvent *event, | |
| 1219 | gpointer data) | |
| 1220 | { | |
| 1221 | GtkIMHtmlBit *bit; | |
| 1222 | struct line_info *line; | |
| 1223 | GdkGC *gc; | |
| 1224 | GdkColormap *cmap; | |
| 1225 | gint width, height, hoff; | |
| 1226 | ||
| 1227 | line = gtk_object_get_user_data (GTK_OBJECT (widget)); | |
| 1228 | bit = line->bit; | |
| 1229 | gdk_window_get_size (bit->pm, &width, &height); | |
| 1230 | hoff = (widget->allocation.height - height) / 2; | |
| 1231 | gc = gdk_gc_new (widget->window); | |
| 1232 | cmap = gdk_colormap_new (gdk_visual_get_best (), FALSE); | |
| 1233 | ||
| 1234 | if (bit->bg != NULL) { | |
| 1235 | gdk_color_alloc (cmap, bit->bg); | |
| 1236 | gdk_gc_set_foreground (gc, bit->bg); | |
| 1237 | } else | |
| 1238 | gdk_gc_copy (gc, widget->style->white_gc); | |
| 1239 | ||
| 1240 | gdk_draw_rectangle (widget->window, gc, TRUE, 0, 0, | |
| 1241 | widget->allocation.width, | |
| 1242 | widget->allocation.height); | |
| 1243 | ||
| 1244 | if (bit->back != NULL) { | |
| 1245 | gdk_color_alloc (cmap, bit->back); | |
| 1246 | gdk_gc_set_foreground (gc, bit->back); | |
| 1247 | gdk_draw_rectangle (widget->window, gc, TRUE, 0, 0, | |
| 1248 | width, widget->allocation.height); | |
| 1249 | } | |
| 1250 | ||
| 1251 | gdk_draw_pixmap (widget->window, gc, bit->pm, 0, 0, 0, hoff, -1, -1); | |
| 1252 | ||
| 1253 | gdk_colormap_unref (cmap); | |
| 1254 | gdk_gc_unref (gc); | |
| 1255 | ||
| 1256 | return TRUE; | |
| 1257 | } | |
| 1258 | ||
| 1259 | static gint | |
| 1260 | draw_line (GtkWidget *widget, | |
| 1261 | GdkEvent *event, | |
| 1262 | gpointer data) | |
| 1263 | { | |
| 1264 | GtkIMHtmlBit *bit; | |
| 1265 | GdkDrawable *drawable; | |
| 1266 | GdkColormap *cmap; | |
| 1267 | GdkGC *gc; | |
| 1268 | guint max_width; | |
| 1269 | guint max_height; | |
| 1270 | ||
| 1271 | bit = data; | |
| 1272 | drawable = widget->window; | |
| 1273 | cmap = gdk_colormap_new (gdk_visual_get_best (), FALSE); | |
| 1274 | gc = gdk_gc_new (drawable); | |
| 1275 | ||
| 1276 | if (bit->bg != NULL) { | |
| 1277 | gdk_color_alloc (cmap, bit->bg); | |
| 1278 | gdk_gc_set_foreground (gc, bit->bg); | |
| 1279 | ||
| 1280 | gdk_draw_rectangle (widget->window, gc, TRUE, 0, 0, | |
| 1281 | widget->allocation.width, | |
| 1282 | widget->allocation.height); | |
| 1283 | } | |
| 1284 | ||
| 1285 | gdk_gc_copy (gc, widget->style->black_gc); | |
| 1286 | ||
| 1287 | max_width = widget->allocation.width; | |
| 1288 | max_height = widget->allocation.height / 2; | |
| 1289 | ||
| 1290 | gdk_draw_rectangle (drawable, gc, | |
| 1291 | TRUE, | |
| 1292 | 0, max_height / 2, | |
| 1293 | max_width, max_height); | |
| 1294 | ||
| 1295 | gdk_colormap_unref (cmap); | |
| 1296 | gdk_gc_unref (gc); | |
| 1297 | ||
| 1298 | return TRUE; | |
| 1299 | } | |
| 1300 | ||
| 1301 | static gint | |
| 1302 | click_event_box (GtkBin *bin, | |
| 1303 | GdkEventButton *event, | |
| 1304 | GtkIMHtml *imhtml) | |
| 1305 | { | |
| 1306 | struct line_info *li = gtk_object_get_user_data (GTK_OBJECT (bin->child)); | |
| 1307 | ||
| 1308 | if (event->button == 1 && event->type == GDK_BUTTON_PRESS) | |
| 1309 | gtk_signal_emit (GTK_OBJECT (imhtml), signals [URL_CLICKED], li->bit->url); | |
| 1310 | ||
| 1311 | return TRUE; | |
| 1312 | } | |
| 1313 | ||
| 1314 | static void | |
| 1315 | new_line (GtkIMHtml *imhtml) | |
| 1316 | { | |
| 1317 | GList *last = g_list_last (imhtml->line); | |
| 1318 | GtkWidget *widget; | |
| 1319 | struct line_info *li; | |
| 1320 | ||
| 1321 | if (last) { | |
| 1322 | widget = last->data; | |
| 1323 | li = gtk_object_get_user_data (GTK_OBJECT (widget)); | |
| 1324 | if (li->x + li->width != imhtml->xsize - BORDER_SIZE) { | |
| 1325 | li->width = imhtml->xsize - BORDER_SIZE - li->x; | |
| 1326 | gtk_widget_set_usize (widget, li->width, li->height); | |
| 1327 | } | |
| 1328 | } | |
| 1329 | ||
| 1330 | last = imhtml->line; | |
| 1331 | if (last) { | |
| 1332 | widget = last->data; | |
| 1333 | li = gtk_object_get_user_data (GTK_OBJECT (widget)); | |
| 1334 | if (li->height < MIN_HEIGHT) { | |
| 1335 | while (last) { | |
| 1336 | gint diff; | |
| 1337 | widget = last->data; | |
| 1338 | li = gtk_object_get_user_data (GTK_OBJECT (widget)); | |
| 1339 | diff = MIN_HEIGHT - li->height; | |
| 1340 | li->height = MIN_HEIGHT; | |
| 1341 | gtk_widget_set_usize (widget, li->width, li->height); | |
| 1342 | li->ascent += diff >> 1; | |
| 1343 | last = g_list_next (last); | |
| 1344 | } | |
| 1345 | imhtml->llheight = MIN_HEIGHT; | |
| 1346 | } | |
| 1347 | } | |
| 1348 | ||
| 1349 | g_list_free (imhtml->line); | |
| 1350 | imhtml->line = NULL; | |
| 1351 | ||
| 1352 | imhtml->x = BORDER_SIZE; | |
| 1353 | imhtml->y += imhtml->llheight; | |
| 1354 | } | |
| 1355 | ||
| 1356 | static void | |
| 1357 | backwards_update (GtkIMHtml *imhtml, | |
| 1358 | GtkIMHtmlBit *bit, | |
| 1359 | gint height, | |
| 1360 | gint ascent) | |
| 1361 | { | |
| 1362 | gint diff; | |
| 1363 | GList *ls = NULL; | |
| 1364 | struct line_info *li; | |
| 1365 | struct url_widget *uw; | |
| 1366 | ||
| 1367 | if (height > imhtml->llheight) { | |
| 1368 | diff = height - imhtml->llheight; | |
| 1369 | ||
| 1370 | ls = imhtml->line; | |
| 1371 | while (ls) { | |
| 1372 | GtkWidget *data = ls->data; | |
| 1373 | li = gtk_object_get_user_data (GTK_OBJECT (data)); | |
| 1374 | li->height += diff; | |
| 1375 | if (ascent) | |
| 1376 | li->ascent = ascent; | |
| 1377 | else | |
| 1378 | li->ascent += diff >> 1; | |
| 1379 | gtk_widget_set_usize (data, li->width, li->height); | |
| 1380 | ls = g_list_next (ls); | |
| 1381 | } | |
| 1382 | ||
| 1383 | ls = imhtml->urls; | |
| 1384 | while (ls) { | |
| 1385 | uw = ls->data; | |
| 1386 | if (uw->y + diff > imhtml->y) | |
| 1387 | uw->y += diff; | |
| 1388 | ls = g_list_next (ls); | |
| 1389 | } | |
| 1390 | ||
| 1391 | imhtml->llheight = height; | |
| 1392 | if (ascent) | |
| 1393 | imhtml->llascent = ascent; | |
| 1394 | else | |
| 1395 | imhtml->llascent += diff >> 1; | |
| 1396 | } | |
| 1397 | } | |
| 1398 | ||
| 1399 | static GtkTooltips *tips = NULL; | |
| 1400 | ||
| 1401 | static void | |
| 1402 | add_text_renderer (GtkIMHtml *imhtml, | |
| 1403 | GtkIMHtmlBit *bit, | |
| 1404 | gchar *text) | |
| 1405 | { | |
| 1406 | GtkWidget *darea; | |
| 1407 | GtkWidget *eventbox; | |
| 1408 | struct line_info *li; | |
| 1409 | struct url_widget *uw; | |
| 1410 | gint width; | |
| 1411 | ||
| 1412 | if (text) | |
| 1413 | width = gdk_string_width (bit->font, text); | |
| 1414 | else | |
| 1415 | width = 0; | |
| 1416 | ||
| 1417 | darea = gtk_drawing_area_new (); | |
| 1418 | gtk_widget_set_usize (darea, width, imhtml->llheight); | |
| 1419 | gtk_signal_connect (GTK_OBJECT (darea), "expose_event", GTK_SIGNAL_FUNC (draw_text), NULL); | |
| 1420 | ||
| 1421 | li = g_new0 (struct line_info, 1); | |
| 1422 | li->x = imhtml->x; | |
| 1423 | li->y = imhtml->y; | |
| 1424 | li->width = width; | |
| 1425 | li->height = imhtml->llheight; | |
| 1426 | if (text) | |
| 1427 | li->ascent = MAX (imhtml->llascent, bit->font->ascent); | |
| 1428 | else | |
| 1429 | li->ascent = 0; | |
| 1430 | li->text = text; | |
| 1431 | li->bit = bit; | |
| 1432 | ||
| 1433 | gtk_object_set_user_data (GTK_OBJECT (darea), li); | |
| 1434 | ||
| 1435 | if (bit->url) { | |
| 1436 | eventbox = gtk_event_box_new (); | |
| 1437 | gtk_layout_put (GTK_LAYOUT (imhtml), eventbox, imhtml->x, imhtml->y); | |
| 1438 | gtk_signal_connect (GTK_OBJECT (eventbox), "button_press_event", | |
| 1439 | GTK_SIGNAL_FUNC (click_event_box), imhtml); | |
| 1440 | gtk_widget_show (eventbox); | |
| 1441 | ||
| 1442 | gtk_container_add (GTK_CONTAINER (eventbox), darea); | |
| 1443 | ||
| 1444 | uw = g_new0 (struct url_widget, 1); | |
| 1445 | uw->x = imhtml->x; | |
| 1446 | uw->y = imhtml->y; | |
| 1447 | uw->width = width; | |
| 1448 | uw->height = imhtml->llheight; | |
| 1449 | uw->url = bit->url; | |
| 1450 | imhtml->urls = g_list_append (imhtml->urls, uw); | |
| 1451 | ||
| 1452 | if (!tips) | |
| 1453 | tips = gtk_tooltips_new (); | |
| 1454 | gtk_tooltips_set_tip (tips, eventbox, bit->url, ""); | |
| 1455 | } else { | |
| 1456 | gtk_layout_put (GTK_LAYOUT (imhtml), darea, imhtml->x, imhtml->y); | |
| 1457 | } | |
| 1458 | ||
| 1459 | bit->chunks = g_list_append (bit->chunks, darea); | |
| 1460 | imhtml->line = g_list_append (imhtml->line, darea); | |
| 1461 | gtk_widget_show (darea); | |
| 1462 | ||
| 1463 | if (bit->bg) { | |
| 1464 | GdkColormap *cmap; | |
| 1465 | ||
| 1466 | cmap = gdk_colormap_new (gdk_visual_get_best (), FALSE); | |
| 1467 | gdk_color_alloc (cmap, bit->bg); | |
| 1468 | gdk_window_set_background (darea->window, bit->bg); | |
| 1469 | gdk_colormap_unref (cmap); | |
| 1470 | } else | |
| 1471 | gdk_window_set_background (darea->window, &darea->style->white); | |
| 1472 | } | |
| 1473 | ||
| 1474 | static void | |
| 1475 | add_img_renderer (GtkIMHtml *imhtml, | |
| 1476 | GtkIMHtmlBit *bit) | |
| 1477 | { | |
| 1478 | GtkWidget *darea; | |
| 1479 | GtkWidget *eventbox; | |
| 1480 | struct line_info *li; | |
| 1481 | struct url_widget *uw; | |
| 1482 | gint width; | |
| 1483 | ||
| 1484 | gdk_window_get_size (bit->pm, &width, NULL); | |
| 1485 | ||
| 1486 | darea = gtk_drawing_area_new (); | |
| 1487 | gtk_widget_set_usize (darea, width, imhtml->llheight); | |
| 1488 | gtk_signal_connect (GTK_OBJECT (darea), "expose_event", GTK_SIGNAL_FUNC (draw_img), NULL); | |
| 1489 | ||
| 1490 | li = g_new0 (struct line_info, 1); | |
| 1491 | li->x = imhtml->x; | |
| 1492 | li->y = imhtml->y; | |
| 1493 | li->width = width; | |
| 1494 | li->height = imhtml->llheight; | |
| 1495 | li->ascent = 0; | |
| 1496 | li->bit = bit; | |
| 1497 | ||
| 1498 | gtk_object_set_user_data (GTK_OBJECT (darea), li); | |
| 1499 | ||
| 1500 | if (bit->url) { | |
| 1501 | eventbox = gtk_event_box_new (); | |
| 1502 | gtk_layout_put (GTK_LAYOUT (imhtml), eventbox, imhtml->x, imhtml->y); | |
| 1503 | gtk_signal_connect (GTK_OBJECT (eventbox), "button_press_event", | |
| 1504 | GTK_SIGNAL_FUNC (click_event_box), imhtml); | |
| 1505 | gtk_widget_show (eventbox); | |
| 1506 | ||
| 1507 | gtk_container_add (GTK_CONTAINER (eventbox), darea); | |
| 1508 | ||
| 1509 | uw = g_new0 (struct url_widget, 1); | |
| 1510 | uw->x = imhtml->x; | |
| 1511 | uw->y = imhtml->y; | |
| 1512 | uw->width = width; | |
| 1513 | uw->height = imhtml->llheight; | |
| 1514 | uw->url = bit->url; | |
| 1515 | imhtml->urls = g_list_append (imhtml->urls, uw); | |
| 1516 | ||
| 1517 | if (!tips) | |
| 1518 | tips = gtk_tooltips_new (); | |
| 1519 | gtk_tooltips_set_tip (tips, eventbox, bit->url, ""); | |
| 1520 | } else { | |
| 1521 | gtk_layout_put (GTK_LAYOUT (imhtml), darea, imhtml->x, imhtml->y); | |
| 1522 | } | |
| 1523 | ||
| 1524 | bit->chunks = g_list_append (bit->chunks, darea); | |
| 1525 | imhtml->line = g_list_append (imhtml->line, darea); | |
| 1526 | gtk_widget_show (darea); | |
| 1527 | ||
| 1528 | if (bit->bg) { | |
| 1529 | GdkColormap *cmap; | |
| 1530 | ||
| 1531 | cmap = gdk_colormap_new (gdk_visual_get_best (), FALSE); | |
| 1532 | gdk_color_alloc (cmap, bit->bg); | |
| 1533 | gdk_window_set_background (darea->window, bit->bg); | |
| 1534 | gdk_colormap_unref (cmap); | |
| 1535 | } else | |
| 1536 | gdk_window_set_background (darea->window, &darea->style->white); | |
| 1537 | ||
| 1538 | imhtml->x += width; | |
| 1539 | } | |
| 1540 | ||
| 1541 | static void | |
| 1542 | gtk_imhtml_draw_bit (GtkIMHtml *imhtml, | |
| 1543 | GtkIMHtmlBit *bit) | |
| 1544 | { | |
| 1545 | gint width, height; | |
| 1546 | GdkWindow *window; | |
| 1547 | GdkGC *gc; | |
| 1548 | ||
| 1549 | g_return_if_fail (imhtml != NULL); | |
| 1550 | g_return_if_fail (GTK_IS_IMHTML (imhtml)); | |
| 1551 | g_return_if_fail (bit != NULL); | |
| 1552 | ||
| 1553 | window = GTK_LAYOUT (imhtml)->bin_window; | |
| 1554 | gc = gdk_gc_new (window); | |
| 1555 | ||
| 1556 | if ( (bit->type == TYPE_TEXT) || | |
| 1557 | ((bit->type == TYPE_SMILEY) && !imhtml->smileys) || | |
| 1558 | ((bit->type == TYPE_COMMENT) && imhtml->comments)) { | |
| 1559 | gchar *copy = g_strdup (bit->text); | |
| 1560 | gint pos = 0; | |
| 1561 | gboolean seenspace = FALSE; | |
| 1562 | gchar *tmp; | |
| 1563 | ||
| 1564 | height = bit->font->ascent + bit->font->descent; | |
| 1565 | width = gdk_string_width (bit->font, bit->text); | |
| 1566 | ||
| 1567 | if ((imhtml->x != BORDER_SIZE) && | |
| 1568 | ((imhtml->x + width + BORDER_SIZE + BORDER_SIZE + 5) > imhtml->xsize)) { | |
| 1569 | gint remain = imhtml->xsize - imhtml->x - BORDER_SIZE - BORDER_SIZE - 5; | |
| 1570 | while (gdk_text_width (bit->font, copy, pos) < remain) { | |
| 1571 | if (copy [pos] == ' ') | |
| 1572 | seenspace = TRUE; | |
| 1573 | pos++; | |
| 1574 | } | |
| 1575 | if (seenspace) { | |
| 1576 | while (copy [pos - 1] != ' ') pos--; | |
| 1577 | ||
| 1578 | tmp = g_strndup (copy, pos); | |
| 1579 | ||
| 1580 | backwards_update (imhtml, bit, height, bit->font->ascent); | |
| 1581 | add_text_renderer (imhtml, bit, tmp); | |
| 1582 | } else | |
| 1583 | pos = 0; | |
| 1584 | seenspace = FALSE; | |
| 1585 | new_line (imhtml); | |
| 1586 | imhtml->llheight = 0; | |
| 1587 | imhtml->llascent = 0; | |
| 1588 | } | |
| 1589 | ||
| 1590 | backwards_update (imhtml, bit, height, bit->font->ascent); | |
| 1591 | ||
| 1592 | while (pos < strlen (bit->text)) { | |
| 1593 | width = gdk_string_width (bit->font, copy + pos); | |
| 1594 | if (imhtml->x + width + BORDER_SIZE + BORDER_SIZE + 5 > imhtml->xsize) { | |
| 1595 | gint newpos = 0; | |
| 1596 | gint remain = imhtml->xsize - imhtml->x - BORDER_SIZE - BORDER_SIZE - 5; | |
| 1597 | while (gdk_text_width (bit->font, copy + pos, newpos) < remain) { | |
| 1598 | if (copy [pos + newpos] == ' ') | |
| 1599 | seenspace = TRUE; | |
| 1600 | newpos++; | |
| 1601 | } | |
| 1602 | ||
| 1603 | if (seenspace) | |
| 1604 | while (copy [pos + newpos - 1] != ' ') newpos--; | |
| 1605 | ||
| 1606 | if (newpos == 0) | |
| 1607 | break; | |
| 1608 | ||
| 1609 | tmp = g_strndup (copy + pos, newpos); | |
| 1610 | pos += newpos; | |
| 1611 | ||
| 1612 | add_text_renderer (imhtml, bit, tmp); | |
| 1613 | ||
| 1614 | seenspace = FALSE; | |
| 1615 | new_line (imhtml); | |
| 1616 | } else { | |
| 1617 | tmp = g_strdup (copy + pos); | |
| 1618 | ||
| 1619 | add_text_renderer (imhtml, bit, tmp); | |
| 1620 | ||
| 1621 | pos = strlen (bit->text); | |
| 1622 | ||
| 1623 | imhtml->x += width; | |
| 1624 | } | |
| 1625 | } | |
| 1626 | ||
| 1627 | g_free (copy); | |
| 1628 | } else if ((bit->type == TYPE_SMILEY) || (bit->type == TYPE_IMG)) { | |
| 1629 | gdk_window_get_size (bit->pm, &width, &height); | |
| 1630 | ||
| 1631 | if ((imhtml->x != BORDER_SIZE) && | |
| 1632 | ((imhtml->x + width + BORDER_SIZE + BORDER_SIZE + 5) > imhtml->xsize)) { | |
| 1633 | new_line (imhtml); | |
| 1634 | imhtml->llheight = 0; | |
| 1635 | imhtml->llascent = 0; | |
| 1636 | } else | |
| 1637 | backwards_update (imhtml, bit, height, height * 3 / 4); | |
| 1638 | ||
| 1639 | add_img_renderer (imhtml, bit); | |
| 1640 | } else if (bit->type == TYPE_BR) { | |
| 1641 | new_line (imhtml); | |
| 1642 | imhtml->llheight = 0; | |
| 1643 | imhtml->llascent = 0; | |
| 1644 | add_text_renderer (imhtml, bit, NULL); | |
| 1645 | } else if (bit->type == TYPE_SEP) { | |
| 1646 | GtkWidget *darea; | |
| 1647 | if (imhtml->llheight) { | |
| 1648 | new_line (imhtml); | |
| 1649 | imhtml->llheight = 0; | |
| 1650 | imhtml->llascent = 0; | |
| 1651 | } | |
| 1652 | darea = gtk_drawing_area_new (); | |
| 1653 | gtk_widget_set_usize (darea, imhtml->xsize - (BORDER_SIZE * 2), HR_HEIGHT * 2); | |
| 1654 | gtk_layout_put (GTK_LAYOUT (imhtml), darea, imhtml->x, imhtml->y); | |
| 1655 | gtk_signal_connect (GTK_OBJECT (darea), "expose_event", | |
| 1656 | GTK_SIGNAL_FUNC (draw_line), bit); | |
| 1657 | gtk_widget_show (darea); | |
| 1658 | imhtml->llheight = HR_HEIGHT * 2; | |
| 1659 | new_line (imhtml); | |
| 1660 | imhtml->llheight = 0; | |
| 1661 | imhtml->llascent = 0; | |
| 1662 | add_text_renderer (imhtml, bit, NULL); | |
| 1663 | } | |
| 1664 | ||
| 1665 | gtk_layout_set_size (GTK_LAYOUT (imhtml), imhtml->xsize, imhtml->y + 5); | |
| 1666 | ||
| 1667 | gdk_gc_destroy (gc); | |
| 1668 | } | |
| 1669 | ||
| 1670 | void | |
| 1671 | gtk_imhtml_show_smileys (GtkIMHtml *imhtml, | |
| 1672 | gboolean show) | |
| 1673 | { | |
| 1674 | g_return_if_fail (imhtml != NULL); | |
| 1675 | g_return_if_fail (GTK_IS_IMHTML (imhtml)); | |
| 1676 | ||
| 1677 | imhtml->smileys = show; | |
| 1678 | ||
| 1679 | if (GTK_WIDGET_VISIBLE (GTK_WIDGET (imhtml))) | |
| 1680 | gtk_imhtml_redraw_all (imhtml); | |
| 1681 | } | |
| 1682 | ||
| 1683 | void | |
| 1684 | gtk_imhtml_show_comments (GtkIMHtml *imhtml, | |
| 1685 | gboolean show) | |
| 1686 | { | |
| 1687 | g_return_if_fail (imhtml != NULL); | |
| 1688 | g_return_if_fail (GTK_IS_IMHTML (imhtml)); | |
| 1689 | ||
| 1690 | imhtml->comments = show; | |
| 1691 | ||
| 1692 | if (GTK_WIDGET_VISIBLE (GTK_WIDGET (imhtml))) | |
| 1693 | gtk_imhtml_redraw_all (imhtml); | |
| 1694 | } | |
| 1695 | ||
| 1696 | static GdkColor * | |
| 1697 | gtk_imhtml_get_color (const gchar *color) | |
| 1698 | { | |
| 1699 | GdkColor c; | |
| 1700 | gboolean valid = TRUE; | |
| 1701 | ||
| 1702 | g_return_val_if_fail (color != NULL, NULL); | |
| 1703 | ||
| 1704 | c.red = 0; c.green = 0; c.blue = 0; | |
| 1705 | ||
| 1706 | if (!g_strcasecmp (color, "aliceblue")) { | |
| 1707 | c.red = 0xf000; c.green = 0xf800; c.blue = 0xff00; | |
| 1708 | } else if (!g_strcasecmp (color, "antiquewhite")) { | |
| 1709 | c.red = 0xfa00; c.green = 0xeb00; c.blue = 0xd700; | |
| 1710 | } else if (!g_strcasecmp (color, "aqua")) { | |
| 1711 | c.red = 0; c.green = 0xff00; c.blue = 0xff00; | |
| 1712 | } else if (!g_strcasecmp (color, "aquamarine")) { | |
| 1713 | c.red = 0; c.green = 0xff00; c.blue = 0xff00; | |
| 1714 | } else if (!g_strcasecmp (color, "azure")) { | |
| 1715 | c.red = 0xf000; c.green = 0xff00; c.blue = 0xff00; | |
| 1716 | } else if (!g_strcasecmp (color, "beige")) { | |
| 1717 | c.red = 0xf500; c.green = 0xf500; c.blue = 0xdc00; | |
| 1718 | } else if (!g_strcasecmp (color, "bisque")) { | |
| 1719 | c.red = 0xff00; c.green = 0xe400; c.blue = 0xc400; | |
| 1720 | } else if (!g_strcasecmp (color, "black")) { | |
| 1721 | c.red = 0; c.green = 0; c.blue = 0; | |
| 1722 | } else if (!g_strcasecmp (color, "blanchedalmond")) { | |
| 1723 | c.red = 0xff00; c.green = 0xeb00; c.blue = 0xcd00; | |
| 1724 | } else if (!g_strcasecmp (color, "blue")) { | |
| 1725 | c.red = 0; c.green = 0; c.blue = 0xff00; | |
| 1726 | } else if (!g_strcasecmp (color, "blueviolet")) { | |
| 1727 | c.red = 0; c.green = 0; c.blue = 0xff00; | |
| 1728 | } else if (!g_strcasecmp (color, "brown")) { | |
| 1729 | c.red = 0xa500; c.green = 0x2a00; c.blue = 0x2a00; | |
| 1730 | } else if (!g_strcasecmp (color, "burlywood")) { | |
| 1731 | c.red = 0xde00; c.green = 0xb800; c.blue = 0x8700; | |
| 1732 | } else if (!g_strcasecmp (color, "cadetblue")) { | |
| 1733 | c.red = 0x5f00; c.green = 0x9e00; c.blue = 0xa000; | |
| 1734 | } else if (!g_strcasecmp (color, "chartreuse")) { | |
| 1735 | c.red = 0x7f00; c.green = 0xff00; c.blue = 0; | |
| 1736 | } else if (!g_strcasecmp (color, "chocolate")) { | |
| 1737 | c.red = 0xd200; c.green = 0x6900; c.blue = 0x1e00; | |
| 1738 | } else if (!g_strcasecmp (color, "coral")) { | |
| 1739 | c.red = 0xff00; c.green = 0x7f00; c.blue = 0x5000; | |
| 1740 | } else if (!g_strcasecmp (color, "cornflowerblue")) { | |
| 1741 | c.red = 0x6400; c.green = 0x9500; c.blue = 0xed00; | |
| 1742 | } else if (!g_strcasecmp (color, "cornsilk")) { | |
| 1743 | c.red = 0xff00; c.green = 0xf800; c.blue = 0xdc00; | |
| 1744 | } else if (!g_strcasecmp (color, "crimson")) { | |
| 1745 | c.red = 0xdc00; c.green = 0x1400; c.blue = 0x3c00; | |
| 1746 | } else if (!g_strcasecmp (color, "cyan")) { | |
| 1747 | c.red = 0; c.green = 0xff00; c.blue = 0xff00; | |
| 1748 | } else if (!g_strcasecmp (color, "darkblue")) { | |
| 1749 | c.red = 0; c.green = 0; c.blue = 0x8b00; | |
| 1750 | } else if (!g_strcasecmp (color, "darkcyan")) { | |
| 1751 | c.red = 0; c.green = 0x8b00; c.blue = 0x8b00; | |
| 1752 | } else if (!g_strcasecmp (color, "darkgoldenrod")) { | |
| 1753 | c.red = 0xb800; c.green = 0x8600; c.blue = 0x0b00; | |
| 1754 | } else if (!g_strcasecmp (color, "darkgray")) { | |
| 1755 | c.red = 0xa900; c.green = 0xa900; c.blue = 0xa900; | |
| 1756 | } else if (!g_strcasecmp (color, "darkgreen")) { | |
| 1757 | c.red = 0; c.green = 0x6400; c.blue = 0; | |
| 1758 | } else if (!g_strcasecmp (color, "darkkhaki")) { | |
| 1759 | c.red = 0xbd00; c.green = 0xb700; c.blue = 0x6b00; | |
| 1760 | } else if (!g_strcasecmp (color, "darkmagenta")) { | |
| 1761 | c.red = 0x8b00; c.green = 0; c.blue = 0x8b00; | |
| 1762 | } else if (!g_strcasecmp (color, "darkolivegreen")) { | |
| 1763 | c.red = 0x5500; c.green = 0x6b00; c.blue = 0x2f00; | |
| 1764 | } else if (!g_strcasecmp (color, "darkorange")) { | |
| 1765 | c.red = 0xff00; c.green = 0x8c00; c.blue = 0; | |
| 1766 | } else if (!g_strcasecmp (color, "darkorchid")) { | |
| 1767 | c.red = 0x9900; c.green = 0x3200; c.blue = 0xcc00; | |
| 1768 | } else if (!g_strcasecmp (color, "darkred")) { | |
| 1769 | c.red = 0x8b00; c.green = 0; c.blue = 0; | |
| 1770 | } else if (!g_strcasecmp (color, "darksalmon")) { | |
| 1771 | c.red = 0xe900; c.green = 0x9600; c.blue = 0x7a00; | |
| 1772 | } else if (!g_strcasecmp (color, "darkseagreen")) { | |
| 1773 | c.red = 0x8f00; c.green = 0xbc00; c.blue = 0x8f00; | |
| 1774 | } else if (!g_strcasecmp (color, "darkslateblue")) { | |
| 1775 | c.red = 0x4800; c.green = 0x3d00; c.blue = 0x8b00; | |
| 1776 | } else if (!g_strcasecmp (color, "darkslategray")) { | |
| 1777 | c.red = 0x2f00; c.green = 0x4f00; c.blue = 0x4f00; | |
| 1778 | } else if (!g_strcasecmp (color, "darkturquoise")) { | |
| 1779 | c.red = 0; c.green = 0xce00; c.blue = 0xd100; | |
| 1780 | } else if (!g_strcasecmp (color, "darkviolet")) { | |
| 1781 | c.red = 0x9400; c.green = 0; c.blue = 0xd300; | |
| 1782 | } else if (!g_strcasecmp (color, "deeppink")) { | |
| 1783 | c.red = 0xff00; c.green = 0x1400; c.blue = 0x9300; | |
| 1784 | } else if (!g_strcasecmp (color, "deepskyblue")) { | |
| 1785 | c.red = 0; c.green = 0xbf00; c.blue = 0xff00; | |
| 1786 | } else if (!g_strcasecmp (color, "dimgray")) { | |
| 1787 | c.red = 0x6900; c.green = 0x6900; c.blue = 0x6900; | |
| 1788 | } else if (!g_strcasecmp (color, "dodgerblue")) { | |
| 1789 | c.red = 0x1e00; c.green = 0x9000; c.blue = 0xff00; | |
| 1790 | } else if (!g_strcasecmp (color, "firebrick")) { | |
| 1791 | c.red = 0xb200; c.green = 0x2200; c.blue = 0x2200; | |
| 1792 | } else if (!g_strcasecmp (color, "floralwhite")) { | |
| 1793 | c.red = 0xff00; c.green = 0xfa00; c.blue = 0xf000; | |
| 1794 | } else if (!g_strcasecmp (color, "forestgreen")) { | |
| 1795 | c.red = 0x2200; c.green = 0x8b00; c.blue = 0x2200; | |
| 1796 | } else if (!g_strcasecmp (color, "fuchsia")) { | |
| 1797 | c.red = 0xff00; c.green = 0; c.blue = 0xff00; | |
| 1798 | } else if (!g_strcasecmp (color, "gainsboro")) { | |
| 1799 | c.red = 0xdc00; c.green = 0xdc00; c.blue = 0xdc00; | |
| 1800 | } else if (!g_strcasecmp (color, "ghostwhite")) { | |
| 1801 | c.red = 0xf800; c.green = 0xf800; c.blue = 0xff00; | |
| 1802 | } else if (!g_strcasecmp (color, "gold")) { | |
| 1803 | c.red = 0xff00; c.green = 0xd700; c.blue = 0; | |
| 1804 | } else if (!g_strcasecmp (color, "goldenrod")) { | |
| 1805 | c.red = 0xff00; c.green = 0xd700; c.blue = 0; | |
| 1806 | } else if (!g_strcasecmp (color, "gray")) { | |
| 1807 | c.red = 0x8000; c.green = 0x8000; c.blue = 0x8000; | |
| 1808 | } else if (!g_strcasecmp (color, "green")) { | |
| 1809 | c.red = 0; c.green = 0x8000; c.blue = 0; | |
| 1810 | } else if (!g_strcasecmp (color, "greenyellow")) { | |
| 1811 | c.red = 0; c.green = 0x8000; c.blue = 0; | |
| 1812 | } else if (!g_strcasecmp (color, "honeydew")) { | |
| 1813 | c.red = 0xf000; c.green = 0xff00; c.blue = 0xf000; | |
| 1814 | } else if (!g_strcasecmp (color, "hotpink")) { | |
| 1815 | c.red = 0xff00; c.green = 0x6900; c.blue = 0xb400; | |
| 1816 | } else if (!g_strcasecmp (color, "indianred")) { | |
| 1817 | c.red = 0xcd00; c.green = 0x5c00; c.blue = 0x5c00; | |
| 1818 | } else if (!g_strcasecmp (color, "indigo")) { | |
| 1819 | c.red = 0x4b00; c.green = 0; c.blue = 0x8200; | |
| 1820 | } else if (!g_strcasecmp (color, "ivory")) { | |
| 1821 | c.red = 0xff00; c.green = 0xff00; c.blue = 0xf000; | |
| 1822 | } else if (!g_strcasecmp (color, "khaki")) { | |
| 1823 | c.red = 0xf000; c.green = 0xe600; c.blue = 0x8c00; | |
| 1824 | } else if (!g_strcasecmp (color, "lavender")) { | |
| 1825 | c.red = 0xe600; c.green = 0xe600; c.blue = 0xfa00; | |
| 1826 | } else if (!g_strcasecmp (color, "lavenderblush")) { | |
| 1827 | c.red = 0xe600; c.green = 0xe600; c.blue = 0xfa00; | |
| 1828 | } else if (!g_strcasecmp (color, "lawngreen")) { | |
| 1829 | c.red = 0x7c00; c.green = 0xfc00; c.blue = 0; | |
| 1830 | } else if (!g_strcasecmp (color, "lemonchiffon")) { | |
| 1831 | c.red = 0xff00; c.green = 0xfa00; c.blue = 0xcd00; | |
| 1832 | } else if (!g_strcasecmp (color, "lightblue")) { | |
| 1833 | c.red = 0xad00; c.green = 0xd800; c.blue = 0xe600; | |
| 1834 | } else if (!g_strcasecmp (color, "lightcoral")) { | |
| 1835 | c.red = 0xf000; c.green = 0x8000; c.blue = 0x8000; | |
| 1836 | } else if (!g_strcasecmp (color, "lightcyan")) { | |
| 1837 | c.red = 0xe000; c.green = 0xff00; c.blue = 0xff00; | |
| 1838 | } else if (!g_strcasecmp (color, "lightgoldenrodyellow")) { | |
| 1839 | c.red = 0xfa00; c.green = 0xfa00; c.blue = 0xd200; | |
| 1840 | } else if (!g_strcasecmp (color, "lightgreen")) { | |
| 1841 | c.red = 0x9000; c.green = 0xee00; c.blue = 0x9000; | |
| 1842 | } else if (!g_strcasecmp (color, "lightgray")) { | |
| 1843 | c.red = 0xd300; c.green = 0xd300; c.blue = 0xd300; | |
| 1844 | } else if (!g_strcasecmp (color, "lightpink")) { | |
| 1845 | c.red = 0xff00; c.green = 0xb600; c.blue = 0xc100; | |
| 1846 | } else if (!g_strcasecmp (color, "lightsalmon")) { | |
| 1847 | c.red = 0xff00; c.green = 0xa000; c.blue = 0x7a00; | |
| 1848 | } else if (!g_strcasecmp (color, "lightseagreen")) { | |
| 1849 | c.red = 0x2000; c.green = 0xb200; c.blue = 0xaa00; | |
| 1850 | } else if (!g_strcasecmp (color, "lightskyblue")) { | |
| 1851 | c.red = 0x8700; c.green = 0xce00; c.blue = 0xfa00; | |
| 1852 | } else if (!g_strcasecmp (color, "lightslategray")) { | |
| 1853 | c.red = 0x7700; c.green = 0x8800; c.blue = 0x9900; | |
| 1854 | } else if (!g_strcasecmp (color, "lightsteelblue")) { | |
| 1855 | c.red = 0xb000; c.green = 0xc400; c.blue = 0xde00; | |
| 1856 | } else if (!g_strcasecmp (color, "lightyellow")) { | |
| 1857 | c.red = 0xff00; c.green = 0xff00; c.blue = 0xe000; | |
| 1858 | } else if (!g_strcasecmp (color, "lime")) { | |
| 1859 | c.red = 0; c.green = 0xff00; c.blue = 0; | |
| 1860 | } else if (!g_strcasecmp (color, "limegreen")) { | |
| 1861 | c.red = 0; c.green = 0xff00; c.blue = 0; | |
| 1862 | } else if (!g_strcasecmp (color, "linen")) { | |
| 1863 | c.red = 0xfa00; c.green = 0xf000; c.blue = 0xe600; | |
| 1864 | } else if (!g_strcasecmp (color, "magenta")) { | |
| 1865 | c.red = 0xff00; c.green = 0; c.blue = 0xff00; | |
| 1866 | } else if (!g_strcasecmp (color, "maroon")) { | |
| 1867 | c.red = 0x8000; c.green = 0; c.blue = 0; | |
| 1868 | } else if (!g_strcasecmp (color, "mediumaquamarine")) { | |
| 1869 | c.red = 0x6600; c.green = 0xcd00; c.blue = 0xaa00; | |
| 1870 | } else if (!g_strcasecmp (color, "mediumblue")) { | |
| 1871 | c.red = 0; c.green = 0; c.blue = 0xcd00; | |
| 1872 | } else if (!g_strcasecmp (color, "mediumorchid")) { | |
| 1873 | c.red = 0xba00; c.green = 0x5500; c.blue = 0xd300; | |
| 1874 | } else if (!g_strcasecmp (color, "mediumpurple")) { | |
| 1875 | c.red = 0x93; c.green = 0x7000; c.blue = 0xdb00; | |
| 1876 | } else if (!g_strcasecmp (color, "mediumseagreen")) { | |
| 1877 | c.red = 0x3c00; c.green = 0xb300; c.blue = 0x7100; | |
| 1878 | } else if (!g_strcasecmp (color, "mediumslateblue")) { | |
| 1879 | c.red = 0x7b00; c.green = 0x6800; c.blue = 0xee00; | |
| 1880 | } else if (!g_strcasecmp (color, "mediumspringgreen")) { | |
| 1881 | c.red = 0; c.green = 0xfa00; c.blue = 0x9a00; | |
| 1882 | } else if (!g_strcasecmp (color, "mediumturquoise")) { | |
| 1883 | c.red = 0x4800; c.green = 0xd100; c.blue = 0xcc00; | |
| 1884 | } else if (!g_strcasecmp (color, "mediumvioletred")) { | |
| 1885 | c.red = 0xc700; c.green = 0x1500; c.blue = 0x8500; | |
| 1886 | } else if (!g_strcasecmp (color, "midnightblue")) { | |
| 1887 | c.red = 0x1900; c.green = 0x1900; c.blue = 0x7000; | |
| 1888 | } else if (!g_strcasecmp (color, "mintcream")) { | |
| 1889 | c.red = 0xf500; c.green = 0xff00; c.blue = 0xfa00; | |
| 1890 | } else if (!g_strcasecmp (color, "mistyrose")) { | |
| 1891 | c.red = 0xff00; c.green = 0xe400; c.blue = 0xe100; | |
| 1892 | } else if (!g_strcasecmp (color, "moccasin")) { | |
| 1893 | c.red = 0xff00; c.green = 0xe400; c.blue = 0xb500; | |
| 1894 | } else if (!g_strcasecmp (color, "navajowhite")) { | |
| 1895 | c.red = 0xff00; c.green = 0xde00; c.blue = 0xad00; | |
| 1896 | } else if (!g_strcasecmp (color, "navy")) { | |
| 1897 | c.red = 0; c.green = 0x8000; c.blue = 0; | |
| 1898 | } else if (!g_strcasecmp (color, "oldlace")) { | |
| 1899 | c.red = 0xfd00; c.green = 0xf500; c.blue = 0xe600; | |
| 1900 | } else if (!g_strcasecmp (color, "olive")) { | |
| 1901 | c.red = 0x8000; c.green = 0x8000; c.blue = 0; | |
| 1902 | } else if (!g_strcasecmp (color, "olivedrab")) { | |
| 1903 | c.red = 0x8000; c.green = 0x8000; c.blue = 0; | |
| 1904 | } else if (!g_strcasecmp (color, "orange")) { | |
| 1905 | c.red = 0xff00; c.green = 0xa500; c.blue = 0; | |
| 1906 | } else if (!g_strcasecmp (color, "orangered")) { | |
| 1907 | c.red = 0xff00; c.green = 0xa500; c.blue = 0; | |
| 1908 | } else if (!g_strcasecmp (color, "orchid")) { | |
| 1909 | c.red = 0xda00; c.green = 0x7000; c.blue = 0xd600; | |
| 1910 | } else if (!g_strcasecmp (color, "palegoldenrod")) { | |
| 1911 | c.red = 0xee00; c.green = 0xe800; c.blue = 0xaa00; | |
| 1912 | } else if (!g_strcasecmp (color, "palegreen")) { | |
| 1913 | c.red = 0x9800; c.green = 0xfb00; c.blue = 0x9800; | |
| 1914 | } else if (!g_strcasecmp (color, "paleturquoise")) { | |
| 1915 | c.red = 0xaf00; c.green = 0xee00; c.blue = 0xee00; | |
| 1916 | } else if (!g_strcasecmp (color, "palevioletred")) { | |
| 1917 | c.red = 0xdb00; c.green = 0x7000; c.blue = 0x9300; | |
| 1918 | } else if (!g_strcasecmp (color, "papayawhip")) { | |
| 1919 | c.red = 0xff00; c.green = 0xef00; c.blue = 0xd500; | |
| 1920 | } else if (!g_strcasecmp (color, "peachpuff")) { | |
| 1921 | c.red = 0xff00; c.green = 0xda00; c.blue = 0xb900; | |
| 1922 | } else if (!g_strcasecmp (color, "peru")) { | |
| 1923 | c.red = 0xcd00; c.green = 0x8500; c.blue = 0x3f00; | |
| 1924 | } else if (!g_strcasecmp (color, "pink")) { | |
| 1925 | c.red = 0xff00; c.green = 0xc000; c.blue = 0xcb00; | |
| 1926 | } else if (!g_strcasecmp (color, "plum")) { | |
| 1927 | c.red = 0xdd00; c.green = 0xa000; c.blue = 0xdd00; | |
| 1928 | } else if (!g_strcasecmp (color, "powderblue")) { | |
| 1929 | c.red = 0xb000; c.green = 0xe000; c.blue = 0xe600; | |
| 1930 | } else if (!g_strcasecmp (color, "purple")) { | |
| 1931 | c.red = 0x8000; c.green = 0; c.blue = 0x8000; | |
| 1932 | } else if (!g_strcasecmp (color, "red")) { | |
| 1933 | c.red = 0xff00; c.green = 0; c.blue = 0; | |
| 1934 | } else if (!g_strcasecmp (color, "rosybrown")) { | |
| 1935 | c.red = 0xbc00; c.green = 0x8f00; c.blue = 0x8f00; | |
| 1936 | } else if (!g_strcasecmp (color, "royalblue")) { | |
| 1937 | c.red = 0x4100; c.green = 0x6900; c.blue = 0xe100; | |
| 1938 | } else if (!g_strcasecmp (color, "saddlebrown")) { | |
| 1939 | c.red = 0x8b00; c.green = 0x4500; c.blue = 0x1300; | |
| 1940 | } else if (!g_strcasecmp (color, "salmon")) { | |
| 1941 | c.red = 0xfa00; c.green = 0x8000; c.blue = 0x7200; | |
| 1942 | } else if (!g_strcasecmp (color, "sandybrown")) { | |
| 1943 | c.red = 0xf400; c.green = 0xa400; c.blue = 0x6000; | |
| 1944 | } else if (!g_strcasecmp (color, "seagreen")) { | |
| 1945 | c.red = 0x2e00; c.green = 0x8b00; c.blue = 0x5700; | |
| 1946 | } else if (!g_strcasecmp (color, "seashell")) { | |
| 1947 | c.red = 0xff00; c.green = 0xf500; c.blue = 0xee00; | |
| 1948 | } else if (!g_strcasecmp (color, "sienna")) { | |
| 1949 | c.red = 0xa000; c.green = 0x5200; c.blue = 0x2d00; | |
| 1950 | } else if (!g_strcasecmp (color, "silver")) { | |
| 1951 | c.red = 0xc000; c.green = 0xc000; c.blue = 0xc000; | |
| 1952 | } else if (!g_strcasecmp (color, "skyblue")) { | |
| 1953 | c.red = 0x8700; c.green = 0xce00; c.blue = 0xeb00; | |
| 1954 | } else if (!g_strcasecmp (color, "slateblue")) { | |
| 1955 | c.red = 0x6a00; c.green = 0x5a00; c.blue = 0xcd00; | |
| 1956 | } else if (!g_strcasecmp (color, "slategray")) { | |
| 1957 | c.red = 0x7000; c.green = 0x8000; c.blue = 0x9000; | |
| 1958 | } else if (!g_strcasecmp (color, "springgreen")) { | |
| 1959 | c.red = 0; c.green = 0xff00; c.blue = 0x7f00; | |
| 1960 | } else if (!g_strcasecmp (color, "steelblue")) { | |
| 1961 | c.red = 0x4600; c.green = 0x8200; c.blue = 0xb400; | |
| 1962 | } else if (!g_strcasecmp (color, "teal")) { | |
| 1963 | c.red = 0; c.green = 0x8000; c.blue = 0x8000; | |
| 1964 | } else if (!g_strcasecmp (color, "thistle")) { | |
| 1965 | c.red = 0xd800; c.green = 0xbf00; c.blue = 0xd800; | |
| 1966 | } else if (!g_strcasecmp (color, "tomato")) { | |
| 1967 | c.red = 0xff00; c.green = 0x6300; c.blue = 0x4700; | |
| 1968 | } else if (!g_strcasecmp (color, "turquoise")) { | |
| 1969 | c.red = 0x4000; c.green = 0xe000; c.blue = 0xd000; | |
| 1970 | } else if (!g_strcasecmp (color, "violet")) { | |
| 1971 | c.red = 0xee00; c.green = 0x8200; c.blue = 0xee00; | |
| 1972 | } else if (!g_strcasecmp (color, "wheat")) { | |
| 1973 | c.red = 0xf500; c.green = 0xde00; c.blue = 0xb300; | |
| 1974 | } else if (!g_strcasecmp (color, "white")) { | |
| 1975 | c.red = 0xfe00; c.green = 0xfe00; c.blue = 0xfe00; | |
| 1976 | } else if (!g_strcasecmp (color, "whitesmoke")) { | |
| 1977 | c.red = 0xfe00; c.green = 0xfe00; c.blue = 0xfe00; | |
| 1978 | } else if (!g_strcasecmp (color, "yellow")) { | |
| 1979 | c.red = 0xff00; c.green = 0xff00; c.blue = 0; | |
| 1980 | } else if (!g_strcasecmp (color, "yellowgreen")) { | |
| 1981 | c.red = 0xff00; c.green = 0xff00; c.blue = 0; | |
| 1982 | } else { | |
| 1983 | const gchar *hex; | |
| 1984 | guint32 value; | |
| 1985 | ||
| 1986 | if (color [0] == '#') | |
| 1987 | hex = color + 1; | |
| 1988 | else | |
| 1989 | hex = color; | |
| 1990 | ||
| 1991 | if (strlen (hex) == 6) { | |
| 1992 | gint i = 0; | |
| 1993 | for ( ; i < 6; i++) | |
| 1994 | if (!isxdigit ((gint) hex [i])) | |
| 1995 | break; | |
| 1996 | if (i == 6) { | |
| 1997 | sscanf (hex, "%x", &value); | |
| 1998 | c.red = (value & 0xff0000) >> 8; | |
| 1999 | c.green = value & 0xff00; | |
| 2000 | c.blue = (value & 0xff) << 8; | |
| 2001 | } else { | |
| 2002 | valid = FALSE; | |
| 2003 | } | |
| 2004 | } else { | |
| 2005 | valid = FALSE; | |
| 2006 | } | |
| 2007 | } | |
| 2008 | ||
| 2009 | if (valid) | |
| 2010 | return gdk_color_copy (&c); | |
| 2011 | ||
| 2012 | return NULL; | |
| 2013 | } | |
| 2014 | ||
| 2015 | static gint | |
| 2016 | gtk_imhtml_is_smiley (GtkIMHtml *imhtml, | |
| 2017 | const gchar *text) | |
| 2018 | { | |
| 2019 | gchar *tmp; | |
| 2020 | gint i; | |
| 2021 | ||
| 2022 | g_return_val_if_fail (imhtml != NULL, 0); | |
| 2023 | g_return_val_if_fail (GTK_IS_IMHTML (imhtml), 0); | |
| 2024 | g_return_val_if_fail (text != NULL, 0); | |
| 2025 | ||
| 2026 | tmp = g_malloc (imhtml->smax + 1); | |
| 2027 | ||
| 2028 | for (i = imhtml->smin; i <= imhtml->smax; i++) { | |
| 2029 | if (strlen (text) < i) { | |
| 2030 | g_free (tmp); | |
| 2031 | return 0; | |
| 2032 | } | |
| 2033 | g_snprintf (tmp, i + 1, "%s", text); | |
| 2034 | if (g_hash_table_lookup (imhtml->smiley_hash, tmp)) { | |
| 2035 | g_free (tmp); | |
| 2036 | return i; | |
| 2037 | } | |
| 2038 | } | |
| 2039 | ||
| 2040 | g_free (tmp); | |
| 2041 | return 0; | |
| 2042 | } | |
| 2043 | ||
| 2044 | static GtkIMHtmlBit * | |
| 2045 | gtk_imhtml_new_bit (GtkIMHtml *imhtml, | |
| 2046 | gint type, | |
| 2047 | gchar *text, | |
| 2048 | gint bold, | |
| 2049 | gint italics, | |
| 2050 | gint underline, | |
| 2051 | gint strike, | |
| 2052 | FontDetail *font, | |
| 2053 | GdkColor *bg, | |
| 2054 | gchar *url) | |
| 2055 | { | |
| 2056 | GtkIMHtmlBit *bit = NULL; | |
| 2057 | ||
| 2058 | g_return_val_if_fail (imhtml != NULL, NULL); | |
| 2059 | g_return_val_if_fail (GTK_IS_IMHTML (imhtml), NULL); | |
| 2060 | ||
| 2061 | if ((type == TYPE_TEXT) && ((text == NULL) || (strlen (text) == 0))) | |
| 2062 | return NULL; | |
| 2063 | ||
| 2064 | bit = g_new0 (GtkIMHtmlBit, 1); | |
| 2065 | bit->type = type; | |
| 2066 | ||
| 2067 | if ((text != NULL) && (strlen (text) != 0)) | |
| 2068 | bit->text = g_strdup (text); | |
| 2069 | ||
| 2070 | if ((font != NULL) || bold || italics) { | |
| 2071 | if (font && (bold || italics || font->size || font->face)) { | |
| 2072 | bit->font = gtk_imhtml_font_load (imhtml, font->face, bold, italics, font->size); | |
| 2073 | } else if (bold || italics) { | |
| 2074 | bit->font = gtk_imhtml_font_load (imhtml, NULL, bold, italics, 0); | |
| 2075 | } | |
| 2076 | ||
| 2077 | if (font && (type != TYPE_BR)) { | |
| 2078 | if (font->fore != NULL) | |
| 2079 | bit->fore = gdk_color_copy (font->fore); | |
| 2080 | ||
| 2081 | if (font->back != NULL) | |
| 2082 | bit->back = gdk_color_copy (font->back); | |
| 2083 | } | |
| 2084 | } | |
| 2085 | ||
| 2086 | if (((bit->type == TYPE_TEXT) || (bit->type == TYPE_SMILEY) || (bit->type == TYPE_COMMENT)) && | |
| 2087 | (bit->font == NULL)) | |
| 2088 | bit->font = gdk_font_ref (imhtml->default_font); | |
| 2089 | ||
| 2090 | if (bg != NULL) | |
| 2091 | bit->bg = gdk_color_copy (bg); | |
| 2092 | ||
| 2093 | bit->underline = underline; | |
| 2094 | bit->strike = strike; | |
| 2095 | ||
| 2096 | if (url != NULL) | |
| 2097 | bit->url = g_strdup (url); | |
| 2098 | ||
| 2099 | if (type == TYPE_SMILEY) { | |
| 2100 | GdkColor *clr; | |
| 2101 | ||
| 2102 | if ((font != NULL) && (font->back != NULL)) | |
| 2103 | clr = font->back; | |
| 2104 | else | |
| 2105 | clr = (bg != NULL) ? bg : >K_WIDGET (imhtml)->style->white; | |
| 2106 | ||
| 2107 | bit->pm = gdk_pixmap_create_from_xpm_d (GTK_WIDGET (imhtml)->window, | |
| 2108 | &bit->bm, | |
| 2109 | clr, | |
| 2110 | g_hash_table_lookup (imhtml->smiley_hash, text)); | |
| 2111 | } | |
| 2112 | ||
| 2113 | return bit; | |
| 2114 | } | |
| 2115 | ||
| 2116 | #define NEW_TEXT_BIT gtk_imhtml_new_bit (imhtml, TYPE_TEXT, ws, bold, italics, underline, strike, \ | |
| 2117 | fonts ? fonts->data : NULL, bg, url) | |
| 2118 | #define NEW_SMILEY_BIT gtk_imhtml_new_bit (imhtml, TYPE_SMILEY, ws, bold, italics, underline, strike, \ | |
| 2119 | fonts ? fonts->data : NULL, bg, url) | |
| 2120 | #define NEW_SEP_BIT gtk_imhtml_new_bit (imhtml, TYPE_SEP, NULL, 0, 0, 0, 0, NULL, bg, NULL) | |
| 2121 | #define NEW_BR_BIT gtk_imhtml_new_bit (imhtml, TYPE_BR, NULL, 0, 0, 0, 0, \ | |
| 2122 | fonts ? fonts->data : NULL, bg, NULL) | |
| 2123 | #define NEW_COMMENT_BIT gtk_imhtml_new_bit (imhtml, TYPE_COMMENT, ws, bold, italics, underline, strike, \ | |
| 2124 | fonts ? fonts->data : NULL, bg, url) | |
| 2125 | ||
| 2126 | #define NEW_BIT(bit) { GtkIMHtmlBit *tmp = bit; if (tmp != NULL) \ | |
| 2127 | newbits = g_list_append (newbits, tmp); } | |
| 2128 | ||
| 2129 | #define UPDATE_BG_COLORS \ | |
| 2130 | { \ | |
| 2131 | GdkColormap *cmap; \ | |
| 2132 | GList *rev; \ | |
| 2133 | cmap = gdk_colormap_new (gdk_visual_get_best (), FALSE); \ | |
| 2134 | rev = g_list_last (newbits); \ | |
| 2135 | while (rev) { \ | |
| 2136 | GtkIMHtmlBit *bit = rev->data; \ | |
| 2137 | if (bit->type == TYPE_BR) \ | |
| 2138 | break; \ | |
| 2139 | if (bit->bg) \ | |
| 2140 | gdk_color_free (bit->bg); \ | |
| 2141 | bit->bg = gdk_color_copy (bg); \ | |
| 2142 | rev = g_list_previous (rev); \ | |
| 2143 | } \ | |
| 2144 | if (!rev) { \ | |
| 2145 | rev = g_list_last (imhtml->bits); \ | |
| 2146 | while (rev) { \ | |
| 2147 | GList *ln; \ | |
| 2148 | GtkIMHtmlBit *bit = rev->data; \ | |
| 2149 | if (bit->type == TYPE_BR) \ | |
| 2150 | break; \ | |
| 2151 | if (bit->bg) \ | |
| 2152 | gdk_color_free (bit->bg); \ | |
| 2153 | bit->bg = gdk_color_copy (bg); \ | |
| 2154 | gdk_color_alloc (cmap, bit->bg); \ | |
| 2155 | ln = bit->chunks; \ | |
| 2156 | while (ln) { \ | |
| 2157 | GtkWidget *widget = ln->data; \ | |
| 2158 | gdk_window_set_background (widget->window, bit->bg); \ | |
| 2159 | ln = g_list_next (ln); \ | |
| 2160 | } \ | |
| 2161 | rev = g_list_previous (rev); \ | |
| 2162 | } \ | |
| 2163 | gdk_colormap_unref (cmap); \ | |
| 2164 | } \ | |
| 2165 | } | |
| 2166 | ||
| 2167 | GString* | |
| 2168 | gtk_imhtml_append_text (GtkIMHtml *imhtml, | |
| 2169 | const gchar *text, | |
| 2170 | GtkIMHtmlOptions options) | |
| 2171 | { | |
| 2172 | const gchar *c; | |
| 2173 | gboolean intag = FALSE; | |
| 2174 | gboolean tagquote = FALSE; | |
| 2175 | gboolean incomment = FALSE; | |
| 2176 | gchar *ws; | |
| 2177 | gchar *tag; | |
| 2178 | gint wpos = 0; | |
| 2179 | gint tpos = 0; | |
| 2180 | int smilelen; | |
| 2181 | GList *newbits = NULL; | |
| 2182 | ||
| 2183 | guint bold = 0, | |
| 2184 | italics = 0, | |
| 2185 | underline = 0, | |
| 2186 | strike = 0, | |
| 2187 | sub = 0, | |
| 2188 | sup = 0, | |
| 2189 | title = 0; | |
| 2190 | GSList *fonts = NULL; | |
| 2191 | GdkColor *bg = NULL; | |
| 2192 | gchar *url = NULL; | |
| 2193 | ||
| 2194 | GtkAdjustment *vadj; | |
| 2195 | gboolean scrolldown = TRUE; | |
| 2196 | ||
| 2197 | GString *retval = NULL; | |
| 2198 | ||
| 2199 | g_return_val_if_fail (imhtml != NULL, NULL); | |
| 2200 | g_return_val_if_fail (GTK_IS_IMHTML (imhtml), NULL); | |
| 2201 | g_return_val_if_fail (text != NULL, NULL); | |
| 2202 | ||
| 2203 | if (options & GTK_IMHTML_RETURN_LOG) | |
| 2204 | retval = g_string_new (""); | |
| 2205 | ||
| 2206 | vadj = GTK_LAYOUT (imhtml)->vadjustment; | |
| 2207 | if ((vadj->value < imhtml->y + 5 - GTK_WIDGET (imhtml)->allocation.height) && | |
| 2208 | (vadj->upper >= GTK_WIDGET (imhtml)->allocation.height)) | |
| 2209 | scrolldown = FALSE; | |
| 2210 | ||
| 2211 | c = text; | |
| 2212 | ws = g_malloc (strlen (text) + 1); | |
| 2213 | tag = g_malloc (strlen (text) + 1); | |
| 2214 | ||
| 2215 | ws [0] = '\0'; | |
| 2216 | ||
| 2217 | while (*c) { | |
| 2218 | if (*c == '<') { | |
| 2219 | if (intag) { | |
| 2220 | ws [wpos] = 0; | |
| 2221 | tag [tpos] = 0; | |
| 2222 | tpos = 0; | |
| 2223 | strcat (ws, tag); | |
| 2224 | wpos = strlen (ws); | |
| 2225 | } | |
| 2226 | ||
| 2227 | if (incomment) { | |
| 2228 | ws [wpos++] = *c++; | |
| 2229 | continue; | |
| 2230 | } | |
| 2231 | ||
| 2232 | if (!g_strncasecmp (c, "<!--", strlen ("<!--"))) { | |
| 2233 | if (!(options & GTK_IMHTML_NO_COMMENTS)) { | |
| 2234 | ws [wpos] = 0; | |
| 2235 | wpos = 0; | |
| 2236 | tag [tpos] = 0; | |
| 2237 | strcat (tag, ws); | |
| 2238 | incomment = TRUE; | |
| 2239 | intag = FALSE; | |
| 2240 | } | |
| 2241 | ws [wpos++] = *c++; | |
| 2242 | ws [wpos++] = *c++; | |
| 2243 | ws [wpos++] = *c++; | |
| 2244 | ws [wpos++] = *c++; | |
| 2245 | continue; | |
| 2246 | } | |
| 2247 | ||
| 2248 | tag [tpos++] = *c++; | |
| 2249 | intag = TRUE; | |
| 2250 | } else if (incomment && (*c == '-') && !g_strncasecmp (c, "-->", strlen ("-->"))) { | |
| 2251 | gchar *tmp; | |
| 2252 | ws [wpos] = 0; | |
| 2253 | wpos = 0; | |
| 2254 | tmp = g_strdup (ws); | |
| 2255 | ws [wpos] = 0; | |
| 2256 | strcat (ws, tag); | |
| 2257 | NEW_BIT (NEW_TEXT_BIT); | |
| 2258 | ws [wpos] = 0; | |
| 2259 | strcat (ws, tmp + strlen ("<!--")); | |
| 2260 | g_free (tmp); | |
| 2261 | NEW_BIT (NEW_COMMENT_BIT); | |
| 2262 | incomment = FALSE; | |
| 2263 | c += strlen ("-->"); | |
| 2264 | } else if (*c == '>' && intag && !tagquote) { | |
| 2265 | gboolean got_tag = FALSE; | |
| 2266 | tag [tpos++] = *c++; | |
| 2267 | tag [tpos] = 0; | |
| 2268 | ws [wpos] = 0; | |
| 2269 | ||
| 2270 | if (!g_strcasecmp (tag, "<B>") || !g_strcasecmp (tag, "<BOLD>")) { | |
| 2271 | got_tag = TRUE; | |
| 2272 | NEW_BIT (NEW_TEXT_BIT); | |
| 2273 | bold++; | |
| 2274 | } else if (!g_strcasecmp (tag, "</B>") || !g_strcasecmp (tag, "</BOLD>")) { | |
| 2275 | got_tag = TRUE; | |
| 2276 | if (bold) { | |
| 2277 | NEW_BIT (NEW_TEXT_BIT); | |
| 2278 | bold--; | |
| 2279 | } | |
| 2280 | } else if (!g_strcasecmp (tag, "<I>") || !g_strcasecmp (tag, "<ITALIC>")) { | |
| 2281 | got_tag = TRUE; | |
| 2282 | NEW_BIT (NEW_TEXT_BIT); | |
| 2283 | italics++; | |
| 2284 | } else if (!g_strcasecmp (tag, "</I>") || !g_strcasecmp (tag, "</ITALIC>")) { | |
| 2285 | got_tag = TRUE; | |
| 2286 | if (italics) { | |
| 2287 | NEW_BIT (NEW_TEXT_BIT); | |
| 2288 | italics--; | |
| 2289 | } | |
| 2290 | } else if (!g_strcasecmp (tag, "<U>") || !g_strcasecmp (tag, "<UNDERLINE>")) { | |
| 2291 | got_tag = TRUE; | |
| 2292 | NEW_BIT (NEW_TEXT_BIT); | |
| 2293 | underline++; | |
| 2294 | } else if (!g_strcasecmp (tag, "</U>") || !g_strcasecmp (tag, "</UNDERLINE>")) { | |
| 2295 | got_tag = TRUE; | |
| 2296 | if (underline) { | |
| 2297 | NEW_BIT (NEW_TEXT_BIT); | |
| 2298 | underline--; | |
| 2299 | } | |
| 2300 | } else if (!g_strcasecmp (tag, "<S>") || !g_strcasecmp (tag, "<STRIKE>")) { | |
| 2301 | got_tag = TRUE; | |
| 2302 | NEW_BIT (NEW_TEXT_BIT); | |
| 2303 | strike++; | |
| 2304 | } else if (!g_strcasecmp (tag, "</S>") || !g_strcasecmp (tag, "</STRIKE>")) { | |
| 2305 | got_tag = TRUE; | |
| 2306 | if (strike) { | |
| 2307 | NEW_BIT (NEW_TEXT_BIT); | |
| 2308 | strike--; | |
| 2309 | } | |
| 2310 | } else if (!g_strcasecmp (tag, "<SUB>")) { | |
| 2311 | got_tag = TRUE; | |
| 2312 | sub++; | |
| 2313 | } else if (!g_strcasecmp (tag, "</SUB>")) { | |
| 2314 | got_tag = TRUE; | |
| 2315 | if (sub) { | |
| 2316 | sub--; | |
| 2317 | } | |
| 2318 | } else if (!g_strcasecmp (tag, "<SUP>")) { | |
| 2319 | got_tag = TRUE; | |
| 2320 | sup++; | |
| 2321 | } else if (!g_strcasecmp (tag, "</SUP>")) { | |
| 2322 | got_tag = TRUE; | |
| 2323 | if (sup) { | |
| 2324 | sup--; | |
| 2325 | } | |
| 2326 | } else if (!g_strcasecmp (tag, "<TITLE>")) { | |
| 2327 | if (options & GTK_IMHTML_NO_TITLE) { | |
| 2328 | got_tag = TRUE; | |
| 2329 | title++; | |
| 2330 | } else { | |
| 2331 | intag = FALSE; | |
| 2332 | tpos = 0; | |
| 2333 | continue; | |
| 2334 | } | |
| 2335 | } else if (!g_strcasecmp (tag, "</TITLE>")) { | |
| 2336 | if (title) { | |
| 2337 | got_tag = TRUE; | |
| 2338 | wpos = 0; | |
| 2339 | ws [wpos] = '\0'; | |
| 2340 | title--; | |
| 2341 | } else { | |
| 2342 | intag = FALSE; | |
| 2343 | tpos = 0; | |
| 2344 | continue; | |
| 2345 | } | |
| 2346 | } else if (!g_strcasecmp (tag, "<BR>")) { | |
| 2347 | got_tag = TRUE; | |
| 2348 | NEW_BIT (NEW_TEXT_BIT); | |
| 2349 | NEW_BIT (NEW_BR_BIT); | |
| 2350 | } else if (!g_strcasecmp (tag, "<HR>") || | |
| 2351 | !g_strncasecmp (tag, "<HR ", strlen ("<HR "))) { | |
| 2352 | got_tag = TRUE; | |
| 2353 | NEW_BIT (NEW_TEXT_BIT); | |
| 2354 | NEW_BIT (NEW_SEP_BIT); | |
| 2355 | } else if (!g_strncasecmp (tag, "<FONT ", strlen ("<FONT "))) { | |
| 2356 | gchar *t, *e, *a, *value; | |
| 2357 | FontDetail *font = NULL; | |
| 2358 | GdkColor *clr; | |
| 2359 | gint saw; | |
| 2360 | gint i; | |
| 2361 | ||
| 2362 | t = tag + strlen ("<FONT "); | |
| 2363 | ||
| 2364 | while (*t != '\0') { | |
| 2365 | value = NULL; | |
| 2366 | saw = 0; | |
| 2367 | ||
| 2368 | while (g_strncasecmp (t, "COLOR=", strlen ("COLOR=")) | |
| 2369 | && g_strncasecmp (t, "BACK=", strlen ("BACK=")) | |
| 2370 | && g_strncasecmp (t, "FACE=", strlen ("FACE=")) | |
| 2371 | && g_strncasecmp (t, "SIZE=", strlen ("SIZE="))) { | |
| 2372 | gboolean quote = FALSE; | |
| 2373 | if (*t == '\0') break; | |
| 2374 | while (*t && !((*t == ' ') && !quote)) { | |
| 2375 | if (*t == '\"') | |
| 2376 | quote = ! quote; | |
| 2377 | t++; | |
| 2378 | } | |
| 2379 | while (*t && (*t == ' ')) t++; | |
| 2380 | } | |
| 2381 | ||
| 2382 | if (!g_strncasecmp (t, "COLOR=", strlen ("COLOR="))) { | |
| 2383 | t += strlen ("COLOR="); | |
| 2384 | saw = 1; | |
| 2385 | } else if (!g_strncasecmp (t, "BACK=", strlen ("BACK="))) { | |
| 2386 | t += strlen ("BACK="); | |
| 2387 | saw = 2; | |
| 2388 | } else if (!g_strncasecmp (t, "FACE=", strlen ("FACE="))) { | |
| 2389 | t += strlen ("FACE="); | |
| 2390 | saw = 3; | |
| 2391 | } else if (!g_strncasecmp (t, "SIZE=", strlen ("SIZE="))) { | |
| 2392 | t += strlen ("SIZE="); | |
| 2393 | saw = 4; | |
| 2394 | } | |
| 2395 | ||
| 2396 | if (!saw) | |
| 2397 | continue; | |
| 2398 | ||
| 2399 | if ((*t == '\"') || (*t == '\'')) { | |
| 2400 | e = a = ++t; | |
| 2401 | while (*e && (*e != *(t - 1))) e++; | |
| 2402 | if (*e != '\0') { | |
| 2403 | *e = '\0'; | |
| 2404 | t = e + 1; | |
| 2405 | value = g_strdup (a); | |
| 2406 | } else { | |
| 2407 | *t = '\0'; | |
| 2408 | } | |
| 2409 | } else { | |
| 2410 | e = a = t; | |
| 2411 | while (*e && !isspace ((gint) *e)) e++; | |
| 2412 | if (*e == '\0') e--; | |
| 2413 | *e = '\0'; | |
| 2414 | t = e + 1; | |
| 2415 | value = g_strdup (a); | |
| 2416 | } | |
| 2417 | ||
| 2418 | if (value == NULL) | |
| 2419 | continue; | |
| 2420 | ||
| 2421 | if (font == NULL) | |
| 2422 | font = g_new0 (FontDetail, 1); | |
| 2423 | ||
| 2424 | switch (saw) { | |
| 2425 | case 1: | |
| 2426 | clr = gtk_imhtml_get_color (value); | |
| 2427 | if (clr != NULL) { | |
| 2428 | if ( (font->fore == NULL) && | |
| 2429 | !(options & GTK_IMHTML_NO_COLOURS)) | |
| 2430 | font->fore = clr; | |
| 2431 | } | |
| 2432 | break; | |
| 2433 | case 2: | |
| 2434 | clr = gtk_imhtml_get_color (value); | |
| 2435 | if (clr != NULL) { | |
| 2436 | if ( (font->back == NULL) && | |
| 2437 | !(options & GTK_IMHTML_NO_COLOURS)) | |
| 2438 | font->back = clr; | |
| 2439 | } | |
| 2440 | break; | |
| 2441 | case 3: | |
| 2442 | if ( (font->face == NULL) && | |
| 2443 | !(options & GTK_IMHTML_NO_FONTS)) | |
| 2444 | font->face = g_strdup (value); | |
| 2445 | break; | |
| 2446 | case 4: | |
| 2447 | if ((font->size != 0) || | |
| 2448 | (options & GTK_IMHTML_NO_SIZES)) | |
| 2449 | break; | |
| 2450 | ||
| 2451 | if (isdigit ((gint) value [0])) { | |
| 2452 | for (i = 0; i < strlen (value); i++) | |
| 2453 | if (!isdigit ((gint) value [i])) | |
| 2454 | break; | |
| 2455 | if (i != strlen (value)) | |
| 2456 | break; | |
| 2457 | ||
| 2458 | sscanf (value, "%hd", &font->size); | |
| 2459 | break; | |
| 2460 | } | |
| 2461 | ||
| 2462 | if ((value [0] == '+') && (value [1] != '\0')) { | |
| 2463 | for (i = 1; i < strlen (value); i++) | |
| 2464 | if (!isdigit ((gint) value [i])) | |
| 2465 | break; | |
| 2466 | if (i != strlen (value)) | |
| 2467 | break; | |
| 2468 | ||
| 2469 | sscanf (value + 1, "%hd", &font->size); | |
| 2470 | font->size += 3; | |
| 2471 | break; | |
| 2472 | } | |
| 2473 | ||
| 2474 | if ((value [0] == '-') && (value [1] != '\0')) { | |
| 2475 | for (i = 1; i < strlen (value); i++) | |
| 2476 | if (!isdigit ((gint) value [i])) | |
| 2477 | break; | |
| 2478 | if (i != strlen (value)) | |
| 2479 | break; | |
| 2480 | ||
| 2481 | sscanf (value + 1, "%hd", &font->size); | |
| 2482 | font->size = MIN (font->size, 2); | |
| 2483 | font->size = 3 - font->size; | |
| 2484 | break; | |
| 2485 | } | |
| 2486 | ||
| 2487 | break; | |
| 2488 | } | |
| 2489 | ||
| 2490 | g_free (value); | |
| 2491 | } | |
| 2492 | ||
| 2493 | if (!font) { | |
| 2494 | intag = FALSE; | |
| 2495 | tpos = 0; | |
| 2496 | continue; | |
| 2497 | } | |
| 2498 | ||
| 2499 | if (!(font->size || font->face || font->fore || font->back)) { | |
| 2500 | g_free (font); | |
| 2501 | intag = FALSE; | |
| 2502 | tpos = 0; | |
| 2503 | continue; | |
| 2504 | } | |
| 2505 | ||
| 2506 | NEW_BIT (NEW_TEXT_BIT); | |
| 2507 | ||
| 2508 | if (fonts) { | |
| 2509 | FontDetail *oldfont = fonts->data; | |
| 2510 | if (!font->size) | |
| 2511 | font->size = oldfont->size; | |
| 2512 | if (!font->face) | |
| 2513 | font->face = g_strdup (oldfont->face); | |
| 2514 | if (!font->fore && oldfont->fore) | |
| 2515 | font->fore = gdk_color_copy (oldfont->fore); | |
| 2516 | if (!font->back && oldfont->back) | |
| 2517 | font->back = gdk_color_copy (oldfont->back); | |
| 2518 | } else { | |
| 2519 | if (!font->size) | |
| 2520 | font->size = 3; | |
| 2521 | if (!font->face) | |
| 2522 | font->face = g_strdup ("helvetica"); | |
| 2523 | } | |
| 2524 | ||
| 2525 | fonts = g_slist_prepend (fonts, font); | |
| 2526 | got_tag = TRUE; | |
| 2527 | } else if (!g_strcasecmp (tag, "</FONT>")) { | |
| 2528 | FontDetail *font; | |
| 2529 | ||
| 2530 | if (fonts) { | |
| 2531 | got_tag = TRUE; | |
| 2532 | NEW_BIT (NEW_TEXT_BIT); | |
| 2533 | font = fonts->data; | |
| 2534 | fonts = g_slist_remove (fonts, font); | |
| 2535 | g_free (font->face); | |
| 2536 | if (font->fore) | |
| 2537 | gdk_color_free (font->fore); | |
| 2538 | if (font->back) | |
| 2539 | gdk_color_free (font->back); | |
| 2540 | g_free (font); | |
| 2541 | } else { | |
| 2542 | intag = FALSE; | |
| 2543 | tpos = 0; | |
| 2544 | continue; | |
| 2545 | } | |
| 2546 | } else if (!g_strncasecmp (tag, "<BODY ", strlen ("<BODY "))) { | |
| 2547 | gchar *t, *e, *color = NULL; | |
| 2548 | GdkColor *tmp; | |
| 2549 | ||
| 2550 | got_tag = TRUE; | |
| 2551 | ||
| 2552 | if (!(options & GTK_IMHTML_NO_COLOURS)) { | |
| 2553 | t = tag + strlen ("<BODY"); | |
| 2554 | do { | |
| 2555 | gboolean quote = FALSE; | |
| 2556 | if (*t == '\0') break; | |
| 2557 | while (*t && !((*t == ' ') && !quote)) { | |
| 2558 | if (*t == '\"') | |
| 2559 | quote = ! quote; | |
| 2560 | t++; | |
| 2561 | } | |
| 2562 | while (*t && (*t == ' ')) t++; | |
| 2563 | } while (g_strncasecmp (t, "BGCOLOR=", strlen ("BGCOLOR="))); | |
| 2564 | ||
| 2565 | if (!g_strncasecmp (t, "BGCOLOR=", strlen ("BGCOLOR="))) { | |
| 2566 | t += strlen ("BGCOLOR="); | |
| 2567 | if ((*t == '\"') || (*t == '\'')) { | |
| 2568 | e = ++t; | |
| 2569 | while (*e && (*e != *(t - 1))) e++; | |
| 2570 | if (*e != '\0') { | |
| 2571 | *e = '\0'; | |
| 2572 | color = g_strdup (t); | |
| 2573 | } | |
| 2574 | } else { | |
| 2575 | e = t; | |
| 2576 | while (*e && !isspace ((gint) *e)) e++; | |
| 2577 | if (*e == '\0') e--; | |
| 2578 | *e = '\0'; | |
| 2579 | color = g_strdup (t); | |
| 2580 | } | |
| 2581 | ||
| 2582 | if (color != NULL) { | |
| 2583 | tmp = gtk_imhtml_get_color (color); | |
| 2584 | g_free (color); | |
| 2585 | if (tmp != NULL) { | |
| 2586 | NEW_BIT (NEW_TEXT_BIT); | |
| 2587 | bg = tmp; | |
| 2588 | UPDATE_BG_COLORS; | |
| 2589 | } | |
| 2590 | } | |
| 2591 | } | |
| 2592 | } | |
| 2593 | } else if (!g_strncasecmp (tag, "<A ", strlen ("<A "))) { | |
| 2594 | gchar *t, *e; | |
| 2595 | ||
| 2596 | got_tag = TRUE; | |
| 2597 | NEW_BIT (NEW_TEXT_BIT); | |
| 2598 | ||
| 2599 | if (url != NULL) | |
| 2600 | g_free (url); | |
| 2601 | url = NULL; | |
| 2602 | ||
| 2603 | t = tag + strlen ("<A"); | |
| 2604 | do { | |
| 2605 | gboolean quote = FALSE; | |
| 2606 | if (*t == '\0') break; | |
| 2607 | while (*t && !((*t == ' ') && !quote)) { | |
| 2608 | if (*t == '\"') | |
| 2609 | quote = ! quote; | |
| 2610 | t++; | |
| 2611 | } | |
| 2612 | while (*t && (*t == ' ')) t++; | |
| 2613 | } while (g_strncasecmp (t, "HREF=", strlen ("HREF="))); | |
| 2614 | ||
| 2615 | if (!g_strncasecmp (t, "HREF=", strlen ("HREF="))) { | |
| 2616 | t += strlen ("HREF="); | |
| 2617 | if ((*t == '\"') || (*t == '\'')) { | |
| 2618 | e = ++t; | |
| 2619 | while (*e && (*e != *(t - 1))) e++; | |
| 2620 | if (*e != '\0') { | |
| 2621 | *e = '\0'; | |
| 2622 | url = g_strdup (t); | |
| 2623 | } | |
| 2624 | } else { | |
| 2625 | e = t; | |
| 2626 | while (*e && !isspace ((gint) *e)) e++; | |
| 2627 | if (*e == '\0') e--; | |
| 2628 | *e = '\0'; | |
| 2629 | url = g_strdup (t); | |
| 2630 | } | |
| 2631 | } | |
| 2632 | } else if (!g_strcasecmp (tag, "</A>")) { | |
| 2633 | got_tag = TRUE; | |
| 2634 | if (url != NULL) { | |
| 2635 | NEW_BIT (NEW_TEXT_BIT); | |
| 2636 | g_free (url); | |
| 2637 | } | |
| 2638 | url = NULL; | |
| 2639 | } else if (!g_strncasecmp (tag, "<IMG ", strlen ("<IMG "))) { | |
| 2640 | gchar *t, *e, *src = NULL; | |
| 2641 | gchar *copy = g_strdup (tag); | |
| 2642 | gchar **xpm; | |
| 2643 | GdkColor *clr = NULL; | |
| 2644 | GtkIMHtmlBit *bit; | |
| 2645 | ||
| 2646 | intag = FALSE; | |
| 2647 | tpos = 0; | |
| 2648 | ||
| 2649 | if (imhtml->img == NULL) | |
| 2650 | continue; | |
| 2651 | ||
| 2652 | t = tag + strlen ("<IMG"); | |
| 2653 | do { | |
| 2654 | gboolean quote = FALSE; | |
| 2655 | if (*t == '\0') break; | |
| 2656 | while (*t && !((*t == ' ') && !quote)) { | |
| 2657 | if (*t == '\"') | |
| 2658 | quote = ! quote; | |
| 2659 | t++; | |
| 2660 | } | |
| 2661 | while (*t && (*t == ' ')) t++; | |
| 2662 | } while (g_strncasecmp (t, "SRC=", strlen ("SRC="))); | |
| 2663 | ||
| 2664 | if (!g_strncasecmp (t, "SRC=", strlen ("SRC="))) { | |
| 2665 | t += strlen ("SRC="); | |
| 2666 | if ((*t == '\"') || (*t == '\'')) { | |
| 2667 | e = ++t; | |
| 2668 | while (*e && (*e != *(t - 1))) e++; | |
| 2669 | if (*e != '\0') { | |
| 2670 | *e = '\0'; | |
| 2671 | src = g_strdup (t); | |
| 2672 | } | |
| 2673 | } else { | |
| 2674 | e = t; | |
| 2675 | while (*e && !isspace ((gint) *e)) e++; | |
| 2676 | if (*e == '\0') e--; | |
| 2677 | *e = '\0'; | |
| 2678 | src = g_strdup (t); | |
| 2679 | } | |
| 2680 | } | |
| 2681 | ||
| 2682 | if (src == NULL) { | |
| 2683 | ws [wpos] = 0; | |
| 2684 | strcat (ws, copy); | |
| 2685 | wpos = strlen (ws); | |
| 2686 | g_free (copy); | |
| 2687 | continue; | |
| 2688 | } | |
| 2689 | ||
| 2690 | xpm = (* imhtml->img) (src); | |
| 2691 | if (xpm == NULL) { | |
| 2692 | g_free (src); | |
| 2693 | ws [wpos] = 0; | |
| 2694 | strcat (ws, copy); | |
| 2695 | wpos = strlen (ws); | |
| 2696 | g_free (copy); | |
| 2697 | continue; | |
| 2698 | } | |
| 2699 | ||
| 2700 | g_free (copy); | |
| 2701 | ||
| 2702 | if (!fonts || ((clr = ((FontDetail *)fonts->data)->back) == NULL)) | |
| 2703 | clr = (bg != NULL) ? bg : >K_WIDGET (imhtml)->style->white; | |
| 2704 | ||
| 2705 | if (!GTK_WIDGET_REALIZED (imhtml)) | |
| 2706 | gtk_widget_realize (GTK_WIDGET (imhtml)); | |
| 2707 | ||
| 2708 | bit = g_new0 (GtkIMHtmlBit, 1); | |
| 2709 | bit->type = TYPE_IMG; | |
| 2710 | bit->pm = gdk_pixmap_create_from_xpm_d (GTK_WIDGET (imhtml)->window, | |
| 2711 | &bit->bm, | |
| 2712 | clr, | |
| 2713 | xpm); | |
| 2714 | if (url) | |
| 2715 | bit->url = g_strdup (url); | |
| 2716 | ||
| 2717 | NEW_BIT (bit); | |
| 2718 | ||
| 2719 | g_free (src); | |
| 2720 | ||
| 2721 | continue; | |
| 2722 | } else if (!g_strcasecmp (tag, "<P>") || | |
| 2723 | !g_strcasecmp (tag, "</P>") || | |
| 2724 | !g_strncasecmp (tag, "<P ", strlen ("<P ")) || | |
| 2725 | !g_strcasecmp (tag, "<PRE>") || | |
| 2726 | !g_strcasecmp (tag, "</PRE>") || | |
| 2727 | !g_strcasecmp (tag, "<HTML>") || | |
| 2728 | !g_strcasecmp (tag, "</HTML>") || | |
| 2729 | !g_strcasecmp (tag, "<BODY>") || | |
| 2730 | !g_strcasecmp (tag, "</BODY>") || | |
| 2731 | !g_strcasecmp (tag, "<FONT>") || | |
| 2732 | !g_strcasecmp (tag, "<HEAD>") || | |
| 2733 | !g_strcasecmp (tag, "</HEAD>")) { | |
| 2734 | intag = FALSE; | |
| 2735 | tpos = 0; | |
| 2736 | continue; | |
| 2737 | } | |
| 2738 | ||
| 2739 | if (!got_tag) { | |
| 2740 | ws [wpos] = 0; | |
| 2741 | strcat (ws, tag); | |
| 2742 | wpos = strlen (ws); | |
| 2743 | } else { | |
| 2744 | wpos = 0; | |
| 2745 | } | |
| 2746 | intag = FALSE; | |
| 2747 | tpos = 0; | |
| 2748 | } else if (*c == '&' && !intag) { | |
| 2749 | if (!g_strncasecmp (c, "&", 5)) { | |
| 2750 | ws [wpos++] = '&'; | |
| 2751 | c += 5; | |
| 2752 | } else if (!g_strncasecmp (c, "<", 4)) { | |
| 2753 | ws [wpos++] = '<'; | |
| 2754 | c += 4; | |
| 2755 | } else if (!g_strncasecmp (c, ">", 4)) { | |
| 2756 | ws [wpos++] = '>'; | |
| 2757 | c += 4; | |
| 2758 | } else if (!g_strncasecmp (c, " ", 6)) { | |
| 2759 | ws [wpos++] = ' '; | |
| 2760 | c += 6; | |
| 2761 | } else if (!g_strncasecmp (c, "©", 6)) { | |
| 2762 | ws [wpos++] = '©'; | |
| 2763 | c += 6; | |
| 2764 | } else if (!g_strncasecmp (c, """, 6)) { | |
| 2765 | ws [wpos++] = '\"'; | |
| 2766 | c += 6; | |
| 2767 | } else if (!g_strncasecmp (c, "®", 5)) { | |
| 2768 | ws [wpos++] = '®'; | |
| 2769 | c += 5; | |
| 2770 | } else if (*(c + 1) == '#') { | |
| 2771 | gint pound = 0; | |
| 2772 | if (sscanf (c, "&#%d;", £) == 1) { | |
| 2773 | if (*(c + 3 + (gint)log10 (pound)) != ';') { | |
| 2774 | ws [wpos++] = *c++; | |
| 2775 | continue; | |
| 2776 | } | |
| 2777 | ws [wpos++] = (gchar)pound; | |
| 2778 | c += 2; | |
| 2779 | while (isdigit ((gint) *c)) c++; | |
| 2780 | if (*c == ';') c++; | |
| 2781 | } else { | |
| 2782 | ws [wpos++] = *c++; | |
| 2783 | } | |
| 2784 | } else { | |
| 2785 | ws [wpos++] = *c++; | |
| 2786 | } | |
| 2787 | } else if (intag) { | |
| 2788 | if (*c == '\"') | |
| 2789 | tagquote = !tagquote; | |
| 2790 | tag [tpos++] = *c++; | |
| 2791 | } else if (incomment) { | |
| 2792 | ws [wpos++] = *c++; | |
| 2793 | } else if (((smilelen = gtk_imhtml_is_smiley (imhtml, c)) != 0)) { | |
| 2794 | ws [wpos] = 0; | |
| 2795 | wpos = 0; | |
| 2796 | NEW_BIT (NEW_TEXT_BIT); | |
| 2797 | g_snprintf (ws, smilelen + 1, "%s", c); | |
| 2798 | NEW_BIT (NEW_SMILEY_BIT); | |
| 2799 | c += smilelen; | |
| 2800 | } else if (*c == '\n') { | |
| 2801 | if (!(options & GTK_IMHTML_NO_NEWLINE)) { | |
| 2802 | ws [wpos] = 0; | |
| 2803 | wpos = 0; | |
| 2804 | NEW_BIT (NEW_TEXT_BIT); | |
| 2805 | NEW_BIT (NEW_BR_BIT); | |
| 2806 | } | |
| 2807 | c++; | |
| 2808 | } else { | |
| 2809 | ws [wpos++] = *c++; | |
| 2810 | } | |
| 2811 | } | |
| 2812 | ||
| 2813 | if (intag) { | |
| 2814 | tag [tpos] = 0; | |
| 2815 | c = tag; | |
| 2816 | while (*c) { | |
| 2817 | if ((smilelen = gtk_imhtml_is_smiley (imhtml, c)) != 0) { | |
| 2818 | ws [wpos] = 0; | |
| 2819 | wpos = 0; | |
| 2820 | NEW_BIT (NEW_TEXT_BIT); | |
| 2821 | g_snprintf (ws, smilelen + 1, "%s", c); | |
| 2822 | NEW_BIT (NEW_SMILEY_BIT); | |
| 2823 | c += smilelen; | |
| 2824 | } else { | |
| 2825 | ws [wpos++] = *c++; | |
| 2826 | } | |
| 2827 | } | |
| 2828 | } else if (incomment) { | |
| 2829 | ws [wpos] = 0; | |
| 2830 | wpos = 0; | |
| 2831 | strcat (tag, ws); | |
| 2832 | ws [wpos] = 0; | |
| 2833 | c = tag; | |
| 2834 | while (*c) { | |
| 2835 | if ((smilelen = gtk_imhtml_is_smiley (imhtml, c)) != 0) { | |
| 2836 | ws [wpos] = 0; | |
| 2837 | wpos = 0; | |
| 2838 | NEW_BIT (NEW_TEXT_BIT); | |
| 2839 | g_snprintf (ws, smilelen + 1, "%s", c); | |
| 2840 | NEW_BIT (NEW_SMILEY_BIT); | |
| 2841 | c += smilelen; | |
| 2842 | } else { | |
| 2843 | ws [wpos++] = *c++; | |
| 2844 | } | |
| 2845 | } | |
| 2846 | } | |
| 2847 | ||
| 2848 | ws [wpos] = 0; | |
| 2849 | NEW_BIT (NEW_TEXT_BIT); | |
| 2850 | ||
| 2851 | while (newbits) { | |
| 2852 | GtkIMHtmlBit *bit = newbits->data; | |
| 2853 | imhtml->bits = g_list_append (imhtml->bits, bit); | |
| 2854 | newbits = g_list_remove (newbits, bit); | |
| 2855 | gtk_imhtml_draw_bit (imhtml, bit); | |
| 2856 | } | |
| 2857 | ||
| 2858 | gtk_widget_set_usize (GTK_WIDGET (imhtml), -1, imhtml->y + 5); | |
| 2859 | ||
| 2860 | if (!(options & GTK_IMHTML_NO_SCROLL) && | |
| 2861 | scrolldown && | |
| 2862 | (imhtml->y + 5 >= GTK_WIDGET (imhtml)->allocation.height)) | |
| 2863 | gtk_adjustment_set_value (vadj, imhtml->y + 5 - GTK_WIDGET (imhtml)->allocation.height); | |
| 2864 | ||
| 2865 | if (url) { | |
| 2866 | g_free (url); | |
| 2867 | if (retval) | |
| 2868 | retval = g_string_append (retval, "</A>"); | |
| 2869 | } | |
| 2870 | if (bg) | |
| 2871 | gdk_color_free (bg); | |
| 2872 | while (fonts) { | |
| 2873 | FontDetail *font = fonts->data; | |
| 2874 | fonts = g_slist_remove (fonts, font); | |
| 2875 | g_free (font->face); | |
| 2876 | if (font->fore) | |
| 2877 | gdk_color_free (font->fore); | |
| 2878 | if (font->back) | |
| 2879 | gdk_color_free (font->back); | |
| 2880 | g_free (font); | |
| 2881 | if (retval) | |
| 2882 | retval = g_string_append (retval, "</FONT>"); | |
| 2883 | } | |
| 2884 | if (retval) { | |
| 2885 | while (bold) { | |
| 2886 | retval = g_string_append (retval, "</B>"); | |
| 2887 | bold--; | |
| 2888 | } | |
| 2889 | while (italics) { | |
| 2890 | retval = g_string_append (retval, "</I>"); | |
| 2891 | italics--; | |
| 2892 | } | |
| 2893 | while (underline) { | |
| 2894 | retval = g_string_append (retval, "</U>"); | |
| 2895 | underline--; | |
| 2896 | } | |
| 2897 | while (strike) { | |
| 2898 | retval = g_string_append (retval, "</S>"); | |
| 2899 | strike--; | |
| 2900 | } | |
| 2901 | while (sub) { | |
| 2902 | retval = g_string_append (retval, "</SUB>"); | |
| 2903 | sub--; | |
| 2904 | } | |
| 2905 | while (sup) { | |
| 2906 | retval = g_string_append (retval, "</SUP>"); | |
| 2907 | sup--; | |
| 2908 | } | |
| 2909 | while (title) { | |
| 2910 | retval = g_string_append (retval, "</TITLE>"); | |
| 2911 | title--; | |
| 2912 | } | |
| 2913 | } | |
| 2914 | g_free (ws); | |
| 2915 | g_free (tag); | |
| 2916 | ||
| 2917 | return retval; | |
| 2918 | } |