merge the formfield patch from ooo-build
[ooovba.git] / idl / source / objects / module.cxx
blobeeb59e4279fbd2f196707eb43af0f258e26c0d60
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: module.cxx,v $
10 * $Revision: 1.6 $
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 <attrib.hxx>
38 #include <module.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()
51 |* Beschreibung
52 |* Ersterstellung MM 12.12.94
53 |* Letzte Aenderung MM 12.12.94
55 *************************************************************************/
56 SvMetaModule::SvMetaModule()
57 #ifdef IDL_COMPILER
58 : bImported( FALSE )
59 , bIsModified( FALSE )
60 #endif
64 #ifdef IDL_COMPILER
65 SvMetaModule::SvMetaModule( const String & rIdlFileName, BOOL bImp )
66 : aIdlFileName( rIdlFileName )
67 , bImported( bImp ), bIsModified( FALSE )
70 #endif
72 /*************************************************************************
74 |* SvMetaModule::Load()
76 |* Beschreibung
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 );
87 USHORT nVer;
89 rStm >> nVer; // Version
90 DBG_ASSERT( (nVer & ~IDL_WRITE_MASK) == MODULE_VER, "false version" );
92 rStm >> aClassList;
93 rStm >> aTypeList;
94 rStm >> aAttrList;
95 // Browser
96 rStm.ReadByteString( aIdlFileName );
97 rStm.ReadByteString( aHelpFileName );
98 rStm.ReadByteString( aSlotIdFile );
99 rStm.ReadByteString( aModulePrefix );
101 // Compiler Daten lesen
102 USHORT nCmpLen;
103 rStm >> nCmpLen;
104 #ifdef IDL_COMPILER
105 DBG_ASSERT( (nVer & IDL_WRITE_MASK) == IDL_WRITE_COMPILER,
106 "no idl compiler format" );
107 rStm >> aBeginName;
108 rStm >> aEndName;
109 rStm >> aNextName;
110 #else
111 rStm->SeekRel( nCmpLen );
112 #endif
115 /*************************************************************************
117 |* SvMetaModule::Save()
119 |* Beschreibung
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
130 rStm << aClassList;
131 rStm << aTypeList;
132 rStm << aAttrList;
133 // Browser
134 rStm.WriteByteString( aIdlFileName );
135 rStm.WriteByteString( aHelpFileName );
136 rStm.WriteByteString( aSlotIdFile );
137 rStm.WriteByteString( aModulePrefix );
139 // Compiler Daten schreiben
140 USHORT nCmpLen = 0;
141 ULONG nLenPos = rStm.Tell();
142 rStm << nCmpLen;
143 #ifdef IDL_COMPILER
144 rStm << aBeginName;
145 rStm << aEndName;
146 rStm << aNextName;
147 // Laenge der Compiler Daten schreiben
148 ULONG nPos = rStm.Tell();
149 rStm.Seek( nLenPos );
150 rStm << (USHORT)( nPos - nLenPos - sizeof( USHORT ) );
151 rStm.Seek( nPos );
152 #endif
155 /*************************************************************************
157 |* SvMetaModule::SetName()
159 |* Beschreibung
160 |* Ersterstellung MM 12.12.94
161 |* Letzte Aenderung MM 12.12.94
163 *************************************************************************/
164 BOOL SvMetaModule::SetName( const ByteString & rName, SvIdlDataBase * pBase )
166 if( pBase )
168 if( pBase->GetModule( rName ) )
169 return FALSE;
171 return SvMetaExtern::SetName( rName );
174 #ifdef IDL_COMPILER
175 /*************************************************************************
176 |* SvMetaModule::GetNextName()
178 |* Beschreibung
179 *************************************************************************/
180 BOOL SvMetaModule::FillNextName( SvGlobalName * pName )
182 *pName = aNextName;
184 if( aNextName < aEndName )
186 ++aNextName;
187 bIsModified = TRUE;
188 return TRUE;
190 return FALSE;
193 /*************************************************************************
194 |* SvMetaModule::ReadSvIdl()
196 |* Beschreibung
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: ";
210 aStr += aSlotIdFile;
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()
224 |* Beschreibung
225 *************************************************************************/
226 void SvMetaModule::WriteAttributesSvIdl( SvIdlDataBase & rBase,
227 SvStream & rOutStm,
228 USHORT nTab )
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()
257 |* Beschreibung
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() ) )
302 BOOL bOk = FALSE;
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();
327 if( !bOk )
329 rBase.WriteError( aTokStm );
331 // Fehler aus alter Datei wieder herstellen
332 rBase.SetError( aOldErr );
334 else
336 ByteString aStr = "cannot open file: ";
337 aStr += ByteString( aFullName.GetFull(), RTL_TEXTENCODING_UTF8 );
338 rBase.SetError( aStr, pTok );
341 else
343 ByteString aStr = "cannot find file: ";
344 aStr += ByteString( aFullName.GetFull(), RTL_TEXTENCODING_UTF8 );
345 rBase.SetError( aStr, pTok );
348 if( !bOk )
349 rInStm.Seek( nTokPos );
351 else
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()
371 |* Beschreibung
372 *************************************************************************/
373 void SvMetaModule::WriteContextSvIdl( SvIdlDataBase & rBase,
374 SvStream & rOutStm,
375 USHORT nTab )
377 SvMetaExtern::WriteContextSvIdl( rBase, rOutStm, nTab );
378 ULONG n;
379 for( n = 0; n < aTypeList.Count(); n++ )
381 WriteTab( rOutStm, nTab );
382 aTypeList.GetObject( n )->WriteSvIdl( rBase, rOutStm, nTab );
384 rOutStm << endl;
385 for( n = 0; n < aAttrList.Count(); n++ )
387 WriteTab( rOutStm, nTab );
388 aAttrList.GetObject( n )->WriteSvIdl( rBase, rOutStm, nTab );
390 rOutStm << endl;
391 for( n = 0; n < aClassList.Count(); n++ )
393 WriteTab( rOutStm, nTab );
394 aClassList.GetObject( n )->WriteSvIdl( rBase, rOutStm, nTab );
398 /*************************************************************************
400 |* SvMetaModule::ReadSvIdl()
402 |* Beschreibung
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();
411 BOOL bOk = FALSE;
412 bOk = pTok->Is( SvHash_module() );
413 if( bOk )
415 pTok = rInStm.GetToken_Next();
416 if( pTok->IsString() )
417 bOk = aBeginName.MakeId( String::CreateFromAscii( pTok->GetString().GetBuffer() ) );
419 rInStm.ReadDelemiter();
420 if( bOk )
422 pTok = rInStm.GetToken_Next();
423 if( pTok->IsString() )
424 bOk = aEndName.MakeId( String::CreateFromAscii( pTok->GetString().GetBuffer() ) );
426 rInStm.ReadDelemiter();
427 if( bOk )
429 aNextName = aBeginName;
431 rBase.Push( this ); // auf den Context Stack
433 if( ReadNameSvIdl( rBase, rInStm ) )
435 // Zeiger auf sich selbst setzen
436 SetModule( rBase );
437 bOk = SvMetaName::ReadSvIdl( rBase, rInStm );
439 rBase.GetStack().Pop(); // und runter
441 if( !bOk )
442 rInStm.Seek( nTokPos );
443 return bOk;
446 /*************************************************************************
448 |* SvMetaModule::WriteSvIdl()
450 |* Beschreibung
452 *************************************************************************/
453 void SvMetaModule::WriteSvIdl( SvIdlDataBase & rBase, SvStream & rOutStm,
454 USHORT nTab )
456 rOutStm << SvHash_module()->GetName().GetBuffer() << endl
457 << '\"';
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,
478 Table* pTable )
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,
491 SvStream & rOutStm,
492 USHORT nTab,
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() ),
518 LIST_APPEND );
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,
531 USHORT nTab,
532 WriteType nT, WriteAttribute nA )
534 switch ( nT )
536 case WRITE_ODL:
538 if( aSlotIdFile.Len() )
540 WriteTab( rOutStm, nTab );
541 rOutStm << "#include \"" << aSlotIdFile.GetBuffer() << '"' << endl << endl;
543 SvMetaExtern::Write( rBase, rOutStm, nTab, nT, nA );
544 rOutStm << endl;
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 ) )
557 return FALSE;
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() )
582 rOutStm << endl;
586 rOutStm << '}' << endl;
588 break;
589 case WRITE_DOCU:
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();
604 if( pSC )
605 rOutStm << " : " << pSC->GetName().GetBuffer();
607 // Importierte Klassen
608 const SvClassElementMemberList& rClassList = pClass->GetClassList();
609 if ( rClassList.Count() )
611 rOutStm << " ( ";
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() )
619 rOutStm << " )";
620 else
621 rOutStm << " , ";
625 rOutStm << endl;
628 rOutStm << "</CLASSES>" << endl << endl;
629 // kein Break!
632 case WRITE_C_SOURCE:
633 case WRITE_C_HEADER:
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 );
642 break;
644 default:
645 break;
649 /*************************************************************************
650 |* SvMetaModule::WriteSrc()
651 *************************************************************************/
652 void SvMetaModule::WriteSrc( SvIdlDataBase & rBase, SvStream & rOutStm,
653 Table * pTable )
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,
668 USHORT nTab )
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,
681 USHORT nTab )
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