sw/source/filter/ww8/docxattributeoutput.cxx |   24 +---
 sw/source/filter/ww8/docxexport.cxx          |    6 -
 sw/source/filter/ww8/rtfattributeoutput.cxx  |   22 +--
 sw/source/filter/ww8/rtfsdrexport.cxx        |    2 
 sw/source/filter/ww8/wrtw8esh.cxx            |  156 +++++++++++----------------
 sw/source/filter/ww8/wrtw8nds.cxx            |   51 +++-----
 sw/source/filter/ww8/wrtw8sty.cxx            |   32 ++---
 sw/source/filter/ww8/wrtww8.cxx              |   19 +--
 sw/source/filter/ww8/wrtww8gr.cxx            |  105 ++++++++----------
 9 files changed, 182 insertions(+), 235 deletions(-)

New commits:
commit 3ae0aa5e200a57cb30b6ca0131e7b6b7acb49791
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Wed Mar 9 09:55:08 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Wed Mar 9 10:48:55 2022 +0100

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

diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx 
b/sw/source/filter/ww8/docxattributeoutput.cxx
index 6f3601ff0815..a0fd9fd0f995 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -5265,14 +5265,13 @@ void DocxAttributeOutput::WriteSrcRect(
     sal_Int32 nCropB = aGraphicCropStruct.Bottom;
 
     // simulate border padding as a negative crop.
-    const SfxPoolItem* pItem;
-    if (pFrameFormat && SfxItemState::SET == 
pFrameFormat->GetItemState(RES_BOX, false, &pItem))
+    const SvxBoxItem* pBoxItem;
+    if (pFrameFormat && (pBoxItem = pFrameFormat->GetItemIfSet(RES_BOX, 
false)))
     {
-        const SvxBoxItem& rBox = *static_cast<const SvxBoxItem*>(pItem);
-        nCropL -= rBox.GetDistance( SvxBoxItemLine::LEFT );
-        nCropR -= rBox.GetDistance( SvxBoxItemLine::RIGHT );
-        nCropT -= rBox.GetDistance( SvxBoxItemLine::TOP );
-        nCropB -= rBox.GetDistance( SvxBoxItemLine::BOTTOM );
+        nCropL -= pBoxItem->GetDistance( SvxBoxItemLine::LEFT );
+        nCropR -= pBoxItem->GetDistance( SvxBoxItemLine::RIGHT );
+        nCropT -= pBoxItem->GetDistance( SvxBoxItemLine::TOP );
+        nCropB -= pBoxItem->GetDistance( SvxBoxItemLine::BOTTOM );
     }
 
     if ( !((0 != nCropL) || (0 != nCropT) || (0 != nCropR) || (0 != nCropB)) )
@@ -5430,10 +5429,8 @@ void DocxAttributeOutput::FlyFrameGraphic( const 
SwGrfNode* pGrfNode, const Size
 
     // In case there are any grab-bag items on the graphic frame, emit them 
now.
     // These are always character grab-bags, as graphics are at-char or 
as-char in Word.
-    const SfxPoolItem* pItem = nullptr;
-    if (pFrameFormat->GetAttrSet().HasItem(RES_FRMATR_GRABBAG, &pItem))
+    if (const SfxGrabBagItem* pGrabBag = 
pFrameFormat->GetAttrSet().GetItemIfSet(RES_FRMATR_GRABBAG))
     {
-        const SfxGrabBagItem* pGrabBag = static_cast<const 
SfxGrabBagItem*>(pItem);
         CharGrabBag(*pGrabBag);
     }
 
@@ -5552,11 +5549,10 @@ void DocxAttributeOutput::FlyFrameGraphic( const 
SwGrfNode* pGrfNode, const Size
     else
         m_pSerializer->startElementNS(XML_a, XML_blip, FSNS(XML_r, 
nImageType), aRelId);
 
-    pItem = nullptr;
-
-    if ( pGrfNode && SfxItemState::SET == 
pGrfNode->GetSwAttrSet().GetItemState(RES_GRFATR_DRAWMODE, true, &pItem))
+    const SfxEnumItemInterface* pGrafModeItem = nullptr;
+    if ( pGrfNode && (pGrafModeItem = 
pGrfNode->GetSwAttrSet().GetItemIfSet(RES_GRFATR_DRAWMODE)))
     {
-        GraphicDrawMode nMode = static_cast<GraphicDrawMode>(static_cast<const 
SfxEnumItemInterface*>(pItem)->GetEnumValue());
+        GraphicDrawMode nMode = 
static_cast<GraphicDrawMode>(pGrafModeItem->GetEnumValue());
         if (nMode == GraphicDrawMode::Greys)
             m_pSerializer->singleElementNS (XML_a, XML_grayscl);
         else if (nMode == GraphicDrawMode::Mono) //black/white has a 0,5 
threshold in LibreOffice
diff --git a/sw/source/filter/ww8/docxexport.cxx 
b/sw/source/filter/ww8/docxexport.cxx
index c5518afa822f..51534eda5e7c 100644
--- a/sw/source/filter/ww8/docxexport.cxx
+++ b/sw/source/filter/ww8/docxexport.cxx
@@ -1168,10 +1168,10 @@ void DocxExport::WriteSettings()
 
     // Hyphenation details set depending on default style
     SwTextFormatColl* pColl = 
m_rDoc.getIDocumentStylePoolAccess().GetTextCollFromPool(RES_POOLCOLL_STANDARD, 
/*bRegardLanguage=*/false);
-    const SfxPoolItem* pItem;
-    if (pColl && SfxItemState::SET == 
pColl->GetItemState(RES_PARATR_HYPHENZONE, false, &pItem))
+    const SvxHyphenZoneItem* pZoneItem;
+    if (pColl && (pZoneItem = pColl->GetItemIfSet(RES_PARATR_HYPHENZONE, 
false)))
     {
-        if (static_cast<const 
SvxHyphenZoneItem*>(pItem)->IsNoCapsHyphenation())
+        if (pZoneItem->IsNoCapsHyphenation())
             pFS->singleElementNS(XML_w, XML_doNotHyphenateCaps);
     }
 
diff --git a/sw/source/filter/ww8/rtfattributeoutput.cxx 
b/sw/source/filter/ww8/rtfattributeoutput.cxx
index 925b8ddbf016..56c126762fdf 100644
--- a/sw/source/filter/ww8/rtfattributeoutput.cxx
+++ b/sw/source/filter/ww8/rtfattributeoutput.cxx
@@ -742,11 +742,11 @@ void RtfAttributeOutput::TableDefaultBorders(
     const SwWriteTableCell* const pCell
         = pRow->GetCells()[pTableTextNodeInfoInner->getCell()].get();
     const SwFrameFormat* pCellFormat = pCell->GetBox()->GetFrameFormat();
-    const SfxPoolItem* pItem;
-    if (!pCellFormat->GetAttrSet().HasItem(RES_BOX, &pItem))
+    const SvxBoxItem* pItem = pCellFormat->GetAttrSet().GetItemIfSet(RES_BOX);
+    if (!pItem)
         return;
 
-    auto& rBox = pItem->StaticWhichCast(RES_BOX);
+    auto& rBox = *pItem;
     static const SvxBoxItemLine aBorders[] = { SvxBoxItemLine::TOP, 
SvxBoxItemLine::LEFT,
                                                SvxBoxItemLine::BOTTOM, 
SvxBoxItemLine::RIGHT };
     static const char* aBorderNames[]
@@ -797,12 +797,10 @@ void RtfAttributeOutput::TableBackgrounds(
     const SwWriteTableCell* const pCell
         = pRow->GetCells()[pTableTextNodeInfoInner->getCell()].get();
     const SwFrameFormat* pCellFormat = pCell->GetBox()->GetFrameFormat();
-    const SfxPoolItem* pItem;
-    if (pCellFormat->GetAttrSet().HasItem(RES_BACKGROUND, &pItem))
+    if (const SvxBrushItem* pBrushItem = 
pCellFormat->GetAttrSet().GetItemIfSet(RES_BACKGROUND))
     {
-        auto& rBack = pItem->StaticWhichCast(RES_BACKGROUND);
-        if (rBack.GetColor() != COL_AUTO)
-            aColor = rBack.GetColor();
+        if (pBrushItem->GetColor() != COL_AUTO)
+            aColor = pBrushItem->GetColor();
     }
 
     if (!aColor.IsTransparent())
@@ -892,8 +890,6 @@ void RtfAttributeOutput::TableVerticalCell(
     else if (SvxFrameDirection::Vertical_LR_BT == 
m_rExport.TrueFrameDirection(*pCellFormat))
         m_aRowDefs.append(OOO_STRING_SVTOOLS_RTF_CLTXBTLR);
 
-    const SfxPoolItem* pItem;
-
     // vertical merges
     if (pCell->GetRowSpan() > 1)
         m_aRowDefs.append(OOO_STRING_SVTOOLS_RTF_CLVMGF);
@@ -901,10 +897,12 @@ void RtfAttributeOutput::TableVerticalCell(
         m_aRowDefs.append(OOO_STRING_SVTOOLS_RTF_CLVMRG);
 
     // vertical alignment
-    if (!pCellFormat->GetAttrSet().HasItem(RES_VERT_ORIENT, &pItem))
+    const SwFormatVertOrient* pVertOrientItem
+        = pCellFormat->GetAttrSet().GetItemIfSet(RES_VERT_ORIENT);
+    if (!pVertOrientItem)
         return;
 
-    switch (pItem->StaticWhichCast(RES_VERT_ORIENT).GetVertOrient())
+    switch (pVertOrientItem->GetVertOrient())
     {
         case text::VertOrientation::CENTER:
             m_aRowDefs.append(OOO_STRING_SVTOOLS_RTF_CLVERTALC);
diff --git a/sw/source/filter/ww8/rtfsdrexport.cxx 
b/sw/source/filter/ww8/rtfsdrexport.cxx
index 09804fb24f80..5f420ce0f089 100644
--- a/sw/source/filter/ww8/rtfsdrexport.cxx
+++ b/sw/source/filter/ww8/rtfsdrexport.cxx
@@ -628,7 +628,7 @@ sal_Int32 RtfSdrExport::StartShape()
                              msfilter::rtfutil::OutString(rEditObj.GetText(0),
                                                           
m_rExport.GetCurrentEncoding()));
 
-                auto pFontFamily = rItemSet.GetItem(SID_ATTR_CHAR_FONT);
+                const SvxFontItem* pFontFamily = 
rItemSet.GetItem(SID_ATTR_CHAR_FONT);
                 if (pFontFamily)
                 {
                     lcl_AppendSP(m_rAttrOutput.RunText(), "gtextFont",
diff --git a/sw/source/filter/ww8/wrtw8esh.cxx 
b/sw/source/filter/ww8/wrtw8esh.cxx
index 82392ea5106c..122910b037c6 100644
--- a/sw/source/filter/ww8/wrtw8esh.cxx
+++ b/sw/source/filter/ww8/wrtw8esh.cxx
@@ -276,12 +276,8 @@ void SwBasicEscherEx::WriteHyperlinkWithinFly( 
SvMemoryStream& rStrm, const SwFo
 }
 void SwBasicEscherEx::PreWriteHyperlinkWithinFly(const SwFrameFormat& 
rFormat,EscherPropertyContainer& rPropOpt)
 {
-    const SfxPoolItem* pItem;
     const SwAttrSet& rAttrSet = rFormat.GetAttrSet();
-    if (SfxItemState::SET != rAttrSet.GetItemState(RES_URL, true, &pItem))
-        return;
-
-    const SwFormatURL *pINetFormat = dynamic_cast<const SwFormatURL*>(pItem);
+    const SwFormatURL* pINetFormat = rAttrSet.GetItemIfSet(RES_URL);
     if (!pINetFormat || pINetFormat->GetURL().isEmpty())
         return;
 
@@ -1359,10 +1355,9 @@ void WW8Export::WriteOutliner(const OutlinerParaObject& 
rParaObj, sal_uInt8 nTyp
 
         const SfxItemSet& aSet(rEditObj.GetParaAttribs(n));
         bool bIsRTLPara = false;
-        const SfxPoolItem *pItem;
-        if(SfxItemState::SET == aSet.GetItemState(EE_PARA_WRITINGDIR, true, 
&pItem))
+        if(const SvxFrameDirectionItem* pItem = 
aSet.GetItemIfSet(EE_PARA_WRITINGDIR))
         {
-            SvxFrameDirection nDir = static_cast<const 
SvxFrameDirectionItem*>(pItem)->GetValue();
+            SvxFrameDirection nDir = pItem->GetValue();
             bIsRTLPara = SvxFrameDirection::Horizontal_RL_TB == nDir;
         }
 
@@ -1666,27 +1661,23 @@ sal_Int32 SwBasicEscherEx::WriteGrfFlyFrame(const 
SwFrameFormat& rFormat, sal_uI
 void SwBasicEscherEx::WriteGrfAttr(const SwNoTextNode& rNd, const 
SwFrameFormat& rFormat,
     EscherPropertyContainer& rPropOpt)
 {
-    const SfxPoolItem* pItem;
     GraphicDrawMode nMode = GraphicDrawMode::Standard;
     sal_Int32 nContrast = 0;
     sal_Int16 nBrightness = 0;
 
-    if (SfxItemState::SET == 
rNd.GetSwAttrSet().GetItemState(RES_GRFATR_CONTRAST,
-        true, &pItem))
+    if (const SfxInt16Item* pItem = 
rNd.GetSwAttrSet().GetItemIfSet(RES_GRFATR_CONTRAST))
     {
-        nContrast = static_cast<const SfxInt16Item*>(pItem)->GetValue();
+        nContrast = pItem->GetValue();
     }
 
-    if (SfxItemState::SET == 
rNd.GetSwAttrSet().GetItemState(RES_GRFATR_LUMINANCE,
-        true, &pItem))
+    if (const SfxInt16Item* pItem = 
rNd.GetSwAttrSet().GetItemIfSet(RES_GRFATR_LUMINANCE))
     {
-        nBrightness = static_cast<const SfxInt16Item*>(pItem)->GetValue();
+        nBrightness = pItem->GetValue();
     }
 
-    if (SfxItemState::SET == 
rNd.GetSwAttrSet().GetItemState(RES_GRFATR_DRAWMODE,
-        true, &pItem))
+    if (const SfxEnumItemInterface* pItem = 
rNd.GetSwAttrSet().GetItemIfSet(RES_GRFATR_DRAWMODE))
     {
-        nMode = static_cast<GraphicDrawMode>(static_cast<const 
SfxEnumItemInterface*>(pItem)->GetEnumValue());
+        nMode = static_cast<GraphicDrawMode>(pItem->GetEnumValue());
         if (nMode == GraphicDrawMode::Watermark)
         {
             /*
@@ -1739,24 +1730,21 @@ void SwBasicEscherEx::WriteGrfAttr(const SwNoTextNode& 
rNd, const SwFrameFormat&
     sal_Int32 nCropR = 0;
     sal_Int32 nCropT = 0;
     sal_Int32 nCropB = 0;
-    if (SfxItemState::SET == 
rNd.GetSwAttrSet().GetItemState(RES_GRFATR_CROPGRF,
-        true, &pItem))
+    if (const SwCropGrf* pCropItem = 
rNd.GetSwAttrSet().GetItemIfSet(RES_GRFATR_CROPGRF))
     {
-        const SwCropGrf& rCrop = *static_cast<const SwCropGrf*>(pItem);
-        nCropL += rCrop.GetLeft();
-        nCropR += rCrop.GetRight();
-        nCropT += rCrop.GetTop();
-        nCropB += rCrop.GetBottom();
+        nCropL += pCropItem->GetLeft();
+        nCropR += pCropItem->GetRight();
+        nCropT += pCropItem->GetTop();
+        nCropB += pCropItem->GetBottom();
     }
 
     // simulate border padding as a negative crop.
-    if (SfxItemState::SET == rFormat.GetItemState(RES_BOX, false, &pItem))
+    if (const SvxBoxItem* pBoxItem = rFormat.GetItemIfSet(RES_BOX, false))
     {
-        const SvxBoxItem& rBox = *static_cast<const SvxBoxItem*>(pItem);
-        nCropL -= rBox.GetDistance( SvxBoxItemLine::LEFT );
-        nCropR -= rBox.GetDistance( SvxBoxItemLine::RIGHT );
-        nCropT -= rBox.GetDistance( SvxBoxItemLine::TOP );
-        nCropB -= rBox.GetDistance( SvxBoxItemLine::BOTTOM );
+        nCropL -= pBoxItem->GetDistance( SvxBoxItemLine::LEFT );
+        nCropR -= pBoxItem->GetDistance( SvxBoxItemLine::RIGHT );
+        nCropT -= pBoxItem->GetDistance( SvxBoxItemLine::TOP );
+        nCropB -= pBoxItem->GetDistance( SvxBoxItemLine::BOTTOM );
     }
 
     const Size aSz( rNd.GetTwipSize() );
@@ -1890,9 +1878,8 @@ sal_Int32 SwBasicEscherEx::WriteFlyFrameAttr(const 
SwFrameFormat& rFormat,
     MSO_SPT eShapeType, EscherPropertyContainer& rPropOpt)
 {
     sal_Int32 nLineWidth=0;
-    const SfxPoolItem* pItem;
     bool bFirstLine = true;
-    if (SfxItemState::SET == rFormat.GetItemState(RES_BOX, true, &pItem))
+    if (const SvxBoxItem* pItem = rFormat.GetItemIfSet(RES_BOX))
     {
         static const o3tl::enumarray<SvxBoxItemLine, sal_uInt16> aExhperProp =
         {
@@ -1903,7 +1890,7 @@ sal_Int32 SwBasicEscherEx::WriteFlyFrameAttr(const 
SwFrameFormat& rFormat,
 
         for( SvxBoxItemLine n : o3tl::enumrange<SvxBoxItemLine>() )
         {
-            pLine = static_cast<const SvxBoxItem*>(pItem)->GetLine( n );
+            pLine = pItem->GetLine( n );
             if( nullptr != pLine )
             {
                 if( bFirstLine )
@@ -1959,10 +1946,10 @@ sal_Int32 SwBasicEscherEx::WriteFlyFrameAttr(const 
SwFrameFormat& rFormat,
                     bFirstLine = false;
                 }
                 rPropOpt.AddOpt( aExhperProp[ n ], DrawModelToEmu(
-                    static_cast<const SvxBoxItem*>(pItem)->GetDistance( n ) ));
+                    pItem->GetDistance( n ) ));
             }
             else
-                rPropOpt.AddOpt( aExhperProp[ n ], 
DrawModelToEmu(static_cast<const SvxBoxItem*>(pItem)->GetDistance( n )) );
+                rPropOpt.AddOpt( aExhperProp[ n ], 
DrawModelToEmu(pItem->GetDistance( n )) );
         }
     }
     else
@@ -1978,57 +1965,49 @@ sal_Int32 SwBasicEscherEx::WriteFlyFrameAttr(const 
SwFrameFormat& rFormat,
         rPropOpt.AddOpt( ESCHER_Prop_fNoLineDrawDash, 0x80000 );
     }
     const SwAttrSet& rAttrSet = rFormat.GetAttrSet();
-    if (SfxItemState::SET == rAttrSet.GetItemState(RES_BOX, false, &pItem))
+    if (rAttrSet.GetItemIfSet(RES_BOX, false))
     {
-        const SvxBoxItem* pBox = static_cast<const SvxBoxItem*>(pItem);
-        if( pBox )
+        if (const SvxShadowItem* pSI =rAttrSet.GetItemIfSet(RES_SHADOW))
         {
-            const SfxPoolItem* pShadItem;
-            if (SfxItemState::SET
-                == rAttrSet.GetItemState(RES_SHADOW, true, &pShadItem))
-            {
-                const SvxShadowItem* pSI = static_cast<const 
SvxShadowItem*>(pShadItem);
+            constexpr sal_uInt32 nShadowType = 131074;   // shadow type of ms 
word. need to set the default value.
 
-                constexpr sal_uInt32 nShadowType = 131074;   // shadow type of 
ms word. need to set the default value.
+            Color  nColor = pSI->GetColor();
+            sal_Int32 nOffX
+                = o3tl::convert(pSI->GetWidth(), o3tl::Length::twip, 
o3tl::Length::emu);
+            sal_Int32 nOffY
+                = o3tl::convert(pSI->GetWidth(), o3tl::Length::twip, 
o3tl::Length::emu);
 
-                Color  nColor = pSI->GetColor();
-                sal_Int32 nOffX
-                    = o3tl::convert(pSI->GetWidth(), o3tl::Length::twip, 
o3tl::Length::emu);
-                sal_Int32 nOffY
-                    = o3tl::convert(pSI->GetWidth(), o3tl::Length::twip, 
o3tl::Length::emu);
-
-                SvxShadowLocation eLocation = pSI->GetLocation();
-                if( (eLocation!=SvxShadowLocation::NONE) && 
(pSI->GetWidth()!=0) )
+            SvxShadowLocation eLocation = pSI->GetLocation();
+            if( (eLocation!=SvxShadowLocation::NONE) && (pSI->GetWidth()!=0) )
+            {
+                switch( eLocation )
                 {
-                    switch( eLocation )
+                case SvxShadowLocation::TopLeft:
                     {
-                    case SvxShadowLocation::TopLeft:
-                        {
-                            nOffX = -nOffX;
-                            nOffY = -nOffY;
-                        }
-                        break;
-                    case SvxShadowLocation::TopRight:
-                        {
-                            nOffY = -nOffY;
-                        }
-                        break;
-                    case SvxShadowLocation::BottomLeft:
-                        {
-                            nOffX = -nOffX;
-                        }
-                        break;
-                    case SvxShadowLocation::BottomRight:
-                        break;
-                    default:
-                        break;
+                        nOffX = -nOffX;
+                        nOffY = -nOffY;
                     }
-
-                    rPropOpt.AddOpt( DFF_Prop_shadowColor,      
wwUtility::RGBToBGR(nColor));
-                    rPropOpt.AddOpt( DFF_Prop_shadowOffsetX,    nOffX );
-                    rPropOpt.AddOpt( DFF_Prop_shadowOffsetY,    nOffY );
-                    rPropOpt.AddOpt( DFF_Prop_fshadowObscured,  nShadowType );
+                    break;
+                case SvxShadowLocation::TopRight:
+                    {
+                        nOffY = -nOffY;
+                    }
+                    break;
+                case SvxShadowLocation::BottomLeft:
+                    {
+                        nOffX = -nOffX;
+                    }
+                    break;
+                case SvxShadowLocation::BottomRight:
+                    break;
+                default:
+                    break;
                 }
+
+                rPropOpt.AddOpt( DFF_Prop_shadowColor,      
wwUtility::RGBToBGR(nColor));
+                rPropOpt.AddOpt( DFF_Prop_shadowOffsetX,    nOffX );
+                rPropOpt.AddOpt( DFF_Prop_shadowOffsetY,    nOffY );
+                rPropOpt.AddOpt( DFF_Prop_fshadowObscured,  nShadowType );
             }
         }
     }
@@ -2085,13 +2064,12 @@ sal_Int32 SwEscherEx::WriteFlyFrameAttr(const 
SwFrameFormat& rFormat, MSO_SPT eS
      way, perhaps we should actually draw in this space into the graphic we
      are exporting!
      */
-    const SfxPoolItem* pItem;
-    if (SfxItemState::SET == rFormat.GetItemState(RES_LR_SPACE, true, &pItem))
+    if (const SvxLRSpaceItem* pItem = rFormat.GetItemIfSet(RES_LR_SPACE))
     {
         rPropOpt.AddOpt( ESCHER_Prop_dxWrapDistLeft,
-                DrawModelToEmu( static_cast<const 
SvxLRSpaceItem*>(pItem)->GetLeft() ) );
+                DrawModelToEmu( pItem->GetLeft() ) );
         rPropOpt.AddOpt( ESCHER_Prop_dxWrapDistRight,
-                DrawModelToEmu( static_cast<const 
SvxLRSpaceItem*>(pItem)->GetRight() ) );
+                DrawModelToEmu( pItem->GetRight() ) );
     }
     else
     {
@@ -2099,12 +2077,12 @@ sal_Int32 SwEscherEx::WriteFlyFrameAttr(const 
SwFrameFormat& rFormat, MSO_SPT eS
         rPropOpt.AddOpt( ESCHER_Prop_dxWrapDistRight, 0 );
     }
 
-    if (SfxItemState::SET == rFormat.GetItemState(RES_UL_SPACE, true, &pItem))
+    if (const SvxULSpaceItem* pItem = rFormat.GetItemIfSet(RES_UL_SPACE))
     {
         rPropOpt.AddOpt( ESCHER_Prop_dyWrapDistTop,
-                DrawModelToEmu( static_cast<const 
SvxULSpaceItem*>(pItem)->GetUpper() ) );
+                DrawModelToEmu( pItem->GetUpper() ) );
         rPropOpt.AddOpt( ESCHER_Prop_dyWrapDistBottom,
-                DrawModelToEmu( static_cast<const 
SvxULSpaceItem*>(pItem)->GetLower() ) );
+                DrawModelToEmu( pItem->GetLower() ) );
     }
 
     if (rFormat.GetSurround().IsContour())
@@ -2300,12 +2278,8 @@ SwEscherEx::SwEscherEx(SvStream* pStrm, WW8Export& 
rWW8Wrt)
 
             EscherPropertyContainer aPropOpt;
             const SwFrameFormat &rFormat = 
rWrt.m_rDoc.GetPageDesc(0).GetMaster();
-            const SfxPoolItem* pItem = nullptr;
-            SfxItemState eState = rFormat.GetItemState(RES_BACKGROUND, true,
-                &pItem);
-            if (SfxItemState::SET == eState && pItem)
+            if (const SvxBrushItem* pBrush = 
rFormat.GetItemIfSet(RES_BACKGROUND))
             {
-                const SvxBrushItem* pBrush = static_cast<const 
SvxBrushItem*>(pItem);
                 WriteBrushAttr(*pBrush, aPropOpt);
 
                 SvxGraphicPosition ePos = pBrush->GetGraphicPos();
diff --git a/sw/source/filter/ww8/wrtw8nds.cxx 
b/sw/source/filter/ww8/wrtw8nds.cxx
index 658cadabba08..772d85008ded 100644
--- a/sw/source/filter/ww8/wrtw8nds.cxx
+++ b/sw/source/filter/ww8/wrtw8nds.cxx
@@ -571,8 +571,7 @@ void SwWW8AttrIter::handleToggleProperty(SfxItemSet& 
rExportSet, const SwFormatC
     {
         if (const SwCharFormat* pCharFormat = pCharFormatItem->GetCharFormat())
         {
-            const SfxPoolItem* pItem = nullptr;
-            if (pCharFormat->GetAttrSet().HasItem(nWhich, &pItem))
+            if (const SfxPoolItem* pItem = 
pCharFormat->GetAttrSet().GetItem(nWhich))
             {
                 hasPropertyInCharStyle = (*pItem == *pValue);
             }
@@ -587,8 +586,7 @@ void SwWW8AttrIter::handleToggleProperty(SfxItemSet& 
rExportSet, const SwFormatC
         const SwFormat* pFormat = m_rExport.m_pStyles->GetSwFormat(nStyle);
         if (pFormat)
         {
-            const SfxPoolItem* pItem = nullptr;
-            if (pFormat->GetAttrSet().HasItem(nWhich, &pItem))
+            if (const SfxPoolItem* pItem = 
pFormat->GetAttrSet().GetItem(nWhich))
             {
                 hasPropertyInParaStyle = (*pItem == *pValue);
             }
@@ -1698,13 +1696,11 @@ const SvxBrushItem* WW8Export::GetCurrentPageBgBrush() 
const
                     ? m_pCurrentPageDesc->GetMaster()
                     : m_rDoc.GetPageDesc(0).GetMaster();
 
-    const SfxPoolItem* pItem = nullptr;
     //If not set, or "no fill", get real bg
-    SfxItemState eState = rFormat.GetItemState(RES_BACKGROUND, true, &pItem);
+    const SvxBrushItem* pRet = rFormat.GetItemIfSet(RES_BACKGROUND);
 
-    const SvxBrushItem* pRet = static_cast<const SvxBrushItem*>(pItem);
-    if (SfxItemState::SET != eState || !pRet || (!pRet->GetGraphic() &&
-        pRet->GetColor() == COL_TRANSPARENT))
+    if (!pRet ||
+        (!pRet->GetGraphic() && pRet->GetColor() == COL_TRANSPARENT))
     {
         pRet = &m_rDoc.GetAttrPool().GetDefaultItem(RES_BACKGROUND);
     }
@@ -1719,11 +1715,8 @@ std::shared_ptr<SvxBrushItem> 
WW8Export::TrueFrameBgBrush(const SwFrameFormat &r
     while (pFlyFormat)
     {
         //If not set, or "no fill", get real bg
-        const SfxPoolItem* pItem = nullptr;
-        SfxItemState eState =
-            pFlyFormat->GetItemState(RES_BACKGROUND, true, &pItem);
-        pRet = static_cast<const SvxBrushItem*>(pItem);
-        if (SfxItemState::SET != eState || !pRet || (!pRet->GetGraphic() &&
+        pRet = pFlyFormat->GetItemIfSet(RES_BACKGROUND);
+        if (!pRet || (!pRet->GetGraphic() &&
             pRet->GetColor() == COL_TRANSPARENT))
         {
             pRet = nullptr;
@@ -2856,16 +2849,14 @@ void MSWordExportBase::OutputTextNode( SwTextNode& 
rNode )
 
             if( (ND_HAS_PREV_LAYNODE|ND_HAS_NEXT_LAYNODE ) != nPrvNxtNd )
             {
-                const SfxPoolItem* pItem;
-                if( SfxItemState::SET == rNode.GetSwAttrSet().GetItemState(
-                        RES_UL_SPACE, true, &pItem ) &&
-                    ( ( !( ND_HAS_PREV_LAYNODE & nPrvNxtNd ) &&
-                       static_cast<const SvxULSpaceItem*>(pItem)->GetUpper()) 
||
-                      ( !( ND_HAS_NEXT_LAYNODE & nPrvNxtNd ) &&
-                       static_cast<const SvxULSpaceItem*>(pItem)->GetLower()) 
))
+                const SvxULSpaceItem* pSpaceItem = 
rNode.GetSwAttrSet().GetItemIfSet(
+                        RES_UL_SPACE );
+                if( pSpaceItem &&
+                    ( ( !( ND_HAS_PREV_LAYNODE & nPrvNxtNd ) && 
pSpaceItem->GetUpper()) ||
+                      ( !( ND_HAS_NEXT_LAYNODE & nPrvNxtNd ) && 
pSpaceItem->GetLower()) ))
                 {
                     oTmpSet.emplace( rNode.GetSwAttrSet() );
-                    SvxULSpaceItem aUL( *static_cast<const 
SvxULSpaceItem*>(pItem) );
+                    SvxULSpaceItem aUL( *pSpaceItem );
                     // #i25901#- consider compatibility option
                     if 
(!m_rDoc.getIDocumentSettingAccess().get(DocumentSettingId::PARA_SPACE_MAX_AT_PAGES))
                     {
@@ -3005,12 +2996,11 @@ void MSWordExportBase::OutputTextNode( SwTextNode& 
rNode )
                     oTmpSet.emplace(rNode.GetSwAttrSet());
 
                 // create new LRSpace item, based on the current (if present)
-                const SfxPoolItem* pPoolItem = nullptr;
-                oTmpSet->GetItemState(RES_LR_SPACE, true, &pPoolItem);
+                const SfxPoolItem* pLrSpaceItem = 
oTmpSet->GetItemIfSet(RES_LR_SPACE);
                 SvxLRSpaceItem aLRSpace(
-                    ( pPoolItem == nullptr )
+                    ( pLrSpaceItem == nullptr )
                         ? SvxLRSpaceItem(0, 0, 0, 0, RES_LR_SPACE)
-                        : *static_cast<const SvxLRSpaceItem*>( pPoolItem ) );
+                        : *static_cast<const SvxLRSpaceItem*>( pLrSpaceItem ) 
);
 
                 // new left margin = old left + label space
                 const SwNumRule* pRule = rNode.GetNumRule();
@@ -3213,21 +3203,20 @@ void WW8AttributeOutput::EmptyParagraph()
 bool MSWordExportBase::NoPageBreakSection( const SfxItemSet* pSet )
 {
     bool bRet = false;
-    const SfxPoolItem* pI;
     if( pSet)
     {
         bool bNoPageBreak = false;
-        if ( SfxItemState::SET != pSet->GetItemState(RES_PAGEDESC, true, &pI)
-            || nullptr == static_cast<const 
SwFormatPageDesc*>(pI)->GetPageDesc() )
+        const SwFormatPageDesc* pDescItem = pSet->GetItemIfSet(RES_PAGEDESC);
+        if ( !pDescItem || nullptr == pDescItem->GetPageDesc() )
         {
             bNoPageBreak = true;
         }
 
         if (bNoPageBreak)
         {
-            if (SfxItemState::SET == pSet->GetItemState(RES_BREAK, true, &pI))
+            if (const SvxFormatBreakItem* pBreakItem = 
pSet->GetItemIfSet(RES_BREAK))
             {
-                SvxBreak eBreak = static_cast<const 
SvxFormatBreakItem*>(pI)->GetBreak();
+                SvxBreak eBreak = pBreakItem->GetBreak();
                 switch (eBreak)
                 {
                     case SvxBreak::PageBefore:
diff --git a/sw/source/filter/ww8/wrtw8sty.cxx 
b/sw/source/filter/ww8/wrtw8sty.cxx
index d613c00af5a2..04646415b47e 100644
--- a/sw/source/filter/ww8/wrtw8sty.cxx
+++ b/sw/source/filter/ww8/wrtw8sty.cxx
@@ -998,7 +998,6 @@ MSWordSections::MSWordSections( MSWordExportBase& rExport )
     const SwSectionFormat *pFormat = nullptr;
     rExport.m_pCurrentPageDesc = &rExport.m_rDoc.GetPageDesc( 0 );
 
-    const SfxPoolItem* pI;
     const SwNode* pNd = rExport.m_pCurPam->GetContentNode();
     const SfxItemSet* pSet = pNd ? &static_cast<const 
SwContentNode*>(pNd)->GetSwAttrSet() : nullptr;
 
@@ -1035,11 +1034,12 @@ MSWordSections::MSWordSections( MSWordExportBase& 
rExport )
             SectionType::ToxContent == pSectNd->GetSection().GetType()  );
 
     // Try to get page descriptor of the first node
+    const SwFormatPageDesc* pDescItem;
     if ( pSet &&
-         SfxItemState::SET == pSet->GetItemState( RES_PAGEDESC, true, &pI ) &&
-         static_cast<const SwFormatPageDesc*>(pI)->GetPageDesc() )
+         (pDescItem = pSet->GetItemIfSet( RES_PAGEDESC )) &&
+         pDescItem->GetPageDesc() )
     {
-        AppendSection( *static_cast<const SwFormatPageDesc*>(pI), *pNd, 
pFormat, nRstLnNum );
+        AppendSection( *pDescItem, *pNd, pFormat, nRstLnNum );
     }
     else
         AppendSection( rExport.m_pCurrentPageDesc, pFormat, nRstLnNum, 
/*bIsFirstParagraph=*/true );
@@ -1213,20 +1213,16 @@ void WW8_WrPlcSepx::WriteFootnoteEndText( WW8Export& 
rWrt, sal_uLong nCpStt )
 void MSWordSections::SetHeaderFlag( sal_uInt8& rHeadFootFlags, const SwFormat& 
rFormat,
     sal_uInt8 nFlag )
 {
-    const SfxPoolItem* pItem;
-    if( SfxItemState::SET == rFormat.GetItemState(RES_HEADER, true, &pItem)
-        && static_cast<const SwFormatHeader*>(pItem)->IsActive() &&
-        static_cast<const SwFormatHeader*>(pItem)->GetHeaderFormat() )
+    const SwFormatHeader* pItem = rFormat.GetItemIfSet(RES_HEADER);
+    if( pItem && pItem->IsActive() && pItem->GetHeaderFormat() )
         rHeadFootFlags |= nFlag;
 }
 
 void MSWordSections::SetFooterFlag( sal_uInt8& rHeadFootFlags, const SwFormat& 
rFormat,
     sal_uInt8 nFlag )
 {
-    const SfxPoolItem* pItem;
-    if( SfxItemState::SET == rFormat.GetItemState(RES_FOOTER, true, &pItem)
-        && static_cast<const SwFormatFooter*>(pItem)->IsActive() &&
-        static_cast<const SwFormatFooter*>(pItem)->GetFooterFormat() )
+    const SwFormatFooter* pItem = rFormat.GetItemIfSet(RES_FOOTER);
+    if( pItem && pItem->IsActive() && pItem->GetFooterFormat() )
         rHeadFootFlags |= nFlag;
 }
 
@@ -1329,12 +1325,12 @@ void MSWordSections::CheckForFacinPg( const WW8Export& 
rWrt ) const
 
 bool MSWordSections::HasBorderItem( const SwFormat& rFormat )
 {
-    const SfxPoolItem* pItem;
-    return SfxItemState::SET == rFormat.GetItemState(RES_BOX, true, &pItem) &&
-            (   static_cast<const SvxBoxItem*>(pItem)->GetTop() ||
-                static_cast<const SvxBoxItem*>(pItem)->GetBottom()  ||
-                static_cast<const SvxBoxItem*>(pItem)->GetLeft()  ||
-                static_cast<const SvxBoxItem*>(pItem)->GetRight() );
+    const SvxBoxItem* pItem = rFormat.GetItemIfSet(RES_BOX);
+    return pItem &&
+            (   pItem->GetTop() ||
+                pItem->GetBottom()  ||
+                pItem->GetLeft()  ||
+                pItem->GetRight() );
 }
 
 void WW8AttributeOutput::StartSection()
diff --git a/sw/source/filter/ww8/wrtww8.cxx b/sw/source/filter/ww8/wrtww8.cxx
index 63b27a2af334..0dafd6a2a705 100644
--- a/sw/source/filter/ww8/wrtww8.cxx
+++ b/sw/source/filter/ww8/wrtww8.cxx
@@ -2078,10 +2078,8 @@ static sal_uInt16 lcl_TCFlags(SwDoc &rDoc, const 
SwTableBox * pBox, sal_Int32 nR
                 SfxItemSetFixed<RES_CHRATR_ROTATE, RES_CHRATR_ROTATE> 
aCoreSet(rDoc.GetAttrPool());
                 static_cast<const SwTextNode*>(pCNd)->GetParaAttr(aCoreSet,
                     0, static_cast<const 
SwTextNode*>(pCNd)->GetText().getLength());
-                const SfxPoolItem * pRotItem;
-                if ( SfxItemState::SET == 
aCoreSet.GetItemState(RES_CHRATR_ROTATE, true, &pRotItem))
+                if ( const SvxCharRotateItem * pRotate = 
aCoreSet.GetItemIfSet(RES_CHRATR_ROTATE))
                 {
-                    const SvxCharRotateItem * pRotate = static_cast<const 
SvxCharRotateItem*>(pRotItem);
                     if(pRotate && pRotate->GetValue() == 900_deg10)
                     {
                         nFlags = nFlags | 0x0004 | 0x0008;
@@ -2844,9 +2842,10 @@ void MSWordExportBase::WriteText()
                     SwTextNode *pTempNext = aIdx.GetNode().GetTextNode();
                     if ( pTempNext )
                     {
-                        const SfxPoolItem * pTempItem = nullptr;
-                        if (pTempNext->GetpSwAttrSet() && SfxItemState::SET == 
pTempNext->GetpSwAttrSet()->GetItemState(RES_PAGEDESC, false, &pTempItem)
-                            && pTempItem && static_cast<const 
SwFormatPageDesc*>(pTempItem)->GetRegisteredIn())
+                        const SwFormatPageDesc * pTempItem = nullptr;
+                        if (pTempNext->GetpSwAttrSet()
+                            && (pTempItem = 
pTempNext->GetpSwAttrSet()->GetItemIfSet(RES_PAGEDESC, false))
+                            && pTempItem->GetRegisteredIn())
                         {
                             //Next node has a new page style which means this 
node is a section end. Do not insert another page/section break here
                             bNeedExportBreakHere = false;
@@ -3541,13 +3540,13 @@ ErrCode WW8Export::ExportDocument_Impl()
     pDop->fRMPrint = pDop->fRMView;
 
     // set AutoHyphenation flag if found in default para style
-    const SfxPoolItem* pItem;
+    const SvxHyphenZoneItem* pItem;
     SwTextFormatColl* pStdTextFormatColl =
         
m_rDoc.getIDocumentStylePoolAccess().GetTextCollFromPool(RES_POOLCOLL_STANDARD, 
false);
-    if (pStdTextFormatColl && SfxItemState::SET == 
pStdTextFormatColl->GetItemState(
-        RES_PARATR_HYPHENZONE, false, &pItem))
+    if (pStdTextFormatColl && (pItem = pStdTextFormatColl->GetItemIfSet(
+        RES_PARATR_HYPHENZONE, false)))
     {
-        pDop->fAutoHyphen = static_cast<const 
SvxHyphenZoneItem*>(pItem)->IsHyphen();
+        pDop->fAutoHyphen = pItem->IsHyphen();
     }
 
     StoreDoc1();
diff --git a/sw/source/filter/ww8/wrtww8gr.cxx 
b/sw/source/filter/ww8/wrtww8gr.cxx
index 2b72b52edfab..d038be9416d8 100644
--- a/sw/source/filter/ww8/wrtww8gr.cxx
+++ b/sw/source/filter/ww8/wrtww8gr.cxx
@@ -481,17 +481,16 @@ void SwWW8WrGrf::WritePICFHeader(SvStream& rStrm, const 
ww8::Frame &rFly,
     sal_Int16 nCropL = 0, nCropR = 0, nCropT = 0, nCropB = 0;
 
             // write Crop-Attribute content in Header ( if available )
-    const SfxPoolItem* pItem;
-    if (pAttrSet && (SfxItemState::SET
-        == pAttrSet->GetItemState(RES_GRFATR_CROPGRF, false, &pItem)))
+    const SwCropGrf* pCropItem;
+    if (pAttrSet && (pCropItem
+        = pAttrSet->GetItemIfSet(RES_GRFATR_CROPGRF, false)))
     {
-        const SwCropGrf& rCr = *static_cast<const SwCropGrf*>(pItem);
-        nCropL = static_cast<sal_Int16>(rCr.GetLeft());
-        nCropR = static_cast<sal_Int16>(rCr.GetRight());
-        nCropT = static_cast<sal_Int16>(rCr.GetTop());
-        nCropB = static_cast<sal_Int16>(rCr.GetBottom());
-        nXSizeAdd = nXSizeAdd - static_cast<sal_Int16>( rCr.GetLeft() + 
rCr.GetRight() );
-        nYSizeAdd = nYSizeAdd - static_cast<sal_Int16>( rCr.GetTop() + 
rCr.GetBottom() );
+        nCropL = static_cast<sal_Int16>(pCropItem->GetLeft());
+        nCropR = static_cast<sal_Int16>(pCropItem->GetRight());
+        nCropT = static_cast<sal_Int16>(pCropItem->GetTop());
+        nCropB = static_cast<sal_Int16>(pCropItem->GetBottom());
+        nXSizeAdd = nXSizeAdd - static_cast<sal_Int16>( pCropItem->GetLeft() + 
pCropItem->GetRight() );
+        nYSizeAdd = nYSizeAdd - static_cast<sal_Int16>( pCropItem->GetTop() + 
pCropItem->GetBottom() );
     }
 
     Size aGrTwipSz(rFly.GetSize());
@@ -502,58 +501,54 @@ void SwWW8WrGrf::WritePICFHeader(SvStream& rStrm, const 
ww8::Frame &rFly,
     sal_uInt8* pArr = aArr + 0x2E;  // Do borders first
 
     const SwAttrSet& rAttrSet = rFly.GetFrameFormat().GetAttrSet();
-    if (SfxItemState::SET == rAttrSet.GetItemState(RES_BOX, false, &pItem))
+    if (const SvxBoxItem* pBox = rAttrSet.GetItemIfSet(RES_BOX, false))
     {
-        const SvxBoxItem* pBox = static_cast<const SvxBoxItem*>(pItem);
-        if( pBox )
+        bool bShadow = false;               // Shadow ?
+        if (const SvxShadowItem* pSI = 
rAttrSet.GetItem<SvxShadowItem>(RES_SHADOW))
         {
-            bool bShadow = false;               // Shadow ?
-            if (const SvxShadowItem* pSI = 
rAttrSet.GetItem<SvxShadowItem>(RES_SHADOW))
+            bShadow = (pSI->GetLocation() != SvxShadowLocation::NONE) &&
+                (pSI->GetWidth() != 0);
+        }
+
+        static const SvxBoxItemLine aLnArr[4] = { SvxBoxItemLine::TOP, 
SvxBoxItemLine::LEFT,
+                            SvxBoxItemLine::BOTTOM, SvxBoxItemLine::RIGHT };
+        for(const SvxBoxItemLine & i : aLnArr)
+        {
+            const ::editeng::SvxBorderLine* pLn = pBox->GetLine( i );
+            WW8_BRC aBrc;
+            if (pLn)
             {
-                bShadow = (pSI->GetLocation() != SvxShadowLocation::NONE) &&
-                    (pSI->GetWidth() != 0);
+                WW8_BRCVer9 aBrc90 = WW8Export::TranslateBorderLine( *pLn,
+                    pBox->GetDistance( i ), bShadow );
+                sal_uInt8 ico = 
msfilter::util::TransColToIco(msfilter::util::BGRToRGB(
+                    aBrc90.cv()));
+                aBrc = WW8_BRC(aBrc90.dptLineWidth(), aBrc90.brcType(), ico,
+                    aBrc90.dptSpace(), aBrc90.fShadow(), aBrc90.fFrame());
             }
 
-            static const SvxBoxItemLine aLnArr[4] = { SvxBoxItemLine::TOP, 
SvxBoxItemLine::LEFT,
-                                SvxBoxItemLine::BOTTOM, SvxBoxItemLine::RIGHT 
};
-            for(const SvxBoxItemLine & i : aLnArr)
+            // use importer logic to determine how large the exported
+            // border will really be in word and adjust accordingly
+            short nSpacing;
+            short nThick = aBrc.DetermineBorderProperties(&nSpacing);
+            switch (i)
             {
-                const ::editeng::SvxBorderLine* pLn = pBox->GetLine( i );
-                WW8_BRC aBrc;
-                if (pLn)
-                {
-                    WW8_BRCVer9 aBrc90 = WW8Export::TranslateBorderLine( *pLn,
-                        pBox->GetDistance( i ), bShadow );
-                    sal_uInt8 ico = 
msfilter::util::TransColToIco(msfilter::util::BGRToRGB(
-                        aBrc90.cv()));
-                    aBrc = WW8_BRC(aBrc90.dptLineWidth(), aBrc90.brcType(), 
ico,
-                        aBrc90.dptSpace(), aBrc90.fShadow(), aBrc90.fFrame());
-                }
-
-                // use importer logic to determine how large the exported
-                // border will really be in word and adjust accordingly
-                short nSpacing;
-                short nThick = aBrc.DetermineBorderProperties(&nSpacing);
-                switch (i)
-                {
-                    case SvxBoxItemLine::TOP:
-                    case SvxBoxItemLine::BOTTOM:
-                        nHeight -= bShadow ? nThick*2 : nThick;
-                        nHeight = nHeight - nSpacing;
-                        break;
-                    case SvxBoxItemLine::LEFT:
-                    case SvxBoxItemLine::RIGHT:
-                    default:
-                        nWidth -= bShadow ? nThick*2 : nThick;
-                        nWidth = nWidth - nSpacing;
-                        break;
-                }
-                memcpy( pArr, &aBrc.aBits1, 2);
-                pArr+=2;
-
-                memcpy( pArr, &aBrc.aBits2, 2);
-                pArr+=2;
+                case SvxBoxItemLine::TOP:
+                case SvxBoxItemLine::BOTTOM:
+                    nHeight -= bShadow ? nThick*2 : nThick;
+                    nHeight = nHeight - nSpacing;
+                    break;
+                case SvxBoxItemLine::LEFT:
+                case SvxBoxItemLine::RIGHT:
+                default:
+                    nWidth -= bShadow ? nThick*2 : nThick;
+                    nWidth = nWidth - nSpacing;
+                    break;
             }
+            memcpy( pArr, &aBrc.aBits1, 2);
+            pArr+=2;
+
+            memcpy( pArr, &aBrc.aBits2, 2);
+            pArr+=2;
         }
     }
 

Reply via email to