xref: /AOO41X/main/basic/source/sbx/sbxbool.cxx (revision e1f63238eb022c8a12b30d46a012444ff20e0951)
1*e1f63238SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*e1f63238SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*e1f63238SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*e1f63238SAndrew Rist  * distributed with this work for additional information
6*e1f63238SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*e1f63238SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*e1f63238SAndrew Rist  * "License"); you may not use this file except in compliance
9*e1f63238SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*e1f63238SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*e1f63238SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*e1f63238SAndrew Rist  * software distributed under the License is distributed on an
15*e1f63238SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*e1f63238SAndrew Rist  * KIND, either express or implied.  See the License for the
17*e1f63238SAndrew Rist  * specific language governing permissions and limitations
18*e1f63238SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*e1f63238SAndrew Rist  *************************************************************/
21*e1f63238SAndrew Rist 
22*e1f63238SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_basic.hxx"
26cdf0e10cSrcweir #include <tools/errcode.hxx>
27cdf0e10cSrcweir #include <basic/sbx.hxx>
28cdf0e10cSrcweir #include "sbxconv.hxx"
29cdf0e10cSrcweir #include "sbxres.hxx"
30cdf0e10cSrcweir 
31cdf0e10cSrcweir // AB 29.10.99 Unicode
32cdf0e10cSrcweir #ifndef _USE_NO_NAMESPACE
33cdf0e10cSrcweir using namespace rtl;
34cdf0e10cSrcweir #endif
35cdf0e10cSrcweir 
ImpGetBool(const SbxValues * p)36cdf0e10cSrcweir enum SbxBOOL ImpGetBool( const SbxValues* p )
37cdf0e10cSrcweir {
38cdf0e10cSrcweir 	enum SbxBOOL nRes;
39cdf0e10cSrcweir 	switch( +p->eType )
40cdf0e10cSrcweir 	{
41cdf0e10cSrcweir 		case SbxNULL:
42cdf0e10cSrcweir 			SbxBase::SetError( SbxERR_CONVERSION );
43cdf0e10cSrcweir 		case SbxEMPTY:
44cdf0e10cSrcweir 			nRes = SbxFALSE; break;
45cdf0e10cSrcweir 		case SbxCHAR:
46cdf0e10cSrcweir 			nRes = p->nChar ? SbxTRUE : SbxFALSE; break;
47cdf0e10cSrcweir 		case SbxBYTE:
48cdf0e10cSrcweir 			nRes = p->nByte ? SbxTRUE : SbxFALSE; break;
49cdf0e10cSrcweir 		case SbxINTEGER:
50cdf0e10cSrcweir 		case SbxBOOL:
51cdf0e10cSrcweir 			nRes = p->nInteger ? SbxTRUE : SbxFALSE; break;
52cdf0e10cSrcweir 		case SbxERROR:
53cdf0e10cSrcweir 		case SbxUSHORT:
54cdf0e10cSrcweir 			nRes = p->nUShort ? SbxTRUE : SbxFALSE; break;
55cdf0e10cSrcweir 		case SbxLONG:
56cdf0e10cSrcweir 			nRes = p->nLong ? SbxTRUE : SbxFALSE; break;
57cdf0e10cSrcweir 		case SbxULONG:
58cdf0e10cSrcweir 			nRes = p->nULong ? SbxTRUE : SbxFALSE; break;
59cdf0e10cSrcweir 		case SbxSINGLE:
60cdf0e10cSrcweir 			nRes = p->nSingle ? SbxTRUE : SbxFALSE; break;
61cdf0e10cSrcweir 		case SbxDATE:
62cdf0e10cSrcweir 		case SbxDOUBLE:
63cdf0e10cSrcweir 			nRes = p->nDouble ? SbxTRUE : SbxFALSE; break;
64cdf0e10cSrcweir 		case SbxDECIMAL:
65cdf0e10cSrcweir 		case SbxBYREF | SbxDECIMAL:
66cdf0e10cSrcweir 			{
67cdf0e10cSrcweir 			double dVal = 0.0;
68cdf0e10cSrcweir 			if( p->pDecimal )
69cdf0e10cSrcweir 				p->pDecimal->getDouble( dVal );
70cdf0e10cSrcweir 			nRes = dVal ? SbxTRUE : SbxFALSE;
71cdf0e10cSrcweir 			}
72cdf0e10cSrcweir 			break;
73cdf0e10cSrcweir 		case SbxSALINT64:
74cdf0e10cSrcweir             nRes = p->nInt64 ? SbxTRUE : SbxFALSE; break;
75cdf0e10cSrcweir 		case SbxSALUINT64:
76cdf0e10cSrcweir             nRes = p->uInt64 ? SbxTRUE : SbxFALSE; break;
77cdf0e10cSrcweir 		case SbxULONG64:
78cdf0e10cSrcweir 			nRes = !!p->nULong64 ? SbxTRUE : SbxFALSE; break;
79cdf0e10cSrcweir 		case SbxLONG64:
80cdf0e10cSrcweir 		case SbxCURRENCY:
81cdf0e10cSrcweir 			nRes = !!p->nLong64 ? SbxTRUE : SbxFALSE; break;
82cdf0e10cSrcweir 		case SbxBYREF | SbxSTRING:
83cdf0e10cSrcweir 		case SbxSTRING:
84cdf0e10cSrcweir 		case SbxLPSTR:
85cdf0e10cSrcweir 			nRes = SbxFALSE;
86cdf0e10cSrcweir             if ( p->pOUString )
87cdf0e10cSrcweir             {
88cdf0e10cSrcweir                 if( p->pOUString->equalsIgnoreAsciiCase( SbxRes( STRING_TRUE ) ) )
89cdf0e10cSrcweir                     nRes = SbxTRUE;
90cdf0e10cSrcweir                 else if( !p->pOUString->equalsIgnoreAsciiCase( SbxRes( STRING_FALSE ) ) )
91cdf0e10cSrcweir                 {
92cdf0e10cSrcweir                     // Jetzt kann es noch in eine Zahl konvertierbar sein
93cdf0e10cSrcweir                     sal_Bool bError = sal_True;
94cdf0e10cSrcweir                     double n;
95cdf0e10cSrcweir                     SbxDataType t;
96cdf0e10cSrcweir                     sal_uInt16 nLen = 0;
97cdf0e10cSrcweir                     if( ImpScan( *p->pOUString, n, t, &nLen ) == SbxERR_OK )
98cdf0e10cSrcweir                     {
99cdf0e10cSrcweir                         if( nLen == p->pOUString->getLength() )
100cdf0e10cSrcweir                         {
101cdf0e10cSrcweir                             bError = sal_False;
102cdf0e10cSrcweir                             if( n != 0.0 )
103cdf0e10cSrcweir                                 nRes = SbxTRUE;
104cdf0e10cSrcweir                         }
105cdf0e10cSrcweir                     }
106cdf0e10cSrcweir                     if( bError )
107cdf0e10cSrcweir                         SbxBase::SetError( SbxERR_CONVERSION );
108cdf0e10cSrcweir                 }
109cdf0e10cSrcweir             }
110cdf0e10cSrcweir 			break;
111cdf0e10cSrcweir 		case SbxOBJECT:
112cdf0e10cSrcweir 		{
113cdf0e10cSrcweir 			SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
114cdf0e10cSrcweir 			if( pVal )
115cdf0e10cSrcweir 				nRes = pVal->GetBool() ? SbxTRUE : SbxFALSE;
116cdf0e10cSrcweir 			else
117cdf0e10cSrcweir 			{
118cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_NO_OBJECT ); nRes = SbxFALSE;
119cdf0e10cSrcweir 			}
120cdf0e10cSrcweir 			break;
121cdf0e10cSrcweir 		}
122cdf0e10cSrcweir 
123cdf0e10cSrcweir 		case SbxBYREF | SbxCHAR:
124cdf0e10cSrcweir 			nRes = *p->pChar ? SbxTRUE : SbxFALSE; break;
125cdf0e10cSrcweir 		case SbxBYREF | SbxBYTE:
126cdf0e10cSrcweir 			nRes = *p->pByte ? SbxTRUE : SbxFALSE; break;
127cdf0e10cSrcweir 		case SbxBYREF | SbxINTEGER:
128cdf0e10cSrcweir 		case SbxBYREF | SbxBOOL:
129cdf0e10cSrcweir 			nRes = *p->pInteger ? SbxTRUE : SbxFALSE; break;
130cdf0e10cSrcweir 		case SbxBYREF | SbxLONG:
131cdf0e10cSrcweir 			nRes = *p->pLong ? SbxTRUE : SbxFALSE; break;
132cdf0e10cSrcweir 		case SbxBYREF | SbxULONG:
133cdf0e10cSrcweir 			nRes = *p->pULong ? SbxTRUE : SbxFALSE; break;
134cdf0e10cSrcweir 		case SbxBYREF | SbxERROR:
135cdf0e10cSrcweir 		case SbxBYREF | SbxUSHORT:
136cdf0e10cSrcweir 			nRes = *p->pUShort ? SbxTRUE : SbxFALSE; break;
137cdf0e10cSrcweir 		case SbxBYREF | SbxSINGLE:
138cdf0e10cSrcweir 			nRes = ( *p->pSingle != 0 ) ? SbxTRUE : SbxFALSE; break;
139cdf0e10cSrcweir 		case SbxBYREF | SbxDATE:
140cdf0e10cSrcweir 		case SbxBYREF | SbxDOUBLE:
141cdf0e10cSrcweir 			nRes = ( *p->pDouble != 0 ) ? SbxTRUE : SbxFALSE; break;
142cdf0e10cSrcweir 		case SbxBYREF | SbxSALINT64:
143cdf0e10cSrcweir             nRes = ( *p->pnInt64 ) ? SbxTRUE : SbxFALSE; break;
144cdf0e10cSrcweir 		case SbxBYREF | SbxSALUINT64:
145cdf0e10cSrcweir             nRes = ( *p->puInt64 ) ? SbxTRUE : SbxFALSE; break;
146cdf0e10cSrcweir 		case SbxBYREF | SbxULONG64:
147cdf0e10cSrcweir 			nRes = !!*p->pULong64 ? SbxTRUE : SbxFALSE; break;
148cdf0e10cSrcweir 		case SbxBYREF | SbxLONG64:
149cdf0e10cSrcweir 		case SbxBYREF | SbxCURRENCY:
150cdf0e10cSrcweir 			nRes = !!*p->pLong64 ? SbxTRUE : SbxFALSE; break;
151cdf0e10cSrcweir 
152cdf0e10cSrcweir 		default:
153cdf0e10cSrcweir 			SbxBase::SetError( SbxERR_CONVERSION ); nRes = SbxFALSE;
154cdf0e10cSrcweir 	}
155cdf0e10cSrcweir 	return nRes;
156cdf0e10cSrcweir }
157cdf0e10cSrcweir 
ImpPutBool(SbxValues * p,sal_Int16 n)158cdf0e10cSrcweir void ImpPutBool( SbxValues* p, sal_Int16 n )
159cdf0e10cSrcweir {
160cdf0e10cSrcweir 	if( n )
161cdf0e10cSrcweir 		n = SbxTRUE;
162cdf0e10cSrcweir 	switch( +p->eType )
163cdf0e10cSrcweir 	{
164cdf0e10cSrcweir 		case SbxCHAR:
165cdf0e10cSrcweir 			p->nChar = (xub_Unicode) n; break;
166cdf0e10cSrcweir 		case SbxUINT:
167cdf0e10cSrcweir 			p->nByte = (sal_uInt8) n; break;
168cdf0e10cSrcweir 		case SbxINTEGER:
169cdf0e10cSrcweir 		case SbxBOOL:
170cdf0e10cSrcweir 			p->nInteger = n; break;
171cdf0e10cSrcweir 		case SbxLONG:
172cdf0e10cSrcweir 			p->nLong = n; break;
173cdf0e10cSrcweir 		case SbxULONG:
174cdf0e10cSrcweir 			p->nULong = (sal_uInt32) n; break;
175cdf0e10cSrcweir 		case SbxERROR:
176cdf0e10cSrcweir 		case SbxUSHORT:
177cdf0e10cSrcweir 			p->nUShort = (sal_uInt16) n; break;
178cdf0e10cSrcweir 		case SbxSINGLE:
179cdf0e10cSrcweir 			p->nSingle = n; break;
180cdf0e10cSrcweir 		case SbxDATE:
181cdf0e10cSrcweir 		case SbxDOUBLE:
182cdf0e10cSrcweir 			p->nDouble = n; break;
183cdf0e10cSrcweir 		case SbxSALINT64:
184cdf0e10cSrcweir 			p->nInt64 = n; break;
185cdf0e10cSrcweir 		case SbxSALUINT64:
186cdf0e10cSrcweir 			p->uInt64 = n; break;
187cdf0e10cSrcweir 		case SbxULONG64:
188cdf0e10cSrcweir 			p->nULong64.Set( (sal_uInt32)n ); break;
189cdf0e10cSrcweir 		case SbxLONG64:
190cdf0e10cSrcweir 		case SbxCURRENCY:
191cdf0e10cSrcweir 			p->nLong64.Set( (sal_Int32)n ); break;
192cdf0e10cSrcweir 		case SbxDECIMAL:
193cdf0e10cSrcweir 		case SbxBYREF | SbxDECIMAL:
194cdf0e10cSrcweir 			ImpCreateDecimal( p )->setInt( (sal_Int16)n );
195cdf0e10cSrcweir 			break;
196cdf0e10cSrcweir 
197cdf0e10cSrcweir 		case SbxBYREF | SbxSTRING:
198cdf0e10cSrcweir 		case SbxSTRING:
199cdf0e10cSrcweir 		case SbxLPSTR:
200cdf0e10cSrcweir             if ( !p->pOUString )
201cdf0e10cSrcweir                 p->pOUString = new ::rtl::OUString( SbxRes( n ? STRING_TRUE : STRING_FALSE ) );
202cdf0e10cSrcweir             else
203cdf0e10cSrcweir                 *p->pOUString = SbxRes( n ? STRING_TRUE : STRING_FALSE );
204cdf0e10cSrcweir 			break;
205cdf0e10cSrcweir 
206cdf0e10cSrcweir 		case SbxOBJECT:
207cdf0e10cSrcweir 		{
208cdf0e10cSrcweir 			SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
209cdf0e10cSrcweir 			if( pVal )
210cdf0e10cSrcweir 				pVal->PutBool( sal_Bool( n != 0 ) );
211cdf0e10cSrcweir 			else
212cdf0e10cSrcweir 				SbxBase::SetError( SbxERR_NO_OBJECT );
213cdf0e10cSrcweir 			break;
214cdf0e10cSrcweir 		}
215cdf0e10cSrcweir 		case SbxBYREF | SbxCHAR:
216cdf0e10cSrcweir 			*p->pChar = (xub_Unicode) n; break;
217cdf0e10cSrcweir 		case SbxBYREF | SbxBYTE:
218cdf0e10cSrcweir 			*p->pByte = (sal_uInt8) n; break;
219cdf0e10cSrcweir 		case SbxBYREF | SbxINTEGER:
220cdf0e10cSrcweir 		case SbxBYREF | SbxBOOL:
221cdf0e10cSrcweir 			*p->pInteger = (sal_Int16) n; break;
222cdf0e10cSrcweir 		case SbxBYREF | SbxERROR:
223cdf0e10cSrcweir 		case SbxBYREF | SbxUSHORT:
224cdf0e10cSrcweir 			*p->pUShort = (sal_uInt16) n; break;
225cdf0e10cSrcweir 		case SbxBYREF | SbxLONG:
226cdf0e10cSrcweir 			*p->pLong = n; break;
227cdf0e10cSrcweir 		case SbxBYREF | SbxULONG:
228cdf0e10cSrcweir 			*p->pULong = (sal_uInt32) n; break;
229cdf0e10cSrcweir 		case SbxBYREF | SbxSINGLE:
230cdf0e10cSrcweir 			*p->pSingle = n; break;
231cdf0e10cSrcweir 		case SbxBYREF | SbxDATE:
232cdf0e10cSrcweir 		case SbxBYREF | SbxDOUBLE:
233cdf0e10cSrcweir 			*p->pDouble = n; break;
234cdf0e10cSrcweir 		case SbxBYREF | SbxSALINT64:
235cdf0e10cSrcweir 			*p->pnInt64 = n; break;
236cdf0e10cSrcweir 		case SbxBYREF | SbxSALUINT64:
237cdf0e10cSrcweir 			*p->puInt64 = n; break;
238cdf0e10cSrcweir 		case SbxBYREF | SbxULONG64:
239cdf0e10cSrcweir 			p->pULong64->Set( (sal_uInt32)n ); break;
240cdf0e10cSrcweir 		case SbxBYREF | SbxLONG64:
241cdf0e10cSrcweir 		case SbxBYREF | SbxCURRENCY:
242cdf0e10cSrcweir 			p->pLong64->Set( (sal_Int32)n ); break;
243cdf0e10cSrcweir 
244cdf0e10cSrcweir 		default:
245cdf0e10cSrcweir 			SbxBase::SetError( SbxERR_CONVERSION );
246cdf0e10cSrcweir 	}
247cdf0e10cSrcweir }
248cdf0e10cSrcweir 
249