Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include <ctype.h>
22 : #include <stdio.h>
23 :
24 : #include <tools/debug.hxx>
25 :
26 : #include <types.hxx>
27 : #include <globals.hxx>
28 : #include <database.hxx>
29 :
30 0 : SV_IMPL_META_FACTORY1( SvMetaAttribute, SvMetaReference );
31 0 : SvMetaAttribute::SvMetaAttribute()
32 : : aAutomation( sal_True, sal_False )
33 : , aExport( sal_True, sal_False )
34 : , aIsCollection ( sal_False, sal_False )
35 : , aReadOnlyDoc ( sal_True, sal_False )
36 : , aHidden( sal_False, sal_False )
37 0 : , bNewAttr( sal_False )
38 : {
39 0 : }
40 :
41 0 : SvMetaAttribute::SvMetaAttribute( SvMetaType * pType )
42 : : aType( pType )
43 : , aAutomation( sal_True, sal_False )
44 : , aExport( sal_True, sal_False )
45 : , aIsCollection ( sal_False, sal_False)
46 : , aReadOnlyDoc ( sal_True, sal_False)
47 : , aHidden( sal_False, sal_False )
48 0 : , bNewAttr( sal_False )
49 : {
50 0 : }
51 :
52 0 : void SvMetaAttribute::Load( SvPersistStream & rStm )
53 : {
54 0 : SvMetaReference::Load( rStm );
55 :
56 : sal_uInt8 nMask;
57 0 : rStm >> nMask;
58 0 : if( nMask & 0x01 )
59 : {
60 : SvMetaType * pType;
61 0 : rStm >> pType;
62 0 : aType = pType;
63 : }
64 0 : if( nMask & 0x02 ) rStm >> aSlotId;
65 0 : if( nMask & 0x04 ) rStm >> aExport;
66 0 : if( nMask & 0x08 ) rStm >> aReadonly;
67 0 : if( nMask & 0x10 ) rStm >> aAutomation;
68 0 : if( nMask & 0x20 ) rStm >> aIsCollection;
69 0 : if( nMask & 0x40 ) rStm >> aReadOnlyDoc;
70 0 : if( nMask & 0x80 ) rStm >> aHidden;
71 0 : }
72 :
73 0 : void SvMetaAttribute::Save( SvPersistStream & rStm )
74 : {
75 0 : SvMetaReference::Save( rStm );
76 :
77 : // create mask
78 0 : sal_uInt8 nMask = 0;
79 0 : if( aType.Is() ) nMask |= 0x1;
80 0 : if( aSlotId.IsSet() ) nMask |= 0x2;
81 0 : if( aExport.IsSet() ) nMask |= 0x4;
82 0 : if( aReadonly.IsSet() ) nMask |= 0x8;
83 0 : if( aAutomation.IsSet() ) nMask |= 0x10;
84 0 : if( aIsCollection.IsSet() ) nMask |= 0x20;
85 0 : if( aReadOnlyDoc.IsSet() ) nMask |= 0x40;
86 0 : if( aHidden.IsSet() ) nMask |= 0x80;
87 :
88 : // write data
89 0 : rStm << nMask;
90 0 : if( nMask & 0x1 ) rStm << aType;
91 0 : if( nMask & 0x2 ) rStm << aSlotId;
92 0 : if( nMask & 0x4 ) rStm << aExport;
93 0 : if( nMask & 0x8 ) rStm << aReadonly;
94 0 : if( nMask & 0x10 ) rStm << aAutomation;
95 0 : if( nMask & 0x20 ) rStm << aIsCollection;
96 0 : if( nMask & 0x40 ) rStm << aReadOnlyDoc;
97 0 : if( nMask & 0x80 ) rStm << aHidden;
98 0 : }
99 :
100 0 : SvMetaType * SvMetaAttribute::GetType() const
101 : {
102 0 : if( aType.Is() || !GetRef() ) return aType;
103 0 : return ((SvMetaAttribute *)GetRef())->GetType();
104 : }
105 :
106 0 : const SvNumberIdentifier & SvMetaAttribute::GetSlotId() const
107 : {
108 0 : if( aSlotId.IsSet() || !GetRef() ) return aSlotId;
109 0 : return ((SvMetaAttribute *)GetRef())->GetSlotId();
110 : }
111 :
112 0 : sal_Bool SvMetaAttribute::GetReadonly() const
113 : {
114 0 : if( aReadonly.IsSet() || !GetRef() ) return aReadonly;
115 0 : return ((SvMetaAttribute *)GetRef())->GetReadonly();
116 : }
117 :
118 0 : sal_Bool SvMetaAttribute::GetExport() const
119 : {
120 0 : if( aExport.IsSet() || !GetRef() ) return aExport;
121 0 : return ((SvMetaAttribute *)GetRef())->GetExport();
122 : }
123 :
124 0 : sal_Bool SvMetaAttribute::GetHidden() const
125 : {
126 : // when export is set, but hidden is not the default is used
127 0 : if ( aExport.IsSet() && !aHidden.IsSet() )
128 0 : return !aExport;
129 0 : else if( aHidden.IsSet() || !GetRef() )
130 0 : return aHidden;
131 : else
132 0 : return ((SvMetaAttribute *)GetRef())->GetHidden();
133 : }
134 :
135 0 : sal_Bool SvMetaAttribute::GetAutomation() const
136 : {
137 0 : if( aAutomation.IsSet() || !GetRef() ) return aAutomation;
138 0 : return ((SvMetaAttribute *)GetRef())->GetAutomation();
139 : }
140 :
141 0 : sal_Bool SvMetaAttribute::GetIsCollection() const
142 : {
143 : sal_Bool bRet;
144 0 : if( aIsCollection.IsSet() || !GetRef() )
145 : {
146 0 : if ( aIsCollection.IsSet() )
147 : {
148 0 : bRet = aIsCollection;
149 0 : return bRet;
150 : }
151 :
152 0 : return aIsCollection;
153 : }
154 :
155 0 : return ((SvMetaSlot *)GetRef())->GetIsCollection();
156 : }
157 :
158 0 : sal_Bool SvMetaAttribute::GetReadOnlyDoc() const
159 : {
160 0 : if( aReadOnlyDoc.IsSet() || !GetRef() ) return aReadOnlyDoc;
161 0 : return ((SvMetaSlot *)GetRef())->GetReadOnlyDoc();
162 : }
163 :
164 0 : sal_Bool SvMetaAttribute::IsMethod() const
165 : {
166 0 : SvMetaType * pType = GetType();
167 : DBG_ASSERT( pType, "no type for attribute" );
168 0 : return pType->GetType() == TYPE_METHOD;
169 : }
170 :
171 0 : sal_Bool SvMetaAttribute::IsVariable() const
172 : {
173 0 : SvMetaType * pType = GetType();
174 0 : return pType->GetType() != TYPE_METHOD;
175 : }
176 :
177 0 : rtl::OString SvMetaAttribute::GetMangleName( sal_Bool ) const
178 : {
179 0 : return GetName().getString();
180 : }
181 :
182 0 : sal_Bool SvMetaAttribute::Test( SvIdlDataBase & rBase,
183 : SvTokenStream & rInStm )
184 : {
185 0 : sal_Bool bOk = sal_True;
186 0 : if( GetType()->IsItem() && !GetSlotId().IsSet() )
187 : {
188 0 : rBase.SetError( "slot without id declared", rInStm.GetToken() );
189 0 : rBase.WriteError( rInStm );
190 0 : bOk = sal_False;
191 : }
192 0 : return bOk;
193 : }
194 :
195 0 : sal_Bool SvMetaAttribute::ReadSvIdl( SvIdlDataBase & rBase,
196 : SvTokenStream & rInStm )
197 : {
198 0 : sal_uInt32 nTokPos = rInStm.Tell();
199 0 : if( !GetType() )
200 : // no type in ctor passed on
201 0 : aType = rBase.ReadKnownType( rInStm );
202 0 : sal_Bool bOk = sal_False;
203 0 : if( GetType() )
204 : {
205 0 : ReadNameSvIdl( rBase, rInStm );
206 0 : aSlotId.ReadSvIdl( rBase, rInStm );
207 :
208 0 : bOk = sal_True;
209 0 : SvToken * pTok = rInStm.GetToken();
210 0 : if( bOk && pTok->IsChar() && pTok->GetChar() == '(' )
211 : {
212 0 : SvMetaTypeRef xT = new SvMetaType();
213 0 : xT->SetRef( GetType() );
214 0 : aType = xT;
215 0 : bOk = aType->ReadMethodArgs( rBase, rInStm );
216 : }
217 0 : if( bOk )
218 0 : bOk = SvMetaName::ReadSvIdl( rBase, rInStm );
219 : }
220 : else
221 0 : rBase.SetError( "unknown type", rInStm.GetToken() );
222 :
223 0 : if( !bOk )
224 0 : rInStm.Seek( nTokPos );
225 0 : return bOk;
226 : }
227 :
228 0 : void SvMetaAttribute::WriteSvIdl
229 : (
230 : SvIdlDataBase & rBase,
231 : SvStream & rOutStm,
232 : sal_uInt16 nTab
233 : )
234 : {
235 0 : SvMetaType * pType = GetType();
236 0 : pType->WriteTypePrefix( rBase, rOutStm, nTab, WRITE_IDL );
237 0 : rOutStm << ' ' << GetName().getString().getStr();
238 0 : if( aSlotId.IsSet() )
239 0 : rOutStm << ' ' << aSlotId.getString().getStr();
240 0 : if( pType->GetType() == TYPE_METHOD )
241 0 : pType->WriteMethodArgs( rBase, rOutStm, nTab, WRITE_IDL );
242 0 : sal_uLong nPos = rOutStm.Tell();
243 0 : rOutStm << endl;
244 0 : SvMetaName::WriteSvIdl( rBase, rOutStm, nTab );
245 0 : TestAndSeekSpaceOnly( rOutStm, nPos );
246 0 : }
247 :
248 0 : void SvMetaAttribute::ReadAttributesSvIdl( SvIdlDataBase & rBase,
249 : SvTokenStream & rInStm )
250 : {
251 0 : SvMetaReference::ReadAttributesSvIdl( rBase, rInStm );
252 0 : aSlotId.ReadSvIdl( rBase, SvHash_SlotId(), rInStm );
253 0 : aExport.ReadSvIdl( SvHash_Export(), rInStm );
254 0 : aHidden.ReadSvIdl( SvHash_Hidden(), rInStm );
255 0 : aAutomation.ReadSvIdl( SvHash_Automation(), rInStm );
256 0 : aIsCollection.ReadSvIdl( SvHash_IsCollection(), rInStm );
257 0 : aReadOnlyDoc.ReadSvIdl( SvHash_ReadOnlyDoc(), rInStm );
258 0 : if( aReadonly.ReadSvIdl( SvHash_Readonly(), rInStm ) )
259 : {
260 0 : if( GetType()->GetType() == TYPE_METHOD )
261 : {
262 : // set error
263 0 : rBase.SetError( "Readonly in function attribute", rInStm.GetToken() );
264 0 : rBase.WriteError( rInStm );
265 : }
266 : }
267 0 : }
268 :
269 0 : void SvMetaAttribute::WriteAttributesSvIdl
270 : (
271 : SvIdlDataBase & rBase,
272 : SvStream & rOutStm,
273 : sal_uInt16 nTab
274 : )
275 : {
276 0 : SvMetaReference::WriteAttributesSvIdl( rBase, rOutStm, nTab );
277 :
278 0 : if( !aExport || !aAutomation || aReadonly )
279 : {
280 0 : WriteTab( rOutStm, nTab );
281 0 : rOutStm << "//class SvMetaAttribute" << endl;
282 0 : if( !aExport )
283 : {
284 0 : WriteTab( rOutStm, nTab );
285 0 : aExport.WriteSvIdl( SvHash_Export(), rOutStm );
286 0 : rOutStm << ';' << endl;
287 : }
288 0 : if ( aHidden != aExport )
289 : {
290 0 : WriteTab( rOutStm, nTab );
291 0 : aExport.WriteSvIdl( SvHash_Hidden(), rOutStm );
292 0 : rOutStm << ';' << endl;
293 : }
294 0 : if( aReadonly )
295 : {
296 0 : WriteTab( rOutStm, nTab );
297 0 : aReadonly.WriteSvIdl( SvHash_Readonly(), rOutStm );
298 0 : rOutStm << ';' << endl;
299 : }
300 0 : if( !aAutomation )
301 : {
302 0 : WriteTab( rOutStm, nTab );
303 0 : aAutomation.WriteSvIdl( SvHash_Automation(), rOutStm );
304 0 : rOutStm << ';' << endl;
305 : }
306 0 : if( aIsCollection )
307 : {
308 0 : WriteTab( rOutStm, nTab );
309 0 : aIsCollection.WriteSvIdl( SvHash_IsCollection(), rOutStm );
310 0 : rOutStm << ';' << endl;
311 : }
312 0 : if( !aReadOnlyDoc )
313 : {
314 0 : WriteTab( rOutStm, nTab );
315 0 : aReadOnlyDoc.WriteSvIdl( SvHash_ReadOnlyDoc(), rOutStm );
316 0 : rOutStm << ';' << endl;
317 : }
318 : }
319 0 : }
320 :
321 0 : void SvMetaAttribute::WriteParam( SvIdlDataBase & rBase,
322 : SvStream & rOutStm,
323 : sal_uInt16 nTab,
324 : WriteType nT )
325 : {
326 0 : SvMetaType * pType = GetType();
327 : DBG_ASSERT( pType, "no type for attribute" );
328 0 : SvMetaType * pBaseType = pType->GetBaseType();
329 : DBG_ASSERT( pBaseType, "no base type for attribute" );
330 :
331 0 : if( nT == WRITE_ODL || nT == WRITE_DOCU
332 : || nT == WRITE_C_HEADER || nT == WRITE_C_SOURCE )
333 : {
334 0 : if( pBaseType->GetType() == TYPE_STRUCT )
335 : {
336 0 : const SvMetaAttributeMemberList & rList = pBaseType->GetAttrList();
337 0 : sal_uLong nCount = rList.size();
338 0 : for( sal_uLong i = 0; i < nCount; i++ )
339 : {
340 0 : rList[i]->WriteParam( rBase, rOutStm, nTab, nT );
341 0 : if( i+1<nCount )
342 : {
343 0 : rOutStm << ',';
344 : }
345 : }
346 : }
347 : else
348 : {
349 0 : if ( nT != WRITE_DOCU )
350 : {
351 0 : WriteTab( rOutStm, nTab );
352 0 : pBaseType->WriteTypePrefix( rBase, rOutStm, nTab, nT );
353 : }
354 :
355 0 : if( !GetName().getString().isEmpty() )
356 : {
357 0 : rOutStm << ' ';
358 0 : rOutStm << GetName().getString().getStr();
359 : }
360 :
361 0 : if ( nT == WRITE_DOCU )
362 : {
363 0 : if( pBaseType->GetType() == TYPE_METHOD ||
364 0 : pBaseType->GetType() == TYPE_STRUCT ||
365 0 : pBaseType->GetType() == TYPE_ENUM )
366 : {
367 : OSL_FAIL( "Falscher Parametertyp!" );
368 : }
369 : else
370 0 : rOutStm << pBaseType->GetBasicPostfix().getStr();
371 : }
372 : }
373 : }
374 0 : }
375 :
376 0 : sal_uLong SvMetaAttribute::MakeSlotValue( SvIdlDataBase & rBase, sal_Bool bVar ) const
377 : {
378 0 : const SvNumberIdentifier & rId = GetSlotId();
379 0 : sal_uLong n = rId.GetValue();
380 0 : if( !rBase.aStructSlotId.getString().isEmpty() )
381 : {
382 0 : n = n << 20;
383 0 : n += rBase.aStructSlotId.GetValue();
384 : }
385 0 : if( PTR_CAST( SvMetaSlot, this ) )
386 0 : n |= 0x20000;
387 0 : if( !bVar )
388 0 : n += 0x10000;
389 0 : else if ( GetIsCollection() )
390 0 : n += 0x40000;
391 0 : return n;
392 : }
393 :
394 0 : void SvMetaAttribute::WriteAttributes( SvIdlDataBase & rBase, SvStream & rOutStm,
395 : sal_uInt16 nTab,
396 : WriteType nT, WriteAttribute nA )
397 : {
398 0 : if( nT == WRITE_ODL )
399 : {
400 0 : const SvNumberIdentifier & rId = GetSlotId();
401 0 : sal_Bool bReadonly = GetReadonly() || ( nA & WA_READONLY );
402 0 : if( (rId.IsSet() && !(nA & WA_STRUCT)) || bReadonly )
403 : {
404 0 : sal_Bool bVar = IsVariable();
405 0 : if( nA & WA_VARIABLE )
406 0 : bVar = sal_True;
407 0 : else if( nA & WA_METHOD )
408 0 : bVar = sal_False;
409 :
410 0 : WriteTab( rOutStm, nTab );
411 0 : rOutStm << "//class SvMetaAttribute" << endl;
412 0 : if( rId.IsSet() && !(nA & WA_STRUCT) )
413 : {
414 0 : WriteTab( rOutStm, nTab );
415 0 : rOutStm << "id("
416 0 : << rtl::OString::valueOf(static_cast<sal_Int32>(MakeSlotValue(rBase,bVar))).getStr()
417 0 : << ")," << endl;
418 : }
419 0 : if( bVar && (bReadonly || IsMethod()) )
420 : {
421 0 : WriteTab( rOutStm, nTab );
422 0 : rOutStm << "readonly," << endl;
423 : }
424 : }
425 : }
426 0 : }
427 :
428 0 : void SvMetaAttribute::WriteCSource( SvIdlDataBase & rBase, SvStream & rOutStm,
429 : sal_Bool bSet )
430 : {
431 0 : rOutStm << endl;
432 0 : SvMetaType * pType = GetType();
433 0 : SvMetaType * pBaseType = pType->GetBaseType();
434 :
435 : // for Set the return is always void
436 0 : sal_Bool bVoid = bSet;
437 0 : if( pBaseType->GetType() == TYPE_METHOD )
438 0 : bVoid = pBaseType->GetReturnType()->GetBaseType()->GetName().getString() == "void";
439 :
440 : // emit methods/functions body
441 0 : rOutStm << '{' << endl;
442 0 : WriteTab( rOutStm, 1 );
443 :
444 0 : if( !bVoid )
445 : {
446 0 : if ( pBaseType->GetCName() == "double" )
447 : {
448 0 : rOutStm << "return *(double*)";
449 : }
450 : else
451 : {
452 0 : rOutStm << "return (";
453 0 : pType->WriteTypePrefix( rBase, rOutStm, 2, WRITE_C_SOURCE );
454 0 : rOutStm << ") ";
455 : }
456 : }
457 0 : rOutStm << "pODKCallFunction( "
458 0 : << rtl::OString::valueOf(static_cast<sal_Int32>(MakeSlotValue(rBase, IsVariable()))).getStr();
459 0 : rOutStm << ',' << endl;
460 0 : WriteTab( rOutStm, 3 );
461 0 : rOutStm << " h" << rBase.aIFaceName.getStr() << " , ";
462 :
463 0 : rtl::OString aParserStr;
464 0 : if( pBaseType->GetType() == TYPE_METHOD || bSet )
465 0 : aParserStr = pBaseType->GetParserString();
466 0 : if( !aParserStr.isEmpty() )
467 : {
468 0 : rOutStm << '\"';
469 0 : rOutStm << aParserStr.getStr();
470 0 : rOutStm << "\", ";
471 : }
472 : else
473 0 : rOutStm << "NULL, ";
474 :
475 0 : if( pBaseType->GetType() == TYPE_METHOD && !bVoid )
476 : {
477 0 : rOutStm << "'";
478 0 : rOutStm << pBaseType->GetReturnType()->GetBaseType()->GetParserChar();
479 0 : rOutStm << "'";
480 : }
481 0 : else if ( !bSet )
482 : {
483 0 : rOutStm << "'";
484 0 : rOutStm << pBaseType->GetParserChar();
485 0 : rOutStm << "'";
486 : }
487 : else
488 0 : rOutStm << '0';
489 :
490 0 : if( !aParserStr.isEmpty() )
491 : {
492 0 : rOutStm << ", ";
493 0 : if( IsMethod() )
494 0 : pBaseType->WriteParamNames( rBase, rOutStm, rtl::OString() );
495 0 : else if( bSet )
496 0 : pBaseType->WriteParamNames( rBase, rOutStm, GetName().getString() );
497 : }
498 :
499 0 : rOutStm << " );" << endl;
500 0 : rOutStm << '}' << endl;
501 0 : }
502 :
503 0 : void SvMetaAttribute::WriteRecursiv_Impl( SvIdlDataBase & rBase,
504 : SvStream & rOutStm, sal_uInt16 nTab,
505 : WriteType nT, WriteAttribute nA )
506 : {
507 0 : const SvMetaAttributeMemberList & rList = GetType()->GetBaseType()->GetAttrList();
508 0 : sal_uLong nCount = rList.size();
509 :
510 0 : SvNumberIdentifier slotId = rBase.aStructSlotId;
511 0 : if ( !GetSlotId().getString().isEmpty() )
512 0 : rBase.aStructSlotId = GetSlotId();
513 :
514 : // offial hack interface by MM: special controls get passed with the WriteAttribute
515 0 : if ( GetReadonly() )
516 0 : nA |= WA_READONLY;
517 :
518 0 : for( sal_uLong i = 0; i < nCount; i++ )
519 : {
520 0 : SvMetaAttribute *pAttr = rList[i];
521 0 : if ( nT == WRITE_DOCU )
522 0 : pAttr->SetDescription( GetDescription().getString() );
523 0 : pAttr->Write( rBase, rOutStm, nTab, nT, nA );
524 0 : if( nT == WRITE_ODL && i +1 < nCount )
525 0 : rOutStm << ';' << endl;
526 : }
527 :
528 0 : rBase.aStructSlotId = slotId;
529 0 : }
530 :
531 0 : void SvMetaAttribute::Write( SvIdlDataBase & rBase, SvStream & rOutStm,
532 : sal_uInt16 nTab,
533 : WriteType nT, WriteAttribute nA )
534 : {
535 : // no attributes for automation
536 0 : if( nT == WRITE_DOCU )
537 : {
538 0 : if ( GetHidden() )
539 0 : return;
540 : }
541 0 : else if ( !GetAutomation() || !GetExport() )
542 0 : return;
543 :
544 : sal_Bool bVariable;
545 0 : if( nA & WA_VARIABLE )
546 0 : bVariable = sal_True;
547 0 : else if( nA & WA_METHOD )
548 0 : bVariable = sal_False;
549 : else
550 0 : bVariable = IsVariable();
551 :
552 0 : SvMetaType * pType = GetType();
553 : DBG_ASSERT( pType, "no type for attribute" );
554 0 : SvMetaType * pBaseType = pType->GetBaseType();
555 : DBG_ASSERT( pBaseType, "no base type for attribute" );
556 0 : int nBType = pBaseType->GetType();
557 :
558 0 : if( nT == WRITE_ODL )
559 : {
560 0 : if( (bVariable && IsVariable()) || (!bVariable && IsMethod()) )
561 : {
562 0 : if( nBType == TYPE_STRUCT )
563 0 : WriteRecursiv_Impl( rBase, rOutStm, nTab, nT, nA );
564 : else
565 : {
566 0 : SvMetaReference::Write( rBase, rOutStm, nTab, nT, nA );
567 0 : WriteTab( rOutStm, nTab );
568 0 : pBaseType->WriteTypePrefix( rBase, rOutStm, nTab, nT );
569 :
570 0 : if( !GetName().getString().isEmpty() )
571 : {
572 0 : rOutStm << ' ';
573 0 : rOutStm << GetName().getString().getStr();
574 : }
575 0 : if( pType->GetType() == TYPE_METHOD )
576 0 : pType->WriteMethodArgs( rBase, rOutStm, nTab, nT );
577 : }
578 : }
579 : }
580 0 : else if( nT == WRITE_C_HEADER || nT == WRITE_C_SOURCE )
581 : {
582 0 : if( !bVariable && IsMethod() )
583 : {
584 0 : rtl::OString name = rBase.aIFaceName + GetName().getString();
585 0 : const char * pName = name.getStr();
586 0 : WriteTab( rOutStm, nTab );
587 0 : pBaseType->WriteTypePrefix( rBase, rOutStm, nTab, nT );
588 0 : rOutStm << ' ' << pName;
589 0 : pType->WriteMethodArgs( rBase, rOutStm, nTab, nT );
590 0 : if( nT == WRITE_C_HEADER )
591 0 : rOutStm << ';' << endl << endl;
592 : else
593 0 : WriteCSource( rBase, rOutStm, sal_False );
594 : }
595 0 : else if ( bVariable && IsVariable() )
596 : {
597 0 : if( nBType == TYPE_STRUCT )
598 : {
599 : // for assistance emit the name of the property as acomment
600 0 : rOutStm << "/* " << GetName().getString().getStr() << " */" << endl;
601 :
602 0 : WriteRecursiv_Impl( rBase, rOutStm, nTab, nT, nA );
603 : }
604 : else
605 : {
606 0 : rtl::OString name = GetName().getString();
607 :
608 0 : sal_Bool bReadonly = GetReadonly() || ( nA & WA_READONLY );
609 0 : if ( !bReadonly && !IsMethod() )
610 : {
611 : // allocation
612 0 : WriteTab( rOutStm, nTab );
613 0 : rOutStm << "void ";
614 0 : rOutStm << rBase.aIFaceName.getStr()
615 0 : << "Set" << name.getStr() << "( " << C_PREF
616 0 : << "Object h" << rBase.aIFaceName.getStr() << ", " << endl;
617 0 : WriteTab( rOutStm, nTab+1 );
618 0 : pBaseType->WriteTypePrefix( rBase, rOutStm, nTab, nT );
619 0 : rOutStm << ' ' << name.getStr() << " )";
620 0 : if( nT == WRITE_C_HEADER )
621 0 : rOutStm << ';' << endl << endl;
622 : else
623 0 : WriteCSource( rBase, rOutStm, sal_True );
624 : }
625 :
626 : // access
627 0 : WriteTab( rOutStm, nTab );
628 0 : pBaseType->WriteTypePrefix( rBase, rOutStm, nTab, nT );
629 0 : rOutStm << ' ';
630 0 : rOutStm << rBase.aIFaceName.getStr()
631 0 : << "Get" << name.getStr() << "( " << C_PREF
632 0 : << "Object h" << rBase.aIFaceName.getStr() << " )";
633 0 : if( nT == WRITE_C_HEADER )
634 0 : rOutStm << ';' << endl << endl;
635 : else
636 0 : WriteCSource( rBase, rOutStm, sal_False );
637 : }
638 0 : }
639 : }
640 0 : else if ( nT == WRITE_DOCU )
641 : {
642 0 : if( !bVariable && IsMethod() )
643 : {
644 0 : rOutStm << "<METHOD>" << endl
645 0 : << GetSlotId().getString().getStr() << endl
646 0 : << GetName().getString().getStr() << endl
647 0 : << endl; // readonly
648 :
649 : // return type
650 0 : SvMetaType* pType2 = GetType();
651 0 : SvMetaType* pBaseType2 = pType2->GetBaseType();
652 0 : rOutStm << pBaseType2->GetReturnType()->GetBaseType()->GetBasicName().getStr() << endl;
653 :
654 : DBG_ASSERT( !pBaseType2->GetReturnType()->GetBaseType()->GetBasicName().isEmpty(),
655 : "Leerer BasicName" );
656 :
657 : // syntax
658 0 : rOutStm << GetName().getString().getStr();
659 0 : pType2->WriteMethodArgs( rBase, rOutStm, nTab, nT );
660 :
661 : // C return type
662 0 : pBaseType2->WriteTypePrefix( rBase, rOutStm, 0, WRITE_C_HEADER );
663 0 : rOutStm << endl;
664 :
665 : // for methods also C syntax
666 0 : rOutStm << "<C-SYNTAX>" << endl;
667 0 : Write( rBase, rOutStm, 0, WRITE_C_HEADER, nA );
668 0 : rOutStm << "</C-SYNTAX>" << endl;
669 :
670 : // description
671 0 : WriteDescription( rOutStm );
672 0 : rOutStm << "</METHOD>" << endl << endl;
673 : }
674 0 : else if( bVariable && IsVariable() )
675 : {
676 0 : if( nBType == TYPE_STRUCT )
677 : {
678 0 : WriteRecursiv_Impl( rBase, rOutStm, nTab, nT, nA );
679 : }
680 : else
681 : {
682 0 : rOutStm << "<PROPERTY>" << endl
683 0 : << GetSlotId().getString().getStr() << endl
684 0 : << GetName().getString().getStr() << endl;
685 0 : if ( GetReadonly() )
686 0 : rOutStm << "(nur lesen)" << endl;
687 : else
688 0 : rOutStm << endl;
689 :
690 : // for properties type instead of the return value
691 0 : rOutStm << pBaseType->GetBasicName().getStr() << endl;
692 :
693 : DBG_ASSERT( !pBaseType->GetBasicName().isEmpty(),
694 : "Leerer BasicName" );
695 :
696 : // for properties no syntax
697 0 : rOutStm << endl;
698 :
699 : // C return type
700 0 : pBaseType->WriteTypePrefix( rBase, rOutStm, 0, WRITE_C_HEADER );
701 0 : rOutStm << endl;
702 :
703 : // description
704 0 : WriteDescription( rOutStm );
705 0 : rOutStm << "</PROPERTY>" << endl << endl;
706 : }
707 : }
708 : }
709 : }
710 :
711 0 : sal_uLong SvMetaAttribute::MakeSfx( rtl::OStringBuffer& rAttrArray )
712 : {
713 0 : SvMetaType * pType = GetType();
714 : DBG_ASSERT( pType, "no type for attribute" );
715 0 : SvMetaType * pBaseType = pType->GetBaseType();
716 : DBG_ASSERT( pBaseType, "no base type for attribute" );
717 0 : if( pBaseType->GetType() == TYPE_STRUCT )
718 0 : return pBaseType->MakeSfx( rAttrArray );
719 : else
720 : {
721 0 : rAttrArray.append('{');
722 0 : rAttrArray.append(GetSlotId().getString());
723 0 : rAttrArray.append(",\"");
724 0 : rAttrArray.append(GetName().getString());
725 0 : rAttrArray.append("\"}");
726 0 : return 1;
727 : }
728 : }
729 :
730 0 : void SvMetaAttribute::Insert (SvSlotElementList&, const rtl::OString&, SvIdlDataBase&)
731 : {
732 0 : }
733 :
734 0 : void SvMetaAttribute::WriteHelpId( SvIdlDataBase &, SvStream &, HelpIdTable& )
735 : {
736 0 : }
737 :
738 0 : SV_IMPL_META_FACTORY1( SvMetaType, SvMetaExtern );
739 : #define CTOR \
740 : : aCall0( CALL_VALUE, sal_False ) \
741 : , aCall1( CALL_VALUE, sal_False ) \
742 : , aSbxDataType( 0, sal_False ) \
743 : , pAttrList( NULL ) \
744 : , nType( TYPE_BASE ) \
745 : , bIsItem( sal_False ) \
746 : , bIsShell( sal_False ) \
747 : , cParserChar( 'h' )
748 :
749 0 : SvMetaType::SvMetaType()
750 0 : CTOR
751 : {
752 0 : }
753 :
754 0 : SvMetaType::SvMetaType( const rtl::OString& rName, char cPC,
755 : const rtl::OString& rCName )
756 0 : CTOR
757 : {
758 0 : SetName( rName );
759 0 : cParserChar = cPC;
760 0 : aCName.setString(rCName);
761 0 : }
762 :
763 0 : SvMetaType::SvMetaType( const rtl::OString& rName,
764 : const rtl::OString& rSbxName,
765 : const rtl::OString& rOdlName,
766 : char cPc,
767 : const rtl::OString& rCName,
768 : const rtl::OString& rBasicName,
769 : const rtl::OString& rBasicPostfix )
770 0 : CTOR
771 : {
772 0 : SetName( rName );
773 0 : aSbxName.setString(rSbxName);
774 0 : aOdlName.setString(rOdlName);
775 0 : cParserChar = cPc;
776 0 : aCName.setString(rCName);
777 0 : aBasicName.setString(rBasicName);
778 0 : aBasicPostfix.setString(rBasicPostfix);
779 0 : }
780 :
781 0 : void SvMetaType::Load( SvPersistStream & rStm )
782 : {
783 0 : SvMetaExtern::Load( rStm );
784 :
785 : sal_uInt16 nMask;
786 0 : rStm >> nMask;
787 0 : if( nMask & 0x0001 ) rStm >> aIn;
788 0 : if( nMask & 0x0002 ) rStm >> aOut;
789 0 : if( nMask & 0x0004 ) rStm >> aCall0;
790 0 : if( nMask & 0x0008 ) rStm >> aCall1;
791 0 : if( nMask & 0x0010 ) rStm >> aSbxDataType;
792 0 : if( nMask & 0x0020 ) rStm >> aSvName;
793 0 : if( nMask & 0x0040 ) rStm >> aSbxName;
794 0 : if( nMask & 0x0080 ) rStm >> aOdlName;
795 0 : if( nMask & 0x0100 ) rStm >> GetAttrList();
796 0 : if( nMask & 0x0200 ) bIsItem = sal_True;
797 0 : if( nMask & 0x0400 ) bIsShell = sal_True;
798 0 : if( nMask & 0x0800 )
799 : {
800 : sal_uInt16 nT;
801 0 : rStm >> nT;
802 0 : nType = nT;
803 : }
804 0 : if( nMask & 0x1000 ) rStm >> cParserChar;
805 0 : if( nMask & 0x2000 ) rStm >> aCName;
806 0 : if( nMask & 0x4000 ) rStm >> aBasicName;
807 0 : if( nMask & 0x8000 ) rStm >> aBasicPostfix;
808 0 : }
809 :
810 0 : void SvMetaType::Save( SvPersistStream & rStm )
811 : {
812 0 : SvMetaExtern::Save( rStm );
813 :
814 : // create mask
815 0 : sal_uInt16 nMask = 0;
816 0 : if( aIn.IsSet() ) nMask |= 0x0001;
817 0 : if( aOut.IsSet() ) nMask |= 0x0002;
818 0 : if( aCall0.IsSet() ) nMask |= 0x0004;
819 0 : if( aCall1.IsSet() ) nMask |= 0x0008;
820 0 : if( aSbxDataType.IsSet() ) nMask |= 0x0010;
821 0 : if( aSvName.IsSet() ) nMask |= 0x0020;
822 0 : if( aSbxName.IsSet() ) nMask |= 0x0040;
823 0 : if( aOdlName.IsSet() ) nMask |= 0x0080;
824 0 : if( GetAttrCount() ) nMask |= 0x0100;
825 0 : if( bIsItem ) nMask |= 0x0200;
826 0 : if( bIsShell ) nMask |= 0x0400;
827 0 : if( nType != TYPE_BASE ) nMask |= 0x0800;
828 0 : if( cParserChar != 'h' ) nMask |= 0x1000;
829 0 : if( aCName.IsSet() ) nMask |= 0x2000;
830 0 : if( aBasicName.IsSet() ) nMask |= 0x4000;
831 0 : if( aBasicPostfix.IsSet() ) nMask |= 0x8000;
832 :
833 : // write data
834 0 : rStm << nMask;
835 0 : if( nMask & 0x0001 ) rStm << aIn;
836 0 : if( nMask & 0x0002 ) rStm << aOut;
837 0 : if( nMask & 0x0004 ) rStm << aCall0;
838 0 : if( nMask & 0x0008 ) rStm << aCall1;
839 0 : if( nMask & 0x0010 ) rStm << aSbxDataType;
840 0 : if( nMask & 0x0020 ) rStm << aSvName;
841 0 : if( nMask & 0x0040 ) rStm << aSbxName;
842 0 : if( nMask & 0x0080 ) rStm << aOdlName;
843 0 : if( nMask & 0x0100 ) rStm << *pAttrList;
844 0 : if( nMask & 0x0800 ) rStm << (sal_uInt16)nType;
845 0 : if( nMask & 0x1000 ) rStm << cParserChar;
846 0 : if( nMask & 0x2000 ) rStm << aCName;
847 0 : if( nMask & 0x4000 ) rStm << aBasicName;
848 0 : if( nMask & 0x8000 ) rStm << aBasicPostfix;
849 0 : }
850 :
851 0 : SvMetaAttributeMemberList & SvMetaType::GetAttrList() const
852 : {
853 0 : if( !pAttrList )
854 0 : ((SvMetaType *)this)->pAttrList = new SvMetaAttributeMemberList();
855 0 : return *pAttrList;
856 : }
857 :
858 0 : void SvMetaType::SetType( int nT )
859 : {
860 0 : nType = nT;
861 0 : if( nType == TYPE_ENUM )
862 : {
863 0 : aOdlName.setString("short");
864 : }
865 0 : else if( nType == TYPE_CLASS )
866 : {
867 0 : rtl::OStringBuffer aTmp(C_PREF);
868 0 : aTmp.append(RTL_CONSTASCII_STRINGPARAM("Object *"));
869 0 : aCName.setString(aTmp.makeStringAndClear());
870 : }
871 0 : }
872 :
873 0 : SvMetaType * SvMetaType::GetBaseType() const
874 : {
875 0 : if( GetRef() && GetType() == TYPE_BASE )
876 0 : return ((SvMetaType *)GetRef())->GetBaseType();
877 0 : return (SvMetaType *)this;
878 : }
879 :
880 0 : SvMetaType * SvMetaType::GetReturnType() const
881 : {
882 : DBG_ASSERT( GetType() == TYPE_METHOD, "no method" );
883 : DBG_ASSERT( GetRef(), "no return type" );
884 0 : return (SvMetaType *)GetRef();
885 : }
886 :
887 0 : const rtl::OString& SvMetaType::GetBasicName() const
888 : {
889 0 : if( aBasicName.IsSet() || !GetRef() )
890 0 : return aBasicName.getString();
891 : else
892 0 : return ((SvMetaType*)GetRef())->GetBasicName();
893 : }
894 :
895 0 : rtl::OString SvMetaType::GetBasicPostfix() const
896 : {
897 : // MBN and Co always want "As xxx"
898 : return rtl::OStringBuffer(RTL_CONSTASCII_STRINGPARAM(" As ")).
899 0 : append(GetBasicName()).
900 0 : makeStringAndClear();
901 : }
902 :
903 0 : sal_Bool SvMetaType::GetIn() const
904 : {
905 0 : if( aIn.IsSet() || !GetRef() )
906 0 : return aIn;
907 : else
908 0 : return ((SvMetaType *)GetRef())->GetIn();
909 : }
910 :
911 0 : sal_Bool SvMetaType::GetOut() const
912 : {
913 0 : if( aOut.IsSet() || !GetRef() )
914 0 : return aOut;
915 : else
916 0 : return ((SvMetaType *)GetRef())->GetOut();
917 : }
918 :
919 0 : void SvMetaType::SetCall0( int e )
920 : {
921 0 : aCall0 = (int)e;
922 0 : if( aCall0 == CALL_VALUE && aCall1 == CALL_VALUE )
923 : {
924 0 : if( GetType() == TYPE_POINTER )
925 0 : SetType( TYPE_BASE );
926 : }
927 : else
928 : {
929 : DBG_ASSERT( nType == TYPE_POINTER || nType == TYPE_BASE,
930 : "set no base type to pointer" );
931 0 : SetType( TYPE_POINTER );
932 : }
933 0 : }
934 :
935 0 : int SvMetaType::GetCall0() const
936 : {
937 0 : if( aCall0.IsSet() || !GetRef() )
938 0 : return aCall0;
939 : else
940 0 : return ((SvMetaType *)GetRef())->GetCall0();
941 : }
942 :
943 0 : void SvMetaType::SetCall1( int e )
944 : {
945 0 : aCall1 = (int)e;
946 0 : if( aCall0 == CALL_VALUE && aCall1 == CALL_VALUE )
947 : {
948 0 : if( GetType() == TYPE_POINTER )
949 0 : SetType( TYPE_BASE );
950 : }
951 : else
952 : {
953 : DBG_ASSERT( nType == TYPE_POINTER || nType == TYPE_BASE,
954 : "set no base type to pointer" );
955 0 : SetType( TYPE_POINTER );
956 : }
957 0 : }
958 :
959 0 : int SvMetaType::GetCall1() const
960 : {
961 0 : if( aCall1.IsSet() || !GetRef() )
962 0 : return aCall1;
963 : else
964 0 : return ((SvMetaType *)GetRef())->GetCall1();
965 : }
966 :
967 0 : const rtl::OString& SvMetaType::GetSvName() const
968 : {
969 0 : if( aSvName.IsSet() || !GetRef() )
970 0 : return aSvName.getString();
971 : else
972 0 : return ((SvMetaType *)GetRef())->GetSvName();
973 : }
974 :
975 0 : const rtl::OString& SvMetaType::GetSbxName() const
976 : {
977 0 : if( aSbxName.IsSet() || !GetRef() )
978 0 : return aSbxName.getString();
979 : else
980 0 : return ((SvMetaType *)GetRef())->GetSbxName();
981 : }
982 :
983 0 : const rtl::OString& SvMetaType::GetOdlName() const
984 : {
985 0 : if( aOdlName.IsSet() || !GetRef() )
986 0 : return aOdlName.getString();
987 : else
988 0 : return ((SvMetaType *)GetRef())->GetOdlName();
989 : }
990 :
991 0 : const rtl::OString& SvMetaType::GetCName() const
992 : {
993 0 : if( aCName.IsSet() || !GetRef() )
994 0 : return aCName.getString();
995 : else
996 0 : return ((SvMetaType *)GetRef())->GetCName();
997 : }
998 :
999 0 : sal_Bool SvMetaType::SetName( const rtl::OString& rName, SvIdlDataBase * pBase )
1000 : {
1001 0 : aSvName.setString(rName);
1002 0 : aSbxName.setString(rName);
1003 0 : aCName.setString(rName);
1004 0 : if( GetType() != TYPE_ENUM )
1005 0 : aOdlName.setString(rName);
1006 0 : return SvMetaReference::SetName( rName, pBase );
1007 : }
1008 :
1009 0 : rtl::OString SvMetaType::GetCString() const
1010 : {
1011 0 : rtl::OStringBuffer out( GetSvName() );
1012 0 : if( aCall0 == (int)CALL_POINTER )
1013 0 : out.append(" *");
1014 0 : else if( aCall0 == (int)CALL_REFERENCE )
1015 0 : out.append(" &");
1016 0 : if( aCall1 == (int)CALL_POINTER )
1017 0 : out.append('*');
1018 0 : else if( aCall1 == (int)CALL_REFERENCE )
1019 0 : out.append('&');
1020 0 : return out.makeStringAndClear();
1021 : }
1022 :
1023 0 : sal_Bool SvMetaType::ReadHeaderSvIdl( SvIdlDataBase & rBase,
1024 : SvTokenStream & rInStm )
1025 : {
1026 0 : sal_Bool bOk = sal_False;
1027 0 : sal_uInt32 nTokPos = rInStm.Tell();
1028 0 : SvToken * pTok = rInStm.GetToken_Next();
1029 :
1030 0 : if( pTok->Is( SvHash_interface() )
1031 0 : || pTok->Is( SvHash_shell() ) )
1032 : {
1033 0 : if( pTok->Is( SvHash_shell() ) )
1034 0 : bIsShell = sal_True;
1035 0 : SetType( TYPE_CLASS );
1036 0 : bOk = ReadNamesSvIdl( rBase, rInStm );
1037 :
1038 : }
1039 0 : else if( pTok->Is( SvHash_struct() ) )
1040 : {
1041 0 : SetType( TYPE_STRUCT );
1042 0 : bOk = ReadNamesSvIdl( rBase, rInStm );
1043 : }
1044 0 : else if( pTok->Is( SvHash_union() ) )
1045 : {
1046 0 : SetType( TYPE_UNION );
1047 0 : if( ReadNameSvIdl( rBase, rInStm ) )
1048 0 : return sal_True;
1049 : }
1050 0 : else if( pTok->Is( SvHash_enum() ) )
1051 : {
1052 0 : SetType( TYPE_ENUM );
1053 0 : bOk = ReadNameSvIdl( rBase, rInStm );
1054 : }
1055 0 : else if( pTok->Is( SvHash_typedef() )
1056 0 : || pTok->Is( SvHash_item() ) )
1057 : {
1058 0 : if( pTok->Is( SvHash_item() ) )
1059 0 : bIsItem = sal_True;
1060 :
1061 0 : SvMetaType * pType = rBase.ReadKnownType( rInStm );
1062 0 : if( pType )
1063 : {
1064 0 : SetRef( pType );
1065 0 : if( ReadNameSvIdl( rBase, rInStm ) )
1066 : {
1067 0 : if( rInStm.Read( '(' ) )
1068 : {
1069 0 : DoReadContextSvIdl( rBase, rInStm );
1070 0 : if( rInStm.Read( ')' ) )
1071 : {
1072 0 : SetType( TYPE_METHOD );
1073 0 : bOk = sal_True;
1074 : }
1075 : }
1076 : else
1077 : {
1078 0 : bOk = sal_True;
1079 : }
1080 : }
1081 : }
1082 : else
1083 : {
1084 0 : rtl::OString aStr("wrong typedef: ");
1085 0 : rBase.SetError( aStr, rInStm.GetToken() );
1086 0 : rBase.WriteError( rInStm );
1087 : }
1088 : }
1089 0 : if( bOk )
1090 0 : SetModule( rBase );
1091 : else
1092 0 : rInStm.Seek( nTokPos );
1093 0 : return bOk;
1094 : }
1095 :
1096 0 : sal_Bool SvMetaType::ReadSvIdl( SvIdlDataBase & rBase,
1097 : SvTokenStream & rInStm )
1098 : {
1099 0 : if( ReadHeaderSvIdl( rBase, rInStm ) )
1100 : {
1101 0 : rBase.Write(rtl::OString('.'));
1102 0 : return SvMetaExtern::ReadSvIdl( rBase, rInStm );
1103 : }
1104 0 : return sal_False;
1105 : }
1106 :
1107 0 : void SvMetaType::WriteSvIdl
1108 : (
1109 : SvIdlDataBase & rBase,
1110 : SvStream & rOutStm,
1111 : sal_uInt16 nTab
1112 : )
1113 : {
1114 0 : WriteHeaderSvIdl( rBase, rOutStm, nTab );
1115 0 : if( GetType() == TYPE_METHOD )
1116 0 : WriteMethodArgs( rBase, rOutStm, nTab, WRITE_IDL );
1117 :
1118 0 : sal_uLong nOldPos = rOutStm.Tell();
1119 0 : rOutStm << endl;
1120 0 : SvMetaExtern::WriteSvIdl( rBase, rOutStm, nTab );
1121 0 : if( TestAndSeekSpaceOnly( rOutStm, nOldPos ) )
1122 : // nothin written
1123 0 : rOutStm.Seek( nOldPos );
1124 0 : rOutStm << ';' << endl;
1125 0 : }
1126 :
1127 0 : void SvMetaType::WriteContext( SvIdlDataBase & rBase, SvStream & rOutStm,
1128 : sal_uInt16 nTab,
1129 : WriteType nT, WriteAttribute nA )
1130 : {
1131 0 : if( GetAttrCount() )
1132 : {
1133 0 : SvMetaAttributeMemberList::const_iterator it = pAttrList->begin();
1134 0 : while( it != pAttrList->end() )
1135 : {
1136 0 : SvMetaAttribute * pAttr = *it;
1137 0 : pAttr->Write( rBase, rOutStm, nTab, nT, nA );
1138 0 : if( GetType() == TYPE_METHOD )
1139 0 : rOutStm << ',' << endl;
1140 : else
1141 0 : rOutStm << ';' << endl;
1142 0 : ++it;
1143 : }
1144 : }
1145 0 : }
1146 :
1147 0 : void SvMetaType::Write( SvIdlDataBase & rBase, SvStream & rOutStm,
1148 : sal_uInt16 nTab,
1149 : WriteType nT, WriteAttribute nA )
1150 : {
1151 0 : if( nT == WRITE_C_HEADER && nType != TYPE_ENUM )
1152 : // write only enum
1153 0 : return;
1154 :
1155 0 : rtl::OString name = GetName().getString();
1156 0 : if( nT == WRITE_ODL || nT == WRITE_C_HEADER || nT == WRITE_CXX_HEADER )
1157 : {
1158 0 : switch( nType )
1159 : {
1160 : case TYPE_CLASS:
1161 : {
1162 : }
1163 0 : break;
1164 : case TYPE_STRUCT:
1165 : case TYPE_UNION:
1166 : case TYPE_ENUM:
1167 : {
1168 0 : WriteStars( rOutStm );
1169 0 : if( nType == TYPE_STRUCT || nType == TYPE_UNION )
1170 0 : nA = WA_STRUCT;
1171 :
1172 0 : if( nT == WRITE_ODL || nT == WRITE_C_HEADER)
1173 : {
1174 0 : if ( nT == WRITE_C_HEADER )
1175 : {
1176 0 : rtl::OString aStr = name.toAsciiUpperCase();
1177 0 : rOutStm << "#ifndef " << C_PREF << aStr.getStr() << "_DEF " << endl;
1178 0 : rOutStm << "#define " << C_PREF << aStr.getStr() << "_DEF " << endl;
1179 : }
1180 :
1181 0 : WriteTab( rOutStm, nTab );
1182 0 : rOutStm << "typedef" << endl;
1183 0 : if ( nT == WRITE_ODL )
1184 0 : SvMetaName::Write( rBase, rOutStm, nTab, nT, nA );
1185 : }
1186 0 : WriteTab( rOutStm, nTab );
1187 0 : if( nType == TYPE_STRUCT )
1188 0 : rOutStm << "struct";
1189 0 : else if( nType == TYPE_UNION )
1190 0 : rOutStm << "union";
1191 : else
1192 0 : rOutStm << "enum";
1193 0 : if( nT != WRITE_ODL && nT != WRITE_C_HEADER)
1194 0 : rOutStm << ' ' << name.getStr();
1195 :
1196 0 : rOutStm << endl;
1197 0 : WriteTab( rOutStm, nTab );
1198 0 : rOutStm << '{' << endl;
1199 0 : WriteContext( rBase, rOutStm, nTab +1, nT, nA );
1200 0 : WriteTab( rOutStm, nTab );
1201 0 : rOutStm << '}';
1202 0 : if( nT == WRITE_ODL || nT == WRITE_C_HEADER )
1203 : {
1204 0 : rOutStm << ' ' << C_PREF << name.getStr();
1205 : }
1206 0 : rOutStm << ';' << endl;
1207 :
1208 0 : if ( nT == WRITE_C_HEADER )
1209 0 : rOutStm << "#endif";
1210 0 : rOutStm << endl;
1211 : }
1212 0 : break;
1213 : case TYPE_POINTER:
1214 : case TYPE_BASE:
1215 : {
1216 : }
1217 0 : break;
1218 : case TYPE_METHOD:
1219 : {
1220 : }
1221 0 : break;
1222 : }
1223 0 : }
1224 : }
1225 :
1226 0 : sal_Bool SvMetaType::ReadNamesSvIdl( SvIdlDataBase & rBase,
1227 : SvTokenStream & rInStm )
1228 : {
1229 0 : sal_Bool bOk = ReadNameSvIdl( rBase, rInStm );
1230 :
1231 0 : return bOk;
1232 : }
1233 :
1234 0 : void SvMetaType::WriteHeaderSvIdl( SvIdlDataBase & rBase,
1235 : SvStream & rOutStm,
1236 : sal_uInt16 nTab )
1237 : {
1238 0 : switch( nType )
1239 : {
1240 : case TYPE_CLASS:
1241 : {
1242 0 : if( IsShell() )
1243 0 : rOutStm << SvHash_shell()->GetName().getStr();
1244 : else
1245 0 : rOutStm << SvHash_interface()->GetName().getStr();
1246 0 : rOutStm << ' ' << GetName().getString().getStr();
1247 : }
1248 0 : break;
1249 : case TYPE_STRUCT:
1250 : {
1251 0 : rOutStm << SvHash_struct()->GetName().getStr()
1252 0 : << ' ' << GetName().getString().getStr();
1253 : }
1254 0 : break;
1255 : case TYPE_UNION:
1256 : {
1257 0 : rOutStm << SvHash_union()->GetName().getStr()
1258 0 : << ' ' << GetName().getString().getStr();
1259 : }
1260 0 : break;
1261 : case TYPE_ENUM:
1262 : {
1263 0 : rOutStm << SvHash_enum()->GetName().getStr()
1264 0 : << ' ' << GetName().getString().getStr();
1265 : }
1266 0 : break;
1267 : case TYPE_POINTER:
1268 : case TYPE_BASE:
1269 : {
1270 0 : if( IsItem() )
1271 0 : rOutStm << SvHash_item()->GetName().getStr() << ' ';
1272 : else
1273 0 : rOutStm << SvHash_typedef()->GetName().getStr() << ' ';
1274 0 : if( GetRef() )
1275 : {
1276 0 : ((SvMetaType *)GetRef())->WriteTheType( rBase, rOutStm, nTab, WRITE_IDL );
1277 0 : rOutStm << ' ';
1278 : }
1279 0 : rOutStm << GetName().getString().getStr();
1280 : }
1281 0 : break;
1282 : case TYPE_METHOD:
1283 : {
1284 0 : rOutStm << SvHash_typedef()->GetName().getStr() << ' ';
1285 0 : ((SvMetaType *)GetRef())->WriteTheType( rBase, rOutStm, nTab, WRITE_IDL );
1286 0 : rOutStm << ' ' << GetName().getString().getStr() << "( ";
1287 0 : WriteContextSvIdl( rBase, rOutStm, nTab );
1288 0 : rOutStm << " )";
1289 : }
1290 0 : break;
1291 : }
1292 0 : }
1293 :
1294 0 : void SvMetaType::ReadAttributesSvIdl( SvIdlDataBase & rBase,
1295 : SvTokenStream & rInStm )
1296 : {
1297 0 : SvMetaExtern::ReadAttributesSvIdl( rBase, rInStm );
1298 0 : aSvName.ReadSvIdl( SvHash_SvName(), rInStm );
1299 0 : aSbxName.ReadSvIdl( SvHash_SbxName(), rInStm );
1300 0 : aOdlName.ReadSvIdl( SvHash_OdlName(), rInStm );
1301 0 : }
1302 :
1303 0 : void SvMetaType::WriteAttributesSvIdl( SvIdlDataBase & rBase,
1304 : SvStream & rOutStm,
1305 : sal_uInt16 nTab )
1306 : {
1307 0 : SvMetaExtern::WriteAttributesSvIdl( rBase, rOutStm, nTab );
1308 0 : rtl::OString name = GetName().getString();
1309 0 : if( aSvName.getString() != name || aSbxName.getString() != name || aOdlName.getString() != name )
1310 : {
1311 0 : WriteTab( rOutStm, nTab );
1312 0 : rOutStm << "class SvMetaType" << endl;
1313 0 : if( aSvName.getString() != name )
1314 : {
1315 0 : WriteTab( rOutStm, nTab );
1316 0 : aSvName.WriteSvIdl( SvHash_SvName(), rOutStm, nTab );
1317 0 : rOutStm << endl;
1318 : }
1319 0 : if( aSbxName.getString() != name )
1320 : {
1321 0 : WriteTab( rOutStm, nTab );
1322 0 : aSbxName.WriteSvIdl( SvHash_SbxName(), rOutStm, nTab );
1323 0 : rOutStm << endl;
1324 : }
1325 0 : if( aOdlName.getString() != name )
1326 : {
1327 0 : WriteTab( rOutStm, nTab );
1328 0 : aOdlName.WriteSvIdl( SvHash_OdlName(), rOutStm, nTab );
1329 0 : rOutStm << endl;
1330 : }
1331 0 : }
1332 0 : }
1333 :
1334 0 : void SvMetaType::ReadContextSvIdl( SvIdlDataBase & rBase,
1335 : SvTokenStream & rInStm )
1336 : {
1337 0 : SvMetaAttributeRef xAttr = new SvMetaAttribute();
1338 0 : if( xAttr->ReadSvIdl( rBase, rInStm ) )
1339 : {
1340 0 : if( xAttr->Test( rBase, rInStm ) )
1341 0 : GetAttrList().push_back( xAttr );
1342 0 : }
1343 0 : }
1344 :
1345 0 : void SvMetaType::WriteContextSvIdl
1346 : (
1347 : SvIdlDataBase & rBase,
1348 : SvStream & rOutStm,
1349 : sal_uInt16 nTab
1350 : )
1351 : {
1352 0 : if( GetAttrCount() )
1353 : {
1354 0 : SvMetaAttributeMemberList::const_iterator it = pAttrList->begin();
1355 0 : while( it != pAttrList->end() )
1356 : {
1357 0 : SvMetaAttribute * pAttr = *it;
1358 0 : WriteTab( rOutStm, nTab );
1359 0 : pAttr->WriteSvIdl( rBase, rOutStm, nTab );
1360 0 : if( GetType() == TYPE_METHOD )
1361 0 : rOutStm << ',' << endl;
1362 : else
1363 0 : rOutStm << ';' << endl;
1364 0 : ++it;
1365 : }
1366 : }
1367 0 : }
1368 :
1369 0 : void SvMetaType::WriteAttributes( SvIdlDataBase & rBase, SvStream & rOutStm,
1370 : sal_uInt16 nTab,
1371 : WriteType nT, WriteAttribute nA )
1372 : {
1373 0 : SvMetaExtern::WriteAttributes( rBase, rOutStm, nTab, nT, nA );
1374 0 : }
1375 :
1376 0 : sal_uLong SvMetaType::MakeSfx( rtl::OStringBuffer& rAttrArray )
1377 : {
1378 0 : sal_uLong nC = 0;
1379 :
1380 0 : if( GetBaseType()->GetType() == TYPE_STRUCT )
1381 : {
1382 0 : sal_uLong nAttrCount = GetAttrCount();
1383 : // write the single attributes
1384 0 : for( sal_uLong n = 0; n < nAttrCount; n++ )
1385 : {
1386 0 : nC += (*pAttrList)[n]->MakeSfx( rAttrArray );
1387 0 : if( n +1 < nAttrCount )
1388 0 : rAttrArray.append(", ");
1389 : }
1390 : }
1391 0 : return nC;
1392 : }
1393 :
1394 0 : void SvMetaType::WriteSfxItem(
1395 : const rtl::OString& rItemName, SvIdlDataBase &, SvStream & rOutStm )
1396 : {
1397 0 : WriteStars( rOutStm );
1398 0 : rtl::OStringBuffer aVarName(RTL_CONSTASCII_STRINGPARAM(" a"));
1399 0 : aVarName.append(rItemName).append(RTL_CONSTASCII_STRINGPARAM("_Impl"));
1400 :
1401 0 : rtl::OStringBuffer aTypeName(RTL_CONSTASCII_STRINGPARAM("SfxType"));
1402 0 : rtl::OStringBuffer aAttrArray;
1403 0 : sal_uLong nAttrCount = MakeSfx( aAttrArray );
1404 : rtl::OString aAttrCount(
1405 0 : rtl::OString::valueOf(static_cast<sal_Int32>(nAttrCount)));
1406 0 : aTypeName.append(aAttrCount);
1407 :
1408 0 : rOutStm << "extern " << aTypeName.getStr()
1409 0 : << aVarName.getStr() << ';' << endl;
1410 :
1411 : // write the implementation part
1412 0 : rOutStm << "#ifdef SFX_TYPEMAP" << endl
1413 0 : << "#if defined(DISABLE_DYNLOADING) && (defined(ANDROID) || defined(IOS))" << endl
1414 0 : << "__attribute__((__weak__))" << endl
1415 0 : << "#endif" << endl
1416 0 : << aTypeName.getStr() << aVarName.getStr()
1417 0 : << " = " << endl;
1418 0 : rOutStm << '{' << endl
1419 0 : << "\tTYPE(" << rItemName.getStr() << "), "
1420 0 : << aAttrCount.getStr();
1421 0 : if( nAttrCount )
1422 : {
1423 0 : rOutStm << ", { ";
1424 : // write the single attributes
1425 0 : rOutStm << aAttrArray.getStr();
1426 0 : rOutStm << " }";
1427 : }
1428 0 : rOutStm << endl << "};" << endl
1429 0 : << "#endif" << endl << endl;
1430 0 : }
1431 :
1432 0 : void SvMetaType::WriteSfx( SvIdlDataBase & rBase, SvStream & rOutStm )
1433 : {
1434 0 : if( IsItem() )
1435 : {
1436 0 : if( GetBaseType()->GetType() == TYPE_STRUCT )
1437 0 : GetBaseType()->WriteSfxItem( GetName().getString(), rBase, rOutStm );
1438 : else
1439 0 : WriteSfxItem( GetName().getString(), rBase, rOutStm );
1440 : }
1441 0 : }
1442 :
1443 0 : sal_Bool SvMetaType::ReadMethodArgs( SvIdlDataBase & rBase,
1444 : SvTokenStream & rInStm )
1445 : {
1446 0 : sal_uInt32 nTokPos = rInStm.Tell();
1447 0 : if( rInStm.Read( '(' ) )
1448 : {
1449 0 : DoReadContextSvIdl( rBase, rInStm );
1450 0 : if( rInStm.Read( ')' ) )
1451 : {
1452 0 : SetType( TYPE_METHOD );
1453 0 : return sal_True;
1454 : }
1455 : }
1456 0 : rInStm.Seek( nTokPos );
1457 0 : return sal_False;
1458 : }
1459 :
1460 0 : void SvMetaType::WriteMethodArgs
1461 : (
1462 : SvIdlDataBase & rBase,
1463 : SvStream & rOutStm,
1464 : sal_uInt16 nTab, WriteType nT
1465 : )
1466 : {
1467 0 : if( nT == WRITE_IDL )
1468 : {
1469 0 : if( GetAttrCount() )
1470 : {
1471 0 : rOutStm << endl;
1472 0 : WriteTab( rOutStm, nTab );
1473 0 : rOutStm << '(' << endl;
1474 :
1475 0 : SvMetaAttributeMemberList::const_iterator it = pAttrList->begin();
1476 0 : while( it != pAttrList->end() )
1477 : {
1478 0 : SvMetaAttribute * pAttr = *it;
1479 0 : WriteTab( rOutStm, nTab +1 );
1480 0 : pAttr->WriteSvIdl( rBase, rOutStm, nTab +1 );
1481 0 : ++it;
1482 0 : if( it != pAttrList->end() )
1483 0 : rOutStm << ',' << endl;
1484 : }
1485 0 : rOutStm << endl;
1486 0 : WriteTab( rOutStm, nTab );
1487 0 : rOutStm << ')';
1488 : }
1489 : else
1490 0 : rOutStm << "()";
1491 : }
1492 0 : else if ( nT == WRITE_DOCU )
1493 : {
1494 :
1495 0 : rOutStm << '(';
1496 0 : if( GetAttrCount() )
1497 : {
1498 0 : SvMetaAttributeMemberList::const_iterator it = pAttrList->begin();
1499 0 : while( it != pAttrList->end() )
1500 : {
1501 0 : SvMetaAttribute * pAttr = *it;
1502 0 : pAttr->WriteParam( rBase, rOutStm, nTab+1, nT );
1503 0 : ++it;
1504 0 : if( it != pAttrList->end() )
1505 0 : rOutStm << ',';
1506 : else
1507 0 : rOutStm << ' ';
1508 : }
1509 : }
1510 0 : rOutStm << ')' << endl;
1511 : }
1512 : else
1513 : {
1514 0 : rOutStm << '(';
1515 0 : if( nT == WRITE_C_HEADER || nT == WRITE_C_SOURCE )
1516 : {
1517 0 : rOutStm << ' ' << C_PREF << "Object h" << rBase.aIFaceName.getStr();
1518 0 : if( GetAttrCount() )
1519 0 : rOutStm << ',';
1520 : else
1521 0 : rOutStm << ' ';
1522 : }
1523 :
1524 0 : if( GetAttrCount() )
1525 : {
1526 0 : rOutStm << endl;
1527 0 : SvMetaAttributeMemberList::const_iterator it = pAttrList->begin();
1528 0 : while( it != pAttrList->end() )
1529 : {
1530 0 : SvMetaAttribute* pAttr = *it;
1531 0 : switch( nT )
1532 : {
1533 : case WRITE_C_HEADER:
1534 : case WRITE_C_SOURCE:
1535 : case WRITE_ODL:
1536 : {
1537 0 : pAttr->WriteParam( rBase, rOutStm, nTab +1, nT );
1538 : }
1539 0 : break;
1540 :
1541 : default:
1542 : {
1543 : DBG_ASSERT( sal_False, "WriteType not implemented" );
1544 : }
1545 : }
1546 0 : ++it;
1547 0 : if( it != pAttrList->end() )
1548 0 : rOutStm << ',' << endl;
1549 : }
1550 0 : if( nT != WRITE_C_HEADER && nT != WRITE_C_SOURCE )
1551 : {
1552 0 : rOutStm << endl;
1553 0 : WriteTab( rOutStm, nTab +1 );
1554 : }
1555 0 : rOutStm << ' ';
1556 : }
1557 0 : rOutStm << ')';
1558 : }
1559 0 : }
1560 :
1561 0 : void SvMetaType::WriteTypePrefix( SvIdlDataBase & rBase, SvStream & rOutStm,
1562 : sal_uInt16 nTab, WriteType nT )
1563 : {
1564 0 : switch( nT )
1565 : {
1566 : case WRITE_IDL:
1567 : {
1568 0 : if( GetIn() && GetOut() )
1569 0 : rOutStm << SvHash_inout()->GetName().getStr() << ' ';
1570 0 : else if( GetIn() )
1571 0 : rOutStm << SvHash_in()->GetName().getStr() << ' ';
1572 0 : else if( GetOut() )
1573 0 : rOutStm << SvHash_out()->GetName().getStr() << ' ';
1574 0 : rOutStm << GetCString().getStr();
1575 : }
1576 0 : break;
1577 :
1578 : case WRITE_ODL:
1579 : {
1580 0 : sal_Bool bIn = GetIn();
1581 0 : sal_Bool bOut = GetOut();
1582 0 : if( bIn || bOut )
1583 : {
1584 0 : if( bIn && bOut )
1585 0 : rOutStm << "[in,out] ";
1586 0 : else if( bIn )
1587 0 : rOutStm << "[in] ";
1588 0 : else if( bOut )
1589 0 : rOutStm << "[out] ";
1590 : }
1591 :
1592 0 : rtl::OString out;
1593 0 : if( GetType() == TYPE_METHOD )
1594 0 : out = GetReturnType()->GetBaseType()->GetOdlName();
1595 : else
1596 : {
1597 0 : SvMetaType * pBType = GetBaseType();
1598 0 : out = pBType->GetOdlName();
1599 : }
1600 0 : if( aCall0 == (int)CALL_POINTER
1601 0 : || aCall0 == (int)CALL_REFERENCE )
1602 0 : rOutStm << " *";
1603 0 : if( aCall1 == (int)CALL_POINTER
1604 0 : || aCall1 == (int)CALL_REFERENCE )
1605 0 : rOutStm << " *";
1606 0 : rOutStm << out.getStr();
1607 : }
1608 0 : break;
1609 :
1610 : case WRITE_C_HEADER:
1611 : case WRITE_C_SOURCE:
1612 : case WRITE_CXX_HEADER:
1613 : case WRITE_CXX_SOURCE:
1614 : {
1615 :
1616 0 : SvMetaType * pBaseType = GetBaseType();
1617 : DBG_ASSERT( pBaseType, "no base type for attribute" );
1618 :
1619 0 : if( pBaseType->GetType() == TYPE_METHOD )
1620 : pBaseType->GetReturnType()->WriteTypePrefix(
1621 0 : rBase, rOutStm, nTab, nT );
1622 0 : else if( nT == WRITE_C_HEADER || nT == WRITE_C_SOURCE )
1623 : {
1624 0 : if( TYPE_STRUCT == pBaseType->GetType() )
1625 0 : rOutStm << C_PREF << pBaseType->GetName().getString().getStr()
1626 0 : << " *";
1627 : else
1628 : {
1629 0 : if ( pBaseType->GetType() == TYPE_ENUM )
1630 0 : rOutStm << C_PREF;
1631 0 : rOutStm << pBaseType->GetCName().getStr();
1632 : }
1633 : }
1634 : else
1635 : {
1636 0 : if( TYPE_STRUCT == pBaseType->GetType() )
1637 0 : rOutStm << pBaseType->GetName().getString().getStr() << " *";
1638 : else
1639 0 : rOutStm << pBaseType->GetName().getString().getStr();
1640 : }
1641 : }
1642 0 : break;
1643 :
1644 : case WRITE_DOCU:
1645 : {
1646 :
1647 0 : SvMetaType * pBaseType = GetBaseType();
1648 : DBG_ASSERT( pBaseType, "no base type for attribute" );
1649 :
1650 0 : if( pBaseType->GetType() == TYPE_METHOD )
1651 : {
1652 : pBaseType->GetReturnType()->WriteTypePrefix(
1653 0 : rBase, rOutStm, nTab, nT );
1654 : }
1655 : else
1656 : {
1657 0 : if( TYPE_STRUCT == pBaseType->GetType() )
1658 0 : rOutStm << "VARIANT" << pBaseType->GetName().getString().getStr();
1659 0 : else if ( pBaseType->GetType() == TYPE_ENUM )
1660 0 : rOutStm << "integer";
1661 : else
1662 0 : rOutStm << pBaseType->GetOdlName().getStr();
1663 : }
1664 : }
1665 :
1666 : default:
1667 : {
1668 : DBG_ASSERT( sal_False, "WriteType not implemented" );
1669 : }
1670 : }
1671 0 : }
1672 :
1673 0 : void SvMetaType::WriteTheType( SvIdlDataBase & rBase, SvStream & rOutStm,
1674 : sal_uInt16 nTab, WriteType nT )
1675 : {
1676 0 : WriteTypePrefix( rBase, rOutStm, nTab, nT );
1677 0 : if( GetType() == TYPE_METHOD )
1678 0 : WriteMethodArgs( rBase, rOutStm, nTab +2, nT );
1679 0 : }
1680 :
1681 0 : rtl::OString SvMetaType::GetParserString() const
1682 : {
1683 0 : SvMetaType * pBT = GetBaseType();
1684 0 : if( pBT != this )
1685 0 : return pBT->GetParserString();
1686 :
1687 0 : int type = GetType();
1688 0 : rtl::OString aPStr;
1689 :
1690 0 : if( TYPE_METHOD == type || TYPE_STRUCT == type )
1691 : {
1692 0 : sal_uLong nAttrCount = GetAttrCount();
1693 : // write the single attributes
1694 0 : for( sal_uLong n = 0; n < nAttrCount; n++ )
1695 : {
1696 0 : SvMetaAttribute * pT = (*pAttrList)[n];
1697 0 : aPStr += pT->GetType()->GetParserString();
1698 0 : }
1699 : }
1700 : else
1701 0 : aPStr = rtl::OString(GetParserChar());
1702 0 : return aPStr;
1703 : }
1704 :
1705 0 : void SvMetaType::WriteParamNames( SvIdlDataBase & rBase,
1706 : SvStream & rOutStm,
1707 : const rtl::OString& rChief )
1708 : {
1709 0 : SvMetaType * pBT = GetBaseType();
1710 0 : if( pBT != this )
1711 0 : pBT->WriteParamNames( rBase, rOutStm, rChief );
1712 : else
1713 : {
1714 0 : int type = GetType();
1715 :
1716 0 : if( TYPE_METHOD == type || TYPE_STRUCT == type )
1717 : {
1718 0 : sal_uLong nAttrCount = GetAttrCount();
1719 : // write the single attributes
1720 0 : for( sal_uLong n = 0; n < nAttrCount; n++ )
1721 : {
1722 0 : SvMetaAttribute * pA = (*pAttrList)[n];
1723 0 : rtl::OString aStr = pA->GetName().getString();
1724 0 : pA->GetType()->WriteParamNames( rBase, rOutStm, aStr );
1725 0 : if( n +1 < nAttrCount )
1726 0 : rOutStm << ", ";
1727 0 : }
1728 : }
1729 : else
1730 0 : rOutStm << rChief.getStr();
1731 : }
1732 0 : }
1733 :
1734 0 : SV_IMPL_META_FACTORY1( SvMetaTypeString, SvMetaType );
1735 0 : SvMetaTypeString::SvMetaTypeString()
1736 0 : : SvMetaType( "String", "SbxSTRING", "BSTR", 's', "char *", "String", "$" )
1737 : {
1738 0 : }
1739 :
1740 0 : void SvMetaTypeString::Load( SvPersistStream & rStm )
1741 : {
1742 0 : SvMetaType::Load( rStm );
1743 0 : }
1744 :
1745 0 : void SvMetaTypeString::Save( SvPersistStream & rStm )
1746 : {
1747 0 : SvMetaType::Save( rStm );
1748 0 : }
1749 :
1750 0 : SV_IMPL_META_FACTORY1( SvMetaEnumValue, SvMetaName );
1751 0 : SvMetaEnumValue::SvMetaEnumValue()
1752 : {
1753 0 : }
1754 :
1755 0 : void SvMetaEnumValue::Load( SvPersistStream & rStm )
1756 : {
1757 0 : SvMetaName::Load( rStm );
1758 :
1759 : sal_uInt8 nMask;
1760 0 : rStm >> nMask;
1761 0 : if( nMask >= 0x02 )
1762 : {
1763 0 : rStm.SetError( SVSTREAM_FILEFORMAT_ERROR );
1764 : OSL_FAIL( "wrong format" );
1765 0 : return;
1766 : }
1767 0 : if( nMask & 0x01 ) aEnumValue = read_lenPrefixed_uInt8s_ToOString<sal_uInt16>(rStm);
1768 : }
1769 :
1770 0 : void SvMetaEnumValue::Save( SvPersistStream & rStm )
1771 : {
1772 0 : SvMetaName::Save( rStm );
1773 :
1774 : // create mask
1775 0 : sal_uInt8 nMask = 0;
1776 0 : if( !aEnumValue.isEmpty() ) nMask |= 0x01;
1777 :
1778 : // write data
1779 0 : rStm << nMask;
1780 0 : if( nMask & 0x01 ) write_lenPrefixed_uInt8s_FromOString<sal_uInt16>(rStm, aEnumValue);
1781 0 : }
1782 :
1783 0 : sal_Bool SvMetaEnumValue::ReadSvIdl( SvIdlDataBase & rBase,
1784 : SvTokenStream & rInStm )
1785 : {
1786 0 : if( !ReadNameSvIdl( rBase, rInStm ) )
1787 0 : return sal_False;
1788 0 : return sal_True;
1789 : }
1790 :
1791 0 : void SvMetaEnumValue::WriteSvIdl( SvIdlDataBase &, SvStream & rOutStm, sal_uInt16 )
1792 : {
1793 0 : rOutStm << GetName().getString().getStr();
1794 0 : }
1795 :
1796 0 : void SvMetaEnumValue::Write( SvIdlDataBase &, SvStream & rOutStm, sal_uInt16,
1797 : WriteType nT, WriteAttribute )
1798 : {
1799 0 : if ( nT == WRITE_C_HEADER || nT == WRITE_C_SOURCE )
1800 0 : rOutStm << C_PREF << GetName().getString().getStr();
1801 : else
1802 0 : rOutStm << GetName().getString().getStr();
1803 0 : }
1804 :
1805 0 : SV_IMPL_META_FACTORY1( SvMetaTypeEnum, SvMetaType );
1806 0 : SvMetaTypeEnum::SvMetaTypeEnum()
1807 : {
1808 0 : SetBasicName("Integer");
1809 0 : }
1810 :
1811 0 : void SvMetaTypeEnum::Load( SvPersistStream & rStm )
1812 : {
1813 0 : SvMetaType::Load( rStm );
1814 :
1815 : sal_uInt8 nMask;
1816 0 : rStm >> nMask;
1817 0 : if( nMask >= 0x04 )
1818 : {
1819 0 : rStm.SetError( SVSTREAM_FILEFORMAT_ERROR );
1820 : OSL_FAIL( "wrong format" );
1821 0 : return;
1822 : }
1823 0 : if( nMask & 0x01 ) rStm >> aEnumValueList;
1824 0 : if( nMask & 0x02 ) aPrefix = read_lenPrefixed_uInt8s_ToOString<sal_uInt16>(rStm);
1825 : }
1826 :
1827 0 : void SvMetaTypeEnum::Save( SvPersistStream & rStm )
1828 : {
1829 0 : SvMetaType::Save( rStm );
1830 :
1831 : // create mask
1832 0 : sal_uInt8 nMask = 0;
1833 0 : if( !aEnumValueList.empty() ) nMask |= 0x01;
1834 0 : if( !aPrefix.isEmpty() ) nMask |= 0x02;
1835 :
1836 : // write data
1837 0 : rStm << nMask;
1838 0 : if( nMask & 0x01 ) rStm << aEnumValueList;
1839 0 : if( nMask & 0x02 ) write_lenPrefixed_uInt8s_FromOString<sal_uInt16>(rStm, aPrefix);
1840 0 : }
1841 :
1842 : namespace
1843 : {
1844 0 : rtl::OString getCommonSubPrefix(const rtl::OString &rA, const rtl::OString &rB)
1845 : {
1846 0 : sal_Int32 nMax = std::min(rA.getLength(), rB.getLength());
1847 0 : sal_Int32 nI = 0;
1848 0 : while (nI < nMax)
1849 : {
1850 0 : if (rA[nI] != rB[nI])
1851 0 : break;
1852 0 : ++nI;
1853 : }
1854 0 : return rA.copy(0, nI);
1855 : }
1856 : }
1857 :
1858 0 : void SvMetaTypeEnum::ReadContextSvIdl( SvIdlDataBase & rBase,
1859 : SvTokenStream & rInStm )
1860 : {
1861 0 : sal_uInt32 nTokPos = rInStm.Tell();
1862 :
1863 0 : SvMetaEnumValueRef aEnumVal = new SvMetaEnumValue();
1864 0 : sal_Bool bOk = aEnumVal->ReadSvIdl( rBase, rInStm );
1865 0 : if( bOk )
1866 : {
1867 0 : if( aEnumValueList.empty() )
1868 : {
1869 : // the first
1870 0 : aPrefix = aEnumVal->GetName().getString();
1871 : }
1872 : else
1873 : {
1874 0 : aPrefix = getCommonSubPrefix(aPrefix, aEnumVal->GetName().getString());
1875 : }
1876 0 : aEnumValueList.push_back( aEnumVal );
1877 : }
1878 0 : if( !bOk )
1879 0 : rInStm.Seek( nTokPos );
1880 0 : }
1881 :
1882 0 : void SvMetaTypeEnum::WriteContextSvIdl( SvIdlDataBase & rBase,
1883 : SvStream & rOutStm,
1884 : sal_uInt16 nTab )
1885 : {
1886 0 : WriteTab( rOutStm, nTab +1 );
1887 0 : for( sal_uLong n = 0; n < aEnumValueList.size(); n++ )
1888 : {
1889 0 : aEnumValueList[n]->WriteSvIdl( rBase, rOutStm, nTab );
1890 0 : if( n + 1 != aEnumValueList.size() )
1891 0 : rOutStm << ", ";
1892 : else
1893 0 : rOutStm << endl;
1894 : }
1895 0 : }
1896 :
1897 0 : sal_Bool SvMetaTypeEnum::ReadSvIdl( SvIdlDataBase & rBase,
1898 : SvTokenStream & rInStm )
1899 : {
1900 0 : sal_uInt32 nTokPos = rInStm.Tell();
1901 0 : if( SvMetaType::ReadHeaderSvIdl( rBase, rInStm )
1902 0 : && GetType() == TYPE_ENUM )
1903 : {
1904 0 : if( SvMetaName::ReadSvIdl( rBase, rInStm ) )
1905 0 : return sal_True;
1906 : }
1907 0 : rInStm.Seek( nTokPos );
1908 0 : return sal_False;
1909 : }
1910 :
1911 0 : void SvMetaTypeEnum::WriteSvIdl( SvIdlDataBase & rBase, SvStream & rOutStm,
1912 : sal_uInt16 nTab )
1913 : {
1914 0 : WriteHeaderSvIdl( rBase, rOutStm, nTab );
1915 0 : rOutStm << endl;
1916 0 : SvMetaName::WriteSvIdl( rBase, rOutStm, nTab );
1917 0 : rOutStm << endl;
1918 0 : }
1919 :
1920 0 : void SvMetaTypeEnum::Write( SvIdlDataBase & rBase, SvStream & rOutStm,
1921 : sal_uInt16 nTab,
1922 : WriteType nT, WriteAttribute nA )
1923 : {
1924 0 : SvMetaType::Write( rBase, rOutStm, nTab, nT, nA );
1925 0 : }
1926 :
1927 0 : void SvMetaTypeEnum::WriteContext( SvIdlDataBase & rBase, SvStream & rOutStm,
1928 : sal_uInt16 nTab,
1929 : WriteType nT, WriteAttribute nA )
1930 : {
1931 0 : WriteTab( rOutStm, nTab +1 );
1932 0 : for( sal_uLong n = 0; n < aEnumValueList.size(); n++ )
1933 : {
1934 0 : aEnumValueList[n]->Write( rBase, rOutStm, nTab +1, nT, nA );
1935 :
1936 0 : if( n + 1 != aEnumValueList.size() )
1937 : {
1938 0 : if( 2 == n % 3 )
1939 : {
1940 0 : rOutStm << ',' << endl;
1941 0 : WriteTab( rOutStm, nTab +1 );
1942 : }
1943 : else
1944 0 : rOutStm << ",\t";
1945 : }
1946 : else
1947 0 : rOutStm << endl;
1948 : }
1949 0 : rOutStm << endl;
1950 0 : }
1951 :
1952 0 : SV_IMPL_META_FACTORY1( SvMetaTypevoid, SvMetaType );
1953 0 : SvMetaTypevoid::SvMetaTypevoid()
1954 0 : : SvMetaType( "void", "SbxVOID", "void", 'v', "void", "", "" )
1955 : {
1956 0 : }
1957 :
1958 0 : void SvMetaTypevoid::Load( SvPersistStream & rStm )
1959 : {
1960 0 : SvMetaType::Load( rStm );
1961 0 : }
1962 :
1963 0 : void SvMetaTypevoid::Save( SvPersistStream & rStm )
1964 : {
1965 0 : SvMetaType::Save( rStm );
1966 0 : }
1967 :
1968 0 : rtl::OString SvMetaAttribute::Compare( SvMetaAttribute* pAttr )
1969 : {
1970 0 : rtl::OStringBuffer aStr;
1971 :
1972 0 : if ( aType.Is() )
1973 : {
1974 0 : if ( aType->GetType() == TYPE_METHOD )
1975 : {
1976 : // Test only when the attribute is a method not if it has one!
1977 0 : if ( !pAttr->GetType()->GetType() == TYPE_METHOD )
1978 0 : aStr.append(" IsMethod\n");
1979 0 : else if ( aType->GetReturnType() &&
1980 0 : aType->GetReturnType()->GetType() != pAttr->GetType()->GetReturnType()->GetType() )
1981 : {
1982 0 : aStr.append(" ReturnType\n");
1983 : }
1984 :
1985 0 : if ( aType->GetAttrCount() )
1986 : {
1987 0 : sal_uLong nCount = aType->GetAttrCount();
1988 0 : SvMetaAttributeMemberList& rList = aType->GetAttrList();
1989 0 : SvMetaAttributeMemberList& rOtherList = pAttr->GetType()->GetAttrList();
1990 0 : if ( pAttr->GetType()->GetAttrCount() != nCount )
1991 : {
1992 0 : aStr.append(" AttributeCount\n");
1993 : }
1994 : else
1995 : {
1996 0 : for ( sal_uInt16 n=0; n<nCount; n++ )
1997 : {
1998 0 : SvMetaAttribute *pAttr1 = rList[n];
1999 0 : SvMetaAttribute *pAttr2 = rOtherList[n];
2000 0 : pAttr1->Compare( pAttr2 );
2001 : }
2002 : }
2003 : }
2004 : }
2005 :
2006 0 : if ( GetType()->GetType() != pAttr->GetType()->GetType() )
2007 0 : aStr.append(" Type\n");
2008 :
2009 0 : if ( !GetType()->GetSvName().equals( pAttr->GetType()->GetSvName() ) )
2010 0 : aStr.append(" ItemType\n");
2011 : }
2012 :
2013 0 : if ( GetExport() != pAttr->GetExport() )
2014 0 : aStr.append(" Export\n");
2015 :
2016 0 : if ( GetAutomation() != pAttr->GetAutomation() )
2017 0 : aStr.append(" Automation\n");
2018 :
2019 0 : if ( GetIsCollection() != pAttr->GetIsCollection() )
2020 0 : aStr.append(" IsCollection\n");
2021 :
2022 0 : if ( GetReadOnlyDoc() != pAttr->GetReadOnlyDoc() )
2023 0 : aStr.append(" ReadOnlyDoc\n");
2024 :
2025 0 : if ( GetExport() && GetReadonly() != pAttr->GetReadonly() )
2026 0 : aStr.append(" Readonly\n");
2027 :
2028 0 : return aStr.makeStringAndClear();
2029 : }
2030 :
2031 0 : void SvMetaAttribute::WriteCSV( SvIdlDataBase&, SvStream& rStrm )
2032 : {
2033 0 : rStrm << GetType()->GetSvName().getStr() << ' ';
2034 0 : rStrm << GetName().getString().getStr() << ' ';
2035 0 : rStrm << GetSlotId().getString().getStr();
2036 0 : }
2037 :
2038 :
2039 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|