merge the formfield patch from ooo-build
[ooovba.git] / idl / source / objects / basobj.cxx
blob68a4706138551d1cf0297630c17d6a5f23477ed4
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: basobj.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 <ctype.h>
35 #include <stdio.h>
37 #include <tools/debug.hxx>
39 #include <attrib.hxx>
40 #include <basobj.hxx>
41 #include <module.hxx>
42 #include <globals.hxx>
43 #include <database.hxx>
45 /****************** SvMetaObject *****************************************/
46 SV_IMPL_META_FACTORY1( SvMetaObject, SvRttiBase )
47 /*************************************************************************
48 |* SvMetaObject::SvMetaObject()
50 |* Beschreibung
51 *************************************************************************/
52 SvMetaObject::SvMetaObject()
56 void SvMetaObject::Load( SvPersistStream & )
60 void SvMetaObject::Save( SvPersistStream & )
64 /*************************************************************************
65 |* SvMetaObject::WriteTab()
67 |* Beschreibung
68 *************************************************************************/
69 #ifdef IDL_COMPILER
70 void SvMetaObject::WriteTab( SvStream & rOutStm, USHORT nTab )
72 while( nTab-- )
73 rOutStm << " ";
74 // rOutStm << '\t';
77 /*************************************************************************
78 |* SvMetaObject::WriteStart()
80 |* Beschreibung
81 *************************************************************************/
82 void SvMetaObject::WriteStars( SvStream & rOutStm )
84 rOutStm << '/';
85 for( int i = 6; i > 0; i-- )
86 rOutStm << "**********";
87 rOutStm << '/' << endl;
90 /*************************************************************************
91 |* SvMetaObject::TestAndSeekSpaceOnly()
93 |* Beschreibung
94 *************************************************************************/
95 BOOL SvMetaObject::TestAndSeekSpaceOnly( SvStream & rOutStm, ULONG nBegPos )
97 // keine leeren Klammern schreiben
98 ULONG nPos = rOutStm.Tell();
99 rOutStm.Seek( nBegPos );
100 BOOL bOnlySpace = TRUE;
101 while( bOnlySpace && rOutStm.Tell() < nPos )
103 char c;
104 rOutStm >> c;
105 if( !isspace( c ) )
106 bOnlySpace = FALSE;
108 if( bOnlySpace )
109 // nichts geschrieben
110 rOutStm.Seek( nBegPos );
111 else
112 rOutStm.Seek( nPos );
113 return bOnlySpace;
116 /*************************************************************************
117 |* SvMetaObject::Back2Delemitter()
119 |* Beschreibung
120 *************************************************************************/
121 void SvMetaObject::Back2Delemitter( SvStream & rOutStm )
123 // keine leeren Klammern schreiben
124 ULONG nPos = rOutStm.Tell();
125 rOutStm.SeekRel( -1 );
126 char c = 0;
127 rOutStm >> c;
129 while( isspace( c ) && rOutStm.Tell() != 1 )
131 rOutStm.SeekRel( -2 );
132 rOutStm >> c;
135 if( c == ';' || c == ',' )
136 rOutStm.SeekRel( -1 );
137 else
138 rOutStm.Seek( nPos );
141 /*************************************************************************
142 |* SvMetaObject::ReadSvIdl()
144 |* Beschreibung
145 *************************************************************************/
146 BOOL SvMetaObject::ReadSvIdl( SvIdlDataBase &, SvTokenStream & )
148 return FALSE;
151 /*************************************************************************
152 |* SvMetaObject::WriteSvIdl()
154 |* Beschreibung
155 *************************************************************************/
156 void SvMetaObject::WriteSvIdl( SvIdlDataBase &, SvStream &, USHORT /*nTab */ )
160 /*************************************************************************
161 |* SvMetaObject::Write()
163 |* Beschreibung
164 *************************************************************************/
165 void SvMetaObject::Write( SvIdlDataBase &, SvStream &, USHORT /*nTab */,
166 WriteType, WriteAttribute )
170 /*************************************************************************
171 |* SvMetaObject::WriteCxx()
173 |* Beschreibung
174 *************************************************************************/
175 void SvMetaObject::WriteCxx( SvIdlDataBase &, SvStream &, USHORT /*nTab */ )
179 /*************************************************************************
180 |* SvMetaObject::WriteHxx()
182 |* Beschreibung
183 *************************************************************************/
184 void SvMetaObject::WriteHxx( SvIdlDataBase &, SvStream &, USHORT /*nTab */ )
188 #endif
190 /****************** SvMetaName *****************************************/
191 SV_IMPL_META_FACTORY1( SvMetaName, SvMetaObject );
192 /*************************************************************************
193 |* SvMetaName::SvMetaName()
195 |* Beschreibung
196 *************************************************************************/
197 SvMetaName::SvMetaName()
201 void SvMetaName::Load( SvPersistStream & rStm )
203 SvMetaObject::Load( rStm );
204 BYTE nMask;
205 rStm >> nMask;
207 if( nMask >= 0x20 )
209 rStm.SetError( SVSTREAM_FILEFORMAT_ERROR );
210 DBG_ERROR( "wrong format" );
211 return;
213 if( nMask & 0x01 ) rStm >> aName;
214 if( nMask & 0x02 ) rStm >> aHelpContext;
215 if( nMask & 0x04 ) rStm >> aHelpText;
216 if( nMask & 0x08 ) rStm >> aConfigName;
217 if( nMask & 0x10 ) rStm >> aDescription;
220 void SvMetaName::Save( SvPersistStream & rStm )
222 SvMetaObject::Save( rStm );
223 BYTE nMask = 0;
224 if( aName.IsSet() ) nMask |= 0x01;
225 if( aHelpContext.IsSet() ) nMask |= 0x02;
226 if( aHelpText.IsSet() ) nMask |= 0x04;
227 if( aConfigName.IsSet() ) nMask |= 0x08;
228 if( aDescription.IsSet() ) nMask |= 0x10;
230 rStm << nMask;
231 if( nMask & 0x01 ) rStm << aName;
232 if( nMask & 0x02 ) rStm << aHelpContext;
233 if( nMask & 0x04 ) rStm << aHelpText;
234 if( nMask & 0x08 ) rStm << aConfigName;
235 if( nMask & 0x10 ) rStm << aDescription;
238 /*************************************************************************
241 |* Beschreibung
242 *************************************************************************/
243 BOOL SvMetaName::SetName( const ByteString & rName, SvIdlDataBase * )
245 aName = rName;
246 return TRUE;
249 #ifdef IDL_COMPILER
250 /*************************************************************************
251 |* SvMetaName::ReadNameSvIdl()
253 |* Beschreibung
254 *************************************************************************/
255 BOOL SvMetaName::ReadNameSvIdl( SvIdlDataBase & rBase,
256 SvTokenStream & rInStm )
258 UINT32 nTokPos = rInStm.Tell();
259 SvToken * pTok = rInStm.GetToken_Next();
261 // Modulnamen lesen
262 if( pTok->IsIdentifier() )
263 if( SetName( pTok->GetString(), &rBase ) )
264 return TRUE;
266 rInStm.Seek( nTokPos );
267 return FALSE;
270 /*************************************************************************
271 |* SvMetaName::ReadSvIdl()
273 |* Beschreibung
274 *************************************************************************/
275 void SvMetaName::ReadAttributesSvIdl( SvIdlDataBase & rBase,
276 SvTokenStream & rInStm )
278 UINT32 nTokPos = rInStm.Tell();
279 if( aName.ReadSvIdl( SvHash_Name(), rInStm ) )
281 if( !SetName( aName, &rBase ) )
282 rInStm.Seek( nTokPos );
284 aHelpContext.ReadSvIdl( rBase, SvHash_HelpContext(), rInStm );
285 aHelpText.ReadSvIdl( rBase, rInStm );
286 aConfigName.ReadSvIdl( SvHash_ConfigName(), rInStm );
287 aDescription.ReadSvIdl( SvHash_Description(), rInStm );
289 aHelpContext.ReadSvIdl( GetModule()->GetInfo()->GetHelpContextContainer(),
290 rInStm );
294 /*************************************************************************
295 |* SvMetaName::DoReadContextSvIdl()
297 |* Beschreibung
298 *************************************************************************/
299 void SvMetaName::DoReadContextSvIdl( SvIdlDataBase & rBase,
300 SvTokenStream & rInStm, char cDel )
302 UINT32 nBeginPos = 0; // kann mit Tell nicht vorkommen
303 while( nBeginPos != rInStm.Tell() )
305 nBeginPos = rInStm.Tell();
306 ReadContextSvIdl( rBase, rInStm );
307 if( cDel == '\0' )
308 rInStm.ReadDelemiter();
309 else
310 rInStm.Read( cDel );
314 /*************************************************************************
315 |* SvMetaName::ReadSvIdl()
317 |* Beschreibung
318 *************************************************************************/
319 void SvMetaName::ReadContextSvIdl( SvIdlDataBase &, SvTokenStream & )
323 /*************************************************************************
324 |* SvMetaName::Test()
326 |* Beschreibung
327 *************************************************************************/
328 BOOL SvMetaName::Test( SvIdlDataBase &, SvTokenStream & )
330 return TRUE;
333 /*************************************************************************
334 |* SvMetaName::WriteContextSvIdl()
336 |* Beschreibung
337 *************************************************************************/
338 void SvMetaName::WriteContextSvIdl( SvIdlDataBase &, SvStream &, USHORT )
342 /*************************************************************************
343 |* SvMetaName::WriteDescription()
345 |* Beschreibung
346 *************************************************************************/
347 void SvMetaName::WriteDescription( SvStream & rOutStm )
349 rOutStm << "<DESCRIPTION>" << endl;
351 ByteString aDesc( GetDescription() );
352 USHORT nPos = aDesc.Search( '\n' );
353 while ( nPos != STRING_NOTFOUND )
355 rOutStm << aDesc.Copy( 0, nPos ).GetBuffer() << endl;
356 aDesc.Erase(0,nPos+1);
357 nPos = aDesc.Search( '\n' );
360 rOutStm << aDesc.GetBuffer() << endl << "</DESCRIPTION>" << endl;
363 /*************************************************************************
364 |* SvMetaName::WriteAttributesIdl()
366 |* Beschreibung
367 *************************************************************************/
368 void SvMetaName::WriteAttributesSvIdl( SvIdlDataBase & rBase,
369 SvStream & rOutStm,
370 USHORT nTab )
372 if( aHelpContext.IsSet() || aHelpText.IsSet() || aConfigName.IsSet() )
374 WriteTab( rOutStm, nTab );
375 rOutStm << "// class SvMetaName" << endl;
377 if( aHelpContext.IsSet() )
379 WriteTab( rOutStm, nTab );
380 aHelpContext.WriteSvIdl( SvHash_HelpContext(), rOutStm, nTab );
381 rOutStm << ';' << endl;
383 if( aHelpText.IsSet() )
385 WriteTab( rOutStm, nTab );
386 aHelpText.WriteSvIdl( rBase, rOutStm, nTab );
387 rOutStm << ';' << endl;
389 if( aConfigName.IsSet() )
391 WriteTab( rOutStm, nTab );
392 aConfigName.WriteSvIdl( SvHash_ConfigName(), rOutStm, nTab );
393 rOutStm << ';' << endl;
397 /*************************************************************************
398 |* SvMetaName::ReadSvIdl()
400 |* Beschreibung
401 *************************************************************************/
402 BOOL SvMetaName::ReadSvIdl( SvIdlDataBase & rBase, SvTokenStream & rInStm )
404 UINT32 nTokPos = rInStm.Tell();
405 BOOL bOk = TRUE;
406 if( rInStm.Read( '[' ) )
408 UINT32 nBeginPos = 0; // kann mit Tell nicht vorkommen
409 while( nBeginPos != rInStm.Tell() )
411 nBeginPos = rInStm.Tell();
412 ReadAttributesSvIdl( rBase, rInStm );
413 rInStm.ReadDelemiter();
415 bOk = rInStm.Read( ']' );
418 if( bOk )
420 if( rInStm.Read( '{' ) )
422 DoReadContextSvIdl( rBase, rInStm );
423 bOk = rInStm.Read( '}' );
427 if( !bOk )
428 rInStm.Seek( nTokPos );
429 return bOk;
432 /*************************************************************************
433 |* SvMetaName::WriteSvIdl()
435 |* Beschreibung
436 *************************************************************************/
437 void SvMetaName::WriteSvIdl( SvIdlDataBase & rBase, SvStream & rOutStm,
438 USHORT nTab )
440 ULONG nBeginPos = rOutStm.Tell();
441 WriteTab( rOutStm, nTab );
442 rOutStm << '[' << endl;
443 ULONG nOldPos = rOutStm.Tell();
444 WriteAttributesSvIdl( rBase, rOutStm, nTab +1 );
446 // keine leeren Klammern schreiben
447 if( TestAndSeekSpaceOnly( rOutStm, nOldPos ) )
448 // nichts geschrieben
449 rOutStm.Seek( nBeginPos );
450 else
452 WriteTab( rOutStm, nTab );
453 rOutStm << ']';
454 nBeginPos = rOutStm.Tell();
455 rOutStm << endl;
458 WriteTab( rOutStm, nTab );
459 rOutStm << '{' << endl;
460 nOldPos = rOutStm.Tell();
461 WriteContextSvIdl( rBase, rOutStm, nTab +1 );
463 // keine leeren Klammern schreiben
464 if( TestAndSeekSpaceOnly( rOutStm, nOldPos ) )
465 // nichts geschrieben
466 rOutStm.Seek( nBeginPos );
467 else
469 WriteTab( rOutStm, nTab );
470 rOutStm << '}';
474 /*************************************************************************
475 |* SvMetaName::Write()
477 |* Beschreibung
478 *************************************************************************/
479 void SvMetaName::Write( SvIdlDataBase & rBase, SvStream & rOutStm,
480 USHORT nTab,
481 WriteType nT, WriteAttribute nA )
483 ULONG nBeginPos = rOutStm.Tell();
484 WriteTab( rOutStm, nTab );
485 rOutStm << '[' << endl;
486 ULONG nOldPos = rOutStm.Tell();
487 WriteAttributes( rBase, rOutStm, nTab +1, nT, nA );
489 // keine leeren Klammern schreiben
490 ULONG nPos = rOutStm.Tell();
491 rOutStm.Seek( nOldPos );
492 BOOL bOnlySpace = TRUE;
493 while( bOnlySpace && rOutStm.Tell() < nPos )
495 char c;
496 rOutStm >> c;
497 if( !isspace( c ) )
498 bOnlySpace = FALSE;
500 if( bOnlySpace )
501 // nichts geschrieben
502 rOutStm.Seek( nBeginPos );
503 else
505 rOutStm.Seek( nPos );
506 WriteTab( rOutStm, nTab );
507 rOutStm << ']' << endl;
511 /*************************************************************************
512 |* SvMetaName::WriteAttributes()
514 |* Beschreibung
515 *************************************************************************/
516 void SvMetaName::WriteAttributes( SvIdlDataBase &, SvStream & rOutStm,
517 USHORT nTab,
518 WriteType, WriteAttribute )
520 if( GetHelpText().IsSet() || GetHelpContext().IsSet() )
522 WriteTab( rOutStm, nTab );
523 rOutStm << "// class SvMetaName" << endl;
525 if( GetHelpText().IsSet() )
527 WriteTab( rOutStm, nTab );
528 rOutStm << "helpstring(\"" << GetHelpText().GetBuffer() << "\")," << endl;
530 if( GetHelpContext().IsSet() )
532 WriteTab( rOutStm, nTab );
533 rOutStm << "helpcontext("
534 << ByteString::CreateFromInt64(
535 GetHelpContext().GetValue() ).GetBuffer()
536 << ")," << endl;
540 /*************************************************************************
541 |* SvMetaName::WriteContext()
543 |* Beschreibung
544 *************************************************************************/
545 void SvMetaName::WriteContext( SvIdlDataBase &, SvStream &,
546 USHORT,
547 WriteType, WriteAttribute )
550 #endif // IDL_COMPILER
552 /****************** SvMetaReference *****************************************/
553 SV_IMPL_META_FACTORY1( SvMetaReference, SvMetaName );
555 /*************************************************************************
556 |* SvMetaReference::SvMetaReference()
558 |* Beschreibung
559 *************************************************************************/
560 SvMetaReference::SvMetaReference()
564 void SvMetaReference::Load( SvPersistStream & rStm )
566 SvMetaName::Load( rStm );
568 BYTE nMask;
569 rStm >> nMask;
570 if( nMask >= 0x2 )
572 rStm.SetError( SVSTREAM_FILEFORMAT_ERROR );
573 DBG_ERROR( "wrong format" );
574 return;
576 if( nMask & 0x01 )
578 SvMetaReference * pRef;
579 rStm >> pRef;
580 aRef = pRef;
584 void SvMetaReference::Save( SvPersistStream & rStm )
586 SvMetaName::Save( rStm );
588 // Maske erstellen
589 BYTE nMask = 0;
590 if( aRef.Is() )
591 nMask |= 0x01;
593 // Daten schreiben
594 rStm << nMask;
595 if( nMask & 0x01 ) rStm << aRef;
598 /**************************************************************************/
599 /****************** SvMetaExtern ******************************************/
600 SV_IMPL_META_FACTORY1( SvMetaExtern, SvMetaReference );
602 /*************************************************************************
603 |* SvMetaExtern::SvMetaExtern()
605 |* Beschreibung
606 *************************************************************************/
607 SvMetaExtern::SvMetaExtern()
608 : pModule( NULL )
609 , bReadUUId( FALSE )
610 , bReadVersion( FALSE )
614 void SvMetaExtern::Load( SvPersistStream & rStm )
616 SvMetaReference::Load( rStm );
618 BYTE nMask;
619 rStm >> nMask;
620 if( nMask >= 0x20 )
622 rStm.SetError( SVSTREAM_FILEFORMAT_ERROR );
623 DBG_ERROR( "wrong format" );
624 return;
626 if( nMask & 0x01 ) rStm >> pModule;
627 if( nMask & 0x02 ) rStm >> aUUId;
628 if( nMask & 0x04 ) rStm >> aVersion;
629 if( nMask & 0x08 ) bReadUUId = TRUE;
630 if( nMask & 0x10 ) bReadVersion = TRUE;
633 void SvMetaExtern::Save( SvPersistStream & rStm )
635 SvMetaReference::Save( rStm );
637 // Maske erstellen
638 BYTE nMask = 0;
639 if( pModule ) nMask |= 0x01;
640 if( aUUId != SvGlobalName() ) nMask |= 0x02;
641 if( aVersion != SvVersion() ) nMask |= 0x04;
642 if( bReadUUId ) nMask |= 0x08;
643 if( bReadVersion ) nMask |= 0x10;
645 // Daten schreiben
646 rStm << nMask;
647 if( nMask & 0x01 ) rStm << pModule;
648 if( nMask & 0x02 ) rStm << aUUId;
649 if( nMask & 0x04 ) rStm << aVersion;
652 /*************************************************************************
653 |* SvMetaExtern::GetModule()
655 |* Beschreibung
656 *************************************************************************/
657 SvMetaModule * SvMetaExtern::GetModule() const
659 DBG_ASSERT( pModule != NULL, "module not set" );
660 return pModule;
663 /*************************************************************************
664 |* SvMetaExtern::GetUUId()
666 |* Beschreibung
667 *************************************************************************/
668 const SvGlobalName & SvMetaExtern::GetUUId() const
670 #ifdef IDL_COMPILER
671 if( aUUId == SvGlobalName() )
672 GetModule()->FillNextName( &((SvMetaExtern *)this)->aUUId );
673 #endif
674 return aUUId;
677 #ifdef IDL_COMPILER
678 /*************************************************************************
679 |* SvMetaExtern::SetModule()
681 |* Beschreibung
682 *************************************************************************/
683 void SvMetaExtern::SetModule( SvIdlDataBase & rBase )
685 pModule = (SvMetaModule *)rBase.GetStack().Get( TYPE( SvMetaModule ) );
688 /*************************************************************************
689 |* SvMetaExtern::ReadAttributesSvIdl()
691 |* Beschreibung
692 *************************************************************************/
693 void SvMetaExtern::ReadAttributesSvIdl( SvIdlDataBase & rBase,
694 SvTokenStream & rInStm )
696 SvMetaReference::ReadAttributesSvIdl( rBase, rInStm );
697 if( aUUId.ReadSvIdl( rBase, rInStm ) )
698 bReadUUId = TRUE;
699 if( aVersion.ReadSvIdl( rInStm ) )
700 bReadVersion = TRUE;
703 /*************************************************************************
704 |* SvMetaExtern::WriteAttributesSvIdl()
706 |* Beschreibung
707 *************************************************************************/
708 void SvMetaExtern::WriteAttributesSvIdl( SvIdlDataBase & rBase,
709 SvStream & rOutStm, USHORT nTab )
711 SvMetaReference::WriteAttributesSvIdl( rBase, rOutStm, nTab );
712 if( bReadUUId || bReadVersion )
714 WriteTab( rOutStm, nTab );
715 rOutStm << "// class SvMetaExtern" << endl;
717 if( bReadUUId )
719 WriteTab( rOutStm, nTab );
720 aUUId.WriteSvIdl( rOutStm );
721 rOutStm << ';' << endl;
723 if( bReadVersion )
725 WriteTab( rOutStm, nTab );
726 aVersion.WriteSvIdl( rOutStm );
727 rOutStm << ';' << endl;
732 /*************************************************************************
733 |* SvMetaExtern::ReadSvIdl()
735 |* Beschreibung
736 *************************************************************************/
737 BOOL SvMetaExtern::ReadSvIdl( SvIdlDataBase & rBase, SvTokenStream & rInStm )
739 SetModule( rBase );
740 GetUUId(); // Id wird angelegt
741 return SvMetaReference::ReadSvIdl( rBase, rInStm );
744 /*************************************************************************
745 |* SvMetaExtern::WriteSvIdl()
747 |* Beschreibung
748 *************************************************************************/
749 void SvMetaExtern::WriteSvIdl( SvIdlDataBase & rBase, SvStream & rOutStm,
750 USHORT nTab )
752 SvMetaReference::WriteSvIdl( rBase, rOutStm, nTab );
755 /*************************************************************************
756 |* SvMetaExtern::Write()
758 |* Beschreibung
759 *************************************************************************/
760 void SvMetaExtern::Write( SvIdlDataBase & rBase, SvStream & rOutStm,
761 USHORT nTab,
762 WriteType nT, WriteAttribute nA )
764 SvMetaReference::Write( rBase, rOutStm, nTab, nT, nA );
767 /*************************************************************************
768 |* SvMetaExtern::WriteAttributes()
770 |* Beschreibung
771 *************************************************************************/
772 void SvMetaExtern::WriteAttributes( SvIdlDataBase & rBase, SvStream & rOutStm,
773 USHORT nTab,
774 WriteType nT, WriteAttribute nA )
776 SvMetaReference::WriteAttributes( rBase, rOutStm, nTab, nT, nA );
778 WriteTab( rOutStm, nTab );
779 rOutStm << "// class SvMetaExtern" << endl;
780 WriteTab( rOutStm, nTab );
781 rOutStm << "uuid(" << ByteString( GetUUId().GetHexName(), RTL_TEXTENCODING_UTF8 ).GetBuffer() << ")," << endl;
782 WriteTab( rOutStm, nTab );
783 rOutStm << "version(" << ByteString::CreateFromInt32( aVersion.GetMajorVersion() ).GetBuffer() << '.'
784 << ByteString::CreateFromInt32( aVersion.GetMinorVersion() ).GetBuffer() << ")," << endl;
787 #endif // IDL_COMPILER