bump product version to 5.0.4.1
[LibreOffice.git] / idl / source / objects / slot.cxx
blobaffaf4a04b32f2c20205cb8dd79d213ebb974489
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <ctype.h>
22 #include <stdio.h>
23 #include <rtl/strbuf.hxx>
24 #include <osl/diagnose.h>
25 #include <tools/debug.hxx>
26 #include <slot.hxx>
27 #include <globals.hxx>
28 #include <database.hxx>
30 TYPEINIT1( SvMetaSlot, SvMetaAttribute );
32 SvMetaObject *SvMetaSlot::MakeClone() const
34 return new SvMetaSlot( *this );
37 SvMetaSlot::SvMetaSlot()
38 : aCachable( true, false )
39 , aSynchron( true, false )
40 , aRecordPerSet( true, false )
41 , aRecordAbsolute( false, false )
42 , pLinkedSlot(0)
43 , pNextSlot(0)
44 , nListPos(0)
45 , pEnumValue(0)
49 SvMetaSlot::SvMetaSlot( SvMetaType * pType )
50 : SvMetaAttribute( pType )
51 , aCachable( true, false )
52 , aSynchron( true, false )
53 , aRecordPerSet( true, false )
54 , aRecordAbsolute( false, false )
55 , pLinkedSlot(0)
56 , pNextSlot(0)
57 , nListPos(0)
58 , pEnumValue(0)
62 bool SvMetaSlot::IsVariable() const
64 return SvMetaAttribute::IsVariable();
67 bool SvMetaSlot::IsMethod() const
69 bool b = SvMetaAttribute::IsMethod();
70 b |= NULL != GetMethod();
71 return b;
74 OString SvMetaSlot::GetMangleName( bool bVariable ) const
76 if( !bVariable )
78 SvMetaAttribute * pMeth = GetMethod();
79 if( pMeth )
80 return pMeth->GetName().getString();
82 return GetName().getString();
85 /*************************************************************************
86 |* reference
88 |* description Second FALSE in the SvBOOL-Objects means
89 |* IsSet() provides FALSE (default initialization).
90 *************************************************************************/
91 /** reference disbandment **/
92 SvMetaType * SvMetaSlot::GetSlotType() const
94 if( aSlotType.Is() || !GetRef() ) return aSlotType;
95 return static_cast<SvMetaSlot *>(GetRef())->GetSlotType();
97 SvMetaAttribute * SvMetaSlot::GetMethod() const
99 if( aMethod.Is() || !GetRef() ) return aMethod;
100 return static_cast<SvMetaSlot *>(GetRef())->GetMethod();
102 bool SvMetaSlot::GetHasCoreId() const
104 if( aHasCoreId.IsSet() || !GetRef() ) return aHasCoreId;
105 return static_cast<SvMetaSlot *>(GetRef())->GetHasCoreId();
107 const OString& SvMetaSlot::GetGroupId() const
109 if( !aGroupId.getString().isEmpty() || !GetRef() ) return aGroupId.getString();
110 return static_cast<SvMetaSlot *>(GetRef())->GetGroupId();
112 const OString& SvMetaSlot::GetDisableFlags() const
114 if( !aDisableFlags.getString().isEmpty() || !GetRef() ) return aDisableFlags.getString();
115 return static_cast<SvMetaSlot *>(GetRef())->GetDisableFlags();
117 const OString& SvMetaSlot::GetConfigId() const
119 if( !aConfigId.getString().isEmpty() || !GetRef() ) return aConfigId.getString();
120 return static_cast<SvMetaSlot *>(GetRef())->GetConfigId();
122 const OString& SvMetaSlot::GetExecMethod() const
124 if( !aExecMethod.getString().isEmpty() || !GetRef() ) return aExecMethod.getString();
125 return static_cast<SvMetaSlot *>(GetRef())->GetExecMethod();
127 const OString& SvMetaSlot::GetStateMethod() const
129 if( !aStateMethod.getString().isEmpty() || !GetRef() ) return aStateMethod.getString();
130 return static_cast<SvMetaSlot *>(GetRef())->GetStateMethod();
132 const OString& SvMetaSlot::GetDefault() const
134 if( !aDefault.getString().isEmpty() || !GetRef() ) return aDefault.getString();
135 return static_cast<SvMetaSlot *>(GetRef())->GetDefault();
137 bool SvMetaSlot::GetPseudoSlots() const
139 if( aPseudoSlots.IsSet() || !GetRef() ) return aPseudoSlots;
140 return static_cast<SvMetaSlot *>(GetRef())->GetPseudoSlots();
142 bool SvMetaSlot::GetCachable() const
144 // Cachable and Volatile are exclusive
145 if( !GetRef() || aCachable.IsSet() || aVolatile.IsSet() )
146 return aCachable;
147 return static_cast<SvMetaSlot *>(GetRef())->GetCachable();
149 bool SvMetaSlot::GetVolatile() const
151 // Cachable and Volatile are exclusive
152 if( !GetRef() || aVolatile.IsSet() || aCachable.IsSet() )
153 return aVolatile;
154 return static_cast<SvMetaSlot *>(GetRef())->GetVolatile();
156 bool SvMetaSlot::GetToggle() const
158 if( aToggle.IsSet() || !GetRef() ) return aToggle;
159 return static_cast<SvMetaSlot *>(GetRef())->GetToggle();
161 bool SvMetaSlot::GetAutoUpdate() const
163 if( aAutoUpdate.IsSet() || !GetRef() ) return aAutoUpdate;
164 return static_cast<SvMetaSlot *>(GetRef())->GetAutoUpdate();
166 bool SvMetaSlot::GetSynchron() const
168 // Synchron and Asynchron are exclusive
169 if( !GetRef() || aSynchron.IsSet() || aAsynchron.IsSet() )
170 return aSynchron;
171 return static_cast<SvMetaSlot *>(GetRef())->GetSynchron();
173 bool SvMetaSlot::GetAsynchron() const
175 // Synchron and Asynchron are exclusive
176 if( !GetRef() || aAsynchron.IsSet() || aSynchron.IsSet() )
177 return aAsynchron;
178 return static_cast<SvMetaSlot *>(GetRef())->GetAsynchron();
180 bool SvMetaSlot::GetRecordPerItem() const
182 // Record- PerItem, No, PerSet and Manual are exclusive
183 if( !GetRef() || aRecordPerItem.IsSet() || aNoRecord.IsSet()
184 || aRecordPerSet.IsSet() || aRecordManual.IsSet() )
185 return aRecordPerItem;
186 return static_cast<SvMetaSlot *>(GetRef())->GetRecordPerItem();
188 bool SvMetaSlot::GetRecordPerSet() const
190 // Record- PerItem, No, PerSet and Manual are exclusive
191 if( !GetRef() || aRecordPerItem.IsSet() || aNoRecord.IsSet()
192 || aRecordPerSet.IsSet() || aRecordManual.IsSet() )
193 return aRecordPerSet;
194 return static_cast<SvMetaSlot *>(GetRef())->GetRecordPerSet();
196 bool SvMetaSlot::GetRecordManual() const
198 // Record- PerItem, No, PerSet and Manual are exclusive
199 if( !GetRef() || aRecordPerItem.IsSet() || aNoRecord.IsSet()
200 || aRecordPerSet.IsSet() || aRecordManual.IsSet() )
201 return aRecordManual;
202 return static_cast<SvMetaSlot *>(GetRef())->GetRecordManual();
204 bool SvMetaSlot::GetNoRecord() const
206 // Record- PerItem, No, PerSet and Manual are exclusive
207 if( !GetRef() || aRecordPerItem.IsSet() || aNoRecord.IsSet()
208 || aRecordPerSet.IsSet() || aRecordManual.IsSet() )
209 return aNoRecord;
210 return static_cast<SvMetaSlot *>(GetRef())->GetNoRecord();
212 bool SvMetaSlot::GetRecordAbsolute() const
214 if( !GetRef() || aRecordAbsolute.IsSet() )
215 return aRecordAbsolute;
216 return static_cast<SvMetaSlot *>(GetRef())->GetRecordAbsolute();
218 bool SvMetaSlot::GetHasDialog() const
220 if( aHasDialog.IsSet() || !GetRef() ) return aHasDialog;
221 return static_cast<SvMetaSlot *>(GetRef())->GetHasDialog();
223 const OString& SvMetaSlot::GetPseudoPrefix() const
225 if( !aPseudoPrefix.getString().isEmpty() || !GetRef() ) return aPseudoPrefix.getString();
226 return static_cast<SvMetaSlot *>(GetRef())->GetPseudoPrefix();
228 bool SvMetaSlot::GetMenuConfig() const
230 if( aMenuConfig.IsSet() || !GetRef() ) return aMenuConfig;
231 return static_cast<SvMetaSlot *>(GetRef())->GetMenuConfig();
233 bool SvMetaSlot::GetToolBoxConfig() const
235 if( aToolBoxConfig.IsSet() || !GetRef() ) return aToolBoxConfig;
236 return static_cast<SvMetaSlot *>(GetRef())->GetToolBoxConfig();
238 bool SvMetaSlot::GetStatusBarConfig() const
240 if( aStatusBarConfig.IsSet() || !GetRef() ) return aStatusBarConfig;
241 return static_cast<SvMetaSlot *>(GetRef())->GetStatusBarConfig();
243 bool SvMetaSlot::GetAccelConfig() const
245 if( aAccelConfig.IsSet() || !GetRef() ) return aAccelConfig;
246 return static_cast<SvMetaSlot *>(GetRef())->GetAccelConfig();
248 bool SvMetaSlot::GetFastCall() const
250 if( aFastCall.IsSet() || !GetRef() ) return aFastCall;
251 return static_cast<SvMetaSlot *>(GetRef())->GetFastCall();
253 bool SvMetaSlot::GetContainer() const
255 if( aContainer.IsSet() || !GetRef() ) return aContainer;
256 return static_cast<SvMetaSlot *>(GetRef())->GetContainer();
259 bool SvMetaSlot::GetImageRotation() const
261 if( aImageRotation.IsSet() || !GetRef() ) return aImageRotation;
262 return static_cast<SvMetaSlot *>(GetRef())->GetImageRotation();
265 bool SvMetaSlot::GetImageReflection() const
267 if( aImageReflection.IsSet() || !GetRef() ) return aImageReflection;
268 return static_cast<SvMetaSlot *>(GetRef())->GetImageReflection();
271 const OString& SvMetaSlot::GetUnoName() const
273 if( aUnoName.IsSet() || !GetRef() ) return aUnoName.getString();
274 return static_cast<SvMetaSlot *>(GetRef())->GetUnoName();
277 void SvMetaSlot::ReadAttributesSvIdl( SvIdlDataBase & rBase,
278 SvTokenStream & rInStm )
280 SvMetaAttribute::ReadAttributesSvIdl( rBase, rInStm );
282 bool bOk = false;
283 bOk |= aDefault.ReadSvIdl( SvHash_Default(), rInStm );
284 bOk |= aPseudoSlots.ReadSvIdl( SvHash_PseudoSlots(), rInStm );
285 bOk |= aHasCoreId.ReadSvIdl( SvHash_HasCoreId(), rInStm );
286 bOk |= aGroupId.ReadSvIdl( SvHash_GroupId(), rInStm );
287 bOk |= aExecMethod.ReadSvIdl( SvHash_ExecMethod(), rInStm );
288 bOk |= aStateMethod.ReadSvIdl( SvHash_StateMethod(), rInStm );
289 bOk |= aDisableFlags.ReadSvIdl( SvHash_DisableFlags(), rInStm );
290 if( aGet.ReadSvIdl( SvHash_Get(), rInStm ) )
292 SvIdlDataBase::WriteError( "warning", OUStringToOString(rInStm.GetFileName(), RTL_TEXTENCODING_UTF8),
293 "<Get> old style, use Readonly",
294 rInStm.GetToken()->GetLine(),
295 rInStm.GetToken()->GetColumn() );
297 if( aSet.ReadSvIdl( SvHash_Set(), rInStm ) )
299 SvIdlDataBase::WriteError( "warning", OUStringToOString(rInStm.GetFileName(), RTL_TEXTENCODING_UTF8),
300 "<Set> old style, use method declaration",
301 rInStm.GetToken()->GetLine(),
302 rInStm.GetToken()->GetColumn() );
305 if( aCachable.ReadSvIdl( SvHash_Cachable(), rInStm ) )
306 SetCachable( aCachable ), bOk = true;
307 if( aVolatile.ReadSvIdl( SvHash_Volatile(), rInStm ) )
308 SetVolatile( aVolatile ), bOk = true;
309 if( aToggle.ReadSvIdl( SvHash_Toggle(), rInStm ) )
310 SetToggle( aToggle ), bOk = true;
311 if( aAutoUpdate.ReadSvIdl( SvHash_AutoUpdate(), rInStm ) )
312 SetAutoUpdate( aAutoUpdate ), bOk = true;
314 if( aSynchron.ReadSvIdl( SvHash_Synchron(), rInStm ) )
315 SetSynchron( aSynchron ), bOk = true;
316 if( aAsynchron.ReadSvIdl( SvHash_Asynchron(), rInStm ) )
317 SetAsynchron( aAsynchron ), bOk = true;
319 if( aRecordAbsolute.ReadSvIdl( SvHash_RecordAbsolute(), rInStm ) )
320 SetRecordAbsolute( aRecordAbsolute), bOk = true;
321 if( aRecordPerItem.ReadSvIdl( SvHash_RecordPerItem(), rInStm ) )
322 SetRecordPerItem( aRecordPerItem ), bOk = true;
323 if( aRecordPerSet.ReadSvIdl( SvHash_RecordPerSet(), rInStm ) )
324 SetRecordPerSet( aRecordPerSet ), bOk = true;
325 if( aRecordManual.ReadSvIdl( SvHash_RecordManual(), rInStm ) )
326 SetRecordManual( aRecordManual ), bOk = true;
327 if( aNoRecord.ReadSvIdl( SvHash_NoRecord(), rInStm ) )
328 SetNoRecord( aNoRecord ), bOk = true;
330 bOk |= aHasDialog.ReadSvIdl( SvHash_HasDialog(), rInStm );
331 bOk |= aPseudoPrefix.ReadSvIdl( SvHash_PseudoPrefix(), rInStm );
332 bOk |= aMenuConfig.ReadSvIdl( SvHash_MenuConfig(), rInStm );
333 bOk |= aToolBoxConfig.ReadSvIdl( SvHash_ToolBoxConfig(), rInStm );
334 bOk |= aStatusBarConfig.ReadSvIdl( SvHash_StatusBarConfig(), rInStm );
335 bOk |= aAccelConfig.ReadSvIdl( SvHash_AccelConfig(), rInStm );
337 SvBOOL aAllConfig;
338 if( aAllConfig.ReadSvIdl( SvHash_AllConfig(), rInStm ) )
339 SetAllConfig( aAllConfig ), bOk = true;
340 bOk |= aFastCall.ReadSvIdl( SvHash_FastCall(), rInStm );
341 bOk |= aContainer.ReadSvIdl( SvHash_Container(), rInStm );
342 bOk |= aImageRotation.ReadSvIdl( SvHash_ImageRotation(), rInStm );
343 bOk |= aImageReflection.ReadSvIdl( SvHash_ImageReflection(), rInStm );
344 bOk |= aUnoName.ReadSvIdl( SvHash_UnoName(), rInStm );
346 if( !bOk )
348 if( !aSlotType.Is() )
350 sal_uInt32 nTokPos = rInStm.Tell();
351 SvToken * pTok = rInStm.GetToken_Next();
352 if( pTok->Is( SvHash_SlotType() ) )
354 bool bBraket = rInStm.Read( '(' );
355 if( bBraket || rInStm.Read( '=' ) )
357 aSlotType = rBase.ReadKnownType( rInStm );
358 if( aSlotType.Is() )
360 if( aSlotType->IsItem() )
362 if( bBraket )
364 if( rInStm.Read( ')' ) )
365 return;
367 else
368 return;
370 rBase.SetError( "the SlotType is not a item", rInStm.GetToken() );
371 rBase.WriteError( rInStm );
373 rBase.SetError( "SlotType with unknown item type", rInStm.GetToken() );
374 rBase.WriteError( rInStm );
377 rInStm.Seek( nTokPos );
380 if( !aMethod.Is() )
382 SvToken * pTok = rInStm.GetToken();
383 if( pTok->IsIdentifier() )
385 aMethod = new SvMetaSlot();
386 sal_uInt32 nTokPos = rInStm.Tell();
387 if( aMethod->ReadSvIdl( rBase, rInStm ) )
389 if( aMethod->IsMethod() )
391 aMethod->SetSlotId( GetSlotId() );
392 if( aMethod->Test( rBase, rInStm ) )
393 return;
395 rInStm.Seek( nTokPos );
397 aMethod.Clear();
403 bool SvMetaSlot::Test( SvIdlDataBase & rBase, SvTokenStream & rInStm )
405 bool bOk = SvMetaAttribute::Test( rBase, rInStm );
406 if( bOk )
408 SvMetaType * pType = GetType();
409 if( pType->GetType() == TYPE_METHOD )
410 pType = pType->GetReturnType();
411 if( !pType->IsItem() )
413 rBase.SetError( "this attribute is not a slot", rInStm.GetToken() );
414 rBase.WriteError( rInStm );
415 bOk = false;
419 return bOk;
422 bool SvMetaSlot::ReadSvIdl( SvIdlDataBase & rBase, SvTokenStream & rInStm )
424 sal_uInt32 nTokPos = rInStm.Tell();
425 bool bOk = true;
427 SvMetaAttribute * pAttr = rBase.ReadKnownAttr( rInStm, GetType() );
428 if( pAttr )
430 // c
431 SvMetaSlot * pKnownSlot = PTR_CAST( SvMetaSlot, pAttr );
432 if( pKnownSlot )
434 SetRef( pKnownSlot );
435 SetName( pKnownSlot->GetName().getString(), &rBase );
436 bOk = SvMetaName::ReadSvIdl( rBase, rInStm );
438 else
440 OStringBuffer aStr( "attribute " );
441 aStr.append(pAttr->GetName().getString());
442 aStr.append(" is method or variable but not a slot");
443 rBase.SetError( aStr.makeStringAndClear(), rInStm.GetToken() );
444 rBase.WriteError( rInStm );
445 bOk = false;
448 else
450 bOk = SvMetaAttribute::ReadSvIdl( rBase, rInStm );
452 SvMetaAttribute *pAttr2 = rBase.SearchKnownAttr( GetSlotId() );
453 if( pAttr2 )
455 // for testing purposes: reference in case of complete definition
456 SvMetaSlot * pKnownSlot = PTR_CAST( SvMetaSlot, pAttr2 );
457 if( pKnownSlot )
459 SetRef( pKnownSlot );
461 // names may differ, because explicitly given
462 if ( pKnownSlot->GetName().getString() != GetName().getString() )
464 OSL_FAIL("Illegal definition!");
465 rInStm.Seek( nTokPos );
466 return false;
469 SetName( pKnownSlot->GetName().getString(), &rBase );
471 else
473 OStringBuffer aStr("attribute ");
474 aStr.append(pAttr2->GetName().getString());
475 aStr.append(" is method or variable but not a slot");
476 rBase.SetError( aStr.makeStringAndClear(), rInStm.GetToken() );
477 rBase.WriteError( rInStm );
478 bOk = false;
483 if( !bOk )
484 rInStm.Seek( nTokPos );
486 return bOk;
489 void SvMetaSlot::Insert( SvSlotElementList& rList, const OString& rPrefix,
490 SvIdlDataBase& rBase)
492 // get insert position through binary search in slotlist
493 sal_uInt16 nId = (sal_uInt16) GetSlotId().GetValue();
494 sal_uInt16 nListCount = (sal_uInt16) rList.size();
495 sal_uInt16 nPos;
496 sal_uLong m; // for inner "for" loop
498 if ( !nListCount )
499 nPos = 0;
500 else if ( nListCount == 1 )
501 nPos = rList[ 0 ]->xSlot->GetSlotId().GetValue() >= nId ? 0 : 1;
502 else
504 sal_uInt16 nMid = 0, nLow = 0;
505 sal_uInt16 nHigh = nListCount - 1;
506 bool bFound = false;
507 while ( !bFound && nLow <= nHigh )
509 nMid = (nLow + nHigh) >> 1;
510 DBG_ASSERT( nMid < nListCount, "bsearch ist buggy" );
511 int nDiff = (int) nId - (int) rList[ nMid ]->xSlot->GetSlotId().GetValue();
512 if ( nDiff < 0)
514 if ( nMid == 0 )
515 break;
516 nHigh = nMid - 1;
518 else if ( nDiff > 0 )
520 nLow = nMid + 1;
521 if ( nLow == 0 )
522 break;
524 else
525 bFound = true;
528 DBG_ASSERT(!bFound, "Duplicate SlotId!");
529 nPos = bFound ? nMid : nLow;
532 DBG_ASSERT( nPos <= nListCount,
533 "nPos too large" );
534 DBG_ASSERT( nPos == nListCount || nId <=
535 (sal_uInt16) rList[ nPos ]->xSlot->GetSlotId().GetValue(),
536 "Successor has lower SlotId" );
537 DBG_ASSERT( nPos == 0 || nId >
538 (sal_uInt16) rList[ nPos-1 ]->xSlot->GetSlotId().GetValue(),
539 "Predecessor has higher SlotId" );
540 DBG_ASSERT( nPos+1 >= nListCount || nId <
541 (sal_uInt16) rList[ nPos+1 ]->xSlot->GetSlotId().GetValue(),
542 "Successor has lower SlotId" );
544 if ( nPos < rList.size() )
546 SvSlotElementList::iterator it = rList.begin();
547 std::advance( it, nPos );
548 rList.insert( it, new SvSlotElement( this, rPrefix ) );
550 else
552 rList.push_back( new SvSlotElement( this, rPrefix ) );
555 // iron out EnumSlots
556 SvMetaTypeEnum * pEnum = NULL;
557 SvMetaType * pBType = GetType()->GetBaseType();
558 pEnum = PTR_CAST( SvMetaTypeEnum, pBType );
559 if( GetPseudoSlots() && pEnum && pEnum->Count() )
561 // clone the MasterSlot
562 SvMetaSlotRef xEnumSlot;
563 SvMetaSlot *pFirstEnumSlot = NULL;
564 for( sal_uLong n = 0; n < pEnum->Count(); n++ )
566 // create SlotId
567 SvMetaEnumValue *enumValue = pEnum->GetObject(n);
568 OString aValName = enumValue->GetName().getString();
569 OStringBuffer aBuf;
570 if( !GetPseudoPrefix().isEmpty() )
571 aBuf.append(GetPseudoPrefix());
572 else
573 aBuf.append(GetSlotId().getString());
574 aBuf.append('_');
575 aBuf.append(aValName.copy(pEnum->GetPrefix().getLength()));
577 OString aSId = aBuf.makeStringAndClear();
579 xEnumSlot = NULL;
580 for( m=0; m<rBase.GetAttrList().size(); m++ )
582 SvMetaAttribute * pAttr = rBase.GetAttrList()[m];
583 if (aSId.equals(pAttr->GetSlotId().getString()))
585 SvMetaSlot& rSlot = dynamic_cast<SvMetaSlot&>(*pAttr);
586 xEnumSlot = rSlot.Clone();
587 break;
591 if ( m == rBase.GetAttrList().size() )
593 OSL_FAIL("Invalid EnumSlot!");
594 xEnumSlot = Clone();
595 sal_uLong nValue;
596 if ( rBase.FindId(aSId , &nValue) )
598 SvNumberIdentifier aId;
599 aId.setString(aSId);
600 aId.SetValue(nValue);
601 xEnumSlot->SetSlotId(aId);
605 // The slaves are no master!
606 xEnumSlot->aPseudoSlots = false;
607 xEnumSlot->SetEnumValue(enumValue);
609 if ( !pFirstEnumSlot || xEnumSlot->GetSlotId().GetValue() < pFirstEnumSlot->GetSlotId().GetValue() )
610 pFirstEnumSlot = xEnumSlot;
612 // insert the created slave as well
613 xEnumSlot->Insert( rList, rPrefix, rBase);
615 // concatenate the EnumSlots with the master
616 xEnumSlot->pLinkedSlot = this;
619 // master points to the first slave
620 pLinkedSlot = pFirstEnumSlot;
622 // concatenate slaves among themselves
623 xEnumSlot = pFirstEnumSlot;
624 size_t i = 0;
625 SvSlotElement *pEle;
628 pEle = ( ++i < rList.size() ) ? rList[ i ] : NULL;
629 if ( pEle && pEle->xSlot->pLinkedSlot == this )
631 xEnumSlot->pNextSlot = pEle->xSlot;
632 xEnumSlot = pEle->xSlot;
635 while ( pEle );
636 xEnumSlot->pNextSlot = pFirstEnumSlot;
641 static OString MakeSlotName( SvStringHashEntry * pEntry )
643 OStringBuffer aName("SfxSlotMode::");
644 aName.append(pEntry->GetName().toAsciiUpperCase());
645 return aName.makeStringAndClear();
648 void SvMetaSlot::WriteSlotStubs( const OString& rShellName,
649 ByteStringList & rList,
650 SvStream & rOutStm )
652 if ( !GetExport() && !GetHidden() )
653 return;
655 OString aMethodName( GetExecMethod() );
656 if ( !aMethodName.isEmpty() &&
657 aMethodName != "NoExec" )
659 bool bIn = false;
660 for( size_t n = 0; n < rList.size(); n++ )
662 if (rList[n]->equals(aMethodName))
664 bIn = true;
665 break;
669 if ( !bIn )
671 rList.push_back( new OString(aMethodName) );
672 rOutStm.WriteCharPtr( "SFX_EXEC_STUB(" )
673 .WriteCharPtr( rShellName.getStr() )
674 .WriteChar( ',' )
675 .WriteCharPtr( aMethodName.getStr() )
676 .WriteChar( ')' ) << endl;
680 aMethodName = GetStateMethod();
681 if (!aMethodName.isEmpty() &&
682 aMethodName != "NoState")
684 bool bIn = false;
685 for ( size_t n=0; n < rList.size(); n++ )
687 if (rList[n]->equals(aMethodName))
689 bIn = true;
690 break;
694 if ( !bIn )
696 rList.push_back( new OString(aMethodName) );
697 rOutStm.WriteCharPtr( "SFX_STATE_STUB(" )
698 .WriteCharPtr( rShellName.getStr() )
699 .WriteChar( ',' )
700 .WriteCharPtr( aMethodName.getStr() )
701 .WriteChar( ')' ) << endl;
706 void SvMetaSlot::WriteSlot( const OString& rShellName, sal_uInt16 nCount,
707 const OString& rSlotId,
708 SvSlotElementList& rSlotList,
709 size_t nStart,
710 SvIdlDataBase & rBase, SvStream & rOutStm )
712 if ( !GetExport() && !GetHidden() )
713 return;
715 bool bIsEnumSlot = 0 != pEnumValue;
717 rOutStm.WriteCharPtr( "// Slot Nr. " )
718 .WriteCharPtr( OString::number(nListPos).getStr() )
719 .WriteCharPtr( " : " );
720 OString aSlotIdValue(OString::number(GetSlotId().GetValue()));
721 rOutStm.WriteCharPtr( aSlotIdValue.getStr() ) << endl;
722 WriteTab( rOutStm, 1 );
723 if( bIsEnumSlot )
724 rOutStm.WriteCharPtr( "SFX_NEW_SLOT_ENUM( " );
725 else
726 rOutStm.WriteCharPtr( "SFX_NEW_SLOT_ARG( " ).WriteCharPtr( rShellName.getStr() ).WriteChar( ',' ) ;
728 rOutStm.WriteCharPtr( rSlotId.getStr() ).WriteChar( ',' );
729 const SvHelpContext& rHlpCtx = GetHelpContext();
730 if( rHlpCtx.IsSet() )
731 rOutStm.WriteCharPtr( rHlpCtx.getString().getStr() ).WriteChar( ',' );
732 else
733 rOutStm.WriteCharPtr( rSlotId.getStr() ).WriteChar( ',' );
735 // GroupId
736 if( !GetGroupId().isEmpty() )
737 rOutStm.WriteCharPtr( GetGroupId().getStr() );
738 else
739 rOutStm.WriteChar( '0' );
740 rOutStm.WriteChar( ',' ) << endl;
741 WriteTab( rOutStm, 4 );
743 if( bIsEnumSlot )
745 rOutStm.WriteCharPtr( "&a" ).WriteCharPtr( rShellName.getStr() ).WriteCharPtr( "Slots_Impl[" )
746 .WriteCharPtr( OString::number(pLinkedSlot->GetListPos()).getStr() )
747 .WriteCharPtr( "] /*Offset Master*/, " ) << endl;
748 WriteTab( rOutStm, 4 );
749 rOutStm.WriteCharPtr( "&a" ).WriteCharPtr( rShellName.getStr() ).WriteCharPtr( "Slots_Impl[" )
750 .WriteCharPtr( OString::number(pNextSlot->GetListPos()).getStr() )
751 .WriteCharPtr( "] /*Offset Next*/, " ) << endl;
753 WriteTab( rOutStm, 4 );
755 // SlotId
756 if( !GetSlotId().getString().isEmpty() )
757 rOutStm.WriteCharPtr( pLinkedSlot->GetSlotId().getString().getStr() );
758 else
759 rOutStm.WriteChar( '0' );
760 rOutStm.WriteChar( ',' );
761 rOutStm.WriteCharPtr( pEnumValue->GetName().getString().getStr() );
763 else
765 // look for the next slot with the same StateMethod like me
766 // the slotlist is set to the current slot
767 size_t i = nStart;
768 SvSlotElement* pEle = ( ++i < rSlotList.size() ) ? rSlotList[ i ] : NULL;
769 pNextSlot = pEle ? &pEle->xSlot : NULL;
770 while ( pNextSlot )
772 if ( !pNextSlot->pNextSlot &&
773 pNextSlot->GetStateMethod() == GetStateMethod()
775 break;
777 pEle = ( ++i < rSlotList.size() ) ? rSlotList[ i ] : NULL;
778 pNextSlot = pEle ? &pEle->xSlot : NULL;
781 if ( !pNextSlot )
783 // There is no slot behind me that has the same ExecMethod.
784 // So I search for the first slot with it (could be myself).
785 i = 0;
786 pEle = rSlotList.empty() ? NULL : rSlotList[ i ];
787 pNextSlot = pEle ? &pEle->xSlot : NULL;
788 while ( pNextSlot != this )
790 if ( !pNextSlot->pEnumValue &&
791 pNextSlot->GetStateMethod() == GetStateMethod() )
792 break;
793 pEle = ( ++i < rSlotList.size() ) ? rSlotList[ i ] : NULL;
794 pNextSlot = pEle ? &pEle->xSlot : NULL;
798 if ( !pLinkedSlot )
800 rOutStm.WriteCharPtr( "0 ," );
802 else
804 rOutStm.WriteCharPtr( "&a" ).WriteCharPtr( rShellName.getStr() ).WriteCharPtr( "Slots_Impl[" )
805 .WriteCharPtr( OString::number(pLinkedSlot->GetListPos()).getStr() )
806 .WriteCharPtr( "] /*Offset Linked*/, " ) << endl;
807 WriteTab( rOutStm, 4 );
810 rOutStm.WriteCharPtr( "&a" ).WriteCharPtr( rShellName.getStr() ).WriteCharPtr( "Slots_Impl[" )
811 .WriteCharPtr( OString::number(pNextSlot->GetListPos()).getStr() )
812 .WriteCharPtr( "] /*Offset Next*/, " ) << endl;
814 WriteTab( rOutStm, 4 );
816 // write ExecMethod, with standard name if not specified
817 if( !GetExecMethod().isEmpty() &&
818 GetExecMethod() != "NoExec")
820 rOutStm.WriteCharPtr( "SFX_STUB_PTR(" ).WriteCharPtr( rShellName.getStr() ).WriteChar( ',' )
821 .WriteCharPtr( GetExecMethod().getStr() ).WriteChar( ')' );
823 else
824 rOutStm.WriteCharPtr( "SFX_STUB_PTR_EXEC_NONE" );
825 rOutStm.WriteChar( ',' );
827 // write StateMethod, with standard name if not specified
828 if( !GetStateMethod().isEmpty() &&
829 GetStateMethod() != "NoState")
831 rOutStm.WriteCharPtr( "SFX_STUB_PTR(" ).WriteCharPtr( rShellName.getStr() ).WriteChar( ',' )
832 .WriteCharPtr( GetStateMethod().getStr() ).WriteChar( ')' );
834 else
835 rOutStm.WriteCharPtr( "SFX_STUB_PTR_STATE_NONE" );
837 rOutStm.WriteChar( ',' ) << endl;
838 WriteTab( rOutStm, 4 );
840 // write flags
841 if( GetHasCoreId() )
842 rOutStm.WriteCharPtr( MakeSlotName( SvHash_HasCoreId() ).getStr() ).WriteChar( '|' );
843 if( GetCachable() )
844 rOutStm.WriteCharPtr( MakeSlotName( SvHash_Cachable() ).getStr() ).WriteChar( '|' );
845 if( GetVolatile() )
846 rOutStm.WriteCharPtr( MakeSlotName( SvHash_Volatile() ).getStr() ).WriteChar( '|' );
847 if( GetToggle() )
848 rOutStm.WriteCharPtr( MakeSlotName( SvHash_Toggle() ).getStr() ).WriteChar( '|' );
849 if( GetAutoUpdate() )
850 rOutStm.WriteCharPtr( MakeSlotName( SvHash_AutoUpdate() ).getStr() ).WriteChar( '|' );
851 if( GetSynchron() )
852 rOutStm.WriteCharPtr( MakeSlotName( SvHash_Synchron() ).getStr() ).WriteChar( '|' );
853 if( GetAsynchron() )
854 rOutStm.WriteCharPtr( MakeSlotName( SvHash_Asynchron() ).getStr() ).WriteChar( '|' );
855 if( GetRecordPerItem() )
856 rOutStm.WriteCharPtr( MakeSlotName( SvHash_RecordPerItem() ).getStr() ).WriteChar( '|' );
857 if( GetRecordPerSet() )
858 rOutStm.WriteCharPtr( MakeSlotName( SvHash_RecordPerSet() ).getStr() ).WriteChar( '|' );
859 if( GetRecordManual() )
860 rOutStm.WriteCharPtr( MakeSlotName( SvHash_RecordManual() ).getStr() ).WriteChar( '|' );
861 if( GetNoRecord() )
862 rOutStm.WriteCharPtr( MakeSlotName( SvHash_NoRecord() ).getStr() ).WriteChar( '|' );
863 if( GetRecordAbsolute() )
864 rOutStm.WriteCharPtr( MakeSlotName( SvHash_RecordAbsolute() ).getStr() ).WriteChar( '|' );
865 if( GetHasDialog() )
866 rOutStm.WriteCharPtr( MakeSlotName( SvHash_HasDialog() ).getStr() ).WriteChar( '|' );
867 if( GetMenuConfig() )
868 rOutStm.WriteCharPtr( MakeSlotName( SvHash_MenuConfig() ).getStr() ).WriteChar( '|' );
869 if( GetToolBoxConfig() )
870 rOutStm.WriteCharPtr( MakeSlotName( SvHash_ToolBoxConfig() ).getStr() ).WriteChar( '|' );
871 if( GetStatusBarConfig() )
872 rOutStm.WriteCharPtr( MakeSlotName( SvHash_StatusBarConfig() ).getStr() ).WriteChar( '|' );
873 if( GetAccelConfig() )
874 rOutStm.WriteCharPtr( MakeSlotName( SvHash_AccelConfig() ).getStr() ).WriteChar( '|' );
875 if( GetFastCall() )
876 rOutStm.WriteCharPtr( MakeSlotName( SvHash_FastCall() ).getStr() ).WriteChar( '|' );
877 if( GetContainer() )
878 rOutStm.WriteCharPtr( MakeSlotName( SvHash_Container() ).getStr() ).WriteChar( '|' );
879 if ( GetReadOnlyDoc() )
880 rOutStm.WriteCharPtr( MakeSlotName( SvHash_ReadOnlyDoc() ).getStr() ).WriteChar( '|' );
881 if( GetImageRotation() )
882 rOutStm.WriteCharPtr( MakeSlotName( SvHash_ImageRotation() ).getStr() ).WriteChar( '|' );
883 if( GetImageReflection() )
884 rOutStm.WriteCharPtr( MakeSlotName( SvHash_ImageReflection() ).getStr() ).WriteChar( '|' );
885 rOutStm.WriteCharPtr( "SfxSlotMode::NONE" );
887 rOutStm.WriteChar( ',' ) << endl;
888 WriteTab( rOutStm, 4 );
889 if ( GetDisableFlags().isEmpty() )
890 rOutStm.WriteCharPtr( "0" );
891 else
892 rOutStm.WriteCharPtr( GetDisableFlags().getStr() );
894 // write attribute type
895 if( !bIsEnumSlot )
897 rOutStm.WriteChar( ',' ) << endl;
898 WriteTab( rOutStm, 4 );
900 SvMetaType * pT = GetSlotType();
901 if( !pT )
903 if( !IsVariable() )
904 pT = rBase.FindType( "SfxVoidItem" );
905 else
906 pT = GetType();
908 if( pT )
910 rOutStm.WriteCharPtr( pT->GetName().getString().getStr() );
911 if( !SvIdlDataBase::FindType( pT, rBase.aUsedTypes ) )
912 rBase.aUsedTypes.push_back( pT );
914 else
915 rOutStm.WriteCharPtr( "SfxVoidItem not defined" );
917 else
919 SvMetaType *pT = rBase.FindType( "SfxBoolItem" );
920 if ( pT && !SvIdlDataBase::FindType( pT, rBase.aUsedTypes ) )
921 rBase.aUsedTypes.push_back( pT );
924 if( !bIsEnumSlot )
926 rOutStm.WriteChar( ',' ) << endl;
927 WriteTab( rOutStm, 4 );
928 rOutStm
929 .WriteCharPtr( OString::number(nCount).getStr() )
930 .WriteCharPtr( "/*Offset*/, " );
932 if( IsMethod() )
934 SvMetaAttribute * pMethod = GetMethod();
935 SvMetaType * pType;
936 if( pMethod )
937 pType = pMethod->GetType();
938 else
939 pType = GetType();
940 sal_uLong nSCount = pType->GetAttrCount();
941 rOutStm
942 .WriteCharPtr( OString::number(nSCount).getStr() )
943 .WriteCharPtr( "/*Count*/," );
945 else
946 rOutStm.WriteCharPtr( "0," );
948 rOutStm.WriteCharPtr( " " );
950 // Method/Property flags
951 if( IsMethod() )
952 rOutStm.WriteCharPtr( "SfxSlotMode::METHOD|" );
953 if( IsVariable() )
955 rOutStm.WriteCharPtr( "SfxSlotMode::PROPGET|" );
956 if( !GetReadonly() )
957 rOutStm.WriteCharPtr( "SfxSlotMode::PROPSET|" );
960 rOutStm.WriteCharPtr( "SfxSlotMode::NONE" );
964 rOutStm.WriteCharPtr( ",\"" );
965 rOutStm.WriteCharPtr( GetMangleName( false ).getStr() );
966 rOutStm.WriteCharPtr( "\"" );
969 rOutStm.WriteCharPtr( " )," ) << endl;
972 sal_uInt16 SvMetaSlot::WriteSlotParamArray( SvIdlDataBase & rBase, SvStream & rOutStm )
974 if ( !GetExport() && !GetHidden() )
975 return 0;
977 SvMetaAttribute * pMethod = GetMethod();
978 if( IsMethod() )
980 SvMetaType * pType;
981 if( pMethod )
982 pType = pMethod->GetType();
983 else
984 pType = GetType();
986 if( !SvIdlDataBase::FindType( pType, rBase.aUsedTypes ) )
987 rBase.aUsedTypes.push_back( pType );
989 const SvMetaAttributeMemberList & rList =
990 pType->GetAttrList();
991 for( sal_uLong n = 0; n < rList.size(); n++ )
993 SvMetaAttribute * pPar = rList[n];
994 SvMetaType * pPType = pPar->GetType();
995 WriteTab( rOutStm, 1 );
996 rOutStm.WriteCharPtr("{ (const SfxType*) &a")
997 // item type
998 .WriteCharPtr(pPType->GetName().getString().getStr()).WriteCharPtr("_Impl, ")
999 // parameter name
1000 .WriteCharPtr("\"").WriteCharPtr(pPar->GetName().getString().getStr()).WriteCharPtr("\", ")
1001 // slot id
1002 .WriteCharPtr(pPar->GetSlotId().getString().getStr()).WriteCharPtr(" },") << endl;
1003 if( !SvIdlDataBase::FindType( pPType, rBase.aUsedTypes ) )
1004 rBase.aUsedTypes.push_back( pPType );
1006 return (sal_uInt16)rList.size();
1008 return 0;
1011 sal_uInt16 SvMetaSlot::WriteSlotMap( const OString& rShellName, sal_uInt16 nCount,
1012 SvSlotElementList& rSlotList,
1013 size_t nStart,
1014 SvIdlDataBase & rBase,
1015 SvStream & rOutStm )
1017 // SlotId, if not specified generate from name
1018 OString slotId = GetSlotId().getString();
1020 sal_uInt16 nSCount = 0;
1021 if( IsMethod() )
1023 SvMetaType * pType;
1024 SvMetaAttribute * pMethod = GetMethod();
1025 if( pMethod )
1026 pType = pMethod->GetType();
1027 else
1028 pType = GetType();
1030 nSCount = (sal_uInt16)pType->GetAttrCount();
1033 WriteSlot( rShellName, nCount, slotId, rSlotList, nStart, rBase, rOutStm );
1034 return nSCount;
1037 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */