sw/source/core/attr/format.cxx                |    4 ++--
 sw/source/core/crsr/crstrvl.cxx               |    4 ++--
 sw/source/core/doc/docfmt.cxx                 |    2 +-
 sw/source/core/text/atrstck.cxx               |    8 ++++----
 sw/source/core/tox/ToxTabStopTokenHandler.cxx |    2 +-
 sw/source/core/txtnode/ndtxt.cxx              |    8 +++-----
 sw/source/filter/ww8/docxattributeoutput.cxx  |    7 +++----
 sw/source/filter/ww8/rtfattributeoutput.cxx   |    4 ++--
 sw/source/filter/ww8/wrtww8.hxx               |   14 +++++++++++++-
 sw/source/filter/ww8/ww8atr.cxx               |   15 +++++++--------
 sw/source/uibase/utlui/uitool.cxx             |   11 +++++------
 11 files changed, 43 insertions(+), 36 deletions(-)

New commits:
commit 9ca53dfa9b6d1ccdf632bec23b45bb588021f1e9
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Fri Mar 25 11:21:03 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Fri Mar 25 11:21:10 2022 +0100

    simplify some TypedWhichId code
    
    Change-Id: I7c908bac2217fb1e1a10dbd1fe8fe4d3cb253eff
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132098
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sw/source/core/attr/format.cxx b/sw/source/core/attr/format.cxx
index 2ce4c9aa7dc6..bbb1cddd1576 100644
--- a/sw/source/core/attr/format.cxx
+++ b/sw/source/core/attr/format.cxx
@@ -440,10 +440,10 @@ SfxItemState 
SwFormat::GetBackgroundState(std::unique_ptr<SvxBrushItem>& rItem)
         return SfxItemState::DEFAULT;
     }
 
-    const SfxPoolItem* pItem = nullptr;
+    const SvxBrushItem* pItem = nullptr;
     SfxItemState eRet = m_aSet.GetItemState(RES_BACKGROUND, true, &pItem);
     if (pItem)
-        rItem.reset(&pItem->Clone()->StaticWhichCast(RES_BACKGROUND));
+        rItem.reset(pItem->Clone());
     return eRet;
 }
 
diff --git a/sw/source/core/crsr/crstrvl.cxx b/sw/source/core/crsr/crstrvl.cxx
index 7934ad3bc5da..f1a0d4e742ac 100644
--- a/sw/source/core/crsr/crstrvl.cxx
+++ b/sw/source/core/crsr/crstrvl.cxx
@@ -2216,12 +2216,12 @@ bool SwCursorShell::SetShadowCursorPos( const Point& 
rPt, SwFillMode eFillMode )
                     SfxItemSetFixed<
                             RES_PARATR_ADJUST, RES_PARATR_ADJUST,
                             RES_LR_SPACE, RES_LR_SPACE>  aSet( 
GetDoc()->GetAttrPool() );
-                    SvxLRSpaceItem 
aLR(pCNd->GetAttr(RES_LR_SPACE).StaticWhichCast(RES_LR_SPACE));
+                    SvxLRSpaceItem aLR(pCNd->GetAttr(RES_LR_SPACE));
                     aLR.SetTextLeft( aFPos.nTabCnt );
                     aLR.SetTextFirstLineOffset( 0 );
                     aSet.Put( aLR );
 
-                    const SvxAdjustItem& rAdj = 
pCNd->GetAttr(RES_PARATR_ADJUST).StaticWhichCast(RES_PARATR_ADJUST);
+                    const SvxAdjustItem& rAdj = 
pCNd->GetAttr(RES_PARATR_ADJUST);
                     if( SvxAdjust::Left != rAdj.GetAdjust() )
                         aSet.Put( SvxAdjustItem( SvxAdjust::Left, 
RES_PARATR_ADJUST ) );
 
diff --git a/sw/source/core/doc/docfmt.cxx b/sw/source/core/doc/docfmt.cxx
index 257e5707cff4..bbdd0b1ea6fb 100644
--- a/sw/source/core/doc/docfmt.cxx
+++ b/sw/source/core/doc/docfmt.cxx
@@ -1658,7 +1658,7 @@ void SwDoc::MoveLeftMargin(const SwPaM& rPam, bool 
bRight, bool bModulus,
         if( pTNd )
         {
             pTNd = sw::GetParaPropsNode(*pLayout, aIdx);
-            SvxLRSpaceItem 
aLS(pTNd->SwContentNode::GetAttr(RES_LR_SPACE).StaticWhichCast(RES_LR_SPACE));
+            SvxLRSpaceItem aLS(pTNd->SwContentNode::GetAttr(RES_LR_SPACE));
 
             // #i93873# See also lcl_MergeListLevelIndentAsLRSpaceItem in 
thints.cxx
             if ( pTNd->AreListLevelIndentsApplicable() )
diff --git a/sw/source/core/text/atrstck.cxx b/sw/source/core/text/atrstck.cxx
index 8c64b1dd5f45..f5cb36cb03f6 100644
--- a/sw/source/core/text/atrstck.cxx
+++ b/sw/source/core/text/atrstck.cxx
@@ -526,7 +526,7 @@ void SwAttrHandler::ActivateTop( SwFont& rFnt, const 
sal_uInt16 nAttr )
 
         if ( pTwoLineAttr )
         {
-             const auto& rTwoLineItem = CharFormat::GetItem( *pTwoLineAttr, 
RES_CHRATR_TWO_LINES )->StaticWhichCast(RES_CHRATR_TWO_LINES);
+             const auto& rTwoLineItem = *CharFormat::GetItem( *pTwoLineAttr, 
RES_CHRATR_TWO_LINES );
              bTwoLineAct = rTwoLineItem.GetValue();
         }
         else
@@ -541,7 +541,7 @@ void SwAttrHandler::ActivateTop( SwFont& rFnt, const 
sal_uInt16 nAttr )
 
         if ( pRotateAttr )
         {
-            const auto& rRotateItem = CharFormat::GetItem( *pRotateAttr, 
RES_CHRATR_ROTATE )->StaticWhichCast(RES_CHRATR_ROTATE);
+            const auto& rRotateItem = *CharFormat::GetItem( *pRotateAttr, 
RES_CHRATR_ROTATE );
             rFnt.SetVertical( rRotateItem.GetValue(), m_bVertLayout );
         }
         else
@@ -746,7 +746,7 @@ void SwAttrHandler::FontChg(const SfxPoolItem& rItem, 
SwFont& rFnt, bool bPush )
 
             if ( pTwoLineAttr )
             {
-                const auto& rTwoLineItem = CharFormat::GetItem( *pTwoLineAttr, 
RES_CHRATR_TWO_LINES )->StaticWhichCast(RES_CHRATR_TWO_LINES);
+                const auto& rTwoLineItem = *CharFormat::GetItem( 
*pTwoLineAttr, RES_CHRATR_TWO_LINES );
                 bTwoLineAct = rTwoLineItem.GetValue();
             }
             else
@@ -781,7 +781,7 @@ void SwAttrHandler::FontChg(const SfxPoolItem& rItem, 
SwFont& rFnt, bool bPush )
 
             if ( pRotateAttr )
             {
-                const auto& rRotateItem = CharFormat::GetItem( *pRotateAttr, 
RES_CHRATR_ROTATE )->StaticWhichCast(RES_CHRATR_ROTATE);
+                const auto& rRotateItem = *CharFormat::GetItem( *pRotateAttr, 
RES_CHRATR_ROTATE );
                 rFnt.SetVertical( rRotateItem.GetValue(), m_bVertLayout );
             }
             else
diff --git a/sw/source/core/tox/ToxTabStopTokenHandler.cxx 
b/sw/source/core/tox/ToxTabStopTokenHandler.cxx
index d816e2bc47d3..a89e9ad276eb 100644
--- a/sw/source/core/tox/ToxTabStopTokenHandler.cxx
+++ b/sw/source/core/tox/ToxTabStopTokenHandler.cxx
@@ -50,7 +50,7 @@ DefaultToxTabStopTokenHandler::HandleTabStopToken(
 
     // check whether a tab adjustment has been specified.
     if (SvxTabAdjust::End > aToken.eTabAlign) {
-        const SvxLRSpaceItem& rLR = 
targetNode.SwContentNode::GetAttr(RES_LR_SPACE).StaticWhichCast(RES_LR_SPACE);
+        const SvxLRSpaceItem& rLR = 
targetNode.SwContentNode::GetAttr(RES_LR_SPACE);
 
         tools::Long nTabPosition = aToken.nTabStopPosition;
         if (!mTabPositionIsRelativeToParagraphIndent && rLR.GetTextLeft()) {
diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx
index 9b575ad4b821..074bd82f5dc7 100644
--- a/sw/source/core/txtnode/ndtxt.cxx
+++ b/sw/source/core/txtnode/ndtxt.cxx
@@ -4000,7 +4000,7 @@ void SwTextNode::UpdateOutlineState()
 
 int SwTextNode::GetAttrOutlineLevel() const
 {
-    return 
GetAttr(RES_PARATR_OUTLINELEVEL).StaticWhichCast(RES_PARATR_OUTLINELEVEL).GetValue();
+    return GetAttr(RES_PARATR_OUTLINELEVEL).GetValue();
 }
 
 void SwTextNode::SetAttrOutlineLevel(int nLevel)
@@ -4103,8 +4103,7 @@ void SwTextNode::SetListRestart( bool bRestart )
 
 bool SwTextNode::IsListRestart() const
 {
-    const SfxBoolItem& aIsRestartItem =
-        GetAttr( RES_PARATR_LIST_ISRESTART 
).StaticWhichCast(RES_PARATR_LIST_ISRESTART);
+    const SfxBoolItem& aIsRestartItem = GetAttr( RES_PARATR_LIST_ISRESTART );
 
     return aIsRestartItem.GetValue();
 }
@@ -4218,8 +4217,7 @@ void SwTextNode::SetCountedInList( bool bCounted )
 
 bool SwTextNode::IsCountedInList() const
 {
-    const SfxBoolItem& aIsCountedInListItem =
-        GetAttr( RES_PARATR_LIST_ISCOUNTED 
).StaticWhichCast(RES_PARATR_LIST_ISCOUNTED);
+    const SfxBoolItem& aIsCountedInListItem = GetAttr( 
RES_PARATR_LIST_ISCOUNTED );
 
     return aIsCountedInListItem.GetValue();
 }
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx 
b/sw/source/filter/ww8/docxattributeoutput.cxx
index 98a3767cd865..1eda7bc94f8b 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -8410,9 +8410,9 @@ void DocxAttributeOutput::CharBorder(
         pInherited = 
GetExport().m_pCurrentStyle->DerivedFrom()->GetAttrSet().GetItem<SvxBoxItem>(RES_CHRATR_BOX);
     else if ( m_rExport.m_pChpIter ) // incredibly undocumented, but this is 
the character-style info, right?
     {
-        if (const SfxPoolItem* pPoolItem = 
GetExport().m_pChpIter->HasTextItem(RES_CHRATR_BOX))
+        if (const SvxBoxItem* pPoolItem = 
GetExport().m_pChpIter->HasTextItem(RES_CHRATR_BOX))
         {
-            pInherited = &pPoolItem->StaticWhichCast(RES_CHRATR_BOX);
+            pInherited = pPoolItem;
         }
     }
 
@@ -9315,8 +9315,7 @@ void DocxAttributeOutput::FormatLRSpace( const 
SvxLRSpaceItem& rLRSpace )
         m_pageMargins.nLeft = 0;
         m_pageMargins.nRight = 0;
 
-        const SfxPoolItem* pPoolItem = m_rExport.HasItem(RES_BOX);
-        const SvxBoxItem* pBoxItem = pPoolItem ? 
&pPoolItem->StaticWhichCast(RES_BOX) : nullptr;
+        const SvxBoxItem* pBoxItem = m_rExport.HasItem(RES_BOX);
         if (pBoxItem)
         {
             m_pageMargins.nLeft = pBoxItem->CalcLineSpace( 
SvxBoxItemLine::LEFT, /*bEvenIfNoLine*/true );
diff --git a/sw/source/filter/ww8/rtfattributeoutput.cxx 
b/sw/source/filter/ww8/rtfattributeoutput.cxx
index 273d660237f6..645de35025ea 100644
--- a/sw/source/filter/ww8/rtfattributeoutput.cxx
+++ b/sw/source/filter/ww8/rtfattributeoutput.cxx
@@ -3611,8 +3611,8 @@ void RtfAttributeOutput::FormatBox(const SvxBoxItem& rBox)
     else
     {
         SvxShadowLocation eShadowLocation = SvxShadowLocation::NONE;
-        if (const SfxPoolItem* pItem = GetExport().HasItem(RES_SHADOW))
-            eShadowLocation = pItem->StaticWhichCast(RES_SHADOW).GetLocation();
+        if (const SvxShadowItem* pItem = GetExport().HasItem(RES_SHADOW))
+            eShadowLocation = pItem->GetLocation();
 
         const SvxBoxItemLine* pBrd = aBorders;
         const char** pBrdNms = aBorderNames;
diff --git a/sw/source/filter/ww8/wrtww8.hxx b/sw/source/filter/ww8/wrtww8.hxx
index 497e06c08da5..ef5eea2d0c13 100644
--- a/sw/source/filter/ww8/wrtww8.hxx
+++ b/sw/source/filter/ww8/wrtww8.hxx
@@ -813,6 +813,10 @@ public:
     virtual sal_uInt64 ReplaceCr( sal_uInt8 nChar ) = 0;
 
     const SfxPoolItem* HasItem( sal_uInt16 nWhich ) const;
+    template<class T> const T* HasItem(TypedWhichId<T> nWhich) const
+    {
+        return static_cast<const T*>(HasItem(sal_uInt16(nWhich)));
+    }
 
     /// Returns the index of a picture bullet, used in numberings.
     int GetGrfIndex(const SvxBrushItem& rBrush);
@@ -1446,8 +1450,16 @@ public:
     virtual ~MSWordAttrIter();
 
     virtual const SfxPoolItem* HasTextItem( sal_uInt16 nWhich ) const = 0;
+    template<class T> const T* HasTextItem( TypedWhichId<T> nWhich ) const
+    {
+        return static_cast<const T*>(HasTextItem(sal_uInt16(nWhich)));
+    }
     virtual const SfxPoolItem& GetItem( sal_uInt16 nWhich ) const = 0;
- };
+    template<class T> const T* GetItem( TypedWhichId<T> nWhich ) const
+    {
+        return static_cast<const T*>(GetItem(sal_uInt16(nWhich)));
+    }
+};
 
 /// Used to export formatted text associated to drawings.
 class MSWord_SdrAttrIter : public MSWordAttrIter
diff --git a/sw/source/filter/ww8/ww8atr.cxx b/sw/source/filter/ww8/ww8atr.cxx
index 839897f93ebd..dac2745b2117 100644
--- a/sw/source/filter/ww8/ww8atr.cxx
+++ b/sw/source/filter/ww8/ww8atr.cxx
@@ -3740,8 +3740,8 @@ void AttributeOutputBase::ParaNumRule( const 
SwNumRuleItem& rNumRule )
             const SfxItemSet* pSet = GetExport().m_pISet;
             if (pSet && pSet->HasItem(RES_PARATR_LIST_LEVEL))
             {
-                const SfxPoolItem* pItem = 
pSet->GetItem(RES_PARATR_LIST_LEVEL);
-                nLvl = 
pItem->StaticWhichCast(RES_PARATR_LIST_LEVEL).GetValue();
+                const SfxInt16Item* pItem = 
pSet->GetItem(RES_PARATR_LIST_LEVEL);
+                nLvl = pItem->GetValue();
             }
         }
     }
@@ -4124,7 +4124,7 @@ void WW8AttributeOutput::FormatLRSpace( const 
SvxLRSpaceItem& rLR )
         m_pageMargins.nLeft = 0;
         m_pageMargins.nRight = 0;
 
-        if ( auto pBoxItem = static_cast<const 
SvxBoxItem*>(m_rWW8Export.HasItem( RES_BOX )) )
+        if ( const SvxBoxItem* pBoxItem = m_rWW8Export.HasItem( RES_BOX ) )
         {
             m_pageMargins.nLeft = pBoxItem->CalcLineSpace( 
SvxBoxItemLine::LEFT, /*bEvenIfNoLine*/true );
             m_pageMargins.nRight = pBoxItem->CalcLineSpace( 
SvxBoxItemLine::RIGHT, /*bEvenIfNoLine*/true );
@@ -4674,12 +4674,11 @@ void WW8AttributeOutput::FormatBox( const SvxBoxItem& 
rBox )
         return;
 
     bool bShadow = false;
-    const SfxPoolItem* pItem = m_rWW8Export.HasItem( RES_SHADOW );
-    if ( pItem )
+    const SvxShadowItem* pShadowItem = m_rWW8Export.HasItem( RES_SHADOW );
+    if ( pShadowItem )
     {
-        const SvxShadowItem& rShadow = pItem->StaticWhichCast(RES_SHADOW);
-        bShadow = ( rShadow.GetLocation() != SvxShadowLocation::NONE )
-                  && ( rShadow.GetWidth() != 0 );
+        bShadow = ( pShadowItem->GetLocation() != SvxShadowLocation::NONE )
+                  && ( pShadowItem->GetWidth() != 0 );
     }
 
     SvxBoxItem aBox(rBox);
diff --git a/sw/source/uibase/utlui/uitool.cxx 
b/sw/source/uibase/utlui/uitool.cxx
index 51da2892b672..0a9184a88610 100644
--- a/sw/source/uibase/utlui/uitool.cxx
+++ b/sw/source/uibase/utlui/uitool.cxx
@@ -716,19 +716,18 @@ void SfxToSwPageDescAttr( const SwWrtShell& rShell, 
SfxItemSet& rSet )
 // Inquire if in the set is a Sfx-PageDesc combination present and return it.
 void SwToSfxPageDescAttr( SfxItemSet& rCoreSet )
 {
-    const SwFormatPageDesc* pItem = nullptr;
+    const SwFormatPageDesc* pPageDescItem = nullptr;
     OUString aName;
     ::std::optional<sal_uInt16> oNumOffset;
     bool bPut = true;
-    switch( rCoreSet.GetItemState( RES_PAGEDESC, true, &pItem ) )
+    switch( rCoreSet.GetItemState( RES_PAGEDESC, true, &pPageDescItem ) )
     {
     case SfxItemState::SET:
         {
-            auto rPageDescItem = pItem->StaticWhichCast(RES_PAGEDESC);
-            if( rPageDescItem.GetPageDesc() )
+            if( pPageDescItem->GetPageDesc() )
             {
-                aName = rPageDescItem.GetPageDesc()->GetName();
-                oNumOffset = rPageDescItem.GetNumOffset();
+                aName = pPageDescItem->GetPageDesc()->GetName();
+                oNumOffset = pPageDescItem->GetNumOffset();
             }
             rCoreSet.ClearItem( RES_PAGEDESC );
             // Page number

Reply via email to