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