diff options
Diffstat (limited to 'framework/source/uielement/newmenucontroller.cxx')
-rw-r--r-- | framework/source/uielement/newmenucontroller.cxx | 396 |
1 files changed, 198 insertions, 198 deletions
diff --git a/framework/source/uielement/newmenucontroller.cxx b/framework/source/uielement/newmenucontroller.cxx index 5bb88b23842b..0bcd24982c47 100644 --- a/framework/source/uielement/newmenucontroller.cxx +++ b/framework/source/uielement/newmenucontroller.cxx @@ -124,24 +124,24 @@ void NewMenuController::determineAndSetNewDocAccel( PopupMenu* pPopupMenu, const } } - if ( !bFound ) + if ( bFound ) + return; + + // Search for the default module name + OUString aDefaultModuleName( SvtModuleOptions().GetDefaultModuleName() ); + if ( aDefaultModuleName.isEmpty() ) + return; + + for ( sal_uInt16 i = 0; i < nCount; i++ ) { - // Search for the default module name - OUString aDefaultModuleName( SvtModuleOptions().GetDefaultModuleName() ); - if ( !aDefaultModuleName.isEmpty() ) + if ( pPopupMenu->GetItemType( i ) != MenuItemType::SEPARATOR ) { - for ( sal_uInt16 i = 0; i < nCount; i++ ) + nId = pPopupMenu->GetItemId( i ); + aCommand = pPopupMenu->GetItemCommand( nId ); + if ( aCommand.indexOf( aDefaultModuleName ) >= 0 ) { - if ( pPopupMenu->GetItemType( i ) != MenuItemType::SEPARATOR ) - { - nId = pPopupMenu->GetItemId( i ); - aCommand = pPopupMenu->GetItemCommand( nId ); - if ( aCommand.indexOf( aDefaultModuleName ) >= 0 ) - { - pPopupMenu->SetAccelKey( nId, rKeyCode ); - break; - } - } + pPopupMenu->SetAccelKey( nId, rKeyCode ); + break; } } } @@ -149,110 +149,110 @@ void NewMenuController::determineAndSetNewDocAccel( PopupMenu* pPopupMenu, const void NewMenuController::setAccelerators( PopupMenu* pPopupMenu ) { - if ( m_bModuleIdentified ) - { - Reference< XAcceleratorConfiguration > xDocAccelCfg( m_xDocAcceleratorManager ); - Reference< XAcceleratorConfiguration > xModuleAccelCfg( m_xModuleAcceleratorManager ); - Reference< XAcceleratorConfiguration > xGlobalAccelCfg( m_xGlobalAcceleratorManager ); + if ( !m_bModuleIdentified ) + return; - if ( !m_bAcceleratorCfg ) + Reference< XAcceleratorConfiguration > xDocAccelCfg( m_xDocAcceleratorManager ); + Reference< XAcceleratorConfiguration > xModuleAccelCfg( m_xModuleAcceleratorManager ); + Reference< XAcceleratorConfiguration > xGlobalAccelCfg( m_xGlobalAcceleratorManager ); + + if ( !m_bAcceleratorCfg ) + { + // Retrieve references on demand + m_bAcceleratorCfg = true; + if ( !xDocAccelCfg.is() ) { - // Retrieve references on demand - m_bAcceleratorCfg = true; - if ( !xDocAccelCfg.is() ) + Reference< XController > xController = m_xFrame->getController(); + Reference< XModel > xModel; + if ( xController.is() ) { - Reference< XController > xController = m_xFrame->getController(); - Reference< XModel > xModel; - if ( xController.is() ) + xModel = xController->getModel(); + if ( xModel.is() ) { - xModel = xController->getModel(); - if ( xModel.is() ) + Reference< XUIConfigurationManagerSupplier > xSupplier( xModel, UNO_QUERY ); + if ( xSupplier.is() ) { - Reference< XUIConfigurationManagerSupplier > xSupplier( xModel, UNO_QUERY ); - if ( xSupplier.is() ) + Reference< XUIConfigurationManager > xDocUICfgMgr = xSupplier->getUIConfigurationManager(); + if ( xDocUICfgMgr.is() ) { - Reference< XUIConfigurationManager > xDocUICfgMgr = xSupplier->getUIConfigurationManager(); - if ( xDocUICfgMgr.is() ) - { - xDocAccelCfg = xDocUICfgMgr->getShortCutManager(); - m_xDocAcceleratorManager = xDocAccelCfg; - } + xDocAccelCfg = xDocUICfgMgr->getShortCutManager(); + m_xDocAcceleratorManager = xDocAccelCfg; } } } } + } - if ( !xModuleAccelCfg.is() ) + if ( !xModuleAccelCfg.is() ) + { + Reference< XModuleUIConfigurationManagerSupplier > xModuleCfgMgrSupplier = + theModuleUIConfigurationManagerSupplier::get( m_xContext ); + Reference< XUIConfigurationManager > xUICfgMgr = xModuleCfgMgrSupplier->getUIConfigurationManager( m_aModuleIdentifier ); + if ( xUICfgMgr.is() ) { - Reference< XModuleUIConfigurationManagerSupplier > xModuleCfgMgrSupplier = - theModuleUIConfigurationManagerSupplier::get( m_xContext ); - Reference< XUIConfigurationManager > xUICfgMgr = xModuleCfgMgrSupplier->getUIConfigurationManager( m_aModuleIdentifier ); - if ( xUICfgMgr.is() ) - { - xModuleAccelCfg = xUICfgMgr->getShortCutManager(); - m_xModuleAcceleratorManager = xModuleAccelCfg; - } + xModuleAccelCfg = xUICfgMgr->getShortCutManager(); + m_xModuleAcceleratorManager = xModuleAccelCfg; } + } - if ( !xGlobalAccelCfg.is() ) - { - xGlobalAccelCfg = GlobalAcceleratorConfiguration::create( m_xContext ); - m_xGlobalAcceleratorManager = xGlobalAccelCfg; - } + if ( !xGlobalAccelCfg.is() ) + { + xGlobalAccelCfg = GlobalAcceleratorConfiguration::create( m_xContext ); + m_xGlobalAcceleratorManager = xGlobalAccelCfg; } + } - vcl::KeyCode aEmptyKeyCode; - sal_uInt16 nItemCount( pPopupMenu->GetItemCount() ); - std::vector< vcl::KeyCode > aMenuShortCuts; - std::vector< OUString > aCmds; - std::vector< sal_uInt16 > aIds; - for ( sal_uInt16 i = 0; i < nItemCount; i++ ) + vcl::KeyCode aEmptyKeyCode; + sal_uInt16 nItemCount( pPopupMenu->GetItemCount() ); + std::vector< vcl::KeyCode > aMenuShortCuts; + std::vector< OUString > aCmds; + std::vector< sal_uInt16 > aIds; + for ( sal_uInt16 i = 0; i < nItemCount; i++ ) + { + if ( pPopupMenu->GetItemType( i ) != MenuItemType::SEPARATOR ) { - if ( pPopupMenu->GetItemType( i ) != MenuItemType::SEPARATOR ) - { - sal_uInt16 nId( pPopupMenu->GetItemId( i )); - aIds.push_back( nId ); - aMenuShortCuts.push_back( aEmptyKeyCode ); - aCmds.push_back( pPopupMenu->GetItemCommand( nId )); - } + sal_uInt16 nId( pPopupMenu->GetItemId( i )); + aIds.push_back( nId ); + aMenuShortCuts.push_back( aEmptyKeyCode ); + aCmds.push_back( pPopupMenu->GetItemCommand( nId )); } + } - sal_uInt32 nSeqCount( aIds.size() ); + sal_uInt32 nSeqCount( aIds.size() ); - if ( m_bNewMenu ) - nSeqCount+=1; + if ( m_bNewMenu ) + nSeqCount+=1; - Sequence< OUString > aSeq( nSeqCount ); + Sequence< OUString > aSeq( nSeqCount ); - // Add a special command for our "New" menu. - if ( m_bNewMenu ) - { - aSeq[nSeqCount-1] = m_aCommandURL; - aMenuShortCuts.push_back( aEmptyKeyCode ); - } + // Add a special command for our "New" menu. + if ( m_bNewMenu ) + { + aSeq[nSeqCount-1] = m_aCommandURL; + aMenuShortCuts.push_back( aEmptyKeyCode ); + } - const sal_uInt32 nCount = aCmds.size(); - for ( sal_uInt32 i = 0; i < nCount; i++ ) - aSeq[i] = aCmds[i]; + const sal_uInt32 nCount = aCmds.size(); + for ( sal_uInt32 i = 0; i < nCount; i++ ) + aSeq[i] = aCmds[i]; - if ( m_xGlobalAcceleratorManager.is() ) - retrieveShortcutsFromConfiguration( xGlobalAccelCfg, aSeq, aMenuShortCuts ); - if ( m_xModuleAcceleratorManager.is() ) - retrieveShortcutsFromConfiguration( xModuleAccelCfg, aSeq, aMenuShortCuts ); - if ( m_xDocAcceleratorManager.is() ) - retrieveShortcutsFromConfiguration( xDocAccelCfg, aSeq, aMenuShortCuts ); + if ( m_xGlobalAcceleratorManager.is() ) + retrieveShortcutsFromConfiguration( xGlobalAccelCfg, aSeq, aMenuShortCuts ); + if ( m_xModuleAcceleratorManager.is() ) + retrieveShortcutsFromConfiguration( xModuleAccelCfg, aSeq, aMenuShortCuts ); + if ( m_xDocAcceleratorManager.is() ) + retrieveShortcutsFromConfiguration( xDocAccelCfg, aSeq, aMenuShortCuts ); - const sal_uInt32 nCount2 = aIds.size(); - for ( sal_uInt32 i = 0; i < nCount2; i++ ) - pPopupMenu->SetAccelKey( aIds[i], aMenuShortCuts[i] ); + const sal_uInt32 nCount2 = aIds.size(); + for ( sal_uInt32 i = 0; i < nCount2; i++ ) + pPopupMenu->SetAccelKey( aIds[i], aMenuShortCuts[i] ); - // Special handling for "New" menu short-cut should be set at the - // document which will be opened using it. - if ( m_bNewMenu ) - { - if ( aMenuShortCuts[nSeqCount-1] != aEmptyKeyCode ) - determineAndSetNewDocAccel( pPopupMenu, aMenuShortCuts[nSeqCount-1] ); - } + // Special handling for "New" menu short-cut should be set at the + // document which will be opened using it. + if ( m_bNewMenu ) + { + if ( aMenuShortCuts[nSeqCount-1] != aEmptyKeyCode ) + determineAndSetNewDocAccel( pPopupMenu, aMenuShortCuts[nSeqCount-1] ); } } @@ -261,22 +261,22 @@ void NewMenuController::retrieveShortcutsFromConfiguration( const Sequence< OUString >& rCommands, std::vector< vcl::KeyCode >& aMenuShortCuts ) { - if ( rAccelCfg.is() ) + if ( !rAccelCfg.is() ) + return; + + try { - try - { - css::awt::KeyEvent aKeyEvent; - Sequence< Any > aSeqKeyCode = rAccelCfg->getPreferredKeyEventsForCommandList( rCommands ); - for ( sal_Int32 i = 0; i < aSeqKeyCode.getLength(); i++ ) - { - if ( aSeqKeyCode[i] >>= aKeyEvent ) - aMenuShortCuts[i] = svt::AcceleratorExecute::st_AWTKey2VCLKey( aKeyEvent ); - } - } - catch ( const IllegalArgumentException& ) + css::awt::KeyEvent aKeyEvent; + Sequence< Any > aSeqKeyCode = rAccelCfg->getPreferredKeyEventsForCommandList( rCommands ); + for ( sal_Int32 i = 0; i < aSeqKeyCode.getLength(); i++ ) { + if ( aSeqKeyCode[i] >>= aKeyEvent ) + aMenuShortCuts[i] = svt::AcceleratorExecute::st_AWTKey2VCLKey( aKeyEvent ); } } + catch ( const IllegalArgumentException& ) + { + } } NewMenuController::NewMenuController( const css::uno::Reference< css::uno::XComponentContext >& xContext ) : @@ -306,59 +306,59 @@ void NewMenuController::fillPopupMenu( Reference< css::awt::XPopupMenu > const & if ( pPopupMenu ) pVCLPopupMenu = static_cast<PopupMenu *>(pPopupMenu->GetMenu()); - if ( pVCLPopupMenu ) + if ( !pVCLPopupMenu ) + return; + + Reference< XDispatchProvider > xDispatchProvider( m_xFrame, UNO_QUERY ); + URL aTargetURL; + aTargetURL.Complete = OUString::createFromAscii(m_bNewMenu ? aSlotNewDocDirect : aSlotAutoPilot); + m_xURLTransformer->parseStrict( aTargetURL ); + Reference< XDispatch > xMenuItemDispatch = xDispatchProvider->queryDispatch( aTargetURL, OUString(), 0 ); + if(xMenuItemDispatch == nullptr) + return; + + const css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > > aDynamicMenuEntries = + SvtDynamicMenuOptions().GetMenu( m_bNewMenu ? EDynamicMenuType::NewMenu : EDynamicMenuType::WizardMenu ); + + OUString aTitle; + OUString aURL; + OUString aTargetFrame; + OUString aImageId; + sal_uInt16 nItemId = 1; + + for ( const auto& aDynamicMenuEntry : aDynamicMenuEntries ) { - Reference< XDispatchProvider > xDispatchProvider( m_xFrame, UNO_QUERY ); - URL aTargetURL; - aTargetURL.Complete = OUString::createFromAscii(m_bNewMenu ? aSlotNewDocDirect : aSlotAutoPilot); - m_xURLTransformer->parseStrict( aTargetURL ); - Reference< XDispatch > xMenuItemDispatch = xDispatchProvider->queryDispatch( aTargetURL, OUString(), 0 ); - if(xMenuItemDispatch == nullptr) - return; - - const css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > > aDynamicMenuEntries = - SvtDynamicMenuOptions().GetMenu( m_bNewMenu ? EDynamicMenuType::NewMenu : EDynamicMenuType::WizardMenu ); - - OUString aTitle; - OUString aURL; - OUString aTargetFrame; - OUString aImageId; - sal_uInt16 nItemId = 1; - - for ( const auto& aDynamicMenuEntry : aDynamicMenuEntries ) + for ( const auto& aProperty : aDynamicMenuEntry ) { - for ( const auto& aProperty : aDynamicMenuEntry ) - { - if ( aProperty.Name == DYNAMICMENU_PROPERTYNAME_URL ) - aProperty.Value >>= aURL; - else if ( aProperty.Name == DYNAMICMENU_PROPERTYNAME_TITLE ) - aProperty.Value >>= aTitle; - else if ( aProperty.Name == DYNAMICMENU_PROPERTYNAME_IMAGEIDENTIFIER ) - aProperty.Value >>= aImageId; - else if ( aProperty.Name == DYNAMICMENU_PROPERTYNAME_TARGETNAME ) - aProperty.Value >>= aTargetFrame; - } + if ( aProperty.Name == DYNAMICMENU_PROPERTYNAME_URL ) + aProperty.Value >>= aURL; + else if ( aProperty.Name == DYNAMICMENU_PROPERTYNAME_TITLE ) + aProperty.Value >>= aTitle; + else if ( aProperty.Name == DYNAMICMENU_PROPERTYNAME_IMAGEIDENTIFIER ) + aProperty.Value >>= aImageId; + else if ( aProperty.Name == DYNAMICMENU_PROPERTYNAME_TARGETNAME ) + aProperty.Value >>= aTargetFrame; + } - if ( aTitle.isEmpty() && aURL.isEmpty() ) - continue; + if ( aTitle.isEmpty() && aURL.isEmpty() ) + continue; - if ( aURL == "private:separator" ) - pVCLPopupMenu->InsertSeparator(); - else - { - pVCLPopupMenu->InsertItem( nItemId, aTitle ); - pVCLPopupMenu->SetItemCommand( nItemId, aURL ); + if ( aURL == "private:separator" ) + pVCLPopupMenu->InsertSeparator(); + else + { + pVCLPopupMenu->InsertItem( nItemId, aTitle ); + pVCLPopupMenu->SetItemCommand( nItemId, aURL ); - void* nAttributePtr = MenuAttributes::CreateAttribute( aTargetFrame, aImageId ); - pVCLPopupMenu->SetUserValue( nItemId, nAttributePtr, MenuAttributes::ReleaseAttribute ); + void* nAttributePtr = MenuAttributes::CreateAttribute( aTargetFrame, aImageId ); + pVCLPopupMenu->SetUserValue( nItemId, nAttributePtr, MenuAttributes::ReleaseAttribute ); - nItemId++; - } + nItemId++; } - - if ( m_bShowImages ) - setMenuImages( pVCLPopupMenu, m_bShowImages ); } + + if ( m_bShowImages ) + setMenuImages( pVCLPopupMenu, m_bShowImages ); } // XEventListener @@ -393,57 +393,57 @@ void SAL_CALL NewMenuController::itemSelected( const css::awt::MenuEvent& rEvent xContext = m_xContext; } - if ( xPopupMenu.is() ) - { - VCLXPopupMenu* pPopupMenu = static_cast<VCLXPopupMenu *>(comphelper::getUnoTunnelImplementation<VCLXMenu>( xPopupMenu )); - if ( pPopupMenu ) - { - OUString aURL; - OUString aTargetFrame( m_aTargetFrame ); + if ( !xPopupMenu.is() ) + return; - { - SolarMutexGuard aSolarMutexGuard; - PopupMenu* pVCLPopupMenu = static_cast<PopupMenu *>(pPopupMenu->GetMenu()); - aURL = pVCLPopupMenu->GetItemCommand(rEvent.MenuId); - void* nAttributePtr = pVCLPopupMenu->GetUserValue(rEvent.MenuId); - MenuAttributes* pAttributes = static_cast<MenuAttributes *>(nAttributePtr); - if (pAttributes) - aTargetFrame = pAttributes->aTargetFrame; - } + VCLXPopupMenu* pPopupMenu = static_cast<VCLXPopupMenu *>(comphelper::getUnoTunnelImplementation<VCLXMenu>( xPopupMenu )); + if ( !pPopupMenu ) + return; - Sequence< PropertyValue > aArgsList( 1 ); - aArgsList[0].Name = "Referer"; - aArgsList[0].Value <<= OUString( "private:user" ); + OUString aURL; + OUString aTargetFrame( m_aTargetFrame ); - dispatchCommand( aURL, aArgsList, aTargetFrame ); - } + { + SolarMutexGuard aSolarMutexGuard; + PopupMenu* pVCLPopupMenu = static_cast<PopupMenu *>(pPopupMenu->GetMenu()); + aURL = pVCLPopupMenu->GetItemCommand(rEvent.MenuId); + void* nAttributePtr = pVCLPopupMenu->GetUserValue(rEvent.MenuId); + MenuAttributes* pAttributes = static_cast<MenuAttributes *>(nAttributePtr); + if (pAttributes) + aTargetFrame = pAttributes->aTargetFrame; } + + Sequence< PropertyValue > aArgsList( 1 ); + aArgsList[0].Name = "Referer"; + aArgsList[0].Value <<= OUString( "private:user" ); + + dispatchCommand( aURL, aArgsList, aTargetFrame ); } void SAL_CALL NewMenuController::itemActivated( const css::awt::MenuEvent& ) { SolarMutexGuard aSolarMutexGuard; - if ( m_xFrame.is() && m_xPopupMenu.is() ) - { - VCLXPopupMenu* pPopupMenu = static_cast<VCLXPopupMenu *>(comphelper::getUnoTunnelImplementation<VCLXMenu>( m_xPopupMenu )); - if ( pPopupMenu ) - { - const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings(); - bool bShowImages( rSettings.GetUseImagesInMenus() ); - OUString aIconTheme( rSettings.DetermineIconTheme() ); + if ( !(m_xFrame.is() && m_xPopupMenu.is()) ) + return; - PopupMenu* pVCLPopupMenu = static_cast<PopupMenu *>(pPopupMenu->GetMenu()); + VCLXPopupMenu* pPopupMenu = static_cast<VCLXPopupMenu *>(comphelper::getUnoTunnelImplementation<VCLXMenu>( m_xPopupMenu )); + if ( !pPopupMenu ) + return; - if ( m_bShowImages != bShowImages || m_aIconTheme != aIconTheme ) - { - m_bShowImages = bShowImages; - m_aIconTheme = aIconTheme; - setMenuImages( pVCLPopupMenu, m_bShowImages ); - } + const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings(); + bool bShowImages( rSettings.GetUseImagesInMenus() ); + OUString aIconTheme( rSettings.DetermineIconTheme() ); - setAccelerators( pVCLPopupMenu ); - } + PopupMenu* pVCLPopupMenu = static_cast<PopupMenu *>(pPopupMenu->GetMenu()); + + if ( m_bShowImages != bShowImages || m_aIconTheme != aIconTheme ) + { + m_bShowImages = bShowImages; + m_aIconTheme = aIconTheme; + setMenuImages( pVCLPopupMenu, m_bShowImages ); } + + setAccelerators( pVCLPopupMenu ); } // XPopupMenuController @@ -492,18 +492,18 @@ void SAL_CALL NewMenuController::initialize( const Sequence< Any >& aArguments ) osl::MutexGuard aLock( m_aMutex ); bool bInitalized( m_bInitialized ); - if ( !bInitalized ) - { - svt::PopupMenuControllerBase::initialize( aArguments ); + if ( bInitalized ) + return; - if ( m_bInitialized ) - { - const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings(); + svt::PopupMenuControllerBase::initialize( aArguments ); - m_bShowImages = rSettings.GetUseImagesInMenus(); - m_aIconTheme = rSettings.DetermineIconTheme(); - m_bNewMenu = m_aCommandURL == aSlotNewDocDirect; - } + if ( m_bInitialized ) + { + const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings(); + + m_bShowImages = rSettings.GetUseImagesInMenus(); + m_aIconTheme = rSettings.DetermineIconTheme(); + m_bNewMenu = m_aCommandURL == aSlotNewDocDirect; } } |