merge the formfield patch from ooo-build
[ooovba.git] / idl / source / objects / bastype.cxx
blob4c9d9bb08926633d9fca7d1c0298388862a3f219
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: bastype.cxx,v $
10 * $Revision: 1.7 $
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_idl.hxx"
34 #include <tools/debug.hxx>
36 #include <limits.h>
37 #include <ctype.h>
38 #include <bastype.hxx>
39 #include <lex.hxx>
40 #include <globals.hxx>
41 #include <hash.hxx>
42 #include <database.hxx>
44 #ifdef IDL_COMPILER
45 /************************************************************************/
46 static BOOL ReadRangeSvIdl( SvStringHashEntry * pName, SvTokenStream & rInStm,
47 ULONG nMin, ULONG nMax, ULONG* pValue )
49 UINT32 nTokPos = rInStm.Tell();
50 SvToken * pTok = rInStm.GetToken_Next();
51 if( pTok->Is( pName ) )
53 BOOL bOk = FALSE;
54 if( rInStm.Read( '=' ) )
56 pTok = rInStm.GetToken_Next();
57 if( pTok->IsInteger() )
59 ULONG n = pTok->GetNumber();
60 if ( n >= nMin && n <= nMax )
62 *pValue = n;
63 bOk = TRUE;
68 if( bOk )
69 return TRUE;
72 rInStm.Seek( nTokPos );
73 return FALSE;
75 #endif
77 /*************************************************************************
79 |* SvUINT32::Read()
80 |* SvUINT32::Write()
82 |* Beschreibung
83 |* Ersterstellung MM 12.12.94
84 |* Letzte Aenderung MM 12.12.94
86 *************************************************************************/
87 UINT32 SvUINT32::Read( SvStream & rStm )
89 return SvPersistStream::ReadCompressed( rStm );
92 void SvUINT32::Write( SvStream & rStm, UINT32 nVal )
94 SvPersistStream::WriteCompressed( rStm, nVal );
97 /*************************************************************************
99 |* SvStream& operator << ( SvBOOL )
100 |* SvStream& operator >> ( SvBOOL )
102 |* Beschreibung
103 |* Ersterstellung MM 12.12.94
104 |* Letzte Aenderung MM 12.12.94
106 *************************************************************************/
107 SvStream& operator << (SvStream & rStm, const SvBOOL & rb )
109 BYTE n = rb.nVal;
110 if( rb.bSet )
111 n |= 0x02;
112 rStm << n;
113 return rStm;
115 SvStream& operator >> (SvStream & rStm, SvBOOL & rb )
117 BYTE n;
118 rStm >> n;
119 rb.nVal = (n & 0x01) ? TRUE : FALSE;
120 rb.bSet = (n & 0x02) ? TRUE : FALSE;
121 if( n & ~0x03 )
123 rStm.SetError( SVSTREAM_FILEFORMAT_ERROR );
124 DBG_ERROR( "format error" );
126 return rStm;
129 /*************************************************************************
131 |* SvStream& operator << ( SvVersion )
132 |* SvStream& operator >> ( SvVersion )
134 |* Beschreibung
135 |* Ersterstellung MM 12.12.94
136 |* Letzte Aenderung MM 12.12.94
138 *************************************************************************/
139 SvStream& operator << (SvStream & rStm, const SvVersion & r )
141 if( (r.GetMajorVersion() || r.GetMinorVersion())
142 && r.GetMajorVersion() <= 0x0F && r.GetMinorVersion() <= 0x0F )
143 { // Versionsnummer in 1 Byte komprimieren
144 // Format 4 Bit fuer Major, dann 4 Bit fuer Minor.
145 // 0.0 wird nicht komprimiert
147 int n = r.GetMajorVersion() << 4;
148 n |= r.GetMinorVersion();
149 rStm << (BYTE)n;
151 else
153 rStm << (BYTE)0;
154 rStm << r.GetMajorVersion();
155 rStm << r.GetMinorVersion();
157 return rStm;
160 SvStream& operator >> (SvStream & rStm, SvVersion & r )
162 BYTE n;
163 rStm >> n;
164 if( n == 0 )
165 { // nicht komprimiert
166 rStm >> r.nMajorVersion;
167 rStm >> r.nMinorVersion;
169 else
170 { // komprimiert
171 r.nMajorVersion = (n >> 4) & 0x0F;
172 r.nMinorVersion = n & 0x0F;
174 return rStm;
178 #ifdef IDL_COMPILER
179 /************************************************************************/
181 /*************************************************************************
183 |* SvBOOL::ReadSvIdl()
185 |* Beschreibung
186 |* Ersterstellung MM 12.12.94
187 |* Letzte Aenderung MM 12.12.94
189 *************************************************************************/
190 BOOL SvBOOL::ReadSvIdl( SvStringHashEntry * pName, SvTokenStream & rInStm )
192 UINT32 nTokPos = rInStm.Tell();
193 SvToken * pTok = rInStm.GetToken_Next();
195 if( pTok->Is( pName ) )
197 BOOL bOk = TRUE;
198 BOOL bBraket = rInStm.Read( '(' );
199 if( bBraket || rInStm.Read( '=' ) )
201 pTok = rInStm.GetToken();
202 if( pTok->IsBool() )
204 *this = pTok->GetBool();
206 rInStm.GetToken_Next();
208 if( bOk && bBraket )
209 bOk = rInStm.Read( ')' );
211 else
212 *this = TRUE; //Defaultaktion ist auf TRUE setzen
213 if( bOk )
214 return TRUE;
216 rInStm.Seek( nTokPos );
217 return FALSE;
220 /*************************************************************************
222 |* SvBOOL::WriteSvIdl()
224 |* Beschreibung
226 *************************************************************************/
227 BOOL SvBOOL::WriteSvIdl( SvStringHashEntry * pName, SvStream & rOutStm )
229 if( nVal )
230 rOutStm << pName->GetName().GetBuffer();
231 else
232 rOutStm << pName->GetName().GetBuffer() << "(FALSE)";
233 return TRUE;
236 /*************************************************************************
238 |* SvBOOL::WriteSvIdl()
240 |* Beschreibung
242 *************************************************************************/
243 ByteString SvBOOL::GetSvIdlString( SvStringHashEntry * pName )
245 if( nVal )
246 return pName->GetName();
247 else
249 ByteString aTmp( pName->GetName() );
250 aTmp += "(FALSE)";
251 return aTmp;
256 /************************************************************************/
257 /*************************************************************************
259 |* SvIdentifier::ReadSvIdl()
261 |* Beschreibung
263 *************************************************************************/
264 BOOL SvIdentifier::ReadSvIdl( SvStringHashEntry * pName, SvTokenStream & rInStm )
266 UINT32 nTokPos = rInStm.Tell();
267 SvToken * pTok = rInStm.GetToken_Next();
269 if( pTok->Is( pName ) )
271 BOOL bOk = TRUE;
272 BOOL bBraket = rInStm.Read( '(' );
273 if( bBraket || rInStm.Read( '=' ) )
275 pTok = rInStm.GetToken();
276 if( pTok->IsIdentifier() )
278 *(ByteString *)this = pTok->GetString();
279 rInStm.GetToken_Next();
281 if( bOk && bBraket )
282 bOk = rInStm.Read( ')' );
284 if( bOk )
285 return TRUE;
287 rInStm.Seek( nTokPos );
288 return FALSE;
291 /*************************************************************************
293 |* SvIdentifier::WriteSvIdl()
295 |* Beschreibung
297 *************************************************************************/
298 BOOL SvIdentifier::WriteSvIdl( SvStringHashEntry * pName,
299 SvStream & rOutStm,
300 USHORT /*nTab */ )
302 rOutStm << pName->GetName().GetBuffer() << '(';
303 rOutStm << GetBuffer() << ')';
304 return TRUE;
307 SvStream& operator << (SvStream & rStm, const SvIdentifier & r )
309 rStm.WriteByteString( r );
310 return rStm;
313 SvStream& operator >> (SvStream & rStm, SvIdentifier & r )
315 rStm.ReadByteString( r );
316 return rStm;
320 /************************************************************************/
321 /*************************************************************************
323 |* SvNumberIdentifier::ReadSvIdl()
325 |* Beschreibung
327 *************************************************************************/
328 BOOL SvNumberIdentifier::ReadSvIdl( SvIdlDataBase & rBase,
329 SvStringHashEntry * pName,
330 SvTokenStream & rInStm )
332 if( SvIdentifier::ReadSvIdl( pName, rInStm ) )
334 ULONG n;
335 if( rBase.FindId( *this, &n ) )
337 nValue = n;
338 return TRUE;
340 else
342 ByteString aStr ("no value for identifier <");
343 aStr += *this;
344 aStr += "> ";
345 rBase.SetError( aStr, rInStm.GetToken() );
346 rBase.WriteError( rInStm );
349 return FALSE;
352 /*************************************************************************
354 |* SvNumberIdentifier::ReadSvIdl()
356 |* Beschreibung
358 *************************************************************************/
359 BOOL SvNumberIdentifier::ReadSvIdl( SvIdlDataBase & rBase,
360 SvTokenStream & rInStm )
362 UINT32 nTokPos = rInStm.Tell();
363 SvToken * pTok = rInStm.GetToken_Next();
365 if( pTok->IsIdentifier() )
367 ULONG n;
368 if( rBase.FindId( pTok->GetString(), &n ) )
370 *(ByteString *)this = pTok->GetString();
371 nValue = n;
372 return TRUE;
374 else
376 ByteString aStr ("no value for identifier <");
377 aStr += *this;
378 aStr += "> ";
379 rBase.SetError( aStr, rInStm.GetToken() );
380 rBase.WriteError( rInStm );
383 rInStm.Seek( nTokPos );
384 return FALSE;
387 /*************************************************************************
389 |* SvStream& operator << ( SvNumberIdentifier )
390 |* SvStream& operator >> ( SvNumberIdentifier )
392 |* Beschreibung
393 |* Ersterstellung MM 12.12.94
394 |* Letzte Aenderung MM 12.12.94
396 *************************************************************************/
397 SvStream& operator << (SvStream & rStm, const SvNumberIdentifier & r )
399 rStm << (SvIdentifier &)r;
400 SvPersistStream::WriteCompressed( rStm, r.nValue );
401 return rStm;
404 SvStream& operator >> (SvStream & rStm, SvNumberIdentifier & r )
406 rStm >> (SvIdentifier &)r;
407 r.nValue = SvPersistStream::ReadCompressed( rStm );
408 return rStm;
412 /************************************************************************/
413 /*************************************************************************
415 |* SvString::ReadSvIdl()
417 |* Beschreibung
418 |* Ersterstellung MM 12.12.94
419 |* Letzte Aenderung MM 12.12.94
421 *************************************************************************/
422 BOOL SvString::ReadSvIdl( SvStringHashEntry * pName, SvTokenStream & rInStm )
424 UINT32 nTokPos = rInStm.Tell();
425 SvToken * pTok = rInStm.GetToken_Next();
427 if( pTok->Is( pName ) )
429 BOOL bOk = TRUE;
430 BOOL bBraket = rInStm.Read( '(' );
431 if( bBraket || rInStm.Read( '=' ) )
433 pTok = rInStm.GetToken();
434 if( pTok->IsString() )
436 *(ByteString *)this = pTok->GetString();
437 rInStm.GetToken_Next();
439 if( bOk && bBraket )
440 bOk = rInStm.Read( ')' );
442 if( bOk )
443 return TRUE;
445 rInStm.Seek( nTokPos );
446 return FALSE;
449 /*************************************************************************
451 |* SvString::WriteSvIdl()
453 |* Beschreibung
454 |* Ersterstellung MM 12.12.94
455 |* Letzte Aenderung MM 12.12.94
457 *************************************************************************/
458 BOOL SvString::WriteSvIdl( SvStringHashEntry * pName, SvStream & rOutStm,
459 USHORT /*nTab */ )
461 rOutStm << pName->GetName().GetBuffer() << "(\"";
462 rOutStm << GetBuffer() << "\")";
463 return TRUE;
466 SvStream& operator << (SvStream & rStm, const SvString & r )
468 rStm.WriteByteString( r );
469 return rStm;
472 SvStream& operator >> (SvStream & rStm, SvString & r )
474 rStm.ReadByteString( r );
475 return rStm;
479 /*************************************************************************
481 |* SvHelpText::ReadSvIdl()
483 |* Beschreibung
484 |* Ersterstellung MM 12.12.94
485 |* Letzte Aenderung MM 12.12.94
487 *************************************************************************/
488 BOOL SvHelpText::ReadSvIdl( SvIdlDataBase &, SvTokenStream & rInStm )
490 return SvString::ReadSvIdl( SvHash_HelpText(), rInStm );
493 /*************************************************************************
495 |* SvHelpText::WriteSvIdl()
497 |* Beschreibung
498 |* Ersterstellung MM 12.12.94
499 |* Letzte Aenderung MM 12.12.94
501 *************************************************************************/
502 BOOL SvHelpText::WriteSvIdl( SvIdlDataBase &, SvStream & rOutStm, USHORT nTab )
504 return SvString::WriteSvIdl( SvHash_HelpText(), rOutStm, nTab );
507 /************************************************************************/
508 /*************************************************************************
510 |* SvUUId::ReadSvIdl()
512 |* Beschreibung
513 |* Ersterstellung MM 12.12.94
514 |* Letzte Aenderung MM 12.12.94
516 *************************************************************************/
517 BOOL SvUUId::ReadSvIdl( SvIdlDataBase &, SvTokenStream & rInStm )
519 UINT32 nTokPos = rInStm.Tell();
520 SvToken * pTok = rInStm.GetToken_Next();
522 if( pTok->Is( SvHash_uuid() ) )
524 BOOL bOk = TRUE;
525 BOOL bBraket = rInStm.Read( '(' );
526 if( bBraket || rInStm.Read( '=' ) )
528 pTok = rInStm.GetToken();
529 if( pTok->IsString() )
531 pTok = rInStm.GetToken_Next();
532 bOk = MakeId( String::CreateFromAscii( pTok->GetString().GetBuffer() ) );
534 if( bOk && bBraket )
535 bOk = rInStm.Read( ')' );
537 if( bOk )
538 return TRUE;
540 rInStm.Seek( nTokPos );
541 return FALSE;
544 /*************************************************************************
546 |* SvMetaObject::WriteSvIdl()
548 |* Beschreibung
549 |* Ersterstellung MM 12.12.94
550 |* Letzte Aenderung MM 12.12.94
552 *************************************************************************/
553 BOOL SvUUId::WriteSvIdl( SvStream & rOutStm )
555 // Global Id schreiben
556 rOutStm << SvHash_uuid()->GetName().GetBuffer() << "(\"";
557 rOutStm << ByteString( GetHexName(), RTL_TEXTENCODING_UTF8 ).GetBuffer() << "\")";
558 return TRUE;
562 /************************************************************************/
563 /*************************************************************************
565 |* SvVersion::ReadSvIdl()
567 |* Beschreibung
568 |* Ersterstellung MM 12.12.94
569 |* Letzte Aenderung MM 12.12.94
571 *************************************************************************/
572 BOOL SvVersion::ReadSvIdl( SvTokenStream & rInStm )
574 ULONG n = 0;
576 UINT32 nTokPos = rInStm.Tell();
577 if( ReadRangeSvIdl( SvHash_Version(), rInStm, 0 , 0xFFFF, &n ) )
579 nMajorVersion = (USHORT)n;
580 if( rInStm.Read( '.' ) )
582 SvToken * pTok = rInStm.GetToken_Next();
583 if( pTok->IsInteger() && pTok->GetNumber() <= 0xFFFF )
585 nMinorVersion = (USHORT)pTok->GetNumber();
586 return TRUE;
589 else
590 return TRUE;
592 rInStm.Seek( nTokPos );
593 return FALSE;
596 /*************************************************************************
598 |* SvVersion::WriteSvIdl()
600 |* Beschreibung
601 |* Ersterstellung MM 12.12.94
602 |* Letzte Aenderung MM 12.12.94
604 *************************************************************************/
605 BOOL SvVersion::WriteSvIdl( SvStream & rOutStm )
607 rOutStm << SvHash_Version()->GetName().GetBuffer() << '('
608 << ByteString::CreateFromInt32( nMajorVersion ).GetBuffer() << '.'
609 << ByteString::CreateFromInt32( nMinorVersion ).GetBuffer() << ')';
610 return TRUE;
612 #endif //IDL_COMPILER