diff options
author | Christian Lippka <cl@openoffice.org> | 2010-05-06 14:54:49 +0200 |
---|---|---|
committer | Christian Lippka <cl@openoffice.org> | 2010-05-06 14:54:49 +0200 |
commit | 1b831d5078b8ab624b83d8a9ef28e910c9a117e6 (patch) | |
tree | 2c2914ac3a2b736dcaa17d29a798d102085b67c3 | |
parent | 996dee347a8a44b9c2c0ccab06b5961de1fbbd2d (diff) |
#i109296# add shortcuts to toolbar items
-rw-r--r-- | framework/inc/uielement/toolbarmanager.hxx | 9 | ||||
-rw-r--r-- | framework/source/uielement/toolbarmanager.cxx | 147 |
2 files changed, 153 insertions, 3 deletions
diff --git a/framework/inc/uielement/toolbarmanager.hxx b/framework/inc/uielement/toolbarmanager.hxx index f8f4715ef1..aa30175d35 100644 --- a/framework/inc/uielement/toolbarmanager.hxx +++ b/framework/inc/uielement/toolbarmanager.hxx @@ -58,6 +58,7 @@ #include <com/sun/star/frame/XToolbarController.hpp> #include <com/sun/star/ui/ItemStyle.hpp> #include <com/sun/star/util/XURLTransformer.hpp> +#include <com/sun/star/ui/XAcceleratorConfiguration.hpp> //_________________________________________________________________________________________________________________ // other includes @@ -67,6 +68,7 @@ #include <cppuhelper/interfacecontainer.hxx> #include <vcl/toolbox.hxx> +#include <vcl/accel.hxx> namespace com { @@ -194,6 +196,9 @@ class ToolBarManager : public ::com::sun::star::frame::XFrameActionListener void setToolBarImage(const Image& _aImage,const CommandToInfoMap::const_iterator& _pIter); void impl_elementChanged(bool _bRemove,const ::com::sun::star::ui::ConfigurationEvent& Event ); + static bool impl_RetrieveShortcutsFromConfiguration( const ::com::sun::star::uno::Reference< ::com::sun::star::ui::XAcceleratorConfiguration >& rAccelCfg, const rtl::OUString& rCommand, rtl::OUString& rShortCut ); + bool RetrieveShortcut( const rtl::OUString& rCommandURL, rtl::OUString& rShortCut ); + protected: typedef ::std::hash_map< sal_uInt16, ::com::sun::star::uno::Reference< com::sun::star::frame::XStatusListener > > ToolBarControllerMap; typedef ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::frame::XSubToolbarController > > SubToolBarControllerVector; @@ -233,6 +238,10 @@ class ToolBarManager : public ::com::sun::star::frame::XFrameActionListener Timer m_aAsyncUpdateControllersTimer; sal_Int16 m_nSymbolsStyle; MenuDescriptionMap m_aMenuMap; + sal_Bool m_bAcceleratorCfg; + ::com::sun::star::uno::Reference< ::com::sun::star::ui::XAcceleratorConfiguration > m_xDocAcceleratorManager; + ::com::sun::star::uno::Reference< ::com::sun::star::ui::XAcceleratorConfiguration > m_xModuleAcceleratorManager; + ::com::sun::star::uno::Reference< ::com::sun::star::ui::XAcceleratorConfiguration > m_xGlobalAcceleratorManager; }; } diff --git a/framework/source/uielement/toolbarmanager.cxx b/framework/source/uielement/toolbarmanager.cxx index 183bd5510c..d5151d383c 100644 --- a/framework/source/uielement/toolbarmanager.cxx +++ b/framework/source/uielement/toolbarmanager.cxx @@ -52,6 +52,7 @@ #endif #include <classes/addonsoptions.hxx> #include <uielement/toolbarmerger.hxx> +#include <helper/acceleratorinfo.hxx> //_________________________________________________________________________________________________________________ // interface includes @@ -98,11 +99,14 @@ #include <svtools/menuoptions.hxx> #include <unotools/cmdoptions.hxx> #include <boost/bind.hpp> +#include <svtools/acceleratorexecute.hxx> //_________________________________________________________________________________________________________________ // namespaces //_________________________________________________________________________________________________________________ +using rtl::OUString; + using namespace ::com::sun::star::awt; using namespace ::com::sun::star::beans; using namespace ::com::sun::star::uno; @@ -258,7 +262,8 @@ ToolBarManager::ToolBarManager( const Reference< XMultiServiceFactory >& rServic m_xFrame( rFrame ), m_aListenerContainer( m_aLock.getShareableOslMutex() ), m_xServiceManager( rServiceManager ), - m_nSymbolsStyle( SvtMiscOptions().GetCurrentSymbolsStyle() ) + m_nSymbolsStyle( SvtMiscOptions().GetCurrentSymbolsStyle() ), + m_bAcceleratorCfg( sal_False ) { Window* pWindow = m_pToolBar; while ( pWindow && !pWindow->IsSystemWindow() ) @@ -664,6 +669,9 @@ void SAL_CALL ToolBarManager::dispose() throw( RuntimeException ) m_xFrame.clear(); m_xServiceManager.clear(); + m_xGlobalAcceleratorManager.clear(); + m_xModuleAcceleratorManager.clear(); + m_xDocAcceleratorManager.clear(); m_bDisposed = sal_True; } @@ -1262,13 +1270,31 @@ void ToolBarManager::FillToolbar( const Reference< XIndexAccess >& rItemContaine m_pToolBar->InsertItem( nId, aString, nItemBits ); m_pToolBar->SetItemCommand( nId, aCommandURL ); if ( aTooltip.getLength() ) + { m_pToolBar->SetQuickHelpText( nId, aTooltip ); + } else - m_pToolBar->SetQuickHelpText( nId, aString ); + { + ::rtl::OUString sQuickHelp( aString ); + ::rtl::OUString sShortCut; + if( RetrieveShortcut( aCommandURL, sShortCut ) ) + { + sQuickHelp += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( " (" ) ); + sQuickHelp += sShortCut; + sQuickHelp += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ")" ) ); + } + + m_pToolBar->SetQuickHelpText( nId, sQuickHelp ); + } + if ( aLabel.getLength() > 0 ) + { m_pToolBar->SetItemText( nId, aLabel ); + } else + { m_pToolBar->SetItemText( nId, aString ); + } m_pToolBar->EnableItem( nId, sal_True ); m_pToolBar->SetItemState( nId, STATE_NOCHECK ); @@ -2092,7 +2118,7 @@ IMPL_STATIC_LINK_NOINSTANCE( ToolBarManager, ExecuteHdl_Impl, ExecuteInfo*, pExe { pExecuteInfo->xLayoutManager->dockAllWindows( UIElementType::TOOLBAR ); } - } + } catch ( Exception& ) { } @@ -2107,6 +2133,121 @@ Image ToolBarManager::QueryAddonsImage( const ::rtl::OUString& aCommandURL, bool return aImage; } +bool ToolBarManager::impl_RetrieveShortcutsFromConfiguration( + const Reference< XAcceleratorConfiguration >& rAccelCfg, + const rtl::OUString& rCommand, + rtl::OUString& rShortCut ) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "ToolBarManager::impl_RetrieveShortcutsFromConfiguration" ); + if ( rAccelCfg.is() ) + { + try + { + com::sun::star::awt::KeyEvent aKeyEvent; + Sequence< OUString > aCommands(1); + aCommands[0] = rCommand; + + Sequence< Any > aSeqKeyCode( rAccelCfg->getPreferredKeyEventsForCommandList( aCommands ) ); + if( aSeqKeyCode.getLength() == 1 ) + { + if ( aSeqKeyCode[0] >>= aKeyEvent ) + { + rShortCut = svt::AcceleratorExecute::st_AWTKey2VCLKey( aKeyEvent ).GetName(); + return true; + } + } + } + catch ( IllegalArgumentException& ) + { + } + } + + return false; +} + +bool ToolBarManager::RetrieveShortcut( const rtl::OUString& rCommandURL, rtl::OUString& rShortCut ) +{ + RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "ToolBarManager::RetrieveShortcuts" ); + if ( m_bModuleIdentified ) + { + Reference< XAcceleratorConfiguration > xDocAccelCfg( m_xDocAcceleratorManager ); + Reference< XAcceleratorConfiguration > xModuleAccelCfg( m_xModuleAcceleratorManager ); + Reference< XAcceleratorConfiguration > xGlobalAccelCfg( m_xGlobalAcceleratorManager ); + + if ( !m_bAcceleratorCfg ) + { + // Retrieve references on demand + m_bAcceleratorCfg = sal_True; + if ( !xDocAccelCfg.is() ) + { + Reference< XController > xController = m_xFrame->getController(); + Reference< XModel > xModel; + if ( xController.is() ) + { + xModel = xController->getModel(); + if ( xModel.is() ) + { + Reference< XUIConfigurationManagerSupplier > xSupplier( xModel, UNO_QUERY ); + if ( xSupplier.is() ) + { + Reference< XUIConfigurationManager > xDocUICfgMgr( xSupplier->getUIConfigurationManager(), UNO_QUERY ); + if ( xDocUICfgMgr.is() ) + { + xDocAccelCfg = Reference< XAcceleratorConfiguration >( xDocUICfgMgr->getShortCutManager(), UNO_QUERY ); + m_xDocAcceleratorManager = xDocAccelCfg; + } + } + } + } + } + + if ( !xModuleAccelCfg.is() ) + { + Reference< XModuleUIConfigurationManagerSupplier > xModuleCfgMgrSupplier( m_xServiceManager->createInstance( + SERVICENAME_MODULEUICONFIGURATIONMANAGERSUPPLIER ), + UNO_QUERY ); + try + { + Reference< XUIConfigurationManager > xUICfgMgr = xModuleCfgMgrSupplier->getUIConfigurationManager( m_aModuleIdentifier ); + if ( xUICfgMgr.is() ) + { + xModuleAccelCfg = Reference< XAcceleratorConfiguration >( xUICfgMgr->getShortCutManager(), UNO_QUERY ); + m_xModuleAcceleratorManager = xModuleAccelCfg; + } + } + catch ( RuntimeException& ) + { + throw; + } + catch ( Exception& ) + { + } + } + + if ( !xGlobalAccelCfg.is() ) + { + xGlobalAccelCfg = Reference< XAcceleratorConfiguration >( m_xServiceManager->createInstance( + SERVICENAME_GLOBALACCELERATORCONFIGURATION ), + UNO_QUERY ); + m_xGlobalAcceleratorManager = xGlobalAccelCfg; + } + } + + bool bFound = false; + + if ( m_xGlobalAcceleratorManager.is() ) + bFound = impl_RetrieveShortcutsFromConfiguration( xGlobalAccelCfg, rCommandURL, rShortCut ); + if ( !bFound && m_xModuleAcceleratorManager.is() ) + bFound = impl_RetrieveShortcutsFromConfiguration( xModuleAccelCfg, rCommandURL, rShortCut ); + if ( !bFound && m_xDocAcceleratorManager.is() ) + impl_RetrieveShortcutsFromConfiguration( xGlobalAccelCfg, rCommandURL, rShortCut ); + + if( bFound ) + return true; + } + return false; +} + } |