diff options
author | Frank Schoenheit [fs] <frank.schoenheit@sun.com> | 2010-11-01 21:50:46 +0100 |
---|---|---|
committer | Frank Schoenheit [fs] <frank.schoenheit@sun.com> | 2010-11-01 21:50:46 +0100 |
commit | 8241bf7c831b07bc19509387f1514c42bc5624c1 (patch) | |
tree | 18407af3d5aa602a8f618ea20363621e8565e673 | |
parent | 25553ced99b24cd4939945b3b1fa7d4843ed9947 (diff) |
undoapi:
- introduced BasicManager::HasMacro/ExecuteMacro
- removed SfxQueryMacro, superseded by BasicManager::ExecuteMacro
- removed macrconf.hxx
- removed SfxObjectShell::CallScript, migrated the only client to BasicManager::HasMacro/SfxObjectShell::CallXScript
- removed SfxObjectShell::CallStarBasicScript, migrated the only client to SfxObjectShell::CallXScript
-rw-r--r-- | basic/inc/basic/basmgr.hxx | 7 | ||||
-rw-r--r-- | basic/source/basmgr/basmgr.cxx | 112 | ||||
-rw-r--r-- | sfx2/inc/sfx2/objsh.hxx | 22 | ||||
-rw-r--r-- | sfx2/inc/sfxbasic.hxx | 39 | ||||
-rw-r--r-- | sfx2/source/appl/app.cxx | 17 | ||||
-rw-r--r-- | sfx2/source/appl/appserv.cxx | 1 | ||||
-rw-r--r-- | sfx2/source/appl/appuno.cxx | 53 | ||||
-rw-r--r-- | sfx2/source/bastyp/fltfnc.cxx | 1 | ||||
-rw-r--r-- | sfx2/source/control/macrconf.cxx | 88 | ||||
-rw-r--r-- | sfx2/source/control/makefile.mk | 1 | ||||
-rw-r--r-- | sfx2/source/control/shell.cxx | 1 | ||||
-rw-r--r-- | sfx2/source/doc/objmisc.cxx | 74 | ||||
-rw-r--r-- | svx/source/form/fmscriptingenv.cxx | 83 |
13 files changed, 146 insertions, 353 deletions
diff --git a/basic/inc/basic/basmgr.hxx b/basic/inc/basic/basmgr.hxx index 5c62c347fbdd..720a6efd2182 100644 --- a/basic/inc/basic/basmgr.hxx +++ b/basic/inc/basic/basmgr.hxx @@ -237,6 +237,13 @@ public: */ bool LegacyPsswdBinaryLimitExceeded( ::com::sun::star::uno::Sequence< rtl::OUString >& _out_rModuleNames ); + /// determines whether the Basic Manager has a given macro, given by fully qualified name + bool HasMacro( String const& i_fullyQualifiedName ) const; + /// executes a given macro + ErrCode ExecuteMacro( String const& i_fullyQualifiedName, SbxArray* i_arguments, SbxValue* i_retValue ); + /// executes a given macro + ErrCode ExecuteMacro( String const& i_fullyQualifiedName, String const& i_commaSeparatedArgs, SbxValue* i_retValue ); + private: BOOL IsReference( USHORT nLib ); diff --git a/basic/source/basmgr/basmgr.cxx b/basic/source/basmgr/basmgr.cxx index 84763468e64c..a491b957fef6 100644 --- a/basic/source/basmgr/basmgr.cxx +++ b/basic/source/basmgr/basmgr.cxx @@ -42,6 +42,8 @@ #include <tools/diagnose_ex.h> #include <basic/sbmod.hxx> #include <basic/sbobjmod.hxx> +#include <unotools/intlwrapper.hxx> +#include <comphelper/processfactory.hxx> #include <basic/sbuno.hxx> #include <basic/basmgr.hxx> @@ -1868,6 +1870,116 @@ bool BasicManager::LegacyPsswdBinaryLimitExceeded( ::com::sun::star::uno::Sequen return false; } + +namespace +{ + SbMethod* lcl_queryMacro( BasicManager* i_manager, String const& i_fullyQualifiedName ) + { + sal_uInt16 nLast = 0; + String sMacro = i_fullyQualifiedName; + String sLibName = sMacro.GetToken( 0, '.', nLast ); + String sModule = sMacro.GetToken( 0, '.', nLast ); + sMacro.Erase( 0, nLast ); + + IntlWrapper aIntlWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() ); + const CollatorWrapper* pCollator = aIntlWrapper.getCollator(); + sal_uInt16 nLibCount = i_manager->GetLibCount(); + for ( sal_uInt16 nLib = 0; nLib < nLibCount; ++nLib ) + { + if ( COMPARE_EQUAL == pCollator->compareString( i_manager->GetLibName( nLib ), sLibName ) ) + { + StarBASIC* pLib = i_manager->GetLib( nLib ); + if( !pLib ) + { + i_manager->LoadLib( nLib ); + pLib = i_manager->GetLib( nLib ); + } + + if( pLib ) + { + sal_uInt16 nModCount = pLib->GetModules()->Count(); + for( sal_uInt16 nMod = 0; nMod < nModCount; ++nMod ) + { + SbModule* pMod = (SbModule*)pLib->GetModules()->Get( nMod ); + if ( pMod && COMPARE_EQUAL == pCollator->compareString( pMod->GetName(), sModule ) ) + { + SbMethod* pMethod = (SbMethod*)pMod->Find( sMacro, SbxCLASS_METHOD ); + if( pMethod ) + return pMethod; + } + } + } + } + } + return 0; + } +} + +bool BasicManager::HasMacro( String const& i_fullyQualifiedName ) const +{ + return ( NULL != lcl_queryMacro( const_cast< BasicManager* >( this ), i_fullyQualifiedName ) ); +} + +ErrCode BasicManager::ExecuteMacro( String const& i_fullyQualifiedName, SbxArray* i_arguments, SbxValue* i_retValue ) +{ + SbMethod* pMethod = lcl_queryMacro( this, i_fullyQualifiedName ); + ErrCode nError = 0; + if ( pMethod ) + { + if ( i_arguments ) + pMethod->SetParameters( i_arguments ); + nError = pMethod->Call( i_retValue ); + } + else + nError = ERRCODE_BASIC_PROC_UNDEFINED; + return nError; +} + +ErrCode BasicManager::ExecuteMacro( String const& i_fullyQualifiedName, String const& i_commaSeparatedArgs, SbxValue* i_retValue ) +{ + SbMethod* pMethod = lcl_queryMacro( this, i_fullyQualifiedName ); + if ( !pMethod ) + return ERRCODE_BASIC_PROC_UNDEFINED; + + // arguments must be quoted + String sQuotedArgs; + String sArgs( i_commaSeparatedArgs ); + if ( sArgs.Len()<2 || sArgs.GetBuffer()[1] == '\"') + // no args or already quoted args + sQuotedArgs = sArgs; + else + { + // quote parameters + sArgs.Erase( 0, 1 ); + sArgs.Erase( sArgs.Len()-1, 1 ); + + sQuotedArgs = '('; + + sal_uInt16 nCount = sArgs.GetTokenCount(','); + for ( sal_uInt16 n=0; n<nCount; ++n ) + { + sQuotedArgs += '\"'; + sQuotedArgs += sArgs.GetToken( n, ',' ); + sQuotedArgs += '\"'; + if ( n<nCount-1 ) + sQuotedArgs += ','; + } + + sQuotedArgs += ')'; + } + + // add quoted arguments and do the call + String sCall( '[' ); + sCall += pMethod->GetName(); + sCall += sQuotedArgs; + sCall += ']'; + + SbxVariable* pRet = pMethod->GetParent()->Execute( sCall ); + if ( pRet ) + *i_retValue = *pRet; + return SbxBase::GetError(); +} + //===================================================================== class ModuleInfo_Impl : public ModuleInfoHelper diff --git a/sfx2/inc/sfx2/objsh.hxx b/sfx2/inc/sfx2/objsh.hxx index 0198a3c3ee75..4fe7f53a7015 100644 --- a/sfx2/inc/sfx2/objsh.hxx +++ b/sfx2/inc/sfx2/objsh.hxx @@ -366,28 +366,6 @@ public: ErrCode CallBasic( const String& rMacro, const String& rBasicName, SbxArray* pArgs = 0, SbxValue* pRet = 0 ); - ErrCode CallScript( - const String & rScriptType, const String & rCode, const void* pArgs = NULL, void* pRet = NULL ); - - /** calls a StarBasic script without magic - @param _rMacroName - specifies the name of the method to execute - @param _rLocation - specifies the location of the script to execute. Allowed values are "application" and "document". - @param _pArguments - This is a pointer to a Sequence< Any >. All elements of the Sequence are wrapped into Basic objects - and passed as arguments to the method specified by <arg>_rMacroName</arg> - @param _pReturn - If not <NULL/>, the Any pointed to by this argument contains the return value of the (synchronous) call - to the StarBasic macro - */ - ErrCode CallStarBasicScript( - const String& _rMacroName, - const String& _rLocation, - const void* _pArguments = NULL, - void* _pReturn = NULL - ); - ErrCode CallXScript( const String& rScriptURL, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aParams, diff --git a/sfx2/inc/sfxbasic.hxx b/sfx2/inc/sfxbasic.hxx deleted file mode 100644 index 5c367c52a2d4..000000000000 --- a/sfx2/inc/sfxbasic.hxx +++ /dev/null @@ -1,39 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ -#ifndef _SFXBASIC_HXX -#define _SFXBASIC_HXX - -class BasicManager; -class SbMethod; -class String; - -//------------------------------------------------------------------ - -SbMethod* SfxQueryMacro( BasicManager* pMgr, const String& rMacro ); - -#endif - diff --git a/sfx2/source/appl/app.cxx b/sfx2/source/appl/app.cxx index c0b426c387bc..1d71e1747bd1 100644 --- a/sfx2/source/appl/app.cxx +++ b/sfx2/source/appl/app.cxx @@ -36,7 +36,6 @@ #endif // UNX #include <sfx2/app.hxx> -#include "sfxbasic.hxx" #include <sfx2/frame.hxx> #include <vos/process.hxx> #include <tools/simplerm.hxx> @@ -848,19 +847,5 @@ void SfxApplication::MacroOrganizer( INT16 nTabId ) ErrCode SfxApplication::CallBasic( const String& rCode, BasicManager* pMgr, SbxArray* pArgs, SbxValue* pRet ) { - SfxApplication *pApp = SFX_APP(); - pApp->EnterBasicCall(); - SbMethod* pMethod = SfxQueryMacro( pMgr, rCode ); - ErrCode nErr = 0; - if( pMethod ) - { - if ( pArgs ) - pMethod->SetParameters( pArgs ); - nErr = pMethod->Call( pRet ); - } - else - nErr = ERRCODE_BASIC_PROC_UNDEFINED; - - pApp->LeaveBasicCall(); - return nErr; + return pMgr->ExecuteMacro( rCode, pArgs, pRet); } diff --git a/sfx2/source/appl/appserv.cxx b/sfx2/source/appl/appserv.cxx index 5b2b9c3691ad..01258ac7a56b 100644 --- a/sfx2/source/appl/appserv.cxx +++ b/sfx2/source/appl/appserv.cxx @@ -111,7 +111,6 @@ #include <sfx2/new.hxx> #include <sfx2/templdlg.hxx> #include "sfxtypes.hxx" -#include "sfxbasic.hxx" #include <sfx2/tabdlg.hxx> #include "arrdecl.hxx" #include "fltfnc.hxx" diff --git a/sfx2/source/appl/appuno.cxx b/sfx2/source/appl/appuno.cxx index 7056cc48a704..ddde2e26c344 100644 --- a/sfx2/source/appl/appuno.cxx +++ b/sfx2/source/appl/appuno.cxx @@ -120,7 +120,6 @@ using namespace ::com::sun::star::io; #include <sfx2/fcontnr.hxx> #include "frmload.hxx" #include <sfx2/frame.hxx> -#include "sfxbasic.hxx" #include <sfx2/objsh.hxx> #include <sfx2/objuno.hxx> #include <sfx2/unoctitm.hxx> @@ -1802,35 +1801,8 @@ ErrCode SfxMacroLoader::loadMacro( const ::rtl::OUString& rURL, com::sun::star:: aQualifiedMethod.Erase( nArgsPos - nHashPos - 1 ); } - SbxMethod *pMethod = SfxQueryMacro( pBasMgr, aQualifiedMethod ); - if ( pMethod ) + if ( pBasMgr->HasMacro( aQualifiedMethod ) ) { - // arguments must be quoted - String aQuotedArgs; - if ( aArgs.Len()<2 || aArgs.GetBuffer()[1] == '\"') - // no args or already quoted args - aQuotedArgs = aArgs; - else - { - // quote parameters - aArgs.Erase(0,1); - aArgs.Erase( aArgs.Len()-1,1); - - aQuotedArgs = '('; - - sal_uInt16 nCount = aArgs.GetTokenCount(','); - for ( sal_uInt16 n=0; n<nCount; n++ ) - { - aQuotedArgs += '\"'; - aQuotedArgs += aArgs.GetToken( n, ',' ); - aQuotedArgs += '\"'; - if ( n<nCount-1 ) - aQuotedArgs += ','; - } - - aQuotedArgs += ')'; - } - Any aOldThisComponent; if ( pSh ) { @@ -1844,29 +1816,14 @@ ErrCode SfxMacroLoader::loadMacro( const ::rtl::OUString& rURL, com::sun::star:: } } - // add quoted arguments and do the call - String aCall( '[' ); - aCall += pMethod->GetName(); - aCall += aQuotedArgs; - aCall += ']'; - // just to let the shell be alive SfxObjectShellRef rSh = pSh; - // execute function using its Sbx parent, - //SbxVariable* pRet = pMethod->GetParent()->Execute( aCall ); - //rRetval = sbxToUnoValue( pRet ); - - SbxVariable* pRet = pMethod->GetParent()->Execute( aCall ); - if ( pRet ) - { - USHORT nFlags = pRet->GetFlags(); - pRet->SetFlag( SBX_READWRITE | SBX_NO_BROADCAST ); - rRetval = sbxToUnoValue( pRet ); - pRet->SetFlags( nFlags ); - } + SbxVariableRef retValRef = new SbxVariable; + nErr = pBasMgr->ExecuteMacro( aQualifiedMethod, aArgs, retValRef ); + if ( nErr == ERRCODE_NONE ) + rRetval = sbxToUnoValue( retValRef ); - nErr = SbxBase::GetError(); if ( ( pBasMgr == pAppMgr ) && pSh ) { pAppMgr->SetGlobalUNOConstant( "ThisComponent", aOldThisComponent ); diff --git a/sfx2/source/bastyp/fltfnc.cxx b/sfx2/source/bastyp/fltfnc.cxx index d11b8b5130ed..11ff8d666964 100644 --- a/sfx2/source/bastyp/fltfnc.cxx +++ b/sfx2/source/bastyp/fltfnc.cxx @@ -111,7 +111,6 @@ using namespace ::vos; #include <unotools/syslocale.hxx> #include "sfxhelp.hxx" -#include "sfxbasic.hxx" #include <sfx2/docfilt.hxx> #include <sfx2/docfac.hxx> #include "sfxtypes.hxx" diff --git a/sfx2/source/control/macrconf.cxx b/sfx2/source/control/macrconf.cxx deleted file mode 100644 index 30d8cd7a026f..000000000000 --- a/sfx2/source/control/macrconf.cxx +++ /dev/null @@ -1,88 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_sfx2.hxx" - -#include "sfxbasic.hxx" - -#include <basic/sbmeth.hxx> -#include <basic/sbmod.hxx> -#include <basic/basmgr.hxx> -#include <unotools/intlwrapper.hxx> -#include <comphelper/processfactory.hxx> -#include <vcl/svapp.hxx> - -//========================================================================== - -SbMethod* SfxQueryMacro_Impl( BasicManager* pMgr , const String& rMacro, - const String &rLibName, const String& rModule ) -{ - IntlWrapper aIntlWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() ); - const CollatorWrapper* pCollator = aIntlWrapper.getCollator(); - sal_uInt16 nLibCount = pMgr->GetLibCount(); - for ( sal_uInt16 nLib = 0; nLib < nLibCount; ++nLib ) - { - if ( COMPARE_EQUAL == pCollator->compareString( pMgr->GetLibName( nLib ), rLibName ) ) - { - StarBASIC* pLib = pMgr->GetLib( nLib ); - if( !pLib ) - { - pMgr->LoadLib( nLib ); - pLib = pMgr->GetLib( nLib ); - } - - if( pLib ) - { - sal_uInt16 nModCount = pLib->GetModules()->Count(); - for( sal_uInt16 nMod = 0; nMod < nModCount; ++nMod ) - { - SbModule* pMod = (SbModule*)pLib->GetModules()->Get( nMod ); - if ( pMod && COMPARE_EQUAL == pCollator->compareString( pMod->GetName(), rModule ) ) - { - SbMethod* pMethod = (SbMethod*)pMod->Find( rMacro, SbxCLASS_METHOD ); - if( pMethod ) - return pMethod; - } - } - } - } - } - return 0; -} - -SbMethod* SfxQueryMacro( BasicManager* pMgr , const String& rMacro ) -{ - sal_uInt16 nLast = 0; - String aMacro = rMacro; - String aLibName = aMacro.GetToken( 0, '.', nLast ); - String aModule = aMacro.GetToken( 0, '.', nLast ); - aMacro.Erase( 0, nLast ); - - return SfxQueryMacro_Impl( pMgr, aMacro, aLibName, aModule ); -} - diff --git a/sfx2/source/control/makefile.mk b/sfx2/source/control/makefile.mk index 86797589e3aa..7211bc409ca3 100644 --- a/sfx2/source/control/makefile.mk +++ b/sfx2/source/control/makefile.mk @@ -53,7 +53,6 @@ SLOFILES = \ $(SLO)$/bindings.obj \ $(SLO)$/ctrlitem.obj \ $(SLO)$/dispatch.obj \ - $(SLO)$/macrconf.obj \ $(SLO)$/macro.obj \ $(SLO)$/minfitem.obj \ $(SLO)$/msg.obj \ diff --git a/sfx2/source/control/shell.cxx b/sfx2/source/control/shell.cxx index 55486c39f53a..d1605754680a 100644 --- a/sfx2/source/control/shell.cxx +++ b/sfx2/source/control/shell.cxx @@ -46,7 +46,6 @@ #include <sfx2/bindings.hxx> #include <sfx2/dispatch.hxx> #include <sfx2/viewfrm.hxx> -#include "sfxbasic.hxx" #include <sfx2/objface.hxx> #include <sfx2/objsh.hxx> #include <sfx2/viewsh.hxx> diff --git a/sfx2/source/doc/objmisc.cxx b/sfx2/source/doc/objmisc.cxx index 3d1d495aef00..01c1eb558432 100644 --- a/sfx2/source/doc/objmisc.cxx +++ b/sfx2/source/doc/objmisc.cxx @@ -1800,80 +1800,6 @@ namespace { *static_cast< Any* >( _pAny ) = sbxToUnoValue( _rBasicValue ); } } -//------------------------------------------------------------------------- -ErrCode SfxObjectShell::CallStarBasicScript( const String& _rMacroName, const String& _rLocation, - const void* _pArguments, void* _pReturn ) -{ - OSL_TRACE("in CallSBS"); - ::vos::OClearableGuard aGuard( Application::GetSolarMutex() ); - - // the arguments for the call - SbxArrayRef xMacroArguments = lcl_translateUno2Basic( _pArguments ); - - // the return value - SbxVariableRef xReturn = _pReturn ? new SbxVariable : NULL; - - // the location (document or application) - String sMacroLocation; - if ( _rLocation.EqualsAscii( "application" ) ) - sMacroLocation = SFX_APP()->GetName(); -#ifdef DBG_UTIL - else - DBG_ASSERT( _rLocation.EqualsAscii( "document" ), - "SfxObjectShell::CallStarBasicScript: invalid (unknown) location!" ); -#endif - - // call the script - ErrCode eError = CallBasic( _rMacroName, sMacroLocation, xMacroArguments, xReturn ); - - // translate the return value - lcl_translateBasic2Uno( xReturn, _pReturn ); - - // outta here - return eError; -} - -//------------------------------------------------------------------------- -ErrCode SfxObjectShell::CallScript( - const String & rScriptType, - const String & rCode, - const void *pArgs, - void *pRet -) -{ - ::vos::OClearableGuard aGuard( Application::GetSolarMutex() ); - ErrCode nErr = ERRCODE_NONE; - if( rScriptType.EqualsAscii( "StarBasic" ) ) - { - // the arguments for the call - SbxArrayRef xMacroArguments = lcl_translateUno2Basic( pArgs ); - - // the return value - SbxVariableRef xReturn = pRet ? new SbxVariable : NULL; - - // call the script - nErr = CallBasic( rCode, String(), xMacroArguments, xReturn ); - - // translate the return value - lcl_translateBasic2Uno( xReturn, pRet ); - - // did this fail because the method was not found? - if ( nErr == ERRCODE_BASIC_PROC_UNDEFINED ) - { // yep-> look in the application BASIC module - nErr = CallBasic( rCode, SFX_APP()->GetName(), xMacroArguments, xReturn ); - } - } - else if( rScriptType.EqualsAscii( "JavaScript" ) ) - { - DBG_ERROR( "JavaScript not allowed" ); - return 0; - } - else - { - DBG_ERROR( "StarScript not allowed" ); - } - return nErr; -} SfxFrame* SfxObjectShell::GetSmartSelf( SfxFrame* pSelf, SfxMedium& /*rMedium*/ ) { diff --git a/svx/source/form/fmscriptingenv.cxx b/svx/source/form/fmscriptingenv.cxx index 154999333296..f351dba85815 100644 --- a/svx/source/form/fmscriptingenv.cxx +++ b/svx/source/form/fmscriptingenv.cxx @@ -28,7 +28,7 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_svx.hxx" #include "fmscriptingenv.hxx" -#include <svx/fmmodel.hxx> +#include "svx/fmmodel.hxx" /** === begin UNO includes === **/ #include <com/sun/star/lang/IllegalArgumentException.hpp> @@ -37,6 +37,7 @@ #include <com/sun/star/reflection/XInterfaceMethodTypeDescription.hpp> #include <com/sun/star/lang/DisposedException.hpp> /** === end UNO includes === **/ + #include <tools/diagnose_ex.h> #include <cppuhelper/implbase1.hxx> #include <comphelper/implementationreference.hxx> @@ -45,6 +46,8 @@ #include <vcl/svapp.hxx> #include <vos/mutex.hxx> #include <sfx2/objsh.hxx> +#include <sfx2/app.hxx> +#include <basic/basmgr.hxx> #include <boost/shared_ptr.hpp> @@ -416,60 +419,6 @@ namespace svxform m_rObjectShell.CallXScript( m_sScriptCode, _rArguments, _rSynchronousResult, aOutArgsIndex, aOutArgs ); } - - //................................................................ - //. QualifiedBasicScript - //................................................................ - class QualifiedBasicScript : public IScript - { - SfxObjectShell& m_rObjectShell; - const ::rtl::OUString m_sMacroLocation; - const ::rtl::OUString m_sScriptCode; - - public: - QualifiedBasicScript( SfxObjectShell& _rObjectShell, const ::rtl::OUString& _rLocation, const ::rtl::OUString& _rScriptCode ) - :m_rObjectShell( _rObjectShell ) - ,m_sMacroLocation( _rLocation ) - ,m_sScriptCode( _rScriptCode ) - { - } - - // IScript - virtual void invoke( const Sequence< Any >& _rArguments, Any& _rSynchronousResult ); - }; - - //................................................................ - void QualifiedBasicScript::invoke( const Sequence< Any >& _rArguments, Any& _rSynchronousResult ) - { - m_rObjectShell.CallStarBasicScript( m_sScriptCode, m_sMacroLocation, - &_rArguments, &_rSynchronousResult ); - } - - //................................................................ - //. UnqualifiedBasicScript - //................................................................ - class UnqualifiedBasicScript : public IScript - { - SfxObjectShell& m_rObjectShell; - const ::rtl::OUString m_sScriptCode; - - public: - UnqualifiedBasicScript( SfxObjectShell& _rObjectShell, const ::rtl::OUString& _rScriptCode ) - :m_rObjectShell( _rObjectShell ) - ,m_sScriptCode( _rScriptCode ) - { - } - - // IScript - virtual void invoke( const Sequence< Any >& _rArguments, Any& _rSynchronousResult ); - }; - - //................................................................ - void UnqualifiedBasicScript::invoke( const Sequence< Any >& _rArguments, Any& _rSynchronousResult ) - { - m_rObjectShell.CallScript( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "StarBasic" ) ), m_sScriptCode, - &_rArguments, &_rSynchronousResult ); - } } //-------------------------------------------------------------------- @@ -513,14 +462,24 @@ namespace svxform sScriptCode = sScriptCode.copy( nPrefixLen + 1 ); } - if ( sMacroLocation.getLength() ) - { // we have a StarBasic macro with fully-qualified macro location - pScript.reset( new QualifiedBasicScript( *xObjectShell, sMacroLocation, sScriptCode ) ); - } - else - { // we have a StarBasic macro without qualified location - let the object shell gues .... - pScript.reset( new UnqualifiedBasicScript( *xObjectShell, sScriptCode ) ); + if ( !sMacroLocation.getLength() ) + { + // legacy format: use the app-wide Basic, if it has a respective method, otherwise fall back to the doc's Basic + if ( SFX_APP()->GetBasicManager()->HasMacro( sScriptCode ) ) + sMacroLocation = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application" ) ); + else + sMacroLocation = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "document" ) ); } + + ::rtl::OUStringBuffer aScriptURI; + aScriptURI.appendAscii( "vnd.sun.star.script:" ); + aScriptURI.append( sScriptCode ); + aScriptURI.appendAscii( "?language=Basic" ); + aScriptURI.appendAscii( "&location=" ); + aScriptURI.append( sMacroLocation ); + + const ::rtl::OUString sScriptURI( aScriptURI.makeStringAndClear() ); + pScript.reset( new NewStyleUNOScript( *xObjectShell, sScriptURI ) ); } OSL_ENSURE( pScript.get(), "FormScriptingEnvironment::doFireScriptEvent: no script to execute!" ); |