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_icon:
219 * @tooltip: a #GtkTooltip
220 * @pixbuf: a #GdkPixbuf, or %NULL
222 * Sets the icon of the tooltip (which is in front of the text) to be
223 * @pixbuf. If @pixbuf is %NULL, the image will be hidden.
228 gtk_tooltip_set_icon (GtkTooltip *tooltip,
231 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
233 g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
235 gtk_image_set_from_pixbuf (GTK_IMAGE (tooltip->image), pixbuf);
238 gtk_widget_show (tooltip->image);
240 gtk_widget_hide (tooltip->image);
244 * gtk_tooltip_set_icon_from_stock:
245 * @tooltip: a #GtkTooltip
246 * @stock_id: a stock icon name, or %NULL
247 * @size: a stock icon size
249 * Sets the icon of the tooltip (which is in front of the text) to be
250 * the stock item indicated by @stock_id with the size indicated
251 * by @size. If @stock_id is %NULL, the image will be hidden.
256 gtk_tooltip_set_icon_from_stock (GtkTooltip *tooltip,
257 const gchar *stock_id,
260 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
262 gtk_image_set_from_stock (GTK_IMAGE (tooltip->image), stock_id, size);
265 gtk_widget_show (tooltip->image);
267 gtk_widget_hide (tooltip->image);
271 * gtk_tooltip_set_custom:
272 * @tooltip: a #GtkTooltip
273 * @custom_widget: a #GtkWidget
275 * Replaces the widget packed into the tooltip with @custom_widget.
276 * By default a box with a #GtkImage and #GtkLabel is embedded in
277 * the tooltip, which can be configured using gtk_tooltip_set_markup()
278 * and gtk_tooltip_set_icon().
283 gtk_tooltip_set_custom (GtkTooltip *tooltip,
284 GtkWidget *custom_widget)
286 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
288 g_return_if_fail (GTK_IS_WIDGET (custom_widget));
290 if (tooltip->custom_widget)
292 gtk_container_remove (GTK_CONTAINER (tooltip->box),
293 tooltip->custom_widget);
294 g_object_unref (tooltip->custom_widget);
299 tooltip->custom_widget = g_object_ref (custom_widget);
301 gtk_container_add (GTK_CONTAINER (tooltip->box), custom_widget);
302 gtk_widget_show (custom_widget);
305 tooltip->custom_widget = NULL;
309 * gtk_tooltip_trigger_tooltip_query:
310 * @display: a #GtkDisplay
312 * Triggers a new tooltip query on @display, in order to update the current
313 * visible tooltip, or to show/hide the current tooltip. This function is
314 * useful to call when, for example, the state of the widget changed by a
320 gtk_tooltip_trigger_tooltip_query (GdkDisplay *display)
326 /* Trigger logic as if the mouse moved */
327 window = gdk_display_get_window_at_pointer (display, &x, &y);
331 event.type = GDK_MOTION_NOTIFY;
332 event.motion.window = window;
335 event.motion.is_hint = FALSE;
337 _gtk_tooltip_handle_event (&event);
340 /* private functions */
343 gtk_tooltip_reset (GtkTooltip *tooltip)
345 gtk_tooltip_set_markup (tooltip, NULL);
346 gtk_tooltip_set_icon (tooltip, NULL);
347 gtk_tooltip_set_custom (tooltip, NULL);
351 gtk_tooltip_paint_window (GtkTooltip *tooltip)
355 gtk_widget_size_request (tooltip->window, &req);
356 gtk_paint_flat_box (tooltip->window->style,
357 tooltip->window->window,
364 tooltip->window->allocation.width,
365 tooltip->window->allocation.height);
371 gtk_tooltip_window_hide (GtkWidget *widget,
374 GtkTooltip *tooltip = GTK_TOOLTIP (user_data);
376 if (tooltip->custom_widget)
377 gtk_tooltip_set_custom (tooltip, NULL);
380 /* event handling, etc */
385 GtkWidget *container;
392 child_location_foreach (GtkWidget *child,
396 struct ChildLocation *child_loc = data;
398 if (!child_loc->child &&
399 gtk_widget_translate_coordinates (child_loc->container, child,
400 child_loc->x, child_loc->y,
403 if (x >= 0 && x < child->allocation.width
404 && y >= 0 && y < child->allocation.height)
406 if (GTK_IS_CONTAINER (child))
408 struct ChildLocation tmp = { NULL, NULL, 0, 0 };
412 tmp.container = child;
414 gtk_container_foreach (GTK_CONTAINER (child),
415 child_location_foreach, &tmp);
418 child_loc->child = tmp.child;
420 child_loc->child = child;
423 child_loc->child = child;
429 window_to_alloc (GtkWidget *dest_widget,
435 /* Translate from window relative to allocation relative */
436 if (!GTK_WIDGET_NO_WINDOW (dest_widget) && dest_widget->parent)
439 gdk_window_get_position (dest_widget->window, &wx, &wy);
441 src_x += wx - dest_widget->allocation.x;
442 src_y += wy - dest_widget->allocation.y;
446 src_x -= dest_widget->allocation.x;
447 src_y -= dest_widget->allocation.y;
457 find_widget_under_pointer (GdkWindow *window,
461 GtkWidget *event_widget;
462 struct ChildLocation child_loc = { NULL, NULL, 0, 0 };
464 gdk_window_get_user_data (window, (void **)&event_widget);
472 while (window && window != event_widget->window)
476 gdk_window_get_position (window, &px, &py);
480 window = gdk_window_get_parent (window);
483 if (GTK_WIDGET_NO_WINDOW (event_widget))
485 child_loc.x += event_widget->allocation.x;
486 child_loc.y += event_widget->allocation.y;
489 /* Failing to find widget->window can happen for e.g. a detached handle box;
490 * chaining ::query-tooltip up to its parent probably makes little sense,
491 * and users better implement tooltips on handle_box->child.
492 * so we simply ignore the event for tooltips here.
497 if (GTK_IS_CONTAINER (event_widget))
499 window_to_alloc (event_widget,
500 child_loc.x, child_loc.y,
501 &child_loc.x, &child_loc.y);
503 child_loc.container = event_widget;
504 child_loc.child = NULL;
506 gtk_container_foreach (GTK_CONTAINER (event_widget),
507 child_location_foreach, &child_loc);
510 event_widget = child_loc.child;
511 else if (child_loc.container)
512 event_widget = child_loc.container;
524 find_topmost_widget_coords_from_event (GdkEvent *event,
532 gdk_event_get_coords (event, &dx, &dy);
536 tmp = find_widget_under_pointer (event->any.window, &tx, &ty);
547 tooltip_browse_mode_expired (gpointer data)
551 tooltip = GTK_TOOLTIP (data);
553 tooltip->browse_mode_enabled = FALSE;
554 tooltip->browse_mode_timeout_id = 0;
556 /* destroy tooltip */
557 g_object_set_data (G_OBJECT (gtk_widget_get_display (tooltip->window)),
558 "gdk-display-current-tooltip", NULL);
564 gtk_tooltip_display_closed (GdkDisplay *display,
568 g_object_set (display, "gdk-display-current-tooltip", NULL);
572 gtk_tooltip_run_requery (GtkWidget **widget,
577 gboolean has_tooltip = FALSE;
578 gboolean return_value = FALSE;
580 gtk_tooltip_reset (tooltip);
584 g_object_get (*widget,
585 "has-tooltip", &has_tooltip,
589 g_signal_emit_by_name (*widget,
592 tooltip->keyboard_mode_enabled,
598 GtkWidget *parent = (*widget)->parent;
601 gtk_widget_translate_coordinates (*widget, parent, *x, *y, x, y);
614 gtk_tooltip_show_tooltip (GdkDisplay *display)
620 GtkWidget *tooltip_widget;
621 GtkWidget *pointer_widget;
623 gboolean has_tooltip;
624 gboolean return_value = FALSE;
626 tooltip = g_object_get_data (G_OBJECT (display),
627 "gdk-display-current-tooltip");
629 if (tooltip->keyboard_mode_enabled)
631 pointer_widget = tooltip_widget = tooltip->keyboard_widget;
635 window = tooltip->last_window;
637 if (!GDK_IS_WINDOW (window))
640 gdk_window_get_origin (window, &x, &y);
641 x = tooltip->last_x - x;
642 y = tooltip->last_y - y;
644 pointer_widget = tooltip_widget = find_widget_under_pointer (window,
651 g_object_get (tooltip_widget, "has-tooltip", &has_tooltip, NULL);
653 g_assert (tooltip != NULL);
655 return_value = gtk_tooltip_run_requery (&tooltip_widget, tooltip, &x, &y);
659 if (!tooltip->current_window)
661 if (gtk_widget_get_tooltip_window (tooltip_widget))
662 tooltip->current_window = gtk_widget_get_tooltip_window (tooltip_widget);
664 tooltip->current_window = GTK_WINDOW (GTK_TOOLTIP (tooltip)->window);
667 /* Position the tooltip */
668 /* FIXME: should we swap this when RTL is enabled? */
669 if (tooltip->keyboard_mode_enabled)
671 gdk_window_get_origin (tooltip_widget->window, &x, &y);
672 if (GTK_WIDGET_NO_WINDOW (tooltip_widget))
674 x += tooltip_widget->allocation.x;
675 y += tooltip_widget->allocation.y;
678 /* For keyboard mode we position the tooltip below the widget,
679 * right of the center of the widget.
681 x += tooltip_widget->allocation.width / 2;
682 y += tooltip_widget->allocation.height + 4;
691 /* For mouse mode, we position the tooltip right of the cursor,
692 * a little below the cursor's center.
694 cursor_size = gdk_display_get_default_cursor_size (display);
695 x += cursor_size / 2;
696 y += cursor_size / 2;
699 screen = gtk_widget_get_screen (tooltip_widget);
701 if (screen != gtk_widget_get_screen (tooltip->window))
703 g_signal_handlers_disconnect_by_func (display,
704 gtk_tooltip_display_closed,
707 gtk_window_set_screen (GTK_WINDOW (tooltip->window), screen);
709 g_signal_connect (display, "closed",
710 G_CALLBACK (gtk_tooltip_display_closed), tooltip);
713 tooltip->tooltip_widget = tooltip_widget;
716 if (tooltip->current_window)
719 GdkRectangle monitor;
720 GtkRequisition requisition;
722 gtk_widget_size_request (GTK_WIDGET (tooltip->current_window),
725 monitor_num = gdk_screen_get_monitor_at_point (screen, x, y);
726 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
728 if (x + requisition.width > monitor.x + monitor.width)
729 x -= x - (monitor.x + monitor.width) + requisition.width;
730 else if (x < monitor.x)
733 if (y + requisition.height > monitor.y + monitor.height)
734 y -= y - (monitor.y + monitor.height) + requisition.height;
736 gtk_window_move (GTK_WINDOW (tooltip->current_window), x, y);
737 gtk_widget_show (GTK_WIDGET (tooltip->current_window));
740 /* Now a tooltip is visible again on the display, make sure browse
743 tooltip->browse_mode_enabled = TRUE;
744 if (tooltip->browse_mode_timeout_id)
746 g_source_remove (tooltip->browse_mode_timeout_id);
747 tooltip->browse_mode_timeout_id = 0;
752 gtk_tooltip_hide_tooltip (GtkTooltip *tooltip)
757 if (tooltip->timeout_id)
759 g_source_remove (tooltip->timeout_id);
760 tooltip->timeout_id = 0;
763 if (!GTK_TOOLTIP_VISIBLE (tooltip))
766 tooltip->tooltip_widget = NULL;
768 if (!tooltip->keyboard_mode_enabled)
771 GtkSettings *settings;
773 settings = gtk_widget_get_settings (GTK_WIDGET (tooltip->window));
775 g_object_get (settings,
776 "gtk-tooltip-browse-mode-timeout", &timeout,
779 /* The tooltip is gone, after (by default, should be configurable) 500ms
780 * we want to turn off browse mode
782 if (!tooltip->browse_mode_timeout_id)
783 tooltip->browse_mode_timeout_id =
784 gdk_threads_add_timeout_full (0, timeout,
785 tooltip_browse_mode_expired,
786 g_object_ref (tooltip),
791 if (tooltip->browse_mode_timeout_id)
793 g_source_remove (tooltip->browse_mode_timeout_id);
794 tooltip->browse_mode_timeout_id = 0;
798 if (tooltip->current_window)
800 gtk_widget_hide (GTK_WIDGET (tooltip->current_window));
801 tooltip->current_window = NULL;
806 tooltip_popup_timeout (gpointer data)
811 display = GDK_DISPLAY_OBJECT (data);
813 gtk_tooltip_show_tooltip (display);
815 tooltip = g_object_get_data (G_OBJECT (display),
816 "gdk-display-current-tooltip");
817 tooltip->timeout_id = 0;
823 gtk_tooltip_start_delay (GdkDisplay *display)
827 GtkSettings *settings;
829 tooltip = g_object_get_data (G_OBJECT (display),
830 "gdk-display-current-tooltip");
832 if (tooltip && GTK_TOOLTIP_VISIBLE (tooltip))
835 if (tooltip->timeout_id)
836 g_source_remove (tooltip->timeout_id);
838 settings = gtk_widget_get_settings (GTK_WIDGET (tooltip->window));
840 if (tooltip->browse_mode_enabled)
841 g_object_get (settings, "gtk-tooltip-browse-timeout", &timeout, NULL);
843 g_object_get (settings, "gtk-tooltip-timeout", &timeout, NULL);
845 tooltip->timeout_id = gdk_threads_add_timeout_full (0, timeout,
846 tooltip_popup_timeout,
847 g_object_ref (display),
852 _gtk_tooltip_focus_in (GtkWidget *widget)
855 gboolean return_value = FALSE;
859 /* Get current tooltip for this display */
860 display = gtk_widget_get_display (widget);
861 tooltip = g_object_get_data (G_OBJECT (display),
862 "gdk-display-current-tooltip");
864 /* Check if keyboard mode is enabled at this moment */
865 if (!tooltip || !tooltip->keyboard_mode_enabled)
868 if (tooltip->keyboard_widget)
869 g_object_unref (tooltip->keyboard_widget);
871 tooltip->keyboard_widget = g_object_ref (widget);
873 gdk_window_get_pointer (widget->window, &x, &y, NULL);
875 return_value = gtk_tooltip_run_requery (&widget, tooltip, &x, &y);
878 gtk_tooltip_hide_tooltip (tooltip);
882 if (!tooltip->current_window)
884 if (gtk_widget_get_tooltip_window (widget))
885 tooltip->current_window = gtk_widget_get_tooltip_window (widget);
887 tooltip->current_window = GTK_WINDOW (GTK_TOOLTIP (tooltip)->window);
890 gtk_tooltip_show_tooltip (display);
894 _gtk_tooltip_focus_out (GtkWidget *widget)
899 /* Get current tooltip for this display */
900 display = gtk_widget_get_display (widget);
901 tooltip = g_object_get_data (G_OBJECT (display),
902 "gdk-display-current-tooltip");
904 if (!tooltip || !tooltip->keyboard_mode_enabled)
907 if (tooltip->keyboard_widget)
909 g_object_unref (tooltip->keyboard_widget);
910 tooltip->keyboard_widget = NULL;
913 gtk_tooltip_hide_tooltip (tooltip);
917 _gtk_tooltip_toggle_keyboard_mode (GtkWidget *widget)
922 display = gtk_widget_get_display (widget);
923 tooltip = g_object_get_data (G_OBJECT (display),
924 "gdk-display-current-tooltip");
928 tooltip = g_object_new (GTK_TYPE_TOOLTIP, NULL);
929 g_object_set_data_full (G_OBJECT (display),
930 "gdk-display-current-tooltip",
931 tooltip, g_object_unref);
934 tooltip->keyboard_mode_enabled ^= 1;
936 if (tooltip->keyboard_mode_enabled)
938 tooltip->keyboard_widget = g_object_ref (widget);
939 _gtk_tooltip_focus_in (widget);
943 if (tooltip->keyboard_widget)
945 g_object_unref (tooltip->keyboard_widget);
946 tooltip->keyboard_widget = NULL;
949 gtk_tooltip_hide_tooltip (tooltip);
954 _gtk_tooltip_hide (GtkWidget *widget)
960 display = gtk_widget_get_display (widget);
961 tooltip = g_object_get_data (G_OBJECT (display),
962 "gdk-display-current-tooltip");
964 if (!tooltip || !GTK_TOOLTIP_VISIBLE (tooltip) || !tooltip->tooltip_widget)
967 toplevel = gtk_widget_get_toplevel (widget);
969 if (widget == tooltip->tooltip_widget
970 || toplevel->window == tooltip->toplevel_window)
971 gtk_tooltip_hide_tooltip (tooltip);
975 _gtk_tooltip_handle_event (GdkEvent *event)
978 gboolean return_value = FALSE;
979 GtkWidget *has_tooltip_widget = NULL;
981 GtkTooltip *current_tooltip;
983 has_tooltip_widget = find_topmost_widget_coords_from_event (event, &x, &y);
984 display = gdk_drawable_get_display (event->any.window);
985 current_tooltip = g_object_get_data (G_OBJECT (display),
986 "gdk-display-current-tooltip");
990 current_tooltip->last_window = event->any.window;
991 gdk_event_get_root_coords (event,
992 ¤t_tooltip->last_x,
993 ¤t_tooltip->last_y);
996 if (current_tooltip && current_tooltip->keyboard_mode_enabled)
998 has_tooltip_widget = current_tooltip->keyboard_widget;
999 if (!has_tooltip_widget)
1002 return_value = gtk_tooltip_run_requery (&has_tooltip_widget,
1007 gtk_tooltip_hide_tooltip (current_tooltip);
1009 gtk_tooltip_start_delay (display);
1014 /* Always poll for a next motion event */
1015 gdk_event_request_motions (&event->motion);
1017 /* Hide the tooltip when there's no new tooltip widget */
1018 if (!has_tooltip_widget)
1020 if (current_tooltip && GTK_TOOLTIP_VISIBLE (current_tooltip))
1021 gtk_tooltip_hide_tooltip (current_tooltip);
1026 switch (event->type)
1028 case GDK_BUTTON_PRESS:
1029 case GDK_2BUTTON_PRESS:
1030 case GDK_3BUTTON_PRESS:
1032 case GDK_DRAG_ENTER:
1033 case GDK_GRAB_BROKEN:
1034 gtk_tooltip_hide_tooltip (current_tooltip);
1037 case GDK_MOTION_NOTIFY:
1038 case GDK_ENTER_NOTIFY:
1039 case GDK_LEAVE_NOTIFY:
1041 if (current_tooltip)
1043 return_value = gtk_tooltip_run_requery (&has_tooltip_widget,
1048 gtk_tooltip_hide_tooltip (current_tooltip);
1050 gtk_tooltip_start_delay (display);
1054 /* Need a new tooltip for this display */
1055 current_tooltip = g_object_new (GTK_TYPE_TOOLTIP, NULL);
1056 g_object_set_data_full (G_OBJECT (display),
1057 "gdk-display-current-tooltip",
1058 current_tooltip, g_object_unref);
1060 current_tooltip->last_window = event->any.window;
1061 gdk_event_get_root_coords (event,
1062 ¤t_tooltip->last_x,
1063 ¤t_tooltip->last_y);
1065 gtk_tooltip_start_delay (display);
1075 #define __GTK_TOOLTIP_C__
1076 #include "gtkaliasdef.c"