fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / basic / source / sbx / sbxchar.cxx
blob9628be2cbe919afaedc34d582a57118f1c3d2454
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <tools/errcode.hxx>
21 #include <basic/sbx.hxx>
22 #include "sbxconv.hxx"
24 sal_Unicode ImpGetChar( const SbxValues* p )
26 SbxValues aTmp;
27 sal_Unicode nRes = 0;
28 start:
29 switch( +p->eType )
31 case SbxNULL:
32 SbxBase::SetError( SbxERR_CONVERSION );
33 case SbxEMPTY:
34 nRes = 0; break;
35 case SbxCHAR:
36 nRes = p->nChar; break;
37 case SbxBYTE:
38 nRes = (sal_Unicode) p->nByte;
39 break;
40 case SbxINTEGER:
41 case SbxBOOL:
42 if( p->nInteger < SbxMINCHAR )
44 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMINCHAR;
46 else
47 nRes = (sal_Unicode) p->nInteger;
48 break;
49 case SbxERROR:
50 case SbxUSHORT:
51 nRes = (sal_Unicode) p->nUShort;
52 break;
53 case SbxLONG:
54 if( p->nLong > SbxMAXCHAR )
56 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXCHAR;
58 else if( p->nLong < SbxMINCHAR )
60 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMINCHAR;
62 else
63 nRes = (sal_Unicode) p->nLong;
64 break;
65 case SbxULONG:
66 if( p->nULong > SbxMAXCHAR )
68 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXCHAR;
70 else
71 nRes = (sal_Unicode) p->nULong;
72 break;
73 case SbxCURRENCY:
74 case SbxSALINT64:
76 sal_Int64 val = p->nInt64;
78 if ( p->eType == SbxCURRENCY )
79 val = val / CURRENCY_FACTOR;
81 if( val > SbxMAXCHAR )
83 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXCHAR;
85 else if( p->nInt64 < SbxMINCHAR )
87 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMINCHAR;
89 else
90 nRes = (sal_Unicode) val;
91 break;
93 case SbxSALUINT64:
94 if( p->uInt64 > SbxMAXCHAR )
96 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXCHAR;
98 else
99 nRes = (sal_Unicode) p->uInt64;
100 break;
101 case SbxSINGLE:
102 if( p->nSingle > SbxMAXCHAR )
104 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXCHAR;
106 else if( p->nSingle < SbxMINCHAR )
108 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMINCHAR;
110 else
111 nRes = (sal_Unicode) ImpRound( p->nSingle );
112 break;
113 case SbxDATE:
114 case SbxDOUBLE:
115 case SbxDECIMAL:
116 case SbxBYREF | SbxDECIMAL:
118 double dVal;
119 if( p->eType == SbxDECIMAL )
121 dVal = 0.0;
122 if( p->pDecimal )
123 p->pDecimal->getDouble( dVal );
125 else
126 dVal = p->nDouble;
128 if( dVal > SbxMAXCHAR )
130 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXCHAR;
132 else if( dVal < SbxMINCHAR )
134 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMINCHAR;
136 else
137 nRes = (sal_uInt8) ImpRound( dVal );
138 break;
140 case SbxBYREF | SbxSTRING:
141 case SbxSTRING:
142 case SbxLPSTR:
143 if ( p->pOUString )
145 double d;
146 SbxDataType t;
147 if( ImpScan( *p->pOUString, d, t, NULL ) != SbxERR_OK )
148 nRes = 0;
149 else if( d > SbxMAXCHAR )
151 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXCHAR;
153 else if( d < SbxMINCHAR )
155 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMINCHAR;
157 else
158 nRes = (sal_Unicode) ImpRound( d );
160 break;
161 case SbxOBJECT:
163 SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
164 if( pVal )
165 nRes = pVal->GetChar();
166 else
168 SbxBase::SetError( SbxERR_NO_OBJECT ); nRes = 0;
170 break;
173 case SbxBYREF | SbxCHAR:
174 nRes = *p->pChar; break;
175 // from here on will be tested
176 case SbxBYREF | SbxBYTE:
177 aTmp.nByte = *p->pByte; goto ref;
178 case SbxBYREF | SbxINTEGER:
179 case SbxBYREF | SbxBOOL:
180 aTmp.nInteger = *p->pInteger; goto ref;
181 case SbxBYREF | SbxLONG:
182 aTmp.nLong = *p->pLong; goto ref;
183 case SbxBYREF | SbxULONG:
184 aTmp.nULong = *p->pULong; goto ref;
185 case SbxBYREF | SbxERROR:
186 case SbxBYREF | SbxUSHORT:
187 aTmp.nUShort = *p->pUShort; goto ref;
188 case SbxBYREF | SbxSINGLE:
189 aTmp.nSingle = *p->pSingle; goto ref;
190 case SbxBYREF | SbxDATE:
191 case SbxBYREF | SbxDOUBLE:
192 aTmp.nDouble = *p->pDouble; goto ref;
193 case SbxBYREF | SbxCURRENCY:
194 case SbxBYREF | SbxSALINT64:
195 aTmp.nInt64 = *p->pnInt64; goto ref;
196 case SbxBYREF | SbxSALUINT64:
197 aTmp.uInt64 = *p->puInt64; goto ref;
198 ref:
199 aTmp.eType = SbxDataType( p->eType & 0x0FFF );
200 p = &aTmp; goto start;
202 default:
203 SbxBase::SetError( SbxERR_CONVERSION ); nRes = 0;
205 return nRes;
208 void ImpPutChar( SbxValues* p, sal_Unicode n )
210 SbxValues aTmp;
211 start:
212 switch( +p->eType )
214 case SbxCHAR:
215 p->nChar = n; break;
216 case SbxINTEGER:
217 case SbxBOOL:
218 p->nInteger = n; break;
219 case SbxLONG:
220 p->nLong = n; break;
221 case SbxSINGLE:
222 p->nSingle = n; break;
223 case SbxDATE:
224 case SbxDOUBLE:
225 p->nDouble = n; break;
226 case SbxCURRENCY:
227 p->nInt64 = n * CURRENCY_FACTOR; break;
228 case SbxSALINT64:
229 p->nInt64 = n; break;
230 case SbxSALUINT64:
231 p->uInt64 = n; break;
232 case SbxBYREF | SbxDECIMAL:
233 ImpCreateDecimal( p )->setChar( n );
234 break;
236 // from here on will be tested
237 case SbxBYTE:
238 aTmp.pByte = &p->nByte; goto direct;
239 case SbxULONG:
240 aTmp.pULong = &p->nULong; goto direct;
241 case SbxERROR:
242 case SbxUSHORT:
243 aTmp.pUShort = &p->nUShort; goto direct;
244 direct:
245 aTmp.eType = SbxDataType( p->eType | SbxBYREF );
246 p = &aTmp; goto start;
248 case SbxBYREF | SbxSTRING:
249 case SbxSTRING:
250 case SbxLPSTR:
251 if ( !p->pOUString )
252 p->pOUString = new OUString( n );
253 else
254 *p->pOUString = OUString( n );
255 break;
256 case SbxOBJECT:
258 SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
259 if( pVal )
260 pVal->PutChar( n );
261 else
262 SbxBase::SetError( SbxERR_NO_OBJECT );
263 break;
265 case SbxBYREF | SbxCHAR:
266 *p->pChar = n; break;
267 case SbxBYREF | SbxBYTE:
268 *p->pByte = (sal_uInt8) n; break;
269 case SbxBYREF | SbxINTEGER:
270 case SbxBYREF | SbxBOOL:
271 *p->pInteger = n; break;
272 case SbxBYREF | SbxERROR:
273 case SbxBYREF | SbxUSHORT:
274 *p->pUShort = (sal_uInt16) n; break;
275 case SbxBYREF | SbxLONG:
276 *p->pLong = (sal_Int32) n; break;
277 case SbxBYREF | SbxULONG:
278 *p->pULong = (sal_uInt32) n; break;
279 case SbxBYREF | SbxSINGLE:
280 *p->pSingle = (float) n; break;
281 case SbxBYREF | SbxDATE:
282 case SbxBYREF | SbxDOUBLE:
283 *p->pDouble = (double) n; break;
284 case SbxBYREF | SbxCURRENCY:
285 p->nInt64 = n * CURRENCY_FACTOR; break;
286 case SbxBYREF | SbxSALINT64:
287 *p->pnInt64 = n; break;
288 case SbxBYREF | SbxSALUINT64:
289 *p->puInt64 = n; break;
291 default:
292 SbxBase::SetError( SbxERR_CONVERSION );
297 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */