1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_svl.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <string.h> 32*cdf0e10cSrcweir #include <stdio.h> 33*cdf0e10cSrcweir #ifndef GCC 34*cdf0e10cSrcweir #endif 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir #include <svl/itempool.hxx> 37*cdf0e10cSrcweir #include "whassert.hxx" 38*cdf0e10cSrcweir #include <svl/brdcst.hxx> 39*cdf0e10cSrcweir #include <svl/smplhint.hxx> 40*cdf0e10cSrcweir #include "poolio.hxx" 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir //======================================================================== 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir void SfxItemPool::AddSfxItemPoolUser(SfxItemPoolUser& rNewUser) 46*cdf0e10cSrcweir { 47*cdf0e10cSrcweir maSfxItemPoolUsers.push_back(&rNewUser); 48*cdf0e10cSrcweir } 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir void SfxItemPool::RemoveSfxItemPoolUser(SfxItemPoolUser& rOldUser) 51*cdf0e10cSrcweir { 52*cdf0e10cSrcweir const SfxItemPoolUserVector::iterator aFindResult = ::std::find(maSfxItemPoolUsers.begin(), maSfxItemPoolUsers.end(), &rOldUser); 53*cdf0e10cSrcweir if(aFindResult != maSfxItemPoolUsers.end()) 54*cdf0e10cSrcweir { 55*cdf0e10cSrcweir maSfxItemPoolUsers.erase(aFindResult); 56*cdf0e10cSrcweir } 57*cdf0e10cSrcweir } 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir const SfxPoolItem* SfxItemPool::GetPoolDefaultItem( sal_uInt16 nWhich ) const 60*cdf0e10cSrcweir { 61*cdf0e10cSrcweir DBG_CHKTHIS(SfxItemPool, 0); 62*cdf0e10cSrcweir const SfxPoolItem* pRet; 63*cdf0e10cSrcweir if( IsInRange( nWhich ) ) 64*cdf0e10cSrcweir pRet = *(ppPoolDefaults + GetIndex_Impl( nWhich )); 65*cdf0e10cSrcweir else if( pSecondary ) 66*cdf0e10cSrcweir pRet = pSecondary->GetPoolDefaultItem( nWhich ); 67*cdf0e10cSrcweir else 68*cdf0e10cSrcweir { 69*cdf0e10cSrcweir SFX_ASSERT( 0, nWhich, "unknown Which-Id - cannot get pool default" ); 70*cdf0e10cSrcweir pRet = 0; 71*cdf0e10cSrcweir } 72*cdf0e10cSrcweir return pRet; 73*cdf0e10cSrcweir } 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir // ----------------------------------------------------------------------- 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir inline FASTBOOL SfxItemPool::IsItemFlag_Impl( sal_uInt16 nPos, sal_uInt16 nFlag ) const 78*cdf0e10cSrcweir { 79*cdf0e10cSrcweir sal_uInt16 nItemFlag = pItemInfos[nPos]._nFlags; 80*cdf0e10cSrcweir return nFlag == (nItemFlag & nFlag); 81*cdf0e10cSrcweir } 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir // ----------------------------------------------------------------------- 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir FASTBOOL SfxItemPool::IsItemFlag( sal_uInt16 nWhich, sal_uInt16 nFlag ) const 86*cdf0e10cSrcweir { 87*cdf0e10cSrcweir for ( const SfxItemPool *pPool = this; pPool; pPool = pPool->pSecondary ) 88*cdf0e10cSrcweir { 89*cdf0e10cSrcweir if ( pPool->IsInRange(nWhich) ) 90*cdf0e10cSrcweir return pPool->IsItemFlag_Impl( pPool->GetIndex_Impl(nWhich), nFlag); 91*cdf0e10cSrcweir } 92*cdf0e10cSrcweir DBG_ASSERT( !IsWhich(nWhich), "unknown which-id" ); 93*cdf0e10cSrcweir return sal_False; 94*cdf0e10cSrcweir } 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir // ----------------------------------------------------------------------- 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir SfxBroadcaster& SfxItemPool::BC() 99*cdf0e10cSrcweir { 100*cdf0e10cSrcweir return pImp->aBC; 101*cdf0e10cSrcweir } 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir // ----------------------------------------------------------------------- 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir SfxItemPool::SfxItemPool 107*cdf0e10cSrcweir ( 108*cdf0e10cSrcweir UniString const & rName, /* Name des Pools zur Idetifikation 109*cdf0e10cSrcweir im File-Format */ 110*cdf0e10cSrcweir sal_uInt16 nStartWhich, /* erste Which-Id des Pools */ 111*cdf0e10cSrcweir sal_uInt16 nEndWhich, /* letzte Which-Id des Pools */ 112*cdf0e10cSrcweir #ifdef TF_POOLABLE 113*cdf0e10cSrcweir const SfxItemInfo* pInfos, /* SID-Map und Item-Flags */ 114*cdf0e10cSrcweir #endif 115*cdf0e10cSrcweir SfxPoolItem** pDefaults, /* Pointer auf statische Defaults, 116*cdf0e10cSrcweir wird direkt vom Pool referenziert, 117*cdf0e10cSrcweir jedoch kein Eigent"umer"ubergang */ 118*cdf0e10cSrcweir #ifndef TF_POOLABLE 119*cdf0e10cSrcweir sal_uInt16* pSlotIdArray, /* Zuordnung von Slot-Ids zu Which-Ids */ 120*cdf0e10cSrcweir #endif 121*cdf0e10cSrcweir FASTBOOL bLoadRefCounts /* Ref-Counts mitladen oder auf 1 setzen */ 122*cdf0e10cSrcweir ) 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir /* [Beschreibung] 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir Der im Normalfall verwendete Konstruktor der Klasse SfxItemPool. Es 127*cdf0e10cSrcweir wird eine SfxItemPool-Instanz initialisiert, die Items im b"undigen 128*cdf0e10cSrcweir Which-Bereich von 'nStartWhich' bis 'nEndWhich' verwalten kann. 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir F"ur jede dieser Which-Ids mu\s ein statischer Default im Array 'pDefaults' 131*cdf0e10cSrcweir vorhanden sein, die dort beginnend mit einem <SfxPoolItem> mit der 132*cdf0e10cSrcweir Which-Id 'nStartWhich' nach Which-Ids sortiert aufeinanderfolgend 133*cdf0e10cSrcweir eingetragen sein m"ussen. 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir 'pItemInfos' ist ein identisch angeordnetes Array von USHORTs, die 136*cdf0e10cSrcweir Slot-Ids darstellen und Flags. Die Slot-Ids k"onnen 0 sein, wenn die 137*cdf0e10cSrcweir betreffenden Items ausschlie\slich in der Core verwendet werden. 138*cdf0e10cSrcweir "Uber die Flags kann z.B. bestimmt werden, ob Value-Sharing 139*cdf0e10cSrcweir (SFX_ITEM_POOLABLE) stattfinden soll. 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir [Anmerkung] 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir Wenn der Pool <SfxSetItem>s enthalten soll, k"onnen im Konstruktor noch 144*cdf0e10cSrcweir keine static-Defaults angegeben werden. Dies mu\s dann nachtr"aglich 145*cdf0e10cSrcweir mit <SfxItemPool::SetDefaults(SfxItemPool**)> geschehen. 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir [Querverweise] 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir <SfxItemPool::SetDefaults(SfxItemPool**)> 151*cdf0e10cSrcweir <SfxItemPool::ReleaseDefaults(SfxPoolItem**,sal_uInt16,sal_Bool)> 152*cdf0e10cSrcweir <SfxItemPool::ReldaseDefaults(sal_Bool)> 153*cdf0e10cSrcweir */ 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir : aName(rName), 156*cdf0e10cSrcweir nStart(nStartWhich), 157*cdf0e10cSrcweir nEnd(nEndWhich), 158*cdf0e10cSrcweir #ifdef TF_POOLABLE 159*cdf0e10cSrcweir pItemInfos(pInfos), 160*cdf0e10cSrcweir #else 161*cdf0e10cSrcweir pSlotIds(pSlotIdArray), 162*cdf0e10cSrcweir #endif 163*cdf0e10cSrcweir pImp( new SfxItemPool_Impl( nStart, nEnd ) ), 164*cdf0e10cSrcweir ppStaticDefaults(0), 165*cdf0e10cSrcweir ppPoolDefaults(new SfxPoolItem* [ nEndWhich - nStartWhich + 1]), 166*cdf0e10cSrcweir pSecondary(0), 167*cdf0e10cSrcweir pMaster(this), 168*cdf0e10cSrcweir _pPoolRanges( 0 ), 169*cdf0e10cSrcweir bPersistentRefCounts(bLoadRefCounts), 170*cdf0e10cSrcweir maSfxItemPoolUsers() 171*cdf0e10cSrcweir { 172*cdf0e10cSrcweir DBG_CTOR(SfxItemPool, 0); 173*cdf0e10cSrcweir DBG_ASSERT(nStart, "Start-Which-Id must be greater 0" ); 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir pImp->eDefMetric = SFX_MAPUNIT_TWIP; 176*cdf0e10cSrcweir pImp->nVersion = 0; 177*cdf0e10cSrcweir pImp->bStreaming = sal_False; 178*cdf0e10cSrcweir pImp->nLoadingVersion = 0; 179*cdf0e10cSrcweir pImp->nInitRefCount = 1; 180*cdf0e10cSrcweir pImp->nVerStart = nStart; 181*cdf0e10cSrcweir pImp->nVerEnd = nEnd; 182*cdf0e10cSrcweir pImp->bInSetItem = sal_False; 183*cdf0e10cSrcweir pImp->nStoringStart = nStartWhich; 184*cdf0e10cSrcweir pImp->nStoringEnd = nEndWhich; 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir memset( ppPoolDefaults, 0, sizeof( SfxPoolItem* ) * (nEnd - nStart + 1)); 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir if ( pDefaults ) 189*cdf0e10cSrcweir SetDefaults(pDefaults); 190*cdf0e10cSrcweir } 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir // ----------------------------------------------------------------------- 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir SfxItemPool::SfxItemPool 196*cdf0e10cSrcweir ( 197*cdf0e10cSrcweir const SfxItemPool& rPool, // von dieser Instanz kopieren 198*cdf0e10cSrcweir sal_Bool bCloneStaticDefaults /* sal_True 199*cdf0e10cSrcweir statische Defaults kopieren 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir sal_False 202*cdf0e10cSrcweir statische Defaults 203*cdf0e10cSrcweir "ubernehehmen */ 204*cdf0e10cSrcweir ) 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir /* [Beschreibung] 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir Copy-Konstruktor der Klasse SfxItemPool. 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir [Querverweise] 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir <SfxItemPool::Clone()const> 214*cdf0e10cSrcweir */ 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir : aName(rPool.aName), 217*cdf0e10cSrcweir nStart(rPool.nStart), 218*cdf0e10cSrcweir nEnd(rPool.nEnd), 219*cdf0e10cSrcweir #ifdef TF_POOLABLE 220*cdf0e10cSrcweir pItemInfos(rPool.pItemInfos), 221*cdf0e10cSrcweir #else 222*cdf0e10cSrcweir pSlotIds(rPool.pSlotIds), 223*cdf0e10cSrcweir #endif 224*cdf0e10cSrcweir pImp( new SfxItemPool_Impl( nStart, nEnd ) ), 225*cdf0e10cSrcweir ppStaticDefaults(0), 226*cdf0e10cSrcweir ppPoolDefaults(new SfxPoolItem* [ nEnd - nStart + 1]), 227*cdf0e10cSrcweir pSecondary(0), 228*cdf0e10cSrcweir pMaster(this), 229*cdf0e10cSrcweir _pPoolRanges( 0 ), 230*cdf0e10cSrcweir bPersistentRefCounts(rPool.bPersistentRefCounts ), 231*cdf0e10cSrcweir maSfxItemPoolUsers() 232*cdf0e10cSrcweir { 233*cdf0e10cSrcweir DBG_CTOR(SfxItemPool, 0); 234*cdf0e10cSrcweir pImp->eDefMetric = rPool.pImp->eDefMetric; 235*cdf0e10cSrcweir pImp->nVersion = rPool.pImp->nVersion; 236*cdf0e10cSrcweir pImp->bStreaming = sal_False; 237*cdf0e10cSrcweir pImp->nLoadingVersion = 0; 238*cdf0e10cSrcweir pImp->nInitRefCount = 1; 239*cdf0e10cSrcweir pImp->nVerStart = rPool.pImp->nVerStart; 240*cdf0e10cSrcweir pImp->nVerEnd = rPool.pImp->nVerEnd; 241*cdf0e10cSrcweir pImp->bInSetItem = sal_False; 242*cdf0e10cSrcweir pImp->nStoringStart = nStart; 243*cdf0e10cSrcweir pImp->nStoringEnd = nEnd; 244*cdf0e10cSrcweir 245*cdf0e10cSrcweir memset( ppPoolDefaults, 0, sizeof( SfxPoolItem* ) * (nEnd - nStart + 1)); 246*cdf0e10cSrcweir 247*cdf0e10cSrcweir // Static Defaults "ubernehmen 248*cdf0e10cSrcweir if ( bCloneStaticDefaults ) 249*cdf0e10cSrcweir { 250*cdf0e10cSrcweir SfxPoolItem **ppDefaults = new SfxPoolItem*[nEnd-nStart+1]; 251*cdf0e10cSrcweir for ( sal_uInt16 n = 0; n <= nEnd - nStart; ++n ) 252*cdf0e10cSrcweir { 253*cdf0e10cSrcweir (*( ppDefaults + n )) = (*( rPool.ppStaticDefaults + n ))->Clone(this); 254*cdf0e10cSrcweir (*( ppDefaults + n ))->SetKind( SFX_ITEMS_STATICDEFAULT ); 255*cdf0e10cSrcweir } 256*cdf0e10cSrcweir 257*cdf0e10cSrcweir SetDefaults( ppDefaults ); 258*cdf0e10cSrcweir } 259*cdf0e10cSrcweir else 260*cdf0e10cSrcweir SetDefaults( rPool.ppStaticDefaults ); 261*cdf0e10cSrcweir 262*cdf0e10cSrcweir // Pool Defaults kopieren 263*cdf0e10cSrcweir for ( sal_uInt16 n = 0; n <= nEnd - nStart; ++n ) 264*cdf0e10cSrcweir if ( (*( rPool.ppPoolDefaults + n )) ) 265*cdf0e10cSrcweir { 266*cdf0e10cSrcweir (*( ppPoolDefaults + n )) = (*( rPool.ppPoolDefaults + n ))->Clone(this); 267*cdf0e10cSrcweir (*( ppPoolDefaults + n ))->SetKind( SFX_ITEMS_POOLDEFAULT ); 268*cdf0e10cSrcweir } 269*cdf0e10cSrcweir 270*cdf0e10cSrcweir // Copy Version-Map 271*cdf0e10cSrcweir for ( size_t nVer = 0; nVer < rPool.pImp->aVersions.size(); ++nVer ) 272*cdf0e10cSrcweir { 273*cdf0e10cSrcweir const SfxPoolVersion_ImplPtr pOld = rPool.pImp->aVersions[nVer]; 274*cdf0e10cSrcweir SfxPoolVersion_ImplPtr pNew = SfxPoolVersion_ImplPtr( new SfxPoolVersion_Impl( *pOld ) ); 275*cdf0e10cSrcweir pImp->aVersions.push_back( pNew ); 276*cdf0e10cSrcweir } 277*cdf0e10cSrcweir 278*cdf0e10cSrcweir // Verkettung wiederherstellen 279*cdf0e10cSrcweir if ( rPool.pSecondary ) 280*cdf0e10cSrcweir SetSecondaryPool( rPool.pSecondary->Clone() ); 281*cdf0e10cSrcweir } 282*cdf0e10cSrcweir 283*cdf0e10cSrcweir // ----------------------------------------------------------------------- 284*cdf0e10cSrcweir 285*cdf0e10cSrcweir void SfxItemPool::SetDefaults( SfxPoolItem **pDefaults ) 286*cdf0e10cSrcweir { 287*cdf0e10cSrcweir DBG_CHKTHIS(SfxItemPool, 0); 288*cdf0e10cSrcweir DBG_ASSERT( pDefaults, "erst wollen, dann nichts geben..." ); 289*cdf0e10cSrcweir DBG_ASSERT( !ppStaticDefaults, "habe schon defaults" ); 290*cdf0e10cSrcweir 291*cdf0e10cSrcweir ppStaticDefaults = pDefaults; 292*cdf0e10cSrcweir //! if ( (*ppStaticDefaults)->GetKind() != SFX_ITEMS_STATICDEFAULT ) 293*cdf0e10cSrcweir //! geht wohl nicht im Zshg mit SetItems, die hinten stehen 294*cdf0e10cSrcweir { 295*cdf0e10cSrcweir DBG_ASSERT( (*ppStaticDefaults)->GetRefCount() == 0 || 296*cdf0e10cSrcweir IsDefaultItem( (*ppStaticDefaults) ), 297*cdf0e10cSrcweir "das sind keine statics" ); 298*cdf0e10cSrcweir for ( sal_uInt16 n = 0; n <= nEnd - nStart; ++n ) 299*cdf0e10cSrcweir { 300*cdf0e10cSrcweir SFX_ASSERT( (*( ppStaticDefaults + n ))->Which() == n + nStart, 301*cdf0e10cSrcweir n + nStart, "static defaults not sorted" ); 302*cdf0e10cSrcweir (*( ppStaticDefaults + n ))->SetKind( SFX_ITEMS_STATICDEFAULT ); 303*cdf0e10cSrcweir DBG_ASSERT( !(pImp->ppPoolItems[n]), "defaults with setitems with items?!" ); 304*cdf0e10cSrcweir } 305*cdf0e10cSrcweir } 306*cdf0e10cSrcweir } 307*cdf0e10cSrcweir 308*cdf0e10cSrcweir // ----------------------------------------------------------------------- 309*cdf0e10cSrcweir 310*cdf0e10cSrcweir void SfxItemPool::ReleaseDefaults 311*cdf0e10cSrcweir ( 312*cdf0e10cSrcweir sal_Bool bDelete /* sal_True 313*cdf0e10cSrcweir l"oscht sowohl das Array als auch die einzelnen 314*cdf0e10cSrcweir statischen Defaults 315*cdf0e10cSrcweir 316*cdf0e10cSrcweir sal_False 317*cdf0e10cSrcweir l"oscht weder das Array noch die einzelnen 318*cdf0e10cSrcweir statischen Defaults */ 319*cdf0e10cSrcweir ) 320*cdf0e10cSrcweir 321*cdf0e10cSrcweir /* [Beschreibung] 322*cdf0e10cSrcweir 323*cdf0e10cSrcweir Gibt die statischen Defaults der betreffenden SfxItemPool-Instanz frei 324*cdf0e10cSrcweir und l"oscht ggf. die statischen Defaults. 325*cdf0e10cSrcweir 326*cdf0e10cSrcweir Nach Aufruf dieser Methode darf die SfxItemPool-Instanz nicht mehr 327*cdf0e10cSrcweir verwendet werden, einzig ist der Aufruf des Destruktors zu"lassig. 328*cdf0e10cSrcweir */ 329*cdf0e10cSrcweir 330*cdf0e10cSrcweir { 331*cdf0e10cSrcweir DBG_ASSERT( ppStaticDefaults, "keine Arme keine Kekse" ); 332*cdf0e10cSrcweir ReleaseDefaults( ppStaticDefaults, nEnd - nStart + 1, bDelete ); 333*cdf0e10cSrcweir 334*cdf0e10cSrcweir // KSO (22.10.98): ppStaticDefaults zeigt auf geloeschten Speicher, 335*cdf0e10cSrcweir // wenn bDelete == sal_True. 336*cdf0e10cSrcweir if ( bDelete ) 337*cdf0e10cSrcweir ppStaticDefaults = 0; 338*cdf0e10cSrcweir } 339*cdf0e10cSrcweir 340*cdf0e10cSrcweir // ----------------------------------------------------------------------- 341*cdf0e10cSrcweir 342*cdf0e10cSrcweir void SfxItemPool::ReleaseDefaults 343*cdf0e10cSrcweir ( 344*cdf0e10cSrcweir SfxPoolItem** pDefaults, /* freizugebende statische Defaults */ 345*cdf0e10cSrcweir 346*cdf0e10cSrcweir sal_uInt16 nCount, /* Anzahl der statischen Defaults */ 347*cdf0e10cSrcweir 348*cdf0e10cSrcweir sal_Bool bDelete /* sal_True 349*cdf0e10cSrcweir l"oscht sowohl das Array als auch die 350*cdf0e10cSrcweir einzelnen statischen Defaults 351*cdf0e10cSrcweir 352*cdf0e10cSrcweir sal_False 353*cdf0e10cSrcweir l"oscht weder das Array noch die 354*cdf0e10cSrcweir einzelnen statischen Defaults */ 355*cdf0e10cSrcweir ) 356*cdf0e10cSrcweir 357*cdf0e10cSrcweir /* [Beschreibung] 358*cdf0e10cSrcweir 359*cdf0e10cSrcweir Gibt die angegebenen statischen Defaults frei und l"oscht ggf. 360*cdf0e10cSrcweir die statischen Defaults. 361*cdf0e10cSrcweir 362*cdf0e10cSrcweir Diese Methode darf erst nach Zerst"orung aller SfxItemPool-Instanzen, 363*cdf0e10cSrcweir welche die angegebenen statischen Defaults 'pDefault' verwenden, 364*cdf0e10cSrcweir aufgerufen werden. 365*cdf0e10cSrcweir */ 366*cdf0e10cSrcweir 367*cdf0e10cSrcweir { 368*cdf0e10cSrcweir DBG_ASSERT( pDefaults, "erst wollen, dann nichts geben..." ); 369*cdf0e10cSrcweir 370*cdf0e10cSrcweir for ( sal_uInt16 n = 0; n < nCount; ++n ) 371*cdf0e10cSrcweir { 372*cdf0e10cSrcweir SFX_ASSERT( IsStaticDefaultItem( *(pDefaults+n) ), 373*cdf0e10cSrcweir n, "das ist kein static-default" ); 374*cdf0e10cSrcweir (*( pDefaults + n ))->SetRefCount( 0 ); 375*cdf0e10cSrcweir if ( bDelete ) 376*cdf0e10cSrcweir { delete *( pDefaults + n ); *(pDefaults + n) = 0; } 377*cdf0e10cSrcweir } 378*cdf0e10cSrcweir 379*cdf0e10cSrcweir if ( bDelete ) 380*cdf0e10cSrcweir { delete[] pDefaults; pDefaults = 0; } 381*cdf0e10cSrcweir } 382*cdf0e10cSrcweir 383*cdf0e10cSrcweir // ----------------------------------------------------------------------- 384*cdf0e10cSrcweir 385*cdf0e10cSrcweir SfxItemPool::~SfxItemPool() 386*cdf0e10cSrcweir { 387*cdf0e10cSrcweir DBG_DTOR(SfxItemPool, 0); 388*cdf0e10cSrcweir DBG_ASSERT( pMaster == this, "destroying active Secondary-Pool" ); 389*cdf0e10cSrcweir 390*cdf0e10cSrcweir if ( pImp->ppPoolItems && ppPoolDefaults ) 391*cdf0e10cSrcweir Delete(); 392*cdf0e10cSrcweir delete[] _pPoolRanges; 393*cdf0e10cSrcweir delete pImp; 394*cdf0e10cSrcweir } 395*cdf0e10cSrcweir 396*cdf0e10cSrcweir void SfxItemPool::Free(SfxItemPool* pPool) 397*cdf0e10cSrcweir { 398*cdf0e10cSrcweir if(pPool) 399*cdf0e10cSrcweir { 400*cdf0e10cSrcweir // tell all the registered SfxItemPoolUsers that the pool is in destruction 401*cdf0e10cSrcweir SfxItemPoolUserVector aListCopy(pPool->maSfxItemPoolUsers.begin(), pPool->maSfxItemPoolUsers.end()); 402*cdf0e10cSrcweir for(SfxItemPoolUserVector::iterator aIterator = aListCopy.begin(); aIterator != aListCopy.end(); aIterator++) 403*cdf0e10cSrcweir { 404*cdf0e10cSrcweir SfxItemPoolUser* pSfxItemPoolUser = *aIterator; 405*cdf0e10cSrcweir DBG_ASSERT(pSfxItemPoolUser, "corrupt SfxItemPoolUser list (!)"); 406*cdf0e10cSrcweir pSfxItemPoolUser->ObjectInDestruction(*pPool); 407*cdf0e10cSrcweir } 408*cdf0e10cSrcweir 409*cdf0e10cSrcweir // Clear the vector. This means that user do not need to call RemoveSfxItemPoolUser() 410*cdf0e10cSrcweir // when they get called from ObjectInDestruction(). 411*cdf0e10cSrcweir pPool->maSfxItemPoolUsers.clear(); 412*cdf0e10cSrcweir 413*cdf0e10cSrcweir // delete pool 414*cdf0e10cSrcweir delete pPool; 415*cdf0e10cSrcweir } 416*cdf0e10cSrcweir } 417*cdf0e10cSrcweir 418*cdf0e10cSrcweir // ----------------------------------------------------------------------- 419*cdf0e10cSrcweir 420*cdf0e10cSrcweir 421*cdf0e10cSrcweir void SfxItemPool::SetSecondaryPool( SfxItemPool *pPool ) 422*cdf0e10cSrcweir { 423*cdf0e10cSrcweir // ggf. an abgeh"angten Pools den Master zur"ucksetzen 424*cdf0e10cSrcweir if ( pSecondary ) 425*cdf0e10cSrcweir { 426*cdf0e10cSrcweir #ifdef DBG_UTIL 427*cdf0e10cSrcweir HACK( "fuer Image, dort gibt es derzeit keine Statics - Bug" ) 428*cdf0e10cSrcweir if ( ppStaticDefaults ) 429*cdf0e10cSrcweir { 430*cdf0e10cSrcweir // Delete() ist noch nicht gelaufen? 431*cdf0e10cSrcweir if ( pImp->ppPoolItems && pSecondary->pImp->ppPoolItems ) 432*cdf0e10cSrcweir { 433*cdf0e10cSrcweir // hat der master SetItems? 434*cdf0e10cSrcweir sal_Bool bHasSetItems = sal_False; 435*cdf0e10cSrcweir for ( sal_uInt16 i = 0; !bHasSetItems && i < nEnd-nStart; ++i ) 436*cdf0e10cSrcweir bHasSetItems = ppStaticDefaults[i]->ISA(SfxSetItem); 437*cdf0e10cSrcweir 438*cdf0e10cSrcweir // abgehaengte Pools muessen leer sein 439*cdf0e10cSrcweir sal_Bool bOK = bHasSetItems; 440*cdf0e10cSrcweir for ( sal_uInt16 n = 0; 441*cdf0e10cSrcweir bOK && n <= pSecondary->nEnd - pSecondary->nStart; 442*cdf0e10cSrcweir ++n ) 443*cdf0e10cSrcweir { 444*cdf0e10cSrcweir SfxPoolItemArray_Impl** ppItemArr = 445*cdf0e10cSrcweir pSecondary->pImp->ppPoolItems + n; 446*cdf0e10cSrcweir if ( *ppItemArr ) 447*cdf0e10cSrcweir { 448*cdf0e10cSrcweir SfxPoolItemArrayBase_Impl::iterator ppHtArr = (*ppItemArr)->begin(); 449*cdf0e10cSrcweir for( size_t i = (*ppItemArr)->size(); i; ++ppHtArr, --i ) 450*cdf0e10cSrcweir if ( !(*ppHtArr) ) 451*cdf0e10cSrcweir { 452*cdf0e10cSrcweir DBG_ERROR( "old secondary pool must be empty" ); 453*cdf0e10cSrcweir bOK = sal_False; 454*cdf0e10cSrcweir break; 455*cdf0e10cSrcweir } 456*cdf0e10cSrcweir } 457*cdf0e10cSrcweir } 458*cdf0e10cSrcweir } 459*cdf0e10cSrcweir } 460*cdf0e10cSrcweir #endif 461*cdf0e10cSrcweir 462*cdf0e10cSrcweir pSecondary->pMaster = pSecondary; 463*cdf0e10cSrcweir for ( SfxItemPool *p = pSecondary->pSecondary; p; p = p->pSecondary ) 464*cdf0e10cSrcweir p->pMaster = pSecondary; 465*cdf0e10cSrcweir } 466*cdf0e10cSrcweir 467*cdf0e10cSrcweir // ggf. den Master der neuen Secondary-Pools setzen 468*cdf0e10cSrcweir DBG_ASSERT( !pPool || pPool->pMaster == pPool, "Secondary tanzt auf zwei Hochzeiten " ); 469*cdf0e10cSrcweir SfxItemPool *pNewMaster = pMaster ? pMaster : this; 470*cdf0e10cSrcweir for ( SfxItemPool *p = pPool; p; p = p->pSecondary ) 471*cdf0e10cSrcweir p->pMaster = pNewMaster; 472*cdf0e10cSrcweir 473*cdf0e10cSrcweir // neuen Secondary-Pool merken 474*cdf0e10cSrcweir pSecondary = pPool; 475*cdf0e10cSrcweir } 476*cdf0e10cSrcweir 477*cdf0e10cSrcweir // ----------------------------------------------------------------------- 478*cdf0e10cSrcweir 479*cdf0e10cSrcweir SfxMapUnit SfxItemPool::GetMetric( sal_uInt16 ) const 480*cdf0e10cSrcweir { 481*cdf0e10cSrcweir DBG_CHKTHIS(SfxItemPool, 0); 482*cdf0e10cSrcweir 483*cdf0e10cSrcweir return pImp->eDefMetric; 484*cdf0e10cSrcweir } 485*cdf0e10cSrcweir 486*cdf0e10cSrcweir // ----------------------------------------------------------------------- 487*cdf0e10cSrcweir 488*cdf0e10cSrcweir void SfxItemPool::SetDefaultMetric( SfxMapUnit eNewMetric ) 489*cdf0e10cSrcweir { 490*cdf0e10cSrcweir DBG_CHKTHIS(SfxItemPool, 0); 491*cdf0e10cSrcweir 492*cdf0e10cSrcweir pImp->eDefMetric = eNewMetric; 493*cdf0e10cSrcweir } 494*cdf0e10cSrcweir 495*cdf0e10cSrcweir // ----------------------------------------------------------------------- 496*cdf0e10cSrcweir 497*cdf0e10cSrcweir SfxItemPresentation SfxItemPool::GetPresentation 498*cdf0e10cSrcweir ( 499*cdf0e10cSrcweir const SfxPoolItem& rItem, /* IN: <SfxPoolItem>, dessen textuelle 500*cdf0e10cSrcweir Wert-Darstellung geliefert werden 501*cdf0e10cSrcweir soll */ 502*cdf0e10cSrcweir SfxItemPresentation ePresent, /* IN: gew"unschte Art der Darstellung; 503*cdf0e10cSrcweir siehe <SfxItemPresentation> */ 504*cdf0e10cSrcweir SfxMapUnit eMetric, /* IN: gew"unschte Ma\seinheit der Darstellung */ 505*cdf0e10cSrcweir XubString& rText, /* OUT: textuelle Darstellung von 'rItem' */ 506*cdf0e10cSrcweir const IntlWrapper * pIntlWrapper 507*cdf0e10cSrcweir ) const 508*cdf0e10cSrcweir 509*cdf0e10cSrcweir /* [Beschreibung] 510*cdf0e10cSrcweir 511*cdf0e10cSrcweir "Uber diese virtuelle Methode k"onnen textuelle Darstellungen der 512*cdf0e10cSrcweir von der jeweilige SfxItemPool-Subklasse verwalteten SfxPoolItems 513*cdf0e10cSrcweir angefordert werden. 514*cdf0e10cSrcweir 515*cdf0e10cSrcweir In Ableitungen sollte diese Methode "uberladen werden und auf 516*cdf0e10cSrcweir SfxPoolItems reagiert werden, die bei <SfxPoolItem::GetPresentation()const> 517*cdf0e10cSrcweir keine vollst"andige Information liefern k"onnen. 518*cdf0e10cSrcweir 519*cdf0e10cSrcweir Die Basisklasse liefert die unver"anderte Presentation von 'rItem'. 520*cdf0e10cSrcweir */ 521*cdf0e10cSrcweir 522*cdf0e10cSrcweir { 523*cdf0e10cSrcweir DBG_CHKTHIS(SfxItemPool, 0); 524*cdf0e10cSrcweir return rItem.GetPresentation( 525*cdf0e10cSrcweir ePresent, GetMetric(rItem.Which()), eMetric, rText, pIntlWrapper ); 526*cdf0e10cSrcweir } 527*cdf0e10cSrcweir 528*cdf0e10cSrcweir 529*cdf0e10cSrcweir // ----------------------------------------------------------------------- 530*cdf0e10cSrcweir 531*cdf0e10cSrcweir SfxItemPool* SfxItemPool::Clone() const 532*cdf0e10cSrcweir { 533*cdf0e10cSrcweir DBG_CHKTHIS(SfxItemPool, 0); 534*cdf0e10cSrcweir 535*cdf0e10cSrcweir SfxItemPool *pPool = new SfxItemPool( *this ); 536*cdf0e10cSrcweir return pPool; 537*cdf0e10cSrcweir } 538*cdf0e10cSrcweir 539*cdf0e10cSrcweir // ---------------------------------------------------------------------- 540*cdf0e10cSrcweir 541*cdf0e10cSrcweir void SfxItemPool::Delete() 542*cdf0e10cSrcweir { 543*cdf0e10cSrcweir DBG_CHKTHIS(SfxItemPool, 0); 544*cdf0e10cSrcweir 545*cdf0e10cSrcweir // schon deleted? 546*cdf0e10cSrcweir if ( !pImp->ppPoolItems || !ppPoolDefaults ) 547*cdf0e10cSrcweir return; 548*cdf0e10cSrcweir 549*cdf0e10cSrcweir // z.B. laufenden Requests bescheidsagen 550*cdf0e10cSrcweir pImp->aBC.Broadcast( SfxSimpleHint( SFX_HINT_DYING ) ); 551*cdf0e10cSrcweir 552*cdf0e10cSrcweir //MA 16. Apr. 97: Zweimal durchlaufen, in der ersten Runde fuer die SetItems. 553*cdf0e10cSrcweir //Der Klarheit halber wird das jetzt in zwei besser lesbare Schleifen aufgeteilt. 554*cdf0e10cSrcweir 555*cdf0e10cSrcweir SfxPoolItemArray_Impl** ppItemArr = pImp->ppPoolItems; 556*cdf0e10cSrcweir SfxPoolItem** ppDefaultItem = ppPoolDefaults; 557*cdf0e10cSrcweir SfxPoolItem** ppStaticDefaultItem = ppStaticDefaults; 558*cdf0e10cSrcweir sal_uInt16 nArrCnt; 559*cdf0e10cSrcweir 560*cdf0e10cSrcweir //Erst die SetItems abraeumen 561*cdf0e10cSrcweir HACK( "fuer Image, dort gibt es derzeit keine Statics - Bug" ) 562*cdf0e10cSrcweir if ( ppStaticDefaults ) 563*cdf0e10cSrcweir { 564*cdf0e10cSrcweir for ( nArrCnt = GetSize_Impl(); 565*cdf0e10cSrcweir nArrCnt; 566*cdf0e10cSrcweir --nArrCnt, ++ppItemArr, ++ppDefaultItem, ++ppStaticDefaultItem ) 567*cdf0e10cSrcweir { 568*cdf0e10cSrcweir // KSO (22.10.98): *ppStaticDefaultItem kann im dtor einer 569*cdf0e10cSrcweir // von SfxItemPool abgeleiteten Klasse bereits geloescht worden 570*cdf0e10cSrcweir // sein! -> CHAOS Itempool 571*cdf0e10cSrcweir if ( *ppStaticDefaultItem && (*ppStaticDefaultItem)->ISA(SfxSetItem) ) 572*cdf0e10cSrcweir { 573*cdf0e10cSrcweir if ( *ppItemArr ) 574*cdf0e10cSrcweir { 575*cdf0e10cSrcweir SfxPoolItemArrayBase_Impl::iterator ppHtArr = (*ppItemArr)->begin(); 576*cdf0e10cSrcweir for ( size_t n = (*ppItemArr)->size(); n; --n, ++ppHtArr ) 577*cdf0e10cSrcweir if (*ppHtArr) 578*cdf0e10cSrcweir { 579*cdf0e10cSrcweir #ifdef DBG_UTIL 580*cdf0e10cSrcweir ReleaseRef( **ppHtArr, (*ppHtArr)->GetRefCount() ); 581*cdf0e10cSrcweir #endif 582*cdf0e10cSrcweir delete *ppHtArr; 583*cdf0e10cSrcweir } 584*cdf0e10cSrcweir DELETEZ( *ppItemArr ); 585*cdf0e10cSrcweir } 586*cdf0e10cSrcweir if ( *ppDefaultItem ) 587*cdf0e10cSrcweir { 588*cdf0e10cSrcweir #ifdef DBG_UTIL 589*cdf0e10cSrcweir SetRefCount( **ppDefaultItem, 0 ); 590*cdf0e10cSrcweir #endif 591*cdf0e10cSrcweir DELETEZ( *ppDefaultItem ); 592*cdf0e10cSrcweir } 593*cdf0e10cSrcweir } 594*cdf0e10cSrcweir } 595*cdf0e10cSrcweir } 596*cdf0e10cSrcweir 597*cdf0e10cSrcweir ppItemArr = pImp->ppPoolItems; 598*cdf0e10cSrcweir ppDefaultItem = ppPoolDefaults; 599*cdf0e10cSrcweir 600*cdf0e10cSrcweir //Jetzt die 'einfachen' Items 601*cdf0e10cSrcweir for ( nArrCnt = GetSize_Impl(); 602*cdf0e10cSrcweir nArrCnt; 603*cdf0e10cSrcweir --nArrCnt, ++ppItemArr, ++ppDefaultItem ) 604*cdf0e10cSrcweir { 605*cdf0e10cSrcweir if ( *ppItemArr ) 606*cdf0e10cSrcweir { 607*cdf0e10cSrcweir SfxPoolItemArrayBase_Impl::iterator ppHtArr = (*ppItemArr)->begin(); 608*cdf0e10cSrcweir for ( size_t n = (*ppItemArr)->size(); n; --n, ++ppHtArr ) 609*cdf0e10cSrcweir if (*ppHtArr) 610*cdf0e10cSrcweir { 611*cdf0e10cSrcweir #ifdef DBG_UTIL 612*cdf0e10cSrcweir ReleaseRef( **ppHtArr, (*ppHtArr)->GetRefCount() ); 613*cdf0e10cSrcweir #endif 614*cdf0e10cSrcweir delete *ppHtArr; 615*cdf0e10cSrcweir } 616*cdf0e10cSrcweir delete *ppItemArr; 617*cdf0e10cSrcweir } 618*cdf0e10cSrcweir if ( *ppDefaultItem ) 619*cdf0e10cSrcweir { 620*cdf0e10cSrcweir #ifdef DBG_UTIL 621*cdf0e10cSrcweir SetRefCount( **ppDefaultItem, 0 ); 622*cdf0e10cSrcweir #endif 623*cdf0e10cSrcweir delete *ppDefaultItem; 624*cdf0e10cSrcweir } 625*cdf0e10cSrcweir } 626*cdf0e10cSrcweir 627*cdf0e10cSrcweir pImp->DeleteItems(); 628*cdf0e10cSrcweir delete[] ppPoolDefaults; ppPoolDefaults = 0; 629*cdf0e10cSrcweir } 630*cdf0e10cSrcweir 631*cdf0e10cSrcweir // ---------------------------------------------------------------------- 632*cdf0e10cSrcweir 633*cdf0e10cSrcweir void SfxItemPool::Cleanup() 634*cdf0e10cSrcweir { 635*cdf0e10cSrcweir DBG_CHKTHIS(SfxItemPool, 0); 636*cdf0e10cSrcweir 637*cdf0e10cSrcweir //MA 16. Apr. 97: siehe ::Delete() 638*cdf0e10cSrcweir 639*cdf0e10cSrcweir SfxPoolItemArray_Impl** ppItemArr = pImp->ppPoolItems; 640*cdf0e10cSrcweir SfxPoolItem** ppDefaultItem = ppPoolDefaults; 641*cdf0e10cSrcweir SfxPoolItem** ppStaticDefaultItem = ppStaticDefaults; 642*cdf0e10cSrcweir sal_uInt16 nArrCnt; 643*cdf0e10cSrcweir 644*cdf0e10cSrcweir HACK( "fuer Image, dort gibt es derzeit keine Statics - Bug" ) 645*cdf0e10cSrcweir if ( ppStaticDefaults ) //HACK fuer Image, dort gibt es keine Statics!! 646*cdf0e10cSrcweir { 647*cdf0e10cSrcweir for ( nArrCnt = GetSize_Impl(); 648*cdf0e10cSrcweir nArrCnt; 649*cdf0e10cSrcweir --nArrCnt, ++ppItemArr, ++ppDefaultItem, ++ppStaticDefaultItem ) 650*cdf0e10cSrcweir { 651*cdf0e10cSrcweir //Fuer jedes Item gibt es entweder ein Default oder ein static Default! 652*cdf0e10cSrcweir if ( *ppItemArr && 653*cdf0e10cSrcweir ((*ppDefaultItem && (*ppDefaultItem)->ISA(SfxSetItem)) || 654*cdf0e10cSrcweir (*ppStaticDefaultItem)->ISA(SfxSetItem)) ) 655*cdf0e10cSrcweir { 656*cdf0e10cSrcweir SfxPoolItemArrayBase_Impl::iterator ppHtArr = (*ppItemArr)->begin(); 657*cdf0e10cSrcweir for ( size_t n = (*ppItemArr)->size(); n; --n, ++ppHtArr ) 658*cdf0e10cSrcweir if ( *ppHtArr && !(*ppHtArr)->GetRefCount() ) 659*cdf0e10cSrcweir { 660*cdf0e10cSrcweir DELETEZ(*ppHtArr); 661*cdf0e10cSrcweir } 662*cdf0e10cSrcweir } 663*cdf0e10cSrcweir } 664*cdf0e10cSrcweir } 665*cdf0e10cSrcweir 666*cdf0e10cSrcweir ppItemArr = pImp->ppPoolItems; 667*cdf0e10cSrcweir 668*cdf0e10cSrcweir for ( nArrCnt = GetSize_Impl(); 669*cdf0e10cSrcweir nArrCnt; 670*cdf0e10cSrcweir --nArrCnt, ++ppItemArr ) 671*cdf0e10cSrcweir { 672*cdf0e10cSrcweir if ( *ppItemArr ) 673*cdf0e10cSrcweir { 674*cdf0e10cSrcweir SfxPoolItemArrayBase_Impl::iterator ppHtArr = (*ppItemArr)->begin(); 675*cdf0e10cSrcweir for ( size_t n = (*ppItemArr)->size(); n; --n, ++ppHtArr ) 676*cdf0e10cSrcweir if ( *ppHtArr && !(*ppHtArr)->GetRefCount() ) 677*cdf0e10cSrcweir DELETEZ( *ppHtArr ); 678*cdf0e10cSrcweir } 679*cdf0e10cSrcweir } 680*cdf0e10cSrcweir } 681*cdf0e10cSrcweir 682*cdf0e10cSrcweir // ---------------------------------------------------------------------- 683*cdf0e10cSrcweir 684*cdf0e10cSrcweir void SfxItemPool::SetPoolDefaultItem(const SfxPoolItem &rItem) 685*cdf0e10cSrcweir { 686*cdf0e10cSrcweir DBG_CHKTHIS(SfxItemPool, 0); 687*cdf0e10cSrcweir if ( IsInRange(rItem.Which()) ) 688*cdf0e10cSrcweir { 689*cdf0e10cSrcweir SfxPoolItem **ppOldDefault = 690*cdf0e10cSrcweir ppPoolDefaults + GetIndex_Impl(rItem.Which()); 691*cdf0e10cSrcweir SfxPoolItem *pNewDefault = rItem.Clone(this); 692*cdf0e10cSrcweir pNewDefault->SetKind(SFX_ITEMS_POOLDEFAULT); 693*cdf0e10cSrcweir if ( *ppOldDefault ) 694*cdf0e10cSrcweir { 695*cdf0e10cSrcweir (*ppOldDefault)->SetRefCount(0); 696*cdf0e10cSrcweir DELETEZ( *ppOldDefault ); 697*cdf0e10cSrcweir } 698*cdf0e10cSrcweir *ppOldDefault = pNewDefault; 699*cdf0e10cSrcweir } 700*cdf0e10cSrcweir else if ( pSecondary ) 701*cdf0e10cSrcweir pSecondary->SetPoolDefaultItem(rItem); 702*cdf0e10cSrcweir else 703*cdf0e10cSrcweir { 704*cdf0e10cSrcweir SFX_ASSERT( 0, rItem.Which(), "unknown Which-Id - cannot set pool default" ); 705*cdf0e10cSrcweir } 706*cdf0e10cSrcweir } 707*cdf0e10cSrcweir 708*cdf0e10cSrcweir /* 709*cdf0e10cSrcweir * Resets the default of the given <Which-Id> back to the static default. 710*cdf0e10cSrcweir * If a pool default exists it is removed. 711*cdf0e10cSrcweir */ 712*cdf0e10cSrcweir void SfxItemPool::ResetPoolDefaultItem( sal_uInt16 nWhichId ) 713*cdf0e10cSrcweir { 714*cdf0e10cSrcweir DBG_CHKTHIS(SfxItemPool, 0); 715*cdf0e10cSrcweir if ( IsInRange(nWhichId) ) 716*cdf0e10cSrcweir { 717*cdf0e10cSrcweir SfxPoolItem **ppOldDefault = 718*cdf0e10cSrcweir ppPoolDefaults + GetIndex_Impl( nWhichId ); 719*cdf0e10cSrcweir if ( *ppOldDefault ) 720*cdf0e10cSrcweir { 721*cdf0e10cSrcweir (*ppOldDefault)->SetRefCount(0); 722*cdf0e10cSrcweir DELETEZ( *ppOldDefault ); 723*cdf0e10cSrcweir } 724*cdf0e10cSrcweir } 725*cdf0e10cSrcweir else if ( pSecondary ) 726*cdf0e10cSrcweir pSecondary->ResetPoolDefaultItem(nWhichId); 727*cdf0e10cSrcweir else 728*cdf0e10cSrcweir { 729*cdf0e10cSrcweir SFX_ASSERT( 0, nWhichId, "unknown Which-Id - cannot set pool default" ); 730*cdf0e10cSrcweir } 731*cdf0e10cSrcweir } 732*cdf0e10cSrcweir 733*cdf0e10cSrcweir // ----------------------------------------------------------------------- 734*cdf0e10cSrcweir 735*cdf0e10cSrcweir const SfxPoolItem& SfxItemPool::Put( const SfxPoolItem& rItem, sal_uInt16 nWhich ) 736*cdf0e10cSrcweir { 737*cdf0e10cSrcweir DBG_ASSERT( !rItem.ISA(SfxSetItem) || 738*cdf0e10cSrcweir 0 != &((const SfxSetItem&)rItem).GetItemSet(), 739*cdf0e10cSrcweir "SetItem without ItemSet" ); 740*cdf0e10cSrcweir 741*cdf0e10cSrcweir DBG_CHKTHIS(SfxItemPool, 0); 742*cdf0e10cSrcweir if ( 0 == nWhich ) 743*cdf0e10cSrcweir nWhich = rItem.Which(); 744*cdf0e10cSrcweir 745*cdf0e10cSrcweir // richtigen Secondary-Pool finden 746*cdf0e10cSrcweir sal_Bool bSID = nWhich > SFX_WHICH_MAX; 747*cdf0e10cSrcweir if ( !bSID && !IsInRange(nWhich) ) 748*cdf0e10cSrcweir { 749*cdf0e10cSrcweir if ( pSecondary ) 750*cdf0e10cSrcweir return pSecondary->Put( rItem, nWhich ); 751*cdf0e10cSrcweir DBG_ERROR( "unknown Which-Id - cannot put item" ); 752*cdf0e10cSrcweir } 753*cdf0e10cSrcweir 754*cdf0e10cSrcweir // SID oder nicht poolable (neue Definition)? 755*cdf0e10cSrcweir sal_uInt16 nIndex = bSID ? USHRT_MAX : GetIndex_Impl(nWhich); 756*cdf0e10cSrcweir if ( USHRT_MAX == nIndex || 757*cdf0e10cSrcweir IsItemFlag_Impl( nIndex, SFX_ITEM_NOT_POOLABLE ) ) 758*cdf0e10cSrcweir { 759*cdf0e10cSrcweir SFX_ASSERT( USHRT_MAX != nIndex || rItem.Which() != nWhich || 760*cdf0e10cSrcweir !IsDefaultItem(&rItem) || rItem.GetKind() == SFX_ITEMS_DELETEONIDLE, 761*cdf0e10cSrcweir nWhich, "ein nicht Pool-Item ist Default?!" ); 762*cdf0e10cSrcweir SfxPoolItem *pPoolItem = rItem.Clone(pMaster); 763*cdf0e10cSrcweir pPoolItem->SetWhich(nWhich); 764*cdf0e10cSrcweir AddRef( *pPoolItem ); 765*cdf0e10cSrcweir return *pPoolItem; 766*cdf0e10cSrcweir } 767*cdf0e10cSrcweir 768*cdf0e10cSrcweir SFX_ASSERT( rItem.IsA(GetDefaultItem(nWhich).Type()), nWhich, 769*cdf0e10cSrcweir "SFxItemPool: wrong item type in Put" ); 770*cdf0e10cSrcweir 771*cdf0e10cSrcweir SfxPoolItemArray_Impl** ppItemArr = pImp->ppPoolItems + nIndex; 772*cdf0e10cSrcweir if( !*ppItemArr ) 773*cdf0e10cSrcweir *ppItemArr = new SfxPoolItemArray_Impl; 774*cdf0e10cSrcweir 775*cdf0e10cSrcweir SfxPoolItemArrayBase_Impl::iterator ppFree; 776*cdf0e10cSrcweir sal_Bool ppFreeIsSet = sal_False; 777*cdf0e10cSrcweir SfxPoolItemArrayBase_Impl::iterator ppHtArray = (*ppItemArr)->begin(); 778*cdf0e10cSrcweir if ( IsItemFlag_Impl( nIndex, SFX_ITEM_POOLABLE ) ) 779*cdf0e10cSrcweir { 780*cdf0e10cSrcweir // wenn es ueberhaupt gepoolt ist, koennte es schon drin sein 781*cdf0e10cSrcweir if ( IsPooledItem(&rItem) ) 782*cdf0e10cSrcweir { 783*cdf0e10cSrcweir // 1. Schleife: teste ob der Pointer vorhanden ist. 784*cdf0e10cSrcweir for( size_t n = (*ppItemArr)->size(); n; ++ppHtArray, --n ) 785*cdf0e10cSrcweir if( &rItem == (*ppHtArray) ) 786*cdf0e10cSrcweir { 787*cdf0e10cSrcweir AddRef( **ppHtArray ); 788*cdf0e10cSrcweir return **ppHtArray; 789*cdf0e10cSrcweir } 790*cdf0e10cSrcweir } 791*cdf0e10cSrcweir 792*cdf0e10cSrcweir // 2. Schleife: dann muessen eben die Attribute verglichen werden 793*cdf0e10cSrcweir size_t n; 794*cdf0e10cSrcweir for ( n = (*ppItemArr)->size(), ppHtArray = (*ppItemArr)->begin(); 795*cdf0e10cSrcweir n; ++ppHtArray, --n ) 796*cdf0e10cSrcweir { 797*cdf0e10cSrcweir if ( *ppHtArray ) 798*cdf0e10cSrcweir { 799*cdf0e10cSrcweir if( **ppHtArray == rItem ) 800*cdf0e10cSrcweir { 801*cdf0e10cSrcweir AddRef( **ppHtArray ); 802*cdf0e10cSrcweir return **ppHtArray; 803*cdf0e10cSrcweir } 804*cdf0e10cSrcweir } 805*cdf0e10cSrcweir else 806*cdf0e10cSrcweir if ( ppFreeIsSet == sal_False ) 807*cdf0e10cSrcweir { 808*cdf0e10cSrcweir ppFree = ppHtArray; 809*cdf0e10cSrcweir ppFreeIsSet = sal_True; 810*cdf0e10cSrcweir } 811*cdf0e10cSrcweir } 812*cdf0e10cSrcweir } 813*cdf0e10cSrcweir else 814*cdf0e10cSrcweir { 815*cdf0e10cSrcweir // freien Platz suchen 816*cdf0e10cSrcweir SfxPoolItemArrayBase_Impl::iterator ppHtArr; 817*cdf0e10cSrcweir size_t n, nCount = (*ppItemArr)->size(); 818*cdf0e10cSrcweir for ( n = (*ppItemArr)->nFirstFree, 819*cdf0e10cSrcweir ppHtArr = (*ppItemArr)->begin() + n; 820*cdf0e10cSrcweir n < nCount; 821*cdf0e10cSrcweir ++ppHtArr, ++n ) 822*cdf0e10cSrcweir if ( !*ppHtArr ) 823*cdf0e10cSrcweir { 824*cdf0e10cSrcweir ppFree = ppHtArr; 825*cdf0e10cSrcweir ppFreeIsSet = sal_True; 826*cdf0e10cSrcweir break; 827*cdf0e10cSrcweir } 828*cdf0e10cSrcweir 829*cdf0e10cSrcweir // naechstmoeglichen freien Platz merken 830*cdf0e10cSrcweir (*ppItemArr)->nFirstFree = n; 831*cdf0e10cSrcweir } 832*cdf0e10cSrcweir 833*cdf0e10cSrcweir // nicht vorhanden, also im PtrArray eintragen 834*cdf0e10cSrcweir SfxPoolItem* pNewItem = rItem.Clone(pMaster); 835*cdf0e10cSrcweir pNewItem->SetWhich(nWhich); 836*cdf0e10cSrcweir #ifdef DBG_UTIL 837*cdf0e10cSrcweir SFX_ASSERT( rItem.Type() == pNewItem->Type(), nWhich, "unequal types in Put(): no Clone()?" ) 838*cdf0e10cSrcweir #ifdef TF_POOLABLE 839*cdf0e10cSrcweir if ( !rItem.ISA(SfxSetItem) ) 840*cdf0e10cSrcweir { 841*cdf0e10cSrcweir SFX_ASSERT( !IsItemFlag(nWhich, SFX_ITEM_POOLABLE) || 842*cdf0e10cSrcweir rItem == *pNewItem, 843*cdf0e10cSrcweir nWhich, "unequal items in Put(): no operator==?" ); 844*cdf0e10cSrcweir SFX_ASSERT( !IsItemFlag(*pNewItem, SFX_ITEM_POOLABLE) || 845*cdf0e10cSrcweir *pNewItem == rItem, 846*cdf0e10cSrcweir nWhich, "unequal items in Put(): no operator==?" ); 847*cdf0e10cSrcweir } 848*cdf0e10cSrcweir #endif 849*cdf0e10cSrcweir #endif 850*cdf0e10cSrcweir AddRef( *pNewItem, pImp->nInitRefCount ); 851*cdf0e10cSrcweir SfxPoolItem* pTemp = pNewItem; 852*cdf0e10cSrcweir if ( ppFreeIsSet == sal_False ) 853*cdf0e10cSrcweir (*ppItemArr)->push_back( pTemp ); 854*cdf0e10cSrcweir else 855*cdf0e10cSrcweir { 856*cdf0e10cSrcweir DBG_ASSERT( *ppFree == 0, "using surrogate in use" ); 857*cdf0e10cSrcweir *ppFree = pNewItem; 858*cdf0e10cSrcweir } 859*cdf0e10cSrcweir return *pNewItem; 860*cdf0e10cSrcweir } 861*cdf0e10cSrcweir 862*cdf0e10cSrcweir // ----------------------------------------------------------------------- 863*cdf0e10cSrcweir 864*cdf0e10cSrcweir void SfxItemPool::Remove( const SfxPoolItem& rItem ) 865*cdf0e10cSrcweir { 866*cdf0e10cSrcweir DBG_CHKTHIS(SfxItemPool, 0); 867*cdf0e10cSrcweir 868*cdf0e10cSrcweir DBG_ASSERT( !rItem.ISA(SfxSetItem) || 869*cdf0e10cSrcweir 0 != &((const SfxSetItem&)rItem).GetItemSet(), 870*cdf0e10cSrcweir "SetItem without ItemSet" ); 871*cdf0e10cSrcweir 872*cdf0e10cSrcweir SFX_ASSERT( !IsPoolDefaultItem(&rItem), rItem.Which(), 873*cdf0e10cSrcweir "wo kommt denn hier ein Pool-Default her" ); 874*cdf0e10cSrcweir 875*cdf0e10cSrcweir // richtigen Secondary-Pool finden 876*cdf0e10cSrcweir const sal_uInt16 nWhich = rItem.Which(); 877*cdf0e10cSrcweir sal_Bool bSID = nWhich > SFX_WHICH_MAX; 878*cdf0e10cSrcweir if ( !bSID && !IsInRange(nWhich) ) 879*cdf0e10cSrcweir { 880*cdf0e10cSrcweir if ( pSecondary ) 881*cdf0e10cSrcweir { 882*cdf0e10cSrcweir pSecondary->Remove( rItem ); 883*cdf0e10cSrcweir return; 884*cdf0e10cSrcweir } 885*cdf0e10cSrcweir DBG_ERROR( "unknown Which-Id - cannot remove item" ); 886*cdf0e10cSrcweir } 887*cdf0e10cSrcweir 888*cdf0e10cSrcweir // SID oder nicht poolable (neue Definition)? 889*cdf0e10cSrcweir sal_uInt16 nIndex = bSID ? USHRT_MAX : GetIndex_Impl(nWhich); 890*cdf0e10cSrcweir if ( bSID || IsItemFlag_Impl( nIndex, SFX_ITEM_NOT_POOLABLE ) ) 891*cdf0e10cSrcweir { 892*cdf0e10cSrcweir SFX_ASSERT( USHRT_MAX != nIndex || 893*cdf0e10cSrcweir !IsDefaultItem(&rItem), rItem.Which(), 894*cdf0e10cSrcweir "ein nicht Pool-Item ist Default?!" ); 895*cdf0e10cSrcweir if ( 0 == ReleaseRef(rItem) ) 896*cdf0e10cSrcweir { 897*cdf0e10cSrcweir SfxPoolItem *pItem = &(SfxPoolItem &)rItem; 898*cdf0e10cSrcweir delete pItem; 899*cdf0e10cSrcweir } 900*cdf0e10cSrcweir return; 901*cdf0e10cSrcweir } 902*cdf0e10cSrcweir 903*cdf0e10cSrcweir SFX_ASSERT( rItem.GetRefCount(), rItem.Which(), "RefCount == 0, Remove unmoeglich" ); 904*cdf0e10cSrcweir 905*cdf0e10cSrcweir // statische Defaults sind eben einfach da 906*cdf0e10cSrcweir if ( rItem.GetKind() == SFX_ITEMS_STATICDEFAULT && 907*cdf0e10cSrcweir &rItem == *( ppStaticDefaults + GetIndex_Impl(nWhich) ) ) 908*cdf0e10cSrcweir return; 909*cdf0e10cSrcweir 910*cdf0e10cSrcweir // Item im eigenen Pool suchen 911*cdf0e10cSrcweir SfxPoolItemArray_Impl** ppItemArr = (pImp->ppPoolItems + nIndex); 912*cdf0e10cSrcweir SFX_ASSERT( *ppItemArr, rItem.Which(), "removing Item not in Pool" ); 913*cdf0e10cSrcweir SfxPoolItemArrayBase_Impl::iterator ppHtArr = (*ppItemArr)->begin(); 914*cdf0e10cSrcweir for( size_t n = (*ppItemArr)->size(); n; ++ppHtArr, --n ) 915*cdf0e10cSrcweir if( *ppHtArr == &rItem ) 916*cdf0e10cSrcweir { 917*cdf0e10cSrcweir if ( (*ppHtArr)->GetRefCount() ) //! 918*cdf0e10cSrcweir ReleaseRef( **ppHtArr ); 919*cdf0e10cSrcweir else 920*cdf0e10cSrcweir { 921*cdf0e10cSrcweir SFX_ASSERT( 0, rItem.Which(), "removing Item without ref" ); 922*cdf0e10cSrcweir SFX_TRACE( "to be removed, but not no refs: ", *ppHtArr ); 923*cdf0e10cSrcweir } 924*cdf0e10cSrcweir 925*cdf0e10cSrcweir // ggf. kleinstmoegliche freie Position merken 926*cdf0e10cSrcweir size_t nPos = (*ppItemArr)->size() - n; 927*cdf0e10cSrcweir if ( (*ppItemArr)->nFirstFree > nPos ) 928*cdf0e10cSrcweir (*ppItemArr)->nFirstFree = nPos; 929*cdf0e10cSrcweir 930*cdf0e10cSrcweir //! MI: Hack, solange wir das Problem mit dem Outliner haben 931*cdf0e10cSrcweir //! siehe anderes MI-REF 932*cdf0e10cSrcweir if ( 0 == (*ppHtArr)->GetRefCount() && nWhich < 4000 ) 933*cdf0e10cSrcweir DELETEZ(*ppHtArr); 934*cdf0e10cSrcweir return; 935*cdf0e10cSrcweir } 936*cdf0e10cSrcweir 937*cdf0e10cSrcweir // nicht vorhanden 938*cdf0e10cSrcweir SFX_ASSERT( 0, rItem.Which(), "removing Item not in Pool" ); 939*cdf0e10cSrcweir SFX_TRACE( "to be removed, but not in pool: ", &rItem ); 940*cdf0e10cSrcweir } 941*cdf0e10cSrcweir 942*cdf0e10cSrcweir // ----------------------------------------------------------------------- 943*cdf0e10cSrcweir 944*cdf0e10cSrcweir const SfxPoolItem& SfxItemPool::GetDefaultItem( sal_uInt16 nWhich ) const 945*cdf0e10cSrcweir { 946*cdf0e10cSrcweir DBG_CHKTHIS(SfxItemPool, 0); 947*cdf0e10cSrcweir 948*cdf0e10cSrcweir if ( !IsInRange(nWhich) ) 949*cdf0e10cSrcweir { 950*cdf0e10cSrcweir if ( pSecondary ) 951*cdf0e10cSrcweir return pSecondary->GetDefaultItem( nWhich ); 952*cdf0e10cSrcweir SFX_ASSERT( 0, nWhich, "unknown which - dont ask me for defaults" ); 953*cdf0e10cSrcweir } 954*cdf0e10cSrcweir 955*cdf0e10cSrcweir DBG_ASSERT( ppStaticDefaults, "no defaults known - dont ask me for defaults" ); 956*cdf0e10cSrcweir sal_uInt16 nPos = GetIndex_Impl(nWhich); 957*cdf0e10cSrcweir SfxPoolItem *pDefault = *(ppPoolDefaults + nPos); 958*cdf0e10cSrcweir if ( pDefault ) 959*cdf0e10cSrcweir return *pDefault; 960*cdf0e10cSrcweir return **(ppStaticDefaults + nPos); 961*cdf0e10cSrcweir } 962*cdf0e10cSrcweir 963*cdf0e10cSrcweir // ----------------------------------------------------------------------- 964*cdf0e10cSrcweir 965*cdf0e10cSrcweir 966*cdf0e10cSrcweir void SfxItemPool::FreezeIdRanges() 967*cdf0e10cSrcweir 968*cdf0e10cSrcweir /* [Beschreibung] 969*cdf0e10cSrcweir 970*cdf0e10cSrcweir This method should be called at the master pool, when all secondary 971*cdf0e10cSrcweir pools are appended to it. 972*cdf0e10cSrcweir 973*cdf0e10cSrcweir It calculates the ranges of 'which-ids' for fast construction of 974*cdf0e10cSrcweir item-sets, which contains all 'which-ids'. 975*cdf0e10cSrcweir */ 976*cdf0e10cSrcweir 977*cdf0e10cSrcweir { 978*cdf0e10cSrcweir FillItemIdRanges_Impl( _pPoolRanges ); 979*cdf0e10cSrcweir } 980*cdf0e10cSrcweir 981*cdf0e10cSrcweir 982*cdf0e10cSrcweir // ----------------------------------------------------------------------- 983*cdf0e10cSrcweir 984*cdf0e10cSrcweir void SfxItemPool::FillItemIdRanges_Impl( sal_uInt16*& pWhichRanges ) const 985*cdf0e10cSrcweir { 986*cdf0e10cSrcweir DBG_CHKTHIS(SfxItemPool, 0); 987*cdf0e10cSrcweir DBG_ASSERT( !_pPoolRanges, "GetFrozenRanges() would be faster!" ); 988*cdf0e10cSrcweir 989*cdf0e10cSrcweir const SfxItemPool *pPool; 990*cdf0e10cSrcweir sal_uInt16 nLevel = 0; 991*cdf0e10cSrcweir for( pPool = this; pPool; pPool = pPool->pSecondary ) 992*cdf0e10cSrcweir ++nLevel; 993*cdf0e10cSrcweir 994*cdf0e10cSrcweir pWhichRanges = new sal_uInt16[ 2*nLevel + 1 ]; 995*cdf0e10cSrcweir 996*cdf0e10cSrcweir nLevel = 0; 997*cdf0e10cSrcweir for( pPool = this; pPool; pPool = pPool->pSecondary ) 998*cdf0e10cSrcweir { 999*cdf0e10cSrcweir *(pWhichRanges+(nLevel++)) = pPool->nStart; 1000*cdf0e10cSrcweir *(pWhichRanges+(nLevel++)) = pPool->nEnd; 1001*cdf0e10cSrcweir *(pWhichRanges+nLevel) = 0; 1002*cdf0e10cSrcweir } 1003*cdf0e10cSrcweir } 1004*cdf0e10cSrcweir 1005*cdf0e10cSrcweir // ----------------------------------------------------------------------- 1006*cdf0e10cSrcweir 1007*cdf0e10cSrcweir const SfxPoolItem *SfxItemPool::GetItem2(sal_uInt16 nWhich, sal_uInt32 nOfst) const 1008*cdf0e10cSrcweir { 1009*cdf0e10cSrcweir DBG_CHKTHIS(SfxItemPool, 0); 1010*cdf0e10cSrcweir 1011*cdf0e10cSrcweir if ( !IsInRange(nWhich) ) 1012*cdf0e10cSrcweir { 1013*cdf0e10cSrcweir if ( pSecondary ) 1014*cdf0e10cSrcweir return pSecondary->GetItem2( nWhich, nOfst ); 1015*cdf0e10cSrcweir SFX_ASSERT( 0, nWhich, "unknown Which-Id - cannot resolve surrogate" ); 1016*cdf0e10cSrcweir return 0; 1017*cdf0e10cSrcweir } 1018*cdf0e10cSrcweir 1019*cdf0e10cSrcweir // dflt-Attribut? 1020*cdf0e10cSrcweir if ( nOfst == SFX_ITEMS_DEFAULT ) 1021*cdf0e10cSrcweir return *(ppStaticDefaults + GetIndex_Impl(nWhich)); 1022*cdf0e10cSrcweir 1023*cdf0e10cSrcweir SfxPoolItemArray_Impl* pItemArr = *(pImp->ppPoolItems + GetIndex_Impl(nWhich)); 1024*cdf0e10cSrcweir if( pItemArr && nOfst < pItemArr->size() ) 1025*cdf0e10cSrcweir return (*pItemArr)[nOfst]; 1026*cdf0e10cSrcweir 1027*cdf0e10cSrcweir return 0; 1028*cdf0e10cSrcweir } 1029*cdf0e10cSrcweir 1030*cdf0e10cSrcweir // ----------------------------------------------------------------------- 1031*cdf0e10cSrcweir 1032*cdf0e10cSrcweir sal_uInt32 SfxItemPool::GetItemCount2(sal_uInt16 nWhich) const 1033*cdf0e10cSrcweir { 1034*cdf0e10cSrcweir DBG_CHKTHIS(SfxItemPool, 0); 1035*cdf0e10cSrcweir 1036*cdf0e10cSrcweir if ( !IsInRange(nWhich) ) 1037*cdf0e10cSrcweir { 1038*cdf0e10cSrcweir if ( pSecondary ) 1039*cdf0e10cSrcweir return pSecondary->GetItemCount2( nWhich ); 1040*cdf0e10cSrcweir SFX_ASSERT( 0, nWhich, "unknown Which-Id - cannot resolve surrogate" ); 1041*cdf0e10cSrcweir return 0; 1042*cdf0e10cSrcweir } 1043*cdf0e10cSrcweir 1044*cdf0e10cSrcweir SfxPoolItemArray_Impl* pItemArr = *(pImp->ppPoolItems + GetIndex_Impl(nWhich)); 1045*cdf0e10cSrcweir if ( pItemArr ) 1046*cdf0e10cSrcweir return pItemArr->size(); 1047*cdf0e10cSrcweir return 0; 1048*cdf0e10cSrcweir } 1049*cdf0e10cSrcweir 1050*cdf0e10cSrcweir // ----------------------------------------------------------------------- 1051*cdf0e10cSrcweir 1052*cdf0e10cSrcweir sal_uInt16 SfxItemPool::GetWhich( sal_uInt16 nSlotId, sal_Bool bDeep ) const 1053*cdf0e10cSrcweir { 1054*cdf0e10cSrcweir if ( !IsSlot(nSlotId) ) 1055*cdf0e10cSrcweir return nSlotId; 1056*cdf0e10cSrcweir 1057*cdf0e10cSrcweir #ifdef TF_POOLABLE 1058*cdf0e10cSrcweir sal_uInt16 nCount = nEnd - nStart + 1; 1059*cdf0e10cSrcweir for ( sal_uInt16 nOfs = 0; nOfs < nCount; ++nOfs ) 1060*cdf0e10cSrcweir if ( pItemInfos[nOfs]._nSID == nSlotId ) 1061*cdf0e10cSrcweir return nOfs + nStart; 1062*cdf0e10cSrcweir #else 1063*cdf0e10cSrcweir if ( pSlotIds ) 1064*cdf0e10cSrcweir { 1065*cdf0e10cSrcweir sal_uInt16 nCount = nEnd - nStart + 1; 1066*cdf0e10cSrcweir for ( sal_uInt16 nOfs = 0; nOfs < nCount; ++nOfs ) 1067*cdf0e10cSrcweir if ( pSlotIds[nOfs] == nSlotId ) 1068*cdf0e10cSrcweir return nOfs + nStart; 1069*cdf0e10cSrcweir } 1070*cdf0e10cSrcweir #endif 1071*cdf0e10cSrcweir if ( pSecondary && bDeep ) 1072*cdf0e10cSrcweir return pSecondary->GetWhich(nSlotId); 1073*cdf0e10cSrcweir return nSlotId; 1074*cdf0e10cSrcweir } 1075*cdf0e10cSrcweir 1076*cdf0e10cSrcweir // ----------------------------------------------------------------------- 1077*cdf0e10cSrcweir 1078*cdf0e10cSrcweir sal_uInt16 SfxItemPool::GetSlotId( sal_uInt16 nWhich, sal_Bool bDeep ) const 1079*cdf0e10cSrcweir { 1080*cdf0e10cSrcweir if ( !IsWhich(nWhich) ) 1081*cdf0e10cSrcweir return nWhich; 1082*cdf0e10cSrcweir 1083*cdf0e10cSrcweir if ( !IsInRange( nWhich ) ) 1084*cdf0e10cSrcweir { 1085*cdf0e10cSrcweir if ( pSecondary && bDeep ) 1086*cdf0e10cSrcweir return pSecondary->GetSlotId(nWhich); 1087*cdf0e10cSrcweir SFX_ASSERT( 0, nWhich, "unknown Which-Id - cannot get slot-id" ); 1088*cdf0e10cSrcweir return 0; 1089*cdf0e10cSrcweir } 1090*cdf0e10cSrcweir #ifdef TF_POOLABLE 1091*cdf0e10cSrcweir 1092*cdf0e10cSrcweir sal_uInt16 nSID = pItemInfos[nWhich - nStart]._nSID; 1093*cdf0e10cSrcweir return nSID ? nSID : nWhich; 1094*cdf0e10cSrcweir #else 1095*cdf0e10cSrcweir else if ( pSlotIds ) 1096*cdf0e10cSrcweir return pSlotIds[nWhich - nStart]; 1097*cdf0e10cSrcweir return nWhich; 1098*cdf0e10cSrcweir #endif 1099*cdf0e10cSrcweir } 1100*cdf0e10cSrcweir 1101*cdf0e10cSrcweir // ----------------------------------------------------------------------- 1102*cdf0e10cSrcweir 1103*cdf0e10cSrcweir sal_uInt16 SfxItemPool::GetTrueWhich( sal_uInt16 nSlotId, sal_Bool bDeep ) const 1104*cdf0e10cSrcweir { 1105*cdf0e10cSrcweir if ( !IsSlot(nSlotId) ) 1106*cdf0e10cSrcweir return 0; 1107*cdf0e10cSrcweir 1108*cdf0e10cSrcweir #ifdef TF_POOLABLE 1109*cdf0e10cSrcweir sal_uInt16 nCount = nEnd - nStart + 1; 1110*cdf0e10cSrcweir for ( sal_uInt16 nOfs = 0; nOfs < nCount; ++nOfs ) 1111*cdf0e10cSrcweir if ( pItemInfos[nOfs]._nSID == nSlotId ) 1112*cdf0e10cSrcweir return nOfs + nStart; 1113*cdf0e10cSrcweir #else 1114*cdf0e10cSrcweir if ( pSlotIds ) 1115*cdf0e10cSrcweir { 1116*cdf0e10cSrcweir sal_uInt16 nCount = nEnd - nStart + 1; 1117*cdf0e10cSrcweir for ( sal_uInt16 nOfs = 0; nOfs < nCount; ++nOfs ) 1118*cdf0e10cSrcweir if ( pSlotIds[nOfs] == nSlotId ) 1119*cdf0e10cSrcweir return nOfs + nStart; 1120*cdf0e10cSrcweir } 1121*cdf0e10cSrcweir #endif 1122*cdf0e10cSrcweir if ( pSecondary && bDeep ) 1123*cdf0e10cSrcweir return pSecondary->GetTrueWhich(nSlotId); 1124*cdf0e10cSrcweir return 0; 1125*cdf0e10cSrcweir } 1126*cdf0e10cSrcweir 1127*cdf0e10cSrcweir // ----------------------------------------------------------------------- 1128*cdf0e10cSrcweir 1129*cdf0e10cSrcweir sal_uInt16 SfxItemPool::GetTrueSlotId( sal_uInt16 nWhich, sal_Bool bDeep ) const 1130*cdf0e10cSrcweir { 1131*cdf0e10cSrcweir if ( !IsWhich(nWhich) ) 1132*cdf0e10cSrcweir return 0; 1133*cdf0e10cSrcweir 1134*cdf0e10cSrcweir if ( !IsInRange( nWhich ) ) 1135*cdf0e10cSrcweir { 1136*cdf0e10cSrcweir if ( pSecondary && bDeep ) 1137*cdf0e10cSrcweir return pSecondary->GetTrueSlotId(nWhich); 1138*cdf0e10cSrcweir SFX_ASSERT( 0, nWhich, "unknown Which-Id - cannot get slot-id" ); 1139*cdf0e10cSrcweir return 0; 1140*cdf0e10cSrcweir } 1141*cdf0e10cSrcweir #ifdef TF_POOLABLE 1142*cdf0e10cSrcweir return pItemInfos[nWhich - nStart]._nSID; 1143*cdf0e10cSrcweir #else 1144*cdf0e10cSrcweir else if ( pSlotIds ) 1145*cdf0e10cSrcweir return pSlotIds[nWhich - nStart]; 1146*cdf0e10cSrcweir else 1147*cdf0e10cSrcweir return 0; 1148*cdf0e10cSrcweir #endif 1149*cdf0e10cSrcweir } 1150*cdf0e10cSrcweir // ----------------------------------------------------------------------- 1151*cdf0e10cSrcweir void SfxItemPool::SetFileFormatVersion( sal_uInt16 nFileFormatVersion ) 1152*cdf0e10cSrcweir 1153*cdf0e10cSrcweir /* [Description] 1154*cdf0e10cSrcweir 1155*cdf0e10cSrcweir You must call this function to set the file format version after 1156*cdf0e10cSrcweir concatenating your secondary-pools but before you store any 1157*cdf0e10cSrcweir pool, itemset or item. Only set the version at the master pool, 1158*cdf0e10cSrcweir never at any secondary pool. 1159*cdf0e10cSrcweir */ 1160*cdf0e10cSrcweir 1161*cdf0e10cSrcweir { 1162*cdf0e10cSrcweir DBG_ASSERT( this == pMaster, 1163*cdf0e10cSrcweir "SfxItemPool::SetFileFormatVersion() but not a master pool" ); 1164*cdf0e10cSrcweir for ( SfxItemPool *pPool = this; pPool; pPool = pPool->pSecondary ) 1165*cdf0e10cSrcweir pPool->_nFileFormatVersion = nFileFormatVersion; 1166*cdf0e10cSrcweir } 1167*cdf0e10cSrcweir 1168*cdf0e10cSrcweir 1169