summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noelgrandin@gmail.com>2022-05-28 17:11:54 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2022-05-28 20:50:25 +0200
commit8f3e12b7a918935eae4e98c47cdc3b575e8bf089 (patch)
tree6e67a9cac7f6a09845f6b1272958e91b2f14c1a8
parent1cfa3f8694d4b585549e6dae7396d408184106cb (diff)
split SfxItem::ClearItem into two methods
in preparation for passing a hint into it Change-Id: Id9e5516619a314406d8250bb2145996593dafbaf Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135078 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--include/svl/itemset.hxx2
-rw-r--r--svl/source/items/itemset.cxx132
2 files changed, 73 insertions, 61 deletions
diff --git a/include/svl/itemset.hxx b/include/svl/itemset.hxx
index 746ba8448afb..086ddc42f74e 100644
--- a/include/svl/itemset.hxx
+++ b/include/svl/itemset.hxx
@@ -227,6 +227,8 @@ public:
void dumpAsXml(xmlTextWriterPtr pWriter) const;
private:
+ sal_uInt16 ClearSingleItemImpl( sal_uInt16 nWhich );
+ sal_uInt16 ClearAllItemsImpl();
SfxItemState GetItemStateImpl( sal_uInt16 nWhich,
bool bSrchInParent,
const SfxPoolItem **ppItem,
diff --git a/svl/source/items/itemset.cxx b/svl/source/items/itemset.cxx
index e0e1ee8823a3..133603fe0f39 100644
--- a/svl/source/items/itemset.cxx
+++ b/svl/source/items/itemset.cxx
@@ -198,87 +198,97 @@ sal_uInt16 SfxItemSet::ClearItem( sal_uInt16 nWhich )
{
if( !Count() )
return 0;
+ if( nWhich )
+ return ClearSingleItemImpl(nWhich);
+ else
+ return ClearAllItemsImpl();
+}
+sal_uInt16 SfxItemSet::ClearSingleItemImpl( sal_uInt16 nWhich )
+{
sal_uInt16 nDel = 0;
SfxPoolItem const** ppFnd = m_ppItems;
- if( nWhich )
+ for (const WhichPair& rPair : m_pWhichRanges)
{
- for (const WhichPair& rPair : m_pWhichRanges)
+ // Within this range?
+ if( rPair.first <= nWhich && nWhich <= rPair.second )
{
- // Within this range?
- if( rPair.first <= nWhich && nWhich <= rPair.second )
+ // Actually set?
+ ppFnd += nWhich - rPair.first;
+ if( *ppFnd )
{
- // Actually set?
- ppFnd += nWhich - rPair.first;
- if( *ppFnd )
- {
- // Due to the assertions in the sub calls, we need to do the following
- --m_nCount;
- const SfxPoolItem *pItemToClear = *ppFnd;
- *ppFnd = nullptr;
+ // Due to the assertions in the sub calls, we need to do the following
+ --m_nCount;
+ const SfxPoolItem *pItemToClear = *ppFnd;
+ *ppFnd = nullptr;
- if ( !IsInvalidItem(pItemToClear) )
+ if ( !IsInvalidItem(pItemToClear) )
+ {
+ if (SfxItemPool::IsWhich(nWhich))
{
- if (SfxItemPool::IsWhich(nWhich))
- {
- const SfxPoolItem& rNew = m_pParent
- ? m_pParent->Get( nWhich )
- : m_pPool->GetDefaultItem( nWhich );
+ const SfxPoolItem& rNew = m_pParent
+ ? m_pParent->Get( nWhich )
+ : m_pPool->GetDefaultItem( nWhich );
- Changed( *pItemToClear, rNew );
- }
- if ( pItemToClear->Which() )
- m_pPool->Remove( *pItemToClear );
+ Changed( *pItemToClear, rNew );
}
- ++nDel;
+ if ( pItemToClear->Which() )
+ m_pPool->Remove( *pItemToClear );
}
-
- // found => break
- break;
+ ++nDel;
}
- ppFnd += rPair.second - rPair.first + 1;
+
+ // found => break
+ break;
}
+ ppFnd += rPair.second - rPair.first + 1;
}
- else
- {
- nDel = m_nCount;
+ return nDel;
+}
+
- for (const WhichPair& rPair : m_pWhichRanges)
+sal_uInt16 SfxItemSet::ClearAllItemsImpl()
+{
+ sal_uInt16 nDel = m_nCount;
+ SfxPoolItem const** ppFnd = m_ppItems;
+
+ for (const WhichPair& rPair : m_pWhichRanges)
+ {
+ for( sal_uInt16 nWhich = rPair.first; nWhich <= rPair.second; ++nWhich, ++ppFnd )
{
- for( nWhich = rPair.first; nWhich <= rPair.second; ++nWhich, ++ppFnd )
- if( *ppFnd )
- {
- // Due to the assertions in the sub calls, we need to do this
- --m_nCount;
- const SfxPoolItem *pItemToClear = *ppFnd;
- *ppFnd = nullptr;
+ if( !*ppFnd )
+ continue;
- if ( !IsInvalidItem(pItemToClear) )
- {
- if (SfxItemPool::IsWhich(nWhich))
- {
- const SfxPoolItem& rNew = m_pParent
- ? m_pParent->Get( nWhich )
- : m_pPool->GetDefaultItem( nWhich );
+ // Due to the assertions in the sub calls, we need to do this
+ --m_nCount;
+ const SfxPoolItem *pItemToClear = *ppFnd;
+ *ppFnd = nullptr;
- Changed( *pItemToClear, rNew );
- }
+ if ( IsInvalidItem(pItemToClear) )
+ continue;
- // #i32448#
- // Take care of disabled items, too.
- if (!pItemToClear->m_nWhich)
- {
- // item is disabled, delete it
- delete pItemToClear;
- }
- else
- {
- // remove item from pool
- m_pPool->Remove( *pItemToClear );
- }
- }
- }
+ if (SfxItemPool::IsWhich(nWhich))
+ {
+ const SfxPoolItem& rNew = m_pParent
+ ? m_pParent->Get( nWhich )
+ : m_pPool->GetDefaultItem( nWhich );
+
+ Changed( *pItemToClear, rNew );
+ }
+
+ // #i32448#
+ // Take care of disabled items, too.
+ if (!pItemToClear->m_nWhich)
+ {
+ // item is disabled, delete it
+ delete pItemToClear;
+ }
+ else
+ {
+ // remove item from pool
+ m_pPool->Remove( *pItemToClear );
+ }
}
}
return nDel;