1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_idl.hxx"
34 #include <tools/debug.hxx>
39 #include <globals.hxx>
40 #include <database.hxx>
42 /****************** SvMetaObject *****************************************/
43 SV_IMPL_META_FACTORY1( SvMetaObject
, SvRttiBase
)
44 /*************************************************************************
45 |* SvMetaObject::SvMetaObject()
48 *************************************************************************/
49 SvMetaObject::SvMetaObject()
53 void SvMetaObject::Load( SvPersistStream
& )
57 void SvMetaObject::Save( SvPersistStream
& )
61 /*************************************************************************
62 |* SvMetaObject::WriteTab()
65 *************************************************************************/
67 void SvMetaObject::WriteTab( SvStream
& rOutStm
, sal_uInt16 nTab
)
74 /*************************************************************************
75 |* SvMetaObject::WriteStart()
78 *************************************************************************/
79 void SvMetaObject::WriteStars( SvStream
& rOutStm
)
82 for( int i
= 6; i
> 0; i
-- )
83 rOutStm
<< "**********";
84 rOutStm
<< '/' << endl
;
87 /*************************************************************************
88 |* SvMetaObject::TestAndSeekSpaceOnly()
91 *************************************************************************/
92 sal_Bool
SvMetaObject::TestAndSeekSpaceOnly( SvStream
& rOutStm
, sal_uLong nBegPos
)
94 // keine leeren Klammern schreiben
95 sal_uLong nPos
= rOutStm
.Tell();
96 rOutStm
.Seek( nBegPos
);
97 sal_Bool bOnlySpace
= sal_True
;
98 while( bOnlySpace
&& rOutStm
.Tell() < nPos
)
103 bOnlySpace
= sal_False
;
106 // nichts geschrieben
107 rOutStm
.Seek( nBegPos
);
109 rOutStm
.Seek( nPos
);
113 /*************************************************************************
114 |* SvMetaObject::Back2Delemitter()
117 *************************************************************************/
118 void SvMetaObject::Back2Delemitter( SvStream
& rOutStm
)
120 // keine leeren Klammern schreiben
121 sal_uLong nPos
= rOutStm
.Tell();
122 rOutStm
.SeekRel( -1 );
126 while( isspace( c
) && rOutStm
.Tell() != 1 )
128 rOutStm
.SeekRel( -2 );
132 if( c
== ';' || c
== ',' )
133 rOutStm
.SeekRel( -1 );
135 rOutStm
.Seek( nPos
);
138 /*************************************************************************
139 |* SvMetaObject::ReadSvIdl()
142 *************************************************************************/
143 sal_Bool
SvMetaObject::ReadSvIdl( SvIdlDataBase
&, SvTokenStream
& )
148 /*************************************************************************
149 |* SvMetaObject::WriteSvIdl()
152 *************************************************************************/
153 void SvMetaObject::WriteSvIdl( SvIdlDataBase
&, SvStream
&, sal_uInt16
/*nTab */ )
157 /*************************************************************************
158 |* SvMetaObject::Write()
161 *************************************************************************/
162 void SvMetaObject::Write( SvIdlDataBase
&, SvStream
&, sal_uInt16
/*nTab */,
163 WriteType
, WriteAttribute
)
167 /*************************************************************************
168 |* SvMetaObject::WriteCxx()
171 *************************************************************************/
172 void SvMetaObject::WriteCxx( SvIdlDataBase
&, SvStream
&, sal_uInt16
/*nTab */ )
176 /*************************************************************************
177 |* SvMetaObject::WriteHxx()
180 *************************************************************************/
181 void SvMetaObject::WriteHxx( SvIdlDataBase
&, SvStream
&, sal_uInt16
/*nTab */ )
187 /****************** SvMetaName *****************************************/
188 SV_IMPL_META_FACTORY1( SvMetaName
, SvMetaObject
);
189 /*************************************************************************
190 |* SvMetaName::SvMetaName()
193 *************************************************************************/
194 SvMetaName::SvMetaName()
198 void SvMetaName::Load( SvPersistStream
& rStm
)
200 SvMetaObject::Load( rStm
);
206 rStm
.SetError( SVSTREAM_FILEFORMAT_ERROR
);
207 DBG_ERROR( "wrong format" );
210 if( nMask
& 0x01 ) rStm
>> aName
;
211 if( nMask
& 0x02 ) rStm
>> aHelpContext
;
212 if( nMask
& 0x04 ) rStm
>> aHelpText
;
213 if( nMask
& 0x08 ) rStm
>> aConfigName
;
214 if( nMask
& 0x10 ) rStm
>> aDescription
;
217 void SvMetaName::Save( SvPersistStream
& rStm
)
219 SvMetaObject::Save( rStm
);
221 if( aName
.IsSet() ) nMask
|= 0x01;
222 if( aHelpContext
.IsSet() ) nMask
|= 0x02;
223 if( aHelpText
.IsSet() ) nMask
|= 0x04;
224 if( aConfigName
.IsSet() ) nMask
|= 0x08;
225 if( aDescription
.IsSet() ) nMask
|= 0x10;
228 if( nMask
& 0x01 ) rStm
<< aName
;
229 if( nMask
& 0x02 ) rStm
<< aHelpContext
;
230 if( nMask
& 0x04 ) rStm
<< aHelpText
;
231 if( nMask
& 0x08 ) rStm
<< aConfigName
;
232 if( nMask
& 0x10 ) rStm
<< aDescription
;
235 /*************************************************************************
239 *************************************************************************/
240 sal_Bool
SvMetaName::SetName( const ByteString
& rName
, SvIdlDataBase
* )
247 /*************************************************************************
248 |* SvMetaName::ReadNameSvIdl()
251 *************************************************************************/
252 sal_Bool
SvMetaName::ReadNameSvIdl( SvIdlDataBase
& rBase
,
253 SvTokenStream
& rInStm
)
255 sal_uInt32 nTokPos
= rInStm
.Tell();
256 SvToken
* pTok
= rInStm
.GetToken_Next();
259 if( pTok
->IsIdentifier() )
260 if( SetName( pTok
->GetString(), &rBase
) )
263 rInStm
.Seek( nTokPos
);
267 /*************************************************************************
268 |* SvMetaName::ReadSvIdl()
271 *************************************************************************/
272 void SvMetaName::ReadAttributesSvIdl( SvIdlDataBase
& rBase
,
273 SvTokenStream
& rInStm
)
275 sal_uInt32 nTokPos
= rInStm
.Tell();
276 if( aName
.ReadSvIdl( SvHash_Name(), rInStm
) )
278 if( !SetName( aName
, &rBase
) )
279 rInStm
.Seek( nTokPos
);
281 aHelpContext
.ReadSvIdl( rBase
, SvHash_HelpContext(), rInStm
);
282 aHelpText
.ReadSvIdl( rBase
, rInStm
);
283 aConfigName
.ReadSvIdl( SvHash_ConfigName(), rInStm
);
284 aDescription
.ReadSvIdl( SvHash_Description(), rInStm
);
286 aHelpContext.ReadSvIdl( GetModule()->GetInfo()->GetHelpContextContainer(),
291 /*************************************************************************
292 |* SvMetaName::DoReadContextSvIdl()
295 *************************************************************************/
296 void SvMetaName::DoReadContextSvIdl( SvIdlDataBase
& rBase
,
297 SvTokenStream
& rInStm
, char cDel
)
299 sal_uInt32 nBeginPos
= 0; // kann mit Tell nicht vorkommen
300 while( nBeginPos
!= rInStm
.Tell() )
302 nBeginPos
= rInStm
.Tell();
303 ReadContextSvIdl( rBase
, rInStm
);
305 rInStm
.ReadDelemiter();
311 /*************************************************************************
312 |* SvMetaName::ReadSvIdl()
315 *************************************************************************/
316 void SvMetaName::ReadContextSvIdl( SvIdlDataBase
&, SvTokenStream
& )
320 /*************************************************************************
321 |* SvMetaName::Test()
324 *************************************************************************/
325 sal_Bool
SvMetaName::Test( SvIdlDataBase
&, SvTokenStream
& )
330 /*************************************************************************
331 |* SvMetaName::WriteContextSvIdl()
334 *************************************************************************/
335 void SvMetaName::WriteContextSvIdl( SvIdlDataBase
&, SvStream
&, sal_uInt16
)
339 /*************************************************************************
340 |* SvMetaName::WriteDescription()
343 *************************************************************************/
344 void SvMetaName::WriteDescription( SvStream
& rOutStm
)
346 rOutStm
<< "<DESCRIPTION>" << endl
;
348 ByteString
aDesc( GetDescription() );
349 sal_uInt16 nPos
= aDesc
.Search( '\n' );
350 while ( nPos
!= STRING_NOTFOUND
)
352 rOutStm
<< aDesc
.Copy( 0, nPos
).GetBuffer() << endl
;
353 aDesc
.Erase(0,nPos
+1);
354 nPos
= aDesc
.Search( '\n' );
357 rOutStm
<< aDesc
.GetBuffer() << endl
<< "</DESCRIPTION>" << endl
;
360 /*************************************************************************
361 |* SvMetaName::WriteAttributesIdl()
364 *************************************************************************/
365 void SvMetaName::WriteAttributesSvIdl( SvIdlDataBase
& rBase
,
369 if( aHelpContext
.IsSet() || aHelpText
.IsSet() || aConfigName
.IsSet() )
371 WriteTab( rOutStm
, nTab
);
372 rOutStm
<< "// class SvMetaName" << endl
;
374 if( aHelpContext
.IsSet() )
376 WriteTab( rOutStm
, nTab
);
377 aHelpContext
.WriteSvIdl( SvHash_HelpContext(), rOutStm
, nTab
);
378 rOutStm
<< ';' << endl
;
380 if( aHelpText
.IsSet() )
382 WriteTab( rOutStm
, nTab
);
383 aHelpText
.WriteSvIdl( rBase
, rOutStm
, nTab
);
384 rOutStm
<< ';' << endl
;
386 if( aConfigName
.IsSet() )
388 WriteTab( rOutStm
, nTab
);
389 aConfigName
.WriteSvIdl( SvHash_ConfigName(), rOutStm
, nTab
);
390 rOutStm
<< ';' << endl
;
394 /*************************************************************************
395 |* SvMetaName::ReadSvIdl()
398 *************************************************************************/
399 sal_Bool
SvMetaName::ReadSvIdl( SvIdlDataBase
& rBase
, SvTokenStream
& rInStm
)
401 sal_uInt32 nTokPos
= rInStm
.Tell();
402 sal_Bool bOk
= sal_True
;
403 if( rInStm
.Read( '[' ) )
405 sal_uInt32 nBeginPos
= 0; // kann mit Tell nicht vorkommen
406 while( nBeginPos
!= rInStm
.Tell() )
408 nBeginPos
= rInStm
.Tell();
409 ReadAttributesSvIdl( rBase
, rInStm
);
410 rInStm
.ReadDelemiter();
412 bOk
= rInStm
.Read( ']' );
417 if( rInStm
.Read( '{' ) )
419 DoReadContextSvIdl( rBase
, rInStm
);
420 bOk
= rInStm
.Read( '}' );
425 rInStm
.Seek( nTokPos
);
429 /*************************************************************************
430 |* SvMetaName::WriteSvIdl()
433 *************************************************************************/
434 void SvMetaName::WriteSvIdl( SvIdlDataBase
& rBase
, SvStream
& rOutStm
,
437 sal_uLong nBeginPos
= rOutStm
.Tell();
438 WriteTab( rOutStm
, nTab
);
439 rOutStm
<< '[' << endl
;
440 sal_uLong nOldPos
= rOutStm
.Tell();
441 WriteAttributesSvIdl( rBase
, rOutStm
, nTab
+1 );
443 // keine leeren Klammern schreiben
444 if( TestAndSeekSpaceOnly( rOutStm
, nOldPos
) )
445 // nichts geschrieben
446 rOutStm
.Seek( nBeginPos
);
449 WriteTab( rOutStm
, nTab
);
451 nBeginPos
= rOutStm
.Tell();
455 WriteTab( rOutStm
, nTab
);
456 rOutStm
<< '{' << endl
;
457 nOldPos
= rOutStm
.Tell();
458 WriteContextSvIdl( rBase
, rOutStm
, nTab
+1 );
460 // keine leeren Klammern schreiben
461 if( TestAndSeekSpaceOnly( rOutStm
, nOldPos
) )
462 // nichts geschrieben
463 rOutStm
.Seek( nBeginPos
);
466 WriteTab( rOutStm
, nTab
);
471 /*************************************************************************
472 |* SvMetaName::Write()
475 *************************************************************************/
476 void SvMetaName::Write( SvIdlDataBase
& rBase
, SvStream
& rOutStm
,
478 WriteType nT
, WriteAttribute nA
)
480 sal_uLong nBeginPos
= rOutStm
.Tell();
481 WriteTab( rOutStm
, nTab
);
482 rOutStm
<< '[' << endl
;
483 sal_uLong nOldPos
= rOutStm
.Tell();
484 WriteAttributes( rBase
, rOutStm
, nTab
+1, nT
, nA
);
486 // keine leeren Klammern schreiben
487 sal_uLong nPos
= rOutStm
.Tell();
488 rOutStm
.Seek( nOldPos
);
489 sal_Bool bOnlySpace
= sal_True
;
490 while( bOnlySpace
&& rOutStm
.Tell() < nPos
)
495 bOnlySpace
= sal_False
;
498 // nichts geschrieben
499 rOutStm
.Seek( nBeginPos
);
502 rOutStm
.Seek( nPos
);
503 WriteTab( rOutStm
, nTab
);
504 rOutStm
<< ']' << endl
;
508 /*************************************************************************
509 |* SvMetaName::WriteAttributes()
512 *************************************************************************/
513 void SvMetaName::WriteAttributes( SvIdlDataBase
&, SvStream
& rOutStm
,
515 WriteType
, WriteAttribute
)
517 if( GetHelpText().IsSet() || GetHelpContext().IsSet() )
519 WriteTab( rOutStm
, nTab
);
520 rOutStm
<< "// class SvMetaName" << endl
;
522 if( GetHelpText().IsSet() )
524 WriteTab( rOutStm
, nTab
);
525 rOutStm
<< "helpstring(\"" << GetHelpText().GetBuffer() << "\")," << endl
;
527 if( GetHelpContext().IsSet() )
529 WriteTab( rOutStm
, nTab
);
530 rOutStm
<< "helpcontext("
531 << ByteString::CreateFromInt64(
532 GetHelpContext().GetValue() ).GetBuffer()
537 /*************************************************************************
538 |* SvMetaName::WriteContext()
541 *************************************************************************/
542 void SvMetaName::WriteContext( SvIdlDataBase
&, SvStream
&,
544 WriteType
, WriteAttribute
)
547 #endif // IDL_COMPILER
549 /****************** SvMetaReference *****************************************/
550 SV_IMPL_META_FACTORY1( SvMetaReference
, SvMetaName
);
552 /*************************************************************************
553 |* SvMetaReference::SvMetaReference()
556 *************************************************************************/
557 SvMetaReference::SvMetaReference()
561 void SvMetaReference::Load( SvPersistStream
& rStm
)
563 SvMetaName::Load( rStm
);
569 rStm
.SetError( SVSTREAM_FILEFORMAT_ERROR
);
570 DBG_ERROR( "wrong format" );
575 SvMetaReference
* pRef
;
581 void SvMetaReference::Save( SvPersistStream
& rStm
)
583 SvMetaName::Save( rStm
);
592 if( nMask
& 0x01 ) rStm
<< aRef
;
595 /**************************************************************************/
596 /****************** SvMetaExtern ******************************************/
597 SV_IMPL_META_FACTORY1( SvMetaExtern
, SvMetaReference
);
599 /*************************************************************************
600 |* SvMetaExtern::SvMetaExtern()
603 *************************************************************************/
604 SvMetaExtern::SvMetaExtern()
606 , bReadUUId( sal_False
)
607 , bReadVersion( sal_False
)
611 void SvMetaExtern::Load( SvPersistStream
& rStm
)
613 SvMetaReference::Load( rStm
);
619 rStm
.SetError( SVSTREAM_FILEFORMAT_ERROR
);
620 DBG_ERROR( "wrong format" );
623 if( nMask
& 0x01 ) rStm
>> pModule
;
624 if( nMask
& 0x02 ) rStm
>> aUUId
;
625 if( nMask
& 0x04 ) rStm
>> aVersion
;
626 if( nMask
& 0x08 ) bReadUUId
= sal_True
;
627 if( nMask
& 0x10 ) bReadVersion
= sal_True
;
630 void SvMetaExtern::Save( SvPersistStream
& rStm
)
632 SvMetaReference::Save( rStm
);
636 if( pModule
) nMask
|= 0x01;
637 if( aUUId
!= SvGlobalName() ) nMask
|= 0x02;
638 if( aVersion
!= SvVersion() ) nMask
|= 0x04;
639 if( bReadUUId
) nMask
|= 0x08;
640 if( bReadVersion
) nMask
|= 0x10;
644 if( nMask
& 0x01 ) rStm
<< pModule
;
645 if( nMask
& 0x02 ) rStm
<< aUUId
;
646 if( nMask
& 0x04 ) rStm
<< aVersion
;
649 /*************************************************************************
650 |* SvMetaExtern::GetModule()
653 *************************************************************************/
654 SvMetaModule
* SvMetaExtern::GetModule() const
656 DBG_ASSERT( pModule
!= NULL
, "module not set" );
660 /*************************************************************************
661 |* SvMetaExtern::GetUUId()
664 *************************************************************************/
665 const SvGlobalName
& SvMetaExtern::GetUUId() const
668 if( aUUId
== SvGlobalName() )
669 GetModule()->FillNextName( &((SvMetaExtern
*)this)->aUUId
);
675 /*************************************************************************
676 |* SvMetaExtern::SetModule()
679 *************************************************************************/
680 void SvMetaExtern::SetModule( SvIdlDataBase
& rBase
)
682 pModule
= (SvMetaModule
*)rBase
.GetStack().Get( TYPE( SvMetaModule
) );
685 /*************************************************************************
686 |* SvMetaExtern::ReadAttributesSvIdl()
689 *************************************************************************/
690 void SvMetaExtern::ReadAttributesSvIdl( SvIdlDataBase
& rBase
,
691 SvTokenStream
& rInStm
)
693 SvMetaReference::ReadAttributesSvIdl( rBase
, rInStm
);
694 if( aUUId
.ReadSvIdl( rBase
, rInStm
) )
695 bReadUUId
= sal_True
;
696 if( aVersion
.ReadSvIdl( rInStm
) )
697 bReadVersion
= sal_True
;
700 /*************************************************************************
701 |* SvMetaExtern::WriteAttributesSvIdl()
704 *************************************************************************/
705 void SvMetaExtern::WriteAttributesSvIdl( SvIdlDataBase
& rBase
,
706 SvStream
& rOutStm
, sal_uInt16 nTab
)
708 SvMetaReference::WriteAttributesSvIdl( rBase
, rOutStm
, nTab
);
709 if( bReadUUId
|| bReadVersion
)
711 WriteTab( rOutStm
, nTab
);
712 rOutStm
<< "// class SvMetaExtern" << endl
;
716 WriteTab( rOutStm
, nTab
);
717 aUUId
.WriteSvIdl( rOutStm
);
718 rOutStm
<< ';' << endl
;
722 WriteTab( rOutStm
, nTab
);
723 aVersion
.WriteSvIdl( rOutStm
);
724 rOutStm
<< ';' << endl
;
729 /*************************************************************************
730 |* SvMetaExtern::ReadSvIdl()
733 *************************************************************************/
734 sal_Bool
SvMetaExtern::ReadSvIdl( SvIdlDataBase
& rBase
, SvTokenStream
& rInStm
)
737 GetUUId(); // Id wird angelegt
738 return SvMetaReference::ReadSvIdl( rBase
, rInStm
);
741 /*************************************************************************
742 |* SvMetaExtern::WriteSvIdl()
745 *************************************************************************/
746 void SvMetaExtern::WriteSvIdl( SvIdlDataBase
& rBase
, SvStream
& rOutStm
,
749 SvMetaReference::WriteSvIdl( rBase
, rOutStm
, nTab
);
752 /*************************************************************************
753 |* SvMetaExtern::Write()
756 *************************************************************************/
757 void SvMetaExtern::Write( SvIdlDataBase
& rBase
, SvStream
& rOutStm
,
759 WriteType nT
, WriteAttribute nA
)
761 SvMetaReference::Write( rBase
, rOutStm
, nTab
, nT
, nA
);
764 /*************************************************************************
765 |* SvMetaExtern::WriteAttributes()
768 *************************************************************************/
769 void SvMetaExtern::WriteAttributes( SvIdlDataBase
& rBase
, SvStream
& rOutStm
,
771 WriteType nT
, WriteAttribute nA
)
773 SvMetaReference::WriteAttributes( rBase
, rOutStm
, nTab
, nT
, nA
);
775 WriteTab( rOutStm
, nTab
);
776 rOutStm
<< "// class SvMetaExtern" << endl
;
777 WriteTab( rOutStm
, nTab
);
778 rOutStm
<< "uuid(" << ByteString( GetUUId().GetHexName(), RTL_TEXTENCODING_UTF8
).GetBuffer() << ")," << endl
;
779 WriteTab( rOutStm
, nTab
);
780 rOutStm
<< "version(" << ByteString::CreateFromInt32( aVersion
.GetMajorVersion() ).GetBuffer() << '.'
781 << ByteString::CreateFromInt32( aVersion
.GetMinorVersion() ).GetBuffer() << ")," << endl
;
784 #endif // IDL_COMPILER