[gtk+] Add gtk_widget_snapshot_child



commit 52aed5d60744cadec2d6ae4cf86814e8851aa8ec
Author: Timm Bäder <mail baedert org>
Date:   Fri Jan 6 09:43:52 2017 +0100

    Add gtk_widget_snapshot_child

 gtk/gtkboxgadget.c     |    2 +-
 gtk/gtkwidget.c        |   69 ++++++++++++++++++++++++++++++++++++++++++++++++
 gtk/gtkwidgetprivate.h |    5 +++
 3 files changed, 75 insertions(+), 1 deletions(-)
---
diff --git a/gtk/gtkboxgadget.c b/gtk/gtkboxgadget.c
index f331489..93d9d92 100644
--- a/gtk/gtkboxgadget.c
+++ b/gtk/gtkboxgadget.c
@@ -536,7 +536,7 @@ gtk_box_gadget_snapshot (GtkCssGadget *gadget,
       GtkBoxGadgetChild *child = &g_array_index (priv->children, GtkBoxGadgetChild, draw_index);
 
       if (GTK_IS_WIDGET (child->object))
-        gtk_container_snapshot_child (GTK_CONTAINER (owner), GTK_WIDGET (child->object), snapshot);
+        gtk_widget_snapshot_child (owner, GTK_WIDGET (child->object), snapshot);
       else
         gtk_css_gadget_snapshot (GTK_CSS_GADGET (child->object), snapshot);
     }
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index bbf5f3c..8bebdfb 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -15735,3 +15735,72 @@ gtk_widget_forall (GtkWidget   *widget,
       child = next;
     }
 }
+
+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;
+}
+
+void
+gtk_widget_snapshot_child (GtkWidget   *widget,
+                           GtkWidget   *child,
+                           GtkSnapshot *snapshot)
+{
+  int x, y;
+
+  g_return_if_fail (GTK_IS_WIDGET (widget));
+  g_return_if_fail (GTK_IS_WIDGET (child));
+  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_snapshot_translate_2d (snapshot, x, y);
+  gtk_widget_snapshot (child, snapshot);
+  gtk_snapshot_translate_2d (snapshot, -x, -y);
+}
diff --git a/gtk/gtkwidgetprivate.h b/gtk/gtkwidgetprivate.h
index c19dd2a..d4da81c 100644
--- a/gtk/gtkwidgetprivate.h
+++ b/gtk/gtkwidgetprivate.h
@@ -304,6 +304,11 @@ void              gtk_widget_forall                        (GtkWidget
                                                             GtkCallback           callback,
                                                             gpointer              user_data);
 
+void              gtk_widget_snapshot_child                (GtkWidget   *widget,
+                                                            GtkWidget   *child,
+                                                            GtkSnapshot *snapshot);
+
+
 /* inline getters */
 
 static inline gboolean


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]