merge the formfield patch from ooo-build
[ooovba.git] / basic / source / sbx / sbxulng.cxx
blobeaf7b86b43ed16417e604633cff1870230a088d7
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sbxulng.cxx,v $
10 * $Revision: 1.9 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_basic.hxx"
33 #include <tools/errcode.hxx>
34 #include <basic/sbx.hxx>
35 #include "sbxconv.hxx"
37 UINT32 ImpGetULong( const SbxValues* p )
39 SbxValues aTmp;
40 UINT32 nRes;
41 start:
42 switch( +p->eType )
44 case SbxNULL:
45 SbxBase::SetError( SbxERR_CONVERSION );
46 case SbxEMPTY:
47 nRes = 0; break;
48 case SbxCHAR:
49 nRes = p->nChar;
50 break;
51 case SbxBYTE:
52 nRes = p->nByte; break;
53 case SbxINTEGER:
54 case SbxBOOL:
55 if( p->nInteger < 0 )
57 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = 0;
59 else
60 nRes = p->nInteger;
61 break;
62 case SbxERROR:
63 case SbxUSHORT:
64 nRes = p->nUShort;
65 break;
66 case SbxLONG:
67 if( p->nLong < 0 )
69 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = 0;
71 else
72 nRes = p->nLong;
73 break;
74 case SbxULONG:
75 nRes = p->nULong; break;
76 case SbxSINGLE:
77 if( p->nSingle > SbxMAXULNG )
79 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXULNG;
81 else if( p->nSingle < 0 )
83 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = 0;
85 else
86 nRes = (UINT32) ( p->nSingle + 0.5 );
87 break;
88 case SbxDATE:
89 case SbxDOUBLE:
90 case SbxLONG64:
91 case SbxULONG64:
92 case SbxSALINT64:
93 case SbxSALUINT64:
94 case SbxCURRENCY:
95 case SbxDECIMAL:
96 case SbxBYREF | SbxDECIMAL:
98 double dVal;
99 if( p->eType == SbxCURRENCY )
100 dVal = ImpCurrencyToDouble( p->nLong64 );
101 else if( p->eType == SbxLONG64 )
102 dVal = ImpINT64ToDouble( p->nLong64 );
103 else if( p->eType == SbxULONG64 )
104 dVal = ImpUINT64ToDouble( p->nULong64 );
105 else if( p->eType == SbxSALINT64 )
106 dVal = static_cast< double >(p->nInt64);
107 else if( p->eType == SbxSALUINT64 )
108 dVal = ImpSalUInt64ToDouble( p->uInt64 );
109 else if( p->eType == SbxDECIMAL )
111 dVal = 0.0;
112 if( p->pDecimal )
113 p->pDecimal->getDouble( dVal );
115 else
116 dVal = p->nDouble;
118 if( dVal > SbxMAXULNG )
120 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXULNG;
122 else if( dVal < 0 )
124 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = 0;
126 else
127 nRes = (UINT32) ( dVal + 0.5 );
128 break;
130 case SbxBYREF | SbxSTRING:
131 case SbxSTRING:
132 case SbxLPSTR:
133 if( !p->pString )
134 nRes = 0;
135 else
137 double d;
138 SbxDataType t;
139 if( ImpScan( *p->pString, d, t, NULL ) != SbxERR_OK )
140 nRes = 0;
141 else if( d > SbxMAXULNG )
143 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXULNG;
145 else if( d < 0 )
147 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = 0;
149 else
150 nRes = (UINT32) ( d + 0.5 );
152 break;
153 case SbxOBJECT:
155 SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
156 if( pVal )
157 nRes = pVal->GetULong();
158 else
160 SbxBase::SetError( SbxERR_NO_OBJECT ); nRes = 0;
162 break;
165 case SbxBYREF | SbxBYTE:
166 nRes = *p->pByte; break;
167 case SbxBYREF | SbxERROR:
168 case SbxBYREF | SbxUSHORT:
169 nRes = *p->pUShort; break;
170 case SbxBYREF | SbxULONG:
171 nRes = *p->pULong; break;
173 // Tests ab hier
174 case SbxBYREF | SbxCHAR:
175 aTmp.nChar = *p->pChar; goto ref;
176 case SbxBYREF | SbxINTEGER:
177 case SbxBYREF | SbxBOOL:
178 aTmp.nInteger = *p->pInteger; goto ref;
179 case SbxBYREF | SbxLONG:
180 aTmp.nLong = *p->pLong; goto ref;
181 case SbxBYREF | SbxSINGLE:
182 aTmp.nSingle = *p->pSingle; goto ref;
183 case SbxBYREF | SbxDATE:
184 case SbxBYREF | SbxDOUBLE:
185 aTmp.nDouble = *p->pDouble; goto ref;
186 case SbxBYREF | SbxSALINT64:
187 aTmp.nInt64 = *p->pnInt64; goto ref;
188 case SbxBYREF | SbxSALUINT64:
189 aTmp.uInt64 = *p->puInt64; goto ref;
190 case SbxBYREF | SbxULONG64:
191 aTmp.nULong64 = *p->pULong64; goto ref;
192 case SbxBYREF | SbxLONG64:
193 case SbxBYREF | SbxCURRENCY:
194 aTmp.nLong64 = *p->pLong64; goto ref;
195 ref:
196 aTmp.eType = SbxDataType( p->eType & 0x0FFF );
197 p = &aTmp; goto start;
199 default:
200 SbxBase::SetError( SbxERR_CONVERSION ); nRes = 0;
202 return nRes;
205 void ImpPutULong( SbxValues* p, UINT32 n )
207 SbxValues aTmp;
208 start:
209 switch( +p->eType )
211 case SbxULONG:
212 p->nULong = n; break;
213 case SbxSINGLE:
214 p->nSingle = (float) n; break;
215 case SbxDATE:
216 case SbxDOUBLE:
217 p->nDouble = n; break;
218 case SbxSALINT64:
219 p->nInt64 = n; break;
220 case SbxSALUINT64:
221 p->uInt64 = n; break;
222 case SbxDECIMAL:
223 case SbxBYREF | SbxDECIMAL:
224 ImpCreateDecimal( p )->setULong( n );
225 break;
227 // Tests ab hier
228 case SbxCHAR:
229 aTmp.pChar = &p->nChar; goto direct;
230 case SbxUINT:
231 aTmp.pByte = &p->nByte; goto direct;
232 case SbxINTEGER:
233 case SbxBOOL:
234 aTmp.pInteger = &p->nInteger; goto direct;
235 case SbxLONG:
236 aTmp.pLong = &p->nLong; goto direct;
237 case SbxERROR:
238 case SbxUSHORT:
239 aTmp.pUShort = &p->nUShort; goto direct;
240 case SbxULONG64:
241 aTmp.pULong64 = &p->nULong64; goto direct;
242 case SbxLONG64:
243 case SbxCURRENCY:
244 aTmp.pLong64 = &p->nLong64; goto direct;
245 direct:
246 aTmp.eType = SbxDataType( p->eType | SbxBYREF );
247 p = &aTmp; goto start;
249 case SbxBYREF | SbxSTRING:
250 case SbxSTRING:
251 case SbxLPSTR:
252 if( !p->pString )
253 p->pString = new XubString;
254 ImpCvtNum( (double) n, 0, *p->pString );
255 break;
256 case SbxOBJECT:
258 SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
259 if( pVal )
260 pVal->PutULong( n );
261 else
262 SbxBase::SetError( SbxERR_NO_OBJECT );
263 break;
265 case SbxBYREF | SbxCHAR:
266 if( n > SbxMAXCHAR )
268 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXCHAR;
270 *p->pChar = (xub_Unicode) n; break;
271 case SbxBYREF | SbxBYTE:
272 if( n > SbxMAXBYTE )
274 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXBYTE;
276 *p->pByte = (BYTE) n; break;
277 case SbxBYREF | SbxINTEGER:
278 case SbxBYREF | SbxBOOL:
279 if( n > SbxMAXINT )
281 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXINT;
283 *p->pInteger = (INT16) n; break;
284 case SbxBYREF | SbxERROR:
285 case SbxBYREF | SbxUSHORT:
286 if( n > SbxMAXUINT )
288 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXUINT;
290 *p->pUShort = (UINT16) n; break;
291 case SbxBYREF | SbxLONG:
292 if( n > SbxMAXLNG )
294 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXLNG;
296 *p->pLong = (INT32) n; break;
297 case SbxBYREF | SbxULONG:
298 *p->pULong = n; break;
299 case SbxBYREF | SbxSINGLE:
300 *p->pSingle = (float) n; break;
301 case SbxBYREF | SbxDATE:
302 case SbxBYREF | SbxDOUBLE:
303 *p->pDouble = n; break;
304 case SbxBYREF | SbxSALINT64:
305 *p->pnInt64 = n; break;
306 case SbxBYREF | SbxSALUINT64:
307 *p->puInt64 = n; break;
308 case SbxBYREF | SbxCURRENCY:
309 double d;
310 if( n > SbxMAXCURR )
312 SbxBase::SetError( SbxERR_OVERFLOW ); d = SbxMAXCURR;
314 else
316 d = n;
318 *p->pLong64 = ImpDoubleToCurrency( n ); break;
320 default:
321 SbxBase::SetError( SbxERR_CONVERSION );