sw/source/core/undo/SwUndoPageDesc.cxx |   55 ++++++++++++++++-----------------
 sw/source/core/undo/rolbck.cxx         |    4 --
 sw/source/core/undo/unattr.cxx         |    7 ++--
 sw/source/core/undo/undel.cxx          |   11 +++---
 sw/source/core/undo/unsect.cxx         |    4 +-
 sw/source/core/undo/unspnd.cxx         |    9 ++---
 sw/source/core/undo/untbl.cxx          |   42 +++++++++++--------------
 7 files changed, 63 insertions(+), 69 deletions(-)

New commits:
commit 1ff25864d9c40cfc913eb9829e28e366d409743d
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Wed Mar 2 17:59:58 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Thu Mar 3 08:50:43 2022 +0100

    use SfxItemSet::GetItemIfSet in sw/source/core/undo
    
    Change-Id: Iad685caa338367d51292166604892c6bd3ee81ba
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130882
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sw/source/core/undo/SwUndoPageDesc.cxx 
b/sw/source/core/undo/SwUndoPageDesc.cxx
index 888f51328b62..0ec97951ed85 100644
--- a/sw/source/core/undo/SwUndoPageDesc.cxx
+++ b/sw/source/core/undo/SwUndoPageDesc.cxx
@@ -134,43 +134,42 @@ void SwUndoPageDesc::ExchangeContentNodes( SwPageDesc& 
rSource, SwPageDesc &rDes
     {
         // Let the destination page description point to the source node 
position,
         // from now on this descriptor is responsible for the content nodes!
-        const SfxPoolItem* pItem;
-        rDest.GetMaster().GetAttrSet().GetItemState( RES_HEADER, false, &pItem 
);
-        std::unique_ptr<SfxPoolItem> pNewItem(pItem->Clone());
-        SwFrameFormat* pNewFormat = 
static_cast<SwFormatHeader*>(pNewItem.get())->GetHeaderFormat();
+        const SwFormatHeader* pItem = 
rDest.GetMaster().GetAttrSet().GetItemIfSet( RES_HEADER, false );
+        std::unique_ptr<SwFormatHeader> pNewItem(pItem->Clone());
+        SwFrameFormat* pNewFormat = pNewItem->GetHeaderFormat();
         pNewFormat->SetFormatAttr( rSourceHead.GetHeaderFormat()->GetContent() 
);
 
         // Let the source page description point to zero node position,
         // it loses the responsible and can be destroyed without removing the 
content nodes.
-        rSource.GetMaster().GetAttrSet().GetItemState( RES_HEADER, false, 
&pItem );
+        pItem = rSource.GetMaster().GetAttrSet().GetItemIfSet( RES_HEADER, 
false );
         pNewItem.reset(pItem->Clone());
-        pNewFormat = 
static_cast<SwFormatHeader*>(pNewItem.get())->GetHeaderFormat();
+        pNewFormat = pNewItem->GetHeaderFormat();
         pNewFormat->SetFormatAttr( SwFormatContent() );
 
         if( !rDest.IsHeaderShared() )
         {
             // Same procedure for unshared header...
             const SwFormatHeader& rSourceLeftHead = 
rSource.GetLeft().GetHeader();
-            rDest.GetLeft().GetAttrSet().GetItemState( RES_HEADER, false, 
&pItem );
+            pItem = rDest.GetLeft().GetAttrSet().GetItemIfSet( RES_HEADER, 
false );
             pNewItem.reset(pItem->Clone());
-            pNewFormat = 
static_cast<SwFormatHeader*>(pNewItem.get())->GetHeaderFormat();
+            pNewFormat = pNewItem->GetHeaderFormat();
             pNewFormat->SetFormatAttr( 
rSourceLeftHead.GetHeaderFormat()->GetContent() );
-            rSource.GetLeft().GetAttrSet().GetItemState( RES_HEADER, false, 
&pItem );
+            pItem = rSource.GetLeft().GetAttrSet().GetItemIfSet( RES_HEADER, 
false );
             pNewItem.reset(pItem->Clone());
-            pNewFormat = 
static_cast<SwFormatHeader*>(pNewItem.get())->GetHeaderFormat();
+            pNewFormat = pNewItem->GetHeaderFormat();
             pNewFormat->SetFormatAttr( SwFormatContent() );
         }
         if (!rDest.IsFirstShared())
         {
             // Same procedure for unshared header...
             const SwFormatHeader& rSourceFirstMasterHead = 
rSource.GetFirstMaster().GetHeader();
-            rDest.GetFirstMaster().GetAttrSet().GetItemState( RES_HEADER, 
false, &pItem );
+            pItem = rDest.GetFirstMaster().GetAttrSet().GetItemIfSet( 
RES_HEADER, false );
             pNewItem.reset(pItem->Clone());
-            pNewFormat = 
static_cast<SwFormatHeader*>(pNewItem.get())->GetHeaderFormat();
+            pNewFormat = pNewItem->GetHeaderFormat();
             pNewFormat->SetFormatAttr( 
rSourceFirstMasterHead.GetHeaderFormat()->GetContent() );
-            rSource.GetFirstMaster().GetAttrSet().GetItemState( RES_HEADER, 
false, &pItem );
+            pItem = rSource.GetFirstMaster().GetAttrSet().GetItemIfSet( 
RES_HEADER, false );
             pNewItem.reset(pItem->Clone());
-            pNewFormat = 
static_cast<SwFormatHeader*>(pNewItem.get())->GetHeaderFormat();
+            pNewFormat = pNewItem->GetHeaderFormat();
             pNewFormat->SetFormatAttr( SwFormatContent() );
         }
     }
@@ -180,40 +179,40 @@ void SwUndoPageDesc::ExchangeContentNodes( SwPageDesc& 
rSource, SwPageDesc &rDes
     if( !rDestFoot.IsActive() )
         return;
 
-    const SfxPoolItem* pItem;
-    rDest.GetMaster().GetAttrSet().GetItemState( RES_FOOTER, false, &pItem );
-    std::unique_ptr<SfxPoolItem> pNewItem(pItem->Clone());
-    SwFrameFormat *pNewFormat = 
static_cast<SwFormatFooter*>(pNewItem.get())->GetFooterFormat();
+    const SwFormatFooter* pItem;
+    pItem = rDest.GetMaster().GetAttrSet().GetItemIfSet( RES_FOOTER, false );
+    std::unique_ptr<SwFormatFooter> pNewItem(pItem->Clone());
+    SwFrameFormat *pNewFormat = pNewItem->GetFooterFormat();
     pNewFormat->SetFormatAttr( rSourceFoot.GetFooterFormat()->GetContent() );
 
-    rSource.GetMaster().GetAttrSet().GetItemState( RES_FOOTER, false, &pItem );
+    pItem = rSource.GetMaster().GetAttrSet().GetItemIfSet( RES_FOOTER, false );
     pNewItem.reset(pItem->Clone());
-    pNewFormat = 
static_cast<SwFormatFooter*>(pNewItem.get())->GetFooterFormat();
+    pNewFormat = pNewItem->GetFooterFormat();
     pNewFormat->SetFormatAttr( SwFormatContent() );
 
     if( !rDest.IsFooterShared() )
     {
         const SwFormatFooter& rSourceLeftFoot = rSource.GetLeft().GetFooter();
-        rDest.GetLeft().GetAttrSet().GetItemState( RES_FOOTER, false, &pItem );
+        pItem = rDest.GetLeft().GetAttrSet().GetItemIfSet( RES_FOOTER, false );
         pNewItem.reset(pItem->Clone());
-        pNewFormat = 
static_cast<SwFormatFooter*>(pNewItem.get())->GetFooterFormat();
+        pNewFormat = pNewItem->GetFooterFormat();
         pNewFormat->SetFormatAttr( 
rSourceLeftFoot.GetFooterFormat()->GetContent() );
-        rSource.GetLeft().GetAttrSet().GetItemState( RES_FOOTER, false, &pItem 
);
+        pItem = rSource.GetLeft().GetAttrSet().GetItemIfSet( RES_FOOTER, false 
);
         pNewItem.reset(pItem->Clone());
-        pNewFormat = 
static_cast<SwFormatFooter*>(pNewItem.get())->GetFooterFormat();
+        pNewFormat = pNewItem->GetFooterFormat();
         pNewFormat->SetFormatAttr( SwFormatContent() );
     }
     if (rDest.IsFirstShared())
         return;
 
     const SwFormatFooter& rSourceFirstMasterFoot = 
rSource.GetFirstMaster().GetFooter();
-    rDest.GetFirstMaster().GetAttrSet().GetItemState( RES_FOOTER, false, 
&pItem );
+    pItem = rDest.GetFirstMaster().GetAttrSet().GetItemIfSet( RES_FOOTER, 
false );
     pNewItem.reset(pItem->Clone());
-    pNewFormat = 
static_cast<SwFormatFooter*>(pNewItem.get())->GetFooterFormat();
+    pNewFormat = pNewItem->GetFooterFormat();
     pNewFormat->SetFormatAttr( 
rSourceFirstMasterFoot.GetFooterFormat()->GetContent() );
-    rSource.GetFirstMaster().GetAttrSet().GetItemState( RES_FOOTER, false, 
&pItem );
+    pItem = rSource.GetFirstMaster().GetAttrSet().GetItemIfSet( RES_FOOTER, 
false );
     pNewItem.reset(pItem->Clone());
-    pNewFormat = 
static_cast<SwFormatFooter*>(pNewItem.get())->GetFooterFormat();
+    pNewFormat = pNewItem->GetFooterFormat();
     pNewFormat->SetFormatAttr( SwFormatContent() );
 }
 
diff --git a/sw/source/core/undo/rolbck.cxx b/sw/source/core/undo/rolbck.cxx
index 49c4d9b1d946..b46645b91934 100644
--- a/sw/source/core/undo/rolbck.cxx
+++ b/sw/source/core/undo/rolbck.cxx
@@ -1165,9 +1165,7 @@ void SwHistory::AddDeleteFly(SwFrameFormat& rFormat, 
sal_uInt16& rSetPos)
         std::unique_ptr<SwHistoryHint> pHint(new SwHistoryTextFlyCnt( &rFormat 
));
         m_SwpHstry.push_back( std::move(pHint) );
 
-        const SwFormatChain* pChainItem;
-        if( SfxItemState::SET == rFormat.GetItemState( RES_CHAIN, false,
-            reinterpret_cast<const SfxPoolItem**>(&pChainItem) ))
+        if( const SwFormatChain* pChainItem = rFormat.GetItemIfSet( RES_CHAIN, 
false ) )
         {
             assert(RES_FLYFRMFMT == nWh); // not supported on SdrObjects
             if( pChainItem->GetNext() || pChainItem->GetPrev() )
diff --git a/sw/source/core/undo/unattr.cxx b/sw/source/core/undo/unattr.cxx
index 9d279860c086..6119b49d73d1 100644
--- a/sw/source/core/undo/unattr.cxx
+++ b/sw/source/core/undo/unattr.cxx
@@ -850,10 +850,11 @@ void SwUndoAttr::RemoveIdx( SwDoc& rDoc )
 SwUndoDefaultAttr::SwUndoDefaultAttr( const SfxItemSet& rSet, const SwDoc& 
rDoc )
     : SwUndo( SwUndoId::SETDEFTATTR, &rDoc )
 {
-    const SfxPoolItem* pItem;
-    if( SfxItemState::SET == rSet.GetItemState( RES_PARATR_TABSTOP, false, 
&pItem ) ) {
+    const SvxTabStopItem* pItem = rSet.GetItemIfSet( RES_PARATR_TABSTOP, false 
);
+    if( pItem )
+    {
         // store separately, because it may change!
-        m_pTabStop.reset(&pItem->Clone()->StaticWhichCast(RES_PARATR_TABSTOP));
+        m_pTabStop.reset(pItem->Clone());
         if ( 1 != rSet.Count() ) { // are there more attributes?
             m_oOldSet.emplace( rSet );
         }
diff --git a/sw/source/core/undo/undel.cxx b/sw/source/core/undo/undel.cxx
index ed1cdf38794d..0ea396fc154b 100644
--- a/sw/source/core/undo/undel.cxx
+++ b/sw/source/core/undo/undel.cxx
@@ -20,6 +20,7 @@
 #include <UndoDelete.hxx>
 
 #include <libxml/xmlwriter.h>
+#include <editeng/formatbreakitem.hxx>
 
 #include <hintids.hxx>
 #include <osl/diagnose.h>
@@ -45,6 +46,7 @@
 #include <rootfrm.hxx>
 #include <strings.hrc>
 #include <frameformats.hxx>
+#include <fmtpdsc.hxx>
 #include <vector>
 
 // DELETE
@@ -1245,13 +1247,12 @@ void SwUndoDelete::RedoImpl(::sw::UndoRedoContext & 
rContext)
             {
                 SwFrameFormat* pTableFormat = 
pTableNd->GetTable().GetFrameFormat();
 
-                const SfxPoolItem *pItem;
-                if( SfxItemState::SET == pTableFormat->GetItemState( 
RES_PAGEDESC,
-                    false, &pItem ) )
+                if( const SwFormatPageDesc* pItem = 
pTableFormat->GetItemIfSet( RES_PAGEDESC,
+                    false ) )
                     pNextNd->SetAttr( *pItem );
 
-                if( SfxItemState::SET == pTableFormat->GetItemState( RES_BREAK,
-                    false, &pItem ) )
+                if( const SvxFormatBreakItem* pItem = 
pTableFormat->GetItemIfSet( RES_BREAK,
+                    false ) )
                     pNextNd->SetAttr( *pItem );
             }
             pTableNd->DelFrames();
diff --git a/sw/source/core/undo/unsect.cxx b/sw/source/core/undo/unsect.cxx
index 81255ed73cad..5ac2e3f0a13d 100644
--- a/sw/source/core/undo/unsect.cxx
+++ b/sw/source/core/undo/unsect.cxx
@@ -20,6 +20,7 @@
 #include <memory>
 #include <UndoSection.hxx>
 
+#include <editeng/protitem.hxx>
 #include <osl/diagnose.h>
 #include <comphelper/scopeguard.hxx>
 #include <sfx2/linkmgr.hxx>
@@ -474,9 +475,8 @@ void SwUndoUpdateSection::UndoImpl(::sw::UndoRedoContext & 
rContext)
     if (m_oAttrSet)
     {
         // The Content and Protect items must persist
-        const SfxPoolItem* pItem;
         m_oAttrSet->Put( pFormat->GetFormatAttr( RES_CNTNT ));
-        if( SfxItemState::SET == pFormat->GetItemState( RES_PROTECT, true, 
&pItem ))
+        if( const SvxProtectItem* pItem = pFormat->GetItemIfSet( RES_PROTECT ))
         {
             m_oAttrSet->Put( *pItem );
         }
diff --git a/sw/source/core/undo/unspnd.cxx b/sw/source/core/undo/unspnd.cxx
index 1e8bbf02b8a4..2642ae5f0882 100644
--- a/sw/source/core/undo/unspnd.cxx
+++ b/sw/source/core/undo/unspnd.cxx
@@ -30,8 +30,10 @@
 #include <rolbck.hxx>
 #include <redline.hxx>
 #include <docary.hxx>
+#include <fmtpdsc.hxx>
 #include <IShellCursorSupplier.hxx>
 #include <osl/diagnose.h>
+#include <editeng/formatbreakitem.hxx>
 
 // SPLITNODE
 
@@ -90,13 +92,10 @@ void SwUndoSplitNode::UndoImpl(::sw::UndoRedoContext & 
rContext)
             const SfxItemSet* pNdSet = pTNd->GetpSwAttrSet();
             if( pNdSet )
             {
-                const SfxPoolItem *pItem;
-                if( SfxItemState::SET == pNdSet->GetItemState( RES_PAGEDESC, 
false,
-                    &pItem ) )
+                if( const SwFormatPageDesc* pItem = pNdSet->GetItemIfSet( 
RES_PAGEDESC, false ) )
                     pTableFormat->SetFormatAttr( *pItem );
 
-                if( SfxItemState::SET == pNdSet->GetItemState( RES_BREAK, 
false,
-                     &pItem ) )
+                if( const SvxFormatBreakItem* pItem = pNdSet->GetItemIfSet( 
RES_BREAK, false ) )
                     pTableFormat->SetFormatAttr( *pItem );
             }
 
diff --git a/sw/source/core/undo/untbl.cxx b/sw/source/core/undo/untbl.cxx
index d3294b5446a3..7c0ebbbe77c1 100644
--- a/sw/source/core/undo/untbl.cxx
+++ b/sw/source/core/undo/untbl.cxx
@@ -283,14 +283,13 @@ void SwUndoInsTable::UndoImpl(::sw::UndoRedoContext & 
rContext)
     if( pNextNd )
     {
         SwFrameFormat* pTableFormat = pTableNd->GetTable().GetFrameFormat();
-        const SfxPoolItem *pItem;
 
-        if( SfxItemState::SET == pTableFormat->GetItemState( RES_PAGEDESC,
-            false, &pItem ) )
+        if( const SwFormatPageDesc* pItem = pTableFormat->GetItemIfSet( 
RES_PAGEDESC,
+            false ) )
             pNextNd->SetAttr( *pItem );
 
-        if( SfxItemState::SET == pTableFormat->GetItemState( RES_BREAK,
-            false, &pItem ) )
+        if( const SvxFormatBreakItem* pItem = pTableFormat->GetItemIfSet( 
RES_BREAK,
+            false ) )
             pNextNd->SetAttr( *pItem );
     }
 
@@ -911,15 +910,14 @@ sal_uInt16 SaveTable::AddFormat( SwFrameFormat* pFormat, 
bool bIsLine )
         // When a formula is set, never save the value. It possibly must be
         // recalculated.
         // Save formulas always in plain text.
-        const SfxPoolItem* pItem;
-        if( SfxItemState::SET == pSet->GetItemState( RES_BOXATR_FORMULA, true, 
&pItem ))
+        if( const SwTableBoxFormula* pItem = pSet->GetItemIfSet( 
RES_BOXATR_FORMULA ))
         {
             pSet->ClearItem( RES_BOXATR_VALUE );
             if (m_pSwTable && m_bSaveFormula)
             {
                 SwTableFormulaUpdate aMsgHint(m_pSwTable);
                 aMsgHint.m_eFlags = TBL_BOXNAME;
-                SwTableBoxFormula* pFormulaItem = 
const_cast<SwTableBoxFormula*>(static_cast<const SwTableBoxFormula*>(pItem));
+                SwTableBoxFormula* pFormulaItem = 
const_cast<SwTableBoxFormula*>(pItem);
                 pFormulaItem->ChgDefinedIn( pFormat );
                 pFormulaItem->ChangeState( &aMsgHint );
                 pFormulaItem->ChgDefinedIn( nullptr );
@@ -2067,24 +2065,23 @@ SwUndoTableNumFormat::SwUndoTableNumFormat( const 
SwTableBox& rBox,
 
     if( pNewSet )
     {
-        const SfxPoolItem* pItem;
-        if( SfxItemState::SET == pNewSet->GetItemState( RES_BOXATR_FORMAT,
-                false, &pItem ))
+        if( const SwTableBoxNumFormat* pItem = pNewSet->GetItemIfSet( 
RES_BOXATR_FORMAT,
+                false ))
         {
             m_bNewFormat = true;
-            m_nNewFormatIdx = static_cast<const 
SwTableBoxNumFormat*>(pItem)->GetValue();
+            m_nNewFormatIdx = pItem->GetValue();
         }
-        if( SfxItemState::SET == pNewSet->GetItemState( RES_BOXATR_FORMULA,
-                false, &pItem ))
+        if( const SwTableBoxFormula* pItem = pNewSet->GetItemIfSet( 
RES_BOXATR_FORMULA,
+                false ))
         {
             m_bNewFormula = true;
-            m_aNewFormula = static_cast<const 
SwTableBoxFormula*>(pItem)->GetFormula();
+            m_aNewFormula = pItem->GetFormula();
         }
-        if( SfxItemState::SET == pNewSet->GetItemState( RES_BOXATR_VALUE,
-                false, &pItem ))
+        if( const SwTableBoxValue* pItem = pNewSet->GetItemIfSet( 
RES_BOXATR_VALUE,
+                false ))
         {
             m_bNewValue = true;
-            m_fNewNum = static_cast<const SwTableBoxValue*>(pItem)->GetValue();
+            m_fNewNum = pItem->GetValue();
         }
     }
 
@@ -2780,14 +2777,13 @@ void SwUndoCpyTable::UndoImpl(::sw::UndoRedoContext & 
rContext)
     if( pNextNd )
     {
         SwFrameFormat* pTableFormat = pTNd->GetTable().GetFrameFormat();
-        const SfxPoolItem *pItem;
 
-        if( SfxItemState::SET == pTableFormat->GetItemState( RES_PAGEDESC,
-            false, &pItem ) )
+        if( const SwFormatPageDesc* pItem = pTableFormat->GetItemIfSet( 
RES_PAGEDESC,
+            false ) )
             pNextNd->SetAttr( *pItem );
 
-        if( SfxItemState::SET == pTableFormat->GetItemState( RES_BREAK,
-            false, &pItem ) )
+        if( const SvxFormatBreakItem* pItem = pTableFormat->GetItemIfSet( 
RES_BREAK,
+            false ) )
             pNextNd->SetAttr( *pItem );
     }
 

Reply via email to