[gtk/global-coords] menu: Fix destruction
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/global-coords] menu: Fix destruction
- Date: Sat, 1 Jun 2019 03:34:12 +0000 (UTC)
commit feef0ef93a11f92cb939bd3c22cf089eb4dc9a76
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Jun 1 03:19:30 2019 +0000
menu: Fix destruction
Now that menubar and menu are containers
with internal structure, we need to be
careful about doing the right thing in
forall and dispose.
gtk/gtkmenu.c | 23 ++++++++++++++++++++++-
gtk/gtkmenubar.c | 32 ++++++++++++++++++++++++++++++++
2 files changed, 54 insertions(+), 1 deletion(-)
---
diff --git a/gtk/gtkmenu.c b/gtk/gtkmenu.c
index b4fc71a8fd..1cb05a58ed 100644
--- a/gtk/gtkmenu.c
+++ b/gtk/gtkmenu.c
@@ -172,6 +172,7 @@ static void gtk_menu_get_property (GObject *object,
GValue *value,
GParamSpec *pspec);
static void gtk_menu_finalize (GObject *object);
+static void gtk_menu_dispose (GObject *object);
static void gtk_menu_destroy (GtkWidget *widget);
static void gtk_menu_realize (GtkWidget *widget);
static void gtk_menu_unrealize (GtkWidget *widget);
@@ -257,6 +258,17 @@ gtk_menu_get_items (GtkMenuShell *menu_shell)
return gtk_container_get_children (GTK_CONTAINER (priv->box));
}
+static void
+gtk_menu_forall (GtkContainer *container,
+ GtkCallback callback,
+ gpointer data)
+{
+ GtkMenuPrivate *priv = GTK_MENU (container)->priv;
+
+ if (priv->box)
+ gtk_container_forall (GTK_CONTAINER (priv->box), callback, data);
+}
+
static void
gtk_menu_class_init (GtkMenuClass *class)
{
@@ -269,6 +281,7 @@ gtk_menu_class_init (GtkMenuClass *class)
gobject_class->set_property = gtk_menu_set_property;
gobject_class->get_property = gtk_menu_get_property;
gobject_class->finalize = gtk_menu_finalize;
+ gobject_class->dispose = gtk_menu_dispose;
widget_class->destroy = gtk_menu_destroy;
widget_class->realize = gtk_menu_realize;
@@ -282,6 +295,7 @@ gtk_menu_class_init (GtkMenuClass *class)
container_class->add = gtk_menu_add;
container_class->remove = gtk_menu_remove;
+ container_class->forall = gtk_menu_forall;
menu_shell_class->submenu_placement = GTK_LEFT_RIGHT;
menu_shell_class->deactivate = gtk_menu_deactivate;
@@ -869,13 +883,20 @@ gtk_menu_destroy (GtkWidget *widget)
static void
gtk_menu_finalize (GObject *object)
+{
+ G_OBJECT_CLASS (gtk_menu_parent_class)->finalize (object);
+}
+
+static void
+gtk_menu_dispose (GObject *object)
{
GtkMenu *menu = GTK_MENU (object);
GtkMenuPrivate *priv = menu->priv;
g_clear_pointer (&priv->swin, gtk_widget_unparent);
+ priv->box = NULL;
- G_OBJECT_CLASS (gtk_menu_parent_class)->finalize (object);
+ G_OBJECT_CLASS (gtk_menu_parent_class)->dispose (object);
}
static void
diff --git a/gtk/gtkmenubar.c b/gtk/gtkmenubar.c
index ce9a868d0b..6a6babc40f 100644
--- a/gtk/gtkmenubar.c
+++ b/gtk/gtkmenubar.c
@@ -112,15 +112,46 @@ gtk_menu_bar_get_items (GtkMenuShell *menu_shell)
return gtk_container_get_children (GTK_CONTAINER (menu_bar->box));
}
+static void
+gtk_menu_bar_finalize (GObject *object)
+{
+ G_OBJECT_CLASS (gtk_menu_bar_parent_class)->finalize (object);
+}
+
+static void
+gtk_menu_bar_dispose (GObject *object)
+{
+ GtkMenuBar *menu_bar = GTK_MENU_BAR (object);
+
+ g_clear_pointer (&menu_bar->box, gtk_widget_unparent);
+
+ G_OBJECT_CLASS (gtk_menu_bar_parent_class)->dispose (object);
+}
+
+static void
+gtk_menu_bar_forall (GtkContainer *container,
+ GtkCallback callback,
+ gpointer data)
+{
+ GtkMenuBar *menu_bar = GTK_MENU_BAR (container);
+
+ if (menu_bar->box)
+ gtk_container_forall (GTK_CONTAINER (menu_bar->box), callback, data);
+}
+
static void
gtk_menu_bar_class_init (GtkMenuBarClass *class)
{
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
GtkContainerClass *container_class = GTK_CONTAINER_CLASS (class);
GtkMenuShellClass *menu_shell_class = GTK_MENU_SHELL_CLASS (class);
GtkBindingSet *binding_set;
+ object_class->finalize = gtk_menu_bar_finalize;
+ object_class->dispose = gtk_menu_bar_dispose;
+
widget_class->measure = gtk_menu_bar_measure;
widget_class->size_allocate = gtk_menu_bar_size_allocate;
widget_class->root = gtk_menu_bar_root;
@@ -128,6 +159,7 @@ gtk_menu_bar_class_init (GtkMenuBarClass *class)
container_class->add = gtk_menu_bar_add;
container_class->remove = gtk_menu_bar_remove;
+ container_class->forall = gtk_menu_bar_forall;
menu_shell_class->insert = gtk_menu_bar_insert;
menu_shell_class->submenu_placement = GTK_TOP_BOTTOM;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]