diff options
Diffstat (limited to 'framework/source/uielement/menubarmanager.cxx')
-rw-r--r-- | framework/source/uielement/menubarmanager.cxx | 120 |
1 files changed, 70 insertions, 50 deletions
diff --git a/framework/source/uielement/menubarmanager.cxx b/framework/source/uielement/menubarmanager.cxx index 7b856a01d43d..8194cfc8e25f 100644 --- a/framework/source/uielement/menubarmanager.cxx +++ b/framework/source/uielement/menubarmanager.cxx @@ -48,6 +48,7 @@ #include <uno/current_context.hxx> #include <unotools/cmdoptions.hxx> #include <toolkit/awt/vclxmenu.hxx> +#include <utility> #include <vcl/svapp.hxx> #include <vcl/sysdata.hxx> #include <vcl/menu.hxx> @@ -75,7 +76,7 @@ const sal_uInt16 ITEMID_ADDONLIST = 6678; // used to be a SID in sfx namespace framework { -constexpr OUStringLiteral aCmdHelpIndex = u".uno:HelpIndex"; +constexpr OUString aCmdHelpIndex = u".uno:HelpIndex"_ustr; constexpr OUStringLiteral aCmdToolsMenu = u".uno:ToolsMenu"; constexpr OUStringLiteral aCmdHelpMenu = u".uno:HelpMenu"; constexpr OUStringLiteral aSpecialWindowCommand = u".uno:WindowList"; @@ -92,7 +93,7 @@ MenuBarManager::MenuBarManager( , m_bHasMenuBar( bHasMenuBar ) , m_xContext(rxContext) , m_xURLTransformer(_xURLTransformer) - , m_sIconTheme( SvtMiscOptions().GetIconTheme() ) + , m_sIconTheme( SvtMiscOptions::GetIconTheme() ) , m_aAsyncSettingsTimer( "framework::MenuBarManager::Deactivate m_aAsyncSettingsTimer" ) { m_xPopupMenuControllerFactory = frame::thePopupMenuControllerFactory::get(m_xContext); @@ -136,12 +137,12 @@ MenuBarManager::~MenuBarManager() SAL_WARN_IF( OWeakObject::m_refCount != 0, "fwk.uielement", "Who wants to delete an object with refcount > 0!" ); } -void MenuBarManager::Destroy() +// XComponent +void MenuBarManager::disposing(std::unique_lock<std::mutex>& ) { - SolarMutexGuard aGuard; + Reference< XComponent > xThis( this ); - if ( m_bDisposed ) - return; + SolarMutexGuard g; // stop asynchronous settings timer and // release deferred item container reference @@ -155,15 +156,6 @@ void MenuBarManager::Destroy() { m_pVCLMenu.disposeAndClear(); } -} - -// XComponent -void MenuBarManager::disposing(std::unique_lock<std::mutex>& ) -{ - Reference< XComponent > xThis( this ); - - SolarMutexGuard g; - Destroy(); if ( m_xDocImageManager.is() ) { @@ -384,10 +376,7 @@ void MenuBarManager::RequestImages() for (auto const& menuItemHandler : m_aMenuItemHandlerVector) { if ( menuItemHandler->xSubMenuManager.is() ) - { - MenuBarManager* pMenuBarManager = static_cast<MenuBarManager*>(menuItemHandler->xSubMenuManager.get()); - pMenuBarManager->RequestImages(); - } + menuItemHandler->xSubMenuManager->RequestImages(); } } @@ -447,9 +436,8 @@ void MenuBarManager::RemoveListener() menuItemHandler->xPopupMenu.clear(); } - Reference< XComponent > xComponent( menuItemHandler->xSubMenuManager, UNO_QUERY ); - if ( xComponent.is() ) - xComponent->dispose(); + if ( menuItemHandler->xSubMenuManager ) + menuItemHandler->xSubMenuManager->dispose(); } try @@ -523,7 +511,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 @@ -535,9 +523,8 @@ class QuietInteractionContext: { public: explicit QuietInteractionContext( - css::uno::Reference< css::uno::XCurrentContext > - const & context): - context_(context) {} + css::uno::Reference< css::uno::XCurrentContext > context): + context_(std::move(context)) {} QuietInteractionContext(const QuietInteractionContext&) = delete; QuietInteractionContext& operator=(const QuietInteractionContext&) = delete; @@ -572,7 +559,7 @@ IMPL_LINK( MenuBarManager, Activate, Menu *, pMenu, bool ) const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings(); bool bShowMenuImages = rSettings.GetUseImagesInMenus(); bool bShowShortcuts = m_bHasMenuBar || rSettings.GetContextMenuShortcuts(); - bool bHasDisabledEntries = SvtCommandOptions().HasEntries( SvtCommandOptions::CMDOPTION_DISABLED ); + bool bHasDisabledEntries = SvtCommandOptions().HasEntriesDisabled(); SolarMutexGuard g; @@ -589,7 +576,7 @@ IMPL_LINK( MenuBarManager, Activate, Menu *, pMenu, bool ) m_bActive = true; // Check if some modes have changed so we have to update our menu images - OUString sIconTheme = SvtMiscOptions().GetIconTheme(); + OUString sIconTheme = SvtMiscOptions::GetIconTheme(); if ( m_bRetrieveImages || bShowMenuImages != m_bShowMenuImages || @@ -666,14 +653,23 @@ IMPL_LINK( MenuBarManager, Activate, Menu *, pMenu, bool ) if ( bHasDisabledEntries ) { - if ( aCmdOptions.Lookup( SvtCommandOptions::CMDOPTION_DISABLED, aTargetURL.Path )) + if ( aCmdOptions.LookupDisabled( aTargetURL.Path )) pMenu->HideItem( menuItemHandler->nItemId ); } if ( aTargetURL.Complete.startsWith( ".uno:StyleApply?" ) ) xMenuItemDispatch = new StyleDispatcher( m_xFrame, m_xURLTransformer, aTargetURL ); else - xMenuItemDispatch = xDispatchProvider->queryDispatch( aTargetURL, menuItemHandler->aTargetFrame, 0 ); + { + try + { + xMenuItemDispatch = xDispatchProvider->queryDispatch( aTargetURL, menuItemHandler->aTargetFrame, 0 ); + } + catch (uno::Exception const&) + { + TOOLS_WARN_EXCEPTION("fwk.uielement", "MenuBarManager::Activate(): exception from queryDispatch()"); + } + } bool bPopupMenu( false ); if ( !menuItemHandler->xPopupMenuController.is() && @@ -681,6 +677,15 @@ IMPL_LINK( MenuBarManager, Activate, Menu *, pMenu, bool ) { if( xMenuItemDispatch.is() || menuItemHandler->aMenuItemURL != ".uno:RecentFileList" ) bPopupMenu = CreatePopupMenuController(menuItemHandler.get(), m_xDispatchProvider, m_aModuleIdentifier); + + if (bPopupMenu && menuItemHandler->xPopupMenuController.is()) + { + if (PopupMenu* pThisPopup = pMenu->GetPopupMenu(menuItemHandler->nItemId)) + { + pThisPopup->Activate(); + pThisPopup->Deactivate(); + } + } } else if ( menuItemHandler->xPopupMenuController.is() ) { @@ -688,7 +693,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); @@ -712,6 +720,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() ) @@ -731,8 +744,16 @@ IMPL_LINK( MenuBarManager, Activate, Menu *, pMenu, bool ) { } } - else if ( menuItemHandler->xSubMenuManager.is() ) + else if (menuItemHandler->xSubMenuManager.is()) + { + MenuBarManager* pMenuBarManager = menuItemHandler->xSubMenuManager.get(); + if (pMenuBarManager) + { + pMenuBarManager->Activate(pMenuBarManager->GetMenuBar()); + pMenuBarManager->Deactivate(pMenuBarManager->GetMenuBar()); + } lcl_CheckForChildren(pMenu, menuItemHandler->nItemId); + } } } @@ -849,7 +870,7 @@ bool MenuBarManager::MustBeHidden( PopupMenu* pPopupMenu, const Reference< XURLT aTargetURL.Complete = pPopupMenu->GetItemCommand( nId ); rTransformer->parseStrict( aTargetURL ); - if ( aCmdOptions.Lookup( SvtCommandOptions::CMDOPTION_DISABLED, aTargetURL.Path )) + if ( aCmdOptions.LookupDisabled( aTargetURL.Path )) ++nHideCount; } } @@ -882,10 +903,10 @@ bool MenuBarManager::CreatePopupMenuController( MenuItemHandler* pMenuItemHandle return false; auto aSeq( comphelper::InitAnyPropertySequence( { - { "DispatchProvider", makeAny(rDispatchProvider) }, - { "ModuleIdentifier", makeAny(rModuleIdentifier) }, - { "Frame", makeAny(m_xFrame) }, - { "InToolbar", makeAny(!m_bHasMenuBar) } + { "DispatchProvider", Any(rDispatchProvider) }, + { "ModuleIdentifier", Any(rModuleIdentifier) }, + { "Frame", Any(m_xFrame) }, + { "InToolbar", Any(!m_bHasMenuBar) } } ) ); Reference< XPopupMenuController > xPopupMenuController( @@ -971,7 +992,6 @@ void MenuBarManager::FillMenuManager( Menu* pMenu, const Reference< XFrame >& rF aItemCommand = aRealCommand; Reference< XDispatch > xDispatch; - Reference< XStatusListener > xStatusListener; VclPtr<PopupMenu> pPopup = pMenu->GetPopupMenu( nItemId ); // overwrite the show icons on menu option? MenuItemBits nBits = pMenu->GetItemBits( nItemId ) & ( MenuItemBits::ICON | MenuItemBits::TEXT ); @@ -1000,7 +1020,7 @@ void MenuBarManager::FillMenuManager( Menu* pMenu, const Reference< XFrame >& rF // Check if we have to create a popup menu for a uno based popup menu controller. // We have to set an empty popup menu into our menu structure so the controller also // works with inplace OLE. - MenuItemHandler* pItemHandler = new MenuItemHandler( nItemId, xStatusListener, xDispatch ); + MenuItemHandler* pItemHandler = new MenuItemHandler( nItemId, nullptr, xDispatch ); rtl::Reference<VCLXPopupMenu> pVCLXPopupMenu = new VCLXPopupMenu(pPopup); pItemHandler->xPopupMenu = pVCLXPopupMenu; pItemHandler->aMenuItemURL = aItemCommand; @@ -1044,7 +1064,7 @@ void MenuBarManager::FillMenuManager( Menu* pMenu, const Reference< XFrame >& rF if ( bItemShowMenuImages ) m_bRetrieveImages = true; - std::unique_ptr<MenuItemHandler> pItemHandler(new MenuItemHandler( nItemId, xStatusListener, xDispatch )); + std::unique_ptr<MenuItemHandler> pItemHandler(new MenuItemHandler( nItemId, nullptr, xDispatch )); // Retrieve possible attributes struct MenuAttributes* pAttributes = static_cast<MenuAttributes *>(pMenu->GetUserValue( nItemId )); if ( pAttributes ) @@ -1250,7 +1270,7 @@ void MenuBarManager::FillMenuWithConfiguration( AddonsOptions().GetMergeMenuInstructions(), rModuleIdentifier ); - bool bHasDisabledEntries = SvtCommandOptions().HasEntries( SvtCommandOptions::CMDOPTION_DISABLED ); + bool bHasDisabledEntries = SvtCommandOptions().HasEntriesDisabled(); if ( !bHasDisabledEntries ) return; @@ -1295,7 +1315,7 @@ void MenuBarManager::FillMenu( bool bShow = true; bool bEnabled = true; - for ( beans::PropertyValue const & rProp : std::as_const(aProps) ) + for (beans::PropertyValue const& rProp : aProps) { OUString aPropName = rProp.Name; if ( aPropName == "CommandURL" ) @@ -1351,6 +1371,8 @@ void MenuBarManager::FillMenu( { VclPtr<PopupMenu> pNewPopupMenu = VclPtr<PopupMenu>::Create(); pMenu->SetPopupMenu( nId, pNewPopupMenu ); + // Use the command URL as the Help ID for the sub menu + pNewPopupMenu->SetHelpId(aCommandURL); if ( xDispatchProvider.is() ) { @@ -1502,11 +1524,9 @@ void MenuBarManager::GetPopupController( PopupControllerCache& rPopupController rPopupController.emplace( aMainURL, aPopupControllerEntry ); } } - if ( menuItemHandler->xSubMenuManager.is() ) + if ( menuItemHandler->xSubMenuManager ) { - MenuBarManager* pMenuBarManager = static_cast<MenuBarManager*>(menuItemHandler->xSubMenuManager.get()); - if ( pMenuBarManager ) - pMenuBarManager->GetPopupController( rPopupController ); + menuItemHandler->xSubMenuManager->GetPopupController( rPopupController ); } } } @@ -1516,16 +1536,16 @@ void MenuBarManager::AddMenu(MenuBarManager* pSubMenuManager,const OUString& _sI Reference< XStatusListener > xSubMenuManager( pSubMenuManager ); m_xFrame->addFrameActionListener( Reference< XFrameActionListener >( xSubMenuManager, UNO_QUERY )); - Reference< XDispatch > xDispatch; std::unique_ptr<MenuItemHandler> pMenuItemHandler(new MenuItemHandler( _nItemId, - xSubMenuManager, - xDispatch )); + pSubMenuManager, + Reference<XDispatch>() )); pMenuItemHandler->aMenuItemURL = _sItemCommand; m_aMenuItemHandlerVector.push_back( std::move(pMenuItemHandler) ); } -sal_uInt16 MenuBarManager::FillItemCommand(OUString& _rItemCommand, Menu* _pMenu,sal_uInt16 _nIndex) const +// static +sal_uInt16 MenuBarManager::FillItemCommand(OUString& _rItemCommand, Menu* _pMenu,sal_uInt16 _nIndex) { sal_uInt16 nItemId = _pMenu->GetItemId( _nIndex ); |