1*e1f63238SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*e1f63238SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*e1f63238SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*e1f63238SAndrew Rist * distributed with this work for additional information 6*e1f63238SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*e1f63238SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*e1f63238SAndrew Rist * "License"); you may not use this file except in compliance 9*e1f63238SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*e1f63238SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*e1f63238SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*e1f63238SAndrew Rist * software distributed under the License is distributed on an 15*e1f63238SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*e1f63238SAndrew Rist * KIND, either express or implied. See the License for the 17*e1f63238SAndrew Rist * specific language governing permissions and limitations 18*e1f63238SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*e1f63238SAndrew Rist *************************************************************/ 21*e1f63238SAndrew Rist 22*e1f63238SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_basic.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <list> 28cdf0e10cSrcweir 29cdf0e10cSrcweir #include <vos/macros.hxx> 30cdf0e10cSrcweir #include <vcl/svapp.hxx> 31cdf0e10cSrcweir #include <tools/stream.hxx> 32cdf0e10cSrcweir #include <svl/brdcst.hxx> 33cdf0e10cSrcweir #include <tools/shl.hxx> 34cdf0e10cSrcweir #include <basic/sbx.hxx> 35cdf0e10cSrcweir #include "sbdiagnose.hxx" 36cdf0e10cSrcweir #include "sb.hxx" 37cdf0e10cSrcweir #include <sbjsmeth.hxx> 38cdf0e10cSrcweir #include "sbjsmod.hxx" 39cdf0e10cSrcweir #include "sbintern.hxx" 40cdf0e10cSrcweir #include "image.hxx" 41cdf0e10cSrcweir #include "opcodes.hxx" 42cdf0e10cSrcweir #include "runtime.hxx" 43cdf0e10cSrcweir #include "token.hxx" 44cdf0e10cSrcweir #include "sbunoobj.hxx" 45cdf0e10cSrcweir #include "sbtrace.hxx" 46cdf0e10cSrcweir 47cdf0e10cSrcweir 48cdf0e10cSrcweir //#include <basic/hilight.hxx> 49cdf0e10cSrcweir #include <svtools/syntaxhighlight.hxx> 50cdf0e10cSrcweir 51cdf0e10cSrcweir #include <basic/basrdll.hxx> 52cdf0e10cSrcweir #include <vos/mutex.hxx> 53cdf0e10cSrcweir #include <basic/sbobjmod.hxx> 54cdf0e10cSrcweir #include <basic/vbahelper.hxx> 55cdf0e10cSrcweir #include <cppuhelper/implbase3.hxx> 56cdf0e10cSrcweir #include <unotools/eventcfg.hxx> 57cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 58cdf0e10cSrcweir #include <com/sun/star/script/ModuleType.hpp> 59cdf0e10cSrcweir #include <com/sun/star/script/vba/XVBACompatibility.hpp> 60cdf0e10cSrcweir #include <com/sun/star/script/vba/VBAScriptEventId.hpp> 61cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 62cdf0e10cSrcweir #include <com/sun/star/document/XEventBroadcaster.hpp> 63cdf0e10cSrcweir #include <com/sun/star/document/XEventListener.hpp> 64cdf0e10cSrcweir 65cdf0e10cSrcweir using namespace com::sun::star; 66cdf0e10cSrcweir 67cdf0e10cSrcweir // for the bsearch 68cdf0e10cSrcweir #ifdef WNT 69cdf0e10cSrcweir #define CDECL _cdecl 70cdf0e10cSrcweir #endif 71cdf0e10cSrcweir #if defined(UNX) || defined(OS2) 72cdf0e10cSrcweir #define CDECL 73cdf0e10cSrcweir #endif 74cdf0e10cSrcweir #ifdef UNX 75cdf0e10cSrcweir #include <sys/resource.h> 76cdf0e10cSrcweir #endif 77cdf0e10cSrcweir 78cdf0e10cSrcweir #include <stdio.h> 79cdf0e10cSrcweir #include <com/sun/star/frame/XDesktop.hpp> 80cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 81cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 82cdf0e10cSrcweir #include <vcl/svapp.hxx> 83cdf0e10cSrcweir #include <map> 84cdf0e10cSrcweir #include <com/sun/star/reflection/XProxyFactory.hpp> 85cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> 86cdf0e10cSrcweir #include <basic/sbobjmod.hxx> 87cdf0e10cSrcweir #include <com/sun/star/uno/XAggregation.hpp> 88cdf0e10cSrcweir #include <com/sun/star/script/XInvocation.hpp> 89cdf0e10cSrcweir 90cdf0e10cSrcweir using namespace com::sun::star::lang; 91cdf0e10cSrcweir using namespace com::sun::star::reflection; 92cdf0e10cSrcweir using namespace com::sun::star::beans; 93cdf0e10cSrcweir using namespace com::sun::star::script; 94cdf0e10cSrcweir 95cdf0e10cSrcweir 96cdf0e10cSrcweir #include <com/sun/star/script/XLibraryContainer.hpp> 97cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 98cdf0e10cSrcweir #include <com/sun/star/awt/XDialogProvider.hpp> 99cdf0e10cSrcweir #include <com/sun/star/awt/XTopWindow.hpp> 100cdf0e10cSrcweir #include <com/sun/star/awt/XWindow.hpp> 101cdf0e10cSrcweir #include <com/sun/star/awt/XControl.hpp> 102cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> 103cdf0e10cSrcweir #include <comphelper/anytostring.hxx> 104cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 105cdf0e10cSrcweir #include <ooo/vba/VbQueryClose.hpp> 106cdf0e10cSrcweir 107cdf0e10cSrcweir typedef ::cppu::WeakImplHelper1< XInvocation > DocObjectWrapper_BASE; 108cdf0e10cSrcweir typedef ::std::map< sal_Int16, Any, ::std::less< sal_Int16 > > OutParamMap; 109cdf0e10cSrcweir ::com::sun::star::uno::Any sbxToUnoValue( SbxVariable* pVar ); 110cdf0e10cSrcweir void unoToSbxValue( SbxVariable* pVar, const ::com::sun::star::uno::Any& aValue ); 111cdf0e10cSrcweir 112cdf0e10cSrcweir class DocObjectWrapper : public DocObjectWrapper_BASE 113cdf0e10cSrcweir { 114cdf0e10cSrcweir Reference< XAggregation > m_xAggProxy; 115cdf0e10cSrcweir Reference< XInvocation > m_xAggInv; 116cdf0e10cSrcweir Reference< XTypeProvider > m_xAggregateTypeProv; 117cdf0e10cSrcweir Sequence< Type > m_Types; 118cdf0e10cSrcweir SbModule* m_pMod; 119cdf0e10cSrcweir SbMethodRef getMethod( const rtl::OUString& aName ) throw (RuntimeException); 120cdf0e10cSrcweir SbPropertyRef getProperty( const rtl::OUString& aName ) throw (RuntimeException); 121cdf0e10cSrcweir String mName; // for debugging 122cdf0e10cSrcweir 123cdf0e10cSrcweir public: 124cdf0e10cSrcweir DocObjectWrapper( SbModule* pMod ); 125cdf0e10cSrcweir virtual ~DocObjectWrapper(); 126cdf0e10cSrcweir 127cdf0e10cSrcweir virtual void SAL_CALL acquire() throw(); 128cdf0e10cSrcweir virtual void SAL_CALL release() throw(); 129cdf0e10cSrcweir 130cdf0e10cSrcweir virtual Sequence< sal_Int8 > SAL_CALL getImplementationId() throw (RuntimeException) 131cdf0e10cSrcweir { 132cdf0e10cSrcweir if( !m_xAggregateTypeProv.is() ) 133cdf0e10cSrcweir throw RuntimeException(); 134cdf0e10cSrcweir return m_xAggregateTypeProv->getImplementationId(); 135cdf0e10cSrcweir } 136cdf0e10cSrcweir 137cdf0e10cSrcweir virtual Reference< XIntrospectionAccess > SAL_CALL getIntrospection( ) throw (RuntimeException); 138cdf0e10cSrcweir 139cdf0e10cSrcweir virtual Any SAL_CALL invoke( const ::rtl::OUString& aFunctionName, const Sequence< Any >& aParams, Sequence< ::sal_Int16 >& aOutParamIndex, Sequence< Any >& aOutParam ) throw (IllegalArgumentException, CannotConvertException, InvocationTargetException, RuntimeException); 140cdf0e10cSrcweir virtual void SAL_CALL setValue( const ::rtl::OUString& aPropertyName, const Any& aValue ) throw (UnknownPropertyException, CannotConvertException, InvocationTargetException, RuntimeException); 141cdf0e10cSrcweir virtual Any SAL_CALL getValue( const ::rtl::OUString& aPropertyName ) throw (UnknownPropertyException, RuntimeException); 142cdf0e10cSrcweir virtual ::sal_Bool SAL_CALL hasMethod( const ::rtl::OUString& aName ) throw (RuntimeException); 143cdf0e10cSrcweir virtual ::sal_Bool SAL_CALL hasProperty( const ::rtl::OUString& aName ) throw (RuntimeException); 144cdf0e10cSrcweir virtual Any SAL_CALL queryInterface( const Type& aType ) throw ( RuntimeException ); 145cdf0e10cSrcweir 146cdf0e10cSrcweir virtual Sequence< Type > SAL_CALL getTypes() throw ( RuntimeException ); 147cdf0e10cSrcweir }; 148cdf0e10cSrcweir 149cdf0e10cSrcweir DocObjectWrapper::DocObjectWrapper( SbModule* pVar ) : m_pMod( pVar ), mName( pVar->GetName() ) 150cdf0e10cSrcweir { 151cdf0e10cSrcweir SbObjModule* pMod = PTR_CAST(SbObjModule,pVar); 152cdf0e10cSrcweir if ( pMod ) 153cdf0e10cSrcweir { 154cdf0e10cSrcweir if ( pMod->GetModuleType() == ModuleType::DOCUMENT ) 155cdf0e10cSrcweir { 156cdf0e10cSrcweir Reference< XMultiServiceFactory > xFactory = comphelper::getProcessServiceFactory(); 157cdf0e10cSrcweir // Use proxy factory service to create aggregatable proxy. 158cdf0e10cSrcweir SbUnoObject* pUnoObj = PTR_CAST(SbUnoObject,pMod->GetObject() ); 159cdf0e10cSrcweir Reference< XInterface > xIf; 160cdf0e10cSrcweir if ( pUnoObj ) 161cdf0e10cSrcweir { 162cdf0e10cSrcweir Any aObj = pUnoObj->getUnoAny(); 163cdf0e10cSrcweir aObj >>= xIf; 164cdf0e10cSrcweir if ( xIf.is() ) 165cdf0e10cSrcweir { 166cdf0e10cSrcweir m_xAggregateTypeProv.set( xIf, UNO_QUERY ); 167cdf0e10cSrcweir m_xAggInv.set( xIf, UNO_QUERY ); 168cdf0e10cSrcweir } 169cdf0e10cSrcweir } 170cdf0e10cSrcweir if ( xIf.is() ) 171cdf0e10cSrcweir { 172cdf0e10cSrcweir try 173cdf0e10cSrcweir { 174cdf0e10cSrcweir Reference< XMultiComponentFactory > xMFac( xFactory, UNO_QUERY_THROW ); 175cdf0e10cSrcweir Reference< XPropertySet> xPSMPropertySet( xMFac, UNO_QUERY_THROW ); 176cdf0e10cSrcweir Reference< XComponentContext > xCtx; 177cdf0e10cSrcweir xPSMPropertySet->getPropertyValue( 178cdf0e10cSrcweir String( RTL_CONSTASCII_USTRINGPARAM("DefaultContext") ) ) >>= xCtx; 179cdf0e10cSrcweir Reference< XProxyFactory > xProxyFac( xMFac->createInstanceWithContext( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.reflection.ProxyFactory" ) ), xCtx ), UNO_QUERY_THROW ); 180cdf0e10cSrcweir m_xAggProxy = xProxyFac->createProxy( xIf ); 181cdf0e10cSrcweir } 182cdf0e10cSrcweir catch( Exception& ) 183cdf0e10cSrcweir { 184cdf0e10cSrcweir OSL_ENSURE( false, "DocObjectWrapper::DocObjectWrapper: Caught exception!" ); 185cdf0e10cSrcweir } 186cdf0e10cSrcweir } 187cdf0e10cSrcweir 188cdf0e10cSrcweir if ( m_xAggProxy.is() ) 189cdf0e10cSrcweir { 190cdf0e10cSrcweir osl_incrementInterlockedCount( &m_refCount ); 191cdf0e10cSrcweir 192cdf0e10cSrcweir /* i35609 - Fix crash on Solaris. The setDelegator call needs 193cdf0e10cSrcweir to be in its own block to ensure that all temporary Reference 194cdf0e10cSrcweir instances that are acquired during the call are released 195cdf0e10cSrcweir before m_refCount is decremented again */ 196cdf0e10cSrcweir { 197cdf0e10cSrcweir m_xAggProxy->setDelegator( static_cast< cppu::OWeakObject * >( this ) ); 198cdf0e10cSrcweir } 199cdf0e10cSrcweir 200cdf0e10cSrcweir osl_decrementInterlockedCount( &m_refCount ); 201cdf0e10cSrcweir } 202cdf0e10cSrcweir } 203cdf0e10cSrcweir } 204cdf0e10cSrcweir } 205cdf0e10cSrcweir 206cdf0e10cSrcweir void SAL_CALL 207cdf0e10cSrcweir DocObjectWrapper::acquire() throw () 208cdf0e10cSrcweir { 209cdf0e10cSrcweir osl_incrementInterlockedCount( &m_refCount ); 210cdf0e10cSrcweir OSL_TRACE("DocObjectWrapper::acquire(%s) 0x%x refcount is now %d", rtl::OUStringToOString( mName, RTL_TEXTENCODING_UTF8 ).getStr(), this, m_refCount ); 211cdf0e10cSrcweir } 212cdf0e10cSrcweir void SAL_CALL 213cdf0e10cSrcweir DocObjectWrapper::release() throw () 214cdf0e10cSrcweir { 215cdf0e10cSrcweir if ( osl_decrementInterlockedCount( &m_refCount ) == 0 ) 216cdf0e10cSrcweir { 217cdf0e10cSrcweir OSL_TRACE("DocObjectWrapper::release(%s) 0x%x refcount is now %d", rtl::OUStringToOString( mName, RTL_TEXTENCODING_UTF8 ).getStr(), this, m_refCount ); 218cdf0e10cSrcweir delete this; 219cdf0e10cSrcweir } 220cdf0e10cSrcweir else 221cdf0e10cSrcweir OSL_TRACE("DocObjectWrapper::release(%s) 0x%x refcount is now %d", rtl::OUStringToOString( mName, RTL_TEXTENCODING_UTF8 ).getStr(), this, m_refCount ); 222cdf0e10cSrcweir } 223cdf0e10cSrcweir 224cdf0e10cSrcweir DocObjectWrapper::~DocObjectWrapper() 225cdf0e10cSrcweir { 226cdf0e10cSrcweir } 227cdf0e10cSrcweir 228cdf0e10cSrcweir Sequence< Type > SAL_CALL DocObjectWrapper::getTypes() 229cdf0e10cSrcweir throw ( RuntimeException ) 230cdf0e10cSrcweir { 231cdf0e10cSrcweir if ( m_Types.getLength() == 0 ) 232cdf0e10cSrcweir { 233cdf0e10cSrcweir Sequence< Type > sTypes; 234cdf0e10cSrcweir if ( m_xAggregateTypeProv.is() ) 235cdf0e10cSrcweir sTypes = m_xAggregateTypeProv->getTypes(); 236cdf0e10cSrcweir m_Types.realloc( sTypes.getLength() + 1 ); 237cdf0e10cSrcweir Type* pPtr = m_Types.getArray(); 238cdf0e10cSrcweir for ( int i=0; i<m_Types.getLength(); ++i, ++pPtr ) 239cdf0e10cSrcweir { 240cdf0e10cSrcweir if ( i == 0 ) 241cdf0e10cSrcweir *pPtr = XInvocation::static_type( NULL ); 242cdf0e10cSrcweir else 243cdf0e10cSrcweir *pPtr = sTypes[ i - 1 ]; 244cdf0e10cSrcweir } 245cdf0e10cSrcweir } 246cdf0e10cSrcweir return m_Types; 247cdf0e10cSrcweir } 248cdf0e10cSrcweir 249cdf0e10cSrcweir Reference< XIntrospectionAccess > SAL_CALL 250cdf0e10cSrcweir DocObjectWrapper::getIntrospection( ) throw (RuntimeException) 251cdf0e10cSrcweir { 252cdf0e10cSrcweir return NULL; 253cdf0e10cSrcweir } 254cdf0e10cSrcweir 255cdf0e10cSrcweir Any SAL_CALL 256cdf0e10cSrcweir DocObjectWrapper::invoke( const ::rtl::OUString& aFunctionName, const Sequence< Any >& aParams, Sequence< ::sal_Int16 >& aOutParamIndex, Sequence< Any >& aOutParam ) throw (IllegalArgumentException, CannotConvertException, InvocationTargetException, RuntimeException) 257cdf0e10cSrcweir { 258cdf0e10cSrcweir if ( m_xAggInv.is() && m_xAggInv->hasMethod( aFunctionName ) ) 259cdf0e10cSrcweir return m_xAggInv->invoke( aFunctionName, aParams, aOutParamIndex, aOutParam ); 260cdf0e10cSrcweir SbMethodRef pMethod = getMethod( aFunctionName ); 261cdf0e10cSrcweir if ( !pMethod ) 262cdf0e10cSrcweir throw RuntimeException(); 263cdf0e10cSrcweir // check number of parameters 264cdf0e10cSrcweir sal_Int32 nParamsCount = aParams.getLength(); 265cdf0e10cSrcweir SbxInfo* pInfo = pMethod->GetInfo(); 266cdf0e10cSrcweir if ( pInfo ) 267cdf0e10cSrcweir { 268cdf0e10cSrcweir sal_Int32 nSbxOptional = 0; 269cdf0e10cSrcweir sal_uInt16 n = 1; 270cdf0e10cSrcweir for ( const SbxParamInfo* pParamInfo = pInfo->GetParam( n ); pParamInfo; pParamInfo = pInfo->GetParam( ++n ) ) 271cdf0e10cSrcweir { 272cdf0e10cSrcweir if ( ( pParamInfo->nFlags & SBX_OPTIONAL ) != 0 ) 273cdf0e10cSrcweir ++nSbxOptional; 274cdf0e10cSrcweir else 275cdf0e10cSrcweir nSbxOptional = 0; 276cdf0e10cSrcweir } 277cdf0e10cSrcweir sal_Int32 nSbxCount = n - 1; 278cdf0e10cSrcweir if ( nParamsCount < nSbxCount - nSbxOptional ) 279cdf0e10cSrcweir { 280cdf0e10cSrcweir throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "wrong number of parameters!" ) ), Reference< XInterface >() ); 281cdf0e10cSrcweir } 282cdf0e10cSrcweir } 283cdf0e10cSrcweir // set parameters 284cdf0e10cSrcweir SbxArrayRef xSbxParams; 285cdf0e10cSrcweir if ( nParamsCount > 0 ) 286cdf0e10cSrcweir { 287cdf0e10cSrcweir xSbxParams = new SbxArray; 288cdf0e10cSrcweir const Any* pParams = aParams.getConstArray(); 289cdf0e10cSrcweir for ( sal_Int32 i = 0; i < nParamsCount; ++i ) 290cdf0e10cSrcweir { 291cdf0e10cSrcweir SbxVariableRef xSbxVar = new SbxVariable( SbxVARIANT ); 292cdf0e10cSrcweir unoToSbxValue( static_cast< SbxVariable* >( xSbxVar ), pParams[i] ); 293cdf0e10cSrcweir xSbxParams->Put( xSbxVar, static_cast< sal_uInt16 >( i ) + 1 ); 294cdf0e10cSrcweir 295cdf0e10cSrcweir // Enable passing by ref 296cdf0e10cSrcweir if ( xSbxVar->GetType() != SbxVARIANT ) 297cdf0e10cSrcweir xSbxVar->SetFlag( SBX_FIXED ); 298cdf0e10cSrcweir } 299cdf0e10cSrcweir } 300cdf0e10cSrcweir if ( xSbxParams.Is() ) 301cdf0e10cSrcweir pMethod->SetParameters( xSbxParams ); 302cdf0e10cSrcweir 303cdf0e10cSrcweir // call method 304cdf0e10cSrcweir SbxVariableRef xReturn = new SbxVariable; 305cdf0e10cSrcweir ErrCode nErr = SbxERR_OK; 306cdf0e10cSrcweir 307cdf0e10cSrcweir nErr = pMethod->Call( xReturn ); 308cdf0e10cSrcweir Any aReturn; 309cdf0e10cSrcweir // get output parameters 310cdf0e10cSrcweir if ( xSbxParams.Is() ) 311cdf0e10cSrcweir { 312cdf0e10cSrcweir SbxInfo* pInfo_ = pMethod->GetInfo(); 313cdf0e10cSrcweir if ( pInfo_ ) 314cdf0e10cSrcweir { 315cdf0e10cSrcweir OutParamMap aOutParamMap; 316cdf0e10cSrcweir for ( sal_uInt16 n = 1, nCount = xSbxParams->Count(); n < nCount; ++n ) 317cdf0e10cSrcweir { 318cdf0e10cSrcweir const SbxParamInfo* pParamInfo = pInfo_->GetParam( n ); 319cdf0e10cSrcweir if ( pParamInfo && ( pParamInfo->eType & SbxBYREF ) != 0 ) 320cdf0e10cSrcweir { 321cdf0e10cSrcweir SbxVariable* pVar = xSbxParams->Get( n ); 322cdf0e10cSrcweir if ( pVar ) 323cdf0e10cSrcweir { 324cdf0e10cSrcweir SbxVariableRef xVar = pVar; 325cdf0e10cSrcweir aOutParamMap.insert( OutParamMap::value_type( n - 1, sbxToUnoValue( xVar ) ) ); 326cdf0e10cSrcweir } 327cdf0e10cSrcweir } 328cdf0e10cSrcweir } 329cdf0e10cSrcweir sal_Int32 nOutParamCount = aOutParamMap.size(); 330cdf0e10cSrcweir aOutParamIndex.realloc( nOutParamCount ); 331cdf0e10cSrcweir aOutParam.realloc( nOutParamCount ); 332cdf0e10cSrcweir sal_Int16* pOutParamIndex = aOutParamIndex.getArray(); 333cdf0e10cSrcweir Any* pOutParam = aOutParam.getArray(); 334cdf0e10cSrcweir for ( OutParamMap::iterator aIt = aOutParamMap.begin(); aIt != aOutParamMap.end(); ++aIt, ++pOutParamIndex, ++pOutParam ) 335cdf0e10cSrcweir { 336cdf0e10cSrcweir *pOutParamIndex = aIt->first; 337cdf0e10cSrcweir *pOutParam = aIt->second; 338cdf0e10cSrcweir } 339cdf0e10cSrcweir } 340cdf0e10cSrcweir } 341cdf0e10cSrcweir 342cdf0e10cSrcweir // get return value 343cdf0e10cSrcweir aReturn = sbxToUnoValue( xReturn ); 344cdf0e10cSrcweir 345cdf0e10cSrcweir pMethod->SetParameters( NULL ); 346cdf0e10cSrcweir 347cdf0e10cSrcweir return aReturn; 348cdf0e10cSrcweir } 349cdf0e10cSrcweir 350cdf0e10cSrcweir void SAL_CALL 351cdf0e10cSrcweir DocObjectWrapper::setValue( const ::rtl::OUString& aPropertyName, const Any& aValue ) throw (UnknownPropertyException, CannotConvertException, InvocationTargetException, RuntimeException) 352cdf0e10cSrcweir { 353cdf0e10cSrcweir if ( m_xAggInv.is() && m_xAggInv->hasProperty( aPropertyName ) ) 354cdf0e10cSrcweir return m_xAggInv->setValue( aPropertyName, aValue ); 355cdf0e10cSrcweir 356cdf0e10cSrcweir SbPropertyRef pProperty = getProperty( aPropertyName ); 357cdf0e10cSrcweir if ( !pProperty.Is() ) 358cdf0e10cSrcweir throw UnknownPropertyException(); 359cdf0e10cSrcweir unoToSbxValue( (SbxVariable*) pProperty, aValue ); 360cdf0e10cSrcweir } 361cdf0e10cSrcweir 362cdf0e10cSrcweir Any SAL_CALL 363cdf0e10cSrcweir DocObjectWrapper::getValue( const ::rtl::OUString& aPropertyName ) throw (UnknownPropertyException, RuntimeException) 364cdf0e10cSrcweir { 365cdf0e10cSrcweir if ( m_xAggInv.is() && m_xAggInv->hasProperty( aPropertyName ) ) 366cdf0e10cSrcweir return m_xAggInv->getValue( aPropertyName ); 367cdf0e10cSrcweir 368cdf0e10cSrcweir SbPropertyRef pProperty = getProperty( aPropertyName ); 369cdf0e10cSrcweir if ( !pProperty.Is() ) 370cdf0e10cSrcweir throw UnknownPropertyException(); 371cdf0e10cSrcweir 372cdf0e10cSrcweir SbxVariable* pProp = ( SbxVariable* ) pProperty; 373cdf0e10cSrcweir if ( pProp->GetType() == SbxEMPTY ) 374cdf0e10cSrcweir pProperty->Broadcast( SBX_HINT_DATAWANTED ); 375cdf0e10cSrcweir 376cdf0e10cSrcweir Any aRet = sbxToUnoValue( pProp ); 377cdf0e10cSrcweir return aRet; 378cdf0e10cSrcweir } 379cdf0e10cSrcweir 380cdf0e10cSrcweir ::sal_Bool SAL_CALL 381cdf0e10cSrcweir DocObjectWrapper::hasMethod( const ::rtl::OUString& aName ) throw (RuntimeException) 382cdf0e10cSrcweir { 383cdf0e10cSrcweir if ( m_xAggInv.is() && m_xAggInv->hasMethod( aName ) ) 384cdf0e10cSrcweir return sal_True; 385cdf0e10cSrcweir return getMethod( aName ).Is(); 386cdf0e10cSrcweir } 387cdf0e10cSrcweir 388cdf0e10cSrcweir ::sal_Bool SAL_CALL 389cdf0e10cSrcweir DocObjectWrapper::hasProperty( const ::rtl::OUString& aName ) throw (RuntimeException) 390cdf0e10cSrcweir { 391cdf0e10cSrcweir sal_Bool bRes = sal_False; 392cdf0e10cSrcweir if ( m_xAggInv.is() && m_xAggInv->hasProperty( aName ) ) 393cdf0e10cSrcweir bRes = sal_True; 394cdf0e10cSrcweir else bRes = getProperty( aName ).Is(); 395cdf0e10cSrcweir return bRes; 396cdf0e10cSrcweir } 397cdf0e10cSrcweir 398cdf0e10cSrcweir Any SAL_CALL DocObjectWrapper::queryInterface( const Type& aType ) 399cdf0e10cSrcweir throw ( RuntimeException ) 400cdf0e10cSrcweir { 401cdf0e10cSrcweir Any aRet = DocObjectWrapper_BASE::queryInterface( aType ); 402cdf0e10cSrcweir if ( aRet.hasValue() ) 403cdf0e10cSrcweir return aRet; 404cdf0e10cSrcweir else if ( m_xAggProxy.is() ) 405cdf0e10cSrcweir aRet = m_xAggProxy->queryAggregation( aType ); 406cdf0e10cSrcweir return aRet; 407cdf0e10cSrcweir } 408cdf0e10cSrcweir 409cdf0e10cSrcweir SbMethodRef DocObjectWrapper::getMethod( const rtl::OUString& aName ) throw (RuntimeException) 410cdf0e10cSrcweir { 411cdf0e10cSrcweir SbMethodRef pMethod = NULL; 412cdf0e10cSrcweir if ( m_pMod ) 413cdf0e10cSrcweir { 414cdf0e10cSrcweir sal_uInt16 nSaveFlgs = m_pMod->GetFlags(); 415cdf0e10cSrcweir // Limit search to this module 416cdf0e10cSrcweir m_pMod->ResetFlag( SBX_GBLSEARCH ); 417cdf0e10cSrcweir pMethod = (SbMethod*) m_pMod->SbModule::Find( aName, SbxCLASS_METHOD ); 418cdf0e10cSrcweir m_pMod->SetFlags( nSaveFlgs ); 419cdf0e10cSrcweir } 420cdf0e10cSrcweir 421cdf0e10cSrcweir return pMethod; 422cdf0e10cSrcweir } 423cdf0e10cSrcweir 424cdf0e10cSrcweir SbPropertyRef DocObjectWrapper::getProperty( const rtl::OUString& aName ) throw (RuntimeException) 425cdf0e10cSrcweir { 426cdf0e10cSrcweir SbPropertyRef pProperty = NULL; 427cdf0e10cSrcweir if ( m_pMod ) 428cdf0e10cSrcweir { 429cdf0e10cSrcweir sal_uInt16 nSaveFlgs = m_pMod->GetFlags(); 430cdf0e10cSrcweir // Limit search to this module. 431cdf0e10cSrcweir m_pMod->ResetFlag( SBX_GBLSEARCH ); 432cdf0e10cSrcweir pProperty = (SbProperty*)m_pMod->SbModule::Find( aName, SbxCLASS_PROPERTY ); 433cdf0e10cSrcweir m_pMod->SetFlag( nSaveFlgs ); 434cdf0e10cSrcweir } 435cdf0e10cSrcweir 436cdf0e10cSrcweir return pProperty; 437cdf0e10cSrcweir } 438cdf0e10cSrcweir 439cdf0e10cSrcweir TYPEINIT1(SbModule,SbxObject) 440cdf0e10cSrcweir TYPEINIT1(SbMethod,SbxMethod) 441cdf0e10cSrcweir TYPEINIT1(SbProperty,SbxProperty) 442cdf0e10cSrcweir TYPEINIT1(SbProcedureProperty,SbxProperty) 443cdf0e10cSrcweir TYPEINIT1(SbJScriptModule,SbModule) 444cdf0e10cSrcweir TYPEINIT1(SbJScriptMethod,SbMethod) 445cdf0e10cSrcweir TYPEINIT1(SbObjModule,SbModule) 446cdf0e10cSrcweir TYPEINIT1(SbUserFormModule,SbObjModule) 447cdf0e10cSrcweir 448cdf0e10cSrcweir typedef std::vector<HighlightPortion> HighlightPortions; 449cdf0e10cSrcweir 450cdf0e10cSrcweir uno::Reference< frame::XModel > getDocumentModel( StarBASIC* pb ) 451cdf0e10cSrcweir { 452cdf0e10cSrcweir uno::Reference< frame::XModel > xModel; 453cdf0e10cSrcweir if( pb && pb->IsDocBasic() ) 454cdf0e10cSrcweir { 455cdf0e10cSrcweir uno::Any aDoc; 456cdf0e10cSrcweir if( pb->GetUNOConstant( "ThisComponent", aDoc ) ) 457cdf0e10cSrcweir xModel.set( aDoc, uno::UNO_QUERY ); 458cdf0e10cSrcweir } 459cdf0e10cSrcweir return xModel; 460cdf0e10cSrcweir } 461cdf0e10cSrcweir 462cdf0e10cSrcweir uno::Reference< vba::XVBACompatibility > getVBACompatibility( const uno::Reference< frame::XModel >& rxModel ) 463cdf0e10cSrcweir { 464cdf0e10cSrcweir uno::Reference< vba::XVBACompatibility > xVBACompat; 465cdf0e10cSrcweir try 466cdf0e10cSrcweir { 467cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xModelProps( rxModel, uno::UNO_QUERY_THROW ); 468cdf0e10cSrcweir xVBACompat.set( xModelProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BasicLibraries" ) ) ), uno::UNO_QUERY ); 469cdf0e10cSrcweir } 470cdf0e10cSrcweir catch( uno::Exception& ) 471cdf0e10cSrcweir { 472cdf0e10cSrcweir } 473cdf0e10cSrcweir return xVBACompat; 474cdf0e10cSrcweir } 475cdf0e10cSrcweir 476cdf0e10cSrcweir bool getDefaultVBAMode( StarBASIC* pb ) 477cdf0e10cSrcweir { 478cdf0e10cSrcweir uno::Reference< vba::XVBACompatibility > xVBACompat = getVBACompatibility( getDocumentModel( pb ) ); 479cdf0e10cSrcweir return xVBACompat.is() && xVBACompat->getVBACompatibilityMode(); 480cdf0e10cSrcweir } 481cdf0e10cSrcweir 482cdf0e10cSrcweir class AsyncQuitHandler 483cdf0e10cSrcweir { 484cdf0e10cSrcweir AsyncQuitHandler() {} 485cdf0e10cSrcweir AsyncQuitHandler( const AsyncQuitHandler&); 486cdf0e10cSrcweir public: 487cdf0e10cSrcweir static AsyncQuitHandler& instance() 488cdf0e10cSrcweir { 489cdf0e10cSrcweir static AsyncQuitHandler dInst; 490cdf0e10cSrcweir return dInst; 491cdf0e10cSrcweir } 492cdf0e10cSrcweir 493cdf0e10cSrcweir void QuitApplication() 494cdf0e10cSrcweir { 495cdf0e10cSrcweir uno::Reference< lang::XMultiServiceFactory > xFactory = comphelper::getProcessServiceFactory(); 496cdf0e10cSrcweir if ( xFactory.is() ) 497cdf0e10cSrcweir { 498cdf0e10cSrcweir uno::Reference< frame::XDesktop > xDeskTop( xFactory->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.Desktop") ) ), uno::UNO_QUERY ); 499cdf0e10cSrcweir if ( xDeskTop.is() ) 500cdf0e10cSrcweir xDeskTop->terminate(); 501cdf0e10cSrcweir } 502cdf0e10cSrcweir } 503cdf0e10cSrcweir DECL_LINK( OnAsyncQuit, void* ); 504cdf0e10cSrcweir }; 505cdf0e10cSrcweir 506cdf0e10cSrcweir IMPL_LINK( AsyncQuitHandler, OnAsyncQuit, void*, /*pNull*/ ) 507cdf0e10cSrcweir { 508cdf0e10cSrcweir QuitApplication(); 509cdf0e10cSrcweir return 0L; 510cdf0e10cSrcweir } 511cdf0e10cSrcweir 512cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////// 513cdf0e10cSrcweir 514cdf0e10cSrcweir // Ein BASIC-Modul hat EXTSEARCH gesetzt, damit die im Modul enthaltenen 515cdf0e10cSrcweir // Elemente von anderen Modulen aus gefunden werden koennen. 516cdf0e10cSrcweir 517cdf0e10cSrcweir SbModule::SbModule( const String& rName, sal_Bool bVBACompat ) 518cdf0e10cSrcweir : SbxObject( String( RTL_CONSTASCII_USTRINGPARAM("StarBASICModule") ) ), 519cdf0e10cSrcweir pImage( NULL ), pBreaks( NULL ), pClassData( NULL ), mbVBACompat( bVBACompat ), pDocObject( NULL ), bIsProxyModule( false ) 520cdf0e10cSrcweir { 521cdf0e10cSrcweir SetName( rName ); 522cdf0e10cSrcweir SetFlag( SBX_EXTSEARCH | SBX_GBLSEARCH ); 523cdf0e10cSrcweir SetModuleType( script::ModuleType::NORMAL ); 524cdf0e10cSrcweir 525cdf0e10cSrcweir // #i92642: Set name property to intitial name 526cdf0e10cSrcweir SbxVariable* pNameProp = pProps->Find( String( RTL_CONSTASCII_USTRINGPARAM("Name") ), SbxCLASS_PROPERTY ); 527cdf0e10cSrcweir if( pNameProp != NULL ) 528cdf0e10cSrcweir pNameProp->PutString( GetName() ); 529cdf0e10cSrcweir } 530cdf0e10cSrcweir 531cdf0e10cSrcweir SbModule::~SbModule() 532cdf0e10cSrcweir { 533cdf0e10cSrcweir OSL_TRACE("Module named %s is destructing", rtl::OUStringToOString( GetName(), RTL_TEXTENCODING_UTF8 ).getStr() ); 534cdf0e10cSrcweir if( pImage ) 535cdf0e10cSrcweir delete pImage; 536cdf0e10cSrcweir if( pBreaks ) 537cdf0e10cSrcweir delete pBreaks; 538cdf0e10cSrcweir if( pClassData ) 539cdf0e10cSrcweir delete pClassData; 540cdf0e10cSrcweir mxWrapper = NULL; 541cdf0e10cSrcweir } 542cdf0e10cSrcweir 543cdf0e10cSrcweir uno::Reference< script::XInvocation > 544cdf0e10cSrcweir SbModule::GetUnoModule() 545cdf0e10cSrcweir { 546cdf0e10cSrcweir if ( !mxWrapper.is() ) 547cdf0e10cSrcweir mxWrapper = new DocObjectWrapper( this ); 548cdf0e10cSrcweir 549cdf0e10cSrcweir OSL_TRACE("Module named %s returning wrapper mxWrapper (0x%x)", rtl::OUStringToOString( GetName(), RTL_TEXTENCODING_UTF8 ).getStr(), mxWrapper.get() ); 550cdf0e10cSrcweir return mxWrapper; 551cdf0e10cSrcweir } 552cdf0e10cSrcweir 553cdf0e10cSrcweir sal_Bool SbModule::IsCompiled() const 554cdf0e10cSrcweir { 555cdf0e10cSrcweir return sal_Bool( pImage != 0 ); 556cdf0e10cSrcweir } 557cdf0e10cSrcweir 558cdf0e10cSrcweir const SbxObject* SbModule::FindType( String aTypeName ) const 559cdf0e10cSrcweir { 560cdf0e10cSrcweir return pImage ? pImage->FindType( aTypeName ) : NULL; 561cdf0e10cSrcweir } 562cdf0e10cSrcweir 563cdf0e10cSrcweir 564cdf0e10cSrcweir // Aus dem Codegenerator: Loeschen des Images und Invalidieren der Entries 565cdf0e10cSrcweir 566cdf0e10cSrcweir void SbModule::StartDefinitions() 567cdf0e10cSrcweir { 568cdf0e10cSrcweir delete pImage; pImage = NULL; 569cdf0e10cSrcweir if( pClassData ) 570cdf0e10cSrcweir pClassData->clear(); 571cdf0e10cSrcweir 572cdf0e10cSrcweir // Methoden und Properties bleiben erhalten, sind jedoch ungueltig 573cdf0e10cSrcweir // schliesslich sind ja u.U. die Infos belegt 574cdf0e10cSrcweir sal_uInt16 i; 575cdf0e10cSrcweir for( i = 0; i < pMethods->Count(); i++ ) 576cdf0e10cSrcweir { 577cdf0e10cSrcweir SbMethod* p = PTR_CAST(SbMethod,pMethods->Get( i ) ); 578cdf0e10cSrcweir if( p ) 579cdf0e10cSrcweir p->bInvalid = sal_True; 580cdf0e10cSrcweir } 581cdf0e10cSrcweir for( i = 0; i < pProps->Count(); ) 582cdf0e10cSrcweir { 583cdf0e10cSrcweir SbProperty* p = PTR_CAST(SbProperty,pProps->Get( i ) ); 584cdf0e10cSrcweir if( p ) 585cdf0e10cSrcweir pProps->Remove( i ); 586cdf0e10cSrcweir else 587cdf0e10cSrcweir i++; 588cdf0e10cSrcweir } 589cdf0e10cSrcweir } 590cdf0e10cSrcweir 591cdf0e10cSrcweir // Methode anfordern/anlegen 592cdf0e10cSrcweir 593cdf0e10cSrcweir SbMethod* SbModule::GetMethod( const String& rName, SbxDataType t ) 594cdf0e10cSrcweir { 595cdf0e10cSrcweir SbxVariable* p = pMethods->Find( rName, SbxCLASS_METHOD ); 596cdf0e10cSrcweir SbMethod* pMeth = p ? PTR_CAST(SbMethod,p) : NULL; 597cdf0e10cSrcweir if( p && !pMeth ) 598cdf0e10cSrcweir pMethods->Remove( p ); 599cdf0e10cSrcweir if( !pMeth ) 600cdf0e10cSrcweir { 601cdf0e10cSrcweir pMeth = new SbMethod( rName, t, this ); 602cdf0e10cSrcweir pMeth->SetParent( this ); 603cdf0e10cSrcweir pMeth->SetFlags( SBX_READ ); 604cdf0e10cSrcweir pMethods->Put( pMeth, pMethods->Count() ); 605cdf0e10cSrcweir StartListening( pMeth->GetBroadcaster(), sal_True ); 606cdf0e10cSrcweir } 607cdf0e10cSrcweir // Per Default ist die Methode GUELTIG, da sie auch vom Compiler 608cdf0e10cSrcweir // (Codegenerator) erzeugt werden kann 609cdf0e10cSrcweir pMeth->bInvalid = sal_False; 610cdf0e10cSrcweir pMeth->ResetFlag( SBX_FIXED ); 611cdf0e10cSrcweir pMeth->SetFlag( SBX_WRITE ); 612cdf0e10cSrcweir pMeth->SetType( t ); 613cdf0e10cSrcweir pMeth->ResetFlag( SBX_WRITE ); 614cdf0e10cSrcweir if( t != SbxVARIANT ) 615cdf0e10cSrcweir pMeth->SetFlag( SBX_FIXED ); 616cdf0e10cSrcweir return pMeth; 617cdf0e10cSrcweir } 618cdf0e10cSrcweir 619cdf0e10cSrcweir // Property anfordern/anlegen 620cdf0e10cSrcweir 621cdf0e10cSrcweir SbProperty* SbModule::GetProperty( const String& rName, SbxDataType t ) 622cdf0e10cSrcweir { 623cdf0e10cSrcweir SbxVariable* p = pProps->Find( rName, SbxCLASS_PROPERTY ); 624cdf0e10cSrcweir SbProperty* pProp = p ? PTR_CAST(SbProperty,p) : NULL; 625cdf0e10cSrcweir if( p && !pProp ) 626cdf0e10cSrcweir pProps->Remove( p ); 627cdf0e10cSrcweir if( !pProp ) 628cdf0e10cSrcweir { 629cdf0e10cSrcweir pProp = new SbProperty( rName, t, this ); 630cdf0e10cSrcweir pProp->SetFlag( SBX_READWRITE ); 631cdf0e10cSrcweir pProp->SetParent( this ); 632cdf0e10cSrcweir pProps->Put( pProp, pProps->Count() ); 633cdf0e10cSrcweir StartListening( pProp->GetBroadcaster(), sal_True ); 634cdf0e10cSrcweir } 635cdf0e10cSrcweir return pProp; 636cdf0e10cSrcweir } 637cdf0e10cSrcweir 638cdf0e10cSrcweir SbProcedureProperty* SbModule::GetProcedureProperty 639cdf0e10cSrcweir ( const String& rName, SbxDataType t ) 640cdf0e10cSrcweir { 641cdf0e10cSrcweir SbxVariable* p = pProps->Find( rName, SbxCLASS_PROPERTY ); 642cdf0e10cSrcweir SbProcedureProperty* pProp = p ? PTR_CAST(SbProcedureProperty,p) : NULL; 643cdf0e10cSrcweir if( p && !pProp ) 644cdf0e10cSrcweir pProps->Remove( p ); 645cdf0e10cSrcweir if( !pProp ) 646cdf0e10cSrcweir { 647cdf0e10cSrcweir pProp = new SbProcedureProperty( rName, t ); 648cdf0e10cSrcweir pProp->SetFlag( SBX_READWRITE ); 649cdf0e10cSrcweir pProp->SetParent( this ); 650cdf0e10cSrcweir pProps->Put( pProp, pProps->Count() ); 651cdf0e10cSrcweir StartListening( pProp->GetBroadcaster(), sal_True ); 652cdf0e10cSrcweir } 653cdf0e10cSrcweir return pProp; 654cdf0e10cSrcweir } 655cdf0e10cSrcweir 656cdf0e10cSrcweir SbIfaceMapperMethod* SbModule::GetIfaceMapperMethod 657cdf0e10cSrcweir ( const String& rName, SbMethod* pImplMeth ) 658cdf0e10cSrcweir { 659cdf0e10cSrcweir SbxVariable* p = pMethods->Find( rName, SbxCLASS_METHOD ); 660cdf0e10cSrcweir SbIfaceMapperMethod* pMapperMethod = p ? PTR_CAST(SbIfaceMapperMethod,p) : NULL; 661cdf0e10cSrcweir if( p && !pMapperMethod ) 662cdf0e10cSrcweir pMethods->Remove( p ); 663cdf0e10cSrcweir if( !pMapperMethod ) 664cdf0e10cSrcweir { 665cdf0e10cSrcweir pMapperMethod = new SbIfaceMapperMethod( rName, pImplMeth ); 666cdf0e10cSrcweir pMapperMethod->SetParent( this ); 667cdf0e10cSrcweir pMapperMethod->SetFlags( SBX_READ ); 668cdf0e10cSrcweir pMethods->Put( pMapperMethod, pMethods->Count() ); 669cdf0e10cSrcweir } 670cdf0e10cSrcweir pMapperMethod->bInvalid = sal_False; 671cdf0e10cSrcweir return pMapperMethod; 672cdf0e10cSrcweir } 673cdf0e10cSrcweir 674cdf0e10cSrcweir SbIfaceMapperMethod::~SbIfaceMapperMethod() 675cdf0e10cSrcweir { 676cdf0e10cSrcweir } 677cdf0e10cSrcweir 678cdf0e10cSrcweir TYPEINIT1(SbIfaceMapperMethod,SbMethod) 679cdf0e10cSrcweir 680cdf0e10cSrcweir 681cdf0e10cSrcweir // Aus dem Codegenerator: Ungueltige Eintraege entfernen 682cdf0e10cSrcweir 683cdf0e10cSrcweir void SbModule::EndDefinitions( sal_Bool bNewState ) 684cdf0e10cSrcweir { 685cdf0e10cSrcweir for( sal_uInt16 i = 0; i < pMethods->Count(); ) 686cdf0e10cSrcweir { 687cdf0e10cSrcweir SbMethod* p = PTR_CAST(SbMethod,pMethods->Get( i ) ); 688cdf0e10cSrcweir if( p ) 689cdf0e10cSrcweir { 690cdf0e10cSrcweir if( p->bInvalid ) 691cdf0e10cSrcweir pMethods->Remove( p ); 692cdf0e10cSrcweir else 693cdf0e10cSrcweir { 694cdf0e10cSrcweir p->bInvalid = bNewState; 695cdf0e10cSrcweir i++; 696cdf0e10cSrcweir } 697cdf0e10cSrcweir } 698cdf0e10cSrcweir else 699cdf0e10cSrcweir i++; 700cdf0e10cSrcweir } 701cdf0e10cSrcweir SetModified( sal_True ); 702cdf0e10cSrcweir } 703cdf0e10cSrcweir 704cdf0e10cSrcweir void SbModule::Clear() 705cdf0e10cSrcweir { 706cdf0e10cSrcweir delete pImage; pImage = NULL; 707cdf0e10cSrcweir if( pClassData ) 708cdf0e10cSrcweir pClassData->clear(); 709cdf0e10cSrcweir SbxObject::Clear(); 710cdf0e10cSrcweir } 711cdf0e10cSrcweir 712cdf0e10cSrcweir 713cdf0e10cSrcweir SbxVariable* SbModule::Find( const XubString& rName, SbxClassType t ) 714cdf0e10cSrcweir { 715cdf0e10cSrcweir // make sure a search in an uninstatiated class module will fail 716cdf0e10cSrcweir SbxVariable* pRes = SbxObject::Find( rName, t ); 717cdf0e10cSrcweir if ( bIsProxyModule && !GetSbData()->bRunInit ) 718cdf0e10cSrcweir return NULL; 719cdf0e10cSrcweir if( !pRes && pImage ) 720cdf0e10cSrcweir { 721cdf0e10cSrcweir SbiInstance* pInst = pINST; 722cdf0e10cSrcweir if( pInst && pInst->IsCompatibility() ) 723cdf0e10cSrcweir { 724cdf0e10cSrcweir // Put enum types as objects into module, 725cdf0e10cSrcweir // allows MyEnum.First notation 726cdf0e10cSrcweir SbxArrayRef xArray = pImage->GetEnums(); 727cdf0e10cSrcweir if( xArray.Is() ) 728cdf0e10cSrcweir { 729cdf0e10cSrcweir SbxVariable* pEnumVar = xArray->Find( rName, SbxCLASS_DONTCARE ); 730cdf0e10cSrcweir SbxObject* pEnumObject = PTR_CAST( SbxObject, pEnumVar ); 731cdf0e10cSrcweir if( pEnumObject ) 732cdf0e10cSrcweir { 733cdf0e10cSrcweir bool bPrivate = pEnumObject->IsSet( SBX_PRIVATE ); 734cdf0e10cSrcweir String aEnumName = pEnumObject->GetName(); 735cdf0e10cSrcweir 736cdf0e10cSrcweir pRes = new SbxVariable( SbxOBJECT ); 737cdf0e10cSrcweir pRes->SetName( aEnumName ); 738cdf0e10cSrcweir pRes->SetParent( this ); 739cdf0e10cSrcweir pRes->SetFlag( SBX_READ ); 740cdf0e10cSrcweir if( bPrivate ) 741cdf0e10cSrcweir pRes->SetFlag( SBX_PRIVATE ); 742cdf0e10cSrcweir pRes->PutObject( pEnumObject ); 743cdf0e10cSrcweir } 744cdf0e10cSrcweir } 745cdf0e10cSrcweir } 746cdf0e10cSrcweir } 747cdf0e10cSrcweir return pRes; 748cdf0e10cSrcweir } 749cdf0e10cSrcweir 750cdf0e10cSrcweir const ::rtl::OUString& SbModule::GetSource32() const 751cdf0e10cSrcweir { 752cdf0e10cSrcweir return aOUSource; 753cdf0e10cSrcweir } 754cdf0e10cSrcweir 755cdf0e10cSrcweir const String& SbModule::GetSource() const 756cdf0e10cSrcweir { 757cdf0e10cSrcweir static String aRetStr; 758cdf0e10cSrcweir aRetStr = aOUSource; 759cdf0e10cSrcweir return aRetStr; 760cdf0e10cSrcweir } 761cdf0e10cSrcweir 762cdf0e10cSrcweir // Parent und BASIC sind eins! 763cdf0e10cSrcweir 764cdf0e10cSrcweir void SbModule::SetParent( SbxObject* p ) 765cdf0e10cSrcweir { 766cdf0e10cSrcweir // #118083: Assertion is not valid any more 767cdf0e10cSrcweir // DBG_ASSERT( !p || p->IsA( TYPE(StarBASIC) ), "SbModules nur in BASIC eintragen" ); 768cdf0e10cSrcweir pParent = p; 769cdf0e10cSrcweir } 770cdf0e10cSrcweir 771cdf0e10cSrcweir void SbModule::SFX_NOTIFY( SfxBroadcaster& rBC, const TypeId& rBCType, 772cdf0e10cSrcweir const SfxHint& rHint, const TypeId& rHintType ) 773cdf0e10cSrcweir { 774cdf0e10cSrcweir const SbxHint* pHint = PTR_CAST(SbxHint,&rHint); 775cdf0e10cSrcweir if( pHint ) 776cdf0e10cSrcweir { 777cdf0e10cSrcweir SbxVariable* pVar = pHint->GetVar(); 778cdf0e10cSrcweir SbProperty* pProp = PTR_CAST(SbProperty,pVar); 779cdf0e10cSrcweir SbMethod* pMeth = PTR_CAST(SbMethod,pVar); 780cdf0e10cSrcweir if( pProp ) 781cdf0e10cSrcweir { 782cdf0e10cSrcweir if( pProp->GetModule() != this ) 783cdf0e10cSrcweir SetError( SbxERR_BAD_ACTION ); 784cdf0e10cSrcweir } 785cdf0e10cSrcweir else if( pMeth ) 786cdf0e10cSrcweir { 787cdf0e10cSrcweir if( pHint->GetId() == SBX_HINT_DATAWANTED ) 788cdf0e10cSrcweir { 789cdf0e10cSrcweir if( pMeth->bInvalid && !Compile() ) 790cdf0e10cSrcweir // Auto-Compile hat nicht geklappt! 791cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_PROP_VALUE ); 792cdf0e10cSrcweir else 793cdf0e10cSrcweir { 794cdf0e10cSrcweir // Aufruf eines Unterprogramms 795cdf0e10cSrcweir SbModule* pOld = pMOD; 796cdf0e10cSrcweir pMOD = this; 797cdf0e10cSrcweir Run( (SbMethod*) pVar ); 798cdf0e10cSrcweir pMOD = pOld; 799cdf0e10cSrcweir } 800cdf0e10cSrcweir } 801cdf0e10cSrcweir } 802cdf0e10cSrcweir else 803cdf0e10cSrcweir { 804cdf0e10cSrcweir // #i92642: Special handling for name property to avoid 805cdf0e10cSrcweir // side effects when using name as variable implicitely 806cdf0e10cSrcweir bool bForwardToSbxObject = true; 807cdf0e10cSrcweir 808cdf0e10cSrcweir sal_uIntPtr nId = pHint->GetId(); 809cdf0e10cSrcweir if( (nId == SBX_HINT_DATAWANTED || nId == SBX_HINT_DATACHANGED) && 810cdf0e10cSrcweir pVar->GetName().EqualsIgnoreCaseAscii( "name" ) ) 811cdf0e10cSrcweir bForwardToSbxObject = false; 812cdf0e10cSrcweir 813cdf0e10cSrcweir if( bForwardToSbxObject ) 814cdf0e10cSrcweir SbxObject::SFX_NOTIFY( rBC, rBCType, rHint, rHintType ); 815cdf0e10cSrcweir } 816cdf0e10cSrcweir } 817cdf0e10cSrcweir } 818cdf0e10cSrcweir 819cdf0e10cSrcweir // Das Setzen der Source macht das Image ungueltig 820cdf0e10cSrcweir // und scant die Methoden-Definitionen neu ein 821cdf0e10cSrcweir 822cdf0e10cSrcweir void SbModule::SetSource( const String& r ) 823cdf0e10cSrcweir { 824cdf0e10cSrcweir SetSource32( r ); 825cdf0e10cSrcweir } 826cdf0e10cSrcweir 827cdf0e10cSrcweir void SbModule::SetSource32( const ::rtl::OUString& r ) 828cdf0e10cSrcweir { 829cdf0e10cSrcweir // Default basic mode to library container mode, but.. allow Option VBASupport 0/1 override 830cdf0e10cSrcweir SetVBACompat( getDefaultVBAMode( static_cast< StarBASIC*>( GetParent() ) ) ); 831cdf0e10cSrcweir aOUSource = r; 832cdf0e10cSrcweir StartDefinitions(); 833cdf0e10cSrcweir SbiTokenizer aTok( r ); 834cdf0e10cSrcweir while( !aTok.IsEof() ) 835cdf0e10cSrcweir { 836cdf0e10cSrcweir SbiToken eEndTok = NIL; 837cdf0e10cSrcweir 838cdf0e10cSrcweir // Suchen nach SUB oder FUNCTION 839cdf0e10cSrcweir SbiToken eLastTok = NIL; 840cdf0e10cSrcweir while( !aTok.IsEof() ) 841cdf0e10cSrcweir { 842cdf0e10cSrcweir // #32385: Nicht bei declare 843cdf0e10cSrcweir SbiToken eCurTok = aTok.Next(); 844cdf0e10cSrcweir if( eLastTok != DECLARE ) 845cdf0e10cSrcweir { 846cdf0e10cSrcweir if( eCurTok == SUB ) 847cdf0e10cSrcweir { 848cdf0e10cSrcweir eEndTok = ENDSUB; break; 849cdf0e10cSrcweir } 850cdf0e10cSrcweir if( eCurTok == FUNCTION ) 851cdf0e10cSrcweir { 852cdf0e10cSrcweir eEndTok = ENDFUNC; break; 853cdf0e10cSrcweir } 854cdf0e10cSrcweir if( eCurTok == PROPERTY ) 855cdf0e10cSrcweir { 856cdf0e10cSrcweir eEndTok = ENDPROPERTY; break; 857cdf0e10cSrcweir } 858cdf0e10cSrcweir if( eCurTok == OPTION ) 859cdf0e10cSrcweir { 860cdf0e10cSrcweir eCurTok = aTok.Next(); 861cdf0e10cSrcweir if( eCurTok == COMPATIBLE ) 862cdf0e10cSrcweir aTok.SetCompatible( true ); 863cdf0e10cSrcweir else if ( ( eCurTok == VBASUPPORT ) && ( aTok.Next() == NUMBER ) ) 864cdf0e10cSrcweir { 865cdf0e10cSrcweir sal_Bool bIsVBA = ( aTok.GetDbl()== 1 ); 866cdf0e10cSrcweir SetVBACompat( bIsVBA ); 867cdf0e10cSrcweir aTok.SetCompatible( bIsVBA ); 868cdf0e10cSrcweir } 869cdf0e10cSrcweir } 870cdf0e10cSrcweir } 871cdf0e10cSrcweir eLastTok = eCurTok; 872cdf0e10cSrcweir } 873cdf0e10cSrcweir // Definition der Methode 874cdf0e10cSrcweir SbMethod* pMeth = NULL; 875cdf0e10cSrcweir if( eEndTok != NIL ) 876cdf0e10cSrcweir { 877cdf0e10cSrcweir sal_uInt16 nLine1 = aTok.GetLine(); 878cdf0e10cSrcweir if( aTok.Next() == SYMBOL ) 879cdf0e10cSrcweir { 880cdf0e10cSrcweir String aName_( aTok.GetSym() ); 881cdf0e10cSrcweir SbxDataType t = aTok.GetType(); 882cdf0e10cSrcweir if( t == SbxVARIANT && eEndTok == ENDSUB ) 883cdf0e10cSrcweir t = SbxVOID; 884cdf0e10cSrcweir pMeth = GetMethod( aName_, t ); 885cdf0e10cSrcweir pMeth->nLine1 = pMeth->nLine2 = nLine1; 886cdf0e10cSrcweir // Die Methode ist erst mal GUELTIG 887cdf0e10cSrcweir pMeth->bInvalid = sal_False; 888cdf0e10cSrcweir } 889cdf0e10cSrcweir else 890cdf0e10cSrcweir eEndTok = NIL; 891cdf0e10cSrcweir } 892cdf0e10cSrcweir // Skip bis END SUB/END FUNCTION 893cdf0e10cSrcweir if( eEndTok != NIL ) 894cdf0e10cSrcweir { 895cdf0e10cSrcweir while( !aTok.IsEof() ) 896cdf0e10cSrcweir { 897cdf0e10cSrcweir if( aTok.Next() == eEndTok ) 898cdf0e10cSrcweir { 899cdf0e10cSrcweir pMeth->nLine2 = aTok.GetLine(); 900cdf0e10cSrcweir break; 901cdf0e10cSrcweir } 902cdf0e10cSrcweir } 903cdf0e10cSrcweir if( aTok.IsEof() ) 904cdf0e10cSrcweir pMeth->nLine2 = aTok.GetLine(); 905cdf0e10cSrcweir } 906cdf0e10cSrcweir } 907cdf0e10cSrcweir EndDefinitions( sal_True ); 908cdf0e10cSrcweir } 909cdf0e10cSrcweir 910cdf0e10cSrcweir void SbModule::SetComment( const String& r ) 911cdf0e10cSrcweir { 912cdf0e10cSrcweir aComment = r; 913cdf0e10cSrcweir SetModified( sal_True ); 914cdf0e10cSrcweir } 915cdf0e10cSrcweir 916cdf0e10cSrcweir SbMethod* SbModule::GetFunctionForLine( sal_uInt16 nLine ) 917cdf0e10cSrcweir { 918cdf0e10cSrcweir for( sal_uInt16 i = 0; i < pMethods->Count(); i++ ) 919cdf0e10cSrcweir { 920cdf0e10cSrcweir SbMethod* p = (SbMethod*) pMethods->Get( i ); 921cdf0e10cSrcweir if( p->GetSbxId() == SBXID_BASICMETHOD ) 922cdf0e10cSrcweir { 923cdf0e10cSrcweir if( nLine >= p->nLine1 && nLine <= p->nLine2 ) 924cdf0e10cSrcweir return p; 925cdf0e10cSrcweir } 926cdf0e10cSrcweir } 927cdf0e10cSrcweir return NULL; 928cdf0e10cSrcweir } 929cdf0e10cSrcweir 930cdf0e10cSrcweir // Ausstrahlen eines Hints an alle Basics 931cdf0e10cSrcweir 932cdf0e10cSrcweir static void _SendHint( SbxObject* pObj, sal_uIntPtr nId, SbMethod* p ) 933cdf0e10cSrcweir { 934cdf0e10cSrcweir // Selbst ein BASIC? 935cdf0e10cSrcweir if( pObj->IsA( TYPE(StarBASIC) ) && pObj->IsBroadcaster() ) 936cdf0e10cSrcweir pObj->GetBroadcaster().Broadcast( SbxHint( nId, p ) ); 937cdf0e10cSrcweir // Dann die Unterobjekte fragen 938cdf0e10cSrcweir SbxArray* pObjs = pObj->GetObjects(); 939cdf0e10cSrcweir for( sal_uInt16 i = 0; i < pObjs->Count(); i++ ) 940cdf0e10cSrcweir { 941cdf0e10cSrcweir SbxVariable* pVar = pObjs->Get( i ); 942cdf0e10cSrcweir if( pVar->IsA( TYPE(SbxObject) ) ) 943cdf0e10cSrcweir _SendHint( PTR_CAST(SbxObject,pVar), nId, p ); 944cdf0e10cSrcweir } 945cdf0e10cSrcweir } 946cdf0e10cSrcweir 947cdf0e10cSrcweir static void SendHint( SbxObject* pObj, sal_uIntPtr nId, SbMethod* p ) 948cdf0e10cSrcweir { 949cdf0e10cSrcweir while( pObj->GetParent() ) 950cdf0e10cSrcweir pObj = pObj->GetParent(); 951cdf0e10cSrcweir _SendHint( pObj, nId, p ); 952cdf0e10cSrcweir } 953cdf0e10cSrcweir 954cdf0e10cSrcweir // #57841 Uno-Objekte, die in RTL-Funktionen gehalten werden, 955cdf0e10cSrcweir // beim Programm-Ende freigeben, damit nichts gehalten wird. 956cdf0e10cSrcweir void ClearUnoObjectsInRTL_Impl_Rek( StarBASIC* pBasic ) 957cdf0e10cSrcweir { 958cdf0e10cSrcweir // return-Wert von CreateUnoService loeschen 959cdf0e10cSrcweir static String aName( RTL_CONSTASCII_USTRINGPARAM("CreateUnoService") ); 960cdf0e10cSrcweir SbxVariable* pVar = pBasic->GetRtl()->Find( aName, SbxCLASS_METHOD ); 961cdf0e10cSrcweir if( pVar ) 962cdf0e10cSrcweir pVar->SbxValue::Clear(); 963cdf0e10cSrcweir 964cdf0e10cSrcweir // return-Wert von CreateUnoDialog loeschen 965cdf0e10cSrcweir static String aName2( RTL_CONSTASCII_USTRINGPARAM("CreateUnoDialog") ); 966cdf0e10cSrcweir pVar = pBasic->GetRtl()->Find( aName2, SbxCLASS_METHOD ); 967cdf0e10cSrcweir if( pVar ) 968cdf0e10cSrcweir pVar->SbxValue::Clear(); 969cdf0e10cSrcweir 970cdf0e10cSrcweir // return-Wert von CDec loeschen 971cdf0e10cSrcweir static String aName3( RTL_CONSTASCII_USTRINGPARAM("CDec") ); 972cdf0e10cSrcweir pVar = pBasic->GetRtl()->Find( aName3, SbxCLASS_METHOD ); 973cdf0e10cSrcweir if( pVar ) 974cdf0e10cSrcweir pVar->SbxValue::Clear(); 975cdf0e10cSrcweir 976cdf0e10cSrcweir // return-Wert von CreateObject loeschen 977cdf0e10cSrcweir static String aName4( RTL_CONSTASCII_USTRINGPARAM("CreateObject") ); 978cdf0e10cSrcweir pVar = pBasic->GetRtl()->Find( aName4, SbxCLASS_METHOD ); 979cdf0e10cSrcweir if( pVar ) 980cdf0e10cSrcweir pVar->SbxValue::Clear(); 981cdf0e10cSrcweir 982cdf0e10cSrcweir // Ueber alle Sub-Basics gehen 983cdf0e10cSrcweir SbxArray* pObjs = pBasic->GetObjects(); 984cdf0e10cSrcweir sal_uInt16 nCount = pObjs->Count(); 985cdf0e10cSrcweir for( sal_uInt16 i = 0 ; i < nCount ; i++ ) 986cdf0e10cSrcweir { 987cdf0e10cSrcweir SbxVariable* pObjVar = pObjs->Get( i ); 988cdf0e10cSrcweir StarBASIC* pSubBasic = PTR_CAST( StarBASIC, pObjVar ); 989cdf0e10cSrcweir if( pSubBasic ) 990cdf0e10cSrcweir ClearUnoObjectsInRTL_Impl_Rek( pSubBasic ); 991cdf0e10cSrcweir } 992cdf0e10cSrcweir } 993cdf0e10cSrcweir 994cdf0e10cSrcweir void ClearUnoObjectsInRTL_Impl( StarBASIC* pBasic ) 995cdf0e10cSrcweir { 996cdf0e10cSrcweir // #67781 Rueckgabewerte der Uno-Methoden loeschen 997cdf0e10cSrcweir clearUnoMethods(); 998cdf0e10cSrcweir clearUnoServiceCtors(); 999cdf0e10cSrcweir 1000cdf0e10cSrcweir ClearUnoObjectsInRTL_Impl_Rek( pBasic ); 1001cdf0e10cSrcweir 1002cdf0e10cSrcweir // Oberstes Basic suchen 1003cdf0e10cSrcweir SbxObject* p = pBasic; 1004cdf0e10cSrcweir while( p->GetParent() ) 1005cdf0e10cSrcweir p = p->GetParent(); 1006cdf0e10cSrcweir if( ((StarBASIC*)p) != pBasic ) 1007cdf0e10cSrcweir ClearUnoObjectsInRTL_Impl_Rek( (StarBASIC*)p ); 1008cdf0e10cSrcweir } 1009cdf0e10cSrcweir sal_Bool SbModule::IsVBACompat() const 1010cdf0e10cSrcweir { 1011cdf0e10cSrcweir return mbVBACompat; 1012cdf0e10cSrcweir } 1013cdf0e10cSrcweir 1014cdf0e10cSrcweir void SbModule::SetVBACompat( sal_Bool bCompat ) 1015cdf0e10cSrcweir { 1016cdf0e10cSrcweir if( mbVBACompat != bCompat ) 1017cdf0e10cSrcweir { 1018cdf0e10cSrcweir mbVBACompat = bCompat; 1019cdf0e10cSrcweir // initialize VBA document API 1020cdf0e10cSrcweir if( mbVBACompat ) try 1021cdf0e10cSrcweir { 1022cdf0e10cSrcweir StarBASIC* pBasic = static_cast< StarBASIC* >( GetParent() ); 1023cdf0e10cSrcweir uno::Reference< lang::XMultiServiceFactory > xFactory( getDocumentModel( pBasic ), uno::UNO_QUERY_THROW ); 1024cdf0e10cSrcweir xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.VBAGlobals" ) ) ); 1025cdf0e10cSrcweir } 1026cdf0e10cSrcweir catch( Exception& ) 1027cdf0e10cSrcweir { 1028cdf0e10cSrcweir } 1029cdf0e10cSrcweir } 1030cdf0e10cSrcweir } 1031cdf0e10cSrcweir 1032cdf0e10cSrcweir // Ausfuehren eines BASIC-Unterprogramms 1033cdf0e10cSrcweir sal_uInt16 SbModule::Run( SbMethod* pMeth ) 1034cdf0e10cSrcweir { 1035cdf0e10cSrcweir static sal_uInt16 nMaxCallLevel = 0; 1036cdf0e10cSrcweir static String aMSOMacroRuntimeLibName = String::CreateFromAscii( "Launcher" ); 1037cdf0e10cSrcweir static String aMSOMacroRuntimeAppSymbol = String::CreateFromAscii( "Application" ); 1038cdf0e10cSrcweir 1039cdf0e10cSrcweir sal_uInt16 nRes = 0; 1040cdf0e10cSrcweir sal_Bool bDelInst = sal_Bool( pINST == NULL ); 1041cdf0e10cSrcweir StarBASICRef xBasic; 1042cdf0e10cSrcweir uno::Reference< frame::XModel > xModel; 1043cdf0e10cSrcweir uno::Reference< script::vba::XVBACompatibility > xVBACompat; 1044cdf0e10cSrcweir if( bDelInst ) 1045cdf0e10cSrcweir { 1046cdf0e10cSrcweir #ifdef DBG_TRACE_BASIC 1047cdf0e10cSrcweir dbg_InitTrace(); 1048cdf0e10cSrcweir #endif 1049cdf0e10cSrcweir // #32779: Basic waehrend der Ausfuehrung festhalten 1050cdf0e10cSrcweir xBasic = (StarBASIC*) GetParent(); 1051cdf0e10cSrcweir 1052cdf0e10cSrcweir pINST = new SbiInstance( (StarBASIC*) GetParent() ); 1053cdf0e10cSrcweir 1054cdf0e10cSrcweir /* If a VBA script in a document is started, get the VBA compatibility 1055cdf0e10cSrcweir interface from the document Basic library container, and notify all 1056cdf0e10cSrcweir VBA script listeners about the started script. */ 1057cdf0e10cSrcweir if( mbVBACompat ) 1058cdf0e10cSrcweir { 1059cdf0e10cSrcweir StarBASIC* pBasic = static_cast< StarBASIC* >( GetParent() ); 1060cdf0e10cSrcweir if( pBasic && pBasic->IsDocBasic() ) try 1061cdf0e10cSrcweir { 1062cdf0e10cSrcweir xModel.set( getDocumentModel( pBasic ), uno::UNO_SET_THROW ); 1063cdf0e10cSrcweir xVBACompat.set( getVBACompatibility( xModel ), uno::UNO_SET_THROW ); 1064cdf0e10cSrcweir xVBACompat->broadcastVBAScriptEvent( script::vba::VBAScriptEventId::SCRIPT_STARTED, GetName() ); 1065cdf0e10cSrcweir } 1066cdf0e10cSrcweir catch( uno::Exception& ) 1067cdf0e10cSrcweir { 1068cdf0e10cSrcweir } 1069cdf0e10cSrcweir } 1070cdf0e10cSrcweir 1071cdf0e10cSrcweir // Launcher problem 1072cdf0e10cSrcweir // i80726 The Find below will genarate an error in Testtool so we reset it unless there was one before already 1073cdf0e10cSrcweir sal_Bool bWasError = SbxBase::GetError() != 0; 1074cdf0e10cSrcweir SbxVariable* pMSOMacroRuntimeLibVar = Find( aMSOMacroRuntimeLibName, SbxCLASS_OBJECT ); 1075cdf0e10cSrcweir if ( !bWasError && (SbxBase::GetError() == SbxERR_PROC_UNDEFINED) ) 1076cdf0e10cSrcweir SbxBase::ResetError(); 1077cdf0e10cSrcweir if( pMSOMacroRuntimeLibVar ) 1078cdf0e10cSrcweir { 1079cdf0e10cSrcweir StarBASIC* pMSOMacroRuntimeLib = PTR_CAST(StarBASIC,pMSOMacroRuntimeLibVar); 1080cdf0e10cSrcweir if( pMSOMacroRuntimeLib ) 1081cdf0e10cSrcweir { 1082cdf0e10cSrcweir sal_uInt16 nGblFlag = pMSOMacroRuntimeLib->GetFlags() & SBX_GBLSEARCH; 1083cdf0e10cSrcweir pMSOMacroRuntimeLib->ResetFlag( SBX_GBLSEARCH ); 1084cdf0e10cSrcweir SbxVariable* pAppSymbol = pMSOMacroRuntimeLib->Find( aMSOMacroRuntimeAppSymbol, SbxCLASS_METHOD ); 1085cdf0e10cSrcweir pMSOMacroRuntimeLib->SetFlag( nGblFlag ); 1086cdf0e10cSrcweir if( pAppSymbol ) 1087cdf0e10cSrcweir { 1088cdf0e10cSrcweir pMSOMacroRuntimeLib->SetFlag( SBX_EXTSEARCH ); // Could have been disabled before 1089cdf0e10cSrcweir GetSbData()->pMSOMacroRuntimLib = pMSOMacroRuntimeLib; 1090cdf0e10cSrcweir } 1091cdf0e10cSrcweir } 1092cdf0e10cSrcweir } 1093cdf0e10cSrcweir 1094cdf0e10cSrcweir // Error-Stack loeschen 1095cdf0e10cSrcweir SbErrorStack*& rErrStack = GetSbData()->pErrStack; 1096cdf0e10cSrcweir delete rErrStack; 1097cdf0e10cSrcweir rErrStack = NULL; 1098cdf0e10cSrcweir 1099cdf0e10cSrcweir if( nMaxCallLevel == 0 ) 1100cdf0e10cSrcweir { 1101cdf0e10cSrcweir #ifdef UNX 1102cdf0e10cSrcweir struct rlimit rl; 1103cdf0e10cSrcweir getrlimit ( RLIMIT_STACK, &rl ); 1104cdf0e10cSrcweir // printf( "RLIMIT_STACK = %ld\n", rl.rlim_cur ); 1105cdf0e10cSrcweir #endif 1106cdf0e10cSrcweir #if defined LINUX 1107cdf0e10cSrcweir // Empiric value, 900 = needed bytes/Basic call level 1108cdf0e10cSrcweir // for Linux including 10% safety margin 1109cdf0e10cSrcweir nMaxCallLevel = rl.rlim_cur / 900; 1110cdf0e10cSrcweir #elif defined SOLARIS 1111cdf0e10cSrcweir // Empiric value, 1650 = needed bytes/Basic call level 1112cdf0e10cSrcweir // for Solaris including 10% safety margin 1113cdf0e10cSrcweir nMaxCallLevel = rl.rlim_cur / 1650; 1114cdf0e10cSrcweir #elif defined WIN32 1115cdf0e10cSrcweir nMaxCallLevel = 5800; 1116cdf0e10cSrcweir #else 1117cdf0e10cSrcweir nMaxCallLevel = MAXRECURSION; 1118cdf0e10cSrcweir #endif 1119cdf0e10cSrcweir } 1120cdf0e10cSrcweir } 1121cdf0e10cSrcweir 1122cdf0e10cSrcweir // Rekursion zu tief? 1123cdf0e10cSrcweir if( ++pINST->nCallLvl <= nMaxCallLevel ) 1124cdf0e10cSrcweir { 1125cdf0e10cSrcweir // Globale Variable in allen Mods definieren 1126cdf0e10cSrcweir GlobalRunInit( /* bBasicStart = */ bDelInst ); 1127cdf0e10cSrcweir 1128cdf0e10cSrcweir // Trat ein Compiler-Fehler auf? Dann starten wir nicht 1129cdf0e10cSrcweir if( GetSbData()->bGlobalInitErr == sal_False ) 1130cdf0e10cSrcweir { 1131cdf0e10cSrcweir if( bDelInst ) 1132cdf0e10cSrcweir { 1133cdf0e10cSrcweir SendHint( GetParent(), SBX_HINT_BASICSTART, pMeth ); 1134cdf0e10cSrcweir 1135cdf0e10cSrcweir // 16.10.96: #31460 Neues Konzept fuer StepInto/Over/Out 1136cdf0e10cSrcweir // Erklaerung siehe runtime.cxx bei SbiInstance::CalcBreakCallLevel() 1137cdf0e10cSrcweir // BreakCallLevel ermitteln 1138cdf0e10cSrcweir pINST->CalcBreakCallLevel( pMeth->GetDebugFlags() ); 1139cdf0e10cSrcweir } 1140cdf0e10cSrcweir 1141cdf0e10cSrcweir SbModule* pOldMod = pMOD; 1142cdf0e10cSrcweir pMOD = this; 1143cdf0e10cSrcweir SbiRuntime* pRt = new SbiRuntime( this, pMeth, pMeth->nStart ); 1144cdf0e10cSrcweir 1145cdf0e10cSrcweir #ifdef DBG_TRACE_BASIC 1146cdf0e10cSrcweir dbg_traceNotifyCall( this, pMeth, pINST->nCallLvl ); 1147cdf0e10cSrcweir #endif 1148cdf0e10cSrcweir 1149cdf0e10cSrcweir pRt->pNext = pINST->pRun; 1150cdf0e10cSrcweir if( pRt->pNext ) 1151cdf0e10cSrcweir pRt->pNext->block(); 1152cdf0e10cSrcweir pINST->pRun = pRt; 1153cdf0e10cSrcweir if ( mbVBACompat ) 1154cdf0e10cSrcweir { 1155cdf0e10cSrcweir pINST->EnableCompatibility( sal_True ); 1156cdf0e10cSrcweir } 1157cdf0e10cSrcweir while( pRt->Step() ) {} 1158cdf0e10cSrcweir if( pRt->pNext ) 1159cdf0e10cSrcweir pRt->pNext->unblock(); 1160cdf0e10cSrcweir 1161cdf0e10cSrcweir #ifdef DBG_TRACE_BASIC 1162cdf0e10cSrcweir bool bLeave = true; 1163cdf0e10cSrcweir dbg_traceNotifyCall( this, pMeth, pINST->nCallLvl, bLeave ); 1164cdf0e10cSrcweir #endif 1165cdf0e10cSrcweir 1166cdf0e10cSrcweir // #63710 Durch ein anderes Thread-Handling bei Events kann es passieren, 1167cdf0e10cSrcweir // dass show-Aufruf an einem Dialog zurueckkehrt (durch schliessen des 1168cdf0e10cSrcweir // Dialogs per UI), BEVOR ein per Event ausgeloester weitergehender Call, 1169cdf0e10cSrcweir // der in Basic weiter oben im Stack steht und auf einen Basic-Breakpoint 1170cdf0e10cSrcweir // gelaufen ist, zurueckkehrt. Dann wird unten die Instanz zerstoert und 1171cdf0e10cSrcweir // wenn das noch im Call stehende Basic weiterlaeuft, gibt es einen GPF. 1172cdf0e10cSrcweir // Daher muss hier gewartet werden, bis andere Call zurueckkehrt. 1173cdf0e10cSrcweir if( bDelInst ) 1174cdf0e10cSrcweir { 1175cdf0e10cSrcweir // Hier mit 1 statt 0 vergleichen, da vor nCallLvl-- 1176cdf0e10cSrcweir while( pINST->nCallLvl != 1 ) 1177cdf0e10cSrcweir GetpApp()->Yield(); 1178cdf0e10cSrcweir } 1179cdf0e10cSrcweir 1180cdf0e10cSrcweir nRes = sal_True; 1181cdf0e10cSrcweir pINST->pRun = pRt->pNext; 1182cdf0e10cSrcweir pINST->nCallLvl--; // Call-Level wieder runter 1183cdf0e10cSrcweir 1184cdf0e10cSrcweir // Gibt es eine uebergeordnete Runtime-Instanz? 1185cdf0e10cSrcweir // Dann SbDEBUG_BREAK uebernehmen, wenn gesetzt 1186cdf0e10cSrcweir SbiRuntime* pRtNext = pRt->pNext; 1187cdf0e10cSrcweir if( pRtNext && (pRt->GetDebugFlags() & SbDEBUG_BREAK) ) 1188cdf0e10cSrcweir pRtNext->SetDebugFlags( SbDEBUG_BREAK ); 1189cdf0e10cSrcweir 1190cdf0e10cSrcweir delete pRt; 1191cdf0e10cSrcweir pMOD = pOldMod; 1192cdf0e10cSrcweir if( bDelInst ) 1193cdf0e10cSrcweir { 1194cdf0e10cSrcweir // #57841 Uno-Objekte, die in RTL-Funktionen gehalten werden, 1195cdf0e10cSrcweir // beim Programm-Ende freigeben, damit nichts gehalten wird. 1196cdf0e10cSrcweir ClearUnoObjectsInRTL_Impl( xBasic ); 1197cdf0e10cSrcweir 1198cdf0e10cSrcweir clearNativeObjectWrapperVector(); 1199cdf0e10cSrcweir 1200cdf0e10cSrcweir DBG_ASSERT(pINST->nCallLvl==0,"BASIC-Call-Level > 0"); 1201cdf0e10cSrcweir delete pINST, pINST = NULL, bDelInst = sal_False; 1202cdf0e10cSrcweir 1203cdf0e10cSrcweir // #i30690 1204cdf0e10cSrcweir vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 1205cdf0e10cSrcweir SendHint( GetParent(), SBX_HINT_BASICSTOP, pMeth ); 1206cdf0e10cSrcweir 1207cdf0e10cSrcweir GlobalRunDeInit(); 1208cdf0e10cSrcweir 1209cdf0e10cSrcweir #ifdef DBG_UTIL 1210cdf0e10cSrcweir ResetCapturedAssertions(); 1211cdf0e10cSrcweir #endif 1212cdf0e10cSrcweir 1213cdf0e10cSrcweir if( xVBACompat.is() ) 1214cdf0e10cSrcweir { 1215cdf0e10cSrcweir // notify all VBA script listeners about the stopped script 1216cdf0e10cSrcweir try 1217cdf0e10cSrcweir { 1218cdf0e10cSrcweir xVBACompat->broadcastVBAScriptEvent( script::vba::VBAScriptEventId::SCRIPT_STOPPED, GetName() ); 1219cdf0e10cSrcweir } 1220cdf0e10cSrcweir catch( uno::Exception& ) 1221cdf0e10cSrcweir { 1222cdf0e10cSrcweir } 1223cdf0e10cSrcweir // VBA always ensures screenupdating is enabled after completing 1224cdf0e10cSrcweir ::basic::vba::lockControllersOfAllDocuments( xModel, sal_False ); 1225cdf0e10cSrcweir ::basic::vba::enableContainerWindowsOfAllDocuments( xModel, sal_True ); 1226cdf0e10cSrcweir } 1227cdf0e10cSrcweir 1228cdf0e10cSrcweir #ifdef DBG_TRACE_BASIC 1229cdf0e10cSrcweir dbg_DeInitTrace(); 1230cdf0e10cSrcweir #endif 1231cdf0e10cSrcweir } 1232cdf0e10cSrcweir } 1233cdf0e10cSrcweir else 1234cdf0e10cSrcweir pINST->nCallLvl--; // Call-Level wieder runter 1235cdf0e10cSrcweir } 1236cdf0e10cSrcweir else 1237cdf0e10cSrcweir { 1238cdf0e10cSrcweir pINST->nCallLvl--; // Call-Level wieder runter 1239cdf0e10cSrcweir StarBASIC::FatalError( SbERR_STACK_OVERFLOW ); 1240cdf0e10cSrcweir } 1241cdf0e10cSrcweir 1242cdf0e10cSrcweir StarBASIC* pBasic = PTR_CAST(StarBASIC,GetParent()); 1243cdf0e10cSrcweir if( bDelInst ) 1244cdf0e10cSrcweir { 1245cdf0e10cSrcweir // #57841 Uno-Objekte, die in RTL-Funktionen gehalten werden, 1246cdf0e10cSrcweir // beim Programm-Ende freigeben, damit nichts gehalten wird. 1247cdf0e10cSrcweir ClearUnoObjectsInRTL_Impl( xBasic ); 1248cdf0e10cSrcweir 1249cdf0e10cSrcweir delete pINST; 1250cdf0e10cSrcweir pINST = NULL; 1251cdf0e10cSrcweir } 1252cdf0e10cSrcweir if ( pBasic && pBasic->IsDocBasic() && pBasic->IsQuitApplication() && !pINST ) 1253cdf0e10cSrcweir { 1254cdf0e10cSrcweir Application::PostUserEvent( LINK( &AsyncQuitHandler::instance(), AsyncQuitHandler, OnAsyncQuit ), NULL ); 1255cdf0e10cSrcweir } 1256cdf0e10cSrcweir 1257cdf0e10cSrcweir return nRes; 1258cdf0e10cSrcweir } 1259cdf0e10cSrcweir 1260cdf0e10cSrcweir // Ausfuehren der Init-Methode eines Moduls nach dem Laden 1261cdf0e10cSrcweir // oder der Compilation 1262cdf0e10cSrcweir 1263cdf0e10cSrcweir void SbModule::RunInit() 1264cdf0e10cSrcweir { 1265cdf0e10cSrcweir if( pImage 1266cdf0e10cSrcweir && !pImage->bInit 1267cdf0e10cSrcweir && pImage->GetFlag( SBIMG_INITCODE ) ) 1268cdf0e10cSrcweir { 1269cdf0e10cSrcweir // Flag setzen, dass RunInit aktiv ist (Testtool) 1270cdf0e10cSrcweir GetSbData()->bRunInit = sal_True; 1271cdf0e10cSrcweir 1272cdf0e10cSrcweir // sal_Bool bDelInst = sal_Bool( pINST == NULL ); 1273cdf0e10cSrcweir // if( bDelInst ) 1274cdf0e10cSrcweir // pINST = new SbiInstance( (StarBASIC*) GetParent() ); 1275cdf0e10cSrcweir SbModule* pOldMod = pMOD; 1276cdf0e10cSrcweir pMOD = this; 1277cdf0e10cSrcweir // Der Init-Code beginnt immer hier 1278cdf0e10cSrcweir SbiRuntime* pRt = new SbiRuntime( this, NULL, 0 ); 1279cdf0e10cSrcweir 1280cdf0e10cSrcweir #ifdef DBG_TRACE_BASIC 1281cdf0e10cSrcweir dbg_traceNotifyCall( this, NULL, 0 ); 1282cdf0e10cSrcweir #endif 1283cdf0e10cSrcweir 1284cdf0e10cSrcweir pRt->pNext = pINST->pRun; 1285cdf0e10cSrcweir pINST->pRun = pRt; 1286cdf0e10cSrcweir while( pRt->Step() ) {} 1287cdf0e10cSrcweir 1288cdf0e10cSrcweir #ifdef DBG_TRACE_BASIC 1289cdf0e10cSrcweir bool bLeave = true; 1290cdf0e10cSrcweir dbg_traceNotifyCall( this, NULL, 0, bLeave ); 1291cdf0e10cSrcweir #endif 1292cdf0e10cSrcweir 1293cdf0e10cSrcweir pINST->pRun = pRt->pNext; 1294cdf0e10cSrcweir delete pRt; 1295cdf0e10cSrcweir pMOD = pOldMod; 1296cdf0e10cSrcweir // if( bDelInst ) 1297cdf0e10cSrcweir // delete pINST, pINST = NULL; 1298cdf0e10cSrcweir pImage->bInit = sal_True; 1299cdf0e10cSrcweir pImage->bFirstInit = sal_False; 1300cdf0e10cSrcweir 1301cdf0e10cSrcweir // RunInit ist nicht mehr aktiv 1302cdf0e10cSrcweir GetSbData()->bRunInit = sal_False; 1303cdf0e10cSrcweir } 1304cdf0e10cSrcweir } 1305cdf0e10cSrcweir 1306cdf0e10cSrcweir // Mit private/dim deklarierte Variablen loeschen 1307cdf0e10cSrcweir 1308cdf0e10cSrcweir void SbModule::AddVarName( const String& aName ) 1309cdf0e10cSrcweir { 1310cdf0e10cSrcweir // see if the name is added allready 1311cdf0e10cSrcweir std::vector< String >::iterator it_end = mModuleVariableNames.end(); 1312cdf0e10cSrcweir for ( std::vector< String >::iterator it = mModuleVariableNames.begin(); it != it_end; ++it ) 1313cdf0e10cSrcweir { 1314cdf0e10cSrcweir if ( aName == *it ) 1315cdf0e10cSrcweir return; 1316cdf0e10cSrcweir } 1317cdf0e10cSrcweir mModuleVariableNames.push_back( aName ); 1318cdf0e10cSrcweir } 1319cdf0e10cSrcweir 1320cdf0e10cSrcweir void SbModule::RemoveVars() 1321cdf0e10cSrcweir { 1322cdf0e10cSrcweir std::vector< String >::iterator it_end = mModuleVariableNames.end(); 1323cdf0e10cSrcweir for ( std::vector< String >::iterator it = mModuleVariableNames.begin(); it != it_end; ++it ) 1324cdf0e10cSrcweir { 1325cdf0e10cSrcweir // We don't want a Find being called in a derived class ( e.g. 1326cdf0e10cSrcweir // SbUserform because it could trigger say an initialise event 1327cdf0e10cSrcweir // which would cause basic to be re-run in the middle of the init ( and remember RemoveVars is called from compile and we don't want code to run as part of the compile ) 1328cdf0e10cSrcweir SbxVariableRef p = SbModule::Find( *it, SbxCLASS_PROPERTY ); 1329cdf0e10cSrcweir if( p.Is() ) 1330cdf0e10cSrcweir Remove (p); 1331cdf0e10cSrcweir } 1332cdf0e10cSrcweir } 1333cdf0e10cSrcweir 1334cdf0e10cSrcweir void SbModule::ClearPrivateVars() 1335cdf0e10cSrcweir { 1336cdf0e10cSrcweir for( sal_uInt16 i = 0 ; i < pProps->Count() ; i++ ) 1337cdf0e10cSrcweir { 1338cdf0e10cSrcweir SbProperty* p = PTR_CAST(SbProperty,pProps->Get( i ) ); 1339cdf0e10cSrcweir if( p ) 1340cdf0e10cSrcweir { 1341cdf0e10cSrcweir // Arrays nicht loeschen, sondern nur deren Inhalt 1342cdf0e10cSrcweir if( p->GetType() & SbxARRAY ) 1343cdf0e10cSrcweir { 1344cdf0e10cSrcweir SbxArray* pArray = PTR_CAST(SbxArray,p->GetObject()); 1345cdf0e10cSrcweir if( pArray ) 1346cdf0e10cSrcweir { 1347cdf0e10cSrcweir for( sal_uInt16 j = 0 ; j < pArray->Count() ; j++ ) 1348cdf0e10cSrcweir { 1349cdf0e10cSrcweir SbxVariable* pj = PTR_CAST(SbxVariable,pArray->Get( j )); 1350cdf0e10cSrcweir pj->SbxValue::Clear(); 1351cdf0e10cSrcweir /* 1352cdf0e10cSrcweir sal_uInt16 nFlags = pj->GetFlags(); 1353cdf0e10cSrcweir pj->SetFlags( (nFlags | SBX_WRITE) & (~SBX_FIXED) ); 1354cdf0e10cSrcweir pj->PutEmpty(); 1355cdf0e10cSrcweir pj->SetFlags( nFlags ); 1356cdf0e10cSrcweir */ 1357cdf0e10cSrcweir } 1358cdf0e10cSrcweir } 1359cdf0e10cSrcweir } 1360cdf0e10cSrcweir else 1361cdf0e10cSrcweir { 1362cdf0e10cSrcweir p->SbxValue::Clear(); 1363cdf0e10cSrcweir /* 1364cdf0e10cSrcweir sal_uInt16 nFlags = p->GetFlags(); 1365cdf0e10cSrcweir p->SetFlags( (nFlags | SBX_WRITE) & (~SBX_FIXED) ); 1366cdf0e10cSrcweir p->PutEmpty(); 1367cdf0e10cSrcweir p->SetFlags( nFlags ); 1368cdf0e10cSrcweir */ 1369cdf0e10cSrcweir } 1370cdf0e10cSrcweir } 1371cdf0e10cSrcweir } 1372cdf0e10cSrcweir } 1373cdf0e10cSrcweir 1374cdf0e10cSrcweir void SbModule::implClearIfVarDependsOnDeletedBasic( SbxVariable* pVar, StarBASIC* pDeletedBasic ) 1375cdf0e10cSrcweir { 1376cdf0e10cSrcweir if( pVar->SbxValue::GetType() != SbxOBJECT || pVar->ISA( SbProcedureProperty ) ) 1377cdf0e10cSrcweir return; 1378cdf0e10cSrcweir 1379cdf0e10cSrcweir SbxObject* pObj = PTR_CAST(SbxObject,pVar->GetObject()); 1380cdf0e10cSrcweir if( pObj != NULL ) 1381cdf0e10cSrcweir { 1382cdf0e10cSrcweir SbxObject* p = pObj; 1383cdf0e10cSrcweir 1384cdf0e10cSrcweir SbModule* pMod = PTR_CAST( SbModule, p ); 1385cdf0e10cSrcweir if( pMod != NULL ) 1386cdf0e10cSrcweir pMod->ClearVarsDependingOnDeletedBasic( pDeletedBasic ); 1387cdf0e10cSrcweir 1388cdf0e10cSrcweir while( (p = p->GetParent()) != NULL ) 1389cdf0e10cSrcweir { 1390cdf0e10cSrcweir StarBASIC* pBasic = PTR_CAST( StarBASIC, p ); 1391cdf0e10cSrcweir if( pBasic != NULL && pBasic == pDeletedBasic ) 1392cdf0e10cSrcweir { 1393cdf0e10cSrcweir pVar->SbxValue::Clear(); 1394cdf0e10cSrcweir break; 1395cdf0e10cSrcweir } 1396cdf0e10cSrcweir } 1397cdf0e10cSrcweir } 1398cdf0e10cSrcweir } 1399cdf0e10cSrcweir 1400cdf0e10cSrcweir void SbModule::ClearVarsDependingOnDeletedBasic( StarBASIC* pDeletedBasic ) 1401cdf0e10cSrcweir { 1402cdf0e10cSrcweir (void)pDeletedBasic; 1403cdf0e10cSrcweir 1404cdf0e10cSrcweir for( sal_uInt16 i = 0 ; i < pProps->Count() ; i++ ) 1405cdf0e10cSrcweir { 1406cdf0e10cSrcweir SbProperty* p = PTR_CAST(SbProperty,pProps->Get( i ) ); 1407cdf0e10cSrcweir if( p ) 1408cdf0e10cSrcweir { 1409cdf0e10cSrcweir if( p->GetType() & SbxARRAY ) 1410cdf0e10cSrcweir { 1411cdf0e10cSrcweir SbxArray* pArray = PTR_CAST(SbxArray,p->GetObject()); 1412cdf0e10cSrcweir if( pArray ) 1413cdf0e10cSrcweir { 1414cdf0e10cSrcweir for( sal_uInt16 j = 0 ; j < pArray->Count() ; j++ ) 1415cdf0e10cSrcweir { 1416cdf0e10cSrcweir SbxVariable* pVar = PTR_CAST(SbxVariable,pArray->Get( j )); 1417cdf0e10cSrcweir implClearIfVarDependsOnDeletedBasic( pVar, pDeletedBasic ); 1418cdf0e10cSrcweir } 1419cdf0e10cSrcweir } 1420cdf0e10cSrcweir } 1421cdf0e10cSrcweir else 1422cdf0e10cSrcweir { 1423cdf0e10cSrcweir implClearIfVarDependsOnDeletedBasic( p, pDeletedBasic ); 1424cdf0e10cSrcweir } 1425cdf0e10cSrcweir } 1426cdf0e10cSrcweir } 1427cdf0e10cSrcweir } 1428cdf0e10cSrcweir 1429cdf0e10cSrcweir // Zunaechst in dieses Modul, um 358-faehig zu bleiben 1430cdf0e10cSrcweir // (Branch in sb.cxx vermeiden) 1431cdf0e10cSrcweir void StarBASIC::ClearAllModuleVars( void ) 1432cdf0e10cSrcweir { 1433cdf0e10cSrcweir // Eigene Module initialisieren 1434cdf0e10cSrcweir for ( sal_uInt16 nMod = 0; nMod < pModules->Count(); nMod++ ) 1435cdf0e10cSrcweir { 1436cdf0e10cSrcweir SbModule* pModule = (SbModule*)pModules->Get( nMod ); 1437cdf0e10cSrcweir // Nur initialisieren, wenn der Startcode schon ausgefuehrt wurde 1438cdf0e10cSrcweir if( pModule->pImage && pModule->pImage->bInit && !pModule->isProxyModule() && !pModule->ISA(SbObjModule) ) 1439cdf0e10cSrcweir pModule->ClearPrivateVars(); 1440cdf0e10cSrcweir } 1441cdf0e10cSrcweir 1442cdf0e10cSrcweir /* #88042 This code can delete already used public vars during runtime! 1443cdf0e10cSrcweir // Alle Objekte ueberpruefen, ob es sich um ein Basic handelt 1444cdf0e10cSrcweir // Wenn ja, auch dort initialisieren 1445cdf0e10cSrcweir for ( sal_uInt16 nObj = 0; nObj < pObjs->Count(); nObj++ ) 1446cdf0e10cSrcweir { 1447cdf0e10cSrcweir SbxVariable* pVar = pObjs->Get( nObj ); 1448cdf0e10cSrcweir StarBASIC* pBasic = PTR_CAST(StarBASIC,pVar); 1449cdf0e10cSrcweir if( pBasic ) 1450cdf0e10cSrcweir pBasic->ClearAllModuleVars(); 1451cdf0e10cSrcweir } 1452cdf0e10cSrcweir */ 1453cdf0e10cSrcweir } 1454cdf0e10cSrcweir 1455cdf0e10cSrcweir // Ausfuehren des Init-Codes aller Module 1456cdf0e10cSrcweir void SbModule::GlobalRunInit( sal_Bool bBasicStart ) 1457cdf0e10cSrcweir { 1458cdf0e10cSrcweir // Wenn kein Basic-Start, nur initialisieren, wenn Modul uninitialisiert 1459cdf0e10cSrcweir if( !bBasicStart ) 1460cdf0e10cSrcweir if( !(pImage && !pImage->bInit) ) 1461cdf0e10cSrcweir return; 1462cdf0e10cSrcweir 1463cdf0e10cSrcweir // GlobalInitErr-Flag fuer Compiler-Error initialisieren 1464cdf0e10cSrcweir // Anhand dieses Flags kann in SbModule::Run() nach dem Aufruf 1465cdf0e10cSrcweir // von GlobalRunInit festgestellt werden, ob beim initialisieren 1466cdf0e10cSrcweir // der Module ein Fehler auftrat. Dann wird nicht gestartet. 1467cdf0e10cSrcweir GetSbData()->bGlobalInitErr = sal_False; 1468cdf0e10cSrcweir 1469cdf0e10cSrcweir // Parent vom Modul ist ein Basic 1470cdf0e10cSrcweir StarBASIC *pBasic = PTR_CAST(StarBASIC,GetParent()); 1471cdf0e10cSrcweir if( pBasic ) 1472cdf0e10cSrcweir { 1473cdf0e10cSrcweir pBasic->InitAllModules(); 1474cdf0e10cSrcweir 1475cdf0e10cSrcweir SbxObject* pParent_ = pBasic->GetParent(); 1476cdf0e10cSrcweir if( pParent_ ) 1477cdf0e10cSrcweir { 1478cdf0e10cSrcweir StarBASIC * pParentBasic = PTR_CAST(StarBASIC,pParent_); 1479cdf0e10cSrcweir if( pParentBasic ) 1480cdf0e10cSrcweir { 1481cdf0e10cSrcweir pParentBasic->InitAllModules( pBasic ); 1482cdf0e10cSrcweir 1483cdf0e10cSrcweir // #109018 Parent can also have a parent (library in doc) 1484cdf0e10cSrcweir SbxObject* pParentParent = pParentBasic->GetParent(); 1485cdf0e10cSrcweir if( pParentParent ) 1486cdf0e10cSrcweir { 1487cdf0e10cSrcweir StarBASIC * pParentParentBasic = PTR_CAST(StarBASIC,pParentParent); 1488cdf0e10cSrcweir if( pParentParentBasic ) 1489cdf0e10cSrcweir pParentParentBasic->InitAllModules( pParentBasic ); 1490cdf0e10cSrcweir } 1491cdf0e10cSrcweir } 1492cdf0e10cSrcweir } 1493cdf0e10cSrcweir } 1494cdf0e10cSrcweir } 1495cdf0e10cSrcweir 1496cdf0e10cSrcweir void SbModule::GlobalRunDeInit( void ) 1497cdf0e10cSrcweir { 1498cdf0e10cSrcweir StarBASIC *pBasic = PTR_CAST(StarBASIC,GetParent()); 1499cdf0e10cSrcweir if( pBasic ) 1500cdf0e10cSrcweir { 1501cdf0e10cSrcweir pBasic->DeInitAllModules(); 1502cdf0e10cSrcweir 1503cdf0e10cSrcweir SbxObject* pParent_ = pBasic->GetParent(); 1504cdf0e10cSrcweir if( pParent_ ) 1505cdf0e10cSrcweir pBasic = PTR_CAST(StarBASIC,pParent_); 1506cdf0e10cSrcweir if( pBasic ) 1507cdf0e10cSrcweir pBasic->DeInitAllModules(); 1508cdf0e10cSrcweir } 1509cdf0e10cSrcweir } 1510cdf0e10cSrcweir 1511cdf0e10cSrcweir // Suche nach dem naechsten STMNT-Befehl im Code. Wird vom STMNT- 1512cdf0e10cSrcweir // Opcode verwendet, um die Endspalte zu setzen. 1513cdf0e10cSrcweir 1514cdf0e10cSrcweir const sal_uInt8* SbModule::FindNextStmnt( const sal_uInt8* p, sal_uInt16& nLine, sal_uInt16& nCol ) const 1515cdf0e10cSrcweir { 1516cdf0e10cSrcweir return FindNextStmnt( p, nLine, nCol, sal_False ); 1517cdf0e10cSrcweir } 1518cdf0e10cSrcweir 1519cdf0e10cSrcweir const sal_uInt8* SbModule::FindNextStmnt( const sal_uInt8* p, sal_uInt16& nLine, sal_uInt16& nCol, 1520cdf0e10cSrcweir sal_Bool bFollowJumps, const SbiImage* pImg ) const 1521cdf0e10cSrcweir { 1522cdf0e10cSrcweir sal_uInt32 nPC = (sal_uInt32) ( p - (const sal_uInt8*) pImage->GetCode() ); 1523cdf0e10cSrcweir while( nPC < pImage->GetCodeSize() ) 1524cdf0e10cSrcweir { 1525cdf0e10cSrcweir SbiOpcode eOp = (SbiOpcode ) ( *p++ ); 1526cdf0e10cSrcweir nPC++; 1527cdf0e10cSrcweir if( bFollowJumps && eOp == _JUMP && pImg ) 1528cdf0e10cSrcweir { 1529cdf0e10cSrcweir DBG_ASSERT( pImg, "FindNextStmnt: pImg==NULL with FollowJumps option" ); 1530cdf0e10cSrcweir sal_uInt32 nOp1 = *p++; nOp1 |= *p++ << 8; 1531cdf0e10cSrcweir nOp1 |= *p++ << 16; nOp1 |= *p++ << 24; 1532cdf0e10cSrcweir p = (const sal_uInt8*) pImg->GetCode() + nOp1; 1533cdf0e10cSrcweir } 1534cdf0e10cSrcweir else if( eOp >= SbOP1_START && eOp <= SbOP1_END ) 1535cdf0e10cSrcweir p += 4, nPC += 4; 1536cdf0e10cSrcweir else if( eOp == _STMNT ) 1537cdf0e10cSrcweir { 1538cdf0e10cSrcweir sal_uInt32 nl, nc; 1539cdf0e10cSrcweir nl = *p++; nl |= *p++ << 8; 1540cdf0e10cSrcweir nl |= *p++ << 16 ; nl |= *p++ << 24; 1541cdf0e10cSrcweir nc = *p++; nc |= *p++ << 8; 1542cdf0e10cSrcweir nc |= *p++ << 16 ; nc |= *p++ << 24; 1543cdf0e10cSrcweir nLine = (sal_uInt16)nl; nCol = (sal_uInt16)nc; 1544cdf0e10cSrcweir return p; 1545cdf0e10cSrcweir } 1546cdf0e10cSrcweir else if( eOp >= SbOP2_START && eOp <= SbOP2_END ) 1547cdf0e10cSrcweir p += 8, nPC += 8; 1548cdf0e10cSrcweir else if( !( eOp >= SbOP0_START && eOp <= SbOP0_END ) ) 1549cdf0e10cSrcweir { 1550cdf0e10cSrcweir StarBASIC::FatalError( SbERR_INTERNAL_ERROR ); 1551cdf0e10cSrcweir break; 1552cdf0e10cSrcweir } 1553cdf0e10cSrcweir } 1554cdf0e10cSrcweir return NULL; 1555cdf0e10cSrcweir } 1556cdf0e10cSrcweir 1557cdf0e10cSrcweir // Testen, ob eine Zeile STMNT-Opcodes enthaelt 1558cdf0e10cSrcweir 1559cdf0e10cSrcweir sal_Bool SbModule::IsBreakable( sal_uInt16 nLine ) const 1560cdf0e10cSrcweir { 1561cdf0e10cSrcweir if( !pImage ) 1562cdf0e10cSrcweir return sal_False; 1563cdf0e10cSrcweir const sal_uInt8* p = (const sal_uInt8* ) pImage->GetCode(); 1564cdf0e10cSrcweir sal_uInt16 nl, nc; 1565cdf0e10cSrcweir while( ( p = FindNextStmnt( p, nl, nc ) ) != NULL ) 1566cdf0e10cSrcweir if( nl == nLine ) 1567cdf0e10cSrcweir return sal_True; 1568cdf0e10cSrcweir return sal_False; 1569cdf0e10cSrcweir } 1570cdf0e10cSrcweir 1571cdf0e10cSrcweir size_t SbModule::GetBPCount() const 1572cdf0e10cSrcweir { 1573cdf0e10cSrcweir return pBreaks ? pBreaks->size() : 0; 1574cdf0e10cSrcweir } 1575cdf0e10cSrcweir 1576cdf0e10cSrcweir sal_uInt16 SbModule::GetBP( size_t n ) const 1577cdf0e10cSrcweir { 1578cdf0e10cSrcweir if( pBreaks && n < pBreaks->size() ) 1579cdf0e10cSrcweir return pBreaks->operator[]( n ); 1580cdf0e10cSrcweir else 1581cdf0e10cSrcweir return 0; 1582cdf0e10cSrcweir } 1583cdf0e10cSrcweir 1584cdf0e10cSrcweir sal_Bool SbModule::IsBP( sal_uInt16 nLine ) const 1585cdf0e10cSrcweir { 1586cdf0e10cSrcweir if( pBreaks ) 1587cdf0e10cSrcweir { 1588cdf0e10cSrcweir for( size_t i = 0; i < pBreaks->size(); i++ ) 1589cdf0e10cSrcweir { 1590cdf0e10cSrcweir sal_uInt16 b = pBreaks->operator[]( i ); 1591cdf0e10cSrcweir if( b == nLine ) 1592cdf0e10cSrcweir return sal_True; 1593cdf0e10cSrcweir if( b < nLine ) 1594cdf0e10cSrcweir break; 1595cdf0e10cSrcweir } 1596cdf0e10cSrcweir } 1597cdf0e10cSrcweir return sal_False; 1598cdf0e10cSrcweir } 1599cdf0e10cSrcweir 1600cdf0e10cSrcweir sal_Bool SbModule::SetBP( sal_uInt16 nLine ) 1601cdf0e10cSrcweir { 1602cdf0e10cSrcweir if( !IsBreakable( nLine ) ) 1603cdf0e10cSrcweir return sal_False; 1604cdf0e10cSrcweir if( !pBreaks ) 1605cdf0e10cSrcweir pBreaks = new SbiBreakpoints; 1606cdf0e10cSrcweir size_t i; 1607cdf0e10cSrcweir for( i = 0; i < pBreaks->size(); i++ ) 1608cdf0e10cSrcweir { 1609cdf0e10cSrcweir sal_uInt16 b = pBreaks->operator[]( i ); 1610cdf0e10cSrcweir if( b == nLine ) 1611cdf0e10cSrcweir return sal_True; 1612cdf0e10cSrcweir if( b < nLine ) 1613cdf0e10cSrcweir break; 1614cdf0e10cSrcweir } 1615cdf0e10cSrcweir pBreaks->insert( pBreaks->begin() + i, nLine ); 1616cdf0e10cSrcweir 1617cdf0e10cSrcweir // #38568: Zur Laufzeit auch hier SbDEBUG_BREAK setzen 1618cdf0e10cSrcweir if( pINST && pINST->pRun ) 1619cdf0e10cSrcweir pINST->pRun->SetDebugFlags( SbDEBUG_BREAK ); 1620cdf0e10cSrcweir 1621cdf0e10cSrcweir return IsBreakable( nLine ); 1622cdf0e10cSrcweir } 1623cdf0e10cSrcweir 1624cdf0e10cSrcweir sal_Bool SbModule::ClearBP( sal_uInt16 nLine ) 1625cdf0e10cSrcweir { 1626cdf0e10cSrcweir sal_Bool bRes = sal_False; 1627cdf0e10cSrcweir if( pBreaks ) 1628cdf0e10cSrcweir { 1629cdf0e10cSrcweir for( size_t i = 0; i < pBreaks->size(); i++ ) 1630cdf0e10cSrcweir { 1631cdf0e10cSrcweir sal_uInt16 b = pBreaks->operator[]( i ); 1632cdf0e10cSrcweir if( b == nLine ) 1633cdf0e10cSrcweir { 1634cdf0e10cSrcweir pBreaks->erase( pBreaks->begin() + i ); 1635cdf0e10cSrcweir bRes = sal_True; 1636cdf0e10cSrcweir break; 1637cdf0e10cSrcweir } 1638cdf0e10cSrcweir if( b < nLine ) 1639cdf0e10cSrcweir break; 1640cdf0e10cSrcweir } 1641cdf0e10cSrcweir if( pBreaks->empty() ) 1642cdf0e10cSrcweir delete pBreaks, pBreaks = NULL; 1643cdf0e10cSrcweir } 1644cdf0e10cSrcweir return bRes; 1645cdf0e10cSrcweir } 1646cdf0e10cSrcweir 1647cdf0e10cSrcweir void SbModule::ClearAllBP() 1648cdf0e10cSrcweir { 1649cdf0e10cSrcweir delete pBreaks; 1650cdf0e10cSrcweir pBreaks = NULL; 1651cdf0e10cSrcweir } 1652cdf0e10cSrcweir 1653cdf0e10cSrcweir void 1654cdf0e10cSrcweir SbModule::fixUpMethodStart( bool bCvtToLegacy, SbiImage* pImg ) const 1655cdf0e10cSrcweir { 1656cdf0e10cSrcweir if ( !pImg ) 1657cdf0e10cSrcweir pImg = pImage; 1658cdf0e10cSrcweir for( sal_uInt32 i = 0; i < pMethods->Count(); i++ ) 1659cdf0e10cSrcweir { 1660cdf0e10cSrcweir SbMethod* pMeth = PTR_CAST(SbMethod,pMethods->Get( (sal_uInt16)i ) ); 1661cdf0e10cSrcweir if( pMeth ) 1662cdf0e10cSrcweir { 1663cdf0e10cSrcweir //fixup method start positions 1664cdf0e10cSrcweir if ( bCvtToLegacy ) 1665cdf0e10cSrcweir pMeth->nStart = pImg->CalcLegacyOffset( pMeth->nStart ); 1666cdf0e10cSrcweir else 1667cdf0e10cSrcweir pMeth->nStart = pImg->CalcNewOffset( (sal_uInt16)pMeth->nStart ); 1668cdf0e10cSrcweir } 1669cdf0e10cSrcweir } 1670cdf0e10cSrcweir 1671cdf0e10cSrcweir } 1672cdf0e10cSrcweir 1673cdf0e10cSrcweir sal_Bool SbModule::LoadData( SvStream& rStrm, sal_uInt16 nVer ) 1674cdf0e10cSrcweir { 1675cdf0e10cSrcweir Clear(); 1676cdf0e10cSrcweir if( !SbxObject::LoadData( rStrm, 1 ) ) 1677cdf0e10cSrcweir return sal_False; 1678cdf0e10cSrcweir // Precaution... 1679cdf0e10cSrcweir SetFlag( SBX_EXTSEARCH | SBX_GBLSEARCH ); 1680cdf0e10cSrcweir sal_uInt8 bImage; 1681cdf0e10cSrcweir rStrm >> bImage; 1682cdf0e10cSrcweir if( bImage ) 1683cdf0e10cSrcweir { 1684cdf0e10cSrcweir SbiImage* p = new SbiImage; 1685cdf0e10cSrcweir sal_uInt32 nImgVer = 0; 1686cdf0e10cSrcweir 1687cdf0e10cSrcweir if( !p->Load( rStrm, nImgVer ) ) 1688cdf0e10cSrcweir { 1689cdf0e10cSrcweir delete p; 1690cdf0e10cSrcweir return sal_False; 1691cdf0e10cSrcweir } 1692cdf0e10cSrcweir // If the image is in old format, we fix up the method start offsets 1693cdf0e10cSrcweir if ( nImgVer < B_EXT_IMG_VERSION ) 1694cdf0e10cSrcweir { 1695cdf0e10cSrcweir fixUpMethodStart( false, p ); 1696cdf0e10cSrcweir p->ReleaseLegacyBuffer(); 1697cdf0e10cSrcweir } 1698cdf0e10cSrcweir aComment = p->aComment; 1699cdf0e10cSrcweir SetName( p->aName ); 1700cdf0e10cSrcweir if( p->GetCodeSize() ) 1701cdf0e10cSrcweir { 1702cdf0e10cSrcweir aOUSource = p->aOUSource; 1703cdf0e10cSrcweir // Alte Version: Image weg 1704cdf0e10cSrcweir if( nVer == 1 ) 1705cdf0e10cSrcweir { 1706cdf0e10cSrcweir SetSource32( p->aOUSource ); 1707cdf0e10cSrcweir delete p; 1708cdf0e10cSrcweir } 1709cdf0e10cSrcweir else 1710cdf0e10cSrcweir pImage = p; 1711cdf0e10cSrcweir } 1712cdf0e10cSrcweir else 1713cdf0e10cSrcweir { 1714cdf0e10cSrcweir SetSource32( p->aOUSource ); 1715cdf0e10cSrcweir delete p; 1716cdf0e10cSrcweir } 1717cdf0e10cSrcweir } 1718cdf0e10cSrcweir return sal_True; 1719cdf0e10cSrcweir } 1720cdf0e10cSrcweir 1721cdf0e10cSrcweir sal_Bool SbModule::StoreData( SvStream& rStrm ) const 1722cdf0e10cSrcweir { 1723cdf0e10cSrcweir sal_Bool bFixup = ( pImage && !pImage->ExceedsLegacyLimits() ); 1724cdf0e10cSrcweir if ( bFixup ) 1725cdf0e10cSrcweir fixUpMethodStart( true ); 1726cdf0e10cSrcweir sal_Bool bRet = SbxObject::StoreData( rStrm ); 1727cdf0e10cSrcweir if ( !bRet ) 1728cdf0e10cSrcweir return sal_False; 1729cdf0e10cSrcweir 1730cdf0e10cSrcweir if( pImage ) 1731cdf0e10cSrcweir { 1732cdf0e10cSrcweir pImage->aOUSource = aOUSource; 1733cdf0e10cSrcweir pImage->aComment = aComment; 1734cdf0e10cSrcweir pImage->aName = GetName(); 1735cdf0e10cSrcweir rStrm << (sal_uInt8) 1; 1736cdf0e10cSrcweir // # PCode is saved only for legacy formats only 1737cdf0e10cSrcweir // It should be noted that it probably isn't necessary 1738cdf0e10cSrcweir // It would be better not to store the image ( more flexible with 1739cdf0e10cSrcweir // formats ) 1740cdf0e10cSrcweir bool bRes = pImage->Save( rStrm, B_LEGACYVERSION ); 1741cdf0e10cSrcweir if ( bFixup ) 1742cdf0e10cSrcweir fixUpMethodStart( false ); // restore method starts 1743cdf0e10cSrcweir return bRes; 1744cdf0e10cSrcweir 1745cdf0e10cSrcweir } 1746cdf0e10cSrcweir else 1747cdf0e10cSrcweir { 1748cdf0e10cSrcweir SbiImage aImg; 1749cdf0e10cSrcweir aImg.aOUSource = aOUSource; 1750cdf0e10cSrcweir aImg.aComment = aComment; 1751cdf0e10cSrcweir aImg.aName = GetName(); 1752cdf0e10cSrcweir rStrm << (sal_uInt8) 1; 1753cdf0e10cSrcweir return aImg.Save( rStrm ); 1754cdf0e10cSrcweir } 1755cdf0e10cSrcweir } 1756cdf0e10cSrcweir 1757cdf0e10cSrcweir sal_Bool SbModule::ExceedsLegacyModuleSize() 1758cdf0e10cSrcweir { 1759cdf0e10cSrcweir if ( !IsCompiled() ) 1760cdf0e10cSrcweir Compile(); 1761cdf0e10cSrcweir if ( pImage && pImage->ExceedsLegacyLimits() ) 1762cdf0e10cSrcweir return true; 1763cdf0e10cSrcweir return false; 1764cdf0e10cSrcweir } 1765cdf0e10cSrcweir 1766cdf0e10cSrcweir 1767cdf0e10cSrcweir // Store only image, no source 1768cdf0e10cSrcweir sal_Bool SbModule::StoreBinaryData( SvStream& rStrm ) 1769cdf0e10cSrcweir { 1770cdf0e10cSrcweir return StoreBinaryData( rStrm, 0 ); 1771cdf0e10cSrcweir } 1772cdf0e10cSrcweir 1773cdf0e10cSrcweir sal_Bool SbModule::StoreBinaryData( SvStream& rStrm, sal_uInt16 nVer ) 1774cdf0e10cSrcweir { 1775cdf0e10cSrcweir sal_Bool bRet = Compile(); 1776cdf0e10cSrcweir if( bRet ) 1777cdf0e10cSrcweir { 1778cdf0e10cSrcweir sal_Bool bFixup = ( !nVer && !pImage->ExceedsLegacyLimits() );// save in old image format, fix up method starts 1779cdf0e10cSrcweir 1780cdf0e10cSrcweir if ( bFixup ) // save in old image format, fix up method starts 1781cdf0e10cSrcweir fixUpMethodStart( true ); 1782cdf0e10cSrcweir bRet = SbxObject::StoreData( rStrm ); 1783cdf0e10cSrcweir if( bRet ) 1784cdf0e10cSrcweir { 1785cdf0e10cSrcweir pImage->aOUSource = ::rtl::OUString(); 1786cdf0e10cSrcweir pImage->aComment = aComment; 1787cdf0e10cSrcweir pImage->aName = GetName(); 1788cdf0e10cSrcweir 1789cdf0e10cSrcweir rStrm << (sal_uInt8) 1; 1790cdf0e10cSrcweir if ( nVer ) 1791cdf0e10cSrcweir bRet = pImage->Save( rStrm, B_EXT_IMG_VERSION ); 1792cdf0e10cSrcweir else 1793cdf0e10cSrcweir bRet = pImage->Save( rStrm, B_LEGACYVERSION ); 1794cdf0e10cSrcweir if ( bFixup ) 1795cdf0e10cSrcweir fixUpMethodStart( false ); // restore method starts 1796cdf0e10cSrcweir 1797cdf0e10cSrcweir pImage->aOUSource = aOUSource; 1798cdf0e10cSrcweir } 1799cdf0e10cSrcweir } 1800cdf0e10cSrcweir return bRet; 1801cdf0e10cSrcweir } 1802cdf0e10cSrcweir 1803cdf0e10cSrcweir // Called for >= OO 1.0 passwd protected libraries only 1804cdf0e10cSrcweir // 1805cdf0e10cSrcweir 1806cdf0e10cSrcweir sal_Bool SbModule::LoadBinaryData( SvStream& rStrm ) 1807cdf0e10cSrcweir { 1808cdf0e10cSrcweir ::rtl::OUString aKeepSource = aOUSource; 1809cdf0e10cSrcweir bool bRet = LoadData( rStrm, 2 ); 1810cdf0e10cSrcweir LoadCompleted(); 1811cdf0e10cSrcweir aOUSource = aKeepSource; 1812cdf0e10cSrcweir return bRet; 1813cdf0e10cSrcweir } 1814cdf0e10cSrcweir 1815cdf0e10cSrcweir 1816cdf0e10cSrcweir sal_Bool SbModule::LoadCompleted() 1817cdf0e10cSrcweir { 1818cdf0e10cSrcweir SbxArray* p = GetMethods(); 1819cdf0e10cSrcweir sal_uInt16 i; 1820cdf0e10cSrcweir for( i = 0; i < p->Count(); i++ ) 1821cdf0e10cSrcweir { 1822cdf0e10cSrcweir SbMethod* q = PTR_CAST(SbMethod,p->Get( i ) ); 1823cdf0e10cSrcweir if( q ) 1824cdf0e10cSrcweir q->pMod = this; 1825cdf0e10cSrcweir } 1826cdf0e10cSrcweir p = GetProperties(); 1827cdf0e10cSrcweir for( i = 0; i < p->Count(); i++ ) 1828cdf0e10cSrcweir { 1829cdf0e10cSrcweir SbProperty* q = PTR_CAST(SbProperty,p->Get( i ) ); 1830cdf0e10cSrcweir if( q ) 1831cdf0e10cSrcweir q->pMod = this; 1832cdf0e10cSrcweir } 1833cdf0e10cSrcweir return sal_True; 1834cdf0e10cSrcweir } 1835cdf0e10cSrcweir 1836cdf0e10cSrcweir void SbModule::handleProcedureProperties( SfxBroadcaster& rBC, const SfxHint& rHint ) 1837cdf0e10cSrcweir { 1838cdf0e10cSrcweir bool bDone = false; 1839cdf0e10cSrcweir 1840cdf0e10cSrcweir const SbxHint* pHint = PTR_CAST(SbxHint,&rHint); 1841cdf0e10cSrcweir if( pHint ) 1842cdf0e10cSrcweir { 1843cdf0e10cSrcweir SbxVariable* pVar = pHint->GetVar(); 1844cdf0e10cSrcweir SbProcedureProperty* pProcProperty = PTR_CAST( SbProcedureProperty, pVar ); 1845cdf0e10cSrcweir if( pProcProperty ) 1846cdf0e10cSrcweir { 1847cdf0e10cSrcweir bDone = true; 1848cdf0e10cSrcweir 1849cdf0e10cSrcweir if( pHint->GetId() == SBX_HINT_DATAWANTED ) 1850cdf0e10cSrcweir { 1851cdf0e10cSrcweir String aProcName; 1852cdf0e10cSrcweir aProcName.AppendAscii( "Property Get " ); 1853cdf0e10cSrcweir aProcName += pProcProperty->GetName(); 1854cdf0e10cSrcweir 1855cdf0e10cSrcweir SbxVariable* pMeth = Find( aProcName, SbxCLASS_METHOD ); 1856cdf0e10cSrcweir if( pMeth ) 1857cdf0e10cSrcweir { 1858cdf0e10cSrcweir SbxValues aVals; 1859cdf0e10cSrcweir aVals.eType = SbxVARIANT; 1860cdf0e10cSrcweir 1861cdf0e10cSrcweir SbxArray* pArg = pVar->GetParameters(); 1862cdf0e10cSrcweir sal_uInt16 nVarParCount = (pArg != NULL) ? pArg->Count() : 0; 1863cdf0e10cSrcweir if( nVarParCount > 1 ) 1864cdf0e10cSrcweir { 1865cdf0e10cSrcweir SbxArrayRef xMethParameters = new SbxArray; 1866cdf0e10cSrcweir xMethParameters->Put( pMeth, 0 ); // Method as parameter 0 1867cdf0e10cSrcweir for( sal_uInt16 i = 1 ; i < nVarParCount ; ++i ) 1868cdf0e10cSrcweir { 1869cdf0e10cSrcweir SbxVariable* pPar = pArg->Get( i ); 1870cdf0e10cSrcweir xMethParameters->Put( pPar, i ); 1871cdf0e10cSrcweir } 1872cdf0e10cSrcweir 1873cdf0e10cSrcweir pMeth->SetParameters( xMethParameters ); 1874cdf0e10cSrcweir pMeth->Get( aVals ); 1875cdf0e10cSrcweir pMeth->SetParameters( NULL ); 1876cdf0e10cSrcweir } 1877cdf0e10cSrcweir else 1878cdf0e10cSrcweir { 1879cdf0e10cSrcweir pMeth->Get( aVals ); 1880cdf0e10cSrcweir } 1881cdf0e10cSrcweir 1882cdf0e10cSrcweir pVar->Put( aVals ); 1883cdf0e10cSrcweir } 1884cdf0e10cSrcweir } 1885cdf0e10cSrcweir else if( pHint->GetId() == SBX_HINT_DATACHANGED ) 1886cdf0e10cSrcweir { 1887cdf0e10cSrcweir SbxVariable* pMeth = NULL; 1888cdf0e10cSrcweir 1889cdf0e10cSrcweir bool bSet = pProcProperty->isSet(); 1890cdf0e10cSrcweir if( bSet ) 1891cdf0e10cSrcweir { 1892cdf0e10cSrcweir pProcProperty->setSet( false ); 1893cdf0e10cSrcweir 1894cdf0e10cSrcweir String aProcName; 1895cdf0e10cSrcweir aProcName.AppendAscii( "Property Set " ); 1896cdf0e10cSrcweir aProcName += pProcProperty->GetName(); 1897cdf0e10cSrcweir pMeth = Find( aProcName, SbxCLASS_METHOD ); 1898cdf0e10cSrcweir } 1899cdf0e10cSrcweir if( !pMeth ) // Let 1900cdf0e10cSrcweir { 1901cdf0e10cSrcweir String aProcName; 1902cdf0e10cSrcweir aProcName.AppendAscii( "Property Let " ); 1903cdf0e10cSrcweir aProcName += pProcProperty->GetName(); 1904cdf0e10cSrcweir pMeth = Find( aProcName, SbxCLASS_METHOD ); 1905cdf0e10cSrcweir } 1906cdf0e10cSrcweir 1907cdf0e10cSrcweir if( pMeth ) 1908cdf0e10cSrcweir { 1909cdf0e10cSrcweir // Setup parameters 1910cdf0e10cSrcweir SbxArrayRef xArray = new SbxArray; 1911cdf0e10cSrcweir xArray->Put( pMeth, 0 ); // Method as parameter 0 1912cdf0e10cSrcweir xArray->Put( pVar, 1 ); 1913cdf0e10cSrcweir pMeth->SetParameters( xArray ); 1914cdf0e10cSrcweir 1915cdf0e10cSrcweir SbxValues aVals; 1916cdf0e10cSrcweir pMeth->Get( aVals ); 1917cdf0e10cSrcweir pMeth->SetParameters( NULL ); 1918cdf0e10cSrcweir } 1919cdf0e10cSrcweir } 1920cdf0e10cSrcweir } 1921cdf0e10cSrcweir } 1922cdf0e10cSrcweir 1923cdf0e10cSrcweir if( !bDone ) 1924cdf0e10cSrcweir SbModule::Notify( rBC, rHint ); 1925cdf0e10cSrcweir } 1926cdf0e10cSrcweir 1927cdf0e10cSrcweir 1928cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////// 1929cdf0e10cSrcweir // Implementation SbJScriptModule (Basic-Modul fuer JavaScript-Sourcen) 1930cdf0e10cSrcweir SbJScriptModule::SbJScriptModule( const String& rName ) 1931cdf0e10cSrcweir :SbModule( rName ) 1932cdf0e10cSrcweir { 1933cdf0e10cSrcweir } 1934cdf0e10cSrcweir 1935cdf0e10cSrcweir sal_Bool SbJScriptModule::LoadData( SvStream& rStrm, sal_uInt16 nVer ) 1936cdf0e10cSrcweir { 1937cdf0e10cSrcweir (void)nVer; 1938cdf0e10cSrcweir 1939cdf0e10cSrcweir Clear(); 1940cdf0e10cSrcweir if( !SbxObject::LoadData( rStrm, 1 ) ) 1941cdf0e10cSrcweir return sal_False; 1942cdf0e10cSrcweir 1943cdf0e10cSrcweir // Source-String holen 1944cdf0e10cSrcweir String aTmp; 1945cdf0e10cSrcweir rStrm.ReadByteString( aTmp, gsl_getSystemTextEncoding() ); 1946cdf0e10cSrcweir aOUSource = aTmp; 1947cdf0e10cSrcweir //rStrm >> aSource; 1948cdf0e10cSrcweir return sal_True; 1949cdf0e10cSrcweir } 1950cdf0e10cSrcweir 1951cdf0e10cSrcweir sal_Bool SbJScriptModule::StoreData( SvStream& rStrm ) const 1952cdf0e10cSrcweir { 1953cdf0e10cSrcweir if( !SbxObject::StoreData( rStrm ) ) 1954cdf0e10cSrcweir return sal_False; 1955cdf0e10cSrcweir 1956cdf0e10cSrcweir // Source-String schreiben 1957cdf0e10cSrcweir String aTmp = aOUSource; 1958cdf0e10cSrcweir rStrm.WriteByteString( aTmp, gsl_getSystemTextEncoding() ); 1959cdf0e10cSrcweir //rStrm << aSource; 1960cdf0e10cSrcweir return sal_True; 1961cdf0e10cSrcweir } 1962cdf0e10cSrcweir 1963cdf0e10cSrcweir 1964cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////// 1965cdf0e10cSrcweir 1966cdf0e10cSrcweir SbMethod::SbMethod( const String& r, SbxDataType t, SbModule* p ) 1967cdf0e10cSrcweir : SbxMethod( r, t ), pMod( p ) 1968cdf0e10cSrcweir { 1969cdf0e10cSrcweir bInvalid = sal_True; 1970cdf0e10cSrcweir nStart = 1971cdf0e10cSrcweir nDebugFlags = 1972cdf0e10cSrcweir nLine1 = 1973cdf0e10cSrcweir nLine2 = 0; 1974cdf0e10cSrcweir refStatics = new SbxArray; 1975cdf0e10cSrcweir // AB: 2.7.1996: HACK wegen 'Referenz kann nicht gesichert werden' 1976cdf0e10cSrcweir SetFlag( SBX_NO_MODIFY ); 1977cdf0e10cSrcweir } 1978cdf0e10cSrcweir 1979cdf0e10cSrcweir SbMethod::SbMethod( const SbMethod& r ) 1980cdf0e10cSrcweir : SvRefBase( r ), SbxMethod( r ) 1981cdf0e10cSrcweir { 1982cdf0e10cSrcweir pMod = r.pMod; 1983cdf0e10cSrcweir bInvalid = r.bInvalid; 1984cdf0e10cSrcweir nStart = r.nStart; 1985cdf0e10cSrcweir nDebugFlags = r.nDebugFlags; 1986cdf0e10cSrcweir nLine1 = r.nLine1; 1987cdf0e10cSrcweir nLine2 = r.nLine2; 1988cdf0e10cSrcweir refStatics = r.refStatics; 1989cdf0e10cSrcweir SetFlag( SBX_NO_MODIFY ); 1990cdf0e10cSrcweir } 1991cdf0e10cSrcweir 1992cdf0e10cSrcweir SbMethod::~SbMethod() 1993cdf0e10cSrcweir { 1994cdf0e10cSrcweir } 1995cdf0e10cSrcweir 1996cdf0e10cSrcweir SbxArray* SbMethod::GetLocals() 1997cdf0e10cSrcweir { 1998cdf0e10cSrcweir if( pINST ) 1999cdf0e10cSrcweir return pINST->GetLocals( this ); 2000cdf0e10cSrcweir else 2001cdf0e10cSrcweir return NULL; 2002cdf0e10cSrcweir } 2003cdf0e10cSrcweir 2004cdf0e10cSrcweir void SbMethod::ClearStatics() 2005cdf0e10cSrcweir { 2006cdf0e10cSrcweir refStatics = new SbxArray; 2007cdf0e10cSrcweir 2008cdf0e10cSrcweir } 2009cdf0e10cSrcweir SbxArray* SbMethod::GetStatics() 2010cdf0e10cSrcweir { 2011cdf0e10cSrcweir return refStatics; 2012cdf0e10cSrcweir } 2013cdf0e10cSrcweir 2014cdf0e10cSrcweir sal_Bool SbMethod::LoadData( SvStream& rStrm, sal_uInt16 nVer ) 2015cdf0e10cSrcweir { 2016cdf0e10cSrcweir if( !SbxMethod::LoadData( rStrm, 1 ) ) 2017cdf0e10cSrcweir return sal_False; 2018cdf0e10cSrcweir sal_Int16 n; 2019cdf0e10cSrcweir rStrm >> n; 2020cdf0e10cSrcweir sal_Int16 nTempStart = (sal_Int16)nStart; 2021cdf0e10cSrcweir // nDebugFlags = n; // AB 16.1.96: Nicht mehr uebernehmen 2022cdf0e10cSrcweir if( nVer == 2 ) 2023cdf0e10cSrcweir rStrm >> nLine1 >> nLine2 >> nTempStart >> bInvalid; 2024cdf0e10cSrcweir // AB: 2.7.1996: HACK wegen 'Referenz kann nicht gesichert werden' 2025cdf0e10cSrcweir SetFlag( SBX_NO_MODIFY ); 2026cdf0e10cSrcweir nStart = nTempStart; 2027cdf0e10cSrcweir return sal_True; 2028cdf0e10cSrcweir } 2029cdf0e10cSrcweir 2030cdf0e10cSrcweir sal_Bool SbMethod::StoreData( SvStream& rStrm ) const 2031cdf0e10cSrcweir { 2032cdf0e10cSrcweir if( !SbxMethod::StoreData( rStrm ) ) 2033cdf0e10cSrcweir return sal_False; 2034cdf0e10cSrcweir rStrm << (sal_Int16) nDebugFlags 2035cdf0e10cSrcweir << (sal_Int16) nLine1 2036cdf0e10cSrcweir << (sal_Int16) nLine2 2037cdf0e10cSrcweir << (sal_Int16) nStart 2038cdf0e10cSrcweir << (sal_uInt8) bInvalid; 2039cdf0e10cSrcweir return sal_True; 2040cdf0e10cSrcweir } 2041cdf0e10cSrcweir 2042cdf0e10cSrcweir void SbMethod::GetLineRange( sal_uInt16& l1, sal_uInt16& l2 ) 2043cdf0e10cSrcweir { 2044cdf0e10cSrcweir l1 = nLine1; l2 = nLine2; 2045cdf0e10cSrcweir } 2046cdf0e10cSrcweir 2047cdf0e10cSrcweir // Kann spaeter mal weg 2048cdf0e10cSrcweir 2049cdf0e10cSrcweir SbxInfo* SbMethod::GetInfo() 2050cdf0e10cSrcweir { 2051cdf0e10cSrcweir return pInfo; 2052cdf0e10cSrcweir } 2053cdf0e10cSrcweir 2054cdf0e10cSrcweir // Schnittstelle zum Ausfuehren einer Methode aus den Applikationen 2055cdf0e10cSrcweir // #34191# Mit speziellem RefCounting, damit das Basic nicht durch CloseDocument() 2056cdf0e10cSrcweir // abgeschossen werden kann. Rueckgabewert wird als String geliefert. 2057cdf0e10cSrcweir ErrCode SbMethod::Call( SbxValue* pRet ) 2058cdf0e10cSrcweir { 2059cdf0e10cSrcweir // RefCount vom Modul hochzaehlen 2060cdf0e10cSrcweir SbModule* pMod_ = (SbModule*)GetParent(); 2061cdf0e10cSrcweir pMod_->AddRef(); 2062cdf0e10cSrcweir 2063cdf0e10cSrcweir // RefCount vom Basic hochzaehlen 2064cdf0e10cSrcweir StarBASIC* pBasic = (StarBASIC*)pMod_->GetParent(); 2065cdf0e10cSrcweir pBasic->AddRef(); 2066cdf0e10cSrcweir 2067cdf0e10cSrcweir // Values anlegen, um Return-Wert zu erhalten 2068cdf0e10cSrcweir SbxValues aVals; 2069cdf0e10cSrcweir aVals.eType = SbxVARIANT; 2070cdf0e10cSrcweir 2071cdf0e10cSrcweir // #104083: Compile BEFORE get 2072cdf0e10cSrcweir if( bInvalid && !pMod_->Compile() ) 2073cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_PROP_VALUE ); 2074cdf0e10cSrcweir 2075cdf0e10cSrcweir Get( aVals ); 2076cdf0e10cSrcweir if ( pRet ) 2077cdf0e10cSrcweir pRet->Put( aVals ); 2078cdf0e10cSrcweir 2079cdf0e10cSrcweir // Gab es einen Error 2080cdf0e10cSrcweir ErrCode nErr = SbxBase::GetError(); 2081cdf0e10cSrcweir SbxBase::ResetError(); 2082cdf0e10cSrcweir 2083cdf0e10cSrcweir // Objekte freigeben 2084cdf0e10cSrcweir pMod_->ReleaseRef(); 2085cdf0e10cSrcweir pBasic->ReleaseRef(); 2086cdf0e10cSrcweir 2087cdf0e10cSrcweir return nErr; 2088cdf0e10cSrcweir } 2089cdf0e10cSrcweir 2090cdf0e10cSrcweir 2091cdf0e10cSrcweir // #100883 Own Broadcast for SbMethod 2092cdf0e10cSrcweir void SbMethod::Broadcast( sal_uIntPtr nHintId ) 2093cdf0e10cSrcweir { 2094cdf0e10cSrcweir if( pCst && !IsSet( SBX_NO_BROADCAST ) && StaticIsEnabledBroadcasting() ) 2095cdf0e10cSrcweir { 2096cdf0e10cSrcweir // Da die Methode von aussen aufrufbar ist, hier noch einmal 2097cdf0e10cSrcweir // die Berechtigung testen 2098cdf0e10cSrcweir if( nHintId & SBX_HINT_DATAWANTED ) 2099cdf0e10cSrcweir if( !CanRead() ) 2100cdf0e10cSrcweir return; 2101cdf0e10cSrcweir if( nHintId & SBX_HINT_DATACHANGED ) 2102cdf0e10cSrcweir if( !CanWrite() ) 2103cdf0e10cSrcweir return; 2104cdf0e10cSrcweir 2105cdf0e10cSrcweir if( pMod && !pMod->IsCompiled() ) 2106cdf0e10cSrcweir pMod->Compile(); 2107cdf0e10cSrcweir 2108cdf0e10cSrcweir // Block broadcasts while creating new method 2109cdf0e10cSrcweir SfxBroadcaster* pSave = pCst; 2110cdf0e10cSrcweir pCst = NULL; 2111cdf0e10cSrcweir SbMethod* pThisCopy = new SbMethod( *this ); 2112cdf0e10cSrcweir SbMethodRef xHolder = pThisCopy; 2113cdf0e10cSrcweir if( mpPar.Is() ) 2114cdf0e10cSrcweir { 2115cdf0e10cSrcweir // this, als Element 0 eintragen, aber den Parent nicht umsetzen! 2116cdf0e10cSrcweir if( GetType() != SbxVOID ) 2117cdf0e10cSrcweir mpPar->PutDirect( pThisCopy, 0 ); 2118cdf0e10cSrcweir SetParameters( NULL ); 2119cdf0e10cSrcweir } 2120cdf0e10cSrcweir 2121cdf0e10cSrcweir pCst = pSave; 2122cdf0e10cSrcweir pSave->Broadcast( SbxHint( nHintId, pThisCopy ) ); 2123cdf0e10cSrcweir 2124cdf0e10cSrcweir sal_uInt16 nSaveFlags = GetFlags(); 2125cdf0e10cSrcweir SetFlag( SBX_READWRITE ); 2126cdf0e10cSrcweir pCst = NULL; 2127cdf0e10cSrcweir Put( pThisCopy->GetValues_Impl() ); 2128cdf0e10cSrcweir pCst = pSave; 2129cdf0e10cSrcweir SetFlags( nSaveFlags ); 2130cdf0e10cSrcweir } 2131cdf0e10cSrcweir } 2132cdf0e10cSrcweir 2133cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////// 2134cdf0e10cSrcweir 2135cdf0e10cSrcweir // Implementation SbJScriptMethod (Method-Klasse als Wrapper fuer JavaScript-Funktionen) 2136cdf0e10cSrcweir 2137cdf0e10cSrcweir SbJScriptMethod::SbJScriptMethod( const String& r, SbxDataType t, SbModule* p ) 2138cdf0e10cSrcweir : SbMethod( r, t, p ) 2139cdf0e10cSrcweir { 2140cdf0e10cSrcweir } 2141cdf0e10cSrcweir 2142cdf0e10cSrcweir SbJScriptMethod::~SbJScriptMethod() 2143cdf0e10cSrcweir {} 2144cdf0e10cSrcweir 2145cdf0e10cSrcweir 2146cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////// 2147cdf0e10cSrcweir SbObjModule::SbObjModule( const String& rName, const com::sun::star::script::ModuleInfo& mInfo, bool bIsVbaCompatible ) 2148cdf0e10cSrcweir : SbModule( rName, bIsVbaCompatible ) 2149cdf0e10cSrcweir { 2150cdf0e10cSrcweir SetModuleType( mInfo.ModuleType ); 2151cdf0e10cSrcweir if ( mInfo.ModuleType == script::ModuleType::FORM ) 2152cdf0e10cSrcweir { 2153cdf0e10cSrcweir SetClassName( rtl::OUString::createFromAscii( "Form" ) ); 2154cdf0e10cSrcweir } 2155cdf0e10cSrcweir else if ( mInfo.ModuleObject.is() ) 2156cdf0e10cSrcweir SetUnoObject( uno::makeAny( mInfo.ModuleObject ) ); 2157cdf0e10cSrcweir } 2158cdf0e10cSrcweir 2159cdf0e10cSrcweir SbObjModule::~SbObjModule() 2160cdf0e10cSrcweir { 2161cdf0e10cSrcweir } 2162cdf0e10cSrcweir 2163cdf0e10cSrcweir void 2164cdf0e10cSrcweir SbObjModule::SetUnoObject( const uno::Any& aObj ) throw ( uno::RuntimeException ) 2165cdf0e10cSrcweir { 2166cdf0e10cSrcweir SbUnoObject* pUnoObj = PTR_CAST(SbUnoObject,(SbxVariable*)pDocObject); 2167cdf0e10cSrcweir if ( pUnoObj && pUnoObj->getUnoAny() == aObj ) // object is equal, nothing to do 2168cdf0e10cSrcweir return; 2169cdf0e10cSrcweir pDocObject = new SbUnoObject( GetName(), uno::makeAny( aObj ) ); 2170cdf0e10cSrcweir 2171cdf0e10cSrcweir com::sun::star::uno::Reference< com::sun::star::lang::XServiceInfo > xServiceInfo( aObj, com::sun::star::uno::UNO_QUERY_THROW ); 2172cdf0e10cSrcweir if( xServiceInfo->supportsService( rtl::OUString::createFromAscii( "ooo.vba.excel.Worksheet" ) ) ) 2173cdf0e10cSrcweir { 2174cdf0e10cSrcweir SetClassName( rtl::OUString::createFromAscii( "Worksheet" ) ); 2175cdf0e10cSrcweir } 2176cdf0e10cSrcweir else if( xServiceInfo->supportsService( rtl::OUString::createFromAscii( "ooo.vba.excel.Workbook" ) ) ) 2177cdf0e10cSrcweir { 2178cdf0e10cSrcweir SetClassName( rtl::OUString::createFromAscii( "Workbook" ) ); 2179cdf0e10cSrcweir } 2180cdf0e10cSrcweir } 2181cdf0e10cSrcweir 2182cdf0e10cSrcweir SbxVariable* 2183cdf0e10cSrcweir SbObjModule::GetObject() 2184cdf0e10cSrcweir { 2185cdf0e10cSrcweir return pDocObject; 2186cdf0e10cSrcweir } 2187cdf0e10cSrcweir SbxVariable* 2188cdf0e10cSrcweir SbObjModule::Find( const XubString& rName, SbxClassType t ) 2189cdf0e10cSrcweir { 2190cdf0e10cSrcweir //OSL_TRACE("SbObjectModule find for %s", rtl::OUStringToOString( rName, RTL_TEXTENCODING_UTF8 ).getStr() ); 2191cdf0e10cSrcweir SbxVariable* pVar = NULL; 2192cdf0e10cSrcweir if ( pDocObject) 2193cdf0e10cSrcweir pVar = pDocObject->Find( rName, t ); 2194cdf0e10cSrcweir if ( !pVar ) 2195cdf0e10cSrcweir pVar = SbModule::Find( rName, t ); 2196cdf0e10cSrcweir return pVar; 2197cdf0e10cSrcweir } 2198cdf0e10cSrcweir 2199cdf0e10cSrcweir void SbObjModule::SFX_NOTIFY( SfxBroadcaster& rBC, const TypeId& rBCType, 2200cdf0e10cSrcweir const SfxHint& rHint, const TypeId& rHintType ) 2201cdf0e10cSrcweir { 2202cdf0e10cSrcweir SbModule::handleProcedureProperties( rBC, rHint ); 2203cdf0e10cSrcweir } 2204cdf0e10cSrcweir 2205cdf0e10cSrcweir 2206cdf0e10cSrcweir typedef ::cppu::WeakImplHelper3< 2207cdf0e10cSrcweir awt::XTopWindowListener, 2208cdf0e10cSrcweir awt::XWindowListener, 2209cdf0e10cSrcweir document::XEventListener > FormObjEventListener_BASE; 2210cdf0e10cSrcweir 2211cdf0e10cSrcweir class FormObjEventListenerImpl : public FormObjEventListener_BASE 2212cdf0e10cSrcweir { 2213cdf0e10cSrcweir SbUserFormModule* mpUserForm; 2214cdf0e10cSrcweir uno::Reference< lang::XComponent > mxComponent; 2215cdf0e10cSrcweir uno::Reference< frame::XModel > mxModel; 2216cdf0e10cSrcweir bool mbDisposed; 2217cdf0e10cSrcweir sal_Bool mbOpened; 2218cdf0e10cSrcweir sal_Bool mbActivated; 2219cdf0e10cSrcweir sal_Bool mbShowing; 2220cdf0e10cSrcweir 2221cdf0e10cSrcweir FormObjEventListenerImpl(const FormObjEventListenerImpl&); // not defined 2222cdf0e10cSrcweir FormObjEventListenerImpl& operator=(const FormObjEventListenerImpl&); // not defined 2223cdf0e10cSrcweir 2224cdf0e10cSrcweir public: 2225cdf0e10cSrcweir FormObjEventListenerImpl( SbUserFormModule* pUserForm, const uno::Reference< lang::XComponent >& xComponent, const uno::Reference< frame::XModel >& xModel ) : 2226cdf0e10cSrcweir mpUserForm( pUserForm ), mxComponent( xComponent), mxModel( xModel ), 2227cdf0e10cSrcweir mbDisposed( false ), mbOpened( sal_False ), mbActivated( sal_False ), mbShowing( sal_False ) 2228cdf0e10cSrcweir { 2229cdf0e10cSrcweir if ( mxComponent.is() ) 2230cdf0e10cSrcweir { 2231cdf0e10cSrcweir OSL_TRACE("*********** Registering the listeners"); 2232cdf0e10cSrcweir try 2233cdf0e10cSrcweir { 2234cdf0e10cSrcweir uno::Reference< awt::XTopWindow >( mxComponent, uno::UNO_QUERY_THROW )->addTopWindowListener( this ); 2235cdf0e10cSrcweir } 2236cdf0e10cSrcweir catch( uno::Exception& ) {} 2237cdf0e10cSrcweir try 2238cdf0e10cSrcweir { 2239cdf0e10cSrcweir uno::Reference< awt::XWindow >( mxComponent, uno::UNO_QUERY_THROW )->addWindowListener( this ); 2240cdf0e10cSrcweir } 2241cdf0e10cSrcweir catch( uno::Exception& ) {} 2242cdf0e10cSrcweir } 2243cdf0e10cSrcweir 2244cdf0e10cSrcweir if ( mxModel.is() ) 2245cdf0e10cSrcweir { 2246cdf0e10cSrcweir try 2247cdf0e10cSrcweir { 2248cdf0e10cSrcweir uno::Reference< document::XEventBroadcaster >( mxModel, uno::UNO_QUERY_THROW )->addEventListener( this ); 2249cdf0e10cSrcweir } 2250cdf0e10cSrcweir catch( uno::Exception& ) {} 2251cdf0e10cSrcweir } 2252cdf0e10cSrcweir } 2253cdf0e10cSrcweir 2254cdf0e10cSrcweir virtual ~FormObjEventListenerImpl() 2255cdf0e10cSrcweir { 2256cdf0e10cSrcweir removeListener(); 2257cdf0e10cSrcweir } 2258cdf0e10cSrcweir 2259cdf0e10cSrcweir sal_Bool isShowing() const { return mbShowing; } 2260cdf0e10cSrcweir 2261cdf0e10cSrcweir void removeListener() 2262cdf0e10cSrcweir { 2263cdf0e10cSrcweir if ( mxComponent.is() && !mbDisposed ) 2264cdf0e10cSrcweir { 2265cdf0e10cSrcweir OSL_TRACE("*********** Removing the listeners"); 2266cdf0e10cSrcweir try 2267cdf0e10cSrcweir { 2268cdf0e10cSrcweir uno::Reference< awt::XTopWindow >( mxComponent, uno::UNO_QUERY_THROW )->removeTopWindowListener( this ); 2269cdf0e10cSrcweir } 2270cdf0e10cSrcweir catch( uno::Exception& ) {} 2271cdf0e10cSrcweir try 2272cdf0e10cSrcweir { 2273cdf0e10cSrcweir uno::Reference< awt::XWindow >( mxComponent, uno::UNO_QUERY_THROW )->removeWindowListener( this ); 2274cdf0e10cSrcweir } 2275cdf0e10cSrcweir catch( uno::Exception& ) {} 2276cdf0e10cSrcweir } 2277cdf0e10cSrcweir mxComponent.clear(); 2278cdf0e10cSrcweir 2279cdf0e10cSrcweir if ( mxModel.is() && !mbDisposed ) 2280cdf0e10cSrcweir { 2281cdf0e10cSrcweir try 2282cdf0e10cSrcweir { 2283cdf0e10cSrcweir uno::Reference< document::XEventBroadcaster >( mxModel, uno::UNO_QUERY_THROW )->removeEventListener( this ); 2284cdf0e10cSrcweir } 2285cdf0e10cSrcweir catch( uno::Exception& ) {} 2286cdf0e10cSrcweir } 2287cdf0e10cSrcweir mxModel.clear(); 2288cdf0e10cSrcweir } 2289cdf0e10cSrcweir 2290cdf0e10cSrcweir virtual void SAL_CALL windowOpened( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException) 2291cdf0e10cSrcweir { 2292cdf0e10cSrcweir if ( mpUserForm ) 2293cdf0e10cSrcweir { 2294cdf0e10cSrcweir mbOpened = sal_True; 2295cdf0e10cSrcweir mbShowing = sal_True; 2296cdf0e10cSrcweir if ( mbActivated ) 2297cdf0e10cSrcweir { 2298cdf0e10cSrcweir mbOpened = mbActivated = sal_False; 2299cdf0e10cSrcweir mpUserForm->triggerActivateEvent(); 2300cdf0e10cSrcweir } 2301cdf0e10cSrcweir } 2302cdf0e10cSrcweir } 2303cdf0e10cSrcweir 2304cdf0e10cSrcweir //liuchen 2009-7-21, support Excel VBA Form_QueryClose event 2305cdf0e10cSrcweir virtual void SAL_CALL windowClosing( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException) 2306cdf0e10cSrcweir { 2307cdf0e10cSrcweir #if IN_THE_FUTURE 2308cdf0e10cSrcweir uno::Reference< awt::XDialog > xDialog( e.Source, uno::UNO_QUERY ); 2309cdf0e10cSrcweir if ( xDialog.is() ) 2310cdf0e10cSrcweir { 2311cdf0e10cSrcweir uno::Reference< awt::XControl > xControl( xDialog, uno::UNO_QUERY ); 2312cdf0e10cSrcweir if ( xControl->getPeer().is() ) 2313cdf0e10cSrcweir { 2314cdf0e10cSrcweir uno::Reference< document::XVbaMethodParameter > xVbaMethodParameter( xControl->getPeer(), uno::UNO_QUERY ); 2315cdf0e10cSrcweir if ( xVbaMethodParameter.is() ) 2316cdf0e10cSrcweir { 2317cdf0e10cSrcweir #endif 2318cdf0e10cSrcweir sal_Int8 nCancel = 0; 2319cdf0e10cSrcweir sal_Int8 nCloseMode = ::ooo::vba::VbQueryClose::vbFormControlMenu; 2320cdf0e10cSrcweir 2321cdf0e10cSrcweir Sequence< Any > aParams; 2322cdf0e10cSrcweir aParams.realloc(2); 2323cdf0e10cSrcweir aParams[0] <<= nCancel; 2324cdf0e10cSrcweir aParams[1] <<= nCloseMode; 2325cdf0e10cSrcweir 2326cdf0e10cSrcweir mpUserForm->triggerMethod( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Userform_QueryClose") ), 2327cdf0e10cSrcweir aParams); 2328cdf0e10cSrcweir #if IN_THE_FUTURE 2329cdf0e10cSrcweir xVbaMethodParameter->setVbaMethodParameter( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Cancel")), aParams[0]); 2330cdf0e10cSrcweir return; 2331cdf0e10cSrcweir 2332cdf0e10cSrcweir } 2333cdf0e10cSrcweir } 2334cdf0e10cSrcweir } 2335cdf0e10cSrcweir #endif 2336cdf0e10cSrcweir } 2337cdf0e10cSrcweir //liuchen 2009-7-21 2338cdf0e10cSrcweir 2339cdf0e10cSrcweir virtual void SAL_CALL windowClosed( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException) 2340cdf0e10cSrcweir { 2341cdf0e10cSrcweir mbOpened = sal_False; 2342cdf0e10cSrcweir mbShowing = sal_False; 2343cdf0e10cSrcweir } 2344cdf0e10cSrcweir 2345cdf0e10cSrcweir virtual void SAL_CALL windowMinimized( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException) 2346cdf0e10cSrcweir { 2347cdf0e10cSrcweir } 2348cdf0e10cSrcweir 2349cdf0e10cSrcweir virtual void SAL_CALL windowNormalized( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException) 2350cdf0e10cSrcweir { 2351cdf0e10cSrcweir } 2352cdf0e10cSrcweir 2353cdf0e10cSrcweir virtual void SAL_CALL windowActivated( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException) 2354cdf0e10cSrcweir { 2355cdf0e10cSrcweir if ( mpUserForm ) 2356cdf0e10cSrcweir { 2357cdf0e10cSrcweir mbActivated = sal_True; 2358cdf0e10cSrcweir if ( mbOpened ) 2359cdf0e10cSrcweir { 2360cdf0e10cSrcweir mbOpened = mbActivated = sal_False; 2361cdf0e10cSrcweir mpUserForm->triggerActivateEvent(); 2362cdf0e10cSrcweir } 2363cdf0e10cSrcweir } 2364cdf0e10cSrcweir } 2365cdf0e10cSrcweir 2366cdf0e10cSrcweir virtual void SAL_CALL windowDeactivated( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException) 2367cdf0e10cSrcweir { 2368cdf0e10cSrcweir if ( mpUserForm ) 2369cdf0e10cSrcweir mpUserForm->triggerDeactivateEvent(); 2370cdf0e10cSrcweir } 2371cdf0e10cSrcweir 2372cdf0e10cSrcweir virtual void SAL_CALL windowResized( const awt::WindowEvent& /*e*/ ) throw (uno::RuntimeException) 2373cdf0e10cSrcweir { 2374cdf0e10cSrcweir if ( mpUserForm ) 2375cdf0e10cSrcweir { 2376cdf0e10cSrcweir mpUserForm->triggerResizeEvent(); 2377cdf0e10cSrcweir mpUserForm->triggerLayoutEvent(); 2378cdf0e10cSrcweir } 2379cdf0e10cSrcweir } 2380cdf0e10cSrcweir 2381cdf0e10cSrcweir virtual void SAL_CALL windowMoved( const awt::WindowEvent& /*e*/ ) throw (uno::RuntimeException) 2382cdf0e10cSrcweir { 2383cdf0e10cSrcweir if ( mpUserForm ) 2384cdf0e10cSrcweir mpUserForm->triggerLayoutEvent(); 2385cdf0e10cSrcweir } 2386cdf0e10cSrcweir 2387cdf0e10cSrcweir virtual void SAL_CALL windowShown( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException) 2388cdf0e10cSrcweir { 2389cdf0e10cSrcweir } 2390cdf0e10cSrcweir 2391cdf0e10cSrcweir virtual void SAL_CALL windowHidden( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException) 2392cdf0e10cSrcweir { 2393cdf0e10cSrcweir } 2394cdf0e10cSrcweir 2395cdf0e10cSrcweir virtual void SAL_CALL notifyEvent( const document::EventObject& rEvent ) throw (uno::RuntimeException) 2396cdf0e10cSrcweir { 2397cdf0e10cSrcweir // early dosposing on document event "OnUnload", to be sure Basic still exists when calling VBA "UserForm_Terminate" 2398cdf0e10cSrcweir if( rEvent.EventName == GlobalEventConfig::GetEventName( STR_EVENT_CLOSEDOC ) ) 2399cdf0e10cSrcweir { 2400cdf0e10cSrcweir removeListener(); 2401cdf0e10cSrcweir mbDisposed = true; 2402cdf0e10cSrcweir if ( mpUserForm ) 2403cdf0e10cSrcweir mpUserForm->ResetApiObj(); // will trigger "UserForm_Terminate" 2404cdf0e10cSrcweir } 2405cdf0e10cSrcweir } 2406cdf0e10cSrcweir 2407cdf0e10cSrcweir virtual void SAL_CALL disposing( const lang::EventObject& /*Source*/ ) throw (uno::RuntimeException) 2408cdf0e10cSrcweir { 2409cdf0e10cSrcweir OSL_TRACE("** Userform/Dialog disposing"); 2410cdf0e10cSrcweir removeListener(); 2411cdf0e10cSrcweir mbDisposed = true; 2412cdf0e10cSrcweir if ( mpUserForm ) 2413cdf0e10cSrcweir mpUserForm->ResetApiObj( false ); // pass false (too late to trigger VBA events here) 2414cdf0e10cSrcweir } 2415cdf0e10cSrcweir }; 2416cdf0e10cSrcweir 2417cdf0e10cSrcweir SbUserFormModule::SbUserFormModule( const String& rName, const com::sun::star::script::ModuleInfo& mInfo, bool bIsCompat ) 2418cdf0e10cSrcweir : SbObjModule( rName, mInfo, bIsCompat ) 2419cdf0e10cSrcweir , m_mInfo( mInfo ) 2420cdf0e10cSrcweir , mbInit( false ) 2421cdf0e10cSrcweir { 2422cdf0e10cSrcweir m_xModel.set( mInfo.ModuleObject, uno::UNO_QUERY_THROW ); 2423cdf0e10cSrcweir } 2424cdf0e10cSrcweir 2425cdf0e10cSrcweir SbUserFormModule::~SbUserFormModule() 2426cdf0e10cSrcweir { 2427cdf0e10cSrcweir } 2428cdf0e10cSrcweir 2429cdf0e10cSrcweir void SbUserFormModule::ResetApiObj( bool bTriggerTerminateEvent ) 2430cdf0e10cSrcweir { 2431cdf0e10cSrcweir if ( bTriggerTerminateEvent && m_xDialog.is() ) // probably someone close the dialog window 2432cdf0e10cSrcweir { 2433cdf0e10cSrcweir triggerTerminateEvent(); 2434cdf0e10cSrcweir } 2435cdf0e10cSrcweir pDocObject = NULL; 2436cdf0e10cSrcweir m_xDialog = NULL; 2437cdf0e10cSrcweir } 2438cdf0e10cSrcweir 2439cdf0e10cSrcweir void SbUserFormModule::triggerMethod( const String& aMethodToRun ) 2440cdf0e10cSrcweir { 2441cdf0e10cSrcweir Sequence< Any > aArguments; 2442cdf0e10cSrcweir triggerMethod( aMethodToRun, aArguments ); 2443cdf0e10cSrcweir } 2444cdf0e10cSrcweir 2445cdf0e10cSrcweir void SbUserFormModule::triggerMethod( const String& aMethodToRun, Sequence< Any >& aArguments ) 2446cdf0e10cSrcweir { 2447cdf0e10cSrcweir OSL_TRACE("*** trigger %s ***", rtl::OUStringToOString( aMethodToRun, RTL_TEXTENCODING_UTF8 ).getStr() ); 2448cdf0e10cSrcweir // Search method 2449cdf0e10cSrcweir SbxVariable* pMeth = SbObjModule::Find( aMethodToRun, SbxCLASS_METHOD ); 2450cdf0e10cSrcweir if( pMeth ) 2451cdf0e10cSrcweir { 2452cdf0e10cSrcweir if ( aArguments.getLength() > 0 ) // Setup parameters 2453cdf0e10cSrcweir { 2454cdf0e10cSrcweir SbxArrayRef xArray = new SbxArray; 2455cdf0e10cSrcweir xArray->Put( pMeth, 0 ); // Method as parameter 0 2456cdf0e10cSrcweir 2457cdf0e10cSrcweir for ( sal_Int32 i = 0; i < aArguments.getLength(); ++i ) 2458cdf0e10cSrcweir { 2459cdf0e10cSrcweir SbxVariableRef xSbxVar = new SbxVariable( SbxVARIANT ); 2460cdf0e10cSrcweir unoToSbxValue( static_cast< SbxVariable* >( xSbxVar ), aArguments[i] ); 2461cdf0e10cSrcweir xArray->Put( xSbxVar, static_cast< sal_uInt16 >( i ) + 1 ); 2462cdf0e10cSrcweir 2463cdf0e10cSrcweir // Enable passing by ref 2464cdf0e10cSrcweir if ( xSbxVar->GetType() != SbxVARIANT ) 2465cdf0e10cSrcweir xSbxVar->SetFlag( SBX_FIXED ); 2466cdf0e10cSrcweir } 2467cdf0e10cSrcweir pMeth->SetParameters( xArray ); 2468cdf0e10cSrcweir 2469cdf0e10cSrcweir SbxValues aVals; 2470cdf0e10cSrcweir pMeth->Get( aVals ); 2471cdf0e10cSrcweir 2472cdf0e10cSrcweir for ( sal_Int32 i = 0; i < aArguments.getLength(); ++i ) 2473cdf0e10cSrcweir { 2474cdf0e10cSrcweir aArguments[i] = sbxToUnoValue( xArray->Get( static_cast< sal_uInt16 >(i) + 1) ); 2475cdf0e10cSrcweir } 2476cdf0e10cSrcweir pMeth->SetParameters( NULL ); 2477cdf0e10cSrcweir } 2478cdf0e10cSrcweir else 2479cdf0e10cSrcweir { 2480cdf0e10cSrcweir SbxValues aVals; 2481cdf0e10cSrcweir pMeth->Get( aVals ); 2482cdf0e10cSrcweir } 2483cdf0e10cSrcweir } 2484cdf0e10cSrcweir } 2485cdf0e10cSrcweir 2486cdf0e10cSrcweir void SbUserFormModule::triggerActivateEvent( void ) 2487cdf0e10cSrcweir { 2488cdf0e10cSrcweir OSL_TRACE("**** entering SbUserFormModule::triggerActivate"); 2489cdf0e10cSrcweir triggerMethod( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("UserForm_Activate") ) ); 2490cdf0e10cSrcweir OSL_TRACE("**** leaving SbUserFormModule::triggerActivate"); 2491cdf0e10cSrcweir } 2492cdf0e10cSrcweir 2493cdf0e10cSrcweir void SbUserFormModule::triggerDeactivateEvent( void ) 2494cdf0e10cSrcweir { 2495cdf0e10cSrcweir OSL_TRACE("**** SbUserFormModule::triggerDeactivate"); 2496cdf0e10cSrcweir triggerMethod( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Userform_Deactivate") ) ); 2497cdf0e10cSrcweir } 2498cdf0e10cSrcweir 2499cdf0e10cSrcweir void SbUserFormModule::triggerInitializeEvent( void ) 2500cdf0e10cSrcweir { 2501cdf0e10cSrcweir if ( mbInit ) 2502cdf0e10cSrcweir return; 2503cdf0e10cSrcweir OSL_TRACE("**** SbUserFormModule::triggerInitializeEvent"); 2504cdf0e10cSrcweir static String aInitMethodName( RTL_CONSTASCII_USTRINGPARAM("Userform_Initialize") ); 2505cdf0e10cSrcweir triggerMethod( aInitMethodName ); 2506cdf0e10cSrcweir mbInit = true; 2507cdf0e10cSrcweir } 2508cdf0e10cSrcweir 2509cdf0e10cSrcweir void SbUserFormModule::triggerTerminateEvent( void ) 2510cdf0e10cSrcweir { 2511cdf0e10cSrcweir OSL_TRACE("**** SbUserFormModule::triggerTerminateEvent"); 2512cdf0e10cSrcweir static String aTermMethodName( RTL_CONSTASCII_USTRINGPARAM("Userform_Terminate") ); 2513cdf0e10cSrcweir triggerMethod( aTermMethodName ); 2514cdf0e10cSrcweir mbInit=false; 2515cdf0e10cSrcweir } 2516cdf0e10cSrcweir 2517cdf0e10cSrcweir void SbUserFormModule::triggerLayoutEvent( void ) 2518cdf0e10cSrcweir { 2519cdf0e10cSrcweir static String aMethodName( RTL_CONSTASCII_USTRINGPARAM("Userform_Layout") ); 2520cdf0e10cSrcweir triggerMethod( aMethodName ); 2521cdf0e10cSrcweir } 2522cdf0e10cSrcweir 2523cdf0e10cSrcweir void SbUserFormModule::triggerResizeEvent( void ) 2524cdf0e10cSrcweir { 2525cdf0e10cSrcweir static String aMethodName( RTL_CONSTASCII_USTRINGPARAM("Userform_Resize") ); 2526cdf0e10cSrcweir triggerMethod( aMethodName ); 2527cdf0e10cSrcweir } 2528cdf0e10cSrcweir 2529cdf0e10cSrcweir SbUserFormModuleInstance* SbUserFormModule::CreateInstance() 2530cdf0e10cSrcweir { 2531cdf0e10cSrcweir SbUserFormModuleInstance* pInstance = new SbUserFormModuleInstance( this, GetName(), m_mInfo, IsVBACompat() ); 2532cdf0e10cSrcweir return pInstance; 2533cdf0e10cSrcweir } 2534cdf0e10cSrcweir 2535cdf0e10cSrcweir SbUserFormModuleInstance::SbUserFormModuleInstance( SbUserFormModule* pParentModule, 2536cdf0e10cSrcweir const String& rName, const com::sun::star::script::ModuleInfo& mInfo, bool bIsVBACompat ) 2537cdf0e10cSrcweir : SbUserFormModule( rName, mInfo, bIsVBACompat ) 2538cdf0e10cSrcweir , m_pParentModule( pParentModule ) 2539cdf0e10cSrcweir { 2540cdf0e10cSrcweir } 2541cdf0e10cSrcweir 2542cdf0e10cSrcweir sal_Bool SbUserFormModuleInstance::IsClass( const XubString& rName ) const 2543cdf0e10cSrcweir { 2544cdf0e10cSrcweir sal_Bool bParentNameMatches = m_pParentModule->GetName().EqualsIgnoreCaseAscii( rName ); 2545cdf0e10cSrcweir sal_Bool bRet = bParentNameMatches || SbxObject::IsClass( rName ); 2546cdf0e10cSrcweir return bRet; 2547cdf0e10cSrcweir } 2548cdf0e10cSrcweir 2549cdf0e10cSrcweir SbxVariable* SbUserFormModuleInstance::Find( const XubString& rName, SbxClassType t ) 2550cdf0e10cSrcweir { 2551cdf0e10cSrcweir SbxVariable* pVar = m_pParentModule->Find( rName, t ); 2552cdf0e10cSrcweir return pVar; 2553cdf0e10cSrcweir } 2554cdf0e10cSrcweir 2555cdf0e10cSrcweir 2556cdf0e10cSrcweir void SbUserFormModule::Load() 2557cdf0e10cSrcweir { 2558cdf0e10cSrcweir OSL_TRACE("** load() "); 2559cdf0e10cSrcweir // forces a load 2560cdf0e10cSrcweir if ( !pDocObject ) 2561cdf0e10cSrcweir InitObject(); 2562cdf0e10cSrcweir } 2563cdf0e10cSrcweir 2564cdf0e10cSrcweir //liuchen 2009-7-21 change to accmordate VBA's beheavior 2565cdf0e10cSrcweir void SbUserFormModule::Unload() 2566cdf0e10cSrcweir { 2567cdf0e10cSrcweir OSL_TRACE("** Unload() "); 2568cdf0e10cSrcweir 2569cdf0e10cSrcweir sal_Int8 nCancel = 0; 2570cdf0e10cSrcweir sal_Int8 nCloseMode = ::ooo::vba::VbQueryClose::vbFormCode; 2571cdf0e10cSrcweir 2572cdf0e10cSrcweir Sequence< Any > aParams; 2573cdf0e10cSrcweir aParams.realloc(2); 2574cdf0e10cSrcweir aParams[0] <<= nCancel; 2575cdf0e10cSrcweir aParams[1] <<= nCloseMode; 2576cdf0e10cSrcweir 2577cdf0e10cSrcweir triggerMethod( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Userform_QueryClose") ), aParams); 2578cdf0e10cSrcweir 2579cdf0e10cSrcweir aParams[0] >>= nCancel; 2580cdf0e10cSrcweir if (nCancel != 0) // Basic returns -1 for "True" 2581cdf0e10cSrcweir { 2582cdf0e10cSrcweir return; 2583cdf0e10cSrcweir } 2584cdf0e10cSrcweir 2585cdf0e10cSrcweir if ( m_xDialog.is() ) 2586cdf0e10cSrcweir { 2587cdf0e10cSrcweir triggerTerminateEvent(); 2588cdf0e10cSrcweir } 2589cdf0e10cSrcweir // Search method 2590cdf0e10cSrcweir SbxVariable* pMeth = SbObjModule::Find( String( RTL_CONSTASCII_USTRINGPARAM( "UnloadObject" ) ), SbxCLASS_METHOD ); 2591cdf0e10cSrcweir if( pMeth ) 2592cdf0e10cSrcweir { 2593cdf0e10cSrcweir OSL_TRACE("Attempting too run the UnloadObjectMethod"); 2594cdf0e10cSrcweir m_xDialog.clear(); //release ref to the uno object 2595cdf0e10cSrcweir SbxValues aVals; 2596cdf0e10cSrcweir bool bWaitForDispose = true; // assume dialog is showing 2597cdf0e10cSrcweir if ( m_DialogListener.get() ) 2598cdf0e10cSrcweir { 2599cdf0e10cSrcweir bWaitForDispose = m_DialogListener->isShowing(); 2600cdf0e10cSrcweir OSL_TRACE("Showing %d", bWaitForDispose ); 2601cdf0e10cSrcweir } 2602cdf0e10cSrcweir pMeth->Get( aVals); 2603cdf0e10cSrcweir if ( !bWaitForDispose ) 2604cdf0e10cSrcweir { 2605cdf0e10cSrcweir // we've either already got a dispose or we'er never going to get one 2606cdf0e10cSrcweir ResetApiObj(); 2607cdf0e10cSrcweir } // else wait for dispose 2608cdf0e10cSrcweir OSL_TRACE("UnloadObject completed ( we hope )"); 2609cdf0e10cSrcweir } 2610cdf0e10cSrcweir } 2611cdf0e10cSrcweir //liuchen 2612cdf0e10cSrcweir 2613cdf0e10cSrcweir void registerComponentToBeDisposedForBasic( Reference< XComponent > xComponent, StarBASIC* pBasic ); 2614cdf0e10cSrcweir 2615cdf0e10cSrcweir void SbUserFormModule::InitObject() 2616cdf0e10cSrcweir { 2617cdf0e10cSrcweir try 2618cdf0e10cSrcweir { 2619cdf0e10cSrcweir String aHook( RTL_CONSTASCII_USTRINGPARAM( "VBAGlobals" ) ); 2620cdf0e10cSrcweir SbUnoObject* pGlobs = (SbUnoObject*)GetParent()->Find( aHook, SbxCLASS_DONTCARE ); 2621cdf0e10cSrcweir if ( m_xModel.is() && pGlobs ) 2622cdf0e10cSrcweir { 2623cdf0e10cSrcweir // broadcast INITIALIZE_USERFORM script event before the dialog is created 2624cdf0e10cSrcweir Reference< script::vba::XVBACompatibility > xVBACompat( getVBACompatibility( m_xModel ), uno::UNO_SET_THROW ); 2625cdf0e10cSrcweir xVBACompat->broadcastVBAScriptEvent( script::vba::VBAScriptEventId::INITIALIZE_USERFORM, GetName() ); 2626cdf0e10cSrcweir 2627cdf0e10cSrcweir uno::Reference< lang::XMultiServiceFactory > xVBAFactory( pGlobs->getUnoAny(), uno::UNO_QUERY_THROW ); 2628cdf0e10cSrcweir uno::Reference< lang::XMultiServiceFactory > xFactory = comphelper::getProcessServiceFactory(); 2629cdf0e10cSrcweir uno::Sequence< uno::Any > aArgs(1); 2630cdf0e10cSrcweir aArgs[ 0 ] <<= m_xModel; 2631cdf0e10cSrcweir rtl::OUString sDialogUrl( RTL_CONSTASCII_USTRINGPARAM("vnd.sun.star.script:" ) ); 2632cdf0e10cSrcweir rtl::OUString sProjectName( RTL_CONSTASCII_USTRINGPARAM("Standard") ); 2633cdf0e10cSrcweir if ( this->GetParent()->GetName().Len() ) 2634cdf0e10cSrcweir sProjectName = this->GetParent()->GetName(); 2635cdf0e10cSrcweir sDialogUrl = sDialogUrl.concat( sProjectName ).concat( rtl::OUString( '.') ).concat( GetName() ).concat( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("?location=document") ) ); 2636cdf0e10cSrcweir 2637cdf0e10cSrcweir uno::Reference< awt::XDialogProvider > xProvider( xFactory->createInstanceWithArguments( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.DialogProvider")), aArgs ), uno::UNO_QUERY_THROW ); 2638cdf0e10cSrcweir m_xDialog = xProvider->createDialog( sDialogUrl ); 2639cdf0e10cSrcweir 2640cdf0e10cSrcweir // create vba api object 2641cdf0e10cSrcweir aArgs.realloc( 4 ); 2642cdf0e10cSrcweir aArgs[ 0 ] = uno::Any(); 2643cdf0e10cSrcweir aArgs[ 1 ] <<= m_xDialog; 2644cdf0e10cSrcweir aArgs[ 2 ] <<= m_xModel; 2645cdf0e10cSrcweir aArgs[ 3 ] <<= rtl::OUString( GetParent()->GetName() ); 2646cdf0e10cSrcweir pDocObject = new SbUnoObject( GetName(), uno::makeAny( xVBAFactory->createInstanceWithArguments( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.msforms.UserForm")), aArgs ) ) ); 2647cdf0e10cSrcweir 2648cdf0e10cSrcweir uno::Reference< lang::XComponent > xComponent( m_xDialog, uno::UNO_QUERY_THROW ); 2649cdf0e10cSrcweir 2650cdf0e10cSrcweir // the dialog must be disposed at the end! 2651cdf0e10cSrcweir StarBASIC* pParentBasic = NULL; 2652cdf0e10cSrcweir SbxObject* pCurObject = this; 2653cdf0e10cSrcweir do 2654cdf0e10cSrcweir { 2655cdf0e10cSrcweir SbxObject* pObjParent = pCurObject->GetParent(); 2656cdf0e10cSrcweir pParentBasic = PTR_CAST( StarBASIC, pObjParent ); 2657cdf0e10cSrcweir pCurObject = pObjParent; 2658cdf0e10cSrcweir } 2659cdf0e10cSrcweir while( pParentBasic == NULL && pCurObject != NULL ); 2660cdf0e10cSrcweir 2661cdf0e10cSrcweir OSL_ASSERT( pParentBasic != NULL ); 2662cdf0e10cSrcweir registerComponentToBeDisposedForBasic( xComponent, pParentBasic ); 2663cdf0e10cSrcweir 2664cdf0e10cSrcweir // if old listener object exists, remove it from dialog and document model 2665cdf0e10cSrcweir if( m_DialogListener.is() ) 2666cdf0e10cSrcweir m_DialogListener->removeListener(); 2667cdf0e10cSrcweir m_DialogListener.set( new FormObjEventListenerImpl( this, xComponent, m_xModel ) ); 2668cdf0e10cSrcweir 2669cdf0e10cSrcweir triggerInitializeEvent(); 2670cdf0e10cSrcweir } 2671cdf0e10cSrcweir } 2672cdf0e10cSrcweir catch( uno::Exception& ) 2673cdf0e10cSrcweir { 2674cdf0e10cSrcweir } 2675cdf0e10cSrcweir 2676cdf0e10cSrcweir } 2677cdf0e10cSrcweir 2678cdf0e10cSrcweir SbxVariable* 2679cdf0e10cSrcweir SbUserFormModule::Find( const XubString& rName, SbxClassType t ) 2680cdf0e10cSrcweir { 2681cdf0e10cSrcweir if ( !pDocObject && !GetSbData()->bRunInit && pINST ) 2682cdf0e10cSrcweir InitObject(); 2683cdf0e10cSrcweir return SbObjModule::Find( rName, t ); 2684cdf0e10cSrcweir } 2685cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////// 2686cdf0e10cSrcweir 2687cdf0e10cSrcweir SbProperty::SbProperty( const String& r, SbxDataType t, SbModule* p ) 2688cdf0e10cSrcweir : SbxProperty( r, t ), pMod( p ) 2689cdf0e10cSrcweir { 2690cdf0e10cSrcweir bInvalid = sal_False; 2691cdf0e10cSrcweir } 2692cdf0e10cSrcweir 2693cdf0e10cSrcweir SbProperty::~SbProperty() 2694cdf0e10cSrcweir {} 2695cdf0e10cSrcweir 2696cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////// 2697cdf0e10cSrcweir 2698cdf0e10cSrcweir SbProcedureProperty::~SbProcedureProperty() 2699cdf0e10cSrcweir {} 2700cdf0e10cSrcweir 2701