diff options
author | Balazs Varga <balazs.varga.extern@allotropia.de> | 2023-07-26 12:17:19 +0200 |
---|---|---|
committer | Thorsten Behrens <thorsten.behrens@allotropia.de> | 2023-07-31 23:57:57 +0200 |
commit | 21a0cf9b0d990f8a10dbea99f9d4a2bfbf2ba855 (patch) | |
tree | 78a6be925ddf62ddf26d1c31ed2bd4f94e23a718 | |
parent | b1707fea5936557688864124654ef6eeb5c0beb4 (diff) |
tdf#104382 - Menus should be disabled when they have no enabled submenus
Disable menu elements if they only have disabled submenu elemets.
TODO: GTK3
cherry-pick from commit: 630303ad8e94bd634b98e691935a1f4c19582a3a
Change-Id: I83cdc58846afd61719ceeba9f993df894ce6fd01
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154938
Tested-by: Jenkins
Reviewed-by: Balazs Varga <balazs.varga.extern@allotropia.de>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155010
Tested-by: Gabor Kelemen <kelemeng@ubuntu.com>
Reviewed-by: Gabor Kelemen <kelemeng@ubuntu.com>
-rw-r--r-- | framework/source/uielement/menubarmanager.cxx | 29 | ||||
-rw-r--r-- | include/vcl/menu.hxx | 1 | ||||
-rw-r--r-- | vcl/source/window/menu.cxx | 18 |
3 files changed, 46 insertions, 2 deletions
diff --git a/framework/source/uielement/menubarmanager.cxx b/framework/source/uielement/menubarmanager.cxx index f7a41c75f9e3..c0d24d3b4900 100644 --- a/framework/source/uielement/menubarmanager.cxx +++ b/framework/source/uielement/menubarmanager.cxx @@ -564,7 +564,7 @@ void SAL_CALL MenuBarManager::disposing( const EventObject& Source ) static void lcl_CheckForChildren(Menu* pMenu, sal_uInt16 nItemId) { if (PopupMenu* pThisPopup = pMenu->GetPopupMenu( nItemId )) - pMenu->EnableItem( nItemId, pThisPopup->GetItemCount() != 0 ); + pMenu->EnableItem(nItemId, pThisPopup->GetItemCount() != 0 && pThisPopup->HasValidEntries(true)); } // vcl handler @@ -731,6 +731,15 @@ IMPL_LINK( MenuBarManager, Activate, Menu *, pMenu, bool ) { if( xMenuItemDispatch.is() || menuItemHandler->aMenuItemURL != ".uno:RecentFileList" ) bPopupMenu = CreatePopupMenuController(menuItemHandler.get()); + + if (bPopupMenu && menuItemHandler->xPopupMenuController.is()) + { + if (PopupMenu* pThisPopup = pMenu->GetPopupMenu(menuItemHandler->nItemId)) + { + pThisPopup->Activate(); + pThisPopup->Deactivate(); + } + } } else if ( menuItemHandler->xPopupMenuController.is() ) { @@ -738,7 +747,10 @@ IMPL_LINK( MenuBarManager, Activate, Menu *, pMenu, bool ) menuItemHandler->xPopupMenuController->updatePopupMenu(); bPopupMenu = true; if (PopupMenu* pThisPopup = pMenu->GetPopupMenu( menuItemHandler->nItemId )) - pMenu->EnableItem( menuItemHandler->nItemId, pThisPopup->GetItemCount() != 0 ); + { + pThisPopup->Activate(); + pThisPopup->Deactivate(); + } } lcl_CheckForChildren(pMenu, menuItemHandler->nItemId); @@ -763,6 +775,11 @@ IMPL_LINK( MenuBarManager, Activate, Menu *, pMenu, bool ) { // Force update of popup menu menuItemHandler->xPopupMenuController->updatePopupMenu(); + if (PopupMenu* pThisPopup = pMenu->GetPopupMenu(menuItemHandler->nItemId)) + { + pThisPopup->Activate(); + pThisPopup->Deactivate(); + } lcl_CheckForChildren(pMenu, menuItemHandler->nItemId); } else if ( menuItemHandler->xMenuItemDispatch.is() ) @@ -783,7 +800,15 @@ IMPL_LINK( MenuBarManager, Activate, Menu *, pMenu, bool ) } } else if ( menuItemHandler->xSubMenuManager.is() ) + { + MenuBarManager* pMenuBarManager = static_cast<MenuBarManager*>(menuItemHandler->xSubMenuManager.get()); + if (pMenuBarManager) + { + pMenuBarManager->Activate(pMenuBarManager->GetMenuBar()); + pMenuBarManager->Deactivate(pMenuBarManager->GetMenuBar()); + } lcl_CheckForChildren(pMenu, menuItemHandler->nItemId); + } } } } diff --git a/include/vcl/menu.hxx b/include/vcl/menu.hxx index b787b43b31b7..8c5cd2c2af34 100644 --- a/include/vcl/menu.hxx +++ b/include/vcl/menu.hxx @@ -257,6 +257,7 @@ public: void SetMenuFlags( MenuFlags nFlags ) { nMenuFlags = nFlags; } MenuFlags GetMenuFlags() const { return nMenuFlags; } + bool HasValidEntries(bool bCheckPopups) const; sal_uInt16 GetItemCount() const; sal_uInt16 GetItemId(sal_uInt16 nPos) const; sal_uInt16 GetItemId(const OString &rIdent) const; diff --git a/vcl/source/window/menu.cxx b/vcl/source/window/menu.cxx index 38780b020f2a..53faa6ff6675 100644 --- a/vcl/source/window/menu.cxx +++ b/vcl/source/window/menu.cxx @@ -590,6 +590,24 @@ sal_uInt16 Menu::GetItemCount() const return static_cast<sal_uInt16>(pItemList->size()); } +bool Menu::HasValidEntries(bool bCheckPopups) const +{ + bool bValidEntries = false; + sal_uInt16 nCount = GetItemCount(); + for (sal_uInt16 n = 0; !bValidEntries && (n < nCount); n++) + { + MenuItemData* pItem = pItemList->GetDataFromPos(n); + if (pItem->bEnabled && (pItem->eType != MenuItemType::SEPARATOR)) + { + if (bCheckPopups && pItem->pSubMenu) + bValidEntries = pItem->pSubMenu->HasValidEntries(true); + else + bValidEntries = true; + } + } + return bValidEntries; +} + sal_uInt16 Menu::ImplGetVisibleItemCount() const { sal_uInt16 nItems = 0; |