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: basobj.cxx,v $
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"
37 #include <tools/debug.hxx>
42 #include <globals.hxx>
43 #include <database.hxx>
45 /****************** SvMetaObject *****************************************/
46 SV_IMPL_META_FACTORY1( SvMetaObject
, SvRttiBase
)
47 /*************************************************************************
48 |* SvMetaObject::SvMetaObject()
51 *************************************************************************/
52 SvMetaObject::SvMetaObject()
56 void SvMetaObject::Load( SvPersistStream
& )
60 void SvMetaObject::Save( SvPersistStream
& )
64 /*************************************************************************
65 |* SvMetaObject::WriteTab()
68 *************************************************************************/
70 void SvMetaObject::WriteTab( SvStream
& rOutStm
, USHORT nTab
)
77 /*************************************************************************
78 |* SvMetaObject::WriteStart()
81 *************************************************************************/
82 void SvMetaObject::WriteStars( SvStream
& rOutStm
)
85 for( int i
= 6; i
> 0; i
-- )
86 rOutStm
<< "**********";
87 rOutStm
<< '/' << endl
;
90 /*************************************************************************
91 |* SvMetaObject::TestAndSeekSpaceOnly()
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
)
109 // nichts geschrieben
110 rOutStm
.Seek( nBegPos
);
112 rOutStm
.Seek( nPos
);
116 /*************************************************************************
117 |* SvMetaObject::Back2Delemitter()
120 *************************************************************************/
121 void SvMetaObject::Back2Delemitter( SvStream
& rOutStm
)
123 // keine leeren Klammern schreiben
124 ULONG nPos
= rOutStm
.Tell();
125 rOutStm
.SeekRel( -1 );
129 while( isspace( c
) && rOutStm
.Tell() != 1 )
131 rOutStm
.SeekRel( -2 );
135 if( c
== ';' || c
== ',' )
136 rOutStm
.SeekRel( -1 );
138 rOutStm
.Seek( nPos
);
141 /*************************************************************************
142 |* SvMetaObject::ReadSvIdl()
145 *************************************************************************/
146 BOOL
SvMetaObject::ReadSvIdl( SvIdlDataBase
&, SvTokenStream
& )
151 /*************************************************************************
152 |* SvMetaObject::WriteSvIdl()
155 *************************************************************************/
156 void SvMetaObject::WriteSvIdl( SvIdlDataBase
&, SvStream
&, USHORT
/*nTab */ )
160 /*************************************************************************
161 |* SvMetaObject::Write()
164 *************************************************************************/
165 void SvMetaObject::Write( SvIdlDataBase
&, SvStream
&, USHORT
/*nTab */,
166 WriteType
, WriteAttribute
)
170 /*************************************************************************
171 |* SvMetaObject::WriteCxx()
174 *************************************************************************/
175 void SvMetaObject::WriteCxx( SvIdlDataBase
&, SvStream
&, USHORT
/*nTab */ )
179 /*************************************************************************
180 |* SvMetaObject::WriteHxx()
183 *************************************************************************/
184 void SvMetaObject::WriteHxx( SvIdlDataBase
&, SvStream
&, USHORT
/*nTab */ )
190 /****************** SvMetaName *****************************************/
191 SV_IMPL_META_FACTORY1( SvMetaName
, SvMetaObject
);
192 /*************************************************************************
193 |* SvMetaName::SvMetaName()
196 *************************************************************************/
197 SvMetaName::SvMetaName()
201 void SvMetaName::Load( SvPersistStream
& rStm
)
203 SvMetaObject::Load( rStm
);
209 rStm
.SetError( SVSTREAM_FILEFORMAT_ERROR
);
210 DBG_ERROR( "wrong format" );
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
);
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;
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 /*************************************************************************
242 *************************************************************************/
243 BOOL
SvMetaName::SetName( const ByteString
& rName
, SvIdlDataBase
* )
250 /*************************************************************************
251 |* SvMetaName::ReadNameSvIdl()
254 *************************************************************************/
255 BOOL
SvMetaName::ReadNameSvIdl( SvIdlDataBase
& rBase
,
256 SvTokenStream
& rInStm
)
258 UINT32 nTokPos
= rInStm
.Tell();
259 SvToken
* pTok
= rInStm
.GetToken_Next();
262 if( pTok
->IsIdentifier() )
263 if( SetName( pTok
->GetString(), &rBase
) )
266 rInStm
.Seek( nTokPos
);
270 /*************************************************************************
271 |* SvMetaName::ReadSvIdl()
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(),
294 /*************************************************************************
295 |* SvMetaName::DoReadContextSvIdl()
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
);
308 rInStm
.ReadDelemiter();
314 /*************************************************************************
315 |* SvMetaName::ReadSvIdl()
318 *************************************************************************/
319 void SvMetaName::ReadContextSvIdl( SvIdlDataBase
&, SvTokenStream
& )
323 /*************************************************************************
324 |* SvMetaName::Test()
327 *************************************************************************/
328 BOOL
SvMetaName::Test( SvIdlDataBase
&, SvTokenStream
& )
333 /*************************************************************************
334 |* SvMetaName::WriteContextSvIdl()
337 *************************************************************************/
338 void SvMetaName::WriteContextSvIdl( SvIdlDataBase
&, SvStream
&, USHORT
)
342 /*************************************************************************
343 |* SvMetaName::WriteDescription()
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()
367 *************************************************************************/
368 void SvMetaName::WriteAttributesSvIdl( SvIdlDataBase
& rBase
,
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()
401 *************************************************************************/
402 BOOL
SvMetaName::ReadSvIdl( SvIdlDataBase
& rBase
, SvTokenStream
& rInStm
)
404 UINT32 nTokPos
= rInStm
.Tell();
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( ']' );
420 if( rInStm
.Read( '{' ) )
422 DoReadContextSvIdl( rBase
, rInStm
);
423 bOk
= rInStm
.Read( '}' );
428 rInStm
.Seek( nTokPos
);
432 /*************************************************************************
433 |* SvMetaName::WriteSvIdl()
436 *************************************************************************/
437 void SvMetaName::WriteSvIdl( SvIdlDataBase
& rBase
, SvStream
& rOutStm
,
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
);
452 WriteTab( rOutStm
, nTab
);
454 nBeginPos
= rOutStm
.Tell();
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
);
469 WriteTab( rOutStm
, nTab
);
474 /*************************************************************************
475 |* SvMetaName::Write()
478 *************************************************************************/
479 void SvMetaName::Write( SvIdlDataBase
& rBase
, SvStream
& rOutStm
,
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
)
501 // nichts geschrieben
502 rOutStm
.Seek( nBeginPos
);
505 rOutStm
.Seek( nPos
);
506 WriteTab( rOutStm
, nTab
);
507 rOutStm
<< ']' << endl
;
511 /*************************************************************************
512 |* SvMetaName::WriteAttributes()
515 *************************************************************************/
516 void SvMetaName::WriteAttributes( SvIdlDataBase
&, SvStream
& rOutStm
,
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()
540 /*************************************************************************
541 |* SvMetaName::WriteContext()
544 *************************************************************************/
545 void SvMetaName::WriteContext( SvIdlDataBase
&, SvStream
&,
547 WriteType
, WriteAttribute
)
550 #endif // IDL_COMPILER
552 /****************** SvMetaReference *****************************************/
553 SV_IMPL_META_FACTORY1( SvMetaReference
, SvMetaName
);
555 /*************************************************************************
556 |* SvMetaReference::SvMetaReference()
559 *************************************************************************/
560 SvMetaReference::SvMetaReference()
564 void SvMetaReference::Load( SvPersistStream
& rStm
)
566 SvMetaName::Load( rStm
);
572 rStm
.SetError( SVSTREAM_FILEFORMAT_ERROR
);
573 DBG_ERROR( "wrong format" );
578 SvMetaReference
* pRef
;
584 void SvMetaReference::Save( SvPersistStream
& rStm
)
586 SvMetaName::Save( rStm
);
595 if( nMask
& 0x01 ) rStm
<< aRef
;
598 /**************************************************************************/
599 /****************** SvMetaExtern ******************************************/
600 SV_IMPL_META_FACTORY1( SvMetaExtern
, SvMetaReference
);
602 /*************************************************************************
603 |* SvMetaExtern::SvMetaExtern()
606 *************************************************************************/
607 SvMetaExtern::SvMetaExtern()
610 , bReadVersion( FALSE
)
614 void SvMetaExtern::Load( SvPersistStream
& rStm
)
616 SvMetaReference::Load( rStm
);
622 rStm
.SetError( SVSTREAM_FILEFORMAT_ERROR
);
623 DBG_ERROR( "wrong format" );
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
);
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;
647 if( nMask
& 0x01 ) rStm
<< pModule
;
648 if( nMask
& 0x02 ) rStm
<< aUUId
;
649 if( nMask
& 0x04 ) rStm
<< aVersion
;
652 /*************************************************************************
653 |* SvMetaExtern::GetModule()
656 *************************************************************************/
657 SvMetaModule
* SvMetaExtern::GetModule() const
659 DBG_ASSERT( pModule
!= NULL
, "module not set" );
663 /*************************************************************************
664 |* SvMetaExtern::GetUUId()
667 *************************************************************************/
668 const SvGlobalName
& SvMetaExtern::GetUUId() const
671 if( aUUId
== SvGlobalName() )
672 GetModule()->FillNextName( &((SvMetaExtern
*)this)->aUUId
);
678 /*************************************************************************
679 |* SvMetaExtern::SetModule()
682 *************************************************************************/
683 void SvMetaExtern::SetModule( SvIdlDataBase
& rBase
)
685 pModule
= (SvMetaModule
*)rBase
.GetStack().Get( TYPE( SvMetaModule
) );
688 /*************************************************************************
689 |* SvMetaExtern::ReadAttributesSvIdl()
692 *************************************************************************/
693 void SvMetaExtern::ReadAttributesSvIdl( SvIdlDataBase
& rBase
,
694 SvTokenStream
& rInStm
)
696 SvMetaReference::ReadAttributesSvIdl( rBase
, rInStm
);
697 if( aUUId
.ReadSvIdl( rBase
, rInStm
) )
699 if( aVersion
.ReadSvIdl( rInStm
) )
703 /*************************************************************************
704 |* SvMetaExtern::WriteAttributesSvIdl()
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
;
719 WriteTab( rOutStm
, nTab
);
720 aUUId
.WriteSvIdl( rOutStm
);
721 rOutStm
<< ';' << endl
;
725 WriteTab( rOutStm
, nTab
);
726 aVersion
.WriteSvIdl( rOutStm
);
727 rOutStm
<< ';' << endl
;
732 /*************************************************************************
733 |* SvMetaExtern::ReadSvIdl()
736 *************************************************************************/
737 BOOL
SvMetaExtern::ReadSvIdl( SvIdlDataBase
& rBase
, SvTokenStream
& rInStm
)
740 GetUUId(); // Id wird angelegt
741 return SvMetaReference::ReadSvIdl( rBase
, rInStm
);
744 /*************************************************************************
745 |* SvMetaExtern::WriteSvIdl()
748 *************************************************************************/
749 void SvMetaExtern::WriteSvIdl( SvIdlDataBase
& rBase
, SvStream
& rOutStm
,
752 SvMetaReference::WriteSvIdl( rBase
, rOutStm
, nTab
);
755 /*************************************************************************
756 |* SvMetaExtern::Write()
759 *************************************************************************/
760 void SvMetaExtern::Write( SvIdlDataBase
& rBase
, SvStream
& rOutStm
,
762 WriteType nT
, WriteAttribute nA
)
764 SvMetaReference::Write( rBase
, rOutStm
, nTab
, nT
, nA
);
767 /*************************************************************************
768 |* SvMetaExtern::WriteAttributes()
771 *************************************************************************/
772 void SvMetaExtern::WriteAttributes( SvIdlDataBase
& rBase
, SvStream
& rOutStm
,
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