From 354eb5678b13d101bd097e038245be1a7a4aed9c Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Tue, 29 Dec 2015 18:31:10 -0800 Subject: [PATCH] menuitem: fix a crash when reserve_indicator is TRUE In that case, code expects an arrow gadget to be present but we're not creating it in every occurrence. Fix it by ensuring there will be an arrow gadget when reserve_indicator is TRUE. --- gtk/gtkmenuitem.c | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/gtk/gtkmenuitem.c b/gtk/gtkmenuitem.c index 10c2cbd3ae..76f7052185 100644 --- a/gtk/gtkmenuitem.c +++ b/gtk/gtkmenuitem.c @@ -1503,6 +1503,33 @@ update_node_classes (GtkMenuItem *menu_item) } } +static void +update_arrow_gadget (GtkMenuItem *menu_item) +{ + GtkMenuItemPrivate *priv = menu_item->priv; + GtkWidget *widget = GTK_WIDGET (menu_item); + gboolean should_have_gadget; + + should_have_gadget = priv->reserve_indicator || + (priv->submenu && !GTK_IS_MENU_BAR (gtk_widget_get_parent (widget))); + + if (should_have_gadget) + { + if (!priv->arrow_gadget) + { + priv->arrow_gadget = gtk_builtin_icon_new ("arrow", + widget, + priv->gadget, + NULL); + update_node_classes (menu_item); + } + } + else + { + g_clear_object (&priv->arrow_gadget); + } +} + /** * gtk_menu_item_set_submenu: * @menu_item: a #GtkMenuItem @@ -1536,14 +1563,7 @@ gtk_menu_item_set_submenu (GtkMenuItem *menu_item, widget, gtk_menu_item_detacher); - if (!GTK_IS_MENU_BAR (gtk_widget_get_parent (widget))) - { - priv->arrow_gadget = gtk_builtin_icon_new ("arrow", - widget, - priv->gadget, - NULL); - update_node_classes (menu_item); - } + update_arrow_gadget (menu_item); } if (gtk_widget_get_parent (widget)) @@ -2666,6 +2686,7 @@ gtk_menu_item_set_reserve_indicator (GtkMenuItem *menu_item, if (priv->reserve_indicator != reserve) { priv->reserve_indicator = reserve; + update_arrow_gadget (menu_item); gtk_widget_queue_resize (GTK_WIDGET (menu_item)); } }