1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_basic.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <stdlib.h> // getenv 32*cdf0e10cSrcweir #include <vcl/svapp.hxx> 33*cdf0e10cSrcweir #include <vcl/mapmod.hxx> 34*cdf0e10cSrcweir #include <vcl/wrkwin.hxx> 35*cdf0e10cSrcweir #include <vcl/timer.hxx> 36*cdf0e10cSrcweir #include <basic/sbxvar.hxx> 37*cdf0e10cSrcweir #ifndef _SBX_HXX 38*cdf0e10cSrcweir #include <basic/sbx.hxx> 39*cdf0e10cSrcweir #endif 40*cdf0e10cSrcweir #include <svl/zforlist.hxx> 41*cdf0e10cSrcweir #include <tools/fsys.hxx> 42*cdf0e10cSrcweir #include <tools/urlobj.hxx> 43*cdf0e10cSrcweir #include <osl/file.hxx> 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir #ifdef OS2 46*cdf0e10cSrcweir #define INCL_DOS 47*cdf0e10cSrcweir #define INCL_DOSPROCESS 48*cdf0e10cSrcweir #include <svpm.h> 49*cdf0e10cSrcweir #endif 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir #ifndef CLK_TCK 52*cdf0e10cSrcweir #define CLK_TCK CLOCKS_PER_SEC 53*cdf0e10cSrcweir #endif 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir #include <vcl/jobset.hxx> 56*cdf0e10cSrcweir #include <basic/sbobjmod.hxx> 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir #include "sbintern.hxx" 59*cdf0e10cSrcweir #include "runtime.hxx" 60*cdf0e10cSrcweir #include "stdobj.hxx" 61*cdf0e10cSrcweir #include "rtlproto.hxx" 62*cdf0e10cSrcweir #include "dllmgr.hxx" 63*cdf0e10cSrcweir #include <iosys.hxx> 64*cdf0e10cSrcweir #include "sbunoobj.hxx" 65*cdf0e10cSrcweir #include "propacc.hxx" 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx> 71*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 72*cdf0e10cSrcweir #include <com/sun/star/i18n/XCalendar.hpp> 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir using namespace comphelper; 75*cdf0e10cSrcweir using namespace com::sun::star::uno; 76*cdf0e10cSrcweir using namespace com::sun::star::i18n; 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir static Reference< XCalendar > getLocaleCalendar( void ) 80*cdf0e10cSrcweir { 81*cdf0e10cSrcweir static Reference< XCalendar > xCalendar; 82*cdf0e10cSrcweir if( !xCalendar.is() ) 83*cdf0e10cSrcweir { 84*cdf0e10cSrcweir Reference< XMultiServiceFactory > xSMgr = getProcessServiceFactory(); 85*cdf0e10cSrcweir if( xSMgr.is() ) 86*cdf0e10cSrcweir { 87*cdf0e10cSrcweir xCalendar = Reference< XCalendar >( xSMgr->createInstance 88*cdf0e10cSrcweir ( ::rtl::OUString::createFromAscii( "com.sun.star.i18n.LocaleCalendar" ) ), UNO_QUERY ); 89*cdf0e10cSrcweir } 90*cdf0e10cSrcweir } 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir static com::sun::star::lang::Locale aLastLocale; 93*cdf0e10cSrcweir static bool bNeedsInit = true; 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir com::sun::star::lang::Locale aLocale = Application::GetSettings().GetLocale(); 96*cdf0e10cSrcweir bool bNeedsReload = false; 97*cdf0e10cSrcweir if( bNeedsInit ) 98*cdf0e10cSrcweir { 99*cdf0e10cSrcweir bNeedsInit = false; 100*cdf0e10cSrcweir bNeedsReload = true; 101*cdf0e10cSrcweir } 102*cdf0e10cSrcweir else if( aLocale.Language != aLastLocale.Language || 103*cdf0e10cSrcweir aLocale.Country != aLastLocale.Country ) 104*cdf0e10cSrcweir { 105*cdf0e10cSrcweir bNeedsReload = true; 106*cdf0e10cSrcweir } 107*cdf0e10cSrcweir if( bNeedsReload ) 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir aLastLocale = aLocale; 110*cdf0e10cSrcweir xCalendar->loadDefaultCalendar( aLocale ); 111*cdf0e10cSrcweir } 112*cdf0e10cSrcweir return xCalendar; 113*cdf0e10cSrcweir } 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir RTLFUNC(CallByName) 116*cdf0e10cSrcweir { 117*cdf0e10cSrcweir (void)pBasic; 118*cdf0e10cSrcweir (void)bWrite; 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir const sal_Int16 vbGet = 2; 121*cdf0e10cSrcweir const sal_Int16 vbLet = 4; 122*cdf0e10cSrcweir const sal_Int16 vbMethod = 1; 123*cdf0e10cSrcweir const sal_Int16 vbSet = 8; 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir // At least 3 parameter needed plus function itself -> 4 126*cdf0e10cSrcweir sal_uInt16 nParCount = rPar.Count(); 127*cdf0e10cSrcweir if ( nParCount < 4 ) 128*cdf0e10cSrcweir { 129*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 130*cdf0e10cSrcweir return; 131*cdf0e10cSrcweir } 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir // 1. parameter is object 134*cdf0e10cSrcweir SbxBase* pObjVar = (SbxObject*)rPar.Get(1)->GetObject(); 135*cdf0e10cSrcweir SbxObject* pObj = NULL; 136*cdf0e10cSrcweir if( pObjVar ) 137*cdf0e10cSrcweir pObj = PTR_CAST(SbxObject,pObjVar); 138*cdf0e10cSrcweir if( !pObj && pObjVar && pObjVar->ISA(SbxVariable) ) 139*cdf0e10cSrcweir { 140*cdf0e10cSrcweir SbxBase* pObjVarObj = ((SbxVariable*)pObjVar)->GetObject(); 141*cdf0e10cSrcweir pObj = PTR_CAST(SbxObject,pObjVarObj); 142*cdf0e10cSrcweir } 143*cdf0e10cSrcweir if( !pObj ) 144*cdf0e10cSrcweir { 145*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_PARAMETER ); 146*cdf0e10cSrcweir return; 147*cdf0e10cSrcweir } 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir // 2. parameter is ProcedureName 150*cdf0e10cSrcweir String aNameStr = rPar.Get(2)->GetString(); 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir // 3. parameter is CallType 153*cdf0e10cSrcweir sal_Int16 nCallType = rPar.Get(3)->GetInteger(); 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir //SbxObject* pFindObj = NULL; 156*cdf0e10cSrcweir SbxVariable* pFindVar = pObj->Find( aNameStr, SbxCLASS_DONTCARE ); 157*cdf0e10cSrcweir if( pFindVar == NULL ) 158*cdf0e10cSrcweir { 159*cdf0e10cSrcweir StarBASIC::Error( SbERR_PROC_UNDEFINED ); 160*cdf0e10cSrcweir return; 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir switch( nCallType ) 164*cdf0e10cSrcweir { 165*cdf0e10cSrcweir case vbGet: 166*cdf0e10cSrcweir { 167*cdf0e10cSrcweir SbxValues aVals; 168*cdf0e10cSrcweir aVals.eType = SbxVARIANT; 169*cdf0e10cSrcweir pFindVar->Get( aVals ); 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir SbxVariableRef refVar = rPar.Get(0); 172*cdf0e10cSrcweir refVar->Put( aVals ); 173*cdf0e10cSrcweir } 174*cdf0e10cSrcweir break; 175*cdf0e10cSrcweir case vbLet: 176*cdf0e10cSrcweir case vbSet: 177*cdf0e10cSrcweir { 178*cdf0e10cSrcweir if ( nParCount != 5 ) 179*cdf0e10cSrcweir { 180*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 181*cdf0e10cSrcweir return; 182*cdf0e10cSrcweir } 183*cdf0e10cSrcweir SbxVariableRef pValVar = rPar.Get(4); 184*cdf0e10cSrcweir if( nCallType == vbLet ) 185*cdf0e10cSrcweir { 186*cdf0e10cSrcweir SbxValues aVals; 187*cdf0e10cSrcweir aVals.eType = SbxVARIANT; 188*cdf0e10cSrcweir pValVar->Get( aVals ); 189*cdf0e10cSrcweir pFindVar->Put( aVals ); 190*cdf0e10cSrcweir } 191*cdf0e10cSrcweir else 192*cdf0e10cSrcweir { 193*cdf0e10cSrcweir SbxVariableRef rFindVar = pFindVar; 194*cdf0e10cSrcweir SbiInstance* pInst = pINST; 195*cdf0e10cSrcweir SbiRuntime* pRT = pInst ? pInst->pRun : NULL; 196*cdf0e10cSrcweir if( pRT != NULL ) 197*cdf0e10cSrcweir pRT->StepSET_Impl( pValVar, rFindVar, false ); 198*cdf0e10cSrcweir } 199*cdf0e10cSrcweir } 200*cdf0e10cSrcweir break; 201*cdf0e10cSrcweir case vbMethod: 202*cdf0e10cSrcweir { 203*cdf0e10cSrcweir SbMethod* pMeth = PTR_CAST(SbMethod,pFindVar); 204*cdf0e10cSrcweir if( pMeth == NULL ) 205*cdf0e10cSrcweir { 206*cdf0e10cSrcweir StarBASIC::Error( SbERR_PROC_UNDEFINED ); 207*cdf0e10cSrcweir return; 208*cdf0e10cSrcweir } 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir // Setup parameters 211*cdf0e10cSrcweir SbxArrayRef xArray; 212*cdf0e10cSrcweir sal_uInt16 nMethParamCount = nParCount - 4; 213*cdf0e10cSrcweir if( nMethParamCount > 0 ) 214*cdf0e10cSrcweir { 215*cdf0e10cSrcweir xArray = new SbxArray; 216*cdf0e10cSrcweir for( sal_uInt16 i = 0 ; i < nMethParamCount ; i++ ) 217*cdf0e10cSrcweir { 218*cdf0e10cSrcweir SbxVariable* pPar = rPar.Get( i + 4 ); 219*cdf0e10cSrcweir xArray->Put( pPar, i + 1 ); 220*cdf0e10cSrcweir } 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir // Call method 224*cdf0e10cSrcweir SbxVariableRef refVar = rPar.Get(0); 225*cdf0e10cSrcweir if( xArray.Is() ) 226*cdf0e10cSrcweir pMeth->SetParameters( xArray ); 227*cdf0e10cSrcweir pMeth->Call( refVar ); 228*cdf0e10cSrcweir pMeth->SetParameters( NULL ); 229*cdf0e10cSrcweir } 230*cdf0e10cSrcweir break; 231*cdf0e10cSrcweir default: 232*cdf0e10cSrcweir StarBASIC::Error( SbERR_PROC_UNDEFINED ); 233*cdf0e10cSrcweir } 234*cdf0e10cSrcweir } 235*cdf0e10cSrcweir 236*cdf0e10cSrcweir RTLFUNC(CBool) // JSM 237*cdf0e10cSrcweir { 238*cdf0e10cSrcweir (void)pBasic; 239*cdf0e10cSrcweir (void)bWrite; 240*cdf0e10cSrcweir 241*cdf0e10cSrcweir sal_Bool bVal = sal_False; 242*cdf0e10cSrcweir if ( rPar.Count() == 2 ) 243*cdf0e10cSrcweir { 244*cdf0e10cSrcweir SbxVariable *pSbxVariable = rPar.Get(1); 245*cdf0e10cSrcweir bVal = pSbxVariable->GetBool(); 246*cdf0e10cSrcweir } 247*cdf0e10cSrcweir else 248*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 249*cdf0e10cSrcweir 250*cdf0e10cSrcweir rPar.Get(0)->PutBool(bVal); 251*cdf0e10cSrcweir } 252*cdf0e10cSrcweir 253*cdf0e10cSrcweir RTLFUNC(CByte) // JSM 254*cdf0e10cSrcweir { 255*cdf0e10cSrcweir (void)pBasic; 256*cdf0e10cSrcweir (void)bWrite; 257*cdf0e10cSrcweir 258*cdf0e10cSrcweir sal_uInt8 nByte = 0; 259*cdf0e10cSrcweir if ( rPar.Count() == 2 ) 260*cdf0e10cSrcweir { 261*cdf0e10cSrcweir SbxVariable *pSbxVariable = rPar.Get(1); 262*cdf0e10cSrcweir nByte = pSbxVariable->GetByte(); 263*cdf0e10cSrcweir } 264*cdf0e10cSrcweir else 265*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 266*cdf0e10cSrcweir 267*cdf0e10cSrcweir rPar.Get(0)->PutByte(nByte); 268*cdf0e10cSrcweir } 269*cdf0e10cSrcweir 270*cdf0e10cSrcweir RTLFUNC(CCur) // JSM 271*cdf0e10cSrcweir { 272*cdf0e10cSrcweir (void)pBasic; 273*cdf0e10cSrcweir (void)bWrite; 274*cdf0e10cSrcweir 275*cdf0e10cSrcweir SbxINT64 nCur; 276*cdf0e10cSrcweir if ( rPar.Count() == 2 ) 277*cdf0e10cSrcweir { 278*cdf0e10cSrcweir SbxVariable *pSbxVariable = rPar.Get(1); 279*cdf0e10cSrcweir nCur = pSbxVariable->GetCurrency(); 280*cdf0e10cSrcweir } 281*cdf0e10cSrcweir else 282*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 283*cdf0e10cSrcweir 284*cdf0e10cSrcweir rPar.Get(0)->PutCurrency( nCur ); 285*cdf0e10cSrcweir } 286*cdf0e10cSrcweir 287*cdf0e10cSrcweir RTLFUNC(CDec) // JSM 288*cdf0e10cSrcweir { 289*cdf0e10cSrcweir (void)pBasic; 290*cdf0e10cSrcweir (void)bWrite; 291*cdf0e10cSrcweir 292*cdf0e10cSrcweir #ifdef WNT 293*cdf0e10cSrcweir SbxDecimal* pDec = NULL; 294*cdf0e10cSrcweir if ( rPar.Count() == 2 ) 295*cdf0e10cSrcweir { 296*cdf0e10cSrcweir SbxVariable *pSbxVariable = rPar.Get(1); 297*cdf0e10cSrcweir pDec = pSbxVariable->GetDecimal(); 298*cdf0e10cSrcweir } 299*cdf0e10cSrcweir else 300*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 301*cdf0e10cSrcweir 302*cdf0e10cSrcweir rPar.Get(0)->PutDecimal( pDec ); 303*cdf0e10cSrcweir #else 304*cdf0e10cSrcweir rPar.Get(0)->PutEmpty(); 305*cdf0e10cSrcweir StarBASIC::Error(SbERR_NOT_IMPLEMENTED); 306*cdf0e10cSrcweir #endif 307*cdf0e10cSrcweir } 308*cdf0e10cSrcweir 309*cdf0e10cSrcweir RTLFUNC(CDate) // JSM 310*cdf0e10cSrcweir { 311*cdf0e10cSrcweir (void)pBasic; 312*cdf0e10cSrcweir (void)bWrite; 313*cdf0e10cSrcweir 314*cdf0e10cSrcweir double nVal = 0.0; 315*cdf0e10cSrcweir if ( rPar.Count() == 2 ) 316*cdf0e10cSrcweir { 317*cdf0e10cSrcweir SbxVariable *pSbxVariable = rPar.Get(1); 318*cdf0e10cSrcweir nVal = pSbxVariable->GetDate(); 319*cdf0e10cSrcweir } 320*cdf0e10cSrcweir else 321*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 322*cdf0e10cSrcweir 323*cdf0e10cSrcweir rPar.Get(0)->PutDate(nVal); 324*cdf0e10cSrcweir } 325*cdf0e10cSrcweir 326*cdf0e10cSrcweir RTLFUNC(CDbl) // JSM 327*cdf0e10cSrcweir { 328*cdf0e10cSrcweir (void)pBasic; 329*cdf0e10cSrcweir (void)bWrite; 330*cdf0e10cSrcweir 331*cdf0e10cSrcweir double nVal = 0.0; 332*cdf0e10cSrcweir if ( rPar.Count() == 2 ) 333*cdf0e10cSrcweir { 334*cdf0e10cSrcweir SbxVariable *pSbxVariable = rPar.Get(1); 335*cdf0e10cSrcweir if( pSbxVariable->GetType() == SbxSTRING ) 336*cdf0e10cSrcweir { 337*cdf0e10cSrcweir // AB #41690 , String holen 338*cdf0e10cSrcweir String aScanStr = pSbxVariable->GetString(); 339*cdf0e10cSrcweir SbError Error = SbxValue::ScanNumIntnl( aScanStr, nVal ); 340*cdf0e10cSrcweir if( Error != SbxERR_OK ) 341*cdf0e10cSrcweir StarBASIC::Error( Error ); 342*cdf0e10cSrcweir } 343*cdf0e10cSrcweir else 344*cdf0e10cSrcweir { 345*cdf0e10cSrcweir nVal = pSbxVariable->GetDouble(); 346*cdf0e10cSrcweir } 347*cdf0e10cSrcweir } 348*cdf0e10cSrcweir else 349*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 350*cdf0e10cSrcweir 351*cdf0e10cSrcweir rPar.Get(0)->PutDouble(nVal); 352*cdf0e10cSrcweir } 353*cdf0e10cSrcweir 354*cdf0e10cSrcweir RTLFUNC(CInt) // JSM 355*cdf0e10cSrcweir { 356*cdf0e10cSrcweir (void)pBasic; 357*cdf0e10cSrcweir (void)bWrite; 358*cdf0e10cSrcweir 359*cdf0e10cSrcweir sal_Int16 nVal = 0; 360*cdf0e10cSrcweir if ( rPar.Count() == 2 ) 361*cdf0e10cSrcweir { 362*cdf0e10cSrcweir SbxVariable *pSbxVariable = rPar.Get(1); 363*cdf0e10cSrcweir nVal = pSbxVariable->GetInteger(); 364*cdf0e10cSrcweir } 365*cdf0e10cSrcweir else 366*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 367*cdf0e10cSrcweir 368*cdf0e10cSrcweir rPar.Get(0)->PutInteger(nVal); 369*cdf0e10cSrcweir } 370*cdf0e10cSrcweir 371*cdf0e10cSrcweir RTLFUNC(CLng) // JSM 372*cdf0e10cSrcweir { 373*cdf0e10cSrcweir (void)pBasic; 374*cdf0e10cSrcweir (void)bWrite; 375*cdf0e10cSrcweir 376*cdf0e10cSrcweir sal_Int32 nVal = 0; 377*cdf0e10cSrcweir if ( rPar.Count() == 2 ) 378*cdf0e10cSrcweir { 379*cdf0e10cSrcweir SbxVariable *pSbxVariable = rPar.Get(1); 380*cdf0e10cSrcweir nVal = pSbxVariable->GetLong(); 381*cdf0e10cSrcweir } 382*cdf0e10cSrcweir else 383*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 384*cdf0e10cSrcweir 385*cdf0e10cSrcweir rPar.Get(0)->PutLong(nVal); 386*cdf0e10cSrcweir } 387*cdf0e10cSrcweir 388*cdf0e10cSrcweir RTLFUNC(CSng) // JSM 389*cdf0e10cSrcweir { 390*cdf0e10cSrcweir (void)pBasic; 391*cdf0e10cSrcweir (void)bWrite; 392*cdf0e10cSrcweir 393*cdf0e10cSrcweir float nVal = (float)0.0; 394*cdf0e10cSrcweir if ( rPar.Count() == 2 ) 395*cdf0e10cSrcweir { 396*cdf0e10cSrcweir SbxVariable *pSbxVariable = rPar.Get(1); 397*cdf0e10cSrcweir if( pSbxVariable->GetType() == SbxSTRING ) 398*cdf0e10cSrcweir { 399*cdf0e10cSrcweir // AB #41690 , String holen 400*cdf0e10cSrcweir double dVal = 0.0; 401*cdf0e10cSrcweir String aScanStr = pSbxVariable->GetString(); 402*cdf0e10cSrcweir SbError Error = SbxValue::ScanNumIntnl( aScanStr, dVal, /*bSingle=*/sal_True ); 403*cdf0e10cSrcweir if( SbxBase::GetError() == SbxERR_OK && Error != SbxERR_OK ) 404*cdf0e10cSrcweir StarBASIC::Error( Error ); 405*cdf0e10cSrcweir nVal = (float)dVal; 406*cdf0e10cSrcweir } 407*cdf0e10cSrcweir else 408*cdf0e10cSrcweir { 409*cdf0e10cSrcweir nVal = pSbxVariable->GetSingle(); 410*cdf0e10cSrcweir } 411*cdf0e10cSrcweir } 412*cdf0e10cSrcweir else 413*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 414*cdf0e10cSrcweir 415*cdf0e10cSrcweir rPar.Get(0)->PutSingle(nVal); 416*cdf0e10cSrcweir } 417*cdf0e10cSrcweir 418*cdf0e10cSrcweir RTLFUNC(CStr) // JSM 419*cdf0e10cSrcweir { 420*cdf0e10cSrcweir (void)pBasic; 421*cdf0e10cSrcweir (void)bWrite; 422*cdf0e10cSrcweir 423*cdf0e10cSrcweir String aString; 424*cdf0e10cSrcweir if ( rPar.Count() == 2 ) 425*cdf0e10cSrcweir { 426*cdf0e10cSrcweir SbxVariable *pSbxVariable = rPar.Get(1); 427*cdf0e10cSrcweir aString = pSbxVariable->GetString(); 428*cdf0e10cSrcweir } 429*cdf0e10cSrcweir else 430*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 431*cdf0e10cSrcweir 432*cdf0e10cSrcweir rPar.Get(0)->PutString(aString); 433*cdf0e10cSrcweir } 434*cdf0e10cSrcweir 435*cdf0e10cSrcweir RTLFUNC(CVar) // JSM 436*cdf0e10cSrcweir { 437*cdf0e10cSrcweir (void)pBasic; 438*cdf0e10cSrcweir (void)bWrite; 439*cdf0e10cSrcweir 440*cdf0e10cSrcweir SbxValues aVals( SbxVARIANT ); 441*cdf0e10cSrcweir if ( rPar.Count() == 2 ) 442*cdf0e10cSrcweir { 443*cdf0e10cSrcweir SbxVariable *pSbxVariable = rPar.Get(1); 444*cdf0e10cSrcweir pSbxVariable->Get( aVals ); 445*cdf0e10cSrcweir } 446*cdf0e10cSrcweir else 447*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 448*cdf0e10cSrcweir 449*cdf0e10cSrcweir rPar.Get(0)->Put( aVals ); 450*cdf0e10cSrcweir } 451*cdf0e10cSrcweir 452*cdf0e10cSrcweir RTLFUNC(CVErr) 453*cdf0e10cSrcweir { 454*cdf0e10cSrcweir (void)pBasic; 455*cdf0e10cSrcweir (void)bWrite; 456*cdf0e10cSrcweir 457*cdf0e10cSrcweir sal_Int16 nErrCode = 0; 458*cdf0e10cSrcweir if ( rPar.Count() == 2 ) 459*cdf0e10cSrcweir { 460*cdf0e10cSrcweir SbxVariable *pSbxVariable = rPar.Get(1); 461*cdf0e10cSrcweir nErrCode = pSbxVariable->GetInteger(); 462*cdf0e10cSrcweir } 463*cdf0e10cSrcweir else 464*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 465*cdf0e10cSrcweir 466*cdf0e10cSrcweir rPar.Get(0)->PutErr( nErrCode ); 467*cdf0e10cSrcweir } 468*cdf0e10cSrcweir 469*cdf0e10cSrcweir RTLFUNC(Iif) // JSM 470*cdf0e10cSrcweir { 471*cdf0e10cSrcweir (void)pBasic; 472*cdf0e10cSrcweir (void)bWrite; 473*cdf0e10cSrcweir 474*cdf0e10cSrcweir if ( rPar.Count() == 4 ) 475*cdf0e10cSrcweir { 476*cdf0e10cSrcweir if (rPar.Get(1)->GetBool()) 477*cdf0e10cSrcweir *rPar.Get(0) = *rPar.Get(2); 478*cdf0e10cSrcweir else 479*cdf0e10cSrcweir *rPar.Get(0) = *rPar.Get(3); 480*cdf0e10cSrcweir } 481*cdf0e10cSrcweir else 482*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 483*cdf0e10cSrcweir } 484*cdf0e10cSrcweir 485*cdf0e10cSrcweir RTLFUNC(GetSystemType) 486*cdf0e10cSrcweir { 487*cdf0e10cSrcweir (void)pBasic; 488*cdf0e10cSrcweir (void)bWrite; 489*cdf0e10cSrcweir 490*cdf0e10cSrcweir if ( rPar.Count() != 1 ) 491*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 492*cdf0e10cSrcweir else 493*cdf0e10cSrcweir // Removed for SRC595 494*cdf0e10cSrcweir rPar.Get(0)->PutInteger( -1 ); 495*cdf0e10cSrcweir } 496*cdf0e10cSrcweir 497*cdf0e10cSrcweir RTLFUNC(GetGUIType) 498*cdf0e10cSrcweir { 499*cdf0e10cSrcweir (void)pBasic; 500*cdf0e10cSrcweir (void)bWrite; 501*cdf0e10cSrcweir 502*cdf0e10cSrcweir if ( rPar.Count() != 1 ) 503*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 504*cdf0e10cSrcweir else 505*cdf0e10cSrcweir { 506*cdf0e10cSrcweir // 17.7.2000 Make simple solution for testtool / fat office 507*cdf0e10cSrcweir #if defined (WNT) 508*cdf0e10cSrcweir rPar.Get(0)->PutInteger( 1 ); 509*cdf0e10cSrcweir #elif defined OS2 510*cdf0e10cSrcweir rPar.Get(0)->PutInteger( 2 ); 511*cdf0e10cSrcweir #elif defined UNX 512*cdf0e10cSrcweir rPar.Get(0)->PutInteger( 4 ); 513*cdf0e10cSrcweir #else 514*cdf0e10cSrcweir rPar.Get(0)->PutInteger( -1 ); 515*cdf0e10cSrcweir #endif 516*cdf0e10cSrcweir } 517*cdf0e10cSrcweir } 518*cdf0e10cSrcweir 519*cdf0e10cSrcweir RTLFUNC(Red) 520*cdf0e10cSrcweir { 521*cdf0e10cSrcweir (void)pBasic; 522*cdf0e10cSrcweir (void)bWrite; 523*cdf0e10cSrcweir 524*cdf0e10cSrcweir if ( rPar.Count() != 2 ) 525*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 526*cdf0e10cSrcweir else 527*cdf0e10cSrcweir { 528*cdf0e10cSrcweir sal_uIntPtr nRGB = (sal_uIntPtr)rPar.Get(1)->GetLong(); 529*cdf0e10cSrcweir nRGB &= 0x00FF0000; 530*cdf0e10cSrcweir nRGB >>= 16; 531*cdf0e10cSrcweir rPar.Get(0)->PutInteger( (sal_Int16)nRGB ); 532*cdf0e10cSrcweir } 533*cdf0e10cSrcweir } 534*cdf0e10cSrcweir 535*cdf0e10cSrcweir RTLFUNC(Green) 536*cdf0e10cSrcweir { 537*cdf0e10cSrcweir (void)pBasic; 538*cdf0e10cSrcweir (void)bWrite; 539*cdf0e10cSrcweir 540*cdf0e10cSrcweir if ( rPar.Count() != 2 ) 541*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 542*cdf0e10cSrcweir else 543*cdf0e10cSrcweir { 544*cdf0e10cSrcweir sal_uIntPtr nRGB = (sal_uIntPtr)rPar.Get(1)->GetLong(); 545*cdf0e10cSrcweir nRGB &= 0x0000FF00; 546*cdf0e10cSrcweir nRGB >>= 8; 547*cdf0e10cSrcweir rPar.Get(0)->PutInteger( (sal_Int16)nRGB ); 548*cdf0e10cSrcweir } 549*cdf0e10cSrcweir } 550*cdf0e10cSrcweir 551*cdf0e10cSrcweir RTLFUNC(Blue) 552*cdf0e10cSrcweir { 553*cdf0e10cSrcweir (void)pBasic; 554*cdf0e10cSrcweir (void)bWrite; 555*cdf0e10cSrcweir 556*cdf0e10cSrcweir if ( rPar.Count() != 2 ) 557*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 558*cdf0e10cSrcweir else 559*cdf0e10cSrcweir { 560*cdf0e10cSrcweir sal_uIntPtr nRGB = (sal_uIntPtr)rPar.Get(1)->GetLong(); 561*cdf0e10cSrcweir nRGB &= 0x000000FF; 562*cdf0e10cSrcweir rPar.Get(0)->PutInteger( (sal_Int16)nRGB ); 563*cdf0e10cSrcweir } 564*cdf0e10cSrcweir } 565*cdf0e10cSrcweir 566*cdf0e10cSrcweir 567*cdf0e10cSrcweir RTLFUNC(Switch) 568*cdf0e10cSrcweir { 569*cdf0e10cSrcweir (void)pBasic; 570*cdf0e10cSrcweir (void)bWrite; 571*cdf0e10cSrcweir 572*cdf0e10cSrcweir sal_uInt16 nCount = rPar.Count(); 573*cdf0e10cSrcweir if( !(nCount & 0x0001 )) 574*cdf0e10cSrcweir // Anzahl der Argumente muss ungerade sein 575*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 576*cdf0e10cSrcweir sal_uInt16 nCurExpr = 1; 577*cdf0e10cSrcweir while( nCurExpr < (nCount-1) ) 578*cdf0e10cSrcweir { 579*cdf0e10cSrcweir if( rPar.Get( nCurExpr )->GetBool()) 580*cdf0e10cSrcweir { 581*cdf0e10cSrcweir (*rPar.Get(0)) = *(rPar.Get(nCurExpr+1)); 582*cdf0e10cSrcweir return; 583*cdf0e10cSrcweir } 584*cdf0e10cSrcweir nCurExpr += 2; 585*cdf0e10cSrcweir } 586*cdf0e10cSrcweir rPar.Get(0)->PutNull(); 587*cdf0e10cSrcweir } 588*cdf0e10cSrcweir 589*cdf0e10cSrcweir //i#64882# Common wait impl for existing Wait and new WaitUntil 590*cdf0e10cSrcweir // rtl functions 591*cdf0e10cSrcweir void Wait_Impl( bool bDurationBased, SbxArray& rPar ) 592*cdf0e10cSrcweir { 593*cdf0e10cSrcweir if( rPar.Count() != 2 ) 594*cdf0e10cSrcweir { 595*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 596*cdf0e10cSrcweir return; 597*cdf0e10cSrcweir } 598*cdf0e10cSrcweir long nWait = 0; 599*cdf0e10cSrcweir if ( bDurationBased ) 600*cdf0e10cSrcweir { 601*cdf0e10cSrcweir double dWait = rPar.Get(1)->GetDouble(); 602*cdf0e10cSrcweir double dNow = Now_Impl(); 603*cdf0e10cSrcweir double dSecs = (double)( ( dWait - dNow ) * (double)( 24.0*3600.0) ); 604*cdf0e10cSrcweir nWait = (long)( dSecs * 1000 ); // wait in thousands of sec 605*cdf0e10cSrcweir } 606*cdf0e10cSrcweir else 607*cdf0e10cSrcweir nWait = rPar.Get(1)->GetLong(); 608*cdf0e10cSrcweir if( nWait < 0 ) 609*cdf0e10cSrcweir { 610*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 611*cdf0e10cSrcweir return; 612*cdf0e10cSrcweir } 613*cdf0e10cSrcweir 614*cdf0e10cSrcweir Timer aTimer; 615*cdf0e10cSrcweir aTimer.SetTimeout( nWait ); 616*cdf0e10cSrcweir aTimer.Start(); 617*cdf0e10cSrcweir while ( aTimer.IsActive() ) 618*cdf0e10cSrcweir Application::Yield(); 619*cdf0e10cSrcweir } 620*cdf0e10cSrcweir 621*cdf0e10cSrcweir //i#64882# 622*cdf0e10cSrcweir RTLFUNC(Wait) 623*cdf0e10cSrcweir { 624*cdf0e10cSrcweir (void)pBasic; 625*cdf0e10cSrcweir (void)bWrite; 626*cdf0e10cSrcweir Wait_Impl( false, rPar ); 627*cdf0e10cSrcweir } 628*cdf0e10cSrcweir 629*cdf0e10cSrcweir //i#64882# add new WaitUntil ( for application.wait ) 630*cdf0e10cSrcweir // share wait_impl with 'normal' oobasic wait 631*cdf0e10cSrcweir RTLFUNC(WaitUntil) 632*cdf0e10cSrcweir { 633*cdf0e10cSrcweir (void)pBasic; 634*cdf0e10cSrcweir (void)bWrite; 635*cdf0e10cSrcweir Wait_Impl( true, rPar ); 636*cdf0e10cSrcweir } 637*cdf0e10cSrcweir 638*cdf0e10cSrcweir RTLFUNC(DoEvents) 639*cdf0e10cSrcweir { 640*cdf0e10cSrcweir (void)pBasic; 641*cdf0e10cSrcweir (void)bWrite; 642*cdf0e10cSrcweir (void)rPar; 643*cdf0e10cSrcweir // Dummy implementation as the following code leads 644*cdf0e10cSrcweir // to performance problems for unknown reasons 645*cdf0e10cSrcweir //Timer aTimer; 646*cdf0e10cSrcweir //aTimer.SetTimeout( 1 ); 647*cdf0e10cSrcweir //aTimer.Start(); 648*cdf0e10cSrcweir //while ( aTimer.IsActive() ) 649*cdf0e10cSrcweir // Application::Reschedule(); 650*cdf0e10cSrcweir Application::Reschedule( true ); 651*cdf0e10cSrcweir } 652*cdf0e10cSrcweir 653*cdf0e10cSrcweir RTLFUNC(GetGUIVersion) 654*cdf0e10cSrcweir { 655*cdf0e10cSrcweir (void)pBasic; 656*cdf0e10cSrcweir (void)bWrite; 657*cdf0e10cSrcweir 658*cdf0e10cSrcweir if ( rPar.Count() != 1 ) 659*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 660*cdf0e10cSrcweir else 661*cdf0e10cSrcweir { 662*cdf0e10cSrcweir // Removed for SRC595 663*cdf0e10cSrcweir rPar.Get(0)->PutLong( -1 ); 664*cdf0e10cSrcweir } 665*cdf0e10cSrcweir } 666*cdf0e10cSrcweir 667*cdf0e10cSrcweir RTLFUNC(Choose) 668*cdf0e10cSrcweir { 669*cdf0e10cSrcweir (void)pBasic; 670*cdf0e10cSrcweir (void)bWrite; 671*cdf0e10cSrcweir 672*cdf0e10cSrcweir if ( rPar.Count() < 2 ) 673*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 674*cdf0e10cSrcweir sal_Int16 nIndex = rPar.Get(1)->GetInteger(); 675*cdf0e10cSrcweir sal_uInt16 nCount = rPar.Count(); 676*cdf0e10cSrcweir nCount--; 677*cdf0e10cSrcweir if( nCount == 1 || nIndex > (nCount-1) || nIndex < 1 ) 678*cdf0e10cSrcweir { 679*cdf0e10cSrcweir rPar.Get(0)->PutNull(); 680*cdf0e10cSrcweir return; 681*cdf0e10cSrcweir } 682*cdf0e10cSrcweir (*rPar.Get(0)) = *(rPar.Get(nIndex+1)); 683*cdf0e10cSrcweir } 684*cdf0e10cSrcweir 685*cdf0e10cSrcweir 686*cdf0e10cSrcweir RTLFUNC(Trim) 687*cdf0e10cSrcweir { 688*cdf0e10cSrcweir (void)pBasic; 689*cdf0e10cSrcweir (void)bWrite; 690*cdf0e10cSrcweir 691*cdf0e10cSrcweir if ( rPar.Count() < 2 ) 692*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 693*cdf0e10cSrcweir else 694*cdf0e10cSrcweir { 695*cdf0e10cSrcweir String aStr( rPar.Get(1)->GetString() ); 696*cdf0e10cSrcweir aStr.EraseLeadingChars(); 697*cdf0e10cSrcweir aStr.EraseTrailingChars(); 698*cdf0e10cSrcweir rPar.Get(0)->PutString( aStr ); 699*cdf0e10cSrcweir } 700*cdf0e10cSrcweir } 701*cdf0e10cSrcweir 702*cdf0e10cSrcweir RTLFUNC(GetSolarVersion) 703*cdf0e10cSrcweir { 704*cdf0e10cSrcweir (void)pBasic; 705*cdf0e10cSrcweir (void)bWrite; 706*cdf0e10cSrcweir 707*cdf0e10cSrcweir rPar.Get(0)->PutLong( (sal_Int32)SUPD ); 708*cdf0e10cSrcweir } 709*cdf0e10cSrcweir 710*cdf0e10cSrcweir RTLFUNC(TwipsPerPixelX) 711*cdf0e10cSrcweir { 712*cdf0e10cSrcweir (void)pBasic; 713*cdf0e10cSrcweir (void)bWrite; 714*cdf0e10cSrcweir 715*cdf0e10cSrcweir sal_Int32 nResult = 0; 716*cdf0e10cSrcweir Size aSize( 100,0 ); 717*cdf0e10cSrcweir MapMode aMap( MAP_TWIP ); 718*cdf0e10cSrcweir OutputDevice* pDevice = Application::GetDefaultDevice(); 719*cdf0e10cSrcweir if( pDevice ) 720*cdf0e10cSrcweir { 721*cdf0e10cSrcweir aSize = pDevice->PixelToLogic( aSize, aMap ); 722*cdf0e10cSrcweir nResult = aSize.Width() / 100; 723*cdf0e10cSrcweir } 724*cdf0e10cSrcweir rPar.Get(0)->PutLong( nResult ); 725*cdf0e10cSrcweir } 726*cdf0e10cSrcweir 727*cdf0e10cSrcweir RTLFUNC(TwipsPerPixelY) 728*cdf0e10cSrcweir { 729*cdf0e10cSrcweir (void)pBasic; 730*cdf0e10cSrcweir (void)bWrite; 731*cdf0e10cSrcweir 732*cdf0e10cSrcweir sal_Int32 nResult = 0; 733*cdf0e10cSrcweir Size aSize( 0,100 ); 734*cdf0e10cSrcweir MapMode aMap( MAP_TWIP ); 735*cdf0e10cSrcweir OutputDevice* pDevice = Application::GetDefaultDevice(); 736*cdf0e10cSrcweir if( pDevice ) 737*cdf0e10cSrcweir { 738*cdf0e10cSrcweir aSize = pDevice->PixelToLogic( aSize, aMap ); 739*cdf0e10cSrcweir nResult = aSize.Height() / 100; 740*cdf0e10cSrcweir } 741*cdf0e10cSrcweir rPar.Get(0)->PutLong( nResult ); 742*cdf0e10cSrcweir } 743*cdf0e10cSrcweir 744*cdf0e10cSrcweir 745*cdf0e10cSrcweir RTLFUNC(FreeLibrary) 746*cdf0e10cSrcweir { 747*cdf0e10cSrcweir (void)pBasic; 748*cdf0e10cSrcweir (void)bWrite; 749*cdf0e10cSrcweir 750*cdf0e10cSrcweir if ( rPar.Count() != 2 ) 751*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 752*cdf0e10cSrcweir pINST->GetDllMgr()->FreeDll( rPar.Get(1)->GetString() ); 753*cdf0e10cSrcweir } 754*cdf0e10cSrcweir bool IsBaseIndexOne() 755*cdf0e10cSrcweir { 756*cdf0e10cSrcweir bool result = false; 757*cdf0e10cSrcweir if ( pINST && pINST->pRun ) 758*cdf0e10cSrcweir { 759*cdf0e10cSrcweir sal_uInt16 res = pINST->pRun->GetBase(); 760*cdf0e10cSrcweir if ( res ) 761*cdf0e10cSrcweir result = true; 762*cdf0e10cSrcweir } 763*cdf0e10cSrcweir return result; 764*cdf0e10cSrcweir } 765*cdf0e10cSrcweir 766*cdf0e10cSrcweir RTLFUNC(Array) 767*cdf0e10cSrcweir { 768*cdf0e10cSrcweir (void)pBasic; 769*cdf0e10cSrcweir (void)bWrite; 770*cdf0e10cSrcweir 771*cdf0e10cSrcweir SbxDimArray* pArray = new SbxDimArray( SbxVARIANT ); 772*cdf0e10cSrcweir sal_uInt16 nArraySize = rPar.Count() - 1; 773*cdf0e10cSrcweir 774*cdf0e10cSrcweir // Option Base zunaechst ignorieren (kennt leider nur der Compiler) 775*cdf0e10cSrcweir bool bIncIndex = (IsBaseIndexOne() && SbiRuntime::isVBAEnabled() ); 776*cdf0e10cSrcweir if( nArraySize ) 777*cdf0e10cSrcweir { 778*cdf0e10cSrcweir if ( bIncIndex ) 779*cdf0e10cSrcweir pArray->AddDim( 1, nArraySize ); 780*cdf0e10cSrcweir else 781*cdf0e10cSrcweir pArray->AddDim( 0, nArraySize-1 ); 782*cdf0e10cSrcweir } 783*cdf0e10cSrcweir else 784*cdf0e10cSrcweir { 785*cdf0e10cSrcweir pArray->unoAddDim( 0, -1 ); 786*cdf0e10cSrcweir } 787*cdf0e10cSrcweir 788*cdf0e10cSrcweir // Parameter ins Array uebernehmen 789*cdf0e10cSrcweir // ATTENTION: Using type sal_uInt16 for loop variable is 790*cdf0e10cSrcweir // mandatory to workaround a problem with the 791*cdf0e10cSrcweir // Solaris Intel compiler optimizer! See i104354 792*cdf0e10cSrcweir for( sal_uInt16 i = 0 ; i < nArraySize ; i++ ) 793*cdf0e10cSrcweir { 794*cdf0e10cSrcweir SbxVariable* pVar = rPar.Get(i+1); 795*cdf0e10cSrcweir SbxVariable* pNew = new SbxVariable( *pVar ); 796*cdf0e10cSrcweir pNew->SetFlag( SBX_WRITE ); 797*cdf0e10cSrcweir short index = static_cast< short >(i); 798*cdf0e10cSrcweir if ( bIncIndex ) 799*cdf0e10cSrcweir ++index; 800*cdf0e10cSrcweir pArray->Put( pNew, &index ); 801*cdf0e10cSrcweir } 802*cdf0e10cSrcweir 803*cdf0e10cSrcweir // Array zurueckliefern 804*cdf0e10cSrcweir SbxVariableRef refVar = rPar.Get(0); 805*cdf0e10cSrcweir sal_uInt16 nFlags = refVar->GetFlags(); 806*cdf0e10cSrcweir refVar->ResetFlag( SBX_FIXED ); 807*cdf0e10cSrcweir refVar->PutObject( pArray ); 808*cdf0e10cSrcweir refVar->SetFlags( nFlags ); 809*cdf0e10cSrcweir refVar->SetParameters( NULL ); 810*cdf0e10cSrcweir } 811*cdf0e10cSrcweir 812*cdf0e10cSrcweir 813*cdf0e10cSrcweir // Featurewunsch #57868 814*cdf0e10cSrcweir // Die Funktion liefert ein Variant-Array, wenn keine Parameter angegeben 815*cdf0e10cSrcweir // werden, wird ein leeres Array erzeugt (entsprechend dim a(), entspricht 816*cdf0e10cSrcweir // einer Sequence der Laenge 0 in Uno). 817*cdf0e10cSrcweir // Wenn Parameter angegeben sind, wird fuer jeden eine Dimension erzeugt 818*cdf0e10cSrcweir // DimArray( 2, 2, 4 ) entspricht DIM a( 2, 2, 4 ) 819*cdf0e10cSrcweir // Das Array ist immer vom Typ Variant 820*cdf0e10cSrcweir RTLFUNC(DimArray) 821*cdf0e10cSrcweir { 822*cdf0e10cSrcweir (void)pBasic; 823*cdf0e10cSrcweir (void)bWrite; 824*cdf0e10cSrcweir 825*cdf0e10cSrcweir SbxDimArray * pArray = new SbxDimArray( SbxVARIANT ); 826*cdf0e10cSrcweir sal_uInt16 nArrayDims = rPar.Count() - 1; 827*cdf0e10cSrcweir if( nArrayDims > 0 ) 828*cdf0e10cSrcweir { 829*cdf0e10cSrcweir for( sal_uInt16 i = 0; i < nArrayDims ; i++ ) 830*cdf0e10cSrcweir { 831*cdf0e10cSrcweir sal_Int32 ub = rPar.Get(i+1)->GetLong(); 832*cdf0e10cSrcweir if( ub < 0 ) 833*cdf0e10cSrcweir { 834*cdf0e10cSrcweir StarBASIC::Error( SbERR_OUT_OF_RANGE ); 835*cdf0e10cSrcweir ub = 0; 836*cdf0e10cSrcweir } 837*cdf0e10cSrcweir pArray->AddDim32( 0, ub ); 838*cdf0e10cSrcweir } 839*cdf0e10cSrcweir } 840*cdf0e10cSrcweir else 841*cdf0e10cSrcweir pArray->unoAddDim( 0, -1 ); 842*cdf0e10cSrcweir 843*cdf0e10cSrcweir // Array zurueckliefern 844*cdf0e10cSrcweir SbxVariableRef refVar = rPar.Get(0); 845*cdf0e10cSrcweir sal_uInt16 nFlags = refVar->GetFlags(); 846*cdf0e10cSrcweir refVar->ResetFlag( SBX_FIXED ); 847*cdf0e10cSrcweir refVar->PutObject( pArray ); 848*cdf0e10cSrcweir refVar->SetFlags( nFlags ); 849*cdf0e10cSrcweir refVar->SetParameters( NULL ); 850*cdf0e10cSrcweir } 851*cdf0e10cSrcweir 852*cdf0e10cSrcweir /* 853*cdf0e10cSrcweir * FindObject und FindPropertyObject ermoeglichen es, 854*cdf0e10cSrcweir * Objekte und Properties vom Typ Objekt zur Laufzeit 855*cdf0e10cSrcweir * ueber ihren Namen als String-Parameter anzusprechen. 856*cdf0e10cSrcweir * 857*cdf0e10cSrcweir * Bsp.: 858*cdf0e10cSrcweir * MyObj.Prop1.Bla = 5 859*cdf0e10cSrcweir * 860*cdf0e10cSrcweir * entspricht: 861*cdf0e10cSrcweir * dim ObjVar as Object 862*cdf0e10cSrcweir * dim ObjProp as Object 863*cdf0e10cSrcweir * ObjName$ = "MyObj" 864*cdf0e10cSrcweir * ObjVar = FindObject( ObjName$ ) 865*cdf0e10cSrcweir * PropName$ = "Prop1" 866*cdf0e10cSrcweir * ObjProp = FindPropertyObject( ObjVar, PropName$ ) 867*cdf0e10cSrcweir * ObjProp.Bla = 5 868*cdf0e10cSrcweir * 869*cdf0e10cSrcweir * Dabei koennen die Namen zur Laufzeit dynamisch 870*cdf0e10cSrcweir * erzeugt werden und, so dass z.B. ueber Controls 871*cdf0e10cSrcweir * "TextEdit1" bis "TextEdit5" in einem Dialog in 872*cdf0e10cSrcweir * einer Schleife iteriert werden kann. 873*cdf0e10cSrcweir */ 874*cdf0e10cSrcweir 875*cdf0e10cSrcweir // Objekt ueber den Namen ansprechen 876*cdf0e10cSrcweir // 1. Parameter = Name des Objekts als String 877*cdf0e10cSrcweir RTLFUNC(FindObject) 878*cdf0e10cSrcweir { 879*cdf0e10cSrcweir (void)pBasic; 880*cdf0e10cSrcweir (void)bWrite; 881*cdf0e10cSrcweir 882*cdf0e10cSrcweir // Wir brauchen einen Parameter 883*cdf0e10cSrcweir if ( rPar.Count() < 2 ) 884*cdf0e10cSrcweir { 885*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 886*cdf0e10cSrcweir return; 887*cdf0e10cSrcweir } 888*cdf0e10cSrcweir 889*cdf0e10cSrcweir // 1. Parameter ist der Name 890*cdf0e10cSrcweir String aNameStr = rPar.Get(1)->GetString(); 891*cdf0e10cSrcweir 892*cdf0e10cSrcweir // Basic-Suchfunktion benutzen 893*cdf0e10cSrcweir SbxBase* pFind = StarBASIC::FindSBXInCurrentScope( aNameStr ); 894*cdf0e10cSrcweir SbxObject* pFindObj = NULL; 895*cdf0e10cSrcweir if( pFind ) 896*cdf0e10cSrcweir pFindObj = PTR_CAST(SbxObject,pFind); 897*cdf0e10cSrcweir /* 898*cdf0e10cSrcweir if( !pFindObj ) 899*cdf0e10cSrcweir { 900*cdf0e10cSrcweir StarBASIC::Error( SbERR_VAR_UNDEFINED ); 901*cdf0e10cSrcweir return; 902*cdf0e10cSrcweir } 903*cdf0e10cSrcweir */ 904*cdf0e10cSrcweir 905*cdf0e10cSrcweir // Objekt zurueckliefern 906*cdf0e10cSrcweir SbxVariableRef refVar = rPar.Get(0); 907*cdf0e10cSrcweir refVar->PutObject( pFindObj ); 908*cdf0e10cSrcweir } 909*cdf0e10cSrcweir 910*cdf0e10cSrcweir // Objekt-Property in einem Objekt ansprechen 911*cdf0e10cSrcweir // 1. Parameter = Objekt 912*cdf0e10cSrcweir // 2. Parameter = Name der Property als String 913*cdf0e10cSrcweir RTLFUNC(FindPropertyObject) 914*cdf0e10cSrcweir { 915*cdf0e10cSrcweir (void)pBasic; 916*cdf0e10cSrcweir (void)bWrite; 917*cdf0e10cSrcweir 918*cdf0e10cSrcweir // Wir brauchen 2 Parameter 919*cdf0e10cSrcweir if ( rPar.Count() < 3 ) 920*cdf0e10cSrcweir { 921*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 922*cdf0e10cSrcweir return; 923*cdf0e10cSrcweir } 924*cdf0e10cSrcweir 925*cdf0e10cSrcweir // 1. Parameter holen, muss Objekt sein 926*cdf0e10cSrcweir SbxBase* pObjVar = (SbxObject*)rPar.Get(1)->GetObject(); 927*cdf0e10cSrcweir SbxObject* pObj = NULL; 928*cdf0e10cSrcweir if( pObjVar ) 929*cdf0e10cSrcweir pObj = PTR_CAST(SbxObject,pObjVar); 930*cdf0e10cSrcweir if( !pObj && pObjVar && pObjVar->ISA(SbxVariable) ) 931*cdf0e10cSrcweir { 932*cdf0e10cSrcweir SbxBase* pObjVarObj = ((SbxVariable*)pObjVar)->GetObject(); 933*cdf0e10cSrcweir pObj = PTR_CAST(SbxObject,pObjVarObj); 934*cdf0e10cSrcweir } 935*cdf0e10cSrcweir /* 936*cdf0e10cSrcweir if( !pObj ) 937*cdf0e10cSrcweir { 938*cdf0e10cSrcweir StarBASIC::Error( SbERR_VAR_UNDEFINED ); 939*cdf0e10cSrcweir return; 940*cdf0e10cSrcweir } 941*cdf0e10cSrcweir */ 942*cdf0e10cSrcweir 943*cdf0e10cSrcweir // 2. Parameter ist der Name 944*cdf0e10cSrcweir String aNameStr = rPar.Get(2)->GetString(); 945*cdf0e10cSrcweir 946*cdf0e10cSrcweir // Jetzt muss ein Objekt da sein, sonst Error 947*cdf0e10cSrcweir SbxObject* pFindObj = NULL; 948*cdf0e10cSrcweir if( pObj ) 949*cdf0e10cSrcweir { 950*cdf0e10cSrcweir // Im Objekt nach Objekt suchen 951*cdf0e10cSrcweir SbxVariable* pFindVar = pObj->Find( aNameStr, SbxCLASS_OBJECT ); 952*cdf0e10cSrcweir pFindObj = PTR_CAST(SbxObject,pFindVar); 953*cdf0e10cSrcweir } 954*cdf0e10cSrcweir else 955*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_PARAMETER ); 956*cdf0e10cSrcweir 957*cdf0e10cSrcweir // Objekt zurueckliefern 958*cdf0e10cSrcweir SbxVariableRef refVar = rPar.Get(0); 959*cdf0e10cSrcweir refVar->PutObject( pFindObj ); 960*cdf0e10cSrcweir } 961*cdf0e10cSrcweir 962*cdf0e10cSrcweir 963*cdf0e10cSrcweir 964*cdf0e10cSrcweir sal_Bool lcl_WriteSbxVariable( const SbxVariable& rVar, SvStream* pStrm, 965*cdf0e10cSrcweir sal_Bool bBinary, short nBlockLen, sal_Bool bIsArray ) 966*cdf0e10cSrcweir { 967*cdf0e10cSrcweir sal_uIntPtr nFPos = pStrm->Tell(); 968*cdf0e10cSrcweir 969*cdf0e10cSrcweir sal_Bool bIsVariant = !rVar.IsFixed(); 970*cdf0e10cSrcweir SbxDataType eType = rVar.GetType(); 971*cdf0e10cSrcweir 972*cdf0e10cSrcweir switch( eType ) 973*cdf0e10cSrcweir { 974*cdf0e10cSrcweir case SbxBOOL: 975*cdf0e10cSrcweir case SbxCHAR: 976*cdf0e10cSrcweir case SbxBYTE: 977*cdf0e10cSrcweir if( bIsVariant ) 978*cdf0e10cSrcweir *pStrm << (sal_uInt16)SbxBYTE; // VarType Id 979*cdf0e10cSrcweir *pStrm << rVar.GetByte(); 980*cdf0e10cSrcweir break; 981*cdf0e10cSrcweir 982*cdf0e10cSrcweir case SbxEMPTY: 983*cdf0e10cSrcweir case SbxNULL: 984*cdf0e10cSrcweir case SbxVOID: 985*cdf0e10cSrcweir case SbxINTEGER: 986*cdf0e10cSrcweir case SbxUSHORT: 987*cdf0e10cSrcweir case SbxINT: 988*cdf0e10cSrcweir case SbxUINT: 989*cdf0e10cSrcweir if( bIsVariant ) 990*cdf0e10cSrcweir *pStrm << (sal_uInt16)SbxINTEGER; // VarType Id 991*cdf0e10cSrcweir *pStrm << rVar.GetInteger(); 992*cdf0e10cSrcweir break; 993*cdf0e10cSrcweir 994*cdf0e10cSrcweir case SbxLONG: 995*cdf0e10cSrcweir case SbxULONG: 996*cdf0e10cSrcweir case SbxLONG64: 997*cdf0e10cSrcweir case SbxULONG64: 998*cdf0e10cSrcweir if( bIsVariant ) 999*cdf0e10cSrcweir *pStrm << (sal_uInt16)SbxLONG; // VarType Id 1000*cdf0e10cSrcweir *pStrm << rVar.GetLong(); 1001*cdf0e10cSrcweir break; 1002*cdf0e10cSrcweir 1003*cdf0e10cSrcweir case SbxSINGLE: 1004*cdf0e10cSrcweir if( bIsVariant ) 1005*cdf0e10cSrcweir *pStrm << (sal_uInt16)eType; // VarType Id 1006*cdf0e10cSrcweir *pStrm << rVar.GetSingle(); 1007*cdf0e10cSrcweir break; 1008*cdf0e10cSrcweir 1009*cdf0e10cSrcweir case SbxDOUBLE: 1010*cdf0e10cSrcweir case SbxCURRENCY: 1011*cdf0e10cSrcweir case SbxDATE: 1012*cdf0e10cSrcweir if( bIsVariant ) 1013*cdf0e10cSrcweir *pStrm << (sal_uInt16)eType; // VarType Id 1014*cdf0e10cSrcweir *pStrm << rVar.GetDouble(); 1015*cdf0e10cSrcweir break; 1016*cdf0e10cSrcweir 1017*cdf0e10cSrcweir case SbxSTRING: 1018*cdf0e10cSrcweir case SbxLPSTR: 1019*cdf0e10cSrcweir { 1020*cdf0e10cSrcweir const String& rStr = rVar.GetString(); 1021*cdf0e10cSrcweir if( !bBinary || bIsArray ) 1022*cdf0e10cSrcweir { 1023*cdf0e10cSrcweir if( bIsVariant ) 1024*cdf0e10cSrcweir *pStrm << (sal_uInt16)SbxSTRING; 1025*cdf0e10cSrcweir pStrm->WriteByteString( rStr, gsl_getSystemTextEncoding() ); 1026*cdf0e10cSrcweir //*pStrm << rStr; 1027*cdf0e10cSrcweir } 1028*cdf0e10cSrcweir else 1029*cdf0e10cSrcweir { 1030*cdf0e10cSrcweir // ohne Laengenangabe! ohne Endekennung! 1031*cdf0e10cSrcweir // What does that mean for Unicode?! Choosing conversion to ByteString... 1032*cdf0e10cSrcweir ByteString aByteStr( rStr, gsl_getSystemTextEncoding() ); 1033*cdf0e10cSrcweir *pStrm << (const char*)aByteStr.GetBuffer(); 1034*cdf0e10cSrcweir //*pStrm << (const char*)rStr.GetStr(); 1035*cdf0e10cSrcweir } 1036*cdf0e10cSrcweir } 1037*cdf0e10cSrcweir break; 1038*cdf0e10cSrcweir 1039*cdf0e10cSrcweir default: 1040*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1041*cdf0e10cSrcweir return sal_False; 1042*cdf0e10cSrcweir } 1043*cdf0e10cSrcweir 1044*cdf0e10cSrcweir if( nBlockLen ) 1045*cdf0e10cSrcweir pStrm->Seek( nFPos + nBlockLen ); 1046*cdf0e10cSrcweir return pStrm->GetErrorCode() ? sal_False : sal_True; 1047*cdf0e10cSrcweir } 1048*cdf0e10cSrcweir 1049*cdf0e10cSrcweir sal_Bool lcl_ReadSbxVariable( SbxVariable& rVar, SvStream* pStrm, 1050*cdf0e10cSrcweir sal_Bool bBinary, short nBlockLen, sal_Bool bIsArray ) 1051*cdf0e10cSrcweir { 1052*cdf0e10cSrcweir (void)bBinary; 1053*cdf0e10cSrcweir (void)bIsArray; 1054*cdf0e10cSrcweir 1055*cdf0e10cSrcweir double aDouble; 1056*cdf0e10cSrcweir 1057*cdf0e10cSrcweir sal_uIntPtr nFPos = pStrm->Tell(); 1058*cdf0e10cSrcweir 1059*cdf0e10cSrcweir sal_Bool bIsVariant = !rVar.IsFixed(); 1060*cdf0e10cSrcweir SbxDataType eVarType = rVar.GetType(); 1061*cdf0e10cSrcweir 1062*cdf0e10cSrcweir SbxDataType eSrcType = eVarType; 1063*cdf0e10cSrcweir if( bIsVariant ) 1064*cdf0e10cSrcweir { 1065*cdf0e10cSrcweir sal_uInt16 nTemp; 1066*cdf0e10cSrcweir *pStrm >> nTemp; 1067*cdf0e10cSrcweir eSrcType = (SbxDataType)nTemp; 1068*cdf0e10cSrcweir } 1069*cdf0e10cSrcweir 1070*cdf0e10cSrcweir switch( eSrcType ) 1071*cdf0e10cSrcweir { 1072*cdf0e10cSrcweir case SbxBOOL: 1073*cdf0e10cSrcweir case SbxCHAR: 1074*cdf0e10cSrcweir case SbxBYTE: 1075*cdf0e10cSrcweir { 1076*cdf0e10cSrcweir sal_uInt8 aByte; 1077*cdf0e10cSrcweir *pStrm >> aByte; 1078*cdf0e10cSrcweir 1079*cdf0e10cSrcweir if( bBinary && SbiRuntime::isVBAEnabled() && aByte == 1 && pStrm->IsEof() ) 1080*cdf0e10cSrcweir aByte = 0; 1081*cdf0e10cSrcweir 1082*cdf0e10cSrcweir rVar.PutByte( aByte ); 1083*cdf0e10cSrcweir } 1084*cdf0e10cSrcweir break; 1085*cdf0e10cSrcweir 1086*cdf0e10cSrcweir case SbxEMPTY: 1087*cdf0e10cSrcweir case SbxNULL: 1088*cdf0e10cSrcweir case SbxVOID: 1089*cdf0e10cSrcweir case SbxINTEGER: 1090*cdf0e10cSrcweir case SbxUSHORT: 1091*cdf0e10cSrcweir case SbxINT: 1092*cdf0e10cSrcweir case SbxUINT: 1093*cdf0e10cSrcweir { 1094*cdf0e10cSrcweir sal_Int16 aInt; 1095*cdf0e10cSrcweir *pStrm >> aInt; 1096*cdf0e10cSrcweir rVar.PutInteger( aInt ); 1097*cdf0e10cSrcweir } 1098*cdf0e10cSrcweir break; 1099*cdf0e10cSrcweir 1100*cdf0e10cSrcweir case SbxLONG: 1101*cdf0e10cSrcweir case SbxULONG: 1102*cdf0e10cSrcweir case SbxLONG64: 1103*cdf0e10cSrcweir case SbxULONG64: 1104*cdf0e10cSrcweir { 1105*cdf0e10cSrcweir sal_Int32 aInt; 1106*cdf0e10cSrcweir *pStrm >> aInt; 1107*cdf0e10cSrcweir rVar.PutLong( aInt ); 1108*cdf0e10cSrcweir } 1109*cdf0e10cSrcweir break; 1110*cdf0e10cSrcweir 1111*cdf0e10cSrcweir case SbxSINGLE: 1112*cdf0e10cSrcweir { 1113*cdf0e10cSrcweir float nS; 1114*cdf0e10cSrcweir *pStrm >> nS; 1115*cdf0e10cSrcweir rVar.PutSingle( nS ); 1116*cdf0e10cSrcweir } 1117*cdf0e10cSrcweir break; 1118*cdf0e10cSrcweir 1119*cdf0e10cSrcweir case SbxDOUBLE: 1120*cdf0e10cSrcweir case SbxCURRENCY: 1121*cdf0e10cSrcweir { 1122*cdf0e10cSrcweir *pStrm >> aDouble; 1123*cdf0e10cSrcweir rVar.PutDouble( aDouble ); 1124*cdf0e10cSrcweir } 1125*cdf0e10cSrcweir break; 1126*cdf0e10cSrcweir 1127*cdf0e10cSrcweir case SbxDATE: 1128*cdf0e10cSrcweir { 1129*cdf0e10cSrcweir *pStrm >> aDouble; 1130*cdf0e10cSrcweir rVar.PutDate( aDouble ); 1131*cdf0e10cSrcweir } 1132*cdf0e10cSrcweir break; 1133*cdf0e10cSrcweir 1134*cdf0e10cSrcweir case SbxSTRING: 1135*cdf0e10cSrcweir case SbxLPSTR: 1136*cdf0e10cSrcweir { 1137*cdf0e10cSrcweir String aStr; 1138*cdf0e10cSrcweir pStrm->ReadByteString( aStr, gsl_getSystemTextEncoding() ); 1139*cdf0e10cSrcweir rVar.PutString( aStr ); 1140*cdf0e10cSrcweir } 1141*cdf0e10cSrcweir break; 1142*cdf0e10cSrcweir 1143*cdf0e10cSrcweir default: 1144*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1145*cdf0e10cSrcweir return sal_False; 1146*cdf0e10cSrcweir } 1147*cdf0e10cSrcweir 1148*cdf0e10cSrcweir if( nBlockLen ) 1149*cdf0e10cSrcweir pStrm->Seek( nFPos + nBlockLen ); 1150*cdf0e10cSrcweir return pStrm->GetErrorCode() ? sal_False : sal_True; 1151*cdf0e10cSrcweir } 1152*cdf0e10cSrcweir 1153*cdf0e10cSrcweir 1154*cdf0e10cSrcweir // nCurDim = 1...n 1155*cdf0e10cSrcweir sal_Bool lcl_WriteReadSbxArray( SbxDimArray& rArr, SvStream* pStrm, 1156*cdf0e10cSrcweir sal_Bool bBinary, short nCurDim, short* pOtherDims, sal_Bool bWrite ) 1157*cdf0e10cSrcweir { 1158*cdf0e10cSrcweir DBG_ASSERT( nCurDim > 0,"Bad Dim"); 1159*cdf0e10cSrcweir short nLower, nUpper; 1160*cdf0e10cSrcweir if( !rArr.GetDim( nCurDim, nLower, nUpper ) ) 1161*cdf0e10cSrcweir return sal_False; 1162*cdf0e10cSrcweir for( short nCur = nLower; nCur <= nUpper; nCur++ ) 1163*cdf0e10cSrcweir { 1164*cdf0e10cSrcweir pOtherDims[ nCurDim-1 ] = nCur; 1165*cdf0e10cSrcweir if( nCurDim != 1 ) 1166*cdf0e10cSrcweir lcl_WriteReadSbxArray(rArr, pStrm, bBinary, nCurDim-1, pOtherDims, bWrite); 1167*cdf0e10cSrcweir else 1168*cdf0e10cSrcweir { 1169*cdf0e10cSrcweir SbxVariable* pVar = rArr.Get( (const short*)pOtherDims ); 1170*cdf0e10cSrcweir sal_Bool bRet; 1171*cdf0e10cSrcweir if( bWrite ) 1172*cdf0e10cSrcweir bRet = lcl_WriteSbxVariable(*pVar, pStrm, bBinary, 0, sal_True ); 1173*cdf0e10cSrcweir else 1174*cdf0e10cSrcweir bRet = lcl_ReadSbxVariable(*pVar, pStrm, bBinary, 0, sal_True ); 1175*cdf0e10cSrcweir if( !bRet ) 1176*cdf0e10cSrcweir return sal_False; 1177*cdf0e10cSrcweir } 1178*cdf0e10cSrcweir } 1179*cdf0e10cSrcweir return sal_True; 1180*cdf0e10cSrcweir } 1181*cdf0e10cSrcweir 1182*cdf0e10cSrcweir void PutGet( SbxArray& rPar, sal_Bool bPut ) 1183*cdf0e10cSrcweir { 1184*cdf0e10cSrcweir // Wir brauchen 3 Parameter 1185*cdf0e10cSrcweir if ( rPar.Count() != 4 ) 1186*cdf0e10cSrcweir { 1187*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1188*cdf0e10cSrcweir return; 1189*cdf0e10cSrcweir } 1190*cdf0e10cSrcweir sal_Int16 nFileNo = rPar.Get(1)->GetInteger(); 1191*cdf0e10cSrcweir SbxVariable* pVar2 = rPar.Get(2); 1192*cdf0e10cSrcweir SbxDataType eType2 = pVar2->GetType(); 1193*cdf0e10cSrcweir sal_Bool bHasRecordNo = (sal_Bool)(eType2 != SbxEMPTY && eType2 != SbxERROR); 1194*cdf0e10cSrcweir long nRecordNo = pVar2->GetLong(); 1195*cdf0e10cSrcweir if ( nFileNo < 1 || ( bHasRecordNo && nRecordNo < 1 ) ) 1196*cdf0e10cSrcweir { 1197*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1198*cdf0e10cSrcweir return; 1199*cdf0e10cSrcweir } 1200*cdf0e10cSrcweir nRecordNo--; // wir moegen's ab 0! 1201*cdf0e10cSrcweir SbiIoSystem* pIO = pINST->GetIoSystem(); 1202*cdf0e10cSrcweir SbiStream* pSbStrm = pIO->GetStream( nFileNo ); 1203*cdf0e10cSrcweir // das File muss Random (feste Record-Laenge) oder Binary sein 1204*cdf0e10cSrcweir if ( !pSbStrm || !(pSbStrm->GetMode() & (SBSTRM_BINARY | SBSTRM_RANDOM)) ) 1205*cdf0e10cSrcweir { 1206*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_CHANNEL ); 1207*cdf0e10cSrcweir return; 1208*cdf0e10cSrcweir } 1209*cdf0e10cSrcweir 1210*cdf0e10cSrcweir SvStream* pStrm = pSbStrm->GetStrm(); 1211*cdf0e10cSrcweir sal_Bool bRandom = pSbStrm->IsRandom(); 1212*cdf0e10cSrcweir short nBlockLen = bRandom ? pSbStrm->GetBlockLen() : 0; 1213*cdf0e10cSrcweir 1214*cdf0e10cSrcweir if( bPut ) 1215*cdf0e10cSrcweir { 1216*cdf0e10cSrcweir // Datei aufplustern, falls jemand uebers Dateiende hinaus geseekt hat 1217*cdf0e10cSrcweir pSbStrm->ExpandFile(); 1218*cdf0e10cSrcweir } 1219*cdf0e10cSrcweir 1220*cdf0e10cSrcweir // auf die Startposition seeken 1221*cdf0e10cSrcweir if( bHasRecordNo ) 1222*cdf0e10cSrcweir { 1223*cdf0e10cSrcweir sal_uIntPtr nFilePos = bRandom ? (sal_uIntPtr)(nBlockLen*nRecordNo) : (sal_uIntPtr)nRecordNo; 1224*cdf0e10cSrcweir pStrm->Seek( nFilePos ); 1225*cdf0e10cSrcweir } 1226*cdf0e10cSrcweir 1227*cdf0e10cSrcweir SbxDimArray* pArr = 0; 1228*cdf0e10cSrcweir SbxVariable* pVar = rPar.Get(3); 1229*cdf0e10cSrcweir if( pVar->GetType() & SbxARRAY ) 1230*cdf0e10cSrcweir { 1231*cdf0e10cSrcweir SbxBase* pParObj = pVar->GetObject(); 1232*cdf0e10cSrcweir pArr = PTR_CAST(SbxDimArray,pParObj); 1233*cdf0e10cSrcweir } 1234*cdf0e10cSrcweir 1235*cdf0e10cSrcweir sal_Bool bRet; 1236*cdf0e10cSrcweir 1237*cdf0e10cSrcweir if( pArr ) 1238*cdf0e10cSrcweir { 1239*cdf0e10cSrcweir sal_uIntPtr nFPos = pStrm->Tell(); 1240*cdf0e10cSrcweir short nDims = pArr->GetDims(); 1241*cdf0e10cSrcweir short* pDims = new short[ nDims ]; 1242*cdf0e10cSrcweir bRet = lcl_WriteReadSbxArray(*pArr,pStrm,!bRandom,nDims,pDims,bPut); 1243*cdf0e10cSrcweir delete [] pDims; 1244*cdf0e10cSrcweir if( nBlockLen ) 1245*cdf0e10cSrcweir pStrm->Seek( nFPos + nBlockLen ); 1246*cdf0e10cSrcweir } 1247*cdf0e10cSrcweir else 1248*cdf0e10cSrcweir { 1249*cdf0e10cSrcweir if( bPut ) 1250*cdf0e10cSrcweir bRet = lcl_WriteSbxVariable(*pVar, pStrm, !bRandom, nBlockLen, sal_False); 1251*cdf0e10cSrcweir else 1252*cdf0e10cSrcweir bRet = lcl_ReadSbxVariable(*pVar, pStrm, !bRandom, nBlockLen, sal_False); 1253*cdf0e10cSrcweir } 1254*cdf0e10cSrcweir if( !bRet || pStrm->GetErrorCode() ) 1255*cdf0e10cSrcweir StarBASIC::Error( SbERR_IO_ERROR ); 1256*cdf0e10cSrcweir } 1257*cdf0e10cSrcweir 1258*cdf0e10cSrcweir RTLFUNC(Put) 1259*cdf0e10cSrcweir { 1260*cdf0e10cSrcweir (void)pBasic; 1261*cdf0e10cSrcweir (void)bWrite; 1262*cdf0e10cSrcweir 1263*cdf0e10cSrcweir PutGet( rPar, sal_True ); 1264*cdf0e10cSrcweir } 1265*cdf0e10cSrcweir 1266*cdf0e10cSrcweir RTLFUNC(Get) 1267*cdf0e10cSrcweir { 1268*cdf0e10cSrcweir (void)pBasic; 1269*cdf0e10cSrcweir (void)bWrite; 1270*cdf0e10cSrcweir 1271*cdf0e10cSrcweir PutGet( rPar, sal_False ); 1272*cdf0e10cSrcweir } 1273*cdf0e10cSrcweir 1274*cdf0e10cSrcweir RTLFUNC(Environ) 1275*cdf0e10cSrcweir { 1276*cdf0e10cSrcweir (void)pBasic; 1277*cdf0e10cSrcweir (void)bWrite; 1278*cdf0e10cSrcweir 1279*cdf0e10cSrcweir if ( rPar.Count() != 2 ) 1280*cdf0e10cSrcweir { 1281*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1282*cdf0e10cSrcweir return; 1283*cdf0e10cSrcweir } 1284*cdf0e10cSrcweir String aResult; 1285*cdf0e10cSrcweir // sollte ANSI sein, aber unter Win16 in DLL nicht moeglich 1286*cdf0e10cSrcweir ByteString aByteStr( rPar.Get(1)->GetString(), gsl_getSystemTextEncoding() ); 1287*cdf0e10cSrcweir const char* pEnvStr = getenv( aByteStr.GetBuffer() ); 1288*cdf0e10cSrcweir if ( pEnvStr ) 1289*cdf0e10cSrcweir aResult = String::CreateFromAscii( pEnvStr ); 1290*cdf0e10cSrcweir rPar.Get(0)->PutString( aResult ); 1291*cdf0e10cSrcweir } 1292*cdf0e10cSrcweir 1293*cdf0e10cSrcweir static double GetDialogZoomFactor( sal_Bool bX, long nValue ) 1294*cdf0e10cSrcweir { 1295*cdf0e10cSrcweir OutputDevice* pDevice = Application::GetDefaultDevice(); 1296*cdf0e10cSrcweir double nResult = 0; 1297*cdf0e10cSrcweir if( pDevice ) 1298*cdf0e10cSrcweir { 1299*cdf0e10cSrcweir Size aRefSize( nValue, nValue ); 1300*cdf0e10cSrcweir Fraction aFracX( 1, 26 ); 1301*cdf0e10cSrcweir Fraction aFracY( 1, 24 ); 1302*cdf0e10cSrcweir MapMode aMap( MAP_APPFONT, Point(), aFracX, aFracY ); 1303*cdf0e10cSrcweir Size aScaledSize = pDevice->LogicToPixel( aRefSize, aMap ); 1304*cdf0e10cSrcweir aRefSize = pDevice->LogicToPixel( aRefSize, MapMode(MAP_TWIP) ); 1305*cdf0e10cSrcweir 1306*cdf0e10cSrcweir double nRef, nScaled; 1307*cdf0e10cSrcweir if( bX ) 1308*cdf0e10cSrcweir { 1309*cdf0e10cSrcweir nRef = aRefSize.Width(); 1310*cdf0e10cSrcweir nScaled = aScaledSize.Width(); 1311*cdf0e10cSrcweir } 1312*cdf0e10cSrcweir else 1313*cdf0e10cSrcweir { 1314*cdf0e10cSrcweir nRef = aRefSize.Height(); 1315*cdf0e10cSrcweir nScaled = aScaledSize.Height(); 1316*cdf0e10cSrcweir } 1317*cdf0e10cSrcweir nResult = nScaled / nRef; 1318*cdf0e10cSrcweir } 1319*cdf0e10cSrcweir return nResult; 1320*cdf0e10cSrcweir } 1321*cdf0e10cSrcweir 1322*cdf0e10cSrcweir 1323*cdf0e10cSrcweir RTLFUNC(GetDialogZoomFactorX) 1324*cdf0e10cSrcweir { 1325*cdf0e10cSrcweir (void)pBasic; 1326*cdf0e10cSrcweir (void)bWrite; 1327*cdf0e10cSrcweir 1328*cdf0e10cSrcweir if ( rPar.Count() != 2 ) 1329*cdf0e10cSrcweir { 1330*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1331*cdf0e10cSrcweir return; 1332*cdf0e10cSrcweir } 1333*cdf0e10cSrcweir rPar.Get(0)->PutDouble( GetDialogZoomFactor( sal_True, rPar.Get(1)->GetLong() )); 1334*cdf0e10cSrcweir } 1335*cdf0e10cSrcweir 1336*cdf0e10cSrcweir RTLFUNC(GetDialogZoomFactorY) 1337*cdf0e10cSrcweir { 1338*cdf0e10cSrcweir (void)pBasic; 1339*cdf0e10cSrcweir (void)bWrite; 1340*cdf0e10cSrcweir 1341*cdf0e10cSrcweir if ( rPar.Count() != 2 ) 1342*cdf0e10cSrcweir { 1343*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1344*cdf0e10cSrcweir return; 1345*cdf0e10cSrcweir } 1346*cdf0e10cSrcweir rPar.Get(0)->PutDouble( GetDialogZoomFactor( sal_False, rPar.Get(1)->GetLong())); 1347*cdf0e10cSrcweir } 1348*cdf0e10cSrcweir 1349*cdf0e10cSrcweir 1350*cdf0e10cSrcweir RTLFUNC(EnableReschedule) 1351*cdf0e10cSrcweir { 1352*cdf0e10cSrcweir (void)pBasic; 1353*cdf0e10cSrcweir (void)bWrite; 1354*cdf0e10cSrcweir 1355*cdf0e10cSrcweir rPar.Get(0)->PutEmpty(); 1356*cdf0e10cSrcweir if ( rPar.Count() != 2 ) 1357*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1358*cdf0e10cSrcweir if( pINST ) 1359*cdf0e10cSrcweir pINST->EnableReschedule( rPar.Get(1)->GetBool() ); 1360*cdf0e10cSrcweir } 1361*cdf0e10cSrcweir 1362*cdf0e10cSrcweir RTLFUNC(GetSystemTicks) 1363*cdf0e10cSrcweir { 1364*cdf0e10cSrcweir (void)pBasic; 1365*cdf0e10cSrcweir (void)bWrite; 1366*cdf0e10cSrcweir 1367*cdf0e10cSrcweir if ( rPar.Count() != 1 ) 1368*cdf0e10cSrcweir { 1369*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1370*cdf0e10cSrcweir return; 1371*cdf0e10cSrcweir } 1372*cdf0e10cSrcweir rPar.Get(0)->PutLong( Time::GetSystemTicks() ); 1373*cdf0e10cSrcweir } 1374*cdf0e10cSrcweir 1375*cdf0e10cSrcweir RTLFUNC(GetPathSeparator) 1376*cdf0e10cSrcweir { 1377*cdf0e10cSrcweir (void)pBasic; 1378*cdf0e10cSrcweir (void)bWrite; 1379*cdf0e10cSrcweir 1380*cdf0e10cSrcweir if ( rPar.Count() != 1 ) 1381*cdf0e10cSrcweir { 1382*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1383*cdf0e10cSrcweir return; 1384*cdf0e10cSrcweir } 1385*cdf0e10cSrcweir rPar.Get(0)->PutString( DirEntry::GetAccessDelimiter() ); 1386*cdf0e10cSrcweir } 1387*cdf0e10cSrcweir 1388*cdf0e10cSrcweir RTLFUNC(ResolvePath) 1389*cdf0e10cSrcweir { 1390*cdf0e10cSrcweir (void)pBasic; 1391*cdf0e10cSrcweir (void)bWrite; 1392*cdf0e10cSrcweir 1393*cdf0e10cSrcweir if ( rPar.Count() == 2 ) 1394*cdf0e10cSrcweir { 1395*cdf0e10cSrcweir String aStr = rPar.Get(1)->GetString(); 1396*cdf0e10cSrcweir DirEntry aEntry( aStr ); 1397*cdf0e10cSrcweir //if( aEntry.IsVirtual() ) 1398*cdf0e10cSrcweir //aStr = aEntry.GetRealPathFromVirtualURL(); 1399*cdf0e10cSrcweir rPar.Get(0)->PutString( aStr ); 1400*cdf0e10cSrcweir } 1401*cdf0e10cSrcweir else 1402*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1403*cdf0e10cSrcweir } 1404*cdf0e10cSrcweir 1405*cdf0e10cSrcweir RTLFUNC(TypeLen) 1406*cdf0e10cSrcweir { 1407*cdf0e10cSrcweir (void)pBasic; 1408*cdf0e10cSrcweir (void)bWrite; 1409*cdf0e10cSrcweir 1410*cdf0e10cSrcweir if ( rPar.Count() != 2 ) 1411*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1412*cdf0e10cSrcweir else 1413*cdf0e10cSrcweir { 1414*cdf0e10cSrcweir SbxDataType eType = rPar.Get(1)->GetType(); 1415*cdf0e10cSrcweir sal_Int16 nLen = 0; 1416*cdf0e10cSrcweir switch( eType ) 1417*cdf0e10cSrcweir { 1418*cdf0e10cSrcweir case SbxEMPTY: 1419*cdf0e10cSrcweir case SbxNULL: 1420*cdf0e10cSrcweir case SbxVECTOR: 1421*cdf0e10cSrcweir case SbxARRAY: 1422*cdf0e10cSrcweir case SbxBYREF: 1423*cdf0e10cSrcweir case SbxVOID: 1424*cdf0e10cSrcweir case SbxHRESULT: 1425*cdf0e10cSrcweir case SbxPOINTER: 1426*cdf0e10cSrcweir case SbxDIMARRAY: 1427*cdf0e10cSrcweir case SbxCARRAY: 1428*cdf0e10cSrcweir case SbxUSERDEF: 1429*cdf0e10cSrcweir nLen = 0; 1430*cdf0e10cSrcweir break; 1431*cdf0e10cSrcweir 1432*cdf0e10cSrcweir case SbxINTEGER: 1433*cdf0e10cSrcweir case SbxERROR: 1434*cdf0e10cSrcweir case SbxUSHORT: 1435*cdf0e10cSrcweir case SbxINT: 1436*cdf0e10cSrcweir case SbxUINT: 1437*cdf0e10cSrcweir nLen = 2; 1438*cdf0e10cSrcweir break; 1439*cdf0e10cSrcweir 1440*cdf0e10cSrcweir case SbxLONG: 1441*cdf0e10cSrcweir case SbxSINGLE: 1442*cdf0e10cSrcweir case SbxULONG: 1443*cdf0e10cSrcweir nLen = 4; 1444*cdf0e10cSrcweir break; 1445*cdf0e10cSrcweir 1446*cdf0e10cSrcweir case SbxDOUBLE: 1447*cdf0e10cSrcweir case SbxCURRENCY: 1448*cdf0e10cSrcweir case SbxDATE: 1449*cdf0e10cSrcweir case SbxLONG64: 1450*cdf0e10cSrcweir case SbxULONG64: 1451*cdf0e10cSrcweir nLen = 8; 1452*cdf0e10cSrcweir break; 1453*cdf0e10cSrcweir 1454*cdf0e10cSrcweir case SbxOBJECT: 1455*cdf0e10cSrcweir case SbxVARIANT: 1456*cdf0e10cSrcweir case SbxDATAOBJECT: 1457*cdf0e10cSrcweir nLen = 0; 1458*cdf0e10cSrcweir break; 1459*cdf0e10cSrcweir 1460*cdf0e10cSrcweir case SbxCHAR: 1461*cdf0e10cSrcweir case SbxBYTE: 1462*cdf0e10cSrcweir case SbxBOOL: 1463*cdf0e10cSrcweir nLen = 1; 1464*cdf0e10cSrcweir break; 1465*cdf0e10cSrcweir 1466*cdf0e10cSrcweir case SbxLPSTR: 1467*cdf0e10cSrcweir case SbxLPWSTR: 1468*cdf0e10cSrcweir case SbxCoreSTRING: 1469*cdf0e10cSrcweir case SbxSTRING: 1470*cdf0e10cSrcweir nLen = (sal_Int16)rPar.Get(1)->GetString().Len(); 1471*cdf0e10cSrcweir break; 1472*cdf0e10cSrcweir 1473*cdf0e10cSrcweir default: 1474*cdf0e10cSrcweir nLen = 0; 1475*cdf0e10cSrcweir } 1476*cdf0e10cSrcweir rPar.Get(0)->PutInteger( nLen ); 1477*cdf0e10cSrcweir } 1478*cdf0e10cSrcweir } 1479*cdf0e10cSrcweir 1480*cdf0e10cSrcweir 1481*cdf0e10cSrcweir // Uno-Struct eines beliebigen Typs erzeugen 1482*cdf0e10cSrcweir // 1. Parameter == Klassename, weitere Parameter zur Initialisierung 1483*cdf0e10cSrcweir RTLFUNC(CreateUnoStruct) 1484*cdf0e10cSrcweir { 1485*cdf0e10cSrcweir (void)pBasic; 1486*cdf0e10cSrcweir (void)bWrite; 1487*cdf0e10cSrcweir 1488*cdf0e10cSrcweir RTL_Impl_CreateUnoStruct( pBasic, rPar, bWrite ); 1489*cdf0e10cSrcweir } 1490*cdf0e10cSrcweir 1491*cdf0e10cSrcweir // Uno-Service erzeugen 1492*cdf0e10cSrcweir // 1. Parameter == Service-Name 1493*cdf0e10cSrcweir RTLFUNC(CreateUnoService) 1494*cdf0e10cSrcweir { 1495*cdf0e10cSrcweir (void)pBasic; 1496*cdf0e10cSrcweir (void)bWrite; 1497*cdf0e10cSrcweir 1498*cdf0e10cSrcweir RTL_Impl_CreateUnoService( pBasic, rPar, bWrite ); 1499*cdf0e10cSrcweir } 1500*cdf0e10cSrcweir 1501*cdf0e10cSrcweir RTLFUNC(CreateUnoServiceWithArguments) 1502*cdf0e10cSrcweir { 1503*cdf0e10cSrcweir (void)pBasic; 1504*cdf0e10cSrcweir (void)bWrite; 1505*cdf0e10cSrcweir 1506*cdf0e10cSrcweir RTL_Impl_CreateUnoServiceWithArguments( pBasic, rPar, bWrite ); 1507*cdf0e10cSrcweir } 1508*cdf0e10cSrcweir 1509*cdf0e10cSrcweir 1510*cdf0e10cSrcweir RTLFUNC(CreateUnoValue) 1511*cdf0e10cSrcweir { 1512*cdf0e10cSrcweir (void)pBasic; 1513*cdf0e10cSrcweir (void)bWrite; 1514*cdf0e10cSrcweir 1515*cdf0e10cSrcweir RTL_Impl_CreateUnoValue( pBasic, rPar, bWrite ); 1516*cdf0e10cSrcweir } 1517*cdf0e10cSrcweir 1518*cdf0e10cSrcweir 1519*cdf0e10cSrcweir // ServiceManager liefern (keine Parameter) 1520*cdf0e10cSrcweir RTLFUNC(GetProcessServiceManager) 1521*cdf0e10cSrcweir { 1522*cdf0e10cSrcweir (void)pBasic; 1523*cdf0e10cSrcweir (void)bWrite; 1524*cdf0e10cSrcweir 1525*cdf0e10cSrcweir RTL_Impl_GetProcessServiceManager( pBasic, rPar, bWrite ); 1526*cdf0e10cSrcweir } 1527*cdf0e10cSrcweir 1528*cdf0e10cSrcweir // PropertySet erzeugen 1529*cdf0e10cSrcweir // 1. Parameter == Sequence<PropertyValue> 1530*cdf0e10cSrcweir RTLFUNC(CreatePropertySet) 1531*cdf0e10cSrcweir { 1532*cdf0e10cSrcweir (void)pBasic; 1533*cdf0e10cSrcweir (void)bWrite; 1534*cdf0e10cSrcweir 1535*cdf0e10cSrcweir RTL_Impl_CreatePropertySet( pBasic, rPar, bWrite ); 1536*cdf0e10cSrcweir } 1537*cdf0e10cSrcweir 1538*cdf0e10cSrcweir // Abfragen, ob ein Interface unterstuetzt wird 1539*cdf0e10cSrcweir // Mehrere Interface-Namen als Parameter 1540*cdf0e10cSrcweir RTLFUNC(HasUnoInterfaces) 1541*cdf0e10cSrcweir { 1542*cdf0e10cSrcweir (void)pBasic; 1543*cdf0e10cSrcweir (void)bWrite; 1544*cdf0e10cSrcweir 1545*cdf0e10cSrcweir RTL_Impl_HasInterfaces( pBasic, rPar, bWrite ); 1546*cdf0e10cSrcweir } 1547*cdf0e10cSrcweir 1548*cdf0e10cSrcweir // Abfragen, ob ein Basic-Objekt ein Uno-Struct repraesentiert 1549*cdf0e10cSrcweir RTLFUNC(IsUnoStruct) 1550*cdf0e10cSrcweir { 1551*cdf0e10cSrcweir (void)pBasic; 1552*cdf0e10cSrcweir (void)bWrite; 1553*cdf0e10cSrcweir 1554*cdf0e10cSrcweir RTL_Impl_IsUnoStruct( pBasic, rPar, bWrite ); 1555*cdf0e10cSrcweir } 1556*cdf0e10cSrcweir 1557*cdf0e10cSrcweir // Abfragen, ob zwei Uno-Objekte identisch sind 1558*cdf0e10cSrcweir RTLFUNC(EqualUnoObjects) 1559*cdf0e10cSrcweir { 1560*cdf0e10cSrcweir (void)pBasic; 1561*cdf0e10cSrcweir (void)bWrite; 1562*cdf0e10cSrcweir 1563*cdf0e10cSrcweir RTL_Impl_EqualUnoObjects( pBasic, rPar, bWrite ); 1564*cdf0e10cSrcweir } 1565*cdf0e10cSrcweir 1566*cdf0e10cSrcweir // Instanciate "com.sun.star.awt.UnoControlDialog" on basis 1567*cdf0e10cSrcweir // of a DialogLibrary entry: Convert from XML-ByteSequence 1568*cdf0e10cSrcweir // and attach events. Implemented in classes\eventatt.cxx 1569*cdf0e10cSrcweir void RTL_Impl_CreateUnoDialog( StarBASIC* pBasic, SbxArray& rPar, sal_Bool bWrite ); 1570*cdf0e10cSrcweir 1571*cdf0e10cSrcweir RTLFUNC(CreateUnoDialog) 1572*cdf0e10cSrcweir { 1573*cdf0e10cSrcweir (void)pBasic; 1574*cdf0e10cSrcweir (void)bWrite; 1575*cdf0e10cSrcweir 1576*cdf0e10cSrcweir RTL_Impl_CreateUnoDialog( pBasic, rPar, bWrite ); 1577*cdf0e10cSrcweir } 1578*cdf0e10cSrcweir 1579*cdf0e10cSrcweir // Return the application standard lib as root scope 1580*cdf0e10cSrcweir RTLFUNC(GlobalScope) 1581*cdf0e10cSrcweir { 1582*cdf0e10cSrcweir (void)pBasic; 1583*cdf0e10cSrcweir (void)bWrite; 1584*cdf0e10cSrcweir 1585*cdf0e10cSrcweir SbxObject* p = pBasic; 1586*cdf0e10cSrcweir while( p->GetParent() ) 1587*cdf0e10cSrcweir p = p->GetParent(); 1588*cdf0e10cSrcweir 1589*cdf0e10cSrcweir SbxVariableRef refVar = rPar.Get(0); 1590*cdf0e10cSrcweir refVar->PutObject( p ); 1591*cdf0e10cSrcweir } 1592*cdf0e10cSrcweir 1593*cdf0e10cSrcweir // Helper functions to convert Url from/to system paths 1594*cdf0e10cSrcweir RTLFUNC(ConvertToUrl) 1595*cdf0e10cSrcweir { 1596*cdf0e10cSrcweir (void)pBasic; 1597*cdf0e10cSrcweir (void)bWrite; 1598*cdf0e10cSrcweir 1599*cdf0e10cSrcweir if ( rPar.Count() == 2 ) 1600*cdf0e10cSrcweir { 1601*cdf0e10cSrcweir String aStr = rPar.Get(1)->GetString(); 1602*cdf0e10cSrcweir INetURLObject aURLObj( aStr, INET_PROT_FILE ); 1603*cdf0e10cSrcweir ::rtl::OUString aFileURL = aURLObj.GetMainURL( INetURLObject::NO_DECODE ); 1604*cdf0e10cSrcweir if( !aFileURL.getLength() ) 1605*cdf0e10cSrcweir ::osl::File::getFileURLFromSystemPath( aFileURL, aFileURL ); 1606*cdf0e10cSrcweir if( !aFileURL.getLength() ) 1607*cdf0e10cSrcweir aFileURL = aStr; 1608*cdf0e10cSrcweir rPar.Get(0)->PutString( String(aFileURL) ); 1609*cdf0e10cSrcweir } 1610*cdf0e10cSrcweir else 1611*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1612*cdf0e10cSrcweir } 1613*cdf0e10cSrcweir 1614*cdf0e10cSrcweir RTLFUNC(ConvertFromUrl) 1615*cdf0e10cSrcweir { 1616*cdf0e10cSrcweir (void)pBasic; 1617*cdf0e10cSrcweir (void)bWrite; 1618*cdf0e10cSrcweir 1619*cdf0e10cSrcweir if ( rPar.Count() == 2 ) 1620*cdf0e10cSrcweir { 1621*cdf0e10cSrcweir String aStr = rPar.Get(1)->GetString(); 1622*cdf0e10cSrcweir ::rtl::OUString aSysPath; 1623*cdf0e10cSrcweir ::osl::File::getSystemPathFromFileURL( aStr, aSysPath ); 1624*cdf0e10cSrcweir if( !aSysPath.getLength() ) 1625*cdf0e10cSrcweir aSysPath = aStr; 1626*cdf0e10cSrcweir rPar.Get(0)->PutString( String(aSysPath) ); 1627*cdf0e10cSrcweir } 1628*cdf0e10cSrcweir else 1629*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1630*cdf0e10cSrcweir } 1631*cdf0e10cSrcweir 1632*cdf0e10cSrcweir 1633*cdf0e10cSrcweir // Provide DefaultContext 1634*cdf0e10cSrcweir RTLFUNC(GetDefaultContext) 1635*cdf0e10cSrcweir { 1636*cdf0e10cSrcweir (void)pBasic; 1637*cdf0e10cSrcweir (void)bWrite; 1638*cdf0e10cSrcweir 1639*cdf0e10cSrcweir RTL_Impl_GetDefaultContext( pBasic, rPar, bWrite ); 1640*cdf0e10cSrcweir } 1641*cdf0e10cSrcweir 1642*cdf0e10cSrcweir #ifdef DBG_TRACE_BASIC 1643*cdf0e10cSrcweir RTLFUNC(TraceCommand) 1644*cdf0e10cSrcweir { 1645*cdf0e10cSrcweir RTL_Impl_TraceCommand( pBasic, rPar, bWrite ); 1646*cdf0e10cSrcweir } 1647*cdf0e10cSrcweir #endif 1648*cdf0e10cSrcweir 1649*cdf0e10cSrcweir RTLFUNC(Join) 1650*cdf0e10cSrcweir { 1651*cdf0e10cSrcweir (void)pBasic; 1652*cdf0e10cSrcweir (void)bWrite; 1653*cdf0e10cSrcweir 1654*cdf0e10cSrcweir sal_uInt16 nParCount = rPar.Count(); 1655*cdf0e10cSrcweir if ( nParCount != 3 && nParCount != 2 ) 1656*cdf0e10cSrcweir { 1657*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1658*cdf0e10cSrcweir return; 1659*cdf0e10cSrcweir } 1660*cdf0e10cSrcweir SbxBase* pParObj = rPar.Get(1)->GetObject(); 1661*cdf0e10cSrcweir SbxDimArray* pArr = PTR_CAST(SbxDimArray,pParObj); 1662*cdf0e10cSrcweir if( pArr ) 1663*cdf0e10cSrcweir { 1664*cdf0e10cSrcweir if( pArr->GetDims() != 1 ) 1665*cdf0e10cSrcweir StarBASIC::Error( SbERR_WRONG_DIMS ); // Syntax Error?! 1666*cdf0e10cSrcweir 1667*cdf0e10cSrcweir String aDelim; 1668*cdf0e10cSrcweir if( nParCount == 3 ) 1669*cdf0e10cSrcweir aDelim = rPar.Get(2)->GetString(); 1670*cdf0e10cSrcweir else 1671*cdf0e10cSrcweir aDelim = String::CreateFromAscii( " " ); 1672*cdf0e10cSrcweir 1673*cdf0e10cSrcweir String aRetStr; 1674*cdf0e10cSrcweir short nLower, nUpper; 1675*cdf0e10cSrcweir pArr->GetDim( 1, nLower, nUpper ); 1676*cdf0e10cSrcweir for( short i = nLower ; i <= nUpper ; ++i ) 1677*cdf0e10cSrcweir { 1678*cdf0e10cSrcweir String aStr = pArr->Get( &i )->GetString(); 1679*cdf0e10cSrcweir aRetStr += aStr; 1680*cdf0e10cSrcweir if( i != nUpper ) 1681*cdf0e10cSrcweir aRetStr += aDelim; 1682*cdf0e10cSrcweir } 1683*cdf0e10cSrcweir rPar.Get(0)->PutString( aRetStr ); 1684*cdf0e10cSrcweir } 1685*cdf0e10cSrcweir else 1686*cdf0e10cSrcweir StarBASIC::Error( SbERR_MUST_HAVE_DIMS ); 1687*cdf0e10cSrcweir } 1688*cdf0e10cSrcweir 1689*cdf0e10cSrcweir 1690*cdf0e10cSrcweir RTLFUNC(Split) 1691*cdf0e10cSrcweir { 1692*cdf0e10cSrcweir (void)pBasic; 1693*cdf0e10cSrcweir (void)bWrite; 1694*cdf0e10cSrcweir 1695*cdf0e10cSrcweir sal_uInt16 nParCount = rPar.Count(); 1696*cdf0e10cSrcweir if ( nParCount < 2 ) 1697*cdf0e10cSrcweir { 1698*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1699*cdf0e10cSrcweir return; 1700*cdf0e10cSrcweir } 1701*cdf0e10cSrcweir 1702*cdf0e10cSrcweir String aExpression = rPar.Get(1)->GetString(); 1703*cdf0e10cSrcweir short nArraySize = 0; 1704*cdf0e10cSrcweir StringVector vRet; 1705*cdf0e10cSrcweir if( aExpression.Len() ) 1706*cdf0e10cSrcweir { 1707*cdf0e10cSrcweir String aDelim; 1708*cdf0e10cSrcweir if( nParCount >= 3 ) 1709*cdf0e10cSrcweir aDelim = rPar.Get(2)->GetString(); 1710*cdf0e10cSrcweir else 1711*cdf0e10cSrcweir aDelim = String::CreateFromAscii( " " ); 1712*cdf0e10cSrcweir 1713*cdf0e10cSrcweir sal_Int32 nCount = -1; 1714*cdf0e10cSrcweir if( nParCount == 4 ) 1715*cdf0e10cSrcweir nCount = rPar.Get(3)->GetLong(); 1716*cdf0e10cSrcweir 1717*cdf0e10cSrcweir xub_StrLen nDelimLen = aDelim.Len(); 1718*cdf0e10cSrcweir if( nDelimLen ) 1719*cdf0e10cSrcweir { 1720*cdf0e10cSrcweir xub_StrLen iSearch = STRING_NOTFOUND; 1721*cdf0e10cSrcweir xub_StrLen iStart = 0; 1722*cdf0e10cSrcweir do 1723*cdf0e10cSrcweir { 1724*cdf0e10cSrcweir bool bBreak = false; 1725*cdf0e10cSrcweir if( nCount >= 0 && nArraySize == nCount - 1 ) 1726*cdf0e10cSrcweir bBreak = true; 1727*cdf0e10cSrcweir 1728*cdf0e10cSrcweir iSearch = aExpression.Search( aDelim, iStart ); 1729*cdf0e10cSrcweir String aSubStr; 1730*cdf0e10cSrcweir if( iSearch != STRING_NOTFOUND && !bBreak ) 1731*cdf0e10cSrcweir { 1732*cdf0e10cSrcweir aSubStr = aExpression.Copy( iStart, iSearch - iStart ); 1733*cdf0e10cSrcweir iStart = iSearch + nDelimLen; 1734*cdf0e10cSrcweir } 1735*cdf0e10cSrcweir else 1736*cdf0e10cSrcweir { 1737*cdf0e10cSrcweir aSubStr = aExpression.Copy( iStart ); 1738*cdf0e10cSrcweir } 1739*cdf0e10cSrcweir vRet.push_back( aSubStr ); 1740*cdf0e10cSrcweir nArraySize++; 1741*cdf0e10cSrcweir 1742*cdf0e10cSrcweir if( bBreak ) 1743*cdf0e10cSrcweir break; 1744*cdf0e10cSrcweir } 1745*cdf0e10cSrcweir while( iSearch != STRING_NOTFOUND ); 1746*cdf0e10cSrcweir } 1747*cdf0e10cSrcweir else 1748*cdf0e10cSrcweir { 1749*cdf0e10cSrcweir vRet.push_back( aExpression ); 1750*cdf0e10cSrcweir nArraySize = 1; 1751*cdf0e10cSrcweir } 1752*cdf0e10cSrcweir } 1753*cdf0e10cSrcweir 1754*cdf0e10cSrcweir SbxDimArray* pArray = new SbxDimArray( SbxVARIANT ); 1755*cdf0e10cSrcweir pArray->unoAddDim( 0, nArraySize-1 ); 1756*cdf0e10cSrcweir 1757*cdf0e10cSrcweir // Parameter ins Array uebernehmen 1758*cdf0e10cSrcweir for( short i = 0 ; i < nArraySize ; i++ ) 1759*cdf0e10cSrcweir { 1760*cdf0e10cSrcweir SbxVariableRef xVar = new SbxVariable( SbxVARIANT ); 1761*cdf0e10cSrcweir xVar->PutString( vRet[i] ); 1762*cdf0e10cSrcweir pArray->Put( (SbxVariable*)xVar, &i ); 1763*cdf0e10cSrcweir } 1764*cdf0e10cSrcweir 1765*cdf0e10cSrcweir // Array zurueckliefern 1766*cdf0e10cSrcweir SbxVariableRef refVar = rPar.Get(0); 1767*cdf0e10cSrcweir sal_uInt16 nFlags = refVar->GetFlags(); 1768*cdf0e10cSrcweir refVar->ResetFlag( SBX_FIXED ); 1769*cdf0e10cSrcweir refVar->PutObject( pArray ); 1770*cdf0e10cSrcweir refVar->SetFlags( nFlags ); 1771*cdf0e10cSrcweir refVar->SetParameters( NULL ); 1772*cdf0e10cSrcweir } 1773*cdf0e10cSrcweir 1774*cdf0e10cSrcweir // MonthName(month[, abbreviate]) 1775*cdf0e10cSrcweir RTLFUNC(MonthName) 1776*cdf0e10cSrcweir { 1777*cdf0e10cSrcweir (void)pBasic; 1778*cdf0e10cSrcweir (void)bWrite; 1779*cdf0e10cSrcweir 1780*cdf0e10cSrcweir sal_uInt16 nParCount = rPar.Count(); 1781*cdf0e10cSrcweir if( nParCount != 2 && nParCount != 3 ) 1782*cdf0e10cSrcweir { 1783*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1784*cdf0e10cSrcweir return; 1785*cdf0e10cSrcweir } 1786*cdf0e10cSrcweir 1787*cdf0e10cSrcweir Reference< XCalendar > xCalendar = getLocaleCalendar(); 1788*cdf0e10cSrcweir if( !xCalendar.is() ) 1789*cdf0e10cSrcweir { 1790*cdf0e10cSrcweir StarBASIC::Error( SbERR_INTERNAL_ERROR ); 1791*cdf0e10cSrcweir return; 1792*cdf0e10cSrcweir } 1793*cdf0e10cSrcweir Sequence< CalendarItem > aMonthSeq = xCalendar->getMonths(); 1794*cdf0e10cSrcweir sal_Int32 nMonthCount = aMonthSeq.getLength(); 1795*cdf0e10cSrcweir 1796*cdf0e10cSrcweir sal_Int16 nVal = rPar.Get(1)->GetInteger(); 1797*cdf0e10cSrcweir if( nVal < 1 || nVal > nMonthCount ) 1798*cdf0e10cSrcweir { 1799*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1800*cdf0e10cSrcweir return; 1801*cdf0e10cSrcweir } 1802*cdf0e10cSrcweir 1803*cdf0e10cSrcweir sal_Bool bAbbreviate = false; 1804*cdf0e10cSrcweir if( nParCount == 3 ) 1805*cdf0e10cSrcweir bAbbreviate = rPar.Get(2)->GetBool(); 1806*cdf0e10cSrcweir 1807*cdf0e10cSrcweir const CalendarItem* pCalendarItems = aMonthSeq.getConstArray(); 1808*cdf0e10cSrcweir const CalendarItem& rItem = pCalendarItems[nVal - 1]; 1809*cdf0e10cSrcweir 1810*cdf0e10cSrcweir ::rtl::OUString aRetStr = ( bAbbreviate ? rItem.AbbrevName : rItem.FullName ); 1811*cdf0e10cSrcweir rPar.Get(0)->PutString( String(aRetStr) ); 1812*cdf0e10cSrcweir } 1813*cdf0e10cSrcweir 1814*cdf0e10cSrcweir // WeekdayName(weekday, abbreviate, firstdayofweek) 1815*cdf0e10cSrcweir RTLFUNC(WeekdayName) 1816*cdf0e10cSrcweir { 1817*cdf0e10cSrcweir (void)pBasic; 1818*cdf0e10cSrcweir (void)bWrite; 1819*cdf0e10cSrcweir 1820*cdf0e10cSrcweir sal_uInt16 nParCount = rPar.Count(); 1821*cdf0e10cSrcweir if( nParCount < 2 || nParCount > 4 ) 1822*cdf0e10cSrcweir { 1823*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1824*cdf0e10cSrcweir return; 1825*cdf0e10cSrcweir } 1826*cdf0e10cSrcweir 1827*cdf0e10cSrcweir Reference< XCalendar > xCalendar = getLocaleCalendar(); 1828*cdf0e10cSrcweir if( !xCalendar.is() ) 1829*cdf0e10cSrcweir { 1830*cdf0e10cSrcweir StarBASIC::Error( SbERR_INTERNAL_ERROR ); 1831*cdf0e10cSrcweir return; 1832*cdf0e10cSrcweir } 1833*cdf0e10cSrcweir 1834*cdf0e10cSrcweir Sequence< CalendarItem > aDaySeq = xCalendar->getDays(); 1835*cdf0e10cSrcweir sal_Int16 nDayCount = (sal_Int16)aDaySeq.getLength(); 1836*cdf0e10cSrcweir sal_Int16 nDay = rPar.Get(1)->GetInteger(); 1837*cdf0e10cSrcweir sal_Int16 nFirstDay = 0; 1838*cdf0e10cSrcweir if( nParCount == 4 ) 1839*cdf0e10cSrcweir { 1840*cdf0e10cSrcweir nFirstDay = rPar.Get(3)->GetInteger(); 1841*cdf0e10cSrcweir if( nFirstDay < 0 || nFirstDay > 7 ) 1842*cdf0e10cSrcweir { 1843*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1844*cdf0e10cSrcweir return; 1845*cdf0e10cSrcweir } 1846*cdf0e10cSrcweir } 1847*cdf0e10cSrcweir if( nFirstDay == 0 ) 1848*cdf0e10cSrcweir nFirstDay = sal_Int16( xCalendar->getFirstDayOfWeek() + 1 ); 1849*cdf0e10cSrcweir 1850*cdf0e10cSrcweir nDay = 1 + (nDay + nDayCount + nFirstDay - 2) % nDayCount; 1851*cdf0e10cSrcweir if( nDay < 1 || nDay > nDayCount ) 1852*cdf0e10cSrcweir { 1853*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1854*cdf0e10cSrcweir return; 1855*cdf0e10cSrcweir } 1856*cdf0e10cSrcweir 1857*cdf0e10cSrcweir sal_Bool bAbbreviate = false; 1858*cdf0e10cSrcweir if( nParCount >= 3 ) 1859*cdf0e10cSrcweir { 1860*cdf0e10cSrcweir SbxVariable* pPar2 = rPar.Get(2); 1861*cdf0e10cSrcweir if( !pPar2->IsErr() ) 1862*cdf0e10cSrcweir bAbbreviate = pPar2->GetBool(); 1863*cdf0e10cSrcweir } 1864*cdf0e10cSrcweir 1865*cdf0e10cSrcweir const CalendarItem* pCalendarItems = aDaySeq.getConstArray(); 1866*cdf0e10cSrcweir const CalendarItem& rItem = pCalendarItems[nDay - 1]; 1867*cdf0e10cSrcweir 1868*cdf0e10cSrcweir ::rtl::OUString aRetStr = ( bAbbreviate ? rItem.AbbrevName : rItem.FullName ); 1869*cdf0e10cSrcweir rPar.Get(0)->PutString( String(aRetStr) ); 1870*cdf0e10cSrcweir } 1871*cdf0e10cSrcweir 1872*cdf0e10cSrcweir sal_Int16 implGetWeekDay( double aDate, bool bFirstDayParam = false, sal_Int16 nFirstDay = 0 ) 1873*cdf0e10cSrcweir { 1874*cdf0e10cSrcweir Date aRefDate( 1,1,1900 ); 1875*cdf0e10cSrcweir long nDays = (long) aDate; 1876*cdf0e10cSrcweir nDays -= 2; // normieren: 1.1.1900 => 0 1877*cdf0e10cSrcweir aRefDate += nDays; 1878*cdf0e10cSrcweir DayOfWeek aDay = aRefDate.GetDayOfWeek(); 1879*cdf0e10cSrcweir sal_Int16 nDay; 1880*cdf0e10cSrcweir if ( aDay != SUNDAY ) 1881*cdf0e10cSrcweir nDay = (sal_Int16)aDay + 2; 1882*cdf0e10cSrcweir else 1883*cdf0e10cSrcweir nDay = 1; // 1==Sonntag 1884*cdf0e10cSrcweir 1885*cdf0e10cSrcweir // #117253 Optional 2. parameter "firstdayofweek" 1886*cdf0e10cSrcweir if( bFirstDayParam ) 1887*cdf0e10cSrcweir { 1888*cdf0e10cSrcweir if( nFirstDay < 0 || nFirstDay > 7 ) 1889*cdf0e10cSrcweir { 1890*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1891*cdf0e10cSrcweir return 0; 1892*cdf0e10cSrcweir } 1893*cdf0e10cSrcweir if( nFirstDay == 0 ) 1894*cdf0e10cSrcweir { 1895*cdf0e10cSrcweir Reference< XCalendar > xCalendar = getLocaleCalendar(); 1896*cdf0e10cSrcweir if( !xCalendar.is() ) 1897*cdf0e10cSrcweir { 1898*cdf0e10cSrcweir StarBASIC::Error( SbERR_INTERNAL_ERROR ); 1899*cdf0e10cSrcweir return 0; 1900*cdf0e10cSrcweir } 1901*cdf0e10cSrcweir nFirstDay = sal_Int16( xCalendar->getFirstDayOfWeek() + 1 ); 1902*cdf0e10cSrcweir } 1903*cdf0e10cSrcweir nDay = 1 + (nDay + 7 - nFirstDay) % 7; 1904*cdf0e10cSrcweir } 1905*cdf0e10cSrcweir return nDay; 1906*cdf0e10cSrcweir } 1907*cdf0e10cSrcweir 1908*cdf0e10cSrcweir RTLFUNC(Weekday) 1909*cdf0e10cSrcweir { 1910*cdf0e10cSrcweir (void)pBasic; 1911*cdf0e10cSrcweir (void)bWrite; 1912*cdf0e10cSrcweir 1913*cdf0e10cSrcweir sal_uInt16 nParCount = rPar.Count(); 1914*cdf0e10cSrcweir if ( nParCount < 2 ) 1915*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 1916*cdf0e10cSrcweir else 1917*cdf0e10cSrcweir { 1918*cdf0e10cSrcweir double aDate = rPar.Get(1)->GetDate(); 1919*cdf0e10cSrcweir 1920*cdf0e10cSrcweir bool bFirstDay = false; 1921*cdf0e10cSrcweir sal_Int16 nFirstDay = 0; 1922*cdf0e10cSrcweir if ( nParCount > 2 ) 1923*cdf0e10cSrcweir { 1924*cdf0e10cSrcweir nFirstDay = rPar.Get(2)->GetInteger(); 1925*cdf0e10cSrcweir bFirstDay = true; 1926*cdf0e10cSrcweir } 1927*cdf0e10cSrcweir sal_Int16 nDay = implGetWeekDay( aDate, bFirstDay, nFirstDay ); 1928*cdf0e10cSrcweir rPar.Get(0)->PutInteger( nDay ); 1929*cdf0e10cSrcweir } 1930*cdf0e10cSrcweir } 1931*cdf0e10cSrcweir 1932*cdf0e10cSrcweir 1933*cdf0e10cSrcweir enum Interval 1934*cdf0e10cSrcweir { 1935*cdf0e10cSrcweir INTERVAL_NONE, 1936*cdf0e10cSrcweir INTERVAL_YYYY, 1937*cdf0e10cSrcweir INTERVAL_Q, 1938*cdf0e10cSrcweir INTERVAL_M, 1939*cdf0e10cSrcweir INTERVAL_Y, 1940*cdf0e10cSrcweir INTERVAL_D, 1941*cdf0e10cSrcweir INTERVAL_W, 1942*cdf0e10cSrcweir INTERVAL_WW, 1943*cdf0e10cSrcweir INTERVAL_H, 1944*cdf0e10cSrcweir INTERVAL_N, 1945*cdf0e10cSrcweir INTERVAL_S 1946*cdf0e10cSrcweir }; 1947*cdf0e10cSrcweir 1948*cdf0e10cSrcweir struct IntervalInfo 1949*cdf0e10cSrcweir { 1950*cdf0e10cSrcweir Interval meInterval; 1951*cdf0e10cSrcweir const char* mpStringCode; 1952*cdf0e10cSrcweir double mdValue; 1953*cdf0e10cSrcweir bool mbSimple; 1954*cdf0e10cSrcweir 1955*cdf0e10cSrcweir IntervalInfo( Interval eInterval, const char* pStringCode, double dValue, bool bSimple ) 1956*cdf0e10cSrcweir : meInterval( eInterval ) 1957*cdf0e10cSrcweir , mpStringCode( pStringCode ) 1958*cdf0e10cSrcweir , mdValue( dValue ) 1959*cdf0e10cSrcweir , mbSimple( bSimple ) 1960*cdf0e10cSrcweir {} 1961*cdf0e10cSrcweir }; 1962*cdf0e10cSrcweir 1963*cdf0e10cSrcweir static IntervalInfo pIntervalTable[] = 1964*cdf0e10cSrcweir { 1965*cdf0e10cSrcweir IntervalInfo( INTERVAL_YYYY, "yyyy", 0.0, false ), // Year 1966*cdf0e10cSrcweir IntervalInfo( INTERVAL_Q, "q", 0.0, false ), // Quarter 1967*cdf0e10cSrcweir IntervalInfo( INTERVAL_M, "m", 0.0, false ), // Month 1968*cdf0e10cSrcweir IntervalInfo( INTERVAL_Y, "y", 1.0, true ), // Day of year 1969*cdf0e10cSrcweir IntervalInfo( INTERVAL_D, "d", 1.0, true ), // Day 1970*cdf0e10cSrcweir IntervalInfo( INTERVAL_W, "w", 1.0, true ), // Weekday 1971*cdf0e10cSrcweir IntervalInfo( INTERVAL_WW, "ww", 7.0, true ), // Week 1972*cdf0e10cSrcweir IntervalInfo( INTERVAL_H, "h", (1.0 / 24.0), true ), // Hour 1973*cdf0e10cSrcweir IntervalInfo( INTERVAL_N, "n", (1.0 / 1440.0), true), // Minute 1974*cdf0e10cSrcweir IntervalInfo( INTERVAL_S, "s", (1.0 / 86400.0), true ), // Second 1975*cdf0e10cSrcweir IntervalInfo( INTERVAL_NONE, NULL, 0.0, false ) 1976*cdf0e10cSrcweir }; 1977*cdf0e10cSrcweir 1978*cdf0e10cSrcweir IntervalInfo* getIntervalInfo( const String& rStringCode ) 1979*cdf0e10cSrcweir { 1980*cdf0e10cSrcweir IntervalInfo* pInfo = NULL; 1981*cdf0e10cSrcweir sal_Int16 i = 0; 1982*cdf0e10cSrcweir while( (pInfo = pIntervalTable + i)->mpStringCode != NULL ) 1983*cdf0e10cSrcweir { 1984*cdf0e10cSrcweir if( rStringCode.EqualsIgnoreCaseAscii( pInfo->mpStringCode ) ) 1985*cdf0e10cSrcweir break; 1986*cdf0e10cSrcweir i++; 1987*cdf0e10cSrcweir } 1988*cdf0e10cSrcweir return pInfo; 1989*cdf0e10cSrcweir } 1990*cdf0e10cSrcweir 1991*cdf0e10cSrcweir // From methods.cxx 1992*cdf0e10cSrcweir sal_Bool implDateSerial( sal_Int16 nYear, sal_Int16 nMonth, sal_Int16 nDay, double& rdRet ); 1993*cdf0e10cSrcweir sal_Int16 implGetDateDay( double aDate ); 1994*cdf0e10cSrcweir sal_Int16 implGetDateMonth( double aDate ); 1995*cdf0e10cSrcweir sal_Int16 implGetDateYear( double aDate ); 1996*cdf0e10cSrcweir 1997*cdf0e10cSrcweir sal_Int16 implGetHour( double dDate ); 1998*cdf0e10cSrcweir sal_Int16 implGetMinute( double dDate ); 1999*cdf0e10cSrcweir sal_Int16 implGetSecond( double dDate ); 2000*cdf0e10cSrcweir 2001*cdf0e10cSrcweir 2002*cdf0e10cSrcweir inline void implGetDayMonthYear( sal_Int16& rnYear, sal_Int16& rnMonth, sal_Int16& rnDay, double dDate ) 2003*cdf0e10cSrcweir { 2004*cdf0e10cSrcweir rnDay = implGetDateDay( dDate ); 2005*cdf0e10cSrcweir rnMonth = implGetDateMonth( dDate ); 2006*cdf0e10cSrcweir rnYear = implGetDateYear( dDate ); 2007*cdf0e10cSrcweir } 2008*cdf0e10cSrcweir 2009*cdf0e10cSrcweir inline sal_Int16 limitToINT16( sal_Int32 n32 ) 2010*cdf0e10cSrcweir { 2011*cdf0e10cSrcweir if( n32 > 32767 ) 2012*cdf0e10cSrcweir n32 = 32767; 2013*cdf0e10cSrcweir else if( n32 < -32768 ) 2014*cdf0e10cSrcweir n32 = -32768; 2015*cdf0e10cSrcweir return (sal_Int16)n32; 2016*cdf0e10cSrcweir } 2017*cdf0e10cSrcweir 2018*cdf0e10cSrcweir RTLFUNC(DateAdd) 2019*cdf0e10cSrcweir { 2020*cdf0e10cSrcweir (void)pBasic; 2021*cdf0e10cSrcweir (void)bWrite; 2022*cdf0e10cSrcweir 2023*cdf0e10cSrcweir sal_uInt16 nParCount = rPar.Count(); 2024*cdf0e10cSrcweir if( nParCount != 4 ) 2025*cdf0e10cSrcweir { 2026*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 2027*cdf0e10cSrcweir return; 2028*cdf0e10cSrcweir } 2029*cdf0e10cSrcweir 2030*cdf0e10cSrcweir String aStringCode = rPar.Get(1)->GetString(); 2031*cdf0e10cSrcweir IntervalInfo* pInfo = getIntervalInfo( aStringCode ); 2032*cdf0e10cSrcweir if( !pInfo ) 2033*cdf0e10cSrcweir { 2034*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 2035*cdf0e10cSrcweir return; 2036*cdf0e10cSrcweir } 2037*cdf0e10cSrcweir 2038*cdf0e10cSrcweir sal_Int32 lNumber = rPar.Get(2)->GetLong(); 2039*cdf0e10cSrcweir double dDate = rPar.Get(3)->GetDate(); 2040*cdf0e10cSrcweir double dNewDate = 0; 2041*cdf0e10cSrcweir if( pInfo->mbSimple ) 2042*cdf0e10cSrcweir { 2043*cdf0e10cSrcweir double dAdd = pInfo->mdValue * lNumber; 2044*cdf0e10cSrcweir dNewDate = dDate + dAdd; 2045*cdf0e10cSrcweir } 2046*cdf0e10cSrcweir else 2047*cdf0e10cSrcweir { 2048*cdf0e10cSrcweir // Keep hours, minutes, seconds 2049*cdf0e10cSrcweir double dHoursMinutesSeconds = dDate - floor( dDate ); 2050*cdf0e10cSrcweir 2051*cdf0e10cSrcweir sal_Bool bOk = sal_True; 2052*cdf0e10cSrcweir sal_Int16 nYear, nMonth, nDay; 2053*cdf0e10cSrcweir sal_Int16 nTargetYear16 = 0, nTargetMonth = 0; 2054*cdf0e10cSrcweir implGetDayMonthYear( nYear, nMonth, nDay, dDate ); 2055*cdf0e10cSrcweir switch( pInfo->meInterval ) 2056*cdf0e10cSrcweir { 2057*cdf0e10cSrcweir case INTERVAL_YYYY: 2058*cdf0e10cSrcweir { 2059*cdf0e10cSrcweir sal_Int32 nTargetYear = lNumber + nYear; 2060*cdf0e10cSrcweir nTargetYear16 = limitToINT16( nTargetYear ); 2061*cdf0e10cSrcweir nTargetMonth = nMonth; 2062*cdf0e10cSrcweir bOk = implDateSerial( nTargetYear16, nTargetMonth, nDay, dNewDate ); 2063*cdf0e10cSrcweir break; 2064*cdf0e10cSrcweir } 2065*cdf0e10cSrcweir case INTERVAL_Q: 2066*cdf0e10cSrcweir case INTERVAL_M: 2067*cdf0e10cSrcweir { 2068*cdf0e10cSrcweir bool bNeg = (lNumber < 0); 2069*cdf0e10cSrcweir if( bNeg ) 2070*cdf0e10cSrcweir lNumber = -lNumber; 2071*cdf0e10cSrcweir sal_Int32 nYearsAdd; 2072*cdf0e10cSrcweir sal_Int16 nMonthAdd; 2073*cdf0e10cSrcweir if( pInfo->meInterval == INTERVAL_Q ) 2074*cdf0e10cSrcweir { 2075*cdf0e10cSrcweir nYearsAdd = lNumber / 4; 2076*cdf0e10cSrcweir nMonthAdd = (sal_Int16)( 3 * (lNumber % 4) ); 2077*cdf0e10cSrcweir } 2078*cdf0e10cSrcweir else 2079*cdf0e10cSrcweir { 2080*cdf0e10cSrcweir nYearsAdd = lNumber / 12; 2081*cdf0e10cSrcweir nMonthAdd = (sal_Int16)( lNumber % 12 ); 2082*cdf0e10cSrcweir } 2083*cdf0e10cSrcweir 2084*cdf0e10cSrcweir sal_Int32 nTargetYear; 2085*cdf0e10cSrcweir if( bNeg ) 2086*cdf0e10cSrcweir { 2087*cdf0e10cSrcweir nTargetMonth = nMonth - nMonthAdd; 2088*cdf0e10cSrcweir if( nTargetMonth <= 0 ) 2089*cdf0e10cSrcweir { 2090*cdf0e10cSrcweir nTargetMonth += 12; 2091*cdf0e10cSrcweir nYearsAdd++; 2092*cdf0e10cSrcweir } 2093*cdf0e10cSrcweir nTargetYear = (sal_Int32)nYear - nYearsAdd; 2094*cdf0e10cSrcweir } 2095*cdf0e10cSrcweir else 2096*cdf0e10cSrcweir { 2097*cdf0e10cSrcweir nTargetMonth = nMonth + nMonthAdd; 2098*cdf0e10cSrcweir if( nTargetMonth > 12 ) 2099*cdf0e10cSrcweir { 2100*cdf0e10cSrcweir nTargetMonth -= 12; 2101*cdf0e10cSrcweir nYearsAdd++; 2102*cdf0e10cSrcweir } 2103*cdf0e10cSrcweir nTargetYear = (sal_Int32)nYear + nYearsAdd; 2104*cdf0e10cSrcweir } 2105*cdf0e10cSrcweir nTargetYear16 = limitToINT16( nTargetYear ); 2106*cdf0e10cSrcweir bOk = implDateSerial( nTargetYear16, nTargetMonth, nDay, dNewDate ); 2107*cdf0e10cSrcweir break; 2108*cdf0e10cSrcweir } 2109*cdf0e10cSrcweir default: break; 2110*cdf0e10cSrcweir } 2111*cdf0e10cSrcweir 2112*cdf0e10cSrcweir if( bOk ) 2113*cdf0e10cSrcweir { 2114*cdf0e10cSrcweir // Overflow? 2115*cdf0e10cSrcweir sal_Int16 nNewYear, nNewMonth, nNewDay; 2116*cdf0e10cSrcweir implGetDayMonthYear( nNewYear, nNewMonth, nNewDay, dNewDate ); 2117*cdf0e10cSrcweir if( nNewYear > 9999 || nNewYear < 100 ) 2118*cdf0e10cSrcweir { 2119*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 2120*cdf0e10cSrcweir return; 2121*cdf0e10cSrcweir } 2122*cdf0e10cSrcweir sal_Int16 nCorrectionDay = nDay; 2123*cdf0e10cSrcweir while( nNewMonth > nTargetMonth ) 2124*cdf0e10cSrcweir { 2125*cdf0e10cSrcweir nCorrectionDay--; 2126*cdf0e10cSrcweir implDateSerial( nTargetYear16, nTargetMonth, nCorrectionDay, dNewDate ); 2127*cdf0e10cSrcweir implGetDayMonthYear( nNewYear, nNewMonth, nNewDay, dNewDate ); 2128*cdf0e10cSrcweir } 2129*cdf0e10cSrcweir dNewDate += dHoursMinutesSeconds; 2130*cdf0e10cSrcweir } 2131*cdf0e10cSrcweir } 2132*cdf0e10cSrcweir 2133*cdf0e10cSrcweir rPar.Get(0)->PutDate( dNewDate ); 2134*cdf0e10cSrcweir } 2135*cdf0e10cSrcweir 2136*cdf0e10cSrcweir inline double RoundImpl( double d ) 2137*cdf0e10cSrcweir { 2138*cdf0e10cSrcweir return ( d >= 0 ) ? floor( d + 0.5 ) : -floor( -d + 0.5 ); 2139*cdf0e10cSrcweir } 2140*cdf0e10cSrcweir 2141*cdf0e10cSrcweir RTLFUNC(DateDiff) 2142*cdf0e10cSrcweir { 2143*cdf0e10cSrcweir (void)pBasic; 2144*cdf0e10cSrcweir (void)bWrite; 2145*cdf0e10cSrcweir 2146*cdf0e10cSrcweir // DateDiff(interval, date1, date2[, firstdayofweek[, firstweekofyear]]) 2147*cdf0e10cSrcweir 2148*cdf0e10cSrcweir sal_uInt16 nParCount = rPar.Count(); 2149*cdf0e10cSrcweir if( nParCount < 4 || nParCount > 6 ) 2150*cdf0e10cSrcweir { 2151*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 2152*cdf0e10cSrcweir return; 2153*cdf0e10cSrcweir } 2154*cdf0e10cSrcweir 2155*cdf0e10cSrcweir String aStringCode = rPar.Get(1)->GetString(); 2156*cdf0e10cSrcweir IntervalInfo* pInfo = getIntervalInfo( aStringCode ); 2157*cdf0e10cSrcweir if( !pInfo ) 2158*cdf0e10cSrcweir { 2159*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 2160*cdf0e10cSrcweir return; 2161*cdf0e10cSrcweir } 2162*cdf0e10cSrcweir 2163*cdf0e10cSrcweir double dDate1 = rPar.Get(2)->GetDate(); 2164*cdf0e10cSrcweir double dDate2 = rPar.Get(3)->GetDate(); 2165*cdf0e10cSrcweir 2166*cdf0e10cSrcweir double dRet = 0.0; 2167*cdf0e10cSrcweir switch( pInfo->meInterval ) 2168*cdf0e10cSrcweir { 2169*cdf0e10cSrcweir case INTERVAL_YYYY: 2170*cdf0e10cSrcweir { 2171*cdf0e10cSrcweir sal_Int16 nYear1 = implGetDateYear( dDate1 ); 2172*cdf0e10cSrcweir sal_Int16 nYear2 = implGetDateYear( dDate2 ); 2173*cdf0e10cSrcweir dRet = nYear2 - nYear1; 2174*cdf0e10cSrcweir break; 2175*cdf0e10cSrcweir } 2176*cdf0e10cSrcweir case INTERVAL_Q: 2177*cdf0e10cSrcweir { 2178*cdf0e10cSrcweir sal_Int16 nYear1 = implGetDateYear( dDate1 ); 2179*cdf0e10cSrcweir sal_Int16 nYear2 = implGetDateYear( dDate2 ); 2180*cdf0e10cSrcweir sal_Int16 nQ1 = 1 + (implGetDateMonth( dDate1 ) - 1) / 3; 2181*cdf0e10cSrcweir sal_Int16 nQ2 = 1 + (implGetDateMonth( dDate2 ) - 1) / 3; 2182*cdf0e10cSrcweir sal_Int16 nQGes1 = 4 * nYear1 + nQ1; 2183*cdf0e10cSrcweir sal_Int16 nQGes2 = 4 * nYear2 + nQ2; 2184*cdf0e10cSrcweir dRet = nQGes2 - nQGes1; 2185*cdf0e10cSrcweir break; 2186*cdf0e10cSrcweir } 2187*cdf0e10cSrcweir case INTERVAL_M: 2188*cdf0e10cSrcweir { 2189*cdf0e10cSrcweir sal_Int16 nYear1 = implGetDateYear( dDate1 ); 2190*cdf0e10cSrcweir sal_Int16 nYear2 = implGetDateYear( dDate2 ); 2191*cdf0e10cSrcweir sal_Int16 nMonth1 = implGetDateMonth( dDate1 ); 2192*cdf0e10cSrcweir sal_Int16 nMonth2 = implGetDateMonth( dDate2 ); 2193*cdf0e10cSrcweir sal_Int16 nMonthGes1 = 12 * nYear1 + nMonth1; 2194*cdf0e10cSrcweir sal_Int16 nMonthGes2 = 12 * nYear2 + nMonth2; 2195*cdf0e10cSrcweir dRet = nMonthGes2 - nMonthGes1; 2196*cdf0e10cSrcweir break; 2197*cdf0e10cSrcweir } 2198*cdf0e10cSrcweir case INTERVAL_Y: 2199*cdf0e10cSrcweir case INTERVAL_D: 2200*cdf0e10cSrcweir { 2201*cdf0e10cSrcweir double dDays1 = floor( dDate1 ); 2202*cdf0e10cSrcweir double dDays2 = floor( dDate2 ); 2203*cdf0e10cSrcweir dRet = dDays2 - dDays1; 2204*cdf0e10cSrcweir break; 2205*cdf0e10cSrcweir } 2206*cdf0e10cSrcweir case INTERVAL_W: 2207*cdf0e10cSrcweir case INTERVAL_WW: 2208*cdf0e10cSrcweir { 2209*cdf0e10cSrcweir double dDays1 = floor( dDate1 ); 2210*cdf0e10cSrcweir double dDays2 = floor( dDate2 ); 2211*cdf0e10cSrcweir if( pInfo->meInterval == INTERVAL_WW ) 2212*cdf0e10cSrcweir { 2213*cdf0e10cSrcweir sal_Int16 nFirstDay = 1; // Default 2214*cdf0e10cSrcweir if( nParCount >= 5 ) 2215*cdf0e10cSrcweir { 2216*cdf0e10cSrcweir nFirstDay = rPar.Get(4)->GetInteger(); 2217*cdf0e10cSrcweir if( nFirstDay < 0 || nFirstDay > 7 ) 2218*cdf0e10cSrcweir { 2219*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 2220*cdf0e10cSrcweir return; 2221*cdf0e10cSrcweir } 2222*cdf0e10cSrcweir if( nFirstDay == 0 ) 2223*cdf0e10cSrcweir { 2224*cdf0e10cSrcweir Reference< XCalendar > xCalendar = getLocaleCalendar(); 2225*cdf0e10cSrcweir if( !xCalendar.is() ) 2226*cdf0e10cSrcweir { 2227*cdf0e10cSrcweir StarBASIC::Error( SbERR_INTERNAL_ERROR ); 2228*cdf0e10cSrcweir return; 2229*cdf0e10cSrcweir } 2230*cdf0e10cSrcweir nFirstDay = sal_Int16( xCalendar->getFirstDayOfWeek() + 1 ); 2231*cdf0e10cSrcweir } 2232*cdf0e10cSrcweir } 2233*cdf0e10cSrcweir sal_Int16 nDay1 = implGetWeekDay( dDate1 ); 2234*cdf0e10cSrcweir sal_Int16 nDay1_Diff = nDay1 - nFirstDay; 2235*cdf0e10cSrcweir if( nDay1_Diff < 0 ) 2236*cdf0e10cSrcweir nDay1_Diff += 7; 2237*cdf0e10cSrcweir dDays1 -= nDay1_Diff; 2238*cdf0e10cSrcweir 2239*cdf0e10cSrcweir sal_Int16 nDay2 = implGetWeekDay( dDate2 ); 2240*cdf0e10cSrcweir sal_Int16 nDay2_Diff = nDay2 - nFirstDay; 2241*cdf0e10cSrcweir if( nDay2_Diff < 0 ) 2242*cdf0e10cSrcweir nDay2_Diff += 7; 2243*cdf0e10cSrcweir dDays2 -= nDay2_Diff; 2244*cdf0e10cSrcweir } 2245*cdf0e10cSrcweir 2246*cdf0e10cSrcweir double dDiff = dDays2 - dDays1; 2247*cdf0e10cSrcweir dRet = ( dDiff >= 0 ) ? floor( dDiff / 7.0 ) : -floor( -dDiff / 7.0 ); 2248*cdf0e10cSrcweir break; 2249*cdf0e10cSrcweir } 2250*cdf0e10cSrcweir case INTERVAL_H: 2251*cdf0e10cSrcweir { 2252*cdf0e10cSrcweir double dFactor = 24.0; 2253*cdf0e10cSrcweir dRet = RoundImpl( dFactor * (dDate2 - dDate1) ); 2254*cdf0e10cSrcweir break; 2255*cdf0e10cSrcweir } 2256*cdf0e10cSrcweir case INTERVAL_N: 2257*cdf0e10cSrcweir { 2258*cdf0e10cSrcweir double dFactor =1440.0; 2259*cdf0e10cSrcweir dRet = RoundImpl( dFactor * (dDate2 - dDate1) ); 2260*cdf0e10cSrcweir break; 2261*cdf0e10cSrcweir } 2262*cdf0e10cSrcweir case INTERVAL_S: 2263*cdf0e10cSrcweir { 2264*cdf0e10cSrcweir double dFactor = 86400.0; 2265*cdf0e10cSrcweir dRet = RoundImpl( dFactor * (dDate2 - dDate1) ); 2266*cdf0e10cSrcweir break; 2267*cdf0e10cSrcweir } 2268*cdf0e10cSrcweir case INTERVAL_NONE: 2269*cdf0e10cSrcweir break; 2270*cdf0e10cSrcweir } 2271*cdf0e10cSrcweir rPar.Get(0)->PutDouble( dRet ); 2272*cdf0e10cSrcweir } 2273*cdf0e10cSrcweir 2274*cdf0e10cSrcweir double implGetDateOfFirstDayInFirstWeek 2275*cdf0e10cSrcweir ( sal_Int16 nYear, sal_Int16& nFirstDay, sal_Int16& nFirstWeek, bool* pbError = NULL ) 2276*cdf0e10cSrcweir { 2277*cdf0e10cSrcweir SbError nError = 0; 2278*cdf0e10cSrcweir if( nFirstDay < 0 || nFirstDay > 7 ) 2279*cdf0e10cSrcweir nError = SbERR_BAD_ARGUMENT; 2280*cdf0e10cSrcweir 2281*cdf0e10cSrcweir if( nFirstWeek < 0 || nFirstWeek > 3 ) 2282*cdf0e10cSrcweir nError = SbERR_BAD_ARGUMENT; 2283*cdf0e10cSrcweir 2284*cdf0e10cSrcweir Reference< XCalendar > xCalendar; 2285*cdf0e10cSrcweir if( nFirstDay == 0 || nFirstWeek == 0 ) 2286*cdf0e10cSrcweir { 2287*cdf0e10cSrcweir xCalendar = getLocaleCalendar(); 2288*cdf0e10cSrcweir if( !xCalendar.is() ) 2289*cdf0e10cSrcweir nError = SbERR_BAD_ARGUMENT; 2290*cdf0e10cSrcweir } 2291*cdf0e10cSrcweir 2292*cdf0e10cSrcweir if( nError != 0 ) 2293*cdf0e10cSrcweir { 2294*cdf0e10cSrcweir StarBASIC::Error( nError ); 2295*cdf0e10cSrcweir if( pbError ) 2296*cdf0e10cSrcweir *pbError = true; 2297*cdf0e10cSrcweir return 0.0; 2298*cdf0e10cSrcweir } 2299*cdf0e10cSrcweir 2300*cdf0e10cSrcweir if( nFirstDay == 0 ) 2301*cdf0e10cSrcweir nFirstDay = sal_Int16( xCalendar->getFirstDayOfWeek() + 1 ); 2302*cdf0e10cSrcweir 2303*cdf0e10cSrcweir sal_Int16 nFirstWeekMinDays = 0; // Not used for vbFirstJan1 = default 2304*cdf0e10cSrcweir if( nFirstWeek == 0 ) 2305*cdf0e10cSrcweir { 2306*cdf0e10cSrcweir nFirstWeekMinDays = xCalendar->getMinimumNumberOfDaysForFirstWeek(); 2307*cdf0e10cSrcweir if( nFirstWeekMinDays == 1 ) 2308*cdf0e10cSrcweir { 2309*cdf0e10cSrcweir nFirstWeekMinDays = 0; 2310*cdf0e10cSrcweir nFirstWeek = 1; 2311*cdf0e10cSrcweir } 2312*cdf0e10cSrcweir else if( nFirstWeekMinDays == 4 ) 2313*cdf0e10cSrcweir nFirstWeek = 2; 2314*cdf0e10cSrcweir else if( nFirstWeekMinDays == 7 ) 2315*cdf0e10cSrcweir nFirstWeek = 3; 2316*cdf0e10cSrcweir } 2317*cdf0e10cSrcweir else if( nFirstWeek == 2 ) 2318*cdf0e10cSrcweir nFirstWeekMinDays = 4; // vbFirstFourDays 2319*cdf0e10cSrcweir else if( nFirstWeek == 3 ) 2320*cdf0e10cSrcweir nFirstWeekMinDays = 7; // vbFirstFourDays 2321*cdf0e10cSrcweir 2322*cdf0e10cSrcweir double dBaseDate; 2323*cdf0e10cSrcweir implDateSerial( nYear, 1, 1, dBaseDate ); 2324*cdf0e10cSrcweir double dRetDate = dBaseDate; 2325*cdf0e10cSrcweir 2326*cdf0e10cSrcweir sal_Int16 nWeekDay0101 = implGetWeekDay( dBaseDate ); 2327*cdf0e10cSrcweir sal_Int16 nDayDiff = nWeekDay0101 - nFirstDay; 2328*cdf0e10cSrcweir if( nDayDiff < 0 ) 2329*cdf0e10cSrcweir nDayDiff += 7; 2330*cdf0e10cSrcweir 2331*cdf0e10cSrcweir if( nFirstWeekMinDays ) 2332*cdf0e10cSrcweir { 2333*cdf0e10cSrcweir sal_Int16 nThisWeeksDaysInYearCount = 7 - nDayDiff; 2334*cdf0e10cSrcweir if( nThisWeeksDaysInYearCount < nFirstWeekMinDays ) 2335*cdf0e10cSrcweir nDayDiff -= 7; 2336*cdf0e10cSrcweir } 2337*cdf0e10cSrcweir dRetDate = dBaseDate - nDayDiff; 2338*cdf0e10cSrcweir return dRetDate; 2339*cdf0e10cSrcweir } 2340*cdf0e10cSrcweir 2341*cdf0e10cSrcweir RTLFUNC(DatePart) 2342*cdf0e10cSrcweir { 2343*cdf0e10cSrcweir (void)pBasic; 2344*cdf0e10cSrcweir (void)bWrite; 2345*cdf0e10cSrcweir 2346*cdf0e10cSrcweir // DatePart(interval, date[,firstdayofweek[, firstweekofyear]]) 2347*cdf0e10cSrcweir 2348*cdf0e10cSrcweir sal_uInt16 nParCount = rPar.Count(); 2349*cdf0e10cSrcweir if( nParCount < 3 || nParCount > 5 ) 2350*cdf0e10cSrcweir { 2351*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 2352*cdf0e10cSrcweir return; 2353*cdf0e10cSrcweir } 2354*cdf0e10cSrcweir 2355*cdf0e10cSrcweir String aStringCode = rPar.Get(1)->GetString(); 2356*cdf0e10cSrcweir IntervalInfo* pInfo = getIntervalInfo( aStringCode ); 2357*cdf0e10cSrcweir if( !pInfo ) 2358*cdf0e10cSrcweir { 2359*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 2360*cdf0e10cSrcweir return; 2361*cdf0e10cSrcweir } 2362*cdf0e10cSrcweir 2363*cdf0e10cSrcweir double dDate = rPar.Get(2)->GetDate(); 2364*cdf0e10cSrcweir 2365*cdf0e10cSrcweir sal_Int32 nRet = 0; 2366*cdf0e10cSrcweir switch( pInfo->meInterval ) 2367*cdf0e10cSrcweir { 2368*cdf0e10cSrcweir case INTERVAL_YYYY: 2369*cdf0e10cSrcweir { 2370*cdf0e10cSrcweir nRet = implGetDateYear( dDate ); 2371*cdf0e10cSrcweir break; 2372*cdf0e10cSrcweir } 2373*cdf0e10cSrcweir case INTERVAL_Q: 2374*cdf0e10cSrcweir { 2375*cdf0e10cSrcweir nRet = 1 + (implGetDateMonth( dDate ) - 1) / 3; 2376*cdf0e10cSrcweir break; 2377*cdf0e10cSrcweir } 2378*cdf0e10cSrcweir case INTERVAL_M: 2379*cdf0e10cSrcweir { 2380*cdf0e10cSrcweir nRet = implGetDateMonth( dDate ); 2381*cdf0e10cSrcweir break; 2382*cdf0e10cSrcweir } 2383*cdf0e10cSrcweir case INTERVAL_Y: 2384*cdf0e10cSrcweir { 2385*cdf0e10cSrcweir sal_Int16 nYear = implGetDateYear( dDate ); 2386*cdf0e10cSrcweir double dBaseDate; 2387*cdf0e10cSrcweir implDateSerial( nYear, 1, 1, dBaseDate ); 2388*cdf0e10cSrcweir nRet = 1 + sal_Int32( dDate - dBaseDate ); 2389*cdf0e10cSrcweir break; 2390*cdf0e10cSrcweir } 2391*cdf0e10cSrcweir case INTERVAL_D: 2392*cdf0e10cSrcweir { 2393*cdf0e10cSrcweir nRet = implGetDateDay( dDate ); 2394*cdf0e10cSrcweir break; 2395*cdf0e10cSrcweir } 2396*cdf0e10cSrcweir case INTERVAL_W: 2397*cdf0e10cSrcweir { 2398*cdf0e10cSrcweir bool bFirstDay = false; 2399*cdf0e10cSrcweir sal_Int16 nFirstDay = 1; // Default 2400*cdf0e10cSrcweir if( nParCount >= 4 ) 2401*cdf0e10cSrcweir { 2402*cdf0e10cSrcweir nFirstDay = rPar.Get(3)->GetInteger(); 2403*cdf0e10cSrcweir bFirstDay = true; 2404*cdf0e10cSrcweir } 2405*cdf0e10cSrcweir nRet = implGetWeekDay( dDate, bFirstDay, nFirstDay ); 2406*cdf0e10cSrcweir break; 2407*cdf0e10cSrcweir } 2408*cdf0e10cSrcweir case INTERVAL_WW: 2409*cdf0e10cSrcweir { 2410*cdf0e10cSrcweir sal_Int16 nFirstDay = 1; // Default 2411*cdf0e10cSrcweir if( nParCount >= 4 ) 2412*cdf0e10cSrcweir nFirstDay = rPar.Get(3)->GetInteger(); 2413*cdf0e10cSrcweir 2414*cdf0e10cSrcweir sal_Int16 nFirstWeek = 1; // Default 2415*cdf0e10cSrcweir if( nParCount == 5 ) 2416*cdf0e10cSrcweir nFirstWeek = rPar.Get(4)->GetInteger(); 2417*cdf0e10cSrcweir 2418*cdf0e10cSrcweir sal_Int16 nYear = implGetDateYear( dDate ); 2419*cdf0e10cSrcweir bool bError = false; 2420*cdf0e10cSrcweir double dYearFirstDay = implGetDateOfFirstDayInFirstWeek( nYear, nFirstDay, nFirstWeek, &bError ); 2421*cdf0e10cSrcweir if( !bError ) 2422*cdf0e10cSrcweir { 2423*cdf0e10cSrcweir if( dYearFirstDay > dDate ) 2424*cdf0e10cSrcweir { 2425*cdf0e10cSrcweir // Date belongs to last year's week 2426*cdf0e10cSrcweir dYearFirstDay = implGetDateOfFirstDayInFirstWeek( nYear - 1, nFirstDay, nFirstWeek ); 2427*cdf0e10cSrcweir } 2428*cdf0e10cSrcweir else if( nFirstWeek != 1 ) 2429*cdf0e10cSrcweir { 2430*cdf0e10cSrcweir // Check if date belongs to next year 2431*cdf0e10cSrcweir double dNextYearFirstDay = implGetDateOfFirstDayInFirstWeek( nYear + 1, nFirstDay, nFirstWeek ); 2432*cdf0e10cSrcweir if( dDate >= dNextYearFirstDay ) 2433*cdf0e10cSrcweir dYearFirstDay = dNextYearFirstDay; 2434*cdf0e10cSrcweir } 2435*cdf0e10cSrcweir 2436*cdf0e10cSrcweir // Calculate week 2437*cdf0e10cSrcweir double dDiff = dDate - dYearFirstDay; 2438*cdf0e10cSrcweir nRet = 1 + sal_Int32( dDiff / 7 ); 2439*cdf0e10cSrcweir } 2440*cdf0e10cSrcweir break; 2441*cdf0e10cSrcweir } 2442*cdf0e10cSrcweir case INTERVAL_H: 2443*cdf0e10cSrcweir { 2444*cdf0e10cSrcweir nRet = implGetHour( dDate ); 2445*cdf0e10cSrcweir break; 2446*cdf0e10cSrcweir } 2447*cdf0e10cSrcweir case INTERVAL_N: 2448*cdf0e10cSrcweir { 2449*cdf0e10cSrcweir nRet = implGetMinute( dDate ); 2450*cdf0e10cSrcweir break; 2451*cdf0e10cSrcweir } 2452*cdf0e10cSrcweir case INTERVAL_S: 2453*cdf0e10cSrcweir { 2454*cdf0e10cSrcweir nRet = implGetSecond( dDate ); 2455*cdf0e10cSrcweir break; 2456*cdf0e10cSrcweir } 2457*cdf0e10cSrcweir case INTERVAL_NONE: 2458*cdf0e10cSrcweir break; 2459*cdf0e10cSrcweir } 2460*cdf0e10cSrcweir rPar.Get(0)->PutLong( nRet ); 2461*cdf0e10cSrcweir } 2462*cdf0e10cSrcweir 2463*cdf0e10cSrcweir // FormatDateTime(Date[,NamedFormat]) 2464*cdf0e10cSrcweir RTLFUNC(FormatDateTime) 2465*cdf0e10cSrcweir { 2466*cdf0e10cSrcweir (void)pBasic; 2467*cdf0e10cSrcweir (void)bWrite; 2468*cdf0e10cSrcweir 2469*cdf0e10cSrcweir sal_uInt16 nParCount = rPar.Count(); 2470*cdf0e10cSrcweir if( nParCount < 2 || nParCount > 3 ) 2471*cdf0e10cSrcweir { 2472*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 2473*cdf0e10cSrcweir return; 2474*cdf0e10cSrcweir } 2475*cdf0e10cSrcweir 2476*cdf0e10cSrcweir double dDate = rPar.Get(1)->GetDate(); 2477*cdf0e10cSrcweir sal_Int16 nNamedFormat = 0; 2478*cdf0e10cSrcweir if( nParCount > 2 ) 2479*cdf0e10cSrcweir { 2480*cdf0e10cSrcweir nNamedFormat = rPar.Get(2)->GetInteger(); 2481*cdf0e10cSrcweir if( nNamedFormat < 0 || nNamedFormat > 4 ) 2482*cdf0e10cSrcweir { 2483*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 2484*cdf0e10cSrcweir return; 2485*cdf0e10cSrcweir } 2486*cdf0e10cSrcweir } 2487*cdf0e10cSrcweir 2488*cdf0e10cSrcweir Reference< XCalendar > xCalendar = getLocaleCalendar(); 2489*cdf0e10cSrcweir if( !xCalendar.is() ) 2490*cdf0e10cSrcweir { 2491*cdf0e10cSrcweir StarBASIC::Error( SbERR_INTERNAL_ERROR ); 2492*cdf0e10cSrcweir return; 2493*cdf0e10cSrcweir } 2494*cdf0e10cSrcweir 2495*cdf0e10cSrcweir String aRetStr; 2496*cdf0e10cSrcweir SbxVariableRef pSbxVar = new SbxVariable( SbxSTRING ); 2497*cdf0e10cSrcweir switch( nNamedFormat ) 2498*cdf0e10cSrcweir { 2499*cdf0e10cSrcweir // GeneralDate: 2500*cdf0e10cSrcweir // Display a date and/or time. If there is a date part, 2501*cdf0e10cSrcweir // display it as a short date. If there is a time part, 2502*cdf0e10cSrcweir // display it as a long time. If present, both parts are displayed. 2503*cdf0e10cSrcweir 2504*cdf0e10cSrcweir // 12/21/2004 11:24:50 AM 2505*cdf0e10cSrcweir // 21.12.2004 12:13:51 2506*cdf0e10cSrcweir case 0: 2507*cdf0e10cSrcweir pSbxVar->PutDate( dDate ); 2508*cdf0e10cSrcweir aRetStr = pSbxVar->GetString(); 2509*cdf0e10cSrcweir break; 2510*cdf0e10cSrcweir 2511*cdf0e10cSrcweir // LongDate: Display a date using the long date format specified 2512*cdf0e10cSrcweir // in your computer's regional settings. 2513*cdf0e10cSrcweir // Tuesday, December 21, 2004 2514*cdf0e10cSrcweir // Dienstag, 21. December 2004 2515*cdf0e10cSrcweir case 1: 2516*cdf0e10cSrcweir { 2517*cdf0e10cSrcweir SvNumberFormatter* pFormatter = NULL; 2518*cdf0e10cSrcweir if( pINST ) 2519*cdf0e10cSrcweir pFormatter = pINST->GetNumberFormatter(); 2520*cdf0e10cSrcweir else 2521*cdf0e10cSrcweir { 2522*cdf0e10cSrcweir sal_uInt32 n; // Dummy 2523*cdf0e10cSrcweir SbiInstance::PrepareNumberFormatter( pFormatter, n, n, n ); 2524*cdf0e10cSrcweir } 2525*cdf0e10cSrcweir 2526*cdf0e10cSrcweir LanguageType eLangType = GetpApp()->GetSettings().GetLanguage(); 2527*cdf0e10cSrcweir sal_uIntPtr nIndex = pFormatter->GetFormatIndex( NF_DATE_SYSTEM_LONG, eLangType ); 2528*cdf0e10cSrcweir Color* pCol; 2529*cdf0e10cSrcweir pFormatter->GetOutputString( dDate, nIndex, aRetStr, &pCol ); 2530*cdf0e10cSrcweir 2531*cdf0e10cSrcweir if( !pINST ) 2532*cdf0e10cSrcweir delete pFormatter; 2533*cdf0e10cSrcweir 2534*cdf0e10cSrcweir break; 2535*cdf0e10cSrcweir } 2536*cdf0e10cSrcweir 2537*cdf0e10cSrcweir // ShortDate: Display a date using the short date format specified 2538*cdf0e10cSrcweir // in your computer's regional settings. 2539*cdf0e10cSrcweir // 12/21/2004 2540*cdf0e10cSrcweir // 21.12.2004 2541*cdf0e10cSrcweir case 2: 2542*cdf0e10cSrcweir pSbxVar->PutDate( floor(dDate) ); 2543*cdf0e10cSrcweir aRetStr = pSbxVar->GetString(); 2544*cdf0e10cSrcweir break; 2545*cdf0e10cSrcweir 2546*cdf0e10cSrcweir // LongTime: Display a time using the time format specified 2547*cdf0e10cSrcweir // in your computer's regional settings. 2548*cdf0e10cSrcweir // 11:24:50 AM 2549*cdf0e10cSrcweir // 12:13:51 2550*cdf0e10cSrcweir case 3: 2551*cdf0e10cSrcweir // ShortTime: Display a time using the 24-hour format (hh:mm). 2552*cdf0e10cSrcweir // 11:24 2553*cdf0e10cSrcweir case 4: 2554*cdf0e10cSrcweir double n; 2555*cdf0e10cSrcweir double dTime = modf( dDate, &n ); 2556*cdf0e10cSrcweir pSbxVar->PutDate( dTime ); 2557*cdf0e10cSrcweir if( nNamedFormat == 3 ) 2558*cdf0e10cSrcweir aRetStr = pSbxVar->GetString(); 2559*cdf0e10cSrcweir else 2560*cdf0e10cSrcweir aRetStr = pSbxVar->GetString().Copy( 0, 5 ); 2561*cdf0e10cSrcweir break; 2562*cdf0e10cSrcweir } 2563*cdf0e10cSrcweir 2564*cdf0e10cSrcweir rPar.Get(0)->PutString( aRetStr ); 2565*cdf0e10cSrcweir } 2566*cdf0e10cSrcweir 2567*cdf0e10cSrcweir RTLFUNC(Round) 2568*cdf0e10cSrcweir { 2569*cdf0e10cSrcweir (void)pBasic; 2570*cdf0e10cSrcweir (void)bWrite; 2571*cdf0e10cSrcweir 2572*cdf0e10cSrcweir sal_uInt16 nParCount = rPar.Count(); 2573*cdf0e10cSrcweir if( nParCount != 2 && nParCount != 3 ) 2574*cdf0e10cSrcweir { 2575*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 2576*cdf0e10cSrcweir return; 2577*cdf0e10cSrcweir } 2578*cdf0e10cSrcweir 2579*cdf0e10cSrcweir SbxVariable *pSbxVariable = rPar.Get(1); 2580*cdf0e10cSrcweir double dVal = pSbxVariable->GetDouble(); 2581*cdf0e10cSrcweir double dRes = 0.0; 2582*cdf0e10cSrcweir if( dVal != 0.0 ) 2583*cdf0e10cSrcweir { 2584*cdf0e10cSrcweir bool bNeg = false; 2585*cdf0e10cSrcweir if( dVal < 0.0 ) 2586*cdf0e10cSrcweir { 2587*cdf0e10cSrcweir bNeg = true; 2588*cdf0e10cSrcweir dVal = -dVal; 2589*cdf0e10cSrcweir } 2590*cdf0e10cSrcweir 2591*cdf0e10cSrcweir sal_Int16 numdecimalplaces = 0; 2592*cdf0e10cSrcweir if( nParCount == 3 ) 2593*cdf0e10cSrcweir { 2594*cdf0e10cSrcweir numdecimalplaces = rPar.Get(2)->GetInteger(); 2595*cdf0e10cSrcweir if( numdecimalplaces < 0 || numdecimalplaces > 22 ) 2596*cdf0e10cSrcweir { 2597*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 2598*cdf0e10cSrcweir return; 2599*cdf0e10cSrcweir } 2600*cdf0e10cSrcweir } 2601*cdf0e10cSrcweir 2602*cdf0e10cSrcweir if( numdecimalplaces == 0 ) 2603*cdf0e10cSrcweir { 2604*cdf0e10cSrcweir dRes = floor( dVal + 0.5 ); 2605*cdf0e10cSrcweir } 2606*cdf0e10cSrcweir else 2607*cdf0e10cSrcweir { 2608*cdf0e10cSrcweir double dFactor = pow( 10.0, numdecimalplaces ); 2609*cdf0e10cSrcweir dVal *= dFactor; 2610*cdf0e10cSrcweir dRes = floor( dVal + 0.5 ); 2611*cdf0e10cSrcweir dRes /= dFactor; 2612*cdf0e10cSrcweir } 2613*cdf0e10cSrcweir 2614*cdf0e10cSrcweir if( bNeg ) 2615*cdf0e10cSrcweir dRes = -dRes; 2616*cdf0e10cSrcweir } 2617*cdf0e10cSrcweir rPar.Get(0)->PutDouble( dRes ); 2618*cdf0e10cSrcweir } 2619*cdf0e10cSrcweir 2620*cdf0e10cSrcweir RTLFUNC(StrReverse) 2621*cdf0e10cSrcweir { 2622*cdf0e10cSrcweir (void)pBasic; 2623*cdf0e10cSrcweir (void)bWrite; 2624*cdf0e10cSrcweir 2625*cdf0e10cSrcweir if ( rPar.Count() != 2 ) 2626*cdf0e10cSrcweir { 2627*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 2628*cdf0e10cSrcweir return; 2629*cdf0e10cSrcweir } 2630*cdf0e10cSrcweir 2631*cdf0e10cSrcweir SbxVariable *pSbxVariable = rPar.Get(1); 2632*cdf0e10cSrcweir if( pSbxVariable->IsNull() ) 2633*cdf0e10cSrcweir { 2634*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 2635*cdf0e10cSrcweir return; 2636*cdf0e10cSrcweir } 2637*cdf0e10cSrcweir 2638*cdf0e10cSrcweir String aStr = pSbxVariable->GetString(); 2639*cdf0e10cSrcweir aStr.Reverse(); 2640*cdf0e10cSrcweir rPar.Get(0)->PutString( aStr ); 2641*cdf0e10cSrcweir } 2642*cdf0e10cSrcweir 2643*cdf0e10cSrcweir RTLFUNC(CompatibilityMode) 2644*cdf0e10cSrcweir { 2645*cdf0e10cSrcweir (void)pBasic; 2646*cdf0e10cSrcweir (void)bWrite; 2647*cdf0e10cSrcweir 2648*cdf0e10cSrcweir bool bEnabled = false; 2649*cdf0e10cSrcweir sal_uInt16 nCount = rPar.Count(); 2650*cdf0e10cSrcweir if ( nCount != 1 && nCount != 2 ) 2651*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 2652*cdf0e10cSrcweir 2653*cdf0e10cSrcweir SbiInstance* pInst = pINST; 2654*cdf0e10cSrcweir if( pInst ) 2655*cdf0e10cSrcweir { 2656*cdf0e10cSrcweir if ( nCount == 2 ) 2657*cdf0e10cSrcweir pInst->EnableCompatibility( rPar.Get(1)->GetBool() ); 2658*cdf0e10cSrcweir 2659*cdf0e10cSrcweir bEnabled = pInst->IsCompatibility(); 2660*cdf0e10cSrcweir } 2661*cdf0e10cSrcweir rPar.Get(0)->PutBool( bEnabled ); 2662*cdf0e10cSrcweir } 2663*cdf0e10cSrcweir 2664*cdf0e10cSrcweir RTLFUNC(Input) 2665*cdf0e10cSrcweir { 2666*cdf0e10cSrcweir (void)pBasic; 2667*cdf0e10cSrcweir (void)bWrite; 2668*cdf0e10cSrcweir 2669*cdf0e10cSrcweir // 2 parameters needed 2670*cdf0e10cSrcweir if ( rPar.Count() < 3 ) 2671*cdf0e10cSrcweir { 2672*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 2673*cdf0e10cSrcweir return; 2674*cdf0e10cSrcweir } 2675*cdf0e10cSrcweir 2676*cdf0e10cSrcweir sal_uInt16 nByteCount = rPar.Get(1)->GetUShort(); 2677*cdf0e10cSrcweir sal_Int16 nFileNumber = rPar.Get(2)->GetInteger(); 2678*cdf0e10cSrcweir 2679*cdf0e10cSrcweir SbiIoSystem* pIosys = pINST->GetIoSystem(); 2680*cdf0e10cSrcweir SbiStream* pSbStrm = pIosys->GetStream( nFileNumber ); 2681*cdf0e10cSrcweir if ( !pSbStrm || !(pSbStrm->GetMode() & (SBSTRM_BINARY | SBSTRM_INPUT)) ) 2682*cdf0e10cSrcweir { 2683*cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_CHANNEL ); 2684*cdf0e10cSrcweir return; 2685*cdf0e10cSrcweir } 2686*cdf0e10cSrcweir 2687*cdf0e10cSrcweir ByteString aByteBuffer; 2688*cdf0e10cSrcweir SbError err = pSbStrm->Read( aByteBuffer, nByteCount, true ); 2689*cdf0e10cSrcweir if( !err ) 2690*cdf0e10cSrcweir err = pIosys->GetError(); 2691*cdf0e10cSrcweir 2692*cdf0e10cSrcweir if( err ) 2693*cdf0e10cSrcweir { 2694*cdf0e10cSrcweir StarBASIC::Error( err ); 2695*cdf0e10cSrcweir return; 2696*cdf0e10cSrcweir } 2697*cdf0e10cSrcweir rPar.Get(0)->PutString( String( aByteBuffer, gsl_getSystemTextEncoding() ) ); 2698*cdf0e10cSrcweir } 2699*cdf0e10cSrcweir 2700*cdf0e10cSrcweir // #115824 2701*cdf0e10cSrcweir RTLFUNC(Me) 2702*cdf0e10cSrcweir { 2703*cdf0e10cSrcweir (void)pBasic; 2704*cdf0e10cSrcweir (void)bWrite; 2705*cdf0e10cSrcweir 2706*cdf0e10cSrcweir SbModule* pActiveModule = pINST->GetActiveModule(); 2707*cdf0e10cSrcweir SbClassModuleObject* pClassModuleObject = PTR_CAST(SbClassModuleObject,pActiveModule); 2708*cdf0e10cSrcweir SbxVariableRef refVar = rPar.Get(0); 2709*cdf0e10cSrcweir if( pClassModuleObject == NULL ) 2710*cdf0e10cSrcweir { 2711*cdf0e10cSrcweir SbObjModule* pMod = PTR_CAST(SbObjModule,pActiveModule); 2712*cdf0e10cSrcweir if ( pMod ) 2713*cdf0e10cSrcweir refVar->PutObject( pMod ); 2714*cdf0e10cSrcweir else 2715*cdf0e10cSrcweir StarBASIC::Error( SbERR_INVALID_USAGE_OBJECT ); 2716*cdf0e10cSrcweir } 2717*cdf0e10cSrcweir else 2718*cdf0e10cSrcweir refVar->PutObject( pClassModuleObject ); 2719*cdf0e10cSrcweir } 2720*cdf0e10cSrcweir 2721