[gtk+/wip/baedert/drawing] inspector: Use GtkWidget::pick when picking widgets
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/baedert/drawing] inspector: Use GtkWidget::pick when picking widgets
- Date: Mon, 26 Jun 2017 10:01:22 +0000 (UTC)
commit 572a97892c8144ae79bfb5313ae1a13a1dd922bb
Author: Timm Bäder <mail baedert org>
Date: Mon Jun 26 11:48:33 2017 +0200
inspector: Use GtkWidget::pick when picking widgets
gtk/inspector/inspect-button.c | 155 ++++++++-------------------------------
1 files changed, 32 insertions(+), 123 deletions(-)
---
diff --git a/gtk/inspector/inspect-button.c b/gtk/inspector/inspect-button.c
index 7109d83..776ec43 100644
--- a/gtk/inspector/inspect-button.c
+++ b/gtk/inspector/inspect-button.c
@@ -31,124 +31,11 @@
#include "gtkmain.h"
#include "gtkinvisible.h"
-typedef struct
-{
- gint x;
- gint y;
- gboolean found;
- gboolean first;
- GtkWidget *res_widget;
-} FindWidgetData;
-
-static void
-find_widget (GtkWidget *widget,
- FindWidgetData *data)
-{
- GtkAllocation new_allocation;
- gint x_offset = 0;
- gint y_offset = 0;
- GtkWidget *child;
-
- gtk_widget_get_allocation (widget, &new_allocation);
-
- if (data->found || !gtk_widget_get_mapped (widget))
- return;
-
- /* Note that in the following code, we only count the
- * position as being inside a WINDOW widget if it is inside
- * widget->window; points that are outside of widget->window
- * but within the allocation are not counted. This is consistent
- * with the way we highlight drag targets.
- */
- if (gtk_widget_get_has_window (widget))
- {
- new_allocation.x = 0;
- new_allocation.y = 0;
- }
-
- if (gtk_widget_get_parent (widget) && !data->first)
- {
- GdkWindow *window;
-
- window = gtk_widget_get_window (widget);
- while (window != gtk_widget_get_window (gtk_widget_get_parent (widget)))
- {
- gint tx, ty, twidth, theight;
-
- if (window == NULL)
- return;
-
- twidth = gdk_window_get_width (window);
- theight = gdk_window_get_height (window);
-
- if (new_allocation.x < 0)
- {
- new_allocation.width += new_allocation.x;
- new_allocation.x = 0;
- }
- if (new_allocation.y < 0)
- {
- new_allocation.height += new_allocation.y;
- new_allocation.y = 0;
- }
- if (new_allocation.x + new_allocation.width > twidth)
- new_allocation.width = twidth - new_allocation.x;
- if (new_allocation.y + new_allocation.height > theight)
- new_allocation.height = theight - new_allocation.y;
-
- gdk_window_get_position (window, &tx, &ty);
- new_allocation.x += tx;
- x_offset += tx;
- new_allocation.y += ty;
- y_offset += ty;
-
- window = gdk_window_get_parent (window);
- }
- }
-
- if ((data->x >= new_allocation.x) && (data->y >= new_allocation.y) &&
- (data->x < new_allocation.x + new_allocation.width) &&
- (data->y < new_allocation.y + new_allocation.height))
- {
- FindWidgetData new_data = *data;
- /* First, check if the drag is in a valid drop site in
- * one of our children
- */
- new_data.x -= x_offset;
- new_data.y -= y_offset;
- new_data.found = FALSE;
- new_data.first = FALSE;
-
- for (child = gtk_widget_get_first_child (widget);
- child != NULL;
- child = gtk_widget_get_next_sibling (child))
- {
- find_widget (child, &new_data);
- }
-
- data->found = new_data.found;
- if (data->found)
- data->res_widget = new_data.res_widget;
-
- /* If not, and this widget is registered as a drop site, check to
- * emit "drag_motion" to check if we are actually in
- * a drop site.
- */
- if (!data->found)
- {
- data->found = TRUE;
- data->res_widget = widget;
- }
- }
-}
-
static GtkWidget *
find_widget_at_pointer (GdkDevice *device)
{
GtkWidget *widget = NULL;
GdkWindow *pointer_window;
- gint x, y;
- FindWidgetData data;
pointer_window = gdk_device_get_window_at_position (device, NULL, NULL);
@@ -158,23 +45,45 @@ find_widget_at_pointer (GdkDevice *device)
gdk_window_get_user_data (pointer_window, &widget_ptr);
widget = widget_ptr;
+
+ if (!GTK_IS_WINDOW (widget))
+ {
+ while (TRUE)
+ {
+ GdkWindow *parent = gdk_window_get_parent (pointer_window);
+
+ if (!parent)
+ break;
+
+ pointer_window = parent;
+ gdk_window_get_user_data (pointer_window, &widget_ptr);
+ widget = widget_ptr;
+
+ if (GTK_IS_WINDOW (widget))
+ break;
+ }
+
+ }
}
if (widget)
{
- gdk_window_get_device_position (gtk_widget_get_window (widget),
- device, &x, &y, NULL);
+ double x, y;
+
+ gdk_window_get_device_position_double (gtk_widget_get_window (widget),
+ device, &x, &y, NULL);
- data.x = x;
- data.y = y;
- data.found = FALSE;
- data.first = TRUE;
+ while (widget)
+ {
+ GtkWidget *w;
- find_widget (widget, &data);
- if (data.found)
- return data.res_widget;
+ w = GTK_WIDGET_GET_CLASS (widget)->pick (widget, x, y, &x, &y);
- return widget;
+ if (!w)
+ return widget;
+
+ widget = w;
+ }
}
return NULL;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]