[gtk+/wip/baedert/children: 30/54] widget: Add children and sibling pointers



commit 91e5f29535705ab2457ddb38caaa0fecd612da39
Author: Timm Bäder <mail baedert org>
Date:   Fri Nov 18 09:29:52 2016 +0100

    widget: Add children and sibling pointers
    
    and a (private) way to access them. We will later use these pointers to
    manage children of non-container widgets and containers alike.

 gtk/gtkwidget.c        |   60 ++++++++++++++++++++++++++++++++++++++++++++++++
 gtk/gtkwidget.h        |    9 +++++++
 gtk/gtkwidgetprivate.h |   34 ++++++++++++++++++++++++--
 3 files changed, 100 insertions(+), 3 deletions(-)
---
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 9f212fe..c26dbc9 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -3800,6 +3800,10 @@ gtk_widget_init (GTypeInstance *instance, gpointer g_class)
   priv->alpha = 255;
   priv->window = NULL;
   priv->parent = NULL;
+  priv->first_child = NULL;
+  priv->last_child = NULL;
+  priv->prev_sibling = NULL;
+  priv->next_sibling = NULL;
 
   priv->sensitive = TRUE;
   priv->redraw_on_alloc = TRUE;
@@ -4043,7 +4047,22 @@ gtk_widget_unparent (GtkWidget *widget)
   priv->child_visible = TRUE;
 
   old_parent = priv->parent;
+  if (old_parent)
+    {
+      if (old_parent->priv->first_child == widget)
+        old_parent->priv->first_child = priv->next_sibling;
+
+      if (old_parent->priv->last_child == widget)
+        old_parent->priv->last_child = priv->prev_sibling;
+
+      if (priv->prev_sibling)
+        priv->prev_sibling->priv->next_sibling = priv->next_sibling;
+      if (priv->next_sibling)
+        priv->next_sibling->priv->prev_sibling = priv->prev_sibling;
+    }
   priv->parent = NULL;
+  priv->prev_sibling = NULL;
+  priv->next_sibling = NULL;
 
   /* parent may no longer expand if the removed
    * child was expand=TRUE and could therefore
@@ -8464,6 +8483,15 @@ gtk_widget_set_parent (GtkWidget *widget,
   gtk_widget_push_verify_invariants (widget);
 
   priv->parent = parent;
+  if (parent)
+    {
+      priv->prev_sibling = parent->priv->last_child;
+      if (parent->priv->last_child)
+        parent->priv->last_child->priv->next_sibling = widget;
+      parent->priv->last_child = widget;
+      if (!parent->priv->first_child)
+        parent->priv->first_child = widget;
+    }
 
   parent_flags = _gtk_widget_get_state_flags (parent);
 
@@ -15701,3 +15729,35 @@ gtk_widget_render (GtkWidget            *widget,
 
   gdk_window_end_draw_frame (window, context);
 }
+
+GtkWidget *
+gtk_widget_get_first_child (GtkWidget *widget)
+{
+  g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
+
+  return widget->priv->first_child;
+}
+
+GtkWidget *
+gtk_widget_get_last_child (GtkWidget *widget)
+{
+  g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
+
+  return widget->priv->last_child;
+}
+
+GtkWidget *
+gtk_widget_get_next_sibling (GtkWidget *widget)
+{
+  g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
+
+  return widget->priv->next_sibling;
+}
+
+GtkWidget *
+gtk_widget_get_prev_sibling (GtkWidget *widget)
+{
+  g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
+
+  return widget->priv->prev_sibling;
+}
diff --git a/gtk/gtkwidget.h b/gtk/gtkwidget.h
index cea1298..3f05d8d 100644
--- a/gtk/gtkwidget.h
+++ b/gtk/gtkwidget.h
@@ -1309,6 +1309,15 @@ void                    gtk_widget_set_font_map         (GtkWidget             *
 GDK_AVAILABLE_IN_3_18
 PangoFontMap *          gtk_widget_get_font_map         (GtkWidget             *widget);
 
+GDK_AVAILABLE_IN_3_90
+GtkWidget *             gtk_widget_get_first_child      (GtkWidget *widget);
+GDK_AVAILABLE_IN_3_90
+GtkWidget *             gtk_widget_get_last_child       (GtkWidget *widget);
+GDK_AVAILABLE_IN_3_90
+GtkWidget *             gtk_widget_get_next_sibling     (GtkWidget *widget);
+GDK_AVAILABLE_IN_3_90
+GtkWidget *             gtk_widget_get_prev_sibling     (GtkWidget *widget);
+
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkWidget, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkRequisition, gtk_requisition_free)
 
diff --git a/gtk/gtkwidgetprivate.h b/gtk/gtkwidgetprivate.h
index 7fcbbb4..5b2ddc2 100644
--- a/gtk/gtkwidgetprivate.h
+++ b/gtk/gtkwidgetprivate.h
@@ -149,12 +149,16 @@ struct _GtkWidgetPrivate
   GdkWindow *window;
   GList *registered_windows;
 
-  /* The widget's parent */
-  GtkWidget *parent;
-
   GList *event_controllers;
 
   AtkObject *accessible;
+
+  /* Widget tree */
+  GtkWidget *parent;
+  GtkWidget *prev_sibling;
+  GtkWidget *next_sibling;
+  GtkWidget *first_child;
+  GtkWidget *last_child;
 };
 
 GtkCssNode *  gtk_widget_get_css_node       (GtkWidget *widget);
@@ -396,6 +400,30 @@ _gtk_widget_get_allocation (GtkWidget     *widget,
   *allocation = widget->priv->allocation;
 }
 
+static inline GtkWidget *
+_gtk_widget_get_prev_sibling (GtkWidget *widget)
+{
+  return widget->priv->prev_sibling;
+}
+
+static inline GtkWidget *
+_gtk_widget_get_next_sibling (GtkWidget *widget)
+{
+  return widget->priv->next_sibling;
+}
+
+static inline GtkWidget *
+_gtk_widget_get_first_child (GtkWidget *widget)
+{
+  return widget->priv->first_child;
+}
+
+static inline GtkWidget *
+_gtk_widget_get_last_child (GtkWidget *widget)
+{
+  return widget->priv->last_child;
+}
+
 G_END_DECLS
 
 #endif /* __GTK_WIDGET_PRIVATE_H__ */


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