Mercurial > pidgin
comparison src/gtkimhtml.c @ 1998:00dc6b2df5b6
[gaim-migrate @ 2008]
ok, stuff should be fixed.
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Tue, 12 Jun 2001 05:14:56 +0000 |
parents | 1c01a85c0616 |
children | 7c2457745344 |
comparison
equal
deleted
inserted
replaced
1997:1c01a85c0616 | 1998:00dc6b2df5b6 |
---|---|
49 #define MAX_SIZE 7 | 49 #define MAX_SIZE 7 |
50 #define MAX_FONTS 32767 | 50 #define MAX_FONTS 32767 |
51 | 51 |
52 gint font_sizes [] = { 80, 100, 120, 140, 200, 300, 400 }; | 52 gint font_sizes [] = { 80, 100, 120, 140, 200, 300, 400 }; |
53 | 53 |
54 #define BORDER_SIZE 3 | 54 #define BORDER_SIZE 2 |
55 #define TOP_BORDER 10 | |
55 #define MIN_HEIGHT 20 | 56 #define MIN_HEIGHT 20 |
56 #define HR_HEIGHT 2 | 57 #define HR_HEIGHT 2 |
57 #define TOOLTIP_TIMEOUT 500 | 58 #define TOOLTIP_TIMEOUT 500 |
58 | 59 |
59 #define DIFF(a, b) (((a) > (b)) ? ((a) - (b)) : ((b) - (a))) | 60 #define DIFF(a, b) (((a) > (b)) ? ((a) - (b)) : ((b) - (a))) |
234 | 235 |
235 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), | 236 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), |
236 &attributes, attributes_mask); | 237 &attributes, attributes_mask); |
237 gdk_window_set_user_data (widget->window, widget); | 238 gdk_window_set_user_data (widget->window, widget); |
238 | 239 |
239 attributes.x = 0; | 240 attributes.x = widget->style->klass->xthickness + BORDER_SIZE; |
240 attributes.y = 0; | 241 attributes.y = widget->style->klass->xthickness + BORDER_SIZE; |
242 attributes.width = MAX (1, (gint) widget->allocation.width - (gint) attributes.x * 2); | |
243 attributes.height = MAX (1, (gint) widget->allocation.height - (gint) attributes.y * 2); | |
241 attributes.event_mask = gtk_widget_get_events (widget) | 244 attributes.event_mask = gtk_widget_get_events (widget) |
242 | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | 245 | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
243 | GDK_POINTER_MOTION_MASK | GDK_EXPOSURE_MASK | GDK_LEAVE_NOTIFY_MASK; | 246 | GDK_POINTER_MOTION_MASK | GDK_EXPOSURE_MASK | GDK_LEAVE_NOTIFY_MASK; |
244 | 247 |
245 GTK_LAYOUT (imhtml)->bin_window = gdk_window_new (widget->window, | 248 GTK_LAYOUT (imhtml)->bin_window = gdk_window_new (widget->window, |
248 | 251 |
249 widget->style = gtk_style_attach (widget->style, widget->window); | 252 widget->style = gtk_style_attach (widget->style, widget->window); |
250 | 253 |
251 gdk_window_set_cursor (widget->window, imhtml->arrow_cursor); | 254 gdk_window_set_cursor (widget->window, imhtml->arrow_cursor); |
252 | 255 |
253 gdk_window_set_background (widget->window, &widget->style->base [GTK_WIDGET_STATE (widget)]); | 256 gdk_window_set_background (widget->window, &widget->style->base [GTK_STATE_NORMAL]); |
254 gdk_window_set_background (GTK_LAYOUT (imhtml)->bin_window, | 257 gdk_window_set_background (GTK_LAYOUT (imhtml)->bin_window, |
255 &widget->style->base [GTK_WIDGET_STATE (widget)]); | 258 &widget->style->base [GTK_STATE_NORMAL]); |
259 | |
260 gdk_window_show (GTK_LAYOUT (imhtml)->bin_window); | |
256 } | 261 } |
257 | 262 |
258 static gboolean | 263 static gboolean |
259 similar_colors (GdkColor *bg, | 264 similar_colors (GdkColor *bg, |
260 GdkColor *fg) | 265 GdkColor *fg) |
471 | 476 |
472 gdk_gc_unref (gc); | 477 gdk_gc_unref (gc); |
473 } | 478 } |
474 | 479 |
475 static void | 480 static void |
481 gtk_imhtml_draw_focus (GtkWidget *widget) | |
482 { | |
483 GtkIMHtml *imhtml; | |
484 gint x = 0, | |
485 y = 0, | |
486 w = 0, | |
487 h = 0; | |
488 | |
489 imhtml = GTK_IMHTML (widget); | |
490 | |
491 if (!GTK_WIDGET_DRAWABLE (widget)) | |
492 return; | |
493 | |
494 if (GTK_WIDGET_HAS_FOCUS (widget)) { | |
495 gtk_paint_focus (widget->style, widget->window, NULL, widget, "text", 0, 0, | |
496 widget->allocation.width - 1, widget->allocation.height - 1); | |
497 x = 1; y = 1; w = 2; h = 2; | |
498 } | |
499 | |
500 gtk_paint_shadow (widget->style, widget->window, GTK_STATE_NORMAL, | |
501 GTK_SHADOW_IN, NULL, widget, "text", x, y, | |
502 widget->allocation.width - w, widget->allocation.height - h); | |
503 } | |
504 | |
505 static void | |
476 gtk_imhtml_draw_exposed (GtkIMHtml *imhtml) | 506 gtk_imhtml_draw_exposed (GtkIMHtml *imhtml) |
477 { | 507 { |
478 GList *bits; | 508 GList *bits; |
479 GtkIMHtmlBit *bit; | 509 GtkIMHtmlBit *bit; |
480 GList *chunks; | 510 GList *chunks; |
482 gfloat x, y; | 512 gfloat x, y; |
483 guint32 width, height; | 513 guint32 width, height; |
484 | 514 |
485 x = GTK_LAYOUT (imhtml)->hadjustment->value; | 515 x = GTK_LAYOUT (imhtml)->hadjustment->value; |
486 y = GTK_LAYOUT (imhtml)->vadjustment->value; | 516 y = GTK_LAYOUT (imhtml)->vadjustment->value; |
487 width = GTK_WIDGET (imhtml)->allocation.width; | 517 gdk_window_get_size (GTK_LAYOUT (imhtml)->bin_window, &width, &height); |
488 height = GTK_WIDGET (imhtml)->allocation.height; | |
489 | 518 |
490 bits = imhtml->bits; | 519 bits = imhtml->bits; |
491 | 520 |
492 while (bits) { | 521 while (bits) { |
493 bit = bits->data; | 522 bit = bits->data; |
528 chunks = g_list_next (chunks); | 557 chunks = g_list_next (chunks); |
529 } | 558 } |
530 } | 559 } |
531 bits = g_list_next (bits); | 560 bits = g_list_next (bits); |
532 } | 561 } |
562 | |
563 gtk_imhtml_draw_focus (GTK_WIDGET (imhtml)); | |
533 } | 564 } |
534 | 565 |
535 static void | 566 static void |
536 gtk_imhtml_draw (GtkWidget *widget, | 567 gtk_imhtml_draw (GtkWidget *widget, |
537 GdkRectangle *area) | 568 GdkRectangle *area) |
567 { | 598 { |
568 GtkIMHtml *imhtml; | 599 GtkIMHtml *imhtml; |
569 | 600 |
570 g_return_val_if_fail (widget != NULL, FALSE); | 601 g_return_val_if_fail (widget != NULL, FALSE); |
571 g_return_val_if_fail (GTK_IS_IMHTML (widget), FALSE); | 602 g_return_val_if_fail (GTK_IS_IMHTML (widget), FALSE); |
572 | |
573 if (GTK_WIDGET_CLASS (parent_class)->expose_event) | |
574 (* GTK_WIDGET_CLASS (parent_class)->expose_event) (widget, event); | |
575 | 603 |
576 imhtml = GTK_IMHTML (widget); | 604 imhtml = GTK_IMHTML (widget); |
577 gtk_imhtml_draw_exposed (imhtml); | 605 gtk_imhtml_draw_exposed (imhtml); |
578 | 606 |
579 return FALSE; | 607 return FALSE; |
600 while (imhtml->urls) { | 628 while (imhtml->urls) { |
601 g_free (imhtml->urls->data); | 629 g_free (imhtml->urls->data); |
602 imhtml->urls = g_list_remove (imhtml->urls, imhtml->urls->data); | 630 imhtml->urls = g_list_remove (imhtml->urls, imhtml->urls->data); |
603 } | 631 } |
604 | 632 |
605 imhtml->x = BORDER_SIZE; | 633 imhtml->x = 0; |
606 imhtml->y = BORDER_SIZE + 10; | 634 imhtml->y = TOP_BORDER; |
607 imhtml->llheight = 0; | 635 imhtml->llheight = 0; |
608 imhtml->llascent = 0; | 636 imhtml->llascent = 0; |
609 | 637 |
610 b = imhtml->bits; | 638 b = imhtml->bits; |
611 while (b) { | 639 while (b) { |
619 g_free (li); | 647 g_free (li); |
620 } | 648 } |
621 gtk_imhtml_draw_bit (imhtml, bit); | 649 gtk_imhtml_draw_bit (imhtml, bit); |
622 } | 650 } |
623 | 651 |
624 gtk_widget_set_usize (GTK_WIDGET (imhtml), -1, imhtml->y + 5); | 652 GTK_LAYOUT (imhtml)->height = imhtml->y; |
653 GTK_LAYOUT (imhtml)->vadjustment->upper = imhtml->y; | |
654 gtk_signal_emit_by_name (GTK_OBJECT (GTK_LAYOUT (imhtml)->vadjustment), "changed"); | |
655 | |
656 gtk_widget_set_usize (GTK_WIDGET (imhtml), -1, imhtml->y); | |
625 gtk_adjustment_set_value (vadj, vadj->upper * oldvalue); | 657 gtk_adjustment_set_value (vadj, vadj->upper * oldvalue); |
626 | 658 |
627 if (GTK_LAYOUT (imhtml)->bin_window && (imhtml->y < oldy)) { | 659 if (GTK_LAYOUT (imhtml)->bin_window && (imhtml->y < oldy)) { |
628 GdkGC *gc; | 660 GdkGC *gc; |
629 GdkColormap *cmap; | 661 GdkColormap *cmap; |
641 | 673 |
642 gdk_gc_unref (gc); | 674 gdk_gc_unref (gc); |
643 } | 675 } |
644 | 676 |
645 gtk_layout_thaw (GTK_LAYOUT (imhtml)); | 677 gtk_layout_thaw (GTK_LAYOUT (imhtml)); |
678 gtk_imhtml_draw_focus (GTK_WIDGET (imhtml)); | |
646 } | 679 } |
647 | 680 |
648 static void | 681 static void |
649 gtk_imhtml_size_allocate (GtkWidget *widget, | 682 gtk_imhtml_size_allocate (GtkWidget *widget, |
650 GtkAllocation *allocation) | 683 GtkAllocation *allocation) |
651 { | 684 { |
652 GtkIMHtml *imhtml; | 685 GtkIMHtml *imhtml; |
653 GtkLayout *layout; | 686 GtkLayout *layout; |
687 gint new_xsize, new_ysize; | |
654 | 688 |
655 g_return_if_fail (widget != NULL); | 689 g_return_if_fail (widget != NULL); |
656 g_return_if_fail (GTK_IS_IMHTML (widget)); | 690 g_return_if_fail (GTK_IS_IMHTML (widget)); |
657 g_return_if_fail (allocation != NULL); | 691 g_return_if_fail (allocation != NULL); |
658 | 692 |
659 imhtml = GTK_IMHTML (widget); | 693 imhtml = GTK_IMHTML (widget); |
660 layout = GTK_LAYOUT (widget); | 694 layout = GTK_LAYOUT (widget); |
661 | 695 |
662 widget->allocation = *allocation; | 696 widget->allocation = *allocation; |
663 | 697 |
698 new_xsize = MAX (1, (gint) allocation->width - | |
699 (gint) (widget->style->klass->xthickness + BORDER_SIZE) * 2); | |
700 new_ysize = MAX (1, (gint) allocation->height - | |
701 (gint) (widget->style->klass->ythickness + BORDER_SIZE) * 2); | |
702 | |
664 if (GTK_WIDGET_REALIZED (widget)) { | 703 if (GTK_WIDGET_REALIZED (widget)) { |
704 gint x = widget->style->klass->xthickness + BORDER_SIZE; | |
705 gint y = widget->style->klass->ythickness + BORDER_SIZE; | |
665 gdk_window_move_resize (widget->window, | 706 gdk_window_move_resize (widget->window, |
666 allocation->x, allocation->y, | 707 allocation->x, allocation->y, |
667 allocation->width, allocation->height); | 708 allocation->width, allocation->height); |
668 gdk_window_move_resize (layout->bin_window, | 709 gdk_window_move_resize (layout->bin_window, |
669 0, 0, | 710 x, y, new_xsize, new_ysize); |
670 allocation->width, allocation->height); | 711 } |
671 } | 712 |
672 | 713 layout->hadjustment->page_size = new_xsize; |
673 layout->hadjustment->page_size = allocation->width; | 714 layout->hadjustment->page_increment = new_xsize / 2; |
674 layout->hadjustment->page_increment = allocation->width / 2; | |
675 layout->hadjustment->lower = 0; | 715 layout->hadjustment->lower = 0; |
676 layout->hadjustment->upper = imhtml->xsize; | 716 layout->hadjustment->upper = imhtml->x; |
677 | 717 |
678 layout->vadjustment->page_size = allocation->height; | 718 layout->vadjustment->page_size = new_ysize; |
679 layout->vadjustment->page_increment = allocation->height / 2; | 719 layout->vadjustment->page_increment = new_ysize / 2; |
680 layout->vadjustment->lower = 0; | 720 layout->vadjustment->lower = 0; |
681 layout->vadjustment->upper = imhtml->y + 5; | 721 layout->vadjustment->upper = imhtml->y; |
682 | 722 |
683 gtk_signal_emit_by_name (GTK_OBJECT (layout->hadjustment), "changed"); | 723 gtk_signal_emit_by_name (GTK_OBJECT (layout->hadjustment), "changed"); |
684 gtk_signal_emit_by_name (GTK_OBJECT (layout->vadjustment), "changed"); | 724 gtk_signal_emit_by_name (GTK_OBJECT (layout->vadjustment), "changed"); |
685 | 725 |
686 if (allocation->width == imhtml->xsize) { | 726 if (new_xsize == imhtml->xsize) { |
687 if ((GTK_LAYOUT (imhtml)->vadjustment->value > imhtml->y + 5 - allocation->height)) { | 727 if ((GTK_LAYOUT (imhtml)->vadjustment->value > imhtml->y - new_ysize)) { |
688 if (imhtml->y + 5 > allocation->height) | 728 if (imhtml->y > new_ysize) |
689 gtk_adjustment_set_value (GTK_LAYOUT (imhtml)->vadjustment, | 729 gtk_adjustment_set_value (GTK_LAYOUT (imhtml)->vadjustment, |
690 imhtml->y + 5 - allocation->height); | 730 imhtml->y - new_ysize); |
691 else | 731 else |
692 gtk_adjustment_set_value (GTK_LAYOUT (imhtml)->vadjustment, 0); | 732 gtk_adjustment_set_value (GTK_LAYOUT (imhtml)->vadjustment, 0); |
693 } | 733 } |
694 return; | 734 return; |
695 } | 735 } |
696 | 736 |
697 imhtml->xsize = allocation->width; | 737 imhtml->xsize = new_xsize; |
698 | 738 |
699 if (GTK_WIDGET_REALIZED (widget)) | 739 if (GTK_WIDGET_REALIZED (widget)) |
700 gtk_imhtml_redraw_all (imhtml); | 740 gtk_imhtml_redraw_all (imhtml); |
701 } | 741 } |
702 | 742 |
1056 baseline_skip = style->font->ascent + style->font->descent + gap; | 1096 baseline_skip = style->font->ascent + style->font->descent + gap; |
1057 | 1097 |
1058 if (!imhtml->tip_bit) | 1098 if (!imhtml->tip_bit) |
1059 return FALSE; | 1099 return FALSE; |
1060 | 1100 |
1061 gtk_paint_flat_box(style, imhtml->tip_window->window, GTK_STATE_NORMAL, GTK_SHADOW_OUT, | 1101 gtk_paint_flat_box (style, imhtml->tip_window->window, GTK_STATE_NORMAL, GTK_SHADOW_OUT, |
1062 NULL, imhtml->tip_window, "tooltip", 0, 0, -1, -1); | 1102 NULL, imhtml->tip_window, "tooltip", 0, 0, -1, -1); |
1063 | 1103 |
1064 y = style->font->ascent + 4; | 1104 y = style->font->ascent + 4; |
1065 gtk_paint_string (style, imhtml->tip_window->window, GTK_STATE_NORMAL, NULL, | 1105 gtk_paint_string (style, imhtml->tip_window->window, GTK_STATE_NORMAL, NULL, |
1066 imhtml->tip_window, "tooltip", 4, y, imhtml->tip_bit->url); | 1106 imhtml->tip_window, "tooltip", 4, y, imhtml->tip_bit->url); |
1378 | 1418 |
1379 static void | 1419 static void |
1380 gtk_imhtml_adjustment_changed (GtkAdjustment *adjustment, | 1420 gtk_imhtml_adjustment_changed (GtkAdjustment *adjustment, |
1381 GtkIMHtml *imhtml) | 1421 GtkIMHtml *imhtml) |
1382 { | 1422 { |
1383 gint dx, dy; | |
1384 GtkLayout *layout = GTK_LAYOUT (imhtml); | 1423 GtkLayout *layout = GTK_LAYOUT (imhtml); |
1385 GtkWidget *widget = GTK_WIDGET (imhtml); | |
1386 | |
1387 dx = (gint) layout->hadjustment->value - layout->xoffset; | |
1388 dy = (gint) layout->vadjustment->value - layout->yoffset; | |
1389 | 1424 |
1390 layout->xoffset = (gint) layout->hadjustment->value; | 1425 layout->xoffset = (gint) layout->hadjustment->value; |
1391 layout->yoffset = (gint) layout->vadjustment->value; | 1426 layout->yoffset = (gint) layout->vadjustment->value; |
1392 | 1427 |
1393 if (!GTK_WIDGET_MAPPED (imhtml) || !GTK_WIDGET_REALIZED (imhtml)) | 1428 if (!GTK_WIDGET_MAPPED (imhtml) || !GTK_WIDGET_REALIZED (imhtml)) |
1394 return; | 1429 return; |
1395 | 1430 |
1396 if (layout->freeze_count) | 1431 if (layout->freeze_count) |
1397 return; | 1432 return; |
1398 | 1433 |
1399 if (dx > 0) { | 1434 if (layout->yoffset < TOP_BORDER) |
1400 gdk_window_resize (layout->bin_window, | 1435 gdk_window_clear_area (layout->bin_window, 0, 0, |
1401 widget->allocation.width + dx, | 1436 imhtml->xsize, TOP_BORDER - layout->yoffset); |
1402 widget->allocation.height); | |
1403 gdk_window_move (layout->bin_window, -dx, 0); | |
1404 gdk_window_move_resize (layout->bin_window, | |
1405 0, 0, | |
1406 widget->allocation.width, | |
1407 widget->allocation.height); | |
1408 } else if (dx) { | |
1409 gdk_window_move_resize (layout->bin_window, | |
1410 dx, 0, | |
1411 widget->allocation.width - dx, | |
1412 widget->allocation.height); | |
1413 gdk_window_move (layout->bin_window, 0, 0); | |
1414 gdk_window_resize (layout->bin_window, | |
1415 widget->allocation.width, | |
1416 widget->allocation.height); | |
1417 } | |
1418 | |
1419 if (dy > 0) { | |
1420 gdk_window_resize (layout->bin_window, | |
1421 widget->allocation.width, | |
1422 widget->allocation.height + dy); | |
1423 gdk_window_move (layout->bin_window, 0, -dy); | |
1424 gdk_window_move_resize (layout->bin_window, | |
1425 0, 0, | |
1426 widget->allocation.width, | |
1427 widget->allocation.height); | |
1428 } else if (dy) { | |
1429 gdk_window_move_resize (layout->bin_window, | |
1430 0, dy, | |
1431 widget->allocation.width, | |
1432 widget->allocation.height - dy); | |
1433 gdk_window_move (layout->bin_window, 0, 0); | |
1434 gdk_window_resize (layout->bin_window, | |
1435 widget->allocation.width, | |
1436 widget->allocation.height); | |
1437 } | |
1438 | 1437 |
1439 gtk_imhtml_draw_exposed (imhtml); | 1438 gtk_imhtml_draw_exposed (imhtml); |
1440 } | 1439 } |
1441 | 1440 |
1442 static void | 1441 static void |
1518 | 1517 |
1519 object_class->destroy = gtk_imhtml_destroy; | 1518 object_class->destroy = gtk_imhtml_destroy; |
1520 | 1519 |
1521 widget_class->realize = gtk_imhtml_realize; | 1520 widget_class->realize = gtk_imhtml_realize; |
1522 widget_class->draw = gtk_imhtml_draw; | 1521 widget_class->draw = gtk_imhtml_draw; |
1522 widget_class->draw_focus = gtk_imhtml_draw_focus; | |
1523 widget_class->style_set = gtk_imhtml_style_set; | 1523 widget_class->style_set = gtk_imhtml_style_set; |
1524 widget_class->expose_event = gtk_imhtml_expose_event; | 1524 widget_class->expose_event = gtk_imhtml_expose_event; |
1525 widget_class->size_allocate = gtk_imhtml_size_allocate; | 1525 widget_class->size_allocate = gtk_imhtml_size_allocate; |
1526 widget_class->motion_notify_event = gtk_imhtml_motion_notify_event; | 1526 widget_class->motion_notify_event = gtk_imhtml_motion_notify_event; |
1527 widget_class->leave_notify_event = gtk_imhtml_leave_notify_event; | 1527 widget_class->leave_notify_event = gtk_imhtml_leave_notify_event; |
1787 gtk_imhtml_set_adjustments (imhtml, hadj, vadj); | 1787 gtk_imhtml_set_adjustments (imhtml, hadj, vadj); |
1788 | 1788 |
1789 imhtml->bits = NULL; | 1789 imhtml->bits = NULL; |
1790 imhtml->urls = NULL; | 1790 imhtml->urls = NULL; |
1791 | 1791 |
1792 imhtml->x = BORDER_SIZE; | 1792 imhtml->x = 0; |
1793 imhtml->y = BORDER_SIZE + 10; | 1793 imhtml->y = TOP_BORDER; |
1794 imhtml->llheight = 0; | 1794 imhtml->llheight = 0; |
1795 imhtml->llascent = 0; | 1795 imhtml->llascent = 0; |
1796 imhtml->line = NULL; | 1796 imhtml->line = NULL; |
1797 | 1797 |
1798 imhtml->selected_text = g_string_new (""); | 1798 imhtml->selected_text = g_string_new (""); |
1891 GList *last = g_list_last (imhtml->line); | 1891 GList *last = g_list_last (imhtml->line); |
1892 struct line_info *li; | 1892 struct line_info *li; |
1893 | 1893 |
1894 if (last) { | 1894 if (last) { |
1895 li = last->data; | 1895 li = last->data; |
1896 if (li->x + li->width != imhtml->xsize - BORDER_SIZE) | 1896 if (li->x + li->width != imhtml->xsize) |
1897 li->width = imhtml->xsize - BORDER_SIZE - li->x; | 1897 li->width = imhtml->xsize - li->x; |
1898 } | 1898 } |
1899 | 1899 |
1900 last = imhtml->line; | 1900 last = imhtml->line; |
1901 if (last) { | 1901 if (last) { |
1902 li = last->data; | 1902 li = last->data; |
1914 } | 1914 } |
1915 | 1915 |
1916 g_list_free (imhtml->line); | 1916 g_list_free (imhtml->line); |
1917 imhtml->line = NULL; | 1917 imhtml->line = NULL; |
1918 | 1918 |
1919 imhtml->x = BORDER_SIZE; | 1919 imhtml->x = 0; |
1920 imhtml->y += imhtml->llheight; | 1920 imhtml->y += imhtml->llheight; |
1921 imhtml->llheight = 0; | 1921 imhtml->llheight = 0; |
1922 imhtml->llascent = 0; | 1922 imhtml->llascent = 0; |
1923 } | 1923 } |
1924 | 1924 |
2056 gchar *tmp; | 2056 gchar *tmp; |
2057 | 2057 |
2058 height = bit->font->ascent + bit->font->descent; | 2058 height = bit->font->ascent + bit->font->descent; |
2059 width = gdk_string_width (bit->font, bit->text); | 2059 width = gdk_string_width (bit->font, bit->text); |
2060 | 2060 |
2061 if ((imhtml->x != BORDER_SIZE) && | 2061 if ((imhtml->x != 0) && ((imhtml->x + width) > imhtml->xsize)) { |
2062 ((imhtml->x + width + BORDER_SIZE + BORDER_SIZE + 5) > imhtml->xsize)) { | 2062 gint remain = imhtml->xsize - imhtml->x; |
2063 gint remain = imhtml->xsize - imhtml->x - BORDER_SIZE - BORDER_SIZE - 5; | |
2064 while (gdk_text_width (bit->font, copy, pos) < remain) { | 2063 while (gdk_text_width (bit->font, copy, pos) < remain) { |
2065 if (copy [pos] == ' ') | 2064 if (copy [pos] == ' ') |
2066 seenspace = TRUE; | 2065 seenspace = TRUE; |
2067 pos++; | 2066 pos++; |
2068 } | 2067 } |
2081 | 2080 |
2082 backwards_update (imhtml, bit, height, bit->font->ascent); | 2081 backwards_update (imhtml, bit, height, bit->font->ascent); |
2083 | 2082 |
2084 while (pos < strlen (bit->text)) { | 2083 while (pos < strlen (bit->text)) { |
2085 width = gdk_string_width (bit->font, copy + pos); | 2084 width = gdk_string_width (bit->font, copy + pos); |
2086 if (imhtml->x + width + BORDER_SIZE + BORDER_SIZE + 5 > imhtml->xsize) { | 2085 if (imhtml->x + width > imhtml->xsize) { |
2087 gint newpos = 0; | 2086 gint newpos = 0; |
2088 gint remain = imhtml->xsize - imhtml->x - BORDER_SIZE - BORDER_SIZE - 5; | 2087 gint remain = imhtml->xsize - imhtml->x; |
2089 while (gdk_text_width (bit->font, copy + pos, newpos) < remain) { | 2088 while (gdk_text_width (bit->font, copy + pos, newpos) < remain) { |
2090 if (copy [pos + newpos] == ' ') | 2089 if (copy [pos + newpos] == ' ') |
2091 seenspace = TRUE; | 2090 seenspace = TRUE; |
2092 newpos++; | 2091 newpos++; |
2093 } | 2092 } |
2120 | 2119 |
2121 g_free (copy); | 2120 g_free (copy); |
2122 } else if ((bit->type == TYPE_SMILEY) || (bit->type == TYPE_IMG)) { | 2121 } else if ((bit->type == TYPE_SMILEY) || (bit->type == TYPE_IMG)) { |
2123 gdk_window_get_size (bit->pm, &width, &height); | 2122 gdk_window_get_size (bit->pm, &width, &height); |
2124 | 2123 |
2125 if ((imhtml->x != BORDER_SIZE) && | 2124 if ((imhtml->x != 0) && ((imhtml->x + width) > imhtml->xsize)) |
2126 ((imhtml->x + width + BORDER_SIZE + BORDER_SIZE + 5) > imhtml->xsize)) | |
2127 new_line (imhtml); | 2125 new_line (imhtml); |
2128 else | 2126 else |
2129 backwards_update (imhtml, bit, height, 0); | 2127 backwards_update (imhtml, bit, height, 0); |
2130 | 2128 |
2131 add_img_renderer (imhtml, bit); | 2129 add_img_renderer (imhtml, bit); |
2138 new_line (imhtml); | 2136 new_line (imhtml); |
2139 | 2137 |
2140 li = g_new0 (struct line_info, 1); | 2138 li = g_new0 (struct line_info, 1); |
2141 li->x = imhtml->x; | 2139 li->x = imhtml->x; |
2142 li->y = imhtml->y; | 2140 li->y = imhtml->y; |
2143 li->width = imhtml->xsize - BORDER_SIZE - BORDER_SIZE; | 2141 li->width = imhtml->xsize; |
2144 li->height = HR_HEIGHT * 2; | 2142 li->height = HR_HEIGHT * 2; |
2145 li->ascent = 0; | 2143 li->ascent = 0; |
2146 li->text = NULL; | 2144 li->text = NULL; |
2147 li->bit = bit; | 2145 li->bit = bit; |
2148 | 2146 |
2150 | 2148 |
2151 imhtml->llheight = HR_HEIGHT * 2; | 2149 imhtml->llheight = HR_HEIGHT * 2; |
2152 new_line (imhtml); | 2150 new_line (imhtml); |
2153 add_text_renderer (imhtml, bit, NULL); | 2151 add_text_renderer (imhtml, bit, NULL); |
2154 } | 2152 } |
2155 | |
2156 GTK_LAYOUT (imhtml)->height = imhtml->y + 5; | |
2157 GTK_LAYOUT (imhtml)->vadjustment->upper = imhtml->y + 5; | |
2158 gtk_signal_emit_by_name (GTK_OBJECT (GTK_LAYOUT (imhtml)->vadjustment), "changed"); | |
2159 } | 2153 } |
2160 | 2154 |
2161 void | 2155 void |
2162 gtk_imhtml_show_smileys (GtkIMHtml *imhtml, | 2156 gtk_imhtml_show_smileys (GtkIMHtml *imhtml, |
2163 gboolean show) | 2157 gboolean show) |
2439 | 2433 |
2440 if (options & GTK_IMHTML_RETURN_LOG) | 2434 if (options & GTK_IMHTML_RETURN_LOG) |
2441 retval = g_string_new (""); | 2435 retval = g_string_new (""); |
2442 | 2436 |
2443 vadj = GTK_LAYOUT (imhtml)->vadjustment; | 2437 vadj = GTK_LAYOUT (imhtml)->vadjustment; |
2444 if ((vadj->value < imhtml->y + 5 - GTK_WIDGET (imhtml)->allocation.height) && | 2438 if ((vadj->value < imhtml->y - GTK_WIDGET (imhtml)->allocation.height) && |
2445 (vadj->upper >= GTK_WIDGET (imhtml)->allocation.height)) | 2439 (vadj->upper >= GTK_WIDGET (imhtml)->allocation.height)) |
2446 scrolldown = FALSE; | 2440 scrolldown = FALSE; |
2447 | 2441 |
2448 c = text; | 2442 c = text; |
2449 ws = g_malloc (strlen (text) + 1); | 2443 ws = g_malloc (strlen (text) + 1); |
3171 imhtml->bits = g_list_append (imhtml->bits, bit); | 3165 imhtml->bits = g_list_append (imhtml->bits, bit); |
3172 newbits = g_list_remove (newbits, bit); | 3166 newbits = g_list_remove (newbits, bit); |
3173 gtk_imhtml_draw_bit (imhtml, bit); | 3167 gtk_imhtml_draw_bit (imhtml, bit); |
3174 } | 3168 } |
3175 | 3169 |
3176 gtk_widget_set_usize (GTK_WIDGET (imhtml), -1, imhtml->y + 5); | 3170 GTK_LAYOUT (imhtml)->height = imhtml->y; |
3171 GTK_LAYOUT (imhtml)->vadjustment->upper = imhtml->y; | |
3172 gtk_signal_emit_by_name (GTK_OBJECT (GTK_LAYOUT (imhtml)->vadjustment), "changed"); | |
3173 | |
3174 gtk_widget_set_usize (GTK_WIDGET (imhtml), -1, imhtml->y); | |
3177 | 3175 |
3178 if (!(options & GTK_IMHTML_NO_SCROLL) && | 3176 if (!(options & GTK_IMHTML_NO_SCROLL) && |
3179 scrolldown && | 3177 scrolldown && |
3180 (imhtml->y + 5 >= GTK_WIDGET (imhtml)->allocation.height)) | 3178 (imhtml->y >= MAX (1, |
3181 gtk_adjustment_set_value (vadj, imhtml->y + 5 - GTK_WIDGET (imhtml)->allocation.height); | 3179 (GTK_WIDGET (imhtml)->allocation.height - |
3180 (GTK_WIDGET (imhtml)->style->klass->ythickness + BORDER_SIZE) * 2)))) | |
3181 gtk_adjustment_set_value (vadj, imhtml->y - | |
3182 MAX (1, (GTK_WIDGET (imhtml)->allocation.height - | |
3183 (GTK_WIDGET (imhtml)->style->klass->ythickness + | |
3184 BORDER_SIZE) * 2))); | |
3182 | 3185 |
3183 if (url) { | 3186 if (url) { |
3184 g_free (url); | 3187 g_free (url); |
3185 if (retval) | 3188 if (retval) |
3186 retval = g_string_append (retval, "</A>"); | 3189 retval = g_string_append (retval, "</A>"); |
3294 } | 3297 } |
3295 imhtml->tip_bit = NULL; | 3298 imhtml->tip_bit = NULL; |
3296 | 3299 |
3297 gdk_window_set_cursor (GTK_LAYOUT (imhtml)->bin_window, imhtml->arrow_cursor); | 3300 gdk_window_set_cursor (GTK_LAYOUT (imhtml)->bin_window, imhtml->arrow_cursor); |
3298 | 3301 |
3299 imhtml->x = BORDER_SIZE; | 3302 imhtml->x = 0; |
3300 imhtml->y = BORDER_SIZE + 10; | 3303 imhtml->y = TOP_BORDER; |
3301 imhtml->llheight = 0; | 3304 imhtml->llheight = 0; |
3302 imhtml->llascent = 0; | 3305 imhtml->llascent = 0; |
3303 imhtml->line = NULL; | 3306 imhtml->line = NULL; |
3304 | 3307 |
3305 if (GTK_WIDGET_REALIZED (GTK_WIDGET (imhtml))) | 3308 if (GTK_WIDGET_REALIZED (GTK_WIDGET (imhtml))) |