[gtk/wip/baedert/some-api: 5/7] widget: Save the depth of a widget in the tree
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/baedert/some-api: 5/7] widget: Save the depth of a widget in the tree
- Date: Tue, 25 Dec 2018 13:59:02 +0000 (UTC)
commit 1cfbca09b5561e388e3978609e297027d82b3abe
Author: Timm Bäder <mail baedert org>
Date: Tue Dec 25 11:44:18 2018 +0100
widget: Save the depth of a widget in the tree
This is handy whenever we do some operation on all parent widgets of a
widget.
gtk/gtkwidget.c | 19 +++++++++++++++++++
gtk/gtkwidgetprivate.h | 7 +++++++
2 files changed, 26 insertions(+)
---
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 4fadd96534..4e57d5e833 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -2802,6 +2802,7 @@ gtk_widget_init (GTypeInstance *instance, gpointer g_class)
priv->last_child = NULL;
priv->prev_sibling = NULL;
priv->next_sibling = NULL;
+ priv->depth = 1;
priv->allocated_baseline = -1;
priv->allocated_size_baseline = -1;
@@ -2979,6 +2980,22 @@ gtk_widget_new (GType type,
return widget;
}
+static void
+gtk_widget_propagate_depth (GtkWidget *widget,
+ int new_depth)
+{
+ GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
+ GtkWidget *child;
+
+ priv->depth = new_depth;
+
+ for (child = _gtk_widget_get_first_child (widget);
+ child != NULL;
+ child = _gtk_widget_get_next_sibling (child))
+ gtk_widget_propagate_depth (child, new_depth + 1);
+}
+
+
/**
* gtk_widget_unparent:
* @widget: a #GtkWidget
@@ -3062,6 +3079,7 @@ gtk_widget_unparent (GtkWidget *widget)
priv->parent = NULL;
priv->prev_sibling = NULL;
priv->next_sibling = NULL;
+ gtk_widget_propagate_depth (widget, 1);
/* parent may no longer expand if the removed
* child was expand=TRUE and could therefore
@@ -6505,6 +6523,7 @@ gtk_widget_reposition_after (GtkWidget *widget,
gtk_widget_push_verify_invariants (widget);
priv->parent = parent;
+ gtk_widget_propagate_depth (widget, gtk_widget_get_depth (parent) + 1);
if (previous_sibling)
{
diff --git a/gtk/gtkwidgetprivate.h b/gtk/gtkwidgetprivate.h
index f658811358..390fdc8a57 100644
--- a/gtk/gtkwidgetprivate.h
+++ b/gtk/gtkwidgetprivate.h
@@ -167,6 +167,7 @@ struct _GtkWidgetPrivate
GtkWidget *next_sibling;
GtkWidget *first_child;
GtkWidget *last_child;
+ int depth;
/* only created on-demand */
GtkListListModel *children_observer;
@@ -481,6 +482,12 @@ _gtk_widget_get_last_child (GtkWidget *widget)
return widget->priv->last_child;
}
+static inline int
+gtk_widget_get_depth (GtkWidget *widget)
+{
+ return widget->priv->depth;
+}
+
G_END_DECLS
#endif /* __GTK_WIDGET_PRIVATE_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]