diff options
author | Emmanuele Bassi <ebassi@gnome.org> | 2019-06-10 14:43:14 +0100 |
---|---|---|
committer | Emmanuele Bassi <ebassi@gnome.org> | 2019-06-30 23:42:44 +0100 |
commit | e7b2c530c512523242270caaaa8e0a15bf99e492 (patch) | |
tree | 2e79284ccd0f77253a40112fe9a4c2c00d31405d /gtk/gtklayoutmanager.c | |
parent | e07098da03353c026cd90c58064d79c036ab912c (diff) | |
download | gtk+-e7b2c530c512523242270caaaa8e0a15bf99e492.tar.gz |
Propagate rooting and unrooting widgets to layout managers
Layout managers may need to get access to data attached to the root of a
scene graph.
Diffstat (limited to 'gtk/gtklayoutmanager.c')
-rw-r--r-- | gtk/gtklayoutmanager.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/gtk/gtklayoutmanager.c b/gtk/gtklayoutmanager.c index c41a604b99..1aa7724d49 100644 --- a/gtk/gtklayoutmanager.c +++ b/gtk/gtklayoutmanager.c @@ -91,6 +91,7 @@ typedef struct { GtkWidget *widget; + GtkRoot *root; /* HashTable<Widget, LayoutChild> */ GHashTable *layout_children; @@ -98,6 +99,16 @@ typedef struct { G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GtkLayoutManager, gtk_layout_manager, G_TYPE_OBJECT) +static void +gtk_layout_manager_real_root (GtkLayoutManager *manager) +{ +} + +static void +gtk_layout_manager_real_unroot (GtkLayoutManager *manager) +{ +} + static GtkSizeRequestMode gtk_layout_manager_real_get_request_mode (GtkLayoutManager *manager, GtkWidget *widget) @@ -195,6 +206,8 @@ gtk_layout_manager_class_init (GtkLayoutManagerClass *klass) klass->measure = gtk_layout_manager_real_measure; klass->allocate = gtk_layout_manager_real_allocate; klass->create_layout_child = gtk_layout_manager_real_create_layout_child; + klass->root = gtk_layout_manager_real_root; + klass->unroot = gtk_layout_manager_real_unroot; } static void @@ -226,6 +239,38 @@ gtk_layout_manager_set_widget (GtkLayoutManager *layout_manager, } priv->widget = widget; + + if (widget != NULL) + gtk_layout_manager_set_root (layout_manager, gtk_widget_get_root (widget)); +} + +/*< private > + * gtk_layout_manager_set_root: + * @layout_manager: a #GtkLayoutManager + * @root: (nullable): a #GtkWidget implementing #GtkRoot + * + * Sets a back pointer from @root to @layout_manager. + * + * This function is called by #GtkWidget when getting rooted and unrooted, + * and will call #GtkLayoutManagerClass.root() or #GtkLayoutManagerClass.unroot() + * depending on whether @root is a #GtkWidget or %NULL. + */ +void +gtk_layout_manager_set_root (GtkLayoutManager *layout_manager, + GtkRoot *root) +{ + GtkLayoutManagerPrivate *priv = gtk_layout_manager_get_instance_private (layout_manager); + GtkRoot *old_root = priv->root; + + priv->root = root; + + if (old_root != root) + { + if (priv->root != NULL) + GTK_LAYOUT_MANAGER_GET_CLASS (layout_manager)->root (layout_manager); + else + GTK_LAYOUT_MANAGER_GET_CLASS (layout_manager)->unroot (layout_manager); + } } /** |