3 * Copyright (C) 2006-2007 Imendio AB
4 * Contact: Kristian Rietveld <kris@imendio.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library 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 GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
23 #include "gtktooltip.h"
25 #include "gtkwindow.h"
30 #include "gtkalignment.h"
37 #define GTK_TOOLTIP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_TOOLTIP, GtkTooltip))
38 #define GTK_TOOLTIP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_TOOLTIP, GtkTooltipClass))
39 #define GTK_IS_TOOLTIP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_TOOLTIP))
40 #define GTK_IS_TOOLTIP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_TOOLTIP))
41 #define GTK_TOOLTIP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_TOOLTIP, GtkTooltipClass))
43 typedef struct _GtkTooltipClass GtkTooltipClass;
47 GObject parent_instance;
54 GtkWidget *custom_widget;
56 GtkWindow *current_window;
57 GtkWidget *keyboard_widget;
59 GtkWidget *tooltip_widget;
60 GdkWindow *toplevel_window;
64 GdkWindow *last_window;
67 guint browse_mode_timeout_id;
69 guint browse_mode_enabled : 1;
70 guint keyboard_mode_enabled : 1;
73 struct _GtkTooltipClass
75 GObjectClass parent_class;
78 #define GTK_TOOLTIP_VISIBLE(tooltip) ((tooltip)->current_window && GTK_WIDGET_VISIBLE ((tooltip)->current_window))
81 static void gtk_tooltip_class_init (GtkTooltipClass *klass);
82 static void gtk_tooltip_init (GtkTooltip *tooltip);
83 static void gtk_tooltip_finalize (GObject *object);
85 static gboolean gtk_tooltip_paint_window (GtkTooltip *tooltip);
86 static void gtk_tooltip_window_hide (GtkWidget *widget,
88 static void gtk_tooltip_display_closed (GdkDisplay *display,
93 G_DEFINE_TYPE (GtkTooltip, gtk_tooltip, G_TYPE_OBJECT);
96 gtk_tooltip_class_init (GtkTooltipClass *klass)
98 GObjectClass *object_class;
100 object_class = G_OBJECT_CLASS (klass);
102 object_class->finalize = gtk_tooltip_finalize;
106 gtk_tooltip_init (GtkTooltip *tooltip)
108 tooltip->timeout_id = 0;
109 tooltip->browse_mode_timeout_id = 0;
111 tooltip->browse_mode_enabled = FALSE;
112 tooltip->keyboard_mode_enabled = FALSE;
114 tooltip->current_window = NULL;
115 tooltip->keyboard_widget = NULL;
117 tooltip->tooltip_widget = NULL;
118 tooltip->toplevel_window = NULL;
120 tooltip->last_window = NULL;
122 tooltip->window = g_object_ref (gtk_window_new (GTK_WINDOW_POPUP));
123 gtk_window_set_type_hint (GTK_WINDOW (tooltip->window),
124 GDK_WINDOW_TYPE_HINT_TOOLTIP);
125 gtk_widget_set_app_paintable (tooltip->window, TRUE);
126 gtk_window_set_resizable (GTK_WINDOW (tooltip->window), FALSE);
127 gtk_widget_set_name (tooltip->window, "gtk-tooltip");
128 g_signal_connect (tooltip->window, "hide",
129 G_CALLBACK (gtk_tooltip_window_hide), tooltip);
131 tooltip->alignment = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
132 gtk_alignment_set_padding (GTK_ALIGNMENT (tooltip->alignment),
133 tooltip->window->style->ythickness,
134 tooltip->window->style->ythickness,
135 tooltip->window->style->xthickness,
136 tooltip->window->style->xthickness);
137 gtk_container_add (GTK_CONTAINER (tooltip->window), tooltip->alignment);
138 gtk_widget_show (tooltip->alignment);
140 g_signal_connect_swapped (tooltip->window, "expose_event",
141 G_CALLBACK (gtk_tooltip_paint_window), tooltip);
143 tooltip->box = gtk_hbox_new (FALSE, tooltip->window->style->xthickness);
144 gtk_container_add (GTK_CONTAINER (tooltip->alignment), tooltip->box);
145 gtk_widget_show (tooltip->box);
147 tooltip->image = gtk_image_new ();
148 gtk_box_pack_start (GTK_BOX (tooltip->box), tooltip->image,
151 tooltip->label = gtk_label_new ("");
152 gtk_box_pack_start (GTK_BOX (tooltip->box), tooltip->label,
155 tooltip->custom_widget = NULL;
159 gtk_tooltip_finalize (GObject *object)
161 GtkTooltip *tooltip = GTK_TOOLTIP (object);
163 if (tooltip->timeout_id)
165 g_source_remove (tooltip->timeout_id);
166 tooltip->timeout_id = 0;
169 if (tooltip->browse_mode_timeout_id)
171 g_source_remove (tooltip->browse_mode_timeout_id);
172 tooltip->browse_mode_timeout_id = 0;
179 display = gtk_widget_get_display (tooltip->window);
180 g_signal_handlers_disconnect_by_func (display,
181 gtk_tooltip_display_closed,
183 gtk_widget_destroy (tooltip->window);
186 G_OBJECT_CLASS (gtk_tooltip_parent_class)->finalize (object);
192 * gtk_tooltip_set_markup:
193 * @tooltip: a #GtkTooltip
194 * @markup: a markup string (see <link linkend="PangoMarkupFormat">Pango markup format</link>) or %NULL
196 * Sets the text of the tooltip to be @markup, which is marked up
198 * linkend="PangoMarkupFormat">Pango text markup language</link>.
199 * If @markup is %NULL, the label will be hidden.
204 gtk_tooltip_set_markup (GtkTooltip *tooltip,
207 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
209 gtk_label_set_markup (GTK_LABEL (tooltip->label), markup);
212 gtk_widget_show (tooltip->label);
214 gtk_widget_hide (tooltip->label);
218 * gtk_tooltip_set_text:
219 * @tooltip: a #GtkTooltip
220 * @text: a text string or %NULL
222 * Sets the text of the tooltip to be @text. If @text is %NULL, the label
223 * will be hidden. See also gtk_tooltip_set_markup().
228 gtk_tooltip_set_text (GtkTooltip *tooltip,
231 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
233 gtk_label_set_text (GTK_LABEL (tooltip->label), text);
236 gtk_widget_show (tooltip->label);
238 gtk_widget_hide (tooltip->label);
242 * gtk_tooltip_set_icon:
243 * @tooltip: a #GtkTooltip
244 * @pixbuf: a #GdkPixbuf, or %NULL
246 * Sets the icon of the tooltip (which is in front of the text) to be
247 * @pixbuf. If @pixbuf is %NULL, the image will be hidden.
252 gtk_tooltip_set_icon (GtkTooltip *tooltip,
255 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
257 g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
259 gtk_image_set_from_pixbuf (GTK_IMAGE (tooltip->image), pixbuf);
262 gtk_widget_show (tooltip->image);
264 gtk_widget_hide (tooltip->image);
268 * gtk_tooltip_set_icon_from_stock:
269 * @tooltip: a #GtkTooltip
270 * @stock_id: a stock icon name, or %NULL
271 * @size: a stock icon size
273 * Sets the icon of the tooltip (which is in front of the text) to be
274 * the stock item indicated by @stock_id with the size indicated
275 * by @size. If @stock_id is %NULL, the image will be hidden.
280 gtk_tooltip_set_icon_from_stock (GtkTooltip *tooltip,
281 const gchar *stock_id,
284 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
286 gtk_image_set_from_stock (GTK_IMAGE (tooltip->image), stock_id, size);
289 gtk_widget_show (tooltip->image);
291 gtk_widget_hide (tooltip->image);
295 * gtk_tooltip_set_custom:
296 * @tooltip: a #GtkTooltip
297 * @custom_widget: a #GtkWidget
299 * Replaces the widget packed into the tooltip with @custom_widget.
300 * By default a box with a #GtkImage and #GtkLabel is embedded in
301 * the tooltip, which can be configured using gtk_tooltip_set_markup()
302 * and gtk_tooltip_set_icon().
307 gtk_tooltip_set_custom (GtkTooltip *tooltip,
308 GtkWidget *custom_widget)
310 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
312 g_return_if_fail (GTK_IS_WIDGET (custom_widget));
314 if (tooltip->custom_widget)
316 gtk_container_remove (GTK_CONTAINER (tooltip->box),
317 tooltip->custom_widget);
318 g_object_unref (tooltip->custom_widget);
323 tooltip->custom_widget = g_object_ref (custom_widget);
325 gtk_container_add (GTK_CONTAINER (tooltip->box), custom_widget);
326 gtk_widget_show (custom_widget);
329 tooltip->custom_widget = NULL;
333 * gtk_tooltip_trigger_tooltip_query:
334 * @display: a #GtkDisplay
336 * Triggers a new tooltip query on @display, in order to update the current
337 * visible tooltip, or to show/hide the current tooltip. This function is
338 * useful to call when, for example, the state of the widget changed by a
344 gtk_tooltip_trigger_tooltip_query (GdkDisplay *display)
350 /* Trigger logic as if the mouse moved */
351 window = gdk_display_get_window_at_pointer (display, &x, &y);
355 event.type = GDK_MOTION_NOTIFY;
356 event.motion.window = window;
359 event.motion.is_hint = FALSE;
361 _gtk_tooltip_handle_event (&event);
364 /* private functions */
367 gtk_tooltip_reset (GtkTooltip *tooltip)
369 gtk_tooltip_set_markup (tooltip, NULL);
370 gtk_tooltip_set_icon (tooltip, NULL);
371 gtk_tooltip_set_custom (tooltip, NULL);
375 gtk_tooltip_paint_window (GtkTooltip *tooltip)
377 gtk_paint_flat_box (tooltip->window->style,
378 tooltip->window->window,
385 tooltip->window->allocation.width,
386 tooltip->window->allocation.height);
392 gtk_tooltip_window_hide (GtkWidget *widget,
395 GtkTooltip *tooltip = GTK_TOOLTIP (user_data);
397 if (tooltip->custom_widget)
398 gtk_tooltip_set_custom (tooltip, NULL);
401 /* event handling, etc */
406 GtkWidget *container;
413 child_location_foreach (GtkWidget *child,
417 struct ChildLocation *child_loc = data;
419 if (!child_loc->child &&
420 gtk_widget_translate_coordinates (child_loc->container, child,
421 child_loc->x, child_loc->y,
424 if (x >= 0 && x < child->allocation.width
425 && y >= 0 && y < child->allocation.height)
427 if (GTK_IS_CONTAINER (child))
429 struct ChildLocation tmp = { NULL, NULL, 0, 0 };
433 tmp.container = child;
435 gtk_container_foreach (GTK_CONTAINER (child),
436 child_location_foreach, &tmp);
439 child_loc->child = tmp.child;
441 child_loc->child = child;
444 child_loc->child = child;
450 window_to_alloc (GtkWidget *dest_widget,
456 /* Translate from window relative to allocation relative */
457 if (!GTK_WIDGET_NO_WINDOW (dest_widget) && dest_widget->parent)
460 gdk_window_get_position (dest_widget->window, &wx, &wy);
462 src_x += wx - dest_widget->allocation.x;
463 src_y += wy - dest_widget->allocation.y;
467 src_x -= dest_widget->allocation.x;
468 src_y -= dest_widget->allocation.y;
478 find_widget_under_pointer (GdkWindow *window,
482 GtkWidget *event_widget;
483 struct ChildLocation child_loc = { NULL, NULL, 0, 0 };
485 gdk_window_get_user_data (window, (void **)&event_widget);
493 while (window && window != event_widget->window)
497 gdk_window_get_position (window, &px, &py);
501 window = gdk_window_get_parent (window);
504 if (GTK_WIDGET_NO_WINDOW (event_widget))
506 child_loc.x += event_widget->allocation.x;
507 child_loc.y += event_widget->allocation.y;
510 /* Failing to find widget->window can happen for e.g. a detached handle box;
511 * chaining ::query-tooltip up to its parent probably makes little sense,
512 * and users better implement tooltips on handle_box->child.
513 * so we simply ignore the event for tooltips here.
518 if (GTK_IS_CONTAINER (event_widget))
520 window_to_alloc (event_widget,
521 child_loc.x, child_loc.y,
522 &child_loc.x, &child_loc.y);
524 child_loc.container = event_widget;
525 child_loc.child = NULL;
527 gtk_container_foreach (GTK_CONTAINER (event_widget),
528 child_location_foreach, &child_loc);
531 event_widget = child_loc.child;
532 else if (child_loc.container)
533 event_widget = child_loc.container;
545 find_topmost_widget_coords_from_event (GdkEvent *event,
553 gdk_event_get_coords (event, &dx, &dy);
557 tmp = find_widget_under_pointer (event->any.window, &tx, &ty);
568 tooltip_browse_mode_expired (gpointer data)
572 tooltip = GTK_TOOLTIP (data);
574 tooltip->browse_mode_enabled = FALSE;
575 tooltip->browse_mode_timeout_id = 0;
577 /* destroy tooltip */
578 g_object_set_data (G_OBJECT (gtk_widget_get_display (tooltip->window)),
579 "gdk-display-current-tooltip", NULL);
585 gtk_tooltip_display_closed (GdkDisplay *display,
589 g_object_set (display, "gdk-display-current-tooltip", NULL);
593 gtk_tooltip_run_requery (GtkWidget **widget,
598 gboolean has_tooltip = FALSE;
599 gboolean return_value = FALSE;
601 gtk_tooltip_reset (tooltip);
605 g_object_get (*widget,
606 "has-tooltip", &has_tooltip,
610 g_signal_emit_by_name (*widget,
613 tooltip->keyboard_mode_enabled,
619 GtkWidget *parent = (*widget)->parent;
622 gtk_widget_translate_coordinates (*widget, parent, *x, *y, x, y);
635 gtk_tooltip_show_tooltip (GdkDisplay *display)
641 GtkWidget *tooltip_widget;
642 GtkWidget *pointer_widget;
644 gboolean has_tooltip;
645 gboolean return_value = FALSE;
647 tooltip = g_object_get_data (G_OBJECT (display),
648 "gdk-display-current-tooltip");
650 if (tooltip->keyboard_mode_enabled)
652 pointer_widget = tooltip_widget = tooltip->keyboard_widget;
656 window = tooltip->last_window;
658 if (!GDK_IS_WINDOW (window))
661 gdk_window_get_origin (window, &x, &y);
662 x = tooltip->last_x - x;
663 y = tooltip->last_y - y;
665 pointer_widget = tooltip_widget = find_widget_under_pointer (window,
672 g_object_get (tooltip_widget, "has-tooltip", &has_tooltip, NULL);
674 g_assert (tooltip != NULL);
676 return_value = gtk_tooltip_run_requery (&tooltip_widget, tooltip, &x, &y);
680 if (!tooltip->current_window)
682 if (gtk_widget_get_tooltip_window (tooltip_widget))
683 tooltip->current_window = gtk_widget_get_tooltip_window (tooltip_widget);
685 tooltip->current_window = GTK_WINDOW (GTK_TOOLTIP (tooltip)->window);
688 /* Position the tooltip */
689 /* FIXME: should we swap this when RTL is enabled? */
690 if (tooltip->keyboard_mode_enabled)
692 gdk_window_get_origin (tooltip_widget->window, &x, &y);
693 if (GTK_WIDGET_NO_WINDOW (tooltip_widget))
695 x += tooltip_widget->allocation.x;
696 y += tooltip_widget->allocation.y;
699 /* For keyboard mode we position the tooltip below the widget,
700 * right of the center of the widget.
702 x += tooltip_widget->allocation.width / 2;
703 y += tooltip_widget->allocation.height + 4;
712 /* For mouse mode, we position the tooltip right of the cursor,
713 * a little below the cursor's center.
715 cursor_size = gdk_display_get_default_cursor_size (display);
716 x += cursor_size / 2;
717 y += cursor_size / 2;
720 screen = gtk_widget_get_screen (tooltip_widget);
722 if (screen != gtk_widget_get_screen (tooltip->window))
724 g_signal_handlers_disconnect_by_func (display,
725 gtk_tooltip_display_closed,
728 gtk_window_set_screen (GTK_WINDOW (tooltip->window), screen);
730 g_signal_connect (display, "closed",
731 G_CALLBACK (gtk_tooltip_display_closed), tooltip);
734 tooltip->tooltip_widget = tooltip_widget;
737 if (tooltip->current_window)
740 GdkRectangle monitor;
741 GtkRequisition requisition;
743 gtk_widget_size_request (GTK_WIDGET (tooltip->current_window),
746 monitor_num = gdk_screen_get_monitor_at_point (screen, x, y);
747 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
749 if (x + requisition.width > monitor.x + monitor.width)
750 x -= x - (monitor.x + monitor.width) + requisition.width;
751 else if (x < monitor.x)
754 if (y + requisition.height > monitor.y + monitor.height)
755 y -= y - (monitor.y + monitor.height) + requisition.height;
757 gtk_window_move (GTK_WINDOW (tooltip->current_window), x, y);
758 gtk_widget_show (GTK_WIDGET (tooltip->current_window));
761 /* Now a tooltip is visible again on the display, make sure browse
764 tooltip->browse_mode_enabled = TRUE;
765 if (tooltip->browse_mode_timeout_id)
767 g_source_remove (tooltip->browse_mode_timeout_id);
768 tooltip->browse_mode_timeout_id = 0;
773 gtk_tooltip_hide_tooltip (GtkTooltip *tooltip)
778 if (tooltip->timeout_id)
780 g_source_remove (tooltip->timeout_id);
781 tooltip->timeout_id = 0;
784 if (!GTK_TOOLTIP_VISIBLE (tooltip))
787 tooltip->tooltip_widget = NULL;
789 if (!tooltip->keyboard_mode_enabled)
792 GtkSettings *settings;
794 settings = gtk_widget_get_settings (GTK_WIDGET (tooltip->window));
796 g_object_get (settings,
797 "gtk-tooltip-browse-mode-timeout", &timeout,
800 /* The tooltip is gone, after (by default, should be configurable) 500ms
801 * we want to turn off browse mode
803 if (!tooltip->browse_mode_timeout_id)
804 tooltip->browse_mode_timeout_id =
805 gdk_threads_add_timeout_full (0, timeout,
806 tooltip_browse_mode_expired,
807 g_object_ref (tooltip),
812 if (tooltip->browse_mode_timeout_id)
814 g_source_remove (tooltip->browse_mode_timeout_id);
815 tooltip->browse_mode_timeout_id = 0;
819 if (tooltip->current_window)
821 gtk_widget_hide (GTK_WIDGET (tooltip->current_window));
822 tooltip->current_window = NULL;
827 tooltip_popup_timeout (gpointer data)
832 display = GDK_DISPLAY_OBJECT (data);
834 gtk_tooltip_show_tooltip (display);
836 tooltip = g_object_get_data (G_OBJECT (display),
837 "gdk-display-current-tooltip");
838 tooltip->timeout_id = 0;
844 gtk_tooltip_start_delay (GdkDisplay *display)
848 GtkSettings *settings;
850 tooltip = g_object_get_data (G_OBJECT (display),
851 "gdk-display-current-tooltip");
853 if (tooltip && GTK_TOOLTIP_VISIBLE (tooltip))
856 if (tooltip->timeout_id)
857 g_source_remove (tooltip->timeout_id);
859 settings = gtk_widget_get_settings (GTK_WIDGET (tooltip->window));
861 if (tooltip->browse_mode_enabled)
862 g_object_get (settings, "gtk-tooltip-browse-timeout", &timeout, NULL);
864 g_object_get (settings, "gtk-tooltip-timeout", &timeout, NULL);
866 tooltip->timeout_id = gdk_threads_add_timeout_full (0, timeout,
867 tooltip_popup_timeout,
868 g_object_ref (display),
873 _gtk_tooltip_focus_in (GtkWidget *widget)
876 gboolean return_value = FALSE;
880 /* Get current tooltip for this display */
881 display = gtk_widget_get_display (widget);
882 tooltip = g_object_get_data (G_OBJECT (display),
883 "gdk-display-current-tooltip");
885 /* Check if keyboard mode is enabled at this moment */
886 if (!tooltip || !tooltip->keyboard_mode_enabled)
889 if (tooltip->keyboard_widget)
890 g_object_unref (tooltip->keyboard_widget);
892 tooltip->keyboard_widget = g_object_ref (widget);
894 gdk_window_get_pointer (widget->window, &x, &y, NULL);
896 return_value = gtk_tooltip_run_requery (&widget, tooltip, &x, &y);
899 gtk_tooltip_hide_tooltip (tooltip);
903 if (!tooltip->current_window)
905 if (gtk_widget_get_tooltip_window (widget))
906 tooltip->current_window = gtk_widget_get_tooltip_window (widget);
908 tooltip->current_window = GTK_WINDOW (GTK_TOOLTIP (tooltip)->window);
911 gtk_tooltip_show_tooltip (display);
915 _gtk_tooltip_focus_out (GtkWidget *widget)
920 /* Get current tooltip for this display */
921 display = gtk_widget_get_display (widget);
922 tooltip = g_object_get_data (G_OBJECT (display),
923 "gdk-display-current-tooltip");
925 if (!tooltip || !tooltip->keyboard_mode_enabled)
928 if (tooltip->keyboard_widget)
930 g_object_unref (tooltip->keyboard_widget);
931 tooltip->keyboard_widget = NULL;
934 gtk_tooltip_hide_tooltip (tooltip);
938 _gtk_tooltip_toggle_keyboard_mode (GtkWidget *widget)
943 display = gtk_widget_get_display (widget);
944 tooltip = g_object_get_data (G_OBJECT (display),
945 "gdk-display-current-tooltip");
949 tooltip = g_object_new (GTK_TYPE_TOOLTIP, NULL);
950 g_object_set_data_full (G_OBJECT (display),
951 "gdk-display-current-tooltip",
952 tooltip, g_object_unref);
955 tooltip->keyboard_mode_enabled ^= 1;
957 if (tooltip->keyboard_mode_enabled)
959 tooltip->keyboard_widget = g_object_ref (widget);
960 _gtk_tooltip_focus_in (widget);
964 if (tooltip->keyboard_widget)
966 g_object_unref (tooltip->keyboard_widget);
967 tooltip->keyboard_widget = NULL;
970 gtk_tooltip_hide_tooltip (tooltip);
975 _gtk_tooltip_hide (GtkWidget *widget)
981 display = gtk_widget_get_display (widget);
982 tooltip = g_object_get_data (G_OBJECT (display),
983 "gdk-display-current-tooltip");
985 if (!tooltip || !GTK_TOOLTIP_VISIBLE (tooltip) || !tooltip->tooltip_widget)
988 toplevel = gtk_widget_get_toplevel (widget);
990 if (widget == tooltip->tooltip_widget
991 || toplevel->window == tooltip->toplevel_window)
992 gtk_tooltip_hide_tooltip (tooltip);
996 _gtk_tooltip_handle_event (GdkEvent *event)
999 gboolean return_value = FALSE;
1000 GtkWidget *has_tooltip_widget = NULL;
1001 GdkDisplay *display;
1002 GtkTooltip *current_tooltip;
1004 has_tooltip_widget = find_topmost_widget_coords_from_event (event, &x, &y);
1005 display = gdk_drawable_get_display (event->any.window);
1006 current_tooltip = g_object_get_data (G_OBJECT (display),
1007 "gdk-display-current-tooltip");
1009 if (current_tooltip)
1011 current_tooltip->last_window = event->any.window;
1012 gdk_event_get_root_coords (event,
1013 ¤t_tooltip->last_x,
1014 ¤t_tooltip->last_y);
1017 if (current_tooltip && current_tooltip->keyboard_mode_enabled)
1019 has_tooltip_widget = current_tooltip->keyboard_widget;
1020 if (!has_tooltip_widget)
1023 return_value = gtk_tooltip_run_requery (&has_tooltip_widget,
1028 gtk_tooltip_hide_tooltip (current_tooltip);
1030 gtk_tooltip_start_delay (display);
1035 /* Always poll for a next motion event */
1036 gdk_event_request_motions (&event->motion);
1038 /* Hide the tooltip when there's no new tooltip widget */
1039 if (!has_tooltip_widget)
1041 if (current_tooltip && GTK_TOOLTIP_VISIBLE (current_tooltip))
1042 gtk_tooltip_hide_tooltip (current_tooltip);
1047 switch (event->type)
1049 case GDK_BUTTON_PRESS:
1050 case GDK_2BUTTON_PRESS:
1051 case GDK_3BUTTON_PRESS:
1053 case GDK_DRAG_ENTER:
1054 case GDK_GRAB_BROKEN:
1055 gtk_tooltip_hide_tooltip (current_tooltip);
1058 case GDK_MOTION_NOTIFY:
1059 case GDK_ENTER_NOTIFY:
1060 case GDK_LEAVE_NOTIFY:
1062 if (current_tooltip)
1064 return_value = gtk_tooltip_run_requery (&has_tooltip_widget,
1069 gtk_tooltip_hide_tooltip (current_tooltip);
1071 gtk_tooltip_start_delay (display);
1075 /* Need a new tooltip for this display */
1076 current_tooltip = g_object_new (GTK_TYPE_TOOLTIP, NULL);
1077 g_object_set_data_full (G_OBJECT (display),
1078 "gdk-display-current-tooltip",
1079 current_tooltip, g_object_unref);
1081 current_tooltip->last_window = event->any.window;
1082 gdk_event_get_root_coords (event,
1083 ¤t_tooltip->last_x,
1084 ¤t_tooltip->last_y);
1086 gtk_tooltip_start_delay (display);
1096 #define __GTK_TOOLTIP_C__
1097 #include "gtkaliasdef.c"