diff options
author | Daniel Rentz [dr] <daniel.rentz@oracle.com> | 2010-08-30 19:25:43 +0200 |
---|---|---|
committer | Daniel Rentz [dr] <daniel.rentz@oracle.com> | 2010-08-30 19:25:43 +0200 |
commit | 8b4b42daa8b06dc095965e458105f669928693b6 (patch) | |
tree | 36b994e8175a56c8b926e9074a92dd3f320ef038 /filter/source/msfilter/msvbahelper.cxx | |
parent | c29c922edb2ae9454e86e9f99d55ba005132194e (diff) | |
parent | 40e1e1a4b2c190ffd71e17d83fc9f00c81d7d5b1 (diff) |
dr77: rebase to DEV300m87
Diffstat (limited to 'filter/source/msfilter/msvbahelper.cxx')
-rw-r--r-- | filter/source/msfilter/msvbahelper.cxx | 78 |
1 files changed, 44 insertions, 34 deletions
diff --git a/filter/source/msfilter/msvbahelper.cxx b/filter/source/msfilter/msvbahelper.cxx index 07170e424aba..44db464ee06d 100644 --- a/filter/source/msfilter/msvbahelper.cxx +++ b/filter/source/msfilter/msvbahelper.cxx @@ -39,6 +39,7 @@ #include <com/sun/star/lang/XUnoTunnel.hpp> #include <tools/urlobj.hxx> #include <osl/file.hxx> +#include <unotools/pathoptions.hxx> using namespace ::com::sun::star; @@ -120,7 +121,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; @@ -223,7 +241,16 @@ MacroResolvedInfo resolveVBAMacro( SfxObjectShell* pShell, const rtl::OUString& String sDocUrlOrPath = aMacroName.copy( 0, nDocSepIndex ); aMacroName = aMacroName.copy( nDocSepIndex + 1 ); OSL_TRACE("doc search, current shell is 0x%x", pShell ); - SfxObjectShell* pFoundShell = findShellForUrl( sDocUrlOrPath ); + SfxObjectShell* pFoundShell = 0; + if( bSearchGlobalTemplates ) + { + SvtPathOptions aPathOpt; + String aAddinPath = aPathOpt.GetAddinPath(); + if( rtl::OUString( sDocUrlOrPath ).indexOf( aAddinPath ) == 0 ) + pFoundShell = pShell; + } + if( !pFoundShell ) + pFoundShell = findShellForUrl( sDocUrlOrPath ); OSL_TRACE("doc search, after find, found shell is 0x%x", pFoundShell ); return resolveVBAMacro( pFoundShell, aMacroName ); } @@ -342,7 +369,7 @@ MacroResolvedInfo resolveVBAMacro( SfxObjectShell* pShell, const rtl::OUString& } // 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 ) @@ -353,42 +380,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; } |