diff options
author | Kurt Zenker <kz@openoffice.org> | 2008-03-06 15:18:54 +0000 |
---|---|---|
committer | Kurt Zenker <kz@openoffice.org> | 2008-03-06 15:18:54 +0000 |
commit | bef555e4aa2250bef503885020d95e607ab1378c (patch) | |
tree | c94af6599d74fa247eb7b7fd6fd8cffc8500412f /scripting/source/basprov/basscript.cxx | |
parent | de29c5a217a5bbb4f38a20fb8e35cee1ae3e5e81 (diff) |
INTEGRATION: CWS odbmacros2 (1.14.54); FILE MERGED
2007/12/19 14:53:50 fs 1.14.54.2: #i49133# BasicManager::Insert/Set/ResetGlobalUNOConstant superseded by SetGlobalUNOConstant
2007/12/19 13:24:57 fs 1.14.54.1: #i49133# when invoking a script, temporarily set the XScriptInvocationContext as ThisComponent at the script
Diffstat (limited to 'scripting/source/basprov/basscript.cxx')
-rw-r--r-- | scripting/source/basprov/basscript.cxx | 40 |
1 files changed, 35 insertions, 5 deletions
diff --git a/scripting/source/basprov/basscript.cxx b/scripting/source/basprov/basscript.cxx index c32441932299..0dd180c57e95 100644 --- a/scripting/source/basprov/basscript.cxx +++ b/scripting/source/basprov/basscript.cxx @@ -4,9 +4,9 @@ * * $RCSfile: basscript.cxx,v $ * - * $Revision: 1.14 $ + * $Revision: 1.15 $ * - * last change: $Author: obo $ $Date: 2006-09-16 12:26:29 $ + * last change: $Author: kz $ $Date: 2008-03-06 16:18:54 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -58,9 +58,13 @@ #ifndef _SB_SBMETH_HXX #include <basic/sbmeth.hxx> #endif +#ifndef _BASMGR_HXX +#include <basic/basmgr.hxx> +#endif #ifndef _COM_SUN_STAR_SCRIPT_PROVIDER_SCRIPTFRAMEWORKERRORTYPE_HPP_ #include <com/sun/star/script/provider/ScriptFrameworkErrorType.hpp> #endif + #include <map> @@ -68,7 +72,7 @@ using namespace ::com::sun::star; using namespace ::com::sun::star::lang; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::script; - +using namespace ::com::sun::star::document; extern ::com::sun::star::uno::Any sbxToUnoValue( SbxVariable* pVar ); extern void unoToSbxValue( SbxVariable* pVar, const ::com::sun::star::uno::Any& aValue ); @@ -85,13 +89,28 @@ namespace basprov // BasicScriptImpl // ============================================================================= + // ----------------------------------------------------------------------------- + BasicScriptImpl::BasicScriptImpl( const ::rtl::OUString& funcName, SbMethodRef xMethod ) - :m_xMethod( xMethod ), m_funcName( funcName ) + :m_xMethod( xMethod ) + ,m_funcName( funcName ) + ,m_documentBasicManager( NULL ) + ,m_xDocumentScriptContext() { } // ----------------------------------------------------------------------------- + BasicScriptImpl::BasicScriptImpl( const ::rtl::OUString& funcName, SbMethodRef xMethod, + BasicManager& documentBasicManager, const Reference< XScriptInvocationContext >& documentScriptContext ) + :m_xMethod( xMethod ) + ,m_funcName( funcName ) + ,m_documentBasicManager( &documentBasicManager ) + ,m_xDocumentScriptContext( documentScriptContext ) + { + } + + // ----------------------------------------------------------------------------- BasicScriptImpl::~BasicScriptImpl() { } @@ -168,7 +187,18 @@ namespace basprov // call method SbxVariableRef xReturn = new SbxVariable; - ErrCode nErr = m_xMethod->Call( xReturn ); + ErrCode nErr = SbxERR_OK; + { + // if it's a document-based script, temporarily reset ThisComponent to the script invocation context + Any aOldThisComponent; + if ( m_documentBasicManager && m_xDocumentScriptContext.is() ) + aOldThisComponent = m_documentBasicManager->SetGlobalUNOConstant( "ThisComponent", makeAny( m_xDocumentScriptContext ) ); + + nErr = m_xMethod->Call( xReturn ); + + if ( m_documentBasicManager && m_xDocumentScriptContext.is() ) + m_documentBasicManager->SetGlobalUNOConstant( "ThisComponent", aOldThisComponent ); + } if ( nErr != SbxERR_OK ) { // TODO: throw InvocationTargetException ? |