#include "gtksizerequest.h"
+/**
+ * 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:
+ * <itemizedlist>
+ * <listitem>
+ * <para>
+ * 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.
+ * </para>
+ * </listitem>
+ * <listitem>
+ * <para>
+ * 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
+ * the tooltip's markup, setting an image from a stock icon, or even putting in
+ * a custom widget.
+ * </para>
+ * </listitem>
+ * <listitem>
+ * <para>
+ * Return %TRUE from your query-tooltip handler. This causes the tooltip to be
+ * show. If you return %FALSE, it will not be shown.
+ * </para>
+ * </listitem>
+ * </itemizedlist>
+ *
+ * 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:
+ * <itemizedlist>
+ * <listitem>
+ * <para>
+ * Set #GtkWidget:has-tooltip and connect to #GtkWidget::query-tooltip as
+ * before.
+ * </para>
+ * </listitem>
+ * <listitem>
+ * <para>
+ * Use gtk_widget_set_tooltip_window() to set a #GtkWindow created by you as
+ * tooltip window.
+ * </para>
+ * </listitem>
+ * <listitem>
+ * <para>
+ * 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.
+ * </para>
+ * </listitem>
+ * </itemizedlist>
+ */
+
+
#undef DEBUG_TOOLTIP
static void gtk_tooltip_dispose (GObject *object);
static void gtk_tooltip_window_style_set (GtkTooltip *tooltip);
-static gboolean gtk_tooltip_paint_window (GtkTooltip *tooltip);
+static gboolean gtk_tooltip_paint_window (GtkTooltip *tooltip,
+ cairo_t *cr);
static void gtk_tooltip_window_hide (GtkWidget *widget,
gpointer user_data);
static void gtk_tooltip_display_closed (GdkDisplay *display,
g_signal_connect_swapped (tooltip->window, "style-set",
G_CALLBACK (gtk_tooltip_window_style_set), tooltip);
- g_signal_connect_swapped (tooltip->window, "expose-event",
+ g_signal_connect_swapped (tooltip->window, "draw",
G_CALLBACK (gtk_tooltip_paint_window), tooltip);
- tooltip->box = gtk_hbox_new (FALSE, style->xthickness);
+ tooltip->box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, style->xthickness);
gtk_container_add (GTK_CONTAINER (tooltip->alignment), tooltip->box);
gtk_widget_show (tooltip->box);
}
static gboolean
-gtk_tooltip_paint_window (GtkTooltip *tooltip)
+gtk_tooltip_paint_window (GtkTooltip *tooltip,
+ cairo_t *cr)
{
- GtkAllocation allocation;
-
- gtk_widget_get_allocation (tooltip->window, &allocation);
gtk_paint_flat_box (gtk_widget_get_style (tooltip->window),
- gtk_widget_get_window (tooltip->window),
+ cr,
GTK_STATE_NORMAL,
GTK_SHADOW_OUT,
- NULL,
tooltip->window,
"tooltip",
0, 0,
- allocation.width, allocation.height);
+ gtk_widget_get_allocated_width (tooltip->window),
+ gtk_widget_get_allocated_height (tooltip->window));
return FALSE;
}
screen = gtk_widget_get_screen (new_tooltip_widget);
- gtk_size_request_get_size (GTK_SIZE_REQUEST (tooltip->current_window),
- &requisition, NULL);
+ gtk_widget_get_preferred_size (GTK_WIDGET (tooltip->current_window),
+ &requisition, NULL);
monitor_num = gdk_screen_get_monitor_at_point (screen,
tooltip->last_x,
GdkScreen *screen;
GtkSettings *settings;
- screen = gdk_drawable_get_screen (window);
+ screen = gdk_window_get_screen (window);
settings = gtk_settings_get_for_screen (screen);
g_object_get (settings,
/* Returns coordinates relative to has_tooltip_widget's allocation. */
has_tooltip_widget = find_topmost_widget_coords_from_event (event, &x, &y);
- display = gdk_drawable_get_display (event->any.window);
+ display = gdk_window_get_display (event->any.window);
current_tooltip = g_object_get_data (G_OBJECT (display),
"gdk-display-current-tooltip");