[gtk+/wip/baedert/children: 12/40] widget: Add widget version of gtk_container_snapshot_child
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/baedert/children: 12/40] widget: Add widget version of gtk_container_snapshot_child
- Date: Thu, 1 Dec 2016 19:12:51 +0000 (UTC)
commit 4c89832d58726d234ffb361ae7ac9d4eb077c270
Author: Timm Bäder <mail baedert org>
Date: Wed Nov 16 14:32:50 2016 +0100
widget: Add widget version of gtk_container_snapshot_child
gtk/gtkwidget.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++-
gtk/gtkwidgetprivate.h | 4 ++
2 files changed, 75 insertions(+), 1 deletions(-)
---
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 6196e6a..cf0567b 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -10775,13 +10775,14 @@ gtk_widget_real_unmap (GtkWidget *widget)
if (_gtk_widget_get_mapped (widget))
{
GtkWidget *child;
+
priv->mapped = FALSE;
if (_gtk_widget_get_has_window (widget))
gdk_window_hide (priv->window);
for (child = gtk_widget_get_first_child (widget);
- chlid != NULL;
+ child != NULL;
child = gtk_widget_get_next_sibling (child))
{
gtk_widget_unmap (child);
@@ -15841,3 +15842,72 @@ gtk_widget_get_prev_sibling (GtkWidget *widget)
return widget->priv->prev_sibling;
}
+
+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 5b2ddc2..572d42b 100644
--- a/gtk/gtkwidgetprivate.h
+++ b/gtk/gtkwidgetprivate.h
@@ -289,6 +289,10 @@ void gtk_widget_render (GtkWidget
void gtk_widget_snapshot (GtkWidget *widget,
GtkSnapshot *snapshot);
+void gtk_widget_snapshot_child (GtkWidget *widget,
+ GtkWidget *child,
+ GtkSnapshot *snapshot);
+
/* inline getters */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]