sw/source/core/text/EnhancedPDFExportHelper.cxx |    6 +--
 sw/source/core/text/atrstck.cxx                 |    5 +-
 sw/source/core/text/itrform2.cxx                |    6 +--
 sw/source/core/text/itrpaint.cxx                |    7 +--
 sw/source/core/text/porlay.cxx                  |    5 +-
 sw/source/core/text/pormulti.cxx                |   48 +++++++++---------------
 sw/source/core/text/txtfld.cxx                  |   13 +++---
 sw/source/core/text/txtfrm.cxx                  |   11 ++---
 sw/source/core/text/txtftn.cxx                  |   11 ++---
 9 files changed, 44 insertions(+), 68 deletions(-)

New commits:
commit 9a44807ff3a11afa8f7ce9857ae6a6144a61d481
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Wed Mar 2 17:58:31 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Thu Mar 3 08:52:49 2022 +0100

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

diff --git a/sw/source/core/text/EnhancedPDFExportHelper.cxx 
b/sw/source/core/text/EnhancedPDFExportHelper.cxx
index ca02c98e6e52..1e9e74e33736 100644
--- a/sw/source/core/text/EnhancedPDFExportHelper.cxx
+++ b/sw/source/core/text/EnhancedPDFExportHelper.cxx
@@ -1730,15 +1730,15 @@ void SwEnhancedPDFExportHelper::EnhancedPDFExport()
         for( size_t n = 0; n < nSpzFrameFormatsCount; ++n )
         {
             SwFrameFormat* pFrameFormat = (*pTable)[n];
-            const SfxPoolItem* pItem;
+            const SwFormatURL* pItem;
             if ( RES_DRAWFRMFMT != pFrameFormat->Which() &&
                 GetFrameOfModify(mrSh.GetLayout(), *pFrameFormat, 
SwFrameType::Fly) &&
-                 SfxItemState::SET == pFrameFormat->GetAttrSet().GetItemState( 
RES_URL, true, &pItem ) )
+                 (pItem = pFrameFormat->GetAttrSet().GetItemIfSet( RES_URL )) )
             {
                 const SwPageFrame* pCurrPage =
                     static_cast<const SwPageFrame*>( mrSh.GetLayout()->Lower() 
);
 
-                OUString aURL( static_cast<const 
SwFormatURL*>(pItem)->GetURL() );
+                OUString aURL( pItem->GetURL() );
                 if (aURL.isEmpty())
                     continue;
                 const bool bIntern = '#' == aURL[0];
diff --git a/sw/source/core/text/atrstck.cxx b/sw/source/core/text/atrstck.cxx
index 30a88c30110d..8c64b1dd5f45 100644
--- a/sw/source/core/text/atrstck.cxx
+++ b/sw/source/core/text/atrstck.cxx
@@ -220,9 +220,8 @@ static bool lcl_ChgHyperLinkColor( const SwTextAttr& rAttr,
                 // take color from character format 'unvisited link'
                 rINetAttr.SetVisited(false);
                 const SwCharFormat* pTmpFormat = rINetAttr.GetCharFormat();
-                const SfxPoolItem* pItem;
-                if (SfxItemState::SET == 
pTmpFormat->GetItemState(RES_CHRATR_COLOR, true, &pItem))
-                    *pColor = 
pItem->StaticWhichCast(RES_CHRATR_COLOR).GetValue();
+                if (const SvxColorItem* pItem = 
pTmpFormat->GetItemIfSet(RES_CHRATR_COLOR))
+                    *pColor = pItem->GetValue();
                 rINetAttr.SetVisited(true);
             }
             return true;
diff --git a/sw/source/core/text/itrform2.cxx b/sw/source/core/text/itrform2.cxx
index 6a91d3c37dfc..354c976e6e0b 100644
--- a/sw/source/core/text/itrform2.cxx
+++ b/sw/source/core/text/itrform2.cxx
@@ -1561,11 +1561,9 @@ SwLinePortion *SwTextFormatter::NewPortion( 
SwTextFormatInfo &rInf )
                     pInfo = &pDoc->GetFootnoteInfo();
                 const SwAttrSet& rSet = 
pInfo->GetAnchorCharFormat(const_cast<SwDoc&>(*pDoc))->GetAttrSet();
 
-                const SfxPoolItem* pItem;
                 Degree10 nDir(0);
-                if( SfxItemState::SET == rSet.GetItemState( RES_CHRATR_ROTATE,
-                    true, &pItem ))
-                    nDir = static_cast<const 
SvxCharRotateItem*>(pItem)->GetValue();
+                if( const SvxCharRotateItem* pItem = rSet.GetItemIfSet( 
RES_CHRATR_ROTATE ) )
+                    nDir = pItem->GetValue();
 
                 if ( nDir )
                 {
diff --git a/sw/source/core/text/itrpaint.cxx b/sw/source/core/text/itrpaint.cxx
index 96faaf23615a..7f783e40428f 100644
--- a/sw/source/core/text/itrpaint.cxx
+++ b/sw/source/core/text/itrpaint.cxx
@@ -543,12 +543,11 @@ void SwTextPainter::CheckSpecialUnderline( const 
SwLinePortion* pPor,
         sal_Int32 nTmp(0);
         for (auto const& e : pMerged->extents)
         {
-            const SfxPoolItem* pItem;
-            if (SfxItemState::SET == e.pNode->GetSwAttrSet().GetItemState(
-                        RES_CHRATR_UNDERLINE, true, &pItem))
+            if (const SvxUnderlineItem* pItem = 
e.pNode->GetSwAttrSet().GetItemIfSet(
+                        RES_CHRATR_UNDERLINE))
             {
                 const bool bUnderSelect(m_pFont->GetUnderline() ==
-                    static_cast<SvxUnderlineItem 
const*>(pItem)->GetLineStyle());
+                    pItem->GetLineStyle());
                 aUnderMulti.Select(Range(nTmp, nTmp + e.nEnd - e.nStart - 1),
                         bUnderSelect);
             }
diff --git a/sw/source/core/text/porlay.cxx b/sw/source/core/text/porlay.cxx
index bd9d6a0e143c..8212fca02f6a 100644
--- a/sw/source/core/text/porlay.cxx
+++ b/sw/source/core/text/porlay.cxx
@@ -2621,9 +2621,8 @@ void SwScriptInfo::selectHiddenTextProperty(const 
SwTextNode& rNode,
     assert((rNode.GetText().isEmpty() && rHiddenMulti.GetTotalRange().Len() == 
1)
         || (rNode.GetText().getLength() == 
rHiddenMulti.GetTotalRange().Len()));
 
-    const SfxPoolItem* pItem = nullptr;
-    if( SfxItemState::SET == rNode.GetSwAttrSet().GetItemState( 
RES_CHRATR_HIDDEN, true, &pItem ) &&
-        static_cast<const SvxCharHiddenItem*>(pItem)->GetValue() )
+    const SvxCharHiddenItem* pItem = rNode.GetSwAttrSet().GetItemIfSet( 
RES_CHRATR_HIDDEN );
+    if( pItem && pItem->GetValue() )
     {
         rHiddenMulti.SelectAll();
     }
diff --git a/sw/source/core/text/pormulti.cxx b/sw/source/core/text/pormulti.cxx
index ee1595496a6c..2e4831065537 100644
--- a/sw/source/core/text/pormulti.cxx
+++ b/sw/source/core/text/pormulti.cxx
@@ -969,9 +969,9 @@ std::optional<SwMultiCreator> 
SwTextSizeInfo::GetMultiCreator(TextFrameIndex &rP
     // need the node that contains input rPos
     std::pair<SwTextNode const*, sal_Int32> 
startPos(m_pFrame->MapViewToModel(rPos));
     const SvxCharRotateItem* pActiveRotateItem(nullptr);
-    const SfxPoolItem* pNodeRotateItem(nullptr);
+    const SvxCharRotateItem* pNodeRotateItem(nullptr);
     const SvxTwoLinesItem* pActiveTwoLinesItem(nullptr);
-    const SfxPoolItem* pNodeTwoLinesItem(nullptr);
+    const SvxTwoLinesItem* pNodeTwoLinesItem(nullptr);
     SwTextAttr const* pActiveTwoLinesHint(nullptr);
     SwTextAttr const* pActiveRotateHint(nullptr);
     const SwTextAttr *pRuby = nullptr;
@@ -1029,25 +1029,16 @@ std::optional<SwMultiCreator> 
SwTextSizeInfo::GetMultiCreator(TextFrameIndex &rP
             if (startPos.first->GetIndex() == pNode->GetIndex())
             {
                 iterAtStartOfNode.Assign(iter);
-                if (SfxItemState::SET == pNode->GetSwAttrSet().GetItemState(
-                            RES_CHRATR_ROTATE, true, &pNodeRotateItem) &&
-                    static_cast<const 
SvxCharRotateItem*>(pNodeRotateItem)->GetValue())
+                pNodeRotateItem = 
pNode->GetSwAttrSet().GetItemIfSet(RES_CHRATR_ROTATE);
+                if (pNodeRotateItem && pNodeRotateItem->GetValue())
                 {
-                    pActiveRotateItem = static_cast<const 
SvxCharRotateItem*>(pNodeRotateItem);
+                    pActiveRotateItem = pNodeRotateItem;
                 }
-                else
-                {
-                    pNodeRotateItem = nullptr;
-                }
-                if (SfxItemState::SET == 
startPos.first->GetSwAttrSet().GetItemState(
-                            RES_CHRATR_TWO_LINES, true, &pNodeTwoLinesItem) &&
-                    static_cast<const 
SvxTwoLinesItem*>(pNodeTwoLinesItem)->GetValue())
-                {
-                    pActiveTwoLinesItem = static_cast<const 
SvxTwoLinesItem*>(pNodeTwoLinesItem);
-                }
-                else
+                pNodeTwoLinesItem = 
startPos.first->GetSwAttrSet().GetItemIfSet(
+                            RES_CHRATR_TWO_LINES);
+                if (pNodeTwoLinesItem && pNodeTwoLinesItem->GetValue())
                 {
-                    pNodeTwoLinesItem = nullptr;
+                    pActiveTwoLinesItem = pNodeTwoLinesItem;
                 }
             }
         }
@@ -1090,9 +1081,9 @@ std::optional<SwMultiCreator> 
SwTextSizeInfo::GetMultiCreator(TextFrameIndex &rP
             if (pNodeTwoLinesItem)
             {
                 aEnd.push_front(m_pFrame->MapModelToView(startPos.first, 
startPos.first->Len()));
-                bOn = static_cast<const 
SvxTwoLinesItem*>(pNodeTwoLinesItem)->GetEndBracket() ==
+                bOn = pNodeTwoLinesItem->GetEndBracket() ==
                         pActiveTwoLinesItem->GetEndBracket() &&
-                      static_cast<const 
SvxTwoLinesItem*>(pNodeTwoLinesItem)->GetStartBracket() ==
+                      pNodeTwoLinesItem->GetStartBracket() ==
                         pActiveTwoLinesItem->GetStartBracket();
             }
             else
@@ -1150,9 +1141,8 @@ std::optional<SwMultiCreator> 
SwTextSizeInfo::GetMultiCreator(TextFrameIndex &rP
             }
             else
             {
-                pNodeTwoLinesItem = nullptr;
-                pNode->GetSwAttrSet().GetItemState(
-                            RES_CHRATR_TWO_LINES, true, &pNodeTwoLinesItem);
+                pNodeTwoLinesItem = pNode->GetSwAttrSet().GetItemIfSet(
+                            RES_CHRATR_TWO_LINES);
                 nTmpStart = m_pFrame->MapModelToView(pNode, 0);
                 nTmpEnd = m_pFrame->MapModelToView(pNode, pNode->Len());
                 assert(rPos <= nTmpEnd); // next node must not have smaller 
index
@@ -1255,9 +1245,8 @@ std::optional<SwMultiCreator> 
SwTextSizeInfo::GetMultiCreator(TextFrameIndex &rP
             }
             else
             {
-                pNodeTwoLinesItem = nullptr;
-                pNode->GetSwAttrSet().GetItemState(
-                            RES_CHRATR_TWO_LINES, true, &pNodeTwoLinesItem);
+                pNodeTwoLinesItem = pNode->GetSwAttrSet().GetItemIfSet(
+                            RES_CHRATR_TWO_LINES);
                 nTmpStart = m_pFrame->MapModelToView(pNode, 0);
                 nTmpEnd = m_pFrame->MapModelToView(pNode, pNode->Len());
                 assert(n2Start <= nTmpEnd); // next node must not have smaller 
index
@@ -1321,7 +1310,7 @@ std::optional<SwMultiCreator> 
SwTextSizeInfo::GetMultiCreator(TextFrameIndex &rP
             if (pNodeRotateItem)
             {
                 aEnd.push_front(m_pFrame->MapModelToView(startPos.first, 
startPos.first->Len()));
-                bOn = static_cast<const 
SvxCharRotateItem*>(pNodeRotateItem)->GetValue() ==
+                bOn = pNodeRotateItem->GetValue() ==
                         pActiveRotateItem->GetValue();
             }
             else
@@ -1356,9 +1345,8 @@ std::optional<SwMultiCreator> 
SwTextSizeInfo::GetMultiCreator(TextFrameIndex &rP
             }
             else
             {
-                pNodeRotateItem = nullptr;
-                pNode->GetSwAttrSet().GetItemState(
-                            RES_CHRATR_ROTATE, true, &pNodeRotateItem);
+                pNodeRotateItem = pNode->GetSwAttrSet().GetItemIfSet(
+                            RES_CHRATR_ROTATE);
                 nTmpStart = m_pFrame->MapModelToView(pNode, 0);
                 nTmpEnd = m_pFrame->MapModelToView(pNode, pNode->Len());
                 assert(rPos <= nTmpEnd); // next node must not have smaller 
index
diff --git a/sw/source/core/text/txtfld.cxx b/sw/source/core/text/txtfld.cxx
index 90fbf0d630ce..06cb7388378e 100644
--- a/sw/source/core/text/txtfld.cxx
+++ b/sw/source/core/text/txtfld.cxx
@@ -596,13 +596,12 @@ static void lcl_setRedlineAttr( SwTextFormatInfo &rInf, 
const SwTextNode& rTextN
     else
         SW_MOD()->GetInsertAuthorAttr(aAuthor, aSet);
 
-    const SfxPoolItem* pItem = nullptr;
-    if (SfxItemState::SET == aSet.GetItemState(RES_CHRATR_COLOR, true, &pItem))
-        pNumFnt->SetColor(static_cast<const SvxColorItem*>(pItem)->GetValue());
-    if (SfxItemState::SET == aSet.GetItemState(RES_CHRATR_UNDERLINE, true, 
&pItem))
-        pNumFnt->SetUnderline(static_cast<const 
SvxUnderlineItem*>(pItem)->GetLineStyle());
-    if (SfxItemState::SET == aSet.GetItemState(RES_CHRATR_CROSSEDOUT, true, 
&pItem))
-        pNumFnt->SetStrikeout( static_cast<const 
SvxCrossedOutItem*>(pItem)->GetStrikeout() );
+    if (const SvxColorItem* pItem = aSet.GetItemIfSet(RES_CHRATR_COLOR))
+        pNumFnt->SetColor(pItem->GetValue());
+    if (const SvxUnderlineItem* pItem = 
aSet.GetItemIfSet(RES_CHRATR_UNDERLINE))
+        pNumFnt->SetUnderline(pItem->GetLineStyle());
+    if (const SvxCrossedOutItem* pItem = 
aSet.GetItemIfSet(RES_CHRATR_CROSSEDOUT))
+        pNumFnt->SetStrikeout( pItem->GetStrikeout() );
 }
 
 SwNumberPortion *SwTextFormatter::NewNumberPortion( SwTextFormatInfo &rInf ) 
const
diff --git a/sw/source/core/text/txtfrm.cxx b/sw/source/core/text/txtfrm.cxx
index b592f179226f..fec5bf391d31 100644
--- a/sw/source/core/text/txtfrm.cxx
+++ b/sw/source/core/text/txtfrm.cxx
@@ -2338,24 +2338,21 @@ void SwTextFrame::SwClientNotify(SwModify const& 
rModify, SfxHint const& rHint)
             InvalidateLineNum();
 
             const SwAttrSet& rNewSet = *static_cast<const 
SwAttrSetChg*>(pNew)->GetChgSet();
-            const SfxPoolItem* pItem = nullptr;
             int nClear = 0;
             sal_uInt16 nCount = rNewSet.Count();
 
-            if( SfxItemState::SET == rNewSet.GetItemState( RES_TXTATR_FTN, 
false, &pItem ))
+            if( const SwFormatFootnote* pItem = rNewSet.GetItemIfSet( 
RES_TXTATR_FTN, false ) )
             {
-                nPos = MapModelToView(&rNode,
-                    static_cast<const 
SwFormatFootnote*>(pItem)->GetTextFootnote()->GetStart());
+                nPos = MapModelToView(&rNode, 
pItem->GetTextFootnote()->GetStart());
                 if (IsIdxInside(nPos, TextFrameIndex(1)))
                     Prepare( PrepareHint::FootnoteInvalidation, pNew );
                 nClear = 0x01;
                 --nCount;
             }
 
-            if( SfxItemState::SET == rNewSet.GetItemState( RES_TXTATR_FIELD, 
false, &pItem ))
+            if( const SwFormatField* pItem = rNewSet.GetItemIfSet( 
RES_TXTATR_FIELD, false ) )
             {
-                nPos = MapModelToView(&rNode,
-                    static_cast<const 
SwFormatField*>(pItem)->GetTextField()->GetStart());
+                nPos = MapModelToView(&rNode, 
pItem->GetTextField()->GetStart());
                 if (IsIdxInside(nPos, TextFrameIndex(1)))
                 {
                     const SfxPoolItem* pOldItem = pOld ?
diff --git a/sw/source/core/text/txtftn.cxx b/sw/source/core/text/txtftn.cxx
index 5b3254b7c2ae..ce7756c23a45 100644
--- a/sw/source/core/text/txtftn.cxx
+++ b/sw/source/core/text/txtftn.cxx
@@ -1313,17 +1313,14 @@ SwFootnoteSave::SwFootnoteSave(const SwTextSizeInfo& 
rInf, const SwTextFootnote*
         }
 
         // set the correct rotation at the footnote font
-        const SfxPoolItem* pItem;
-        if( SfxItemState::SET == rSet.GetItemState( RES_CHRATR_ROTATE,
-            true, &pItem ))
-            m_pFnt->SetVertical(static_cast<const 
SvxCharRotateItem*>(pItem)->GetValue(),
+        if( const SvxCharRotateItem* pItem = rSet.GetItemIfSet( 
RES_CHRATR_ROTATE ) )
+            m_pFnt->SetVertical(pItem->GetValue(),
                                 rInf.GetTextFrame()->IsVertical());
 
         m_pFnt->ChgPhysFnt(m_pInf->GetVsh(), *m_pInf->GetOut());
 
-        if( SfxItemState::SET == rSet.GetItemState( RES_CHRATR_BACKGROUND,
-            true, &pItem ))
-            m_pFnt->SetBackColor(static_cast<const 
SvxBrushItem*>(pItem)->GetColor());
+        if( const SvxBrushItem* pItem = rSet.GetItemIfSet( 
RES_CHRATR_BACKGROUND ) )
+            m_pFnt->SetBackColor(pItem->GetColor());
     }
     else
         m_pFnt = nullptr;

Reply via email to