27#include <libxml/xmlwriter.h>
48 : m_pPool(&rPool), m_pParent(nullptr),
50 m_pWhichRanges(rPool.GetFrozenIdRanges()),
62 , m_bItemsFixed(false)
71 , m_pWhichRanges(
std::move(ranges))
84 m_pWhichRanges(std::move(wids)),
93 : m_pPool( rASet.m_pPool )
94 , m_pParent( rASet.m_pParent )
95 , m_pWhichRanges( rASet.m_pWhichRanges )
97 , m_bItemsFixed(false)
111 for( sal_uInt16
n = nCnt;
n; --
n, ++ppDst, ++ppSrc )
112 if (
nullptr == *ppSrc ||
123 else if ( !(*ppSrc)->Which() )
124 *ppDst = (*ppSrc)->
Clone();
133 : m_pPool( rASet.m_pPool )
134 , m_pParent( rASet.m_pParent )
135 , m_ppItems( rASet.m_ppItems )
136 , m_pWhichRanges( std::move(rASet.m_pWhichRanges) )
138 , m_bItemsFixed(
false)
140 if (rASet.m_bItemsFixed)
145 std::copy(rASet.m_ppItems, rASet.m_ppItems + noItems, m_ppItems);
149 rASet.m_ppItems =
nullptr;
150 rASet.m_pPool =
nullptr;
151 rASet.m_pParent =
nullptr;
164 for( sal_uInt16 nCnt =
nCount; nCnt; --nCnt, ++ppFnd )
167 if( !(*ppFnd)->Which() )
207 pFoundOne =
m_ppItems + *oItemOffsetHint;
208 assert(!*pFoundOne ||
IsInvalidItem(*pFoundOne) || (*pFoundOne)->IsVoidItem() || (*pFoundOne)->Which() == nWhich);
216 if( rPair.first <= nWhich && nWhich <= rPair.second )
219 ppFnd += nWhich - rPair.first;
225 ppFnd += rPair.second - rPair.first + 1;
228 if (pFoundOne && *pFoundOne)
233 *pFoundOne =
nullptr;
243 Changed( *pItemToClear, rNew );
245 if ( pItemToClear->
Which() )
261 for( sal_uInt16 nWhich = rPair.first; nWhich <= rPair.second; ++nWhich, ++ppFnd )
280 Changed( *pItemToClear, rNew );
305 for( sal_uInt16 nWhich = rPair.first; nWhich <= rPair.second; ++nWhich, ++ppFnd )
316 assert( !
m_nCount &&
"There are still Items set" );
331 std::optional<sal_uInt16> oItemsOffsetHint)
const
339 if (oItemsOffsetHint)
341 pFoundOne = pCurrentSet->
m_ppItems + *oItemsOffsetHint;
342 assert(!*pFoundOne ||
IsInvalidItem(*pFoundOne) || (*pFoundOne)->IsVoidItem() || (*pFoundOne)->Which() == nWhich);
343 oItemsOffsetHint.reset();
350 if ( rPair.first <= nWhich && nWhich <= rPair.second )
353 pFoundOne = ppFnd + nWhich - rPair.first;
356 ppFnd += rPair.second - rPair.first + 1;
375 if ( (*pFoundOne)->IsVoidItem() )
380 *ppItem = *pFoundOne;
388 }
while (
nullptr != pCurrentSet);
404 assert(!bPassingOwnership);
411 if( rPair.first <= nWhich && nWhich <= rPair.second )
414 ppFnd += nWhich - rPair.first;
418 if ( *ppFnd == &rItem )
420 assert(!bPassingOwnership);
427 auto const old = *ppFnd;
430 assert(old->Which() == 0);
442 if (bPassingOwnership)
449 if ( rItem == **ppFnd )
451 if (bPassingOwnership)
471 if (bPassingOwnership)
488 dynamic_cast<const SfxSetItem*
>( &rItem ) ==
nullptr &&
490 "svl.items",
"putted Item unequal, with ID/pos " << nWhich );
493 ppFnd += rPair.second - rPair.first + 1;
495 if (bPassingOwnership)
508 for ( sal_uInt16 nWhich = rPair.first; nWhich <= rPair.second; ++nWhich, ++ppFnd )
513 if ( bInvalidAsDefault )
521 bRet |=
nullptr !=
Put( **ppFnd, nWhich );
554 for ( sal_uInt16 nWhich = rPair.first; nWhich <= rPair.second; ++nWhich, ++ppFnd )
560 switch ( eDontCareAs )
575 assert(!
"invalid Argument for eDontCareAs");
580 Put( **ppFnd, nWhich );
585 switch ( eDefaultAs )
600 assert(!
"invalid Argument for eDefaultAs");
652 sal_uInt16 nNewCount = 0;
654 memset( aNewItems, 0, nSize *
sizeof(
SfxPoolItem* ) );
658 for (
auto const & pRange : pNewRanges )
661 for ( sal_uInt16 nWID = pRange.first; nWID <= pRange.second; ++nWID, ++
n )
685 aNewItems[
n] =
nullptr;
691 for ( sal_uInt16 nItem = 0; nItem < nOldTotalCount; ++nItem )
754 if (!nWhich1 || !nWhich2)
756 if (nWhich1 > nWhich2)
761 if (nWhich1 < nWhich2)
768 bRet |=
nullptr !=
Put( *pItem, pItem->
Which() );
801 if( pCurrentSet->
Count() )
806 if( pPtr.first <= nWhich && nWhich <= pPtr.second )
809 ppFnd += nWhich - pPtr.first;
822 SAL_INFO(
"svl.items",
"SFX_WARNING: Getting disabled Item");
828 ppFnd += pPtr.second - pPtr.first + 1;
837 }
while (
nullptr != pCurrentSet);
862 assert(
m_pPool &&
"Not implemented without Pool");
880 for( ; nSize; --nSize, ++ppFnd1, ++ppFnd2 )
881 if( *ppFnd1 && !*ppFnd2 )
886 sal_uInt16 nWhich = (*ppFnd1)->
Which();
926 for( ; nSize; --nSize, ++ppFnd1, ++ppFnd2 )
927 if( *ppFnd1 && *ppFnd2 )
932 sal_uInt16 nWhich = (*ppFnd1)->
Which();
1040 bool bIgnoreDefaults )
1042 assert(ppFnd1 !=
nullptr &&
"Merging to 0-Item");
1051 else if ( pFnd2 && !bIgnoreDefaults &&
1056 else if ( pFnd2 && bIgnoreDefaults )
1058 *ppFnd1 = &_pPool->
Put( *pFnd2 );
1070 if ( !bIgnoreDefaults &&
1074 _pPool->
Remove( **ppFnd1 );
1081 if ( !bIgnoreDefaults ||
1086 _pPool->
Remove( **ppFnd1 );
1093 if ( **ppFnd1 != *pFnd2 )
1096 _pPool->
Remove( **ppFnd1 );
1115 for( ; nSize; --nSize, ++ppFnd1, ++ppFnd2 )
1122 while( 0 != ( nWhich = aIter.
NextWhich() ) )
1143 const sal_uInt16 nWhich = rAttr.
Which();
1147 if( pPtr.first <= nWhich && nWhich <= pPtr.second )
1149 ppFnd += nWhich - pPtr.first;
1153 ppFnd += pPtr.second - pPtr.first + 1;
1162 if( pPtr.first <= nWhich && nWhich <= pPtr.second )
1165 ppFnd += nWhich - pPtr.first;
1182 ppFnd += pPtr.second - pPtr.first + 1;
1191 n = ( pPtr.second - pPtr.first ) + 1;
1193 return pPtr.first +
nPos;
1202 return Equals( rCmp,
true);
1210 (bComparePool && bDifferentPools) ||
1219 if ( nCount1 != nCount2 )
1234 const SfxPoolItem *pItem1 =
nullptr, *pItem2 =
nullptr;
1237 ( pItem1 != pItem2 &&
1240 *pItem1 != *pItem2 ) ) ) )
1259 if ( *ppItem1 != *ppItem2 &&
1260 ( ( !*ppItem1 || !*ppItem2 ) ||
1263 **ppItem1 != **ppItem2 ) )
1275 if (pToPool && pToPool !=
m_pPool)
1286 pNewSet->Put( *pItem, pItem->
Which() );
1293 return std::unique_ptr<SfxItemSet>(bItems
1302 assert((
typeid(*
this) ==
typeid(
SfxItemSet)) &&
"cannot call this on a subclass of SfxItemSet");
1304 if (pToPool && pToPool !=
m_pPool)
1315 aNewSet.
Put( *pItem, pItem->
Which() );
1330 const sal_uInt16 nWhich = rItem.
Which();
1337 if( pPtr.first <= nWhich && nWhich <= pPtr.second )
1340 ppFnd += nWhich - pPtr.first;
1344 if( rItem == **ppFnd )
1363 ppFnd += pPtr.second - pPtr.first + 1;
1369 (void)xmlTextWriterStartElement(pWriter, BAD_CAST(
"SfxItemSet"));
1375 (void)xmlTextWriterStartElement(pWriter, BAD_CAST(
"invalid"));
1376 (void)xmlTextWriterEndElement(pWriter);
1380 pItem->dumpAsXml(pWriter);
1383 (void)xmlTextWriterEndElement(pWriter);
1428 if (pToPool && pToPool !=
m_pPool)
1430 std::unique_ptr<SfxAllItemSet> pNewSet(
new SfxAllItemSet( *pToPool ));
1432 pNewSet->Set( *
this );
1443 for (
int i=0;
i<nSize; ++
i)
1451 : m_size(1), m_bOwnRanges(true)
1454 p[0] = { nWhichStart, nWhichEnd };
1460 std::swap(
m_pairs, other.m_pairs);
1461 std::swap(
m_size, other.m_size);
1467 std::swap(
m_pairs, other.m_pairs);
1468 std::swap(
m_size, other.m_size);
1518 sal_uInt16 nTo)
const
1526 const size_t nOldCount =
size();
1530 std::unique_ptr<WhichPair[]> aRangesTable(
new WhichPair[nOldCount+1]);
1531 int aRangesTableSize = 0;
1532 bool bAdded =
false;
1533 for (
const auto& rPair : *
this)
1535 if (!bAdded && rPair.first >= nFrom)
1537 aRangesTable[aRangesTableSize++] = { nFrom, nTo };
1541 aRangesTable[aRangesTableSize++] = rPair;
1544 aRangesTable[aRangesTableSize++] = { nFrom, nTo };
1548 return (lhs.first - 1) <= rhs.second && (rhs.first - 1) <= lhs.second;
1551 auto it = aRangesTable.get();
1552 auto endIt = aRangesTable.get() + aRangesTableSize;
1556 auto itNext = std::next(it);
1557 if (itNext == endIt)
1560 if (needMerge(*it, *itNext))
1563 it->second = std::max(it->second, itNext->second);
1565 std::move(std::next(itNext), endIt, itNext);
1567 endIt = aRangesTable.get() + aRangesTableSize;
virtual const SfxPoolItem * PutImpl(const SfxPoolItem &, sal_uInt16 nWhich, bool bPassingOwnership) override
Putting with automatic extension of the WhichId with the ID of the Item.
virtual std::unique_ptr< SfxItemSet > Clone(bool bItems=true, SfxItemPool *pToPool=nullptr) const override
const SfxPoolItem * GetCurItem() const
get item, or null if no items
const SfxPoolItem * NextItem()
Base class for providers of defaults of SfxPoolItems.
sal_uInt16 GetWhich(sal_uInt16 nSlot, bool bDeep=true) const
const SfxPoolItem & GetDefaultItem(sal_uInt16 nWhich) const
bool IsItemPoolable(sal_uInt16 nWhich) const
bool CheckItemInPool(const SfxPoolItem *) const
const T & Put(std::unique_ptr< T > xItem, sal_uInt16 nWhich=0)
static bool IsWhich(sal_uInt16 nId)
void Remove(const SfxPoolItem &)
virtual const SfxPoolItem & PutImpl(const SfxPoolItem &, sal_uInt16 nWhich=0, bool bPassingOwnership=false)
virtual void Changed(const SfxPoolItem &rOld, const SfxPoolItem &rNew)
Notification callback.
void MergeValues(const SfxItemSet &rSet)
SfxItemPool * m_pPool
pool that stores the items
SfxItemSet(SfxItemPool &, SfxAllItemSetFlag)
SfxItemPool * GetPool() const
sal_uInt16 ClearAllItemsImpl()
void dumpAsXml(xmlTextWriterPtr pWriter) const
bool m_bItemsFixed
true if this is a SfxItemSetFixed object
void PutExtended(const SfxItemSet &, SfxItemState eDontCareAs, SfxItemState eDefaultAs)
This method takes the Items from the 'rSet' and adds to '*this'.
virtual std::unique_ptr< SfxItemSet > Clone(bool bItems=true, SfxItemPool *pToPool=nullptr) const
bool operator==(const SfxItemSet &) const
sal_uInt16 ClearSingleItemImpl(sal_uInt16 nWhich, std::optional< sal_uInt16 > oItemOffsetHint)
sal_uInt16 ClearItem(sal_uInt16 nWhich=0)
Delete single Items or all Items (nWhich == 0)
void InvalidateAllItems()
const SfxItemSet * m_pParent
derivation
bool HasItem(sal_uInt16 nWhich, const SfxPoolItem **ppItem=nullptr) const
void MergeValue(const SfxPoolItem &rItem, bool bOverwriteDefaults=false)
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
const SfxPoolItem * GetItem(sal_uInt16 nWhich, bool bSearchInParent=true) const
This method eases accessing single Items in the SfxItemSet.
void PutDirect(const SfxPoolItem &rItem)
sal_uInt16 TotalCount() const
SfxItemSet CloneAsValue(bool bItems=true, SfxItemPool *pToPool=nullptr) const
note that this only works if you know for sure that you are dealing with an SfxItemSet and not one of...
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
SfxItemState GetItemStateImpl(sal_uInt16 nWhich, bool bSrchInParent, const SfxPoolItem **ppItem, std::optional< sal_uInt16 > oItemsOffsetHint) const
SfxAllItemSetFlag
special constructor for SfxAllItemSet
void Intersect(const SfxItemSet &rSet)
Only retain the Items that are also present in rSet (nevermind their value).
WhichRangesContainer m_pWhichRanges
array of Which Ranges
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
bool Set(const SfxItemSet &, bool bDeep=true)
The SfxItemSet takes over exactly those SfxPoolItems that are set in rSet and are in their own Which ...
void DisableItem(sal_uInt16 nWhich)
Disable Item Using a VoidItem with Which value 0.
void SetRanges(const WhichRangesContainer &)
Modifies the ranges of settable items.
sal_uInt16 GetWhichByPos(sal_uInt16 nPos) const
SfxPoolItem const ** m_ppItems
pointer to array of items, we allocate and free this unless m_bItemsFixed==true
virtual const SfxPoolItem * PutImpl(const SfxPoolItem &, sal_uInt16 nWhich, bool bPassingOwnership)
SVL_DLLPRIVATE void RecreateRanges_Impl(const WhichRangesContainer &pNewRanges)
friend class SfxAllItemSet
sal_uInt16 m_nCount
number of items
void Differentiate(const SfxItemSet &rSet)
void MergeRange(sal_uInt16 nFrom, sal_uInt16 nTo)
Expands the ranges of settable items by 'nFrom' to 'nTo'.
bool Equals(const SfxItemSet &, bool bComparePool) const
Compare possibly ignoring SfxItemPool pointer.
void InvalidateItem(sal_uInt16 nWhich)
void AddRef(sal_uInt32 n=1) const
sal_uInt32 ReleaseRef(sal_uInt32 n=1) const
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const =0
virtual bool IsVoidItem() const
Only SfxVoidItem shall and must return true for this.
Iterates over the which ids and the pool items arrays together (which are stored in parallel arrays).
SfxItemState GetItemState(bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
struct _xmlTextWriter * xmlTextWriterPtr
static void MergeItem_Impl(SfxItemPool *_pPool, sal_uInt16 &rCount, const SfxPoolItem **ppFnd1, const SfxPoolItem *pFnd2, bool bIgnoreDefaults)
Decision table for MergeValue(s)
#define SAL_WARN_IF(condition, area, stream)
#define SAL_INFO(area, stream)
constexpr bool validRange(sal_uInt16 wid1, sal_uInt16 wid2)
sal_uInt16 CountRanges(const WhichRangesContainer &pRanges)
Determines the number of sal_uInt16s in a container of pairs of sal_uInt16s, each representing a rang...
bool validRanges2(const WhichRangesContainer &pRanges)
#define INVALID_POOL_ITEM
bool IsPoolDefaultItem(const SfxPoolItem *pItem)
SfxItemState
These values have to match the values in the css::frame::status::ItemState IDL to be found at offapi/...
@ DISABLED
Specifies that the property is currently disabled.
@ DEFAULT
Specifies that the property is currently in a default state.
@ UNKNOWN
Specifies an unknown state.
@ SET
The property has been explicitly set to a given value hence we know we are not taking the default val...
@ DONTCARE
Specifies that the property is currently in a don't care state.
bool IsDefaultItem(const SfxPoolItem *pItem)
bool IsInvalidItem(const SfxPoolItem *pItem)
bool IsStaticDefaultItem(const SfxPoolItem *pItem)
Most of the time, the which ranges we point at are a compile-time literal.
bool operator==(WhichRangesContainer const &other) const
bool empty() const noexcept
sal_Int32 size() const noexcept
WhichRangesContainer & operator=(WhichRangesContainer &&other)
WhichRangesContainer()=default
SAL_WARN_UNUSED_RESULT WhichRangesContainer MergeRange(sal_uInt16 nFrom, sal_uInt16 nTo) const
WhichPair const * m_pairs
bool m_bOwnRanges
if true, we allocated and need to delete the pairs, if not, we are pointing at a global const literal
std::pair< sal_uInt16, sal_uInt16 > WhichPair