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.
This commit is contained in:
Matthias Clasen 2019-06-01 03:19:30 +00:00
parent 6c201e7927
commit feef0ef93a
2 changed files with 54 additions and 1 deletions

View File

@ -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

View File

@ -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;