diff options
author | Noel Power <noel.power@novell.com> | 2010-10-13 10:51:50 +0100 |
---|---|---|
committer | Noel Power <noel.power@novell.com> | 2010-10-13 10:51:50 +0100 |
commit | 606a57481911e111dfab950cd7fb90ae80aed014 (patch) | |
tree | 62e85311b32105e6d4e165d60c9d4bbdb80c03bc /basic | |
parent | a4d7dbf897e41a1afda6c2b6f0e5cc35920a1cf3 (diff) | |
parent | ed49568618442960781b63c3a47ddc65031b2fa0 (diff) |
Merge branch 'vba' fix conflics, trailing ws & tab issues
also removed some old headers ( which I need to add new ones for )
Conflicts:
basic/source/classes/sbunoobj.cxx
basic/source/classes/sbxmod.cxx
xmloff/inc/xmlnmspe.hxx
xmloff/inc/xmloff/xmltoken.hxx
xmlscript/inc/xmlscript/xmldlg_imexp.hxx
Diffstat (limited to 'basic')
32 files changed, 1773 insertions, 595 deletions
diff --git a/basic/inc/basic/basmgr.hxx b/basic/inc/basic/basmgr.hxx index 73b64a2690..6f74f37843 100644 --- a/basic/inc/basic/basmgr.hxx +++ b/basic/inc/basic/basmgr.hxx @@ -236,7 +236,7 @@ public: takes the names of modules whose size exceeds the legacy limit */ bool LegacyPsswdBinaryLimitExceeded( ::com::sun::star::uno::Sequence< rtl::OUString >& _out_rModuleNames ); - + bool HasExeCode( const String& ); private: BOOL IsReference( USHORT nLib ); diff --git a/basic/inc/basic/sbmeth.hxx b/basic/inc/basic/sbmeth.hxx index 7b3cd4dc03..26e83b3caf 100644 --- a/basic/inc/basic/sbmeth.hxx +++ b/basic/inc/basic/sbmeth.hxx @@ -46,6 +46,7 @@ class SbMethod : public SbxMethod friend class SbIfaceMapperMethod; SbMethodImpl* mpSbMethodImpl; // Impl data + SbxVariable* mCaller; // caller SbModule* pMod; USHORT nDebugFlags; USHORT nLine1, nLine2; @@ -72,7 +73,7 @@ public: void GetLineRange( USHORT&, USHORT& ); // Interface to execute a method from the applications - virtual ErrCode Call( SbxValue* pRet = NULL ); + virtual ErrCode Call( SbxValue* pRet = NULL, SbxVariable* pCaller = NULL ); virtual void Broadcast( ULONG nHintId ); }; diff --git a/basic/inc/basic/sbmod.hxx b/basic/inc/basic/sbmod.hxx index ae52ca4046..dbf864925b 100644 --- a/basic/inc/basic/sbmod.hxx +++ b/basic/inc/basic/sbmod.hxx @@ -59,6 +59,8 @@ class SbModule : public SbxObject SbModuleImpl* mpSbModuleImpl; // Impl data std::vector< String > mModuleVariableNames; + SbModule(); + SbModule(const SbModule&); protected: com::sun::star::uno::Reference< com::sun::star::script::XInvocation > mxWrapper; @@ -132,6 +134,7 @@ public: BOOL LoadBinaryData( SvStream& ); BOOL ExceedsLegacyModuleSize(); void fixUpMethodStart( bool bCvtToLegacy, SbiImage* pImg = NULL ) const; + bool HasExeCode(); BOOL IsVBACompat() const; void SetVBACompat( BOOL bCompat ); INT32 GetModuleType() { return mnType; } diff --git a/basic/inc/basic/sbuno.hxx b/basic/inc/basic/sbuno.hxx index 27fe320dd8..c5e0209ffc 100644 --- a/basic/inc/basic/sbuno.hxx +++ b/basic/inc/basic/sbuno.hxx @@ -38,6 +38,7 @@ SbxObjectRef GetSbUnoObject( const String& aName, const com::sun::star::uno::Any // Force creation of all properties for debugging void createAllObjectProperties( SbxObject* pObj ); +void SetSbUnoObjectDfltPropName( SbxObject* pObj ); ::com::sun::star::uno::Any sbxToUnoValue( SbxVariable* pVar ); diff --git a/basic/source/basmgr/basmgr.cxx b/basic/source/basmgr/basmgr.cxx index 30dd13f8d3..6886acc37b 100644 --- a/basic/source/basmgr/basmgr.cxx +++ b/basic/source/basmgr/basmgr.cxx @@ -1,7 +1,7 @@ /************************************************************************* * * 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 @@ -343,7 +343,7 @@ void SAL_CALL BasMgrContainerListenerImpl::elementReplaced( const ContainerEvent pMod->SetSource32( aMod ); else pLib->MakeModule32( aName, aMod ); - + pLib->SetModified( FALSE ); } } @@ -1139,6 +1139,25 @@ void BasicManager::LegacyDeleteBasicManager( BasicManager*& _rpManager ) _rpManager = NULL; } + +bool BasicManager::HasExeCode( const String& sLib ) +{ + StarBASIC* pLib = GetLib(sLib); + if ( pLib ) + { + SbxArray* pMods = pLib->GetModules(); + USHORT nMods = pMods ? pMods->Count() : 0; + for( USHORT i = 0; i < nMods; i++ ) + { + SbModule* p = (SbModule*) pMods->Get( i ); + if ( p ) + if ( p->HasExeCode() ) + return true; + } + } + return false; +} + void BasicManager::Init() { DBG_CHKTHIS( BasicManager, 0 ); diff --git a/basic/source/classes/image.cxx b/basic/source/classes/image.cxx index 358da59409..916370e41d 100644 --- a/basic/source/classes/image.cxx +++ b/basic/source/classes/image.cxx @@ -431,7 +431,7 @@ void SbiImage::AddString( const String& r ) memcpy( p, pStrings, nStringSize * sizeof( sal_Unicode ) ); delete[] pStrings; pStrings = p; - nStringSize = sal::static_int_cast< UINT16 >(nNewLen); + nStringSize = sal::static_int_cast< UINT32 >(nNewLen); } else bError = TRUE; diff --git a/basic/source/classes/sb.cxx b/basic/source/classes/sb.cxx index 90b357395a..3da68f7229 100644 --- a/basic/source/classes/sb.cxx +++ b/basic/source/classes/sb.cxx @@ -611,93 +611,7 @@ SbClassModuleObject::~SbClassModuleObject() void SbClassModuleObject::SFX_NOTIFY( SfxBroadcaster& rBC, const TypeId& rBCType, const SfxHint& rHint, const TypeId& rHintType ) { - bool bDone = false; - - const SbxHint* pHint = PTR_CAST(SbxHint,&rHint); - if( pHint ) - { - SbxVariable* pVar = pHint->GetVar(); - SbProcedureProperty* pProcProperty = PTR_CAST( SbProcedureProperty, pVar ); - if( pProcProperty ) - { - bDone = true; - - if( pHint->GetId() == SBX_HINT_DATAWANTED ) - { - String aProcName; - aProcName.AppendAscii( "Property Get " ); - aProcName += pProcProperty->GetName(); - - SbxVariable* pMeth = Find( aProcName, SbxCLASS_METHOD ); - if( pMeth ) - { - SbxValues aVals; - aVals.eType = SbxVARIANT; - - 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 ); - } - } - else if( pHint->GetId() == SBX_HINT_DATACHANGED ) - { - SbxVariable* pMeth = NULL; - - bool bSet = pProcProperty->isSet(); - if( bSet ) - { - pProcProperty->setSet( false ); - - String aProcName; - aProcName.AppendAscii( "Property Set " ); - aProcName += pProcProperty->GetName(); - pMeth = Find( aProcName, SbxCLASS_METHOD ); - } - if( !pMeth ) // Let - { - String aProcName; - aProcName.AppendAscii( "Property Let " ); - aProcName += pProcProperty->GetName(); - pMeth = Find( aProcName, SbxCLASS_METHOD ); - } - - if( pMeth ) - { - // Setup parameters - SbxArrayRef xArray = new SbxArray; - xArray->Put( pMeth, 0 ); // Method as parameter 0 - xArray->Put( pVar, 1 ); - pMeth->SetParameters( xArray ); - - SbxValues aVals; - pMeth->Get( aVals ); - pMeth->SetParameters( NULL ); - } - } - } - } - - if( !bDone ) - SbModule::SFX_NOTIFY( rBC, rBCType, rHint, rHintType ); + SbModule::SFX_NOTIFY( rBC, rBCType, rHint, rHintType ); } SbxVariable* SbClassModuleObject::Find( const XubString& rName, SbxClassType t ) @@ -1217,7 +1131,6 @@ SbxVariable* StarBASIC::Find( const String& rName, SbxClassType t ) INT32 nType = p->GetModuleType(); if ( nType == ModuleType::DOCUMENT || nType == ModuleType::FORM ) continue; - // otherwise check if the element is available // unset GBLSEARCH-Flag (due to Rekursion) USHORT nGblFlag = p->GetFlags() & SBX_GBLSEARCH; diff --git a/basic/source/classes/sbunoobj.cxx b/basic/source/classes/sbunoobj.cxx index 6f53cbf6fb..55953d2e5b 100644 --- a/basic/source/classes/sbunoobj.cxx +++ b/basic/source/classes/sbunoobj.cxx @@ -1,7 +1,7 @@ /************************************************************************* * * 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 @@ -58,6 +58,7 @@ #include <com/sun/star/script/XInvocationAdapterFactory.hpp> #include <com/sun/star/script/XTypeConverter.hpp> #include <com/sun/star/script/XDefaultProperty.hpp> +#include <com/sun/star/script/XDefaultMethod.hpp> #include <com/sun/star/container/XNameAccess.hpp> #include <com/sun/star/container/XHierarchicalNameAccess.hpp> #include <com/sun/star/reflection/XIdlArray.hpp> @@ -69,7 +70,7 @@ #include <com/sun/star/bridge/oleautomation/Decimal.hpp> #include <com/sun/star/bridge/oleautomation/Currency.hpp> #include <com/sun/star/bridge/oleautomation/XAutomationObject.hpp> - +#include <com/sun/star/script/XAutomationInvocation.hpp> using com::sun::star::uno::Reference; using namespace com::sun::star::uno; @@ -155,6 +156,21 @@ SbxVariable* getDefaultProp( SbxVariable* pRef ) return pDefaultProp; } +void SetSbUnoObjectDfltPropName( SbxObject* pObj ) +{ + SbUnoObject* pUnoObj = PTR_CAST(SbUnoObject,(SbxObject*) pObj); + if ( pUnoObj ) + { + String sDfltPropName; + + if ( SbUnoObject::getDefaultPropName( pUnoObj, sDfltPropName ) ) + { + OSL_TRACE("SetSbUnoObjectDfltPropName setting dflt prop for %s", rtl::OUStringToOString( pObj->GetName(), RTL_TEXTENCODING_UTF8 ).getStr() ); + pUnoObj->SetDfltProperty( sDfltPropName ); + } + } +} + Reference< XComponentContext > getComponentContext_Impl( void ) { static Reference< XComponentContext > xContext; @@ -456,6 +472,32 @@ void implHandleWrappedTargetException( const Any& _rWrappedTargetException ) SbError nError( ERRCODE_BASIC_EXCEPTION ); ::rtl::OUStringBuffer aMessageBuf; + // Add for VBA, to get the correct error code and message. + if ( SbiRuntime::isVBAEnabled() ) + { + if ( aExamine >>= aBasicError ) + { + if ( aBasicError.ErrorCode != 0 ) + { + nError = StarBASIC::GetSfxFromVBError( (USHORT) aBasicError.ErrorCode ); + if ( nError == 0 ) + { + nError = (SbError) aBasicError.ErrorCode; + } + aMessageBuf.append( aBasicError.ErrorMessageArgument ); + aExamine.clear(); + } + } + + IndexOutOfBoundsException aIdxOutBndsExp; + if ( aExamine >>= aIdxOutBndsExp ) + { + nError = SbERR_OUT_OF_RANGE; + aExamine.clear(); + } + } + // End add + // strip any other WrappedTargetException instances, but this time preserve the error messages. WrappedTargetException aWrapped; sal_Int32 nLevel = 0; @@ -755,7 +797,7 @@ void unoToSbxValue( SbxVariable* pVar, const Any& aValue ) // instantiate a SbUnoObject String aName; SbUnoObject* pSbUnoObject = new SbUnoObject( aName, aValue ); - //If this is called externally e.g. from the scripting + //If this is called externally e.g. from the scripting //framework then there is no 'active' runtime the default property will not be set up //only a vba object will have XDefaultProp set anyway so... this //test seems a bit of overkill @@ -1505,6 +1547,101 @@ Any sbxToUnoValue( SbxVariable* pVar, const Type& rType, Property* pUnoProperty return aRetVal; } +void processAutomationParams( SbxArray* pParams, Sequence< Any >& args, bool bOLEAutomation, UINT32 nParamCount ) +{ + AutomationNamedArgsSbxArray* pArgNamesArray = NULL; + if( bOLEAutomation ) + pArgNamesArray = PTR_CAST(AutomationNamedArgsSbxArray,pParams); + + args.realloc( nParamCount ); + Any* pAnyArgs = args.getArray(); + bool bBlockConversionToSmallestType = pINST->IsCompatibility(); + UINT32 i = 0; + if( pArgNamesArray ) + { + Sequence< ::rtl::OUString >& rNameSeq = pArgNamesArray->getNames(); + ::rtl::OUString* pNames = rNameSeq.getArray(); + Any aValAny; + for( i = 0 ; i < nParamCount ; i++ ) + { + USHORT iSbx = (USHORT)(i+1); + + aValAny = sbxToUnoValueImpl( pParams->Get( iSbx ), + bBlockConversionToSmallestType ); + + ::rtl::OUString aParamName = pNames[iSbx]; + if( aParamName.getLength() ) + { + oleautomation::NamedArgument aNamedArgument; + aNamedArgument.Name = aParamName; + aNamedArgument.Value = aValAny; + pAnyArgs[i] <<= aNamedArgument; + } + else + { + pAnyArgs[i] = aValAny; + } + } + } + else + { + for( i = 0 ; i < nParamCount ; i++ ) + { + pAnyArgs[i] = sbxToUnoValueImpl( pParams->Get( (USHORT)(i+1) ), + bBlockConversionToSmallestType ); + } + } + +} +enum INVOKETYPE +{ + GetProp = 0, + SetProp, + Func +}; +Any invokeAutomationMethod( const String& Name, Sequence< Any >& args, SbxArray* pParams, UINT32 nParamCount, Reference< XInvocation >& rxInvocation, INVOKETYPE invokeType = Func ) +{ + Sequence< INT16 > OutParamIndex; + Sequence< Any > OutParam; + + Any aRetAny; + switch( invokeType ) + { + case Func: + aRetAny = rxInvocation->invoke( Name, args, OutParamIndex, OutParam ); + break; + case GetProp: + { + Reference< XAutomationInvocation > xAutoInv( rxInvocation, UNO_QUERY ); + aRetAny = xAutoInv->invokeGetProperty( Name, args, OutParamIndex, OutParam ); + break; + } + case SetProp: + { + Reference< XAutomationInvocation > xAutoInv( rxInvocation, UNO_QUERY_THROW ); + aRetAny = xAutoInv->invokePutProperty( Name, args, OutParamIndex, OutParam ); + break; + } + default: + break; // should introduce an error here + + } + const INT16* pIndices = OutParamIndex.getConstArray(); + UINT32 nLen = OutParamIndex.getLength(); + if( nLen ) + { + const Any* pNewValues = OutParam.getConstArray(); + for( UINT32 j = 0 ; j < nLen ; j++ ) + { + INT16 iTarget = pIndices[ j ]; + if( iTarget >= (INT16)nParamCount ) + break; + unoToSbxValue( (SbxVariable*)pParams->Get( (USHORT)(j+1) ), pNewValues[ j ] ); + } + } + return aRetAny; +} + // Debugging help method to readout the imlemented interfaces of an object String Impl_GetInterfaceInfo( const Reference< XInterface >& x, const Reference< XIdlClass >& xClass, USHORT nRekLevel ) { @@ -2011,11 +2148,24 @@ void SbUnoObject::SFX_NOTIFY( SfxBroadcaster& rBC, const TypeId& rBCType, { try { - // get the value - Any aRetAny = mxInvocation->getValue( pProp->GetName() ); - + UINT32 nParamCount = pParams ? ((UINT32)pParams->Count() - 1) : 0; + sal_Bool bCanBeConsideredAMethod = mxInvocation->hasMethod( pProp->GetName() ); + Any aRetAny; + if ( bCanBeConsideredAMethod && nParamCount ) + { + // Automation properties have methods, so.. we need to invoke this through + // XInvocation + Sequence<Any> args; + processAutomationParams( pParams, args, true, nParamCount ); + aRetAny = invokeAutomationMethod( pProp->GetName(), args, pParams, nParamCount, mxInvocation, GetProp ); + } + else + aRetAny = mxInvocation->getValue( pProp->GetName() ); // take over the value from Uno to Sbx unoToSbxValue( pVar, aRetAny ); + if( pParams && bCanBeConsideredAMethod ) + pVar->SetParameters( NULL ); + } catch( const Exception& ) { @@ -2140,52 +2290,7 @@ void SbUnoObject::SFX_NOTIFY( SfxBroadcaster& rBC, const TypeId& rBCType, else if( bInvocation && pParams && mxInvocation.is() ) { bool bOLEAutomation = true; - // TODO: bOLEAutomation = xOLEAutomation.is() - - AutomationNamedArgsSbxArray* pArgNamesArray = NULL; - if( bOLEAutomation ) - pArgNamesArray = PTR_CAST(AutomationNamedArgsSbxArray,pParams); - - args.realloc( nParamCount ); - Any* pAnyArgs = args.getArray(); - bool bBlockConversionToSmallestType = pINST->IsCompatibility(); - if( pArgNamesArray ) - { - Sequence< ::rtl::OUString >& rNameSeq = pArgNamesArray->getNames(); - ::rtl::OUString* pNames = rNameSeq.getArray(); - - Any aValAny; - for( i = 0 ; i < nParamCount ; i++ ) - { - USHORT iSbx = (USHORT)(i+1); - - // ATTENTION: Don't forget for Sbx-Parameter the offset! - aValAny = sbxToUnoValueImpl( pParams->Get( iSbx ), - bBlockConversionToSmallestType ); - - ::rtl::OUString aParamName = pNames[iSbx]; - if( aParamName.getLength() ) - { - oleautomation::NamedArgument aNamedArgument; - aNamedArgument.Name = aParamName; - aNamedArgument.Value = aValAny; - pAnyArgs[i] <<= aNamedArgument; - } - else - { - pAnyArgs[i] = aValAny; - } - } - } - else - { - for( i = 0 ; i < nParamCount ; i++ ) - { - // ATTENTION: Don't forget for Sbx-Parameter the offset! - pAnyArgs[i] = sbxToUnoValueImpl( pParams->Get( (USHORT)(i+1) ), - bBlockConversionToSmallestType ); - } - } + processAutomationParams( pParams, args, bOLEAutomation, nParamCount ); } // call the method @@ -2220,26 +2325,8 @@ void SbUnoObject::SFX_NOTIFY( SfxBroadcaster& rBC, const TypeId& rBCType, } else if( bInvocation && mxInvocation.is() ) { - Sequence< INT16 > OutParamIndex; - Sequence< Any > OutParam; - Any aRetAny = mxInvocation->invoke( pMeth->GetName(), args, OutParamIndex, OutParam ); - - // take over the value from Uno to Sbx + Any aRetAny = invokeAutomationMethod( pMeth->GetName(), args, pParams, nParamCount, mxInvocation ); unoToSbxValue( pVar, aRetAny ); - - const INT16* pIndices = OutParamIndex.getConstArray(); - UINT32 nLen = OutParamIndex.getLength(); - if( nLen ) - { - const Any* pNewValues = OutParam.getConstArray(); - for( UINT32 j = 0 ; j < nLen ; j++ ) - { - INT16 iTarget = pIndices[ j ]; - if( iTarget >= (INT16)nParamCount ) - break; - unoToSbxValue( (SbxVariable*)pParams->Get( (USHORT)(j+1) ), pNewValues[ j ] ); - } - } } // remove parameter here, because this was not done anymore in unoToSbxValue() @@ -2937,7 +3024,7 @@ void RTL_Impl_CreateUnoServiceWithArguments( StarBASIC* pBasic, SbxArray& rPar, { (void)pBasic; (void)bWrite; - + // We need 2 parameter minimum if ( rPar.Count() < 3 ) { @@ -3177,11 +3264,16 @@ getTypeDescriptorEnumeration( const ::rtl::OUString& sSearchRoot, typedef std::hash_map< ::rtl::OUString, Any, ::rtl::OUStringHash, ::std::equal_to< ::rtl::OUString > > VBAConstantsHash; -SbxVariable* getVBAConstant( const String& rName ) +VBAConstantHelper& +VBAConstantHelper::instance() +{ + static VBAConstantHelper aHelper; + return aHelper; +} + +void +VBAConstantHelper::init() { - SbxVariable* pConst = NULL; - static VBAConstantsHash aConstCache; - static bool isInited = false; if ( !isInited ) { Sequence< TypeClass > types(1); @@ -3189,39 +3281,77 @@ SbxVariable* getVBAConstant( const String& rName ) Reference< XTypeDescriptionEnumeration > xEnum = getTypeDescriptorEnumeration( defaultNameSpace, types, TypeDescriptionSearchDepth_INFINITE ); if ( !xEnum.is() ) - return NULL; + return; //NULL; while ( xEnum->hasMoreElements() ) { Reference< XConstantsTypeDescription > xConstants( xEnum->nextElement(), UNO_QUERY ); if ( xConstants.is() ) { + // store constant group name + ::rtl::OUString sFullName = xConstants->getName(); + sal_Int32 indexLastDot = sFullName.lastIndexOf('.'); + ::rtl::OUString sLeafName( sFullName ); + if ( indexLastDot > -1 ) + sLeafName = sFullName.copy( indexLastDot + 1); + aConstCache.push_back( sLeafName ); // assume constant group names are unique Sequence< Reference< XConstantTypeDescription > > aConsts = xConstants->getConstants(); Reference< XConstantTypeDescription >* pSrc = aConsts.getArray(); sal_Int32 nLen = aConsts.getLength(); for ( sal_Int32 index =0; index<nLen; ++pSrc, ++index ) { + // store constant member name Reference< XConstantTypeDescription >& rXConst = *pSrc; - ::rtl::OUString sFullName = rXConst->getName(); - sal_Int32 indexLastDot = sFullName.lastIndexOf('.'); - ::rtl::OUString sLeafName; + sFullName = rXConst->getName(); + indexLastDot = sFullName.lastIndexOf('.'); + sLeafName = sFullName; if ( indexLastDot > -1 ) sLeafName = sFullName.copy( indexLastDot + 1); - aConstCache[ sLeafName.toAsciiLowerCase() ] = rXConst->getConstantValue(); + aConstHash[ sLeafName.toAsciiLowerCase() ] = rXConst->getConstantValue(); } } } isInited = true; } +} + +bool +VBAConstantHelper::isVBAConstantType( const String& rName ) +{ + init(); + bool bConstant = false; + ::rtl::OUString sKey( rName ); + VBAConstantsVector::const_iterator it = aConstCache.begin(); + + for( ; it != aConstCache.end(); it++ ) + { + if( sKey.equalsIgnoreAsciiCase( *it ) ) + { + bConstant = true; + break; + } + } + return bConstant; +} + +SbxVariable* +VBAConstantHelper::getVBAConstant( const String& rName ) +{ + SbxVariable* pConst = NULL; + init(); + ::rtl::OUString sKey( rName ); - VBAConstantsHash::const_iterator it = aConstCache.find( sKey.toAsciiLowerCase() ); - if ( it != aConstCache.end() ) + + VBAConstantsHash::const_iterator it = aConstHash.find( sKey.toAsciiLowerCase() ); + + if ( it != aConstHash.end() ) { pConst = new SbxVariable( SbxVARIANT ); pConst->SetName( rName ); unoToSbxValue( pConst, it->second ); } + return pConst; } @@ -3424,7 +3554,7 @@ SbxVariable* SbUnoService::Find( const String& rName, SbxClassType ) for( int i = 0 ; i < nCtorCount ; ++i ) { Reference< XServiceConstructorDescription > xCtor = pCtorSeq[i]; - + String aName( xCtor->getName() ); if( !aName.Len() ) { @@ -3569,7 +3699,7 @@ void SbUnoService::SFX_NOTIFY( SfxBroadcaster& rBC, const TypeId& rBCType, Reference < XPropertySet > xProps( ::comphelper::getProcessServiceFactory(), UNO_QUERY_THROW ); xContext.set( xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" )) ), UNO_QUERY_THROW ); } - Reference< XMultiComponentFactory > xServiceMgr( xContext->getServiceManager() ); + Reference< XMultiComponentFactory > xServiceMgr( xContext->getServiceManager() ); Any aRetAny; if( xServiceMgr.is() ) @@ -3726,7 +3856,7 @@ void SbUnoSingleton::SFX_NOTIFY( SfxBroadcaster& rBC, const TypeId& rBCType, SbxObject::SFX_NOTIFY( rBC, rBCType, rHint, rHintType ); } - + //======================================================================== //======================================================================== //======================================================================== @@ -4188,7 +4318,7 @@ public: throw( UnknownPropertyException ); virtual sal_Bool SAL_CALL hasMethod( const ::rtl::OUString& rName ) throw(); virtual sal_Bool SAL_CALL hasProperty( const ::rtl::OUString& rProp ) throw(); - + virtual Any SAL_CALL invoke( const ::rtl::OUString& rFunction, const Sequence< Any >& rParams, Sequence< sal_Int16 >& rOutParamIndex, @@ -4344,7 +4474,7 @@ Reference< XInterface > createComListener( const Any& aControlAny, const ::rtl:: Reference< XInterface > xRet; Reference< XComponentContext > xContext = getComponentContext_Impl(); - Reference< XMultiComponentFactory > xServiceMgr( xContext->getServiceManager() ); + Reference< XMultiComponentFactory > xServiceMgr( xContext->getServiceManager() ); Reference< XInvocation > xProxy = new ModuleInvocationProxy( aPrefix, xScopeObj ); @@ -4374,7 +4504,7 @@ bool SbModule::createCOMWrapperForIface( Any& o_rRetAny, SbClassModuleObject* pP // TODO: Check if support for multiple interfaces is needed Reference< XComponentContext > xContext = getComponentContext_Impl(); - Reference< XMultiComponentFactory > xServiceMgr( xContext->getServiceManager() ); + Reference< XMultiComponentFactory > xServiceMgr( xContext->getServiceManager() ); Reference< XSingleServiceFactory > xComImplementsFactory ( xServiceMgr->createInstanceWithContext( diff --git a/basic/source/classes/sbxmod.cxx b/basic/source/classes/sbxmod.cxx index e805f9bbcf..d647d4c9a9 100644 --- a/basic/source/classes/sbxmod.cxx +++ b/basic/source/classes/sbxmod.cxx @@ -1,7 +1,7 @@ /************************************************************************* * * 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 @@ -56,6 +56,7 @@ #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/script/ModuleType.hpp> #include <com/sun/star/script/vba/XVBACompatibility.hpp> +#include <com/sun/star/document/XVbaMethodParameter.hpp> #include <com/sun/star/beans/XPropertySet.hpp> using namespace com::sun::star; @@ -84,7 +85,7 @@ using namespace com::sun::star; #include <map> #include <com/sun/star/script/XInvocation.hpp> - using namespace ::com::sun::star; + using namespace ::com::sun::star; using namespace com::sun::star::lang; using namespace com::sun::star::reflection; using namespace com::sun::star::beans; @@ -117,7 +118,7 @@ class DocObjectWrapper : public DocObjectWrapper_BASE SbPropertyRef getProperty( const rtl::OUString& aName ) throw (RuntimeException); String mName; // for debugging -public: +public: DocObjectWrapper( SbModule* pMod ); virtual ~DocObjectWrapper(); @@ -139,16 +140,16 @@ public: 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 ) + if ( pMod->GetModuleType() == ModuleType::DOCUMENT ) { Reference< XMultiServiceFactory > xFactory = comphelper::getProcessServiceFactory(); // Use proxy factory service to create aggregatable proxy. @@ -156,7 +157,7 @@ DocObjectWrapper::DocObjectWrapper( SbModule* pVar ) : m_pMod( pVar ), mName( pV Reference< XInterface > xIf; if ( pUnoObj ) { - Any aObj = pUnoObj->getUnoAny(); + Any aObj = pUnoObj->getUnoAny(); aObj >>= xIf; if ( xIf.is() ) { @@ -181,11 +182,11 @@ DocObjectWrapper::DocObjectWrapper( SbModule* pVar ) : m_pMod( pVar ), mName( pV 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 @@ -193,7 +194,7 @@ DocObjectWrapper::DocObjectWrapper( SbModule* pVar ) : m_pMod( pVar ), mName( pV { m_xAggProxy->setDelegator( static_cast< cppu::OWeakObject * >( this ) ); } - + osl_decrementInterlockedCount( &m_refCount ); } } @@ -206,7 +207,7 @@ 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 +void SAL_CALL DocObjectWrapper::release() throw () { if ( osl_decrementInterlockedCount( &m_refCount ) == 0 ) @@ -226,7 +227,7 @@ Sequence< Type > SAL_CALL DocObjectWrapper::getTypes() throw ( RuntimeException ) { if ( m_Types.getLength() == 0 ) - { + { Sequence< Type > sTypes; if ( m_xAggregateTypeProv.is() ) sTypes = m_xAggregateTypeProv->getTypes(); @@ -234,7 +235,7 @@ Sequence< Type > SAL_CALL DocObjectWrapper::getTypes() Type* pPtr = m_Types.getArray(); for ( int i=0; i<m_Types.getLength(); ++i, ++pPtr ) { - if ( i == 0 ) + if ( i == 0 ) *pPtr = XInvocation::static_type( NULL ); else *pPtr = sTypes[ i - 1 ]; @@ -243,13 +244,13 @@ Sequence< Type > SAL_CALL DocObjectWrapper::getTypes() return m_Types; } -Reference< XIntrospectionAccess > SAL_CALL +Reference< XIntrospectionAccess > SAL_CALL DocObjectWrapper::getIntrospection( ) throw (RuntimeException) { return NULL; } -Any SAL_CALL +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 ) ) @@ -344,19 +345,19 @@ DocObjectWrapper::invoke( const ::rtl::OUString& aFunctionName, const Sequence< return aReturn; } -void SAL_CALL +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 +Any SAL_CALL DocObjectWrapper::getValue( const ::rtl::OUString& aPropertyName ) throw (UnknownPropertyException, RuntimeException) { if ( m_xAggInv.is() && m_xAggInv->hasProperty( aPropertyName ) ) @@ -374,20 +375,20 @@ DocObjectWrapper::getValue( const ::rtl::OUString& aPropertyName ) throw (Unknow return aRet; } -::sal_Bool SAL_CALL +::sal_Bool SAL_CALL DocObjectWrapper::hasMethod( const ::rtl::OUString& aName ) throw (RuntimeException) { if ( m_xAggInv.is() && m_xAggInv->hasMethod( aName ) ) - return sal_True; + return sal_True; return getMethod( aName ).Is(); } -::sal_Bool SAL_CALL +::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; + bRes = sal_True; else bRes = getProperty( aName ).Is(); return bRes; } @@ -458,7 +459,7 @@ bool getDefaultVBAMode( StarBASIC* pb ) { uno::Reference< beans::XPropertySet > xProp( aDoc, uno::UNO_QUERY ); if ( xProp.is() ) - { + { uno::Reference< script::vba::XVBACompatibility > xVBAMode( xProp->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("BasicLibraries") ) ), uno::UNO_QUERY ); if ( xVBAMode.is() ) bResult = xVBAMode->getVBACompatibilityMode() == sal_True; @@ -473,7 +474,7 @@ class AsyncQuitHandler AsyncQuitHandler() {} AsyncQuitHandler( const AsyncQuitHandler&); public: - static AsyncQuitHandler& instance() + static AsyncQuitHandler& instance() { static AsyncQuitHandler dInst; return dInst; @@ -486,7 +487,7 @@ public: { uno::Reference< frame::XDesktop > xDeskTop( xFactory->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.Desktop") ) ), uno::UNO_QUERY ); if ( xDeskTop.is() ) - xDeskTop->terminate(); + xDeskTop->terminate(); } } DECL_LINK( OnAsyncQuit, void* ); @@ -498,7 +499,6 @@ IMPL_LINK( AsyncQuitHandler, OnAsyncQuit, void*, /*pNull*/ ) return 0L; } -#if 0 bool UnlockControllerHack( StarBASIC* pBasic ) { bool bRes = false; @@ -508,7 +508,7 @@ bool UnlockControllerHack( StarBASIC* pBasic ) ::rtl::OUString sVarName( ::rtl::OUString::createFromAscii( "ThisComponent" ) ); SbUnoObject* pGlobs = dynamic_cast<SbUnoObject*>( pBasic->Find( sVarName, SbxCLASS_DONTCARE ) ); if ( pGlobs ) - aUnoVar = pGlobs->getUnoAny(); + aUnoVar = pGlobs->getUnoAny(); uno::Reference< frame::XModel > xModel( aUnoVar, uno::UNO_QUERY); if ( xModel.is() ) { @@ -524,7 +524,7 @@ bool UnlockControllerHack( StarBASIC* pBasic ) } return bRes; } -#endif + ///////////////////////////////////////////////////////////////////////////// // A Basic module has set EXTSEARCH, so that the elements, that the modul contains, @@ -793,6 +793,82 @@ void SbModule::SFX_NOTIFY( SfxBroadcaster& rBC, const TypeId& rBCType, SbxVariable* pVar = pHint->GetVar(); SbProperty* pProp = PTR_CAST(SbProperty,pVar); SbMethod* pMeth = PTR_CAST(SbMethod,pVar); + SbProcedureProperty* pProcProperty = PTR_CAST( SbProcedureProperty, pVar ); + if( pProcProperty ) + { + + if( pHint->GetId() == SBX_HINT_DATAWANTED ) + { + String aProcName; + aProcName.AppendAscii( "Property Get " ); + aProcName += pProcProperty->GetName(); + + SbxVariable* pMethVar = Find( aProcName, SbxCLASS_METHOD ); + if( pMethVar ) + { + SbxValues aVals; + aVals.eType = SbxVARIANT; + + SbxArray* pArg = pVar->GetParameters(); + USHORT nVarParCount = (pArg != NULL) ? pArg->Count() : 0; + if( nVarParCount > 1 ) + { + SbxArrayRef xMethParameters = new SbxArray; + xMethParameters->Put( pMethVar, 0 ); // Method as parameter 0 + for( USHORT i = 1 ; i < nVarParCount ; ++i ) + { + SbxVariable* pPar = pArg->Get( i ); + xMethParameters->Put( pPar, i ); + } + + pMethVar->SetParameters( xMethParameters ); + pMethVar->Get( aVals ); + pMethVar->SetParameters( NULL ); + } + else + { + pMethVar->Get( aVals ); + } + + pVar->Put( aVals ); + } + } + else if( pHint->GetId() == SBX_HINT_DATACHANGED ) + { + SbxVariable* pMethVar = NULL; + + bool bSet = pProcProperty->isSet(); + if( bSet ) + { + pProcProperty->setSet( false ); + + String aProcName; + aProcName.AppendAscii( "Property Set " ); + aProcName += pProcProperty->GetName(); + pMethVar = Find( aProcName, SbxCLASS_METHOD ); + } + if( !pMethVar ) // Let + { + String aProcName; + aProcName.AppendAscii( "Property Let " ); + aProcName += pProcProperty->GetName(); + pMethVar = Find( aProcName, SbxCLASS_METHOD ); + } + + if( pMethVar ) + { + // Setup parameters + SbxArrayRef xArray = new SbxArray; + xArray->Put( pMethVar, 0 ); // Method as parameter 0 + xArray->Put( pVar, 1 ); + pMethVar->SetParameters( xArray ); + + SbxValues aVals; + pMethVar->Get( aVals ); + pMethVar->SetParameters( NULL ); + } + } + } if( pProp ) { if( pProp->GetModule() != this ) @@ -817,7 +893,7 @@ void SbModule::SFX_NOTIFY( SfxBroadcaster& rBC, const TypeId& rBCType, } else { - // #i92642: Special handling for name property to avoid + // #i92642: Special handling for name property to avoid // side effects when using name as variable implicitely bool bForwardToSbxObject = true; @@ -847,6 +923,7 @@ void SbModule::SetSource32( const ::rtl::OUString& r ) aOUSource = r; StartDefinitions(); SbiTokenizer aTok( r ); + aTok.SetCompatible( IsVBACompat() ); while( !aTok.IsEof() ) { SbiToken eEndTok = NIL; @@ -877,7 +954,7 @@ void SbModule::SetSource32( const ::rtl::OUString& r ) if( eCurTok == COMPATIBLE ) aTok.SetCompatible( true ); else if ( ( eCurTok == VBASUPPORT ) && ( aTok.Next() == NUMBER ) ) - { + { BOOL bIsVBA = ( aTok.GetDbl()== 1 ); SetVBACompat( bIsVBA ); aTok.SetCompatible( bIsVBA ); @@ -1026,7 +1103,7 @@ BOOL SbModule::IsVBACompat() const { return mbVBACompat; } - + void SbModule::SetVBACompat( BOOL bCompat ) { mbVBACompat = bCompat; @@ -1034,12 +1111,14 @@ void SbModule::SetVBACompat( BOOL bCompat ) // Run a Basic-subprogram USHORT SbModule::Run( SbMethod* pMeth ) { + OSL_TRACE("About to run %s, vba compatmode is %d", rtl::OUStringToOString( pMeth->GetName(), RTL_TEXTENCODING_UTF8 ).getStr(), mbVBACompat ); static USHORT nMaxCallLevel = 0; static String aMSOMacroRuntimeLibName = String::CreateFromAscii( "Launcher" ); static String aMSOMacroRuntimeAppSymbol = String::CreateFromAscii( "Application" ); USHORT nRes = 0; BOOL bDelInst = BOOL( pINST == NULL ); + bool bQuit = false; StarBASICRef xBasic; if( bDelInst ) { @@ -1172,6 +1251,15 @@ USHORT SbModule::Run( SbMethod* pMeth ) delete pRt; pMOD = pOldMod; + if ( pINST->nCallLvl == 0 && IsVBACompat() ) + { + // VBA always ensure screenupdating is enabled after completing + StarBASIC* pBasic = PTR_CAST(StarBASIC,GetParent()); + if ( pBasic && pBasic->IsDocBasic() ) + { + UnlockControllerHack( pBasic ); + } + } if( bDelInst ) { // #57841 Clear Uno-Objects, which were helt in RTL functions, @@ -1199,10 +1287,8 @@ USHORT SbModule::Run( SbMethod* pMeth ) // VBA always ensure screenupdating is enabled after completing StarBASIC* pBasic = PTR_CAST(StarBASIC,GetParent()); -#if 0 if ( pBasic && pBasic->IsDocBasic() && !pINST ) UnlockControllerHack( pBasic ); -#endif if( bDelInst ) { // #57841 Clear Uno-Objects, which were helt in RTL functions, @@ -1213,6 +1299,8 @@ USHORT SbModule::Run( SbMethod* pMeth ) pINST = NULL; } if ( pBasic && pBasic->IsDocBasic() && pBasic->IsQuitApplication() && !pINST ) + bQuit = true; + if ( bQuit ) { Application::PostUserEvent( LINK( &AsyncQuitHandler::instance(), AsyncQuitHandler, OnAsyncQuit ), NULL ); } @@ -1268,16 +1356,16 @@ void SbModule::RunInit() // Delete with private/dim declared variables -void SbModule::AddVarName( const String& aName ) -{ +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; + return; } - mModuleVariableNames.push_back( aName ); + mModuleVariableNames.push_back( aName ); } void SbModule::RemoveVars() @@ -1285,8 +1373,8 @@ 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 + // 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() ) @@ -1663,6 +1751,48 @@ BOOL SbModule::ExceedsLegacyModuleSize() return false; } +class ErrorHdlResetter +{ + Link mErrHandler; + bool mbError; + public: + ErrorHdlResetter() : mbError( false ) + { + // save error handler + mErrHandler = StarBASIC::GetGlobalErrorHdl(); + // set new error handler + StarBASIC::SetGlobalErrorHdl( LINK( this, ErrorHdlResetter, BasicErrorHdl ) ); + } + ~ErrorHdlResetter() + { + // restore error handler + StarBASIC::SetGlobalErrorHdl(mErrHandler); + } + DECL_LINK( BasicErrorHdl, StarBASIC * ); + bool HasError() { return mbError; } +}; +IMPL_LINK( ErrorHdlResetter, BasicErrorHdl, StarBASIC *, /*pBasic*/) +{ + mbError = true; + return 0; +} + +bool SbModule::HasExeCode() +{ + + ErrorHdlResetter aGblErrHdl; + // And empty Image always has the Global Chain set up + static const unsigned char pEmptyImage[] = { 0x45, 0x0 , 0x0, 0x0, 0x0 }; + // lets be stricter for the moment than VBA + + bool bRes = false; + if ( !IsCompiled() ) + Compile(); + if ( pImage && !( pImage->GetCodeSize() == 5 && ( memcmp( pImage->GetCode(), pEmptyImage, pImage->GetCodeSize() ) == 0 ) ) + || aGblErrHdl.HasError() ) + bRes = true; + return bRes; +} // Store only image, no source BOOL SbModule::StoreBinaryData( SvStream& rStrm ) @@ -1712,7 +1842,6 @@ BOOL SbModule::LoadBinaryData( SvStream& rStrm ) return bRet; } - BOOL SbModule::LoadCompleted() { SbxArray* p = GetMethods(); @@ -1780,6 +1909,7 @@ SbMethod::SbMethod( const String& r, SbxDataType t, SbModule* p ) nLine1 = nLine2 = 0; refStatics = new SbxArray; + mCaller = 0; // From: 1996-07.02: HACK due to 'Referenz could not be saved' SetFlag( SBX_NO_MODIFY ); } @@ -1793,7 +1923,8 @@ SbMethod::SbMethod( const SbMethod& r ) nDebugFlags = r.nDebugFlags; nLine1 = r.nLine1; nLine2 = r.nLine2; - refStatics = r.refStatics; + refStatics = r.refStatics; + mCaller = r.mCaller; SetFlag( SBX_NO_MODIFY ); } @@ -1812,7 +1943,7 @@ SbxArray* SbMethod::GetLocals() void SbMethod::ClearStatics() { refStatics = new SbxArray; - + } SbxArray* SbMethod::GetStatics() { @@ -1862,9 +1993,14 @@ SbxInfo* SbMethod::GetInfo() // Interface to execute a method of the applications // #34191# With special RefCounting, damit so that the Basic was not fired of by CloseDocument() // The return value will be delivered as string. -ErrCode SbMethod::Call( SbxValue* pRet ) +ErrCode SbMethod::Call( SbxValue* pRet, SbxVariable* pCaller ) { - // Increment the RefCount of the module + if ( pCaller ) + { + OSL_TRACE("SbMethod::Call Have been passed a caller 0x%x", pCaller ); + mCaller = pCaller; + } + // RefCount vom Modul hochzaehlen SbModule* pMod_ = (SbModule*)GetParent(); pMod_->AddRef(); @@ -1891,7 +2027,7 @@ ErrCode SbMethod::Call( SbxValue* pRet ) // Release objects pMod_->ReleaseRef(); pBasic->ReleaseRef(); - + mCaller = 0; return nErr; } @@ -1970,7 +2106,7 @@ SbObjModule::SetUnoObject( const uno::Any& aObj ) throw ( uno::RuntimeException if ( pUnoObj && pUnoObj->getUnoAny() == aObj ) // object is equal, nothing to do return; pDocObject = new SbUnoObject( GetName(), uno::makeAny( aObj ) ); - + com::sun::star::uno::Reference< com::sun::star::lang::XServiceInfo > xServiceInfo( aObj, com::sun::star::uno::UNO_QUERY_THROW ); if( xServiceInfo->supportsService( rtl::OUString::createFromAscii( "ooo.vba.excel.Worksheet" ) ) ) { @@ -1983,7 +2119,7 @@ SbObjModule::SetUnoObject( const uno::Any& aObj ) throw ( uno::RuntimeException } SbxVariable* -SbObjModule::GetObject() +SbObjModule::GetObject() { return pDocObject; } @@ -2072,11 +2208,10 @@ public: } } } - + //liuchen 2009-7-21, support Excel VBA Form_QueryClose event - virtual void SAL_CALL windowClosing( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException) - { -#if IN_THE_FUTURE + virtual void SAL_CALL windowClosing( const lang::EventObject& e ) throw (uno::RuntimeException) + { uno::Reference< awt::XDialog > xDialog( e.Source, uno::UNO_QUERY ); if ( xDialog.is() ) { @@ -2085,7 +2220,7 @@ public: { uno::Reference< document::XVbaMethodParameter > xVbaMethodParameter( xControl->getPeer(), uno::UNO_QUERY ); if ( xVbaMethodParameter.is() ) - { + { sal_Int8 nCancel = 0; sal_Int8 nCloseMode = 0; @@ -2098,16 +2233,15 @@ public: aParams); xVbaMethodParameter->setVbaMethodParameter( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Cancel")), aParams[0]); return; - - } - } + + } + } } - + mpUserForm->triggerMethod( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Userform_QueryClose") ) ); -#endif } //liuchen 2009-7-21 - + virtual void SAL_CALL windowClosed( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException) { mbOpened = sal_False; @@ -2134,7 +2268,7 @@ public: } } } - + virtual void SAL_CALL windowDeactivated( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException) { if ( mpUserForm ) @@ -2201,14 +2335,13 @@ void SbUserFormModule::triggerMethod( const String& aMethodToRun ) Sequence< Any > aArguments; triggerMethod( aMethodToRun, aArguments ); } -void SbUserFormModule::triggerMethod( const String& aMethodToRun, Sequence< Any >& /*aArguments*/) +void SbUserFormModule::triggerMethod( const String& aMethodToRun, Sequence< Any >& aArguments) { OSL_TRACE("*** trigger %s ***", rtl::OUStringToOString( aMethodToRun, RTL_TEXTENCODING_UTF8 ).getStr() ); // Search method SbxVariable* pMeth = SbObjModule::Find( aMethodToRun, SbxCLASS_METHOD ); if( pMeth ) - { -#if IN_THE_FUTURE + { //liuchen 2009-7-21, support Excel VBA UserForm_QueryClose event with parameters if ( aArguments.getLength() > 0 ) // Setup parameters { @@ -2229,16 +2362,15 @@ void SbUserFormModule::triggerMethod( const String& aMethodToRun, Sequence< Any SbxValues aVals; pMeth->Get( aVals ); - + for ( sal_Int32 i = 0; i < aArguments.getLength(); ++i ) { aArguments[i] = sbxToUnoValue( xArray->Get( static_cast< USHORT >(i) + 1) ); - } + } pMeth->SetParameters( NULL ); } else //liuchen 2009-7-21 -#endif { SbxValues aVals; pMeth->Get( aVals ); @@ -2340,11 +2472,14 @@ void SbUserFormModule::Unload() triggerMethod( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Userform_QueryClose") ), aParams); aParams[0] >>= nCancel; - if (nCancel == 1) + // basic boolean ( and what the user might use ) can be ambiguous ( e.g. basic true = -1 ) + // test agains 0 ( false ) and assume anything else is true + // ( Note: ) this used to work ( something changes somewhere ) + if (nCancel != 0) { return; } - + if ( m_xDialog.is() ) { triggerTerminateEvent(); @@ -2379,10 +2514,10 @@ void SbUserFormModule::InitObject() { String aHook( RTL_CONSTASCII_USTRINGPARAM( "VBAGlobals" ) ); - SbUnoObject* pGlobs = (SbUnoObject*)GetParent()->Find( aHook, SbxCLASS_DONTCARE ); + SbUnoObject* pGlobs = (SbUnoObject*)GetParent()->Find( aHook, SbxCLASS_DONTCARE ); if ( m_xModel.is() && pGlobs ) { - + uno::Reference< lang::XMultiServiceFactory > xVBAFactory( pGlobs->getUnoAny(), uno::UNO_QUERY_THROW ); uno::Reference< lang::XMultiServiceFactory > xFactory = comphelper::getProcessServiceFactory(); uno::Sequence< uno::Any > aArgs(1); @@ -2390,8 +2525,8 @@ void SbUserFormModule::InitObject() rtl::OUString sDialogUrl( RTL_CONSTASCII_USTRINGPARAM("vnd.sun.star.script:" ) ); rtl::OUString sProjectName( RTL_CONSTASCII_USTRINGPARAM("Standard") ); if ( this->GetParent()->GetName().Len() ) - sProjectName = this->GetParent()->GetName(); - sDialogUrl = sDialogUrl.concat( sProjectName ).concat( rtl::OUString( '.') ).concat( GetName() ).concat( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("?location=document") ) ); + sProjectName = this->GetParent()->GetName(); + sDialogUrl = sDialogUrl.concat( sProjectName ).concat( rtl::OUString( '.') ).concat( GetName() ).concat( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("?location=document") ) ); uno::Reference< awt::XDialogProvider > xProvider( xFactory->createInstanceWithArguments( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.DialogProvider")), aArgs ), uno::UNO_QUERY_THROW ); m_xDialog = xProvider->createDialog( sDialogUrl ); @@ -2401,7 +2536,7 @@ void SbUserFormModule::InitObject() aArgs[ 0 ] = uno::Any(); aArgs[ 1 ] <<= m_xDialog; aArgs[ 2 ] <<= m_xModel; - aArgs[ 3 ] <<= rtl::OUString( GetParent()->GetName() ); + aArgs[ 3 ] <<= sProjectName; 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 diff --git a/basic/source/comp/codegen.cxx b/basic/source/comp/codegen.cxx index 256dcf92e0..22f3b32315 100644 --- a/basic/source/comp/codegen.cxx +++ b/basic/source/comp/codegen.cxx @@ -163,8 +163,6 @@ void SbiCodeGen::Save() rMod.bIsProxyModule = false; } - if( pParser->bText ) - p->SetFlag( SBIMG_COMPARETEXT ); // GlobalCode-Flag if( pParser->HasGlobalCode() ) p->SetFlag( SBIMG_INITCODE ); @@ -244,6 +242,8 @@ void SbiCodeGen::Save() if( nPass == 1 ) aPropName = aPropName.Copy( aIfaceName.Len() + 1 ); SbProcedureProperty* pProcedureProperty = NULL; + OSL_TRACE("*** getProcedureProperty for thing %s", + rtl::OUStringToOString( aPropName,RTL_TEXTENCODING_UTF8 ).getStr() ); pProcedureProperty = rMod.GetProcedureProperty( aPropName, ePropType ); } if( nPass == 1 ) diff --git a/basic/source/comp/dim.cxx b/basic/source/comp/dim.cxx index 367be2a3e3..c17f4a874d 100644 --- a/basic/source/comp/dim.cxx +++ b/basic/source/comp/dim.cxx @@ -1,7 +1,7 @@ /************************************************************************* * * 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 @@ -29,6 +29,8 @@ #include "precompiled_basic.hxx" #include <basic/sbx.hxx> #include "sbcomp.hxx" +#include "sbunoobj.hxx" + SbxObject* cloneTypeObjectImpl( const SbxObject& rTypeObj ); @@ -153,7 +155,7 @@ void SbiParser::TypeDecl( SbiSymDef& rDef, BOOL bAsNewAlreadyParsed ) } } } - else if( rEnumArray->Find( aCompleteName, SbxCLASS_OBJECT ) ) + else if( rEnumArray->Find( aCompleteName, SbxCLASS_OBJECT ) || ( IsVBASupportOn() && VBAConstantHelper::instance().isVBAConstantType( aCompleteName ) ) ) { eType = SbxLONG; break; @@ -210,9 +212,9 @@ void SbiParser::DefVar( SbiOpcode eOp, BOOL bStatic ) if( eCurTok == GLOBAL ) bPersistantGlobal = TRUE; } - // behavior in VBA is that a module scope variable's lifetime is + // behavior in VBA is that a module scope variable's lifetime is // tied to the document. e.g. a module scope variable is global - if( GetBasic()->IsDocBasic() && bVBASupportOn && !pProc ) + if( GetBasic()->IsDocBasic() && bVBASupportOn && !pProc ) bPersistantGlobal = TRUE; // PRIVATE ist Synonym fuer DIM // _CONST_? @@ -236,7 +238,7 @@ void SbiParser::DefVar( SbiOpcode eOp, BOOL bStatic ) } else if( eCurTok == SUB || eCurTok == FUNCTION || eCurTok == PROPERTY ) { - // End global chain if necessary (not done in + // End global chain if necessary (not done in // SbiParser::Parse() under these conditions if( bNewGblDefs && nGblChain == 0 ) { @@ -256,7 +258,7 @@ void SbiParser::DefVar( SbiOpcode eOp, BOOL bStatic ) else if( eCurTok == DECLARE ) { Next(); - DefDeclare( bPrivate ); + DefDeclare( bPrivate ); return; } // #i109049 @@ -356,7 +358,7 @@ void SbiParser::DefVar( SbiOpcode eOp, BOOL bStatic ) SbiOpcode eOp2; switch ( pDef->GetScope() ) { - case SbGLOBAL: eOp2 = bPersistantGlobal ? _GLOBAL_P : _GLOBAL; + case SbGLOBAL: eOp2 = bPersistantGlobal ? _GLOBAL_P : _GLOBAL; goto global; case SbPUBLIC: eOp2 = bPersistantGlobal ? _PUBLIC_P : _PUBLIC; // AB 9.7.97, #40689, kein eigener Opcode mehr @@ -426,7 +428,10 @@ void SbiParser::DefVar( SbiOpcode eOp, BOOL bStatic ) aExpr.Gen(); SbiOpcode eOp_ = pDef->IsNew() ? _CREATE : _TCREATE; aGen.Gen( eOp_, pDef->GetId(), pDef->GetTypeId() ); - aGen.Gen( _SET ); + if ( bVBASupportOn ) + aGen.Gen( _VBASET ); + else + aGen.Gen( _SET ); } } else @@ -603,7 +608,7 @@ void SbiParser::DefType( BOOL bPrivate ) SbxProperty *pTypeElem = new SbxProperty( aElemName, eElemType ); if( pDim ) { - SbxDimArray* pArray = new SbxDimArray( pElem->GetType() ); + SbxDimArray* pArray = new SbxDimArray( pElem->GetType() ); if ( pDim->GetSize() ) { // Dimension the target array @@ -624,15 +629,15 @@ void SbiParser::DefType( BOOL bPrivate ) } else if ( !bCompatible ) ub += nBase; - pArray->AddDim32( lb, ub ); + pArray->AddDim32( lb, ub ); } pArray->setHasFixedSize( true ); } else pArray->unoAddDim( 0, -1 ); // variant array USHORT nSavFlags = pTypeElem->GetFlags(); - // need to reset the FIXED flag - // when calling PutObject ( because the type will not match Object ) + // need to reset the FIXED flag + // when calling PutObject ( because the type will not match Object ) pTypeElem->ResetFlag( SBX_FIXED ); pTypeElem->PutObject( pArray ); pTypeElem->SetFlags( nSavFlags ); @@ -766,7 +771,7 @@ void SbiParser::DefEnum( BOOL bPrivate ) if( !bPrivate ) { - SbiOpcode eOp = _GLOBAL; + SbiOpcode eOp = _GLOBAL; aGen.BackChain( nGblChain ); nGblChain = 0; bGblDefs = bNewGblDefs = TRUE; @@ -1043,6 +1048,24 @@ void SbiParser::DefDeclare( BOOL bPrivate ) } } +void SbiParser::Attribute() +{ + // TODO: Need to implement the method as an attributed object. + while( Next() != EQ ) + { + String aSym( GetSym() ); + if( Next() != DOT) + break; + } + + if( eCurTok != EQ ) + Error( SbERR_SYNTAX ); + else + SbiExpression aValue( this ); + + // Don't generate any code - just discard it. +} + // Aufruf einer SUB oder FUNCTION void SbiParser::Call() @@ -1179,7 +1202,7 @@ void SbiParser::DefStatic( BOOL bPrivate ) case SUB: case FUNCTION: case PROPERTY: - // End global chain if necessary (not done in + // End global chain if necessary (not done in // SbiParser::Parse() under these conditions if( bNewGblDefs && nGblChain == 0 ) { diff --git a/basic/source/comp/exprtree.cxx b/basic/source/comp/exprtree.cxx index f858c428af..50ddc0f85d 100644 --- a/basic/source/comp/exprtree.cxx +++ b/basic/source/comp/exprtree.cxx @@ -1,7 +1,7 @@ /************************************************************************* * * 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 @@ -46,7 +46,7 @@ SbiExpression::SbiExpression( SbiParser* p, SbiExprType t, nParenLevel = 0; eCurExpr = t; m_eMode = eMode; - pNext = NULL; + pNext = NULL; pExpr = (t != SbSTDEXPR ) ? Term( pKeywordSymbolInfo ) : Boolean(); if( t != SbSYMBOL ) pExpr->Optimize(); @@ -127,7 +127,7 @@ static BOOL DoParametersFollow( SbiParser* p, SbiExprType eCurExpr, SbiToken eTo if ( tokens.Peek() == ASSIGN ) return TRUE; } - return FALSE; + return FALSE; } // Definition eines neuen Symbols @@ -373,8 +373,12 @@ SbiExprNode* SbiExpression::Term( const KeywordSymbolInfo* pKeywordSymbolInfo ) // Typ SbxOBJECT sein if( pDef->GetType() != SbxOBJECT && pDef->GetType() != SbxVARIANT ) { - pParser->Error( SbERR_BAD_DECLARATION, aSym ); - bError = TRUE; + // defer error until runtime if in vba mode + if ( !pParser->IsVBASupportOn() ) + { + pParser->Error( SbERR_BAD_DECLARATION, aSym ); + bError = TRUE; + } } if( !bError ) pNd->aVar.pNext = ObjTerm( *pDef ); @@ -435,7 +439,7 @@ SbiExprNode* SbiExpression::ObjTerm( SbiSymDef& rObj ) bError |= !pPar->IsValid(); eTok = pParser->Peek(); } - + } BOOL bObj = BOOL( ( eTok == DOT || eTok == EXCLAM ) && !pParser->WhiteSpace() ); if( bObj ) @@ -580,7 +584,11 @@ SbiExprNode* SbiExpression::Unary() eTok = NEG; case NOT: pParser->Next(); - pNd = new SbiExprNode( pParser, Unary(), eTok, NULL ); + // process something like "Do While Not "foo"="" " + if( pParser->IsVBASupportOn() ) + pNd = new SbiExprNode( pParser, Like(), eTok, NULL ); + else + pNd = new SbiExprNode( pParser, Unary(), eTok, NULL ); break; case PLUS: pParser->Next(); @@ -736,7 +744,7 @@ SbiExprNode* SbiExpression::Like() pNd = new SbiExprNode( pParser, pNd, eTok, Comp() ), nCount++; } // Mehrere Operatoren hintereinander gehen nicht - if( nCount > 1 ) + if( nCount > 1 && !pParser->IsVBASupportOn() ) { pParser->Error( SbERR_SYNTAX ); bError = TRUE; diff --git a/basic/source/comp/parser.cxx b/basic/source/comp/parser.cxx index 83e7bbd604..31a78f1e47 100644 --- a/basic/source/comp/parser.cxx +++ b/basic/source/comp/parser.cxx @@ -49,6 +49,7 @@ struct SbiStatement { #define N FALSE static SbiStatement StmntTable [] = { +{ ATTRIBUTE, &SbiParser::Attribute, Y, Y, }, // ATTRIBUTE { CALL, &SbiParser::Call, N, Y, }, // CALL { CLOSE, &SbiParser::Close, N, Y, }, // CLOSE { _CONST_, &SbiParser::Dim, Y, Y, }, // CONST @@ -387,6 +388,18 @@ BOOL SbiParser::Parse() Next(); return TRUE; } + // In vba it's possible to do Error.foobar ( even if it results in + // a runtime error + if ( eCurTok == _ERROR_ && IsVBASupportOn() ) // we probably need to define a subset of keywords where this madness applies e.g. if ( IsVBASupportOn() && SymbolCanBeRedined( eCurTok ) ) + { + SbiTokenizer tokens( *(SbiTokenizer*)this ); + tokens.Next(); + if ( tokens.Peek() == DOT ) + { + eCurTok = SYMBOL; + ePush = eCurTok; + } + } // Kommt ein Symbol, ist es entweder eine Variable( LET ) // oder eine SUB-Prozedur( CALL ohne Klammern ) // DOT fuer Zuweisungen im WITH-Block: .A=5 @@ -795,7 +808,7 @@ void SbiParser::Option() bClassModule = TRUE; aGen.GetModule().SetModuleType( com::sun::star::script::ModuleType::CLASS ); break; - case VBASUPPORT: + case VBASUPPORT: // Option VBASupport used to override the module mode ( in fact this must reset the mode if( Next() == NUMBER ) { if ( nVal == 1 || nVal == 0 ) diff --git a/basic/source/comp/token.cxx b/basic/source/comp/token.cxx index 00690796a7..3312e66bf3 100644 --- a/basic/source/comp/token.cxx +++ b/basic/source/comp/token.cxx @@ -58,6 +58,7 @@ static TokenTable aTokTable_Basic [] = { // Token-Tabelle: { ANY, "Any" }, { APPEND, "Append" }, { AS, "As" }, + { ATTRIBUTE,"Attribute" }, { BASE, "Base" }, { BINARY, "Binary" }, { TBOOLEAN, "Boolean" }, diff --git a/basic/source/inc/dlgcont.hxx b/basic/source/inc/dlgcont.hxx index 614fccf30c..00abc7df3f 100644 --- a/basic/source/inc/dlgcont.hxx +++ b/basic/source/inc/dlgcont.hxx @@ -94,7 +94,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); - + // XLibraryQueryExecutable + virtual sal_Bool SAL_CALL HasExecutableCode(const rtl::OUString&) + throw (::com::sun::star::uno::RuntimeException); // Service static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_static(); static ::rtl::OUString getImplementationName_static(); diff --git a/basic/source/inc/namecont.hxx b/basic/source/inc/namecont.hxx index 72cdcee2da..69ea926775 100644 --- a/basic/source/inc/namecont.hxx +++ b/basic/source/inc/namecont.hxx @@ -1,7 +1,7 @@ /************************************************************************* * * 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 @@ -35,6 +35,7 @@ #include <com/sun/star/script/XStorageBasedLibraryContainer.hpp> #include <com/sun/star/script/XLibraryContainerPassword.hpp> #include <com/sun/star/script/XLibraryContainerExport.hpp> +#include <com/sun/star/script/XLibraryQueryExecutable.hpp> #include <com/sun/star/script/XLibraryContainer3.hpp> #include <com/sun/star/container/XNameContainer.hpp> #include <com/sun/star/container/XContainer.hpp> @@ -59,6 +60,7 @@ #include <cppuhelper/implbase2.hxx> #include <cppuhelper/compbase8.hxx> +#include <cppuhelper/compbase9.hxx> #include <cppuhelper/interfacecontainer.hxx> #include <com/sun/star/script/vba/XVBACompatibility.hpp> @@ -67,13 +69,14 @@ class BasicManager; namespace basic { -typedef ::cppu::WeakComponentImplHelper8< +typedef ::cppu::WeakComponentImplHelper9< ::com::sun::star::lang::XInitialization, ::com::sun::star::script::XStorageBasedLibraryContainer, ::com::sun::star::script::XLibraryContainerPassword, ::com::sun::star::script::XLibraryContainerExport, ::com::sun::star::script::XLibraryContainer3, ::com::sun::star::container::XContainer, + ::com::sun::star::script::XLibraryQueryExecutable, ::com::sun::star::script::vba::XVBACompatibility, ::com::sun::star::lang::XServiceInfo > LibraryContainerHelper; @@ -133,45 +136,45 @@ public: { mpxEventSource = pxEventSource; } // Methods XElementAccess - virtual ::com::sun::star::uno::Type SAL_CALL getElementType( ) + virtual ::com::sun::star::uno::Type SAL_CALL getElementType( ) throw(::com::sun::star::uno::RuntimeException); - virtual sal_Bool SAL_CALL hasElements( ) + virtual sal_Bool SAL_CALL hasElements( ) throw(::com::sun::star::uno::RuntimeException); // Methods XNameAccess - virtual ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) - throw(::com::sun::star::container::NoSuchElementException, - ::com::sun::star::lang::WrappedTargetException, + virtual ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) + throw(::com::sun::star::container::NoSuchElementException, + ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames( ) + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames( ) throw(::com::sun::star::uno::RuntimeException); - virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) + virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw(::com::sun::star::uno::RuntimeException); // Methods XNameReplace - virtual void SAL_CALL replaceByName( const ::rtl::OUString& aName, const ::com::sun::star::uno::Any& aElement ) - throw(::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::container::NoSuchElementException, - ::com::sun::star::lang::WrappedTargetException, + virtual void SAL_CALL replaceByName( const ::rtl::OUString& aName, const ::com::sun::star::uno::Any& aElement ) + throw(::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::container::NoSuchElementException, + ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); // Methods XNameContainer virtual void SAL_CALL insertByName( const ::rtl::OUString& aName, const ::com::sun::star::uno::Any& aElement ) - throw(::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::container::ElementExistException, - ::com::sun::star::lang::WrappedTargetException, + throw(::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::container::ElementExistException, + ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL removeByName( const ::rtl::OUString& Name ) - throw(::com::sun::star::container::NoSuchElementException, - ::com::sun::star::lang::WrappedTargetException, + virtual void SAL_CALL removeByName( const ::rtl::OUString& Name ) + throw(::com::sun::star::container::NoSuchElementException, + ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); // Methods XContainer - virtual void SAL_CALL addContainerListener( const ::com::sun::star::uno::Reference< - ::com::sun::star::container::XContainerListener >& xListener ) + virtual void SAL_CALL addContainerListener( const ::com::sun::star::uno::Reference< + ::com::sun::star::container::XContainerListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL removeContainerListener( const ::com::sun::star::uno::Reference< - ::com::sun::star::container::XContainerListener >& xListener ) + virtual void SAL_CALL removeContainerListener( const ::com::sun::star::uno::Reference< + ::com::sun::star::container::XContainerListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); }; @@ -256,21 +259,21 @@ protected: void implStoreLibrary( SfxLibrary* pLib, const ::rtl::OUString& aName, const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage, - const ::rtl::OUString& aTargetURL, + const ::rtl::OUString& aTargetURL, const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess > xToUseSFI, const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& xHandler ); - void implStoreLibraryIndexFile( SfxLibrary* pLib, const ::xmlscript::LibDescriptor& rLib, + void implStoreLibraryIndexFile( SfxLibrary* pLib, const ::xmlscript::LibDescriptor& rLib, const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage ); // New variant for library export - void implStoreLibraryIndexFile( SfxLibrary* pLib, const ::xmlscript::LibDescriptor& rLib, + void implStoreLibraryIndexFile( SfxLibrary* pLib, const ::xmlscript::LibDescriptor& rLib, const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage, - const ::rtl::OUString& aTargetURL, + const ::rtl::OUString& aTargetURL, const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess > xToUseSFI ); sal_Bool implLoadLibraryIndexFile( SfxLibrary* pLib, - ::xmlscript::LibDescriptor& rLib, + ::xmlscript::LibDescriptor& rLib, const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage, const ::rtl::OUString& aIndexFileName ); @@ -279,45 +282,45 @@ protected: // Methods to distinguish between deffirent library types virtual SfxLibrary* SAL_CALL implCreateLibrary( const ::rtl::OUString& aName ) = 0; virtual SfxLibrary* SAL_CALL implCreateLibraryLink - ( const ::rtl::OUString& aName, const ::rtl::OUString& aLibInfoFileURL, + ( const ::rtl::OUString& aName, const ::rtl::OUString& aLibInfoFileURL, const ::rtl::OUString& StorageURL, sal_Bool ReadOnly ) = 0; virtual ::com::sun::star::uno::Any SAL_CALL createEmptyLibraryElement( void ) = 0; virtual bool SAL_CALL isLibraryElementValid( ::com::sun::star::uno::Any aElement ) const = 0; virtual void SAL_CALL writeLibraryElement - ( + ( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer>& xLibrary, - const ::rtl::OUString& aElementName, - const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& xOutput + const ::rtl::OUString& aElementName, + const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& xOutput ) throw(::com::sun::star::uno::Exception) = 0; virtual ::com::sun::star::uno::Any SAL_CALL importLibraryElement - ( + ( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer>& xLibrary, - const ::rtl::OUString& aElementName, + const ::rtl::OUString& aElementName, const ::rtl::OUString& aFile, const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xElementStream ) = 0; virtual void SAL_CALL importFromOldStorage( const ::rtl::OUString& aFile ) = 0; // Password encryption - virtual sal_Bool implStorePasswordLibrary( SfxLibrary* pLib, const ::rtl::OUString& aName, + virtual sal_Bool implStorePasswordLibrary( SfxLibrary* pLib, const ::rtl::OUString& aName, const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage, const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& Handler ); // New variant for library export - virtual sal_Bool implStorePasswordLibrary( SfxLibrary* pLib, const ::rtl::OUString& aName, + virtual sal_Bool implStorePasswordLibrary( SfxLibrary* pLib, const ::rtl::OUString& aName, const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage, - const ::rtl::OUString& aTargetURL, + const ::rtl::OUString& aTargetURL, const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess > xToUseSFI, const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& Handler ); virtual sal_Bool implLoadPasswordLibrary( SfxLibrary* pLib, const ::rtl::OUString& Name, - sal_Bool bVerifyPasswordOnly=false ) - throw(::com::sun::star::lang::WrappedTargetException, + sal_Bool bVerifyPasswordOnly=false ) + throw(::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); virtual void onNewRootStorage() = 0; - // #56666, Creates another library container + // #56666, Creates another library container // instance of the same derived class virtual SfxLibraryContainer* createInstanceImpl( void ) = 0; @@ -337,8 +340,8 @@ protected: // Handle maLibInfoFileURL and maStorageURL correctly void checkStorageURL ( - const ::rtl::OUString& aSourceURL, - ::rtl::OUString& aLibInfoFileURL, + const ::rtl::OUString& aSourceURL, + ::rtl::OUString& aLibInfoFileURL, ::rtl::OUString& aStorageURL, ::rtl::OUString& aUnexpandedStorageURL ); @@ -368,11 +371,11 @@ private: public: SfxLibraryContainer( void ); ~SfxLibraryContainer(); - + // Interface to set the BasicManager (Hack for password implementation) void setBasicManager( BasicManager* pBasMgr ) - { + { mpBasMgr = pBasMgr; } @@ -384,17 +387,17 @@ public: // Methods XElementAccess virtual ::com::sun::star::uno::Type SAL_CALL getElementType() throw(::com::sun::star::uno::RuntimeException); - virtual sal_Bool SAL_CALL hasElements() + virtual sal_Bool SAL_CALL hasElements() throw(::com::sun::star::uno::RuntimeException); // Methods XNameAccess - virtual ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) - throw(::com::sun::star::container::NoSuchElementException, - ::com::sun::star::lang::WrappedTargetException, + virtual ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) + throw(::com::sun::star::container::NoSuchElementException, + ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames() throw(::com::sun::star::uno::RuntimeException); - virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) + virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw(::com::sun::star::uno::RuntimeException); // Members XStorageBasedLibraryContainer @@ -414,90 +417,90 @@ public: virtual void SAL_CALL storeLibraries( ) throw (::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); //Methods XLibraryContainer3 - virtual ::rtl::OUString SAL_CALL getOriginalLibraryLinkURL( const ::rtl::OUString& Name ) - throw (::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::container::NoSuchElementException, + virtual ::rtl::OUString SAL_CALL getOriginalLibraryLinkURL( const ::rtl::OUString& Name ) + throw (::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException); - + // Methods XLibraryContainer2 (base of XPersistentLibraryContainer) - virtual sal_Bool SAL_CALL isLibraryLink( const ::rtl::OUString& Name ) - throw (::com::sun::star::container::NoSuchElementException, + virtual sal_Bool SAL_CALL isLibraryLink( const ::rtl::OUString& Name ) + throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException); - virtual ::rtl::OUString SAL_CALL getLibraryLinkURL( const ::rtl::OUString& Name ) - throw (::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::container::NoSuchElementException, + virtual ::rtl::OUString SAL_CALL getLibraryLinkURL( const ::rtl::OUString& Name ) + throw (::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException); - virtual sal_Bool SAL_CALL isLibraryReadOnly( const ::rtl::OUString& Name ) - throw (::com::sun::star::container::NoSuchElementException, + virtual sal_Bool SAL_CALL isLibraryReadOnly( const ::rtl::OUString& Name ) + throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL setLibraryReadOnly( const ::rtl::OUString& Name, sal_Bool bReadOnly ) - throw (::com::sun::star::container::NoSuchElementException, + virtual void SAL_CALL setLibraryReadOnly( const ::rtl::OUString& Name, sal_Bool bReadOnly ) + throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL renameLibrary( const ::rtl::OUString& Name, const ::rtl::OUString& NewName ) - throw (::com::sun::star::container::NoSuchElementException, - ::com::sun::star::container::ElementExistException, + virtual void SAL_CALL renameLibrary( const ::rtl::OUString& Name, const ::rtl::OUString& NewName ) + throw (::com::sun::star::container::NoSuchElementException, + ::com::sun::star::container::ElementExistException, ::com::sun::star::uno::RuntimeException); // Methods XLibraryContainer (base of XLibraryContainer2) - virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer > SAL_CALL - createLibrary( const ::rtl::OUString& Name ) - throw(::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::container::ElementExistException, + virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer > SAL_CALL + createLibrary( const ::rtl::OUString& Name ) + throw(::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::container::ElementExistException, ::com::sun::star::uno::RuntimeException); virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL createLibraryLink - ( const ::rtl::OUString& Name, const ::rtl::OUString& StorageURL, sal_Bool ReadOnly ) - throw(::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::container::ElementExistException, + ( const ::rtl::OUString& Name, const ::rtl::OUString& StorageURL, sal_Bool ReadOnly ) + throw(::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::container::ElementExistException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL removeLibrary( const ::rtl::OUString& Name ) - throw(::com::sun::star::container::NoSuchElementException, - ::com::sun::star::lang::WrappedTargetException, + virtual void SAL_CALL removeLibrary( const ::rtl::OUString& Name ) + throw(::com::sun::star::container::NoSuchElementException, + ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); - virtual sal_Bool SAL_CALL isLibraryLoaded( const ::rtl::OUString& Name ) - throw(::com::sun::star::container::NoSuchElementException, + virtual sal_Bool SAL_CALL isLibraryLoaded( const ::rtl::OUString& Name ) + throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL loadLibrary( const ::rtl::OUString& Name ) - throw(::com::sun::star::container::NoSuchElementException, - ::com::sun::star::lang::WrappedTargetException, + virtual void SAL_CALL loadLibrary( const ::rtl::OUString& Name ) + throw(::com::sun::star::container::NoSuchElementException, + ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); // Methods XInitialization - virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< - ::com::sun::star::uno::Any >& aArguments ) - throw (::com::sun::star::uno::Exception, + virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Any >& aArguments ) + throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); // Methods XLibraryContainerPassword - virtual sal_Bool SAL_CALL isLibraryPasswordProtected( const ::rtl::OUString& Name ) - throw (::com::sun::star::container::NoSuchElementException, + virtual sal_Bool SAL_CALL isLibraryPasswordProtected( const ::rtl::OUString& Name ) + throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException); - virtual sal_Bool SAL_CALL isLibraryPasswordVerified( const ::rtl::OUString& Name ) - throw (::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::container::NoSuchElementException, + virtual sal_Bool SAL_CALL isLibraryPasswordVerified( const ::rtl::OUString& Name ) + throw (::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException); - virtual sal_Bool SAL_CALL verifyLibraryPassword( const ::rtl::OUString& Name, const ::rtl::OUString& Password ) - throw (::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::container::NoSuchElementException, + virtual sal_Bool SAL_CALL verifyLibraryPassword( const ::rtl::OUString& Name, const ::rtl::OUString& Password ) + throw (::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL changeLibraryPassword( const ::rtl::OUString& Name, - const ::rtl::OUString& OldPassword, const ::rtl::OUString& NewPassword ) - throw (::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::container::NoSuchElementException, + virtual void SAL_CALL changeLibraryPassword( const ::rtl::OUString& Name, + const ::rtl::OUString& OldPassword, const ::rtl::OUString& NewPassword ) + throw (::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException); // Methods XContainer - virtual void SAL_CALL addContainerListener( const ::com::sun::star::uno::Reference< - ::com::sun::star::container::XContainerListener >& xListener ) + virtual void SAL_CALL addContainerListener( const ::com::sun::star::uno::Reference< + ::com::sun::star::container::XContainerListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL removeContainerListener( const ::com::sun::star::uno::Reference< - ::com::sun::star::container::XContainerListener >& xListener ) + virtual void SAL_CALL removeContainerListener( const ::com::sun::star::uno::Reference< + ::com::sun::star::container::XContainerListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); // Methods XLibraryContainerExport - virtual void SAL_CALL exportLibrary( const ::rtl::OUString& Name, const ::rtl::OUString& URL, - const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& Handler ) - throw (::com::sun::star::uno::Exception, - ::com::sun::star::container::NoSuchElementException, + virtual void SAL_CALL exportLibrary( const ::rtl::OUString& Name, const ::rtl::OUString& URL, + const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& Handler ) + throw (::com::sun::star::uno::Exception, + ::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException); // Methods XServiceInfo @@ -559,7 +562,7 @@ private: ::rtl::OUString maStorageURL; ::rtl::OUString maUnexpandedStorageURL; ::rtl::OUString maOrignialStorageURL; - + sal_Bool mbLink; sal_Bool mbReadOnly; sal_Bool mbReadOnlyLink; @@ -623,51 +626,51 @@ public: virtual void SAL_CALL release() throw() { OComponentHelper::release(); } // Methods XElementAccess - virtual ::com::sun::star::uno::Type SAL_CALL getElementType( ) + virtual ::com::sun::star::uno::Type SAL_CALL getElementType( ) throw(::com::sun::star::uno::RuntimeException); - virtual sal_Bool SAL_CALL hasElements( ) + virtual sal_Bool SAL_CALL hasElements( ) throw(::com::sun::star::uno::RuntimeException); // Methods XNameAccess - virtual ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) - throw(::com::sun::star::container::NoSuchElementException, - ::com::sun::star::lang::WrappedTargetException, + virtual ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) + throw(::com::sun::star::container::NoSuchElementException, + ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames( ) + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames( ) throw(::com::sun::star::uno::RuntimeException); - virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) + virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw(::com::sun::star::uno::RuntimeException); // Methods XNameReplace - virtual void SAL_CALL replaceByName( const ::rtl::OUString& aName, const ::com::sun::star::uno::Any& aElement ) - throw(::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::container::NoSuchElementException, - ::com::sun::star::lang::WrappedTargetException, + virtual void SAL_CALL replaceByName( const ::rtl::OUString& aName, const ::com::sun::star::uno::Any& aElement ) + throw(::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::container::NoSuchElementException, + ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); // Methods XNameContainer virtual void SAL_CALL insertByName( const ::rtl::OUString& aName, const ::com::sun::star::uno::Any& aElement ) - throw(::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::container::ElementExistException, - ::com::sun::star::lang::WrappedTargetException, + throw(::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::container::ElementExistException, + ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL removeByName( const ::rtl::OUString& Name ) - throw(::com::sun::star::container::NoSuchElementException, - ::com::sun::star::lang::WrappedTargetException, + virtual void SAL_CALL removeByName( const ::rtl::OUString& Name ) + throw(::com::sun::star::container::NoSuchElementException, + ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); // XTypeProvider - ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes( ) + ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes( ) throw( ::com::sun::star::uno::RuntimeException ); - ::com::sun::star::uno::Sequence<sal_Int8> SAL_CALL getImplementationId( ) + ::com::sun::star::uno::Sequence<sal_Int8> SAL_CALL getImplementationId( ) throw( ::com::sun::star::uno::RuntimeException ); // Methods XContainer - virtual void SAL_CALL addContainerListener( const ::com::sun::star::uno::Reference< - ::com::sun::star::container::XContainerListener >& xListener ) + virtual void SAL_CALL addContainerListener( const ::com::sun::star::uno::Reference< + ::com::sun::star::container::XContainerListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL removeContainerListener( const ::com::sun::star::uno::Reference< - ::com::sun::star::container::XContainerListener >& xListener ) + virtual void SAL_CALL removeContainerListener( const ::com::sun::star::uno::Reference< + ::com::sun::star::container::XContainerListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); public: @@ -732,7 +735,7 @@ protected: implGetNextBundledScriptPackage( bool& rbPureDialogLib ); com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > m_xContext; - + IteratorState m_eState; com::sun::star::uno::Sequence< com::sun::star::uno::Reference diff --git a/basic/source/inc/parser.hxx b/basic/source/inc/parser.hxx index d83bc3c68c..cf4dad844d 100644 --- a/basic/source/inc/parser.hxx +++ b/basic/source/inc/parser.hxx @@ -107,6 +107,7 @@ public: void BadSyntax(); // Falsches SbiToken void NoIf(); // ELSE/ELSE IF ohne IF void Assign(); // LET + void Attribute(); // Attribute void Call(); // CALL void Close(); // CLOSE void Declare(); // DECLARE diff --git a/basic/source/inc/runtime.hxx b/basic/source/inc/runtime.hxx index f549659904..1e944dd824 100644 --- a/basic/source/inc/runtime.hxx +++ b/basic/source/inc/runtime.hxx @@ -196,7 +196,6 @@ class SbiInstance BOOL bCompatibility; // Flag: TRUE = VBA runtime compatibility mode ComponentVector_t ComponentVector; - public: SbiRuntime* pRun; // Call-Stack SbiInstance* pNext; // Instanzen-Chain @@ -285,7 +284,9 @@ class SbiRuntime SbxArrayRef refExprStk; // expression stack SbxArrayRef refCaseStk; // CASE expression stack SbxArrayRef refRedimpArray; // Array saved to use for REDIM PRESERVE + SbxVariableRef refRedim; // Array saved to use for REDIM SbxVariableRef xDummyVar; // Ersatz fuer nicht gefundene Variablen + SbxVariable* mpExtCaller; // Caller ( external - e.g. button name, shape, range object etc. - only in vba mode ) SbiArgvStack* pArgvStk; // ARGV-Stack SbiGosubStack* pGosubStk; // GOSUB stack SbiForStack* pForStk; // FOR/NEXT-Stack @@ -455,6 +456,7 @@ public: SbMethod* GetCaller(); SbxArray* GetLocals(); SbxArray* GetParams(); + SbxVariable* GetExternalCaller(){ return mpExtCaller; } SbxBase* FindElementExtern( const String& rName ); static bool isVBAEnabled(); diff --git a/basic/source/inc/sbunoobj.hxx b/basic/source/inc/sbunoobj.hxx index a1274b9f50..fe6e16f171 100644 --- a/basic/source/inc/sbunoobj.hxx +++ b/basic/source/inc/sbunoobj.hxx @@ -1,7 +1,7 @@ /************************************************************************* * * 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 @@ -38,9 +38,10 @@ #include <com/sun/star/beans/XIntrospection.hpp> #include <com/sun/star/script/XInvocation.hpp> #include <com/sun/star/reflection/XIdlClass.hpp> -#include <com/sun/star/reflection/XServiceTypeDescription2.hpp> -#include <com/sun/star/reflection/XSingletonTypeDescription.hpp> +#include <com/sun/star/reflection/XServiceTypeDescription2.hpp> +#include <com/sun/star/reflection/XSingletonTypeDescription.hpp> #include <rtl/ustring.hxx> +#include <hash_map> class SbUnoObject: public SbxObject { @@ -106,7 +107,7 @@ class SbUnoMethod : public SbxMethod public: TYPEINFO(); - SbUnoMethod( const String& aName_, SbxDataType eSbxType, ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XIdlMethod > xUnoMethod_, + SbUnoMethod( const String& aName_, SbxDataType eSbxType, ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XIdlMethod > xUnoMethod_, bool bInvocation ); virtual ~SbUnoMethod(); virtual SbxInfo* GetInfo(); @@ -225,7 +226,7 @@ public: { return m_xServiceCtorDesc; } }; - + // Wrapper for UNO Singleton class SbUnoSingleton : public SbxObject { @@ -261,7 +262,7 @@ public: }; -// #112509 Special SbxArray to transport named parameters for calls +// #112509 Special SbxArray to transport named parameters for calls // to OLEAutomation objects through the UNO OLE automation bridge class AutomationNamedArgsSbxArray : public SbxArray @@ -319,6 +320,26 @@ public: virtual void Clear(); }; +typedef std::hash_map< ::rtl::OUString, ::com::sun::star::uno::Any, ::rtl::OUStringHash, ::std::equal_to< ::rtl::OUString > > VBAConstantsHash; + +typedef std::vector< rtl::OUString > VBAConstantsVector; + +class VBAConstantHelper +{ +private: + + VBAConstantsVector aConstCache; + VBAConstantsHash aConstHash; + bool isInited; + VBAConstantHelper():isInited( false ) {} + VBAConstantHelper(const VBAConstantHelper&); + void init(); +public: + static VBAConstantHelper& instance(); + SbxVariable* getVBAConstant( const String& rName ); + bool isVBAConstantType( const String& rName ); +}; + #endif diff --git a/basic/source/inc/scriptcont.hxx b/basic/source/inc/scriptcont.hxx index 71ad535600..3fb35ed429 100644 --- a/basic/source/inc/scriptcont.hxx +++ b/basic/source/inc/scriptcont.hxx @@ -122,7 +122,9 @@ public: throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException); - + // XLibraryQueryExecutable + virtual sal_Bool SAL_CALL HasExecutableCode(const rtl::OUString&) + throw (::com::sun::star::uno::RuntimeException); // Methods XServiceInfo virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException); diff --git a/basic/source/inc/token.hxx b/basic/source/inc/token.hxx index 4bac670594..2c71d263e8 100644 --- a/basic/source/inc/token.hxx +++ b/basic/source/inc/token.hxx @@ -70,7 +70,7 @@ enum SbiToken { IF, _IN_, INPUT, LET, LINE, LINEINPUT, LOCAL, LOOP, LPRINT, LSET, NAME, NEW, NEXT, - ON, OPEN, OPTION, IMPLEMENTS, + ON, OPEN, OPTION, ATTRIBUTE, IMPLEMENTS, PRINT, PRIVATE, PROPERTY, PUBLIC, REDIM, REM, RESUME, RETURN, RSET, SELECT, SET, SHARED, STATIC, STEP, STOP, SUB, diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx index df4f65d7bc..8ebf80ea18 100644 --- a/basic/source/runtime/methods.cxx +++ b/basic/source/runtime/methods.cxx @@ -1,7 +1,7 @@ /************************************************************************* * * 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 @@ -46,6 +46,7 @@ #include <unotools/ucbstreamhelper.hxx> #include <tools/wldcrd.hxx> #include <i18npool/lang.h> +#include <rtl/string.hxx> #include "runtime.hxx" #include "sbunoobj.hxx" @@ -71,13 +72,16 @@ #include <com/sun/star/io/XOutputStream.hpp> #include <com/sun/star/io/XStream.hpp> #include <com/sun/star/io/XSeekable.hpp> - +#include <com/sun/star/script/XErrorQuery.hpp> +#include <ooo/vba/XHelperInterface.hpp> +#include <com/sun/star/bridge/oleautomation/XAutomationObject.hpp> using namespace comphelper; using namespace osl; using namespace com::sun::star::uno; using namespace com::sun::star::lang; using namespace com::sun::star::ucb; using namespace com::sun::star::io; +using namespace com::sun::star::script; #endif /* _USE_UNO */ @@ -99,6 +103,8 @@ using namespace com::sun::star::io; #include <stdlib.h> #include <ctype.h> +SbxVariable* getDefaultProp( SbxVariable* pRef ); + #if defined (WIN) || defined (WNT) || defined (OS2) #include <direct.h> // _getdcwd get current work directory, _chdrive #endif @@ -117,6 +123,9 @@ using namespace com::sun::star::io; #include <io.h> #endif + +#include <basic/sbobjmod.hxx> + #include <basic/sbobjmod.hxx> static void FilterWhiteSpace( String& rStr ) @@ -702,6 +711,36 @@ RTLFUNC(MkDir) // JSM { try { + if ( SbiRuntime::isVBAEnabled() ) + { + // If aPath is the folder name, not a path, then create the folder under current directory. + INetURLObject aTryPathURL( aPath ); + ::rtl::OUString sPathURL = aTryPathURL.GetMainURL( INetURLObject::NO_DECODE ); + if ( !sPathURL.getLength() ) + { + File::getFileURLFromSystemPath( aPath, sPathURL ); + } + INetURLObject aPathURL( sPathURL ); + if ( !aPathURL.GetPath().getLength() ) + { + ::rtl::OUString sCurDirURL; + SbxArrayRef pPar = new SbxArray; + SbxVariableRef pVar = new SbxVariable(); + pPar->Put( pVar, 0 ); + SbRtl_CurDir( pBasic, *pPar, FALSE ); + String aCurPath = pPar->Get(0)->GetString(); + + File::getFileURLFromSystemPath( aCurPath, sCurDirURL ); + INetURLObject aDirURL( sCurDirURL ); + aDirURL.Append( aPath ); + ::rtl::OUString aTmpPath = aDirURL.GetMainURL( INetURLObject::NO_DECODE ); + if ( aTmpPath.getLength() > 0 ) + { + aPath = aTmpPath; + } + } + } + xSFI->createFolder( getFullPath( aPath ) ); } catch( Exception & ) @@ -936,6 +975,26 @@ RTLFUNC(Hex) } } +RTLFUNC(FuncCaller) +{ + (void)pBasic; + (void)bWrite; + if ( SbiRuntime::isVBAEnabled() && pINST && pINST->pRun ) + { + if ( pINST->pRun->GetExternalCaller() ) + *rPar.Get(0) = *pINST->pRun->GetExternalCaller(); + else + { + SbxVariableRef pVar = new SbxVariable(SbxVARIANT); + *rPar.Get(0) = *pVar; + } + } + else + { + StarBASIC::Error( SbERR_NOT_IMPLEMENTED ); + } + +} // InStr( [start],string,string,[compare] ) RTLFUNC(InStr) @@ -1340,13 +1399,13 @@ RTLFUNC(Oct) } } -// Replace(expression, find, replace[, start[, count[, compare]]]) +// Replace(expression, find, replace[, start[, count[, compare]]]) RTLFUNC(Replace) { (void)pBasic; (void)bWrite; - + ULONG nArgCount = rPar.Count()-1; if ( nArgCount < 3 || nArgCount > 6 ) StarBASIC::Error( SbERR_BAD_ARGUMENT ); @@ -1376,7 +1435,7 @@ RTLFUNC(Replace) if( lCount < -1 || lCount > 0xffff ) { StarBASIC::Error( SbERR_BAD_ARGUMENT ); - lCount = -1; + lCount = -1; } } @@ -1808,7 +1867,7 @@ BOOL implDateSerial( INT16 nYear, INT16 nMonth, INT16 nDay, double& rdRet ) else if ( nYear < 100 ) nYear += 1900; Date aCurDate( nDay, nMonth, nYear ); - if ((nYear < 100 || nYear > 9999) ) + if ((nYear < 100 || nYear > 9999) ) { StarBASIC::Error( SbERR_BAD_ARGUMENT ); return FALSE; @@ -1816,7 +1875,7 @@ BOOL implDateSerial( INT16 nYear, INT16 nMonth, INT16 nDay, double& rdRet ) if ( !SbiRuntime::isVBAEnabled() ) { if ( (nMonth < 1 || nMonth > 12 )|| - (nDay < 1 || nDay > 31 ) ) + (nDay < 1 || nDay > 31 ) ) { StarBASIC::Error( SbERR_BAD_ARGUMENT ); return FALSE; @@ -1826,7 +1885,7 @@ BOOL implDateSerial( INT16 nYear, INT16 nMonth, INT16 nDay, double& rdRet ) { // grab the year & month aCurDate = Date( 1, (( nMonth % 12 ) > 0 ) ? ( nMonth % 12 ) : 12 + ( nMonth % 12 ), nYear ); - + // adjust year based on month value // e.g. 2000, 0, xx = 1999, 12, xx ( or December of the previous year ) // 2000, 13, xx = 2001, 1, xx ( or January of the following year ) @@ -1847,7 +1906,7 @@ BOOL implDateSerial( INT16 nYear, INT16 nMonth, INT16 nDay, double& rdRet ) aCurDate += nDay - 1; else aCurDate.SetDay( nDay ); - } + } long nDiffDays = GetDayDiff( aCurDate ); rdRet = (double)nDiffDays; @@ -1975,16 +2034,16 @@ RTLFUNC(DateValue) String aStr( rPar.Get(1)->GetString() ); BOOL bSuccess = pFormatter->IsNumberFormat( aStr, nIndex, fResult ); short nType = pFormatter->GetType( nIndex ); - + // DateValue("February 12, 1969") raises error if the system locale is not en_US // by using SbiInstance::GetNumberFormatter. - // It seems that both locale number formatter and English number formatter + // It seems that both locale number formatter and English number formatter // are supported in Visual Basic. LanguageType eLangType = GetpApp()->GetSettings().GetLanguage(); if( !bSuccess && ( eLangType != LANGUAGE_ENGLISH_US ) ) { // Create a new SvNumberFormatter by using LANGUAGE_ENGLISH to get the date value; - com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > + com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > xFactory = comphelper::getProcessServiceFactory(); SvNumberFormatter aFormatter( xFactory, LANGUAGE_ENGLISH_US ); bSuccess = aFormatter.IsNumberFormat( aStr, nIndex, fResult ); @@ -2407,7 +2466,18 @@ RTLFUNC(IsEmpty) if ( rPar.Count() < 2 ) StarBASIC::Error( SbERR_BAD_ARGUMENT ); else - rPar.Get( 0 )->PutBool( rPar.Get(1)->IsEmpty() ); + { + SbxVariable* pVar = NULL; + if( SbiRuntime::isVBAEnabled() ) + pVar = getDefaultProp( rPar.Get(1) ); + if ( pVar ) + { + pVar->Broadcast( SBX_HINT_DATAWANTED ); + rPar.Get( 0 )->PutBool( pVar->IsEmpty() ); + } + else + rPar.Get( 0 )->PutBool( rPar.Get(1)->IsEmpty() ); + } } RTLFUNC(IsError) @@ -2418,7 +2488,22 @@ RTLFUNC(IsError) if ( rPar.Count() < 2 ) StarBASIC::Error( SbERR_BAD_ARGUMENT ); else - rPar.Get( 0 )->PutBool( rPar.Get(1)->IsErr() ); + { + SbxVariable* pVar =rPar.Get( 1 ); + SbUnoObject* pObj = PTR_CAST(SbUnoObject,pVar ); + if ( !pObj ) + { + if ( SbxBase* pBaseObj = pVar->GetObject() ) + pObj = PTR_CAST(SbUnoObject, pBaseObj ); + } + Reference< XErrorQuery > xError; + if ( pObj ) + xError.set( pObj->getUnoAny(), UNO_QUERY ); + if ( xError.is() ) + rPar.Get( 0 )->PutBool( xError->hasError() ); + else + rPar.Get( 0 )->PutBool( rPar.Get(1)->IsErr() ); + } } RTLFUNC(IsNull) @@ -2986,8 +3071,8 @@ RTLFUNC(GetAttr) return; } - #endif - + #endif + // <-- UCB if( hasUno() ) { @@ -3538,6 +3623,13 @@ RTLFUNC(Shell) NAMESPACE_VOS(OArgumentList) aArgList( pArgumentList, nParamCount ); bSucc = pApp->execute( eOptions, aArgList ) == NAMESPACE_VOS(OProcess)::E_None; } + long nResult = 0; + NAMESPACE_VOS(OProcess)::TProcessInfo aInfo; + // We should return the identifier of the executing process when is running VBA, because method Shell(...) returns it in Excel. + if ( bSucc && SbiRuntime::isVBAEnabled() && pApp->getInfo( NAMESPACE_VOS(OProcess)::TData_Identifier, &aInfo ) == NAMESPACE_VOS(OProcess)::E_None ) + { + nResult = aInfo.Ident; + } /* if( nParamCount == 0 ) @@ -3552,7 +3644,7 @@ RTLFUNC(Shell) if( !bSucc ) StarBASIC::Error( SbERR_FILE_NOT_FOUND ); else - rPar.Get(0)->PutLong( 0 ); + rPar.Get(0)->PutLong( nResult ); } } @@ -3623,6 +3715,65 @@ String getBasicTypeName( SbxDataType eType ) return aRetStr; } +String getObjectTypeName( SbxVariable* pVar ) +{ + rtl::OUString sRet( RTL_CONSTASCII_USTRINGPARAM("Object") ); + if ( pVar ) + { + SbxBase* pObj = pVar->GetObject(); + if( !pObj ) + sRet = String( RTL_CONSTASCII_USTRINGPARAM("Nothing") ); + else + { + SbUnoObject* pUnoObj = PTR_CAST(SbUnoObject,pVar ); + if ( !pUnoObj ) + { + if ( SbxBase* pBaseObj = pVar->GetObject() ) + pUnoObj = PTR_CAST(SbUnoObject, pBaseObj ); + } + if ( pUnoObj ) + { + Any aObj = pUnoObj->getUnoAny(); + // For upstreaming unless we start to build oovbaapi by default + // we need to get detect the vba-ness of the object in some + // other way + // note: Automation objects do not support XServiceInfo + Reference< XServiceInfo > xServInfo( aObj, UNO_QUERY ); + if ( xServInfo.is() ) + { + // is this a VBA object ? + Reference< ooo::vba::XHelperInterface > xVBA( aObj, UNO_QUERY ); + Sequence< rtl::OUString > sServices = xServInfo->getSupportedServiceNames(); + if ( sServices.getLength() ) + sRet = sServices[ 0 ]; + } + else + { + Reference< com::sun::star::bridge::oleautomation::XAutomationObject > xAutoMation( aObj, UNO_QUERY ); + if ( xAutoMation.is() ) + { + Reference< XInvocation > xInv( aObj, UNO_QUERY ); + if ( xInv.is() ) + { + try + { + xInv->getValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("$GetTypeName") ) ) >>= sRet; + } + catch( Exception& ) + { + } + } + } + } + sal_Int32 nDot = sRet.lastIndexOf( '.' ); + if ( nDot != -1 && nDot < sRet.getLength() ) + sRet = sRet.copy( nDot + 1 ); + } + } + } + return sRet; +} + RTLFUNC(TypeName) { (void)pBasic; @@ -3634,7 +3785,12 @@ RTLFUNC(TypeName) { SbxDataType eType = rPar.Get(1)->GetType(); BOOL bIsArray = ( ( eType & SbxARRAY ) != 0 ); - String aRetStr = getBasicTypeName( eType ); + + String aRetStr; + if ( SbiRuntime::isVBAEnabled() && eType == SbxOBJECT ) + aRetStr = getObjectTypeName( rPar.Get(1) ); + else + aRetStr = getBasicTypeName( eType ); if( bIsArray ) aRetStr.AppendAscii( "()" ); rPar.Get(0)->PutString( aRetStr ); @@ -3976,28 +4132,28 @@ RTLFUNC(StrConv) { (void)pBasic; (void)bWrite; - + ULONG nArgCount = rPar.Count()-1; if( nArgCount < 2 || nArgCount > 3 ) { StarBASIC::Error( SbERR_BAD_ARGUMENT ); - return; + return; } - String aOldStr = rPar.Get(1)->GetString(); + String aOldStr = rPar.Get(1)->GetString(); INT32 nConversion = rPar.Get(2)->GetLong(); - + USHORT nLanguage = LANGUAGE_SYSTEM; if( nArgCount == 3 ) { - // LCID not supported now + // LCID not supported now //nLanguage = rPar.Get(3)->GetInteger(); } USHORT nOldLen = aOldStr.Len(); if( nOldLen == 0 ) { - // null string,return + // null string,return rPar.Get(0)->PutString(aOldStr); return; } @@ -4012,7 +4168,7 @@ RTLFUNC(StrConv) nType |= ::com::sun::star::i18n::TransliterationModules_LOWERCASE_UPPERCASE; else if ( (nConversion & 0x02) == 2 ) // vbLowerCase nType |= ::com::sun::star::i18n::TransliterationModules_UPPERCASE_LOWERCASE; - + if ( (nConversion & 0x04) == 4 ) // vbWide nType |= ::com::sun::star::i18n::TransliterationModules_HALFWIDTH_FULLWIDTH; else if ( (nConversion & 0x08) == 8 ) // vbNarrow @@ -4043,12 +4199,12 @@ RTLFUNC(StrConv) { pChar[i] = static_cast< sal_Char >( i%2 ? ((*pSrc) >> 8) & 0xff : (*pSrc) & 0xff ); if( i%2 ) - pSrc++; + pSrc++; } pChar[nSize] = '\0'; - ::rtl::OString aOStr(pChar); - - // there is no concept about default codepage in unix. so it is incorrectly in unix + ::rtl::OString aOStr(pChar); + + // there is no concept about default codepage in unix. so it is incorrectly in unix ::rtl::OUString aOUStr = ::rtl::OStringToOUString(aOStr, osl_getThreadTextEncoding()); aNewStr = String(aOUStr); rPar.Get(0)->PutString( aNewStr ); @@ -4057,7 +4213,7 @@ RTLFUNC(StrConv) else if ( (nConversion & 0x80) == 128 ) // vbFromUnicode { ::rtl::OUString aOUStr(aNewStr); - // there is no concept about default codepage in unix. so it is incorrectly in unix + // there is no concept about default codepage in unix. so it is incorrectly in unix ::rtl::OString aOStr = ::rtl::OUStringToOString(aNewStr,osl_getThreadTextEncoding()); const sal_Char* pChar = aOStr.getStr(); USHORT nArraySize = static_cast< USHORT >( aOStr.getLength() ); @@ -4068,11 +4224,11 @@ RTLFUNC(StrConv) if( bIncIndex ) pArray->AddDim( 1, nArraySize ); else - pArray->AddDim( 0, nArraySize-1 ); + pArray->AddDim( 0, nArraySize-1 ); } else { - pArray->unoAddDim( 0, -1 ); + pArray->unoAddDim( 0, -1 ); } for( USHORT i=0; i< nArraySize; i++) @@ -4084,7 +4240,7 @@ RTLFUNC(StrConv) short index = i; if( bIncIndex ) ++index; - pArray->Put( pNew, &index ); + pArray->Put( pNew, &index ); } SbxVariableRef refVar = rPar.Get(0); @@ -4093,7 +4249,7 @@ RTLFUNC(StrConv) refVar->PutObject( pArray ); refVar->SetFlags( nFlags ); refVar->SetParameters( NULL ); - return; + return; } rPar.Get(0)->PutString(aNewStr); @@ -4502,7 +4658,7 @@ RTLFUNC(Partition) { (void)pBasic; (void)bWrite; - + if ( rPar.Count() != 5 ) { StarBASIC::Error( SbERR_BAD_ARGUMENT ); @@ -4513,7 +4669,7 @@ RTLFUNC(Partition) INT32 nStart = rPar.Get(2)->GetLong(); INT32 nStop = rPar.Get(3)->GetLong(); INT32 nInterval = rPar.Get(4)->GetLong(); - + if( nStart < 0 || nStop <= nStart || nInterval < 1 ) { StarBASIC::Error( SbERR_BAD_ARGUMENT ); @@ -4523,7 +4679,7 @@ RTLFUNC(Partition) // the Partition function inserts leading spaces before lowervalue and uppervalue // so that they both have the same number of characters as the string // representation of the value (Stop + 1). This ensures that if you use the output - // of the Partition function with several values of Number, the resulting text + // of the Partition function with several values of Number, the resulting text // will be handled properly during any subsequent sort operation. // calculate the maximun number of characters before lowervalue and uppervalue @@ -4535,7 +4691,7 @@ RTLFUNC(Partition) ::rtl::OUStringBuffer aRetStr( nLen * 2 + 1); ::rtl::OUString aLowerValue; - ::rtl::OUString aUpperValue; + ::rtl::OUString aUpperValue; if( nNumber < nStart ) { aUpperValue = aBeforeStart; @@ -4553,7 +4709,7 @@ RTLFUNC(Partition) nLowerValue = ((( nNumber - nStart ) / nInterval ) * nInterval ) + nStart; nUpperValue = nLowerValue + nInterval - 1; } - + aLowerValue = ::rtl::OUString::valueOf( nLowerValue ); aUpperValue = ::rtl::OUString::valueOf( nUpperValue ); } diff --git a/basic/source/runtime/methods1.cxx b/basic/source/runtime/methods1.cxx index dfcbeca66b..d044f0202a 100644 --- a/basic/source/runtime/methods1.cxx +++ b/basic/source/runtime/methods1.cxx @@ -1,7 +1,7 @@ /************************************************************************* * * 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 @@ -76,11 +76,15 @@ #include <com/sun/star/uno/Sequence.hxx> #include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <com/sun/star/i18n/XCalendar.hpp> +#include <com/sun/star/sheet/XFunctionAccess.hpp> using namespace comphelper; +using namespace com::sun::star::sheet; using namespace com::sun::star::uno; using namespace com::sun::star::i18n; +void unoToSbxValue( SbxVariable* pVar, const Any& aValue ); +Any sbxToUnoValue( SbxVariable* pVar, const Type& rType, com::sun::star::beans::Property* pUnoProperty = NULL ); static Reference< XCalendar > getLocaleCalendar( void ) { @@ -526,6 +530,10 @@ RTLFUNC(DoEvents) (void)pBasic; (void)bWrite; (void)rPar; +// don't undstand what upstream are up to +// we already process application events etc. in between +// basic runtime pcode ( on a timed basis ) +#if 0 // Dummy implementation as the following code leads // to performance problems for unknown reasons //Timer aTimer; @@ -533,6 +541,9 @@ RTLFUNC(DoEvents) //aTimer.Start(); //while ( aTimer.IsActive() ) // Application::Reschedule(); +#endif + // always return 0 + rPar.Get(0)->PutInteger( 0 ); } RTLFUNC(GetGUIVersion) @@ -671,8 +682,8 @@ RTLFUNC(Array) } // Parameter ins Array uebernehmen - // ATTENTION: Using type USHORT for loop variable is - // mandatory to workaround a problem with the + // ATTENTION: Using type USHORT for loop variable is + // mandatory to workaround a problem with the // Solaris Intel compiler optimizer! See i104354 for( USHORT i = 0 ; i < nArraySize ; i++ ) { @@ -1407,7 +1418,7 @@ RTLFUNC(CreateUnoServiceWithArguments) { (void)pBasic; (void)bWrite; - + RTL_Impl_CreateUnoServiceWithArguments( pBasic, rPar, bWrite ); } @@ -2516,6 +2527,546 @@ RTLFUNC(Round) rPar.Get(0)->PutDouble( dRes ); } +void CallFunctionAccessFunction( const Sequence< Any >& aArgs, const rtl::OUString& sFuncName, SbxVariable* pRet ) +{ + static Reference< XFunctionAccess > xFunc; + Any aRes; + try + { + if ( !xFunc.is() ) + { + Reference< XMultiServiceFactory > xFactory( getProcessServiceFactory() ); + if( xFactory.is() ) + { + xFunc.set( xFactory->createInstance(::rtl::OUString::createFromAscii( "com.sun.star.sheet.FunctionAccess")), UNO_QUERY_THROW); + } + } + Any aRet = xFunc->callFunction( sFuncName, aArgs ); + + unoToSbxValue( pRet, aRet ); + + } + catch( Exception& ) + { + StarBASIC::Error( SbERR_BAD_ARGUMENT ); + } +} + +RTLFUNC(SYD) +{ + (void)pBasic; + (void)bWrite; + + ULONG nArgCount = rPar.Count()-1; + + if ( nArgCount < 4 ) + { + StarBASIC::Error( SbERR_BAD_ARGUMENT ); + return; + } + + // retrieve non-optional params + + Sequence< Any > aParams( 4 ); + aParams[ 0 ] <<= makeAny( rPar.Get(1)->GetDouble() ); + aParams[ 1 ] <<= makeAny( rPar.Get(2)->GetDouble() ); + aParams[ 2 ] <<= makeAny( rPar.Get(3)->GetDouble() ); + aParams[ 3 ] <<= makeAny( rPar.Get(4)->GetDouble() ); + + CallFunctionAccessFunction( aParams, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("SYD") ), rPar.Get( 0 ) ); +} + +RTLFUNC(SLN) +{ + (void)pBasic; + (void)bWrite; + + ULONG nArgCount = rPar.Count()-1; + + if ( nArgCount < 3 ) + { + StarBASIC::Error( SbERR_BAD_ARGUMENT ); + return; + } + + // retrieve non-optional params + + Sequence< Any > aParams( 3 ); + aParams[ 0 ] <<= makeAny( rPar.Get(1)->GetDouble() ); + aParams[ 1 ] <<= makeAny( rPar.Get(2)->GetDouble() ); + aParams[ 2 ] <<= makeAny( rPar.Get(3)->GetDouble() ); + + CallFunctionAccessFunction( aParams, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("SLN") ), rPar.Get( 0 ) ); +} + +RTLFUNC(Pmt) +{ + (void)pBasic; + (void)bWrite; + + ULONG nArgCount = rPar.Count()-1; + + if ( nArgCount < 3 || nArgCount > 5 ) + { + StarBASIC::Error( SbERR_BAD_ARGUMENT ); + return; + } + // retrieve non-optional params + + double rate = rPar.Get(1)->GetDouble(); + double nper = rPar.Get(2)->GetDouble(); + double pmt = rPar.Get(3)->GetDouble(); + + // set default values for Optional args + double fv = 0; + double type = 0; + + // fv + if ( nArgCount >= 4 ) + { + if( rPar.Get(4)->GetType() != SbxEMPTY ) + fv = rPar.Get(4)->GetDouble(); + } + // type + if ( nArgCount >= 5 ) + { + if( rPar.Get(5)->GetType() != SbxEMPTY ) + type = rPar.Get(5)->GetDouble(); + } + + Sequence< Any > aParams( 5 ); + aParams[ 0 ] <<= rate; + aParams[ 1 ] <<= nper; + aParams[ 2 ] <<= pmt; + aParams[ 3 ] <<= fv; + aParams[ 4 ] <<= type; + + CallFunctionAccessFunction( aParams, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Pmt") ), rPar.Get( 0 ) ); +} + +RTLFUNC(PPmt) +{ + (void)pBasic; + (void)bWrite; + + ULONG nArgCount = rPar.Count()-1; + + if ( nArgCount < 4 || nArgCount > 6 ) + { + StarBASIC::Error( SbERR_BAD_ARGUMENT ); + return; + } + // retrieve non-optional params + + double rate = rPar.Get(1)->GetDouble(); + double per = rPar.Get(2)->GetDouble(); + double nper = rPar.Get(3)->GetDouble(); + double pv = rPar.Get(4)->GetDouble(); + + // set default values for Optional args + double fv = 0; + double type = 0; + + // fv + if ( nArgCount >= 5 ) + { + if( rPar.Get(5)->GetType() != SbxEMPTY ) + fv = rPar.Get(5)->GetDouble(); + } + // type + if ( nArgCount >= 6 ) + { + if( rPar.Get(6)->GetType() != SbxEMPTY ) + type = rPar.Get(6)->GetDouble(); + } + + Sequence< Any > aParams( 6 ); + aParams[ 0 ] <<= rate; + aParams[ 1 ] <<= per; + aParams[ 2 ] <<= nper; + aParams[ 3 ] <<= pv; + aParams[ 4 ] <<= fv; + aParams[ 5 ] <<= type; + + CallFunctionAccessFunction( aParams, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("PPmt") ), rPar.Get( 0 ) ); +} + +RTLFUNC(PV) +{ + (void)pBasic; + (void)bWrite; + + ULONG nArgCount = rPar.Count()-1; + + if ( nArgCount < 3 || nArgCount > 5 ) + { + StarBASIC::Error( SbERR_BAD_ARGUMENT ); + return; + } + // retrieve non-optional params + + double rate = rPar.Get(1)->GetDouble(); + double nper = rPar.Get(2)->GetDouble(); + double pmt = rPar.Get(3)->GetDouble(); + + // set default values for Optional args + double fv = 0; + double type = 0; + + // fv + if ( nArgCount >= 4 ) + { + if( rPar.Get(4)->GetType() != SbxEMPTY ) + fv = rPar.Get(4)->GetDouble(); + } + // type + if ( nArgCount >= 5 ) + { + if( rPar.Get(5)->GetType() != SbxEMPTY ) + type = rPar.Get(5)->GetDouble(); + } + + Sequence< Any > aParams( 5 ); + aParams[ 0 ] <<= rate; + aParams[ 1 ] <<= nper; + aParams[ 2 ] <<= pmt; + aParams[ 3 ] <<= fv; + aParams[ 4 ] <<= type; + + CallFunctionAccessFunction( aParams, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("PV") ), rPar.Get( 0 ) ); +} + +RTLFUNC(NPV) +{ + (void)pBasic; + (void)bWrite; + + ULONG nArgCount = rPar.Count()-1; + + if ( nArgCount < 1 || nArgCount > 2 ) + { + StarBASIC::Error( SbERR_BAD_ARGUMENT ); + return; + } + + Sequence< Any > aParams( 2 ); + aParams[ 0 ] <<= makeAny( rPar.Get(1)->GetDouble() ); + Any aValues = sbxToUnoValue( rPar.Get(2), + getCppuType( (Sequence<double>*)0 ) ); + + // convert for calc functions + Sequence< Sequence< double > > sValues(1); + aValues >>= sValues[ 0 ]; + aValues <<= sValues; + + aParams[ 1 ] <<= aValues; + + CallFunctionAccessFunction( aParams, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("NPV") ), rPar.Get( 0 ) ); +} + +RTLFUNC(NPer) +{ + (void)pBasic; + (void)bWrite; + + ULONG nArgCount = rPar.Count()-1; + + if ( nArgCount < 3 || nArgCount > 5 ) + { + StarBASIC::Error( SbERR_BAD_ARGUMENT ); + return; + } + // retrieve non-optional params + + double rate = rPar.Get(1)->GetDouble(); + double pmt = rPar.Get(2)->GetDouble(); + double pv = rPar.Get(3)->GetDouble(); + + // set default values for Optional args + double fv = 0; + double type = 0; + + // fv + if ( nArgCount >= 4 ) + { + if( rPar.Get(4)->GetType() != SbxEMPTY ) + fv = rPar.Get(4)->GetDouble(); + } + // type + if ( nArgCount >= 5 ) + { + if( rPar.Get(5)->GetType() != SbxEMPTY ) + type = rPar.Get(5)->GetDouble(); + } + + Sequence< Any > aParams( 5 ); + aParams[ 0 ] <<= rate; + aParams[ 1 ] <<= pmt; + aParams[ 2 ] <<= pv; + aParams[ 3 ] <<= fv; + aParams[ 4 ] <<= type; + + CallFunctionAccessFunction( aParams, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("NPer") ), rPar.Get( 0 ) ); +} + +RTLFUNC(MIRR) +{ + (void)pBasic; + (void)bWrite; + + ULONG nArgCount = rPar.Count()-1; + + if ( nArgCount < 3 ) + { + StarBASIC::Error( SbERR_BAD_ARGUMENT ); + return; + } + + // retrieve non-optional params + + Sequence< Any > aParams( 3 ); + Any aValues = sbxToUnoValue( rPar.Get(1), + getCppuType( (Sequence<double>*)0 ) ); + + // convert for calc functions + Sequence< Sequence< double > > sValues(1); + aValues >>= sValues[ 0 ]; + aValues <<= sValues; + + aParams[ 0 ] <<= aValues; + aParams[ 1 ] <<= makeAny( rPar.Get(2)->GetDouble() ); + aParams[ 2 ] <<= makeAny( rPar.Get(3)->GetDouble() ); + + CallFunctionAccessFunction( aParams, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("MIRR") ), rPar.Get( 0 ) ); +} + +RTLFUNC(IRR) +{ + (void)pBasic; + (void)bWrite; + + ULONG nArgCount = rPar.Count()-1; + + if ( nArgCount < 1 || nArgCount > 2 ) + { + StarBASIC::Error( SbERR_BAD_ARGUMENT ); + return; + } + // retrieve non-optional params + Any aValues = sbxToUnoValue( rPar.Get(1), + getCppuType( (Sequence<double>*)0 ) ); + + // convert for calc functions + Sequence< Sequence< double > > sValues(1); + aValues >>= sValues[ 0 ]; + aValues <<= sValues; + + // set default values for Optional args + double guess = 0.1; + // guess + if ( nArgCount >= 2 ) + { + if( rPar.Get(2)->GetType() != SbxEMPTY ) + guess = rPar.Get(2)->GetDouble(); + } + + Sequence< Any > aParams( 2 ); + aParams[ 0 ] <<= aValues; + aParams[ 1 ] <<= guess; + + CallFunctionAccessFunction( aParams, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("IRR") ), rPar.Get( 0 ) ); +} + +RTLFUNC(IPmt) +{ + (void)pBasic; + (void)bWrite; + + ULONG nArgCount = rPar.Count()-1; + + if ( nArgCount < 4 || nArgCount > 6 ) + { + StarBASIC::Error( SbERR_BAD_ARGUMENT ); + return; + } + // retrieve non-optional params + + double rate = rPar.Get(1)->GetDouble(); + double per = rPar.Get(2)->GetInteger(); + double nper = rPar.Get(3)->GetDouble(); + double pv = rPar.Get(4)->GetDouble(); + + // set default values for Optional args + double fv = 0; + double type = 0; + + // fv + if ( nArgCount >= 5 ) + { + if( rPar.Get(5)->GetType() != SbxEMPTY ) + fv = rPar.Get(5)->GetDouble(); + } + // type + if ( nArgCount >= 6 ) + { + if( rPar.Get(6)->GetType() != SbxEMPTY ) + type = rPar.Get(6)->GetDouble(); + } + + Sequence< Any > aParams( 6 ); + aParams[ 0 ] <<= rate; + aParams[ 1 ] <<= per; + aParams[ 2 ] <<= nper; + aParams[ 3 ] <<= pv; + aParams[ 4 ] <<= fv; + aParams[ 5 ] <<= type; + + CallFunctionAccessFunction( aParams, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("IPmt") ), rPar.Get( 0 ) ); +} + +RTLFUNC(FV) +{ + (void)pBasic; + (void)bWrite; + + ULONG nArgCount = rPar.Count()-1; + + if ( nArgCount < 3 || nArgCount > 5 ) + { + StarBASIC::Error( SbERR_BAD_ARGUMENT ); + return; + } + // retrieve non-optional params + + double rate = rPar.Get(1)->GetDouble(); + double nper = rPar.Get(2)->GetDouble(); + double pmt = rPar.Get(3)->GetDouble(); + + // set default values for Optional args + double pv = 0; + double type = 0; + + // pv + if ( nArgCount >= 4 ) + { + if( rPar.Get(4)->GetType() != SbxEMPTY ) + pv = rPar.Get(4)->GetDouble(); + } + // type + if ( nArgCount >= 5 ) + { + if( rPar.Get(5)->GetType() != SbxEMPTY ) + type = rPar.Get(5)->GetDouble(); + } + + Sequence< Any > aParams( 5 ); + aParams[ 0 ] <<= rate; + aParams[ 1 ] <<= nper; + aParams[ 2 ] <<= pmt; + aParams[ 3 ] <<= pv; + aParams[ 4 ] <<= type; + + CallFunctionAccessFunction( aParams, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FV") ), rPar.Get( 0 ) ); +} + +RTLFUNC(DDB) +{ + (void)pBasic; + (void)bWrite; + + ULONG nArgCount = rPar.Count()-1; + + if ( nArgCount < 4 || nArgCount > 5 ) + { + StarBASIC::Error( SbERR_BAD_ARGUMENT ); + return; + } + // retrieve non-optional params + + double cost = rPar.Get(1)->GetDouble(); + double salvage = rPar.Get(2)->GetDouble(); + double life = rPar.Get(3)->GetDouble(); + double period = rPar.Get(4)->GetDouble(); + + // set default values for Optional args + double factor = 2; + + // factor + if ( nArgCount >= 5 ) + { + if( rPar.Get(5)->GetType() != SbxEMPTY ) + factor = rPar.Get(5)->GetDouble(); + } + + Sequence< Any > aParams( 5 ); + aParams[ 0 ] <<= cost; + aParams[ 1 ] <<= salvage; + aParams[ 2 ] <<= life; + aParams[ 3 ] <<= period; + aParams[ 4 ] <<= factor; + + CallFunctionAccessFunction( aParams, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("DDB") ), rPar.Get( 0 ) ); +} + +RTLFUNC(Rate) +{ + (void)pBasic; + (void)bWrite; + + ULONG nArgCount = rPar.Count()-1; + + if ( nArgCount < 3 || nArgCount > 6 ) + { + StarBASIC::Error( SbERR_BAD_ARGUMENT ); + return; + } + // retrieve non-optional params + + double nper = 0; + double pmt = 0; + double pv = 0; + + nper = rPar.Get(1)->GetDouble(); + pmt = rPar.Get(2)->GetDouble(); + pv = rPar.Get(3)->GetDouble(); + + // set default values for Optional args + double fv = 0; + double type = 0; + double guess = 0.1; + + // fv + if ( nArgCount >= 4 ) + { + if( rPar.Get(4)->GetType() != SbxEMPTY ) + fv = rPar.Get(4)->GetDouble(); + } + + // type + if ( nArgCount >= 5 ) + { + if( rPar.Get(5)->GetType() != SbxEMPTY ) + type = rPar.Get(5)->GetDouble(); + } + + // guess + if ( nArgCount >= 6 ) + { + if( rPar.Get(6)->GetType() != SbxEMPTY ) + type = rPar.Get(6)->GetDouble(); + } + + Sequence< Any > aParams( 6 ); + aParams[ 0 ] <<= nper; + aParams[ 1 ] <<= pmt; + aParams[ 2 ] <<= pv; + aParams[ 3 ] <<= fv; + aParams[ 4 ] <<= type; + aParams[ 5 ] <<= guess; + + CallFunctionAccessFunction( aParams, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Rate") ), rPar.Get( 0 ) ); +} + RTLFUNC(StrReverse) { (void)pBasic; diff --git a/basic/source/runtime/rtlproto.hxx b/basic/source/runtime/rtlproto.hxx index e3b2a05395..b1145c84ed 100644 --- a/basic/source/runtime/rtlproto.hxx +++ b/basic/source/runtime/rtlproto.hxx @@ -165,29 +165,41 @@ extern RTLFUNC(Kill); // JSM extern RTLFUNC(MkDir); // JSM extern RTLFUNC(RmDir); // JSM extern RTLFUNC(SendKeys); // JSM +extern RTLFUNC(DDB); extern RTLFUNC(DimArray); extern RTLFUNC(Dir); extern RTLFUNC(DoEvents); extern RTLFUNC(Exp); extern RTLFUNC(FileLen); extern RTLFUNC(Fix); +extern RTLFUNC(FV); extern RTLFUNC(Hex); extern RTLFUNC(Input); extern RTLFUNC(InStr); extern RTLFUNC(InStrRev); extern RTLFUNC(Int); +extern RTLFUNC(IPmt); +extern RTLFUNC(IRR); extern RTLFUNC(Join); extern RTLFUNC(LCase); extern RTLFUNC(Left); extern RTLFUNC(Log); extern RTLFUNC(LTrim); extern RTLFUNC(Mid); +extern RTLFUNC(MIRR); +extern RTLFUNC(NPer); +extern RTLFUNC(NPV); extern RTLFUNC(Oct); +extern RTLFUNC(Pmt); +extern RTLFUNC(PPmt); +extern RTLFUNC(PV); +extern RTLFUNC(Rate); extern RTLFUNC(Replace); extern RTLFUNC(Right); extern RTLFUNC(RTrim); extern RTLFUNC(RTL); extern RTLFUNC(Sgn); +extern RTLFUNC(SLN); extern RTLFUNC(Space); extern RTLFUNC(Split); extern RTLFUNC(Sqr); @@ -195,6 +207,7 @@ extern RTLFUNC(Str); extern RTLFUNC(StrComp); extern RTLFUNC(String); extern RTLFUNC(StrReverse); +extern RTLFUNC(SYD); extern RTLFUNC(Tan); extern RTLFUNC(UCase); extern RTLFUNC(Val); @@ -297,6 +310,7 @@ extern RTLFUNC(Switch); extern RTLFUNC(Wait); //i#64882# add new WaitUntil extern RTLFUNC(WaitUntil); +extern RTLFUNC(FuncCaller); extern RTLFUNC(GetGUIVersion); extern RTLFUNC(Choose); diff --git a/basic/source/runtime/runtime.cxx b/basic/source/runtime/runtime.cxx index a8eff4d55d..f358178da3 100644 --- a/basic/source/runtime/runtime.cxx +++ b/basic/source/runtime/runtime.cxx @@ -1,7 +1,7 @@ /************************************************************************* * * 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 @@ -46,6 +46,8 @@ #include "errobject.hxx" #include "sbtrace.hxx" +SbxVariable* getDefaultProp( SbxVariable* pRef ); + using namespace ::com::sun::star; bool SbiRuntime::isVBAEnabled() @@ -54,7 +56,7 @@ bool SbiRuntime::isVBAEnabled() SbiInstance* pInst = pINST; if ( pInst && pINST->pRun ) result = pInst->pRun->bVBAEnabled; - return result; + return result; } // #91147 Global reschedule flag @@ -75,7 +77,7 @@ void StarBASIC::SetVBAEnabled( BOOL bEnabled ) BOOL StarBASIC::isVBAEnabled() { if ( bDocBasic ) - { + { if( SbiRuntime::isVBAEnabled() ) return TRUE; return bVBAEnabled; @@ -209,7 +211,7 @@ SbiRuntime::pStep2 SbiRuntime::aStep2[] = {// Alle Opcodes mit zwei Operanden &SbiRuntime::StepSTATIC, // Statische Variable (+StringId+StringId) &SbiRuntime::StepTCREATE, // User Defined Objekte (+StringId+StringId) &SbiRuntime::StepDCREATE, // Objekt-Array kreieren (+StringID+StringID) - &SbiRuntime::StepGLOBAL_P, // Globale Variable definieren, die beim Neustart + &SbiRuntime::StepGLOBAL_P, // Globale Variable definieren, die beim Neustart // von Basic nicht ueberschrieben wird (+StringID+Typ) &SbiRuntime::StepFIND_G, // Sucht globale Variable mit Spezialbehandlung wegen _GLOBAL_P &SbiRuntime::StepDCREATE_REDIMP, // Objekt-Array redimensionieren (+StringID+StringID) @@ -363,7 +365,7 @@ void SbiInstance::PrepareNumberFormatter( SvNumberFormatter*& rpNumberFormatter, sal_uInt32 &rnStdDateIdx, sal_uInt32 &rnStdTimeIdx, sal_uInt32 &rnStdDateTimeIdx, LanguageType* peFormatterLangType, DateFormat* peFormatterDateFormat ) { - com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > + com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > xFactory = comphelper::getProcessServiceFactory(); LanguageType eLangType; @@ -543,8 +545,8 @@ SbxArray* SbiInstance::GetLocals( SbMethod* pMeth ) // Achtung: pMeth kann auch NULL sein (beim Aufruf des Init-Codes) SbiRuntime::SbiRuntime( SbModule* pm, SbMethod* pe, UINT32 nStart ) - : rBasic( *(StarBASIC*)pm->pParent ), pInst( pINST ), - pMod( pm ), pMeth( pe ), pImg( pMod->pImage ), m_nLastTime(0) + : rBasic( *(StarBASIC*)pm->pParent ), pInst( pINST ), + pMod( pm ), pMeth( pe ), pImg( pMod->pImage ), mpExtCaller(0), m_nLastTime(0) { nFlags = pe ? pe->GetDebugFlags() : 0; pIosys = pInst->pIosys; @@ -600,7 +602,14 @@ SbiRuntime::~SbiRuntime() void SbiRuntime::SetVBAEnabled(bool bEnabled ) { - bVBAEnabled = bEnabled; + bVBAEnabled = bEnabled; + if ( bVBAEnabled ) + { + if ( pMeth ) + mpExtCaller = pMeth->mCaller; + } + else + mpExtCaller = 0; } // Aufbau der Parameterliste. Alle ByRef-Parameter werden direkt @@ -652,7 +661,7 @@ void SbiRuntime::SetParameters( SbxArray* pParams ) bByVal |= BOOL( ( p->eType & SbxBYREF ) == 0 ); t = (SbxDataType) ( p->eType & 0x0FFF ); - if( !bByVal && t != SbxVARIANT && + if( !bByVal && t != SbxVARIANT && (!v->IsFixed() || (SbxDataType)(v->GetType() & 0x0FFF ) != t) ) bByVal = TRUE; } @@ -736,7 +745,7 @@ BOOL SbiRuntime::Step() else if( eOp >= SbOP1_START && eOp <= SbOP1_END ) { nOp1 = *pCode++; nOp1 |= *pCode++ << 8; nOp1 |= *pCode++ << 16; nOp1 |= *pCode++ << 24; - + (this->*( aStep1[ eOp - SbOP1_START ] ) )( nOp1 ); } else if( eOp >= SbOP2_START && eOp <= SbOP2_END ) @@ -775,7 +784,7 @@ BOOL SbiRuntime::Step() pInst->nErl = nLine; pErrCode = pCode; pErrStmnt = pStmnt; - // An error occured in an error handler + // An error occured in an error handler // force parent handler ( if there is one ) // to handle the error bool bLetParentHandleThis = false; @@ -789,14 +798,14 @@ BOOL SbiRuntime::Step() StepRESUME( 1 ); else if( pError ) // On Error Goto ... pCode = pError; - else + else bLetParentHandleThis = true; } else { bLetParentHandleThis = true; pError = NULL; //terminate the handler - } + } if ( bLetParentHandleThis ) { // AB 13.2.1997, neues Error-Handling: @@ -930,7 +939,7 @@ sal_Int32 SbiRuntime::translateErrorToVba( SbError nError, String& rMsg ) DBG_ASSERT( nTmp, "No VB error!" ); #endif - StarBASIC::MakeErrorText( nError, rMsg ); + StarBASIC::MakeErrorText( nError, rMsg ); rMsg = StarBASIC::GetErrorText(); if ( !rMsg.Len() ) // no message for err no, need localized resource here rMsg = String( RTL_CONSTASCII_USTRINGPARAM("Internal Object Error:") ); @@ -1029,7 +1038,25 @@ SbxVariable* SbiRuntime::GetTOS( short n ) void SbiRuntime::TOSMakeTemp() { SbxVariable* p = refExprStk->Get( nExprLvl - 1 ); - if( p->GetRefCount() != 1 ) + if ( p->GetType() == SbxEMPTY ) + p->Broadcast( SBX_HINT_DATAWANTED ); + + SbxVariable* pDflt = NULL; + if ( bVBAEnabled && ( p->GetType() == SbxOBJECT || p->GetType() == SbxVARIANT ) && ( pDflt = getDefaultProp( p ) ) ) + { + pDflt->Broadcast( SBX_HINT_DATAWANTED ); + // replacing new p on stack causes object pointed by + // pDft->pParent to be deleted, when p2->Compute() is + // called below pParent is accessed ( but its deleted ) + // so set it to NULL now + pDflt->SetParent( NULL ); + p = new SbxVariable( *pDflt ); + p->SetFlag( SBX_READWRITE ); + refExprStk->Put( p, nExprLvl - 1 ); +// return; + } + + else if( p->GetRefCount() != 1 ) { SbxVariable* pNew = new SbxVariable( *p ); pNew->SetFlag( SBX_READWRITE ); @@ -1038,7 +1065,6 @@ void SbiRuntime::TOSMakeTemp() } // Der GOSUB-Stack nimmt Returnadressen fuer GOSUBs auf - void SbiRuntime::PushGosub( const BYTE* pc ) { if( ++nGosubLvl > MAXRECURSION ) @@ -1258,11 +1284,11 @@ void SbiRuntime::DllCall } USHORT SbiRuntime::GetImageFlag( USHORT n ) const -{ - return pImg->GetFlag( n ); -} +{ + return pImg->GetFlag( n ); +} USHORT SbiRuntime::GetBase() -{ +{ return pImg->GetBase(); } diff --git a/basic/source/runtime/stdobj.cxx b/basic/source/runtime/stdobj.cxx index d621a12f0f..c23ebe8e70 100644 --- a/basic/source/runtime/stdobj.cxx +++ b/basic/source/runtime/stdobj.cxx @@ -1,7 +1,7 @@ /************************************************************************* * * 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 @@ -33,7 +33,7 @@ #include <basic/sbstdobj.hxx> #include "rtlproto.hxx" #include "sbintern.hxx" - +#include <hash_map> // Das nArgs-Feld eines Tabelleneintrags ist wie folgt verschluesselt: // Zur Zeit wird davon ausgegangen, dass Properties keine Parameter // benoetigen! @@ -69,6 +69,45 @@ struct Methods { USHORT nHash; // Hashcode }; +struct StringHashCode +{ + size_t operator()( const String& rStr ) const + { + return rtl_ustr_hashCode_WithLength( rStr.GetBuffer(), rStr.Len() ); + } +}; + +class VBABlacklist +{ +friend class VBABlackListQuery; + std::hash_map< String, bool, StringHashCode > mBlackList; + VBABlacklist() + { + const char* list[] = { "Red" }; + sal_Int32 nSize = sizeof( list ) / sizeof( list[ 0 ] ); + for ( sal_Int32 index = 0; index < nSize; ++index ) + { + mBlackList[ String::CreateFromAscii( list[ index ] ).ToLowerAscii() ] = true; + } + } +public: + bool isBlackListed( const String& sName ) + { + String sNameLower( sName ); + sNameLower.ToLowerAscii(); + return ( mBlackList.find( sNameLower ) != mBlackList.end() ); + } +}; + +class VBABlackListQuery +{ +public: + static bool isBlackListed( const String& sName ) + { + static VBABlacklist blackList; + return blackList.isBlackListed( sName ); + } +}; static Methods aMethods[] = { { "AboutStarBasic", SbxNULL, 1 | _FUNCTION, RTLNAME(AboutStarBasic),0 }, @@ -171,7 +210,12 @@ static Methods aMethods[] = { { "expression", SbxVARIANT, 0,NULL,0 }, { "CVErr", SbxVARIANT, 1 | _FUNCTION, RTLNAME(CVErr),0 }, { "expression", SbxVARIANT, 0,NULL,0 }, - +{ "DDB", SbxDOUBLE, 5 | _FUNCTION | _COMPTMASK, RTLNAME(DDB),0 }, + { "Cost", SbxDOUBLE, 0, NULL,0 }, + { "Salvage", SbxDOUBLE, 0, NULL,0 }, + { "Life", SbxDOUBLE, 0, NULL,0 }, + { "Period", SbxDOUBLE, 0, NULL,0 }, + { "Factor", SbxVARIANT, _OPT, NULL,0 }, { "Date", SbxDATE, _LFUNCTION,RTLNAME(Date),0 }, { "DateAdd", SbxDATE, 3 | _FUNCTION, RTLNAME(DateAdd),0 }, { "Interval", SbxSTRING, 0,NULL,0 }, @@ -216,7 +260,7 @@ static Methods aMethods[] = { { "Dir", SbxSTRING, 2 | _FUNCTION, RTLNAME(Dir),0 }, { "FileSpec", SbxSTRING, _OPT, NULL,0 }, { "attrmask", SbxINTEGER, _OPT, NULL,0 }, -{ "DoEvents", SbxEMPTY, _FUNCTION, RTLNAME(DoEvents),0 }, +{ "DoEvents", SbxINTEGER, _FUNCTION, RTLNAME(DoEvents),0 }, { "DumpAllObjects", SbxEMPTY, 2 | _SUB, RTLNAME(DumpAllObjects),0 }, { "FileSpec", SbxSTRING, 0,NULL,0 }, { "DumpAll", SbxINTEGER, _OPT, NULL,0 }, @@ -271,6 +315,12 @@ static Methods aMethods[] = { { "FreeLibrary", SbxNULL, 1 | _FUNCTION, RTLNAME(FreeLibrary),0 }, { "Modulename", SbxSTRING, 0,NULL,0 }, +{ "FV", SbxDOUBLE, 5 | _FUNCTION | _COMPTMASK, RTLNAME(FV),0 }, + { "Rate", SbxDOUBLE, 0, NULL,0 }, + { "NPer", SbxDOUBLE, 0, NULL,0 }, + { "Pmt", SbxDOUBLE, 0, NULL,0 }, + { "PV", SbxVARIANT, _OPT, NULL,0 }, + { "Due", SbxVARIANT, _OPT, NULL,0 }, { "Get", SbxNULL, 3 | _FUNCTION, RTLNAME(Get),0 }, { "filenumber", SbxINTEGER, 0,NULL,0 }, { "recordnumber", SbxLONG, 0,NULL,0 }, @@ -331,6 +381,16 @@ static Methods aMethods[] = { { "Compare", SbxINTEGER, _OPT, NULL,0 }, { "Int", SbxDOUBLE, 1 | _FUNCTION, RTLNAME(Int),0 }, { "number", SbxDOUBLE, 0,NULL,0 }, +{ "IPmt", SbxDOUBLE, 6 | _FUNCTION | _COMPTMASK, RTLNAME(IPmt),0 }, + { "Rate", SbxDOUBLE, 0, NULL,0 }, + { "Per", SbxDOUBLE, 0, NULL,0 }, + { "NPer", SbxDOUBLE, 0, NULL,0 }, + { "PV", SbxDOUBLE, 0, NULL,0 }, + { "FV", SbxVARIANT, _OPT, NULL,0 }, + { "Due", SbxVARIANT, _OPT, NULL,0 }, +{ "IRR", SbxDOUBLE, 2 | _FUNCTION | _COMPTMASK, RTLNAME(IRR),0 }, + { "ValueArray", SbxARRAY, 0, NULL,0 }, + { "Guess", SbxVARIANT, _OPT, NULL,0 }, { "IsArray", SbxBOOL, 1 | _FUNCTION, RTLNAME(IsArray),0 }, { "Variant", SbxVARIANT, 0,NULL,0 }, { "IsDate", SbxBOOL, 1 | _FUNCTION, RTLNAME(IsDate),0 }, @@ -401,6 +461,10 @@ static Methods aMethods[] = { { "Length", SbxLONG, _OPT, NULL,0 }, { "Minute", SbxINTEGER, 1 | _FUNCTION, RTLNAME(Minute),0 }, { "Date", SbxDATE, 0,NULL,0 }, +{ "MIRR", SbxDOUBLE, 2 | _FUNCTION | _COMPTMASK, RTLNAME(MIRR),0 }, + { "ValueArray", SbxARRAY, 0, NULL,0 }, + { "FinanceRate", SbxDOUBLE, 0, NULL,0 }, + { "ReinvestRate", SbxDOUBLE, 0, NULL,0 }, { "MkDir", SbxNULL, 1 | _FUNCTION, RTLNAME(MkDir),0 }, { "pathname", SbxSTRING, 0,NULL,0 }, { "Month", SbxINTEGER, 1 | _FUNCTION, RTLNAME(Month),0 }, @@ -417,6 +481,15 @@ static Methods aMethods[] = { { "Nothing", SbxOBJECT, _CPROP, RTLNAME(Nothing),0 }, { "Now", SbxDATE, _FUNCTION, RTLNAME(Now),0 }, +{ "NPer", SbxDOUBLE, 5 | _FUNCTION | _COMPTMASK, RTLNAME(NPer),0 }, + { "Rate", SbxDOUBLE, 0, NULL,0 }, + { "Pmt", SbxDOUBLE, 0, NULL,0 }, + { "PV", SbxDOUBLE, 0, NULL,0 }, + { "FV", SbxVARIANT, _OPT, NULL,0 }, + { "Due", SbxVARIANT, _OPT, NULL,0 }, +{ "NPV", SbxDOUBLE, 2 | _FUNCTION | _COMPTMASK, RTLNAME(NPV),0 }, + { "Rate", SbxDOUBLE, 0, NULL,0 }, + { "ValueArray", SbxARRAY, 0, NULL,0 }, { "Null", SbxNULL, _CPROP, RTLNAME(Null),0 }, { "Oct", SbxSTRING, 1 | _FUNCTION, RTLNAME(Oct),0 }, @@ -428,16 +501,46 @@ static Methods aMethods[] = { { "stop", SbxLONG, 0,NULL,0 }, { "interval", SbxLONG, 0,NULL,0 }, { "Pi", SbxDOUBLE, _CPROP, RTLNAME(PI),0 }, + +{ "Pmt", SbxDOUBLE, 5 | _FUNCTION | _COMPTMASK, RTLNAME(Pmt),0 }, + { "Rate", SbxDOUBLE, 0, NULL,0 }, + { "NPer", SbxDOUBLE, 0, NULL,0 }, + { "PV", SbxDOUBLE, 0, NULL,0 }, + { "FV", SbxVARIANT, _OPT, NULL,0 }, + { "Due", SbxVARIANT, _OPT, NULL,0 }, + +{ "PPmt", SbxDOUBLE, 6 | _FUNCTION | _COMPTMASK, RTLNAME(PPmt),0 }, + { "Rate", SbxDOUBLE, 0, NULL,0 }, + { "Per", SbxDOUBLE, 0, NULL,0 }, + { "NPer", SbxDOUBLE, 0, NULL,0 }, + { "PV", SbxDOUBLE, 0, NULL,0 }, + { "FV", SbxVARIANT, _OPT, NULL,0 }, + { "Due", SbxVARIANT, _OPT, NULL,0 }, + { "Put", SbxNULL, 3 | _FUNCTION, RTLNAME(Put),0 }, { "filenumber", SbxINTEGER, 0,NULL,0 }, { "recordnumber", SbxLONG, 0,NULL,0 }, { "variablename", SbxVARIANT, 0,NULL,0 }, +{ "PV", SbxDOUBLE, 5 | _FUNCTION | _COMPTMASK, RTLNAME(PV),0 }, + { "Rate", SbxDOUBLE, 0, NULL,0 }, + { "NPer", SbxDOUBLE, 0, NULL,0 }, + { "Pmt", SbxDOUBLE, 0, NULL,0 }, + { "FV", SbxVARIANT, _OPT, NULL,0 }, + { "Due", SbxVARIANT, _OPT, NULL,0 }, + { "QBColor", SbxLONG, 1 | _FUNCTION, RTLNAME(QBColor),0 }, { "number", SbxINTEGER, 0,NULL,0 }, { "Randomize", SbxNULL, 1 | _FUNCTION, RTLNAME(Randomize),0 }, { "Number", SbxDOUBLE, _OPT, NULL,0 }, +{ "Rate", SbxDOUBLE, 6 | _FUNCTION | _COMPTMASK, RTLNAME(Rate),0 }, + { "NPer", SbxDOUBLE, 0, NULL,0 }, + { "Pmt", SbxDOUBLE, 0, NULL,0 }, + { "PV", SbxDOUBLE, 0, NULL,0 }, + { "FV", SbxVARIANT, _OPT, NULL,0 }, + { "Due", SbxVARIANT, _OPT, NULL,0 }, + { "Guess", SbxVARIANT, _OPT, NULL,0 }, { "Red", SbxINTEGER, 1 | _FUNCTION, RTLNAME(Red),0 }, { "RGB-Value", SbxLONG, 0,NULL,0 }, { "Reset", SbxNULL, 0 | _FUNCTION, RTLNAME(Reset),0 }, @@ -491,6 +594,15 @@ static Methods aMethods[] = { { "WindowStyle", SbxINTEGER, _OPT, NULL,0 }, { "Sin", SbxDOUBLE, 1 | _FUNCTION, RTLNAME(Sin),0 }, { "number", SbxDOUBLE, 0,NULL,0 }, +{ "SLN", SbxDOUBLE, 2 | _FUNCTION | _COMPTMASK, RTLNAME(SLN),0 }, + { "Cost", SbxDOUBLE, 0,NULL,0 }, + { "Double", SbxDOUBLE, 0,NULL,0 }, + { "Life", SbxDOUBLE, 0,NULL,0 }, +{ "SYD", SbxDOUBLE, 2 | _FUNCTION | _COMPTMASK, RTLNAME(SYD),0 }, + { "Cost", SbxDOUBLE, 0,NULL,0 }, + { "Salvage", SbxDOUBLE, 0,NULL,0 }, + { "Life", SbxDOUBLE, 0,NULL,0 }, + { "Period", SbxDOUBLE, 0,NULL,0 }, { "Space", SbxSTRING, 1 | _FUNCTION, RTLNAME(Space),0 }, { "string", SbxLONG, 0,NULL,0 }, { "Spc", SbxSTRING, 1 | _FUNCTION, RTLNAME(Spc),0 }, @@ -605,6 +717,7 @@ static Methods aMethods[] = { { "Wait", SbxNULL, 1 | _FUNCTION, RTLNAME(Wait),0 }, { "Milliseconds", SbxLONG, 0,NULL,0 }, +{ "FuncCaller", SbxVARIANT, _FUNCTION, RTLNAME(FuncCaller),0 }, //#i64882# { "WaitUntil", SbxNULL, 1 | _FUNCTION, RTLNAME(WaitUntil),0 }, { "Date", SbxDOUBLE, 0,NULL,0 }, @@ -683,13 +796,15 @@ SbxVariable* SbiStdObject::Find( const String& rName, SbxClassType t ) && ( p->nHash == nHash_ ) && ( rName.EqualsIgnoreCaseAscii( p->pName ) ) ) { + SbiInstance* pInst = pINST; bFound = TRUE; if( p->nArgs & _COMPTMASK ) { - SbiInstance* pInst = pINST; if( !pInst || !pInst->IsCompatibility() ) bFound = FALSE; } + if ( pInst && pInst->IsCompatibility() && VBABlackListQuery::isBlackListed( rName ) ) + bFound = FALSE; break; } nIndex += ( p->nArgs & _ARGSMASK ) + 1; diff --git a/basic/source/runtime/step0.cxx b/basic/source/runtime/step0.cxx index 7d1f92fcf4..c714832608 100644 --- a/basic/source/runtime/step0.cxx +++ b/basic/source/runtime/step0.cxx @@ -1,7 +1,7 @@ /************************************************************************* * * 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 @@ -48,6 +48,11 @@ Reference< XInterface > createComListener( const Any& aControlAny, const ::rtl:: #include <algorithm> +// for a patch forward declaring these methods below makes sense +// but, #FIXME lets really just move the methods to the top +void lcl_clearImpl( SbxVariableRef& refVar, SbxDataType& eType ); +void lcl_eraseImpl( SbxVariableRef& refVar, bool bVBAEnabled ); + SbxVariable* getDefaultProp( SbxVariable* pRef ); void SbiRuntime::StepNOP() @@ -59,34 +64,6 @@ void SbiRuntime::StepArith( SbxOperator eOp ) TOSMakeTemp(); SbxVariable* p2 = GetTOS(); - - // This could & should be moved to the MakeTempTOS() method in runtime.cxx - // In the code which this is cut'npaste from there is a check for a ref - // count != 1 based on which the copy of the SbxVariable is done. - // see orig code in MakeTempTOS ( and I'm not sure what the significance, - // of that is ) - // here we alway seem to have a refcount of 1. Also it seems that - // MakeTempTOS is called for other operation, so I hold off for now - // until I have a better idea - if ( bVBAEnabled - && ( p2->GetType() == SbxOBJECT || p2->GetType() == SbxVARIANT ) - ) - { - SbxVariable* pDflt = getDefaultProp( p2 ); - if ( pDflt ) - { - pDflt->Broadcast( SBX_HINT_DATAWANTED ); - // replacing new p2 on stack causes object pointed by - // pDft->pParent to be deleted, when p2->Compute() is - // called below pParent is accessed ( but its deleted ) - // so set it to NULL now - pDflt->SetParent( NULL ); - p2 = new SbxVariable( *pDflt ); - p2->SetFlag( SBX_READWRITE ); - refExprStk->Put( p2, nExprLvl - 1 ); - } - } - p2->ResetFlag( SBX_FIXED ); p2->Compute( eOp, *p1 ); @@ -105,23 +82,28 @@ void SbiRuntime::StepCompare( SbxOperator eOp ) SbxVariableRef p1 = PopVar(); SbxVariableRef p2 = PopVar(); - // Make sure objects with default params have + // Make sure objects with default params have // values ( and type ) set as appropriate - SbxDataType p1Type = p1->GetType(); - SbxDataType p2Type = p2->GetType(); + SbxDataType p1Type = p1->GetType(); + SbxDataType p2Type = p2->GetType(); + if ( p1Type == SbxEMPTY ) + { + p1->Broadcast( SBX_HINT_DATAWANTED ); + p1Type = p1->GetType(); + } + if ( p2Type == SbxEMPTY ) + { + p2->Broadcast( SBX_HINT_DATAWANTED ); + p2Type = p2->GetType(); + } if ( p1Type == p2Type ) { - if ( p1Type == SbxEMPTY ) - { - p1->Broadcast( SBX_HINT_DATAWANTED ); - p2->Broadcast( SBX_HINT_DATAWANTED ); - } // if both sides are an object and have default props // then we need to use the default props - // we don't need to worry if only one side ( lhs, rhs ) is an - // object ( object side will get coerced to correct type in + // we don't need to worry if only one side ( lhs, rhs ) is an + // object ( object side will get coerced to correct type in // Compare ) - else if ( p1Type == SbxOBJECT ) + if ( p1Type == SbxOBJECT ) { SbxVariable* pDflt = getDefaultProp( p1 ); if ( pDflt ) @@ -141,8 +123,21 @@ void SbiRuntime::StepCompare( SbxOperator eOp ) #ifndef WIN static SbxVariable* pTRUE = NULL; static SbxVariable* pFALSE = NULL; - - if( p2->Compare( eOp, *p1 ) ) + static SbxVariable* pNULL = NULL; + // why do this on non-windows ? + // why do this at all ? + // I dumbly follow the pattern :-/ + if ( bVBAEnabled && ( p1->IsNull() || p2->IsNull() ) ) + { + if( !pNULL ) + { + pNULL = new SbxVariable; + pNULL->PutNull(); + pNULL->AddRef(); + } + PushVar( pNULL ); + } + else if( p2->Compare( eOp, *p1 ) ) { if( !pTRUE ) { @@ -163,9 +158,14 @@ void SbiRuntime::StepCompare( SbxOperator eOp ) PushVar( pFALSE ); } #else - BOOL bRes = p2->Compare( eOp, *p1 ); SbxVariable* pRes = new SbxVariable; - pRes->PutBool( bRes ); + if ( bVBAEnabled && ( p1->IsNull() || p2->IsNull() ) ) + pRes->PutNull(); + else + { + BOOL bRes = p2->Compare( eOp, *p1 ); + pRes->PutBool( bRes ); + } PushVar( pRes ); #endif } @@ -212,7 +212,7 @@ namespace sResult.Append('^'); - while (start < end) + while (start < end) { switch (*start) { @@ -394,20 +394,20 @@ void SbiRuntime::StepPUT() refVar->SetFlag( SBX_WRITE ); } - // if left side arg is an object or variant and right handside isn't - // either an object or a variant then try and see if a default + // if left side arg is an object or variant and right handside isn't + // either an object or a variant then try and see if a default // property exists. // to use e.g. Range{"A1") = 34 - // could equate to Range("A1").Value = 34 + // could equate to Range("A1").Value = 34 if ( bVBAEnabled ) { - if ( refVar->GetType() == SbxOBJECT ) + if ( refVar->GetType() == SbxOBJECT ) { SbxVariable* pDflt = getDefaultProp( refVar ); if ( pDflt ) refVar = pDflt; } - if ( refVal->GetType() == SbxOBJECT ) + if ( refVal->GetType() == SbxOBJECT ) { SbxVariable* pDflt = getDefaultProp( refVal ); if ( pDflt ) @@ -511,7 +511,7 @@ void SbiRuntime::StepSET_Impl( SbxVariableRef& refVal, SbxVariableRef& refVar, b // if it is then use the object not the default property SbxObject* pObj = NULL; - + pObj = PTR_CAST(SbxObject,(SbxVariable*)refVar); // calling GetObject on a SbxEMPTY variable raises @@ -520,7 +520,7 @@ void SbiRuntime::StepSET_Impl( SbxVariableRef& refVal, SbxVariableRef& refVar, b { SbxBase* pObjVarObj = refVar->GetObject(); pObj = PTR_CAST(SbxObject,pObjVarObj); - } + } SbxVariable* pDflt = NULL; if ( pObj || bLHSHasDefaultProp ) // lhs is either a valid object || or has a defaultProp @@ -528,8 +528,8 @@ void SbiRuntime::StepSET_Impl( SbxVariableRef& refVal, SbxVariableRef& refVar, b if ( pDflt ) refVal = pDflt; } - } - + } + // Handle withevents BOOL bWithEvents = refVar->IsSet( SBX_WITH_EVENTS ); if ( bWithEvents ) @@ -559,7 +559,7 @@ void SbiRuntime::StepSET_Impl( SbxVariableRef& refVal, SbxVariableRef& refVar, b } // 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 + // in this case if there is a default prop involved the value of the // default property may infact be void so the type will also be SbxEMPTY // in this case we do not want to call checkUnoStructCopy 'cause that will // cause an error also @@ -679,6 +679,17 @@ void SbiRuntime::StepDIM() // #56204 DIM-Funktionalitaet in Hilfsmethode auslagern (step0.cxx) void SbiRuntime::DimImpl( SbxVariableRef refVar ) { + // If refDim then this DIM statement is terminating a ReDIM and + // previous StepERASE_CLEAR for an array, the following actions have + // been delayed from ( StepERASE_CLEAR ) 'till here + if ( refRedim ) + { + if ( !refRedimpArray ) // only erase the array not ReDim Preserve + lcl_eraseImpl( refVar, bVBAEnabled ); + SbxDataType eType = refVar->GetType(); + lcl_clearImpl( refVar, eType ); + refRedim = NULL; + } SbxArray* pDims = refVar->GetParameters(); // Muss eine gerade Anzahl Argumente haben // Man denke daran, dass Arg[0] nicht zaehlt! @@ -737,7 +748,7 @@ void implCopyDimArray( SbxDimArray* pNewArray, SbxDimArray* pOldArray, short nMa { if( nActualDim < nMaxDimIndex ) { - implCopyDimArray( pNewArray, pOldArray, nMaxDimIndex, nActualDim + 1, + implCopyDimArray( pNewArray, pOldArray, nMaxDimIndex, nActualDim + 1, pActualIndices, pLowerBounds, pUpperBounds ); } else @@ -844,6 +855,7 @@ void SbiRuntime::StepREDIMP() void SbiRuntime::StepREDIMP_ERASE() { SbxVariableRef refVar = PopVar(); + refRedim = refVar; SbxDataType eType = refVar->GetType(); if( eType & SbxARRAY ) { @@ -854,12 +866,6 @@ void SbiRuntime::StepREDIMP_ERASE() refRedimpArray = pDimArray; } - // As in ERASE - USHORT nSavFlags = refVar->GetFlags(); - refVar->ResetFlag( SBX_FIXED ); - refVar->SetType( SbxDataType(eType & 0x0FFF) ); - refVar->SetFlags( nSavFlags ); - refVar->Clear(); } else if( refVar->IsFixed() ) @@ -903,7 +909,7 @@ void lcl_eraseImpl( SbxVariableRef& refVar, bool bVBAEnabled ) SbxArray* pArray = PTR_CAST(SbxArray,pElemObj); if ( pArray ) pArray->Clear(); - } + } } else // AB 2.4.1996 @@ -932,10 +938,7 @@ void SbiRuntime::StepERASE() void SbiRuntime::StepERASE_CLEAR() { - SbxVariableRef refVar = PopVar(); - lcl_eraseImpl( refVar, bVBAEnabled ); - SbxDataType eType = refVar->GetType(); - lcl_clearImpl( refVar, eType ); + refRedim = PopVar(); } void SbiRuntime::StepARRAYACCESS() @@ -1083,7 +1086,7 @@ void SbiRuntime::StepINPUT() // ErrorBox( NULL, WB_OK, aMsg ).Execute(); //****** DONT CHECK IN, TEST ONLY ******* //****** DONT CHECK IN, TEST ONLY ******* - + pCode = pRestart; } else @@ -1324,7 +1327,7 @@ void SbiRuntime::StepERROR() SbxVariableRef refCode = PopVar(); USHORT n = refCode->GetUShort(); SbError error = StarBASIC::GetSfxFromVBError( n ); - if ( bVBAEnabled ) + if ( bVBAEnabled ) pInst->Error( error ); else Error( error ); diff --git a/basic/source/runtime/step1.cxx b/basic/source/runtime/step1.cxx index f448f7900b..0a82b9af57 100644 --- a/basic/source/runtime/step1.cxx +++ b/basic/source/runtime/step1.cxx @@ -1,7 +1,7 @@ /************************************************************************* * * 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 @@ -38,7 +38,7 @@ #include "sbunoobj.hxx" #include "errobject.hxx" -bool checkUnoObjectType( SbUnoObject* refVal, +bool checkUnoObjectType( SbUnoObject* refVal, const String& aClass ); // Laden einer numerischen Konstanten (+ID) @@ -93,6 +93,15 @@ void SbiRuntime::StepARGN( UINT32 nOp1 ) { String aAlias( pImg->GetString( static_cast<short>( nOp1 ) ) ); SbxVariableRef pVal = PopVar(); + if( bVBAEnabled && ( pVal->ISA(SbxMethod) || pVal->ISA(SbUnoProperty) || pVal->ISA(SbProcedureProperty) ) ) + { + // named variables ( that are Any especially properties ) can be empty at this point and need a broadcast + if ( pVal->GetType() == SbxEMPTY ) + pVal->Broadcast( SBX_HINT_DATAWANTED ); + // Methoden und Properties evaluieren! + SbxVariable* pRes = new SbxVariable( *pVal ); + pVal = pRes; + } refArgv->Put( pVal, nArgc ); refArgv->PutAlias( aAlias, nArgc++ ); } @@ -160,7 +169,7 @@ void SbiRuntime::StepPAD( UINT32 nOp1 ) void SbiRuntime::StepJUMP( UINT32 nOp1 ) { #ifdef DBG_UTIL - // #QUESTION shouln't this be + // #QUESTION shouln't this be // if( (BYTE*)( nOp1+pImagGetCode() ) >= pImg->GetCodeSize() ) if( nOp1 >= pImg->GetCodeSize() ) StarBASIC::FatalError( SbERR_INTERNAL_ERROR ); @@ -182,7 +191,9 @@ void SbiRuntime::StepJUMPT( UINT32 nOp1 ) void SbiRuntime::StepJUMPF( UINT32 nOp1 ) { SbxVariableRef p = PopVar(); - if( !p->GetBool() ) + // In a test e.g. If Null then + // will evaluate Null will act as if False + if( ( bVBAEnabled && p->IsNull() ) || !p->GetBool() ) StepJUMP( nOp1 ); } @@ -443,7 +454,7 @@ bool SbiRuntime::implIsClass( SbxObject* pObj, const String& aClass ) SbClassData* pClassData; if( pClassMod && (pClassData=pClassMod->pClassData) != NULL ) { - SbxVariable* pClassVar = + SbxVariable* pClassVar = pClassData->mxIfaces->Find( aClass, SbxCLASS_DONTCARE ); bRet = (pClassVar != NULL); } @@ -452,7 +463,7 @@ bool SbiRuntime::implIsClass( SbxObject* pObj, const String& aClass ) return bRet; } -bool SbiRuntime::checkClass_Impl( const SbxVariableRef& refVal, +bool SbiRuntime::checkClass_Impl( const SbxVariableRef& refVal, const String& aClass, bool bRaiseErrors, bool bDefault ) { bool bOk = bDefault; diff --git a/basic/source/runtime/step2.cxx b/basic/source/runtime/step2.cxx index 419f00bd21..5068470278 100644 --- a/basic/source/runtime/step2.cxx +++ b/basic/source/runtime/step2.cxx @@ -1,7 +1,7 @@ /************************************************************************* * * 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 @@ -96,7 +96,7 @@ SbxVariable* SbiRuntime::FindElement if( bLocal ) { if ( bStatic ) - { + { if ( pMeth ) pElem = pMeth->GetStatics()->Find( aName, SbxCLASS_DONTCARE ); } @@ -139,7 +139,7 @@ SbxVariable* SbiRuntime::FindElement if ( pElem ) bSetName = false; // don't overwrite uno name else - pElem = getVBAConstant( aName ); + pElem = VBAConstantHelper::instance().getVBAConstant( aName ); } // #72382 VORSICHT! Liefert jetzt wegen unbekannten // Modulen IMMER ein Ergebnis! @@ -259,10 +259,10 @@ SbxVariable* SbiRuntime::FindElement if( bSet ) pElem->SetType( t2 ); pElem = pNew; - } + } // Index-Access bei UnoObjekten beruecksichtigen - // definitely we want this for VBA where properties are often - // collections ( which need index access ), but lets only do + // 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() ) { @@ -455,7 +455,7 @@ SbxVariable* SbiRuntime::CheckArray( SbxVariable* pElem ) { // Falls wir ein Array haben, wollen wir bitte das Array-Element! SbxArray* pPar; - if( pElem->GetType() & SbxARRAY ) + if( ( pElem->GetType() & SbxARRAY ) && (SbxVariable*)refRedim != pElem ) { SbxBase* pElemObj = pElem->GetObject(); SbxDimArray* pDimArray = PTR_CAST(SbxDimArray,pElemObj); @@ -487,7 +487,7 @@ SbxVariable* SbiRuntime::CheckArray( SbxVariable* pElem ) pPar->Put( NULL, 0 ); } // Index-Access bei UnoObjekten beruecksichtigen - else if( pElem->GetType() == SbxOBJECT && !pElem->ISA(SbxMethod) ) + else if( pElem->GetType() == SbxOBJECT && !pElem->ISA(SbxMethod) && ( !bVBAEnabled || ( bVBAEnabled && !pElem->ISA(SbxProperty) ) ) ) { pPar = pElem->GetParameters(); if ( pPar ) @@ -679,7 +679,7 @@ void SbiRuntime::StepPARAM( UINT32 nOp1, UINT32 nOp2 ) p = new SbxVariable(); if( SbiRuntime::isVBAEnabled() && - (t == SbxOBJECT || t == SbxSTRING) ) + (t == SbxOBJECT || t == SbxSTRING) ) { if( t == SbxOBJECT ) p->PutObject( NULL ); @@ -731,6 +731,8 @@ void SbiRuntime::StepPARAM( UINT32 nOp1, UINT32 nOp2 ) SaveRef( q ); *q = *p; p = q; + if ( i ) + refParams->Put( p, i ); } SetupArgs( p, nOp1 ); PushVar( CheckArray( p ) ); @@ -1170,11 +1172,11 @@ void SbiRuntime::StepGLOBAL( UINT32 nOp1, UINT32 nOp2 ) String aName( pImg->GetString( static_cast<short>( nOp1 ) ) ); SbxDataType t = (SbxDataType)(nOp2 & 0xffff); - // Store module scope variables at module scope + // 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() ) + if ( SbiRuntime::isVBAEnabled() ) { pStorage = pMod; pMod->AddVarName( aName ); diff --git a/basic/source/sbx/sbxvalue.cxx b/basic/source/sbx/sbxvalue.cxx index 2200aaa8c8..ebf05b6b73 100644 --- a/basic/source/sbx/sbxvalue.cxx +++ b/basic/source/sbx/sbxvalue.cxx @@ -1,7 +1,7 @@ /************************************************************************* * * 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 @@ -301,7 +301,7 @@ SbxValue& SbxValue::operator=( const SbxValue& r ) { // string -> byte array if( IsFixed() && (aData.eType == SbxOBJECT) - && aData.pObj && ( aData.pObj->GetType() == (SbxARRAY | SbxBYTE) ) + && aData.pObj && ( aData.pObj->GetType() == (SbxARRAY | SbxBYTE) ) && (r.aData.eType == SbxSTRING) ) { ::rtl::OUString aStr = r.GetString(); @@ -1122,7 +1122,7 @@ BOOL SbxValue::Convert( SbxDataType eTo ) BOOL SbxValue::Compute( SbxOperator eOp, const SbxValue& rOp ) { - bool bVBAInterop = SbiRuntime::isVBAEnabled(); + bool bVBAInterop = SbiRuntime::isVBAEnabled(); SbxDataType eThisType = GetType(); SbxDataType eOpType = rOp.GetType(); @@ -1137,8 +1137,8 @@ BOOL SbxValue::Compute( SbxOperator eOp, const SbxValue& rOp ) else if( eThisType == SbxNULL || eOpType == SbxNULL ) SetType( SbxNULL ); // Sonderregel 2: Ist ein Operand Empty, ist das Ergebnis der 2. Operand - else if( eThisType == SbxEMPTY - && !bVBAInterop + else if( eThisType == SbxEMPTY + && !bVBAInterop ) *this = rOp; // 13.2.96: Nicht schon vor Get auf SbxEMPTY pruefen @@ -1146,8 +1146,8 @@ BOOL SbxValue::Compute( SbxOperator eOp, const SbxValue& rOp ) { SbxValues aL, aR; bool bDecimal = false; - if( bVBAInterop && ( ( eThisType == SbxSTRING && eOpType != SbxSTRING ) || - ( eThisType != SbxSTRING && eOpType == SbxSTRING ) ) && + if( bVBAInterop && ( ( eThisType == SbxSTRING && eOpType != SbxSTRING && eOpType != SbxEMPTY ) || + ( eThisType != SbxSTRING && eThisType != SbxEMPTY && eOpType == SbxSTRING ) ) && ( eOp == SbxMUL || eOp == SbxDIV || eOp == SbxPLUS || eOp == SbxMINUS ) ) { goto Lbl_OpIsDouble; @@ -1194,6 +1194,8 @@ BOOL SbxValue::Compute( SbxOperator eOp, const SbxValue& rOp ) aL.eType = aR.eType = GetType(); // else if( GetType() == SbxDouble || GetType() == SbxSingle ) // aL.eType = aR.eType = SbxLONG64; + else if ( bVBAInterop && eOpType == SbxBOOL ) + aL.eType = aR.eType = SbxBOOL; else aL.eType = aR.eType = SbxLONG; } @@ -1280,7 +1282,12 @@ BOOL SbxValue::Compute( SbxOperator eOp, const SbxValue& rOp ) break; case SbxNOT: if( aL.eType != SbxLONG && aL.eType != SbxULONG ) - aL.nLong64 = ~aL.nLong64; + { + if ( aL.eType != SbxBOOL ) + aL.nLong64 = ~aL.nLong64; + else + aL.nLong = ~aL.nLong; + } else aL.nLong = ~aL.nLong; break; @@ -1288,7 +1295,7 @@ BOOL SbxValue::Compute( SbxOperator eOp, const SbxValue& rOp ) } } } - else if( ( GetType() == SbxDECIMAL || rOp.GetType() == SbxDECIMAL ) && + else if( ( GetType() == SbxDECIMAL || rOp.GetType() == SbxDECIMAL ) && ( eOp == SbxMUL || eOp == SbxDIV || eOp == SbxPLUS || eOp == SbxMINUS || eOp == SbxNEG ) ) { aL.eType = aR.eType = SbxDECIMAL; @@ -1300,7 +1307,7 @@ BOOL SbxValue::Compute( SbxOperator eOp, const SbxValue& rOp ) releaseDecimalPtr( aL.pDecimal ); goto Lbl_OpIsEmpty; } - if( Get( aL ) ) + if( Get( aL ) ) { if( aL.pDecimal && aR.pDecimal ) { @@ -1371,7 +1378,7 @@ BOOL SbxValue::Compute( SbxOperator eOp, const SbxValue& rOp ) { SetError( SbxERR_ZERODIV ); } - else + else { // #i20704 Implement directly BigInt b1( aL.nLong64 ); @@ -1397,7 +1404,7 @@ BOOL SbxValue::Compute( SbxOperator eOp, const SbxValue& rOp ) } } else -Lbl_OpIsDouble: +Lbl_OpIsDouble: { // Andere Operatoren aL.eType = aR.eType = SbxDOUBLE; if( rOp.Get( aR ) ) @@ -1456,7 +1463,7 @@ Lbl_OpIsEmpty: BOOL SbxValue::Compare( SbxOperator eOp, const SbxValue& rOp ) const { - bool bVBAInterop = SbiRuntime::isVBAEnabled(); + bool bVBAInterop = SbiRuntime::isVBAEnabled(); BOOL bRes = FALSE; SbxError eOld = GetError(); @@ -1476,12 +1483,12 @@ BOOL SbxValue::Compare( SbxOperator eOp, const SbxValue& rOp ) const // Sonderregel 2: Wenn beide Variant sind und einer ist numerisch, // und der andere ein String, ist num < str else if( !IsFixed() && !rOp.IsFixed() - && ( rOp.GetType() == SbxSTRING && GetType() != SbxSTRING && IsNumeric() ) && !bVBAInterop + && ( rOp.GetType() == SbxSTRING && GetType() != SbxSTRING && IsNumeric() ) && !bVBAInterop ) bRes = BOOL( eOp == SbxLT || eOp == SbxLE || eOp == SbxNE ); else if( !IsFixed() && !rOp.IsFixed() - && ( GetType() == SbxSTRING && rOp.GetType() != SbxSTRING && rOp.IsNumeric() ) -&& !bVBAInterop + && ( GetType() == SbxSTRING && rOp.GetType() != SbxSTRING && rOp.IsNumeric() ) +&& !bVBAInterop ) bRes = BOOL( eOp == SbxGT || eOp == SbxGE || eOp == SbxNE ); else @@ -1813,7 +1820,7 @@ BOOL SbxValue::StoreData( SvStream& r ) const break; case SbxCHAR: { - char c = sal::static_int_cast< char >(aData.nChar); + char c = sal::static_int_cast< char >(aData.nChar); r << c; break; } diff --git a/basic/source/uno/dlgcont.cxx b/basic/source/uno/dlgcont.cxx index aee3d18392..c1772422bc 100644 --- a/basic/source/uno/dlgcont.cxx +++ b/basic/source/uno/dlgcont.cxx @@ -1,7 +1,7 @@ /************************************************************************* * * 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 @@ -258,7 +258,7 @@ void SfxDialogLibraryContainer::storeLibrariesToStorage( const uno::Reference< e Any SAL_CALL SfxDialogLibraryContainer::importLibraryElement ( const Reference < XNameContainer >& /*xLib*/, - const OUString& /*aElementName */, const OUString& aFile, + const OUString& /*aElementName */, const OUString& aFile, const uno::Reference< io::XInputStream >& xElementStream ) { Any aRetAny; @@ -322,7 +322,7 @@ Any SAL_CALL SfxDialogLibraryContainer::importLibraryElement try { // start parsing - xParser->setDocumentHandler( ::xmlscript::importDialogModel( xDialogModel, xContext ) ); + xParser->setDocumentHandler( ::xmlscript::importDialogModel( xDialogModel, xContext, mxOwnerDocument ) ); xParser->parseStream( source ); } catch( Exception& ) @@ -336,7 +336,7 @@ Any SAL_CALL SfxDialogLibraryContainer::importLibraryElement // Create InputStream, TODO: Implement own InputStreamProvider // to avoid creating the DialogModel here! - Reference< XInputStreamProvider > xISP = ::xmlscript::exportDialogModel( xDialogModel, xContext ); + Reference< XInputStreamProvider > xISP = ::xmlscript::exportDialogModel( xDialogModel, xContext, mxOwnerDocument ); aRetAny <<= xISP; return aRetAny; } @@ -484,7 +484,11 @@ void SfxDialogLibraryContainer::onNewRootStorage() } } - +sal_Bool SAL_CALL +SfxDialogLibraryContainer:: HasExecutableCode( const ::rtl::OUString& Library ) throw (uno::RuntimeException) +{ + return sal_False; // dialog library has no executable code +} //============================================================================ // Service diff --git a/basic/source/uno/scriptcont.cxx b/basic/source/uno/scriptcont.cxx index 22d000f5ce..30402ac132 100644 --- a/basic/source/uno/scriptcont.cxx +++ b/basic/source/uno/scriptcont.cxx @@ -64,7 +64,8 @@ #include <xmlscript/xmlmod_imexp.hxx> #include <cppuhelper/factory.hxx> #include <com/sun/star/util/VetoException.hpp> - +#include <com/sun/star/script/XLibraryQueryExecutable.hpp> +#include <cppuhelper/implbase1.hxx> namespace basic { @@ -135,7 +136,6 @@ sal_Bool SfxScriptLibraryContainer::hasLibraryPassword( const String& rLibraryNa return pImplLib->mbPasswordProtected; } - // Ctor for service SfxScriptLibraryContainer::SfxScriptLibraryContainer( void ) :maScriptLanguage( RTL_CONSTASCII_USTRINGPARAM( "StarBasic" ) ) @@ -1163,6 +1163,17 @@ void SfxScriptLibraryContainer::onNewRootStorage() { } +sal_Bool SAL_CALL +SfxScriptLibraryContainer:: HasExecutableCode( const ::rtl::OUString& Library ) throw (uno::RuntimeException) +{ + BasicManager* pBasicMgr = getBasicManager(); + OSL_ENSURE( pBasicMgr, "we need a basicmanager, really we do" ); + if ( pBasicMgr ) + return pBasicMgr->HasExeCode( Library ); // need to change this to take name + // default to it has code if we can't decide + return sal_True; +} + //============================================================================ // Service void createRegistryInfo_SfxScriptLibraryContainer() |