1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sbxchar.cxx,v $
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 // AB 29.10.99 Unicode
38 #ifndef _USE_NO_NAMESPACE
42 xub_Unicode
ImpGetChar( const SbxValues
* p
)
50 SbxBase::SetError( SbxERR_CONVERSION
);
54 nRes
= p
->nChar
; break;
56 nRes
= (xub_Unicode
) p
->nByte
;
60 if( p
->nInteger
< SbxMINCHAR
)
62 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMINCHAR
;
65 nRes
= (xub_Unicode
) p
->nInteger
;
69 nRes
= (xub_Unicode
) p
->nUShort
;
72 if( p
->nLong
> SbxMAXCHAR
)
74 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMAXCHAR
;
76 else if( p
->nLong
< SbxMINCHAR
)
78 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMINCHAR
;
81 nRes
= (xub_Unicode
) p
->nLong
;
84 if( p
->nULong
> SbxMAXCHAR
)
86 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMAXCHAR
;
89 nRes
= (xub_Unicode
) p
->nULong
;
92 if( p
->nInt64
> SbxMAXCHAR
)
94 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMAXCHAR
;
96 else if( p
->nInt64
< SbxMINCHAR
)
98 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMINCHAR
;
101 nRes
= (xub_Unicode
) p
->nInt64
;
104 if( p
->uInt64
> SbxMAXCHAR
)
106 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMAXCHAR
;
109 nRes
= (xub_Unicode
) p
->uInt64
;
112 if( p
->nSingle
> SbxMAXCHAR
)
114 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMAXCHAR
;
116 else if( p
->nSingle
< SbxMINCHAR
)
118 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMINCHAR
;
121 nRes
= (xub_Unicode
) ImpRound( p
->nSingle
);
129 case SbxBYREF
| SbxDECIMAL
:
132 if( p
->eType
== SbxCURRENCY
)
133 dVal
= ImpCurrencyToDouble( p
->nLong64
);
134 else if( p
->eType
== SbxLONG64
)
135 dVal
= ImpINT64ToDouble( p
->nLong64
);
136 else if( p
->eType
== SbxULONG64
)
137 dVal
= ImpUINT64ToDouble( p
->nULong64
);
138 else if( p
->eType
== SbxDECIMAL
)
142 p
->pDecimal
->getDouble( dVal
);
147 if( dVal
> SbxMAXCHAR
)
149 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMAXCHAR
;
151 else if( dVal
< SbxMINCHAR
)
153 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMINCHAR
;
156 nRes
= (BYTE
) ImpRound( dVal
);
159 case SbxBYREF
| SbxSTRING
:
168 if( ImpScan( *p
->pString
, d
, t
, NULL
) != SbxERR_OK
)
170 else if( d
> SbxMAXCHAR
)
172 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMAXCHAR
;
174 else if( d
< SbxMINCHAR
)
176 SbxBase::SetError( SbxERR_OVERFLOW
); nRes
= SbxMINCHAR
;
179 nRes
= (xub_Unicode
) ImpRound( d
);
184 SbxValue
* pVal
= PTR_CAST(SbxValue
,p
->pObj
);
186 nRes
= pVal
->GetChar();
189 SbxBase::SetError( SbxERR_NO_OBJECT
); nRes
= 0;
194 case SbxBYREF
| SbxCHAR
:
195 nRes
= *p
->pChar
; break;
196 // ab hier wird getestet
197 case SbxBYREF
| SbxBYTE
:
198 aTmp
.nByte
= *p
->pByte
; goto ref
;
199 case SbxBYREF
| SbxINTEGER
:
200 case SbxBYREF
| SbxBOOL
:
201 aTmp
.nInteger
= *p
->pInteger
; goto ref
;
202 case SbxBYREF
| SbxLONG
:
203 aTmp
.nLong
= *p
->pLong
; goto ref
;
204 case SbxBYREF
| SbxULONG
:
205 aTmp
.nULong
= *p
->pULong
; goto ref
;
206 case SbxBYREF
| SbxERROR
:
207 case SbxBYREF
| SbxUSHORT
:
208 aTmp
.nUShort
= *p
->pUShort
; goto ref
;
209 case SbxBYREF
| SbxSINGLE
:
210 aTmp
.nSingle
= *p
->pSingle
; goto ref
;
211 case SbxBYREF
| SbxDATE
:
212 case SbxBYREF
| SbxDOUBLE
:
213 aTmp
.nDouble
= *p
->pDouble
; goto ref
;
214 case SbxBYREF
| SbxULONG64
:
215 aTmp
.nULong64
= *p
->pULong64
; goto ref
;
216 case SbxBYREF
| SbxLONG64
:
217 case SbxBYREF
| SbxCURRENCY
:
218 aTmp
.nLong64
= *p
->pLong64
; goto ref
;
219 case SbxBYREF
| SbxSALINT64
:
220 aTmp
.nInt64
= *p
->pnInt64
; goto ref
;
221 case SbxBYREF
| SbxSALUINT64
:
222 aTmp
.uInt64
= *p
->puInt64
; goto ref
;
224 aTmp
.eType
= SbxDataType( p
->eType
& 0x0FFF );
225 p
= &aTmp
; goto start
;
228 SbxBase::SetError( SbxERR_CONVERSION
); nRes
= 0;
233 void ImpPutChar( SbxValues
* p
, xub_Unicode n
)
243 p
->nInteger
= n
; break;
247 p
->nSingle
= n
; break;
250 p
->nDouble
= n
; break;
252 p
->nInt64
= n
; break;
254 p
->uInt64
= n
; break;
256 p
->nULong64
= ImpDoubleToUINT64( (double)n
); break;
258 p
->nLong64
= ImpDoubleToINT64( (double)n
); break;
260 p
->nLong64
= ImpDoubleToCurrency( (double)n
); break;
261 case SbxBYREF
| SbxDECIMAL
:
262 ImpCreateDecimal( p
)->setChar( n
);
265 // ab hier wird getestet
267 aTmp
.pByte
= &p
->nByte
; goto direct
;
269 aTmp
.pULong
= &p
->nULong
; goto direct
;
272 aTmp
.pUShort
= &p
->nUShort
; goto direct
;
274 aTmp
.eType
= SbxDataType( p
->eType
| SbxBYREF
);
275 p
= &aTmp
; goto start
;
277 case SbxBYREF
| SbxSTRING
:
281 p
->pString
= new XubString
;
286 SbxValue
* pVal
= PTR_CAST(SbxValue
,p
->pObj
);
290 SbxBase::SetError( SbxERR_NO_OBJECT
);
293 case SbxBYREF
| SbxCHAR
:
294 *p
->pChar
= n
; break;
295 case SbxBYREF
| SbxBYTE
:
296 *p
->pByte
= (BYTE
) n
; break;
297 case SbxBYREF
| SbxINTEGER
:
298 case SbxBYREF
| SbxBOOL
:
299 *p
->pInteger
= n
; break;
300 case SbxBYREF
| SbxERROR
:
301 case SbxBYREF
| SbxUSHORT
:
302 *p
->pUShort
= (UINT16
) n
; break;
303 case SbxBYREF
| SbxLONG
:
304 *p
->pLong
= (INT32
) n
; break;
305 case SbxBYREF
| SbxULONG
:
306 *p
->pULong
= (UINT32
) n
; break;
307 case SbxBYREF
| SbxSINGLE
:
308 *p
->pSingle
= (float) n
; break;
309 case SbxBYREF
| SbxDATE
:
310 case SbxBYREF
| SbxDOUBLE
:
311 *p
->pDouble
= (double) n
; break;
312 case SbxBYREF
| SbxSALINT64
:
313 *p
->pnInt64
= n
; break;
314 case SbxBYREF
| SbxSALUINT64
:
315 *p
->puInt64
= n
; break;
316 case SbxBYREF
| SbxULONG64
:
317 *p
->pULong64
= ImpDoubleToUINT64( (double)n
); break;
318 case SbxBYREF
| SbxLONG64
:
319 *p
->pLong64
= ImpDoubleToINT64( (double)n
); break;
320 case SbxBYREF
| SbxCURRENCY
:
321 *p
->pLong64
= ImpDoubleToCurrency( (double)n
); break;
324 SbxBase::SetError( SbxERR_CONVERSION
);