xref: /trunk/main/idl/source/objects/object.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3) !
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_idl.hxx"
30 
31 #include <ctype.h>
32 #include <stdio.h>
33 
34 #include <tools/debug.hxx>
35 
36 #include <attrib.hxx>
37 #include <object.hxx>
38 #include <globals.hxx>
39 #include <database.hxx>
40 
41 /******************** class SvClassElement *******************************/
42 SV_IMPL_PERSIST1( SvClassElement, SvPersistBase );
43 
44 /*************************************************************************
45 |*    SvClassElement::SvClassElement()
46 |*
47 |*    Beschreibung
48 *************************************************************************/
49 SvClassElement::SvClassElement()
50 {
51 };
52 
53 /*************************************************************************
54 |*    SvClassElement::Load()
55 |*
56 |*    Beschreibung
57 *************************************************************************/
58 void SvClassElement::Load( SvPersistStream & rStm )
59 {
60     sal_uInt8 nMask;
61     rStm >> nMask;
62     if( nMask >= 0x08 )
63     {
64         rStm.SetError( SVSTREAM_FILEFORMAT_ERROR );
65         DBG_ERROR( "wrong format" );
66         return;
67     }
68     if( nMask & 0x01 ) rStm >> aAutomation;
69     if( nMask & 0x02 ) rStm.ReadByteString( aPrefix );
70     if( nMask & 0x04 )
71     {
72         SvMetaClass * p;
73         rStm >> p;
74         xClass = p;
75     }
76 }
77 
78 /*************************************************************************
79 |*    SvClassElement::Save()
80 |*
81 |*    Beschreibung
82 *************************************************************************/
83 void SvClassElement::Save( SvPersistStream & rStm )
84 {
85     // Maske erstellen
86     sal_uInt8 nMask = 0;
87     if( aAutomation.IsSet() )       nMask |= 0x1;
88     if( aPrefix.Len() )             nMask |= 0x2;
89     if( xClass.Is() )               nMask |= 0x4;
90 
91     // Daten schreiben
92     rStm << nMask;
93     if( nMask & 0x01 ) rStm << aAutomation;
94     if( nMask & 0x02 ) rStm.WriteByteString( aPrefix );
95     if( nMask & 0x04 ) rStm << xClass;
96 }
97 
98 /****************** SvMetaClass ******************************************/
99 SV_IMPL_META_FACTORY1( SvMetaClass, SvMetaType );
100 /*************************************************************************
101 |*    SvMetaClass::SvMetaClass()
102 |*
103 |*    Beschreibung
104 *************************************************************************/
105 SvMetaClass::SvMetaClass()
106     : aAutomation( sal_True, sal_False )
107 {
108 }
109 
110 /*************************************************************************
111 |*    SvMetaClass::Load()
112 |*
113 |*    Beschreibung
114 *************************************************************************/
115 void SvMetaClass::Load( SvPersistStream & rStm )
116 {
117     SvMetaType::Load( rStm );
118 
119     sal_uInt8 nMask;
120     rStm >> nMask;
121     if( nMask >= 0x20 )
122     {
123         rStm.SetError( SVSTREAM_FILEFORMAT_ERROR );
124         DBG_ERROR( "wrong format" );
125         return;
126     }
127     if( nMask & 0x01 ) rStm >> aAttrList;
128     if( nMask & 0x02 )
129     {
130         SvMetaClass * pSuper;
131          rStm >> pSuper;
132         aSuperClass = pSuper;
133     }
134     if( nMask & 0x04 ) rStm >> aClassList;
135     if( nMask & 0x8 )
136     {
137         SvMetaClass * p;
138         rStm >> p;
139         xAutomationInterface = p;
140     }
141     if( nMask & 0x10 ) rStm >> aAutomation;
142 }
143 
144 /*************************************************************************
145 |*    SvMetaClass::Save()
146 |*
147 |*    Beschreibung
148 *************************************************************************/
149 void SvMetaClass::Save( SvPersistStream & rStm )
150 {
151     SvMetaType::Save( rStm );
152 
153     // Maske erstellen
154     sal_uInt8 nMask = 0;
155     if( aAttrList.Count() )         nMask |= 0x1;
156     if( aSuperClass.Is() )          nMask |= 0x2;
157     if( aClassList.Count() )        nMask |= 0x4;
158     if( xAutomationInterface.Is() ) nMask |= 0x8;
159     if( aAutomation.IsSet() )       nMask |= 0x10;
160 
161     // Daten schreiben
162     rStm << nMask;
163     if( nMask & 0x01 ) rStm << aAttrList;
164     if( nMask & 0x02 ) rStm << aSuperClass;
165     if( nMask & 0x04 ) rStm << aClassList;
166     if( nMask & 0x08 ) rStm << xAutomationInterface;
167     if( nMask & 0x10 ) rStm << aAutomation;
168 }
169 
170 /*************************************************************************
171 |*    SvMetaClass::FillSbxObject()
172 |*
173 |*    Beschreibung
174 *************************************************************************/
175 /*
176 void SvMetaClass::FillSbxMemberObject( SvIdlDataBase & rBase,
177                                         SbxObject * pObj,
178                                         StringList & rSuperList,
179                                         sal_Bool bVariable )
180 {
181     // alle Attribute der Klasse schreiben
182     sal_uLong n ;
183     for( n = 0; n < aAttrList.Count(); n++ )
184     {
185         SvMetaAttribute * pAttr = aAttrList.GetObject( n );
186 
187         ByteString aMangleName = pAttr->GetMangleName( bVariable );
188         ByteString * pS = SvIdlDataBase::FindName( aMangleName, rSuperList );
189 
190         if( !pS && pAttr->GetExport() )
191         {
192             // nicht doppelt
193             if( bVariable && pAttr->IsVariable() )
194             {
195                 rSuperList.Insert( new ByteString( aMangleName ), LIST_APPEND );
196                 pAttr->FillSbxObject( rBase, pObj, bVariable );
197             }
198             else if( !bVariable && pAttr->IsMethod() )
199             {
200                 rSuperList.Insert( new ByteString( aMangleName ), LIST_APPEND );
201                 pAttr->FillSbxObject( rBase, pObj, bVariable );
202             }
203         }
204     }
205     // alle Attribute der importierten Klassen schreiben
206     for( n = 0; n < aClassList.Count(); n++ )
207     {
208         SvClassElement * pEle = aClassList.GetObject( n );
209         SvMetaClass * pClass = pEle->GetClass();
210         pClass->FillSbxMemberObject( rBase, pObj, rSuperList, bVariable );
211     }
212     // alle Attribute der Superklassen schreiben
213     if( aSuperClass.Is() )
214         aSuperClass->FillSbxMemberObject( rBase, pObj, rSuperList, bVariable );
215 }
216 */
217 /*************************************************************************
218 |*    SvMetaClass::FillSbxObject()
219 |*
220 |*    Beschreibung
221 *************************************************************************/
222 /*
223 void SvMetaClass::FillSbxObject( SvIdlDataBase & rBase, SbxObject * pObj )
224 {
225     StringList aSuperList;
226     FillSbxMemberObject( rBase, pObj, aSuperList, sal_True );
227     FillSbxMemberObject( rBase, pObj, aSuperList, sal_False );
228 
229     ByteString * pStr = aSuperList.First();
230     while( pStr )
231     {
232         delete pStr;
233         pStr = aSuperList.Next();
234     }
235 }
236  */
237 #ifdef IDL_COMPILER
238 /*************************************************************************
239 |*    SvMetaClass::ReadAttributesSvIdl()
240 |*
241 |*    Beschreibung
242 *************************************************************************/
243 void SvMetaClass::ReadAttributesSvIdl( SvIdlDataBase & rBase,
244                                         SvTokenStream & rInStm )
245 {
246     SvMetaType::ReadAttributesSvIdl( rBase, rInStm );
247     aAutomation.ReadSvIdl( SvHash_Automation(), rInStm );
248 }
249 
250 /*************************************************************************
251 |*    SvMetaClass::WriteAttributesSvIdl()
252 |*
253 |*    Beschreibung
254 *************************************************************************/
255 void SvMetaClass::WriteAttributesSvIdl( SvIdlDataBase & rBase,
256                                  SvStream & rOutStm, sal_uInt16 nTab )
257 {
258     SvMetaType::WriteAttributesSvIdl( rBase, rOutStm, nTab );
259 
260     if( !aAutomation )
261     {
262         WriteTab( rOutStm, nTab );
263         rOutStm << "//class SvMetaClass" << endl;
264         if( !aAutomation )
265         {
266             WriteTab( rOutStm, nTab );
267             aAutomation.WriteSvIdl( SvHash_Automation(), rOutStm );
268             rOutStm << ';' << endl;
269         }
270     }
271 }
272 
273 /*************************************************************************
274 |*    SvMetaClass::ReadContextSvIdl()
275 |*
276 |*    Beschreibung
277 *************************************************************************/
278 void SvMetaClass::ReadContextSvIdl( SvIdlDataBase & rBase,
279                                     SvTokenStream & rInStm )
280 {
281     sal_uInt32  nTokPos = rInStm.Tell();
282     SvToken * pTok = rInStm.GetToken_Next();
283 
284     if( pTok->Is( SvHash_import() ) )
285     {
286         SvMetaClass * pClass = rBase.ReadKnownClass( rInStm );
287         if( pClass )
288         {
289             SvClassElementRef xEle = new SvClassElement();
290             xEle->SetClass( pClass );
291             aClassList.Append( xEle );
292 
293             if( rInStm.Read( '[' ) )
294             {
295                 pTok = rInStm.GetToken_Next();
296                 if( pTok->Is( SvHash_Automation() ) )
297                 {
298                     if( rInStm.Read( ']' ) )
299                     {
300                         if( xAutomationInterface.Is() )
301                         {
302                             // Fehler setzen
303                             rBase.SetError( "Automation allready set",
304                                             rInStm.GetToken() );
305                             rBase.WriteError( rInStm );
306                         }
307                         xAutomationInterface = pClass;
308                         xEle->SetAutomation( sal_True );
309                     }
310                     else
311                     {
312                         // Fehler setzen
313                         rBase.SetError( "missing ]", rInStm.GetToken() );
314                         rBase.WriteError( rInStm );
315                     }
316                 }
317                 else
318                 {
319                     // Fehler setzen
320                     rBase.SetError( "only attribute Automation allowed",
321                                     rInStm.GetToken() );
322                     rBase.WriteError( rInStm );
323                 }
324             }
325             pTok = rInStm.GetToken();
326             if( pTok->IsString() )
327             {
328                 xEle->SetPrefix( pTok->GetString() );
329                 rInStm.GetToken_Next();
330             }
331             return;
332         }
333         else
334         {
335             // Fehler setzen
336             rBase.SetError( "unknown imported interface", rInStm.GetToken() );
337             rBase.WriteError( rInStm );
338         }
339     }
340     else
341     {
342         rInStm.Seek( nTokPos );
343         SvMetaType * pType = rBase.ReadKnownType( rInStm );
344 
345         sal_Bool bOk = sal_False;
346         SvMetaAttributeRef xAttr;
347         if( !pType || pType->IsItem() )
348         {
349             xAttr = new SvMetaSlot( pType );
350             if( xAttr->ReadSvIdl( rBase, rInStm ) )
351                 bOk = xAttr->Test( rBase, rInStm );
352         }
353         else
354         {
355             xAttr = new SvMetaAttribute( pType );
356             if( xAttr->ReadSvIdl( rBase, rInStm ) )
357                 bOk = xAttr->Test( rBase, rInStm );
358         }
359 
360         if( bOk )
361             bOk = TestAttribute( rBase, rInStm, *xAttr );
362         if( bOk )
363         {
364             if( !xAttr->GetSlotId().IsSet() )
365             {
366                 SvNumberIdentifier aI;
367                 aI.SetValue( rBase.GetUniqueId() );
368                 xAttr->SetSlotId( aI );
369             }
370             aAttrList.Append( xAttr );
371             return;
372         }
373     }
374     rInStm.Seek( nTokPos );
375 }
376 
377 /*************************************************************************
378 |*    SvMetaClass::WriteContextSvIdl()
379 |*
380 |*    Beschreibung
381 *************************************************************************/
382 void SvMetaClass::WriteContextSvIdl
383 (
384     SvIdlDataBase & rBase,
385     SvStream & rOutStm,
386     sal_uInt16 nTab
387 )
388 {
389     //SvMetaType::WriteContextSvIdl( rBase, rOutStm, nTab );
390     sal_uLong n;
391     for( n = 0; n < aAttrList.Count(); n++ )
392     {
393         WriteTab( rOutStm, nTab );
394         aAttrList.GetObject( n )->WriteSvIdl( rBase, rOutStm, nTab );
395         rOutStm << ';' << endl;
396     }
397     for( n = 0; n < aClassList.Count(); n++ )
398     {
399         SvClassElement * pEle = aClassList.GetObject( n );
400         WriteTab( rOutStm, nTab );
401         rOutStm << SvHash_import()->GetName().GetBuffer() << ' '
402                 << pEle->GetPrefix().GetBuffer();
403         if( pEle->GetAutomation() )
404             rOutStm << " [ " << SvHash_Automation()->GetName().GetBuffer()
405                     << " ]";
406         if( pEle->GetPrefix().Len() )
407             rOutStm << ' ' << pEle->GetPrefix().GetBuffer();
408         rOutStm << ';' << endl;
409     }
410 }
411 
412 /*************************************************************************
413 |*    SvMetaClass::ReadSvIdl()
414 |*
415 |*    Beschreibung
416 *************************************************************************/
417 sal_Bool SvMetaClass::ReadSvIdl( SvIdlDataBase & rBase, SvTokenStream & rInStm )
418 {
419     sal_uLong nTokPos = rInStm.Tell();
420     if( SvMetaType::ReadHeaderSvIdl( rBase, rInStm ) && GetType() == TYPE_CLASS )
421     {
422         sal_Bool bOk = sal_True;
423         if( rInStm.Read( ':' ) )
424         {
425             aSuperClass = rBase.ReadKnownClass( rInStm );
426             bOk = aSuperClass.Is();
427             if( !bOk )
428             {
429                 // Fehler setzen
430                 rBase.SetError( "unknown super class",
431                                 rInStm.GetToken() );
432                 rBase.WriteError( rInStm );
433             }
434         }
435         if( bOk )
436         {
437             rBase.Write( '.' );
438             bOk = SvMetaName::ReadSvIdl( rBase, rInStm );
439         }
440         if( bOk )
441             return bOk;
442     }
443     rInStm.Seek( nTokPos );
444     return sal_False;
445 }
446 
447 /*************************************************************************
448 |*    SvMetaClass::TestAttribute()
449 |*
450 |*    Beschreibung
451 *************************************************************************/
452 sal_Bool SvMetaClass::TestAttribute( SvIdlDataBase & rBase, SvTokenStream & rInStm,
453                                  SvMetaAttribute & rAttr ) const
454 {
455     if ( !rAttr.GetRef() && rAttr.IsA( TYPE( SvMetaSlot ) ) )
456     {
457         DBG_ERROR( "Neuer Slot : " );
458         DBG_ERROR( rAttr.GetSlotId().GetBuffer() );
459     }
460 
461     for( sal_uLong n = 0; n < aAttrList.Count(); n++ )
462     {
463         SvMetaAttribute * pS = aAttrList.GetObject( n );
464         if( pS->GetName() == rAttr.GetName() )
465         {
466             // Werte muessen uebereinstimmen
467             if( pS->GetSlotId().GetValue() != rAttr.GetSlotId().GetValue() )
468             {
469                 DBG_ERROR( "Gleicher Name in MetaClass : " );
470                 DBG_ERROR( pS->GetName().GetBuffer() );
471                 DBG_ERROR( pS->GetSlotId().GetBuffer() );
472                 DBG_ERROR( rAttr.GetSlotId().GetBuffer() );
473 
474                 ByteString aStr( "Attribute's " );
475                 aStr += pS->GetName();
476                 aStr += " with different id's";
477                 rBase.SetError( aStr, rInStm.GetToken() );
478                 rBase.WriteError( rInStm );
479                 return sal_False;
480             }
481         }
482         else
483         {
484             sal_uInt32 nId1 = pS->GetSlotId().GetValue();
485             sal_uInt32 nId2 = rAttr.GetSlotId().GetValue();
486             if( nId1 == nId2 && nId1 != 0 /*&& nId2 != 0 ist ueberfluessig*/ )
487             {
488                 DBG_ERROR( "Gleiche Id in MetaClass : " );
489                 DBG_ERROR( ByteString::CreateFromInt32( pS->GetSlotId().GetValue() ).GetBuffer() );
490                 DBG_ERROR( pS->GetSlotId().GetBuffer() );
491                 DBG_ERROR( rAttr.GetSlotId().GetBuffer() );
492 
493                 ByteString aStr( "Attribute " );
494                 aStr += pS->GetName();
495                 aStr += " and Attribute ";
496                 aStr += rAttr.GetName();
497                 aStr += " with equal id's";
498                 rBase.SetError( aStr, rInStm.GetToken() );
499                 rBase.WriteError( rInStm );
500                 return sal_False;
501             }
502         }
503     }
504     SvMetaClass * pSC = aSuperClass;
505     if( pSC )
506         return pSC->TestAttribute( rBase, rInStm, rAttr );
507     return sal_True;
508 }
509 
510 /*************************************************************************
511 |*    SvMetaClass::WriteSvIdl()
512 |*
513 |*    Beschreibung
514 *************************************************************************/
515 void SvMetaClass::WriteSvIdl( SvIdlDataBase & rBase, SvStream & rOutStm,
516                               sal_uInt16 nTab )
517 {
518     WriteHeaderSvIdl( rBase, rOutStm, nTab );
519     if( aSuperClass.Is() )
520         rOutStm << " : " << aSuperClass->GetName().GetBuffer();
521     rOutStm << endl;
522     SvMetaName::WriteSvIdl( rBase, rOutStm, nTab );
523     rOutStm << endl;
524 }
525 
526 /*************************************************************************
527 |*    SvMetaClass::WriteOdlMember()
528 |*
529 |*    Beschreibung
530 *************************************************************************/
531 /*
532 void SvMetaClass::WriteOdlMembers( ByteStringList & rSuperList,
533                                     sal_Bool bVariable, sal_Bool bWriteTab,
534                                     SvIdlDataBase & rBase,
535                                     SvStream & rOutStm, sal_uInt16 nTab )
536 {
537     // alle Attribute schreiben
538     sal_uLong n;
539     for( n = 0; n < aAttrList.Count(); n++ )
540     {
541         SvMetaAttribute * pAttr = aAttrList.GetObject( n );
542 
543         ByteString aMangleName = pAttr->GetMangleName( bVariable );
544         ByteString * pS = rBase.FindName( aMangleName, rSuperList );
545 
546         if( !pS && pAttr->GetExport() )
547         {
548             // nicht doppelt
549             if( bVariable && pAttr->IsVariable() )
550             {
551                 rSuperList.Insert( new ByteString( aMangleName ), LIST_APPEND );
552                 pAttr->Write( rBase, rOutStm, nTab +1, WRITE_ODL,
553                                 WA_VARIABLE );
554                 rOutStm << ';' << endl;
555             }
556             else if( !bVariable && pAttr->IsMethod() )
557             {
558                 rSuperList.Insert( new ByteString( aMangleName ), LIST_APPEND );
559                 pAttr->Write( rBase, rOutStm, nTab +1, WRITE_ODL,
560                                 WA_METHOD );
561                 rOutStm << ';' << endl;
562             }
563         }
564         else
565             continue;
566     }
567     // alle Attribute der importierten Klassen schreiben
568     for( n = 0; n < aClassList.Count(); n++ )
569     {
570         SvClassElement * pEle = aClassList.GetObject( n );
571         SvMetaClass * pCl = pEle->GetClass();
572         pCl->WriteOdlMembers( rSuperList, bVariable, bWriteTab,
573                                 rBase, rOutStm, nTab );
574     }
575     // alle Attribute der Superklassen schreiben
576     SvMetaClass * pSC = aSuperClass;
577     if( pSC )
578         pSC->WriteOdlMembers( rSuperList, bVariable, bWriteTab,
579                             rBase, rOutStm, nTab );
580 }
581  */
582 
583 /*************************************************************************
584 |*    SvMetaClass::Write()
585 |*
586 |*    Beschreibung
587 *************************************************************************/
588 void SvMetaClass::Write( SvIdlDataBase & rBase, SvStream & rOutStm,
589                         sal_uInt16 nTab,
590                         WriteType nT, WriteAttribute )
591 {
592     rBase.aIFaceName = GetName();
593     switch( nT )
594     {
595         case WRITE_ODL:
596         {
597             DBG_ERROR( "Not supported anymore!" );
598 /*
599             // Schreibt die Attribute
600             SvMetaName::Write( rBase, rOutStm, nTab, nT, nA );
601 
602             WriteTab( rOutStm, nTab );
603             rOutStm << "dispinterface " << GetName().GetBuffer() << endl;
604             WriteTab( rOutStm, nTab );
605             rOutStm << '{' << endl;
606 
607             WriteTab( rOutStm, nTab );
608             rOutStm << "properties:";
609             rOutStm << endl;
610 
611             StringList aSuperList;
612             WriteOdlMembers( aSuperList, sal_True, sal_True, rBase, rOutStm, nTab );
613 
614             WriteTab( rOutStm, nTab );
615             rOutStm << "methods:";
616             rOutStm << endl;
617 
618             WriteOdlMembers( aSuperList, sal_False, sal_True, rBase, rOutStm, nTab );
619 
620             ByteString * pStr = aSuperList.First();
621             while( pStr )
622             {
623                 delete pStr;
624                 pStr = aSuperList.Next();
625             }
626 
627             WriteTab( rOutStm, 1 );
628             rOutStm << '}' << endl;
629  */
630             break;
631         }
632         case WRITE_C_SOURCE:
633         case WRITE_C_HEADER:
634         {
635             DBG_ERROR( "Not supported anymore!" );
636 /*
637             StringList aSuperList;
638             if( nT == WRITE_C_SOURCE )
639             {
640                 rOutStm << "#pragma code_seg (\"" << GetName().GetBuffer()
641                     << "\",\"CODE\")" << endl;
642             }
643             WriteCFunctions( aSuperList, rBase, rOutStm, nTab, nT );
644  */
645             break;
646         }
647         case WRITE_DOCU:
648         {
649             rOutStm << "<INTERFACE>" << endl
650                     << GetName().GetBuffer();
651             if ( GetAutomation() )
652                 rOutStm << " ( Automation ) ";
653             rOutStm << endl;
654             WriteDescription( rOutStm );
655             rOutStm << "</INTERFACE>" << endl << endl;
656 
657             // alle Attribute schreiben
658             sal_uLong n;
659             for( n = 0; n < aAttrList.Count(); n++ )
660             {
661                 SvMetaAttribute * pAttr = aAttrList.GetObject( n );
662                 if( !pAttr->GetHidden() )
663                 {
664                     if( pAttr->IsMethod() )
665                         pAttr->Write( rBase, rOutStm, nTab, nT, WA_METHOD );
666 
667                     if( pAttr->IsVariable() )
668                         pAttr->Write( rBase, rOutStm, nTab, nT, WA_VARIABLE );
669                 }
670             }
671 
672             break;
673         }
674         default:
675             break;
676     }
677 }
678 
679 /*************************************************************************
680 |*    SvMetaClass::WriteSlotParamArray()
681 |*
682 |*    Beschreibung
683 *************************************************************************/
684 sal_uInt16 SvMetaClass::WriteSlotParamArray( SvIdlDataBase & rBase,
685                                         SvSlotElementList & rSlotList,
686                                         SvStream & rOutStm )
687 {
688     sal_uInt16 nCount = 0;
689     for( sal_uLong n = 0; n < rSlotList.Count(); n++ )
690     {
691         SvSlotElement *pEle = rSlotList.GetObject( n );
692         SvMetaSlot *pAttr = pEle->xSlot;
693         nCount = nCount + pAttr->WriteSlotParamArray( rBase, rOutStm );
694     }
695 
696     return nCount;
697 }
698 
699 /*************************************************************************
700 |*    SvMetaClass::WriteSlots()
701 |*
702 |*    Beschreibung
703 *************************************************************************/
704 sal_uInt16 SvMetaClass::WriteSlots( const ByteString & rShellName,
705                                 sal_uInt16 nCount, SvSlotElementList & rSlotList,
706                                 SvIdlDataBase & rBase,
707                                 SvStream & rOutStm )
708 {
709     sal_uInt16 nSCount = 0;
710     for( sal_uLong n = 0; n < rSlotList.Count(); n++ )
711     {
712         rSlotList.Seek(n);
713         SvSlotElement * pEle = rSlotList.GetCurObject();
714         SvMetaSlot * pAttr = pEle->xSlot;
715         nSCount = nSCount + pAttr->WriteSlotMap( rShellName, nCount + nSCount,
716                                         rSlotList, pEle->aPrefix, rBase,
717                                         rOutStm );
718     }
719 
720     return nSCount;
721 }
722 
723 /*************************************************************************
724 |*    SvMetaClass::InsertSlots()
725 |*
726 |*    Beschreibung
727 *************************************************************************/
728 void SvMetaClass::InsertSlots( SvSlotElementList& rList, SvULongs& rSuperList,
729                             SvMetaClassList &rClassList,
730                             const ByteString & rPrefix, SvIdlDataBase& rBase)
731 {
732     // Wurde diese Klasse schon geschrieben ?
733     if ( rClassList.GetPos(this) != LIST_ENTRY_NOTFOUND )
734         return;
735 
736     rClassList.Insert(this, LIST_APPEND);
737 
738     // alle direkten Attribute schreiben
739     sal_uLong n;
740     for( n = 0; n < aAttrList.Count(); n++ )
741     {
742         SvMetaAttribute * pAttr = aAttrList.GetObject( n );
743 
744         sal_uLong nId = pAttr->GetSlotId().GetValue();
745         sal_uInt16 nPos;
746         for ( nPos=0; nPos < rSuperList.Count(); nPos++ )
747         {
748             if ( rSuperList.GetObject(nPos) == nId )
749                 break;
750         }
751 
752         if( nPos == rSuperList.Count() )
753         {
754             // nur schreiben, wenn nicht schon bei SubClass oder
755             // importiertem Interface geschrieben
756             rSuperList.Insert( nId, nPos );
757             pAttr->Insert(rList, rPrefix, rBase);
758         }
759     }
760 
761     // Alle schon von SuperShells importierten Interfaces sollen nicht
762     // mehr geschrieben werden
763     // Es ist also verboten, da\s Shell und SuperShell die gleiche Klasse
764     // direkt importieren !
765     if( IsShell() && aSuperClass.Is() )
766         aSuperClass->FillClasses( rClassList );
767 
768     // alle Attribute der importierten Klassen schreiben, sofern diese nicht
769     // schon von der Superklasse importiert wurden
770     for( n = 0; n < aClassList.Count(); n++ )
771     {
772         SvClassElement * pEle = aClassList.GetObject( n );
773         SvMetaClass * pCl = pEle->GetClass();
774         ByteString rPre = rPrefix;
775         if( rPre.Len() && pEle->GetPrefix().Len() )
776             rPre += '.';
777         rPre += pEle->GetPrefix();
778 
779         // Zun"achst die direkt importierten Interfaces schreiben
780         pCl->InsertSlots( rList, rSuperList, rClassList, rPre, rBase );
781     }
782 
783     // Superklassen nur schreiben, wenn keine Shell und nicht in der Liste
784     if( !IsShell() && aSuperClass.Is() )
785     {
786         aSuperClass->InsertSlots( rList, rSuperList, rClassList, rPrefix, rBase );
787     }
788 }
789 
790 /*************************************************************************
791 |*    SvMetaClass::FillClasses()
792 |*
793 |*    Beschreibung
794 *************************************************************************/
795 void SvMetaClass::FillClasses( SvMetaClassList & rList )
796 {
797     // Bin ich noch nicht drin ?
798     if ( rList.GetPos(this) == LIST_ENTRY_NOTFOUND )
799     {
800         rList.Insert(this, LIST_APPEND);
801 
802         // Meine Imports
803         for( sal_uLong n = 0; n < aClassList.Count(); n++ )
804         {
805             SvClassElement * pEle = aClassList.GetObject( n );
806             SvMetaClass * pCl = pEle->GetClass();
807             pCl->FillClasses( rList );
808         }
809 
810         // Meine Superklasse
811         if( aSuperClass.Is() )
812             aSuperClass->FillClasses( rList );
813     }
814 }
815 
816 
817 /*************************************************************************
818 |*    SvMetaClass::WriteSlotStubs()
819 |*
820 |*    Beschreibung
821 *************************************************************************/
822 void SvMetaClass::WriteSlotStubs( const ByteString & rShellName,
823                                 SvSlotElementList & rSlotList,
824                                 ByteStringList & rList,
825                                 SvStream & rOutStm )
826 {
827     // alle Attribute schreiben
828     for( sal_uLong n = 0; n < rSlotList.Count(); n++ )
829     {
830         SvSlotElement *pEle = rSlotList.GetObject( n );
831         SvMetaSlot *pAttr = pEle->xSlot;
832         pAttr->WriteSlotStubs( rShellName, rList, rOutStm );
833     }
834 }
835 
836 /*************************************************************************
837 |*    SvMetaClass::WriteSfx()
838 |*
839 |*    Beschreibung
840 *************************************************************************/
841 void SvMetaClass::WriteSfx( SvIdlDataBase & rBase, SvStream & rOutStm )
842 {
843     WriteStars( rOutStm );
844     // Klasse definieren
845     rOutStm << "#ifdef " << GetName().GetBuffer() << endl;
846     rOutStm << "#undef ShellClass" << endl;
847     rOutStm << "#undef " << GetName().GetBuffer() << endl;
848     rOutStm << "#define ShellClass " << GetName().GetBuffer() << endl;
849 
850 //    rOutStm << "SFX_TYPELIB(" << GetName().GetBuffer() << ',' << endl
851 //        << "\t/* library type */"
852 //        << '"' << ByteString( GetModule()->GetUUId().GetHexName(), RTL_TEXTENCODING_UTF8 ).GetBuffer() << "\"," << endl
853 //        << "\t\"" << GetModule()->GetTypeLibFileName().GetBuffer() << "\","
854 //        << ByteString::CreateFromInt32( GetModule()->GetVersion().GetMajorVersion() ).GetBuffer() << ','
855 //        << ByteString::CreateFromInt32( GetModule()->GetVersion().GetMinorVersion() ).GetBuffer() << ',' << endl
856 //        << "\t/* shell type   */"
857 //        << '"';
858 //    if( xAutomationInterface.Is() )
859 //        rOutStm << ByteString( xAutomationInterface->GetUUId().GetHexName(), RTL_TEXTENCODING_UTF8 ).GetBuffer();
860 //    else
861 //        rOutStm << ByteString( GetUUId().GetHexName(), RTL_TEXTENCODING_UTF8 ).GetBuffer();
862 //    rOutStm << "\");" << endl << endl;
863 
864     // Fuer Interfaces werden kein Slotmaps geschrieben
865     if( !IsShell() )
866     {
867         rOutStm << "#endif" << endl << endl;
868         return;
869     }
870     // Parameter Array schreiben
871     //rOutStm << "SfxArgList " << GetName().GetBuffer() << "ArgMap[] = {" << endl;
872     rOutStm << "SFX_ARGUMENTMAP(" << GetName().GetBuffer() << ')' << endl
873         << '{' << endl;
874 
875     SvULongs aSuperList;
876     SvMetaClassList classList;
877     SvSlotElementList aSlotList;
878     InsertSlots(aSlotList, aSuperList, classList, ByteString(), rBase);
879     sal_uLong n;
880     for ( n=0; n<aSlotList.Count(); n++ )
881     {
882         SvSlotElement *pEle = aSlotList.GetObject( n );
883         SvMetaSlot *pSlot = pEle->xSlot;
884         pSlot->SetListPos(n);
885     }
886 
887     sal_uLong nSlotCount = aSlotList.Count();
888 
889     // alle Attribute schreiben
890     sal_uInt16 nArgCount = WriteSlotParamArray( rBase, aSlotList, rOutStm );
891     if( nArgCount )
892         Back2Delemitter( rOutStm );
893     else
894     {
895         // mindestens einen dummy
896         WriteTab( rOutStm, 1 );
897         rOutStm << "SFX_ARGUMENT( 0, 0, SfxVoidItem )" << endl;
898     }
899     rOutStm << endl << "};" << endl << endl;
900 
901     ByteStringList aStringList;
902     WriteSlotStubs( GetName(), aSlotList, aStringList, rOutStm );
903     ByteString * pStr = aStringList.First();
904     while( pStr )
905     {
906         delete pStr;
907         pStr = aStringList.Next();
908     }
909 
910     rOutStm << endl;
911 
912     // Slotmap schreiben
913     rOutStm << "SFX_SLOTMAP_ARG(" << GetName().GetBuffer() << ')' << endl
914         << '{' << endl;
915 
916     // alle Attribute schreiben
917     WriteSlots( GetName(), 0, aSlotList, rBase, rOutStm );
918     if( nSlotCount )
919         Back2Delemitter( rOutStm );
920     else
921     {
922         // mindestens einen dummy
923         WriteTab( rOutStm, 1 );
924         rOutStm << "SFX_SLOT_ARG(" << GetName().GetBuffer()
925                 << ", 0, 0, "
926                 << "SFX_STUB_PTR_EXEC_NONE,"
927                 << "SFX_STUB_PTR_STATE_NONE,"
928                 << "0, SfxVoidItem, 0, 0, \"\", 0 )" << endl;
929     }
930     rOutStm << endl << "};" << endl << "#endif" << endl << endl;
931 
932     for( n=0; n<aSlotList.Count(); n++ )
933     {
934         aSlotList.Seek(n);
935         SvSlotElement* pEle = aSlotList.GetCurObject();
936         SvMetaSlot* pAttr = pEle->xSlot;
937         pAttr->ResetSlotPointer();
938     }
939 
940     for ( n=0; n<aSlotList.Count(); n++ )
941         delete aSlotList.GetObject(n);
942 }
943 
944 void SvMetaClass::WriteHelpIds( SvIdlDataBase & rBase, SvStream & rOutStm,
945                             Table* pTable )
946 {
947     for( sal_uLong n=0; n<aAttrList.Count(); n++ )
948     {
949         SvMetaAttribute * pAttr = aAttrList.GetObject( n );
950         pAttr->WriteHelpId( rBase, rOutStm, pTable );
951     }
952 }
953 
954 /*************************************************************************
955 |*    SvMetaShell::WriteSrc()
956 *************************************************************************/
957 void SvMetaClass::WriteSrc( SvIdlDataBase & rBase, SvStream & rOutStm,
958                              Table * pTable )
959 {
960     for( sal_uLong n=0; n<aAttrList.Count(); n++ )
961     {
962         SvMetaAttribute * pAttr = aAttrList.GetObject( n );
963         pAttr->WriteSrc( rBase, rOutStm, pTable );
964     }
965 }
966 
967 /*************************************************************************
968 |*    SvMetaClass::WriteHxx()
969 |*
970 |*    Beschreibung
971 *************************************************************************/
972 void SvMetaClass::WriteHxx( SvIdlDataBase &, SvStream & rOutStm, sal_uInt16 )
973 {
974     ByteString aSuperName( "SvDispatch" );
975     if( GetSuperClass() )
976         aSuperName = GetSuperClass()->GetName();
977     const char * pSup = aSuperName.GetBuffer();
978 
979     rOutStm
980     << "class " << GetSvName().GetBuffer()
981     << ": public " << pSup << endl
982     << '{' << endl
983     << "protected:" << endl
984     << "\tvirtual SvGlobalName  GetTypeName() const;" << endl
985     << "\tvirtual sal_Bool          FillTypeLibInfo( SvGlobalName *, sal_uInt16 * pMajor," << endl
986     << "\t                                       sal_uInt16 * pMinor ) const;" << endl
987     << "\tvirtual sal_Bool          FillTypeLibInfo( ByteString * pName, sal_uInt16 * pMajor," << endl;
988     rOutStm
989     << "\t                                       sal_uInt16 * pMinor ) const;" << endl
990     << "\tvirtual void          Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) = 0;" << endl
991     << "public:" << endl
992     << "\t static SvGlobalName  ClassName()" << endl
993     << "\t                      { return SvGlobalName( " << ByteString( GetUUId().GetctorName(), RTL_TEXTENCODING_UTF8 ).GetBuffer() << " ); }" << endl
994     << "};" << endl;
995 }
996 
997 /*************************************************************************
998 |*    SvMetaClass::WriteCxx()
999 |*
1000 |*    Beschreibung
1001 *************************************************************************/
1002 void SvMetaClass::WriteCxx( SvIdlDataBase &, SvStream & rOutStm, sal_uInt16 )
1003 {
1004     ByteString aSuperName( "SvDispatch" );
1005     if( GetSuperClass() )
1006         aSuperName = GetSuperClass()->GetName();
1007     const char * pSup = aSuperName.GetBuffer();
1008 
1009     ByteString name = GetSvName();
1010     // GetTypeName
1011     rOutStm << "SvGlobalName " << name.GetBuffer() << "::GetTypeName() const" << endl
1012     << '{' << endl
1013     << "\treturn ClassName();" << endl
1014     << '}' << endl;
1015 
1016     SvMetaModule * pMod = GetModule();
1017     // FillTypeLibInfo
1018     rOutStm << "sal_Bool " << name.GetBuffer() << "::FillTypeLibInfo( SvGlobalName * pGN," << endl
1019     << "\t                               sal_uInt16 * pMajor," << endl
1020     << "\t                               sal_uInt16 * pMinor ) const" << endl
1021     << '{' << endl
1022     << "\tSvGlobalName aN( " << ByteString( pMod->GetUUId().GetctorName(), RTL_TEXTENCODING_UTF8 ).GetBuffer() << " );" << endl;
1023     rOutStm << "\t*pGN = aN;" << endl
1024     << "\t*pMajor = " << ByteString::CreateFromInt32(pMod->GetVersion().GetMajorVersion()).GetBuffer() << ';' << endl
1025     << "\t*pMinor = " << ByteString::CreateFromInt32(pMod->GetVersion().GetMinorVersion()).GetBuffer() << ';' << endl
1026     << "\treturn sal_True;" << endl
1027     << '}' << endl;
1028 
1029     // FillTypeLibInfo
1030     rOutStm << "sal_Bool " << name.GetBuffer() << "::FillTypeLibInfo( ByteString * pName,"
1031     << "\t                               sal_uInt16 * pMajor," << endl
1032     << "\t                               sal_uInt16 * pMinor ) const" << endl;
1033     rOutStm << '{' << endl
1034     << "\t*pName = \"" << pMod->GetTypeLibFileName().GetBuffer()  << "\";" << endl
1035     << "\t*pMajor = " << ByteString::CreateFromInt32(pMod->GetVersion().GetMajorVersion()).GetBuffer() << ';' << endl
1036     << "\t*pMinor = " << ByteString::CreateFromInt32(pMod->GetVersion().GetMinorVersion()).GetBuffer() << ';' << endl
1037     << "\treturn sal_True;" << endl
1038     << '}' << endl;
1039 
1040     rOutStm << "void " << name.GetBuffer() << "::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )" << endl
1041     << '{' << endl
1042     << "\t" << pSup << "::Notify( rBC, rHint );" << endl
1043     << '}' << endl;
1044 }
1045 
1046 #endif // IDL_COMPILER
1047 
1048