[gtk/wip/baedert/for-master: 69/74] container: Stop remove()ing all widgets in dispose



commit 521aff4cfe0fe8822a826bce0e0b74fd4012a7c6
Author: Timm Bäder <mail baedert org>
Date:   Thu Oct 3 10:18:24 2019 +0200

    container: Stop remove()ing all widgets in dispose

 gtk/gtkbin.c         | 13 ++++++++++++
 gtk/gtkbox.c         | 20 ++++++++++++++++++
 gtk/gtkcontainer.c   |  2 --
 gtk/gtkframe.c       | 12 +++++++++++
 gtk/gtkgrid.c        | 19 +++++++++++++++++
 gtk/gtkheaderbar.c   | 60 ++++++++++++++++++++++++++++++++++++----------------
 gtk/gtklistbox.c     | 19 +++++++++++++++++
 gtk/gtkmodelbutton.c |  2 +-
 gtk/gtkoverlay.c     | 22 +++++++++++++++++++
 gtk/gtkpaned.c       | 12 +++++++++++
 gtk/gtkpathbar.c     | 11 ++++++++++
 gtk/gtktoolbar.c     | 11 +++++++++-
 12 files changed, 181 insertions(+), 22 deletions(-)
---
diff --git a/gtk/gtkbin.c b/gtk/gtkbin.c
index 386ac55fd8..bff4b41d83 100644
--- a/gtk/gtkbin.c
+++ b/gtk/gtkbin.c
@@ -80,12 +80,25 @@ gtk_bin_size_allocate (GtkWidget *widget,
                               }, baseline);
 }
 
+static void
+gtk_bin_dispose (GObject *object)
+{
+  GtkBinPrivate *priv = gtk_bin_get_instance_private (GTK_BIN (object));
+
+  g_clear_pointer (&priv->child, gtk_widget_unparent);
+
+  G_OBJECT_CLASS (gtk_bin_parent_class)->dispose (object);
+}
+
 static void
 gtk_bin_class_init (GtkBinClass *class)
 {
+  GObjectClass *object_class = (GObjectClass *) class;
   GtkWidgetClass *widget_class = (GtkWidgetClass*) class;
   GtkContainerClass *container_class = (GtkContainerClass*) class;
 
+  object_class->dispose = gtk_bin_dispose;
+
   widget_class->measure = gtk_bin_measure;
   widget_class->size_allocate = gtk_bin_size_allocate;
 
diff --git a/gtk/gtkbox.c b/gtk/gtkbox.c
index f6195dbfbb..81b1fd626d 100644
--- a/gtk/gtkbox.c
+++ b/gtk/gtkbox.c
@@ -117,6 +117,25 @@ G_DEFINE_TYPE_WITH_CODE (GtkBox, gtk_box, GTK_TYPE_CONTAINER,
                          G_ADD_PRIVATE (GtkBox)
                          G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL))
 
+static void
+gtk_box_dispose (GObject *object)
+{
+  GtkWidget *child;
+
+
+  child = gtk_widget_get_first_child (GTK_WIDGET (object));
+  while (child)
+    {
+      GtkWidget *next = gtk_widget_get_next_sibling (child);
+
+      gtk_widget_unparent (child);
+
+      child = next;
+    }
+
+  G_OBJECT_CLASS (gtk_box_parent_class)->dispose (object);
+}
+
 static void
 gtk_box_class_init (GtkBoxClass *class)
 {
@@ -124,6 +143,7 @@ gtk_box_class_init (GtkBoxClass *class)
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
   GtkContainerClass *container_class = GTK_CONTAINER_CLASS (class);
 
+  object_class->dispose = gtk_box_dispose;
   object_class->set_property = gtk_box_set_property;
   object_class->get_property = gtk_box_get_property;
 
diff --git a/gtk/gtkcontainer.c b/gtk/gtkcontainer.c
index 4b89b6b8a3..9850ca837a 100644
--- a/gtk/gtkcontainer.c
+++ b/gtk/gtkcontainer.c
@@ -251,8 +251,6 @@ gtk_container_dispose (GObject *object)
   if (priv->restyle_pending)
     priv->restyle_pending = FALSE;
 
-  gtk_container_foreach (container, (GtkCallback) gtk_widget_destroy, NULL);
-
   G_OBJECT_CLASS (gtk_container_parent_class)->dispose (object);
 }
 
diff --git a/gtk/gtkframe.c b/gtk/gtkframe.c
index b5a2aa8a6e..8460df1c84 100644
--- a/gtk/gtkframe.c
+++ b/gtk/gtkframe.c
@@ -149,6 +149,17 @@ G_DEFINE_TYPE_WITH_CODE (GtkFrame, gtk_frame, GTK_TYPE_BIN,
                         G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
                                                gtk_frame_buildable_init))
 
+
+static void
+gtk_frame_dispose (GObject *object)
+{
+  GtkFramePrivate *priv = gtk_frame_get_instance_private (GTK_FRAME (object));
+
+  g_clear_pointer (&priv->label_widget, gtk_widget_unparent);
+
+  G_OBJECT_CLASS (gtk_frame_parent_class)->dispose (object);
+}
+
 static void
 gtk_frame_class_init (GtkFrameClass *class)
 {
@@ -160,6 +171,7 @@ gtk_frame_class_init (GtkFrameClass *class)
   widget_class = GTK_WIDGET_CLASS (class);
   container_class = GTK_CONTAINER_CLASS (class);
 
+  gobject_class->dispose = gtk_frame_dispose;
   gobject_class->set_property = gtk_frame_set_property;
   gobject_class->get_property = gtk_frame_get_property;
 
diff --git a/gtk/gtkgrid.c b/gtk/gtkgrid.c
index a0c3ac107e..0887a9f605 100644
--- a/gtk/gtkgrid.c
+++ b/gtk/gtkgrid.c
@@ -325,6 +325,24 @@ gtk_grid_child_type (GtkContainer *container)
   return GTK_TYPE_WIDGET;
 }
 
+static void
+gtk_grid_dispose (GObject *object)
+{
+  GtkWidget *child;
+
+  child = gtk_widget_get_first_child (GTK_WIDGET (object));
+  while (child)
+    {
+      GtkWidget *next = gtk_widget_get_next_sibling (child);
+
+      gtk_widget_unparent (child);
+
+      child = next;
+    }
+
+  G_OBJECT_CLASS (gtk_grid_parent_class)->dispose (object);
+}
+
 static void
 gtk_grid_class_init (GtkGridClass *class)
 {
@@ -332,6 +350,7 @@ gtk_grid_class_init (GtkGridClass *class)
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
   GtkContainerClass *container_class = GTK_CONTAINER_CLASS (class);
 
+  object_class->dispose = gtk_grid_dispose;
   object_class->get_property = gtk_grid_get_property;
   object_class->set_property = gtk_grid_set_property;
 
diff --git a/gtk/gtkheaderbar.c b/gtk/gtkheaderbar.c
index 7141a2d300..26db60b061 100644
--- a/gtk/gtkheaderbar.c
+++ b/gtk/gtkheaderbar.c
@@ -271,21 +271,27 @@ _gtk_header_bar_update_separator_visibility (GtkHeaderBar *bar)
   GList *l;
   GList *children;
 
-  children = gtk_container_get_children (GTK_CONTAINER (priv->start_box));
-  for (l = children; l; l = l->next)
+  if (priv->start_box)
     {
-      if (l->data != priv->titlebar_start_box && gtk_widget_get_visible (l->data))
-        have_visible_at_start = TRUE;
+      children = gtk_container_get_children (GTK_CONTAINER (priv->start_box));
+      for (l = children; l; l = l->next)
+        {
+          if (l->data != priv->titlebar_start_box && gtk_widget_get_visible (l->data))
+            have_visible_at_start = TRUE;
+        }
+      g_list_free (children);
     }
-  g_list_free (children);
 
-  children = gtk_container_get_children (GTK_CONTAINER (priv->end_box));
-  for (l = children; l; l = l->next)
+  if (priv->end_box)
     {
-      if (l->data != priv->titlebar_end_box && gtk_widget_get_visible (l->data))
-        have_visible_at_end = TRUE;
+      children = gtk_container_get_children (GTK_CONTAINER (priv->end_box));
+      for (l = children; l; l = l->next)
+        {
+          if (l->data != priv->titlebar_end_box && gtk_widget_get_visible (l->data))
+            have_visible_at_end = TRUE;
+        }
+      g_list_free (children);
     }
-  g_list_free (children);
 
   if (priv->titlebar_start_separator != NULL)
     gtk_widget_set_visible (priv->titlebar_start_separator, have_visible_at_start);
@@ -805,10 +811,19 @@ gtk_header_bar_get_custom_title (GtkHeaderBar *bar)
   return priv->custom_title;
 }
 
+static void
+notify_child_cb (GObject      *child,
+                 GParamSpec   *pspec,
+                 GtkHeaderBar *bar)
+{
+  _gtk_header_bar_update_separator_visibility (bar);
+}
+
 static void
 gtk_header_bar_dispose (GObject *object)
 {
   GtkHeaderBarPrivate *priv = gtk_header_bar_get_instance_private (GTK_HEADER_BAR (object));
+  GtkWidget *w;
 
   if (priv->label_sizing_box)
     {
@@ -816,6 +831,23 @@ gtk_header_bar_dispose (GObject *object)
       g_clear_object (&priv->label_sizing_box);
     }
 
+  /* Clean start/end box manually here so the visible notify won't fire on a
+   * headerbar that's in the middle of being disposed */
+  for (w = gtk_widget_get_first_child (priv->start_box);
+       w != NULL;
+       w = gtk_widget_get_next_sibling (w))
+    {
+      if (w != priv->titlebar_start_box)
+        g_signal_handlers_disconnect_by_func (w, notify_child_cb, object);
+    }
+  for (w = gtk_widget_get_first_child (priv->end_box);
+       w != NULL;
+       w = gtk_widget_get_next_sibling (w))
+    {
+      if (w != priv->titlebar_end_box)
+        g_signal_handlers_disconnect_by_func (w, notify_child_cb, object);
+    }
+
   g_clear_pointer (&priv->custom_title, gtk_widget_unparent);
   g_clear_pointer (&priv->label_box, gtk_widget_unparent);
   g_clear_pointer (&priv->start_box, gtk_widget_unparent);
@@ -926,14 +958,6 @@ gtk_header_bar_set_property (GObject      *object,
     }
 }
 
-static void
-notify_child_cb (GObject      *child,
-                 GParamSpec   *pspec,
-                 GtkHeaderBar *bar)
-{
-  _gtk_header_bar_update_separator_visibility (bar);
-}
-
 static void
 gtk_header_bar_pack (GtkHeaderBar *bar,
                      GtkWidget    *widget,
diff --git a/gtk/gtklistbox.c b/gtk/gtklistbox.c
index 857da444c7..2af79aeba1 100644
--- a/gtk/gtklistbox.c
+++ b/gtk/gtklistbox.c
@@ -433,6 +433,24 @@ gtk_list_box_finalize (GObject *obj)
   G_OBJECT_CLASS (gtk_list_box_parent_class)->finalize (obj);
 }
 
+static void
+gtk_list_box_dispose (GObject *object)
+{
+  GtkWidget *child;
+
+  child = gtk_widget_get_first_child (GTK_WIDGET (object));
+  while (child)
+    {
+      GtkWidget *next = gtk_widget_get_next_sibling (child);
+
+      gtk_widget_unparent (child);
+
+      child = next;
+    }
+
+  G_OBJECT_CLASS (gtk_list_box_parent_class)->dispose (object);
+}
+
 static void
 gtk_list_box_class_init (GtkListBoxClass *klass)
 {
@@ -445,6 +463,7 @@ gtk_list_box_class_init (GtkListBoxClass *klass)
 
   object_class->get_property = gtk_list_box_get_property;
   object_class->set_property = gtk_list_box_set_property;
+  object_class->dispose = gtk_list_box_dispose;
   object_class->finalize = gtk_list_box_finalize;
   widget_class->show = gtk_list_box_show;
   widget_class->focus = gtk_list_box_focus;
diff --git a/gtk/gtkmodelbutton.c b/gtk/gtkmodelbutton.c
index 9f41a25ce6..7ce9b7284f 100644
--- a/gtk/gtkmodelbutton.c
+++ b/gtk/gtkmodelbutton.c
@@ -945,12 +945,12 @@ gtk_model_button_finalize (GObject *object)
 {
   GtkModelButton *button = GTK_MODEL_BUTTON (object);
 
+  g_clear_object (&button->action_helper);
   g_clear_pointer (&button->image, gtk_widget_unparent);
   g_clear_pointer (&button->label, gtk_widget_unparent);
   g_clear_pointer (&button->start_box, gtk_widget_unparent);
   g_clear_pointer (&button->accel_label, gtk_widget_unparent);
   g_clear_pointer (&button->end_indicator, gtk_widget_unparent);
-  g_clear_object (&button->action_helper);
   g_free (button->accel);
   g_clear_pointer (&button->popover, gtk_widget_unparent);
 
diff --git a/gtk/gtkoverlay.c b/gtk/gtkoverlay.c
index f23982221e..6217509935 100644
--- a/gtk/gtkoverlay.c
+++ b/gtk/gtkoverlay.c
@@ -271,6 +271,26 @@ gtk_overlay_snapshot (GtkWidget   *widget,
     }
 }
 
+static void
+gtk_overlay_dispose (GObject *object)
+{
+  GtkWidget *child;
+
+  child = gtk_widget_get_first_child (GTK_WIDGET (object));
+  while (child)
+    {
+      GtkWidget *next = gtk_widget_get_next_sibling (child);
+
+      gtk_widget_unparent (child);
+
+      child = next;
+    }
+
+  _gtk_bin_set_child (GTK_BIN (object), NULL);
+
+  G_OBJECT_CLASS (gtk_overlay_parent_class)->dispose (object);
+}
+
 static void
 gtk_overlay_class_init (GtkOverlayClass *klass)
 {
@@ -278,6 +298,8 @@ gtk_overlay_class_init (GtkOverlayClass *klass)
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
   GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
 
+  object_class->dispose = gtk_overlay_dispose;
+
   widget_class->snapshot = gtk_overlay_snapshot;
 
   container_class->add = gtk_overlay_add;
diff --git a/gtk/gtkpaned.c b/gtk/gtkpaned.c
index 1bf644fa8f..708ab43fac 100644
--- a/gtk/gtkpaned.c
+++ b/gtk/gtkpaned.c
@@ -332,6 +332,17 @@ gtk_paned_handle_contains (GtkGizmo *handle,
   return graphene_rect_contains_point (&area, &GRAPHENE_POINT_INIT (x, y));
 }
 
+static void
+gtk_paned_dispose (GObject *object)
+{
+  GtkPanedPrivate *priv = gtk_paned_get_instance_private (GTK_PANED (object));
+
+  g_clear_pointer (&priv->child1, gtk_widget_unparent);
+  g_clear_pointer (&priv->child2, gtk_widget_unparent);
+
+  G_OBJECT_CLASS (gtk_paned_parent_class)->dispose (object);
+}
+
 static void
 gtk_paned_class_init (GtkPanedClass *class)
 {
@@ -348,6 +359,7 @@ gtk_paned_class_init (GtkPanedClass *class)
 
   object_class->set_property = gtk_paned_set_property;
   object_class->get_property = gtk_paned_get_property;
+  object_class->dispose = gtk_paned_dispose;
   object_class->finalize = gtk_paned_finalize;
 
   widget_class->measure = gtk_paned_measure;
diff --git a/gtk/gtkpathbar.c b/gtk/gtkpathbar.c
index 5bc9906888..dff05f9e32 100644
--- a/gtk/gtkpathbar.c
+++ b/gtk/gtkpathbar.c
@@ -352,12 +352,23 @@ gtk_path_bar_dispose (GObject *object)
 {
   GtkPathBar *path_bar = GTK_PATH_BAR (object);
   GtkPathBarPrivate *priv = gtk_path_bar_get_instance_private (path_bar);
+  GtkWidget *child;
 
   remove_settings_signal (path_bar, gtk_widget_get_display (GTK_WIDGET (object)));
 
   priv->get_info_cancellable = NULL;
   cancel_all_cancellables (path_bar);
 
+  child = gtk_widget_get_first_child (GTK_WIDGET (object));
+  while (child)
+    {
+      GtkWidget *next = gtk_widget_get_next_sibling (child);
+
+      gtk_widget_unparent (child);
+
+      child = next;
+    }
+
   G_OBJECT_CLASS (gtk_path_bar_parent_class)->dispose (object);
 }
 
diff --git a/gtk/gtktoolbar.c b/gtk/gtktoolbar.c
index 6d6d88e1ed..ec602d79a0 100644
--- a/gtk/gtktoolbar.c
+++ b/gtk/gtktoolbar.c
@@ -2517,8 +2517,17 @@ gtk_toolbar_dispose (GObject *object)
 {
   GtkToolbar *toolbar = GTK_TOOLBAR (object);
   GtkToolbarPrivate *priv = toolbar->priv;
+  GtkWidget *child;
 
-  g_clear_pointer (&priv->arrow_button, gtk_widget_unparent);
+  child = gtk_widget_get_first_child (GTK_WIDGET (object));
+  while (child)
+    {
+      GtkWidget *next = gtk_widget_get_next_sibling (child);
+
+      gtk_widget_unparent (child);
+
+      child = next;
+    }
 
   if (priv->menu)
     {


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