1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
33 #include <tools/debug.hxx>
37 #include <globals.hxx>
38 #include <database.hxx>
40 SV_IMPL_META_FACTORY1( SvMetaObject
, SvRttiBase
)
41 SvMetaObject::SvMetaObject()
45 void SvMetaObject::Load( SvPersistStream
& )
49 void SvMetaObject::Save( SvPersistStream
& )
53 void SvMetaObject::WriteTab( SvStream
& rOutStm
, sal_uInt16 nTab
)
59 void SvMetaObject::WriteStars( SvStream
& rOutStm
)
62 for( int i
= 6; i
> 0; i
-- )
63 rOutStm
<< "**********";
64 rOutStm
<< '/' << endl
;
67 sal_Bool
SvMetaObject::TestAndSeekSpaceOnly( SvStream
& rOutStm
, sal_uLong nBegPos
)
69 // write no empty brackets
70 sal_uLong nPos
= rOutStm
.Tell();
71 rOutStm
.Seek( nBegPos
);
72 sal_Bool bOnlySpace
= sal_True
;
73 while( bOnlySpace
&& rOutStm
.Tell() < nPos
)
78 bOnlySpace
= sal_False
;
82 rOutStm
.Seek( nBegPos
);
88 void SvMetaObject::Back2Delemitter( SvStream
& rOutStm
)
90 // write no empty brackets
91 sal_uLong nPos
= rOutStm
.Tell();
92 rOutStm
.SeekRel( -1 );
96 while( isspace( c
) && rOutStm
.Tell() != 1 )
98 rOutStm
.SeekRel( -2 );
102 if( c
== ';' || c
== ',' )
103 rOutStm
.SeekRel( -1 );
105 rOutStm
.Seek( nPos
);
108 sal_Bool
SvMetaObject::ReadSvIdl( SvIdlDataBase
&, SvTokenStream
& )
113 void SvMetaObject::WriteSvIdl( SvIdlDataBase
&, SvStream
&, sal_uInt16
/*nTab */ )
117 void SvMetaObject::Write( SvIdlDataBase
&, SvStream
&, sal_uInt16
/*nTab */,
118 WriteType
, WriteAttribute
)
122 SV_IMPL_META_FACTORY1( SvMetaName
, SvMetaObject
);
123 SvMetaName::SvMetaName()
127 void SvMetaName::Load( SvPersistStream
& rStm
)
129 SvMetaObject::Load( rStm
);
135 rStm
.SetError( SVSTREAM_FILEFORMAT_ERROR
);
136 OSL_FAIL( "wrong format" );
139 if( nMask
& 0x01 ) rStm
>> aName
;
140 if( nMask
& 0x02 ) rStm
>> aHelpContext
;
141 if( nMask
& 0x04 ) rStm
>> aHelpText
;
142 if( nMask
& 0x08 ) rStm
>> aConfigName
;
143 if( nMask
& 0x10 ) rStm
>> aDescription
;
146 void SvMetaName::Save( SvPersistStream
& rStm
)
148 SvMetaObject::Save( rStm
);
150 if( aName
.IsSet() ) nMask
|= 0x01;
151 if( aHelpContext
.IsSet() ) nMask
|= 0x02;
152 if( aHelpText
.IsSet() ) nMask
|= 0x04;
153 if( aConfigName
.IsSet() ) nMask
|= 0x08;
154 if( aDescription
.IsSet() ) nMask
|= 0x10;
157 if( nMask
& 0x01 ) rStm
<< aName
;
158 if( nMask
& 0x02 ) rStm
<< aHelpContext
;
159 if( nMask
& 0x04 ) rStm
<< aHelpText
;
160 if( nMask
& 0x08 ) rStm
<< aConfigName
;
161 if( nMask
& 0x10 ) rStm
<< aDescription
;
164 sal_Bool
SvMetaName::SetName( const rtl::OString
& rName
, SvIdlDataBase
* )
166 aName
.setString(rName
);
170 sal_Bool
SvMetaName::ReadNameSvIdl( SvIdlDataBase
& rBase
,
171 SvTokenStream
& rInStm
)
173 sal_uInt32 nTokPos
= rInStm
.Tell();
174 SvToken
* pTok
= rInStm
.GetToken_Next();
177 if( pTok
->IsIdentifier() )
178 if( SetName( pTok
->GetString(), &rBase
) )
181 rInStm
.Seek( nTokPos
);
185 void SvMetaName::ReadAttributesSvIdl( SvIdlDataBase
& rBase
,
186 SvTokenStream
& rInStm
)
188 sal_uInt32 nTokPos
= rInStm
.Tell();
189 if( aName
.ReadSvIdl( SvHash_Name(), rInStm
) )
191 if( !SetName( aName
.getString(), &rBase
) )
192 rInStm
.Seek( nTokPos
);
194 aHelpContext
.ReadSvIdl( rBase
, SvHash_HelpContext(), rInStm
);
195 aHelpText
.ReadSvIdl( rBase
, rInStm
);
196 aConfigName
.ReadSvIdl( SvHash_ConfigName(), rInStm
);
197 aDescription
.ReadSvIdl( SvHash_Description(), rInStm
);
200 void SvMetaName::DoReadContextSvIdl( SvIdlDataBase
& rBase
,
201 SvTokenStream
& rInStm
, char cDel
)
203 sal_uInt32 nBeginPos
= 0; // can not happen with Tell
204 while( nBeginPos
!= rInStm
.Tell() )
206 nBeginPos
= rInStm
.Tell();
207 ReadContextSvIdl( rBase
, rInStm
);
209 rInStm
.ReadDelemiter();
215 void SvMetaName::ReadContextSvIdl( SvIdlDataBase
&, SvTokenStream
& )
219 sal_Bool
SvMetaName::Test( SvIdlDataBase
&, SvTokenStream
& )
224 void SvMetaName::WriteContextSvIdl( SvIdlDataBase
&, SvStream
&, sal_uInt16
)
228 void SvMetaName::WriteDescription( SvStream
& rOutStm
)
230 rOutStm
<< "<DESCRIPTION>" << endl
;
232 rtl::OString
aDesc( GetDescription().getString() );
233 sal_Int32 nPos
= aDesc
.indexOf('\n');
236 rOutStm
<< aDesc
.copy( 0, nPos
).getStr() << endl
;
237 aDesc
= aDesc
.copy(nPos
+1);
238 nPos
= aDesc
.indexOf('\n');
241 rOutStm
<< aDesc
.getStr() << endl
<< "</DESCRIPTION>" << endl
;
244 void SvMetaName::WriteAttributesSvIdl( SvIdlDataBase
& rBase
,
248 if( aHelpContext
.IsSet() || aHelpText
.IsSet() || aConfigName
.IsSet() )
250 WriteTab( rOutStm
, nTab
);
251 rOutStm
<< "// class SvMetaName" << endl
;
253 if( aHelpContext
.IsSet() )
255 WriteTab( rOutStm
, nTab
);
256 aHelpContext
.WriteSvIdl( SvHash_HelpContext(), rOutStm
, nTab
);
257 rOutStm
<< ';' << endl
;
259 if( aHelpText
.IsSet() )
261 WriteTab( rOutStm
, nTab
);
262 aHelpText
.WriteSvIdl( rBase
, rOutStm
, nTab
);
263 rOutStm
<< ';' << endl
;
265 if( aConfigName
.IsSet() )
267 WriteTab( rOutStm
, nTab
);
268 aConfigName
.WriteSvIdl( SvHash_ConfigName(), rOutStm
, nTab
);
269 rOutStm
<< ';' << endl
;
273 sal_Bool
SvMetaName::ReadSvIdl( SvIdlDataBase
& rBase
, SvTokenStream
& rInStm
)
275 sal_uInt32 nTokPos
= rInStm
.Tell();
276 sal_Bool bOk
= sal_True
;
277 if( rInStm
.Read( '[' ) )
279 sal_uInt32 nBeginPos
= 0; // can not happen with Tell
280 while( nBeginPos
!= rInStm
.Tell() )
282 nBeginPos
= rInStm
.Tell();
283 ReadAttributesSvIdl( rBase
, rInStm
);
284 rInStm
.ReadDelemiter();
286 bOk
= rInStm
.Read( ']' );
291 if( rInStm
.Read( '{' ) )
293 DoReadContextSvIdl( rBase
, rInStm
);
294 bOk
= rInStm
.Read( '}' );
299 rInStm
.Seek( nTokPos
);
303 void SvMetaName::WriteSvIdl( SvIdlDataBase
& rBase
, SvStream
& rOutStm
,
306 sal_uLong nBeginPos
= rOutStm
.Tell();
307 WriteTab( rOutStm
, nTab
);
308 rOutStm
<< '[' << endl
;
309 sal_uLong nOldPos
= rOutStm
.Tell();
310 WriteAttributesSvIdl( rBase
, rOutStm
, nTab
+1 );
312 // write no empty brackets
313 if( TestAndSeekSpaceOnly( rOutStm
, nOldPos
) )
315 rOutStm
.Seek( nBeginPos
);
318 WriteTab( rOutStm
, nTab
);
320 nBeginPos
= rOutStm
.Tell();
324 WriteTab( rOutStm
, nTab
);
325 rOutStm
<< '{' << endl
;
326 nOldPos
= rOutStm
.Tell();
327 WriteContextSvIdl( rBase
, rOutStm
, nTab
+1 );
329 // write no empty brackets
330 if( TestAndSeekSpaceOnly( rOutStm
, nOldPos
) )
332 rOutStm
.Seek( nBeginPos
);
335 WriteTab( rOutStm
, nTab
);
340 void SvMetaName::Write( SvIdlDataBase
& rBase
, SvStream
& rOutStm
,
342 WriteType nT
, WriteAttribute nA
)
344 sal_uLong nBeginPos
= rOutStm
.Tell();
345 WriteTab( rOutStm
, nTab
);
346 rOutStm
<< '[' << endl
;
347 sal_uLong nOldPos
= rOutStm
.Tell();
348 WriteAttributes( rBase
, rOutStm
, nTab
+1, nT
, nA
);
350 // write no empty brackets
351 sal_uLong nPos
= rOutStm
.Tell();
352 rOutStm
.Seek( nOldPos
);
353 sal_Bool bOnlySpace
= sal_True
;
354 while( bOnlySpace
&& rOutStm
.Tell() < nPos
)
359 bOnlySpace
= sal_False
;
363 rOutStm
.Seek( nBeginPos
);
366 rOutStm
.Seek( nPos
);
367 WriteTab( rOutStm
, nTab
);
368 rOutStm
<< ']' << endl
;
372 void SvMetaName::WriteAttributes( SvIdlDataBase
&, SvStream
& rOutStm
,
374 WriteType
, WriteAttribute
)
376 if( GetHelpText().IsSet() || GetHelpContext().IsSet() )
378 WriteTab( rOutStm
, nTab
);
379 rOutStm
<< "// class SvMetaName" << endl
;
381 if( GetHelpText().IsSet() )
383 WriteTab( rOutStm
, nTab
);
384 rOutStm
<< "helpstring(\"" << GetHelpText().getString().getStr() << "\")," << endl
;
386 if( GetHelpContext().IsSet() )
388 WriteTab( rOutStm
, nTab
);
389 rOutStm
<< "helpcontext("
390 << rtl::OString::valueOf(static_cast<sal_Int64
>(
391 GetHelpContext().GetValue())).getStr()
396 void SvMetaName::WriteContext( SvIdlDataBase
&, SvStream
&,
398 WriteType
, WriteAttribute
)
402 SV_IMPL_META_FACTORY1( SvMetaReference
, SvMetaName
);
404 SvMetaReference::SvMetaReference()
408 void SvMetaReference::Load( SvPersistStream
& rStm
)
410 SvMetaName::Load( rStm
);
416 rStm
.SetError( SVSTREAM_FILEFORMAT_ERROR
);
417 OSL_FAIL( "wrong format" );
422 SvMetaReference
* pRef
;
428 void SvMetaReference::Save( SvPersistStream
& rStm
)
430 SvMetaName::Save( rStm
);
439 if( nMask
& 0x01 ) rStm
<< aRef
;
442 SV_IMPL_META_FACTORY1( SvMetaExtern
, SvMetaReference
);
444 SvMetaExtern::SvMetaExtern()
446 , bReadUUId( sal_False
)
447 , bReadVersion( sal_False
)
451 void SvMetaExtern::Load( SvPersistStream
& rStm
)
453 SvMetaReference::Load( rStm
);
459 rStm
.SetError( SVSTREAM_FILEFORMAT_ERROR
);
460 OSL_FAIL( "wrong format" );
463 if( nMask
& 0x01 ) rStm
>> pModule
;
464 if( nMask
& 0x02 ) rStm
>> aUUId
;
465 if( nMask
& 0x04 ) rStm
>> aVersion
;
466 if( nMask
& 0x08 ) bReadUUId
= sal_True
;
467 if( nMask
& 0x10 ) bReadVersion
= sal_True
;
470 void SvMetaExtern::Save( SvPersistStream
& rStm
)
472 SvMetaReference::Save( rStm
);
476 if( pModule
) nMask
|= 0x01;
477 if( aUUId
!= SvGlobalName() ) nMask
|= 0x02;
478 if( aVersion
!= SvVersion() ) nMask
|= 0x04;
479 if( bReadUUId
) nMask
|= 0x08;
480 if( bReadVersion
) nMask
|= 0x10;
484 if( nMask
& 0x01 ) rStm
<< pModule
;
485 if( nMask
& 0x02 ) rStm
<< aUUId
;
486 if( nMask
& 0x04 ) rStm
<< aVersion
;
489 SvMetaModule
* SvMetaExtern::GetModule() const
491 DBG_ASSERT( pModule
!= NULL
, "module not set" );
495 const SvGlobalName
& SvMetaExtern::GetUUId() const
497 if( aUUId
== SvGlobalName() )
498 GetModule()->FillNextName( &((SvMetaExtern
*)this)->aUUId
);
502 void SvMetaExtern::SetModule( SvIdlDataBase
& rBase
)
504 pModule
= (SvMetaModule
*)rBase
.GetStack().Get( TYPE( SvMetaModule
) );
507 void SvMetaExtern::ReadAttributesSvIdl( SvIdlDataBase
& rBase
,
508 SvTokenStream
& rInStm
)
510 SvMetaReference::ReadAttributesSvIdl( rBase
, rInStm
);
511 if( aUUId
.ReadSvIdl( rBase
, rInStm
) )
512 bReadUUId
= sal_True
;
513 if( aVersion
.ReadSvIdl( rInStm
) )
514 bReadVersion
= sal_True
;
517 void SvMetaExtern::WriteAttributesSvIdl( SvIdlDataBase
& rBase
,
518 SvStream
& rOutStm
, sal_uInt16 nTab
)
520 SvMetaReference::WriteAttributesSvIdl( rBase
, rOutStm
, nTab
);
521 if( bReadUUId
|| bReadVersion
)
523 WriteTab( rOutStm
, nTab
);
524 rOutStm
<< "// class SvMetaExtern" << endl
;
528 WriteTab( rOutStm
, nTab
);
529 aUUId
.WriteSvIdl( rOutStm
);
530 rOutStm
<< ';' << endl
;
534 WriteTab( rOutStm
, nTab
);
535 aVersion
.WriteSvIdl( rOutStm
);
536 rOutStm
<< ';' << endl
;
541 sal_Bool
SvMetaExtern::ReadSvIdl( SvIdlDataBase
& rBase
, SvTokenStream
& rInStm
)
544 GetUUId(); // id gets created
545 return SvMetaReference::ReadSvIdl( rBase
, rInStm
);
548 void SvMetaExtern::WriteSvIdl( SvIdlDataBase
& rBase
, SvStream
& rOutStm
,
551 SvMetaReference::WriteSvIdl( rBase
, rOutStm
, nTab
);
554 void SvMetaExtern::Write( SvIdlDataBase
& rBase
, SvStream
& rOutStm
,
556 WriteType nT
, WriteAttribute nA
)
558 SvMetaReference::Write( rBase
, rOutStm
, nTab
, nT
, nA
);
561 void SvMetaExtern::WriteAttributes( SvIdlDataBase
& rBase
, SvStream
& rOutStm
,
563 WriteType nT
, WriteAttribute nA
)
565 SvMetaReference::WriteAttributes( rBase
, rOutStm
, nTab
, nT
, nA
);
567 WriteTab( rOutStm
, nTab
);
568 rOutStm
<< "// class SvMetaExtern" << endl
;
569 WriteTab( rOutStm
, nTab
);
570 rOutStm
<< "uuid(" << rtl::OUStringToOString(GetUUId().GetHexName(), RTL_TEXTENCODING_UTF8
).getStr() << ")," << endl
;
571 WriteTab( rOutStm
, nTab
);
572 rOutStm
<< "version("
573 << rtl::OString::valueOf(static_cast<sal_Int32
>(aVersion
.GetMajorVersion())).getStr()
575 << rtl::OString::valueOf(static_cast<sal_Int32
>(aVersion
.GetMinorVersion())).getStr()
579 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */