Mercurial > pidgin.yaz
comparison src/gtkimhtml.c @ 1574:7ad82fa9e6ce
[gaim-migrate @ 1584]
woo. tooltips. yay.
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Thu, 15 Mar 2001 13:44:16 +0000 |
parents | 7b50a08090a2 |
children | 4fcd012c0a6a |
comparison
equal
deleted
inserted
replaced
1573:3a8bd72f431f | 1574:7ad82fa9e6ce |
---|---|
49 gint font_sizes [] = { 80, 100, 120, 140, 200, 300, 400 }; | 49 gint font_sizes [] = { 80, 100, 120, 140, 200, 300, 400 }; |
50 | 50 |
51 #define BORDER_SIZE 3 | 51 #define BORDER_SIZE 3 |
52 #define MIN_HEIGHT 20 | 52 #define MIN_HEIGHT 20 |
53 #define HR_HEIGHT 2 | 53 #define HR_HEIGHT 2 |
54 #define TOOLTIP_TIMEOUT 500 | |
54 | 55 |
55 #define DIFF(a, b) (((a) > (b)) ? ((a) - (b)) : ((b) - (a))) | 56 #define DIFF(a, b) (((a) > (b)) ? ((a) - (b)) : ((b) - (a))) |
56 #define COLOR_MOD 0x8000 | 57 #define COLOR_MOD 0x8000 |
57 #define COLOR_DIFF 0x80 | 58 #define COLOR_DIFF 0x80 |
58 | 59 |
111 struct url_widget { | 112 struct url_widget { |
112 gint x; | 113 gint x; |
113 gint y; | 114 gint y; |
114 gint width; | 115 gint width; |
115 gint height; | 116 gint height; |
116 gchar *url; | 117 GtkIMHtmlBit *bit; |
117 }; | 118 }; |
118 | 119 |
119 static GtkLayoutClass *parent_class = NULL; | 120 static GtkLayoutClass *parent_class = NULL; |
120 | 121 |
121 enum { | 122 enum { |
980 | 981 |
981 return FALSE; | 982 return FALSE; |
982 } | 983 } |
983 | 984 |
984 static gint | 985 static gint |
986 gtk_imhtml_tip_paint (GtkIMHtml *imhtml) | |
987 { | |
988 GtkStyle *style; | |
989 gint y, baseline_skip, gap; | |
990 | |
991 style = imhtml->tip_window->style; | |
992 | |
993 gap = (style->font->ascent + style->font->descent) / 4; | |
994 if (gap < 2) | |
995 gap = 2; | |
996 baseline_skip = style->font->ascent + style->font->descent + gap; | |
997 | |
998 if (!imhtml->tip_bit) | |
999 return FALSE; | |
1000 | |
1001 gtk_paint_flat_box(style, imhtml->tip_window->window, GTK_STATE_NORMAL, GTK_SHADOW_OUT, | |
1002 NULL, imhtml->tip_window, "tooltip", 0, 0, -1, -1); | |
1003 | |
1004 y = style->font->ascent + 4; | |
1005 gtk_paint_string (style, imhtml->tip_window->window, GTK_STATE_NORMAL, NULL, | |
1006 imhtml->tip_window, "tooltip", 4, y, imhtml->tip_bit->url); | |
1007 | |
1008 return FALSE; | |
1009 } | |
1010 | |
1011 static gint | |
1012 gtk_imhtml_tip (gpointer data) | |
1013 { | |
1014 GtkIMHtml *imhtml = data; | |
1015 GtkWidget *widget = GTK_WIDGET (imhtml); | |
1016 GtkStyle *style; | |
1017 gint gap, x, y, w, h, scr_w, scr_h, baseline_skip; | |
1018 | |
1019 if (!imhtml->tip_bit || !GTK_WIDGET_DRAWABLE (widget)) { | |
1020 imhtml->tip_timer = 0; | |
1021 return FALSE; | |
1022 } | |
1023 | |
1024 if (imhtml->tip_window) | |
1025 gtk_widget_destroy (imhtml->tip_window); | |
1026 | |
1027 imhtml->tip_window = gtk_window_new (GTK_WINDOW_POPUP); | |
1028 gtk_widget_set_app_paintable (imhtml->tip_window, TRUE); | |
1029 gtk_window_set_policy (GTK_WINDOW (imhtml->tip_window), FALSE, FALSE, TRUE); | |
1030 gtk_widget_set_name (imhtml->tip_window, "gtk-tooltips"); | |
1031 gtk_signal_connect_object (GTK_OBJECT (imhtml->tip_window), "expose_event", | |
1032 GTK_SIGNAL_FUNC (gtk_imhtml_tip_paint), GTK_OBJECT (imhtml)); | |
1033 gtk_signal_connect_object (GTK_OBJECT (imhtml->tip_window), "draw", | |
1034 GTK_SIGNAL_FUNC (gtk_imhtml_tip_paint), GTK_OBJECT (imhtml)); | |
1035 | |
1036 gtk_widget_ensure_style (imhtml->tip_window); | |
1037 style = imhtml->tip_window->style; | |
1038 | |
1039 scr_w = gdk_screen_width (); | |
1040 scr_h = gdk_screen_height (); | |
1041 | |
1042 gap = (style->font->ascent + style->font->descent) / 4; | |
1043 if (gap < 2) | |
1044 gap = 2; | |
1045 baseline_skip = style->font->ascent + style->font->descent + gap; | |
1046 | |
1047 w = 8 + gdk_string_width (style->font, imhtml->tip_bit->url); | |
1048 h = 8 - gap + baseline_skip; | |
1049 | |
1050 gdk_window_get_pointer (NULL, &x, &y, NULL); | |
1051 if (GTK_WIDGET_NO_WINDOW (widget)) | |
1052 y += widget->allocation.y; | |
1053 | |
1054 x -= ((w >> 1) + 4); | |
1055 | |
1056 if ((x + w) > scr_w) | |
1057 x -= (x + w) - scr_w; | |
1058 else if (x < 0) | |
1059 x = 0; | |
1060 | |
1061 if ((y + h + + 4) > scr_h) | |
1062 y = y - imhtml->tip_bit->font->ascent + imhtml->tip_bit->font->descent; | |
1063 else | |
1064 y = y + imhtml->tip_bit->font->ascent + imhtml->tip_bit->font->descent; | |
1065 | |
1066 gtk_widget_set_usize (imhtml->tip_window, w, h); | |
1067 gtk_widget_popup (imhtml->tip_window, x, y); | |
1068 | |
1069 imhtml->tip_timer = 0; | |
1070 return FALSE; | |
1071 } | |
1072 | |
1073 static gint | |
985 gtk_imhtml_motion_notify_event (GtkWidget *widget, | 1074 gtk_imhtml_motion_notify_event (GtkWidget *widget, |
986 GdkEventMotion *event) | 1075 GdkEventMotion *event) |
987 { | 1076 { |
988 gint x, y; | 1077 gint x, y; |
989 GdkModifierType state; | 1078 GdkModifierType state; |
1034 | 1123 |
1035 while (urls) { | 1124 while (urls) { |
1036 uw = (struct url_widget *) urls->data; | 1125 uw = (struct url_widget *) urls->data; |
1037 if ((x > uw->x) && (x < uw->x + uw->width) && | 1126 if ((x > uw->x) && (x < uw->x + uw->width) && |
1038 (y > uw->y) && (y < uw->y + uw->height)) { | 1127 (y > uw->y) && (y < uw->y + uw->height)) { |
1128 if (imhtml->tip_bit != uw->bit) { | |
1129 imhtml->tip_bit = uw->bit; | |
1130 if (imhtml->tip_timer != 0) | |
1131 gtk_timeout_remove (imhtml->tip_timer); | |
1132 if (imhtml->tip_window) { | |
1133 gtk_widget_destroy (imhtml->tip_window); | |
1134 imhtml->tip_window = NULL; | |
1135 } | |
1136 imhtml->tip_timer = gtk_timeout_add (TOOLTIP_TIMEOUT, | |
1137 gtk_imhtml_tip, | |
1138 imhtml); | |
1139 } | |
1039 gdk_window_set_cursor (GTK_LAYOUT (imhtml)->bin_window, | 1140 gdk_window_set_cursor (GTK_LAYOUT (imhtml)->bin_window, |
1040 imhtml->hand_cursor); | 1141 imhtml->hand_cursor); |
1041 return TRUE; | 1142 return TRUE; |
1042 } | 1143 } |
1043 urls = g_list_next (urls); | 1144 urls = g_list_next (urls); |
1044 } | 1145 } |
1045 } | 1146 } |
1147 | |
1148 if (imhtml->tip_timer) { | |
1149 gtk_timeout_remove (imhtml->tip_timer); | |
1150 imhtml->tip_timer = 0; | |
1151 } | |
1152 if (imhtml->tip_window) { | |
1153 gtk_widget_destroy (imhtml->tip_window); | |
1154 imhtml->tip_window = NULL; | |
1155 } | |
1156 imhtml->tip_bit = NULL; | |
1046 | 1157 |
1047 gdk_window_set_cursor (GTK_LAYOUT (imhtml)->bin_window, imhtml->arrow_cursor); | 1158 gdk_window_set_cursor (GTK_LAYOUT (imhtml)->bin_window, imhtml->arrow_cursor); |
1048 | 1159 |
1049 return TRUE; | 1160 return TRUE; |
1050 } | 1161 } |
1103 | 1214 |
1104 while (urls) { | 1215 while (urls) { |
1105 uw = (struct url_widget *) urls->data; | 1216 uw = (struct url_widget *) urls->data; |
1106 if ((x > uw->x) && (x < uw->x + uw->width) && | 1217 if ((x > uw->x) && (x < uw->x + uw->width) && |
1107 (y > uw->y) && (y < uw->y + uw->height)) { | 1218 (y > uw->y) && (y < uw->y + uw->height)) { |
1108 gtk_signal_emit (GTK_OBJECT (imhtml), signals [URL_CLICKED], uw->url); | 1219 gtk_signal_emit (GTK_OBJECT (imhtml), signals [URL_CLICKED], |
1220 uw->bit->url); | |
1109 return TRUE; | 1221 return TRUE; |
1110 } | 1222 } |
1111 urls = g_list_next (urls); | 1223 urls = g_list_next (urls); |
1112 } | 1224 } |
1113 } | 1225 } |
1614 uw = g_new0 (struct url_widget, 1); | 1726 uw = g_new0 (struct url_widget, 1); |
1615 uw->x = imhtml->x; | 1727 uw->x = imhtml->x; |
1616 uw->y = imhtml->y; | 1728 uw->y = imhtml->y; |
1617 uw->width = width; | 1729 uw->width = width; |
1618 uw->height = imhtml->llheight; | 1730 uw->height = imhtml->llheight; |
1619 uw->url = bit->url; | 1731 uw->bit = bit; |
1620 imhtml->urls = g_list_append (imhtml->urls, uw); | 1732 imhtml->urls = g_list_append (imhtml->urls, uw); |
1621 } | 1733 } |
1622 | 1734 |
1623 bit->chunks = g_list_append (bit->chunks, li); | 1735 bit->chunks = g_list_append (bit->chunks, li); |
1624 imhtml->line = g_list_append (imhtml->line, li); | 1736 imhtml->line = g_list_append (imhtml->line, li); |
1646 uw = g_new0 (struct url_widget, 1); | 1758 uw = g_new0 (struct url_widget, 1); |
1647 uw->x = imhtml->x; | 1759 uw->x = imhtml->x; |
1648 uw->y = imhtml->y; | 1760 uw->y = imhtml->y; |
1649 uw->width = width; | 1761 uw->width = width; |
1650 uw->height = imhtml->llheight; | 1762 uw->height = imhtml->llheight; |
1651 uw->url = bit->url; | 1763 uw->bit = bit; |
1652 imhtml->urls = g_list_append (imhtml->urls, uw); | 1764 imhtml->urls = g_list_append (imhtml->urls, uw); |
1653 } | 1765 } |
1654 | 1766 |
1655 bit->chunks = g_list_append (bit->chunks, li); | 1767 bit->chunks = g_list_append (bit->chunks, li); |
1656 imhtml->line = g_list_append (imhtml->line, li); | 1768 imhtml->line = g_list_append (imhtml->line, li); |