From 5e59105ea3774b6de1c8c62dbee371b66768ea61 Mon Sep 17 00:00:00 2001 From: Kristian Rietveld Date: Wed, 23 May 2007 12:32:42 +0000 Subject: [PATCH] translate coordinates from the window they were received on to the event 2007-05-23 Kristian Rietveld * 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 | 11 +++++++++++ gtk/gtktooltip.c | 26 ++++++++++++++++++++++++++ gtk/gtkwidget.c | 4 ++-- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index c58dc532d5..8f608198d7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2007-05-23 Kristian Rietveld + + * 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 * gtk/gtkprintcontext.c (gtk_print_context_finalize), diff --git a/gtk/gtktooltip.c b/gtk/gtktooltip.c index 47a1b207ec..15dfce9e3e 100644 --- a/gtk/gtktooltip.c +++ b/gtk/gtktooltip.c @@ -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, diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c index 2d5c6add3e..31a8c5c07f 100644 --- a/gtk/gtkwidget.c +++ b/gtk/gtkwidget.c @@ -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 *