*/
#include "config.h"
+
+#include <math.h>
+#include <string.h>
+
#include "gtktooltip.h"
#include "gtkintl.h"
#include "gtkwindow.h"
#include "gtkalias.h"
-#include <string.h>
-
#undef DEBUG_TOOLTIP
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;
+ gdk_window_get_root_coords (window, x, y, &x, &y);
+ event.motion.x_root = x;
+ event.motion.y_root = y;
_gtk_tooltip_handle_event (&event);
}
*/
while (window && window != event_widget->window)
{
- gint px, py;
+ gdouble px, py;
- gdk_window_get_position (window, &px, &py);
- child_loc.x += px;
- child_loc.y += py;
+ gdk_window_coords_to_parent (window,
+ child_loc.x, child_loc.y,
+ &px, &py);
+ child_loc.x = px;
+ child_loc.y = py;
- window = gdk_window_get_parent (window);
+ window = gdk_window_get_effective_parent (window);
}
/* Failing to find widget->window can happen for e.g. a detached handle box;
return return_value;
}
+static void
+get_bounding_box (GtkWidget *widget,
+ GdkRectangle *bounds)
+{
+ GdkWindow *window;
+ gint x, y;
+ gint w, h;
+ gint x1, y1;
+ gint x2, y2;
+ gint x3, y3;
+ gint x4, y4;
+
+ window = gtk_widget_get_parent_window (widget);
+
+ x = widget->allocation.x;
+ y = widget->allocation.y;
+ w = widget->allocation.width;
+ h = widget->allocation.height;
+
+ gdk_window_get_root_coords (window, x, y, &x1, &y1);
+ gdk_window_get_root_coords (window, x + w, y, &x2, &y2);
+ gdk_window_get_root_coords (window, x, y + h, &x3, &y3);
+ gdk_window_get_root_coords (window, x + w, y + h, &x4, &y4);
+
+#define MIN4(a,b,c,d) MIN(MIN(a,b),MIN(c,d))
+#define MAX4(a,b,c,d) MAX(MAX(a,b),MAX(c,d))
+
+ bounds->x = floor (MIN4 (x1, x2, x3, x4));
+ bounds->y = floor (MIN4 (y1, y2, y3, y4));
+ bounds->width = ceil (MAX4 (x1, x2, x3, x4)) - bounds->x;
+ bounds->height = ceil (MAX4 (y1, y2, y3, y4)) - bounds->y;
+}
+
static void
gtk_tooltip_position (GtkTooltip *tooltip,
GdkDisplay *display,
/* FIXME: should we swap this when RTL is enabled? */
if (tooltip->keyboard_mode_enabled)
{
- gdk_window_get_origin (new_tooltip_widget->window, &x, &y);
- if (!gtk_widget_get_has_window (new_tooltip_widget))
- {
- x += new_tooltip_widget->allocation.x;
- y += new_tooltip_widget->allocation.y;
- }
+ GdkRectangle bounds;
+
+ get_bounding_box (new_tooltip_widget, &bounds);
/* For keyboard mode we position the tooltip below the widget,
* right of the center of the widget.
*/
- x += new_tooltip_widget->allocation.width / 2;
- y += new_tooltip_widget->allocation.height + 4;
+ x = bounds.x + bounds.width / 2;
+ y = bounds.y + bounds.height + 4;
}
else
{
}
else
{
+ gint tx, ty;
+
window = tooltip->last_window;
if (!GDK_IS_WINDOW (window))
return;
- gdk_window_get_origin (window, &x, &y);
- x = tooltip->last_x - x;
- y = tooltip->last_y - y;
+ gdk_window_get_pointer (window, &x, &y, NULL);
+
+ gdk_window_get_root_coords (window, x, y, &tx, &ty);
+ tooltip->last_x = tx;
+ tooltip->last_y = ty;
pointer_widget = tooltip_widget = find_widget_under_pointer (window,
&x, &y);
if (current_tooltip)
{
gtk_tooltip_set_last_window (current_tooltip, event->any.window);
- gdk_event_get_root_coords (event,
- ¤t_tooltip->last_x,
- ¤t_tooltip->last_y);
}
if (current_tooltip && current_tooltip->keyboard_mode_enabled)
current_tooltip);
gtk_tooltip_set_last_window (current_tooltip, event->any.window);
- gdk_event_get_root_coords (event,
- ¤t_tooltip->last_x,
- ¤t_tooltip->last_y);
gtk_tooltip_start_delay (display);
}