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: module.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"
39 #include <globals.hxx>
40 #include <database.hxx>
41 #include <tools/fsys.hxx>
42 #include <tools/debug.hxx>
44 /****************** SvMetaModule ******************************************/
45 SV_IMPL_META_FACTORY1( SvMetaModule
, SvMetaExtern
);
47 /*************************************************************************
49 |* SvMetaModule::SvMetaModule()
52 |* Ersterstellung MM 12.12.94
53 |* Letzte Aenderung MM 12.12.94
55 *************************************************************************/
56 SvMetaModule::SvMetaModule()
59 , bIsModified( FALSE
)
65 SvMetaModule::SvMetaModule( const String
& rIdlFileName
, BOOL bImp
)
66 : aIdlFileName( rIdlFileName
)
67 , bImported( bImp
), bIsModified( FALSE
)
72 /*************************************************************************
74 |* SvMetaModule::Load()
77 |* Ersterstellung MM 12.12.94
78 |* Letzte Aenderung MM 12.12.94
80 *************************************************************************/
81 #define MODULE_VER 0x0001
82 void SvMetaModule::Load( SvPersistStream
& rStm
)
84 bImported
= TRUE
; // immer importiert
85 SvMetaExtern::Load( rStm
);
89 rStm
>> nVer
; // Version
90 DBG_ASSERT( (nVer
& ~IDL_WRITE_MASK
) == MODULE_VER
, "false version" );
96 rStm
.ReadByteString( aIdlFileName
);
97 rStm
.ReadByteString( aHelpFileName
);
98 rStm
.ReadByteString( aSlotIdFile
);
99 rStm
.ReadByteString( aModulePrefix
);
101 // Compiler Daten lesen
105 DBG_ASSERT( (nVer
& IDL_WRITE_MASK
) == IDL_WRITE_COMPILER
,
106 "no idl compiler format" );
111 rStm
->SeekRel( nCmpLen
);
115 /*************************************************************************
117 |* SvMetaModule::Save()
120 |* Ersterstellung MM 12.12.94
121 |* Letzte Aenderung MM 12.12.94
123 *************************************************************************/
124 void SvMetaModule::Save( SvPersistStream
& rStm
)
126 SvMetaExtern::Save( rStm
);
128 rStm
<< (USHORT
)(MODULE_VER
| IDL_WRITE_COMPILER
); // Version
134 rStm
.WriteByteString( aIdlFileName
);
135 rStm
.WriteByteString( aHelpFileName
);
136 rStm
.WriteByteString( aSlotIdFile
);
137 rStm
.WriteByteString( aModulePrefix
);
139 // Compiler Daten schreiben
141 ULONG nLenPos
= rStm
.Tell();
147 // Laenge der Compiler Daten schreiben
148 ULONG nPos
= rStm
.Tell();
149 rStm
.Seek( nLenPos
);
150 rStm
<< (USHORT
)( nPos
- nLenPos
- sizeof( USHORT
) );
155 /*************************************************************************
157 |* SvMetaModule::SetName()
160 |* Ersterstellung MM 12.12.94
161 |* Letzte Aenderung MM 12.12.94
163 *************************************************************************/
164 BOOL
SvMetaModule::SetName( const ByteString
& rName
, SvIdlDataBase
* pBase
)
168 if( pBase
->GetModule( rName
) )
171 return SvMetaExtern::SetName( rName
);
175 /*************************************************************************
176 |* SvMetaModule::GetNextName()
179 *************************************************************************/
180 BOOL
SvMetaModule::FillNextName( SvGlobalName
* pName
)
184 if( aNextName
< aEndName
)
193 /*************************************************************************
194 |* SvMetaModule::ReadSvIdl()
197 *************************************************************************/
198 void SvMetaModule::ReadAttributesSvIdl( SvIdlDataBase
& rBase
,
199 SvTokenStream
& rInStm
)
201 SvMetaExtern::ReadAttributesSvIdl( rBase
, rInStm
);
203 aHelpFileName
.ReadSvIdl( SvHash_HelpFile(), rInStm
);
204 if( aSlotIdFile
.ReadSvIdl( SvHash_SlotIdFile(), rInStm
) )
206 UINT32 nTokPos
= rInStm
.Tell();
207 if( !rBase
.ReadIdFile( String::CreateFromAscii( aSlotIdFile
.GetBuffer() ) ) )
209 ByteString aStr
= "cannot read file: ";
211 rBase
.SetError( aStr
, rInStm
.GetToken() );
212 rBase
.WriteError( rInStm
);
214 rInStm
.Seek( nTokPos
);
217 aTypeLibFile
.ReadSvIdl( SvHash_TypeLibFile(), rInStm
);
218 aModulePrefix
.ReadSvIdl( SvHash_ModulePrefix(), rInStm
);
221 /*************************************************************************
222 |* SvMetaModule::WriteAttributesSvIdl()
225 *************************************************************************/
226 void SvMetaModule::WriteAttributesSvIdl( SvIdlDataBase
& rBase
,
230 SvMetaExtern::WriteAttributesSvIdl( rBase
, rOutStm
, nTab
);
231 if( aTypeLibFile
.Len() || aSlotIdFile
.Len() || aTypeLibFile
.Len() )
233 if( aHelpFileName
.Len() )
235 WriteTab( rOutStm
, nTab
);
236 aHelpFileName
.WriteSvIdl( SvHash_HelpFile(), rOutStm
, nTab
+1 );
237 rOutStm
<< ';' << endl
;
239 if( aSlotIdFile
.Len() )
241 WriteTab( rOutStm
, nTab
);
242 aSlotIdFile
.WriteSvIdl( SvHash_SlotIdFile(), rOutStm
, nTab
+1 );
243 rOutStm
<< ';' << endl
;
245 if( aTypeLibFile
.Len() )
247 WriteTab( rOutStm
, nTab
);
248 aTypeLibFile
.WriteSvIdl( SvHash_TypeLibFile(), rOutStm
, nTab
+1 );
249 rOutStm
<< ';' << endl
;
254 /*************************************************************************
255 |* SvMetaModule::ReadContextSvIdl()
258 *************************************************************************/
259 void SvMetaModule::ReadContextSvIdl( SvIdlDataBase
& rBase
,
260 SvTokenStream
& rInStm
)
262 UINT32 nTokPos
= rInStm
.Tell();
263 if( rInStm
.GetToken()->Is( SvHash_interface() )
264 || rInStm
.GetToken()->Is( SvHash_shell() ) )
266 SvMetaClassRef aClass
= new SvMetaClass();
267 if( aClass
->ReadSvIdl( rBase
, rInStm
) )
269 aClassList
.Append( aClass
);
270 // Global bekanntgeben
271 rBase
.GetClassList().Append( aClass
);
274 else if( rInStm
.GetToken()->Is( SvHash_enum() ) )
276 SvMetaTypeEnumRef aEnum
= new SvMetaTypeEnum();
278 if( aEnum
->ReadSvIdl( rBase
, rInStm
) )
280 // Im Modul deklariert
281 aTypeList
.Append( aEnum
);
282 // Global bekanntgeben
283 rBase
.GetTypeList().Append( aEnum
);
286 else if( rInStm
.GetToken()->Is( SvHash_item() )
287 || rInStm
.GetToken()->Is( SvHash_struct() )
288 || rInStm
.GetToken()->Is( SvHash_typedef() ) )
290 SvMetaTypeRef xItem
= new SvMetaType();
292 if( xItem
->ReadSvIdl( rBase
, rInStm
) )
294 // Im Modul deklariert
295 aTypeList
.Append( xItem
);
296 // Global bekanntgeben
297 rBase
.GetTypeList().Append( xItem
);
300 else if( rInStm
.GetToken()->Is( SvHash_include() ) )
303 rInStm
.GetToken_Next();
304 SvToken
* pTok
= rInStm
.GetToken_Next();
305 if( pTok
->IsString() )
307 DirEntry
aFullName( String::CreateFromAscii( pTok
->GetString().GetBuffer() ) );
308 rBase
.StartNewFile( aFullName
.GetFull() );
309 if( aFullName
.Find( rBase
.GetPath() ) )
311 SvTokenStream
aTokStm( aFullName
.GetFull() );
312 if( SVSTREAM_OK
== aTokStm
.GetStream().GetError() )
314 // Fehler aus alter Datei retten
315 SvIdlError aOldErr
= rBase
.GetError();
316 // Fehler zuruecksetzen
317 rBase
.SetError( SvIdlError() );
319 UINT32 nBeginPos
= 0xFFFFFFFF; // kann mit Tell nicht vorkommen
320 while( nBeginPos
!= aTokStm
.Tell() )
322 nBeginPos
= aTokStm
.Tell();
323 ReadContextSvIdl( rBase
, aTokStm
);
324 aTokStm
.ReadDelemiter();
326 bOk
= aTokStm
.GetToken()->IsEof();
329 rBase
.WriteError( aTokStm
);
331 // Fehler aus alter Datei wieder herstellen
332 rBase
.SetError( aOldErr
);
336 ByteString aStr
= "cannot open file: ";
337 aStr
+= ByteString( aFullName
.GetFull(), RTL_TEXTENCODING_UTF8
);
338 rBase
.SetError( aStr
, pTok
);
343 ByteString aStr
= "cannot find file: ";
344 aStr
+= ByteString( aFullName
.GetFull(), RTL_TEXTENCODING_UTF8
);
345 rBase
.SetError( aStr
, pTok
);
349 rInStm
.Seek( nTokPos
);
353 SvMetaSlotRef xSlot
= new SvMetaSlot();
355 if( xSlot
->ReadSvIdl( rBase
, rInStm
) )
357 if( xSlot
->Test( rBase
, rInStm
) )
359 // Im Modul deklariert
360 aAttrList
.Append( xSlot
);
361 // Global bekanntgeben
362 rBase
.AppendAttr( xSlot
);
368 /*************************************************************************
369 |* SvMetaModule::WriteContextSvIdl()
372 *************************************************************************/
373 void SvMetaModule::WriteContextSvIdl( SvIdlDataBase
& rBase
,
377 SvMetaExtern::WriteContextSvIdl( rBase
, rOutStm
, nTab
);
379 for( n
= 0; n
< aTypeList
.Count(); n
++ )
381 WriteTab( rOutStm
, nTab
);
382 aTypeList
.GetObject( n
)->WriteSvIdl( rBase
, rOutStm
, nTab
);
385 for( n
= 0; n
< aAttrList
.Count(); n
++ )
387 WriteTab( rOutStm
, nTab
);
388 aAttrList
.GetObject( n
)->WriteSvIdl( rBase
, rOutStm
, nTab
);
391 for( n
= 0; n
< aClassList
.Count(); n
++ )
393 WriteTab( rOutStm
, nTab
);
394 aClassList
.GetObject( n
)->WriteSvIdl( rBase
, rOutStm
, nTab
);
398 /*************************************************************************
400 |* SvMetaModule::ReadSvIdl()
404 *************************************************************************/
405 BOOL
SvMetaModule::ReadSvIdl( SvIdlDataBase
& rBase
, SvTokenStream
& rInStm
)
407 bIsModified
= TRUE
; // bisher immer wenn Compiler laueft
409 UINT32 nTokPos
= rInStm
.Tell();
410 SvToken
* pTok
= rInStm
.GetToken_Next();
412 bOk
= pTok
->Is( SvHash_module() );
415 pTok
= rInStm
.GetToken_Next();
416 if( pTok
->IsString() )
417 bOk
= aBeginName
.MakeId( String::CreateFromAscii( pTok
->GetString().GetBuffer() ) );
419 rInStm
.ReadDelemiter();
422 pTok
= rInStm
.GetToken_Next();
423 if( pTok
->IsString() )
424 bOk
= aEndName
.MakeId( String::CreateFromAscii( pTok
->GetString().GetBuffer() ) );
426 rInStm
.ReadDelemiter();
429 aNextName
= aBeginName
;
431 rBase
.Push( this ); // auf den Context Stack
433 if( ReadNameSvIdl( rBase
, rInStm
) )
435 // Zeiger auf sich selbst setzen
437 bOk
= SvMetaName::ReadSvIdl( rBase
, rInStm
);
439 rBase
.GetStack().Pop(); // und runter
442 rInStm
.Seek( nTokPos
);
446 /*************************************************************************
448 |* SvMetaModule::WriteSvIdl()
452 *************************************************************************/
453 void SvMetaModule::WriteSvIdl( SvIdlDataBase
& rBase
, SvStream
& rOutStm
,
456 rOutStm
<< SvHash_module()->GetName().GetBuffer() << endl
458 rOutStm
.WriteByteString( aBeginName
.GetHexName() );
459 rOutStm
<< '\"' << endl
<< '\"';
460 rOutStm
.WriteByteString( aEndName
.GetHexName() );
461 rOutStm
<< '\"' << endl
;
462 SvMetaExtern::WriteSvIdl( rBase
, rOutStm
, nTab
);
465 /*************************************************************************
466 |* SvMetaModule::WriteSfx()
467 *************************************************************************/
468 void SvMetaModule::WriteSfx( SvIdlDataBase
& rBase
, SvStream
& rOutStm
)
470 for( ULONG n
= 0; n
< aClassList
.Count(); n
++ )
472 SvMetaClass
* pClass
= aClassList
.GetObject( n
);
473 pClass
->WriteSfx( rBase
, rOutStm
);
477 void SvMetaModule::WriteHelpIds( SvIdlDataBase
& rBase
, SvStream
& rOutStm
,
480 for( ULONG n
= 0; n
< aClassList
.Count(); n
++ )
482 SvMetaClass
* pClass
= aClassList
.GetObject( n
);
483 pClass
->WriteHelpIds( rBase
, rOutStm
, pTable
);
487 /*************************************************************************
488 |* SvMetaModule::WriteAttributes()
489 *************************************************************************/
490 void SvMetaModule::WriteAttributes( SvIdlDataBase
& rBase
,
493 WriteType nT
, WriteAttribute nA
)
495 SvMetaExtern::WriteAttributes( rBase
, rOutStm
, nTab
, nT
, nA
);
496 if( aHelpFileName
.Len() )
498 WriteTab( rOutStm
, nTab
);
499 rOutStm
<< "// class SvMetaModule" << endl
;
500 WriteTab( rOutStm
, nTab
);
501 rOutStm
<< "helpfile(\"" << aHelpFileName
.GetBuffer() << "\");" << endl
;
505 /*************************************************************************
506 |* SvMetaModule::WriteSbx()
507 *************************************************************************/
509 void SvMetaModule::WriteSbx( SvIdlDataBase & rBase, SvStream & rOutStm,
510 SvNamePosList & rList )
512 for( ULONG n = 0; n < aClassList.Count(); n++ )
514 SvMetaClass * pClass = aClassList.GetObject( n );
515 if( !pClass->IsShell() && pClass->GetAutomation() )
517 rList.Insert( new SvNamePos( pClass->GetUUId(), rOutStm.Tell() ),
519 SbxObjectRef xSbxObj = new SbxObject( pClass->GetName() );
520 pClass->FillSbxObject( rBase, xSbxObj );
521 xSbxObj->Store( rOutStm );
527 /*************************************************************************
528 |* SvMetaModule::Write()
529 *************************************************************************/
530 void SvMetaModule::Write( SvIdlDataBase
& rBase
, SvStream
& rOutStm
,
532 WriteType nT
, WriteAttribute nA
)
538 if( aSlotIdFile
.Len() )
540 WriteTab( rOutStm
, nTab
);
541 rOutStm
<< "#include \"" << aSlotIdFile
.GetBuffer() << '"' << endl
<< endl
;
543 SvMetaExtern::Write( rBase
, rOutStm
, nTab
, nT
, nA
);
545 WriteTab( rOutStm
, nTab
);
546 rOutStm
<< "library " << GetName().GetBuffer() << endl
;
547 WriteTab( rOutStm
, nTab
);
548 rOutStm
<< '{' << endl
;
549 WriteTab( rOutStm
, nTab
);
550 rOutStm
<< "importlib(\"STDOLE.TLB\");" << endl
;
553 for( ULONG n = 0; n < aTypeList.Count(); n++ )
555 SvMetaType * pType = aTypeList.GetObject( n );
556 if( !pType ->Write( rBase, rOutStm, nTab +1, nT, nA ) )
561 for( ULONG n = 0; n < rBase.GetModuleList().Count(); n++ )
563 SvMetaModule * pModule = rBase.GetModuleList().GetObject( n );
564 const SvMetaTypeMemberList &rTypeList = pModule->GetTypeList();
565 for( ULONG n = 0; n < rTypeList.Count(); n++ )
567 SvMetaType * pType = rTypeList.GetObject( n );
568 pType->Write( rBase, rOutStm, nTab +1, nT, nA );
573 for( ULONG n
= 0; n
< aClassList
.Count(); n
++ )
575 SvMetaClass
* pClass
= aClassList
.GetObject( n
);
576 if( !pClass
->IsShell() && pClass
->GetAutomation() )
578 WriteTab( rOutStm
, nTab
);
579 WriteStars( rOutStm
);
580 pClass
->Write( rBase
, rOutStm
, nTab
+1, nT
, nA
);
581 if( n
+1 < aClassList
.Count() )
586 rOutStm
<< '}' << endl
;
591 rOutStm
<< "SvIDL interface documentation" << endl
<< endl
;
592 rOutStm
<< "<MODULE>" << endl
<< GetName().GetBuffer() << endl
;
593 WriteDescription( rOutStm
);
594 rOutStm
<< "</MODULE>" << endl
<< endl
;
596 rOutStm
<< "<CLASSES>" << endl
;
597 for( ULONG n
= 0; n
< aClassList
.Count(); n
++ )
599 SvMetaClass
* pClass
= aClassList
.GetObject( n
);
600 if( !pClass
->IsShell() )
602 rOutStm
<< pClass
->GetName().GetBuffer();
603 SvMetaClass
* pSC
= pClass
->GetSuperClass();
605 rOutStm
<< " : " << pSC
->GetName().GetBuffer();
607 // Importierte Klassen
608 const SvClassElementMemberList
& rClassList
= pClass
->GetClassList();
609 if ( rClassList
.Count() )
613 for( ULONG m
=0; m
<rClassList
.Count(); m
++ )
615 SvClassElement
*pEle
= rClassList
.GetObject(m
);
616 SvMetaClass
*pCl
= pEle
->GetClass();
617 rOutStm
<< pCl
->GetName().GetBuffer();
618 if ( m
+1 == rClassList
.Count() )
628 rOutStm
<< "</CLASSES>" << endl
<< endl
;
635 for( ULONG n
= 0; n
< aClassList
.Count(); n
++ )
637 SvMetaClass
* pClass
= aClassList
.GetObject( n
);
638 if( !pClass
->IsShell() /* && pClass->GetAutomation() */ )
639 pClass
->Write( rBase
, rOutStm
, nTab
, nT
, nA
);
649 /*************************************************************************
650 |* SvMetaModule::WriteSrc()
651 *************************************************************************/
652 void SvMetaModule::WriteSrc( SvIdlDataBase
& rBase
, SvStream
& rOutStm
,
655 // rOutStm << "#pragma CHARSET IBMPC" << endl;
656 if( aSlotIdFile
.Len() )
657 rOutStm
<< "//#include <" << aSlotIdFile
.GetBuffer() << '>' << endl
;
658 for( ULONG n
= 0; n
< aClassList
.Count(); n
++ )
660 aClassList
.GetObject( n
)->WriteSrc( rBase
, rOutStm
, pTable
);
664 /*************************************************************************
665 |* SvMetaModule::WriteHxx()
666 *************************************************************************/
667 void SvMetaModule::WriteHxx( SvIdlDataBase
& rBase
, SvStream
& rOutStm
,
670 for( ULONG n
= 0; n
< aClassList
.Count(); n
++ )
672 SvMetaClass
* pClass
= aClassList
.GetObject( n
);
673 pClass
->WriteHxx( rBase
, rOutStm
, nTab
);
677 /*************************************************************************
678 |* SvMetaModule::WriteCxx()
679 *************************************************************************/
680 void SvMetaModule::WriteCxx( SvIdlDataBase
& rBase
, SvStream
& rOutStm
,
683 for( ULONG n
= 0; n
< aClassList
.Count(); n
++ )
685 SvMetaClass
* pClass
= aClassList
.GetObject( n
);
686 pClass
->WriteCxx( rBase
, rOutStm
, nTab
);
690 #endif // IDL_COMPILER