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