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/source/runtime/methods.cxx | |
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/source/runtime/methods.cxx')
-rw-r--r-- | basic/source/runtime/methods.cxx | 234 |
1 files changed, 195 insertions, 39 deletions
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 ); } |