Mercurial > pidgin.yaz
comparison src/gtkimhtml.c @ 1997:1c01a85c0616
[gaim-migrate @ 2007]
no border.
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Tue, 12 Jun 2001 01:45:08 +0000 |
parents | fc0a285c207a |
children | 00dc6b2df5b6 |
comparison
equal
deleted
inserted
replaced
1996:fc0a285c207a | 1997:1c01a85c0616 |
---|---|
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 2 | 54 #define BORDER_SIZE 3 |
55 #define MIN_HEIGHT 20 | 55 #define MIN_HEIGHT 20 |
56 #define HR_HEIGHT 2 | 56 #define HR_HEIGHT 2 |
57 #define TOOLTIP_TIMEOUT 500 | 57 #define TOOLTIP_TIMEOUT 500 |
58 | 58 |
59 #define DIFF(a, b) (((a) > (b)) ? ((a) - (b)) : ((b) - (a))) | 59 #define DIFF(a, b) (((a) > (b)) ? ((a) - (b)) : ((b) - (a))) |
234 | 234 |
235 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), | 235 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), |
236 &attributes, attributes_mask); | 236 &attributes, attributes_mask); |
237 gdk_window_set_user_data (widget->window, widget); | 237 gdk_window_set_user_data (widget->window, widget); |
238 | 238 |
239 attributes.x = widget->style->klass->xthickness + BORDER_SIZE; | 239 attributes.x = 0; |
240 attributes.y = widget->style->klass->xthickness + BORDER_SIZE; | 240 attributes.y = 0; |
241 attributes.width = MAX (1, (gint) widget->allocation.width - (gint) attributes.x * 2); | |
242 attributes.height = MAX (1, (gint) widget->allocation.height - (gint) attributes.y * 2); | |
243 attributes.event_mask = gtk_widget_get_events (widget) | 241 attributes.event_mask = gtk_widget_get_events (widget) |
244 | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | 242 | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
245 | GDK_POINTER_MOTION_MASK | GDK_EXPOSURE_MASK | GDK_LEAVE_NOTIFY_MASK; | 243 | GDK_POINTER_MOTION_MASK | GDK_EXPOSURE_MASK | GDK_LEAVE_NOTIFY_MASK; |
246 | 244 |
247 GTK_LAYOUT (imhtml)->bin_window = gdk_window_new (widget->window, | 245 GTK_LAYOUT (imhtml)->bin_window = gdk_window_new (widget->window, |
250 | 248 |
251 widget->style = gtk_style_attach (widget->style, widget->window); | 249 widget->style = gtk_style_attach (widget->style, widget->window); |
252 | 250 |
253 gdk_window_set_cursor (widget->window, imhtml->arrow_cursor); | 251 gdk_window_set_cursor (widget->window, imhtml->arrow_cursor); |
254 | 252 |
255 gdk_window_set_background (widget->window, &widget->style->base [GTK_STATE_NORMAL]); | 253 gdk_window_set_background (widget->window, &widget->style->base [GTK_WIDGET_STATE (widget)]); |
256 gdk_window_set_background (GTK_LAYOUT (imhtml)->bin_window, | 254 gdk_window_set_background (GTK_LAYOUT (imhtml)->bin_window, |
257 &widget->style->base [GTK_STATE_NORMAL]); | 255 &widget->style->base [GTK_WIDGET_STATE (widget)]); |
258 | |
259 gdk_window_show (GTK_LAYOUT (imhtml)->bin_window); | |
260 } | 256 } |
261 | 257 |
262 static gboolean | 258 static gboolean |
263 similar_colors (GdkColor *bg, | 259 similar_colors (GdkColor *bg, |
264 GdkColor *fg) | 260 GdkColor *fg) |
472 | 468 |
473 gdk_draw_rectangle (drawable, gc, TRUE, line->x - xoff, line->y - yoff + line_height / 2, | 469 gdk_draw_rectangle (drawable, gc, TRUE, line->x - xoff, line->y - yoff + line_height / 2, |
474 line->width, line_height); | 470 line->width, line_height); |
475 | 471 |
476 gdk_gc_unref (gc); | 472 gdk_gc_unref (gc); |
477 } | |
478 | |
479 static void | |
480 gtk_imhtml_draw_focus (GtkWidget *widget) | |
481 { | |
482 GtkIMHtml *imhtml; | |
483 gint x = 0, | |
484 y = 0, | |
485 w = 0, | |
486 h = 0; | |
487 | |
488 imhtml = GTK_IMHTML (widget); | |
489 | |
490 if (!GTK_WIDGET_DRAWABLE (widget)) | |
491 return; | |
492 | |
493 if (GTK_WIDGET_HAS_FOCUS (widget)) { | |
494 gtk_paint_focus (widget->style, widget->window, NULL, widget, "text", 0, 0, | |
495 widget->allocation.width - 1, widget->allocation.height - 1); | |
496 x = 1; y = 1; w = 2; h = 2; | |
497 } | |
498 | |
499 gtk_paint_shadow (widget->style, widget->window, GTK_STATE_NORMAL, | |
500 GTK_SHADOW_IN, NULL, widget, "text", x, y, | |
501 widget->allocation.width - w, widget->allocation.height - h); | |
502 } | 473 } |
503 | 474 |
504 static void | 475 static void |
505 gtk_imhtml_draw_exposed (GtkIMHtml *imhtml) | 476 gtk_imhtml_draw_exposed (GtkIMHtml *imhtml) |
506 { | 477 { |
557 chunks = g_list_next (chunks); | 528 chunks = g_list_next (chunks); |
558 } | 529 } |
559 } | 530 } |
560 bits = g_list_next (bits); | 531 bits = g_list_next (bits); |
561 } | 532 } |
562 | |
563 gtk_imhtml_draw_focus (GTK_WIDGET (imhtml)); | |
564 } | 533 } |
565 | 534 |
566 static void | 535 static void |
567 gtk_imhtml_draw (GtkWidget *widget, | 536 gtk_imhtml_draw (GtkWidget *widget, |
568 GdkRectangle *area) | 537 GdkRectangle *area) |
598 { | 567 { |
599 GtkIMHtml *imhtml; | 568 GtkIMHtml *imhtml; |
600 | 569 |
601 g_return_val_if_fail (widget != NULL, FALSE); | 570 g_return_val_if_fail (widget != NULL, FALSE); |
602 g_return_val_if_fail (GTK_IS_IMHTML (widget), FALSE); | 571 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); | |
603 | 575 |
604 imhtml = GTK_IMHTML (widget); | 576 imhtml = GTK_IMHTML (widget); |
605 gtk_imhtml_draw_exposed (imhtml); | 577 gtk_imhtml_draw_exposed (imhtml); |
606 | 578 |
607 return FALSE; | 579 return FALSE; |
628 while (imhtml->urls) { | 600 while (imhtml->urls) { |
629 g_free (imhtml->urls->data); | 601 g_free (imhtml->urls->data); |
630 imhtml->urls = g_list_remove (imhtml->urls, imhtml->urls->data); | 602 imhtml->urls = g_list_remove (imhtml->urls, imhtml->urls->data); |
631 } | 603 } |
632 | 604 |
633 imhtml->x = 0; | 605 imhtml->x = BORDER_SIZE; |
634 imhtml->y = 10; | 606 imhtml->y = BORDER_SIZE + 10; |
635 imhtml->llheight = 0; | 607 imhtml->llheight = 0; |
636 imhtml->llascent = 0; | 608 imhtml->llascent = 0; |
637 | 609 |
638 b = imhtml->bits; | 610 b = imhtml->bits; |
639 while (b) { | 611 while (b) { |
669 | 641 |
670 gdk_gc_unref (gc); | 642 gdk_gc_unref (gc); |
671 } | 643 } |
672 | 644 |
673 gtk_layout_thaw (GTK_LAYOUT (imhtml)); | 645 gtk_layout_thaw (GTK_LAYOUT (imhtml)); |
674 gtk_imhtml_draw_focus (GTK_WIDGET (imhtml)); | |
675 } | 646 } |
676 | 647 |
677 static void | 648 static void |
678 gtk_imhtml_size_allocate (GtkWidget *widget, | 649 gtk_imhtml_size_allocate (GtkWidget *widget, |
679 GtkAllocation *allocation) | 650 GtkAllocation *allocation) |
689 layout = GTK_LAYOUT (widget); | 660 layout = GTK_LAYOUT (widget); |
690 | 661 |
691 widget->allocation = *allocation; | 662 widget->allocation = *allocation; |
692 | 663 |
693 if (GTK_WIDGET_REALIZED (widget)) { | 664 if (GTK_WIDGET_REALIZED (widget)) { |
694 gint x = widget->style->klass->xthickness + BORDER_SIZE; | |
695 gint y = widget->style->klass->ythickness + BORDER_SIZE; | |
696 gdk_window_move_resize (widget->window, | 665 gdk_window_move_resize (widget->window, |
697 allocation->x, allocation->y, | 666 allocation->x, allocation->y, |
698 allocation->width, allocation->height); | 667 allocation->width, allocation->height); |
699 gdk_window_move_resize (layout->bin_window, | 668 gdk_window_move_resize (layout->bin_window, |
700 x, y, | 669 0, 0, |
701 MAX (1, (gint) allocation->width - x * 2), | 670 allocation->width, allocation->height); |
702 MAX (1, (gint) allocation->height - y * 2)); | |
703 } | 671 } |
704 | 672 |
705 layout->hadjustment->page_size = allocation->width; | 673 layout->hadjustment->page_size = allocation->width; |
706 layout->hadjustment->page_increment = allocation->width / 2; | 674 layout->hadjustment->page_increment = allocation->width / 2; |
707 layout->hadjustment->lower = 0; | 675 layout->hadjustment->lower = 0; |
1088 baseline_skip = style->font->ascent + style->font->descent + gap; | 1056 baseline_skip = style->font->ascent + style->font->descent + gap; |
1089 | 1057 |
1090 if (!imhtml->tip_bit) | 1058 if (!imhtml->tip_bit) |
1091 return FALSE; | 1059 return FALSE; |
1092 | 1060 |
1093 gtk_paint_flat_box (style, imhtml->tip_window->window, GTK_STATE_NORMAL, GTK_SHADOW_OUT, | 1061 gtk_paint_flat_box(style, imhtml->tip_window->window, GTK_STATE_NORMAL, GTK_SHADOW_OUT, |
1094 NULL, imhtml->tip_window, "tooltip", 0, 0, -1, -1); | 1062 NULL, imhtml->tip_window, "tooltip", 0, 0, -1, -1); |
1095 | 1063 |
1096 y = style->font->ascent + 4; | 1064 y = style->font->ascent + 4; |
1097 gtk_paint_string (style, imhtml->tip_window->window, GTK_STATE_NORMAL, NULL, | 1065 gtk_paint_string (style, imhtml->tip_window->window, GTK_STATE_NORMAL, NULL, |
1098 imhtml->tip_window, "tooltip", 4, y, imhtml->tip_bit->url); | 1066 imhtml->tip_window, "tooltip", 4, y, imhtml->tip_bit->url); |
1550 | 1518 |
1551 object_class->destroy = gtk_imhtml_destroy; | 1519 object_class->destroy = gtk_imhtml_destroy; |
1552 | 1520 |
1553 widget_class->realize = gtk_imhtml_realize; | 1521 widget_class->realize = gtk_imhtml_realize; |
1554 widget_class->draw = gtk_imhtml_draw; | 1522 widget_class->draw = gtk_imhtml_draw; |
1555 widget_class->draw_focus = gtk_imhtml_draw_focus; | |
1556 widget_class->style_set = gtk_imhtml_style_set; | 1523 widget_class->style_set = gtk_imhtml_style_set; |
1557 widget_class->expose_event = gtk_imhtml_expose_event; | 1524 widget_class->expose_event = gtk_imhtml_expose_event; |
1558 widget_class->size_allocate = gtk_imhtml_size_allocate; | 1525 widget_class->size_allocate = gtk_imhtml_size_allocate; |
1559 widget_class->motion_notify_event = gtk_imhtml_motion_notify_event; | 1526 widget_class->motion_notify_event = gtk_imhtml_motion_notify_event; |
1560 widget_class->leave_notify_event = gtk_imhtml_leave_notify_event; | 1527 widget_class->leave_notify_event = gtk_imhtml_leave_notify_event; |
1820 gtk_imhtml_set_adjustments (imhtml, hadj, vadj); | 1787 gtk_imhtml_set_adjustments (imhtml, hadj, vadj); |
1821 | 1788 |
1822 imhtml->bits = NULL; | 1789 imhtml->bits = NULL; |
1823 imhtml->urls = NULL; | 1790 imhtml->urls = NULL; |
1824 | 1791 |
1825 imhtml->x = 0; | 1792 imhtml->x = BORDER_SIZE; |
1826 imhtml->y = 10; | 1793 imhtml->y = BORDER_SIZE + 10; |
1827 imhtml->llheight = 0; | 1794 imhtml->llheight = 0; |
1828 imhtml->llascent = 0; | 1795 imhtml->llascent = 0; |
1829 imhtml->line = NULL; | 1796 imhtml->line = NULL; |
1830 | 1797 |
1831 imhtml->selected_text = g_string_new (""); | 1798 imhtml->selected_text = g_string_new (""); |
1924 GList *last = g_list_last (imhtml->line); | 1891 GList *last = g_list_last (imhtml->line); |
1925 struct line_info *li; | 1892 struct line_info *li; |
1926 | 1893 |
1927 if (last) { | 1894 if (last) { |
1928 li = last->data; | 1895 li = last->data; |
1929 if (li->x + li->width != imhtml->xsize) | 1896 if (li->x + li->width != imhtml->xsize - BORDER_SIZE) |
1930 li->width = imhtml->xsize - li->x; | 1897 li->width = imhtml->xsize - BORDER_SIZE - li->x; |
1931 } | 1898 } |
1932 | 1899 |
1933 last = imhtml->line; | 1900 last = imhtml->line; |
1934 if (last) { | 1901 if (last) { |
1935 li = last->data; | 1902 li = last->data; |
1947 } | 1914 } |
1948 | 1915 |
1949 g_list_free (imhtml->line); | 1916 g_list_free (imhtml->line); |
1950 imhtml->line = NULL; | 1917 imhtml->line = NULL; |
1951 | 1918 |
1952 imhtml->x = 0; | 1919 imhtml->x = BORDER_SIZE; |
1953 imhtml->y += imhtml->llheight; | 1920 imhtml->y += imhtml->llheight; |
1954 imhtml->llheight = 0; | 1921 imhtml->llheight = 0; |
1955 imhtml->llascent = 0; | 1922 imhtml->llascent = 0; |
1956 } | 1923 } |
1957 | 1924 |
2089 gchar *tmp; | 2056 gchar *tmp; |
2090 | 2057 |
2091 height = bit->font->ascent + bit->font->descent; | 2058 height = bit->font->ascent + bit->font->descent; |
2092 width = gdk_string_width (bit->font, bit->text); | 2059 width = gdk_string_width (bit->font, bit->text); |
2093 | 2060 |
2094 if ((imhtml->x != 0) && | 2061 if ((imhtml->x != BORDER_SIZE) && |
2095 ((imhtml->x + width + 5) > imhtml->xsize)) { | 2062 ((imhtml->x + width + BORDER_SIZE + BORDER_SIZE + 5) > imhtml->xsize)) { |
2096 gint remain = imhtml->xsize - imhtml->x - 5; | 2063 gint remain = imhtml->xsize - imhtml->x - BORDER_SIZE - BORDER_SIZE - 5; |
2097 while (gdk_text_width (bit->font, copy, pos) < remain) { | 2064 while (gdk_text_width (bit->font, copy, pos) < remain) { |
2098 if (copy [pos] == ' ') | 2065 if (copy [pos] == ' ') |
2099 seenspace = TRUE; | 2066 seenspace = TRUE; |
2100 pos++; | 2067 pos++; |
2101 } | 2068 } |
2114 | 2081 |
2115 backwards_update (imhtml, bit, height, bit->font->ascent); | 2082 backwards_update (imhtml, bit, height, bit->font->ascent); |
2116 | 2083 |
2117 while (pos < strlen (bit->text)) { | 2084 while (pos < strlen (bit->text)) { |
2118 width = gdk_string_width (bit->font, copy + pos); | 2085 width = gdk_string_width (bit->font, copy + pos); |
2119 if (imhtml->x + width + 5 > imhtml->xsize) { | 2086 if (imhtml->x + width + BORDER_SIZE + BORDER_SIZE + 5 > imhtml->xsize) { |
2120 gint newpos = 0; | 2087 gint newpos = 0; |
2121 gint remain = imhtml->xsize - imhtml->x - 5; | 2088 gint remain = imhtml->xsize - imhtml->x - BORDER_SIZE - BORDER_SIZE - 5; |
2122 while (gdk_text_width (bit->font, copy + pos, newpos) < remain) { | 2089 while (gdk_text_width (bit->font, copy + pos, newpos) < remain) { |
2123 if (copy [pos + newpos] == ' ') | 2090 if (copy [pos + newpos] == ' ') |
2124 seenspace = TRUE; | 2091 seenspace = TRUE; |
2125 newpos++; | 2092 newpos++; |
2126 } | 2093 } |
2153 | 2120 |
2154 g_free (copy); | 2121 g_free (copy); |
2155 } else if ((bit->type == TYPE_SMILEY) || (bit->type == TYPE_IMG)) { | 2122 } else if ((bit->type == TYPE_SMILEY) || (bit->type == TYPE_IMG)) { |
2156 gdk_window_get_size (bit->pm, &width, &height); | 2123 gdk_window_get_size (bit->pm, &width, &height); |
2157 | 2124 |
2158 if ((imhtml->x != 0) && | 2125 if ((imhtml->x != BORDER_SIZE) && |
2159 ((imhtml->x + width + 5) > imhtml->xsize)) | 2126 ((imhtml->x + width + BORDER_SIZE + BORDER_SIZE + 5) > imhtml->xsize)) |
2160 new_line (imhtml); | 2127 new_line (imhtml); |
2161 else | 2128 else |
2162 backwards_update (imhtml, bit, height, 0); | 2129 backwards_update (imhtml, bit, height, 0); |
2163 | 2130 |
2164 add_img_renderer (imhtml, bit); | 2131 add_img_renderer (imhtml, bit); |
2171 new_line (imhtml); | 2138 new_line (imhtml); |
2172 | 2139 |
2173 li = g_new0 (struct line_info, 1); | 2140 li = g_new0 (struct line_info, 1); |
2174 li->x = imhtml->x; | 2141 li->x = imhtml->x; |
2175 li->y = imhtml->y; | 2142 li->y = imhtml->y; |
2176 li->width = imhtml->xsize; | 2143 li->width = imhtml->xsize - BORDER_SIZE - BORDER_SIZE; |
2177 li->height = HR_HEIGHT * 2; | 2144 li->height = HR_HEIGHT * 2; |
2178 li->ascent = 0; | 2145 li->ascent = 0; |
2179 li->text = NULL; | 2146 li->text = NULL; |
2180 li->bit = bit; | 2147 li->bit = bit; |
2181 | 2148 |
3327 } | 3294 } |
3328 imhtml->tip_bit = NULL; | 3295 imhtml->tip_bit = NULL; |
3329 | 3296 |
3330 gdk_window_set_cursor (GTK_LAYOUT (imhtml)->bin_window, imhtml->arrow_cursor); | 3297 gdk_window_set_cursor (GTK_LAYOUT (imhtml)->bin_window, imhtml->arrow_cursor); |
3331 | 3298 |
3332 imhtml->x = 0; | 3299 imhtml->x = BORDER_SIZE; |
3333 imhtml->y = 10; | 3300 imhtml->y = BORDER_SIZE + 10; |
3334 imhtml->llheight = 0; | 3301 imhtml->llheight = 0; |
3335 imhtml->llascent = 0; | 3302 imhtml->llascent = 0; |
3336 imhtml->line = NULL; | 3303 imhtml->line = NULL; |
3337 | 3304 |
3338 if (GTK_WIDGET_REALIZED (GTK_WIDGET (imhtml))) | 3305 if (GTK_WIDGET_REALIZED (GTK_WIDGET (imhtml))) |