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 #include <tools/errcode.hxx> 31*cdf0e10cSrcweir #include <basic/sbx.hxx> 32*cdf0e10cSrcweir #include "sbxconv.hxx" 33*cdf0e10cSrcweir #include "sbxres.hxx" 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir // AB 29.10.99 Unicode 36*cdf0e10cSrcweir #ifndef _USE_NO_NAMESPACE 37*cdf0e10cSrcweir using namespace rtl; 38*cdf0e10cSrcweir #endif 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir enum SbxBOOL ImpGetBool( const SbxValues* p ) 41*cdf0e10cSrcweir { 42*cdf0e10cSrcweir enum SbxBOOL nRes; 43*cdf0e10cSrcweir switch( +p->eType ) 44*cdf0e10cSrcweir { 45*cdf0e10cSrcweir case SbxNULL: 46*cdf0e10cSrcweir SbxBase::SetError( SbxERR_CONVERSION ); 47*cdf0e10cSrcweir case SbxEMPTY: 48*cdf0e10cSrcweir nRes = SbxFALSE; break; 49*cdf0e10cSrcweir case SbxCHAR: 50*cdf0e10cSrcweir nRes = p->nChar ? SbxTRUE : SbxFALSE; break; 51*cdf0e10cSrcweir case SbxBYTE: 52*cdf0e10cSrcweir nRes = p->nByte ? SbxTRUE : SbxFALSE; break; 53*cdf0e10cSrcweir case SbxINTEGER: 54*cdf0e10cSrcweir case SbxBOOL: 55*cdf0e10cSrcweir nRes = p->nInteger ? SbxTRUE : SbxFALSE; break; 56*cdf0e10cSrcweir case SbxERROR: 57*cdf0e10cSrcweir case SbxUSHORT: 58*cdf0e10cSrcweir nRes = p->nUShort ? SbxTRUE : SbxFALSE; break; 59*cdf0e10cSrcweir case SbxLONG: 60*cdf0e10cSrcweir nRes = p->nLong ? SbxTRUE : SbxFALSE; break; 61*cdf0e10cSrcweir case SbxULONG: 62*cdf0e10cSrcweir nRes = p->nULong ? SbxTRUE : SbxFALSE; break; 63*cdf0e10cSrcweir case SbxSINGLE: 64*cdf0e10cSrcweir nRes = p->nSingle ? SbxTRUE : SbxFALSE; break; 65*cdf0e10cSrcweir case SbxDATE: 66*cdf0e10cSrcweir case SbxDOUBLE: 67*cdf0e10cSrcweir nRes = p->nDouble ? SbxTRUE : SbxFALSE; break; 68*cdf0e10cSrcweir case SbxDECIMAL: 69*cdf0e10cSrcweir case SbxBYREF | SbxDECIMAL: 70*cdf0e10cSrcweir { 71*cdf0e10cSrcweir double dVal = 0.0; 72*cdf0e10cSrcweir if( p->pDecimal ) 73*cdf0e10cSrcweir p->pDecimal->getDouble( dVal ); 74*cdf0e10cSrcweir nRes = dVal ? SbxTRUE : SbxFALSE; 75*cdf0e10cSrcweir } 76*cdf0e10cSrcweir break; 77*cdf0e10cSrcweir case SbxSALINT64: 78*cdf0e10cSrcweir nRes = p->nInt64 ? SbxTRUE : SbxFALSE; break; 79*cdf0e10cSrcweir case SbxSALUINT64: 80*cdf0e10cSrcweir nRes = p->uInt64 ? SbxTRUE : SbxFALSE; break; 81*cdf0e10cSrcweir case SbxULONG64: 82*cdf0e10cSrcweir nRes = !!p->nULong64 ? SbxTRUE : SbxFALSE; break; 83*cdf0e10cSrcweir case SbxLONG64: 84*cdf0e10cSrcweir case SbxCURRENCY: 85*cdf0e10cSrcweir nRes = !!p->nLong64 ? SbxTRUE : SbxFALSE; break; 86*cdf0e10cSrcweir case SbxBYREF | SbxSTRING: 87*cdf0e10cSrcweir case SbxSTRING: 88*cdf0e10cSrcweir case SbxLPSTR: 89*cdf0e10cSrcweir nRes = SbxFALSE; 90*cdf0e10cSrcweir if ( p->pOUString ) 91*cdf0e10cSrcweir { 92*cdf0e10cSrcweir if( p->pOUString->equalsIgnoreAsciiCase( SbxRes( STRING_TRUE ) ) ) 93*cdf0e10cSrcweir nRes = SbxTRUE; 94*cdf0e10cSrcweir else if( !p->pOUString->equalsIgnoreAsciiCase( SbxRes( STRING_FALSE ) ) ) 95*cdf0e10cSrcweir { 96*cdf0e10cSrcweir // Jetzt kann es noch in eine Zahl konvertierbar sein 97*cdf0e10cSrcweir sal_Bool bError = sal_True; 98*cdf0e10cSrcweir double n; 99*cdf0e10cSrcweir SbxDataType t; 100*cdf0e10cSrcweir sal_uInt16 nLen = 0; 101*cdf0e10cSrcweir if( ImpScan( *p->pOUString, n, t, &nLen ) == SbxERR_OK ) 102*cdf0e10cSrcweir { 103*cdf0e10cSrcweir if( nLen == p->pOUString->getLength() ) 104*cdf0e10cSrcweir { 105*cdf0e10cSrcweir bError = sal_False; 106*cdf0e10cSrcweir if( n != 0.0 ) 107*cdf0e10cSrcweir nRes = SbxTRUE; 108*cdf0e10cSrcweir } 109*cdf0e10cSrcweir } 110*cdf0e10cSrcweir if( bError ) 111*cdf0e10cSrcweir SbxBase::SetError( SbxERR_CONVERSION ); 112*cdf0e10cSrcweir } 113*cdf0e10cSrcweir } 114*cdf0e10cSrcweir break; 115*cdf0e10cSrcweir case SbxOBJECT: 116*cdf0e10cSrcweir { 117*cdf0e10cSrcweir SbxValue* pVal = PTR_CAST(SbxValue,p->pObj); 118*cdf0e10cSrcweir if( pVal ) 119*cdf0e10cSrcweir nRes = pVal->GetBool() ? SbxTRUE : SbxFALSE; 120*cdf0e10cSrcweir else 121*cdf0e10cSrcweir { 122*cdf0e10cSrcweir SbxBase::SetError( SbxERR_NO_OBJECT ); nRes = SbxFALSE; 123*cdf0e10cSrcweir } 124*cdf0e10cSrcweir break; 125*cdf0e10cSrcweir } 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir case SbxBYREF | SbxCHAR: 128*cdf0e10cSrcweir nRes = *p->pChar ? SbxTRUE : SbxFALSE; break; 129*cdf0e10cSrcweir case SbxBYREF | SbxBYTE: 130*cdf0e10cSrcweir nRes = *p->pByte ? SbxTRUE : SbxFALSE; break; 131*cdf0e10cSrcweir case SbxBYREF | SbxINTEGER: 132*cdf0e10cSrcweir case SbxBYREF | SbxBOOL: 133*cdf0e10cSrcweir nRes = *p->pInteger ? SbxTRUE : SbxFALSE; break; 134*cdf0e10cSrcweir case SbxBYREF | SbxLONG: 135*cdf0e10cSrcweir nRes = *p->pLong ? SbxTRUE : SbxFALSE; break; 136*cdf0e10cSrcweir case SbxBYREF | SbxULONG: 137*cdf0e10cSrcweir nRes = *p->pULong ? SbxTRUE : SbxFALSE; break; 138*cdf0e10cSrcweir case SbxBYREF | SbxERROR: 139*cdf0e10cSrcweir case SbxBYREF | SbxUSHORT: 140*cdf0e10cSrcweir nRes = *p->pUShort ? SbxTRUE : SbxFALSE; break; 141*cdf0e10cSrcweir case SbxBYREF | SbxSINGLE: 142*cdf0e10cSrcweir nRes = ( *p->pSingle != 0 ) ? SbxTRUE : SbxFALSE; break; 143*cdf0e10cSrcweir case SbxBYREF | SbxDATE: 144*cdf0e10cSrcweir case SbxBYREF | SbxDOUBLE: 145*cdf0e10cSrcweir nRes = ( *p->pDouble != 0 ) ? SbxTRUE : SbxFALSE; break; 146*cdf0e10cSrcweir case SbxBYREF | SbxSALINT64: 147*cdf0e10cSrcweir nRes = ( *p->pnInt64 ) ? SbxTRUE : SbxFALSE; break; 148*cdf0e10cSrcweir case SbxBYREF | SbxSALUINT64: 149*cdf0e10cSrcweir nRes = ( *p->puInt64 ) ? SbxTRUE : SbxFALSE; break; 150*cdf0e10cSrcweir case SbxBYREF | SbxULONG64: 151*cdf0e10cSrcweir nRes = !!*p->pULong64 ? SbxTRUE : SbxFALSE; break; 152*cdf0e10cSrcweir case SbxBYREF | SbxLONG64: 153*cdf0e10cSrcweir case SbxBYREF | SbxCURRENCY: 154*cdf0e10cSrcweir nRes = !!*p->pLong64 ? SbxTRUE : SbxFALSE; break; 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir default: 157*cdf0e10cSrcweir SbxBase::SetError( SbxERR_CONVERSION ); nRes = SbxFALSE; 158*cdf0e10cSrcweir } 159*cdf0e10cSrcweir return nRes; 160*cdf0e10cSrcweir } 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir void ImpPutBool( SbxValues* p, sal_Int16 n ) 163*cdf0e10cSrcweir { 164*cdf0e10cSrcweir if( n ) 165*cdf0e10cSrcweir n = SbxTRUE; 166*cdf0e10cSrcweir switch( +p->eType ) 167*cdf0e10cSrcweir { 168*cdf0e10cSrcweir case SbxCHAR: 169*cdf0e10cSrcweir p->nChar = (xub_Unicode) n; break; 170*cdf0e10cSrcweir case SbxUINT: 171*cdf0e10cSrcweir p->nByte = (sal_uInt8) n; break; 172*cdf0e10cSrcweir case SbxINTEGER: 173*cdf0e10cSrcweir case SbxBOOL: 174*cdf0e10cSrcweir p->nInteger = n; break; 175*cdf0e10cSrcweir case SbxLONG: 176*cdf0e10cSrcweir p->nLong = n; break; 177*cdf0e10cSrcweir case SbxULONG: 178*cdf0e10cSrcweir p->nULong = (sal_uInt32) n; break; 179*cdf0e10cSrcweir case SbxERROR: 180*cdf0e10cSrcweir case SbxUSHORT: 181*cdf0e10cSrcweir p->nUShort = (sal_uInt16) n; break; 182*cdf0e10cSrcweir case SbxSINGLE: 183*cdf0e10cSrcweir p->nSingle = n; break; 184*cdf0e10cSrcweir case SbxDATE: 185*cdf0e10cSrcweir case SbxDOUBLE: 186*cdf0e10cSrcweir p->nDouble = n; break; 187*cdf0e10cSrcweir case SbxSALINT64: 188*cdf0e10cSrcweir p->nInt64 = n; break; 189*cdf0e10cSrcweir case SbxSALUINT64: 190*cdf0e10cSrcweir p->uInt64 = n; break; 191*cdf0e10cSrcweir case SbxULONG64: 192*cdf0e10cSrcweir p->nULong64.Set( (sal_uInt32)n ); break; 193*cdf0e10cSrcweir case SbxLONG64: 194*cdf0e10cSrcweir case SbxCURRENCY: 195*cdf0e10cSrcweir p->nLong64.Set( (sal_Int32)n ); break; 196*cdf0e10cSrcweir case SbxDECIMAL: 197*cdf0e10cSrcweir case SbxBYREF | SbxDECIMAL: 198*cdf0e10cSrcweir ImpCreateDecimal( p )->setInt( (sal_Int16)n ); 199*cdf0e10cSrcweir break; 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir case SbxBYREF | SbxSTRING: 202*cdf0e10cSrcweir case SbxSTRING: 203*cdf0e10cSrcweir case SbxLPSTR: 204*cdf0e10cSrcweir if ( !p->pOUString ) 205*cdf0e10cSrcweir p->pOUString = new ::rtl::OUString( SbxRes( n ? STRING_TRUE : STRING_FALSE ) ); 206*cdf0e10cSrcweir else 207*cdf0e10cSrcweir *p->pOUString = SbxRes( n ? STRING_TRUE : STRING_FALSE ); 208*cdf0e10cSrcweir break; 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir case SbxOBJECT: 211*cdf0e10cSrcweir { 212*cdf0e10cSrcweir SbxValue* pVal = PTR_CAST(SbxValue,p->pObj); 213*cdf0e10cSrcweir if( pVal ) 214*cdf0e10cSrcweir pVal->PutBool( sal_Bool( n != 0 ) ); 215*cdf0e10cSrcweir else 216*cdf0e10cSrcweir SbxBase::SetError( SbxERR_NO_OBJECT ); 217*cdf0e10cSrcweir break; 218*cdf0e10cSrcweir } 219*cdf0e10cSrcweir case SbxBYREF | SbxCHAR: 220*cdf0e10cSrcweir *p->pChar = (xub_Unicode) n; break; 221*cdf0e10cSrcweir case SbxBYREF | SbxBYTE: 222*cdf0e10cSrcweir *p->pByte = (sal_uInt8) n; break; 223*cdf0e10cSrcweir case SbxBYREF | SbxINTEGER: 224*cdf0e10cSrcweir case SbxBYREF | SbxBOOL: 225*cdf0e10cSrcweir *p->pInteger = (sal_Int16) n; break; 226*cdf0e10cSrcweir case SbxBYREF | SbxERROR: 227*cdf0e10cSrcweir case SbxBYREF | SbxUSHORT: 228*cdf0e10cSrcweir *p->pUShort = (sal_uInt16) n; break; 229*cdf0e10cSrcweir case SbxBYREF | SbxLONG: 230*cdf0e10cSrcweir *p->pLong = n; break; 231*cdf0e10cSrcweir case SbxBYREF | SbxULONG: 232*cdf0e10cSrcweir *p->pULong = (sal_uInt32) n; break; 233*cdf0e10cSrcweir case SbxBYREF | SbxSINGLE: 234*cdf0e10cSrcweir *p->pSingle = n; break; 235*cdf0e10cSrcweir case SbxBYREF | SbxDATE: 236*cdf0e10cSrcweir case SbxBYREF | SbxDOUBLE: 237*cdf0e10cSrcweir *p->pDouble = n; break; 238*cdf0e10cSrcweir case SbxBYREF | SbxSALINT64: 239*cdf0e10cSrcweir *p->pnInt64 = n; break; 240*cdf0e10cSrcweir case SbxBYREF | SbxSALUINT64: 241*cdf0e10cSrcweir *p->puInt64 = n; break; 242*cdf0e10cSrcweir case SbxBYREF | SbxULONG64: 243*cdf0e10cSrcweir p->pULong64->Set( (sal_uInt32)n ); break; 244*cdf0e10cSrcweir case SbxBYREF | SbxLONG64: 245*cdf0e10cSrcweir case SbxBYREF | SbxCURRENCY: 246*cdf0e10cSrcweir p->pLong64->Set( (sal_Int32)n ); break; 247*cdf0e10cSrcweir 248*cdf0e10cSrcweir default: 249*cdf0e10cSrcweir SbxBase::SetError( SbxERR_CONVERSION ); 250*cdf0e10cSrcweir } 251*cdf0e10cSrcweir } 252*cdf0e10cSrcweir 253