summaryrefslogtreecommitdiff
path: root/filter
diff options
context:
space:
mode:
authorDaniel Rentz <dr@openoffice.org>2010-07-06 19:34:53 +0200
committerDaniel Rentz <dr@openoffice.org>2010-07-06 19:34:53 +0200
commit19d399fdda8f8e2b124e00bff54ecea476a3592e (patch)
tree0f901aeb53d33c41b9cf7f87822c5ae0e525be35 /filter
parentfdc8e8e76a6fb265a8a5fc31d36112d5e0c56a03 (diff)
mib17: #i112634# add VBA sheet event handling, based on a patch from Noel Power
Diffstat (limited to 'filter')
-rw-r--r--filter/source/msfilter/msvbahelper.cxx83
1 files changed, 47 insertions, 36 deletions
diff --git a/filter/source/msfilter/msvbahelper.cxx b/filter/source/msfilter/msvbahelper.cxx
index 18ecc5ae6530..19e93dbb791a 100644
--- a/filter/source/msfilter/msvbahelper.cxx
+++ b/filter/source/msfilter/msvbahelper.cxx
@@ -38,6 +38,7 @@
#include <com/sun/star/document/XDocumentInfoSupplier.hpp>
#include <tools/urlobj.hxx>
#include <osl/file.hxx>
+#include <unotools/pathoptions.hxx>
using namespace ::com::sun::star;
@@ -108,7 +109,24 @@ SfxObjectShell* findShellForUrl( const rtl::OUString& sMacroURLOrPath )
}
else
{
- if ( aURL.equals( xModel->getURL() ) )
+ // sometimes just the name of the document ( without the path
+ // is used
+ bool bDocNameNoPathMatch = false;
+ if ( aURL.getLength() && aURL.indexOf( '/' ) == -1 )
+ {
+ sal_Int32 lastSlashIndex = xModel->getURL().lastIndexOf( '/' );
+ if ( lastSlashIndex > -1 )
+ {
+ bDocNameNoPathMatch = xModel->getURL().copy( lastSlashIndex + 1 ).equals( aURL );
+ if ( !bDocNameNoPathMatch )
+ {
+ rtl::OUString aTmpName = rtl::OUString::createFromAscii("'") + xModel->getURL().copy( lastSlashIndex + 1 ) + rtl::OUString::createFromAscii("'");
+ bDocNameNoPathMatch = aTmpName.equals( aURL );
+ }
+ }
+ }
+
+ if ( aURL.equals( xModel->getURL() ) || bDocNameNoPathMatch )
{
pFoundShell = pShell;
break;
@@ -221,9 +239,19 @@ VBAMacroResolvedInfo resolveVBAMacro( SfxObjectShell* pShell, const rtl::OUStrin
String sDocUrlOrPath = sMacroUrl.copy( 0, nDocSepIndex );
sMacroUrl = sMacroUrl.copy( nDocSepIndex + 1 );
OSL_TRACE("doc search, current shell is 0x%x", pShell );
- SfxObjectShell* pFoundShell = findShellForUrl( sDocUrlOrPath );
+ SfxObjectShell* pFoundShell = NULL;
+ if( bSearchGlobalTemplates )
+ {
+ SvtPathOptions aPathOpt;
+ String aAddinPath = aPathOpt.GetAddinPath();
+ if( rtl::OUString( sDocUrlOrPath ).indexOf( aAddinPath ) == 0 )
+ pFoundShell = pShell;
+ }
+ if( pFoundShell == NULL )
+ pFoundShell = findShellForUrl( sDocUrlOrPath );
OSL_TRACE("doc search, after find, found shell is 0x%x", pFoundShell );
- aRes = resolveVBAMacro( pFoundShell, sMacroUrl );
+ aRes = resolveVBAMacro( pFoundShell, sMacroUrl, bSearchGlobalTemplates );
+ return aRes;
}
else
{
@@ -337,14 +365,14 @@ VBAMacroResolvedInfo resolveVBAMacro( SfxObjectShell* pShell, const rtl::OUStrin
break;
}
}
+ aRes.SetResolvedMacro( sProcedure.Insert( '.', 0 ).Insert( sModule, 0).Insert( '.', 0 ).Insert( sContainer, 0 ) );
}
- aRes.SetResolvedMacro( sProcedure.Insert( '.', 0 ).Insert( sModule, 0).Insert( '.', 0 ).Insert( sContainer, 0 ) );
return aRes;
}
// Treat the args as possible inouts ( convertion at bottom of method )
-sal_Bool executeMacro( SfxObjectShell* pShell, const String& sMacroName, uno::Sequence< uno::Any >& aArgs, uno::Any& /*aRet*/, const uno::Any& aCaller )
+sal_Bool executeMacro( SfxObjectShell* pShell, const String& sMacroName, uno::Sequence< uno::Any >& aArgs, uno::Any& aRet, const uno::Any& /*aCaller*/)
{
sal_Bool bRes = sal_False;
if ( !pShell )
@@ -355,42 +383,25 @@ sal_Bool executeMacro( SfxObjectShell* pShell, const String& sMacroName, uno::Se
uno::Sequence< uno::Any > aOutArgs;
try
- {
- uno::Reference< script::provider::XScriptProvider > xScriptProvider;
- uno::Reference< script::provider::XScriptProviderSupplier > xSPS( pShell->GetModel(), uno::UNO_QUERY_THROW );
-
- xScriptProvider.set( xSPS->getScriptProvider(), uno::UNO_QUERY_THROW );
-
- uno::Reference< script::provider::XScript > xScript( xScriptProvider->getScript( sUrl ), uno::UNO_QUERY_THROW );
-
- if ( aCaller.hasValue() )
+ { ErrCode nErr( ERRCODE_BASIC_INTERNAL_ERROR );
+ if ( pShell )
{
- uno::Reference< beans::XPropertySet > xProps( xScript, uno::UNO_QUERY );
- if ( xProps.is() )
+ nErr = pShell->CallXScript( sUrl,
+ aArgs, aRet, aOutArgsIndex, aOutArgs, false );
+ sal_Int32 nLen = aOutArgs.getLength();
+ // convert any out params to seem like they were inouts
+ if ( nLen )
{
- uno::Sequence< uno::Any > aCallerHack(1);
- aCallerHack[ 0 ] = aCaller;
- xProps->setPropertyValue( rtl::OUString::createFromAscii( "Caller" ), uno::makeAny( aCallerHack ) );
+ for ( sal_Int32 index=0; index < nLen; ++index )
+ {
+ sal_Int32 nOutIndex = aOutArgsIndex[ index ];
+ aArgs[ nOutIndex ] = aOutArgs[ index ];
+ }
}
}
-
-
- xScript->invoke( aArgs, aOutArgsIndex, aOutArgs );
-
- sal_Int32 nLen = aOutArgs.getLength();
- // convert any out params to seem like they were inouts
- if ( nLen )
- {
- for ( sal_Int32 index=0; index < nLen; ++index )
- {
- sal_Int32 nOutIndex = aOutArgsIndex[ index ];
- aArgs[ nOutIndex ] = aOutArgs[ index ];
- }
- }
-
- bRes = sal_True;
+ bRes = ( nErr == ERRCODE_NONE );
}
- catch ( uno::Exception& e )
+ catch ( uno::Exception& )
{
bRes = sal_False;
}