tdf#158101 Make non-gtk backends context popup menu item

visibility behavior like gtk

For context popup menus, gtk's native popup menu hides disabled menu
items. This patch makes this the behavior for non-gtk backends while
preserving the intent of commit
a0955317900075371d6adb7f924af24c22f02d09 to make VCL PopupMenu respect
the officecfg::Office::Common::View::Menu::DontHideDisabledEntry setting.

Change-Id: Ice59f2b5ec20dac9d1b0891ccbd83dbbcd308078
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159192
Tested-by: Jenkins
Reviewed-by: Jim Raykowski <raykowj@gmail.com>
(cherry picked from commit 1ac7350a7032a760be22cce845eab7efe435827d)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162825
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
diff --git a/toolkit/source/awt/vclxmenu.cxx b/toolkit/source/awt/vclxmenu.cxx
index 3778584..20d3d5d 100644
--- a/toolkit/source/awt/vclxmenu.cxx
+++ b/toolkit/source/awt/vclxmenu.cxx
@@ -481,8 +481,13 @@ sal_Int16 VCLXMenu::execute(
        if ( !mpMenu || !IsPopupMenu() )
            return 0;
    }
    PopupMenu* pPopupMenu = static_cast<PopupMenu*>(pMenu.get());
    MenuFlags nMenuFlags = pPopupMenu->GetMenuFlags();
    // #102790# context menus shall never show disabled entries
    nMenuFlags |= MenuFlags::HideDisabledEntries;
    pPopupMenu->SetMenuFlags(nMenuFlags);
    // cannot call this with mutex locked because it will call back into us
    return static_cast<PopupMenu*>(pMenu.get())->Execute(
    return pPopupMenu->Execute(
                VCLUnoHelper::GetWindow( rxWindowPeer ),
                VCLRectangle( rPos ),
                static_cast<PopupMenuFlags>(nFlags) | PopupMenuFlags::NoMouseUpClose );
diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx
index 95beb90..50ecd19 100644
--- a/vcl/source/app/salvtables.cxx
+++ b/vcl/source/app/salvtables.cxx
@@ -1068,6 +1068,12 @@ void SalInstanceToolbar::set_menu_item_active(const OUString& rIdent, bool bActi
    {
        if (bActive)
        {
            MenuFlags nMenuFlags = pPopup->GetMenuFlags();
            if (officecfg::Office::Common::View::Menu::DontHideDisabledEntry::get())
                nMenuFlags &= ~MenuFlags::HideDisabledEntries;
            else
                nMenuFlags |= MenuFlags::HideDisabledEntries;
            pPopup->SetMenuFlags(nMenuFlags);
            tools::Rectangle aRect = m_xToolBox->GetItemRect(nItemId);
            pPopup->Execute(m_xToolBox, aRect, PopupMenuFlags::ExecuteDown);
        }
diff --git a/vcl/source/window/menu.cxx b/vcl/source/window/menu.cxx
index 82d6307..a0a03be 100644
--- a/vcl/source/window/menu.cxx
+++ b/vcl/source/window/menu.cxx
@@ -2863,9 +2863,12 @@ bool PopupMenu::PrepareRun(const VclPtr<vcl::Window>& pParentWin, tools::Rectang
    if (bRealExecute)
        nPopupModeFlags |= FloatWinPopupFlags::NewLevel;

    // MenuFlags get clobbered in the Activate function. Restore them after calling.
    MenuFlags nMenuFlagsSaved = GetMenuFlags();
    bInCallback = true; // set it here, if Activate overridden
    Activate();
    bInCallback = false;
    SetMenuFlags(nMenuFlagsSaved);

    if (pParentWin->isDisposed())
        return false;
@@ -2884,13 +2887,6 @@ bool PopupMenu::PrepareRun(const VclPtr<vcl::Window>& pParentWin, tools::Rectang
        else
            nMenuFlags &= ~MenuFlags::HideDisabledEntries;
    }
    else
    {
         if (officecfg::Office::Common::View::Menu::DontHideDisabledEntry::get())
             nMenuFlags &= ~MenuFlags::HideDisabledEntries;
         else
             nMenuFlags |= MenuFlags::HideDisabledEntries;
    }

    sal_uInt16 nVisibleEntries = ImplGetVisibleItemCount();
    if ( !nVisibleEntries )