2007-02-06 10:25:21 +00:00
|
|
|
|
/* gtktooltip.c
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2006-2007 Imendio AB
|
|
|
|
|
* Contact: Kristian Rietveld <kris@imendio.com>
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Library General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2007-02-06 10:25:21 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2008-06-22 14:28:52 +00:00
|
|
|
|
#include "config.h"
|
2010-04-15 11:03:43 +00:00
|
|
|
|
|
2010-09-14 01:33:06 +00:00
|
|
|
|
#include "gtktooltip.h"
|
|
|
|
|
|
2010-04-15 11:03:43 +00:00
|
|
|
|
#include <math.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
2007-02-06 10:25:21 +00:00
|
|
|
|
#include "gtkintl.h"
|
|
|
|
|
#include "gtkwindow.h"
|
|
|
|
|
#include "gtkmain.h"
|
|
|
|
|
#include "gtklabel.h"
|
|
|
|
|
#include "gtkimage.h"
|
2011-08-28 05:54:55 +00:00
|
|
|
|
#include "gtkbox.h"
|
2012-03-03 18:22:22 +00:00
|
|
|
|
#include "gtksettings.h"
|
2010-09-14 01:33:06 +00:00
|
|
|
|
#include "gtksizerequest.h"
|
2012-03-03 18:22:22 +00:00
|
|
|
|
#include "gtkstylecontext.h"
|
2011-04-26 22:25:48 +00:00
|
|
|
|
#include "gtkwindowprivate.h"
|
2007-02-06 10:25:21 +00:00
|
|
|
|
|
2007-05-23 17:49:34 +00:00
|
|
|
|
|
2013-02-07 11:27:00 +00:00
|
|
|
|
#ifdef GDK_WINDOWING_WAYLAND
|
|
|
|
|
#include "wayland/gdkwayland.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
2010-10-02 22:58:38 +00:00
|
|
|
|
/**
|
|
|
|
|
* SECTION:gtktooltip
|
|
|
|
|
* @Short_description: Add tips to your widgets
|
|
|
|
|
* @Title: GtkTooltip
|
|
|
|
|
*
|
|
|
|
|
* Basic tooltips can be realized simply by using gtk_widget_set_tooltip_text()
|
|
|
|
|
* or gtk_widget_set_tooltip_markup() without any explicit tooltip object.
|
|
|
|
|
*
|
|
|
|
|
* When you need a tooltip with a little more fancy contents, like adding an
|
|
|
|
|
* image, or you want the tooltip to have different contents per #GtkTreeView
|
|
|
|
|
* row or cell, you will have to do a little more work:
|
2014-02-02 06:07:39 +00:00
|
|
|
|
*
|
|
|
|
|
* - Set the #GtkWidget:has-tooltip property to %TRUE, this will make GTK+
|
|
|
|
|
* monitor the widget for motion and related events which are needed to
|
|
|
|
|
* determine when and where to show a tooltip.
|
|
|
|
|
*
|
|
|
|
|
* - Connect to the #GtkWidget::query-tooltip signal. This signal will be
|
|
|
|
|
* emitted when a tooltip is supposed to be shown. One of the arguments passed
|
|
|
|
|
* to the signal handler is a GtkTooltip object. This is the object that we
|
|
|
|
|
* are about to display as a tooltip, and can be manipulated in your callback
|
|
|
|
|
* using functions like gtk_tooltip_set_icon(). There are functions for setting
|
2014-02-07 18:01:26 +00:00
|
|
|
|
* the tooltip’s markup, setting an image from a named icon, or even putting in
|
2014-02-02 06:07:39 +00:00
|
|
|
|
* a custom widget.
|
|
|
|
|
*
|
|
|
|
|
* Return %TRUE from your query-tooltip handler. This causes the tooltip to be
|
|
|
|
|
* show. If you return %FALSE, it will not be shown.
|
2010-10-02 22:58:38 +00:00
|
|
|
|
*
|
|
|
|
|
* In the probably rare case where you want to have even more control over the
|
|
|
|
|
* tooltip that is about to be shown, you can set your own #GtkWindow which
|
|
|
|
|
* will be used as tooltip window. This works as follows:
|
2014-02-02 06:07:39 +00:00
|
|
|
|
*
|
|
|
|
|
* - Set #GtkWidget:has-tooltip and connect to #GtkWidget::query-tooltip as before.
|
|
|
|
|
* Use gtk_widget_set_tooltip_window() to set a #GtkWindow created by you as
|
|
|
|
|
* tooltip window.
|
|
|
|
|
*
|
|
|
|
|
* - In the #GtkWidget::query-tooltip callback you can access your window using
|
|
|
|
|
* gtk_widget_get_tooltip_window() and manipulate as you wish. The semantics of
|
|
|
|
|
* the return value are exactly as before, return %TRUE to show the window,
|
|
|
|
|
* %FALSE to not show it.
|
2010-10-02 22:58:38 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
2007-08-21 10:52:43 +00:00
|
|
|
|
#undef DEBUG_TOOLTIP
|
|
|
|
|
|
2013-07-08 17:13:23 +00:00
|
|
|
|
#define HOVER_TIMEOUT 500
|
|
|
|
|
#define BROWSE_TIMEOUT 60
|
|
|
|
|
#define BROWSE_DISABLE_TIMEOUT 500
|
2007-02-06 10:25:21 +00:00
|
|
|
|
|
|
|
|
|
#define GTK_TOOLTIP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_TOOLTIP, GtkTooltipClass))
|
|
|
|
|
#define GTK_IS_TOOLTIP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_TOOLTIP))
|
|
|
|
|
#define GTK_TOOLTIP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_TOOLTIP, GtkTooltipClass))
|
|
|
|
|
|
|
|
|
|
typedef struct _GtkTooltipClass GtkTooltipClass;
|
|
|
|
|
|
|
|
|
|
struct _GtkTooltip
|
|
|
|
|
{
|
|
|
|
|
GObject parent_instance;
|
|
|
|
|
|
|
|
|
|
GtkWidget *window;
|
|
|
|
|
GtkWidget *box;
|
|
|
|
|
GtkWidget *image;
|
|
|
|
|
GtkWidget *label;
|
|
|
|
|
GtkWidget *custom_widget;
|
|
|
|
|
|
|
|
|
|
GtkWindow *current_window;
|
|
|
|
|
GtkWidget *keyboard_widget;
|
|
|
|
|
|
|
|
|
|
GtkWidget *tooltip_widget;
|
|
|
|
|
GdkWindow *toplevel_window;
|
|
|
|
|
|
|
|
|
|
gdouble last_x;
|
|
|
|
|
gdouble last_y;
|
|
|
|
|
GdkWindow *last_window;
|
|
|
|
|
|
|
|
|
|
guint timeout_id;
|
|
|
|
|
guint browse_mode_timeout_id;
|
|
|
|
|
|
2007-07-13 14:25:21 +00:00
|
|
|
|
GdkRectangle tip_area;
|
|
|
|
|
|
2007-02-06 10:25:21 +00:00
|
|
|
|
guint browse_mode_enabled : 1;
|
|
|
|
|
guint keyboard_mode_enabled : 1;
|
2007-07-13 14:25:21 +00:00
|
|
|
|
guint tip_area_set : 1;
|
2008-05-28 14:00:31 +00:00
|
|
|
|
guint custom_was_reset : 1;
|
2007-02-06 10:25:21 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct _GtkTooltipClass
|
|
|
|
|
{
|
|
|
|
|
GObjectClass parent_class;
|
|
|
|
|
};
|
|
|
|
|
|
2010-03-01 06:47:38 +00:00
|
|
|
|
#define GTK_TOOLTIP_VISIBLE(tooltip) ((tooltip)->current_window && gtk_widget_get_visible (GTK_WIDGET((tooltip)->current_window)))
|
2007-02-06 10:25:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void gtk_tooltip_class_init (GtkTooltipClass *klass);
|
|
|
|
|
static void gtk_tooltip_init (GtkTooltip *tooltip);
|
2009-08-03 19:39:34 +00:00
|
|
|
|
static void gtk_tooltip_dispose (GObject *object);
|
2007-02-06 10:25:21 +00:00
|
|
|
|
|
2010-09-08 15:09:12 +00:00
|
|
|
|
static gboolean gtk_tooltip_paint_window (GtkTooltip *tooltip,
|
|
|
|
|
cairo_t *cr);
|
2011-10-06 21:06:57 +00:00
|
|
|
|
static void gtk_tooltip_realize_window (GtkTooltip *tooltip,
|
|
|
|
|
GtkWidget *widget);
|
2011-10-22 16:38:29 +00:00
|
|
|
|
static void gtk_tooltip_composited_changed (GtkTooltip *tooltip,
|
|
|
|
|
GtkWidget *widget);
|
2007-02-06 10:25:21 +00:00
|
|
|
|
static void gtk_tooltip_window_hide (GtkWidget *widget,
|
|
|
|
|
gpointer user_data);
|
|
|
|
|
static void gtk_tooltip_display_closed (GdkDisplay *display,
|
|
|
|
|
gboolean was_error,
|
|
|
|
|
GtkTooltip *tooltip);
|
2007-12-17 15:33:45 +00:00
|
|
|
|
static void gtk_tooltip_set_last_window (GtkTooltip *tooltip,
|
|
|
|
|
GdkWindow *window);
|
2007-02-06 10:25:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (GtkTooltip, gtk_tooltip, G_TYPE_OBJECT);
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_tooltip_class_init (GtkTooltipClass *klass)
|
|
|
|
|
{
|
|
|
|
|
GObjectClass *object_class;
|
|
|
|
|
|
|
|
|
|
object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
2009-08-03 19:39:34 +00:00
|
|
|
|
object_class->dispose = gtk_tooltip_dispose;
|
2007-02-06 10:25:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_tooltip_init (GtkTooltip *tooltip)
|
|
|
|
|
{
|
2011-01-04 01:18:51 +00:00
|
|
|
|
GtkStyleContext *context;
|
2011-06-08 02:31:34 +00:00
|
|
|
|
GtkWidget *window;
|
|
|
|
|
GtkWidget *box;
|
|
|
|
|
GtkWidget *image;
|
|
|
|
|
GtkWidget *label;
|
2011-10-06 21:06:57 +00:00
|
|
|
|
GdkScreen *screen;
|
|
|
|
|
GdkVisual *visual;
|
2010-08-11 20:51:01 +00:00
|
|
|
|
|
2007-02-06 10:25:21 +00:00
|
|
|
|
tooltip->timeout_id = 0;
|
|
|
|
|
tooltip->browse_mode_timeout_id = 0;
|
|
|
|
|
|
|
|
|
|
tooltip->browse_mode_enabled = FALSE;
|
|
|
|
|
tooltip->keyboard_mode_enabled = FALSE;
|
|
|
|
|
|
|
|
|
|
tooltip->current_window = NULL;
|
|
|
|
|
tooltip->keyboard_widget = NULL;
|
|
|
|
|
|
|
|
|
|
tooltip->tooltip_widget = NULL;
|
|
|
|
|
tooltip->toplevel_window = NULL;
|
|
|
|
|
|
|
|
|
|
tooltip->last_window = NULL;
|
|
|
|
|
|
2012-09-12 20:43:32 +00:00
|
|
|
|
window = gtk_window_new (GTK_WINDOW_POPUP);
|
2011-10-06 21:06:57 +00:00
|
|
|
|
screen = gtk_widget_get_screen (window);
|
|
|
|
|
visual = gdk_screen_get_rgba_visual (screen);
|
|
|
|
|
|
|
|
|
|
if (visual != NULL)
|
|
|
|
|
gtk_widget_set_visual (window, visual);
|
|
|
|
|
|
2011-06-08 02:31:34 +00:00
|
|
|
|
gtk_window_set_type_hint (GTK_WINDOW (window), GDK_WINDOW_TYPE_HINT_TOOLTIP);
|
|
|
|
|
gtk_widget_set_app_paintable (window, TRUE);
|
|
|
|
|
gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
|
|
|
|
|
gtk_widget_set_name (window, "gtk-tooltip");
|
|
|
|
|
g_signal_connect (window, "hide",
|
|
|
|
|
G_CALLBACK (gtk_tooltip_window_hide), tooltip);
|
2007-02-06 10:25:21 +00:00
|
|
|
|
|
2011-06-08 02:31:34 +00:00
|
|
|
|
context = gtk_widget_get_style_context (window);
|
2011-01-04 01:18:51 +00:00
|
|
|
|
gtk_style_context_add_class (context, GTK_STYLE_CLASS_TOOLTIP);
|
|
|
|
|
|
2011-06-08 02:31:34 +00:00
|
|
|
|
g_signal_connect_swapped (window, "draw",
|
|
|
|
|
G_CALLBACK (gtk_tooltip_paint_window), tooltip);
|
2011-10-06 21:06:57 +00:00
|
|
|
|
g_signal_connect_swapped (window, "realize",
|
|
|
|
|
G_CALLBACK (gtk_tooltip_realize_window), tooltip);
|
|
|
|
|
g_signal_connect_swapped (window, "composited-changed",
|
2011-10-22 16:38:29 +00:00
|
|
|
|
G_CALLBACK (gtk_tooltip_composited_changed), tooltip);
|
2011-06-08 02:31:34 +00:00
|
|
|
|
|
|
|
|
|
/* FIXME: don't hardcode the padding */
|
|
|
|
|
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
|
2013-11-14 22:31:17 +00:00
|
|
|
|
gtk_widget_set_margin_start (box, 6);
|
|
|
|
|
gtk_widget_set_margin_end (box, 6);
|
2011-06-08 02:31:34 +00:00
|
|
|
|
gtk_widget_set_margin_top (box, 6);
|
|
|
|
|
gtk_widget_set_margin_bottom (box, 6);
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (window), box);
|
|
|
|
|
gtk_widget_show (box);
|
|
|
|
|
|
|
|
|
|
image = gtk_image_new ();
|
|
|
|
|
gtk_box_pack_start (GTK_BOX (box), image, FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
|
|
label = gtk_label_new ("");
|
|
|
|
|
gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
|
|
|
|
|
gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
|
|
tooltip->window = window;
|
|
|
|
|
tooltip->box = box;
|
|
|
|
|
tooltip->image = image;
|
|
|
|
|
tooltip->label = label;
|
2007-02-06 10:25:21 +00:00
|
|
|
|
tooltip->custom_widget = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2009-08-03 19:39:34 +00:00
|
|
|
|
gtk_tooltip_dispose (GObject *object)
|
2007-02-06 10:25:21 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTooltip *tooltip = GTK_TOOLTIP (object);
|
|
|
|
|
|
|
|
|
|
if (tooltip->timeout_id)
|
|
|
|
|
{
|
|
|
|
|
g_source_remove (tooltip->timeout_id);
|
|
|
|
|
tooltip->timeout_id = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (tooltip->browse_mode_timeout_id)
|
|
|
|
|
{
|
|
|
|
|
g_source_remove (tooltip->browse_mode_timeout_id);
|
|
|
|
|
tooltip->browse_mode_timeout_id = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2009-05-25 02:01:04 +00:00
|
|
|
|
gtk_tooltip_set_custom (tooltip, NULL);
|
2007-12-17 15:33:45 +00:00
|
|
|
|
gtk_tooltip_set_last_window (tooltip, NULL);
|
|
|
|
|
|
2007-02-06 10:25:21 +00:00
|
|
|
|
if (tooltip->window)
|
|
|
|
|
{
|
|
|
|
|
GdkDisplay *display;
|
|
|
|
|
|
|
|
|
|
display = gtk_widget_get_display (tooltip->window);
|
|
|
|
|
g_signal_handlers_disconnect_by_func (display,
|
|
|
|
|
gtk_tooltip_display_closed,
|
|
|
|
|
tooltip);
|
|
|
|
|
gtk_widget_destroy (tooltip->window);
|
2009-08-03 19:39:34 +00:00
|
|
|
|
tooltip->window = NULL;
|
2007-02-06 10:25:21 +00:00
|
|
|
|
}
|
2007-02-06 12:11:33 +00:00
|
|
|
|
|
2009-08-03 19:39:34 +00:00
|
|
|
|
G_OBJECT_CLASS (gtk_tooltip_parent_class)->dispose (object);
|
2007-02-06 10:25:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* public API */
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_tooltip_set_markup:
|
2007-05-26 20:29:26 +00:00
|
|
|
|
* @tooltip: a #GtkTooltip
|
2014-02-07 02:07:03 +00:00
|
|
|
|
* @markup: (allow-none): a markup string (see [Pango markup format][PangoMarkupFormat]) or %NULL
|
2007-02-06 10:25:21 +00:00
|
|
|
|
*
|
2007-05-26 20:29:26 +00:00
|
|
|
|
* Sets the text of the tooltip to be @markup, which is marked up
|
2014-02-07 02:07:03 +00:00
|
|
|
|
* with the [Pango text markup language][PangoMarkupFormat].
|
2007-02-06 10:25:21 +00:00
|
|
|
|
* If @markup is %NULL, the label will be hidden.
|
|
|
|
|
*
|
|
|
|
|
* Since: 2.12
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_tooltip_set_markup (GtkTooltip *tooltip,
|
|
|
|
|
const gchar *markup)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
|
|
|
|
|
|
|
|
|
|
if (markup)
|
2014-02-20 23:31:10 +00:00
|
|
|
|
{
|
|
|
|
|
gtk_label_set_markup (GTK_LABEL (tooltip->label), markup);
|
|
|
|
|
gtk_widget_show (tooltip->label);
|
|
|
|
|
}
|
2007-02-06 10:25:21 +00:00
|
|
|
|
else
|
2014-02-20 23:31:10 +00:00
|
|
|
|
{
|
|
|
|
|
gtk_widget_hide (tooltip->label);
|
|
|
|
|
}
|
2007-02-06 10:25:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-06-15 18:24:55 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_tooltip_set_text:
|
|
|
|
|
* @tooltip: a #GtkTooltip
|
2010-02-19 16:53:17 +00:00
|
|
|
|
* @text: (allow-none): a text string or %NULL
|
2007-06-15 18:24:55 +00:00
|
|
|
|
*
|
|
|
|
|
* Sets the text of the tooltip to be @text. If @text is %NULL, the label
|
|
|
|
|
* will be hidden. See also gtk_tooltip_set_markup().
|
|
|
|
|
*
|
|
|
|
|
* Since: 2.12
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_tooltip_set_text (GtkTooltip *tooltip,
|
|
|
|
|
const gchar *text)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
|
|
|
|
|
|
|
|
|
|
if (text)
|
2014-02-20 23:31:10 +00:00
|
|
|
|
{
|
|
|
|
|
gtk_label_set_text (GTK_LABEL (tooltip->label), text);
|
|
|
|
|
gtk_widget_show (tooltip->label);
|
|
|
|
|
}
|
2007-06-15 18:24:55 +00:00
|
|
|
|
else
|
2014-02-20 23:31:10 +00:00
|
|
|
|
{
|
|
|
|
|
gtk_widget_hide (tooltip->label);
|
|
|
|
|
}
|
2007-06-15 18:24:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-02-06 10:25:21 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_tooltip_set_icon:
|
|
|
|
|
* @tooltip: a #GtkTooltip
|
2010-02-19 16:53:17 +00:00
|
|
|
|
* @pixbuf: (allow-none): a #GdkPixbuf, or %NULL
|
2007-02-06 10:25:21 +00:00
|
|
|
|
*
|
|
|
|
|
* Sets the icon of the tooltip (which is in front of the text) to be
|
|
|
|
|
* @pixbuf. If @pixbuf is %NULL, the image will be hidden.
|
|
|
|
|
*
|
|
|
|
|
* Since: 2.12
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_tooltip_set_icon (GtkTooltip *tooltip,
|
|
|
|
|
GdkPixbuf *pixbuf)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
|
|
|
|
|
if (pixbuf)
|
|
|
|
|
g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
|
|
|
|
|
|
|
|
|
|
if (pixbuf)
|
2014-02-20 23:31:10 +00:00
|
|
|
|
{
|
|
|
|
|
gtk_image_set_from_pixbuf (GTK_IMAGE (tooltip->image), pixbuf);
|
|
|
|
|
gtk_widget_show (tooltip->image);
|
|
|
|
|
}
|
2007-02-06 10:25:21 +00:00
|
|
|
|
else
|
2014-02-20 23:31:10 +00:00
|
|
|
|
{
|
|
|
|
|
gtk_widget_hide (tooltip->image);
|
|
|
|
|
}
|
2007-02-06 10:25:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_tooltip_set_icon_from_stock:
|
|
|
|
|
* @tooltip: a #GtkTooltip
|
2010-02-19 16:53:17 +00:00
|
|
|
|
* @stock_id: (allow-none): a stock id, or %NULL
|
2009-12-18 10:58:36 +00:00
|
|
|
|
* @size: (type int): a stock icon size
|
2007-02-06 10:25:21 +00:00
|
|
|
|
*
|
|
|
|
|
* Sets the icon of the tooltip (which is in front of the text) to be
|
|
|
|
|
* the stock item indicated by @stock_id with the size indicated
|
|
|
|
|
* by @size. If @stock_id is %NULL, the image will be hidden.
|
|
|
|
|
*
|
|
|
|
|
* Since: 2.12
|
2013-06-25 03:47:52 +00:00
|
|
|
|
*
|
|
|
|
|
* Deprecated: 3.10: Use gtk_tooltip_set_icon_from_icon_name() instead.
|
2007-02-06 10:25:21 +00:00
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_tooltip_set_icon_from_stock (GtkTooltip *tooltip,
|
|
|
|
|
const gchar *stock_id,
|
|
|
|
|
GtkIconSize size)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
|
|
|
|
|
|
|
|
|
|
if (stock_id)
|
2014-02-20 23:31:10 +00:00
|
|
|
|
{
|
|
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
|
|
|
|
|
gtk_image_set_from_stock (GTK_IMAGE (tooltip->image), stock_id, size);
|
|
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS;
|
|
|
|
|
gtk_widget_show (tooltip->image);
|
|
|
|
|
}
|
2007-02-06 10:25:21 +00:00
|
|
|
|
else
|
2014-02-20 23:31:10 +00:00
|
|
|
|
{
|
|
|
|
|
gtk_widget_hide (tooltip->image);
|
|
|
|
|
}
|
2007-02-06 10:25:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-12-14 05:00:51 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_tooltip_set_icon_from_icon_name:
|
|
|
|
|
* @tooltip: a #GtkTooltip
|
2010-02-19 16:53:17 +00:00
|
|
|
|
* @icon_name: (allow-none): an icon name, or %NULL
|
2009-12-18 10:58:36 +00:00
|
|
|
|
* @size: (type int): a stock icon size
|
2007-12-14 05:00:51 +00:00
|
|
|
|
*
|
|
|
|
|
* Sets the icon of the tooltip (which is in front of the text) to be
|
|
|
|
|
* the icon indicated by @icon_name with the size indicated
|
|
|
|
|
* by @size. If @icon_name is %NULL, the image will be hidden.
|
|
|
|
|
*
|
2008-02-15 23:42:42 +00:00
|
|
|
|
* Since: 2.14
|
2007-12-14 05:00:51 +00:00
|
|
|
|
*/
|
|
|
|
|
void
|
2009-10-13 12:53:09 +00:00
|
|
|
|
gtk_tooltip_set_icon_from_icon_name (GtkTooltip *tooltip,
|
|
|
|
|
const gchar *icon_name,
|
|
|
|
|
GtkIconSize size)
|
2007-12-14 05:00:51 +00:00
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
|
|
|
|
|
|
|
|
|
|
if (icon_name)
|
2014-02-20 23:31:10 +00:00
|
|
|
|
{
|
|
|
|
|
gtk_image_set_from_icon_name (GTK_IMAGE (tooltip->image), icon_name, size);
|
|
|
|
|
gtk_widget_show (tooltip->image);
|
|
|
|
|
}
|
2009-10-13 12:53:09 +00:00
|
|
|
|
else
|
2014-02-20 23:31:10 +00:00
|
|
|
|
{
|
|
|
|
|
gtk_widget_hide (tooltip->image);
|
|
|
|
|
}
|
2009-10-13 12:53:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2009-11-01 21:12:43 +00:00
|
|
|
|
* gtk_tooltip_set_icon_from_gicon:
|
2009-10-13 12:53:09 +00:00
|
|
|
|
* @tooltip: a #GtkTooltip
|
2010-02-19 16:53:17 +00:00
|
|
|
|
* @gicon: (allow-none): a #GIcon representing the icon, or %NULL
|
2009-12-18 10:58:36 +00:00
|
|
|
|
* @size: (type int): a stock icon size
|
2009-11-01 21:12:43 +00:00
|
|
|
|
*
|
|
|
|
|
* Sets the icon of the tooltip (which is in front of the text)
|
|
|
|
|
* to be the icon indicated by @gicon with the size indicated
|
|
|
|
|
* by @size. If @gicon is %NULL, the image will be hidden.
|
2009-10-13 12:53:09 +00:00
|
|
|
|
*
|
|
|
|
|
* Since: 2.20
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_tooltip_set_icon_from_gicon (GtkTooltip *tooltip,
|
|
|
|
|
GIcon *gicon,
|
|
|
|
|
GtkIconSize size)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
|
|
|
|
|
|
|
|
|
|
if (gicon)
|
2014-02-20 23:31:10 +00:00
|
|
|
|
{
|
|
|
|
|
gtk_image_set_from_gicon (GTK_IMAGE (tooltip->image), gicon, size);
|
|
|
|
|
gtk_widget_show (tooltip->image);
|
|
|
|
|
}
|
2007-12-14 05:00:51 +00:00
|
|
|
|
else
|
2014-02-20 23:31:10 +00:00
|
|
|
|
{
|
|
|
|
|
gtk_widget_hide (tooltip->image);
|
|
|
|
|
}
|
2007-12-14 05:00:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-02-06 10:25:21 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_tooltip_set_custom:
|
2007-05-26 20:29:26 +00:00
|
|
|
|
* @tooltip: a #GtkTooltip
|
2010-02-19 16:53:17 +00:00
|
|
|
|
* @custom_widget: (allow-none): a #GtkWidget, or %NULL to unset the old custom widget.
|
2007-02-06 10:25:21 +00:00
|
|
|
|
*
|
2009-05-25 02:01:04 +00:00
|
|
|
|
* Replaces the widget packed into the tooltip with
|
|
|
|
|
* @custom_widget. @custom_widget does not get destroyed when the tooltip goes
|
|
|
|
|
* away.
|
2007-05-26 20:29:26 +00:00
|
|
|
|
* By default a box with a #GtkImage and #GtkLabel is embedded in
|
|
|
|
|
* the tooltip, which can be configured using gtk_tooltip_set_markup()
|
|
|
|
|
* and gtk_tooltip_set_icon().
|
2009-05-25 02:01:04 +00:00
|
|
|
|
|
2007-02-06 10:25:21 +00:00
|
|
|
|
*
|
|
|
|
|
* Since: 2.12
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_tooltip_set_custom (GtkTooltip *tooltip,
|
|
|
|
|
GtkWidget *custom_widget)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
|
|
|
|
|
if (custom_widget)
|
|
|
|
|
g_return_if_fail (GTK_IS_WIDGET (custom_widget));
|
|
|
|
|
|
2008-05-28 14:00:31 +00:00
|
|
|
|
/* The custom widget has been updated from the query-tooltip
|
|
|
|
|
* callback, so we do not want to reset the custom widget later on.
|
|
|
|
|
*/
|
|
|
|
|
tooltip->custom_was_reset = TRUE;
|
|
|
|
|
|
|
|
|
|
/* No need to do anything if the custom widget stays the same */
|
|
|
|
|
if (tooltip->custom_widget == custom_widget)
|
|
|
|
|
return;
|
|
|
|
|
|
2007-02-06 10:25:21 +00:00
|
|
|
|
if (tooltip->custom_widget)
|
|
|
|
|
{
|
2007-07-24 03:54:16 +00:00
|
|
|
|
GtkWidget *custom = tooltip->custom_widget;
|
|
|
|
|
/* Note: We must reset tooltip->custom_widget first,
|
|
|
|
|
* since gtk_container_remove() will recurse into
|
|
|
|
|
* gtk_tooltip_set_custom()
|
|
|
|
|
*/
|
|
|
|
|
tooltip->custom_widget = NULL;
|
|
|
|
|
gtk_container_remove (GTK_CONTAINER (tooltip->box), custom);
|
|
|
|
|
g_object_unref (custom);
|
2007-02-06 10:25:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (custom_widget)
|
|
|
|
|
{
|
|
|
|
|
tooltip->custom_widget = g_object_ref (custom_widget);
|
|
|
|
|
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (tooltip->box), custom_widget);
|
|
|
|
|
gtk_widget_show (custom_widget);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-07-13 14:25:21 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_tooltip_set_tip_area:
|
|
|
|
|
* @tooltip: a #GtkTooltip
|
|
|
|
|
* @rect: a #GdkRectangle
|
|
|
|
|
*
|
|
|
|
|
* Sets the area of the widget, where the contents of this tooltip apply,
|
|
|
|
|
* to be @rect (in widget coordinates). This is especially useful for
|
|
|
|
|
* properly setting tooltips on #GtkTreeView rows and cells, #GtkIconViews,
|
|
|
|
|
* etc.
|
|
|
|
|
*
|
|
|
|
|
* For setting tooltips on #GtkTreeView, please refer to the convenience
|
|
|
|
|
* functions for this: gtk_tree_view_set_tooltip_row() and
|
|
|
|
|
* gtk_tree_view_set_tooltip_cell().
|
|
|
|
|
*
|
|
|
|
|
* Since: 2.12
|
|
|
|
|
*/
|
|
|
|
|
void
|
2008-01-25 09:30:40 +00:00
|
|
|
|
gtk_tooltip_set_tip_area (GtkTooltip *tooltip,
|
|
|
|
|
const GdkRectangle *rect)
|
2007-07-13 14:25:21 +00:00
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
|
|
|
|
|
|
|
|
|
|
if (!rect)
|
|
|
|
|
tooltip->tip_area_set = FALSE;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
tooltip->tip_area_set = TRUE;
|
|
|
|
|
tooltip->tip_area = *rect;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-02-06 10:25:21 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_tooltip_trigger_tooltip_query:
|
2007-07-09 19:29:51 +00:00
|
|
|
|
* @display: a #GdkDisplay
|
2007-02-06 10:25:21 +00:00
|
|
|
|
*
|
|
|
|
|
* Triggers a new tooltip query on @display, in order to update the current
|
|
|
|
|
* visible tooltip, or to show/hide the current tooltip. This function is
|
|
|
|
|
* useful to call when, for example, the state of the widget changed by a
|
|
|
|
|
* key press.
|
|
|
|
|
*
|
|
|
|
|
* Since: 2.12
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_tooltip_trigger_tooltip_query (GdkDisplay *display)
|
|
|
|
|
{
|
|
|
|
|
gint x, y;
|
|
|
|
|
GdkWindow *window;
|
|
|
|
|
GdkEvent event;
|
2010-12-27 00:05:40 +00:00
|
|
|
|
GdkDevice *device;
|
2007-02-06 10:25:21 +00:00
|
|
|
|
|
|
|
|
|
/* Trigger logic as if the mouse moved */
|
2010-12-27 00:05:40 +00:00
|
|
|
|
device = gdk_device_manager_get_client_pointer (gdk_display_get_device_manager (display));
|
2010-12-27 17:45:39 +00:00
|
|
|
|
window = gdk_device_get_window_at_position (device, &x, &y);
|
2007-02-06 10:25:21 +00:00
|
|
|
|
if (!window)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
event.type = GDK_MOTION_NOTIFY;
|
|
|
|
|
event.motion.window = window;
|
|
|
|
|
event.motion.x = x;
|
|
|
|
|
event.motion.y = y;
|
|
|
|
|
event.motion.is_hint = FALSE;
|
|
|
|
|
|
2010-04-15 11:03:43 +00:00
|
|
|
|
gdk_window_get_root_coords (window, x, y, &x, &y);
|
|
|
|
|
event.motion.x_root = x;
|
|
|
|
|
event.motion.y_root = y;
|
2009-02-04 01:16:35 +00:00
|
|
|
|
|
2007-02-06 10:25:21 +00:00
|
|
|
|
_gtk_tooltip_handle_event (&event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_tooltip_reset (GtkTooltip *tooltip)
|
|
|
|
|
{
|
|
|
|
|
gtk_tooltip_set_markup (tooltip, NULL);
|
|
|
|
|
gtk_tooltip_set_icon (tooltip, NULL);
|
2007-07-13 14:25:21 +00:00
|
|
|
|
gtk_tooltip_set_tip_area (tooltip, NULL);
|
2008-05-28 14:00:31 +00:00
|
|
|
|
|
|
|
|
|
/* See if the custom widget is again set from the query-tooltip
|
|
|
|
|
* callback.
|
|
|
|
|
*/
|
|
|
|
|
tooltip->custom_was_reset = FALSE;
|
2007-02-06 10:25:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-10-06 21:06:57 +00:00
|
|
|
|
static void
|
|
|
|
|
paint_background_and_frame (GtkTooltip *tooltip,
|
|
|
|
|
cairo_t *cr)
|
2007-02-06 10:25:21 +00:00
|
|
|
|
{
|
2011-01-04 01:18:51 +00:00
|
|
|
|
GtkStyleContext *context;
|
2011-10-06 21:06:57 +00:00
|
|
|
|
gint width, height;
|
2011-01-04 01:18:51 +00:00
|
|
|
|
|
2011-10-06 21:06:57 +00:00
|
|
|
|
width = gtk_widget_get_allocated_width (tooltip->window);
|
|
|
|
|
height = gtk_widget_get_allocated_height (tooltip->window);
|
2011-01-04 01:18:51 +00:00
|
|
|
|
context = gtk_widget_get_style_context (tooltip->window);
|
|
|
|
|
|
2011-10-06 21:06:57 +00:00
|
|
|
|
gtk_render_background (context, cr,
|
|
|
|
|
0, 0, width, height);
|
|
|
|
|
gtk_render_frame (context, cr,
|
|
|
|
|
0, 0, width, height);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
maybe_update_shape (GtkTooltip *tooltip)
|
|
|
|
|
{
|
|
|
|
|
cairo_t *cr;
|
|
|
|
|
cairo_surface_t *surface;
|
|
|
|
|
cairo_region_t *region;
|
|
|
|
|
|
|
|
|
|
/* fallback to XShape only for non-composited clients */
|
|
|
|
|
if (gtk_widget_is_composited (tooltip->window))
|
|
|
|
|
{
|
|
|
|
|
gtk_widget_shape_combine_region (tooltip->window, NULL);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
surface = gdk_window_create_similar_surface (gtk_widget_get_window (tooltip->window),
|
|
|
|
|
CAIRO_CONTENT_COLOR_ALPHA,
|
|
|
|
|
gtk_widget_get_allocated_width (tooltip->window),
|
|
|
|
|
gtk_widget_get_allocated_height (tooltip->window));
|
|
|
|
|
|
|
|
|
|
cr = cairo_create (surface);
|
|
|
|
|
paint_background_and_frame (tooltip, cr);
|
|
|
|
|
cairo_destroy (cr);
|
|
|
|
|
|
|
|
|
|
region = gdk_cairo_region_create_from_surface (surface);
|
|
|
|
|
gtk_widget_shape_combine_region (tooltip->window, region);
|
|
|
|
|
|
|
|
|
|
cairo_surface_destroy (surface);
|
|
|
|
|
cairo_region_destroy (region);
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-22 16:38:29 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_tooltip_composited_changed (GtkTooltip *tooltip,
|
|
|
|
|
GtkWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
if (gtk_widget_get_realized (tooltip->window))
|
|
|
|
|
maybe_update_shape (tooltip);
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-06 21:06:57 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_tooltip_realize_window (GtkTooltip *tooltip,
|
|
|
|
|
GtkWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
maybe_update_shape (tooltip);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
gtk_tooltip_paint_window (GtkTooltip *tooltip,
|
|
|
|
|
cairo_t *cr)
|
|
|
|
|
{
|
|
|
|
|
if (gtk_widget_is_composited (tooltip->window))
|
|
|
|
|
{
|
|
|
|
|
/* clear any background */
|
|
|
|
|
cairo_save (cr);
|
|
|
|
|
cairo_set_source_rgba (cr, 0, 0, 0, 0);
|
|
|
|
|
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
|
|
|
|
|
cairo_paint (cr);
|
|
|
|
|
cairo_restore (cr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
maybe_update_shape (tooltip);
|
|
|
|
|
paint_background_and_frame (tooltip, cr);
|
2007-02-06 10:25:21 +00:00
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_tooltip_window_hide (GtkWidget *widget,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
GtkTooltip *tooltip = GTK_TOOLTIP (user_data);
|
|
|
|
|
|
2007-07-24 03:54:16 +00:00
|
|
|
|
gtk_tooltip_set_custom (tooltip, NULL);
|
2007-02-06 10:25:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* event handling, etc */
|
|
|
|
|
|
|
|
|
|
struct ChildLocation
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *child;
|
|
|
|
|
GtkWidget *container;
|
|
|
|
|
|
|
|
|
|
gint x;
|
|
|
|
|
gint y;
|
|
|
|
|
};
|
|
|
|
|
|
2013-04-29 17:25:21 +00:00
|
|
|
|
static void
|
|
|
|
|
prepend_and_ref_widget (GtkWidget *widget,
|
|
|
|
|
gpointer data)
|
|
|
|
|
{
|
|
|
|
|
GSList **slist_p = data;
|
|
|
|
|
|
|
|
|
|
*slist_p = g_slist_prepend (*slist_p, g_object_ref (widget));
|
|
|
|
|
}
|
|
|
|
|
|
2007-02-06 10:25:21 +00:00
|
|
|
|
static void
|
|
|
|
|
child_location_foreach (GtkWidget *child,
|
|
|
|
|
gpointer data)
|
|
|
|
|
{
|
2010-08-11 20:51:01 +00:00
|
|
|
|
GtkAllocation child_allocation;
|
2007-02-14 20:38:02 +00:00
|
|
|
|
gint x, y;
|
2007-02-06 10:25:21 +00:00
|
|
|
|
struct ChildLocation *child_loc = data;
|
|
|
|
|
|
2007-07-10 17:40:05 +00:00
|
|
|
|
/* Ignore invisible widgets */
|
2010-01-07 15:47:35 +00:00
|
|
|
|
if (!gtk_widget_is_drawable (child))
|
2007-07-10 17:40:05 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2010-08-11 20:51:01 +00:00
|
|
|
|
gtk_widget_get_allocation (child, &child_allocation);
|
|
|
|
|
|
2009-02-04 01:16:35 +00:00
|
|
|
|
x = 0;
|
|
|
|
|
y = 0;
|
|
|
|
|
|
2007-08-21 10:52:43 +00:00
|
|
|
|
/* (child_loc->x, child_loc->y) are relative to
|
|
|
|
|
* child_loc->container's allocation.
|
|
|
|
|
*/
|
|
|
|
|
|
2007-02-14 20:38:02 +00:00
|
|
|
|
if (!child_loc->child &&
|
2007-02-06 10:25:21 +00:00
|
|
|
|
gtk_widget_translate_coordinates (child_loc->container, child,
|
|
|
|
|
child_loc->x, child_loc->y,
|
2007-02-14 20:38:02 +00:00
|
|
|
|
&x, &y))
|
|
|
|
|
{
|
2007-08-21 10:52:43 +00:00
|
|
|
|
#ifdef DEBUG_TOOLTIP
|
|
|
|
|
g_print ("candidate: %s alloc=[(%d,%d) %dx%d] (%d, %d)->(%d, %d)\n",
|
|
|
|
|
gtk_widget_get_name (child),
|
2010-08-11 20:51:01 +00:00
|
|
|
|
child_allocation.x,
|
|
|
|
|
child_allocation.y,
|
|
|
|
|
child_allocation.width,
|
|
|
|
|
child_allocation.height,
|
2007-08-21 10:52:43 +00:00
|
|
|
|
child_loc->x, child_loc->y,
|
|
|
|
|
x, y);
|
|
|
|
|
#endif /* DEBUG_TOOLTIP */
|
|
|
|
|
|
|
|
|
|
/* (x, y) relative to child's allocation. */
|
2010-08-11 20:51:01 +00:00
|
|
|
|
if (x >= 0 && x < child_allocation.width
|
|
|
|
|
&& y >= 0 && y < child_allocation.height)
|
2007-02-06 10:25:21 +00:00
|
|
|
|
{
|
|
|
|
|
if (GTK_IS_CONTAINER (child))
|
|
|
|
|
{
|
|
|
|
|
struct ChildLocation tmp = { NULL, NULL, 0, 0 };
|
2013-04-29 17:25:21 +00:00
|
|
|
|
GSList *children = NULL, *tmp_list;
|
2007-02-06 10:25:21 +00:00
|
|
|
|
|
2007-08-21 10:52:43 +00:00
|
|
|
|
/* Take (x, y) relative the child's allocation and
|
|
|
|
|
* recurse.
|
|
|
|
|
*/
|
2007-02-06 10:25:21 +00:00
|
|
|
|
tmp.x = x;
|
|
|
|
|
tmp.y = y;
|
|
|
|
|
tmp.container = child;
|
|
|
|
|
|
2007-07-10 17:47:10 +00:00
|
|
|
|
gtk_container_forall (GTK_CONTAINER (child),
|
2013-04-29 17:25:21 +00:00
|
|
|
|
prepend_and_ref_widget, &children);
|
|
|
|
|
|
|
|
|
|
for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
|
|
|
|
|
{
|
|
|
|
|
child_location_foreach (tmp_list->data, &tmp);
|
|
|
|
|
g_object_unref (tmp_list->data);
|
|
|
|
|
}
|
2007-02-06 10:25:21 +00:00
|
|
|
|
|
|
|
|
|
if (tmp.child)
|
|
|
|
|
child_loc->child = tmp.child;
|
|
|
|
|
else
|
|
|
|
|
child_loc->child = child;
|
2013-04-29 17:25:21 +00:00
|
|
|
|
|
|
|
|
|
g_slist_free (children);
|
2007-02-06 10:25:21 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
child_loc->child = child;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-21 10:52:43 +00:00
|
|
|
|
/* Translates coordinates from dest_widget->window relative (src_x, src_y),
|
|
|
|
|
* to allocation relative (dest_x, dest_y) of dest_widget.
|
|
|
|
|
*/
|
2007-02-06 10:25:21 +00:00
|
|
|
|
static void
|
|
|
|
|
window_to_alloc (GtkWidget *dest_widget,
|
|
|
|
|
gint src_x,
|
|
|
|
|
gint src_y,
|
|
|
|
|
gint *dest_x,
|
|
|
|
|
gint *dest_y)
|
|
|
|
|
{
|
2010-08-11 20:51:01 +00:00
|
|
|
|
GtkAllocation allocation;
|
|
|
|
|
|
|
|
|
|
gtk_widget_get_allocation (dest_widget, &allocation);
|
|
|
|
|
|
2007-02-06 10:25:21 +00:00
|
|
|
|
/* Translate from window relative to allocation relative */
|
2010-08-11 20:51:01 +00:00
|
|
|
|
if (gtk_widget_get_has_window (dest_widget) &&
|
|
|
|
|
gtk_widget_get_parent (dest_widget))
|
2007-02-06 10:25:21 +00:00
|
|
|
|
{
|
|
|
|
|
gint wx, wy;
|
2010-08-11 20:51:01 +00:00
|
|
|
|
gdk_window_get_position (gtk_widget_get_window (dest_widget),
|
|
|
|
|
&wx, &wy);
|
2007-02-06 10:25:21 +00:00
|
|
|
|
|
2007-08-21 10:52:43 +00:00
|
|
|
|
/* Offset coordinates if widget->window is smaller than
|
|
|
|
|
* widget->allocation.
|
|
|
|
|
*/
|
2010-08-11 20:51:01 +00:00
|
|
|
|
src_x += wx - allocation.x;
|
|
|
|
|
src_y += wy - allocation.y;
|
2007-02-06 10:25:21 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2010-08-11 20:51:01 +00:00
|
|
|
|
src_x -= allocation.x;
|
|
|
|
|
src_y -= allocation.y;
|
2007-02-06 10:25:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dest_x)
|
|
|
|
|
*dest_x = src_x;
|
|
|
|
|
if (dest_y)
|
|
|
|
|
*dest_y = src_y;
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-21 10:52:43 +00:00
|
|
|
|
/* Translates coordinates from window relative (x, y) to
|
|
|
|
|
* allocation relative (x, y) of the returned widget.
|
|
|
|
|
*/
|
2010-05-26 15:09:11 +00:00
|
|
|
|
GtkWidget *
|
|
|
|
|
_gtk_widget_find_at_coords (GdkWindow *window,
|
|
|
|
|
gint window_x,
|
|
|
|
|
gint window_y,
|
|
|
|
|
gint *widget_x,
|
|
|
|
|
gint *widget_y)
|
2007-02-06 10:25:21 +00:00
|
|
|
|
{
|
|
|
|
|
GtkWidget *event_widget;
|
|
|
|
|
struct ChildLocation child_loc = { NULL, NULL, 0, 0 };
|
|
|
|
|
|
2010-05-26 15:09:11 +00:00
|
|
|
|
g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
|
|
|
|
|
|
2007-05-24 15:54:23 +00:00
|
|
|
|
gdk_window_get_user_data (window, (void **)&event_widget);
|
|
|
|
|
|
|
|
|
|
if (!event_widget)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2007-08-21 10:52:43 +00:00
|
|
|
|
#ifdef DEBUG_TOOLTIP
|
|
|
|
|
g_print ("event window %p (belonging to %p (%s)) (%d, %d)\n",
|
|
|
|
|
window, event_widget, gtk_widget_get_name (event_widget),
|
2010-05-26 15:09:11 +00:00
|
|
|
|
window_x, window_y);
|
2007-08-21 10:52:43 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* Coordinates are relative to event window */
|
2010-05-26 15:09:11 +00:00
|
|
|
|
child_loc.x = window_x;
|
|
|
|
|
child_loc.y = window_y;
|
2007-02-06 10:25:21 +00:00
|
|
|
|
|
2007-08-21 10:52:43 +00:00
|
|
|
|
/* We go down the window hierarchy to the widget->window,
|
|
|
|
|
* coordinates stay relative to the current window.
|
|
|
|
|
* We end up with window == widget->window, coordinates relative to that.
|
|
|
|
|
*/
|
2010-08-11 20:51:01 +00:00
|
|
|
|
while (window && window != gtk_widget_get_window (event_widget))
|
2007-05-23 12:32:42 +00:00
|
|
|
|
{
|
2010-04-15 11:03:43 +00:00
|
|
|
|
gdouble px, py;
|
2007-05-23 12:32:42 +00:00
|
|
|
|
|
2010-04-15 11:03:43 +00:00
|
|
|
|
gdk_window_coords_to_parent (window,
|
|
|
|
|
child_loc.x, child_loc.y,
|
|
|
|
|
&px, &py);
|
|
|
|
|
child_loc.x = px;
|
|
|
|
|
child_loc.y = py;
|
2007-05-23 12:32:42 +00:00
|
|
|
|
|
2010-04-15 11:03:43 +00:00
|
|
|
|
window = gdk_window_get_effective_parent (window);
|
2007-05-23 12:32:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Failing to find widget->window can happen for e.g. a detached handle box;
|
|
|
|
|
* chaining ::query-tooltip up to its parent probably makes little sense,
|
|
|
|
|
* and users better implement tooltips on handle_box->child.
|
|
|
|
|
* so we simply ignore the event for tooltips here.
|
|
|
|
|
*/
|
|
|
|
|
if (!window)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2007-08-21 10:52:43 +00:00
|
|
|
|
/* Convert the window relative coordinates to allocation
|
|
|
|
|
* relative coordinates.
|
|
|
|
|
*/
|
|
|
|
|
window_to_alloc (event_widget,
|
|
|
|
|
child_loc.x, child_loc.y,
|
|
|
|
|
&child_loc.x, &child_loc.y);
|
|
|
|
|
|
2007-02-06 10:25:21 +00:00
|
|
|
|
if (GTK_IS_CONTAINER (event_widget))
|
|
|
|
|
{
|
2007-08-21 10:52:43 +00:00
|
|
|
|
GtkWidget *container = event_widget;
|
2007-02-06 10:25:21 +00:00
|
|
|
|
|
|
|
|
|
child_loc.container = event_widget;
|
|
|
|
|
child_loc.child = NULL;
|
|
|
|
|
|
2007-07-10 17:47:10 +00:00
|
|
|
|
gtk_container_forall (GTK_CONTAINER (event_widget),
|
|
|
|
|
child_location_foreach, &child_loc);
|
2007-02-06 10:25:21 +00:00
|
|
|
|
|
2007-08-21 10:52:43 +00:00
|
|
|
|
/* Here we have a widget, with coordinates relative to
|
|
|
|
|
* child_loc.container's allocation.
|
|
|
|
|
*/
|
|
|
|
|
|
2007-02-06 10:25:21 +00:00
|
|
|
|
if (child_loc.child)
|
|
|
|
|
event_widget = child_loc.child;
|
|
|
|
|
else if (child_loc.container)
|
|
|
|
|
event_widget = child_loc.container;
|
2007-08-21 10:52:43 +00:00
|
|
|
|
|
|
|
|
|
/* Translate to event_widget's allocation */
|
|
|
|
|
gtk_widget_translate_coordinates (container, event_widget,
|
|
|
|
|
child_loc.x, child_loc.y,
|
|
|
|
|
&child_loc.x, &child_loc.y);
|
2007-02-06 10:25:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-08-21 10:52:43 +00:00
|
|
|
|
/* We return (x, y) relative to the allocation of event_widget. */
|
2010-05-26 15:09:11 +00:00
|
|
|
|
if (widget_x)
|
|
|
|
|
*widget_x = child_loc.x;
|
|
|
|
|
if (widget_y)
|
|
|
|
|
*widget_y = child_loc.y;
|
2007-02-06 10:25:21 +00:00
|
|
|
|
|
|
|
|
|
return event_widget;
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-21 10:52:43 +00:00
|
|
|
|
/* Ignores (x, y) on input, translates event coordinates to
|
|
|
|
|
* allocation relative (x, y) of the returned widget.
|
|
|
|
|
*/
|
2007-02-06 10:25:21 +00:00
|
|
|
|
static GtkWidget *
|
|
|
|
|
find_topmost_widget_coords_from_event (GdkEvent *event,
|
|
|
|
|
gint *x,
|
|
|
|
|
gint *y)
|
|
|
|
|
{
|
2010-08-11 20:51:01 +00:00
|
|
|
|
GtkAllocation allocation;
|
2007-02-06 10:25:21 +00:00
|
|
|
|
gint tx, ty;
|
|
|
|
|
gdouble dx, dy;
|
|
|
|
|
GtkWidget *tmp;
|
|
|
|
|
|
|
|
|
|
gdk_event_get_coords (event, &dx, &dy);
|
|
|
|
|
|
2007-08-21 10:52:43 +00:00
|
|
|
|
/* Returns coordinates relative to tmp's allocation. */
|
2010-05-26 15:09:11 +00:00
|
|
|
|
tmp = _gtk_widget_find_at_coords (event->any.window, dx, dy, &tx, &ty);
|
2007-02-06 10:25:21 +00:00
|
|
|
|
|
2007-07-19 15:03:18 +00:00
|
|
|
|
if (!tmp)
|
2007-07-16 16:39:53 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
|
2007-08-21 10:52:43 +00:00
|
|
|
|
/* Make sure the pointer can actually be on the widget returned. */
|
2010-08-11 20:51:01 +00:00
|
|
|
|
gtk_widget_get_allocation (tmp, &allocation);
|
|
|
|
|
if (tx < 0 || tx >= allocation.width ||
|
|
|
|
|
ty < 0 || ty >= allocation.height)
|
2007-08-21 10:52:43 +00:00
|
|
|
|
return NULL;
|
2007-07-19 15:03:18 +00:00
|
|
|
|
|
2007-04-25 07:15:49 +00:00
|
|
|
|
if (x)
|
|
|
|
|
*x = tx;
|
|
|
|
|
if (y)
|
|
|
|
|
*y = ty;
|
2007-02-06 10:25:21 +00:00
|
|
|
|
|
|
|
|
|
return tmp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gint
|
|
|
|
|
tooltip_browse_mode_expired (gpointer data)
|
|
|
|
|
{
|
|
|
|
|
GtkTooltip *tooltip;
|
|
|
|
|
|
|
|
|
|
tooltip = GTK_TOOLTIP (data);
|
|
|
|
|
|
|
|
|
|
tooltip->browse_mode_enabled = FALSE;
|
|
|
|
|
tooltip->browse_mode_timeout_id = 0;
|
|
|
|
|
|
|
|
|
|
/* destroy tooltip */
|
|
|
|
|
g_object_set_data (G_OBJECT (gtk_widget_get_display (tooltip->window)),
|
|
|
|
|
"gdk-display-current-tooltip", NULL);
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_tooltip_display_closed (GdkDisplay *display,
|
|
|
|
|
gboolean was_error,
|
|
|
|
|
GtkTooltip *tooltip)
|
|
|
|
|
{
|
2007-10-08 12:39:02 +00:00
|
|
|
|
g_object_set_data (G_OBJECT (display), "gdk-display-current-tooltip", NULL);
|
2007-02-06 10:25:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-12-17 15:33:45 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_tooltip_set_last_window (GtkTooltip *tooltip,
|
|
|
|
|
GdkWindow *window)
|
|
|
|
|
{
|
2009-09-30 03:45:03 +00:00
|
|
|
|
if (tooltip->last_window == window)
|
|
|
|
|
return;
|
|
|
|
|
|
2007-12-17 15:33:45 +00:00
|
|
|
|
if (tooltip->last_window)
|
|
|
|
|
g_object_remove_weak_pointer (G_OBJECT (tooltip->last_window),
|
|
|
|
|
(gpointer *) &tooltip->last_window);
|
|
|
|
|
|
|
|
|
|
tooltip->last_window = window;
|
|
|
|
|
|
|
|
|
|
if (window)
|
|
|
|
|
g_object_add_weak_pointer (G_OBJECT (tooltip->last_window),
|
|
|
|
|
(gpointer *) &tooltip->last_window);
|
|
|
|
|
}
|
|
|
|
|
|
2007-02-06 10:25:21 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
gtk_tooltip_run_requery (GtkWidget **widget,
|
|
|
|
|
GtkTooltip *tooltip,
|
|
|
|
|
gint *x,
|
|
|
|
|
gint *y)
|
|
|
|
|
{
|
|
|
|
|
gboolean has_tooltip = FALSE;
|
|
|
|
|
gboolean return_value = FALSE;
|
|
|
|
|
|
|
|
|
|
gtk_tooltip_reset (tooltip);
|
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
g_object_get (*widget,
|
|
|
|
|
"has-tooltip", &has_tooltip,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
if (has_tooltip)
|
|
|
|
|
g_signal_emit_by_name (*widget,
|
|
|
|
|
"query-tooltip",
|
|
|
|
|
*x, *y,
|
|
|
|
|
tooltip->keyboard_mode_enabled,
|
|
|
|
|
tooltip,
|
|
|
|
|
&return_value);
|
|
|
|
|
|
|
|
|
|
if (!return_value)
|
|
|
|
|
{
|
2010-08-11 20:51:01 +00:00
|
|
|
|
GtkWidget *parent = gtk_widget_get_parent (*widget);
|
2007-02-06 10:25:21 +00:00
|
|
|
|
|
|
|
|
|
if (parent)
|
|
|
|
|
gtk_widget_translate_coordinates (*widget, parent, *x, *y, x, y);
|
|
|
|
|
|
|
|
|
|
*widget = parent;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
while (*widget);
|
|
|
|
|
|
2008-05-28 14:00:31 +00:00
|
|
|
|
/* If the custom widget was not reset in the query-tooltip
|
|
|
|
|
* callback, we clear it here.
|
|
|
|
|
*/
|
|
|
|
|
if (!tooltip->custom_was_reset)
|
|
|
|
|
gtk_tooltip_set_custom (tooltip, NULL);
|
|
|
|
|
|
2007-02-06 10:25:21 +00:00
|
|
|
|
return return_value;
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-15 11:03:43 +00:00
|
|
|
|
static void
|
|
|
|
|
get_bounding_box (GtkWidget *widget,
|
|
|
|
|
GdkRectangle *bounds)
|
|
|
|
|
{
|
2010-08-11 20:51:01 +00:00
|
|
|
|
GtkAllocation allocation;
|
2010-04-15 11:03:43 +00:00
|
|
|
|
GdkWindow *window;
|
|
|
|
|
gint x, y;
|
|
|
|
|
gint w, h;
|
|
|
|
|
gint x1, y1;
|
|
|
|
|
gint x2, y2;
|
|
|
|
|
gint x3, y3;
|
|
|
|
|
gint x4, y4;
|
|
|
|
|
|
|
|
|
|
window = gtk_widget_get_parent_window (widget);
|
2010-08-05 04:12:41 +00:00
|
|
|
|
if (window == NULL)
|
|
|
|
|
window = gtk_widget_get_window (widget);
|
2010-04-15 11:03:43 +00:00
|
|
|
|
|
2010-08-11 20:51:01 +00:00
|
|
|
|
gtk_widget_get_allocation (widget, &allocation);
|
|
|
|
|
x = allocation.x;
|
|
|
|
|
y = allocation.y;
|
|
|
|
|
w = allocation.width;
|
|
|
|
|
h = allocation.height;
|
2010-04-15 11:03:43 +00:00
|
|
|
|
|
|
|
|
|
gdk_window_get_root_coords (window, x, y, &x1, &y1);
|
|
|
|
|
gdk_window_get_root_coords (window, x + w, y, &x2, &y2);
|
|
|
|
|
gdk_window_get_root_coords (window, x, y + h, &x3, &y3);
|
|
|
|
|
gdk_window_get_root_coords (window, x + w, y + h, &x4, &y4);
|
|
|
|
|
|
|
|
|
|
#define MIN4(a,b,c,d) MIN(MIN(a,b),MIN(c,d))
|
|
|
|
|
#define MAX4(a,b,c,d) MAX(MAX(a,b),MAX(c,d))
|
|
|
|
|
|
|
|
|
|
bounds->x = floor (MIN4 (x1, x2, x3, x4));
|
|
|
|
|
bounds->y = floor (MIN4 (y1, y2, y3, y4));
|
|
|
|
|
bounds->width = ceil (MAX4 (x1, x2, x3, x4)) - bounds->x;
|
|
|
|
|
bounds->height = ceil (MAX4 (y1, y2, y3, y4)) - bounds->y;
|
|
|
|
|
}
|
|
|
|
|
|
2007-07-13 14:25:21 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_tooltip_position (GtkTooltip *tooltip,
|
|
|
|
|
GdkDisplay *display,
|
|
|
|
|
GtkWidget *new_tooltip_widget)
|
|
|
|
|
{
|
2011-04-26 22:25:48 +00:00
|
|
|
|
gint x, y, width, height;
|
2007-07-13 14:25:21 +00:00
|
|
|
|
GdkScreen *screen;
|
2010-05-08 02:19:56 +00:00
|
|
|
|
gint monitor_num;
|
|
|
|
|
GdkRectangle monitor;
|
|
|
|
|
guint cursor_size;
|
|
|
|
|
GdkRectangle bounds;
|
|
|
|
|
|
|
|
|
|
#define MAX_DISTANCE 32
|
2007-07-13 14:25:21 +00:00
|
|
|
|
|
2011-04-26 22:25:48 +00:00
|
|
|
|
gtk_widget_realize (GTK_WIDGET (tooltip->current_window));
|
2013-10-15 13:06:26 +00:00
|
|
|
|
gtk_widget_set_visible (GTK_WIDGET (tooltip->current_window), TRUE);
|
2011-04-26 22:25:48 +00:00
|
|
|
|
|
2007-07-13 14:25:21 +00:00
|
|
|
|
tooltip->tooltip_widget = new_tooltip_widget;
|
|
|
|
|
|
2010-05-08 02:19:56 +00:00
|
|
|
|
screen = gtk_widget_get_screen (new_tooltip_widget);
|
|
|
|
|
|
2011-04-26 22:25:48 +00:00
|
|
|
|
width = gtk_widget_get_allocated_width (GTK_WIDGET (tooltip->current_window));
|
|
|
|
|
height = gtk_widget_get_allocated_height (GTK_WIDGET (tooltip->current_window));
|
2010-05-08 02:19:56 +00:00
|
|
|
|
|
|
|
|
|
monitor_num = gdk_screen_get_monitor_at_point (screen,
|
|
|
|
|
tooltip->last_x,
|
|
|
|
|
tooltip->last_y);
|
2011-12-18 19:28:01 +00:00
|
|
|
|
gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
|
2010-05-08 02:19:56 +00:00
|
|
|
|
|
|
|
|
|
get_bounding_box (new_tooltip_widget, &bounds);
|
|
|
|
|
|
2007-07-13 14:25:21 +00:00
|
|
|
|
/* Position the tooltip */
|
2010-05-08 02:19:56 +00:00
|
|
|
|
|
|
|
|
|
cursor_size = gdk_display_get_default_cursor_size (display);
|
|
|
|
|
|
|
|
|
|
/* Try below */
|
2011-04-26 22:25:48 +00:00
|
|
|
|
x = bounds.x + bounds.width / 2 - width / 2;
|
2010-05-08 02:19:56 +00:00
|
|
|
|
y = bounds.y + bounds.height + 4;
|
|
|
|
|
|
2011-04-26 22:25:48 +00:00
|
|
|
|
if (y + height <= monitor.y + monitor.height)
|
2007-07-13 14:25:21 +00:00
|
|
|
|
{
|
2010-05-08 02:19:56 +00:00
|
|
|
|
if (tooltip->keyboard_mode_enabled)
|
|
|
|
|
goto found;
|
2010-04-15 11:03:43 +00:00
|
|
|
|
|
2010-05-08 02:19:56 +00:00
|
|
|
|
if (y <= tooltip->last_y + cursor_size + MAX_DISTANCE)
|
|
|
|
|
{
|
|
|
|
|
if (tooltip->last_x + cursor_size + MAX_DISTANCE < x)
|
|
|
|
|
x = tooltip->last_x + cursor_size + MAX_DISTANCE;
|
2011-04-26 22:25:48 +00:00
|
|
|
|
else if (x + width < tooltip->last_x - MAX_DISTANCE)
|
|
|
|
|
x = tooltip->last_x - MAX_DISTANCE - width;
|
2007-07-13 14:25:21 +00:00
|
|
|
|
|
2010-05-08 02:19:56 +00:00
|
|
|
|
goto found;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Try above */
|
2011-04-26 22:25:48 +00:00
|
|
|
|
x = bounds.x + bounds.width / 2 - width / 2;
|
|
|
|
|
y = bounds.y - height - 4;
|
2010-05-08 02:19:56 +00:00
|
|
|
|
|
|
|
|
|
if (y >= monitor.y)
|
|
|
|
|
{
|
|
|
|
|
if (tooltip->keyboard_mode_enabled)
|
|
|
|
|
goto found;
|
|
|
|
|
|
2011-04-26 22:25:48 +00:00
|
|
|
|
if (y + height >= tooltip->last_y - MAX_DISTANCE)
|
2010-05-08 02:19:56 +00:00
|
|
|
|
{
|
|
|
|
|
if (tooltip->last_x + cursor_size + MAX_DISTANCE < x)
|
|
|
|
|
x = tooltip->last_x + cursor_size + MAX_DISTANCE;
|
2011-04-26 22:25:48 +00:00
|
|
|
|
else if (x + width < tooltip->last_x - MAX_DISTANCE)
|
|
|
|
|
x = tooltip->last_x - MAX_DISTANCE - width;
|
2010-05-08 02:19:56 +00:00
|
|
|
|
|
|
|
|
|
goto found;
|
|
|
|
|
}
|
2007-07-13 14:25:21 +00:00
|
|
|
|
}
|
2010-05-08 02:19:56 +00:00
|
|
|
|
|
|
|
|
|
/* Try right FIXME: flip on rtl ? */
|
|
|
|
|
x = bounds.x + bounds.width + 4;
|
2011-04-26 22:25:48 +00:00
|
|
|
|
y = bounds.y + bounds.height / 2 - height / 2;
|
2010-05-08 02:19:56 +00:00
|
|
|
|
|
2011-04-26 22:25:48 +00:00
|
|
|
|
if (x + width <= monitor.x + monitor.width)
|
2007-07-13 14:25:21 +00:00
|
|
|
|
{
|
2010-05-08 02:19:56 +00:00
|
|
|
|
if (tooltip->keyboard_mode_enabled)
|
|
|
|
|
goto found;
|
2007-07-13 14:25:21 +00:00
|
|
|
|
|
2010-05-08 02:19:56 +00:00
|
|
|
|
if (x <= tooltip->last_x + cursor_size + MAX_DISTANCE)
|
|
|
|
|
{
|
|
|
|
|
if (tooltip->last_y + cursor_size + MAX_DISTANCE < y)
|
|
|
|
|
y = tooltip->last_y + cursor_size + MAX_DISTANCE;
|
2011-04-26 22:25:48 +00:00
|
|
|
|
else if (y + height < tooltip->last_y - MAX_DISTANCE)
|
|
|
|
|
y = tooltip->last_y - MAX_DISTANCE - height;
|
2007-07-13 14:25:21 +00:00
|
|
|
|
|
2010-05-08 02:19:56 +00:00
|
|
|
|
goto found;
|
|
|
|
|
}
|
2007-07-13 14:25:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-05-08 02:19:56 +00:00
|
|
|
|
/* Try left FIXME: flip on rtl ? */
|
2011-04-26 22:25:48 +00:00
|
|
|
|
x = bounds.x - width - 4;
|
|
|
|
|
y = bounds.y + bounds.height / 2 - height / 2;
|
2007-07-13 14:25:21 +00:00
|
|
|
|
|
2010-05-08 02:19:56 +00:00
|
|
|
|
if (x >= monitor.x)
|
2007-07-13 14:25:21 +00:00
|
|
|
|
{
|
2010-05-08 02:19:56 +00:00
|
|
|
|
if (tooltip->keyboard_mode_enabled)
|
|
|
|
|
goto found;
|
2007-07-13 14:25:21 +00:00
|
|
|
|
|
2011-04-26 22:25:48 +00:00
|
|
|
|
if (x + width >= tooltip->last_x - MAX_DISTANCE)
|
2010-05-08 02:19:56 +00:00
|
|
|
|
{
|
|
|
|
|
if (tooltip->last_y + cursor_size + MAX_DISTANCE < y)
|
|
|
|
|
y = tooltip->last_y + cursor_size + MAX_DISTANCE;
|
2011-04-26 22:25:48 +00:00
|
|
|
|
else if (y + height < tooltip->last_y - MAX_DISTANCE)
|
|
|
|
|
y = tooltip->last_y - MAX_DISTANCE - height;
|
2007-07-13 14:25:21 +00:00
|
|
|
|
|
2010-05-08 02:19:56 +00:00
|
|
|
|
goto found;
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-07-13 14:25:21 +00:00
|
|
|
|
|
2010-05-08 02:19:56 +00:00
|
|
|
|
/* Fallback */
|
|
|
|
|
if (tooltip->keyboard_mode_enabled)
|
|
|
|
|
{
|
2011-04-26 22:25:48 +00:00
|
|
|
|
x = bounds.x + bounds.width / 2 - width / 2;
|
2010-05-08 02:19:56 +00:00
|
|
|
|
y = bounds.y + bounds.height + 4;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* At cursor */
|
|
|
|
|
x = tooltip->last_x + cursor_size * 3 / 4;
|
|
|
|
|
y = tooltip->last_y + cursor_size * 3 / 4;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
found:
|
|
|
|
|
/* Show it */
|
|
|
|
|
if (tooltip->current_window)
|
|
|
|
|
{
|
2011-04-26 22:25:48 +00:00
|
|
|
|
if (x + width > monitor.x + monitor.width)
|
|
|
|
|
x -= x - (monitor.x + monitor.width) + width;
|
2007-07-13 14:25:21 +00:00
|
|
|
|
else if (x < monitor.x)
|
|
|
|
|
x = monitor.x;
|
|
|
|
|
|
2011-04-26 22:25:48 +00:00
|
|
|
|
if (y + height > monitor.y + monitor.height)
|
|
|
|
|
y -= y - (monitor.y + monitor.height) + height;
|
2010-05-08 02:19:56 +00:00
|
|
|
|
else if (y < monitor.y)
|
|
|
|
|
y = monitor.y;
|
|
|
|
|
|
2007-07-20 12:13:24 +00:00
|
|
|
|
if (!tooltip->keyboard_mode_enabled)
|
|
|
|
|
{
|
|
|
|
|
/* don't pop up under the pointer */
|
2011-04-26 22:25:48 +00:00
|
|
|
|
if (x <= tooltip->last_x && tooltip->last_x < x + width &&
|
|
|
|
|
y <= tooltip->last_y && tooltip->last_y < y + height)
|
|
|
|
|
y = tooltip->last_y - height - 2;
|
2007-07-20 12:13:24 +00:00
|
|
|
|
}
|
2010-05-08 02:19:56 +00:00
|
|
|
|
|
2013-02-07 11:27:00 +00:00
|
|
|
|
#ifdef GDK_WINDOWING_WAYLAND
|
|
|
|
|
/* set the transient parent on the tooltip when running with the Wayland
|
|
|
|
|
* backend to allow correct positioning of the tooltip windows */
|
|
|
|
|
if (GDK_IS_WAYLAND_DISPLAY (display))
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *toplevel;
|
|
|
|
|
|
|
|
|
|
toplevel = gtk_widget_get_toplevel (tooltip->tooltip_widget);
|
|
|
|
|
if (GTK_IS_WINDOW (toplevel))
|
|
|
|
|
gtk_window_set_transient_for (GTK_WINDOW (tooltip->current_window),
|
|
|
|
|
GTK_WINDOW (toplevel));
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2007-07-13 14:25:21 +00:00
|
|
|
|
gtk_window_move (GTK_WINDOW (tooltip->current_window), x, y);
|
|
|
|
|
gtk_widget_show (GTK_WIDGET (tooltip->current_window));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-02-06 10:25:21 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_tooltip_show_tooltip (GdkDisplay *display)
|
|
|
|
|
{
|
|
|
|
|
gint x, y;
|
|
|
|
|
GdkScreen *screen;
|
|
|
|
|
|
|
|
|
|
GdkWindow *window;
|
|
|
|
|
GtkWidget *tooltip_widget;
|
|
|
|
|
GtkTooltip *tooltip;
|
|
|
|
|
gboolean has_tooltip;
|
|
|
|
|
gboolean return_value = FALSE;
|
|
|
|
|
|
|
|
|
|
tooltip = g_object_get_data (G_OBJECT (display),
|
2011-01-24 02:50:39 +00:00
|
|
|
|
"gdk-display-current-tooltip");
|
2007-02-06 10:25:21 +00:00
|
|
|
|
|
|
|
|
|
if (tooltip->keyboard_mode_enabled)
|
|
|
|
|
{
|
2008-10-07 18:06:00 +00:00
|
|
|
|
x = y = -1;
|
2011-01-24 02:50:39 +00:00
|
|
|
|
tooltip_widget = tooltip->keyboard_widget;
|
2007-02-06 10:25:21 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2011-10-28 20:12:02 +00:00
|
|
|
|
GdkDevice *device;
|
2010-04-15 11:03:43 +00:00
|
|
|
|
gint tx, ty;
|
|
|
|
|
|
2007-02-06 10:25:21 +00:00
|
|
|
|
window = tooltip->last_window;
|
|
|
|
|
|
2007-06-06 12:28:50 +00:00
|
|
|
|
if (!GDK_IS_WINDOW (window))
|
2011-01-24 02:50:39 +00:00
|
|
|
|
return;
|
2007-06-06 12:28:50 +00:00
|
|
|
|
|
2011-10-28 20:12:02 +00:00
|
|
|
|
device = gdk_device_manager_get_client_pointer (gdk_display_get_device_manager (display));
|
|
|
|
|
|
|
|
|
|
gdk_window_get_device_position (window, device, &x, &y, NULL);
|
2010-04-15 11:03:43 +00:00
|
|
|
|
|
|
|
|
|
gdk_window_get_root_coords (window, x, y, &tx, &ty);
|
|
|
|
|
tooltip->last_x = tx;
|
|
|
|
|
tooltip->last_y = ty;
|
2007-02-06 10:25:21 +00:00
|
|
|
|
|
2011-01-24 02:50:39 +00:00
|
|
|
|
tooltip_widget = _gtk_widget_find_at_coords (window, x, y, &x, &y);
|
2007-02-06 10:25:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!tooltip_widget)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
g_object_get (tooltip_widget, "has-tooltip", &has_tooltip, NULL);
|
|
|
|
|
|
|
|
|
|
return_value = gtk_tooltip_run_requery (&tooltip_widget, tooltip, &x, &y);
|
|
|
|
|
if (!return_value)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!tooltip->current_window)
|
|
|
|
|
{
|
|
|
|
|
if (gtk_widget_get_tooltip_window (tooltip_widget))
|
2011-01-24 02:50:39 +00:00
|
|
|
|
tooltip->current_window = gtk_widget_get_tooltip_window (tooltip_widget);
|
2007-02-06 10:25:21 +00:00
|
|
|
|
else
|
2011-01-24 02:50:39 +00:00
|
|
|
|
tooltip->current_window = GTK_WINDOW (GTK_TOOLTIP (tooltip)->window);
|
2007-02-06 10:25:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
screen = gtk_widget_get_screen (tooltip_widget);
|
|
|
|
|
|
2007-07-13 14:25:21 +00:00
|
|
|
|
/* FIXME: should use tooltip->current_window iso tooltip->window */
|
2007-02-06 10:25:21 +00:00
|
|
|
|
if (screen != gtk_widget_get_screen (tooltip->window))
|
|
|
|
|
{
|
|
|
|
|
g_signal_handlers_disconnect_by_func (display,
|
2011-01-24 02:50:39 +00:00
|
|
|
|
gtk_tooltip_display_closed,
|
|
|
|
|
tooltip);
|
2007-02-06 10:25:21 +00:00
|
|
|
|
|
|
|
|
|
gtk_window_set_screen (GTK_WINDOW (tooltip->window), screen);
|
|
|
|
|
|
|
|
|
|
g_signal_connect (display, "closed",
|
2011-01-24 02:50:39 +00:00
|
|
|
|
G_CALLBACK (gtk_tooltip_display_closed), tooltip);
|
2007-02-06 10:25:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-07-13 14:25:21 +00:00
|
|
|
|
gtk_tooltip_position (tooltip, display, tooltip_widget);
|
2007-02-06 10:25:21 +00:00
|
|
|
|
|
|
|
|
|
/* Now a tooltip is visible again on the display, make sure browse
|
|
|
|
|
* mode is enabled.
|
|
|
|
|
*/
|
|
|
|
|
tooltip->browse_mode_enabled = TRUE;
|
|
|
|
|
if (tooltip->browse_mode_timeout_id)
|
|
|
|
|
{
|
|
|
|
|
g_source_remove (tooltip->browse_mode_timeout_id);
|
|
|
|
|
tooltip->browse_mode_timeout_id = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_tooltip_hide_tooltip (GtkTooltip *tooltip)
|
|
|
|
|
{
|
2007-02-13 12:41:36 +00:00
|
|
|
|
if (!tooltip)
|
2007-02-06 10:25:21 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (tooltip->timeout_id)
|
|
|
|
|
{
|
|
|
|
|
g_source_remove (tooltip->timeout_id);
|
|
|
|
|
tooltip->timeout_id = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2007-02-13 12:41:36 +00:00
|
|
|
|
if (!GTK_TOOLTIP_VISIBLE (tooltip))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
tooltip->tooltip_widget = NULL;
|
|
|
|
|
|
2007-02-06 10:25:21 +00:00
|
|
|
|
if (!tooltip->keyboard_mode_enabled)
|
|
|
|
|
{
|
2013-07-08 17:13:23 +00:00
|
|
|
|
guint timeout = BROWSE_DISABLE_TIMEOUT;
|
2007-02-06 10:25:21 +00:00
|
|
|
|
|
|
|
|
|
/* The tooltip is gone, after (by default, should be configurable) 500ms
|
|
|
|
|
* we want to turn off browse mode
|
|
|
|
|
*/
|
|
|
|
|
if (!tooltip->browse_mode_timeout_id)
|
2013-10-22 13:43:43 +00:00
|
|
|
|
{
|
|
|
|
|
tooltip->browse_mode_timeout_id =
|
|
|
|
|
gdk_threads_add_timeout_full (0, timeout,
|
|
|
|
|
tooltip_browse_mode_expired,
|
|
|
|
|
g_object_ref (tooltip),
|
|
|
|
|
g_object_unref);
|
|
|
|
|
g_source_set_name_by_id (tooltip->browse_mode_timeout_id, "[gtk+] tooltip_browse_mode_expired");
|
|
|
|
|
}
|
2007-02-06 10:25:21 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (tooltip->browse_mode_timeout_id)
|
|
|
|
|
{
|
|
|
|
|
g_source_remove (tooltip->browse_mode_timeout_id);
|
|
|
|
|
tooltip->browse_mode_timeout_id = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (tooltip->current_window)
|
|
|
|
|
{
|
|
|
|
|
gtk_widget_hide (GTK_WIDGET (tooltip->current_window));
|
|
|
|
|
tooltip->current_window = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gint
|
|
|
|
|
tooltip_popup_timeout (gpointer data)
|
|
|
|
|
{
|
|
|
|
|
GdkDisplay *display;
|
|
|
|
|
GtkTooltip *tooltip;
|
|
|
|
|
|
2010-12-20 16:11:00 +00:00
|
|
|
|
display = GDK_DISPLAY (data);
|
2009-08-22 21:21:44 +00:00
|
|
|
|
tooltip = g_object_get_data (G_OBJECT (display),
|
|
|
|
|
"gdk-display-current-tooltip");
|
|
|
|
|
|
|
|
|
|
/* This usually does not happen. However, it does occur in language
|
|
|
|
|
* bindings were reference counting of objects behaves differently.
|
|
|
|
|
*/
|
|
|
|
|
if (!tooltip)
|
|
|
|
|
return FALSE;
|
2007-02-06 10:25:21 +00:00
|
|
|
|
|
|
|
|
|
gtk_tooltip_show_tooltip (display);
|
|
|
|
|
|
|
|
|
|
tooltip->timeout_id = 0;
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_tooltip_start_delay (GdkDisplay *display)
|
|
|
|
|
{
|
|
|
|
|
guint timeout;
|
|
|
|
|
GtkTooltip *tooltip;
|
|
|
|
|
|
|
|
|
|
tooltip = g_object_get_data (G_OBJECT (display),
|
|
|
|
|
"gdk-display-current-tooltip");
|
|
|
|
|
|
2009-08-22 21:21:44 +00:00
|
|
|
|
if (!tooltip || GTK_TOOLTIP_VISIBLE (tooltip))
|
2007-02-06 10:25:21 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (tooltip->timeout_id)
|
|
|
|
|
g_source_remove (tooltip->timeout_id);
|
|
|
|
|
|
|
|
|
|
if (tooltip->browse_mode_enabled)
|
2013-07-08 17:13:23 +00:00
|
|
|
|
timeout = BROWSE_TIMEOUT;
|
2007-02-06 10:25:21 +00:00
|
|
|
|
else
|
2013-07-08 17:13:23 +00:00
|
|
|
|
timeout = HOVER_TIMEOUT;
|
2007-02-06 10:25:21 +00:00
|
|
|
|
|
2007-04-04 13:05:42 +00:00
|
|
|
|
tooltip->timeout_id = gdk_threads_add_timeout_full (0, timeout,
|
|
|
|
|
tooltip_popup_timeout,
|
|
|
|
|
g_object_ref (display),
|
|
|
|
|
g_object_unref);
|
2013-10-22 13:43:43 +00:00
|
|
|
|
g_source_set_name_by_id (tooltip->timeout_id, "[gtk+] tooltip_popup_timeout");
|
2007-02-06 10:25:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
_gtk_tooltip_focus_in (GtkWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
gint x, y;
|
|
|
|
|
gboolean return_value = FALSE;
|
|
|
|
|
GdkDisplay *display;
|
|
|
|
|
GtkTooltip *tooltip;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
GdkDevice *device;
|
2007-02-06 10:25:21 +00:00
|
|
|
|
|
|
|
|
|
/* Get current tooltip for this display */
|
|
|
|
|
display = gtk_widget_get_display (widget);
|
|
|
|
|
tooltip = g_object_get_data (G_OBJECT (display),
|
|
|
|
|
"gdk-display-current-tooltip");
|
|
|
|
|
|
|
|
|
|
/* Check if keyboard mode is enabled at this moment */
|
|
|
|
|
if (!tooltip || !tooltip->keyboard_mode_enabled)
|
|
|
|
|
return;
|
|
|
|
|
|
2010-05-25 22:38:44 +00:00
|
|
|
|
device = gtk_get_current_event_device ();
|
|
|
|
|
|
2010-11-23 19:25:13 +00:00
|
|
|
|
if (device && gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
|
2010-05-25 22:38:44 +00:00
|
|
|
|
device = gdk_device_get_associated_device (device);
|
|
|
|
|
|
|
|
|
|
/* This function should be called by either a focus in event,
|
|
|
|
|
* or a key binding. In either case there should be a device.
|
|
|
|
|
*/
|
|
|
|
|
if (!device)
|
|
|
|
|
return;
|
|
|
|
|
|
2007-02-06 10:25:21 +00:00
|
|
|
|
if (tooltip->keyboard_widget)
|
|
|
|
|
g_object_unref (tooltip->keyboard_widget);
|
|
|
|
|
|
|
|
|
|
tooltip->keyboard_widget = g_object_ref (widget);
|
|
|
|
|
|
2010-08-11 20:51:01 +00:00
|
|
|
|
gdk_window_get_device_position (gtk_widget_get_window (widget),
|
|
|
|
|
device, &x, &y, NULL);
|
2007-02-06 10:25:21 +00:00
|
|
|
|
|
|
|
|
|
return_value = gtk_tooltip_run_requery (&widget, tooltip, &x, &y);
|
|
|
|
|
if (!return_value)
|
|
|
|
|
{
|
|
|
|
|
gtk_tooltip_hide_tooltip (tooltip);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!tooltip->current_window)
|
|
|
|
|
{
|
|
|
|
|
if (gtk_widget_get_tooltip_window (widget))
|
|
|
|
|
tooltip->current_window = gtk_widget_get_tooltip_window (widget);
|
|
|
|
|
else
|
|
|
|
|
tooltip->current_window = GTK_WINDOW (GTK_TOOLTIP (tooltip)->window);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gtk_tooltip_show_tooltip (display);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
_gtk_tooltip_focus_out (GtkWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
GdkDisplay *display;
|
|
|
|
|
GtkTooltip *tooltip;
|
|
|
|
|
|
|
|
|
|
/* Get current tooltip for this display */
|
|
|
|
|
display = gtk_widget_get_display (widget);
|
|
|
|
|
tooltip = g_object_get_data (G_OBJECT (display),
|
|
|
|
|
"gdk-display-current-tooltip");
|
|
|
|
|
|
|
|
|
|
if (!tooltip || !tooltip->keyboard_mode_enabled)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (tooltip->keyboard_widget)
|
|
|
|
|
{
|
|
|
|
|
g_object_unref (tooltip->keyboard_widget);
|
|
|
|
|
tooltip->keyboard_widget = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gtk_tooltip_hide_tooltip (tooltip);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
_gtk_tooltip_toggle_keyboard_mode (GtkWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
GdkDisplay *display;
|
|
|
|
|
GtkTooltip *tooltip;
|
|
|
|
|
|
|
|
|
|
display = gtk_widget_get_display (widget);
|
|
|
|
|
tooltip = g_object_get_data (G_OBJECT (display),
|
|
|
|
|
"gdk-display-current-tooltip");
|
|
|
|
|
|
|
|
|
|
if (!tooltip)
|
|
|
|
|
{
|
|
|
|
|
tooltip = g_object_new (GTK_TYPE_TOOLTIP, NULL);
|
|
|
|
|
g_object_set_data_full (G_OBJECT (display),
|
|
|
|
|
"gdk-display-current-tooltip",
|
|
|
|
|
tooltip, g_object_unref);
|
2007-10-08 12:39:02 +00:00
|
|
|
|
g_signal_connect (display, "closed",
|
|
|
|
|
G_CALLBACK (gtk_tooltip_display_closed),
|
|
|
|
|
tooltip);
|
2007-02-06 10:25:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tooltip->keyboard_mode_enabled ^= 1;
|
|
|
|
|
|
|
|
|
|
if (tooltip->keyboard_mode_enabled)
|
|
|
|
|
{
|
|
|
|
|
tooltip->keyboard_widget = g_object_ref (widget);
|
|
|
|
|
_gtk_tooltip_focus_in (widget);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (tooltip->keyboard_widget)
|
|
|
|
|
{
|
|
|
|
|
g_object_unref (tooltip->keyboard_widget);
|
|
|
|
|
tooltip->keyboard_widget = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gtk_tooltip_hide_tooltip (tooltip);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
_gtk_tooltip_hide (GtkWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *toplevel;
|
|
|
|
|
GdkDisplay *display;
|
|
|
|
|
GtkTooltip *tooltip;
|
|
|
|
|
|
|
|
|
|
display = gtk_widget_get_display (widget);
|
|
|
|
|
tooltip = g_object_get_data (G_OBJECT (display),
|
|
|
|
|
"gdk-display-current-tooltip");
|
|
|
|
|
|
|
|
|
|
if (!tooltip || !GTK_TOOLTIP_VISIBLE (tooltip) || !tooltip->tooltip_widget)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
toplevel = gtk_widget_get_toplevel (widget);
|
|
|
|
|
|
|
|
|
|
if (widget == tooltip->tooltip_widget
|
2010-08-11 20:51:01 +00:00
|
|
|
|
|| gtk_widget_get_window (toplevel) == tooltip->toplevel_window)
|
2007-02-06 10:25:21 +00:00
|
|
|
|
gtk_tooltip_hide_tooltip (tooltip);
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-02 09:32:14 +00:00
|
|
|
|
static gboolean
|
2011-11-26 19:28:53 +00:00
|
|
|
|
tooltips_enabled (GdkEvent *event)
|
2008-07-02 09:32:14 +00:00
|
|
|
|
{
|
2011-11-26 19:28:53 +00:00
|
|
|
|
GdkDevice *source_device;
|
|
|
|
|
GdkInputSource source;
|
2008-07-02 09:32:14 +00:00
|
|
|
|
|
2011-11-26 19:28:53 +00:00
|
|
|
|
source_device = gdk_event_get_source_device (event);
|
|
|
|
|
|
|
|
|
|
if (!source_device)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
source = gdk_device_get_source (source_device);
|
2008-07-02 09:32:14 +00:00
|
|
|
|
|
2013-06-30 18:28:02 +00:00
|
|
|
|
if (source != GDK_SOURCE_TOUCHSCREEN)
|
2011-11-26 19:28:53 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
2008-07-02 09:32:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-02-06 10:25:21 +00:00
|
|
|
|
void
|
|
|
|
|
_gtk_tooltip_handle_event (GdkEvent *event)
|
|
|
|
|
{
|
|
|
|
|
gint x, y;
|
|
|
|
|
gboolean return_value = FALSE;
|
|
|
|
|
GtkWidget *has_tooltip_widget = NULL;
|
|
|
|
|
GdkDisplay *display;
|
|
|
|
|
GtkTooltip *current_tooltip;
|
2007-08-07 11:28:01 +00:00
|
|
|
|
|
2011-11-26 19:28:53 +00:00
|
|
|
|
if (!tooltips_enabled (event))
|
2007-08-07 11:28:01 +00:00
|
|
|
|
return;
|
2007-02-06 10:25:21 +00:00
|
|
|
|
|
2007-08-21 10:52:43 +00:00
|
|
|
|
/* Returns coordinates relative to has_tooltip_widget's allocation. */
|
2007-02-06 10:25:21 +00:00
|
|
|
|
has_tooltip_widget = find_topmost_widget_coords_from_event (event, &x, &y);
|
2010-08-29 00:08:24 +00:00
|
|
|
|
display = gdk_window_get_display (event->any.window);
|
2007-02-06 10:25:21 +00:00
|
|
|
|
current_tooltip = g_object_get_data (G_OBJECT (display),
|
|
|
|
|
"gdk-display-current-tooltip");
|
|
|
|
|
|
|
|
|
|
if (current_tooltip)
|
|
|
|
|
{
|
2007-12-17 15:33:45 +00:00
|
|
|
|
gtk_tooltip_set_last_window (current_tooltip, event->any.window);
|
2007-02-06 10:25:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (current_tooltip && current_tooltip->keyboard_mode_enabled)
|
|
|
|
|
{
|
|
|
|
|
has_tooltip_widget = current_tooltip->keyboard_widget;
|
|
|
|
|
if (!has_tooltip_widget)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
return_value = gtk_tooltip_run_requery (&has_tooltip_widget,
|
|
|
|
|
current_tooltip,
|
|
|
|
|
&x, &y);
|
|
|
|
|
|
|
|
|
|
if (!return_value)
|
|
|
|
|
gtk_tooltip_hide_tooltip (current_tooltip);
|
|
|
|
|
else
|
|
|
|
|
gtk_tooltip_start_delay (display);
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-21 10:52:43 +00:00
|
|
|
|
#ifdef DEBUG_TOOLTIP
|
|
|
|
|
if (has_tooltip_widget)
|
|
|
|
|
g_print ("%p (%s) at (%d, %d) %dx%d pointer: (%d, %d)\n",
|
|
|
|
|
has_tooltip_widget, gtk_widget_get_name (has_tooltip_widget),
|
|
|
|
|
has_tooltip_widget->allocation.x,
|
|
|
|
|
has_tooltip_widget->allocation.y,
|
|
|
|
|
has_tooltip_widget->allocation.width,
|
|
|
|
|
has_tooltip_widget->allocation.height,
|
|
|
|
|
x, y);
|
|
|
|
|
#endif /* DEBUG_TOOLTIP */
|
|
|
|
|
|
2007-02-06 10:25:21 +00:00
|
|
|
|
/* Always poll for a next motion event */
|
2007-02-06 14:53:35 +00:00
|
|
|
|
gdk_event_request_motions (&event->motion);
|
2007-02-06 10:25:21 +00:00
|
|
|
|
|
|
|
|
|
/* Hide the tooltip when there's no new tooltip widget */
|
|
|
|
|
if (!has_tooltip_widget)
|
|
|
|
|
{
|
2007-07-25 17:45:22 +00:00
|
|
|
|
if (current_tooltip)
|
2007-02-06 10:25:21 +00:00
|
|
|
|
gtk_tooltip_hide_tooltip (current_tooltip);
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (event->type)
|
|
|
|
|
{
|
|
|
|
|
case GDK_BUTTON_PRESS:
|
|
|
|
|
case GDK_2BUTTON_PRESS:
|
|
|
|
|
case GDK_3BUTTON_PRESS:
|
|
|
|
|
case GDK_KEY_PRESS:
|
|
|
|
|
case GDK_DRAG_ENTER:
|
|
|
|
|
case GDK_GRAB_BROKEN:
|
2011-05-01 14:38:56 +00:00
|
|
|
|
case GDK_SCROLL:
|
2007-02-06 10:25:21 +00:00
|
|
|
|
gtk_tooltip_hide_tooltip (current_tooltip);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GDK_MOTION_NOTIFY:
|
|
|
|
|
case GDK_ENTER_NOTIFY:
|
|
|
|
|
case GDK_LEAVE_NOTIFY:
|
|
|
|
|
if (current_tooltip)
|
|
|
|
|
{
|
2007-07-13 14:25:21 +00:00
|
|
|
|
gboolean tip_area_set;
|
|
|
|
|
GdkRectangle tip_area;
|
|
|
|
|
gboolean hide_tooltip;
|
|
|
|
|
|
|
|
|
|
tip_area_set = current_tooltip->tip_area_set;
|
|
|
|
|
tip_area = current_tooltip->tip_area;
|
|
|
|
|
|
2007-02-06 10:25:21 +00:00
|
|
|
|
return_value = gtk_tooltip_run_requery (&has_tooltip_widget,
|
|
|
|
|
current_tooltip,
|
|
|
|
|
&x, &y);
|
|
|
|
|
|
2007-07-13 14:25:21 +00:00
|
|
|
|
/* Requested to be hidden? */
|
|
|
|
|
hide_tooltip = !return_value;
|
|
|
|
|
|
2007-08-21 11:09:42 +00:00
|
|
|
|
/* Leave notify should override the query function */
|
|
|
|
|
hide_tooltip = (event->type == GDK_LEAVE_NOTIFY);
|
|
|
|
|
|
2007-07-13 14:25:21 +00:00
|
|
|
|
/* Is the pointer above another widget now? */
|
|
|
|
|
if (GTK_TOOLTIP_VISIBLE (current_tooltip))
|
|
|
|
|
hide_tooltip |= has_tooltip_widget != current_tooltip->tooltip_widget;
|
|
|
|
|
|
|
|
|
|
/* Did the pointer move out of the previous "context area"? */
|
|
|
|
|
if (tip_area_set)
|
|
|
|
|
hide_tooltip |= (x <= tip_area.x
|
|
|
|
|
|| x >= tip_area.x + tip_area.width
|
|
|
|
|
|| y <= tip_area.y
|
|
|
|
|
|| y >= tip_area.y + tip_area.height);
|
|
|
|
|
|
|
|
|
|
if (hide_tooltip)
|
2007-02-06 10:25:21 +00:00
|
|
|
|
gtk_tooltip_hide_tooltip (current_tooltip);
|
|
|
|
|
else
|
|
|
|
|
gtk_tooltip_start_delay (display);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Need a new tooltip for this display */
|
|
|
|
|
current_tooltip = g_object_new (GTK_TYPE_TOOLTIP, NULL);
|
|
|
|
|
g_object_set_data_full (G_OBJECT (display),
|
|
|
|
|
"gdk-display-current-tooltip",
|
|
|
|
|
current_tooltip, g_object_unref);
|
2007-10-08 12:39:02 +00:00
|
|
|
|
g_signal_connect (display, "closed",
|
|
|
|
|
G_CALLBACK (gtk_tooltip_display_closed),
|
|
|
|
|
current_tooltip);
|
2007-02-06 10:25:21 +00:00
|
|
|
|
|
2007-12-17 15:33:45 +00:00
|
|
|
|
gtk_tooltip_set_last_window (current_tooltip, event->any.window);
|
2007-02-06 10:25:21 +00:00
|
|
|
|
|
|
|
|
|
gtk_tooltip_start_delay (display);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|