summaryrefslogtreecommitdiff
path: root/framework
diff options
context:
space:
mode:
authorChristian Lippka <cl@openoffice.org>2010-05-06 14:54:49 +0200
committerChristian Lippka <cl@openoffice.org>2010-05-06 14:54:49 +0200
commit5c3614277d347e72c403135f5c92c0c13fb55d5f (patch)
tree9bb5e3ad373a1b4bef9562d2750264293fea9712 /framework
parentc28130630c58f9d873b912c223573b3490b287e6 (diff)
#i109296# add shortcuts to toolbar items
Diffstat (limited to 'framework')
-rw-r--r--framework/inc/uielement/toolbarmanager.hxx9
-rw-r--r--framework/source/uielement/toolbarmanager.cxx145
2 files changed, 152 insertions, 2 deletions
diff --git a/framework/inc/uielement/toolbarmanager.hxx b/framework/inc/uielement/toolbarmanager.hxx
index 98894b623aea..62d117ee1a9c 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 5da7db82c363..25cd6f5ff4c5 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 );
@@ -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;
+}
+
}