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 <cstdarg>
29cdf0e10cSrcweir
30cdf0e10cSrcweir #define _SVSTDARR_USHORTS
31cdf0e10cSrcweir #define _SVSTDARR_ULONGS
32cdf0e10cSrcweir
33cdf0e10cSrcweir #include <svl/svstdarr.hxx>
34cdf0e10cSrcweir #include <svl/itemset.hxx>
35cdf0e10cSrcweir #include <svl/itempool.hxx>
36cdf0e10cSrcweir #include <svl/itemiter.hxx>
37cdf0e10cSrcweir #include <svl/whiter.hxx>
38cdf0e10cSrcweir #include <svl/nranges.hxx>
39cdf0e10cSrcweir #include "whassert.hxx"
40cdf0e10cSrcweir
41cdf0e10cSrcweir #include <tools/stream.hxx>
42cdf0e10cSrcweir #include <tools/solar.h>
43cdf0e10cSrcweir
44cdf0e10cSrcweir // STATIC DATA -----------------------------------------------------------
45cdf0e10cSrcweir
46cdf0e10cSrcweir static const sal_uInt16 nInitCount = 10; // einzelne USHORTs => 5 Paare ohne '0'
47cdf0e10cSrcweir #ifdef DBG_UTIL
48cdf0e10cSrcweir static sal_uLong nRangesCopyCount = 0; // wie oft wurden Ranges kopiert
49cdf0e10cSrcweir #endif
50cdf0e10cSrcweir
DBG_NAME(SfxItemSet) const51cdf0e10cSrcweir DBG_NAME(SfxItemSet)
52cdf0e10cSrcweir
53cdf0e10cSrcweir //========================================================================
54cdf0e10cSrcweir
55cdf0e10cSrcweir #define NUMTYPE sal_uInt16
56cdf0e10cSrcweir #define SvNums SvUShorts
57cdf0e10cSrcweir #define SfxNumRanges SfxUShortRanges
58cdf0e10cSrcweir #include "nranges.cxx"
59cdf0e10cSrcweir #undef NUMTYPE
60cdf0e10cSrcweir #undef SvNums
61cdf0e10cSrcweir #undef SfxNumRanges
62cdf0e10cSrcweir
63cdf0e10cSrcweir #define NUMTYPE sal_uLong
64cdf0e10cSrcweir #define SvNums SvULongs
65cdf0e10cSrcweir #define SfxNumRanges SfxULongRanges
66cdf0e10cSrcweir #include "nranges.cxx"
67cdf0e10cSrcweir #undef NUMTYPE
68cdf0e10cSrcweir #undef SvNums
69cdf0e10cSrcweir #undef SfxNumRanges
70cdf0e10cSrcweir
71cdf0e10cSrcweir //========================================================================
72cdf0e10cSrcweir
73cdf0e10cSrcweir #ifdef DBG_UTIL
74cdf0e10cSrcweir
75cdf0e10cSrcweir
76cdf0e10cSrcweir const sal_Char *DbgCheckItemSet( const void* pVoid )
77cdf0e10cSrcweir {
78cdf0e10cSrcweir const SfxItemSet *pSet = (const SfxItemSet*) pVoid;
79cdf0e10cSrcweir SfxWhichIter aIter( *pSet );
80cdf0e10cSrcweir sal_uInt16 nCount = 0, n = 0;
81cdf0e10cSrcweir for ( sal_uInt16 nWh = aIter.FirstWhich(); nWh; nWh = aIter.NextWhich(), ++n )
82cdf0e10cSrcweir {
83cdf0e10cSrcweir const SfxPoolItem *pItem = pSet->_aItems[n];
84cdf0e10cSrcweir if ( pItem )
85cdf0e10cSrcweir {
86cdf0e10cSrcweir ++nCount;
87cdf0e10cSrcweir DBG_ASSERT( IsInvalidItem(pItem) ||
88cdf0e10cSrcweir pItem->Which() == 0 || pItem->Which() == nWh,
89cdf0e10cSrcweir "SfxItemSet: invalid which-id" );
90cdf0e10cSrcweir DBG_ASSERT( IsInvalidItem(pItem) || !pItem->Which() ||
91cdf0e10cSrcweir !SfxItemPool::IsWhich(pItem->Which()) ||
92cdf0e10cSrcweir pSet->GetPool()->IsItemFlag(nWh, SFX_ITEM_NOT_POOLABLE) ||
93cdf0e10cSrcweir SFX_ITEMS_NULL != pSet->GetPool()->GetSurrogate(pItem),
94cdf0e10cSrcweir "SfxItemSet: item in set which is not in pool" );
95cdf0e10cSrcweir }
96cdf0e10cSrcweir
97cdf0e10cSrcweir }
98cdf0e10cSrcweir DBG_ASSERT( pSet->_nCount == nCount, "wrong SfxItemSet::nCount detected" );
99cdf0e10cSrcweir
100cdf0e10cSrcweir return 0;
101cdf0e10cSrcweir }
102cdf0e10cSrcweir
103cdf0e10cSrcweir #endif
104cdf0e10cSrcweir // -----------------------------------------------------------------------
105cdf0e10cSrcweir
SfxItemSet(SfxItemPool & rPool,sal_Bool bTotalRanges)106cdf0e10cSrcweir SfxItemSet::SfxItemSet
107cdf0e10cSrcweir (
108cdf0e10cSrcweir SfxItemPool& rPool, /* der Pool, in dem die SfxPoolItems,
109cdf0e10cSrcweir welche in dieses SfxItemSet gelangen,
110cdf0e10cSrcweir aufgenommen werden sollen */
111cdf0e10cSrcweir sal_Bool
112cdf0e10cSrcweir #ifdef DBG_UTIL
113cdf0e10cSrcweir #ifdef SFX_ITEMSET_NO_DEFAULT_CTOR
114cdf0e10cSrcweir
115cdf0e10cSrcweir bTotalRanges /* komplette Pool-Ranges uebernehmen,
116cdf0e10cSrcweir muss auf sal_True gesetzt werden */
117cdf0e10cSrcweir #endif
118cdf0e10cSrcweir #endif
119cdf0e10cSrcweir )
120cdf0e10cSrcweir /* [Beschreibung]
121cdf0e10cSrcweir
122cdf0e10cSrcweir Konstruktor fuer ein SfxItemSet mit genau den Which-Bereichen, welche
123cdf0e10cSrcweir dem angegebenen <SfxItemPool> bekannt sind.
124cdf0e10cSrcweir
125cdf0e10cSrcweir
126cdf0e10cSrcweir [Anmerkung]
127cdf0e10cSrcweir
128cdf0e10cSrcweir F"ur Sfx-Programmierer ein derart konstruiertes SfxItemSet kann
129cdf0e10cSrcweir keinerlei Items mit Slot-Ids als Which-Werte aufnehmen!
130cdf0e10cSrcweir */
131cdf0e10cSrcweir
132cdf0e10cSrcweir : _pPool( &rPool ),
133cdf0e10cSrcweir _pParent( 0 ),
134*05f023e4SWang Lei _nCount( 0 ),
135*05f023e4SWang Lei _aHashKey( 0 ) //i120575
136cdf0e10cSrcweir {
137cdf0e10cSrcweir DBG_CTOR(SfxItemSet, DbgCheckItemSet);
138cdf0e10cSrcweir DBG_ASSERTWARNING( _pPool == _pPool->GetMasterPool(), "kein Master-Pool" );
139cdf0e10cSrcweir DBG( _pChildCountCtor; *_pChildCount(this) = 0 );
140cdf0e10cSrcweir // DBG_ASSERT( bTotalRanges || abs( &bTotalRanges - this ) < 1000,
141cdf0e10cSrcweir // "please use suitable ranges" );
142cdf0e10cSrcweir #ifdef DBG_UTIL
143cdf0e10cSrcweir #ifdef SFX_ITEMSET_NO_DEFAULT_CTOR
144cdf0e10cSrcweir if ( !bTotalRanges )
145cdf0e10cSrcweir *(int*)0 = 0; // GPF
146cdf0e10cSrcweir #endif
147cdf0e10cSrcweir #endif
148cdf0e10cSrcweir
149cdf0e10cSrcweir _pWhichRanges = (sal_uInt16*) _pPool->GetFrozenIdRanges();
150cdf0e10cSrcweir DBG_ASSERT( _pWhichRanges, "don't create ItemSets with full range before FreezeIdRanges()" );
151cdf0e10cSrcweir if ( !_pWhichRanges )
152cdf0e10cSrcweir _pPool->FillItemIdRanges_Impl( _pWhichRanges );
153cdf0e10cSrcweir
154cdf0e10cSrcweir const sal_uInt16 nSize = TotalCount();
155cdf0e10cSrcweir _aItems = new const SfxPoolItem* [ nSize ];
156cdf0e10cSrcweir memset( (void*) _aItems, 0, nSize * sizeof( SfxPoolItem* ) );
157cdf0e10cSrcweir }
158cdf0e10cSrcweir
159cdf0e10cSrcweir // -----------------------------------------------------------------------
160cdf0e10cSrcweir
SfxItemSet(SfxItemPool & rPool,sal_uInt16 nWhich1,sal_uInt16 nWhich2)161cdf0e10cSrcweir SfxItemSet::SfxItemSet( SfxItemPool& rPool, sal_uInt16 nWhich1, sal_uInt16 nWhich2 ):
162cdf0e10cSrcweir _pPool( &rPool ),
163cdf0e10cSrcweir _pParent( 0 ),
164*05f023e4SWang Lei _nCount( 0 ),
165*05f023e4SWang Lei _aHashKey( 0 ) //i120575
166cdf0e10cSrcweir {
167cdf0e10cSrcweir DBG_CTOR(SfxItemSet, DbgCheckItemSet);
168cdf0e10cSrcweir DBG_ASSERT( nWhich1 <= nWhich2, "Ungueltiger Bereich" );
169cdf0e10cSrcweir DBG_ASSERTWARNING( _pPool == _pPool->GetMasterPool(), "kein Master-Pool" );
170cdf0e10cSrcweir DBG( _pChildCountCtor; *_pChildCount(this) = 0 );
171cdf0e10cSrcweir
172cdf0e10cSrcweir InitRanges_Impl(nWhich1, nWhich2);
173cdf0e10cSrcweir }
174cdf0e10cSrcweir
175cdf0e10cSrcweir // -----------------------------------------------------------------------
176cdf0e10cSrcweir
InitRanges_Impl(sal_uInt16 nWh1,sal_uInt16 nWh2)177cdf0e10cSrcweir void SfxItemSet::InitRanges_Impl(sal_uInt16 nWh1, sal_uInt16 nWh2)
178cdf0e10cSrcweir {
179cdf0e10cSrcweir DBG_CHKTHIS(SfxItemSet, 0);
180cdf0e10cSrcweir _pWhichRanges = new sal_uInt16[ 3 ];
181cdf0e10cSrcweir *(_pWhichRanges+0) = nWh1;
182cdf0e10cSrcweir *(_pWhichRanges+1) = nWh2;
183cdf0e10cSrcweir *(_pWhichRanges+2) = 0;
184cdf0e10cSrcweir const sal_uInt16 nRg = nWh2 - nWh1 + 1;
185cdf0e10cSrcweir _aItems = new const SfxPoolItem* [ nRg ];
186cdf0e10cSrcweir memset( (void*) _aItems, 0, nRg * sizeof( SfxPoolItem* ) );
187cdf0e10cSrcweir }
188cdf0e10cSrcweir
189cdf0e10cSrcweir // -----------------------------------------------------------------------
190cdf0e10cSrcweir
InitRanges_Impl(va_list pArgs,sal_uInt16 nWh1,sal_uInt16 nWh2,sal_uInt16 nNull)191cdf0e10cSrcweir void SfxItemSet::InitRanges_Impl(va_list pArgs, sal_uInt16 nWh1, sal_uInt16 nWh2, sal_uInt16 nNull)
192cdf0e10cSrcweir {
193cdf0e10cSrcweir DBG_CHKTHIS(SfxItemSet, 0);
194cdf0e10cSrcweir
195cdf0e10cSrcweir sal_uInt16 nSize = InitializeRanges_Impl( _pWhichRanges, pArgs, nWh1, nWh2, nNull );
196cdf0e10cSrcweir _aItems = new const SfxPoolItem* [ nSize ];
197cdf0e10cSrcweir memset( (void*) _aItems, 0, sizeof( SfxPoolItem* ) * nSize );
198cdf0e10cSrcweir }
199cdf0e10cSrcweir
200cdf0e10cSrcweir // -----------------------------------------------------------------------
201cdf0e10cSrcweir
SfxItemSet(SfxItemPool & rPool,USHORT_ARG nWh1,USHORT_ARG nWh2,USHORT_ARG nNull,...)202cdf0e10cSrcweir SfxItemSet::SfxItemSet( SfxItemPool& rPool,
203cdf0e10cSrcweir USHORT_ARG nWh1, USHORT_ARG nWh2, USHORT_ARG nNull, ... ):
204cdf0e10cSrcweir _pPool( &rPool ),
205cdf0e10cSrcweir _pParent( 0 ),
206cdf0e10cSrcweir _pWhichRanges( 0 ),
207*05f023e4SWang Lei _nCount( 0 ),
208*05f023e4SWang Lei _aHashKey( 0 ) //i120575
209cdf0e10cSrcweir {
210cdf0e10cSrcweir DBG_CTOR(SfxItemSet, DbgCheckItemSet);
211cdf0e10cSrcweir DBG_ASSERT( nWh1 <= nWh2, "Ungueltiger Bereich" );
212cdf0e10cSrcweir DBG_ASSERTWARNING( _pPool == _pPool->GetMasterPool(), "kein Master-Pool" );
213cdf0e10cSrcweir DBG( _pChildCountCtor; *_pChildCount(this) = 0 );
214cdf0e10cSrcweir
215cdf0e10cSrcweir if(!nNull)
216cdf0e10cSrcweir InitRanges_Impl(
217cdf0e10cSrcweir sal::static_int_cast< sal_uInt16 >(nWh1),
218cdf0e10cSrcweir sal::static_int_cast< sal_uInt16 >(nWh2));
219cdf0e10cSrcweir else {
220cdf0e10cSrcweir va_list pArgs;
221cdf0e10cSrcweir va_start( pArgs, nNull );
222cdf0e10cSrcweir InitRanges_Impl(
223cdf0e10cSrcweir pArgs, sal::static_int_cast< sal_uInt16 >(nWh1),
224cdf0e10cSrcweir sal::static_int_cast< sal_uInt16 >(nWh2),
225cdf0e10cSrcweir sal::static_int_cast< sal_uInt16 >(nNull));
226cdf0e10cSrcweir }
227cdf0e10cSrcweir }
228cdf0e10cSrcweir
229cdf0e10cSrcweir // -----------------------------------------------------------------------
230cdf0e10cSrcweir
InitRanges_Impl(const sal_uInt16 * pWhichPairTable)231cdf0e10cSrcweir void SfxItemSet::InitRanges_Impl(const sal_uInt16 *pWhichPairTable)
232cdf0e10cSrcweir {
233cdf0e10cSrcweir DBG_CHKTHIS(SfxItemSet, 0);
234cdf0e10cSrcweir DBG_TRACE1("SfxItemSet: Ranges-CopyCount==%ul", ++nRangesCopyCount);
235cdf0e10cSrcweir
236cdf0e10cSrcweir sal_uInt16 nCnt = 0;
237cdf0e10cSrcweir const sal_uInt16* pPtr = pWhichPairTable;
238cdf0e10cSrcweir while( *pPtr )
239cdf0e10cSrcweir {
240cdf0e10cSrcweir nCnt += ( *(pPtr+1) - *pPtr ) + 1;
241cdf0e10cSrcweir pPtr += 2;
242cdf0e10cSrcweir }
243cdf0e10cSrcweir
244cdf0e10cSrcweir _aItems = new const SfxPoolItem* [ nCnt ];
245cdf0e10cSrcweir memset( (void*) _aItems, 0, sizeof( SfxPoolItem* ) * nCnt );
246cdf0e10cSrcweir
247cdf0e10cSrcweir std::ptrdiff_t cnt = pPtr - pWhichPairTable +1;
248cdf0e10cSrcweir _pWhichRanges = new sal_uInt16[ cnt ];
249cdf0e10cSrcweir memcpy( _pWhichRanges, pWhichPairTable, sizeof( sal_uInt16 ) * cnt );
250cdf0e10cSrcweir }
251cdf0e10cSrcweir
252cdf0e10cSrcweir
253cdf0e10cSrcweir // -----------------------------------------------------------------------
254cdf0e10cSrcweir
SfxItemSet(SfxItemPool & rPool,const sal_uInt16 * pWhichPairTable)255cdf0e10cSrcweir SfxItemSet::SfxItemSet( SfxItemPool& rPool, const sal_uInt16* pWhichPairTable ):
256cdf0e10cSrcweir _pPool( &rPool ),
257cdf0e10cSrcweir _pParent( 0 ),
258cdf0e10cSrcweir _pWhichRanges(0),
259*05f023e4SWang Lei _nCount( 0 ),
260*05f023e4SWang Lei _aHashKey( 0 ) //i120575
261cdf0e10cSrcweir {
262cdf0e10cSrcweir DBG_CTOR(SfxItemSet, 0);
263cdf0e10cSrcweir DBG_ASSERTWARNING( _pPool == _pPool->GetMasterPool(), "kein Master-Pool" );
264cdf0e10cSrcweir DBG( _pChildCountCtor; *_pChildCount(this) = 0 );
265cdf0e10cSrcweir
266cdf0e10cSrcweir // pWhichPairTable == 0 ist f"ur das SfxAllEnumItemSet
267cdf0e10cSrcweir if ( pWhichPairTable )
268cdf0e10cSrcweir InitRanges_Impl(pWhichPairTable);
269cdf0e10cSrcweir }
270cdf0e10cSrcweir
271cdf0e10cSrcweir // -----------------------------------------------------------------------
272cdf0e10cSrcweir
SfxItemSet(const SfxItemSet & rASet)273cdf0e10cSrcweir SfxItemSet::SfxItemSet( const SfxItemSet& rASet ):
274cdf0e10cSrcweir _pPool( rASet._pPool ),
275cdf0e10cSrcweir _pParent( rASet._pParent ),
276*05f023e4SWang Lei _nCount( rASet._nCount ),
277*05f023e4SWang Lei _aHashKey( 0 ) //i120575
278cdf0e10cSrcweir {
279cdf0e10cSrcweir DBG_CTOR(SfxItemSet, DbgCheckItemSet);
280cdf0e10cSrcweir DBG_ASSERTWARNING( _pPool == _pPool->GetMasterPool(), "kein Master-Pool" );
281cdf0e10cSrcweir DBG( _pChildCountCtor; *_pChildCount(this) = 0 );
282cdf0e10cSrcweir DBG( ++*_pChildCount(_pParent) );
283cdf0e10cSrcweir
284cdf0e10cSrcweir // errechne die Anzahl von Attributen
285cdf0e10cSrcweir sal_uInt16 nCnt = 0;
286cdf0e10cSrcweir sal_uInt16* pPtr = rASet._pWhichRanges;
287cdf0e10cSrcweir while( *pPtr )
288cdf0e10cSrcweir {
289cdf0e10cSrcweir nCnt += ( *(pPtr+1) - *pPtr ) + 1;
290cdf0e10cSrcweir pPtr += 2;
291cdf0e10cSrcweir }
292cdf0e10cSrcweir
293cdf0e10cSrcweir _aItems = new const SfxPoolItem* [ nCnt ];
294cdf0e10cSrcweir
295cdf0e10cSrcweir // Attribute kopieren
296cdf0e10cSrcweir SfxItemArray ppDst = _aItems, ppSrc = rASet._aItems;
297cdf0e10cSrcweir for( sal_uInt16 n = nCnt; n; --n, ++ppDst, ++ppSrc )
298cdf0e10cSrcweir if ( 0 == *ppSrc || // aktueller Default?
299cdf0e10cSrcweir IsInvalidItem(*ppSrc) || // Dont Care?
300cdf0e10cSrcweir IsStaticDefaultItem(*ppSrc) ) // nicht zu poolende Defaults
301cdf0e10cSrcweir // einfach Pointer kopieren
302cdf0e10cSrcweir *ppDst = *ppSrc;
303cdf0e10cSrcweir else if ( _pPool->IsItemFlag( **ppSrc, SFX_ITEM_POOLABLE ) )
304cdf0e10cSrcweir {
305cdf0e10cSrcweir // einfach Pointer kopieren und Ref-Count erh"ohen
306cdf0e10cSrcweir *ppDst = *ppSrc;
307cdf0e10cSrcweir ( (SfxPoolItem*) (*ppDst) )->AddRef();
308cdf0e10cSrcweir }
309cdf0e10cSrcweir else if ( !(*ppSrc)->Which() )
310cdf0e10cSrcweir *ppDst = (*ppSrc)->Clone();
311cdf0e10cSrcweir else
312cdf0e10cSrcweir // !IsPoolable() => via Pool zuweisen
313cdf0e10cSrcweir *ppDst = &_pPool->Put( **ppSrc );
314cdf0e10cSrcweir
315cdf0e10cSrcweir // dann noch die Which Ranges kopieren
316cdf0e10cSrcweir DBG_TRACE1("SfxItemSet: Ranges-CopyCount==%ul", ++nRangesCopyCount);
317cdf0e10cSrcweir std::ptrdiff_t cnt = pPtr - rASet._pWhichRanges+1;
318cdf0e10cSrcweir _pWhichRanges = new sal_uInt16[ cnt ];
319cdf0e10cSrcweir memcpy( _pWhichRanges, rASet._pWhichRanges, sizeof( sal_uInt16 ) * cnt);
320cdf0e10cSrcweir }
321cdf0e10cSrcweir
322cdf0e10cSrcweir // -----------------------------------------------------------------------
323cdf0e10cSrcweir
~SfxItemSet()324cdf0e10cSrcweir SfxItemSet::~SfxItemSet()
325cdf0e10cSrcweir {
326cdf0e10cSrcweir DBG_DTOR(SfxItemSet, DbgCheckItemSet);
327cdf0e10cSrcweir #ifdef DBG_UTIL
328cdf0e10cSrcweir DBG( DBG_ASSERT( 0 == *_pChildCount(this), "SfxItemSet: deleting parent-itemset" ) )
329cdf0e10cSrcweir #endif
330cdf0e10cSrcweir
331cdf0e10cSrcweir sal_uInt16 nCount = TotalCount();
332cdf0e10cSrcweir if( Count() )
333cdf0e10cSrcweir {
334cdf0e10cSrcweir SfxItemArray ppFnd = _aItems;
335cdf0e10cSrcweir for( sal_uInt16 nCnt = nCount; nCnt; --nCnt, ++ppFnd )
336cdf0e10cSrcweir if( *ppFnd && !IsInvalidItem(*ppFnd) )
337cdf0e10cSrcweir {
338cdf0e10cSrcweir if( !(*ppFnd)->Which() )
339cdf0e10cSrcweir delete (SfxPoolItem*) *ppFnd;
340cdf0e10cSrcweir else {
341cdf0e10cSrcweir // noch mehrer Referenzen vorhanden, also nur den
342cdf0e10cSrcweir // ReferenzCounter manipulieren
343cdf0e10cSrcweir if ( 1 < (*ppFnd)->GetRefCount() && !IsDefaultItem(*ppFnd) )
344cdf0e10cSrcweir (*ppFnd)->ReleaseRef();
345cdf0e10cSrcweir else
346cdf0e10cSrcweir if ( !IsDefaultItem(*ppFnd) )
347cdf0e10cSrcweir // aus dem Pool loeschen
348cdf0e10cSrcweir _pPool->Remove( **ppFnd );
349cdf0e10cSrcweir }
350cdf0e10cSrcweir }
351cdf0e10cSrcweir }
352cdf0e10cSrcweir
353cdf0e10cSrcweir // FIXME: could be delete[] (SfxPoolItem **)_aItems;
354cdf0e10cSrcweir delete[] _aItems;
355cdf0e10cSrcweir if ( _pWhichRanges != _pPool->GetFrozenIdRanges() )
356cdf0e10cSrcweir delete[] _pWhichRanges;
357cdf0e10cSrcweir _pWhichRanges = 0; // for invariant-testing
358cdf0e10cSrcweir
359cdf0e10cSrcweir DBG( --*_pChildCount(_pParent) );
360cdf0e10cSrcweir DBG( delete _pChildCount(this); _pChildCountDtor );
361cdf0e10cSrcweir }
362cdf0e10cSrcweir
363cdf0e10cSrcweir // -----------------------------------------------------------------------
364cdf0e10cSrcweir
ClearItem(sal_uInt16 nWhich)365cdf0e10cSrcweir sal_uInt16 SfxItemSet::ClearItem( sal_uInt16 nWhich )
366cdf0e10cSrcweir
367cdf0e10cSrcweir // einzelnes Item oder alle Items (nWhich==0) l"oschen
368cdf0e10cSrcweir
369cdf0e10cSrcweir {
370cdf0e10cSrcweir DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet);
371cdf0e10cSrcweir if( !Count() )
372cdf0e10cSrcweir return 0;
373cdf0e10cSrcweir
374cdf0e10cSrcweir sal_uInt16 nDel = 0;
375cdf0e10cSrcweir SfxItemArray ppFnd = _aItems;
376cdf0e10cSrcweir
377cdf0e10cSrcweir if( nWhich )
378cdf0e10cSrcweir {
379cdf0e10cSrcweir const sal_uInt16* pPtr = _pWhichRanges;
380cdf0e10cSrcweir while( *pPtr )
381cdf0e10cSrcweir {
382cdf0e10cSrcweir // in diesem Bereich?
383cdf0e10cSrcweir if( *pPtr <= nWhich && nWhich <= *(pPtr+1) )
384cdf0e10cSrcweir {
385cdf0e10cSrcweir // "uberhaupt gesetzt?
386cdf0e10cSrcweir ppFnd += nWhich - *pPtr;
387cdf0e10cSrcweir if( *ppFnd )
388cdf0e10cSrcweir {
389cdf0e10cSrcweir // wegen der Assertions ins Sub-Calls mu\s das hier sein
390cdf0e10cSrcweir --_nCount;
391cdf0e10cSrcweir const SfxPoolItem *pItemToClear = *ppFnd;
392cdf0e10cSrcweir *ppFnd = 0;
393cdf0e10cSrcweir
394cdf0e10cSrcweir if ( !IsInvalidItem(pItemToClear) )
395cdf0e10cSrcweir {
396cdf0e10cSrcweir if ( nWhich <= SFX_WHICH_MAX )
397cdf0e10cSrcweir {
398cdf0e10cSrcweir const SfxPoolItem& rNew = _pParent
399cdf0e10cSrcweir ? _pParent->Get( nWhich, sal_True )
400cdf0e10cSrcweir : _pPool->GetDefaultItem( nWhich );
401cdf0e10cSrcweir
402cdf0e10cSrcweir Changed( *pItemToClear, rNew );
403cdf0e10cSrcweir }
404cdf0e10cSrcweir if ( pItemToClear->Which() )
405cdf0e10cSrcweir _pPool->Remove( *pItemToClear );
406cdf0e10cSrcweir }
407cdf0e10cSrcweir ++nDel;
408cdf0e10cSrcweir }
409cdf0e10cSrcweir
410cdf0e10cSrcweir // gefunden => raus
411cdf0e10cSrcweir break;
412cdf0e10cSrcweir }
413cdf0e10cSrcweir ppFnd += *(pPtr+1) - *pPtr + 1;
414cdf0e10cSrcweir pPtr += 2;
415cdf0e10cSrcweir }
416cdf0e10cSrcweir }
417cdf0e10cSrcweir else
418cdf0e10cSrcweir {
419cdf0e10cSrcweir nDel = _nCount;
420cdf0e10cSrcweir
421cdf0e10cSrcweir sal_uInt16* pPtr = _pWhichRanges;
422cdf0e10cSrcweir while( *pPtr )
423cdf0e10cSrcweir {
424cdf0e10cSrcweir for( nWhich = *pPtr; nWhich <= *(pPtr+1); ++nWhich, ++ppFnd )
425cdf0e10cSrcweir if( *ppFnd )
426cdf0e10cSrcweir {
427cdf0e10cSrcweir // wegen der Assertions ins Sub-Calls mu\s das hier sein
428cdf0e10cSrcweir --_nCount;
429cdf0e10cSrcweir const SfxPoolItem *pItemToClear = *ppFnd;
430cdf0e10cSrcweir *ppFnd = 0;
431cdf0e10cSrcweir
432cdf0e10cSrcweir if ( !IsInvalidItem(pItemToClear) )
433cdf0e10cSrcweir {
434cdf0e10cSrcweir if ( nWhich <= SFX_WHICH_MAX )
435cdf0e10cSrcweir {
436cdf0e10cSrcweir const SfxPoolItem& rNew = _pParent
437cdf0e10cSrcweir ? _pParent->Get( nWhich, sal_True )
438cdf0e10cSrcweir : _pPool->GetDefaultItem( nWhich );
439cdf0e10cSrcweir
440cdf0e10cSrcweir Changed( *pItemToClear, rNew );
441cdf0e10cSrcweir }
442cdf0e10cSrcweir
443cdf0e10cSrcweir // #i32448#
444cdf0e10cSrcweir // Take care of disabled items, too.
445cdf0e10cSrcweir if(!pItemToClear->nWhich)
446cdf0e10cSrcweir {
447cdf0e10cSrcweir // item is disabled, delete it
448cdf0e10cSrcweir delete pItemToClear;
449cdf0e10cSrcweir }
450cdf0e10cSrcweir else
451cdf0e10cSrcweir {
452cdf0e10cSrcweir // remove item from pool
453cdf0e10cSrcweir _pPool->Remove( *pItemToClear );
454cdf0e10cSrcweir }
455cdf0e10cSrcweir }
456cdf0e10cSrcweir }
457cdf0e10cSrcweir pPtr += 2;
458cdf0e10cSrcweir }
459cdf0e10cSrcweir }
460*05f023e4SWang Lei InvalidateHashKey(); //i120575
461cdf0e10cSrcweir return nDel;
462cdf0e10cSrcweir }
463cdf0e10cSrcweir
464cdf0e10cSrcweir // -----------------------------------------------------------------------
465cdf0e10cSrcweir
ClearInvalidItems(sal_Bool bHardDefault)466cdf0e10cSrcweir void SfxItemSet::ClearInvalidItems( sal_Bool bHardDefault )
467cdf0e10cSrcweir {
468cdf0e10cSrcweir DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet);
469cdf0e10cSrcweir sal_uInt16* pPtr = _pWhichRanges;
470cdf0e10cSrcweir SfxItemArray ppFnd = _aItems;
471cdf0e10cSrcweir if ( bHardDefault )
472cdf0e10cSrcweir while( *pPtr )
473cdf0e10cSrcweir {
474cdf0e10cSrcweir for ( sal_uInt16 nWhich = *pPtr; nWhich <= *(pPtr+1); ++nWhich, ++ppFnd )
475cdf0e10cSrcweir if ( IsInvalidItem(*ppFnd) )
476cdf0e10cSrcweir *ppFnd = &_pPool->Put( _pPool->GetDefaultItem(nWhich) );
477cdf0e10cSrcweir pPtr += 2;
478cdf0e10cSrcweir }
479cdf0e10cSrcweir else
480cdf0e10cSrcweir while( *pPtr )
481cdf0e10cSrcweir {
482cdf0e10cSrcweir for( sal_uInt16 nWhich = *pPtr; nWhich <= *(pPtr+1); ++nWhich, ++ppFnd )
483cdf0e10cSrcweir if( IsInvalidItem(*ppFnd) )
484cdf0e10cSrcweir {
485cdf0e10cSrcweir *ppFnd = 0;
486cdf0e10cSrcweir --_nCount;
487cdf0e10cSrcweir }
488cdf0e10cSrcweir pPtr += 2;
489cdf0e10cSrcweir }
490*05f023e4SWang Lei InvalidateHashKey(); //i120575
491cdf0e10cSrcweir }
492cdf0e10cSrcweir
493cdf0e10cSrcweir //------------------------------------------------------------------------
494cdf0e10cSrcweir
495cdf0e10cSrcweir
InvalidateAllItems()496cdf0e10cSrcweir void SfxItemSet::InvalidateAllItems()
497cdf0e10cSrcweir {
498cdf0e10cSrcweir DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet);
499cdf0e10cSrcweir DBG_ASSERT( !_nCount, "Es sind noch Items gesetzt" );
500cdf0e10cSrcweir
501cdf0e10cSrcweir memset( (void*)_aItems, -1, ( _nCount = TotalCount() ) * sizeof( SfxPoolItem*) );
502*05f023e4SWang Lei InvalidateHashKey(); //i120575
503cdf0e10cSrcweir }
504cdf0e10cSrcweir
505cdf0e10cSrcweir // -----------------------------------------------------------------------
506cdf0e10cSrcweir
GetItemState(sal_uInt16 nWhich,sal_Bool bSrchInParent,const SfxPoolItem ** ppItem) const507cdf0e10cSrcweir SfxItemState SfxItemSet::GetItemState( sal_uInt16 nWhich,
508cdf0e10cSrcweir sal_Bool bSrchInParent,
509cdf0e10cSrcweir const SfxPoolItem **ppItem ) const
510cdf0e10cSrcweir {
511cdf0e10cSrcweir DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet);
512cdf0e10cSrcweir // suche den Bereich in dem das Which steht:
513cdf0e10cSrcweir const SfxItemSet* pAktSet = this;
514cdf0e10cSrcweir SfxItemState eRet = SFX_ITEM_UNKNOWN;
515cdf0e10cSrcweir do
516cdf0e10cSrcweir {
517cdf0e10cSrcweir SfxItemArray ppFnd = pAktSet->_aItems;
518cdf0e10cSrcweir const sal_uInt16* pPtr = pAktSet->_pWhichRanges;
519cdf0e10cSrcweir if (pPtr)
520cdf0e10cSrcweir {
521cdf0e10cSrcweir while ( *pPtr )
522cdf0e10cSrcweir {
523cdf0e10cSrcweir if ( *pPtr <= nWhich && nWhich <= *(pPtr+1) )
524cdf0e10cSrcweir {
525cdf0e10cSrcweir // in diesem Bereich
526cdf0e10cSrcweir ppFnd += nWhich - *pPtr;
527cdf0e10cSrcweir if ( !*ppFnd )
528cdf0e10cSrcweir {
529cdf0e10cSrcweir eRet = SFX_ITEM_DEFAULT;
530cdf0e10cSrcweir if( !bSrchInParent )
531cdf0e10cSrcweir return eRet; // nicht vorhanden
532cdf0e10cSrcweir break; // JP: in den Parents weitersuchen !!!
533cdf0e10cSrcweir }
534cdf0e10cSrcweir
535cdf0e10cSrcweir if ( (SfxPoolItem*) -1 == *ppFnd )
536cdf0e10cSrcweir // Unterschiedlich vorhanden
537cdf0e10cSrcweir return SFX_ITEM_DONTCARE;
538cdf0e10cSrcweir
539cdf0e10cSrcweir if ( (*ppFnd)->Type() == TYPE(SfxVoidItem) )
540cdf0e10cSrcweir return SFX_ITEM_DISABLED;
541cdf0e10cSrcweir
542cdf0e10cSrcweir if (ppItem)
543cdf0e10cSrcweir {
544cdf0e10cSrcweir #ifdef DBG_UTIL
545cdf0e10cSrcweir const SfxPoolItem *pItem = *ppFnd;
546cdf0e10cSrcweir DBG_ASSERT( !pItem->ISA(SfxSetItem) ||
547cdf0e10cSrcweir 0 != &((const SfxSetItem*)pItem)->GetItemSet(),
548cdf0e10cSrcweir "SetItem without ItemSet" );
549cdf0e10cSrcweir #endif
550cdf0e10cSrcweir *ppItem = *ppFnd;
551cdf0e10cSrcweir }
552cdf0e10cSrcweir return SFX_ITEM_SET;
553cdf0e10cSrcweir }
554cdf0e10cSrcweir ppFnd += *(pPtr+1) - *pPtr + 1;
555cdf0e10cSrcweir pPtr += 2;
556cdf0e10cSrcweir }
557cdf0e10cSrcweir }
558cdf0e10cSrcweir } while( bSrchInParent && 0 != ( pAktSet = pAktSet->_pParent ));
559cdf0e10cSrcweir return eRet;
560cdf0e10cSrcweir }
561cdf0e10cSrcweir
562cdf0e10cSrcweir // -----------------------------------------------------------------------
563cdf0e10cSrcweir
Put(const SfxPoolItem & rItem,sal_uInt16 nWhich)564cdf0e10cSrcweir const SfxPoolItem* SfxItemSet::Put( const SfxPoolItem& rItem, sal_uInt16 nWhich )
565cdf0e10cSrcweir {
566cdf0e10cSrcweir DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet);
567cdf0e10cSrcweir DBG_ASSERT( !rItem.ISA(SfxSetItem) ||
568cdf0e10cSrcweir 0 != &((const SfxSetItem&)rItem).GetItemSet(),
569cdf0e10cSrcweir "SetItem without ItemSet" );
570cdf0e10cSrcweir if ( !nWhich )
571cdf0e10cSrcweir return 0; //! nur wegen Outliner-Bug
572cdf0e10cSrcweir SfxItemArray ppFnd = _aItems;
573cdf0e10cSrcweir const sal_uInt16* pPtr = _pWhichRanges;
574cdf0e10cSrcweir while( *pPtr )
575cdf0e10cSrcweir {
576cdf0e10cSrcweir if( *pPtr <= nWhich && nWhich <= *(pPtr+1) )
577cdf0e10cSrcweir {
578cdf0e10cSrcweir // in diesem Bereich
579cdf0e10cSrcweir ppFnd += nWhich - *pPtr;
580cdf0e10cSrcweir if( *ppFnd ) // schon einer vorhanden
581cdf0e10cSrcweir {
582cdf0e10cSrcweir // selbes Item bereits vorhanden?
583cdf0e10cSrcweir if ( *ppFnd == &rItem )
584cdf0e10cSrcweir return 0;
585cdf0e10cSrcweir
586cdf0e10cSrcweir // wird dontcare oder disabled mit was echtem ueberschrieben?
587cdf0e10cSrcweir if ( rItem.Which() && ( IsInvalidItem(*ppFnd) || !(*ppFnd)->Which() ) )
588cdf0e10cSrcweir {
589cdf0e10cSrcweir *ppFnd = &_pPool->Put( rItem, nWhich );
590*05f023e4SWang Lei InvalidateHashKey(); //i120575
591cdf0e10cSrcweir return *ppFnd;
592cdf0e10cSrcweir }
593cdf0e10cSrcweir
594cdf0e10cSrcweir // wird disabled?
595cdf0e10cSrcweir if( !rItem.Which() )
596cdf0e10cSrcweir {
597cdf0e10cSrcweir *ppFnd = rItem.Clone(_pPool);
598*05f023e4SWang Lei InvalidateHashKey(); //i120575
599cdf0e10cSrcweir return 0;
600cdf0e10cSrcweir }
601cdf0e10cSrcweir else
602cdf0e10cSrcweir {
603cdf0e10cSrcweir // selber Wert bereits vorhanden?
604cdf0e10cSrcweir if ( rItem == **ppFnd )
605cdf0e10cSrcweir return 0;
606cdf0e10cSrcweir
607cdf0e10cSrcweir // den neuen eintragen, den alten austragen
608cdf0e10cSrcweir const SfxPoolItem& rNew = _pPool->Put( rItem, nWhich );
609cdf0e10cSrcweir const SfxPoolItem* pOld = *ppFnd;
610cdf0e10cSrcweir *ppFnd = &rNew;
611cdf0e10cSrcweir if(nWhich <= SFX_WHICH_MAX)
612cdf0e10cSrcweir Changed( *pOld, rNew );
613cdf0e10cSrcweir _pPool->Remove( *pOld );
614cdf0e10cSrcweir }
615cdf0e10cSrcweir }
616cdf0e10cSrcweir else
617cdf0e10cSrcweir {
618cdf0e10cSrcweir ++_nCount;
619cdf0e10cSrcweir if( !rItem.Which() )
620cdf0e10cSrcweir *ppFnd = rItem.Clone(_pPool);
621cdf0e10cSrcweir else {
622cdf0e10cSrcweir const SfxPoolItem& rNew = _pPool->Put( rItem, nWhich );
623cdf0e10cSrcweir *ppFnd = &rNew;
624cdf0e10cSrcweir if (nWhich <= SFX_WHICH_MAX )
625cdf0e10cSrcweir {
626cdf0e10cSrcweir const SfxPoolItem& rOld = _pParent
627cdf0e10cSrcweir ? _pParent->Get( nWhich, sal_True )
628cdf0e10cSrcweir : _pPool->GetDefaultItem( nWhich );
629cdf0e10cSrcweir Changed( rOld, rNew );
630cdf0e10cSrcweir }
631cdf0e10cSrcweir }
632cdf0e10cSrcweir }
633cdf0e10cSrcweir SFX_ASSERT( !_pPool->IsItemFlag(nWhich, SFX_ITEM_POOLABLE) ||
634cdf0e10cSrcweir rItem.ISA(SfxSetItem) || **ppFnd == rItem,
635cdf0e10cSrcweir nWhich, "putted Item unequal" );
636*05f023e4SWang Lei
637*05f023e4SWang Lei InvalidateHashKey(); //i120575
638cdf0e10cSrcweir return *ppFnd;
639cdf0e10cSrcweir }
640cdf0e10cSrcweir ppFnd += *(pPtr+1) - *pPtr + 1;
641cdf0e10cSrcweir pPtr += 2;
642cdf0e10cSrcweir }
643*05f023e4SWang Lei InvalidateHashKey(); //i120575
644cdf0e10cSrcweir return 0;
645cdf0e10cSrcweir }
646cdf0e10cSrcweir
647cdf0e10cSrcweir // -----------------------------------------------------------------------
648cdf0e10cSrcweir
Put(const SfxItemSet & rSet,sal_Bool bInvalidAsDefault)649cdf0e10cSrcweir int SfxItemSet::Put( const SfxItemSet& rSet, sal_Bool bInvalidAsDefault )
650cdf0e10cSrcweir {
651cdf0e10cSrcweir DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet);
652cdf0e10cSrcweir sal_Bool bRet = sal_False;
653cdf0e10cSrcweir if( rSet.Count() )
654cdf0e10cSrcweir {
655cdf0e10cSrcweir SfxItemArray ppFnd = rSet._aItems;
656cdf0e10cSrcweir const sal_uInt16* pPtr = rSet._pWhichRanges;
657cdf0e10cSrcweir while ( *pPtr )
658cdf0e10cSrcweir {
659cdf0e10cSrcweir for ( sal_uInt16 nWhich = *pPtr; nWhich <= *(pPtr+1); ++nWhich, ++ppFnd )
660cdf0e10cSrcweir if( *ppFnd )
661cdf0e10cSrcweir {
662cdf0e10cSrcweir if ( IsInvalidItem( *ppFnd ) )
663cdf0e10cSrcweir {
664cdf0e10cSrcweir if ( bInvalidAsDefault )
665cdf0e10cSrcweir bRet |= 0 != ClearItem( nWhich );
666cdf0e10cSrcweir // gab GPF bei non.WIDs:
667cdf0e10cSrcweir // bRet |= 0 != Put( rSet.GetPool()->GetDefaultItem(nWhich), nWhich );
668cdf0e10cSrcweir else
669cdf0e10cSrcweir InvalidateItem( nWhich );
670cdf0e10cSrcweir }
671cdf0e10cSrcweir else
672cdf0e10cSrcweir bRet |= 0 != Put( **ppFnd, nWhich );
673cdf0e10cSrcweir }
674cdf0e10cSrcweir pPtr += 2;
675cdf0e10cSrcweir }
676cdf0e10cSrcweir }
677cdf0e10cSrcweir return bRet;
678cdf0e10cSrcweir }
679cdf0e10cSrcweir
680cdf0e10cSrcweir // -----------------------------------------------------------------------
681cdf0e10cSrcweir
PutExtended(const SfxItemSet & rSet,SfxItemState eDontCareAs,SfxItemState eDefaultAs)682cdf0e10cSrcweir void SfxItemSet::PutExtended
683cdf0e10cSrcweir (
684cdf0e10cSrcweir const SfxItemSet& rSet, // Quelle der zu puttenden Items
685cdf0e10cSrcweir SfxItemState eDontCareAs, // was mit DontCare-Items passiert
686cdf0e10cSrcweir SfxItemState eDefaultAs // was mit Default-Items passiert
687cdf0e10cSrcweir )
688cdf0e10cSrcweir
689cdf0e10cSrcweir /* [Beschreibung]
690cdf0e10cSrcweir
691cdf0e10cSrcweir Diese Methode "ubernimmt die Items aus 'rSet' in '*this'. Die
692cdf0e10cSrcweir Which-Bereiche in '*this', die in 'rSet' nicht vorkommen bleiben unver-
693cdf0e10cSrcweir "andert. Der Which-Bereich von '*this' bleibt auch unver"andert.
694cdf0e10cSrcweir
695cdf0e10cSrcweir In 'rSet' gesetzte Items werden auch in '*this*' gesetzt. Default-
696cdf0e10cSrcweir (0 Pointer) und Invalid- (-1 Pointer) Items werden je nach Parameter
697cdf0e10cSrcweir ('eDontCareAs' und 'eDefaultAs' behandelt:
698cdf0e10cSrcweir
699cdf0e10cSrcweir SFX_ITEM_SET: hart auf Default des Pools gesetzt
700cdf0e10cSrcweir SFX_ITEM_DEFAULT: gel"oscht (0 Pointer)
701cdf0e10cSrcweir SFX_ITEM_DONTCARE: invalidiert (-1 Pointer)
702cdf0e10cSrcweir
703cdf0e10cSrcweir Alle anderen Werte f"ur 'eDontCareAs' und 'eDefaultAs' sind ung"ultig.
704cdf0e10cSrcweir */
705cdf0e10cSrcweir
706cdf0e10cSrcweir {
707cdf0e10cSrcweir DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet);
708cdf0e10cSrcweir
709cdf0e10cSrcweir // don't "optimize" with "if( rSet.Count()" because of dont-care + defaults
710cdf0e10cSrcweir SfxItemArray ppFnd = rSet._aItems;
711cdf0e10cSrcweir const sal_uInt16* pPtr = rSet._pWhichRanges;
712cdf0e10cSrcweir while ( *pPtr )
713cdf0e10cSrcweir {
714cdf0e10cSrcweir for ( sal_uInt16 nWhich = *pPtr; nWhich <= *(pPtr+1); ++nWhich, ++ppFnd )
715cdf0e10cSrcweir if( *ppFnd )
716cdf0e10cSrcweir {
717cdf0e10cSrcweir if ( IsInvalidItem( *ppFnd ) )
718cdf0e10cSrcweir {
719cdf0e10cSrcweir // Item ist DontCare:
720cdf0e10cSrcweir switch ( eDontCareAs )
721cdf0e10cSrcweir {
722cdf0e10cSrcweir case SFX_ITEM_SET:
723cdf0e10cSrcweir Put( rSet.GetPool()->GetDefaultItem(nWhich), nWhich );
724cdf0e10cSrcweir break;
725cdf0e10cSrcweir
726cdf0e10cSrcweir case SFX_ITEM_DEFAULT:
727cdf0e10cSrcweir ClearItem( nWhich );
728cdf0e10cSrcweir break;
729cdf0e10cSrcweir
730cdf0e10cSrcweir case SFX_ITEM_DONTCARE:
731cdf0e10cSrcweir InvalidateItem( nWhich );
732cdf0e10cSrcweir break;
733cdf0e10cSrcweir
734cdf0e10cSrcweir default:
735cdf0e10cSrcweir DBG_ERROR( "invalid Argument for eDontCareAs" );
736cdf0e10cSrcweir }
737cdf0e10cSrcweir }
738cdf0e10cSrcweir else
739cdf0e10cSrcweir // Item ist gesetzt:
740cdf0e10cSrcweir Put( **ppFnd, nWhich );
741cdf0e10cSrcweir }
742cdf0e10cSrcweir else
743cdf0e10cSrcweir {
744cdf0e10cSrcweir // Item ist Default:
745cdf0e10cSrcweir switch ( eDefaultAs )
746cdf0e10cSrcweir {
747cdf0e10cSrcweir case SFX_ITEM_SET:
748cdf0e10cSrcweir Put( rSet.GetPool()->GetDefaultItem(nWhich), nWhich );
749cdf0e10cSrcweir break;
750cdf0e10cSrcweir
751cdf0e10cSrcweir case SFX_ITEM_DEFAULT:
752cdf0e10cSrcweir ClearItem( nWhich );
753cdf0e10cSrcweir break;
754cdf0e10cSrcweir
755cdf0e10cSrcweir case SFX_ITEM_DONTCARE:
756cdf0e10cSrcweir InvalidateItem( nWhich );
757cdf0e10cSrcweir break;
758cdf0e10cSrcweir
759cdf0e10cSrcweir default:
760cdf0e10cSrcweir DBG_ERROR( "invalid Argument for eDefaultAs" );
761cdf0e10cSrcweir }
762cdf0e10cSrcweir }
763cdf0e10cSrcweir pPtr += 2;
764cdf0e10cSrcweir }
765cdf0e10cSrcweir }
766cdf0e10cSrcweir
767cdf0e10cSrcweir // -----------------------------------------------------------------------
768cdf0e10cSrcweir
MergeRange(sal_uInt16 nFrom,sal_uInt16 nTo)769cdf0e10cSrcweir void SfxItemSet::MergeRange( sal_uInt16 nFrom, sal_uInt16 nTo )
770cdf0e10cSrcweir /** <H3>Description</H3>
771cdf0e10cSrcweir
772cdf0e10cSrcweir Expands the ranges of settable items by 'nFrom' to 'nTo'. Keeps state of
773cdf0e10cSrcweir items which are new ranges too.
774cdf0e10cSrcweir */
775cdf0e10cSrcweir
776cdf0e10cSrcweir {
777cdf0e10cSrcweir // special case: exactly one sal_uInt16 which is already included?
778cdf0e10cSrcweir if ( nFrom == nTo && SFX_ITEM_AVAILABLE <= GetItemState(nFrom, sal_False) )
779cdf0e10cSrcweir return;
780cdf0e10cSrcweir
781cdf0e10cSrcweir // merge new range
782cdf0e10cSrcweir SfxUShortRanges aRanges( _pWhichRanges );
783cdf0e10cSrcweir aRanges += SfxUShortRanges( nFrom, nTo );
784cdf0e10cSrcweir SetRanges( aRanges );
785cdf0e10cSrcweir }
786cdf0e10cSrcweir
787cdf0e10cSrcweir // -----------------------------------------------------------------------
788cdf0e10cSrcweir
SetRanges(const sal_uInt16 * pNewRanges)789cdf0e10cSrcweir void SfxItemSet::SetRanges( const sal_uInt16 *pNewRanges )
790cdf0e10cSrcweir
791cdf0e10cSrcweir /** <H3>Description</H3>
792cdf0e10cSrcweir
793cdf0e10cSrcweir Modifies the ranges of settable items. Keeps state of items which
794cdf0e10cSrcweir are new ranges too.
795cdf0e10cSrcweir */
796cdf0e10cSrcweir
797cdf0e10cSrcweir {
798cdf0e10cSrcweir // identische Ranges?
799cdf0e10cSrcweir if ( _pWhichRanges == pNewRanges )
800cdf0e10cSrcweir return;
801cdf0e10cSrcweir const sal_uInt16* pOld = _pWhichRanges;
802cdf0e10cSrcweir const sal_uInt16* pNew = pNewRanges;
803cdf0e10cSrcweir while ( *pOld == *pNew )
804cdf0e10cSrcweir {
805cdf0e10cSrcweir if ( !*pOld && !*pNew )
806cdf0e10cSrcweir return;
807cdf0e10cSrcweir ++pOld, ++pNew;
808cdf0e10cSrcweir }
809cdf0e10cSrcweir
810cdf0e10cSrcweir // create new item-array (by iterating through all new ranges)
811cdf0e10cSrcweir sal_uLong nSize = Capacity_Impl(pNewRanges);
812cdf0e10cSrcweir SfxItemArray aNewItems = new const SfxPoolItem* [ nSize ];
813cdf0e10cSrcweir sal_uInt16 n = 0, nNewCount = 0;
814cdf0e10cSrcweir if ( _nCount == 0 )
815cdf0e10cSrcweir memset( aNewItems, 0, nSize * sizeof( SfxPoolItem* ) );
816cdf0e10cSrcweir else
817cdf0e10cSrcweir {
818cdf0e10cSrcweir for ( const sal_uInt16 *pRange = pNewRanges; *pRange; pRange += 2 )
819cdf0e10cSrcweir {
820cdf0e10cSrcweir // iterate through all ids in the range
821cdf0e10cSrcweir for ( sal_uInt16 nWID = *pRange; nWID <= pRange[1]; ++nWID, ++n )
822cdf0e10cSrcweir {
823cdf0e10cSrcweir // direct move of pointer (not via pool)
824cdf0e10cSrcweir SfxItemState eState = GetItemState( nWID, sal_False, aNewItems+n );
825cdf0e10cSrcweir if ( SFX_ITEM_SET == eState )
826cdf0e10cSrcweir {
827cdf0e10cSrcweir // increment new item count and possibly increment ref count
828cdf0e10cSrcweir ++nNewCount;
829cdf0e10cSrcweir aNewItems[n]->AddRef();
830cdf0e10cSrcweir }
831cdf0e10cSrcweir else if ( SFX_ITEM_DISABLED == eState )
832cdf0e10cSrcweir {
833cdf0e10cSrcweir // put "disabled" item
834cdf0e10cSrcweir ++nNewCount;
835cdf0e10cSrcweir aNewItems[n] = new SfxVoidItem(0);
836cdf0e10cSrcweir }
837cdf0e10cSrcweir else if ( SFX_ITEM_DONTCARE == eState )
838cdf0e10cSrcweir {
839cdf0e10cSrcweir ++nNewCount;
840cdf0e10cSrcweir aNewItems[n] = (SfxPoolItem*)-1;
841cdf0e10cSrcweir }
842cdf0e10cSrcweir else
843cdf0e10cSrcweir {
844cdf0e10cSrcweir // default
845cdf0e10cSrcweir aNewItems[n] = 0;
846cdf0e10cSrcweir }
847cdf0e10cSrcweir }
848cdf0e10cSrcweir }
849cdf0e10cSrcweir // free old items
850cdf0e10cSrcweir sal_uInt16 nOldTotalCount = TotalCount();
851cdf0e10cSrcweir for ( sal_uInt16 nItem = 0; nItem < nOldTotalCount; ++nItem )
852cdf0e10cSrcweir {
853cdf0e10cSrcweir const SfxPoolItem *pItem = _aItems[nItem];
854cdf0e10cSrcweir if ( pItem && !IsInvalidItem(pItem) && pItem->Which() )
855cdf0e10cSrcweir _pPool->Remove(*pItem);
856cdf0e10cSrcweir }
857cdf0e10cSrcweir }
858cdf0e10cSrcweir
859cdf0e10cSrcweir // replace old items-array and ranges
860cdf0e10cSrcweir delete[] _aItems;
861cdf0e10cSrcweir _aItems = aNewItems;
862cdf0e10cSrcweir _nCount = nNewCount;
863cdf0e10cSrcweir
864cdf0e10cSrcweir if( pNewRanges == GetPool()->GetFrozenIdRanges() )
865cdf0e10cSrcweir {
866cdf0e10cSrcweir delete[] _pWhichRanges;
867cdf0e10cSrcweir _pWhichRanges = ( sal_uInt16* ) pNewRanges;
868cdf0e10cSrcweir }
869cdf0e10cSrcweir else
870cdf0e10cSrcweir {
871cdf0e10cSrcweir sal_uInt16 nCount = Count_Impl(pNewRanges) + 1;
872cdf0e10cSrcweir if ( _pWhichRanges != _pPool->GetFrozenIdRanges() )
873cdf0e10cSrcweir delete[] _pWhichRanges;
874cdf0e10cSrcweir _pWhichRanges = new sal_uInt16[ nCount ];
875cdf0e10cSrcweir memcpy( _pWhichRanges, pNewRanges, sizeof( sal_uInt16 ) * nCount );
876cdf0e10cSrcweir }
877*05f023e4SWang Lei InvalidateHashKey(); //i120575
878cdf0e10cSrcweir }
879cdf0e10cSrcweir
880cdf0e10cSrcweir // -----------------------------------------------------------------------
881cdf0e10cSrcweir
Set(const SfxItemSet & rSet,sal_Bool bDeep)882cdf0e10cSrcweir int SfxItemSet::Set
883cdf0e10cSrcweir (
884cdf0e10cSrcweir const SfxItemSet& rSet, /* das SfxItemSet, dessen SfxPoolItems
885cdf0e10cSrcweir "ubernommen werden sollen */
886cdf0e10cSrcweir
887cdf0e10cSrcweir sal_Bool bDeep /* sal_True (default)
888cdf0e10cSrcweir auch die SfxPoolItems aus den ggf. an
889cdf0e10cSrcweir rSet vorhandenen Parents werden direkt
890cdf0e10cSrcweir in das SfxItemSet "ubernommen
891cdf0e10cSrcweir
892cdf0e10cSrcweir sal_False
893cdf0e10cSrcweir die SfxPoolItems aus den Parents von
894cdf0e10cSrcweir rSet werden nicht ber"ucksichtigt */
895cdf0e10cSrcweir )
896cdf0e10cSrcweir
897cdf0e10cSrcweir /* [Beschreibung]
898cdf0e10cSrcweir
899cdf0e10cSrcweir Das SfxItemSet nimmt genau die SfxPoolItems an, die auch in
900cdf0e10cSrcweir rSet gesetzt sind und im eigenen <Which-Bereich> liegen. Alle
901cdf0e10cSrcweir anderen werden entfernt. Der SfxItemPool wird dabei beibehalten,
902cdf0e10cSrcweir so da"s die "ubernommenen SfxPoolItems dabei ggf. vom SfxItemPool
903cdf0e10cSrcweir von rSet in den SfxItemPool von *this "ubernommen werden.
904cdf0e10cSrcweir
905cdf0e10cSrcweir SfxPoolItems, f"ur die in rSet IsInvalidItem() == sal_True gilt,
906cdf0e10cSrcweir werden als Invalid-Item "ubernommen.
907cdf0e10cSrcweir
908cdf0e10cSrcweir
909cdf0e10cSrcweir [R"uckgabewert]
910cdf0e10cSrcweir
911cdf0e10cSrcweir int sal_True
912cdf0e10cSrcweir es wurden SfxPoolItems "ubernommen
913cdf0e10cSrcweir
914cdf0e10cSrcweir sal_False
915cdf0e10cSrcweir es wurden keine SfxPoolItems "ubernommen,
916cdf0e10cSrcweir da z.B. die Which-Bereiche der SfxItemSets
917cdf0e10cSrcweir keine Schnittmenge haben oder in der
918cdf0e10cSrcweir Schnittmenge keine SfxPoolItems in rSet
919cdf0e10cSrcweir gesetzt sind
920cdf0e10cSrcweir
921cdf0e10cSrcweir */
922cdf0e10cSrcweir
923cdf0e10cSrcweir {
924cdf0e10cSrcweir DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet);
925cdf0e10cSrcweir int bRet = sal_False;
926cdf0e10cSrcweir if ( _nCount )
927cdf0e10cSrcweir ClearItem();
928cdf0e10cSrcweir if ( bDeep )
929cdf0e10cSrcweir {
930cdf0e10cSrcweir SfxWhichIter aIter(*this);
931cdf0e10cSrcweir sal_uInt16 nWhich = aIter.FirstWhich();
932cdf0e10cSrcweir while ( nWhich )
933cdf0e10cSrcweir {
934cdf0e10cSrcweir const SfxPoolItem* pItem;
935cdf0e10cSrcweir if( SFX_ITEM_SET == rSet.GetItemState( nWhich, sal_True, &pItem ) )
936cdf0e10cSrcweir bRet |= 0 != Put( *pItem, pItem->Which() );
937cdf0e10cSrcweir nWhich = aIter.NextWhich();
938cdf0e10cSrcweir }
939cdf0e10cSrcweir }
940cdf0e10cSrcweir else
941cdf0e10cSrcweir bRet = Put(rSet, sal_False);
942cdf0e10cSrcweir
943cdf0e10cSrcweir return bRet;
944cdf0e10cSrcweir }
945cdf0e10cSrcweir
946cdf0e10cSrcweir //------------------------------------------------------------------------
947cdf0e10cSrcweir
GetItem(sal_uInt16 nId,sal_Bool bSrchInParent,TypeId aItemType) const948cdf0e10cSrcweir const SfxPoolItem* SfxItemSet::GetItem
949cdf0e10cSrcweir (
950cdf0e10cSrcweir sal_uInt16 nId, // Slot-Id oder Which-Id des Items
951cdf0e10cSrcweir sal_Bool bSrchInParent, // sal_True: auch in Parent-ItemSets suchen
952cdf0e10cSrcweir TypeId aItemType // != 0 => RTTI Pruefung mit Assertion
953cdf0e10cSrcweir ) const
954cdf0e10cSrcweir
955cdf0e10cSrcweir /* [Beschreibung]
956cdf0e10cSrcweir
957cdf0e10cSrcweir Mit dieser Methode wird der Zugriff auf einzelne Items im
958cdf0e10cSrcweir SfxItemSet wesentlich vereinfacht. Insbesondere wird die Typpr"ufung
959cdf0e10cSrcweir (per Assertion) durchgef"uhrt, wodurch die Applikations-Sourcen
960cdf0e10cSrcweir wesentlich "ubersichtlicher werden. In der PRODUCT-Version wird
961cdf0e10cSrcweir eine 0 zur"uckgegeben, wenn das gefundene Item nicht von der
962cdf0e10cSrcweir angegebenen Klasse ist. Ist kein Item mit der Id 'nWhich' in dem ItemSet,
963cdf0e10cSrcweir so wird 0 zurueckgegeben.
964cdf0e10cSrcweir */
965cdf0e10cSrcweir
966cdf0e10cSrcweir {
967cdf0e10cSrcweir // ggf. in Which-Id umrechnen
968cdf0e10cSrcweir sal_uInt16 nWhich = GetPool()->GetWhich(nId);
969cdf0e10cSrcweir
970cdf0e10cSrcweir // ist das Item gesetzt oder bei bDeep==sal_True verf"ugbar?
971cdf0e10cSrcweir const SfxPoolItem *pItem = 0;
972cdf0e10cSrcweir SfxItemState eState = GetItemState( nWhich, bSrchInParent, &pItem );
973cdf0e10cSrcweir if ( bSrchInParent && SFX_ITEM_AVAILABLE == eState &&
974cdf0e10cSrcweir nWhich <= SFX_WHICH_MAX )
975cdf0e10cSrcweir pItem = &_pPool->GetDefaultItem(nWhich);
976cdf0e10cSrcweir if ( pItem )
977cdf0e10cSrcweir {
978cdf0e10cSrcweir // stimmt der Typ "uberein?
979cdf0e10cSrcweir if ( !aItemType || pItem->IsA(aItemType) )
980cdf0e10cSrcweir return pItem;
981cdf0e10cSrcweir
982cdf0e10cSrcweir // sonst Fehler melden
983cdf0e10cSrcweir DBG_ERROR( "invalid argument type" );
984cdf0e10cSrcweir }
985cdf0e10cSrcweir
986cdf0e10cSrcweir // kein Item gefunden oder falschen Typ gefunden
987cdf0e10cSrcweir return 0;
988cdf0e10cSrcweir }
989cdf0e10cSrcweir
990cdf0e10cSrcweir
991cdf0e10cSrcweir //------------------------------------------------------------------------
992cdf0e10cSrcweir
993cdf0e10cSrcweir
Get(sal_uInt16 nWhich,sal_Bool bSrchInParent) const994cdf0e10cSrcweir const SfxPoolItem& SfxItemSet::Get( sal_uInt16 nWhich, sal_Bool bSrchInParent) const
995cdf0e10cSrcweir {
996cdf0e10cSrcweir DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet);
997cdf0e10cSrcweir // suche den Bereich in dem das Which steht:
998cdf0e10cSrcweir const SfxItemSet* pAktSet = this;
999cdf0e10cSrcweir do
1000cdf0e10cSrcweir {
1001cdf0e10cSrcweir if( pAktSet->Count() )
1002cdf0e10cSrcweir {
1003cdf0e10cSrcweir SfxItemArray ppFnd = pAktSet->_aItems;
1004cdf0e10cSrcweir const sal_uInt16* pPtr = pAktSet->_pWhichRanges;
1005cdf0e10cSrcweir while( *pPtr )
1006cdf0e10cSrcweir {
1007cdf0e10cSrcweir if( *pPtr <= nWhich && nWhich <= *(pPtr+1) )
1008cdf0e10cSrcweir {
1009cdf0e10cSrcweir // in diesem Bereich
1010cdf0e10cSrcweir ppFnd += nWhich - *pPtr;
1011cdf0e10cSrcweir if( *ppFnd )
1012cdf0e10cSrcweir {
1013cdf0e10cSrcweir if( (SfxPoolItem*)-1 == *ppFnd ) {
1014cdf0e10cSrcweir //?MI: folgender code ist Doppelt (unten)
1015cdf0e10cSrcweir SFX_ASSERT(_pPool, nWhich, "kein Pool, aber Status uneindeutig");
1016cdf0e10cSrcweir //!((SfxAllItemSet *)this)->aDefault.SetWhich(nWhich);
1017cdf0e10cSrcweir //!return aDefault;
1018cdf0e10cSrcweir return _pPool->GetDefaultItem( nWhich );
1019cdf0e10cSrcweir }
1020cdf0e10cSrcweir #ifdef DBG_UTIL
1021cdf0e10cSrcweir const SfxPoolItem *pItem = *ppFnd;
1022cdf0e10cSrcweir DBG_ASSERT( !pItem->ISA(SfxSetItem) ||
1023cdf0e10cSrcweir 0 != &((const SfxSetItem*)pItem)->GetItemSet(),
1024cdf0e10cSrcweir "SetItem without ItemSet" );
1025cdf0e10cSrcweir if ( pItem->ISA(SfxVoidItem) || !pItem->Which() )
1026cdf0e10cSrcweir DBG_WARNING( "SFX_WARNING: Getting disabled Item" );
1027cdf0e10cSrcweir #endif
1028cdf0e10cSrcweir return **ppFnd;
1029cdf0e10cSrcweir }
1030cdf0e10cSrcweir break; // dann beim Parent suchen
1031cdf0e10cSrcweir }
1032cdf0e10cSrcweir ppFnd += *(pPtr+1) - *pPtr + 1;
1033cdf0e10cSrcweir pPtr += 2;
1034cdf0e10cSrcweir }
1035cdf0e10cSrcweir }
1036cdf0e10cSrcweir // bis zum Ende vom Such-Bereich: was nun ? zum Parent, oder Default ??
1037cdf0e10cSrcweir // if( !*pPtr ) // bis zum Ende vom Such-Bereich ?
1038cdf0e10cSrcweir // break;
1039cdf0e10cSrcweir } while( bSrchInParent && 0 != ( pAktSet = pAktSet->_pParent ));
1040cdf0e10cSrcweir
1041cdf0e10cSrcweir // dann das Default vom Pool holen und returnen
1042cdf0e10cSrcweir SFX_ASSERT(_pPool, nWhich, "kein Pool, aber Status uneindeutig");
1043cdf0e10cSrcweir const SfxPoolItem *pItem = &_pPool->GetDefaultItem( nWhich );
1044cdf0e10cSrcweir DBG_ASSERT( !pItem->ISA(SfxSetItem) ||
1045cdf0e10cSrcweir 0 != &((const SfxSetItem*)pItem)->GetItemSet(),
1046cdf0e10cSrcweir "SetItem without ItemSet" );
1047cdf0e10cSrcweir return *pItem;
1048cdf0e10cSrcweir }
1049cdf0e10cSrcweir
1050cdf0e10cSrcweir // Notification-Callback
1051cdf0e10cSrcweir // -----------------------------------------------------------------------
1052cdf0e10cSrcweir
Changed(const SfxPoolItem &,const SfxPoolItem &)1053cdf0e10cSrcweir void SfxItemSet::Changed( const SfxPoolItem&, const SfxPoolItem& )
1054cdf0e10cSrcweir {
1055cdf0e10cSrcweir DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet);
1056cdf0e10cSrcweir }
1057cdf0e10cSrcweir
1058cdf0e10cSrcweir // -----------------------------------------------------------------------
1059cdf0e10cSrcweir
TotalCount() const1060cdf0e10cSrcweir sal_uInt16 SfxItemSet::TotalCount() const
1061cdf0e10cSrcweir {
1062cdf0e10cSrcweir DBG_CHKTHIS(SfxItemSet, 0); // wird im Ctor benutzt bevor vollst. init.
1063cdf0e10cSrcweir sal_uInt16 nRet = 0;
1064cdf0e10cSrcweir sal_uInt16* pPtr = _pWhichRanges;
1065cdf0e10cSrcweir while( *pPtr )
1066cdf0e10cSrcweir {
1067cdf0e10cSrcweir nRet += ( *(pPtr+1) - *pPtr ) + 1;
1068cdf0e10cSrcweir pPtr += 2;
1069cdf0e10cSrcweir }
1070cdf0e10cSrcweir return nRet;
1071cdf0e10cSrcweir }
1072cdf0e10cSrcweir // -----------------------------------------------------------------------
1073cdf0e10cSrcweir
1074cdf0e10cSrcweir // behalte nur die Items, die auch in rSet enthalten sein (Wert egal)
1075cdf0e10cSrcweir
Intersect(const SfxItemSet & rSet)1076cdf0e10cSrcweir void SfxItemSet::Intersect( const SfxItemSet& rSet )
1077cdf0e10cSrcweir {
1078cdf0e10cSrcweir DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet);
1079cdf0e10cSrcweir DBG_ASSERT(_pPool, "nicht implementiert ohne Pool");
1080cdf0e10cSrcweir if( !Count() ) // gar keine gesetzt ?
1081cdf0e10cSrcweir return;
1082cdf0e10cSrcweir
1083cdf0e10cSrcweir // loesche alle Items, die im rSet nicht mehr vorhanden sind
1084cdf0e10cSrcweir if( !rSet.Count() )
1085cdf0e10cSrcweir {
1086cdf0e10cSrcweir ClearItem(); // alles loeschen
1087cdf0e10cSrcweir return;
1088cdf0e10cSrcweir }
1089cdf0e10cSrcweir
1090cdf0e10cSrcweir // teste mal, ob sich die Which-Bereiche unterscheiden.
1091cdf0e10cSrcweir sal_Bool bEqual = sal_True;
1092cdf0e10cSrcweir sal_uInt16* pWh1 = _pWhichRanges;
1093cdf0e10cSrcweir sal_uInt16* pWh2 = rSet._pWhichRanges;
1094cdf0e10cSrcweir sal_uInt16 nSize = 0;
1095cdf0e10cSrcweir
1096cdf0e10cSrcweir for( sal_uInt16 n = 0; *pWh1 && *pWh2; ++pWh1, ++pWh2, ++n )
1097cdf0e10cSrcweir {
1098cdf0e10cSrcweir if( *pWh1 != *pWh2 )
1099cdf0e10cSrcweir {
1100cdf0e10cSrcweir bEqual = sal_False;
1101cdf0e10cSrcweir break;
1102cdf0e10cSrcweir }
1103cdf0e10cSrcweir if( n & 1 )
1104cdf0e10cSrcweir nSize += ( *(pWh1) - *(pWh1-1) ) + 1;
1105cdf0e10cSrcweir }
1106cdf0e10cSrcweir bEqual = *pWh1 == *pWh2; // auch die 0 abpruefen
1107cdf0e10cSrcweir
1108cdf0e10cSrcweir // sind die Bereiche identisch, ist es einfacher zu handhaben !
1109cdf0e10cSrcweir if( bEqual )
1110cdf0e10cSrcweir {
1111cdf0e10cSrcweir SfxItemArray ppFnd1 = _aItems;
1112cdf0e10cSrcweir SfxItemArray ppFnd2 = rSet._aItems;
1113cdf0e10cSrcweir
1114cdf0e10cSrcweir for( ; nSize; --nSize, ++ppFnd1, ++ppFnd2 )
1115cdf0e10cSrcweir if( *ppFnd1 && !*ppFnd2 )
1116cdf0e10cSrcweir {
1117cdf0e10cSrcweir // aus dem Pool loeschen
1118cdf0e10cSrcweir if( !IsInvalidItem( *ppFnd1 ) )
1119cdf0e10cSrcweir {
1120cdf0e10cSrcweir sal_uInt16 nWhich = (*ppFnd1)->Which();
1121cdf0e10cSrcweir if(nWhich <= SFX_WHICH_MAX)
1122cdf0e10cSrcweir {
1123cdf0e10cSrcweir const SfxPoolItem& rNew = _pParent
1124cdf0e10cSrcweir ? _pParent->Get( nWhich, sal_True )
1125cdf0e10cSrcweir : _pPool->GetDefaultItem( nWhich );
1126cdf0e10cSrcweir
1127cdf0e10cSrcweir Changed( **ppFnd1, rNew );
1128cdf0e10cSrcweir }
1129cdf0e10cSrcweir _pPool->Remove( **ppFnd1 );
1130cdf0e10cSrcweir }
1131cdf0e10cSrcweir *ppFnd1 = 0;
1132cdf0e10cSrcweir --_nCount;
1133cdf0e10cSrcweir }
1134cdf0e10cSrcweir }
1135cdf0e10cSrcweir else
1136cdf0e10cSrcweir {
1137cdf0e10cSrcweir SfxItemIter aIter( *this );
1138cdf0e10cSrcweir const SfxPoolItem* pItem = aIter.GetCurItem();
1139cdf0e10cSrcweir while( sal_True )
1140cdf0e10cSrcweir {
1141cdf0e10cSrcweir sal_uInt16 nWhich = IsInvalidItem( pItem )
1142cdf0e10cSrcweir ? GetWhichByPos( aIter.GetCurPos() )
1143cdf0e10cSrcweir : pItem->Which();
1144cdf0e10cSrcweir if( 0 == rSet.GetItemState( nWhich, sal_False ) )
1145cdf0e10cSrcweir ClearItem( nWhich ); // loeschen
1146cdf0e10cSrcweir if( aIter.IsAtEnd() )
1147cdf0e10cSrcweir break;
1148cdf0e10cSrcweir pItem = aIter.NextItem();
1149cdf0e10cSrcweir }
1150cdf0e10cSrcweir }
1151*05f023e4SWang Lei InvalidateHashKey(); //i120575
1152cdf0e10cSrcweir }
1153cdf0e10cSrcweir
1154cdf0e10cSrcweir // -----------------------------------------------------------------------
1155cdf0e10cSrcweir
Differentiate(const SfxItemSet & rSet)1156cdf0e10cSrcweir void SfxItemSet::Differentiate( const SfxItemSet& rSet )
1157cdf0e10cSrcweir {
1158cdf0e10cSrcweir DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet);
1159cdf0e10cSrcweir if( !Count() || !rSet.Count() ) // gar keine gesetzt ?
1160cdf0e10cSrcweir return;
1161cdf0e10cSrcweir
1162cdf0e10cSrcweir // teste mal, ob sich die Which-Bereiche unterscheiden.
1163cdf0e10cSrcweir sal_Bool bEqual = sal_True;
1164cdf0e10cSrcweir sal_uInt16* pWh1 = _pWhichRanges;
1165cdf0e10cSrcweir sal_uInt16* pWh2 = rSet._pWhichRanges;
1166cdf0e10cSrcweir sal_uInt16 nSize = 0;
1167cdf0e10cSrcweir
1168cdf0e10cSrcweir for( sal_uInt16 n = 0; *pWh1 && *pWh2; ++pWh1, ++pWh2, ++n )
1169cdf0e10cSrcweir {
1170cdf0e10cSrcweir if( *pWh1 != *pWh2 )
1171cdf0e10cSrcweir {
1172cdf0e10cSrcweir bEqual = sal_False;
1173cdf0e10cSrcweir break;
1174cdf0e10cSrcweir }
1175cdf0e10cSrcweir if( n & 1 )
1176cdf0e10cSrcweir nSize += ( *(pWh1) - *(pWh1-1) ) + 1;
1177cdf0e10cSrcweir }
1178cdf0e10cSrcweir bEqual = *pWh1 == *pWh2; // auch die 0 abpruefen
1179cdf0e10cSrcweir
1180cdf0e10cSrcweir // sind die Bereiche identisch, ist es einfacher zu handhaben !
1181cdf0e10cSrcweir if( bEqual )
1182cdf0e10cSrcweir {
1183cdf0e10cSrcweir SfxItemArray ppFnd1 = _aItems;
1184cdf0e10cSrcweir SfxItemArray ppFnd2 = rSet._aItems;
1185cdf0e10cSrcweir
1186cdf0e10cSrcweir for( ; nSize; --nSize, ++ppFnd1, ++ppFnd2 )
1187cdf0e10cSrcweir if( *ppFnd1 && *ppFnd2 )
1188cdf0e10cSrcweir {
1189cdf0e10cSrcweir // aus dem Pool loeschen
1190cdf0e10cSrcweir if( !IsInvalidItem( *ppFnd1 ) )
1191cdf0e10cSrcweir {
1192cdf0e10cSrcweir sal_uInt16 nWhich = (*ppFnd1)->Which();
1193cdf0e10cSrcweir if(nWhich <= SFX_WHICH_MAX)
1194cdf0e10cSrcweir {
1195cdf0e10cSrcweir const SfxPoolItem& rNew = _pParent
1196cdf0e10cSrcweir ? _pParent->Get( nWhich, sal_True )
1197cdf0e10cSrcweir : _pPool->GetDefaultItem( nWhich );
1198cdf0e10cSrcweir
1199cdf0e10cSrcweir Changed( **ppFnd1, rNew );
1200cdf0e10cSrcweir }
1201cdf0e10cSrcweir _pPool->Remove( **ppFnd1 );
1202cdf0e10cSrcweir }
1203cdf0e10cSrcweir *ppFnd1 = 0;
1204cdf0e10cSrcweir --_nCount;
1205cdf0e10cSrcweir }
1206cdf0e10cSrcweir }
1207cdf0e10cSrcweir else
1208cdf0e10cSrcweir {
1209cdf0e10cSrcweir SfxItemIter aIter( *this );
1210cdf0e10cSrcweir const SfxPoolItem* pItem = aIter.GetCurItem();
1211cdf0e10cSrcweir while( sal_True )
1212cdf0e10cSrcweir {
1213cdf0e10cSrcweir sal_uInt16 nWhich = IsInvalidItem( pItem )
1214cdf0e10cSrcweir ? GetWhichByPos( aIter.GetCurPos() )
1215cdf0e10cSrcweir : pItem->Which();
1216cdf0e10cSrcweir if( SFX_ITEM_SET == rSet.GetItemState( nWhich, sal_False ) )
1217cdf0e10cSrcweir ClearItem( nWhich ); // loeschen
1218cdf0e10cSrcweir if( aIter.IsAtEnd() )
1219cdf0e10cSrcweir break;
1220cdf0e10cSrcweir pItem = aIter.NextItem();
1221cdf0e10cSrcweir }
1222cdf0e10cSrcweir
1223cdf0e10cSrcweir }
1224*05f023e4SWang Lei InvalidateHashKey(); //i120575
1225cdf0e10cSrcweir }
1226cdf0e10cSrcweir
1227cdf0e10cSrcweir // -----------------------------------------------------------------------
1228cdf0e10cSrcweir /* Entscheidungstabelle fuer MergeValue[s]
1229cdf0e10cSrcweir
1230cdf0e10cSrcweir Grundsaetze:
1231cdf0e10cSrcweir 1. Ist der Which-Wert im 1.Set "unknown", dann folgt niemals eine Aktion.
1232cdf0e10cSrcweir 2. Ist der Which-Wert im 2.Set "unknown", dann gilt er als "default".
1233cdf0e10cSrcweir 3. Es gelten fuer Vergleiche die Werte der "default"-Items.
1234cdf0e10cSrcweir
1235cdf0e10cSrcweir 1.-Item 2.-Item Values bIgnoreDefs Remove Assign Add
1236cdf0e10cSrcweir
1237cdf0e10cSrcweir set set == sal_False - - -
1238cdf0e10cSrcweir default set == sal_False - - -
1239cdf0e10cSrcweir dontcare set == sal_False - - -
1240cdf0e10cSrcweir unknown set == sal_False - - -
1241cdf0e10cSrcweir set default == sal_False - - -
1242cdf0e10cSrcweir default default == sal_False - - -
1243cdf0e10cSrcweir dontcare default == sal_False - - -
1244cdf0e10cSrcweir unknown default == sal_False - - -
1245cdf0e10cSrcweir set dontcare == sal_False 1.-Item -1 -
1246cdf0e10cSrcweir default dontcare == sal_False - -1 -
1247cdf0e10cSrcweir dontcare dontcare == sal_False - - -
1248cdf0e10cSrcweir unknown dontcare == sal_False - - -
1249cdf0e10cSrcweir set unknown == sal_False 1.-Item -1 -
1250cdf0e10cSrcweir default unknown == sal_False - - -
1251cdf0e10cSrcweir dontcare unknown == sal_False - - -
1252cdf0e10cSrcweir unknown unknown == sal_False - - -
1253cdf0e10cSrcweir
1254cdf0e10cSrcweir set set != sal_False 1.-Item -1 -
1255cdf0e10cSrcweir default set != sal_False - -1 -
1256cdf0e10cSrcweir dontcare set != sal_False - - -
1257cdf0e10cSrcweir unknown set != sal_False - - -
1258cdf0e10cSrcweir set default != sal_False 1.-Item -1 -
1259cdf0e10cSrcweir default default != sal_False - - -
1260cdf0e10cSrcweir dontcare default != sal_False - - -
1261cdf0e10cSrcweir unknown default != sal_False - - -
1262cdf0e10cSrcweir set dontcare != sal_False 1.-Item -1 -
1263cdf0e10cSrcweir default dontcare != sal_False - -1 -
1264cdf0e10cSrcweir dontcare dontcare != sal_False - - -
1265cdf0e10cSrcweir unknown dontcare != sal_False - - -
1266cdf0e10cSrcweir set unknown != sal_False 1.-Item -1 -
1267cdf0e10cSrcweir default unknown != sal_False - - -
1268cdf0e10cSrcweir dontcare unknown != sal_False - - -
1269cdf0e10cSrcweir unknown unknown != sal_False - - -
1270cdf0e10cSrcweir
1271cdf0e10cSrcweir set set == sal_True - - -
1272cdf0e10cSrcweir default set == sal_True - 2.-Item 2.-Item
1273cdf0e10cSrcweir dontcare set == sal_True - - -
1274cdf0e10cSrcweir unknown set == sal_True - - -
1275cdf0e10cSrcweir set default == sal_True - - -
1276cdf0e10cSrcweir default default == sal_True - - -
1277cdf0e10cSrcweir dontcare default == sal_True - - -
1278cdf0e10cSrcweir unknown default == sal_True - - -
1279cdf0e10cSrcweir set dontcare == sal_True - - -
1280cdf0e10cSrcweir default dontcare == sal_True - -1 -
1281cdf0e10cSrcweir dontcare dontcare == sal_True - - -
1282cdf0e10cSrcweir unknown dontcare == sal_True - - -
1283cdf0e10cSrcweir set unknown == sal_True - - -
1284cdf0e10cSrcweir default unknown == sal_True - - -
1285cdf0e10cSrcweir dontcare unknown == sal_True - - -
1286cdf0e10cSrcweir unknown unknown == sal_True - - -
1287cdf0e10cSrcweir
1288cdf0e10cSrcweir set set != sal_True 1.-Item -1 -
1289cdf0e10cSrcweir default set != sal_True - 2.-Item 2.-Item
1290cdf0e10cSrcweir dontcare set != sal_True - - -
1291cdf0e10cSrcweir unknown set != sal_True - - -
1292cdf0e10cSrcweir set default != sal_True - - -
1293cdf0e10cSrcweir default default != sal_True - - -
1294cdf0e10cSrcweir dontcare default != sal_True - - -
1295cdf0e10cSrcweir unknown default != sal_True - - -
1296cdf0e10cSrcweir set dontcare != sal_True 1.-Item -1 -
1297cdf0e10cSrcweir default dontcare != sal_True - -1 -
1298cdf0e10cSrcweir dontcare dontcare != sal_True - - -
1299cdf0e10cSrcweir unknown dontcare != sal_True - - -
1300cdf0e10cSrcweir set unknown != sal_True - - -
1301cdf0e10cSrcweir default unknown != sal_True - - -
1302cdf0e10cSrcweir dontcare unknown != sal_True - - -
1303cdf0e10cSrcweir unknown unknown != sal_True - - -
1304cdf0e10cSrcweir */
1305cdf0e10cSrcweir
1306cdf0e10cSrcweir
MergeItem_Impl(SfxItemPool * _pPool,sal_uInt16 & rCount,const SfxPoolItem ** ppFnd1,const SfxPoolItem * pFnd2,sal_Bool bIgnoreDefaults)1307cdf0e10cSrcweir static void MergeItem_Impl( SfxItemPool *_pPool, sal_uInt16 &rCount,
1308cdf0e10cSrcweir const SfxPoolItem **ppFnd1, const SfxPoolItem *pFnd2,
1309cdf0e10cSrcweir sal_Bool bIgnoreDefaults )
1310cdf0e10cSrcweir {
1311cdf0e10cSrcweir DBG_ASSERT( ppFnd1 != 0, "Merging to 0-Item" );
1312cdf0e10cSrcweir
1313cdf0e10cSrcweir // 1. Item ist default?
1314cdf0e10cSrcweir if ( !*ppFnd1 )
1315cdf0e10cSrcweir {
1316cdf0e10cSrcweir if ( IsInvalidItem(pFnd2) )
1317cdf0e10cSrcweir // Entscheidungstabelle: default, dontcare, egal, egal
1318cdf0e10cSrcweir *ppFnd1 = (SfxPoolItem*) -1;
1319cdf0e10cSrcweir
1320cdf0e10cSrcweir else if ( pFnd2 && !bIgnoreDefaults &&
1321cdf0e10cSrcweir _pPool->GetDefaultItem(pFnd2->Which()) != *pFnd2 )
1322cdf0e10cSrcweir // Entscheidungstabelle: default, set, !=, sal_False
1323cdf0e10cSrcweir *ppFnd1 = (SfxPoolItem*) -1;
1324cdf0e10cSrcweir
1325cdf0e10cSrcweir else if ( pFnd2 && bIgnoreDefaults )
1326cdf0e10cSrcweir // Entscheidungstabelle: default, set, egal, sal_True
1327cdf0e10cSrcweir *ppFnd1 = &_pPool->Put( *pFnd2 );
1328cdf0e10cSrcweir
1329cdf0e10cSrcweir if ( *ppFnd1 )
1330cdf0e10cSrcweir ++rCount;
1331cdf0e10cSrcweir }
1332cdf0e10cSrcweir
1333cdf0e10cSrcweir // 1. Item ist gesetzt?
1334cdf0e10cSrcweir else if ( !IsInvalidItem(*ppFnd1) )
1335cdf0e10cSrcweir {
1336cdf0e10cSrcweir if ( !pFnd2 )
1337cdf0e10cSrcweir {
1338cdf0e10cSrcweir // 2. Item ist default
1339cdf0e10cSrcweir if ( !bIgnoreDefaults &&
1340cdf0e10cSrcweir **ppFnd1 != _pPool->GetDefaultItem((*ppFnd1)->Which()) )
1341cdf0e10cSrcweir {
1342cdf0e10cSrcweir // Entscheidungstabelle: set, default, !=, sal_False
1343cdf0e10cSrcweir _pPool->Remove( **ppFnd1 );
1344cdf0e10cSrcweir *ppFnd1 = (SfxPoolItem*) -1;
1345cdf0e10cSrcweir }
1346cdf0e10cSrcweir }
1347cdf0e10cSrcweir else if ( IsInvalidItem(pFnd2) )
1348cdf0e10cSrcweir {
1349cdf0e10cSrcweir // 2. Item ist dontcare
1350cdf0e10cSrcweir if ( !bIgnoreDefaults ||
1351cdf0e10cSrcweir **ppFnd1 != _pPool->GetDefaultItem( (*ppFnd1)->Which()) )
1352cdf0e10cSrcweir {
1353cdf0e10cSrcweir // Entscheidungstabelle: set, dontcare, egal, sal_False
1354cdf0e10cSrcweir // oder: set, dontcare, !=, sal_True
1355cdf0e10cSrcweir _pPool->Remove( **ppFnd1 );
1356cdf0e10cSrcweir *ppFnd1 = (SfxPoolItem*) -1;
1357cdf0e10cSrcweir }
1358cdf0e10cSrcweir }
1359cdf0e10cSrcweir else
1360cdf0e10cSrcweir {
1361cdf0e10cSrcweir // 2. Item ist gesetzt
1362cdf0e10cSrcweir if ( **ppFnd1 != *pFnd2 )
1363cdf0e10cSrcweir {
1364cdf0e10cSrcweir // Entscheidungstabelle: set, set, !=, egal
1365cdf0e10cSrcweir _pPool->Remove( **ppFnd1 );
1366cdf0e10cSrcweir *ppFnd1 = (SfxPoolItem*) -1;
1367cdf0e10cSrcweir }
1368cdf0e10cSrcweir }
1369cdf0e10cSrcweir }
1370cdf0e10cSrcweir }
1371cdf0e10cSrcweir
1372cdf0e10cSrcweir // -----------------------------------------------------------------------
1373cdf0e10cSrcweir
MergeValues(const SfxItemSet & rSet,sal_Bool bIgnoreDefaults)1374cdf0e10cSrcweir void SfxItemSet::MergeValues( const SfxItemSet& rSet, sal_Bool bIgnoreDefaults )
1375cdf0e10cSrcweir {
1376cdf0e10cSrcweir // Achtung!!! Bei Aenderungen/Bugfixes immer obenstehende Tabelle pflegen!
1377cdf0e10cSrcweir DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet);
1378cdf0e10cSrcweir DBG_ASSERT( GetPool() == rSet.GetPool(), "MergeValues mit verschiedenen Pools" );
1379cdf0e10cSrcweir
1380cdf0e10cSrcweir // teste mal, ob sich die Which-Bereiche unterscheiden.
1381cdf0e10cSrcweir sal_Bool bEqual = sal_True;
1382cdf0e10cSrcweir sal_uInt16* pWh1 = _pWhichRanges;
1383cdf0e10cSrcweir sal_uInt16* pWh2 = rSet._pWhichRanges;
1384cdf0e10cSrcweir sal_uInt16 nSize = 0;
1385cdf0e10cSrcweir
1386cdf0e10cSrcweir for( sal_uInt16 n = 0; *pWh1 && *pWh2; ++pWh1, ++pWh2, ++n )
1387cdf0e10cSrcweir {
1388cdf0e10cSrcweir if( *pWh1 != *pWh2 )
1389cdf0e10cSrcweir {
1390cdf0e10cSrcweir bEqual = sal_False;
1391cdf0e10cSrcweir break;
1392cdf0e10cSrcweir }
1393cdf0e10cSrcweir if( n & 1 )
1394cdf0e10cSrcweir nSize += ( *(pWh1) - *(pWh1-1) ) + 1;
1395cdf0e10cSrcweir }
1396cdf0e10cSrcweir bEqual = *pWh1 == *pWh2; // auch die 0 abpruefen
1397cdf0e10cSrcweir
1398cdf0e10cSrcweir // sind die Bereiche identisch, ist es effizieter zu handhaben !
1399cdf0e10cSrcweir if( bEqual )
1400cdf0e10cSrcweir {
1401cdf0e10cSrcweir SfxItemArray ppFnd1 = _aItems;
1402cdf0e10cSrcweir SfxItemArray ppFnd2 = rSet._aItems;
1403cdf0e10cSrcweir
1404cdf0e10cSrcweir for( ; nSize; --nSize, ++ppFnd1, ++ppFnd2 )
1405cdf0e10cSrcweir MergeItem_Impl( _pPool, _nCount, ppFnd1, *ppFnd2, bIgnoreDefaults );
1406cdf0e10cSrcweir }
1407cdf0e10cSrcweir else
1408cdf0e10cSrcweir {
1409cdf0e10cSrcweir SfxWhichIter aIter( rSet );
1410cdf0e10cSrcweir register sal_uInt16 nWhich;
1411cdf0e10cSrcweir while( 0 != ( nWhich = aIter.NextWhich() ) )
1412cdf0e10cSrcweir {
1413cdf0e10cSrcweir const SfxPoolItem* pItem = 0;
1414cdf0e10cSrcweir rSet.GetItemState( nWhich, sal_True, &pItem );
1415cdf0e10cSrcweir if( !pItem )
1416cdf0e10cSrcweir {
1417cdf0e10cSrcweir // nicht gesetzt, also default
1418cdf0e10cSrcweir if ( !bIgnoreDefaults )
1419cdf0e10cSrcweir MergeValue( rSet.GetPool()->GetDefaultItem( nWhich ), bIgnoreDefaults );
1420cdf0e10cSrcweir }
1421cdf0e10cSrcweir else if( IsInvalidItem( pItem ) )
1422cdf0e10cSrcweir // dont care
1423cdf0e10cSrcweir InvalidateItem( nWhich );
1424cdf0e10cSrcweir else
1425cdf0e10cSrcweir MergeValue( *pItem, bIgnoreDefaults );
1426cdf0e10cSrcweir }
1427cdf0e10cSrcweir }
1428*05f023e4SWang Lei InvalidateHashKey(); //i120575
1429cdf0e10cSrcweir }
1430cdf0e10cSrcweir
1431cdf0e10cSrcweir // -----------------------------------------------------------------------
1432cdf0e10cSrcweir
MergeValue(const SfxPoolItem & rAttr,sal_Bool bIgnoreDefaults)1433cdf0e10cSrcweir void SfxItemSet::MergeValue( const SfxPoolItem& rAttr, sal_Bool bIgnoreDefaults )
1434cdf0e10cSrcweir {
1435cdf0e10cSrcweir DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet);
1436cdf0e10cSrcweir SfxItemArray ppFnd = _aItems;
1437cdf0e10cSrcweir const sal_uInt16* pPtr = _pWhichRanges;
1438cdf0e10cSrcweir const sal_uInt16 nWhich = rAttr.Which();
1439cdf0e10cSrcweir while( *pPtr )
1440cdf0e10cSrcweir {
1441cdf0e10cSrcweir // in diesem Bereich?
1442cdf0e10cSrcweir if( *pPtr <= nWhich && nWhich <= *(pPtr+1) )
1443cdf0e10cSrcweir {
1444cdf0e10cSrcweir ppFnd += nWhich - *pPtr;
1445cdf0e10cSrcweir MergeItem_Impl( _pPool, _nCount, ppFnd, &rAttr, bIgnoreDefaults );
1446cdf0e10cSrcweir break;
1447cdf0e10cSrcweir }
1448cdf0e10cSrcweir ppFnd += *(pPtr+1) - *pPtr + 1;
1449cdf0e10cSrcweir pPtr += 2;
1450cdf0e10cSrcweir }
1451*05f023e4SWang Lei InvalidateHashKey(); //i120575
1452cdf0e10cSrcweir }
1453cdf0e10cSrcweir
1454cdf0e10cSrcweir // -----------------------------------------------------------------------
1455cdf0e10cSrcweir
InvalidateItem(sal_uInt16 nWhich)1456cdf0e10cSrcweir void SfxItemSet::InvalidateItem( sal_uInt16 nWhich )
1457cdf0e10cSrcweir {
1458cdf0e10cSrcweir DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet);
1459cdf0e10cSrcweir SfxItemArray ppFnd = _aItems;
1460cdf0e10cSrcweir const sal_uInt16* pPtr = _pWhichRanges;
1461cdf0e10cSrcweir while( *pPtr )
1462cdf0e10cSrcweir {
1463cdf0e10cSrcweir if( *pPtr <= nWhich && nWhich <= *(pPtr+1) )
1464cdf0e10cSrcweir {
1465cdf0e10cSrcweir // in diesem Bereich
1466cdf0e10cSrcweir ppFnd += nWhich - *pPtr;
1467cdf0e10cSrcweir
1468cdf0e10cSrcweir if( *ppFnd ) // bei mir gesetzt
1469cdf0e10cSrcweir {
1470cdf0e10cSrcweir if( (SfxPoolItem*)-1 != *ppFnd ) // noch nicht dontcare !
1471cdf0e10cSrcweir {
1472cdf0e10cSrcweir _pPool->Remove( **ppFnd );
1473cdf0e10cSrcweir *ppFnd = (SfxPoolItem*)-1;
1474cdf0e10cSrcweir }
1475cdf0e10cSrcweir }
1476cdf0e10cSrcweir else
1477cdf0e10cSrcweir {
1478cdf0e10cSrcweir *ppFnd = (SfxPoolItem*)-1;
1479cdf0e10cSrcweir ++_nCount;
1480cdf0e10cSrcweir }
1481cdf0e10cSrcweir break;
1482cdf0e10cSrcweir }
1483cdf0e10cSrcweir ppFnd += *(pPtr+1) - *pPtr + 1;
1484cdf0e10cSrcweir pPtr += 2;
1485cdf0e10cSrcweir }
1486*05f023e4SWang Lei InvalidateHashKey(); //i120575
1487cdf0e10cSrcweir }
1488cdf0e10cSrcweir
1489cdf0e10cSrcweir // -----------------------------------------------------------------------
1490cdf0e10cSrcweir
GetWhichByPos(sal_uInt16 nPos) const1491cdf0e10cSrcweir sal_uInt16 SfxItemSet::GetWhichByPos( sal_uInt16 nPos ) const
1492cdf0e10cSrcweir {
1493cdf0e10cSrcweir DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet);
1494cdf0e10cSrcweir sal_uInt16 n = 0;
1495cdf0e10cSrcweir sal_uInt16* pPtr = _pWhichRanges;
1496cdf0e10cSrcweir while( *pPtr )
1497cdf0e10cSrcweir {
1498cdf0e10cSrcweir n = ( *(pPtr+1) - *pPtr ) + 1;
1499cdf0e10cSrcweir if( nPos < n )
1500cdf0e10cSrcweir return *(pPtr)+nPos;
1501cdf0e10cSrcweir nPos = nPos - n;
1502cdf0e10cSrcweir pPtr += 2;
1503cdf0e10cSrcweir }
1504cdf0e10cSrcweir DBG_ASSERT( sal_False, "Hier sind wir falsch" );
1505cdf0e10cSrcweir return 0;
1506cdf0e10cSrcweir }
1507cdf0e10cSrcweir
1508cdf0e10cSrcweir // -----------------------------------------------------------------------
1509cdf0e10cSrcweir
Store(SvStream & rStream,FASTBOOL bDirect) const1510cdf0e10cSrcweir SvStream &SfxItemSet::Store
1511cdf0e10cSrcweir (
1512cdf0e10cSrcweir SvStream& rStream, // Zielstream f"ur normale Items
1513cdf0e10cSrcweir FASTBOOL bDirect // sal_True: Items direkt speicher, sal_False: Surrogate
1514cdf0e10cSrcweir ) const
1515cdf0e10cSrcweir
1516cdf0e10cSrcweir /* [Beschreibung]
1517cdf0e10cSrcweir
1518cdf0e10cSrcweir Speichert die <SfxItemSet>-Instanz in den angegebenen Stream. Dabei
1519cdf0e10cSrcweir werden die Surrorage der gesetzten <SfxPoolItem>s bzw. ('bDirect==sal_True')
1520cdf0e10cSrcweir die gesetzten Items selbst wie folgt im Stream abgelegt:
1521cdf0e10cSrcweir
1522cdf0e10cSrcweir sal_uInt16 (Count) Anzahl der gesetzten Items
1523cdf0e10cSrcweir Count* _pPool->StoreItem() siehe <SfxItemPool::StoreItem()const>
1524cdf0e10cSrcweir
1525cdf0e10cSrcweir
1526cdf0e10cSrcweir [Querverweise]
1527cdf0e10cSrcweir
1528cdf0e10cSrcweir <SfxItemSet::Load(SvStream&,sal_Bool,const SfxItemPool*)>
1529cdf0e10cSrcweir */
1530cdf0e10cSrcweir
1531cdf0e10cSrcweir {
1532cdf0e10cSrcweir DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet);
1533cdf0e10cSrcweir DBG_ASSERT( _pPool, "Kein Pool" );
1534cdf0e10cSrcweir DBG_ASSERTWARNING( _pPool == _pPool->GetMasterPool(), "kein Master-Pool" );
1535cdf0e10cSrcweir
1536cdf0e10cSrcweir // Position des Counts merken, um ggf. zu korrigieren
1537cdf0e10cSrcweir sal_uLong nCountPos = rStream.Tell();
1538cdf0e10cSrcweir rStream << _nCount;
1539cdf0e10cSrcweir
1540cdf0e10cSrcweir // wenn nichts zu speichern ist, auch keinen ItemIter aufsetzen!
1541cdf0e10cSrcweir if ( _nCount )
1542cdf0e10cSrcweir {
1543cdf0e10cSrcweir // mitz"ahlen wieviel Items tats"achlich gespeichert werden
1544cdf0e10cSrcweir sal_uInt16 nWrittenCount = 0; // Anzahl in 'rStream' gestreamter Items
1545cdf0e10cSrcweir
1546cdf0e10cSrcweir // "uber alle gesetzten Items iterieren
1547cdf0e10cSrcweir SfxItemIter aIter(*this);
1548cdf0e10cSrcweir for ( const SfxPoolItem *pItem = aIter.FirstItem();
1549cdf0e10cSrcweir pItem;
1550cdf0e10cSrcweir pItem = aIter.NextItem() )
1551cdf0e10cSrcweir {
1552cdf0e10cSrcweir // Item (ggf. als Surrogat) via Pool speichern lassen
1553cdf0e10cSrcweir DBG_ASSERT( !IsInvalidItem(pItem), "can't store invalid items" );
1554cdf0e10cSrcweir if ( !IsInvalidItem(pItem) &&
1555cdf0e10cSrcweir _pPool->StoreItem( rStream, *pItem, bDirect ) )
1556cdf0e10cSrcweir // Item wurde in 'rStream' gestreamt
1557cdf0e10cSrcweir ++nWrittenCount;
1558cdf0e10cSrcweir };
1559cdf0e10cSrcweir
1560cdf0e10cSrcweir // weniger geschrieben als enthalten (z.B. altes Format)
1561cdf0e10cSrcweir if ( nWrittenCount != _nCount )
1562cdf0e10cSrcweir {
1563cdf0e10cSrcweir // tats"achlichen Count im Stream ablegen
1564cdf0e10cSrcweir sal_uLong nPos = rStream.Tell();
1565cdf0e10cSrcweir rStream.Seek( nCountPos );
1566cdf0e10cSrcweir rStream << nWrittenCount;
1567cdf0e10cSrcweir rStream.Seek( nPos );
1568cdf0e10cSrcweir }
1569cdf0e10cSrcweir }
1570cdf0e10cSrcweir
1571cdf0e10cSrcweir return rStream;
1572cdf0e10cSrcweir }
1573cdf0e10cSrcweir
1574cdf0e10cSrcweir // -----------------------------------------------------------------------
1575cdf0e10cSrcweir
Load(SvStream & rStream,FASTBOOL bDirect,const SfxItemPool * pRefPool)1576cdf0e10cSrcweir SvStream &SfxItemSet::Load
1577cdf0e10cSrcweir (
1578cdf0e10cSrcweir SvStream& rStream, // Stream, aus dem geladen werden soll
1579cdf0e10cSrcweir
1580cdf0e10cSrcweir FASTBOOL bDirect, /* sal_True
1581cdf0e10cSrcweir Items werden direkt aus dem Stream
1582cdf0e10cSrcweir gelesen, nicht "uber Surrogate
1583cdf0e10cSrcweir
1584cdf0e10cSrcweir sal_False (default)
1585cdf0e10cSrcweir Items werden "uber Surrogate gelesen */
1586cdf0e10cSrcweir
1587cdf0e10cSrcweir const SfxItemPool* pRefPool /* Pool, der die Surrogate aufl"osen kann
1588cdf0e10cSrcweir (z.B. zum Einf"ugen von Dokumenten) */
1589cdf0e10cSrcweir )
1590cdf0e10cSrcweir
1591cdf0e10cSrcweir /* [Beschreibung]
1592cdf0e10cSrcweir
1593cdf0e10cSrcweir Diese Methode l"adt ein <SfxItemSet> aus einem Stream. Falls der
1594cdf0e10cSrcweir <SfxItemPool> ohne Ref-Counts geladen wurde, werden die geladenen
1595cdf0e10cSrcweir Item-Referenzen in den Items hochgez"ahlt, ansonsten wird vorausgesetzt,
1596cdf0e10cSrcweir da\s sie schon beim Laden des SfxItemPools ber"ucksichtigt waren.
1597cdf0e10cSrcweir
1598cdf0e10cSrcweir [Querverweise]
1599cdf0e10cSrcweir
1600cdf0e10cSrcweir <SfxItemSet::Store(Stream&,sal_Bool)const>
1601cdf0e10cSrcweir */
1602cdf0e10cSrcweir
1603cdf0e10cSrcweir {
1604cdf0e10cSrcweir DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet);
1605cdf0e10cSrcweir DBG_ASSERT( _pPool, "Kein Pool");
1606cdf0e10cSrcweir DBG_ASSERTWARNING( _pPool == _pPool->GetMasterPool(), "Kein Master-Pool");
1607cdf0e10cSrcweir
1608cdf0e10cSrcweir // kein Ref-Pool => Surrogate mit Pool des ItemSets aufl"osen
1609cdf0e10cSrcweir if ( !pRefPool )
1610cdf0e10cSrcweir pRefPool = _pPool;
1611cdf0e10cSrcweir
1612cdf0e10cSrcweir // Anzahl der zu ladenden Items laden und dann ebensoviele Items
1613cdf0e10cSrcweir sal_uInt16 nCount = 0;
1614cdf0e10cSrcweir rStream >> nCount;
1615cdf0e10cSrcweir for ( sal_uInt16 i = 0; i < nCount; ++i )
1616cdf0e10cSrcweir {
1617cdf0e10cSrcweir // Surrogat/Item laden und (Surrogat) aufl"osen lassen
1618cdf0e10cSrcweir const SfxPoolItem *pItem =
1619cdf0e10cSrcweir _pPool->LoadItem( rStream, bDirect, pRefPool );
1620cdf0e10cSrcweir
1621cdf0e10cSrcweir // konnte ein Item geladen oder via Surrogat aufgel"ost werden?
1622cdf0e10cSrcweir if ( pItem )
1623cdf0e10cSrcweir {
1624cdf0e10cSrcweir // Position f"ur Item-Pointer im Set suchen
1625cdf0e10cSrcweir sal_uInt16 nWhich = pItem->Which();
1626cdf0e10cSrcweir SfxItemArray ppFnd = _aItems;
1627cdf0e10cSrcweir const sal_uInt16* pPtr = _pWhichRanges;
1628cdf0e10cSrcweir while ( *pPtr )
1629cdf0e10cSrcweir {
1630cdf0e10cSrcweir // in diesem Bereich?
1631cdf0e10cSrcweir if ( *pPtr <= nWhich && nWhich <= *(pPtr+1) )
1632cdf0e10cSrcweir {
1633cdf0e10cSrcweir // Item-Pointer im Set merken
1634cdf0e10cSrcweir ppFnd += nWhich - *pPtr;
1635cdf0e10cSrcweir SFX_ASSERT( !*ppFnd, nWhich, "Item doppelt eingetragen");
1636cdf0e10cSrcweir *ppFnd = pItem;
1637cdf0e10cSrcweir ++_nCount;
1638cdf0e10cSrcweir break;
1639cdf0e10cSrcweir }
1640cdf0e10cSrcweir
1641cdf0e10cSrcweir // im Range-Array und Item-Array zum n"achsten Which-Range
1642cdf0e10cSrcweir ppFnd += *(pPtr+1) - *pPtr + 1;
1643cdf0e10cSrcweir pPtr += 2;
1644cdf0e10cSrcweir }
1645cdf0e10cSrcweir }
1646cdf0e10cSrcweir }
1647cdf0e10cSrcweir
1648*05f023e4SWang Lei
1649*05f023e4SWang Lei InvalidateHashKey(); //i120575
1650cdf0e10cSrcweir return rStream;
1651cdf0e10cSrcweir }
1652cdf0e10cSrcweir
1653cdf0e10cSrcweir // -----------------------------------------------------------------------
1654cdf0e10cSrcweir
operator ==(const SfxItemSet & rCmp) const1655cdf0e10cSrcweir int SfxItemSet::operator==(const SfxItemSet &rCmp) const
1656cdf0e10cSrcweir {
1657cdf0e10cSrcweir DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet);
1658cdf0e10cSrcweir DBG_CHKOBJ(&rCmp, SfxItemSet, DbgCheckItemSet);
1659cdf0e10cSrcweir
1660cdf0e10cSrcweir // besonders schnell zu ermittelnde Werte muessen gleich sein
1661cdf0e10cSrcweir if ( _pParent != rCmp._pParent ||
1662cdf0e10cSrcweir _pPool != rCmp._pPool ||
1663cdf0e10cSrcweir Count() != rCmp.Count() )
1664cdf0e10cSrcweir return sal_False;
1665cdf0e10cSrcweir
1666cdf0e10cSrcweir // Ranges durchzaehlen lassen dauert laenger, muss aber auch gleich sein
1667cdf0e10cSrcweir sal_uInt16 nCount1 = TotalCount();
1668cdf0e10cSrcweir sal_uInt16 nCount2 = rCmp.TotalCount();
1669cdf0e10cSrcweir if ( nCount1 != nCount2 )
1670cdf0e10cSrcweir return sal_False;
1671cdf0e10cSrcweir
1672cdf0e10cSrcweir // sind die Ranges selbst ungleich?
1673cdf0e10cSrcweir for ( sal_uInt16 nRange = 0; _pWhichRanges[nRange]; nRange += 2 )
1674cdf0e10cSrcweir if ( _pWhichRanges[nRange] != rCmp._pWhichRanges[nRange] ||
1675cdf0e10cSrcweir _pWhichRanges[nRange+1] != rCmp._pWhichRanges[nRange+1] )
1676cdf0e10cSrcweir {
1677cdf0e10cSrcweir // dann m"ussen wir die langsame Methode verwenden
1678cdf0e10cSrcweir SfxWhichIter aIter( *this );
1679cdf0e10cSrcweir for ( sal_uInt16 nWh = aIter.FirstWhich();
1680cdf0e10cSrcweir nWh;
1681cdf0e10cSrcweir nWh = aIter.NextWhich() )
1682cdf0e10cSrcweir {
1683cdf0e10cSrcweir // wenn die Pointer von poolable Items ungleich sind,
1684cdf0e10cSrcweir // muessen die Items gleich sein
1685cdf0e10cSrcweir const SfxPoolItem *pItem1 = 0, *pItem2 = 0;
1686cdf0e10cSrcweir if ( GetItemState( nWh, sal_False, &pItem1 ) !=
1687cdf0e10cSrcweir rCmp.GetItemState( nWh, sal_False, &pItem2 ) ||
1688cdf0e10cSrcweir ( pItem1 != pItem2 &&
1689cdf0e10cSrcweir ( !pItem1 || IsInvalidItem(pItem1) ||
1690cdf0e10cSrcweir ( _pPool->IsItemFlag(*pItem1, SFX_ITEM_POOLABLE) &&
1691cdf0e10cSrcweir *pItem1 != *pItem2 ) ) ) )
1692cdf0e10cSrcweir return sal_False;
1693cdf0e10cSrcweir }
1694cdf0e10cSrcweir
1695cdf0e10cSrcweir return sal_True;
1696cdf0e10cSrcweir }
1697cdf0e10cSrcweir
1698cdf0e10cSrcweir // Pointer alle gleich?
1699cdf0e10cSrcweir if ( 0 == memcmp( _aItems, rCmp._aItems, nCount1 * sizeof(_aItems[0]) ) )
1700cdf0e10cSrcweir return sal_True;
1701cdf0e10cSrcweir
1702cdf0e10cSrcweir // dann werden wir wohl alle einzeln vergleichen muessen
1703cdf0e10cSrcweir const SfxPoolItem **ppItem1 = (const SfxPoolItem**) _aItems;
1704cdf0e10cSrcweir const SfxPoolItem **ppItem2 = (const SfxPoolItem**) rCmp._aItems;
1705cdf0e10cSrcweir for ( sal_uInt16 nPos = 0; nPos < nCount1; ++nPos )
1706cdf0e10cSrcweir {
1707cdf0e10cSrcweir // wenn die Pointer von poolable Items ungleich sind,
1708cdf0e10cSrcweir // muessen die Items gleich sein
1709cdf0e10cSrcweir if ( *ppItem1 != *ppItem2 &&
1710cdf0e10cSrcweir ( ( !*ppItem1 || !*ppItem2 ) ||
1711cdf0e10cSrcweir ( IsInvalidItem(*ppItem1) || IsInvalidItem(*ppItem2) ) ||
1712cdf0e10cSrcweir ( _pPool->IsItemFlag(**ppItem1, SFX_ITEM_POOLABLE) ) ||
1713cdf0e10cSrcweir **ppItem1 != **ppItem2 ) )
1714cdf0e10cSrcweir return sal_False;
1715cdf0e10cSrcweir
1716cdf0e10cSrcweir ++ppItem1;
1717cdf0e10cSrcweir ++ppItem2;
1718cdf0e10cSrcweir }
1719cdf0e10cSrcweir
1720cdf0e10cSrcweir return sal_True;
1721cdf0e10cSrcweir }
1722cdf0e10cSrcweir
1723cdf0e10cSrcweir // -----------------------------------------------------------------------
1724cdf0e10cSrcweir
Clone(sal_Bool bItems,SfxItemPool * pToPool) const1725cdf0e10cSrcweir SfxItemSet *SfxItemSet::Clone(sal_Bool bItems, SfxItemPool *pToPool ) const
1726cdf0e10cSrcweir {
1727cdf0e10cSrcweir DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet);
1728cdf0e10cSrcweir if ( pToPool && pToPool != _pPool )
1729cdf0e10cSrcweir {
1730cdf0e10cSrcweir SfxItemSet *pNewSet = new SfxItemSet( *pToPool, _pWhichRanges );
1731cdf0e10cSrcweir if ( bItems )
1732cdf0e10cSrcweir {
1733cdf0e10cSrcweir SfxWhichIter aIter(*pNewSet);
1734cdf0e10cSrcweir sal_uInt16 nWhich = aIter.FirstWhich();
1735cdf0e10cSrcweir while ( nWhich )
1736cdf0e10cSrcweir {
1737cdf0e10cSrcweir const SfxPoolItem* pItem;
1738cdf0e10cSrcweir if ( SFX_ITEM_SET == GetItemState( nWhich, sal_False, &pItem ) )
1739cdf0e10cSrcweir pNewSet->Put( *pItem, pItem->Which() );
1740cdf0e10cSrcweir nWhich = aIter.NextWhich();
1741cdf0e10cSrcweir }
1742cdf0e10cSrcweir }
1743cdf0e10cSrcweir return pNewSet;
1744cdf0e10cSrcweir }
1745cdf0e10cSrcweir else
1746cdf0e10cSrcweir return bItems
1747cdf0e10cSrcweir ? new SfxItemSet(*this)
1748cdf0e10cSrcweir : new SfxItemSet(*_pPool, _pWhichRanges);
1749cdf0e10cSrcweir }
1750cdf0e10cSrcweir
1751cdf0e10cSrcweir // -----------------------------------------------------------------------
1752cdf0e10cSrcweir
PutDirect(const SfxPoolItem & rItem)1753cdf0e10cSrcweir int SfxItemSet::PutDirect(const SfxPoolItem &rItem)
1754cdf0e10cSrcweir {
1755cdf0e10cSrcweir DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet);
1756cdf0e10cSrcweir SfxItemArray ppFnd = _aItems;
1757cdf0e10cSrcweir const sal_uInt16* pPtr = _pWhichRanges;
1758cdf0e10cSrcweir const sal_uInt16 nWhich = rItem.Which();
1759cdf0e10cSrcweir #ifdef DBG_UTIL
1760cdf0e10cSrcweir IsPoolDefaultItem(&rItem) || _pPool->GetSurrogate(&rItem);
1761cdf0e10cSrcweir // nur Assertion in den callees provozieren
1762cdf0e10cSrcweir #endif
1763cdf0e10cSrcweir while( *pPtr )
1764cdf0e10cSrcweir {
1765cdf0e10cSrcweir if( *pPtr <= nWhich && nWhich <= *(pPtr+1) )
1766cdf0e10cSrcweir {
1767cdf0e10cSrcweir // in diesem Bereich
1768cdf0e10cSrcweir ppFnd += nWhich - *pPtr;
1769cdf0e10cSrcweir const SfxPoolItem* pOld = *ppFnd;
1770cdf0e10cSrcweir if( pOld ) // schon einer vorhanden
1771cdf0e10cSrcweir {
1772cdf0e10cSrcweir if( rItem == **ppFnd )
1773cdf0e10cSrcweir return sal_False; // schon vorhanden !
1774cdf0e10cSrcweir _pPool->Remove( *pOld );
1775cdf0e10cSrcweir }
1776cdf0e10cSrcweir else
1777cdf0e10cSrcweir ++_nCount;
1778cdf0e10cSrcweir
1779cdf0e10cSrcweir // den neuen eintragen
1780cdf0e10cSrcweir if( IsPoolDefaultItem(&rItem) )
1781cdf0e10cSrcweir *ppFnd = &_pPool->Put( rItem );
1782cdf0e10cSrcweir else
1783cdf0e10cSrcweir {
1784cdf0e10cSrcweir *ppFnd = &rItem;
1785cdf0e10cSrcweir if( !IsStaticDefaultItem( &rItem ) )
1786cdf0e10cSrcweir rItem.AddRef();
1787cdf0e10cSrcweir }
1788cdf0e10cSrcweir
1789*05f023e4SWang Lei InvalidateHashKey(); //i120575
1790cdf0e10cSrcweir return sal_True;
1791cdf0e10cSrcweir }
1792cdf0e10cSrcweir ppFnd += *(pPtr+1) - *pPtr + 1;
1793cdf0e10cSrcweir pPtr += 2;
1794cdf0e10cSrcweir }
1795cdf0e10cSrcweir return sal_False;
1796cdf0e10cSrcweir }
1797cdf0e10cSrcweir
1798cdf0e10cSrcweir // -----------------------------------------------------------------------
1799cdf0e10cSrcweir
SfxAllItemSet(SfxItemPool & rPool)1800cdf0e10cSrcweir SfxAllItemSet::SfxAllItemSet( SfxItemPool &rPool )
1801cdf0e10cSrcweir : SfxItemSet(rPool, (const sal_uInt16*) 0),
1802cdf0e10cSrcweir aDefault(0),
1803cdf0e10cSrcweir nFree(nInitCount)
1804cdf0e10cSrcweir {
1805cdf0e10cSrcweir // initial keine Items
1806cdf0e10cSrcweir _aItems = 0;
1807cdf0e10cSrcweir
1808cdf0e10cSrcweir // nInitCount Paare an USHORTs fuer Ranges allozieren
1809cdf0e10cSrcweir _pWhichRanges = new sal_uInt16[ nInitCount + 1 ];
1810cdf0e10cSrcweir memset( _pWhichRanges, 0, ( nInitCount + 1 ) * sizeof(sal_uInt16) );
1811cdf0e10cSrcweir }
1812cdf0e10cSrcweir
1813cdf0e10cSrcweir
1814cdf0e10cSrcweir // -----------------------------------------------------------------------
1815cdf0e10cSrcweir
1816cdf0e10cSrcweir
SfxAllItemSet(const SfxItemSet & rCopy)1817cdf0e10cSrcweir SfxAllItemSet::SfxAllItemSet(const SfxItemSet &rCopy)
1818cdf0e10cSrcweir : SfxItemSet(rCopy),
1819cdf0e10cSrcweir aDefault(0),
1820cdf0e10cSrcweir nFree(0)
1821cdf0e10cSrcweir {
1822cdf0e10cSrcweir }
1823cdf0e10cSrcweir
1824cdf0e10cSrcweir // -----------------------------------------------------------------------
1825cdf0e10cSrcweir
1826cdf0e10cSrcweir
1827cdf0e10cSrcweir
SfxAllItemSet(const SfxAllItemSet & rCopy)1828cdf0e10cSrcweir SfxAllItemSet::SfxAllItemSet(const SfxAllItemSet &rCopy)
1829cdf0e10cSrcweir : SfxItemSet(rCopy),
1830cdf0e10cSrcweir aDefault(0),
1831cdf0e10cSrcweir nFree(0)
1832cdf0e10cSrcweir /* [Anmerkung]
1833cdf0e10cSrcweir
1834cdf0e10cSrcweir Der mu\s sein, da sonst vom Compiler einer generiert wird, er nimmt
1835cdf0e10cSrcweir nicht den Ctor mit der 'const SfxItemSet&'!
1836cdf0e10cSrcweir */
1837cdf0e10cSrcweir {
1838cdf0e10cSrcweir }
1839cdf0e10cSrcweir
1840cdf0e10cSrcweir // -----------------------------------------------------------------------
1841cdf0e10cSrcweir
AddRanges_Impl(sal_uInt16 * pUS,std::ptrdiff_t nOldSize,sal_uInt16 nIncr)1842cdf0e10cSrcweir static sal_uInt16 *AddRanges_Impl(
1843cdf0e10cSrcweir sal_uInt16 *pUS, std::ptrdiff_t nOldSize, sal_uInt16 nIncr)
1844cdf0e10cSrcweir
1845cdf0e10cSrcweir /* Diese interne Funktion erzeugt ein neues Which-Range-Array, welches von
1846cdf0e10cSrcweir dem 'nOldSize'-USHORTs langen 'pUS' kopiert wird und hinten an Platz
1847cdf0e10cSrcweir f"ur 'nIncr' neue USHORTs hat. Das terminierende sal_uInt16 mit der '0'
1848cdf0e10cSrcweir wird weder in 'nOldSize' noch in 'nIncr' mitgez"ahlt, sondern implizit
1849cdf0e10cSrcweir hinzugerechnet.
1850cdf0e10cSrcweir
1851cdf0e10cSrcweir Das neue Which-Range-Array wird als Returnwert zur"uckgegeben, das alte
1852cdf0e10cSrcweir 'pUS' freigegeben.
1853cdf0e10cSrcweir */
1854cdf0e10cSrcweir
1855cdf0e10cSrcweir {
1856cdf0e10cSrcweir // neues Which-Range-Array anlegen
1857cdf0e10cSrcweir sal_uInt16 *pNew = new sal_uInt16[ nOldSize + nIncr + 1 ];
1858cdf0e10cSrcweir
1859cdf0e10cSrcweir // die alten Ranges "ubernehmen
1860cdf0e10cSrcweir memcpy( pNew, pUS, nOldSize * sizeof(sal_uInt16) );
1861cdf0e10cSrcweir
1862cdf0e10cSrcweir // die neuen auf 0 initialisieren
1863cdf0e10cSrcweir memset( pNew + nOldSize, 0, ( nIncr + 1 ) * sizeof(sal_uInt16) );
1864cdf0e10cSrcweir
1865cdf0e10cSrcweir // das alte Array freigeben
1866cdf0e10cSrcweir delete[] pUS;
1867cdf0e10cSrcweir
1868cdf0e10cSrcweir return pNew;
1869cdf0e10cSrcweir }
1870cdf0e10cSrcweir
1871cdf0e10cSrcweir // -----------------------------------------------------------------------
1872cdf0e10cSrcweir
AddItem_Impl(SfxItemArray pItems,sal_uInt16 nOldSize,sal_uInt16 nPos)1873cdf0e10cSrcweir static SfxItemArray AddItem_Impl(SfxItemArray pItems, sal_uInt16 nOldSize, sal_uInt16 nPos)
1874cdf0e10cSrcweir
1875cdf0e10cSrcweir /* Diese interne Funktion erzeugt ein neues ItemArray, welches von 'pItems'
1876cdf0e10cSrcweir kopiert wird, an der Position 'nPos' jedoch Platz f"ur einen neuen
1877cdf0e10cSrcweir ItemPointer hat.
1878cdf0e10cSrcweir
1879cdf0e10cSrcweir Das neue ItemArray wird als Returnwert zur"uckgegeben, das alte 'pItems'
1880cdf0e10cSrcweir wird freigegeben.
1881cdf0e10cSrcweir */
1882cdf0e10cSrcweir
1883cdf0e10cSrcweir {
1884cdf0e10cSrcweir // neues ItemArray anlegen
1885cdf0e10cSrcweir SfxItemArray pNew = new const SfxPoolItem*[nOldSize+1];
1886cdf0e10cSrcweir
1887cdf0e10cSrcweir // war schon vorher eins da?
1888cdf0e10cSrcweir if ( pItems )
1889cdf0e10cSrcweir {
1890cdf0e10cSrcweir // alte Items vor nPos kopieren
1891cdf0e10cSrcweir if ( nPos )
1892cdf0e10cSrcweir memcpy( (void*) pNew, pItems, nPos * sizeof(SfxPoolItem **) );
1893cdf0e10cSrcweir
1894cdf0e10cSrcweir // alte Items hinter nPos kopieren
1895cdf0e10cSrcweir if ( nPos < nOldSize )
1896cdf0e10cSrcweir memcpy( (void*) (pNew + nPos + 1), pItems + nPos,
1897cdf0e10cSrcweir (nOldSize-nPos) * sizeof(SfxPoolItem **) );
1898cdf0e10cSrcweir }
1899cdf0e10cSrcweir
1900cdf0e10cSrcweir // neues Item initialisieren
1901cdf0e10cSrcweir *(pNew + nPos) = 0;
1902cdf0e10cSrcweir
1903cdf0e10cSrcweir // altes ItemArray freigeben
1904cdf0e10cSrcweir delete[] pItems;
1905cdf0e10cSrcweir
1906cdf0e10cSrcweir return pNew;
1907cdf0e10cSrcweir }
1908cdf0e10cSrcweir
1909cdf0e10cSrcweir // -----------------------------------------------------------------------
1910cdf0e10cSrcweir
Put(const SfxPoolItem & rItem,sal_uInt16 nWhich)1911cdf0e10cSrcweir const SfxPoolItem* SfxAllItemSet::Put( const SfxPoolItem& rItem, sal_uInt16 nWhich )
1912cdf0e10cSrcweir
1913cdf0e10cSrcweir // Putten mit automatischer Erweiterung der Whichs-Ids um die ID
1914cdf0e10cSrcweir // des Items.
1915cdf0e10cSrcweir
1916cdf0e10cSrcweir {
1917cdf0e10cSrcweir sal_uInt16 nPos = 0; // Position f"ur 'rItem' in '_aItems'
1918cdf0e10cSrcweir const sal_uInt16 nItemCount = TotalCount();
1919cdf0e10cSrcweir
1920cdf0e10cSrcweir // erstmal sehen, ob es schon einen passenden Bereich gibt
1921cdf0e10cSrcweir sal_uInt16 *pPtr = _pWhichRanges;
1922cdf0e10cSrcweir while ( *pPtr )
1923cdf0e10cSrcweir {
1924cdf0e10cSrcweir // Which-Id liegt in diesem Bereich?
1925cdf0e10cSrcweir if( *pPtr <= nWhich && nWhich <= *(pPtr+1) )
1926cdf0e10cSrcweir {
1927cdf0e10cSrcweir // Einfuegen
1928cdf0e10cSrcweir nPos += nWhich - *pPtr;
1929cdf0e10cSrcweir break;
1930cdf0e10cSrcweir }
1931cdf0e10cSrcweir
1932cdf0e10cSrcweir // Position des Items in _aItems mitf"uhren
1933cdf0e10cSrcweir nPos += *(pPtr+1) - *pPtr + 1;
1934cdf0e10cSrcweir
1935cdf0e10cSrcweir // zum n"achsten Bereich
1936cdf0e10cSrcweir pPtr += 2;
1937cdf0e10cSrcweir }
1938cdf0e10cSrcweir
1939cdf0e10cSrcweir // Which-Id noch nicht vorhanden?
1940cdf0e10cSrcweir if ( !*pPtr )
1941cdf0e10cSrcweir {
1942cdf0e10cSrcweir // suchen, ob man sie irgendwo dranpacken kann
1943cdf0e10cSrcweir pPtr = _pWhichRanges;
1944cdf0e10cSrcweir nPos = 0;
1945cdf0e10cSrcweir while ( *pPtr )
1946cdf0e10cSrcweir {
1947cdf0e10cSrcweir // Which-Id liegt exakt vor diesem Bereich?
1948cdf0e10cSrcweir if ( (nWhich+1) == *pPtr )
1949cdf0e10cSrcweir {
1950cdf0e10cSrcweir // Bereich waechst nach unten
1951cdf0e10cSrcweir (*pPtr)--;
1952cdf0e10cSrcweir
1953cdf0e10cSrcweir // vor erstem Item dieses Bereichs Platz schaffen
1954cdf0e10cSrcweir _aItems = AddItem_Impl(_aItems, nItemCount, nPos);
1955cdf0e10cSrcweir break;
1956cdf0e10cSrcweir }
1957cdf0e10cSrcweir
1958cdf0e10cSrcweir // Which-Id liegt exakt hinter diesem Bereich?
1959cdf0e10cSrcweir else if ( (nWhich-1) == *(pPtr+1) )
1960cdf0e10cSrcweir {
1961cdf0e10cSrcweir // Bereich waechst nach oben
1962cdf0e10cSrcweir (*(pPtr+1))++;
1963cdf0e10cSrcweir
1964cdf0e10cSrcweir // hinter letztem Item dieses Bereichs Platz schaffen
1965cdf0e10cSrcweir nPos += nWhich - *pPtr;
1966cdf0e10cSrcweir _aItems = AddItem_Impl(_aItems, nItemCount, nPos);
1967cdf0e10cSrcweir break;
1968cdf0e10cSrcweir }
1969cdf0e10cSrcweir
1970cdf0e10cSrcweir // Position des Items in _aItems mitf"uhren
1971cdf0e10cSrcweir nPos += *(pPtr+1) - *pPtr + 1;
1972cdf0e10cSrcweir
1973cdf0e10cSrcweir // zum n"achsten Bereich
1974cdf0e10cSrcweir pPtr += 2;
1975cdf0e10cSrcweir }
1976cdf0e10cSrcweir }
1977cdf0e10cSrcweir
1978cdf0e10cSrcweir // keinen erweiterbaren Bereich gefunden?
1979cdf0e10cSrcweir if ( !*pPtr )
1980cdf0e10cSrcweir {
1981cdf0e10cSrcweir // kein Platz mehr in _pWhichRanges => erweitern
1982cdf0e10cSrcweir std::ptrdiff_t nSize = pPtr - _pWhichRanges;
1983cdf0e10cSrcweir if( !nFree )
1984cdf0e10cSrcweir {
1985cdf0e10cSrcweir _pWhichRanges = AddRanges_Impl(_pWhichRanges, nSize, nInitCount);
1986cdf0e10cSrcweir nFree += nInitCount;
1987cdf0e10cSrcweir }
1988cdf0e10cSrcweir
1989cdf0e10cSrcweir // neuen Which-Range anh"angen
1990cdf0e10cSrcweir pPtr = _pWhichRanges + nSize;
1991cdf0e10cSrcweir *pPtr++ = nWhich;
1992cdf0e10cSrcweir *pPtr = nWhich;
1993cdf0e10cSrcweir nFree -= 2;
1994cdf0e10cSrcweir
1995cdf0e10cSrcweir // Itemarray vergroessern
1996cdf0e10cSrcweir nPos = nItemCount;
1997cdf0e10cSrcweir _aItems = AddItem_Impl(_aItems, nItemCount, nPos);
1998cdf0e10cSrcweir }
1999cdf0e10cSrcweir
2000cdf0e10cSrcweir // neues Item in Pool aufnehmen
2001cdf0e10cSrcweir const SfxPoolItem& rNew = _pPool->Put( rItem, nWhich );
2002cdf0e10cSrcweir
2003cdf0e10cSrcweir // altes Item merken
2004cdf0e10cSrcweir sal_Bool bIncrementCount = sal_False;
2005cdf0e10cSrcweir const SfxPoolItem* pOld = *( _aItems + nPos );
2006cdf0e10cSrcweir if ( reinterpret_cast< SfxPoolItem* >( -1 ) == pOld ) // state "dontcare"
2007cdf0e10cSrcweir pOld = NULL;
2008cdf0e10cSrcweir if ( !pOld )
2009cdf0e10cSrcweir {
2010cdf0e10cSrcweir bIncrementCount = sal_True;
2011cdf0e10cSrcweir pOld = _pParent ?
2012cdf0e10cSrcweir &_pParent->Get( nWhich, sal_True )
2013cdf0e10cSrcweir : nWhich <= SFX_WHICH_MAX ? &_pPool->GetDefaultItem( nWhich ) : 0;
2014cdf0e10cSrcweir }
2015cdf0e10cSrcweir
2016cdf0e10cSrcweir // neue Item in ItemSet aufnehmen
2017cdf0e10cSrcweir *(_aItems + nPos) = &rNew;
2018cdf0e10cSrcweir
2019cdf0e10cSrcweir // Changed Notification versenden
2020cdf0e10cSrcweir if ( pOld )
2021cdf0e10cSrcweir {
2022cdf0e10cSrcweir Changed( *pOld, rNew );
2023cdf0e10cSrcweir if ( !IsDefaultItem(pOld) )
2024cdf0e10cSrcweir _pPool->Remove( *pOld );
2025cdf0e10cSrcweir }
2026cdf0e10cSrcweir
2027cdf0e10cSrcweir if ( bIncrementCount )
2028cdf0e10cSrcweir ++_nCount;
2029*05f023e4SWang Lei
2030*05f023e4SWang Lei InvalidateHashKey(); //i120575
2031cdf0e10cSrcweir
2032cdf0e10cSrcweir return &rNew;
2033cdf0e10cSrcweir }
2034cdf0e10cSrcweir
2035cdf0e10cSrcweir // -----------------------------------------------------------------------
2036cdf0e10cSrcweir
2037cdf0e10cSrcweir
2038cdf0e10cSrcweir /* Diese Methode wird forwarded, damit sie nicht durch die anderen
2039cdf0e10cSrcweir Put-Methoden dieser SubClass gehided wird.
2040cdf0e10cSrcweir */
2041cdf0e10cSrcweir
Put(const SfxItemSet & rSet,sal_Bool bInvalidAsDefault)2042cdf0e10cSrcweir int SfxAllItemSet::Put( const SfxItemSet& rSet, sal_Bool bInvalidAsDefault )
2043cdf0e10cSrcweir {
2044cdf0e10cSrcweir //? pruefen, ob Which-Ranges erweitert werden
2045cdf0e10cSrcweir return SfxItemSet::Put( rSet, bInvalidAsDefault );
2046cdf0e10cSrcweir }
2047cdf0e10cSrcweir
2048cdf0e10cSrcweir // -----------------------------------------------------------------------
2049cdf0e10cSrcweir // Item disablen, wenn durch ein VoidItem mit dem Which-Wert 0 ausgedrueckt
2050cdf0e10cSrcweir
DisableItem(sal_uInt16 nWhich)2051cdf0e10cSrcweir void SfxItemSet::DisableItem(sal_uInt16 nWhich)
2052cdf0e10cSrcweir {
2053cdf0e10cSrcweir DBG_CHKTHIS(SfxItemSet, 0);
2054cdf0e10cSrcweir Put( SfxVoidItem(0), nWhich );
2055cdf0e10cSrcweir }
2056cdf0e10cSrcweir
2057cdf0e10cSrcweir // -----------------------------------------------------------------------
2058cdf0e10cSrcweir
2059cdf0e10cSrcweir #if 0
2060cdf0e10cSrcweir sal_Bool SfxAllItemSet::Remove(sal_uInt16 nWhich)
2061cdf0e10cSrcweir {
2062cdf0e10cSrcweir DBG_CHKTHIS(SfxAllItemSet, 0);
2063cdf0e10cSrcweir sal_uInt16 *pPtr = _pWhichRanges;
2064cdf0e10cSrcweir sal_uInt16 nPos = 0;
2065cdf0e10cSrcweir while( *pPtr )
2066cdf0e10cSrcweir {
2067cdf0e10cSrcweir if( *pPtr <= nWhich && nWhich <= *(pPtr+1) )
2068cdf0e10cSrcweir {
2069cdf0e10cSrcweir sal_uInt16 *pTmp = pPtr;
2070cdf0e10cSrcweir sal_uInt16 nLeft = 0;
2071cdf0e10cSrcweir sal_uInt16 nRest = 0;
2072cdf0e10cSrcweir while(*++pTmp){
2073cdf0e10cSrcweir if( nLeft & 1 )
2074cdf0e10cSrcweir nRest = *pTmp - *(pTmp-1) + 1;
2075cdf0e10cSrcweir ++nLeft;
2076cdf0e10cSrcweir }
2077cdf0e10cSrcweir
2078cdf0e10cSrcweir // in diesem Bereich
2079cdf0e10cSrcweir nPos += nWhich - *pPtr;
2080cdf0e10cSrcweir nRest -= nWhich - *pPtr;
2081cdf0e10cSrcweir // 3,3
2082cdf0e10cSrcweir if(*pPtr == nWhich && *(pPtr+1) == nWhich) {
2083cdf0e10cSrcweir memmove(pPtr, pPtr + 2, nLeft * sizeof(sal_uInt16));
2084cdf0e10cSrcweir nFree += 2;
2085cdf0e10cSrcweir }
2086cdf0e10cSrcweir // Anfang
2087cdf0e10cSrcweir else if(*pPtr == nWhich)
2088cdf0e10cSrcweir (*pPtr)++;
2089cdf0e10cSrcweir // Ende
2090cdf0e10cSrcweir else if(*(pPtr+1) == nWhich)
2091cdf0e10cSrcweir (*(pPtr+1))--;
2092cdf0e10cSrcweir else {
2093cdf0e10cSrcweir if(nPos + nRest + 2 > nFree) {
2094cdf0e10cSrcweir sal_uInt16 nOf = pPtr - _pWhichRanges;
2095cdf0e10cSrcweir _pWhichRanges = IncrSize(_pWhichRanges, nPos + nRest, nInitCount);
2096cdf0e10cSrcweir nFree += nInitCount;
2097cdf0e10cSrcweir pPtr = _pWhichRanges + nOf;
2098cdf0e10cSrcweir }
2099cdf0e10cSrcweir memmove(pPtr +2, pPtr, (nLeft+2) * sizeof(sal_uInt16));
2100cdf0e10cSrcweir *++pPtr = nWhich-1;
2101cdf0e10cSrcweir *++pPtr = nWhich+1;
2102cdf0e10cSrcweir nFree -= 2;
2103cdf0e10cSrcweir }
2104cdf0e10cSrcweir SfxPoolItem* pItem = *( _aItems + nPos );
2105cdf0e10cSrcweir if( pItem )
2106cdf0e10cSrcweir {
2107cdf0e10cSrcweir if(_pPool)
2108cdf0e10cSrcweir _pPool->Remove(*pItem );
2109cdf0e10cSrcweir else
2110cdf0e10cSrcweir delete pItem;
2111cdf0e10cSrcweir --_nCount;
2112cdf0e10cSrcweir }
2113cdf0e10cSrcweir memmove(_aItems + nPos +1, _aItems + nPos,
2114cdf0e10cSrcweir sizeof(SfxPoolItem *) * (nRest - 1));
2115cdf0e10cSrcweir break; // dann beim Parent suchen
2116cdf0e10cSrcweir }
2117cdf0e10cSrcweir nPos += *(pPtr+1) - *pPtr + 1;
2118cdf0e10cSrcweir pPtr += 2;
2119cdf0e10cSrcweir }
2120cdf0e10cSrcweir return *pPtr? sal_True: sal_False;
2121cdf0e10cSrcweir }
2122cdf0e10cSrcweir #endif
2123cdf0e10cSrcweir
2124cdf0e10cSrcweir // -----------------------------------------------------------------------
2125cdf0e10cSrcweir
Clone(sal_Bool bItems,SfxItemPool * pToPool) const2126cdf0e10cSrcweir SfxItemSet *SfxAllItemSet::Clone(sal_Bool bItems, SfxItemPool *pToPool ) const
2127cdf0e10cSrcweir {
2128cdf0e10cSrcweir DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet);
2129cdf0e10cSrcweir if ( pToPool && pToPool != _pPool )
2130cdf0e10cSrcweir {
2131cdf0e10cSrcweir SfxAllItemSet *pNewSet = new SfxAllItemSet( *pToPool );
2132cdf0e10cSrcweir if ( bItems )
2133cdf0e10cSrcweir pNewSet->Set( *this );
2134cdf0e10cSrcweir return pNewSet;
2135cdf0e10cSrcweir }
2136cdf0e10cSrcweir else
2137cdf0e10cSrcweir return bItems ? new SfxAllItemSet(*this) : new SfxAllItemSet(*_pPool);
2138cdf0e10cSrcweir }
2139cdf0e10cSrcweir
2140*05f023e4SWang Lei //for i120575
2141*05f023e4SWang Lei //align with the rtl_hash, return signed int result and input len limited to 2G.
2142*05f023e4SWang Lei //can be replaced with other hash function in future for better performance, e.g. fnv hash.
myhash(void * buf,sal_Int32 buf_len)2143*05f023e4SWang Lei inline sal_Int32 myhash(void * buf, sal_Int32 buf_len)
2144*05f023e4SWang Lei {
2145*05f023e4SWang Lei return rtl_str_hashCode_WithLength( reinterpret_cast<const sal_Char *>(buf), buf_len);
2146*05f023e4SWang Lei }
2147*05f023e4SWang Lei
UpdateHashKey()2148*05f023e4SWang Lei inline void SfxItemSet::UpdateHashKey()
2149*05f023e4SWang Lei {
2150*05f023e4SWang Lei _aHashKey= myhash(_aItems,TotalCount()* sizeof(_aItems[0]));
2151*05f023e4SWang Lei
2152*05f023e4SWang Lei //always treat '0' as invalidate hash key, not using addtional bool data field for saving space.
2153*05f023e4SWang Lei if (!IsValidateHashKey() )
2154*05f023e4SWang Lei {
2155*05f023e4SWang Lei _aHashKey = 1;
2156*05f023e4SWang Lei }
2157*05f023e4SWang Lei }
2158*05f023e4SWang Lei
QuickCompare(SfxItemSet & rCmp)2159*05f023e4SWang Lei sal_Bool SfxItemSet::QuickCompare( SfxItemSet & rCmp)
2160*05f023e4SWang Lei {
2161*05f023e4SWang Lei if ( _pParent != rCmp._pParent ||
2162*05f023e4SWang Lei _pPool != rCmp._pPool ||
2163*05f023e4SWang Lei Count() != rCmp.Count() )
2164*05f023e4SWang Lei return sal_False;
2165*05f023e4SWang Lei
2166*05f023e4SWang Lei if ((0==Count())&&(0==rCmp.Count()))
2167*05f023e4SWang Lei return sal_True;
2168*05f023e4SWang Lei
2169*05f023e4SWang Lei if (!IsValidateHashKey())
2170*05f023e4SWang Lei {
2171*05f023e4SWang Lei UpdateHashKey();
2172*05f023e4SWang Lei }
2173*05f023e4SWang Lei if (!rCmp.IsValidateHashKey())
2174*05f023e4SWang Lei {
2175*05f023e4SWang Lei rCmp.UpdateHashKey();
2176*05f023e4SWang Lei }
2177*05f023e4SWang Lei
2178*05f023e4SWang Lei //improved performance here, in most cases, the hashkey is not equal.
2179*05f023e4SWang Lei if (GetHashKey() != rCmp.GetHashKey())
2180*05f023e4SWang Lei return sal_False;
2181*05f023e4SWang Lei
2182*05f023e4SWang Lei if ( 0 == memcmp( _aItems, rCmp._aItems, TotalCount() * sizeof(_aItems[0]) ) )
2183*05f023e4SWang Lei return sal_True;
2184*05f023e4SWang Lei else
2185*05f023e4SWang Lei return sal_False;
2186*05f023e4SWang Lei }
2187*05f023e4SWang Lei //end: i120575
2188