tdf#140225 call cancel before destroying menubar

a) in case there are some menus open cancel them before removing
their parent menubar
b) when a GtkSalMenu is deleted clear the action-group of the
hierarchy and flag it as needed a refresh, clearing it of
any references to the deleted GtkSalMenu

Change-Id: I9ec59c52c72b8b58976a8ee41727ca7612ebf6b1
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110542
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
diff --git a/vcl/unx/gtk3/gtk3gtksalmenu.cxx b/vcl/unx/gtk3/gtk3gtksalmenu.cxx
index f78bbab..c5e0a95 100644
--- a/vcl/unx/gtk3/gtk3gtksalmenu.cxx
+++ b/vcl/unx/gtk3/gtk3gtksalmenu.cxx
@@ -596,6 +596,16 @@ GtkSalMenu::~GtkSalMenu()
{
    SolarMutexGuard aGuard;

    if (mpActionGroup)
    {
        // tdf#140225 if any menu is deleted clear the action-group shared
        // by the hierarchy
        GLOActionGroup* pActionGroup = G_LO_ACTION_GROUP(mpActionGroup);
        g_lo_action_group_clear(pActionGroup);
        // and flag the hierarchy as needing an update
        SetNeedsUpdate();
    }

    DestroyMenuBarWidget();

    if (mpMenuModel)
@@ -998,6 +1008,10 @@ void GtkSalMenu::DestroyMenuBarWidget()
{
    if (mpMenuBarContainerWidget)
    {
        // tdf#140225 call cancel before destroying it in case there are some
        // active menus popped open
        gtk_menu_shell_cancel(GTK_MENU_SHELL(mpMenuBarWidget));

        gtk_widget_destroy(mpMenuBarContainerWidget);
        mpMenuBarContainerWidget = nullptr;
        mpCloseButton = nullptr;