Code change for Bug 53614:KEYNAV:Tooltip



I have added support for popping down a tooltip by using the Escape key; a focus 
switch already popped down the tooltip. I also added code to move the tooltip 
close to the widget if the tooltip was popped up using Ctrl+F1.

Is it OK to commit?

Padraig

===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktooltips.c,v
retrieving revision 1.42
diff -u -p -r1.42 gtktooltips.c
--- gtktooltips.c       2001/08/19 11:48:31     1.42
+++ gtktooltips.c       2001/09/19 11:50:54
@@ -35,6 +35,7 @@
 #include "gtksignal.h"
 #include "gtkstyle.h"
 #include "gtktooltips.h"
+#include "gdk/gdkkeysyms.h"
 
 
 #define DEFAULT_DELAY 500           /* Default delay in ms */
@@ -318,7 +319,7 @@ gtk_tooltips_draw_tips (GtkTooltips * to
   GtkRequisition requisition;
   GtkWidget *widget;
   GtkStyle *style;
-  gint x, y, w, h, scr_w, scr_h;
+  gint xp, x, y, w, h, scr_w, scr_h;
   GtkTooltipsData *data;
 
   if (!tooltips->tip_window)
@@ -342,10 +343,23 @@ gtk_tooltips_draw_tips (GtkTooltips * to
   w = requisition.width;
   h = requisition.height;
 
-  gdk_window_get_pointer (NULL, &x, NULL, NULL);
-  gdk_window_get_origin (widget->window, NULL, &y);
+  gdk_window_get_pointer (NULL, &xp, NULL, NULL);
+  gdk_window_get_origin (widget->window, &x, &y);
   if (GTK_WIDGET_NO_WINDOW (widget))
-    y += widget->allocation.y;
+    {
+      x += widget->allocation.x;
+      y += widget->allocation.y;
+    }
+  /*
+   * Ensure that centre of tooltip is close to widget.
+   * The tooltip may be displayed because of keyboard action so the
+   * pointer may not be near the widget.
+   */
+  if (xp < x)
+    xp = x;
+  else if (xp > x + widget->allocation.width)
+    xp = x + widget->allocation.width;  
+  x = xp;
 
   x -= (w / 2 + 4);
 
@@ -445,6 +459,23 @@ gtk_tooltips_event_handler (GtkWidget *w
       event->crossing.detail == GDK_NOTIFY_INFERIOR)
     return FALSE;
 
+  if (event->type == GDK_KEY_PRESS)
+    {
+      GdkEventKey *key_event = (GdkEventKey *)event;
+      if (key_event->keyval == GDK_Escape)
+        {
+          old_tips_data = gtk_tooltips_data_get (widget);
+          tooltips = old_tips_data->tooltips;
+
+          if (tooltips->active_tips_data &&
+              (tooltips->active_tips_data->widget == widget))
+            {
+              gtk_tooltips_set_active_widget (tooltips, NULL);
+              return TRUE;
+            }
+        }
+    }
+      
   event_widget = gtk_get_event_widget (event);
   if (event_widget != widget)
     return FALSE;
@@ -491,8 +522,8 @@ gtk_tooltips_event_handler (GtkWidget *w
       break;
       
     default:
-      gtk_tooltips_set_active_widget (tooltips, NULL);
-      return FALSE;
+      if (tooltips->active_tips_data)
+        gtk_tooltips_set_active_widget (tooltips, NULL);
       break;
     }
 





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