fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / basic / source / sbx / sbxbool.cxx
blob4ff018fd1e189f62c46cb3602e4298ab0aa9f787
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"
23 #include "sbxres.hxx"
25 enum SbxBOOL ImpGetBool( const SbxValues* p )
27 enum SbxBOOL nRes;
28 switch( +p->eType )
30 case SbxNULL:
31 SbxBase::SetError( SbxERR_CONVERSION );
32 case SbxEMPTY:
33 nRes = SbxFALSE; break;
34 case SbxCHAR:
35 nRes = p->nChar ? SbxTRUE : SbxFALSE; break;
36 case SbxBYTE:
37 nRes = p->nByte ? SbxTRUE : SbxFALSE; break;
38 case SbxINTEGER:
39 case SbxBOOL:
40 nRes = p->nInteger ? SbxTRUE : SbxFALSE; break;
41 case SbxERROR:
42 case SbxUSHORT:
43 nRes = p->nUShort ? SbxTRUE : SbxFALSE; break;
44 case SbxLONG:
45 nRes = p->nLong ? SbxTRUE : SbxFALSE; break;
46 case SbxULONG:
47 nRes = p->nULong ? SbxTRUE : SbxFALSE; break;
48 case SbxSINGLE:
49 nRes = p->nSingle ? SbxTRUE : SbxFALSE; break;
50 case SbxDATE:
51 case SbxDOUBLE:
52 nRes = p->nDouble ? SbxTRUE : SbxFALSE; break;
53 case SbxDECIMAL:
54 case SbxBYREF | SbxDECIMAL:
56 double dVal = 0.0;
57 if( p->pDecimal )
58 p->pDecimal->getDouble( dVal );
59 nRes = dVal ? SbxTRUE : SbxFALSE;
61 break;
62 case SbxSALINT64:
63 case SbxCURRENCY:
64 nRes = p->nInt64 ? SbxTRUE : SbxFALSE; break;
65 case SbxSALUINT64:
66 nRes = p->uInt64 ? SbxTRUE : SbxFALSE; break;
67 case SbxBYREF | SbxSTRING:
68 case SbxSTRING:
69 case SbxLPSTR:
70 nRes = SbxFALSE;
71 if ( p->pOUString )
73 if( p->pOUString->equalsIgnoreAsciiCase( SbxRes( STRING_TRUE ) ) )
74 nRes = SbxTRUE;
75 else if( !p->pOUString->equalsIgnoreAsciiCase( SbxRes( STRING_FALSE ) ) )
77 // it can be convertible to a number
78 bool bError = true;
79 double n;
80 SbxDataType t;
81 sal_uInt16 nLen = 0;
82 if( ImpScan( *p->pOUString, n, t, &nLen ) == SbxERR_OK )
84 if( nLen == p->pOUString->getLength() )
86 bError = false;
87 if( n != 0.0 )
88 nRes = SbxTRUE;
91 if( bError )
92 SbxBase::SetError( SbxERR_CONVERSION );
95 break;
96 case SbxOBJECT:
98 SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
99 if( pVal )
100 nRes = pVal->GetBool() ? SbxTRUE : SbxFALSE;
101 else
103 SbxBase::SetError( SbxERR_NO_OBJECT ); nRes = SbxFALSE;
105 break;
108 case SbxBYREF | SbxCHAR:
109 nRes = *p->pChar ? SbxTRUE : SbxFALSE; break;
110 case SbxBYREF | SbxBYTE:
111 nRes = *p->pByte ? SbxTRUE : SbxFALSE; break;
112 case SbxBYREF | SbxINTEGER:
113 case SbxBYREF | SbxBOOL:
114 nRes = *p->pInteger ? SbxTRUE : SbxFALSE; break;
115 case SbxBYREF | SbxLONG:
116 nRes = *p->pLong ? SbxTRUE : SbxFALSE; break;
117 case SbxBYREF | SbxULONG:
118 nRes = *p->pULong ? SbxTRUE : SbxFALSE; break;
119 case SbxBYREF | SbxERROR:
120 case SbxBYREF | SbxUSHORT:
121 nRes = *p->pUShort ? SbxTRUE : SbxFALSE; break;
122 case SbxBYREF | SbxSINGLE:
123 nRes = ( *p->pSingle != 0 ) ? SbxTRUE : SbxFALSE; break;
124 case SbxBYREF | SbxDATE:
125 case SbxBYREF | SbxDOUBLE:
126 nRes = ( *p->pDouble != 0 ) ? SbxTRUE : SbxFALSE; break;
127 case SbxBYREF | SbxCURRENCY:
128 case SbxBYREF | SbxSALINT64:
129 nRes = ( *p->pnInt64 ) ? SbxTRUE : SbxFALSE; break;
130 case SbxBYREF | SbxSALUINT64:
131 nRes = ( *p->puInt64 ) ? SbxTRUE : SbxFALSE; break;
132 default:
133 SbxBase::SetError( SbxERR_CONVERSION ); nRes = SbxFALSE;
135 return nRes;
138 void ImpPutBool( SbxValues* p, sal_Int16 n )
140 if( n )
141 n = SbxTRUE;
142 switch( +p->eType )
144 case SbxCHAR:
145 p->nChar = (sal_Unicode) n; break;
146 case SbxUINT:
147 p->nByte = (sal_uInt8) n; break;
148 case SbxINTEGER:
149 case SbxBOOL:
150 p->nInteger = n; break;
151 case SbxLONG:
152 p->nLong = n; break;
153 case SbxULONG:
154 p->nULong = (sal_uInt32) n; break;
155 case SbxERROR:
156 case SbxUSHORT:
157 p->nUShort = (sal_uInt16) n; break;
158 case SbxSINGLE:
159 p->nSingle = n; break;
160 case SbxDATE:
161 case SbxDOUBLE:
162 p->nDouble = n; break;
163 case SbxCURRENCY:
164 case SbxSALINT64:
165 p->nInt64 = (sal_Int64) n; break;
166 case SbxSALUINT64:
167 p->uInt64 = (sal_uInt64) n; break;
168 case SbxDECIMAL:
169 case SbxBYREF | SbxDECIMAL:
170 ImpCreateDecimal( p )->setInt( (sal_Int16)n );
171 break;
173 case SbxBYREF | SbxSTRING:
174 case SbxSTRING:
175 case SbxLPSTR:
176 if ( !p->pOUString )
177 p->pOUString = new OUString( SbxRes( n ? STRING_TRUE : STRING_FALSE ) );
178 else
179 *p->pOUString = SbxRes( n ? STRING_TRUE : STRING_FALSE );
180 break;
182 case SbxOBJECT:
184 SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
185 if( pVal )
186 pVal->PutBool( sal_Bool( n != 0 ) );
187 else
188 SbxBase::SetError( SbxERR_NO_OBJECT );
189 break;
191 case SbxBYREF | SbxCHAR:
192 *p->pChar = (sal_Unicode) n; break;
193 case SbxBYREF | SbxBYTE:
194 *p->pByte = (sal_uInt8) n; break;
195 case SbxBYREF | SbxINTEGER:
196 case SbxBYREF | SbxBOOL:
197 *p->pInteger = (sal_Int16) n; break;
198 case SbxBYREF | SbxERROR:
199 case SbxBYREF | SbxUSHORT:
200 *p->pUShort = (sal_uInt16) n; break;
201 case SbxBYREF | SbxLONG:
202 *p->pLong = n; break;
203 case SbxBYREF | SbxULONG:
204 *p->pULong = (sal_uInt32) n; break;
205 case SbxBYREF | SbxSINGLE:
206 *p->pSingle = n; break;
207 case SbxBYREF | SbxDATE:
208 case SbxBYREF | SbxDOUBLE:
209 *p->pDouble = n; break;
210 case SbxBYREF | SbxCURRENCY:
211 case SbxBYREF | SbxSALINT64:
212 *p->pnInt64 = (sal_Int64) n; break;
213 case SbxBYREF | SbxSALUINT64:
214 *p->puInt64 = (sal_uInt64) n; break;
215 default:
216 SbxBase::SetError( SbxERR_CONVERSION );
220 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */