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