]> Pileus Git - ~andy/gtk/commitdiff
translate coordinates from the window they were received on to the event
authorKristian Rietveld <kris@imendio.com>
Wed, 23 May 2007 12:32:42 +0000 (12:32 +0000)
committerKristian Rietveld <kristian@src.gnome.org>
Wed, 23 May 2007 12:32:42 +0000 (12:32 +0000)
2007-05-23  Kristian Rietveld  <kris@imendio.com>

* gtk/gtktooltip.c (find_widget_under_pointer): translate coordinates
from the window they were received on to the event widget's window;
correct for no-window widgets after that, bail out on failure.  This
makes the coordinates given by GtkWidget::query-tooltip truly relative
to widget->window.  (#435188).

* gtk/gtkwidget.c (gtk_widget_class_init): update docs for
GtkWidget::query-tooltip.

svn path=/trunk/; revision=17896

ChangeLog
gtk/gtktooltip.c
gtk/gtkwidget.c

index c58dc532d58355a94077dda9bc3f100ccc626868..8f608198d7b1e5d098e0bf9062142145c81d244a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2007-05-23  Kristian Rietveld  <kris@imendio.com>
+
+       * gtk/gtktooltip.c (find_widget_under_pointer): translate coordinates
+       from the window they were received on to the event widget's window;
+       correct for no-window widgets after that, bail out on failure.  This
+       makes the coordinates given by GtkWidget::query-tooltip truly relative
+       to widget->window.  (#435188).
+
+       * gtk/gtkwidget.c (gtk_widget_class_init): update docs for
+       GtkWidget::query-tooltip.
+
 2007-05-22  Behdad Esfahbod  <behdad@gnome.org>
 
        * gtk/gtkprintcontext.c (gtk_print_context_finalize),
index 47a1b207ec4be2eafc99a57ecf93595da4dc0545..15dfce9e3e0f8b9ba4bd75305dd9239c0ddc06d4 100644 (file)
@@ -463,6 +463,32 @@ find_widget_under_pointer (GdkWindow *window,
   child_loc.y = *y;
 
   gdk_window_get_user_data (window, (void **)&event_widget);
+
+  while (window && window != event_widget->window)
+    {
+      gint px, py;
+
+      gdk_window_get_position (window, &px, &py);
+      child_loc.x += px;
+      child_loc.y += py;
+
+      window = gdk_window_get_parent (window);
+    }
+
+  if (GTK_WIDGET_NO_WINDOW (event_widget))
+    {
+      child_loc.x += event_widget->allocation.x;
+      child_loc.y += event_widget->allocation.y;
+    }
+
+  /* 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;
+
   if (GTK_IS_CONTAINER (event_widget))
     {
       window_to_alloc (event_widget,
index 2d5c6add3ece250c438cdc289ddb515275202b23..31a8c5c07ffe5f919060997827a89579516eb668 100644 (file)
@@ -1514,9 +1514,9 @@ gtk_widget_class_init (GtkWidgetClass *klass)
    * GtkWidget::query-tooltip:
    * @widget: the object which received the signal
    * @x: the x coordinate of the cursor position where the request has been
-   *     emitted, relative to the widget's allocation
+   *     emitted, relative to widget->window
    * @y: the y coordinate of the cursor position where the request has been
-   *     emitted, relative to the widget's allocation
+   *     emitted, relative to widget->window
    * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
    * @tooltip: a #GtkTooltip
    *