[Libreoffice-commits] core.git: sw/source

Bjoern Michaelsen (via logerrit) logerrit at kemper.freedesktop.org
Thu Feb 4 00:16:35 UTC 2021


 sw/source/core/attr/format.cxx                          |    8 
 sw/source/core/attr/swatrset.cxx                        |   32 +--
 sw/source/core/crsr/crstrvl.cxx                         |    8 
 sw/source/core/crsr/findattr.cxx                        |   14 -
 sw/source/core/doc/DocumentContentOperationsManager.cxx |    4 
 sw/source/core/doc/docfly.cxx                           |   34 +--
 sw/source/core/doc/docfmt.cxx                           |   23 +-
 sw/source/core/text/atrstck.cxx                         |  156 +++++++---------
 sw/source/filter/ww8/ww8atr.cxx                         |   53 +++--
 sw/source/uibase/utlui/uitool.cxx                       |   20 +-
 10 files changed, 177 insertions(+), 175 deletions(-)

New commits:
commit e89ff1a6378d3910f9026e5c4e797b74e20f7ce3
Author:     Bjoern Michaelsen <bjoern.michaelsen at libreoffice.org>
AuthorDate: Sun Jan 31 01:03:24 2021 +0100
Commit:     Bjoern Michaelsen <bjoern.michaelsen at libreoffice.org>
CommitDate: Thu Feb 4 01:15:45 2021 +0100

    use more StaticWhichCast
    
    - because it uses TypedWhichIds well-defined mapping of id to type
    - ... and assert, if the content found doesnt match up expectations
    
    Change-Id: Idda58ccda47c5d074326537dcc6670ef0cfcabf1
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110233
    Tested-by: Jenkins
    Reviewed-by: Bjoern Michaelsen <bjoern.michaelsen at libreoffice.org>

diff --git a/sw/source/core/attr/format.cxx b/sw/source/core/attr/format.cxx
index 9224a61f2ab2..b668c8e24e6e 100644
--- a/sw/source/core/attr/format.cxx
+++ b/sw/source/core/attr/format.cxx
@@ -244,7 +244,7 @@ void SwFormat::SwClientNotify(const SwModify&, const SfxHint& rHint)
                 break;
             // If the dying object is the parent format of this format so
             // attach this to the parent of the parent
-            SwFormat* pFormat = static_cast<SwFormat*>(static_cast<const SwPtrMsgPoolItem*>(pLegacy->m_pNew)->pObject);
+            SwFormat* pFormat = static_cast<SwFormat*>(pLegacy->m_pNew->StaticWhichCast(RES_OBJECTDYING).pObject);
 
             // do not move if this is the topmost format
             if(GetRegisteredIn() && GetRegisteredIn() == pFormat)
@@ -442,7 +442,7 @@ SfxItemState SwFormat::GetBackgroundState(std::unique_ptr<SvxBrushItem>& rItem)
     const SfxPoolItem* pItem = nullptr;
     SfxItemState eRet = m_aSet.GetItemState(RES_BACKGROUND, true, &pItem);
     if (pItem)
-        rItem.reset(static_cast<SvxBrushItem*>(pItem->Clone()));
+        rItem.reset(&pItem->Clone()->StaticWhichCast(RES_BACKGROUND));
     return eRet;
 }
 
@@ -459,7 +459,7 @@ bool SwFormat::SetFormatAttr( const SfxPoolItem& rAttr )
         // FALLBACKBREAKHERE should not be used; instead use [XATTR_FILL_FIRST .. XATTR_FILL_LAST]
         SAL_INFO("sw.core", "Do no longer use SvxBrushItem, instead use [XATTR_FILL_FIRST .. XATTR_FILL_LAST] FillAttributes (simple fallback is in place and used)");
         SfxItemSet aTempSet(*m_aSet.GetPool(), svl::Items<XATTR_FILL_FIRST, XATTR_FILL_LAST>{});
-        const SvxBrushItem& rSource = static_cast< const SvxBrushItem& >(rAttr);
+        const SvxBrushItem& rSource = rAttr.StaticWhichCast(RES_BACKGROUND);
 
         // fill a local ItemSet with the attributes corresponding as good as possible
         // to the new fill properties [XATTR_FILL_FIRST .. XATTR_FILL_LAST] and set these
@@ -559,7 +559,7 @@ bool SwFormat::SetFormatAttr( const SfxItemSet& rSet )
             // copy all items to be set anyways to a local ItemSet with is also prepared for the new
             // fill attribute ranges [XATTR_FILL_FIRST .. XATTR_FILL_LAST]. Add the attributes
             // corresponding as good as possible to the new fill properties and set the whole ItemSet
-            const SvxBrushItem& rSource(static_cast< const SvxBrushItem& >(*pSource));
+            const SvxBrushItem& rSource(pSource->StaticWhichCast(RES_BACKGROUND));
             setSvxBrushItemAsFillAttributesToTargetSet(rSource, aTempSet);
 
             if(IsModifyLocked())
diff --git a/sw/source/core/attr/swatrset.cxx b/sw/source/core/attr/swatrset.cxx
index 90343c31e19f..aae6df77112b 100644
--- a/sw/source/core/attr/swatrset.cxx
+++ b/sw/source/core/attr/swatrset.cxx
@@ -253,32 +253,32 @@ bool SwAttrSet::SetModifyAtAttr( const sw::BroadcastingModify* pModify )
 
     const SfxPoolItem* pItem;
     if( SfxItemState::SET == GetItemState( RES_PAGEDESC, false, &pItem ) &&
-        static_cast<const SwFormatPageDesc*>(pItem)->GetDefinedIn() != pModify  )
+        pItem->StaticWhichCast(RES_PAGEDESC).GetDefinedIn() != pModify  )
     {
-        const_cast<SwFormatPageDesc*>(static_cast<const SwFormatPageDesc*>(pItem))->ChgDefinedIn( pModify );
+        const_cast<SwFormatPageDesc&>(pItem->StaticWhichCast(RES_PAGEDESC)).ChgDefinedIn( pModify );
         bSet = true;
     }
 
     if(SfxItemState::SET == GetItemState( RES_PARATR_DROP, false, &pItem ))
     {
         auto pDropDefiner = dynamic_cast<const sw::FormatDropDefiner*>(pModify);
-        auto pFormatDrop = const_cast<SwFormatDrop*>(static_cast<const SwFormatDrop*>(pItem));
+        SwFormatDrop& rFormatDrop = const_cast<SwFormatDrop&>(pItem->StaticWhichCast(RES_PARATR_DROP));
         // If CharFormat is set and it is set in different attribute pools then
         // the CharFormat has to be copied.
-        SwCharFormat* pCharFormat = pFormatDrop->GetCharFormat();
+        SwCharFormat* pCharFormat = rFormatDrop.GetCharFormat();
         if(pCharFormat && GetPool() != pCharFormat->GetAttrSet().GetPool())
         {
            pCharFormat = GetDoc()->CopyCharFormat(*pCharFormat);
-           pFormatDrop->SetCharFormat(pCharFormat);
+           rFormatDrop.SetCharFormat(pCharFormat);
         }
-        pFormatDrop->ChgDefinedIn(pDropDefiner);
+        rFormatDrop.ChgDefinedIn(pDropDefiner);
         bSet = true;
     }
 
     if( SfxItemState::SET == GetItemState( RES_BOXATR_FORMULA, false, &pItem ) &&
-        static_cast<const SwTableBoxFormula*>(pItem)->GetDefinedIn() != pModify )
+        pItem->StaticWhichCast(RES_BOXATR_FORMULA).GetDefinedIn() != pModify )
     {
-        const_cast<SwTableBoxFormula*>(static_cast<const SwTableBoxFormula*>(pItem))->ChgDefinedIn( pModify );
+        const_cast<SwTableBoxFormula&>(pItem->StaticWhichCast(RES_BOXATR_FORMULA)).ChgDefinedIn( pModify );
         bSet = true;
     }
 
@@ -306,7 +306,7 @@ void SwAttrSet::CopyToModify( sw::BroadcastingModify& rMod ) const
             if( pSrcDoc != pDstDoc &&
                 SfxItemState::SET == GetItemState( RES_PARATR_NUMRULE, false, &pItem ) )
             {
-                const OUString& rNm = static_cast<const SwNumRuleItem*>(pItem)->GetValue();
+                const OUString& rNm = pItem->StaticWhichCast(RES_PARATR_NUMRULE).GetValue();
                 if( !rNm.isEmpty() )
                 {
                     SwNumRule* pDestRule = pDstDoc->FindNumRulePtr( rNm );
@@ -372,7 +372,7 @@ void SwAttrSet::CopyToModify( sw::BroadcastingModify& rMod ) const
             if( pSrcDoc != pDstDoc && SfxItemState::SET == GetItemState(
                                             RES_PAGEDESC, false, &pItem ))
             {
-                const SwPageDesc* pPgDesc = static_cast<const SwFormatPageDesc*>(pItem)->GetPageDesc();
+                const SwPageDesc* pPgDesc = pItem->StaticWhichCast(RES_PAGEDESC).GetPageDesc();
                 if( pPgDesc )
                 {
                     tmpSet.reset(new SfxItemSet(*this));
@@ -384,13 +384,13 @@ void SwAttrSet::CopyToModify( sw::BroadcastingModify& rMod ) const
                         pDstDoc->CopyPageDesc( *pPgDesc, *pDstPgDesc );
                     }
                     SwFormatPageDesc aDesc( pDstPgDesc );
-                    aDesc.SetNumOffset( static_cast<const SwFormatPageDesc*>(pItem)->GetNumOffset() );
+                    aDesc.SetNumOffset( pItem->StaticWhichCast(RES_PAGEDESC).GetNumOffset() );
                     tmpSet->Put( aDesc );
                 }
             }
 
             if( pSrcDoc != pDstDoc && SfxItemState::SET == GetItemState( RES_ANCHOR, false, &pItem )
-                && static_cast< const SwFormatAnchor* >( pItem )->GetContentAnchor() != nullptr )
+                && pItem->StaticWhichCast(RES_ANCHOR).GetContentAnchor() != nullptr )
             {
                 if( !tmpSet )
                     tmpSet.reset( new SfxItemSet( *this ));
@@ -402,16 +402,16 @@ void SwAttrSet::CopyToModify( sw::BroadcastingModify& rMod ) const
             if (pSrcDoc != pDstDoc &&
                 SfxItemState::SET == GetItemState(RES_PARATR_LIST_AUTOFMT, false, &pItem))
             {
-                SfxItemSet const& rAutoStyle(*static_cast<SwFormatAutoFormat const&>(*pItem).GetStyleHandle());
+                SfxItemSet const& rAutoStyle(*pItem->StaticWhichCast(RES_PARATR_LIST_AUTOFMT).GetStyleHandle());
                 std::shared_ptr<SfxItemSet> const pNewSet(
                     rAutoStyle.SfxItemSet::Clone(true, &pDstDoc->GetAttrPool()));
 
                 // fix up character style, it contains pointers to pSrcDoc
                 if (SfxItemState::SET == pNewSet->GetItemState(RES_TXTATR_CHARFMT, false, &pItem))
                 {
-                    auto const* pChar(static_cast<SwFormatCharFormat const*>(pItem));
-                    SwCharFormat *const pCopy(pDstDoc->CopyCharFormat(*pChar->GetCharFormat()));
-                    const_cast<SwFormatCharFormat*>(pChar)->SetCharFormat(pCopy);
+                    const auto& rChar(pItem->StaticWhichCast(RES_TXTATR_CHARFMT));
+                    SwCharFormat *const pCopy(pDstDoc->CopyCharFormat(*rChar.GetCharFormat()));
+                    const_cast<SwFormatCharFormat&>(rChar).SetCharFormat(pCopy);
                 }
 
                 SwFormatAutoFormat item(RES_PARATR_LIST_AUTOFMT);
diff --git a/sw/source/core/crsr/crstrvl.cxx b/sw/source/core/crsr/crstrvl.cxx
index 9c18f16f4fbb..08cf06763f44 100644
--- a/sw/source/core/crsr/crstrvl.cxx
+++ b/sw/source/core/crsr/crstrvl.cxx
@@ -1734,7 +1734,7 @@ bool SwCursorShell::GetContentAtPos( const Point& rPt,
                             rContentAtPos.eContentAtPos = IsAttrAtPos::TableBoxValue;
                         else
 #endif
-                            const_cast<SwTableBoxFormula*>(static_cast<const SwTableBoxFormula*>(pItem))->PtrToBoxNm( &pTableNd->GetTable() );
+                            const_cast<SwTableBoxFormula&>(pItem->StaticWhichCast(RES_BOXATR_FORMULA)).PtrToBoxNm( &pTableNd->GetTable() );
 
                         bRet = true;
                         if( bSetCursor )
@@ -2131,14 +2131,12 @@ bool SwCursorShell::SetShadowCursorPos( const Point& rPt, SwFillMode eFillMode )
                         svl::Items<
                             RES_PARATR_ADJUST, RES_PARATR_ADJUST,
                             RES_LR_SPACE, RES_LR_SPACE>{});
-                    SvxLRSpaceItem aLR( static_cast<const SvxLRSpaceItem&>(
-                                        pCNd->GetAttr( RES_LR_SPACE ) ) );
+                    SvxLRSpaceItem aLR(pCNd->GetAttr(RES_LR_SPACE).StaticWhichCast(RES_LR_SPACE));
                     aLR.SetTextLeft( aFPos.nTabCnt );
                     aLR.SetTextFirstLineOffset( 0 );
                     aSet.Put( aLR );
 
-                    const SvxAdjustItem& rAdj = static_cast<const SvxAdjustItem&>(pCNd->
-                                        GetAttr( RES_PARATR_ADJUST ));
+                    const SvxAdjustItem& rAdj = pCNd->GetAttr(RES_PARATR_ADJUST).StaticWhichCast(RES_PARATR_ADJUST);
                     if( SvxAdjust::Left != rAdj.GetAdjust() )
                         aSet.Put( SvxAdjustItem( SvxAdjust::Left, RES_PARATR_ADJUST ) );
 
diff --git a/sw/source/core/crsr/findattr.cxx b/sw/source/core/crsr/findattr.cxx
index 85d7830c502f..09f78df324e8 100644
--- a/sw/source/core/crsr/findattr.cxx
+++ b/sw/source/core/crsr/findattr.cxx
@@ -57,22 +57,18 @@ static bool CmpAttr( const SfxPoolItem& rItem1, const SfxPoolItem& rItem2 )
     switch( rItem1.Which() )
     {
     case RES_CHRATR_FONT:
-        return static_cast<const SvxFontItem&>(rItem1).GetFamilyName() ==
-                static_cast<const SvxFontItem&>(rItem2).GetFamilyName();
+        return rItem1.StaticWhichCast(RES_CHRATR_FONT).GetFamilyName() == rItem2.StaticWhichCast(RES_CHRATR_FONT).GetFamilyName();
 
     case RES_CHRATR_COLOR:
-        return static_cast<const SvxColorItem&>(rItem1).GetValue().IsRGBEqual(
-                                static_cast<const SvxColorItem&>(rItem2).GetValue() );
+        return rItem1.StaticWhichCast(RES_CHRATR_COLOR).GetValue().IsRGBEqual(rItem2.StaticWhichCast(RES_CHRATR_COLOR).GetValue());
     case RES_PAGEDESC:
-        ::std::optional<sal_uInt16> const oNumOffset1 =
-            static_cast<const SwFormatPageDesc&>(rItem1).GetNumOffset();
-        ::std::optional<sal_uInt16> const oNumOffset2 =
-            static_cast<const SwFormatPageDesc&>(rItem2).GetNumOffset();
+        ::std::optional<sal_uInt16> const oNumOffset1 = rItem1.StaticWhichCast(RES_PAGEDESC).GetNumOffset();
+        ::std::optional<sal_uInt16> const oNumOffset2 = rItem2.StaticWhichCast(RES_PAGEDESC).GetNumOffset();
 
         if (oNumOffset1 != oNumOffset2)
             return false;
 
-        return static_cast<const SwFormatPageDesc&>(rItem1).GetPageDesc() == static_cast<const SwFormatPageDesc&>(rItem2).GetPageDesc();
+        return rItem1.StaticWhichCast(RES_PAGEDESC).GetPageDesc() == rItem2.StaticWhichCast(RES_PAGEDESC).GetPageDesc();
     }
     return rItem1 == rItem2;
 }
diff --git a/sw/source/core/doc/DocumentContentOperationsManager.cxx b/sw/source/core/doc/DocumentContentOperationsManager.cxx
index 1b160fe2deec..93646ac74565 100644
--- a/sw/source/core/doc/DocumentContentOperationsManager.cxx
+++ b/sw/source/core/doc/DocumentContentOperationsManager.cxx
@@ -4553,13 +4553,13 @@ static void lcl_PushNumruleState(
     aNumRuleState = pAttrSet->GetItemState(RES_PARATR_NUMRULE, false, &pItem);
     if (SfxItemState::SET == aNumRuleState)
     {
-        aNumRuleItem.reset(static_cast<SwNumRuleItem*>(pItem->Clone()));
+        aNumRuleItem.reset(&pItem->Clone()->StaticWhichCast(RES_PARATR_NUMRULE));
     }
 
     aListIdState = pAttrSet->GetItemState(RES_PARATR_LIST_ID, false, &pItem);
     if (SfxItemState::SET == aListIdState)
     {
-        aListIdItem.reset(static_cast<SfxStringItem*>(pItem->Clone()));
+        aListIdItem.reset(&pItem->Clone()->StaticWhichCast(RES_PARATR_LIST_ID));
     }
 }
 
diff --git a/sw/source/core/doc/docfly.cxx b/sw/source/core/doc/docfly.cxx
index db38549fcf87..9f3770968228 100644
--- a/sw/source/core/doc/docfly.cxx
+++ b/sw/source/core/doc/docfly.cxx
@@ -375,16 +375,16 @@ sal_Int8 SwDoc::SetFlyFrameAnchor( SwFrameFormat& rFormat, SfxItemSet& rSet, boo
             bool bPutOldH(false);
 
             if( text::HoriOrientation::NONE == aOldH.GetHoriOrient() && ( !pItem ||
-                aOldH.GetPos() == static_cast<const SwFormatHoriOrient*>(pItem)->GetPos() ))
+                aOldH.GetPos() == pItem->StaticWhichCast(RES_HORI_ORIENT).GetPos() ))
             {
                 SwTwips nPos = (RndStdIds::FLY_AS_CHAR == nOld) ? 0 : aOldH.GetPos();
                 nPos += aOldAnchorPos.getX() - aNewAnchorPos.getX();
 
                 if( pItem )
                 {
-                    SwFormatHoriOrient* pH = const_cast<SwFormatHoriOrient*>(static_cast<const SwFormatHoriOrient*>(pItem));
-                    aOldH.SetHoriOrient( pH->GetHoriOrient() );
-                    aOldH.SetRelationOrient( pH->GetRelationOrient() );
+                    SwFormatHoriOrient& rH = const_cast<SwFormatHoriOrient&>(pItem->StaticWhichCast(RES_HORI_ORIENT));
+                    aOldH.SetHoriOrient( rH.GetHoriOrient() );
+                    aOldH.SetRelationOrient( rH.GetRelationOrient() );
                 }
                 aOldH.SetPos( nPos );
                 bPutOldH = true;
@@ -392,7 +392,7 @@ sal_Int8 SwDoc::SetFlyFrameAnchor( SwFrameFormat& rFormat, SfxItemSet& rSet, boo
             if (nNew == RndStdIds::FLY_AT_PAGE)
             {
                 sal_Int16 nRelOrient(pItem
-                    ? static_cast<const SwFormatHoriOrient*>(pItem)->GetRelationOrient()
+                    ? pItem->StaticWhichCast(RES_HORI_ORIENT).GetRelationOrient()
                     : aOldH.GetRelationOrient());
                 if (sw::GetAtPageRelOrientation(nRelOrient, false))
                 {
@@ -413,15 +413,15 @@ sal_Int8 SwDoc::SetFlyFrameAnchor( SwFrameFormat& rFormat, SfxItemSet& rSet, boo
             // #i28922# - correction: compare <aOldV.GetVertOrient() with
             // <text::VertOrientation::NONE>
             if( text::VertOrientation::NONE == aOldV.GetVertOrient() && (!pItem ||
-                aOldV.GetPos() == static_cast<const SwFormatVertOrient*>(pItem)->GetPos() ) )
+                aOldV.GetPos() == pItem->StaticWhichCast(RES_VERT_ORIENT).GetPos() ) )
             {
                 SwTwips nPos = (RndStdIds::FLY_AS_CHAR == nOld) ? 0 : aOldV.GetPos();
                 nPos += aOldAnchorPos.getY() - aNewAnchorPos.getY();
                 if( pItem )
                 {
-                    SwFormatVertOrient* pV = const_cast<SwFormatVertOrient*>(static_cast<const SwFormatVertOrient*>(pItem));
-                    aOldV.SetVertOrient( pV->GetVertOrient() );
-                    aOldV.SetRelationOrient( pV->GetRelationOrient() );
+                    SwFormatVertOrient& rV = const_cast<SwFormatVertOrient&>(pItem->StaticWhichCast(RES_VERT_ORIENT));
+                    aOldV.SetVertOrient( rV.GetVertOrient() );
+                    aOldV.SetRelationOrient( rV.GetRelationOrient() );
                 }
                 aOldV.SetPos( nPos );
                 rSet.Put( aOldV );
@@ -512,37 +512,37 @@ void SwDoc::CheckForUniqueItemForLineFillNameOrIndex(SfxItemSet& rSet)
         {
             case XATTR_FILLBITMAP:
             {
-                pResult = static_cast< const XFillBitmapItem* >(pItem)->checkForUniqueItem(pDrawModel);
+                pResult = pItem->StaticWhichCast(XATTR_FILLBITMAP).checkForUniqueItem(pDrawModel);
                 break;
             }
             case XATTR_LINEDASH:
             {
-                pResult = static_cast< const XLineDashItem* >(pItem)->checkForUniqueItem(pDrawModel);
+                pResult = pItem->StaticWhichCast(XATTR_LINEDASH).checkForUniqueItem(pDrawModel);
                 break;
             }
             case XATTR_LINESTART:
             {
-                pResult = static_cast< const XLineStartItem* >(pItem)->checkForUniqueItem(pDrawModel);
+                pResult = pItem->StaticWhichCast(XATTR_LINESTART).checkForUniqueItem(pDrawModel);
                 break;
             }
             case XATTR_LINEEND:
             {
-                pResult = static_cast< const XLineEndItem* >(pItem)->checkForUniqueItem(pDrawModel);
+                pResult = pItem->StaticWhichCast(XATTR_LINEEND).checkForUniqueItem(pDrawModel);
                 break;
             }
             case XATTR_FILLGRADIENT:
             {
-                pResult = static_cast< const XFillGradientItem* >(pItem)->checkForUniqueItem(pDrawModel);
+                pResult = pItem->StaticWhichCast(XATTR_FILLGRADIENT).checkForUniqueItem(pDrawModel);
                 break;
             }
             case XATTR_FILLFLOATTRANSPARENCE:
             {
-                pResult = static_cast< const XFillFloatTransparenceItem* >(pItem)->checkForUniqueItem(pDrawModel);
+                pResult = pItem->StaticWhichCast(XATTR_FILLFLOATTRANSPARENCE).checkForUniqueItem(pDrawModel);
                 break;
             }
             case XATTR_FILLHATCH:
             {
-                pResult = static_cast< const XFillHatchItem* >(pItem)->checkForUniqueItem(pDrawModel);
+                pResult = pItem->StaticWhichCast(XATTR_FILLHATCH).checkForUniqueItem(pDrawModel);
                 break;
             }
         }
@@ -668,7 +668,7 @@ bool SwDoc::SetFrameFormatToFly( SwFrameFormat& rFormat, SwFrameFormat& rNewForm
         const SfxItemSet* pAsk = pSet;
         if( !pAsk ) pAsk = &rNewFormat.GetAttrSet();
         if( SfxItemState::SET == pAsk->GetItemState( RES_ANCHOR, false, &pItem )
-            && static_cast<const SwFormatAnchor*>(pItem)->GetAnchorId() !=
+            && pItem->StaticWhichCast(RES_ANCHOR).GetAnchorId() !=
                 rFormat.GetAnchor().GetAnchorId() )
         {
             if( pSet )
diff --git a/sw/source/core/doc/docfmt.cxx b/sw/source/core/doc/docfmt.cxx
index 7de2b60941d5..2ded69b4ae4c 100644
--- a/sw/source/core/doc/docfmt.cxx
+++ b/sw/source/core/doc/docfmt.cxx
@@ -1210,7 +1210,7 @@ SwTextFormatColl* SwDoc::CopyTextColl( const SwTextFormatColl& rColl )
         if( SfxItemState::SET == pNewColl->GetItemState( RES_PARATR_NUMRULE,
             false, &pItem ))
         {
-            const OUString& rName = static_cast<const SwNumRuleItem*>(pItem)->GetValue();
+            const OUString& rName = pItem->StaticWhichCast(RES_PARATR_NUMRULE).GetValue();
             if( !rName.isEmpty() )
             {
                 const SwNumRule* pRule = rColl.GetDoc()->FindNumRulePtr( rName );
@@ -1292,12 +1292,11 @@ void SwDoc::CopyFormatArr( const SwFormatsBase& rSourceArr,
 
         // #i94285#: existing <SwFormatPageDesc> instance, before copying attributes
         const SfxPoolItem* pItem;
-        if( &GetAttrPool() != pSrc->GetAttrSet().GetPool() &&
-            SfxItemState::SET == pSrc->GetAttrSet().GetItemState(
-            RES_PAGEDESC, false, &pItem ) &&
-            static_cast<const SwFormatPageDesc*>(pItem)->GetPageDesc() )
+        if( &GetAttrPool() != pSrc->GetAttrSet().GetPool()
+                && SfxItemState::SET == pSrc->GetAttrSet().GetItemState( RES_PAGEDESC, false, &pItem )
+                && pItem->StaticWhichCast(RES_PAGEDESC).GetPageDesc() )
         {
-            SwFormatPageDesc aPageDesc( *static_cast<const SwFormatPageDesc*>(pItem) );
+            SwFormatPageDesc aPageDesc( pItem->StaticWhichCast(RES_PAGEDESC) );
             const OUString& rNm = aPageDesc.GetPageDesc()->GetName();
             SwPageDesc* pPageDesc = FindPageDesc( rNm );
             if( !pPageDesc )
@@ -1360,9 +1359,9 @@ void SwDoc::CopyPageDescHeaderFooterImpl( bool bCpyHeader,
 
     SwFrameFormat* pOldFormat;
     if( bCpyHeader )
-         pOldFormat = static_cast<SwFormatHeader*>(pNewItem.get())->GetHeaderFormat();
+         pOldFormat = pNewItem->StaticWhichCast(RES_HEADER).GetHeaderFormat();
     else
-         pOldFormat = static_cast<SwFormatFooter*>(pNewItem.get())->GetFooterFormat();
+         pOldFormat = pNewItem->StaticWhichCast(RES_FOOTER).GetFooterFormat();
 
     if( !pOldFormat )
         return;
@@ -1374,7 +1373,7 @@ void SwDoc::CopyPageDescHeaderFooterImpl( bool bCpyHeader,
     if( SfxItemState::SET == pNewFormat->GetAttrSet().GetItemState(
         RES_CNTNT, false, &pItem ))
     {
-        const SwFormatContent* pContent = static_cast<const SwFormatContent*>(pItem);
+        const SwFormatContent* pContent = &pItem->StaticWhichCast(RES_CNTNT);
         if( pContent->GetContentIdx() )
         {
             SwNodeIndex aTmpIdx( GetNodes().GetEndOfAutotext() );
@@ -1399,9 +1398,9 @@ void SwDoc::CopyPageDescHeaderFooterImpl( bool bCpyHeader,
             pNewFormat->ResetFormatAttr( RES_CNTNT );
     }
     if( bCpyHeader )
-        static_cast<SwFormatHeader*>(pNewItem.get())->RegisterToFormat(*pNewFormat);
+        pNewItem->StaticWhichCast(RES_HEADER).RegisterToFormat(*pNewFormat);
     else
-        static_cast<SwFormatFooter*>(pNewItem.get())->RegisterToFormat(*pNewFormat);
+        pNewItem->StaticWhichCast(RES_FOOTER).RegisterToFormat(*pNewFormat);
     rDestFormat.SetFormatAttr( *pNewItem );
 }
 
@@ -1645,7 +1644,7 @@ void SwDoc::MoveLeftMargin(const SwPaM& rPam, bool bRight, bool bModulus,
         if( pTNd )
         {
             pTNd = sw::GetParaPropsNode(*pLayout, aIdx);
-            SvxLRSpaceItem aLS( static_cast<const SvxLRSpaceItem&>(pTNd->SwContentNode::GetAttr( RES_LR_SPACE )) );
+            SvxLRSpaceItem aLS(pTNd->SwContentNode::GetAttr(RES_LR_SPACE).StaticWhichCast(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 c5d29692719f..4cc7b501094f 100644
--- a/sw/source/core/text/atrstck.cxx
+++ b/sw/source/core/text/atrstck.cxx
@@ -135,13 +135,13 @@ const SfxItemSet* GetItemSet( const SfxPoolItem& rAttr )
 
     if ( RES_TXTATR_AUTOFMT == rAttr.Which() )
     {
-        pSet = static_cast<const SwFormatAutoFormat&>(rAttr).GetStyleHandle().get();
+        pSet = rAttr.StaticWhichCast(RES_TXTATR_AUTOFMT).GetStyleHandle().get();
     }
     else
     {
         // Get the attributes from the template
         const SwCharFormat* pFormat = RES_TXTATR_INETFMT == rAttr.Which() ?
-                        static_cast<const SwFormatINetFormat&>(rAttr).GetTextINetFormat()->GetCharFormat() :
+                        rAttr.StaticWhichCast(RES_TXTATR_INETFMT).GetTextINetFormat()->GetCharFormat() :
                         static_cast<const SwFormatCharFormat&>(rAttr).GetCharFormat();
         if( pFormat )
         {
@@ -222,7 +222,7 @@ static bool lcl_ChgHyperLinkColor( const SwTextAttr& rAttr,
                 const SwCharFormat* pTmpFormat = rINetAttr.GetCharFormat();
                 const SfxPoolItem* pItem;
                 if (SfxItemState::SET == pTmpFormat->GetItemState(RES_CHRATR_COLOR, true, &pItem))
-                    *pColor = static_cast<const SvxColorItem*>(pItem)->GetValue();
+                    *pColor = pItem->StaticWhichCast(RES_CHRATR_COLOR).GetValue();
                 rINetAttr.SetVisited(true);
             }
             return true;
@@ -531,12 +531,11 @@ void SwAttrHandler::ActivateTop( SwFont& rFnt, const sal_uInt16 nAttr )
 
         if ( pTwoLineAttr )
         {
-             const SfxPoolItem* pTwoLineItem = CharFormat::GetItem( *pTwoLineAttr, RES_CHRATR_TWO_LINES );
-             bTwoLineAct = static_cast<const SvxTwoLinesItem*>(pTwoLineItem)->GetValue();
+             const auto& rTwoLineItem = CharFormat::GetItem( *pTwoLineAttr, RES_CHRATR_TWO_LINES )->StaticWhichCast(RES_CHRATR_TWO_LINES);
+             bTwoLineAct = rTwoLineItem.GetValue();
         }
         else
-            bTwoLineAct =
-                static_cast<const SvxTwoLinesItem*>(m_pDefaultArray[ nTwoLineStack ])->GetValue();
+            bTwoLineAct = m_pDefaultArray[ nTwoLineStack ]->StaticWhichCast(RES_CHRATR_TWO_LINES).GetValue();
 
         if ( bTwoLineAct )
             return;
@@ -547,15 +546,11 @@ void SwAttrHandler::ActivateTop( SwFont& rFnt, const sal_uInt16 nAttr )
 
         if ( pRotateAttr )
         {
-            const SfxPoolItem* pRotateItem = CharFormat::GetItem( *pRotateAttr, RES_CHRATR_ROTATE );
-            rFnt.SetVertical( static_cast<const SvxCharRotateItem*>(pRotateItem)->GetValue(),
-                               m_bVertLayout );
+            const auto& rRotateItem = CharFormat::GetItem( *pRotateAttr, RES_CHRATR_ROTATE )->StaticWhichCast(RES_CHRATR_ROTATE);
+            rFnt.SetVertical( rRotateItem.GetValue(), m_bVertLayout );
         }
         else
-            rFnt.SetVertical(
-                static_cast<const SvxCharRotateItem*>(m_pDefaultArray[ nRotateStack ])->GetValue(),
-                 m_bVertLayout
-            );
+            rFnt.SetVertical( m_pDefaultArray[ nRotateStack ]->StaticWhichCast(RES_CHRATR_ROTATE).GetValue(), m_bVertLayout );
     }
     else if ( RES_TXTATR_INPUTFIELD == nAttr )
         rFnt.GetInputField()--;
@@ -571,42 +566,45 @@ void SwAttrHandler::FontChg(const SfxPoolItem& rItem, SwFont& rFnt, bool bPush )
     switch ( rItem.Which() )
     {
         case RES_CHRATR_CASEMAP :
-            rFnt.SetCaseMap( static_cast<const SvxCaseMapItem&>(rItem).GetCaseMap() );
+            rFnt.SetCaseMap( rItem.StaticWhichCast(RES_CHRATR_CASEMAP).GetCaseMap() );
             break;
         case RES_CHRATR_COLOR :
-            rFnt.SetColor( static_cast<const SvxColorItem&>(rItem).GetValue() );
+            rFnt.SetColor( rItem.StaticWhichCast(RES_CHRATR_COLOR).GetValue() );
             break;
         case RES_CHRATR_CONTOUR :
-            rFnt.SetOutline( static_cast<const SvxContourItem&>(rItem).GetValue() );
+            rFnt.SetOutline( rItem.StaticWhichCast(RES_CHRATR_CONTOUR).GetValue() );
             break;
         case RES_CHRATR_CROSSEDOUT :
-            rFnt.SetStrikeout( static_cast<const SvxCrossedOutItem&>(rItem).GetStrikeout() );
+            rFnt.SetStrikeout( rItem.StaticWhichCast(RES_CHRATR_CROSSEDOUT).GetStrikeout() );
             break;
         case RES_CHRATR_ESCAPEMENT :
-            rFnt.SetEscapement( static_cast<const SvxEscapementItem&>(rItem).GetEsc() );
-            rFnt.SetProportion( static_cast<const SvxEscapementItem&>(rItem).GetProportionalHeight() );
+            rFnt.SetEscapement( rItem.StaticWhichCast(RES_CHRATR_ESCAPEMENT).GetEsc() );
+            rFnt.SetProportion( rItem.StaticWhichCast(RES_CHRATR_ESCAPEMENT).GetProportionalHeight() );
             break;
         case RES_CHRATR_FONT :
-            rFnt.SetName( static_cast<const SvxFontItem&>(rItem).GetFamilyName(), SwFontScript::Latin );
-            rFnt.SetStyleName( static_cast<const SvxFontItem&>(rItem).GetStyleName(), SwFontScript::Latin );
-            rFnt.SetFamily( static_cast<const SvxFontItem&>(rItem).GetFamily(), SwFontScript::Latin );
-            rFnt.SetPitch( static_cast<const SvxFontItem&>(rItem).GetPitch(), SwFontScript::Latin );
-            rFnt.SetCharSet( static_cast<const SvxFontItem&>(rItem).GetCharSet(), SwFontScript::Latin );
+        {
+            auto& rFontItem = rItem.StaticWhichCast(RES_CHRATR_FONT);
+            rFnt.SetName( rFontItem.GetFamilyName(), SwFontScript::Latin );
+            rFnt.SetStyleName( rFontItem.GetStyleName(), SwFontScript::Latin );
+            rFnt.SetFamily( rFontItem.GetFamily(), SwFontScript::Latin );
+            rFnt.SetPitch( rFontItem.GetPitch(), SwFontScript::Latin );
+            rFnt.SetCharSet( rFontItem.GetCharSet(), SwFontScript::Latin );
             break;
+        }
         case RES_CHRATR_FONTSIZE :
-            rFnt.SetSize(Size(0,static_cast<const SvxFontHeightItem&>(rItem).GetHeight() ), SwFontScript::Latin );
+            rFnt.SetSize(Size(0, rItem.StaticWhichCast(RES_CHRATR_FONTSIZE).GetHeight() ), SwFontScript::Latin );
             break;
         case RES_CHRATR_KERNING :
-            rFnt.SetFixKerning( static_cast<const SvxKerningItem&>(rItem).GetValue() );
+            rFnt.SetFixKerning( rItem.StaticWhichCast(RES_CHRATR_KERNING).GetValue() );
             break;
         case RES_CHRATR_LANGUAGE :
-            rFnt.SetLanguage( static_cast<const SvxLanguageItem&>(rItem).GetLanguage(), SwFontScript::Latin );
+            rFnt.SetLanguage( rItem.StaticWhichCast(RES_CHRATR_LANGUAGE).GetLanguage(), SwFontScript::Latin );
             break;
         case RES_CHRATR_POSTURE :
-            rFnt.SetItalic( static_cast<const SvxPostureItem&>(rItem).GetPosture(), SwFontScript::Latin );
+            rFnt.SetItalic( rItem.StaticWhichCast(RES_CHRATR_POSTURE).GetPosture(), SwFontScript::Latin );
             break;
         case RES_CHRATR_SHADOWED :
-            rFnt.SetShadow( static_cast<const SvxShadowedItem&>(rItem).GetValue() );
+            rFnt.SetShadow( rItem.StaticWhichCast(RES_CHRATR_SHADOWED).GetValue() );
             break;
         case RES_CHRATR_UNDERLINE :
         {
@@ -618,16 +616,16 @@ void SwAttrHandler::FontChg(const SfxPoolItem& rItem, SwFont& rFnt, bool bPush )
                                           m_pDefaultArray[ nStackPos ];
 
             if ((m_pShell && !m_pShell->GetWin()) ||
-                (pTmpItem && !static_cast<const SvxCharHiddenItem*>(pTmpItem)->GetValue()) )
+                (pTmpItem && !pTmpItem->StaticWhichCast(RES_CHRATR_HIDDEN).GetValue()) )
             {
-                rFnt.SetUnderline( static_cast<const SvxUnderlineItem&>(rItem).GetLineStyle() );
-                rFnt.SetUnderColor( static_cast<const SvxUnderlineItem&>(rItem).GetColor() );
+                rFnt.SetUnderline( rItem.StaticWhichCast(RES_CHRATR_UNDERLINE).GetLineStyle() );
+                rFnt.SetUnderColor( rItem.StaticWhichCast(RES_CHRATR_UNDERLINE).GetColor() );
             }
             break;
         }
         case RES_CHRATR_BOX:
         {
-            const SvxBoxItem& aBoxItem = static_cast<const SvxBoxItem&>(rItem);
+            const SvxBoxItem& aBoxItem = rItem.StaticWhichCast(RES_CHRATR_BOX);
             rFnt.SetTopBorder( aBoxItem.GetTop() );
             rFnt.SetBottomBorder( aBoxItem.GetBottom() );
             rFnt.SetRightBorder( aBoxItem.GetRight() );
@@ -640,24 +638,24 @@ void SwAttrHandler::FontChg(const SfxPoolItem& rItem, SwFont& rFnt, bool bPush )
         }
         case RES_CHRATR_SHADOW:
         {
-            const SvxShadowItem& aShadowItem = static_cast<const SvxShadowItem&>(rItem);
+            const SvxShadowItem& aShadowItem = rItem.StaticWhichCast(RES_CHRATR_SHADOW);
             rFnt.SetShadowColor( aShadowItem.GetColor() );
             rFnt.SetShadowWidth( aShadowItem.GetWidth() );
             rFnt.SetShadowLocation( aShadowItem.GetLocation() );
             break;
         }
         case RES_CHRATR_OVERLINE :
-            rFnt.SetOverline( static_cast<const SvxOverlineItem&>(rItem).GetLineStyle() );
-            rFnt.SetOverColor( static_cast<const SvxOverlineItem&>(rItem).GetColor() );
+            rFnt.SetOverline( rItem.StaticWhichCast(RES_CHRATR_OVERLINE).GetLineStyle() );
+            rFnt.SetOverColor( rItem.StaticWhichCast(RES_CHRATR_OVERLINE).GetColor() );
             break;
         case RES_CHRATR_WEIGHT :
-            rFnt.SetWeight( static_cast<const SvxWeightItem&>(rItem).GetWeight(), SwFontScript::Latin );
+            rFnt.SetWeight( rItem.StaticWhichCast(RES_CHRATR_WEIGHT).GetWeight(), SwFontScript::Latin );
             break;
         case RES_CHRATR_WORDLINEMODE :
-            rFnt.SetWordLineMode( static_cast<const SvxWordLineModeItem&>(rItem).GetValue() );
+            rFnt.SetWordLineMode( rItem.StaticWhichCast(RES_CHRATR_WORDLINEMODE).GetValue() );
             break;
         case RES_CHRATR_AUTOKERN :
-            if( static_cast<const SvxAutoKernItem&>(rItem).GetValue() )
+            if( rItem.StaticWhichCast(RES_CHRATR_AUTOKERN).GetValue() )
             {
                 rFnt.SetAutoKern( (!m_pIDocumentSettingAccess ||
                                    !m_pIDocumentSettingAccess->get(DocumentSettingId::KERN_ASIAN_PUNCTUATION)) ?
@@ -668,64 +666,68 @@ void SwAttrHandler::FontChg(const SfxPoolItem& rItem, SwFont& rFnt, bool bPush )
                 rFnt.SetAutoKern( FontKerning::NONE );
             break;
         case RES_CHRATR_BACKGROUND :
-            rFnt.SetBackColor(static_cast<const SvxBrushItem&>(rItem).GetColor());
+            rFnt.SetBackColor(rItem.StaticWhichCast(RES_CHRATR_BACKGROUND).GetColor());
             break;
         case RES_CHRATR_HIGHLIGHT :
-            rFnt.SetHighlightColor( static_cast<const SvxBrushItem&>(rItem).GetColor() );
+            rFnt.SetHighlightColor( rItem.StaticWhichCast(RES_CHRATR_HIGHLIGHT).GetColor() );
             break;
         case RES_CHRATR_CJK_FONT :
-            rFnt.SetName( static_cast<const SvxFontItem&>(rItem).GetFamilyName(), SwFontScript::CJK );
-            rFnt.SetStyleName( static_cast<const SvxFontItem&>(rItem).GetStyleName(), SwFontScript::CJK );
-            rFnt.SetFamily( static_cast<const SvxFontItem&>(rItem).GetFamily(), SwFontScript::CJK );
-            rFnt.SetPitch( static_cast<const SvxFontItem&>(rItem).GetPitch(), SwFontScript::CJK );
-            rFnt.SetCharSet( static_cast<const SvxFontItem&>(rItem).GetCharSet(), SwFontScript::CJK );
+        {
+            auto& rFontItem = rItem.StaticWhichCast(RES_CHRATR_CJK_FONT);
+            rFnt.SetName( rFontItem.GetFamilyName(), SwFontScript::CJK );
+            rFnt.SetStyleName( rFontItem.GetStyleName(), SwFontScript::CJK );
+            rFnt.SetFamily( rFontItem.GetFamily(), SwFontScript::CJK );
+            rFnt.SetPitch( rFontItem.GetPitch(), SwFontScript::CJK );
+            rFnt.SetCharSet( rFontItem.GetCharSet(), SwFontScript::CJK );
             break;
+        }
         case RES_CHRATR_CJK_FONTSIZE :
-            rFnt.SetSize(Size( 0, static_cast<const SvxFontHeightItem&>(rItem).GetHeight()), SwFontScript::CJK);
+            rFnt.SetSize(Size( 0, rItem.StaticWhichCast(RES_CHRATR_CJK_FONTSIZE).GetHeight()), SwFontScript::CJK);
             break;
         case RES_CHRATR_CJK_LANGUAGE :
-            rFnt.SetLanguage( static_cast<const SvxLanguageItem&>(rItem).GetLanguage(), SwFontScript::CJK );
+            rFnt.SetLanguage( rItem.StaticWhichCast(RES_CHRATR_CJK_LANGUAGE).GetLanguage(), SwFontScript::CJK );
             break;
         case RES_CHRATR_CJK_POSTURE :
-            rFnt.SetItalic( static_cast<const SvxPostureItem&>(rItem).GetPosture(), SwFontScript::CJK );
+            rFnt.SetItalic( rItem.StaticWhichCast(RES_CHRATR_CJK_POSTURE).GetPosture(), SwFontScript::CJK );
             break;
         case RES_CHRATR_CJK_WEIGHT :
-            rFnt.SetWeight( static_cast<const SvxWeightItem&>(rItem).GetWeight(), SwFontScript::CJK );
+            rFnt.SetWeight( rItem.StaticWhichCast(RES_CHRATR_CJK_WEIGHT).GetWeight(), SwFontScript::CJK );
             break;
         case RES_CHRATR_CTL_FONT :
-            rFnt.SetName( static_cast<const SvxFontItem&>(rItem).GetFamilyName(), SwFontScript::CTL );
-            rFnt.SetStyleName( static_cast<const SvxFontItem&>(rItem).GetStyleName(), SwFontScript::CTL );
-            rFnt.SetFamily( static_cast<const SvxFontItem&>(rItem).GetFamily(), SwFontScript::CTL );
-            rFnt.SetPitch( static_cast<const SvxFontItem&>(rItem).GetPitch(), SwFontScript::CTL );
-            rFnt.SetCharSet( static_cast<const SvxFontItem&>(rItem).GetCharSet(), SwFontScript::CTL );
+        {
+            auto& rFontItem = rItem.StaticWhichCast(RES_CHRATR_CTL_FONT);
+            rFnt.SetName( rFontItem.GetFamilyName(), SwFontScript::CTL );
+            rFnt.SetStyleName( rFontItem.GetStyleName(), SwFontScript::CTL );
+            rFnt.SetFamily( rFontItem.GetFamily(), SwFontScript::CTL );
+            rFnt.SetPitch( rFontItem.GetPitch(), SwFontScript::CTL );
+            rFnt.SetCharSet( rFontItem.GetCharSet(), SwFontScript::CTL );
             break;
+        }
         case RES_CHRATR_CTL_FONTSIZE :
-            rFnt.SetSize(Size(0, static_cast<const SvxFontHeightItem&>(rItem).GetHeight() ), SwFontScript::CTL);
+            rFnt.SetSize(Size(0, rItem.StaticWhichCast(RES_CHRATR_CTL_FONTSIZE).GetHeight() ), SwFontScript::CTL);
             break;
         case RES_CHRATR_CTL_LANGUAGE :
-            rFnt.SetLanguage( static_cast<const SvxLanguageItem&>(rItem).GetLanguage(), SwFontScript::CTL );
+            rFnt.SetLanguage( rItem.StaticWhichCast(RES_CHRATR_CTL_LANGUAGE).GetLanguage(), SwFontScript::CTL );
             break;
         case RES_CHRATR_CTL_POSTURE :
-            rFnt.SetItalic( static_cast<const SvxPostureItem&>(rItem).GetPosture(), SwFontScript::CTL );
+            rFnt.SetItalic( rItem.StaticWhichCast(RES_CHRATR_CTL_POSTURE).GetPosture(), SwFontScript::CTL );
             break;
         case RES_CHRATR_CTL_WEIGHT :
-            rFnt.SetWeight( static_cast<const SvxWeightItem&>(rItem).GetWeight(), SwFontScript::CTL );
+            rFnt.SetWeight( rItem.StaticWhichCast(RES_CHRATR_CTL_WEIGHT).GetWeight(), SwFontScript::CTL );
             break;
         case RES_CHRATR_EMPHASIS_MARK :
-            rFnt.SetEmphasisMark(
-                     static_cast<const SvxEmphasisMarkItem&>(rItem).GetEmphasisMark()
-                     );
+            rFnt.SetEmphasisMark( rItem.StaticWhichCast(RES_CHRATR_EMPHASIS_MARK).GetEmphasisMark() );
             break;
         case RES_CHRATR_SCALEW :
-            rFnt.SetPropWidth( static_cast<const SvxCharScaleWidthItem&>(rItem).GetValue() );
+            rFnt.SetPropWidth( rItem.StaticWhichCast(RES_CHRATR_SCALEW).GetValue() );
             break;
         case RES_CHRATR_RELIEF :
-            rFnt.SetRelief( static_cast<const SvxCharReliefItem&>(rItem).GetValue() );
+            rFnt.SetRelief( rItem.StaticWhichCast(RES_CHRATR_RELIEF).GetValue() );
             break;
         case RES_CHRATR_HIDDEN :
             if (m_pShell && m_pShell->GetWin())
             {
-                if ( static_cast<const SvxCharHiddenItem&>(rItem).GetValue() )
+                if ( rItem.StaticWhichCast(RES_CHRATR_HIDDEN).GetValue() )
                     rFnt.SetUnderline( LINESTYLE_DOTTED );
                 else
                     ActivateTop( rFnt, RES_CHRATR_UNDERLINE );
@@ -749,16 +751,14 @@ void SwAttrHandler::FontChg(const SfxPoolItem& rItem, SwFont& rFnt, bool bPush )
 
             if ( pTwoLineAttr )
             {
-                const SfxPoolItem* pTwoLineItem = CharFormat::GetItem( *pTwoLineAttr, RES_CHRATR_TWO_LINES );
-                bTwoLineAct = static_cast<const SvxTwoLinesItem*>(pTwoLineItem)->GetValue();
+                const auto& rTwoLineItem = CharFormat::GetItem( *pTwoLineAttr, RES_CHRATR_TWO_LINES )->StaticWhichCast(RES_CHRATR_TWO_LINES);
+                bTwoLineAct = rTwoLineItem.GetValue();
             }
             else
-                bTwoLineAct =
-                    static_cast<const SvxTwoLinesItem*>(m_pDefaultArray[ nTwoLineStack ])->GetValue();
+                bTwoLineAct = m_pDefaultArray[ nTwoLineStack ]->StaticWhichCast(RES_CHRATR_TWO_LINES).GetValue();
 
             if ( !bTwoLineAct )
-                rFnt.SetVertical( static_cast<const SvxCharRotateItem&>(rItem).GetValue(),
-                                   m_bVertLayout, m_bVertLayoutLRBT );
+                rFnt.SetVertical( rItem.StaticWhichCast(RES_CHRATR_ROTATE).GetValue(), m_bVertLayout, m_bVertLayoutLRBT );
 
             break;
         }
@@ -770,7 +770,7 @@ void SwAttrHandler::FontChg(const SfxPoolItem& rItem, SwFont& rFnt, bool bPush )
             // two line is activated, if
             // 1. no ruby attribute is set and
             // 2. attribute is active
-            if ( !bRuby && static_cast<const SvxTwoLinesItem&>(rItem).GetValue() )
+            if ( !bRuby && rItem.StaticWhichCast(RES_CHRATR_TWO_LINES).GetValue() )
             {
                 rFnt.SetVertical( 0_deg10, m_bVertLayout );
                 break;
@@ -786,15 +786,11 @@ void SwAttrHandler::FontChg(const SfxPoolItem& rItem, SwFont& rFnt, bool bPush )
 
             if ( pRotateAttr )
             {
-                const SfxPoolItem* pRotateItem = CharFormat::GetItem( *pRotateAttr, RES_CHRATR_ROTATE );
-                rFnt.SetVertical( static_cast<const SvxCharRotateItem*>(pRotateItem)->GetValue(),
-                                   m_bVertLayout );
+                const auto& rRotateItem = CharFormat::GetItem( *pRotateAttr, RES_CHRATR_ROTATE )->StaticWhichCast(RES_CHRATR_ROTATE);
+                rFnt.SetVertical( rRotateItem.GetValue(), m_bVertLayout );
             }
             else
-                rFnt.SetVertical(
-                    static_cast<const SvxCharRotateItem*>(m_pDefaultArray[ nRotateStack ])->GetValue(),
-                     m_bVertLayout
-                );
+                rFnt.SetVertical(m_pDefaultArray[ nRotateStack ]->StaticWhichCast(RES_CHRATR_ROTATE).GetValue(), m_bVertLayout);
             break;
         }
         case RES_TXTATR_CJK_RUBY :
diff --git a/sw/source/filter/ww8/ww8atr.cxx b/sw/source/filter/ww8/ww8atr.cxx
index e7c2b0e71c63..a536d444c5c3 100644
--- a/sw/source/filter/ww8/ww8atr.cxx
+++ b/sw/source/filter/ww8/ww8atr.cxx
@@ -224,12 +224,12 @@ void MSWordExportBase::ExportPoolItemsToCHP( ww8::PoolItems &rItems, sal_uInt16
 
                  if (pINetItem)
                  {
-                     const SwFormatINetFormat& rINet = static_cast<const SwFormatINetFormat&>(*pINetItem);
+                     const SwFormatINetFormat& rINet = pINetItem->StaticWhichCast(RES_TXTATR_INETFMT);
                      const SwCharFormat* pINetFormat = GetSwCharFormat(rINet, m_rDoc);
                      if (!pINetFormat)
                          continue;
 
-                     const SwCharFormat* pFormat = static_cast<const SwFormatCharFormat&>(*pItem).GetCharFormat();
+                     const SwCharFormat* pFormat = pItem->StaticWhichCast(RES_TXTATR_CHARFMT).GetCharFormat();
                      ww8::PoolItems aCharItems, aINetItems;
                      GetPoolItems(pFormat->GetAttrSet(), aCharItems, false);
                      GetPoolItems(pINetFormat->GetAttrSet(), aINetItems, false);
@@ -264,11 +264,11 @@ void MSWordExportBase::ExportPoolItemsToCHP( ww8::PoolItems &rItems, sal_uInt16
              }
              else if (nWhich == RES_CHRATR_COLOR)
              {
-                const SvxColorItem& rColor = static_cast<const SvxColorItem&>(*pItem);
+                const SvxColorItem& rColor = pItem->StaticWhichCast(RES_CHRATR_COLOR);
                 const SfxPoolItem* pBackgroundItem = SearchPoolItems(rItems, RES_CHRATR_BACKGROUND);
                 if (rColor.GetValue() == COL_AUTO && pBackgroundItem)
                 {
-                    const SvxBrushItem& rBrushBackground = static_cast<const SvxBrushItem&>(*pBackgroundItem);
+                    const SvxBrushItem& rBrushBackground = pBackgroundItem->StaticWhichCast(RES_CHRATR_BACKGROUND);
                     SvxColorItem aForeground(rBrushBackground.GetColor().IsDark() ? COL_WHITE : COL_BLACK, RES_CHRATR_COLOR);
                     AttrOutput().OutputItem(aForeground);
                 }
@@ -280,7 +280,7 @@ void MSWordExportBase::ExportPoolItemsToCHP( ww8::PoolItems &rItems, sal_uInt16
              }
              else if (nWhich == RES_CHRATR_HIGHLIGHT)
              {
-                const SvxBrushItem& rBrush = static_cast< const SvxBrushItem& >( *pItem );
+                const SvxBrushItem& rBrush = pItem->StaticWhichCast(RES_CHRATR_HIGHLIGHT);
                 // The UI easily adds unnecessary highlights, so identify and avoid exporting those.
                 // Highlight is not valid in character styles, so must not check there.
                 // Check the (para) style hierarchy to find the nearest defined highlight.
@@ -337,7 +337,7 @@ void MSWordExportBase::OutputItemSet( const SfxItemSet& rSet, bool bPapFormat, b
         AttrOutput().OutputItem( *pItem );
 
         // switch off the numbering?
-        if ( static_cast<const SwNumRuleItem*>(pItem)->GetValue().isEmpty() &&
+        if ( pItem->StaticWhichCast(RES_PARATR_NUMRULE).GetValue().isEmpty() &&
              SfxItemState::SET != rSet.GetItemState( RES_LR_SPACE, false) &&
              SfxItemState::SET == rSet.GetItemState( RES_LR_SPACE, true, &pItem ) )
         {
@@ -501,7 +501,7 @@ void MSWordExportBase::OutputSectionBreaks( const SfxItemSet *pSet, const SwNode
     if ( pSet && pSet->Count() )
     {
         if ( SfxItemState::SET == pSet->GetItemState( RES_PAGEDESC, false, &pItem ) &&
-             static_cast<const SwFormatPageDesc*>(pItem)->GetRegisteredIn() != nullptr)
+             pItem->StaticWhichCast(RES_PAGEDESC).GetRegisteredIn() != nullptr)
         {
             bBreakSet = true;
             bNewPageDesc = true;
@@ -1261,10 +1261,17 @@ void WW8AttributeOutput::CharUnderline( const SvxUnderlineItem& rUnderline )
 {
     m_rWW8Export.InsUInt16( NS_sprm::CKul::val );
 
-    const SfxPoolItem* pItem = m_rWW8Export.HasItem( RES_CHRATR_WORDLINEMODE );
+    // FIXME: this should likely be a StaticWhichCast(), but some we put something dirty in RES_CHRATR_WORDLINEMODE apparently
+    const auto pItem = m_rWW8Export.HasItem(RES_CHRATR_WORDLINEMODE);
     bool bWord = false;
-    if (pItem)
-        bWord = static_cast<const SvxWordLineModeItem*>(pItem)->GetValue();
+    if(pItem)
+    {
+        const auto pWordline = pItem->DynamicWhichCast(RES_CHRATR_WORDLINEMODE);
+        if(pWordline)
+            bWord = pWordline->GetValue();
+        else
+            SAL_WARN("sw.ww8", "m_rWW8Export has an RES_CHRATR_WORDLINEMODE item, but its of the wrong type.");
+    }
 
     // WW95 - parameters:   0 = none,   1 = single, 2 = by Word,
     //                      3 = double, 4 = dotted, 5 = hidden
@@ -4555,9 +4562,9 @@ void WW8AttributeOutput::FormatBox( const SvxBoxItem& rBox )
     const SfxPoolItem* pItem = m_rWW8Export.HasItem( RES_SHADOW );
     if ( pItem )
     {
-        const SvxShadowItem* p = static_cast<const SvxShadowItem*>(pItem);
-        bShadow = ( p->GetLocation() != SvxShadowLocation::NONE )
-                  && ( p->GetWidth() != 0 );
+        const SvxShadowItem& rShadow = pItem->StaticWhichCast(RES_SHADOW);
+        bShadow = ( rShadow.GetLocation() != SvxShadowLocation::NONE )
+                  && ( rShadow.GetWidth() != 0 );
     }
 
     SvxBoxItem aBox(rBox);
@@ -5163,10 +5170,14 @@ void WW8AttributeOutput::ParaTabStop( const SvxTabStopItem& rTabStops )
     tools::Long nCurrentLeft = 0;
     if ( bTabsRelativeToIndex )
     {
-        const SfxPoolItem* pLR = m_rWW8Export.HasItem( RES_LR_SPACE );
-
-        if ( pLR != nullptr )
-            nCurrentLeft = static_cast<const SvxLRSpaceItem*>(pLR)->GetTextLeft();
+        if(const SfxPoolItem* pItem = m_rWW8Export.HasItem( RES_LR_SPACE ))
+        {
+            if(const auto pLR = pItem->DynamicWhichCast(RES_LR_SPACE))
+                nCurrentLeft = pLR->GetTextLeft();
+            else
+                // FIXME: This fails in sw.ww8export/testCommentExport::Load_Verify_Reload_Verify
+                SAL_WARN("sw.ww8", "m_rWW8Export has an RES_LR_SPACE item, but its of the wrong type.");
+        }
     }
 
     // #i100264#
@@ -5226,16 +5237,16 @@ void AttributeOutputBase::OutputItem( const SfxPoolItem& rHt )
     switch ( rHt.Which() )
     {
         case RES_CHRATR_CASEMAP:
-            CharCaseMap( static_cast< const SvxCaseMapItem& >( rHt ) );
+            CharCaseMap(rHt.StaticWhichCast(RES_CHRATR_CASEMAP));
             break;
         case RES_CHRATR_COLOR:
-            CharColor( static_cast< const SvxColorItem& >( rHt ) );
+            CharColor(rHt.StaticWhichCast(RES_CHRATR_COLOR));
             break;
         case RES_CHRATR_CONTOUR:
-            CharContour( static_cast< const SvxContourItem& >( rHt ) );
+            CharContour(rHt.StaticWhichCast(RES_CHRATR_CONTOUR));
             break;
         case RES_CHRATR_CROSSEDOUT:
-            CharCrossedOut( static_cast< const SvxCrossedOutItem& >( rHt ) );
+            CharCrossedOut(rHt.StaticWhichCast(RES_CHRATR_CROSSEDOUT));
             break;
         case RES_CHRATR_ESCAPEMENT:
             CharEscapement( static_cast< const SvxEscapementItem& >( rHt ) );
diff --git a/sw/source/uibase/utlui/uitool.cxx b/sw/source/uibase/utlui/uitool.cxx
index c55acb7241f0..d61e44e3408f 100644
--- a/sw/source/uibase/utlui/uitool.cxx
+++ b/sw/source/uibase/utlui/uitool.cxx
@@ -109,7 +109,7 @@ void ConvertAttrCharToGen(SfxItemSet& rSet, bool bIsPara)
         const SfxPoolItem *pTmpBrush;
         if( SfxItemState::SET == rSet.GetItemState( RES_CHRATR_HIGHLIGHT, true, &pTmpBrush ) )
         {
-            SvxBrushItem aTmpBrush( *static_cast<const SvxBrushItem*>(pTmpBrush) );
+            SvxBrushItem aTmpBrush( pTmpBrush->StaticWhichCast(RES_CHRATR_HIGHLIGHT) );
             if( aTmpBrush.GetColor() != COL_TRANSPARENT )
             {
                 aTmpBrush.SetWhich( RES_CHRATR_BACKGROUND );
@@ -151,7 +151,7 @@ void ConvertAttrGenToChar(SfxItemSet& rSet, const SfxItemSet& rOrigSet, bool bIs
         // Remove shading marker
         if (SfxItemState::SET == rOrigSet.GetItemState(RES_CHRATR_GRABBAG, false, &pTmpItem))
         {
-            SfxGrabBagItem aGrabBag(*static_cast<const SfxGrabBagItem*>(pTmpItem));
+            SfxGrabBagItem aGrabBag(pTmpItem->StaticWhichCast(RES_CHRATR_GRABBAG));
             std::map<OUString, css::uno::Any>& rMap = aGrabBag.GetGrabBag();
             auto aIterator = rMap.find("CharShadingMarker");
             if( aIterator != rMap.end() )
@@ -169,7 +169,7 @@ void ConvertAttrGenToChar(SfxItemSet& rSet, const SfxItemSet& rOrigSet, bool bIs
 
     if (SfxItemState::SET == rOrigSet.GetItemState(RES_PARATR_GRABBAG, false, &pTmpItem))
     {
-        SfxGrabBagItem aGrabBag(*static_cast<const SfxGrabBagItem*>(pTmpItem));
+        SfxGrabBagItem aGrabBag(pTmpItem->StaticWhichCast(RES_PARATR_GRABBAG));
         std::map<OUString, css::uno::Any>& rMap = aGrabBag.GetGrabBag();
         auto aIterator = rMap.find("OrigItemSetRanges");
         if (aIterator != rMap.end())
@@ -203,7 +203,7 @@ void ApplyCharBackground(const Color& rBackgroundColor, SwWrtShell& rShell)
     const SfxPoolItem *pTmpItem;
     if (SfxItemState::SET == aCoreSet.GetItemState(RES_CHRATR_GRABBAG, false, &pTmpItem))
     {
-        SfxGrabBagItem aGrabBag(*static_cast<const SfxGrabBagItem*>(pTmpItem));
+        SfxGrabBagItem aGrabBag(pTmpItem->StaticWhichCast(RES_CHRATR_GRABBAG));
         std::map<OUString, css::uno::Any>& rMap = aGrabBag.GetGrabBag();
         auto aIterator = rMap.find("CharShadingMarker");
         if (aIterator != rMap.end())
@@ -639,9 +639,10 @@ void SfxToSwPageDescAttr( const SwWrtShell& rShell, SfxItemSet& rSet )
         rShell.GetCurAttr( aCoreSet );
         if(SfxItemState::SET == aCoreSet.GetItemState( RES_PAGEDESC, true, &pItem ) )
         {
-            if( static_cast<const SwFormatPageDesc*>(pItem)->GetPageDesc() )
+            auto pPageDesc = pItem->StaticWhichCast(RES_PAGEDESC).GetPageDesc();
+            if( pPageDesc )
             {
-                aPgDesc.RegisterToPageDesc( *const_cast<SwFormatPageDesc*>(static_cast<const SwFormatPageDesc*>(pItem))->GetPageDesc() );
+                aPgDesc.RegisterToPageDesc( *const_cast<SwPageDesc*>(pPageDesc) );
             }
         }
     }
@@ -661,10 +662,11 @@ void SwToSfxPageDescAttr( SfxItemSet& rCoreSet )
     {
     case SfxItemState::SET:
         {
-            if( static_cast<const SwFormatPageDesc*>(pItem)->GetPageDesc() )
+            auto rPageDescItem = pItem->StaticWhichCast(RES_PAGEDESC);
+            if( rPageDescItem.GetPageDesc() )
             {
-                aName = static_cast<const SwFormatPageDesc*>(pItem)->GetPageDesc()->GetName();
-                oNumOffset = static_cast<const SwFormatPageDesc*>(pItem)->GetNumOffset();
+                aName = rPageDescItem.GetPageDesc()->GetName();
+                oNumOffset = rPageDescItem.GetNumOffset();
             }
             rCoreSet.ClearItem( RES_PAGEDESC );
             // Page number


More information about the Libreoffice-commits mailing list