diff options
57 files changed, 1763 insertions, 280 deletions
diff --git a/basic/inc/basic/sbmod.hxx b/basic/inc/basic/sbmod.hxx index cf888adf9dcf..bccf8212f10e 100644 --- a/basic/inc/basic/sbmod.hxx +++ b/basic/inc/basic/sbmod.hxx @@ -28,10 +28,12 @@ #ifndef _SB_SBMOD_HXX #define _SB_SBMOD_HXX +#include <com/sun/star/script/XInvocation.hpp> #include <basic/sbdef.hxx> #include <basic/sbxobj.hxx> #include <basic/sbxdef.hxx> #include <rtl/ustring.hxx> +#include <vector> class SbMethod; class SbProperty; @@ -55,8 +57,10 @@ class SbModule : public SbxObject friend class SbClassModuleObject; SbModuleImpl* mpSbModuleImpl; // Impl data + std::vector< String > mModuleVariableNames; protected: + com::sun::star::uno::Reference< com::sun::star::script::XInvocation > mxWrapper; ::rtl::OUString aOUSource; String aComment; SbiImage* pImage; // the Image @@ -131,6 +135,9 @@ public: INT32 GetModuleType() { return mnType; } void SetModuleType( INT32 nType ) { mnType = nType; } bool GetIsProxyModule() { return bIsProxyModule; } + void AddVarName( const String& aName ); + void RemoveVars(); + ::com::sun::star::uno::Reference< ::com::sun::star::script::XInvocation > GetUnoModule(); bool createCOMWrapperForIface( ::com::sun::star::uno::Any& o_rRetAny, SbClassModuleObject* pProxyClassModuleObject ); }; diff --git a/basic/inc/basic/sbobjmod.hxx b/basic/inc/basic/sbobjmod.hxx index 3d638a475f9a..9ff46d1931f3 100644 --- a/basic/inc/basic/sbobjmod.hxx +++ b/basic/inc/basic/sbobjmod.hxx @@ -36,6 +36,7 @@ #ifndef _SB_OBJMOD_HXX #define _SB_OBJMOD_HXX +#include <rtl/ref.hxx> #include <basic/sbmod.hxx> #include <basic/sbstar.hxx> #include <com/sun/star/script/ModuleInfo.hpp> @@ -60,10 +61,12 @@ public: void SetUnoObject( const com::sun::star::uno::Any& aObj )throw ( com::sun::star::uno::RuntimeException ) ; }; +class FormObjEventListenerImpl; + class SbUserFormModule : public SbObjModule { com::sun::star::script::ModuleInfo m_mInfo; - css::uno::Reference<css::lang::XEventListener> m_DialogListener; + ::rtl::Reference< FormObjEventListenerImpl > m_DialogListener; css::uno::Reference<css::awt::XDialog> m_xDialog; css::uno::Reference<css::frame::XModel> m_xModel; String sFormName; @@ -76,16 +79,19 @@ class SbUserFormModule : public SbObjModule public: TYPEINFO(); SbUserFormModule( const String& rName, const com::sun::star::script::ModuleInfo& mInfo, bool bIsVBACompat ); + virtual ~SbUserFormModule(); virtual SbxVariable* Find( const XubString& rName, SbxClassType t ); void ResetApiObj(); void Unload(); - void load(); + void Load(); void triggerMethod( const String& ); void triggerMethod( const String&, css::uno::Sequence< css::uno::Any >& ); void triggerActivateEvent(); - void triggerDeActivateEvent(); + void triggerDeactivateEvent(); void triggerInitializeEvent(); void triggerTerminateEvent(); + void triggerLayoutEvent(); + void triggerResizeEvent(); class SbUserFormModuleInstance* CreateInstance(); }; diff --git a/basic/source/basmgr/basmgr.cxx b/basic/source/basmgr/basmgr.cxx index b76a2b5e249e..84763468e64c 100644 --- a/basic/source/basmgr/basmgr.cxx +++ b/basic/source/basmgr/basmgr.cxx @@ -67,8 +67,8 @@ #include <com/sun/star/script/XStarBasicLibraryInfo.hpp> #include <com/sun/star/script/XLibraryContainerPassword.hpp> #include <com/sun/star/script/ModuleInfo.hpp> -#include <com/sun/star/script/XVBAModuleInfo.hpp> -#include <com/sun/star/script/XVBACompat.hpp> +#include <com/sun/star/script/vba/XVBACompatibility.hpp> +#include <com/sun/star/script/vba/XVBAModuleInfo.hpp> #include <cppuhelper/implbase1.hxx> @@ -240,7 +240,7 @@ void BasMgrContainerListenerImpl::addLibraryModulesImpl( BasicManager* pMgr, Any aElement = xLibNameAccess->getByName( aModuleName ); ::rtl::OUString aMod; aElement >>= aMod; - Reference< XVBAModuleInfo > xVBAModuleInfo( xLibNameAccess, UNO_QUERY ); + Reference< vba::XVBAModuleInfo > xVBAModuleInfo( xLibNameAccess, UNO_QUERY ); if ( xVBAModuleInfo.is() && xVBAModuleInfo->hasModuleInfo( aModuleName ) ) { ModuleInfo mInfo = xVBAModuleInfo->getModuleInfo( aModuleName ); @@ -285,9 +285,9 @@ void SAL_CALL BasMgrContainerListenerImpl::elementInserted( const ContainerEvent StarBASIC* pLib = mpMgr->GetLib( aName ); if ( pLib ) { - Reference<XVBACompat> xVBACompat( xScriptCont, UNO_QUERY ); + Reference< vba::XVBACompatibility > xVBACompat( xScriptCont, UNO_QUERY ); if ( xVBACompat.is() ) - pLib->SetVBAEnabled( xVBACompat->getVBACompatModeOn() ); + pLib->SetVBAEnabled( xVBACompat->getVBACompatibilityMode() ); } } else @@ -302,7 +302,7 @@ void SAL_CALL BasMgrContainerListenerImpl::elementInserted( const ContainerEvent { ::rtl::OUString aMod; Event.Element >>= aMod; - Reference< XVBAModuleInfo > xVBAModuleInfo( Event.Source, UNO_QUERY ); + Reference< vba::XVBAModuleInfo > xVBAModuleInfo( Event.Source, UNO_QUERY ); if ( xVBAModuleInfo.is() && xVBAModuleInfo->hasModuleInfo( aName ) ) { ModuleInfo mInfo = xVBAModuleInfo->getModuleInfo( aName ); diff --git a/basic/source/classes/disas.cxx b/basic/source/classes/disas.cxx index 7317005d74fe..a837a3dc4f24 100644 --- a/basic/source/classes/disas.cxx +++ b/basic/source/classes/disas.cxx @@ -35,6 +35,7 @@ #include "sb.hxx" #include "iosys.hxx" #include "disas.hxx" +#include "sbtrace.hxx" static const char* pOp1[] = { @@ -153,6 +154,7 @@ static const char* pOp3[] = { "DCREATE_REDIMP", // Change dimensions of a user defined Object-Array (+StringId+StringId) "FIND_CM", // Search inside a class module (CM) to enable global search in time "PUBLIC_P", // Module global Variable (persisted between calls)(+StringID+Typ) + "FIND_STATIC", // local static var lookup (+StringID+Typ) }; static const char** pOps[3] = { pOp1, pOp2, pOp3 }; @@ -220,6 +222,7 @@ static const Func pOperand3[] = { &SbiDisas::Str2Op, // Redimensionate User defined Object-Array (+StringId+StringId) &SbiDisas::VarOp, // FIND_CM &SbiDisas::VarDefOp, // PUBLIC_P + &SbiDisas::VarOp, // FIND_STATIC }; // TODO: Why as method? Isn't a simple define sufficient? @@ -359,6 +362,11 @@ BOOL SbiDisas::DisasLine( String& rText ) rText.Erase(); if( !Fetch() ) return FALSE; + +#ifdef DBG_TRACE_BASIC + String aTraceStr_STMNT; +#endif + // New line? if( eOp == _STMNT && nOp1 != nLine ) { @@ -391,8 +399,13 @@ BOOL SbiDisas::DisasLine( String& rText ) rText.AppendAscii( "; " ); rText += s; rText.AppendAscii( _crlf() ); + +#ifdef DBG_TRACE_BASIC + aTraceStr_STMNT = s; +#endif } } + // Label? const char* p = ""; if( cLabels[ nPC >> 3 ] & ( 1 << ( nPC & 7 ) ) ) @@ -430,20 +443,29 @@ BOOL SbiDisas::DisasLine( String& rText ) rText.AppendAscii( _crlf() ); } snprintf( cBuf, sizeof(cBuf), pMask[ nParts ], nPC, (USHORT) eOp, nOp1, nOp2 ); - rText.AppendAscii( cBuf ); + + String aPCodeStr; + aPCodeStr.AppendAscii( cBuf ); int n = eOp; if( eOp >= SbOP2_START ) n -= SbOP2_START; else if( eOp >= SbOP1_START ) n -= SbOP1_START; - rText += '\t'; - rText.AppendAscii( pOps[ nParts-1 ][ n ] ); - rText += '\t'; + aPCodeStr += '\t'; + aPCodeStr.AppendAscii( pOps[ nParts-1 ][ n ] ); + aPCodeStr += '\t'; switch( nParts ) { - case 2: (this->*( pOperand2[ n ] ) )( rText ); break; - case 3: (this->*( pOperand3[ n ] ) )( rText ); break; + case 2: (this->*( pOperand2[ n ] ) )( aPCodeStr ); break; + case 3: (this->*( pOperand3[ n ] ) )( aPCodeStr ); break; } + + rText += aPCodeStr; + +#ifdef DBG_TRACE_BASIC + dbg_RegisterTraceTextForPC( pMod, nPC, aTraceStr_STMNT, aPCodeStr ); +#endif + return TRUE; } diff --git a/basic/source/classes/sb.cxx b/basic/source/classes/sb.cxx index 79c5f78601ea..e28b0a304f28 100755 --- a/basic/source/classes/sb.cxx +++ b/basic/source/classes/sb.cxx @@ -339,27 +339,18 @@ SbxBase* SbFormFactory::Create( UINT16, UINT32 ) SbxObject* SbFormFactory::CreateObject( const String& rClassName ) { - static String aLoadMethodName( RTL_CONSTASCII_USTRINGPARAM("load") ); - - SbxObject* pRet = NULL; - SbModule* pMod = pMOD; - if( pMod ) + if( SbModule* pMod = pMOD ) { - SbxVariable* pVar = pMod->Find( rClassName, SbxCLASS_OBJECT ); - if( pVar ) + if( SbxVariable* pVar = pMod->Find( rClassName, SbxCLASS_OBJECT ) ) { - SbxBase* pObj = pVar->GetObject(); - SbUserFormModule* pFormModule = PTR_CAST( SbUserFormModule, pObj ); - - if( pFormModule != NULL ) + if( SbUserFormModule* pFormModule = PTR_CAST( SbUserFormModule, pVar->GetObject() ) ) { - pFormModule->load(); - SbUserFormModuleInstance* pFormInstance = pFormModule->CreateInstance(); - pRet = pFormInstance; + pFormModule->Load(); + return pFormModule->CreateInstance(); } } } - return pRet; + return 0; } @@ -569,11 +560,13 @@ SbClassModuleObject::SbClassModuleObject( SbModule* pClassModule ) } } SetModuleType( ModuleType::CLASS ); + mbVBACompat = pClassModule->mbVBACompat; } SbClassModuleObject::~SbClassModuleObject() { - triggerTerminateEvent(); + if( StarBASIC::IsRunning() ) + triggerTerminateEvent(); // Must be deleted by base class dtor because this data // is not owned by the SbClassModuleObject object @@ -606,7 +599,28 @@ void SbClassModuleObject::SFX_NOTIFY( SfxBroadcaster& rBC, const TypeId& rBCType { SbxValues aVals; aVals.eType = SbxVARIANT; - pMeth->Get( aVals ); + + SbxArray* pArg = pVar->GetParameters(); + USHORT nVarParCount = (pArg != NULL) ? pArg->Count() : 0; + if( nVarParCount > 1 ) + { + SbxArrayRef xMethParameters = new SbxArray; + xMethParameters->Put( pMeth, 0 ); // Method as parameter 0 + for( USHORT i = 1 ; i < nVarParCount ; ++i ) + { + SbxVariable* pPar = pArg->Get( i ); + xMethParameters->Put( pPar, i ); + } + + pMeth->SetParameters( xMethParameters ); + pMeth->Get( aVals ); + pMeth->SetParameters( NULL ); + } + else + { + pMeth->Get( aVals ); + } + pVar->Put( aVals ); } } diff --git a/basic/source/classes/sbunoobj.cxx b/basic/source/classes/sbunoobj.cxx index e51a0c09270b..df13bc7ec571 100644..100755 --- a/basic/source/classes/sbunoobj.cxx +++ b/basic/source/classes/sbunoobj.cxx @@ -911,7 +911,7 @@ Type getUnoTypeForSbxBaseType( SbxDataType eType ) case SbxVARIANT: aRetType = ::getCppuType( (Any*)0 ); break; //case SbxDATAOBJECT: break; case SbxCHAR: aRetType = ::getCppuType( (sal_Unicode*)0 ); break; - case SbxBYTE: aRetType = ::getCppuType( (sal_Int16*)0 ); break; + case SbxBYTE: aRetType = ::getCppuType( (sal_Int8*)0 ); break; case SbxUSHORT: aRetType = ::getCppuType( (sal_uInt16*)0 ); break; case SbxULONG: aRetType = ::getCppuType( (sal_uInt32*)0 ); break; //case SbxLONG64: break; diff --git a/basic/source/classes/sbxmod.cxx b/basic/source/classes/sbxmod.cxx index 1b49a376c9bd..8b1069bbeab3 100644 --- a/basic/source/classes/sbxmod.cxx +++ b/basic/source/classes/sbxmod.cxx @@ -45,6 +45,7 @@ #include "runtime.hxx" #include "token.hxx" #include "sbunoobj.hxx" +#include "sbtrace.hxx" //#include <basic/hilight.hxx> @@ -53,9 +54,10 @@ #include <basic/basrdll.hxx> #include <vos/mutex.hxx> #include <basic/sbobjmod.hxx> +#include <cppuhelper/implbase2.hxx> #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/script/ModuleType.hpp> -#include <com/sun/star/script/XVBACompat.hpp> +#include <com/sun/star/script/vba/XVBACompatibility.hpp> #include <com/sun/star/beans/XPropertySet.hpp> using namespace com::sun::star; @@ -76,15 +78,362 @@ using namespace com::sun::star; #include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <comphelper/processfactory.hxx> #include <vcl/svapp.hxx> +#include <map> +#include <com/sun/star/reflection/XProxyFactory.hpp> +#include <cppuhelper/implbase1.hxx> +#include <basic/sbobjmod.hxx> +#include <com/sun/star/uno/XAggregation.hpp> +#include <map> +#include <com/sun/star/script/XInvocation.hpp> + using namespace ::com::sun::star; +using namespace com::sun::star::lang; +using namespace com::sun::star::reflection; +using namespace com::sun::star::beans; +using namespace com::sun::star::script; + #include <com/sun/star/script/XLibraryContainer.hpp> #include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <com/sun/star/awt/XDialogProvider.hpp> #include <com/sun/star/awt/XTopWindow.hpp> +#include <com/sun/star/awt/XWindow.hpp> #include <com/sun/star/awt/XControl.hpp> #include <cppuhelper/implbase1.hxx> #include <comphelper/anytostring.hxx> +#include <com/sun/star/beans/XPropertySet.hpp> + +typedef ::cppu::WeakImplHelper1< XInvocation > DocObjectWrapper_BASE; +typedef ::std::map< sal_Int16, Any, ::std::less< sal_Int16 > > OutParamMap; +::com::sun::star::uno::Any sbxToUnoValue( SbxVariable* pVar ); +void unoToSbxValue( SbxVariable* pVar, const ::com::sun::star::uno::Any& aValue ); + +class DocObjectWrapper : public DocObjectWrapper_BASE +{ + Reference< XAggregation > m_xAggProxy; + Reference< XInvocation > m_xAggInv; + Reference< XTypeProvider > m_xAggregateTypeProv; + Sequence< Type > m_Types; + SbModule* m_pMod; + SbMethodRef getMethod( const rtl::OUString& aName ) throw (RuntimeException); + SbPropertyRef getProperty( const rtl::OUString& aName ) throw (RuntimeException); + String mName; // for debugging + +public: + DocObjectWrapper( SbModule* pMod ); + virtual ~DocObjectWrapper(); + + virtual void SAL_CALL acquire() throw(); + virtual void SAL_CALL release() throw(); + + virtual Sequence< sal_Int8 > SAL_CALL getImplementationId() throw (RuntimeException) + { + if( !m_xAggregateTypeProv.is() ) + throw RuntimeException(); + return m_xAggregateTypeProv->getImplementationId(); + } + + virtual Reference< XIntrospectionAccess > SAL_CALL getIntrospection( ) throw (RuntimeException); + + 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); + virtual void SAL_CALL setValue( const ::rtl::OUString& aPropertyName, const Any& aValue ) throw (UnknownPropertyException, CannotConvertException, InvocationTargetException, RuntimeException); + virtual Any SAL_CALL getValue( const ::rtl::OUString& aPropertyName ) throw (UnknownPropertyException, RuntimeException); + virtual ::sal_Bool SAL_CALL hasMethod( const ::rtl::OUString& aName ) throw (RuntimeException); + virtual ::sal_Bool SAL_CALL hasProperty( const ::rtl::OUString& aName ) throw (RuntimeException); + virtual Any SAL_CALL queryInterface( const Type& aType ) throw ( RuntimeException ); + + virtual Sequence< Type > SAL_CALL getTypes() throw ( RuntimeException ); +}; + +DocObjectWrapper::DocObjectWrapper( SbModule* pVar ) : m_pMod( pVar ), mName( pVar->GetName() ) +{ + SbObjModule* pMod = PTR_CAST(SbObjModule,pVar); + if ( pMod ) + { + if ( pMod->GetModuleType() == ModuleType::DOCUMENT ) + { + Reference< XMultiServiceFactory > xFactory = comphelper::getProcessServiceFactory(); + // Use proxy factory service to create aggregatable proxy. + SbUnoObject* pUnoObj = PTR_CAST(SbUnoObject,pMod->GetObject() ); + Reference< XInterface > xIf; + if ( pUnoObj ) + { + Any aObj = pUnoObj->getUnoAny(); + aObj >>= xIf; + if ( xIf.is() ) + { + m_xAggregateTypeProv.set( xIf, UNO_QUERY ); + m_xAggInv.set( xIf, UNO_QUERY ); + } + } + if ( xIf.is() ) + { + try + { + Reference< XMultiComponentFactory > xMFac( xFactory, UNO_QUERY_THROW ); + Reference< XPropertySet> xPSMPropertySet( xMFac, UNO_QUERY_THROW ); + Reference< XComponentContext > xCtx; + xPSMPropertySet->getPropertyValue( + String( RTL_CONSTASCII_USTRINGPARAM("DefaultContext") ) ) >>= xCtx; + Reference< XProxyFactory > xProxyFac( xMFac->createInstanceWithContext( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.reflection.ProxyFactory" ) ), xCtx ), UNO_QUERY_THROW ); + m_xAggProxy = xProxyFac->createProxy( xIf ); + } + catch( Exception& ) + { + OSL_ENSURE( false, "DocObjectWrapper::DocObjectWrapper: Caught exception!" ); + } + } + + if ( m_xAggProxy.is() ) + { + osl_incrementInterlockedCount( &m_refCount ); + + /* i35609 - Fix crash on Solaris. The setDelegator call needs + to be in its own block to ensure that all temporary Reference + instances that are acquired during the call are released + before m_refCount is decremented again */ + { + m_xAggProxy->setDelegator( static_cast< cppu::OWeakObject * >( this ) ); + } + + osl_decrementInterlockedCount( &m_refCount ); + } + } + } +} + +void SAL_CALL +DocObjectWrapper::acquire() throw () +{ + osl_incrementInterlockedCount( &m_refCount ); + OSL_TRACE("DocObjectWrapper::acquire(%s) 0x%x refcount is now %d", rtl::OUStringToOString( mName, RTL_TEXTENCODING_UTF8 ).getStr(), this, m_refCount ); +} +void SAL_CALL +DocObjectWrapper::release() throw () +{ + if ( osl_decrementInterlockedCount( &m_refCount ) == 0 ) + { + OSL_TRACE("DocObjectWrapper::release(%s) 0x%x refcount is now %d", rtl::OUStringToOString( mName, RTL_TEXTENCODING_UTF8 ).getStr(), this, m_refCount ); + delete this; + } + else + OSL_TRACE("DocObjectWrapper::release(%s) 0x%x refcount is now %d", rtl::OUStringToOString( mName, RTL_TEXTENCODING_UTF8 ).getStr(), this, m_refCount ); +} + +DocObjectWrapper::~DocObjectWrapper() +{ +} + +Sequence< Type > SAL_CALL DocObjectWrapper::getTypes() + throw ( RuntimeException ) +{ + if ( m_Types.getLength() == 0 ) + { + Sequence< Type > sTypes; + if ( m_xAggregateTypeProv.is() ) + sTypes = m_xAggregateTypeProv->getTypes(); + m_Types.realloc( sTypes.getLength() + 1 ); + Type* pPtr = m_Types.getArray(); + for ( int i=0; i<m_Types.getLength(); ++i, ++pPtr ) + { + if ( i == 0 ) + *pPtr = XInvocation::static_type( NULL ); + else + *pPtr = sTypes[ i - 1 ]; + } + } + return m_Types; +} + +Reference< XIntrospectionAccess > SAL_CALL +DocObjectWrapper::getIntrospection( ) throw (RuntimeException) +{ + return NULL; +} + +Any SAL_CALL +DocObjectWrapper::invoke( const ::rtl::OUString& aFunctionName, const Sequence< Any >& aParams, Sequence< ::sal_Int16 >& aOutParamIndex, Sequence< Any >& aOutParam ) throw (IllegalArgumentException, CannotConvertException, InvocationTargetException, RuntimeException) +{ + if ( m_xAggInv.is() && m_xAggInv->hasMethod( aFunctionName ) ) + return m_xAggInv->invoke( aFunctionName, aParams, aOutParamIndex, aOutParam ); + SbMethodRef pMethod = getMethod( aFunctionName ); + if ( !pMethod ) + throw RuntimeException(); + // check number of parameters + sal_Int32 nParamsCount = aParams.getLength(); + SbxInfo* pInfo = pMethod->GetInfo(); + if ( pInfo ) + { + sal_Int32 nSbxOptional = 0; + USHORT n = 1; + for ( const SbxParamInfo* pParamInfo = pInfo->GetParam( n ); pParamInfo; pParamInfo = pInfo->GetParam( ++n ) ) + { + if ( ( pParamInfo->nFlags & SBX_OPTIONAL ) != 0 ) + ++nSbxOptional; + else + nSbxOptional = 0; + } + sal_Int32 nSbxCount = n - 1; + if ( nParamsCount < nSbxCount - nSbxOptional ) + { + throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "wrong number of parameters!" ) ), Reference< XInterface >() ); + } + } + // set parameters + SbxArrayRef xSbxParams; + if ( nParamsCount > 0 ) + { + xSbxParams = new SbxArray; + const Any* pParams = aParams.getConstArray(); + for ( sal_Int32 i = 0; i < nParamsCount; ++i ) + { + SbxVariableRef xSbxVar = new SbxVariable( SbxVARIANT ); + unoToSbxValue( static_cast< SbxVariable* >( xSbxVar ), pParams[i] ); + xSbxParams->Put( xSbxVar, static_cast< USHORT >( i ) + 1 ); + + // Enable passing by ref + if ( xSbxVar->GetType() != SbxVARIANT ) + xSbxVar->SetFlag( SBX_FIXED ); + } + } + if ( xSbxParams.Is() ) + pMethod->SetParameters( xSbxParams ); + + // call method + SbxVariableRef xReturn = new SbxVariable; + ErrCode nErr = SbxERR_OK; + + nErr = pMethod->Call( xReturn ); + Any aReturn; + // get output parameters + if ( xSbxParams.Is() ) + { + SbxInfo* pInfo_ = pMethod->GetInfo(); + if ( pInfo_ ) + { + OutParamMap aOutParamMap; + for ( USHORT n = 1, nCount = xSbxParams->Count(); n < nCount; ++n ) + { + const SbxParamInfo* pParamInfo = pInfo_->GetParam( n ); + if ( pParamInfo && ( pParamInfo->eType & SbxBYREF ) != 0 ) + { + SbxVariable* pVar = xSbxParams->Get( n ); + if ( pVar ) + { + SbxVariableRef xVar = pVar; + aOutParamMap.insert( OutParamMap::value_type( n - 1, sbxToUnoValue( xVar ) ) ); + } + } + } + sal_Int32 nOutParamCount = aOutParamMap.size(); + aOutParamIndex.realloc( nOutParamCount ); + aOutParam.realloc( nOutParamCount ); + sal_Int16* pOutParamIndex = aOutParamIndex.getArray(); + Any* pOutParam = aOutParam.getArray(); + for ( OutParamMap::iterator aIt = aOutParamMap.begin(); aIt != aOutParamMap.end(); ++aIt, ++pOutParamIndex, ++pOutParam ) + { + *pOutParamIndex = aIt->first; + *pOutParam = aIt->second; + } + } + } + + // get return value + aReturn = sbxToUnoValue( xReturn ); + + pMethod->SetParameters( NULL ); + + return aReturn; +} + +void SAL_CALL +DocObjectWrapper::setValue( const ::rtl::OUString& aPropertyName, const Any& aValue ) throw (UnknownPropertyException, CannotConvertException, InvocationTargetException, RuntimeException) +{ + if ( m_xAggInv.is() && m_xAggInv->hasProperty( aPropertyName ) ) + return m_xAggInv->setValue( aPropertyName, aValue ); + + SbPropertyRef pProperty = getProperty( aPropertyName ); + if ( !pProperty.Is() ) + throw UnknownPropertyException(); + unoToSbxValue( (SbxVariable*) pProperty, aValue ); +} + +Any SAL_CALL +DocObjectWrapper::getValue( const ::rtl::OUString& aPropertyName ) throw (UnknownPropertyException, RuntimeException) +{ + if ( m_xAggInv.is() && m_xAggInv->hasProperty( aPropertyName ) ) + return m_xAggInv->getValue( aPropertyName ); + + SbPropertyRef pProperty = getProperty( aPropertyName ); + if ( !pProperty.Is() ) + throw UnknownPropertyException(); + + SbxVariable* pProp = ( SbxVariable* ) pProperty; + if ( pProp->GetType() == SbxEMPTY ) + pProperty->Broadcast( SBX_HINT_DATAWANTED ); + + Any aRet = sbxToUnoValue( pProp ); + return aRet; +} + +::sal_Bool SAL_CALL +DocObjectWrapper::hasMethod( const ::rtl::OUString& aName ) throw (RuntimeException) +{ + if ( m_xAggInv.is() && m_xAggInv->hasMethod( aName ) ) + return sal_True; + return getMethod( aName ).Is(); +} + +::sal_Bool SAL_CALL +DocObjectWrapper::hasProperty( const ::rtl::OUString& aName ) throw (RuntimeException) +{ + sal_Bool bRes = sal_False; + if ( m_xAggInv.is() && m_xAggInv->hasProperty( aName ) ) + bRes = sal_True; + else bRes = getProperty( aName ).Is(); + return bRes; +} + +Any SAL_CALL DocObjectWrapper::queryInterface( const Type& aType ) + throw ( RuntimeException ) +{ + Any aRet = DocObjectWrapper_BASE::queryInterface( aType ); + if ( aRet.hasValue() ) + return aRet; + else if ( m_xAggProxy.is() ) + aRet = m_xAggProxy->queryAggregation( aType ); + return aRet; +} + +SbMethodRef DocObjectWrapper::getMethod( const rtl::OUString& aName ) throw (RuntimeException) +{ + SbMethodRef pMethod = NULL; + if ( m_pMod ) + { + USHORT nSaveFlgs = m_pMod->GetFlags(); + // Limit search to this module + m_pMod->ResetFlag( SBX_GBLSEARCH ); + pMethod = (SbMethod*) m_pMod->SbModule::Find( aName, SbxCLASS_METHOD ); + m_pMod->SetFlags( nSaveFlgs ); + } + + return pMethod; +} + +SbPropertyRef DocObjectWrapper::getProperty( const rtl::OUString& aName ) throw (RuntimeException) +{ + SbPropertyRef pProperty = NULL; + if ( m_pMod ) + { + USHORT nSaveFlgs = m_pMod->GetFlags(); + // Limit search to this module. + m_pMod->ResetFlag( SBX_GBLSEARCH ); + pProperty = (SbProperty*)m_pMod->SbModule::Find( aName, SbxCLASS_PROPERTY ); + m_pMod->SetFlag( nSaveFlgs ); + } + + return pProperty; +} TYPEINIT1(SbModule,SbxObject) TYPEINIT1(SbMethod,SbxMethod) @@ -112,9 +461,9 @@ bool getDefaultVBAMode( StarBASIC* pb ) uno::Reference< beans::XPropertySet > xProp( aDoc, uno::UNO_QUERY ); if ( xProp.is() ) { - uno::Reference< script::XVBACompat > xVBAMode( xProp->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("BasicLibraries") ) ), uno::UNO_QUERY ); + uno::Reference< script::vba::XVBACompatibility > xVBAMode( xProp->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("BasicLibraries") ) ), uno::UNO_QUERY ); if ( xVBAMode.is() ) - bResult = ( xVBAMode->getVBACompatModeOn() == sal_True ); + bResult = xVBAMode->getVBACompatibilityMode() == sal_True; } } } @@ -199,12 +548,24 @@ SbModule::SbModule( const String& rName, BOOL bVBACompat ) SbModule::~SbModule() { + OSL_TRACE("Module named %s is destructing", rtl::OUStringToOString( GetName(), RTL_TEXTENCODING_UTF8 ).getStr() ); if( pImage ) delete pImage; if( pBreaks ) delete pBreaks; if( pClassData ) delete pClassData; + mxWrapper = NULL; +} + +uno::Reference< script::XInvocation > +SbModule::GetUnoModule() +{ + if ( !mxWrapper.is() ) + mxWrapper = new DocObjectWrapper( this ); + + OSL_TRACE("Module named %s returning wrapper mxWrapper (0x%x)", rtl::OUStringToOString( GetName(), RTL_TEXTENCODING_UTF8 ).getStr(), mxWrapper.get() ); + return mxWrapper; } BOOL SbModule::IsCompiled() const @@ -684,6 +1045,9 @@ USHORT SbModule::Run( SbMethod* pMeth ) StarBASICRef xBasic; if( bDelInst ) { +#ifdef DBG_TRACE_BASIC + dbg_InitTrace(); +#endif // #32779: Basic waehrend der Ausfuehrung festhalten xBasic = (StarBASIC*) GetParent(); @@ -762,18 +1126,28 @@ USHORT SbModule::Run( SbMethod* pMeth ) SbModule* pOldMod = pMOD; pMOD = this; SbiRuntime* pRt = new SbiRuntime( this, pMeth, pMeth->nStart ); + +#ifdef DBG_TRACE_BASIC + dbg_traceNotifyCall( this, pMeth, pINST->nCallLvl ); +#endif + pRt->pNext = pINST->pRun; if( pRt->pNext ) pRt->pNext->block(); pINST->pRun = pRt; if ( mbVBACompat ) - { + { pINST->EnableCompatibility( TRUE ); - } + } while( pRt->Step() ) {} if( pRt->pNext ) pRt->pNext->unblock(); +#ifdef DBG_TRACE_BASIC + bool bLeave = true; + dbg_traceNotifyCall( this, pMeth, pINST->nCallLvl, bLeave ); +#endif + // #63710 Durch ein anderes Thread-Handling bei Events kann es passieren, // dass show-Aufruf an einem Dialog zurueckkehrt (durch schliessen des // Dialogs per UI), BEVOR ein per Event ausgeloester weitergehender Call, @@ -867,9 +1241,20 @@ void SbModule::RunInit() pMOD = this; // Der Init-Code beginnt immer hier SbiRuntime* pRt = new SbiRuntime( this, NULL, 0 ); + +#ifdef DBG_TRACE_BASIC + dbg_traceNotifyCall( this, NULL, 0 ); +#endif + pRt->pNext = pINST->pRun; pINST->pRun = pRt; while( pRt->Step() ) {} + +#ifdef DBG_TRACE_BASIC + bool bLeave = true; + dbg_traceNotifyCall( this, NULL, 0, bLeave ); +#endif + pINST->pRun = pRt->pNext; delete pRt; pMOD = pOldMod; @@ -884,6 +1269,33 @@ void SbModule::RunInit() } // Mit private/dim deklarierte Variablen loeschen + +void SbModule::AddVarName( const String& aName ) +{ + // see if the name is added allready + std::vector< String >::iterator it_end = mModuleVariableNames.end(); + for ( std::vector< String >::iterator it = mModuleVariableNames.begin(); it != it_end; ++it ) + { + if ( aName == *it ) + return; + } + mModuleVariableNames.push_back( aName ); +} + +void SbModule::RemoveVars() +{ + std::vector< String >::iterator it_end = mModuleVariableNames.end(); + for ( std::vector< String >::iterator it = mModuleVariableNames.begin(); it != it_end; ++it ) + { + // We don't want a Find being called in a derived class ( e.g. + // SbUserform because it could trigger say an initialise event + // 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 ) + SbxVariableRef p = SbModule::Find( *it, SbxCLASS_PROPERTY ); + if( p.Is() ) + Remove (p); + } +} + void SbModule::ClearPrivateVars() { for( USHORT i = 0 ; i < pProps->Count() ; i++ ) @@ -1600,9 +2012,9 @@ SbObjModule::Find( const XubString& rName, SbxClassType t ) return pVar; } -typedef ::cppu::WeakImplHelper1< awt::XTopWindowListener > EventListener_BASE; +typedef ::cppu::WeakImplHelper2< awt::XTopWindowListener, awt::XWindowListener > FormObjEventListener_BASE; -class FormObjEventListenerImpl : public EventListener_BASE +class FormObjEventListenerImpl : public FormObjEventListener_BASE { SbUserFormModule* mpUserForm; uno::Reference< lang::XComponent > mxComponent; @@ -1612,39 +2024,57 @@ class FormObjEventListenerImpl : public EventListener_BASE sal_Bool mbShowing; FormObjEventListenerImpl(); // not defined FormObjEventListenerImpl(const FormObjEventListenerImpl&); // not defined + public: - FormObjEventListenerImpl( SbUserFormModule* pUserForm, const uno::Reference< lang::XComponent >& xComponent ) : mpUserForm( pUserForm ), mxComponent( xComponent) , mbDisposed( false ), mbOpened( sal_False ), mbActivated( sal_False ), mbShowing( sal_False ) + FormObjEventListenerImpl( SbUserFormModule* pUserForm, const uno::Reference< lang::XComponent >& xComponent ) : + mpUserForm( pUserForm ), mxComponent( xComponent) , + mbDisposed( false ), mbOpened( sal_False ), mbActivated( sal_False ), mbShowing( sal_False ) { if ( mxComponent.is() ) { - uno::Reference< awt::XTopWindow > xList( mxComponent, uno::UNO_QUERY_THROW );; - OSL_TRACE("*********** Registering the listener"); - xList->addTopWindowListener( this ); + OSL_TRACE("*********** Registering the listeners"); + try + { + uno::Reference< awt::XTopWindow >( mxComponent, uno::UNO_QUERY_THROW )->addTopWindowListener( this ); + } + catch( uno::Exception& ) {} + try + { + uno::Reference< awt::XWindow >( mxComponent, uno::UNO_QUERY_THROW )->addWindowListener( this ); + } + catch( uno::Exception& ) {} } } - ~FormObjEventListenerImpl() + virtual ~FormObjEventListenerImpl() { removeListener(); } - sal_Bool isShowing() { return mbShowing; } + + sal_Bool isShowing() const { return mbShowing; } + void removeListener() { - try + if ( mxComponent.is() && !mbDisposed ) { - if ( mxComponent.is() && !mbDisposed ) + OSL_TRACE("*********** Removing the listeners"); + try + { + uno::Reference< awt::XTopWindow >( mxComponent, uno::UNO_QUERY_THROW )->removeTopWindowListener( this ); + } + catch( uno::Exception& ) {} + try { - uno::Reference< awt::XTopWindow > xList( mxComponent, uno::UNO_QUERY_THROW );; - OSL_TRACE("*********** Removing the listener"); - xList->removeTopWindowListener( this ); - mxComponent = NULL; + uno::Reference< awt::XWindow >( mxComponent, uno::UNO_QUERY_THROW )->removeWindowListener( this ); } + catch( uno::Exception& ) {} } - catch( uno::Exception& ) {} + mxComponent.clear(); } + virtual void SAL_CALL windowOpened( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException) { - if ( mpUserForm ) + if ( mpUserForm ) { mbOpened = sal_True; mbShowing = sal_True; @@ -1691,12 +2121,23 @@ public: } //liuchen 2009-7-21 - virtual void SAL_CALL windowClosed( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException) { mbOpened = sal_False; mbShowing = sal_False; } - virtual void SAL_CALL windowMinimized( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException) {} - virtual void SAL_CALL windowNormalized( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException){} + virtual void SAL_CALL windowClosed( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException) + { + mbOpened = sal_False; + mbShowing = sal_False; + } + + virtual void SAL_CALL windowMinimized( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException) + { + } + + virtual void SAL_CALL windowNormalized( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException) + { + } + virtual void SAL_CALL windowActivated( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException) { - if ( mpUserForm ) + if ( mpUserForm ) { mbActivated = sal_True; if ( mbOpened ) @@ -1709,18 +2150,38 @@ public: virtual void SAL_CALL windowDeactivated( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException) { - if ( mpUserForm ) - mpUserForm->triggerDeActivateEvent(); + if ( mpUserForm ) + mpUserForm->triggerDeactivateEvent(); + } + + virtual void SAL_CALL windowResized( const awt::WindowEvent& /*e*/ ) throw (uno::RuntimeException) + { + if ( mpUserForm ) + { + mpUserForm->triggerResizeEvent(); + mpUserForm->triggerLayoutEvent(); + } } + virtual void SAL_CALL windowMoved( const awt::WindowEvent& /*e*/ ) throw (uno::RuntimeException) + { + if ( mpUserForm ) + mpUserForm->triggerLayoutEvent(); + } + + virtual void SAL_CALL windowShown( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException) + { + } + + virtual void SAL_CALL windowHidden( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException) + { + } - virtual void SAL_CALL disposing( const lang::EventObject& Source ) throw (uno::RuntimeException) + virtual void SAL_CALL disposing( const lang::EventObject& /*Source*/ ) throw (uno::RuntimeException) { OSL_TRACE("** Userform/Dialog disposing"); mbDisposed = true; - uno::Any aSource; - aSource <<= Source; - mxComponent = NULL; + mxComponent.clear(); if ( mpUserForm ) mpUserForm->ResetApiObj(); } @@ -1734,6 +2195,10 @@ SbUserFormModule::SbUserFormModule( const String& rName, const com::sun::star::s m_xModel.set( mInfo.ModuleObject, uno::UNO_QUERY_THROW ); } +SbUserFormModule::~SbUserFormModule() +{ +} + void SbUserFormModule::ResetApiObj() { if ( m_xDialog.is() ) // probably someone close the dialog window @@ -1796,23 +2261,22 @@ void SbUserFormModule::triggerMethod( const String& aMethodToRun, Sequence< Any void SbUserFormModule::triggerActivateEvent( void ) { - OSL_TRACE("**** entering SbUserFormModule::triggerActivate"); - triggerMethod( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("UserForm_activate") ) ); - OSL_TRACE("**** leaving SbUserFormModule::triggerActivate"); + OSL_TRACE("**** entering SbUserFormModule::triggerActivate"); + triggerMethod( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("UserForm_Activate") ) ); + OSL_TRACE("**** leaving SbUserFormModule::triggerActivate"); } -void SbUserFormModule::triggerDeActivateEvent( void ) +void SbUserFormModule::triggerDeactivateEvent( void ) { - OSL_TRACE("**** SbUserFormModule::triggerDeActivate"); - triggerMethod( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Userform_DeActivate") ) ); + OSL_TRACE("**** SbUserFormModule::triggerDeactivate"); + triggerMethod( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Userform_Deactivate") ) ); } void SbUserFormModule::triggerInitializeEvent( void ) - { if ( mbInit ) return; - OSL_TRACE("**** SbUserFormModule::triggerInitializeEvent"); + OSL_TRACE("**** SbUserFormModule::triggerInitializeEvent"); static String aInitMethodName( RTL_CONSTASCII_USTRINGPARAM("Userform_Initialize") ); triggerMethod( aInitMethodName ); mbInit = true; @@ -1820,12 +2284,24 @@ void SbUserFormModule::triggerInitializeEvent( void ) void SbUserFormModule::triggerTerminateEvent( void ) { - OSL_TRACE("**** SbUserFormModule::triggerTerminateEvent"); + OSL_TRACE("**** SbUserFormModule::triggerTerminateEvent"); static String aTermMethodName( RTL_CONSTASCII_USTRINGPARAM("Userform_Terminate") ); triggerMethod( aTermMethodName ); mbInit=false; } +void SbUserFormModule::triggerLayoutEvent( void ) +{ + static String aMethodName( RTL_CONSTASCII_USTRINGPARAM("Userform_Layout") ); + triggerMethod( aMethodName ); +} + +void SbUserFormModule::triggerResizeEvent( void ) +{ + static String aMethodName( RTL_CONSTASCII_USTRINGPARAM("Userform_Resize") ); + triggerMethod( aMethodName ); +} + SbUserFormModuleInstance* SbUserFormModule::CreateInstance() { SbUserFormModuleInstance* pInstance = new SbUserFormModuleInstance( this, GetName(), m_mInfo, IsVBACompat() ); @@ -1853,7 +2329,7 @@ SbxVariable* SbUserFormModuleInstance::Find( const XubString& rName, SbxClassTyp } -void SbUserFormModule::load() +void SbUserFormModule::Load() { OSL_TRACE("** load() "); // forces a load @@ -1891,21 +2367,20 @@ void SbUserFormModule::Unload() if( pMeth ) { OSL_TRACE("Attempting too run the UnloadObjectMethod"); - m_xDialog = NULL; //release ref to the uno object + m_xDialog.clear(); //release ref to the uno object SbxValues aVals; - FormObjEventListenerImpl* pFormListener = dynamic_cast< FormObjEventListenerImpl* >( m_DialogListener.get() ); bool bWaitForDispose = true; // assume dialog is showing - if ( pFormListener ) + if ( m_DialogListener.get() ) { - bWaitForDispose = pFormListener->isShowing(); + bWaitForDispose = m_DialogListener->isShowing(); OSL_TRACE("Showing %d", bWaitForDispose ); } pMeth->Get( aVals); - if ( !bWaitForDispose ) - { - // we've either already got a dispose or we'er never going to get one + if ( !bWaitForDispose ) + { + // we've either already got a dispose or we'er never going to get one ResetApiObj(); - } // else wait for dispose + } // else wait for dispose OSL_TRACE("UnloadObject completed ( we hope )"); } } @@ -1943,9 +2418,8 @@ void SbUserFormModule::InitObject() pDocObject = new SbUnoObject( GetName(), uno::makeAny( xVBAFactory->createInstanceWithArguments( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.msforms.UserForm")), aArgs ) ) ); uno::Reference< lang::XComponent > xComponent( aArgs[ 1 ], uno::UNO_QUERY_THROW ); // remove old listener if it exists - FormObjEventListenerImpl* pFormListener = dynamic_cast< FormObjEventListenerImpl* >( m_DialogListener.get() ); - if ( pFormListener ) - pFormListener->removeListener(); + if ( m_DialogListener.get() ) + m_DialogListener->removeListener(); m_DialogListener = new FormObjEventListenerImpl( this, xComponent ); triggerInitializeEvent(); diff --git a/basic/source/comp/exprtree.cxx b/basic/source/comp/exprtree.cxx index 0cf0d9870378..42969b98d0d8 100644 --- a/basic/source/comp/exprtree.cxx +++ b/basic/source/comp/exprtree.cxx @@ -1009,13 +1009,8 @@ SbiParameters::SbiParameters( SbiParser* p, BOOL bStandaloneExpression, BOOL bPa else pExpr = new SbiExpression( pParser ); - if( bByVal ) - { - if( !pExpr->IsLvalue() ) - pParser->Error( SbERR_LVALUE_EXPECTED ); - else - pExpr->SetByVal(); - } + if( bByVal && pExpr->IsLvalue() ) + pExpr->SetByVal(); //pExpr = bConst ? new SbiConstExpression( pParser ) // : new SbiExpression( pParser ); diff --git a/basic/source/comp/sbcomp.cxx b/basic/source/comp/sbcomp.cxx index 6e4f7ddf126e..e6fe73177dd2 100644..100755 --- a/basic/source/comp/sbcomp.cxx +++ b/basic/source/comp/sbcomp.cxx @@ -31,10 +31,310 @@ #include <basic/sbx.hxx> #include "sbcomp.hxx" #include "image.hxx" +#include "sbtrace.hxx" +//========================================================================== +// Tracing, for debugging only + +// To activate tracing enable in sbtrace.hxx +#ifdef DBG_TRACE_BASIC + +#include <hash_map> + +// Trace Settings +static const char* GpTraceFileName = "d:\\zBasic.Asm\\BasicTrace.txt"; +static const bool GbIncludePCodes = false; +static const int GnIndentPerCallLevel = 4; +static const int GnIndentForPCode = 2; + +struct TraceTextData +{ + rtl::OString m_aTraceStr_STMNT; + rtl::OString m_aTraceStr_PCode; +}; +typedef std::hash_map< sal_Int32, TraceTextData > PCToTextDataMap; +typedef std::hash_map< ::rtl::OUString, PCToTextDataMap*, ::rtl::OUStringHash, ::std::equal_to< ::rtl::OUString > > ModuleTraceMap; + +ModuleTraceMap GaModuleTraceMap; +ModuleTraceMap& rModuleTraceMap = GaModuleTraceMap; + +static void lcl_PrepareTraceForModule( SbModule* pModule ) +{ + String aModuleName = pModule->GetName(); + ModuleTraceMap::iterator it = rModuleTraceMap.find( aModuleName ); + if( it != rModuleTraceMap.end() ) + { + PCToTextDataMap* pInnerMap = it->second; + delete pInnerMap; + rModuleTraceMap.erase( it ); + } + + String aDisassemblyStr; + pModule->Disassemble( aDisassemblyStr ); +} + +static void lcl_lineOut( const char* pFileName, const char* pStr, const char* pPreStr = NULL ) +{ + const char* pPrintFirst = (pPreStr != NULL) ? pPreStr : ""; + FILE* pFile = fopen( pFileName, "a+" ); + if( pFile != NULL ) + { + fprintf( pFile, "%s%s\n", pPrintFirst, pStr ); + fclose( pFile ); + } +} + +const char* lcl_getSpaces( int nSpaceCount ) +{ + static sal_Char Spaces[] = " " + " " + " "; + static int nAvailableSpaceCount = strlen( Spaces ); + static sal_Char* pSpacesEnd = Spaces + nAvailableSpaceCount; + + if( nSpaceCount > nAvailableSpaceCount ) + nSpaceCount = nAvailableSpaceCount; + + return pSpacesEnd - nSpaceCount; +} + +static rtl::OString lcl_toOStringSkipLeadingWhites( const String& aStr ) +{ + static sal_Char Buffer[1000]; + + rtl::OString aOStr = OUStringToOString( rtl::OUString( aStr ), RTL_TEXTENCODING_ASCII_US ); + const sal_Char* pStr = aOStr.getStr(); + + // Skip whitespace + sal_Char c = *pStr; + while( c == ' ' || c == '\t' ) + { + pStr++; + c = *pStr; + } + + int nLen = strlen( pStr ); + strncpy( Buffer, pStr, nLen ); + Buffer[nLen] = 0; + + rtl::OString aORetStr( Buffer ); + return aORetStr; +} + +String dumpMethodParameters( SbMethod* pMethod ) +{ + String aStr; + if( pMethod == NULL ) + return aStr; + + SbxError eOld = SbxBase::GetError(); + + SbxArray* pParams = pMethod->GetParameters(); + SbxInfo* pInfo = pMethod->GetInfo(); + if ( pParams ) + { + aStr += '('; + // 0 is sub itself + for ( USHORT nParam = 1; nParam < pParams->Count(); nParam++ ) + { + SbxVariable* pVar = pParams->Get( nParam ); + DBG_ASSERT( pVar, "Parameter?!" ); + if ( pVar->GetName().Len() ) + aStr += pVar->GetName(); + else if ( pInfo ) + { + const SbxParamInfo* pParam = pInfo->GetParam( nParam ); + if ( pParam ) + aStr += pParam->aName; + } + aStr += '='; + if( pVar->GetType() & SbxARRAY ) + aStr += String( RTL_CONSTASCII_USTRINGPARAM( "..." ) ); + else + aStr += pVar->GetString(); + if ( nParam < ( pParams->Count() - 1 ) ) + aStr += String( RTL_CONSTASCII_USTRINGPARAM( ", " ) ); + } + aStr += ')'; + } + + SbxBase::ResetError(); + if( eOld != SbxERR_OK ) + SbxBase::SetError( eOld ); + + return aStr; +} + +// Public functions +void dbg_InitTrace( void ) +{ + FILE* pFile = fopen( GpTraceFileName, "w" ); + if( pFile != NULL ) + fclose( pFile ); +} + +void dbg_traceStep( SbModule* pModule, UINT32 nPC, INT32 nCallLvl ) +{ + SbModule* pTraceMod = pModule; + if( pTraceMod->ISA(SbClassModuleObject) ) + { + SbClassModuleObject* pClassModuleObj = (SbClassModuleObject*)(SbxBase*)pTraceMod; + pTraceMod = pClassModuleObj->getClassModule(); + } + + String aModuleName = pTraceMod->GetName(); + ModuleTraceMap::iterator it = rModuleTraceMap.find( aModuleName ); + if( it == rModuleTraceMap.end() ) + { + const char* pModuleNameStr = OUStringToOString( rtl::OUString( aModuleName ), RTL_TEXTENCODING_ASCII_US ).getStr(); + char Buffer[200]; + sprintf( Buffer, "TRACE ERROR: Unknown module \"%s\"", pModuleNameStr ); + lcl_lineOut( GpTraceFileName, Buffer ); + return; + } + + PCToTextDataMap* pInnerMap = it->second; + if( pInnerMap == NULL ) + { + lcl_lineOut( GpTraceFileName, "TRACE INTERNAL ERROR: No inner map" ); + return; + } + + PCToTextDataMap::iterator itInner = pInnerMap->find( nPC ); + if( itInner == pInnerMap->end() ) + { + const char* pModuleNameStr = OUStringToOString( rtl::OUString( aModuleName ), RTL_TEXTENCODING_ASCII_US ).getStr(); + char Buffer[200]; + sprintf( Buffer, "TRACE ERROR: No info for PC = %d in module \"%s\"", nPC, pModuleNameStr ); + lcl_lineOut( GpTraceFileName, Buffer ); + return; + } + + //nCallLvl--; + //if( nCallLvl < 0 ) + // nCallLvl = 0; + int nIndent = nCallLvl * GnIndentPerCallLevel; + + const TraceTextData& rTraceTextData = itInner->second; + const rtl::OString& rStr_STMNT = rTraceTextData.m_aTraceStr_STMNT; + if( rStr_STMNT.getLength() ) + lcl_lineOut( GpTraceFileName, rStr_STMNT.getStr(), lcl_getSpaces( nIndent ) ); + + if( !GbIncludePCodes ) + return; + + nIndent += GnIndentForPCode; + const rtl::OString& rStr_PCode = rTraceTextData.m_aTraceStr_PCode; + if( rStr_PCode.getLength() ) + lcl_lineOut( GpTraceFileName, rStr_PCode.getStr(), lcl_getSpaces( nIndent ) ); +} + +void dbg_traceNotifyCall( SbModule* pModule, SbMethod* pMethod, INT32 nCallLvl, bool bLeave ) +{ + static const char* pSeparator = "' ================================================================================"; + + SbModule* pTraceMod = pModule; + SbClassModuleObject* pClassModuleObj = NULL; + if( pTraceMod->ISA(SbClassModuleObject) ) + { + pClassModuleObj = (SbClassModuleObject*)(SbxBase*)pTraceMod; + pTraceMod = pClassModuleObj->getClassModule(); + } + + if( nCallLvl > 0 ) + nCallLvl--; + int nIndent = nCallLvl * GnIndentPerCallLevel; + if( !bLeave ) + { + lcl_lineOut( GpTraceFileName, "" ); + lcl_lineOut( GpTraceFileName, pSeparator, lcl_getSpaces( nIndent ) ); + } + + String aStr; + if( bLeave ) + { + lcl_lineOut( GpTraceFileName, "}", lcl_getSpaces( nIndent ) ); + aStr.AppendAscii( "' Leaving " ); + } + else + { + aStr.AppendAscii( "Entering " ); + } + String aModuleName = pModule->GetName(); + aStr += aModuleName; + if( pMethod != NULL ) + { + aStr.AppendAscii( "::" ); + String aMethodName = pMethod->GetName(); + aStr += aMethodName; + } + else + { + aStr.AppendAscii( "/RunInit" ); + } + + if( pClassModuleObj != NULL ) + { + aStr.AppendAscii( "[this=" ); + aStr += pClassModuleObj->GetName(); + aStr.AppendAscii( "]" ); + } + if( !bLeave ) + aStr += dumpMethodParameters( pMethod ); + + lcl_lineOut( GpTraceFileName, OUStringToOString( rtl::OUString( aStr ), RTL_TEXTENCODING_ASCII_US ).getStr(), lcl_getSpaces( nIndent ) ); + if( !bLeave ) + lcl_lineOut( GpTraceFileName, "{", lcl_getSpaces( nIndent ) ); + + if( bLeave ) + lcl_lineOut( GpTraceFileName, "" ); +} + +void dbg_traceNotifyError( SbError nTraceErr, const String& aTraceErrMsg, bool bTraceErrHandled, INT32 nCallLvl ) +{ + rtl::OString aOTraceErrMsg = OUStringToOString( rtl::OUString( aTraceErrMsg ), RTL_TEXTENCODING_ASCII_US ); + + char Buffer[200]; + const char* pHandledStr = bTraceErrHandled ? " / HANDLED" : ""; + sprintf( Buffer, "*** ERROR%s, Id = %d, Msg = \"%s\" ***", pHandledStr, (int)nTraceErr, aOTraceErrMsg.getStr() ); + int nIndent = nCallLvl * GnIndentPerCallLevel; + lcl_lineOut( GpTraceFileName, Buffer, lcl_getSpaces( nIndent ) ); +} + +void dbg_RegisterTraceTextForPC( SbModule* pModule, UINT32 nPC, + const String& aTraceStr_STMNT, const String& aTraceStr_PCode ) +{ + String aModuleName = pModule->GetName(); + ModuleTraceMap::iterator it = rModuleTraceMap.find( aModuleName ); + PCToTextDataMap* pInnerMap; + if( it == rModuleTraceMap.end() ) + { + pInnerMap = new PCToTextDataMap(); + rModuleTraceMap[ aModuleName ] = pInnerMap; + } + else + { + pInnerMap = it->second; + } + + TraceTextData aData; + + rtl::OString aOTraceStr_STMNT = lcl_toOStringSkipLeadingWhites( aTraceStr_STMNT ); + aData.m_aTraceStr_STMNT = aOTraceStr_STMNT; + + rtl::OString aOTraceStr_PCode = lcl_toOStringSkipLeadingWhites( aTraceStr_PCode ); + aData.m_aTraceStr_PCode = aOTraceStr_PCode; + + (*pInnerMap)[nPC] = aData; +} + +#endif + + +//========================================================================== // For debugging only -// #define DBG_SAVE_DISASSEMBLY +//#define DBG_SAVE_DISASSEMBLY #ifdef DBG_SAVE_DISASSEMBLY static bool dbg_bDisassemble = true; @@ -67,7 +367,7 @@ void dbg_SaveDisassembly( SbModule* pModule ) ( OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ) ), UNO_QUERY ); if( xSFI.is() ) { - String aFile( RTL_CONSTASCII_USTRINGPARAM("file:///d:/BasicAsm_") ); + String aFile( RTL_CONSTASCII_USTRINGPARAM("file:///d:/zBasic.Asm/Asm_") ); StarBASIC* pBasic = (StarBASIC*)pModule->GetParent(); if( pBasic ) { @@ -99,6 +399,7 @@ void dbg_SaveDisassembly( SbModule* pModule ) } #endif + // Diese Routine ist hier definiert, damit der Compiler als eigenes Segment // geladen werden kann. @@ -131,6 +432,7 @@ BOOL SbModule::Compile() if( bRet ) { pBasic->ClearAllModuleVars(); + RemoveVars(); // remove 'this' Modules variables // clear all method statics for( USHORT i = 0; i < pMethods->Count(); i++ ) { @@ -154,6 +456,10 @@ BOOL SbModule::Compile() dbg_SaveDisassembly( this ); #endif +#ifdef DBG_TRACE_BASIC + lcl_PrepareTraceForModule( this ); +#endif + return bRet; } diff --git a/basic/source/inc/namecont.hxx b/basic/source/inc/namecont.hxx index ac1199f6c233..7fd6eb06f607 100644 --- a/basic/source/inc/namecont.hxx +++ b/basic/source/inc/namecont.hxx @@ -60,7 +60,7 @@ #include <cppuhelper/implbase2.hxx> #include <cppuhelper/compbase8.hxx> #include <cppuhelper/interfacecontainer.hxx> -#include <com/sun/star/script/XVBACompat.hpp> +#include <com/sun/star/script/vba/XVBACompatibility.hpp> class BasicManager; @@ -74,7 +74,7 @@ typedef ::cppu::WeakComponentImplHelper8< ::com::sun::star::script::XLibraryContainerExport, ::com::sun::star::script::XLibraryContainer3, ::com::sun::star::container::XContainer, - ::com::sun::star::script::XVBACompat, + ::com::sun::star::script::vba::XVBACompatibility, ::com::sun::star::lang::XServiceInfo > LibraryContainerHelper; typedef ::cppu::WeakImplHelper2< ::com::sun::star::container::XNameContainer, @@ -507,9 +507,9 @@ public: throw (::com::sun::star::uno::RuntimeException); virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException) = 0; - // Methods XVBACompat - virtual ::sal_Bool SAL_CALL getVBACompatModeOn() throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL setVBACompatModeOn( ::sal_Bool _vbacompatmodeon ) throw (::com::sun::star::uno::RuntimeException); + // Methods XVBACompatibility + virtual ::sal_Bool SAL_CALL getVBACompatibilityMode() throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setVBACompatibilityMode( ::sal_Bool _vbacompatmodeon ) throw (::com::sun::star::uno::RuntimeException); }; class LibraryContainerMethodGuard diff --git a/basic/source/inc/sbtrace.hxx b/basic/source/inc/sbtrace.hxx new file mode 100755 index 000000000000..e8a482c2f6e9 --- /dev/null +++ b/basic/source/inc/sbtrace.hxx @@ -0,0 +1,42 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _SBTRACE_HXX +#define _SBTRACE_HXX + +// #define DBG_TRACE_BASIC + +#ifdef DBG_TRACE_BASIC +void dbg_InitTrace( void ); +void dbg_traceStep( SbModule* pModule, UINT32 nPC, INT32 nCallLvl ); +void dbg_traceNotifyCall( SbModule* pModule, SbMethod* pMethod, INT32 nCallLvl, bool bLeave = false ); +void dbg_traceNotifyError( SbError nTraceErr, const String& aTraceErrMsg, bool bTraceErrHandled, INT32 nCallLvl ); +void dbg_RegisterTraceTextForPC( SbModule* pModule, UINT32 nPC, + const String& aTraceStr_STMNT, const String& aTraceStr_PCode ); +#endif + +#endif diff --git a/basic/source/inc/scriptcont.hxx b/basic/source/inc/scriptcont.hxx index d184a2d558e2..091fbc24cdbe 100644 --- a/basic/source/inc/scriptcont.hxx +++ b/basic/source/inc/scriptcont.hxx @@ -30,7 +30,7 @@ #include "namecont.hxx" #include <basic/basmgr.hxx> -#include <com/sun/star/script/XVBAModuleInfo.hpp> +#include <com/sun/star/script/vba/XVBAModuleInfo.hpp> #include <comphelper/uno3.hxx> class BasicManager; @@ -141,7 +141,7 @@ public: //============================================================================ typedef std::hash_map< ::rtl::OUString, ::com::sun::star::script::ModuleInfo, ::rtl::OUStringHash, ::std::equal_to< ::rtl::OUString > > ModuleInfoMap; -typedef ::cppu::ImplHelper1 < ::com::sun::star::script::XVBAModuleInfo +typedef ::cppu::ImplHelper1 < ::com::sun::star::script::vba::XVBAModuleInfo > SfxScriptLibrary_BASE; class SfxScriptLibrary : public SfxLibrary diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx index 36fbda5c9097..1a60a5d79a45 100644 --- a/basic/source/runtime/methods.cxx +++ b/basic/source/runtime/methods.cxx @@ -4134,8 +4134,7 @@ RTLFUNC(Load) { if( pObj->IsA( TYPE( SbUserFormModule ) ) ) { - SbUserFormModule* pFormModule = ( SbUserFormModule* )pObj; - pFormModule->load(); + ((SbUserFormModule*)pObj)->Load(); } else if( pObj->IsA( TYPE( SbxObject ) ) ) { diff --git a/basic/source/runtime/props.cxx b/basic/source/runtime/props.cxx index cec74444e7a2..663d12fbcd72 100644 --- a/basic/source/runtime/props.cxx +++ b/basic/source/runtime/props.cxx @@ -76,6 +76,13 @@ RTLFUNC(False) rPar.Get(0)->PutBool( FALSE ); } +RTLFUNC(Empty) +{ + (void)pBasic; + (void)bWrite; + (void)rPar; +} + RTLFUNC(Nothing) { (void)pBasic; diff --git a/basic/source/runtime/rtlproto.hxx b/basic/source/runtime/rtlproto.hxx index 1a1ae4f32283..5437654f69a0 100644 --- a/basic/source/runtime/rtlproto.hxx +++ b/basic/source/runtime/rtlproto.hxx @@ -38,6 +38,7 @@ extern RTLFUNC(Date); extern RTLFUNC(Err); extern RTLFUNC(Erl); extern RTLFUNC(False); +extern RTLFUNC(Empty); extern RTLFUNC(Nothing); extern RTLFUNC(Null); extern RTLFUNC(True); diff --git a/basic/source/runtime/runtime.cxx b/basic/source/runtime/runtime.cxx index c3419adbfdb3..1bb6fb82e113 100755 --- a/basic/source/runtime/runtime.cxx +++ b/basic/source/runtime/runtime.cxx @@ -44,6 +44,7 @@ #include <com/sun/star/container/XEnumerationAccess.hpp> #include "sbunoobj.hxx" #include "errobject.hxx" +#include "sbtrace.hxx" using namespace ::com::sun::star; @@ -720,6 +721,12 @@ BOOL SbiRuntime::Step() if( pInst->IsReschedule() && bStaticGlobalEnableReschedule ) Application::Reschedule(); } + +#ifdef DBG_TRACE_BASIC + UINT32 nPC = ( pCode - (const BYTE* )pImg->GetCode() ); + dbg_traceStep( pMod, nPC, pINST->nCallLvl ); +#endif + SbiOpcode eOp = (SbiOpcode ) ( *pCode++ ); UINT32 nOp1, nOp2; if( eOp <= SbOP0_END ) @@ -756,6 +763,11 @@ BOOL SbiRuntime::Step() // (insbesondere nicht nach Compiler-Fehlern zur Laufzeit) if( nError && bRun ) { +#ifdef DBG_TRACE_BASIC + SbError nTraceErr = nError; + String aTraceErrMsg = GetSbData()->aErrMsg; + bool bTraceErrHandled = true; +#endif SbError err = nError; ClearExprStack(); nError = 0; @@ -836,12 +848,19 @@ BOOL SbiRuntime::Step() // Kein Error-Hdl gefunden -> altes Vorgehen else { +#ifdef DBG_TRACE_BASIC + bTraceErrHandled = false; +#endif pInst->Abort(); } // ALT: Nur // pInst->Abort(); } + +#ifdef DBG_TRACE_BASIC + dbg_traceNotifyError( nTraceErr, aTraceErrMsg, bTraceErrHandled, pINST->nCallLvl ); +#endif } } return bRun; diff --git a/basic/source/runtime/stdobj.cxx b/basic/source/runtime/stdobj.cxx index 60d2e9cf448d..4455901bfeba 100644 --- a/basic/source/runtime/stdobj.cxx +++ b/basic/source/runtime/stdobj.cxx @@ -221,6 +221,7 @@ static Methods aMethods[] = { { "FileSpec", SbxSTRING, 0,NULL,0 }, { "DumpAll", SbxINTEGER, _OPT, NULL,0 }, +{ "Empty", SbxVARIANT, _CPROP, RTLNAME(Empty),0 }, { "EqualUnoObjects",SbxBOOL, 2 | _FUNCTION, RTLNAME(EqualUnoObjects),0 }, { "Variant", SbxVARIANT, 0,NULL,0 }, { "Variant", SbxVARIANT, 0,NULL,0 }, diff --git a/basic/source/runtime/step0.cxx b/basic/source/runtime/step0.cxx index 1d9333ff7555..29965c7e9da5 100644 --- a/basic/source/runtime/step0.cxx +++ b/basic/source/runtime/step0.cxx @@ -312,9 +312,21 @@ void SbiRuntime::StepIS() { SbxVariableRef refVar1 = PopVar(); SbxVariableRef refVar2 = PopVar(); - BOOL bRes = BOOL( - refVar1->GetType() == SbxOBJECT - && refVar2->GetType() == SbxOBJECT ); + + SbxDataType eType1 = refVar1->GetType(); + SbxDataType eType2 = refVar2->GetType(); + if ( eType1 == SbxEMPTY ) + { + refVar1->Broadcast( SBX_HINT_DATAWANTED ); + eType1 = refVar1->GetType(); + } + if ( eType2 == SbxEMPTY ) + { + refVar2->Broadcast( SBX_HINT_DATAWANTED ); + eType2 = refVar2->GetType(); + } + + BOOL bRes = BOOL( eType1 == SbxOBJECT && eType2 == SbxOBJECT ); if ( bVBAEnabled && !bRes ) Error( SbERR_INVALID_USAGE_OBJECT ); bRes = ( bRes && refVar1->GetObject() == refVar2->GetObject() ); @@ -520,9 +532,10 @@ void SbiRuntime::StepSET_Impl( SbxVariableRef& refVal, SbxVariableRef& refVar, b // Handle withevents BOOL bWithEvents = refVar->IsSet( SBX_WITH_EVENTS ); - Reference< XInterface > xComListener; - if( bWithEvents ) + if ( bWithEvents ) { + Reference< XInterface > xComListener; + SbxBase* pObj = refVal->GetObject(); SbUnoObject* pUnoObj = (pObj != NULL) ? PTR_CAST(SbUnoObject,pObj) : NULL; if( pUnoObj != NULL ) @@ -533,13 +546,17 @@ void SbiRuntime::StepSET_Impl( SbxVariableRef& refVal, SbxVariableRef& refVar, b ::rtl::OUString aPrefix = refVar->GetName(); SbxObjectRef xScopeObj = refVar->GetParent(); xComListener = createComListener( aControlAny, aVBAType, aPrefix, xScopeObj ); - } - } - *refVar = *refVal; + refVal->SetDeclareClassName( aDeclareClassName ); + refVal->SetComListener( xComListener ); // Hold reference + } - if( bWithEvents ) - refVar->SetComListener( xComListener ); // Hold reference + *refVar = *refVal; + } + else + { + *refVar = *refVal; + } // lhs is a property who's value is currently (Empty e.g. no broadcast yet) // in this case if there is a default prop involved the value of the diff --git a/basic/source/runtime/step2.cxx b/basic/source/runtime/step2.cxx index 72ea67dd8db4..587b0ae7a590 100644..100755 --- a/basic/source/runtime/step2.cxx +++ b/basic/source/runtime/step2.cxx @@ -263,8 +263,10 @@ SbxVariable* SbiRuntime::FindElement pElem = pNew; } // Index-Access bei UnoObjekten beruecksichtigen - /* - else if( pElem->ISA(SbUnoProperty) ) + // definitely we want this for VBA where properties are often + // collections ( which need index access ), but lets only do + // this if we actually have params following + else if( bVBAEnabled && pElem->ISA(SbUnoProperty) && pElem->GetParameters() ) { // pElem auf eine Ref zuweisen, um ggf. eine Temp-Var zu loeschen SbxVariableRef refTemp = pElem; @@ -274,7 +276,6 @@ SbxVariable* SbiRuntime::FindElement pElem->SetParameters( NULL ); // sonst bleibt Ref auf sich selbst pElem = pNew; } - */ } return CheckArray( pElem ); } @@ -377,7 +378,8 @@ void SbiRuntime::SetupArgs( SbxVariable* p, UINT32 nOp1 ) bool bError_ = true; SbUnoMethod* pUnoMethod = PTR_CAST(SbUnoMethod,p); - if( pUnoMethod ) + SbUnoProperty* pUnoProperty = PTR_CAST(SbUnoProperty,p); + if( pUnoMethod || pUnoProperty ) { SbUnoObject* pParentUnoObj = PTR_CAST( SbUnoObject,p->GetParent() ); if( pParentUnoObj ) @@ -677,7 +679,18 @@ void SbiRuntime::StepPARAM( UINT32 nOp1, UINT32 nOp2 ) while( iLoop >= nParamCount ) { p = new SbxVariable(); - p->PutErr( 448 ); // Wie in VB: Error-Code 448 (SbERR_NAMED_NOT_FOUND) + + if( SbiRuntime::isVBAEnabled() && + (t == SbxOBJECT || t == SbxSTRING) ) + { + if( t == SbxOBJECT ) + p->PutObject( NULL ); + else + p->PutString( String() ); + } + else + p->PutErr( 448 ); // Wie in VB: Error-Code 448 (SbERR_NAMED_NOT_FOUND) + refParams->Put( p, iLoop ); iLoop--; } @@ -1157,15 +1170,26 @@ void SbiRuntime::StepGLOBAL( UINT32 nOp1, UINT32 nOp2 ) StepPUBLIC_Impl( nOp1, nOp2, true ); String aName( pImg->GetString( static_cast<short>( nOp1 ) ) ); - SbxDataType t = (SbxDataType)(SbxDataType)(nOp2 & 0xffff);; - BOOL bFlag = rBasic.IsSet( SBX_NO_MODIFY ); + SbxDataType t = (SbxDataType)(nOp2 & 0xffff); + + // Store module scope variables at module scope + // in non vba mode these are stored at the library level :/ + // not sure if this really should not be enabled for ALL basic + SbxObject* pStorage = &rBasic; + if ( SbiRuntime::isVBAEnabled() ) + { + pStorage = pMod; + pMod->AddVarName( aName ); + } + + BOOL bFlag = pStorage->IsSet( SBX_NO_MODIFY ); rBasic.SetFlag( SBX_NO_MODIFY ); - SbxVariableRef p = rBasic.Find( aName, SbxCLASS_PROPERTY ); + SbxVariableRef p = pStorage->Find( aName, SbxCLASS_PROPERTY ); if( p.Is() ) - rBasic.Remove (p); - p = rBasic.Make( aName, SbxCLASS_PROPERTY, t ); + pStorage->Remove (p); + p = pStorage->Make( aName, SbxCLASS_PROPERTY, t ); if( !bFlag ) - rBasic.ResetFlag( SBX_NO_MODIFY ); + pStorage->ResetFlag( SBX_NO_MODIFY ); if( p ) { p->SetFlag( SBX_DONTSTORE ); diff --git a/basic/source/uno/namecont.cxx b/basic/source/uno/namecont.cxx index e1ad8b6b4308..c31aed1f8ef7 100644 --- a/basic/source/uno/namecont.cxx +++ b/basic/source/uno/namecont.cxx @@ -2793,7 +2793,6 @@ OUString SfxLibraryContainer::expand_url( const OUString& url ) } } - //XLibraryContainer3 OUString SAL_CALL SfxLibraryContainer::getOriginalLibraryLinkURL( const OUString& Name ) throw (IllegalArgumentException, NoSuchElementException, RuntimeException) @@ -2808,12 +2807,13 @@ OUString SAL_CALL SfxLibraryContainer::getOriginalLibraryLinkURL( const OUString } -::sal_Bool SAL_CALL SfxLibraryContainer::getVBACompatModeOn() throw (RuntimeException) +// XVBACompatibility +::sal_Bool SAL_CALL SfxLibraryContainer::getVBACompatibilityMode() throw (RuntimeException) { return mbVBACompat; } -void SAL_CALL SfxLibraryContainer::setVBACompatModeOn( ::sal_Bool _vbacompatmodeon ) throw (RuntimeException) +void SAL_CALL SfxLibraryContainer::setVBACompatibilityMode( ::sal_Bool _vbacompatmodeon ) throw (RuntimeException) { BasicManager* pBasMgr = getBasicManager(); if( pBasMgr ) diff --git a/basic/source/uno/scriptcont.cxx b/basic/source/uno/scriptcont.cxx index 5622adc19af1..f7091d1c1a0b 100644 --- a/basic/source/uno/scriptcont.cxx +++ b/basic/source/uno/scriptcont.cxx @@ -216,8 +216,7 @@ void SAL_CALL SfxScriptLibraryContainer::writeLibraryElement Any aElement = xLib->getByName( aElementName ); aElement >>= aMod.aCode; - Reference < script::XVBAModuleInfo > xModInfo( xLib, UNO_QUERY ); - + Reference< script::vba::XVBAModuleInfo > xModInfo( xLib, UNO_QUERY ); if( xModInfo.is() && xModInfo->hasModuleInfo( aElementName ) ) { script::ModuleInfo aModInfo = xModInfo->getModuleInfo( aElementName ); @@ -312,9 +311,9 @@ Any SAL_CALL SfxScriptLibraryContainer::importLibraryElement // aMod.aName ignored if( aMod.aModuleType.getLength() > 0 ) { - if( !getVBACompatModeOn() ) + if( !getVBACompatibilityMode() ) { - setVBACompatModeOn( sal_True ); + setVBACompatibilityMode( sal_True ); Any aGlobs; Sequence< Any > aArgs(1); @@ -381,8 +380,7 @@ Any SAL_CALL SfxScriptLibraryContainer::importLibraryElement } } - Reference< script::XVBAModuleInfo > xVBAModuleInfo( xLib, - UNO_QUERY ); + Reference< script::vba::XVBAModuleInfo > xVBAModuleInfo( xLib, UNO_QUERY ); if( xVBAModuleInfo.is() ) { if( xVBAModuleInfo->hasModuleInfo( aElementName ) ) diff --git a/formula/inc/formula/errorcodes.hxx b/formula/inc/formula/errorcodes.hxx index f9b04e012fab..f08af17e095e 100644 --- a/formula/inc/formula/errorcodes.hxx +++ b/formula/inc/formula/errorcodes.hxx @@ -64,7 +64,8 @@ const USHORT errInterpOverflow = 527; // Not displayed, temporary for TrackFormulas, // Cell depends on another cell that has errCircularReference const USHORT errTrackFromCircRef = 528; -// Interpreter internal: existing cell has no value but value queried +// ScInterpreter internal: no numeric value but numeric queried. If this is +// set as mnStringNoValueError no error is generated but 0 returned. const USHORT errCellNoValue = 529; // Interpreter: needed AddIn not found const USHORT errNoAddin = 530; @@ -74,6 +75,11 @@ const USHORT errNoMacro = 531; const USHORT errDivisionByZero = 532; // #DIV/0! // Compiler: a non-simple (str,err,val) value was put in an array const USHORT errNestedArray = 533; +// ScInterpreter internal: no numeric value but numeric queried. If this is +// temporarily (!) set as mnStringNoValueError, the error is generated and can +// be used to distinguish that condition from all other (inherited) errors. Do +// not use for anything else! Never push or inherit the error otherwise! +const USHORT errNotNumericString = 534; // Interpreter: NA() not available condition, not a real error const USHORT NOTAVAILABLE = 0x7fff; diff --git a/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu b/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu index 33e5109405d0..5c72d948436f 100644 --- a/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu +++ b/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="UTF-8"?> +<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE oor:component-data SYSTEM "../../../../../component-update.dtd"> <oor:component-data oor:name="CalcCommands" oor:package="org.openoffice.Office.UI" xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <node oor:name="UserInterface"> @@ -160,6 +160,14 @@ <value xml:lang="en-US">~Select...</value> </prop> </node> + <node oor:name=".uno:TableEvents" oor:op="replace"> + <prop oor:name="Label" oor:type="xs:string"> + <value xml:lang="en-US">Sheet ~Events...</value> + </prop> + <prop oor:name="ContextLabel" oor:type="xs:string"> + <value xml:lang="en-US">~Events...</value> + </prop> + </node> <node oor:name=".uno:DataPilotFilter" oor:op="replace"> <prop oor:name="Label" oor:type="xs:string"> <value xml:lang="en-US">DataPilot Filter</value> diff --git a/oovbaapi/ooo/vba/XApplicationBase.idl b/oovbaapi/ooo/vba/XApplicationBase.idl index 7f59ddb75247..d9d32e02f2ce 100644 --- a/oovbaapi/ooo/vba/XApplicationBase.idl +++ b/oovbaapi/ooo/vba/XApplicationBase.idl @@ -24,21 +24,15 @@ * for a copy of the LGPLv3 License. * ************************************************************************/ + #ifndef __ooo_vba_XApplicationBase_idl__ #define __ooo_vba_XApplicationBase_idl__ -#ifndef __com_sun_star_uno_XInterface_idl__ -#include <com/sun/star/uno/XInterface.idl> -#endif - -#ifndef __ooo_vba_XHelperInterface_idl__ #include <ooo/vba/XHelperInterface.idl> -#endif module ooo { module vba { -//============================================================================= - +//============================================================================= interface XApplicationBase { @@ -47,8 +41,9 @@ interface XApplicationBase [attribute] boolean ScreenUpdating; [attribute] boolean DisplayStatusBar; [attribute] boolean Interactive; + [attribute] boolean Visible; + [attribute, readonly] string Version; - //mbn [attribute, readonly] any VBE; [attribute, readonly] any VBProjects; @@ -61,6 +56,8 @@ interface XApplicationBase void Undo(); }; +//============================================================================= + }; }; #endif diff --git a/oovbaapi/ooo/vba/excel/XApplication.idl b/oovbaapi/ooo/vba/excel/XApplication.idl index 39693a37511c..6f513ae64577 100644 --- a/oovbaapi/ooo/vba/excel/XApplication.idl +++ b/oovbaapi/ooo/vba/excel/XApplication.idl @@ -64,6 +64,7 @@ interface XApplication [attribute] any CutCopyMode; [attribute] any StatusBar; [attribute] long Cursor; + [attribute] boolean EnableEvents; void setDefaultFilePath([in] string DefaultFilePath) raises(com::sun::star::script::BasicErrorException); diff --git a/oovbaapi/ooo/vba/excel/XWorksheet.idl b/oovbaapi/ooo/vba/excel/XWorksheet.idl index 271cd81d4d0e..fb6261bc06c0 100644 --- a/oovbaapi/ooo/vba/excel/XWorksheet.idl +++ b/oovbaapi/ooo/vba/excel/XWorksheet.idl @@ -114,6 +114,7 @@ interface XWorksheet XRange Rows([in] any aIndex); XRange Columns([in] any aIndex); any Hyperlinks( [in] any aIndex ); + any Names( [in] any Index ); any Evaluate( [in] string Name); diff --git a/oovbaapi/ooo/vba/excel/makefile.mk b/oovbaapi/ooo/vba/excel/makefile.mk index 12dcf025e489..251588086701 100644 --- a/oovbaapi/ooo/vba/excel/makefile.mk +++ b/oovbaapi/ooo/vba/excel/makefile.mk @@ -29,7 +29,7 @@ PRJ=..$/..$/.. PRJNAME=oovapi TARGET=excel -PACKAGE=ooo$/vba$/Excel +PACKAGE=ooo$/vba$/excel # --- Settings ----------------------------------------------------- .INCLUDE : $(PRJ)$/util$/makefile.pmk diff --git a/oovbaapi/ooo/vba/makefile.mk b/oovbaapi/ooo/vba/makefile.mk index 75f6465bf4c0..4f6d378cfe3f 100644 --- a/oovbaapi/ooo/vba/makefile.mk +++ b/oovbaapi/ooo/vba/makefile.mk @@ -61,9 +61,8 @@ IDLFILES=\ XFontBase.idl\ XDialogsBase.idl\ XDialogBase.idl\ - XPageSetupBase.idl \ - XVBAAppService.idl\ - XVBADocService.idl\ + XPageSetupBase.idl + # ------------------------------------------------------------------ .ENDIF .INCLUDE : target.mk diff --git a/oovbaapi/ooo/vba/word/makefile.mk b/oovbaapi/ooo/vba/word/makefile.mk index e3a19e678414..543e99f7c538 100644 --- a/oovbaapi/ooo/vba/word/makefile.mk +++ b/oovbaapi/ooo/vba/word/makefile.mk @@ -29,7 +29,7 @@ PRJ=..$/..$/.. PRJNAME=oovapi TARGET=word -PACKAGE=ooo$/vba$/Word +PACKAGE=ooo$/vba$/word # --- Settings ----------------------------------------------------- .INCLUDE : $(PRJ)$/util$/makefile.pmk diff --git a/oovbaapi/prj/d.lst b/oovbaapi/prj/d.lst index ac5924e2d684..86e801a15d93 100644 --- a/oovbaapi/prj/d.lst +++ b/oovbaapi/prj/d.lst @@ -8,7 +8,7 @@ mkdir: %COMMON_DEST%\idl%_EXT%\ooo\vba\word ..\%__SRC%\ucr\oovbaapi.db %_DEST%\bin%_EXT%\oovbaapi.rdb -..\ooo\vba\*.idl %COMMON_DEST%\idl%_EXT%\ooo\vba\ +..\ooo\vba\*.idl %COMMON_DEST%\idl%_EXT%\ooo\vba ..\ooo\vba\constants\*.idl %COMMON_DEST%\idl%_EXT%\ooo\vba\constants ..\ooo\vba\excel\*.idl %COMMON_DEST%\idl%_EXT%\ooo\vba\excel ..\ooo\vba\msforms\*.idl %COMMON_DEST%\idl%_EXT%\ooo\vba\msforms diff --git a/sfx2/inc/sfx2/objsh.hxx b/sfx2/inc/sfx2/objsh.hxx index 63eb9e8c876f..9473ac126bd7 100755..100644 --- a/sfx2/inc/sfx2/objsh.hxx +++ b/sfx2/inc/sfx2/objsh.hxx @@ -293,6 +293,7 @@ public: sal_Bool IsReadOnlyUI() const; void SetNoName(); sal_Bool IsInModalMode() const; + sal_Bool IsInPrepareClose() const; //<!--Added by PengYunQuan for Validity Cell Range Picker virtual sal_Bool AcceptStateUpdate() const; //-->Added by PengYunQuan for Validity Cell Range Picker @@ -346,6 +347,9 @@ public: const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage ); virtual void UpdateLinks(); + // called for a few slots like SID_SAVE[AS]DOC, SID_PRINTDOC[DIRECT], derived classes may abort the action + virtual sal_Bool QuerySlotExecutable( USHORT nSlotId ); + sal_Bool SaveChildren(BOOL bObjectsOnly=FALSE); sal_Bool SaveAsChildren( SfxMedium &rMedium ); sal_Bool SwitchChildrenPersistance( diff --git a/sfx2/source/doc/objserv.cxx b/sfx2/source/doc/objserv.cxx index c063546da1c7..066f366b09bd 100644 --- a/sfx2/source/doc/objserv.cxx +++ b/sfx2/source/doc/objserv.cxx @@ -489,6 +489,13 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq) case SID_SAVEASDOC: case SID_SAVEDOC: { + // derived class may decide to abort this + if( !QuerySlotExecutable( nId ) ) + { + rReq.SetReturnValue( SfxBoolItem( 0, FALSE ) ); + return; + } + //!! detaillierte Auswertung eines Fehlercodes SfxObjectShellRef xLock( this ); @@ -895,7 +902,7 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq) rReq.Done(); } -//-------------------------------------------------------------------- +//------------------------------------------------------------------------- void SfxObjectShell::GetState_Impl(SfxItemSet &rSet) { diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx index 49188defc4f1..6c4bdf56ba26 100644 --- a/sfx2/source/doc/objstor.cxx +++ b/sfx2/source/doc/objstor.cxx @@ -195,6 +195,13 @@ sal_Bool SfxObjectShell::SaveAs( SfxMedium& rMedium ) //------------------------------------------------------------------------- +sal_Bool SfxObjectShell::QuerySlotExecutable( USHORT /*nSlotId*/ ) +{ + return sal_True; +} + +//------------------------------------------------------------------------- + sal_Bool GetPasswd_Impl( const SfxItemSet* pSet, ::rtl::OUString& rPasswd ) { const SfxPoolItem* pItem = NULL; diff --git a/sfx2/source/doc/objxtor.cxx b/sfx2/source/doc/objxtor.cxx index f202266dd74e..b7567b89f02f 100755..100644 --- a/sfx2/source/doc/objxtor.cxx +++ b/sfx2/source/doc/objxtor.cxx @@ -526,6 +526,13 @@ SfxObjectShell* SfxObjectShell::Current() return pFrame ? pFrame->GetObjectShell() : 0; } +//------------------------------------------------------------------------- + +sal_Bool SfxObjectShell::IsInPrepareClose() const +{ + return pImp->bInPrepareClose; +} + //------------------------------------------------------------------------ struct BoolEnv_Impl diff --git a/sfx2/source/view/viewprn.cxx b/sfx2/source/view/viewprn.cxx index 5b317e4b770b..4ed0173be8e1 100644 --- a/sfx2/source/view/viewprn.cxx +++ b/sfx2/source/view/viewprn.cxx @@ -700,6 +700,14 @@ void SfxViewShell::ExecPrint_Impl( SfxRequest &rReq ) case SID_PRINTDOCDIRECT: { SfxObjectShell* pDoc = GetObjectShell(); + + // derived class may decide to abort this + if( !pDoc->QuerySlotExecutable( nId ) ) + { + rReq.SetReturnValue( SfxBoolItem( 0, FALSE ) ); + return; + } + bool bDetectHidden = ( !bSilent && pDoc ); if ( bDetectHidden && pDoc->QueryHiddenInformation( WhenPrinting, NULL ) != RET_YES ) break; diff --git a/svx/inc/svx/dialogs.hrc b/svx/inc/svx/dialogs.hrc index d193652b57fc..fd7561bb7192 100755 --- a/svx/inc/svx/dialogs.hrc +++ b/svx/inc/svx/dialogs.hrc @@ -956,7 +956,9 @@ #define RID_SVXSTR_OUTLINENUM_DESCRIPTION_6 (RID_SVXSTR_OUTLINENUM_DESCRIPTIONS + 6)//? #define RID_SVXSTR_OUTLINENUM_DESCRIPTION_7 (RID_SVXSTR_OUTLINENUM_DESCRIPTIONS + 7)//? -#define RID_SVXSTR_NEXTFREE (RID_SVX_START + 1190) +#define RID_SVXSTR_FINDBAR_FIND (RID_SVX_START + 1190) + +#define RID_SVXSTR_NEXTFREE (RID_SVX_START + 1191) // ---------------------------------------------------------------------------- // if we have _a_lot_ time, we should group the resource ids by type, instead diff --git a/svx/source/tbxctrls/makefile.mk b/svx/source/tbxctrls/makefile.mk index 73a178d97594..a9ea745f3cc0 100644 --- a/svx/source/tbxctrls/makefile.mk +++ b/svx/source/tbxctrls/makefile.mk @@ -74,6 +74,7 @@ SRC1FILES = \ lboxctrl.src \ linectrl.src \ tbcontrl.src \ + tbunosearchcontrollers.src \ tbxdraw.src \ grafctrl.src diff --git a/svx/source/tbxctrls/tbunosearchcontrollers.cxx b/svx/source/tbxctrls/tbunosearchcontrollers.cxx index 5dcaf6fd5e72..e446d3d3b9d5 100644 --- a/svx/source/tbxctrls/tbunosearchcontrollers.cxx +++ b/svx/source/tbxctrls/tbunosearchcontrollers.cxx @@ -29,6 +29,8 @@ #include "precompiled_svx.hxx" #include "tbunosearchcontrollers.hxx" +#include <svx/dialogs.hrc> +#include <svx/dialmgr.hxx> #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/frame/XLayoutManager.hpp> @@ -91,7 +93,7 @@ FindTextFieldControl::~FindTextFieldControl() void FindTextFieldControl::InitControls_Impl() { - SetText( String( ::rtl::OUString::createFromAscii("Find") ) ); + SetText( SVX_RESSTR( RID_SVXSTR_FINDBAR_FIND ) ); SetControlForeground(GetSettings().GetStyleSettings().GetDisableColor()); EnableAutocomplete(TRUE, TRUE); @@ -174,7 +176,7 @@ long FindTextFieldControl::PreNotify( NotifyEvent& rNEvt ) case EVENT_LOSEFOCUS: if ( GetText().Len() == 0 ) { - SetText( String( ::rtl::OUString::createFromAscii("Find") ) ); + SetText( SVX_RESSTR( RID_SVXSTR_FINDBAR_FIND ) ); SetControlForeground(GetSettings().GetStyleSettings().GetDisableColor()); m_bToClearTextField = sal_True; } diff --git a/svx/source/tbxctrls/tbunosearchcontrollers.src b/svx/source/tbxctrls/tbunosearchcontrollers.src new file mode 100644 index 000000000000..9a256ae0cabb --- /dev/null +++ b/svx/source/tbxctrls/tbunosearchcontrollers.src @@ -0,0 +1,33 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <svx/dialogs.hrc> + +String RID_SVXSTR_FINDBAR_FIND +{ + Text [ en-US ] = "Find" ; +}; diff --git a/vbahelper/inc/vbahelper/vbaapplicationbase.hxx b/vbahelper/inc/vbahelper/vbaapplicationbase.hxx index e2a5a3bff5da..6902bc7b5042 100644 --- a/vbahelper/inc/vbahelper/vbaapplicationbase.hxx +++ b/vbahelper/inc/vbahelper/vbaapplicationbase.hxx @@ -53,17 +53,20 @@ public: virtual void SAL_CALL setScreenUpdating(sal_Bool bUpdate) throw (css::uno::RuntimeException); virtual sal_Bool SAL_CALL getDisplayStatusBar() throw (css::uno::RuntimeException); virtual void SAL_CALL setDisplayStatusBar(sal_Bool bDisplayStatusBar) throw (css::uno::RuntimeException); - virtual ::sal_Bool SAL_CALL getInteractive() throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL setInteractive( ::sal_Bool bInteractive ) throw (::com::sun::star::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL getInteractive() throw (css::uno::RuntimeException); + virtual void SAL_CALL setInteractive( ::sal_Bool bInteractive ) throw (css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL getVisible() throw (css::uno::RuntimeException); + virtual void SAL_CALL setVisible( ::sal_Bool bVisible ) throw (css::uno::RuntimeException); virtual css::uno::Any SAL_CALL CommandBars( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); virtual ::rtl::OUString SAL_CALL getVersion() throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getVBE() throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getVBProjects() throw (css::uno::RuntimeException); + virtual void SAL_CALL Run( const ::rtl::OUString& MacroName, const css::uno::Any& varg1, const css::uno::Any& varg2, const css::uno::Any& varg3, const css::uno::Any& varg4, const css::uno::Any& varg5, const css::uno::Any& varg6, const css::uno::Any& varg7, const css::uno::Any& varg8, const css::uno::Any& varg9, const css::uno::Any& varg10, const css::uno::Any& varg11, const css::uno::Any& varg12, const css::uno::Any& varg13, const css::uno::Any& varg14, const css::uno::Any& varg15, const css::uno::Any& varg16, const css::uno::Any& varg17, const css::uno::Any& varg18, const css::uno::Any& varg19, const css::uno::Any& varg20, const css::uno::Any& varg21, const css::uno::Any& varg22, const css::uno::Any& varg23, const css::uno::Any& varg24, const css::uno::Any& varg25, const css::uno::Any& varg26, const css::uno::Any& varg27, const css::uno::Any& varg28, const css::uno::Any& varg29, const css::uno::Any& varg30 ) throw (css::uno::RuntimeException); - virtual void SAL_CALL OnTime( const ::com::sun::star::uno::Any& aEarliestTime, const ::rtl::OUString& aFunction, const ::com::sun::star::uno::Any& aLatestTime, const ::com::sun::star::uno::Any& aSchedule ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL OnTime( const css::uno::Any& aEarliestTime, const ::rtl::OUString& aFunction, const css::uno::Any& aLatestTime, const css::uno::Any& aSchedule ) throw (css::uno::RuntimeException); virtual float SAL_CALL CentimetersToPoints( float _Centimeters ) throw (css::uno::RuntimeException); - virtual void SAL_CALL Undo( ) throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL Quit( ) throw (::com::sun::star::uno::RuntimeException); - virtual css::uno::Any SAL_CALL getVBE() throw (css::uno::RuntimeException); - virtual css::uno::Any SAL_CALL SAL_CALL getVBProjects() throw (css::uno::RuntimeException); + virtual void SAL_CALL Undo() throw (css::uno::RuntimeException); + virtual void SAL_CALL Quit() throw (css::uno::RuntimeException); // XHelperInterface virtual rtl::OUString& getServiceImplName(); diff --git a/vbahelper/inc/vbahelper/vbacollectionimpl.hxx b/vbahelper/inc/vbahelper/vbacollectionimpl.hxx index 36102116c7b3..5bd58b44adaf 100644 --- a/vbahelper/inc/vbahelper/vbacollectionimpl.hxx +++ b/vbahelper/inc/vbahelper/vbacollectionimpl.hxx @@ -133,11 +133,12 @@ protected: class VBAHELPER_DLLPUBLIC EnumerationHelperImpl : public EnumerationHelper_BASE { protected: + css::uno::WeakReference< ov::XHelperInterface > m_xParent; css::uno::Reference< css::uno::XComponentContext > m_xContext; css::uno::Reference< css::container::XEnumeration > m_xEnumeration; public: - EnumerationHelperImpl( const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::container::XEnumeration >& xEnumeration ) throw ( css::uno::RuntimeException ) : m_xContext( xContext ), m_xEnumeration( xEnumeration ) { } + EnumerationHelperImpl( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::container::XEnumeration >& xEnumeration ) throw ( css::uno::RuntimeException ) : m_xParent( xParent ), m_xContext( xContext ), m_xEnumeration( xEnumeration ) { } virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (css::uno::RuntimeException) { return m_xEnumeration->hasMoreElements(); } }; diff --git a/vbahelper/inc/vbahelper/vbadocumentbase.hxx b/vbahelper/inc/vbahelper/vbadocumentbase.hxx index 7131e1963b26..2588b7da1720 100644 --- a/vbahelper/inc/vbahelper/vbadocumentbase.hxx +++ b/vbahelper/inc/vbahelper/vbadocumentbase.hxx @@ -52,9 +52,7 @@ public: virtual ::rtl::OUString SAL_CALL getFullName() throw (css::uno::RuntimeException); virtual sal_Bool SAL_CALL getSaved() throw (css::uno::RuntimeException); virtual void SAL_CALL setSaved( sal_Bool bSave ) throw (css::uno::RuntimeException); - - virtual css::uno::Any SAL_CALL getVBProject() throw (css::uno::RuntimeException); // Michhael E. Bohn - + virtual css::uno::Any SAL_CALL getVBProject() throw (css::uno::RuntimeException); // Methods virtual void SAL_CALL Close( const css::uno::Any &bSaveChanges, diff --git a/vbahelper/inc/vbahelper/vbaeventshelperbase.hxx b/vbahelper/inc/vbahelper/vbaeventshelperbase.hxx new file mode 100755 index 000000000000..89d355db71f9 --- /dev/null +++ b/vbahelper/inc/vbahelper/vbaeventshelperbase.hxx @@ -0,0 +1,162 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef VBAHELPER_VBAEVENTSHELPERBASE_HXX +#define VBAHELPER_VBAEVENTSHELPERBASE_HXX + +#include <com/sun/star/lang/XEventListener.hpp> +#include <com/sun/star/script/vba/XVBAEventProcessor.hpp> +#include <cppuhelper/implbase2.hxx> +#include <map> +#include <deque> +#include "vbahelper/vbahelper.hxx" + +namespace com { namespace sun { namespace star { + namespace uno { class XComponentContext; } +} } } + +// ============================================================================ + +typedef ::cppu::WeakImplHelper2< css::script::vba::XVBAEventProcessor, css::lang::XEventListener > VbaEventsHelperBase_BASE; + +class VBAHELPER_DLLPUBLIC VbaEventsHelperBase : public VbaEventsHelperBase_BASE +{ +public: + VbaEventsHelperBase( + const css::uno::Sequence< css::uno::Any >& rArgs, + const css::uno::Reference< css::uno::XComponentContext >& xContext ); + virtual ~VbaEventsHelperBase(); + + // XVBAEventProcessor + virtual sal_Bool SAL_CALL hasVbaEventHandler( sal_Int32 nEventId, const css::uno::Sequence< css::uno::Any >& rArgs ) throw (css::lang::IllegalArgumentException, css::uno::RuntimeException); + virtual void SAL_CALL processVbaEvent( sal_Int32 nEventId, const css::uno::Sequence< css::uno::Any >& rArgs ) throw (css::lang::IllegalArgumentException, css::script::provider::ScriptFrameworkErrorException, css::util::VetoException, css::uno::RuntimeException); + + // XEventListener + virtual void SAL_CALL disposing( const css::lang::EventObject& aSource ) throw (css::uno::RuntimeException); + +protected: + // ------------------------------------------------------------------------ + + enum EventHandlerType { EVENTHANDLER_GLOBAL, EVENTHANDLER_DOCUMENT }; + struct EventHandlerInfo + { + sal_Int32 mnEventId; + ::rtl::OUString maMacroName; + EventHandlerType meType; + sal_Int32 mnCancelIndex; + css::uno::Any maUserData; + }; + + /** Registers a supported event handler. + + @param nEventId Event identifier from com.sun.star.script.vba.EventIdentifier. + @param pcMacroName Name of the associated VBA event handler macro. + @param eType Document event or global event. + @param nCancelIndex 0-based index of Cancel parameter, or -1. + @param rUserData User data for free usage in derived implementations. */ + void registerEventHandler( + sal_Int32 nEventId, + const sal_Char* pcMacroName, + EventHandlerType eType = EVENTHANDLER_DOCUMENT, + sal_Int32 nCancelIndex = -1, + const css::uno::Any& rUserData = css::uno::Any() ); + + /** Throws, if the passed sequence does not contain a value at the specified index. */ + static inline void checkArgument( const css::uno::Sequence< css::uno::Any >& rArgs, sal_Int32 nIndex ) throw (css::lang::IllegalArgumentException) + { if( rArgs.getLength() <= nIndex ) throw css::lang::IllegalArgumentException(); } + + /** Throws, if the passed sequence does not contain a value of a specific at the specified index. */ + template< typename Type > + static inline void checkArgumentType( const css::uno::Sequence< css::uno::Any >& rArgs, sal_Int32 nIndex ) throw (css::lang::IllegalArgumentException) + { if( (rArgs.getLength() <= nIndex) || !rArgs[ nIndex ].has< Type >() ) throw css::lang::IllegalArgumentException(); } + + // ------------------------------------------------------------------------ + + struct EventQueueEntry + { + sal_Int32 mnEventId; + css::uno::Sequence< css::uno::Any > maArgs; + inline /*implicit*/ EventQueueEntry( sal_Int32 nEventId ) : mnEventId( nEventId ) {} + inline EventQueueEntry( sal_Int32 nEventId, const css::uno::Sequence< css::uno::Any >& rArgs ) : mnEventId( nEventId ), maArgs( rArgs ) {} + }; + typedef ::std::deque< EventQueueEntry > EventQueue; + + /** Derived classes return whether event processing is enabled. Throws if + the instance is in an invalid state. */ + virtual bool implEventsEnabled() throw (css::uno::RuntimeException) = 0; + + /** Derived classes do additional prpeparations and return whether the + event handler has to be called. */ + virtual bool implPrepareEvent( + EventQueue& rEventQueue, + const EventHandlerInfo& rInfo, + const css::uno::Sequence< css::uno::Any >& rArgs ) throw (css::uno::RuntimeException) = 0; + + /** Derived classes have to return the argument list for the specified VBA event handler. */ + virtual css::uno::Sequence< css::uno::Any > implBuildArgumentList( + const EventHandlerInfo& rInfo, + const css::uno::Sequence< css::uno::Any >& rArgs ) throw (css::lang::IllegalArgumentException) = 0; + + /** Derived classes may do additional postprocessing. Called even if the + event handler does not exist, or if an error occured during execution. */ + virtual void implPostProcessEvent( + EventQueue& rEventQueue, + const EventHandlerInfo& rInfo, + bool bSuccess, + bool bCancel ) throw (css::uno::RuntimeException) = 0; + + /** Derived classes have to return the name of the Basic document module. */ + virtual ::rtl::OUString implGetDocumentModuleName( + const EventHandlerInfo& rInfo, + const css::uno::Sequence< css::uno::Any >& rArgs ) const throw (css::lang::IllegalArgumentException) = 0; + +private: + /** Returns the event handler info struct for the specified event, or throws. */ + const EventHandlerInfo& getEventHandlerInfo( sal_Int32 nEventId ) const throw (css::lang::IllegalArgumentException); + + /** Searches the event handler in the document and returns its full script path. */ + ::rtl::OUString getEventHandlerPath( + const EventHandlerInfo& rInfo, + const css::uno::Sequence< css::uno::Any >& rArgs ) const throw (css::lang::IllegalArgumentException); + + /** Removes this instance from all broadcasters. */ + void stopListening(); + +protected: + css::uno::Reference< css::frame::XModel > mxModel; + SfxObjectShell* mpShell; + +private: + typedef ::std::map< sal_Int32, EventHandlerInfo > EventHandlerMap; + + EventHandlerMap maEvents; + bool mbDisposed; +}; + +// ============================================================================ + +#endif diff --git a/vbahelper/inc/vbahelper/vbaglobalbase.hxx b/vbahelper/inc/vbahelper/vbaglobalbase.hxx index e75cbb7e7af8..61aaa1d65657 100644 --- a/vbahelper/inc/vbahelper/vbaglobalbase.hxx +++ b/vbahelper/inc/vbahelper/vbaglobalbase.hxx @@ -32,16 +32,16 @@ typedef InheritedHelperInterfaceImpl1< ov::XGlobalsBase > Globals_BASE; class VBAHELPER_DLLPUBLIC VbaGlobalsBase : public Globals_BASE - { protected: + rtl::OUString msDocCtxName; bool hasServiceName( const rtl::OUString& serviceName ); void init( const css::uno::Sequence< css::beans::PropertyValue >& aInitArgs ); public: VbaGlobalsBase( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const rtl::OUString& sDocCtxName ); - virtual ~VbaGlobalsBase(){}; + virtual ~VbaGlobalsBase(); // XMultiServiceFactory virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance( const ::rtl::OUString& aServiceSpecifier ) throw (css::uno::Exception, css::uno::RuntimeException); virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstanceWithArguments( const ::rtl::OUString& ServiceSpecifier, const css::uno::Sequence< css::uno::Any >& Arguments ) throw (css::uno::Exception, css::uno::RuntimeException); diff --git a/vbahelper/inc/vbahelper/vbahelper.hxx b/vbahelper/inc/vbahelper/vbahelper.hxx index 33613bb76091..a1eca84bbdf8 100644 --- a/vbahelper/inc/vbahelper/vbahelper.hxx +++ b/vbahelper/inc/vbahelper/vbahelper.hxx @@ -63,6 +63,7 @@ namespace ooo throw css::lang::IllegalArgumentException(); return aSomething; } + VBAHELPER_DLLPUBLIC css::uno::Reference< css::uno::XInterface > getUnoDocModule( const String& aModName, SfxObjectShell* pShell ); VBAHELPER_DLLPUBLIC SfxObjectShell* getSfxObjShell( const css::uno::Reference< css::frame::XModel >& xModel ) throw ( css::uno::RuntimeException); VBAHELPER_DLLPUBLIC css::uno::Reference< css::uno::XInterface > createVBAUnoAPIService( SfxObjectShell* pShell, const sal_Char* _pAsciiName ) throw (css::uno::RuntimeException); diff --git a/vbahelper/inc/vbahelper/vbahelperinterface.hxx b/vbahelper/inc/vbahelper/vbahelperinterface.hxx index 21339631e1ed..b095b5cd2823 100644 --- a/vbahelper/inc/vbahelper/vbahelperinterface.hxx +++ b/vbahelper/inc/vbahelper/vbahelperinterface.hxx @@ -28,6 +28,8 @@ #define OOVBAAPI_VBA_HELPERINTERFACE_HXX #include <cppuhelper/implbase1.hxx> +#include <cppuhelper/implbase2.hxx> +#include <cppuhelper/implbase3.hxx> #include <ooo/vba/XHelperInterface.hpp> #include <vbahelper/vbahelper.hxx> #include <com/sun/star/container/XNameAccess.hpp> @@ -68,6 +70,7 @@ protected: css::uno::Reference< css::uno::XComponentContext > mxContext; public: InheritedHelperInterfaceImpl() {} + InheritedHelperInterfaceImpl( const css::uno::Reference< css::uno::XComponentContext >& xContext ) : mxContext( xContext ) {} InheritedHelperInterfaceImpl( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext ) : mxParent( xParent ), mxContext( xContext ) {} virtual rtl::OUString& getServiceImplName() = 0; virtual css::uno::Sequence<rtl::OUString> getServiceNames() = 0; @@ -86,7 +89,6 @@ public: return xNameAccess->getByName( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Application" ) ) ); } - // XServiceInfo Methods virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (css::uno::RuntimeException) { return getServiceImplName(); } virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (css::uno::RuntimeException) @@ -101,19 +103,39 @@ public: } virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (css::uno::RuntimeException) { - css::uno::Sequence< rtl::OUString > aNames = getServiceNames();; + css::uno::Sequence< rtl::OUString > aNames = getServiceNames(); return aNames; } }; template< typename Ifc1 > class VBAHELPER_DLLPUBLIC InheritedHelperInterfaceImpl1 : public InheritedHelperInterfaceImpl< ::cppu::WeakImplHelper1< Ifc1 > > +{ + typedef InheritedHelperInterfaceImpl< ::cppu::WeakImplHelper1< Ifc1 > > Base; +public: + InheritedHelperInterfaceImpl1< Ifc1 >() {} + InheritedHelperInterfaceImpl1< Ifc1 >( const css::uno::Reference< css::uno::XComponentContext >& xContext ) : Base( xContext ) {} + InheritedHelperInterfaceImpl1< Ifc1 >( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext ) : Base( xParent, xContext ) {} +}; +template< typename Ifc1, typename Ifc2 > +class VBAHELPER_DLLPUBLIC InheritedHelperInterfaceImpl2 : public InheritedHelperInterfaceImpl< ::cppu::WeakImplHelper2< Ifc1, Ifc2 > > { -typedef InheritedHelperInterfaceImpl< ::cppu::WeakImplHelper1< Ifc1 > > Base; + typedef InheritedHelperInterfaceImpl< ::cppu::WeakImplHelper2< Ifc1, Ifc2 > > Base; public: - InheritedHelperInterfaceImpl1< Ifc1 > ( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext ) : Base( xParent, xContext ) {} + InheritedHelperInterfaceImpl2< Ifc1, Ifc2 >() {} + InheritedHelperInterfaceImpl2< Ifc1, Ifc2 >( const css::uno::Reference< css::uno::XComponentContext >& xContext ) : Base( xContext ) {} + InheritedHelperInterfaceImpl2< Ifc1, Ifc2 >( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext ) : Base( xParent, xContext ) {} +}; +template< typename Ifc1, typename Ifc2, typename Ifc3 > +class VBAHELPER_DLLPUBLIC InheritedHelperInterfaceImpl3 : public InheritedHelperInterfaceImpl< ::cppu::WeakImplHelper3< Ifc1, Ifc2, Ifc3 > > +{ + typedef InheritedHelperInterfaceImpl< ::cppu::WeakImplHelper3< Ifc1, Ifc2, Ifc3 > > Base; +public: + InheritedHelperInterfaceImpl3< Ifc1, Ifc2, Ifc3 >() {} + InheritedHelperInterfaceImpl3< Ifc1, Ifc2, Ifc3 >( const css::uno::Reference< css::uno::XComponentContext >& xContext ) : Base( xContext ) {} + InheritedHelperInterfaceImpl3< Ifc1, Ifc2, Ifc3 >( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext ) : Base( xParent, xContext ) {} }; // ============================================================================ diff --git a/vbahelper/prj/d.lst b/vbahelper/prj/d.lst index d683e97c8b90..2d20ab1f982d 100644 --- a/vbahelper/prj/d.lst +++ b/vbahelper/prj/d.lst @@ -26,3 +26,4 @@ mkdir: %_DEST%\inc%_EXT%\basic ..\inc\vbahelper\vbatextframe.hxx %_DEST%\inc%_EXT%\vbahelper\vbatextframe.hxx ..\inc\vbahelper\vbashaperange.hxx %_DEST%\inc%_EXT%\vbahelper\vbashaperange.hxx ..\inc\vbahelper\vbapagesetupbase.hxx %_DEST%\inc%_EXT%\vbahelper\vbapagesetupbase.hxx +..\inc\vbahelper\vbaeventshelperbase.hxx %_DEST%\inc%_EXT%\vbahelper\vbaeventshelperbase.hxx diff --git a/vbahelper/source/msforms/vbacontrols.cxx b/vbahelper/source/msforms/vbacontrols.cxx index 1284b36be463..8d01687ef905 100644 --- a/vbahelper/source/msforms/vbacontrols.cxx +++ b/vbahelper/source/msforms/vbacontrols.cxx @@ -74,12 +74,20 @@ private: public: ControlArrayWrapper( const uno::Reference< awt::XControl >& xDialog ) { - mxDialog.set( xDialog, uno::UNO_QUERY_THROW ); - uno::Sequence< uno::Reference< awt::XControl > > sXControls = mxDialog->getControls(); + try + { + mxDialog.set( xDialog, uno::UNO_QUERY_THROW ); + uno::Sequence< uno::Reference< awt::XControl > > sXControls = mxDialog->getControls(); - msNames.realloc( sXControls.getLength() ); - for ( sal_Int32 i = 0; i < sXControls.getLength(); ++i ) - SetArrayElementTo( sXControls[ i ], i ); + msNames.realloc( sXControls.getLength() ); + for ( sal_Int32 i = 0; i < sXControls.getLength(); ++i ) + SetArrayElementTo( sXControls[ i ], i ); + } + catch( uno::Exception& ) + { + // accept the case when the dialog already does not exist + // in this case the wrapper should work in dummy mode + } } static rtl::OUString getControlName( const uno::Reference< awt::XControl >& xCtrl ) @@ -186,7 +194,7 @@ ScVbaControls::ScVbaControls( const uno::Reference< XHelperInterface >& xParent, const css::uno::Reference< awt::XControl >& xDialog ) : ControlsImpl_BASE( xParent, xContext, lcl_controlsWrapper( xDialog ) ) { - mxDialog.set( xDialog, uno::UNO_QUERY_THROW ); + mxDialog.set( xDialog, uno::UNO_QUERY ); } uno::Reference< container::XEnumeration > @@ -349,13 +357,16 @@ void SAL_CALL ScVbaControls::Remove( const uno::Any& StringKeyOrIndex ) } catch( uno::RuntimeException& ) { - throw; + // the exceptions are not rethrown, impossibility to find or remove the control is currently not reported + // since in most cases it means just that the controls is already not there, the VBA seems to do it in the same way + + // throw; } catch( uno::Exception& e ) { - throw lang::WrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Can not create AXControl!" ) ), - uno::Reference< uno::XInterface >(), - uno::makeAny( e ) ); + // throw lang::WrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Can not create AXControl!" ) ), + // uno::Reference< uno::XInterface >(), + // uno::makeAny( e ) ); } } diff --git a/vbahelper/source/msforms/vbauserform.cxx b/vbahelper/source/msforms/vbauserform.cxx index 1ce403fc19c3..2a4cecfc2338 100644 --- a/vbahelper/source/msforms/vbauserform.cxx +++ b/vbahelper/source/msforms/vbauserform.cxx @@ -185,7 +185,9 @@ ScVbaUserForm::hasMethod( const ::rtl::OUString& /*aName*/ ) throw (uno::Runtime uno::Any SAL_CALL ScVbaUserForm::Controls( const uno::Any& index ) throw (uno::RuntimeException) { - uno::Reference< awt::XControl > xDialogControl( m_xDialog, uno::UNO_QUERY_THROW ); + // if the dialog already closed we should do nothing, but the VBA will call methods of the Controls objects + // thus we have to provide a dummy object in this case + uno::Reference< awt::XControl > xDialogControl( m_xDialog, uno::UNO_QUERY ); uno::Reference< XCollection > xControls( new ScVbaControls( this, mxContext, xDialogControl ) ); if ( index.hasValue() ) return uno::makeAny( xControls->Item( index, uno::Any() ) ); diff --git a/vbahelper/source/vbahelper/makefile.mk b/vbahelper/source/vbahelper/makefile.mk index 47ad44b3d0ed..22ed40a3adfa 100644 --- a/vbahelper/source/vbahelper/makefile.mk +++ b/vbahelper/source/vbahelper/makefile.mk @@ -65,6 +65,8 @@ SLOFILES=\ $(SLO)$/vbashaperange.obj \ $(SLO)$/vbatextframe.obj \ $(SLO)$/vbapagesetupbase.obj \ + $(SLO)$/vbaeventshelperbase.obj + # --- Targets ------------------------------------------------------- .INCLUDE : target.mk diff --git a/vbahelper/source/vbahelper/vbaapplicationbase.cxx b/vbahelper/source/vbahelper/vbaapplicationbase.cxx index 6d2c51066ca2..326c150edade 100644 --- a/vbahelper/source/vbahelper/vbaapplicationbase.cxx +++ b/vbahelper/source/vbahelper/vbaapplicationbase.cxx @@ -24,39 +24,37 @@ * for a copy of the LGPLv3 License. * ************************************************************************/ + #include "vbahelper/vbaapplicationbase.hxx" + #include <com/sun/star/container/XIndexAccess.hpp> -#include <com/sun/star/lang/XMultiServiceFactory.hpp> //Michael E. Bohn -#include <com/sun/star/lang/XMultiComponentFactory.hpp> //Michael E. Bohn -#include <com/sun/star/lang/XComponent.hpp> //Michael E. Bohn -#include <com/sun/star/container/XEnumeration.hpp> //Michael E. Bohn +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/lang/XMultiComponentFactory.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/container/XEnumeration.hpp> #include <com/sun/star/frame/XLayoutManager.hpp> #include <com/sun/star/frame/XDesktop.hpp> #include <com/sun/star/container/XEnumerationAccess.hpp> #include <com/sun/star/document/XDocumentInfoSupplier.hpp> #include <com/sun/star/document/XDocumentProperties.hpp> #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp> -#include <com/sun/star/document/XEmbeddedScripts.hpp> //Michael E. Bohn -#include <ooo/vba/XVBAAppService.hpp> //Michael E. Bohn +#include <com/sun/star/document/XEmbeddedScripts.hpp> #include <com/sun/star/awt/XWindow2.hpp> - -#include "vbacommandbars.hxx" +#include <hash_map> #include <filter/msfilter/msvbahelper.hxx> #include <tools/datetime.hxx> -// start basic includes #include <basic/sbx.hxx> #include <basic/sbstar.hxx> #include <basic/sbuno.hxx> #include <basic/sbmeth.hxx> #include <basic/sbmod.hxx> -// end basic includes -#include <hash_map> +#include "vbacommandbars.hxx" -using namespace com::sun::star; -using namespace ooo::vba; +using namespace ::com::sun::star; +using namespace ::ooo::vba; #define OFFICEVERSION "11.0" @@ -162,6 +160,9 @@ typedef ::std::hash_map< VbaTimerInfo, VbaTimer*, VbaTimerInfoHash, ::std::equal struct VbaApplicationBase_Impl { VbaTimerHashMap m_aTimerHash; + sal_Bool mbVisible; + + inline VbaApplicationBase_Impl() : mbVisible( sal_True ) {} virtual ~VbaApplicationBase_Impl() { @@ -185,7 +186,6 @@ VbaApplicationBase::VbaApplicationBase( const uno::Reference< uno::XComponentCon VbaApplicationBase::~VbaApplicationBase() { - m_pImpl = 0; delete m_pImpl; } @@ -268,6 +268,16 @@ void SAL_CALL VbaApplicationBase::setInteractive( ::sal_Bool bInteractive ) xWindow->setEnable( bInteractive ); } +sal_Bool SAL_CALL VbaApplicationBase::getVisible() throw (uno::RuntimeException) +{ + return m_pImpl->mbVisible; // dummy implementation +} + +void SAL_CALL VbaApplicationBase::setVisible( sal_Bool bVisible ) throw (uno::RuntimeException) +{ + m_pImpl->mbVisible = bVisible; // dummy implementation +} + uno::Any SAL_CALL VbaApplicationBase::CommandBars( const uno::Any& aIndex ) throw (uno::RuntimeException) { @@ -407,63 +417,50 @@ float SAL_CALL VbaApplicationBase::CentimetersToPoints( float _Centimeters ) thr return ( _Centimeters * rate ); } -// inserted by Michael E. Bohn uno::Any SAL_CALL VbaApplicationBase::getVBE() throw (uno::RuntimeException) { - uno::Any aAny; - uno::Reference< ::lang::XMultiComponentFactory > xServiceManager = mxContext->getServiceManager(); - try - { - uno::Reference < ::uno::XInterface > xInterface = xServiceManager->createInstanceWithContext( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.VBAAppService" )),mxContext); - uno::Reference < ::ooo::vba::XVBAAppService > xVBAAppService (xInterface, ::uno::UNO_QUERY_THROW ); - if (xVBAAppService.is()){ - uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_QUERY_THROW ); - return xVBAAppService->getVBE( this, mxContext, xModel); - } - - }catch(uno::Exception* e) - { - } - return aAny; + try // return empty object on error + { + uno::Sequence< uno::Any > aArgs( 2 ); + aArgs[ 0 ] <<= uno::Reference< XHelperInterface >( this ); + aArgs[ 1 ] <<= getCurrentDocument(); + uno::Reference< lang::XMultiComponentFactory > xServiceManager( mxContext->getServiceManager(), uno::UNO_SET_THROW ); + uno::Reference< uno::XInterface > xVBE = xServiceManager->createInstanceWithArgumentsAndContext( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.VBE" ) ), aArgs, mxContext ); + return uno::Any( xVBE ); + } + catch( uno::Exception& ) + { + } + return uno::Any(); } uno::Any SAL_CALL VbaApplicationBase::getVBProjects() throw (uno::RuntimeException) { - uno::Any aAny; - uno::Reference< ::lang::XMultiComponentFactory > xServiceManager = mxContext->getServiceManager(); - try - { - uno::Reference < ::uno::XInterface > xInterface = xServiceManager->createInstanceWithContext( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.VBAAppService" )),mxContext); - uno::Reference < ::ooo::vba::XVBAAppService > xVBAAppService (xInterface, ::uno::UNO_QUERY_THROW ); - if (xVBAAppService.is()){ - uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_QUERY_THROW ); - uno::Reference< document::XEmbeddedScripts > xEnbeddedScripts ( xModel, uno::UNO_QUERY_THROW ); - uno::Reference< script::XStorageBasedLibraryContainer > xMacroStorageBasedLibraryContainer = xEnbeddedScripts->getBasicLibraries(); - uno::Reference< script::XStorageBasedLibraryContainer > xDialogStorageBasedLibraryContainer = xEnbeddedScripts->getDialogLibraries(); - uno::Reference< script::XLibraryContainer > xMacroLibraryContainer ( xMacroStorageBasedLibraryContainer, uno::UNO_QUERY_THROW ); - uno::Reference< script::XLibraryContainer > xDialogLibraryContainer( xDialogStorageBasedLibraryContainer, uno::UNO_QUERY_THROW ); - return xVBAAppService->getVBProjects(this, mxContext, xModel, xMacroLibraryContainer, xDialogLibraryContainer); - } - - }catch(uno::Exception* e) - { - } - return aAny; - - - + try // return empty object on error + { + uno::Sequence< uno::Any > aArgs( 2 ); + aArgs[ 0 ] <<= uno::Reference< XHelperInterface >( this ); + aArgs[ 1 ] <<= getCurrentDocument(); + uno::Reference< lang::XMultiComponentFactory > xServiceManager( mxContext->getServiceManager(), uno::UNO_SET_THROW ); + uno::Reference< uno::XInterface > xVBProjects = xServiceManager->createInstanceWithArgumentsAndContext( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.VBProjects" ) ), aArgs, mxContext ); + return uno::Any( xVBProjects ); + } + catch( uno::Exception& ) + { + } + return uno::Any(); } - - - rtl::OUString& VbaApplicationBase::getServiceImplName() { static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("VbaApplicationBase") ); return sImplName; } + uno::Sequence<rtl::OUString> VbaApplicationBase::getServiceNames() { diff --git a/vbahelper/source/vbahelper/vbadocumentbase.cxx b/vbahelper/source/vbahelper/vbadocumentbase.cxx index f27f2de53c8a..65f7f4bcfbeb 100644 --- a/vbahelper/source/vbahelper/vbadocumentbase.cxx +++ b/vbahelper/source/vbahelper/vbadocumentbase.cxx @@ -24,9 +24,9 @@ * for a copy of the LGPLv3 License. * ************************************************************************/ -#include <vbahelper/vbadocumentbase.hxx> -#include <vbahelper/helperdecl.hxx> -#include <comphelper/unwrapargs.hxx> + +#include "vbahelper/vbadocumentbase.hxx" +#include "vbahelper/helperdecl.hxx" #include <com/sun/star/util/XModifiable.hpp> #include <com/sun/star/util/XProtectable.hpp> @@ -35,8 +35,8 @@ #include <com/sun/star/frame/XFrame.hpp> #include <com/sun/star/document/XEmbeddedScripts.hpp> //Michael E. Bohn #include <com/sun/star/beans/XPropertySet.hpp> -#include <ooo/vba/XVBADocService.hpp> +#include <comphelper/unwrapargs.hxx> #include <tools/urlobj.hxx> #include <osl/file.hxx> @@ -206,40 +206,25 @@ VbaDocumentBase::Activate() throw (uno::RuntimeException) xFrame->activate(); } -// ---- Michael E.Bohn Start----- - uno::Any SAL_CALL VbaDocumentBase::getVBProject() throw (uno::RuntimeException) - { - uno::Any aAny; - uno::Reference< ::lang::XMultiComponentFactory > xServiceManager = mxContext->getServiceManager(); - try - { - uno::Reference < ::uno::XInterface > xInterface = xServiceManager->createInstanceWithContext( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.VBADocService" )),mxContext); - uno::Reference < ::ooo::vba::XVBADocService > xVBADocService (xInterface, ::uno::UNO_QUERY_THROW ); - if (xVBADocService.is()){ - uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_QUERY_THROW ); - uno::Reference< document::XEmbeddedScripts > xEnbeddedScripts ( xModel, uno::UNO_QUERY_THROW ); - uno::Reference< script::XStorageBasedLibraryContainer > xMacroStorageBasedLibraryContainer = xEnbeddedScripts->getBasicLibraries(); - uno::Reference< script::XStorageBasedLibraryContainer > xDialogStorageBasedLibraryContainer = xEnbeddedScripts->getDialogLibraries(); - uno::Reference< script::XLibraryContainer > xMacroLibraryContainer ( xMacroStorageBasedLibraryContainer, uno::UNO_QUERY_THROW ); - uno::Reference< script::XLibraryContainer > xDialogLibraryContainer( xDialogStorageBasedLibraryContainer, uno::UNO_QUERY_THROW ); - - return xVBADocService->getVBProject( this, mxContext, xModel, xMacroLibraryContainer, xDialogLibraryContainer ); - } - - }catch(uno::Exception* e) - { - } - return aAny; - + try // return empty object on error + { + uno::Sequence< uno::Any > aArgs( 2 ); + aArgs[ 0 ] <<= uno::Reference< XHelperInterface >( this ); + aArgs[ 1 ] <<= mxModel; + uno::Reference< lang::XMultiComponentFactory > xServiceManager( mxContext->getServiceManager(), uno::UNO_SET_THROW ); + uno::Reference< uno::XInterface > xVBProjects = xServiceManager->createInstanceWithArgumentsAndContext( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.VBProject" ) ), aArgs, mxContext ); + return uno::Any( xVBProjects ); + } + catch( uno::Exception& ) + { + } + return uno::Any(); } - -// ---- Michael E.Bohn End ----- - - rtl::OUString& VbaDocumentBase::getServiceImplName() { diff --git a/vbahelper/source/vbahelper/vbaeventshelperbase.cxx b/vbahelper/source/vbahelper/vbaeventshelperbase.cxx new file mode 100755 index 000000000000..16a8671df601 --- /dev/null +++ b/vbahelper/source/vbahelper/vbaeventshelperbase.cxx @@ -0,0 +1,218 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "vbahelper/vbaeventshelperbase.hxx" +#include <filter/msfilter/msvbahelper.hxx> + +using namespace ::com::sun::star; +using namespace ::ooo::vba; + +// ============================================================================ + +VbaEventsHelperBase::VbaEventsHelperBase( const uno::Sequence< uno::Any >& rArgs, const uno::Reference< uno::XComponentContext >& /*xContext*/ ) : + mpShell( 0 ), + mbDisposed( false ) +{ + try + { + mxModel = getXSomethingFromArgs< frame::XModel >( rArgs, 0, false ); + mpShell = getSfxObjShell( mxModel ); + + // add dispose listener + uno::Reference< lang::XComponent > xComponent( mxModel, uno::UNO_QUERY_THROW ); + xComponent->addEventListener( this ); + } + catch( uno::Exception& ) + { + } +} + +VbaEventsHelperBase::~VbaEventsHelperBase() +{ + stopListening(); +} + +sal_Bool SAL_CALL VbaEventsHelperBase::hasVbaEventHandler( sal_Int32 nEventId, const uno::Sequence< uno::Any >& rArgs ) + throw (lang::IllegalArgumentException, uno::RuntimeException) +{ + // getEventHandlerInfo() throws, if unknown event dentifier has been passed + const EventHandlerInfo& rInfo = getEventHandlerInfo( nEventId ); + // getEventHandlerPath() searches for the macro in the document + return getEventHandlerPath( rInfo, rArgs ).getLength() > 0; +} + +void SAL_CALL VbaEventsHelperBase::processVbaEvent( sal_Int32 nEventId, const uno::Sequence< uno::Any >& rArgs ) + throw (lang::IllegalArgumentException, script::provider::ScriptFrameworkErrorException, util::VetoException, uno::RuntimeException) +{ + /* Derived classes may add new event identifiers to be processed while + processing the original event. All unprocessed events are collected in + a queue. First element in the queue is the next event to be processed. */ + EventQueue aEventQueue; + aEventQueue.push_back( EventQueueEntry( nEventId, rArgs ) ); + + /* bEnabled will track if event processing is enabled. Every event handler + may disable handling of other events. */ + bool bEnabled = true; + + /* bCancel will contain the current Cancel value. It is possible that + multiple events will try to modify the Cancel value. Every event + handler receives the Cancel value of the previous event handler. */ + bool bCancel = false; + + /* bSuccess will change to true if at least one event handler has been + executed successfully. */ + bool bSuccess = false; + + /* Loop as long as there are more events to be processed, and as event + handling is still enabled. Derived classes may add new events to be + processed in the virtual implPrepareEvent() function. */ + while( bEnabled && !aEventQueue.empty() ) + { + /* Check that all class members are available, and that we are not + disposed (this may have happened at any time during execution of + the last event handler). */ + if( mbDisposed || !mxModel.is() || !mpShell ) + throw uno::RuntimeException(); + + // get info for next event + const EventHandlerInfo& rInfo = getEventHandlerInfo( aEventQueue.front().mnEventId ); + uno::Sequence< uno::Any > aEventArgs = aEventQueue.front().maArgs; + aEventQueue.pop_front(); + + // let derived classes decide whether event processing is still enabled + bEnabled = implEventsEnabled(); + // let derived classes prepare the event, they may add new events for next iteration + if( bEnabled && implPrepareEvent( aEventQueue, rInfo, aEventArgs ) ) + { + // search the event handler macro in the document + ::rtl::OUString aMacroPath = getEventHandlerPath( rInfo, aEventArgs ); + bool bEventSuccess = false; + if( aMacroPath.getLength() > 0 ) + { + // build the argument list + uno::Sequence< uno::Any > aVbaArgs = implBuildArgumentList( rInfo, aEventArgs ); + // insert current cancel value + if( rInfo.mnCancelIndex >= 0 ) + { + if( rInfo.mnCancelIndex >= aVbaArgs.getLength() ) + throw lang::IllegalArgumentException(); + aVbaArgs[ rInfo.mnCancelIndex ] <<= bCancel; + } + // execute the event handler + uno::Any aRet, aCaller; + bEventSuccess = executeMacro( mpShell, aMacroPath, aVbaArgs, aRet, aCaller ); + // extract new cancel value + if( rInfo.mnCancelIndex >= 0 ) + { + if( rInfo.mnCancelIndex >= aVbaArgs.getLength() ) + throw lang::IllegalArgumentException(); + // cancel value may be boolean or any integer type, Any(bool) does not extract to sal_Int32 + bool bNewCancel = false; + sal_Int32 nNewCancel = 0; + if( aVbaArgs[ rInfo.mnCancelIndex ] >>= bNewCancel ) + bCancel = bNewCancel; + else if( aVbaArgs[ rInfo.mnCancelIndex ] >>= nNewCancel ) + bCancel = nNewCancel != 0; + } + } + // post processing (also, if event handler does not exist, or on error + implPostProcessEvent( aEventQueue, rInfo, bEventSuccess, bCancel ); + // global success, if at least one event handler succeeded + bSuccess |= bEventSuccess; + } + } + + // if event handlers want to cancel the event, do so regardless of any errors + if( bCancel ) + throw util::VetoException(); + + // if no event handler finished successfully, throw + if( !bSuccess ) + throw script::provider::ScriptFrameworkErrorException(); +} + +void SAL_CALL VbaEventsHelperBase::disposing( const lang::EventObject& /*aSource*/ ) throw (uno::RuntimeException) +{ + OSL_TRACE( "VbaEventsHelperBase::disposing" ); + stopListening(); + mbDisposed = true; +} + +// protected ------------------------------------------------------------------ + +void VbaEventsHelperBase::registerEventHandler( sal_Int32 nEventId, + const sal_Char* pcMacroName, EventHandlerType eType, sal_Int32 nCancelIndex, const uno::Any& rUserData ) +{ + EventHandlerInfo& rInfo = maEvents[ nEventId ]; + rInfo.mnEventId = nEventId; + rInfo.maMacroName = ::rtl::OUString::createFromAscii( pcMacroName ); + rInfo.meType = eType; + rInfo.mnCancelIndex = nCancelIndex; + rInfo.maUserData = rUserData; +} + +// private -------------------------------------------------------------------- + +const VbaEventsHelperBase::EventHandlerInfo& VbaEventsHelperBase::getEventHandlerInfo( + sal_Int32 nEventId ) const throw (lang::IllegalArgumentException) +{ + EventHandlerMap::const_iterator aIt = maEvents.find( nEventId ); + if( aIt == maEvents.end() ) + throw lang::IllegalArgumentException(); + return aIt->second; +} + +::rtl::OUString VbaEventsHelperBase::getEventHandlerPath( const EventHandlerInfo& rInfo, + const uno::Sequence< uno::Any >& rArgs ) const throw (lang::IllegalArgumentException) +{ + ::rtl::OUString aMacroName; + switch( rInfo.meType ) + { + case EVENTHANDLER_GLOBAL: + aMacroName = rInfo.maMacroName; + break; + case EVENTHANDLER_DOCUMENT: + aMacroName = ::rtl::OUStringBuffer( implGetDocumentModuleName( rInfo, rArgs ) ). + append( sal_Unicode( '.' ) ).append( rInfo.maMacroName ).makeStringAndClear(); + break; + } + return resolveVBAMacro( mpShell, aMacroName ).ResolvedMacro(); +} + +void VbaEventsHelperBase::stopListening() +{ + if( !mbDisposed ) try + { + uno::Reference< lang::XComponent > xComponent( mxModel, uno::UNO_QUERY_THROW ); + xComponent->removeEventListener( this ); + } + catch( uno::Exception& ) + { + } +} + +// ============================================================================ diff --git a/vbahelper/source/vbahelper/vbaglobalbase.cxx b/vbahelper/source/vbahelper/vbaglobalbase.cxx index c7c33b93b1a3..e0df37583df5 100644 --- a/vbahelper/source/vbahelper/vbaglobalbase.cxx +++ b/vbahelper/source/vbahelper/vbaglobalbase.cxx @@ -35,22 +35,50 @@ using namespace ooo::vba; rtl::OUString sApplication( RTL_CONSTASCII_USTRINGPARAM("Application") ); +// special key to return the Application +rtl::OUString sAppService( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.Application") ); + VbaGlobalsBase::VbaGlobalsBase( const uno::Reference< ov::XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const rtl::OUString& sDocCtxName ) -: Globals_BASE( xParent, xContext ) +: Globals_BASE( xParent, xContext ), msDocCtxName( sDocCtxName ) { // overwrite context with custom one ( that contains the application ) + // wrap the service manager as we don't want the disposing context to tear down the 'normal' ServiceManager ( or at least thats what the code appears like it wants to do ) + uno::Any aSrvMgr; + if ( xContext.is() && xContext->getServiceManager().is() ) + { + aSrvMgr = uno::makeAny( xContext->getServiceManager()->createInstanceWithContext( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.stoc.OServiceManagerWrapper") ), xContext ) ); + } + ::cppu::ContextEntry_Init aHandlerContextInfo[] = { ::cppu::ContextEntry_Init( sApplication, uno::Any() ), ::cppu::ContextEntry_Init( sDocCtxName, uno::Any() ), + ::cppu::ContextEntry_Init( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("/singletons/com.sun.star.lang.theServiceManager" ) ), aSrvMgr ) }; - - mxContext = ::cppu::createComponentContext( aHandlerContextInfo, sizeof( aHandlerContextInfo ) / sizeof( aHandlerContextInfo[0] ), xContext ); - + // don't pass a delegate, this seems to introduce yet another cyclic dependency ( and + // some strange behavior + mxContext = ::cppu::createComponentContext( aHandlerContextInfo, sizeof( aHandlerContextInfo ) / sizeof( aHandlerContextInfo[0] ), NULL ); } +VbaGlobalsBase::~VbaGlobalsBase() +{ + try + { + uno::Reference< container::XNameContainer > xNameContainer( mxContext, uno::UNO_QUERY ); + if ( xNameContainer.is() ) + { + // release document reference ( we don't wan't the component context trying to dispose that ) + xNameContainer->removeByName( msDocCtxName ); + // release application reference, as it is holding onto the context + xNameContainer->removeByName( sApplication ); + } + } + catch ( const uno::Exception& ) + { + } +} void VbaGlobalsBase::init( const uno::Sequence< beans::PropertyValue >& aInitArgs ) @@ -74,19 +102,30 @@ uno::Reference< uno::XInterface > SAL_CALL VbaGlobalsBase::createInstance( const ::rtl::OUString& aServiceSpecifier ) throw (uno::Exception, uno::RuntimeException) { uno::Reference< uno::XInterface > xReturn; - - if ( hasServiceName( aServiceSpecifier ) ) + if ( aServiceSpecifier.equals( sAppService ) ) + { + // try to extract the Application from the context + uno::Reference< container::XNameContainer > xNameContainer( mxContext, uno::UNO_QUERY ); + xNameContainer->getByName( sApplication ) >>= xReturn; + } + else if ( hasServiceName( aServiceSpecifier ) ) xReturn = mxContext->getServiceManager()->createInstanceWithContext( aServiceSpecifier, mxContext ); return xReturn; } uno::Reference< uno::XInterface > SAL_CALL -VbaGlobalsBase::createInstanceWithArguments( const ::rtl::OUString& ServiceSpecifier, const uno::Sequence< uno::Any >& Arguments ) throw (uno::Exception, uno::RuntimeException) +VbaGlobalsBase::createInstanceWithArguments( const ::rtl::OUString& aServiceSpecifier, const uno::Sequence< uno::Any >& Arguments ) throw (uno::Exception, uno::RuntimeException) { uno::Reference< uno::XInterface > xReturn; - if ( hasServiceName( ServiceSpecifier ) ) - xReturn = mxContext->getServiceManager()->createInstanceWithArgumentsAndContext( ServiceSpecifier, Arguments, mxContext ); + if ( aServiceSpecifier.equals( sAppService ) ) + { + // try to extract the Application from the context + uno::Reference< container::XNameContainer > xNameContainer( mxContext, uno::UNO_QUERY ); + xNameContainer->getByName( sApplication ) >>= xReturn; + } + else if ( hasServiceName( aServiceSpecifier ) ) + xReturn = mxContext->getServiceManager()->createInstanceWithArgumentsAndContext( aServiceSpecifier, Arguments, mxContext ); return xReturn; } diff --git a/vbahelper/source/vbahelper/vbahelper.cxx b/vbahelper/source/vbahelper/vbahelper.cxx index 1953d0772f3c..7cd82dff9536 100644 --- a/vbahelper/source/vbahelper/vbahelper.cxx +++ b/vbahelper/source/vbahelper/vbahelper.cxx @@ -1404,6 +1404,26 @@ void UserFormGeometryHelper::setHeight( double nHeight ) return points; } + uno::Reference< uno::XInterface > getUnoDocModule( const String& aModName, SfxObjectShell* pShell ) + { + uno::Reference< uno::XInterface > xIf; + if ( pShell ) + { + rtl::OUString sProj( RTL_CONSTASCII_USTRINGPARAM("Standard") ); + BasicManager* pBasMgr = pShell->GetBasicManager(); + if ( pBasMgr && pBasMgr->GetName().Len() ) + sProj = pShell->GetBasicManager()->GetName(); + StarBASIC* pBasic = pShell->GetBasicManager()->GetLib( sProj ); + if ( pBasic ) + { + SbModule* pMod = pBasic->FindModule( aModName ); + if ( pMod ) + xIf = pMod->GetUnoModule(); + } + } + return xIf; + } + SfxObjectShell* getSfxObjShell( const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException) { SfxObjectShell* pFoundShell = NULL; diff --git a/xmloff/inc/xmloff/xmltoken.hxx b/xmloff/inc/xmloff/xmltoken.hxx index d892c10f4f5d..f4843d54ace1 100644 --- a/xmloff/inc/xmloff/xmltoken.hxx +++ b/xmloff/inc/xmloff/xmltoken.hxx @@ -3107,6 +3107,9 @@ namespace xmloff { namespace token { XML_N_CHART_EXT, XML_COORDINATE_REGION, + XML_DIAGONAL_BL_TR_WIDTHS, + XML_DIAGONAL_TL_BR_WIDTHS, + XML_TOKEN_END }; diff --git a/xmloff/source/core/xmltoken.cxx b/xmloff/source/core/xmltoken.cxx index 2e92c4a6a97d..a3d4a0c48d02 100644 --- a/xmloff/source/core/xmltoken.cxx +++ b/xmloff/source/core/xmltoken.cxx @@ -3107,6 +3107,9 @@ namespace xmloff { namespace token { TOKEN( "http://openoffice.org/2010/chart", XML_N_CHART_EXT ), TOKEN( "coordinate-region", XML_COORDINATE_REGION ), + TOKEN( "diagonal-bl-tr-widths", XML_DIAGONAL_BL_TR_WIDTHS ), + TOKEN( "diagonal-tl-br-widths", XML_DIAGONAL_TL_BR_WIDTHS ), + #if OSL_DEBUG_LEVEL > 0 { 0, NULL, NULL, XML_TOKEN_END } #else |