[gtk+/portal-race: 25/129] widget: Make allocations parent-content-allocation relative
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/portal-race: 25/129] widget: Make allocations parent-content-allocation relative
- Date: Mon, 3 Jul 2017 00:46:05 +0000 (UTC)
commit 2cefb635b2f44108c6df1b50f6dde2658e2fb575
Author: Timm Bäder <mail baedert org>
Date: Sat May 27 15:19:44 2017 +0200
widget: Make allocations parent-content-allocation relative
gtk/gtkcontainer.c | 56 ++----------------------------
gtk/gtkwidget.c | 99 ++++++---------------------------------------------
2 files changed, 15 insertions(+), 140 deletions(-)
---
diff --git a/gtk/gtkcontainer.c b/gtk/gtkcontainer.c
index 81828d5..e8236a2 100644
--- a/gtk/gtkcontainer.c
+++ b/gtk/gtkcontainer.c
@@ -2970,56 +2970,6 @@ gtk_container_get_children_clip (GtkContainer *container,
union_with_clip (child, out_clip);
}
-static void
-gtk_container_get_translation_to_child (GtkContainer *container,
- GtkWidget *child,
- int *x_out,
- int *y_out)
-{
- GtkAllocation allocation;
- GdkWindow *window, *w;
- int x, y;
-
- /* translate coordinates. Ugly business, that. */
- if (!_gtk_widget_get_has_window (GTK_WIDGET (container)))
- {
- _gtk_widget_get_allocation (GTK_WIDGET (container), &allocation);
- x = -allocation.x;
- y = -allocation.y;
- }
- else
- {
- x = 0;
- y = 0;
- }
-
- window = _gtk_widget_get_window (GTK_WIDGET (container));
-
- for (w = _gtk_widget_get_window (child); w && w != window; w = gdk_window_get_parent (w))
- {
- int wx, wy;
- gdk_window_get_position (w, &wx, &wy);
- x += wx;
- y += wy;
- }
-
- if (w == NULL)
- {
- x = 0;
- y = 0;
- }
-
- if (!_gtk_widget_get_has_window (child))
- {
- _gtk_widget_get_allocation (child, &allocation);
- x += allocation.x;
- y += allocation.y;
- }
-
- *x_out = x;
- *y_out = y;
-}
-
/**
* gtk_container_propagate_draw:
* @container: a #GtkContainer
@@ -3049,7 +2999,7 @@ gtk_container_propagate_draw (GtkContainer *container,
GtkWidget *child,
cairo_t *cr)
{
- int x, y;
+ GtkAllocation child_allocation;
g_return_if_fail (GTK_IS_CONTAINER (container));
g_return_if_fail (GTK_IS_WIDGET (child));
@@ -3059,10 +3009,10 @@ gtk_container_propagate_draw (GtkContainer *container,
if (!gtk_container_should_propagate_draw (container, child, cr))
return;
- gtk_container_get_translation_to_child (container, child, &x, &y);
+ gtk_widget_get_allocation (child, &child_allocation);
cairo_save (cr);
- cairo_translate (cr, x, y);
+ cairo_translate (cr, child_allocation.x, child_allocation.y);
gtk_widget_draw_internal (child, cr, TRUE);
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 152f66c..2e81588 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -946,36 +946,6 @@ gtk_widget_real_snapshot (GtkWidget *widget,
gtk_widget_snapshot_child (widget, child, snapshot);
}
-static void
-transform_to_child_coords (GtkWidget *widget,
- GtkWidget *child,
- gdouble x,
- gdouble y,
- gdouble *x_out,
- gdouble *y_out)
-{
- GtkAllocation alloc, child_alloc;
- GdkWindow *window;
- gdouble dx = 0, dy = 0;
-
- gtk_widget_get_allocation (widget, &alloc);
- gtk_widget_get_allocation (child, &child_alloc);
-
- child_alloc.x -= alloc.x;
- child_alloc.y -= alloc.y;
-
- window = _gtk_widget_get_window (child);
-
- while (window != _gtk_widget_get_window (widget))
- {
- gdk_window_coords_to_parent (window, dx, dy, &dx, &dy);
- window = gdk_window_get_parent (window);
- }
-
- *x_out = x - child_alloc.x - dx;
- *y_out = y - child_alloc.y - dy;
-}
-
static GtkWidget *
gtk_widget_real_pick (GtkWidget *widget,
gdouble x,
@@ -983,24 +953,23 @@ gtk_widget_real_pick (GtkWidget *widget,
gdouble *x_out,
gdouble *y_out)
{
- GtkAllocation allocation, parent_allocation;
GtkWidget *child;
- gtk_widget_get_allocation (widget, &parent_allocation);
-
for (child = _gtk_widget_get_last_child (widget);
child;
child = _gtk_widget_get_prev_sibling (child))
{
gdouble tx = x, ty = y;
+ GtkAllocation allocation;
if (gtk_widget_get_pass_through (child) ||
!gtk_widget_is_sensitive (child) ||
!gtk_widget_is_drawable (child))
continue;
- transform_to_child_coords (widget, child, tx, ty, &tx, &ty);
_gtk_widget_get_allocation (child, &allocation);
+ tx -= allocation.x;
+ ty -= allocation.y;
allocation.x = 0;
allocation.y = 0;
@@ -5575,8 +5544,8 @@ gtk_widget_size_allocate_with_baseline (GtkWidget *widget,
/* Since gtk_widget_measure does it for us, we can be sure here that
* the given alloaction is large enough for the css margin/bordder/padding */
- real_allocation.x += margin.left + border.left + padding.left;
- real_allocation.y += margin.top + border.top + padding.top;
+ real_allocation.x = 0;
+ real_allocation.y = 0;
real_allocation.width -= margin.left + border.left + padding.left +
margin.right + border.right + padding.right;
real_allocation.height -= margin.top + border.top + padding.top +
@@ -15579,7 +15548,10 @@ gtk_widget_snapshot (GtkWidget *widget,
if (opacity < 1.0)
gtk_snapshot_push_opacity (snapshot, opacity, "Opacity<%s,%f>", G_OBJECT_TYPE_NAME (widget),
opacity);
+ /* Offset to content allocation */
+ gtk_snapshot_offset (snapshot, margin.left + padding.left + border.left, margin.top + border.top +
padding.top);
klass->snapshot (widget, snapshot);
+ gtk_snapshot_offset (snapshot, - (margin.left + padding.left + border.left), -(margin.top + border.top
+ padding.top));
if (g_signal_has_handler_pending (widget, widget_signals[DRAW], 0, FALSE))
{
@@ -15827,56 +15799,6 @@ gtk_widget_forall (GtkWidget *widget,
}
}
-static void
-gtk_widget_get_translation_to_child (GtkWidget *widget,
- GtkWidget *child,
- int *x_out,
- int *y_out)
-{
- GtkAllocation allocation;
- GdkWindow *window, *w;
- int x, y;
-
- /* translate coordinates. Ugly business, that. */
- if (!_gtk_widget_get_has_window (widget))
- {
- _gtk_widget_get_allocation (widget, &allocation);
- x = -allocation.x;
- y = -allocation.y;
- }
- else
- {
- x = 0;
- y = 0;
- }
-
- window = _gtk_widget_get_window (widget);
-
- for (w = _gtk_widget_get_window (child); w && w != window; w = gdk_window_get_parent (w))
- {
- int wx, wy;
- gdk_window_get_position (w, &wx, &wy);
- x += wx;
- y += wy;
- }
-
- if (w == NULL)
- {
- x = 0;
- y = 0;
- }
-
- if (!_gtk_widget_get_has_window (child))
- {
- _gtk_widget_get_allocation (child, &allocation);
- x += allocation.x;
- y += allocation.y;
- }
-
- *x_out = x;
- *y_out = y;
-}
-
/**
* gtk_widget_snapshot_child:
* @widget: a #GtkWidget
@@ -15902,12 +15824,15 @@ gtk_widget_snapshot_child (GtkWidget *widget,
GtkWidget *child,
GtkSnapshot *snapshot)
{
+ GtkAllocation content_allocation;
int x, y;
g_return_if_fail (_gtk_widget_get_parent (child) == widget);
g_return_if_fail (snapshot != NULL);
- gtk_widget_get_translation_to_child (widget, child, &x, &y);
+ gtk_widget_get_allocation (child, &content_allocation);
+ x = content_allocation.x;
+ y = content_allocation.y;
gtk_snapshot_offset (snapshot, x, y);
gtk_widget_snapshot (child, snapshot);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]