From 4a2a76c2317aa5f1ecc1e5c9a212faf2716eca48 Mon Sep 17 00:00:00 2001 From: Jason Francis Date: Wed, 2 Mar 2022 19:49:39 -0500 Subject: [PATCH] gtk: Have GtkCenterLayout hold a reference to its widgets --- gtk/gtkcenterlayout.c | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/gtk/gtkcenterlayout.c b/gtk/gtkcenterlayout.c index 18bed9ddb9..72db233550 100644 --- a/gtk/gtkcenterlayout.c +++ b/gtk/gtkcenterlayout.c @@ -523,11 +523,26 @@ gtk_center_layout_allocate (GtkLayoutManager *layout_manager, } } +static void +gtk_center_layout_dispose (GObject *object) +{ + GtkCenterLayout *self = GTK_CENTER_LAYOUT (object); + + g_clear_object (&self->start_widget); + g_clear_object (&self->center_widget); + g_clear_object (&self->end_widget); + + G_OBJECT_CLASS (gtk_center_layout_parent_class)->dispose (object); +} + static void gtk_center_layout_class_init (GtkCenterLayoutClass *klass) { + GObjectClass *object_class = G_OBJECT_CLASS (klass); GtkLayoutManagerClass *layout_class = GTK_LAYOUT_MANAGER_CLASS (klass); + object_class->dispose = gtk_center_layout_dispose; + layout_class->get_request_mode = gtk_center_layout_get_request_mode; layout_class->measure = gtk_center_layout_measure; layout_class->allocate = gtk_center_layout_allocate; @@ -641,11 +656,8 @@ gtk_center_layout_set_start_widget (GtkCenterLayout *self, g_return_if_fail (GTK_IS_CENTER_LAYOUT (self)); g_return_if_fail (widget == NULL || GTK_IS_WIDGET (widget)); - if (self->start_widget == widget) - return; - - self->start_widget = widget; - gtk_layout_manager_layout_changed (GTK_LAYOUT_MANAGER (self)); + if (g_set_object (&self->start_widget, widget)) + gtk_layout_manager_layout_changed (GTK_LAYOUT_MANAGER (self)); } /** @@ -680,11 +692,8 @@ gtk_center_layout_set_center_widget (GtkCenterLayout *self, g_return_if_fail (GTK_IS_CENTER_LAYOUT (self)); g_return_if_fail (widget == NULL || GTK_IS_WIDGET (widget)); - if (self->center_widget == widget) - return; - - self->center_widget = widget; - gtk_layout_manager_layout_changed (GTK_LAYOUT_MANAGER (self)); + if (g_set_object (&self->center_widget, widget)) + gtk_layout_manager_layout_changed (GTK_LAYOUT_MANAGER (self)); } /** @@ -706,7 +715,7 @@ gtk_center_layout_get_center_widget (GtkCenterLayout *self) /** * gtk_center_layout_set_end_widget: * @self: a `GtkCenterLayout` - * @widget: (nullable) (transfer none): the new end widget + * @widget: (nullable): the new end widget * * Sets the new end widget of @self. * @@ -719,11 +728,8 @@ gtk_center_layout_set_end_widget (GtkCenterLayout *self, g_return_if_fail (GTK_IS_CENTER_LAYOUT (self)); g_return_if_fail (widget == NULL || GTK_IS_WIDGET (widget)); - if (self->end_widget == widget) - return; - - self->end_widget = widget; - gtk_layout_manager_layout_changed (GTK_LAYOUT_MANAGER (self)); + if (g_set_object (&self->end_widget, widget)) + gtk_layout_manager_layout_changed (GTK_LAYOUT_MANAGER (self)); } /**