Re: Proposal for new tooltips API



Hi,

On Wed, 2006-01-25 at 21:18 +0100, Kristian Rietveld wrote:
> Hello,

Kris, sorry, I've been forgetting repeatedly sending this... I've
attached my half-arsed attempt to implementing Owen's proposal, never
got it to do something better than displaying tooltips like crazy, but I
hope that it will at least save you some work (IIRC, GtkTooltipsGroup
was implemented, and GtkTooltipsWindow was already able to show some
stuff)

	Regards

Index: Makefile.am
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/Makefile.am,v
retrieving revision 1.290
diff -u -r1.290 Makefile.am
--- Makefile.am	18 Jan 2006 22:39:13 -0000	1.290
+++ Makefile.am	25 Jan 2006 23:16:02 -0000
@@ -263,6 +263,8 @@
 	gtktoolbutton.h		\
 	gtktoolitem.h		\
 	gtktooltips.h		\
+	gtktooltipsgroup.h	\
+	gtktooltipswindow.h	\
 	gtktree.h		\
 	gtktreednd.h		\
 	gtktreeitem.h		\
@@ -502,6 +504,8 @@
 	gtktoolbutton.c		\
 	gtktoolitem.c		\
 	gtktooltips.c		\
+	gtktooltipsgroup.c	\
+	gtktooltipswindow.c	\
 	gtktree.c		\
 	gtktreedatalist.c	\
 	gtktreednd.c		\
Index: gtk.h
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtk.h,v
retrieving revision 1.79
diff -u -r1.79 gtk.h
--- gtk.h	18 Jan 2006 22:39:13 -0000	1.79
+++ gtk.h	25 Jan 2006 23:16:02 -0000
@@ -168,6 +168,8 @@
 #include <gtk/gtktoolbutton.h>
 #include <gtk/gtktoolitem.h>
 #include <gtk/gtktooltips.h>
+#include <gtk/gtktooltipsgroup.h>
+#include <gtk/gtktooltipswindow.h>
 #include <gtk/gtktree.h>
 #include <gtk/gtktreednd.h>
 #include <gtk/gtktreeitem.h>
Index: gtkwidget.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkwidget.c,v
retrieving revision 1.421
diff -u -r1.421 gtkwidget.c
--- gtkwidget.c	12 Jan 2006 18:43:35 -0000	1.421
+++ gtkwidget.c	25 Jan 2006 23:16:06 -0000
@@ -1,3 +1,4 @@
+/* -*- Mode: C; c-file-style: "gnu"; tab-width: 8 -*- */
 /* GTK - The GIMP Toolkit
  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
  *
@@ -51,6 +52,7 @@
 #include "gtkintl.h"
 #include "gtkaccessible.h"
 #include "gtktooltips.h"
+#include "gtktooltipswindow.h"
 #include "gtkinvisible.h"
 #include "gtkalias.h"
 
@@ -197,6 +199,10 @@
 								 GdkEventKey      *event);
 static gboolean		gtk_widget_real_key_release_event 	(GtkWidget        *widget,
 								 GdkEventKey      *event);
+static gboolean         gtk_widget_real_enter_notify_event      (GtkWidget        *widget,
+								 GdkEventCrossing *event);
+static gboolean         gtk_widget_real_leave_notify_event      (GtkWidget        *widget,
+								 GdkEventCrossing *event);
 static gboolean		gtk_widget_real_focus_in_event   	 (GtkWidget       *widget,
 								  GdkEventFocus   *event);
 static gboolean		gtk_widget_real_focus_out_event   	(GtkWidget        *widget,
@@ -255,6 +261,7 @@
 static GQuark		quark_rc_style = 0;
 static GQuark		quark_accessible_object = 0;
 static GQuark		quark_mnemonic_labels = 0;
+static GQuark           quark_tooltips_window = 0;
 GParamSpecPool         *_gtk_widget_child_property_pool = NULL;
 GObjectNotifyContext   *_gtk_widget_child_property_notify_context = NULL;
 
@@ -329,6 +336,7 @@
   quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
   quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
   quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
+  quark_tooltips_window = g_quark_from_static_string ("gtk-tooltips-window");
 
   style_property_spec_pool = g_param_spec_pool_new (FALSE);
   _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
@@ -375,8 +383,8 @@
   klass->expose_event = NULL;
   klass->key_press_event = gtk_widget_real_key_press_event;
   klass->key_release_event = gtk_widget_real_key_release_event;
-  klass->enter_notify_event = NULL;
-  klass->leave_notify_event = NULL;
+  klass->enter_notify_event = gtk_widget_real_enter_notify_event;
+  klass->leave_notify_event = gtk_widget_real_leave_notify_event;
   klass->configure_event = NULL;
   klass->focus_in_event = gtk_widget_real_focus_in_event;
   klass->focus_out_event = gtk_widget_real_focus_out_event;
@@ -3481,6 +3489,53 @@
 }
 
 static gboolean
+gtk_widget_real_enter_notify_event (GtkWidget        *widget,
+				    GdkEventCrossing *event)
+{
+  GtkTooltipsWindow *tooltips_window;
+
+  if (event->detail == GDK_NOTIFY_INFERIOR)
+    return FALSE;
+
+  tooltips_window = gtk_widget_get_tooltips_window (widget);
+
+  gtk_tooltips_window_set_markup (tooltips_window,
+				GTK_TOOLTIPS_MOUSE,
+				G_OBJECT (widget),
+				"no way!");
+
+  gtk_tooltips_window_set_area (tooltips_window,
+				GTK_TOOLTIPS_MOUSE,
+				G_OBJECT (widget),
+				widget->window,
+				widget->allocation.x,
+				widget->allocation.y,
+				widget->allocation.width,
+				widget->allocation.height);
+
+  gtk_tooltips_window_begin (tooltips_window,
+			     GTK_TOOLTIPS_MOUSE,
+			     G_OBJECT (widget));
+  return FALSE;
+}
+
+static gboolean
+gtk_widget_real_leave_notify_event (GtkWidget        *widget,
+				    GdkEventCrossing *event)
+{
+  GtkTooltipsWindow *tooltips_window;
+
+  if (event->detail == GDK_NOTIFY_INFERIOR)
+    return TRUE;
+
+  tooltips_window = gtk_widget_get_tooltips_window (widget);
+  gtk_tooltips_window_end (tooltips_window,
+			   GTK_TOOLTIPS_MOUSE,
+			   G_OBJECT (widget));
+  return TRUE;
+}
+
+static gboolean
 gtk_widget_real_focus_in_event (GtkWidget     *widget,
                                 GdkEventFocus *event)
 {
@@ -4125,7 +4180,31 @@
 {
   if (help_type == GTK_WIDGET_HELP_TOOLTIP)
     {
+      /*
+      GtkTooltipsWindow *tooltips_window;
+
+      tooltips_window = gtk_widget_get_tooltips_window (widget);
+
+      gtk_tooltips_window_set_markup (tooltips_window,
+				      GTK_TOOLTIPS_KEYBOARD,
+				      G_OBJECT (widget),
+				      "no way!");
+
+      gtk_tooltips_window_set_area (tooltips_window,
+				    GTK_TOOLTIPS_KEYBOARD,
+				    G_OBJECT (widget),
+				    widget->window,
+				    widget->allocation.x,
+				    widget->allocation.y,
+				    widget->allocation.width,
+				    widget->allocation.height);
+
+      gtk_tooltips_window_begin (tooltips_window,
+				 GTK_TOOLTIPS_KEYBOARD,
+				 G_OBJECT (widget));
+      */
       _gtk_tooltips_toggle_keyboard_mode (widget);
+
       return TRUE;
     }
   else
@@ -7776,6 +7855,45 @@
     GTK_WIDGET_UNSET_FLAGS (widget, GTK_NO_SHOW_ALL);
   
   g_object_notify (G_OBJECT (widget), "no-show-all");
+}
+
+/**
+ * gtk_widget_get_tooltips_window:
+ * @widget: a #GtkWidget
+ *
+ * Gets the #GtkTooltipsWindow object associated to the toplevel window
+ * that contains this #GtkWidget. #GtkTooltipsWindow will be a per toplevel
+ * window singleton.
+ *
+ * Return value: the #GtkTooltipsWindow object.
+ **/
+GtkTooltipsWindow *
+gtk_widget_get_tooltips_window (GtkWidget *widget)
+{
+  GtkWidget *toplevel;
+  GtkTooltipsWindow *tooltips_window;
+
+  g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
+
+  if (!GTK_WIDGET_TOPLEVEL (widget))
+    toplevel = gtk_widget_get_toplevel (widget);
+  else
+    toplevel = widget;
+
+  g_return_val_if_fail (GTK_IS_WIDGET (toplevel), NULL);
+
+  tooltips_window = g_object_get_qdata (G_OBJECT (toplevel),
+					quark_tooltips_window);
+  if (!tooltips_window)
+    {
+      tooltips_window = g_object_new (GTK_TYPE_TOOLTIPS_WINDOW, NULL);
+      g_object_set_qdata_full (G_OBJECT (toplevel),
+			       quark_tooltips_window,
+			       tooltips_window,
+			       (GDestroyNotify) g_object_unref);
+    }
+
+  return tooltips_window;
 }
 
 #define __GTK_WIDGET_C__
Index: gtkwidget.h
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkwidget.h,v
retrieving revision 1.157
diff -u -r1.157 gtkwidget.h
--- gtkwidget.h	26 Jul 2005 15:02:23 -0000	1.157
+++ gtkwidget.h	25 Jan 2006 23:16:07 -0000
@@ -33,6 +33,7 @@
 #include <gtk/gtkadjustment.h>
 #include <gtk/gtkstyle.h>
 #include <gtk/gtksettings.h>
+#include <gtk/gtktooltipswindow.h>
 #include <atk/atkobject.h>
 
 G_BEGIN_DECLS
@@ -599,6 +600,8 @@
 GtkSettings*  gtk_widget_get_settings    (GtkWidget *widget);
 GtkClipboard *gtk_widget_get_clipboard   (GtkWidget *widget,
 					  GdkAtom    selection);
+
+GtkTooltipsWindow*  gtk_widget_get_tooltips_window  (GtkWidget *widget);
 
 #ifndef GTK_DISABLE_DEPRECATED
 #define gtk_widget_set_visual(widget,visual)  ((void) 0)
Index: gtktooltipswindow.c
===================================================================
RCS file: gtktooltipswindow.c
diff -N gtktooltipswindow.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gtktooltipswindow.c	25 Jan 2006 23:16:07 -0000
@@ -0,0 +1,428 @@
+/* -*- Mode: C; c-file-style: "gnu"; tab-width: 8 -*- */
+/* GTK - The GIMP Toolkit
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <config.h>
+#include "gdk/gdk.h"
+#include "gtkwidget.h"
+
+#include "gtktooltipswindow.h"
+#include "gtktooltipsgroup.h"
+#include "gtkwindow.h"
+#include "gtklabel.h"
+
+#define DEFAULT_DELAY 500           /* Default delay in ms */
+#define STICKY_DELAY 0              /* Delay before popping up next tip
+				     * if we're sticky
+				     */
+#define STICKY_REVERT_DELAY 1000    /* Delay before sticky tooltips revert
+				     * to normal
+				     */
+
+#define GTK_TOOLTIPS_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_TOOLTIPS_WINDOW, GtkTooltipsWindowPrivate))
+
+typedef struct _GtkTooltipsWindowPrivate GtkTooltipsWindowPrivate;
+
+struct _GtkTooltipsWindowPrivate
+{
+  guint      timeout_id;
+  GTimeVal   last_popdown;
+
+  GtkWidget *tip_window;
+  GtkWidget *tip_label;
+
+  gchar     *text;
+  gboolean   use_markup;
+
+  GtkTooltipsContext current_context;
+
+  /* coords for managing the tooltip position */
+  GdkWindow *relative_to;
+  gint x;
+  gint y;
+  gint width;
+  gint height;
+};
+
+static void gtk_tooltips_window_class_init (GtkTooltipsWindowClass *class);
+static void gtk_tooltips_window_init       (GtkTooltipsWindow *object);
+static void gtk_tooltips_window_finalize   (GObject *object);
+
+
+G_DEFINE_TYPE (GtkTooltipsWindow, gtk_tooltips_window, G_TYPE_OBJECT);
+
+
+static void
+gtk_tooltips_window_class_init (GtkTooltipsWindowClass *class)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+  object_class->finalize = gtk_tooltips_window_finalize;
+
+  g_type_class_add_private (object_class,
+			    sizeof (GtkTooltipsWindowPrivate));
+}
+
+static void
+gtk_tooltips_window_init (GtkTooltipsWindow *window)
+{
+  GtkTooltipsWindowPrivate *priv;
+
+  priv = GTK_TOOLTIPS_WINDOW_GET_PRIVATE (window);
+
+  priv->timeout_id = 0;
+  priv->last_popdown.tv_sec = -1;
+  priv->last_popdown.tv_usec = -1;
+
+  priv->tip_window = NULL;
+  priv->tip_label  = NULL;
+
+  priv->text = NULL;
+  priv->relative_to = NULL;
+}
+
+static void
+gtk_tooltips_window_finalize (GObject *object)
+{
+  (* G_OBJECT_CLASS (gtk_tooltips_window_parent_class)->finalize) (object);
+}
+
+static gint
+gtk_tooltips_window_paint_window (GtkTooltipsWindow *window)
+{
+  GtkTooltipsWindowPrivate *priv;
+  GtkRequisition req;
+
+  g_return_if_fail (GTK_IS_TOOLTIPS_WINDOW (window));
+
+  priv = GTK_TOOLTIPS_WINDOW_GET_PRIVATE (window);
+
+  gtk_widget_size_request (priv->tip_window, &req);
+  gtk_paint_flat_box (priv->tip_window->style, priv->tip_window->window,
+		      GTK_STATE_NORMAL, GTK_SHADOW_OUT, 
+		      NULL, GTK_WIDGET(priv->tip_window), "tooltip",
+		      0, 0, req.width, req.height);
+  return FALSE;
+}
+
+static void
+gtk_tooltips_window_force_window (GtkTooltipsWindow *window)
+{
+  GtkTooltipsWindowPrivate *priv;
+
+  g_return_if_fail (GTK_IS_TOOLTIPS_WINDOW (window));
+
+  priv = GTK_TOOLTIPS_WINDOW_GET_PRIVATE (window);
+
+  if (!priv->tip_window)
+    {
+      priv->tip_window = gtk_window_new (GTK_WINDOW_POPUP);
+      /* gtk_tooltips_update_screen (tooltips, TRUE); */
+      gtk_widget_set_app_paintable (priv->tip_window, TRUE);
+      gtk_window_set_resizable (GTK_WINDOW (priv->tip_window), FALSE);
+      gtk_widget_set_name (priv->tip_window, "gtk-tooltips");
+      gtk_container_set_border_width (GTK_CONTAINER (priv->tip_window), 4);
+
+      g_signal_connect_swapped (priv->tip_window,
+				"expose_event",
+				G_CALLBACK (gtk_tooltips_window_paint_window),
+				window);
+
+      priv->tip_label = gtk_label_new (NULL);
+      gtk_label_set_line_wrap (GTK_LABEL (priv->tip_label), TRUE);
+      gtk_misc_set_alignment (GTK_MISC (priv->tip_label), 0.5, 0.5);
+      gtk_widget_show (priv->tip_label);
+      
+      gtk_container_add (GTK_CONTAINER (priv->tip_window), priv->tip_label);
+
+      g_signal_connect (priv->tip_window,
+			"destroy",
+			G_CALLBACK (gtk_widget_destroyed),
+			&priv->tip_window);
+    }
+}
+
+static void
+gtk_tooltips_window_draw_tips (GtkTooltipsWindow *window)
+{
+  GtkTooltipsWindowPrivate *priv;
+  GtkRequisition requisition;
+  gint x, y, w, h;
+  GdkScreen *screen;
+  GdkScreen *pointer_screen;
+  gint monitor_num, px, py;
+  GdkRectangle monitor;
+
+  priv = GTK_TOOLTIPS_WINDOW_GET_PRIVATE (window);
+
+  if (!priv->tip_window)
+    gtk_tooltips_window_force_window (window);
+  else if (GTK_WIDGET_VISIBLE (priv->tip_window))
+    g_get_current_time (&priv->last_popdown);
+
+  gtk_widget_ensure_style (priv->tip_window);
+
+  /*
+  gtk_tooltips_update_screen (tooltips, FALSE);
+  */
+  
+  screen = gdk_drawable_get_screen (GDK_DRAWABLE (priv->relative_to));
+
+  /*
+  data = tooltips->active_tips_data;
+  */
+
+  if (priv->use_markup)
+    gtk_label_set_markup (GTK_LABEL (priv->tip_label), priv->text);
+  else
+    gtk_label_set_text (GTK_LABEL (priv->tip_label), priv->text);
+    
+  gtk_widget_size_request (priv->tip_window, &requisition);
+  w = requisition.width;
+  h = requisition.height;
+
+  if (priv->current_context == GTK_TOOLTIPS_KEYBOARD)
+    {
+      gdk_window_get_origin (priv->relative_to, &x, &y);
+      /*
+      x += priv->x + (priv->width / 2);
+      y += priv->y;
+      */
+    }
+  else
+    {
+      gdk_window_get_origin (priv->relative_to, NULL, &y);
+      gdk_window_get_pointer (gdk_screen_get_root_window (screen),
+			      &x, NULL, NULL);
+    }
+
+  x -= (w / 2 + 4);
+
+  gdk_display_get_pointer (gdk_screen_get_display (screen),
+			   &pointer_screen, &px, &py, NULL);
+
+  if (pointer_screen != screen) 
+    {
+      px = x;
+      py = y;
+    }
+
+  monitor_num = gdk_screen_get_monitor_at_point (screen, px, py);
+  gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
+
+  if ((x + w) > monitor.x + monitor.width)
+    x -= (x + w) - (monitor.x + monitor.width);
+  else if (x < monitor.x)
+    x = monitor.x;
+
+  if ((y + h + priv->height + 4) > monitor.y + monitor.height)
+    y = y - h - 4;
+  else
+    y = y + priv->height + 4;
+
+  gtk_window_move (GTK_WINDOW (priv->tip_window), x, y);
+  gtk_widget_show (priv->tip_window);
+}
+
+static gint
+gtk_tooltips_window_timeout (gpointer data)
+{
+  GtkTooltipsWindow *window = (GtkTooltipsWindow *) data;
+
+  GDK_THREADS_ENTER ();
+  /*  
+  if (tooltips->active_tips_data != NULL &&
+      GTK_WIDGET_DRAWABLE (tooltips->active_tips_data->widget))
+  */
+
+  gtk_tooltips_window_draw_tips (window);
+
+  GDK_THREADS_LEAVE ();
+
+  return FALSE;
+}
+
+static gboolean
+tooltip_recently_shown (GtkTooltipsWindow *tooltips_window)
+{
+  GtkTooltipsWindowPrivate *priv;
+  GTimeVal now;
+  glong msec;
+  
+  priv = GTK_TOOLTIPS_WINDOW_GET_PRIVATE (tooltips_window);
+
+  g_get_current_time (&now);
+  msec = (now.tv_sec  - priv->last_popdown.tv_sec) * 1000 +
+	  (now.tv_usec - priv->last_popdown.tv_usec) / 1000;
+
+  return (msec < STICKY_REVERT_DELAY);
+}
+
+static void
+gtk_tooltips_window_remove_tip (GtkTooltipsWindow *window)
+{
+  GtkTooltipsWindowPrivate *priv;
+
+  priv = GTK_TOOLTIPS_WINDOW_GET_PRIVATE (window);
+
+  if (priv->tip_window)
+    {
+      if (GTK_WIDGET_VISIBLE (priv->tip_window))
+	g_get_current_time (&priv->last_popdown);
+
+      gtk_widget_hide (priv->tip_window);
+    }
+
+  if (priv->timeout_id)
+    {
+      g_source_remove (priv->timeout_id);
+      priv->timeout_id = 0;
+    }
+}
+
+void
+gtk_tooltips_window_begin (GtkTooltipsWindow *tooltips_window,
+			   GtkTooltipsContext context,
+			   GObject           *owner)
+{
+  GtkTooltipsWindowPrivate *priv;
+  guint delay;
+
+  g_return_if_fail (GTK_IS_TOOLTIPS_WINDOW (tooltips_window));
+
+  priv = GTK_TOOLTIPS_WINDOW_GET_PRIVATE (tooltips_window);
+
+  gtk_tooltips_window_remove_tip (tooltips_window);
+
+  if (tooltip_recently_shown (tooltips_window))
+    delay = STICKY_DELAY;
+  else
+    delay = DEFAULT_DELAY;
+
+  priv->current_context = context;
+  priv->timeout_id = g_timeout_add (delay,
+				    gtk_tooltips_window_timeout,
+				    tooltips_window);
+}
+
+void
+gtk_tooltips_window_end (GtkTooltipsWindow *window,
+			 GtkTooltipsContext context,
+			 GObject           *owner)
+{
+  g_return_if_fail (GTK_IS_TOOLTIPS_WINDOW (window));
+
+  gtk_tooltips_window_remove_tip (window);
+}
+
+static void
+set_text_and_markup (GtkTooltipsWindow *window,
+		     const gchar       *text,
+		     gboolean           use_markup)
+{
+  GtkTooltipsWindowPrivate *priv;
+
+  g_return_if_fail (GTK_IS_TOOLTIPS_WINDOW (window));
+
+  priv = GTK_TOOLTIPS_WINDOW_GET_PRIVATE (window);
+  priv->use_markup = use_markup;
+
+  if (text)
+    {
+      g_free (priv->text);
+      priv->text = g_strdup (text);
+    }
+  else
+    priv->text = NULL;
+}
+
+void
+gtk_tooltips_window_set_text (GtkTooltipsWindow  *window,
+			      GtkTooltipsContext  context,
+			      GObject            *owner,
+			      const char         *text)
+{
+  set_text_and_markup (window, text, FALSE);
+}
+
+void
+gtk_tooltips_window_set_markup (GtkTooltipsWindow  *window,
+				GtkTooltipsContext  context,
+				GObject            *owner,
+				const char         *markup)
+{
+  set_text_and_markup (window, markup, TRUE);
+}
+
+void
+gtk_tooltips_window_set_area (GtkTooltipsWindow  *window,
+			      GtkTooltipsContext  context,
+			      GObject            *owner,
+			      GdkWindow          *relative_to,
+			      int x, int y, int width, int height)
+{
+  GtkTooltipsWindowPrivate *priv;
+
+  g_return_if_fail (GTK_IS_TOOLTIPS_WINDOW (window));
+
+  priv = GTK_TOOLTIPS_WINDOW_GET_PRIVATE (window);
+
+  priv->relative_to = relative_to;
+  priv->x      = x;
+  priv->y      = y;
+  priv->width  = width;
+  priv->height = height;
+}
+
+/*
+void
+gtk_tooltips_window_set_group (GtkTooltipsWindow  *window,
+			       GtkTooltipsContext  context,
+			       GObject            *owner,
+			       GtkTooltipsGroup    group)
+{
+
+}
+*/
+
+
+/*
+static void
+on_widget_event_handler (GtkWidget *widget,
+			 GdkEvent  *event)
+{
+  GtkTooltipsWindow *tooltips_window;
+
+  tooltips_window = gtk_widget_get_tooltips_window (widget);
+
+  
+}
+
+void
+gtk_tooltips_window_prepare_widget (GtkWidget *widget)
+{
+  g_return_if_fail (GTK_IS_WIDGET (widget));
+
+  g_signal_connect_after (G_OBJECT (object), "event-after",
+			  G_CALLBACK (on_widget_event_handler), NULL);
+}
+*/
+
+
+#define __GTK_TOOLTIPS_WINDOW_C__
+#include "gtkaliasdef.c"
Index: gtktooltipswindow.h
===================================================================
RCS file: gtktooltipswindow.h
diff -N gtktooltipswindow.h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gtktooltipswindow.h	25 Jan 2006 23:16:07 -0000
@@ -0,0 +1,93 @@
+/* -*- Mode: C; c-file-style: "gnu"; tab-width: 8 -*- */
+/* GTK - The GIMP Toolkit
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __GTK_TOOLTIPS_WINDOW_H__
+#define __GTK_TOOLTIPS_WINDOW_H__
+
+#include <gtk/gtktooltipsgroup.h>
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_TOOLTIPS_WINDOW            (gtk_tooltips_window_get_type ())
+#define GTK_TOOLTIPS_WINDOW(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_TOOLTIPS_WINDOW, GtkTooltipsWindow))
+#define GTK_TOOLTIPS_WINDOW_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass),  GTK_TYPE_TOOLTIPS_WINDOW, GtkTooltipsWindowClass))
+#define GTK_IS_TOOLTIPS_WINDOW(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_TOOLTIPS_WINDOW))
+#define GTK_IS_TOOLTIPS_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),  GTK_TYPE_TOOLTIPS_WINDOW))
+#define GTK_TOOLTIPS_WINDOW_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),  GTK_TYPE_TOOLTIPS_WINDOW, GtkTooltipsWindowClass))
+
+typedef enum {
+  GTK_TOOLTIPS_MOUSE,
+  GTK_TOOLTIPS_KEYBOARD
+} GtkTooltipsContext;
+
+
+typedef struct _GtkTooltipsWindow      GtkTooltipsWindow;
+typedef struct _GtkTooltipsWindowClass GtkTooltipsWindowClass;
+
+struct _GtkTooltipsWindow
+{
+  GObject parent_instance;
+};
+
+struct _GtkTooltipsWindowClass
+{
+  GObjectClass parent_class;
+
+  /* Padding for future expansion */
+  void (*_gtk_reserved1) (void);
+  void (*_gtk_reserved2) (void);
+  void (*_gtk_reserved3) (void);
+  void (*_gtk_reserved4) (void);
+};
+
+
+GType  gtk_tooltips_window_get_type (void) G_GNUC_CONST;
+
+void   gtk_tooltips_window_begin (GtkTooltipsWindow *window,
+				  GtkTooltipsContext context,
+				  GObject           *owner);
+void   gtk_tooltips_window_end   (GtkTooltipsWindow *window,
+				  GtkTooltipsContext context,
+				  GObject           *owner);
+
+void   gtk_tooltips_window_set_text (GtkTooltipsWindow  *window,
+				     GtkTooltipsContext  context,
+				     GObject            *owner,
+				     const char         *text);
+void   gtk_tooltips_window_set_markup (GtkTooltipsWindow  *window,
+				       GtkTooltipsContext  context,
+				       GObject            *owner,
+				       const char         *markup);
+
+void   gtk_tooltips_window_set_area   (GtkTooltipsWindow  *window,
+				       GtkTooltipsContext  context,
+				       GObject            *owner,
+				       GdkWindow          *relative_to,
+				       int x, int y, int width, int height);
+
+/*
+void   gtk_tooltips_window_set_group  (GtkTooltipsWindow  *window,
+				       GtkTooltipsContext  context,
+				       GObject            *owner,
+				       GtkTooltipsGroup    group);
+*/
+
+G_END_DECLS
+
+#endif /* __GTK_TOOLTIPS_WINDOW_H__ */
Index: gtktooltipsgroup.c
===================================================================
RCS file: gtktooltipsgroup.c
diff -N gtktooltipsgroup.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gtktooltipsgroup.c	25 Jan 2006 23:16:07 -0000
@@ -0,0 +1,131 @@
+/* -*- Mode: C; c-file-style: "gnu"; tab-width: 8 -*- */
+/* GTK - The GIMP Toolkit
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <config.h>
+#include "gtkwidget.h"
+#include "gtktooltipsgroup.h"
+
+static void gtk_tooltips_group_class_init (GtkTooltipsGroupClass *class);
+static void gtk_tooltips_group_init       (GtkTooltipsGroup *object);
+static void gtk_tooltips_group_finalize   (GObject *object);
+
+
+#define TOOLTIPS_GROUPS_TAG "gtk-tooltips-groups"
+
+static GQuark tooltips_groups_quark;
+
+
+G_DEFINE_TYPE (GtkTooltipsGroup, gtk_tooltips_group, G_TYPE_OBJECT);
+
+static void
+gtk_tooltips_group_class_init (GtkTooltipsGroupClass *class)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+  object_class->finalize = gtk_tooltips_group_finalize;
+
+  tooltips_groups_quark = g_quark_from_static_string (TOOLTIPS_GROUPS_TAG);
+}
+
+static void
+gtk_tooltips_group_init (GtkTooltipsGroup *object)
+{
+  object->widgets = NULL;
+}
+
+static void
+gtk_tooltips_group_finalize (GObject *object)
+{
+  (* G_OBJECT_CLASS (gtk_tooltips_group_parent_class)->finalize) (object);
+}
+
+static GSList*
+get_tooltips_groups (GtkWidget *widget)
+{
+  return g_object_get_qdata (G_OBJECT (widget), tooltips_groups_quark);
+}
+
+static void
+set_tooltips_groups (GtkWidget *widget,
+		    GSList    *groups)
+{
+  g_object_set_qdata_full (G_OBJECT (widget),
+			   tooltips_groups_quark,
+			   groups,
+			   (GDestroyNotify) g_slist_free);
+}
+
+GtkTooltipsGroup*
+gtk_tooltips_group_new (void)
+{
+  return g_object_new (GTK_TYPE_TOOLTIPS_GROUP, NULL);
+}
+
+void
+gtk_tooltips_group_add_widget (GtkTooltipsGroup *tooltips_group,
+			       GtkWidget        *widget)
+{
+  GSList *groups;
+
+  if (!g_slist_find (tooltips_group->widgets, widget))
+    {
+      tooltips_group->widgets = g_slist_prepend (tooltips_group->widgets, widget);
+
+      groups = get_tooltips_groups (widget);
+      groups = g_slist_prepend (groups, tooltips_group);
+      set_tooltips_groups (widget, groups);
+    }
+}
+
+void
+gtk_tooltips_group_remove_widget (GtkTooltipsGroup *tooltips_group,
+				  GtkWidget        *widget)
+{
+  GSList *groups;
+
+  tooltips_group->widgets = g_slist_remove (tooltips_group->widgets, widget);
+
+  groups = get_tooltips_groups (widget);
+  g_slist_remove (groups, tooltips_group);
+  set_tooltips_groups (widget, groups);
+}
+
+gboolean
+_gtk_tooltips_groups_check_widgets_relation (GtkWidget *widget1,
+					     GtkWidget *widget2)
+{
+  GtkTooltipsGroup *group;
+  GSList *groups1, *groups2;
+
+  groups1 = get_tooltips_groups (widget1);
+  groups2 = get_tooltips_groups (widget2);
+
+  while (groups1)
+    {
+      if (g_slist_find (groups2, groups1->data))
+	return TRUE;
+
+      groups1 = groups1->next;
+    }
+
+  return FALSE;
+}
+
+#define __GTK_TOOLTIPS_GROUP_C__
+#include "gtkaliasdef.c"
Index: gtktooltipsgroup.h
===================================================================
RCS file: gtktooltipsgroup.h
diff -N gtktooltipsgroup.h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gtktooltipsgroup.h	25 Jan 2006 23:16:07 -0000
@@ -0,0 +1,72 @@
+/* -*- Mode: C; c-file-style: "gnu"; tab-width: 8 -*- */
+/* GTK - The GIMP Toolkit
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __GTK_TOOLTIPS_GROUP_H__
+#define __GTK_TOOLTIPS_GROUP_H__
+
+
+#include <gdk/gdk.h>
+
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_TOOLTIPS_GROUP            (gtk_tooltips_group_get_type ())
+#define GTK_TOOLTIPS_GROUP(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_TOOLTIPS_GROUP, GtkTooltipsGroup))
+#define GTK_TOOLTIPS_GROUP_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass),  GTK_TYPE_TOOLTIPS_GROUP, GtkTooltipsGroupClass))
+#define GTK_IS_TOOLTIPS_GROUP(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_TOOLTIPS_GROUP))
+#define GTK_IS_TOOLTIPS_GROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),  GTK_TYPE_TOOLTIPS_GROUP))
+#define GTK_TOOLTIPS_GROUP_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),  GTK_TYPE_TOOLTIPS_GROUP, GtkTooltipsGroupClass))
+
+typedef struct _GtkTooltipsGroup      GtkTooltipsGroup;
+typedef struct _GtkTooltipsGroupClass GtkTooltipsGroupClass;
+
+struct _GtkTooltipsGroup
+{
+  GObject parent_instance;
+
+  GSList *widgets;
+};
+
+struct _GtkTooltipsGroupClass
+{
+  GObjectClass parent_class;
+
+  /* Padding for future expansion */
+  void (*_gtk_reserved1) (void);
+  void (*_gtk_reserved2) (void);
+  void (*_gtk_reserved3) (void);
+  void (*_gtk_reserved4) (void);
+};
+
+
+GType             gtk_tooltips_group_get_type      (void) G_GNUC_CONST;
+
+GtkTooltipsGroup* gtk_tooltips_group_new ();
+
+void              gtk_tooltips_group_add_widget    (GtkTooltipsGroup *tooltips_group,
+						    GtkWidget        *widget);
+void              gtk_tooltips_group_remove_widget (GtkTooltipsGroup *tooltips_group,
+						    GtkWidget        *widget);
+
+gboolean          _gtk_tooltips_group_check_widgets_relation (GtkWidget *widget1, GtkWidget *widget2);
+
+
+G_END_DECLS
+
+#endif /* __GTK_TOOLTIPS_GROUP_H__ */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]