summaryrefslogtreecommitdiff
path: root/oox/source/ole/vbamodule.cxx
diff options
context:
space:
mode:
authorNoel Power <noel.power@novell.com>2012-03-05 20:14:13 +0000
committerNoel Power <noel.power@novell.com>2012-03-05 20:15:16 +0000
commit14620c3b33cf0315a9b746a0a2418b78d6154821 (patch)
tree0671d08a2e8fc2395442aac9a3e7acbbf7154fa5 /oox/source/ole/vbamodule.cxx
parentbe5567d9e36ad40deb3e5c6ed219265cddc944c0 (diff)
support import of key shortcut for macro ( Excel only )
Diffstat (limited to 'oox/source/ole/vbamodule.cxx')
-rw-r--r--oox/source/ole/vbamodule.cxx36
1 files changed, 35 insertions, 1 deletions
diff --git a/oox/source/ole/vbamodule.cxx b/oox/source/ole/vbamodule.cxx
index d4b041b2e1bf..9f0e5ffe6bf8 100644
--- a/oox/source/ole/vbamodule.cxx
+++ b/oox/source/ole/vbamodule.cxx
@@ -33,7 +33,9 @@
#include <com/sun/star/script/ModuleInfo.hpp>
#include <com/sun/star/script/ModuleType.hpp>
#include <com/sun/star/script/vba/XVBAModuleInfo.hpp>
+#include <com/sun/star/awt/KeyEvent.hpp>
#include <cppuhelper/implbase1.hxx>
+#include <filter/msfilter/msvbahelper.hxx>
#include "oox/helper/binaryinputstream.hxx"
#include "oox/helper/storagebase.hxx"
#include "oox/helper/textinputstream.hxx"
@@ -54,6 +56,7 @@ using namespace ::com::sun::star::uno;
using ::rtl::OUString;
using ::rtl::OUStringBuffer;
+using ::com::sun::star::awt::KeyEvent;
// ============================================================================
typedef ::cppu::WeakImplHelper1< XIndexContainer > OleIdToNameContainer_BASE;
typedef boost::unordered_map< sal_Int32, rtl::OUString > ObjIdToName;
@@ -249,7 +252,38 @@ OUString VbaModule::readSourceCode( StorageBase& rVbaStrg, const Reference< XNam
if( aCodeLine.matchAsciiL( RTL_CONSTASCII_STRINGPARAM( "Attribute " ) ) )
{
// attribute
- extractOleOverrideFromAttr( aCodeLine, rxOleNameOverrides );
+ int index = aCodeLine.indexOf( ".VB_ProcData.VB_Invoke_Func = " );
+ if ( index != -1 )
+ {
+ // format is
+ // 'Attribute Procedure.VB_ProcData.VB_Invoke_Func = "*\n14"'
+ // where 'Procedure' is the procedure name and '*' is the shortcut key
+ // note: his is only relevant for Excel, seems that
+ // word doesn't store the shortcut in the module
+ // attributes
+ int nSpaceIndex = aCodeLine.indexOf(' ');
+ rtl::OUString sProc = aCodeLine.copy( nSpaceIndex + 1, index - nSpaceIndex - 1);
+ // for Excel short cut key seems limited to cntrl+'a-z, A-Z'
+ rtl::OUString sKey = aCodeLine.copy( aCodeLine.lastIndexOf("= ") + 3, 1 );
+ // only alpha key valid for key shortcut, however the api will accept other keys
+ if ( !isalpha( (char)sKey[ 0 ] ) )
+ {
+ // cntrl modifier is explicit ( but could be cntrl+shift ), parseKeyEvent
+ // will handle and uppercase letter appropriately
+ rtl::OUString sApiKey = "^";
+ sApiKey += sKey;
+ try
+ {
+ KeyEvent aKeyEvent = ooo::vba::parseKeyEvent( sApiKey );
+ ooo::vba::applyShortCutKeyBinding( mxDocModel, aKeyEvent, sProc );
+ }
+ catch( Exception& )
+ {
+ }
+ }
+ }
+ else
+ extractOleOverrideFromAttr( aCodeLine, rxOleNameOverrides );
}
else
{