sw/source/core/layout/flylay.cxx    |    8 +--
 sw/source/core/layout/tabfrm.cxx    |    8 +--
 sw/source/core/layout/wsfrm.cxx     |    5 -
 sw/source/core/table/swnewtable.cxx |   13 +----
 sw/source/core/table/swtable.cxx    |   92 +++++++++++++++++-------------------
 5 files changed, 58 insertions(+), 68 deletions(-)

New commits:
commit 552c9cb9a5e41797a1353a9a014ede03a0971ceb
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Wed Mar 2 17:57:46 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Thu Mar 3 08:52:01 2022 +0100

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

diff --git a/sw/source/core/layout/flylay.cxx b/sw/source/core/layout/flylay.cxx
index cb490c366a9b..ef57a72c5560 100644
--- a/sw/source/core/layout/flylay.cxx
+++ b/sw/source/core/layout/flylay.cxx
@@ -333,13 +333,11 @@ bool SwFlyFreeFrame::supportsAutoContour() const
 
     // Check for Padding. Do not support when padding is used, this will
     // produce a covered space around the object (filled with fill defines)
-    const SfxPoolItem* pItem(nullptr);
+    const SvxBoxItem* pBoxItem(nullptr);
 
-    if(GetFormat() && SfxItemState::SET == GetFormat()->GetItemState(RES_BOX, 
false, &pItem))
+    if(GetFormat() && (pBoxItem = GetFormat()->GetItemIfSet(RES_BOX, false)))
     {
-        const SvxBoxItem& rBox = *static_cast< const SvxBoxItem* >(pItem);
-
-        if(rBox.HasBorder(/*bTreatPaddingAsBorder*/true))
+        if(pBoxItem->HasBorder(/*bTreatPaddingAsBorder*/true))
         {
             return false;
         }
diff --git a/sw/source/core/layout/tabfrm.cxx b/sw/source/core/layout/tabfrm.cxx
index 6db061bd8c9f..832ca2289656 100644
--- a/sw/source/core/layout/tabfrm.cxx
+++ b/sw/source/core/layout/tabfrm.cxx
@@ -5528,10 +5528,10 @@ void SwCellFrame::SwClientNotify(const SwModify& rMod, 
const SfxHint& rHint)
             case RES_ATTRSET_CHG:
             {
                 auto& rChgSet = *static_cast<const 
SwAttrSetChg*>(pLegacy->m_pNew)->GetChgSet();
-                rChgSet.GetItemState(RES_VERT_ORIENT, false, &pVertOrientItem);
-                rChgSet.GetItemState(RES_PROTECT, false, &pProtectItem);
-                rChgSet.GetItemState(RES_FRAMEDIR, false, &pFrameDirItem);
-                rChgSet.GetItemState(RES_BOX, false, &pBoxItem);
+                pVertOrientItem = rChgSet.GetItemIfSet(RES_VERT_ORIENT, false);
+                pProtectItem = rChgSet.GetItemIfSet(RES_PROTECT, false);
+                pFrameDirItem = rChgSet.GetItemIfSet(RES_FRAMEDIR, false);
+                pBoxItem = rChgSet.GetItemIfSet(RES_BOX, false);
                 break;
             }
             case RES_VERT_ORIENT:
diff --git a/sw/source/core/layout/wsfrm.cxx b/sw/source/core/layout/wsfrm.cxx
index dd7999943dd5..bcc4ddce252a 100644
--- a/sw/source/core/layout/wsfrm.cxx
+++ b/sw/source/core/layout/wsfrm.cxx
@@ -450,13 +450,12 @@ void SwTabFrame::CheckDirection( bool bVert )
 void SwCellFrame::CheckDirection( bool bVert )
 {
     const SwFrameFormat* pFormat = GetFormat();
-    const SfxPoolItem* pItem;
+    const SvxFrameDirectionItem* pFrameDirItem;
     // Check if the item is set, before actually
     // using it. Otherwise the dynamic pool default is used, which may be set
     // to LTR in case of OOo 1.0 documents.
-    if( pFormat && SfxItemState::SET == pFormat->GetItemState( RES_FRAMEDIR, 
true, &pItem ) )
+    if( pFormat && (pFrameDirItem = pFormat->GetItemIfSet( RES_FRAMEDIR ) ) )
     {
-        const SvxFrameDirectionItem* pFrameDirItem = static_cast<const 
SvxFrameDirectionItem*>(pItem);
         const SwViewShell *pSh = getRootFrame()->GetCurrShell();
         const bool bBrowseMode = pSh && pSh->GetViewOptions()->getBrowseMode();
         CheckDir( pFrameDirItem->GetValue(), bVert, false, bBrowseMode );
diff --git a/sw/source/core/table/swnewtable.cxx 
b/sw/source/core/table/swnewtable.cxx
index a5556e83ecf3..48953db7c75c 100644
--- a/sw/source/core/table/swnewtable.cxx
+++ b/sw/source/core/table/swnewtable.cxx
@@ -2135,10 +2135,9 @@ void SwTable::ConvertSubtableBox(sal_uInt16 const nRow, 
sal_uInt16 const nBox)
     SwFormatFrameSize const 
outerSize(pSourceLine->GetFrameFormat()->GetFrameSize());
     tools::Long minHeights(0);
     {
-        SwFormatFrameSize const* pSize(nullptr);
         SwFrameFormat const& 
rSubLineFormat(*pSubTableBox->GetTabLines()[0]->GetFrameFormat());
-        if (rSubLineFormat.GetItemState(RES_FRM_SIZE, true,
-            reinterpret_cast<SfxPoolItem const**>(&pSize)) == 
SfxItemState::SET)
+        SwFormatFrameSize const* pSize = 
rSubLineFormat.GetItemIfSet(RES_FRM_SIZE);
+        if (pSize)
         {   // for first row, apply height from inner row to outer row.
             // in case the existing outer row height was larger than the entire
             // subtable, the last inserted row needs to be tweaked (below)
@@ -2157,9 +2156,8 @@ void SwTable::ConvertSubtableBox(sal_uInt16 const nRow, 
sal_uInt16 const nBox)
             pSourceLine->GetTabBoxes().size() - 1 + 
pSubLine->GetTabBoxes().size(),
             nullptr);
         SwFrameFormat const& rSubLineFormat(*pSubLine->GetFrameFormat());
-        SwFormatFrameSize const* pSize(nullptr);
-        if (rSubLineFormat.GetItemState(RES_FRM_SIZE, true,
-            reinterpret_cast<SfxPoolItem const**>(&pSize)) == 
SfxItemState::SET)
+        SwFormatFrameSize const* pSize = 
rSubLineFormat.GetItemIfSet(RES_FRM_SIZE);
+        if (pSize)
         {   // for rows 2..N, copy inner row height to outer row
             pNewLine->ClaimFrameFormat();
             pNewLine->GetFrameFormat()->SetFormatAttr(*pSize);
@@ -2217,8 +2215,7 @@ void SwTable::ConvertSubtableBox(sal_uInt16 const nRow, 
sal_uInt16 const nBox)
                     pDoc->GetNodes().Delete(insPos);
                     if (pRowBrush)
                     {
-                        SfxPoolItem const* pCellBrush(nullptr);
-                        if 
(pNewBox->GetFrameFormat()->GetItemState(RES_BACKGROUND, true, &pCellBrush) != 
SfxItemState::SET)
+                        if 
(pNewBox->GetFrameFormat()->GetItemState(RES_BACKGROUND, true) != 
SfxItemState::SET)
                         {   // set inner row background on inner cell
                             pNewBox->ClaimFrameFormat();
                             
pNewBox->GetFrameFormat()->SetFormatAttr(*pRowBrush);
diff --git a/sw/source/core/table/swtable.cxx b/sw/source/core/table/swtable.cxx
index 101f5245f5ad..ec6487028790 100644
--- a/sw/source/core/table/swtable.cxx
+++ b/sw/source/core/table/swtable.cxx
@@ -336,10 +336,9 @@ void SwTable::SwClientNotify(const SwModify&, const 
SfxHint& rHint)
         case RES_ATTRSET_CHG:
         {
             if (pLegacy->m_pOld && pLegacy->m_pNew
-                    && SfxItemState::SET == static_cast<const 
SwAttrSetChg*>(pLegacy->m_pNew)->GetChgSet()->GetItemState(
+                    && (pNewSize = static_cast<const 
SwAttrSetChg*>(pLegacy->m_pNew)->GetChgSet()->GetItemIfSet(
                             RES_FRM_SIZE,
-                            false,
-                            reinterpret_cast<const SfxPoolItem**>(&pNewSize)))
+                            false)))
             {
                 pOldSize = &static_cast<const 
SwAttrSetChg*>(pLegacy->m_pOld)->GetChgSet()->GetFrameSize();
             }
@@ -2137,11 +2136,11 @@ void ChgTextToNum( SwTableBox& rBox, const OUString& 
rText, const Color* pCol,
 
     SwDoc* pDoc = rBox.GetFrameFormat()->GetDoc();
     SwTextNode* pTNd = pDoc->GetNodes()[ nNdPos ]->GetTextNode();
-    const SfxPoolItem* pItem;
 
     // assign adjustment
     if( bChgAlign )
     {
+        const SfxPoolItem* pItem;
         pItem = &pTNd->SwContentNode::GetAttr( RES_PARATR_ADJUST );
         SvxAdjust eAdjust = static_cast<const 
SvxAdjustItem*>(pItem)->GetAdjust();
         if( SvxAdjust::Left == eAdjust || SvxAdjust::Block == eAdjust )
@@ -2153,14 +2152,14 @@ void ChgTextToNum( SwTableBox& rBox, const OUString& 
rText, const Color* pCol,
     }
 
     // assign color or save "user color"
-    if( !pTNd->GetpSwAttrSet() || SfxItemState::SET != pTNd->GetpSwAttrSet()->
-        GetItemState( RES_CHRATR_COLOR, false, &pItem ))
-        pItem = nullptr;
+    const SvxColorItem* pColorItem = nullptr;
+    if( pTNd->GetpSwAttrSet() )
+        pColorItem = pTNd->GetpSwAttrSet()->GetItemIfSet( RES_CHRATR_COLOR, 
false );
 
     const std::optional<Color>& pOldNumFormatColor = 
rBox.GetSaveNumFormatColor();
     std::optional<Color> pNewUserColor;
-    if (pItem)
-        pNewUserColor = static_cast<const SvxColorItem*>(pItem)->GetValue();
+    if (pColorItem)
+        pNewUserColor = pColorItem->GetValue();
 
     if( ( pNewUserColor && pOldNumFormatColor &&
             *pNewUserColor == *pOldNumFormatColor ) ||
@@ -2170,7 +2169,7 @@ void ChgTextToNum( SwTableBox& rBox, const OUString& 
rText, const Color* pCol,
         if( pCol )
             // if needed, set the color
             pTNd->SetAttr( SvxColorItem( *pCol, RES_CHRATR_COLOR ));
-        else if( pItem )
+        else if( pColorItem )
         {
             pNewUserColor = rBox.GetSaveUserColor();
             if( pNewUserColor )
@@ -2246,10 +2245,10 @@ void ChgTextToNum( SwTableBox& rBox, const OUString& 
rText, const Color* pCol,
     }
 
     // assign vertical orientation
+    const SwFormatVertOrient* pVertOrientItem;
     if( bChgAlign &&
-        ( SfxItemState::SET != rBox.GetFrameFormat()->GetItemState(
-            RES_VERT_ORIENT, true, &pItem ) ||
-            text::VertOrientation::TOP == static_cast<const 
SwFormatVertOrient*>(pItem)->GetVertOrient() ))
+        ( !(pVertOrientItem = rBox.GetFrameFormat()->GetItemIfSet( 
RES_VERT_ORIENT )) ||
+            text::VertOrientation::TOP == pVertOrientItem->GetVertOrient() ))
     {
         rBox.GetFrameFormat()->SetFormatAttr( SwFormatVertOrient( 0, 
text::VertOrientation::BOTTOM ));
     }
@@ -2265,7 +2264,6 @@ static void ChgNumToText( SwTableBox& rBox, sal_uLong 
nFormat )
     SwDoc* pDoc = rBox.GetFrameFormat()->GetDoc();
     SwTextNode* pTNd = pDoc->GetNodes()[ nNdPos ]->GetTextNode();
     bool bChgAlign = pDoc->IsInsTableAlignNum();
-    const SfxPoolItem* pItem;
 
     const Color * pCol = nullptr;
     if( getSwDefaultTextFormat() != nFormat )
@@ -2289,22 +2287,23 @@ static void ChgNumToText( SwTableBox& rBox, sal_uLong 
nFormat )
     const SfxItemSet* pAttrSet = pTNd->GetpSwAttrSet();
 
     // assign adjustment
-    if( bChgAlign && pAttrSet && SfxItemState::SET == pAttrSet->GetItemState(
-        RES_PARATR_ADJUST, false, &pItem ) &&
-            SvxAdjust::Right == static_cast<const 
SvxAdjustItem*>(pItem)->GetAdjust() )
+    const SvxAdjustItem* pAdjustItem;
+    if( bChgAlign && pAttrSet &&
+        (pAdjustItem = pAttrSet->GetItemIfSet( RES_PARATR_ADJUST, false )) &&
+        SvxAdjust::Right == pAdjustItem->GetAdjust() )
     {
         pTNd->SetAttr( SvxAdjustItem( SvxAdjust::Left, RES_PARATR_ADJUST ) );
     }
 
     // assign color or save "user color"
-    if( !pAttrSet || SfxItemState::SET != pAttrSet->
-        GetItemState( RES_CHRATR_COLOR, false, &pItem ))
-        pItem = nullptr;
+    const SvxColorItem* pColorItem = nullptr;
+    if( pAttrSet )
+        pColorItem = pAttrSet->GetItemIfSet( RES_CHRATR_COLOR, false );
 
     const std::optional<Color>& pOldNumFormatColor = 
rBox.GetSaveNumFormatColor();
     std::optional<Color> pNewUserColor;
-    if (pItem)
-        pNewUserColor = static_cast<const SvxColorItem*>(pItem)->GetValue();
+    if (pColorItem)
+        pNewUserColor = pColorItem->GetValue();
 
     if( ( pNewUserColor && pOldNumFormatColor &&
             *pNewUserColor == *pOldNumFormatColor ) ||
@@ -2314,7 +2313,7 @@ static void ChgNumToText( SwTableBox& rBox, sal_uLong 
nFormat )
         if( pCol )
             // if needed, set the color
             pTNd->SetAttr( SvxColorItem( *pCol, RES_CHRATR_COLOR ));
-        else if( pItem )
+        else if( pColorItem )
         {
             pNewUserColor = rBox.GetSaveUserColor();
             if( pNewUserColor )
@@ -2336,10 +2335,10 @@ static void ChgNumToText( SwTableBox& rBox, sal_uLong 
nFormat )
     rBox.SetSaveNumFormatColor( pCol ? *pCol : std::optional<Color>() );
 
     // assign vertical orientation
+    const SwFormatVertOrient* pVertOrientItem;
     if( bChgAlign &&
-        SfxItemState::SET == rBox.GetFrameFormat()->GetItemState(
-        RES_VERT_ORIENT, false, &pItem ) &&
-        text::VertOrientation::BOTTOM == static_cast<const 
SwFormatVertOrient*>(pItem)->GetVertOrient() )
+        (pVertOrientItem = rBox.GetFrameFormat()->GetItemIfSet( 
RES_VERT_ORIENT, false )) &&
+        text::VertOrientation::BOTTOM == pVertOrientItem->GetVertOrient() )
     {
         rBox.GetFrameFormat()->SetFormatAttr( SwFormatVertOrient( 0, 
text::VertOrientation::TOP ));
     }
@@ -2359,7 +2358,7 @@ void SwTableBoxFormat::BoxAttributeChanged(SwTableBox& 
rBox, const SwTableBoxNum
     else
     {
         // fetch the current Item
-        (void)GetItemState(RES_BOXATR_FORMAT, false, reinterpret_cast<const 
SfxPoolItem**>(&pNewFormat));
+        pNewFormat = GetItemIfSet(RES_BOXATR_FORMAT, false);
         nOldFormat = GetTableBoxNumFormat().GetValue();
         nNewFormat = pNewFormat ? pNewFormat->GetValue() : nOldFormat;
     }
@@ -2397,7 +2396,9 @@ void SwTableBoxFormat::BoxAttributeChanged(SwTableBox& 
rBox, const SwTableBoxNum
         OUString aOrigText;
         bool bChgText = true;
         double fVal = 0;
-        if(!pNewValue && SfxItemState::SET != GetItemState(RES_BOXATR_VALUE, 
false, reinterpret_cast<const SfxPoolItem**>(&pNewValue)))
+        if(!pNewValue)
+            pNewValue = GetItemIfSet(RES_BOXATR_VALUE, false);
+        if(!pNewValue)
         {
             // so far, no value has been set, so try to evaluate the content
             SwNodeOffset nNdPos = rBox.IsValidNumTextNd();
@@ -2528,10 +2529,11 @@ void SwTableBoxFormat::SwClientNotify(const SwModify& 
rMod, const SfxHint& rHint
         case RES_ATTRSET_CHG:
         {
             const SfxItemSet& rSet = *static_cast<const 
SwAttrSetChg*>(pLegacy->m_pNew)->GetChgSet();
-            if(SfxItemState::SET == rSet.GetItemState( RES_BOXATR_FORMAT, 
false, reinterpret_cast<const SfxPoolItem**>(&pNewFormat)))
+            pNewFormat = rSet.GetItemIfSet( RES_BOXATR_FORMAT, false);
+            if(pNewFormat)
                 nOldFormat = static_cast<const 
SwAttrSetChg*>(pLegacy->m_pOld)->GetChgSet()->Get(RES_BOXATR_FORMAT).GetValue();
-            rSet.GetItemState(RES_BOXATR_FORMULA, false, 
reinterpret_cast<const SfxPoolItem**>(&pNewFormula));
-            rSet.GetItemState(RES_BOXATR_VALUE, false, reinterpret_cast<const 
SfxPoolItem**>(&pNewVal));
+            pNewFormula = rSet.GetItemIfSet(RES_BOXATR_FORMULA, false);
+            pNewVal = rSet.GetItemIfSet(RES_BOXATR_VALUE, false);
             break;
         }
         case RES_BOXATR_FORMAT:
@@ -2591,10 +2593,9 @@ bool SwTableBox::HasNumContent( double& rNum, 
sal_uInt32& rFormatIndex,
         rIsEmptyTextNd = aText.isEmpty();
         SvNumberFormatter* pNumFormatr = 
GetFrameFormat()->GetDoc()->GetNumberFormatter();
 
-        const SfxPoolItem* pItem;
-        if( SfxItemState::SET == GetFrameFormat()->GetItemState( 
RES_BOXATR_FORMAT, false, &pItem ))
+        if( const SwTableBoxNumFormat* pItem = GetFrameFormat()->GetItemIfSet( 
RES_BOXATR_FORMAT, false) )
         {
-            rFormatIndex = static_cast<const 
SwTableBoxNumFormat*>(pItem)->GetValue();
+            rFormatIndex = pItem->GetValue();
             // Special casing for percent
             if( !rIsEmptyTextNd && SvNumFormatType::PERCENT == 
pNumFormatr->GetType( rFormatIndex ))
             {
@@ -2620,15 +2621,8 @@ bool SwTableBox::IsNumberChanged() const
 
     if( SfxItemState::SET == GetFrameFormat()->GetItemState( 
RES_BOXATR_FORMULA, false ))
     {
-        const SwTableBoxNumFormat *pNumFormat;
-        const SwTableBoxValue *pValue;
-
-        if( SfxItemState::SET != GetFrameFormat()->GetItemState( 
RES_BOXATR_VALUE, false,
-            reinterpret_cast<const SfxPoolItem**>(&pValue) ))
-            pValue = nullptr;
-        if( SfxItemState::SET != GetFrameFormat()->GetItemState( 
RES_BOXATR_FORMAT, false,
-            reinterpret_cast<const SfxPoolItem**>(&pNumFormat) ))
-            pNumFormat = nullptr;
+        const SwTableBoxNumFormat *pNumFormat = 
GetFrameFormat()->GetItemIfSet( RES_BOXATR_FORMAT, false );
+        const SwTableBoxValue *pValue = GetFrameFormat()->GetItemIfSet( 
RES_BOXATR_VALUE, false );
 
         SwNodeOffset nNdPos;
         if( pNumFormat && pValue && NODE_OFFSET_MAX != ( nNdPos = 
IsValidNumTextNd() ) )
@@ -2753,20 +2747,22 @@ sal_uInt16 SwTableBox::IsFormulaOrValueBox() const
 
 void SwTableBox::ActualiseValueBox()
 {
-    const SfxPoolItem *pFormatItem, *pValItem;
     SwFrameFormat* pFormat = GetFrameFormat();
-    if( SfxItemState::SET != pFormat->GetItemState( RES_BOXATR_FORMAT, true, 
&pFormatItem )
-        || SfxItemState::SET != pFormat->GetItemState( RES_BOXATR_VALUE, true, 
&pValItem ))
+    const SwTableBoxNumFormat *pFormatItem = pFormat->GetItemIfSet( 
RES_BOXATR_FORMAT, true );
+    if (!pFormatItem)
+        return;
+    const SwTableBoxValue *pValItem = pFormat->GetItemIfSet( RES_BOXATR_VALUE 
);
+    if (!pValItem)
         return;
 
-    const sal_uLong nFormatId = static_cast<const 
SwTableBoxNumFormat*>(pFormatItem)->GetValue();
+    const sal_uLong nFormatId = pFormatItem->GetValue();
     SwNodeOffset nNdPos = NODE_OFFSET_MAX;
     SvNumberFormatter* pNumFormatr = pFormat->GetDoc()->GetNumberFormatter();
 
     if( !pNumFormatr->IsTextFormat( nFormatId ) &&
         NODE_OFFSET_MAX != (nNdPos = IsValidNumTextNd()) )
     {
-        double fVal = static_cast<const 
SwTableBoxValue*>(pValItem)->GetValue();
+        double fVal = pValItem->GetValue();
         const Color* pCol = nullptr;
         OUString sNewText;
         pNumFormatr->GetOutputString( fVal, nFormatId, sNewText, &pCol );

Reply via email to