]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtktooltip.c
Deprecate widget flag: GTK_WIDGET_VISIBLE
[~andy/gtk] / gtk / gtktooltip.c
index f9d1b8ba70b42cc0f7f303cca96749e94070f090..87871e885cdf2f014c91ad80ca11ba892577fcc4 100644 (file)
@@ -19,7 +19,7 @@
  * Boston, MA 02111-1307, USA.
  */
 
-#include <config.h>
+#include "config.h"
 #include "gtktooltip.h"
 #include "gtkintl.h"
 #include "gtkwindow.h"
@@ -79,12 +79,12 @@ struct _GtkTooltipClass
   GObjectClass parent_class;
 };
 
-#define GTK_TOOLTIP_VISIBLE(tooltip) ((tooltip)->current_window && GTK_WIDGET_VISIBLE ((tooltip)->current_window))
+#define GTK_TOOLTIP_VISIBLE(tooltip) ((tooltip)->current_window && gtk_widget_get_visible (GTK_WIDGET((tooltip)->current_window)))
 
 
 static void       gtk_tooltip_class_init           (GtkTooltipClass *klass);
 static void       gtk_tooltip_init                 (GtkTooltip      *tooltip);
-static void       gtk_tooltip_finalize             (GObject         *object);
+static void       gtk_tooltip_dispose              (GObject         *object);
 
 static void       gtk_tooltip_window_style_set     (GtkTooltip      *tooltip);
 static gboolean   gtk_tooltip_paint_window         (GtkTooltip      *tooltip);
@@ -106,7 +106,7 @@ gtk_tooltip_class_init (GtkTooltipClass *klass)
 
   object_class = G_OBJECT_CLASS (klass);
 
-  object_class->finalize = gtk_tooltip_finalize;
+  object_class->dispose = gtk_tooltip_dispose;
 }
 
 static void
@@ -144,9 +144,9 @@ gtk_tooltip_init (GtkTooltip *tooltip)
   gtk_container_add (GTK_CONTAINER (tooltip->window), tooltip->alignment);
   gtk_widget_show (tooltip->alignment);
 
-  g_signal_connect_swapped (tooltip->window, "style_set",
+  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, "expose-event",
                            G_CALLBACK (gtk_tooltip_paint_window), tooltip);
 
   tooltip->box = gtk_hbox_new (FALSE, tooltip->window->style->xthickness);
@@ -166,7 +166,7 @@ gtk_tooltip_init (GtkTooltip *tooltip)
 }
 
 static void
-gtk_tooltip_finalize (GObject *object)
+gtk_tooltip_dispose (GObject *object)
 {
   GtkTooltip *tooltip = GTK_TOOLTIP (object);
 
@@ -182,6 +182,7 @@ gtk_tooltip_finalize (GObject *object)
       tooltip->browse_mode_timeout_id = 0;
     }
 
+  gtk_tooltip_set_custom (tooltip, NULL);
   gtk_tooltip_set_last_window (tooltip, NULL);
 
   if (tooltip->window)
@@ -193,9 +194,10 @@ gtk_tooltip_finalize (GObject *object)
                                            gtk_tooltip_display_closed,
                                            tooltip);
       gtk_widget_destroy (tooltip->window);
+      tooltip->window = NULL;
     }
 
-  G_OBJECT_CLASS (gtk_tooltip_parent_class)->finalize (object);
+  G_OBJECT_CLASS (gtk_tooltip_parent_class)->dispose (object);
 }
 
 /* public API */
@@ -203,7 +205,7 @@ gtk_tooltip_finalize (GObject *object)
 /**
  * gtk_tooltip_set_markup:
  * @tooltip: a #GtkTooltip
- * @markup: a markup string (see <link linkend="PangoMarkupFormat">Pango markup format</link>) or %NULL
+ * @markup: (allow-none): a markup string (see <link linkend="PangoMarkupFormat">Pango markup format</link>) or %NULL
  *
  * Sets the text of the tooltip to be @markup, which is marked up
  * with the <link
@@ -229,7 +231,7 @@ gtk_tooltip_set_markup (GtkTooltip  *tooltip,
 /**
  * gtk_tooltip_set_text:
  * @tooltip: a #GtkTooltip
- * @text: a text string or %NULL
+ * @text: (allow-none): a text string or %NULL
  *
  * Sets the text of the tooltip to be @text. If @text is %NULL, the label
  * will be hidden. See also gtk_tooltip_set_markup().
@@ -253,7 +255,7 @@ gtk_tooltip_set_text (GtkTooltip  *tooltip,
 /**
  * gtk_tooltip_set_icon:
  * @tooltip: a #GtkTooltip
- * @pixbuf: a #GdkPixbuf, or %NULL
+ * @pixbuf: (allow-none): a #GdkPixbuf, or %NULL
  *
  * 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.
@@ -279,8 +281,8 @@ gtk_tooltip_set_icon (GtkTooltip *tooltip,
 /**
  * gtk_tooltip_set_icon_from_stock:
  * @tooltip: a #GtkTooltip
- * @stock_id: a stock id, or %NULL
- * @size: a stock icon size
+ * @stock_id: (allow-none): a stock id, or %NULL
+ * @size: (type int): a stock icon size
  *
  * 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
@@ -306,8 +308,8 @@ gtk_tooltip_set_icon_from_stock (GtkTooltip  *tooltip,
 /**
  * gtk_tooltip_set_icon_from_icon_name:
  * @tooltip: a #GtkTooltip
- * @icon_name: an icon name, or %NULL
- * @size: a stock icon size
+ * @icon_name: (allow-none): an icon name, or %NULL
+ * @size: (type int): a stock icon size
  *
  * 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
@@ -316,9 +318,9 @@ gtk_tooltip_set_icon_from_stock (GtkTooltip  *tooltip,
  * Since: 2.14
  */
 void
-gtk_tooltip_set_icon_from_icon_name(GtkTooltip  *tooltip,
-                                   const gchar *icon_name,
-                                   GtkIconSize  size)
+gtk_tooltip_set_icon_from_icon_name (GtkTooltip  *tooltip,
+                                    const gchar *icon_name,
+                                    GtkIconSize  size)
 {
   g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
 
@@ -330,15 +332,45 @@ gtk_tooltip_set_icon_from_icon_name(GtkTooltip  *tooltip,
     gtk_widget_hide (tooltip->image);
 }
 
+/**
+ * gtk_tooltip_set_icon_from_gicon:
+ * @tooltip: a #GtkTooltip
+ * @gicon: (allow-none): a #GIcon representing the icon, or %NULL
+ * @size: (type int): a stock icon size
+ *
+ * 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.
+ *
+ * Since: 2.20
+ */
+void
+gtk_tooltip_set_icon_from_gicon (GtkTooltip  *tooltip,
+                                GIcon       *gicon,
+                                GtkIconSize  size)
+{
+  g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
+
+  gtk_image_set_from_gicon (GTK_IMAGE (tooltip->image), gicon, size);
+
+  if (gicon)
+    gtk_widget_show (tooltip->image);
+  else
+    gtk_widget_hide (tooltip->image);
+}
+
 /**
  * gtk_tooltip_set_custom:
  * @tooltip: a #GtkTooltip
- * @custom_widget: a #GtkWidget
+ * @custom_widget: (allow-none): a #GtkWidget, or %NULL to unset the old custom widget.
  *
- * Replaces the widget packed into the tooltip with @custom_widget.  
+ * Replaces the widget packed into the tooltip with
+ * @custom_widget. @custom_widget does not get destroyed when the tooltip goes
+ * away.
  * 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().
+
  *
  * Since: 2.12
  */
@@ -440,6 +472,10 @@ gtk_tooltip_trigger_tooltip_query (GdkDisplay *display)
   event.motion.y = y;
   event.motion.is_hint = FALSE;
 
+  gdk_window_get_origin (window, &x, &y);
+  event.motion.x_root = event.motion.x + x;
+  event.motion.y_root = event.motion.y + y;
+
   _gtk_tooltip_handle_event (&event);
 }
 
@@ -466,6 +502,8 @@ gtk_tooltip_window_style_set (GtkTooltip *tooltip)
                             tooltip->window->style->ythickness,
                             tooltip->window->style->xthickness,
                             tooltip->window->style->xthickness);
+  gtk_box_set_spacing (GTK_BOX (tooltip->box),
+                      tooltip->window->style->xthickness);
 
   gtk_widget_queue_draw (tooltip->window);
 }
@@ -515,9 +553,12 @@ child_location_foreach (GtkWidget *child,
   struct ChildLocation *child_loc = data;
 
   /* Ignore invisible widgets */
-  if (!GTK_WIDGET_DRAWABLE (child))
+  if (!gtk_widget_is_drawable (child))
     return;
 
+  x = 0;
+  y = 0;
+
   /* (child_loc->x, child_loc->y) are relative to
    * child_loc->container's allocation.
    */
@@ -578,7 +619,7 @@ window_to_alloc (GtkWidget *dest_widget,
                 gint      *dest_y)
 {
   /* Translate from window relative to allocation relative */
-  if (!GTK_WIDGET_NO_WINDOW (dest_widget) && dest_widget->parent)
+  if (gtk_widget_get_has_window (dest_widget) && dest_widget->parent)
     {
       gint wx, wy;
       gdk_window_get_position (dest_widget->window, &wx, &wy);
@@ -756,6 +797,9 @@ static void
 gtk_tooltip_set_last_window (GtkTooltip *tooltip,
                             GdkWindow  *window)
 {
+  if (tooltip->last_window == window)
+    return;
+
   if (tooltip->last_window)
     g_object_remove_weak_pointer (G_OBJECT (tooltip->last_window),
                                  (gpointer *) &tooltip->last_window);
@@ -830,7 +874,7 @@ gtk_tooltip_position (GtkTooltip *tooltip,
   if (tooltip->keyboard_mode_enabled)
     {
       gdk_window_get_origin (new_tooltip_widget->window, &x, &y);
-      if (GTK_WIDGET_NO_WINDOW (new_tooltip_widget))
+      if (!gtk_widget_get_has_window (new_tooltip_widget))
         {
          x += new_tooltip_widget->allocation.x;
          y += new_tooltip_widget->allocation.y;
@@ -911,6 +955,7 @@ gtk_tooltip_show_tooltip (GdkDisplay *display)
 
   if (tooltip->keyboard_mode_enabled)
     {
+      x = y = -1;
       pointer_widget = tooltip_widget = tooltip->keyboard_widget;
     }
   else
@@ -933,8 +978,6 @@ gtk_tooltip_show_tooltip (GdkDisplay *display)
 
   g_object_get (tooltip_widget, "has-tooltip", &has_tooltip, NULL);
 
-  g_assert (tooltip != NULL);
-
   return_value = gtk_tooltip_run_requery (&tooltip_widget, tooltip, &x, &y);
   if (!return_value)
     return;
@@ -1036,11 +1079,17 @@ tooltip_popup_timeout (gpointer data)
   GtkTooltip *tooltip;
 
   display = GDK_DISPLAY_OBJECT (data);
+  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;
 
   gtk_tooltip_show_tooltip (display);
 
-  tooltip = g_object_get_data (G_OBJECT (display),
-                              "gdk-display-current-tooltip");
   tooltip->timeout_id = 0;
 
   return FALSE;
@@ -1056,7 +1105,7 @@ gtk_tooltip_start_delay (GdkDisplay *display)
   tooltip = g_object_get_data (G_OBJECT (display),
                               "gdk-display-current-tooltip");
 
-  if (tooltip && GTK_TOOLTIP_VISIBLE (tooltip))
+  if (!tooltip || GTK_TOOLTIP_VISIBLE (tooltip))
     return;
 
   if (tooltip->timeout_id)
@@ -1201,24 +1250,35 @@ _gtk_tooltip_hide (GtkWidget *widget)
     gtk_tooltip_hide_tooltip (tooltip);
 }
 
+static gboolean
+tooltips_enabled (GdkWindow *window)
+{
+  gboolean enabled;
+  gboolean touchscreen;
+  GdkScreen *screen;
+  GtkSettings *settings;
+
+  screen = gdk_drawable_get_screen (window);
+  settings = gtk_settings_get_for_screen (screen);
+
+  g_object_get (settings,
+               "gtk-touchscreen-mode", &touchscreen,
+               "gtk-enable-tooltips", &enabled,
+               NULL);
+
+  return (!touchscreen && enabled);
+}
+
 void
 _gtk_tooltip_handle_event (GdkEvent *event)
 {
   gint x, y;
   gboolean return_value = FALSE;
-  gboolean touchscreen;
   GtkWidget *has_tooltip_widget = NULL;
-  GdkScreen *screen;
   GdkDisplay *display;
   GtkTooltip *current_tooltip;
-  GtkSettings *settings;
-
-  /* Disable tooltips in touchscreen mode */
-  screen = gdk_drawable_get_screen (event->any.window);
-  settings = gtk_settings_get_for_screen (screen);
-  g_object_get (settings, "gtk-touchscreen-mode", &touchscreen, NULL);
 
-  if (touchscreen)
+  if (!tooltips_enabled (event->any.window))
     return;
 
   /* Returns coordinates relative to has_tooltip_widget's allocation. */