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