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