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

Noel (via logerrit) logerrit at kemper.freedesktop.org
Tue Oct 13 08:35:00 UTC 2020


 sc/source/ui/sidebar/AlignmentPropertyPanel.cxx |    8 +--
 sc/source/ui/undo/areasave.cxx                  |   12 +---
 sc/source/ui/undo/undoblk.cxx                   |   63 ++++++++++++------------
 sc/source/ui/undo/undoblk2.cxx                  |    4 -
 sc/source/ui/undo/undoblk3.cxx                  |   42 ++++++++--------
 sc/source/ui/undo/undocell.cxx                  |   20 +++----
 sw/source/core/layout/objectformatter.cxx       |   29 +++++------
 sw/source/core/layout/pagechg.cxx               |   37 +++++---------
 sw/source/core/layout/paintfrm.cxx              |   27 ++++------
 sw/source/core/layout/sectfrm.cxx               |   16 +++---
 sw/source/core/layout/ssfrm.cxx                 |   12 ++--
 sw/source/core/layout/tabfrm.cxx                |    6 --
 sw/source/core/layout/trvlfrm.cxx               |    8 +--
 sw/source/core/layout/wsfrm.cxx                 |   23 +++-----
 sw/source/core/sw3io/swacorr.cxx                |    6 +-
 sw/source/core/text/itrcrsr.cxx                 |    4 -
 sw/source/core/text/porfly.cxx                  |    6 +-
 sw/source/core/text/porrst.cxx                  |    3 -
 sw/source/core/text/txtfrm.cxx                  |    3 -
 sw/source/core/undo/rolbck.cxx                  |   10 +--
 20 files changed, 157 insertions(+), 182 deletions(-)

New commits:
commit c93cdd4e2416c81ccc4b90fd96421d7e45cecd70
Author:     Noel <noelgrandin at gmail.com>
AuthorDate: Tue Oct 13 09:45:36 2020 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Tue Oct 13 10:34:24 2020 +0200

    static_cast after dynamic_cast
    
    Change-Id: If1194bd3364fef8b2d0c26c22854745d0fb7b412
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104223
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sc/source/ui/sidebar/AlignmentPropertyPanel.cxx b/sc/source/ui/sidebar/AlignmentPropertyPanel.cxx
index 6a6bee924459..90e72f5bf1f8 100644
--- a/sc/source/ui/sidebar/AlignmentPropertyPanel.cxx
+++ b/sc/source/ui/sidebar/AlignmentPropertyPanel.cxx
@@ -245,11 +245,9 @@ void AlignmentPropertyPanel::NotifyItemUpdate(
     case SID_H_ALIGNCELL:
         {
             SvxCellHorJustify meHorAlignState = SvxCellHorJustify::Standard;
-            if(eState >= SfxItemState::DEFAULT && dynamic_cast<const SvxHorJustifyItem*>( pState) )
-            {
-                const SvxHorJustifyItem* pItem = static_cast<const SvxHorJustifyItem*>(pState);
-                meHorAlignState = pItem->GetValue();
-            }
+            if(eState >= SfxItemState::DEFAULT)
+                if (auto pItem = dynamic_cast<const SvxHorJustifyItem*>( pState) )
+                    meHorAlignState = pItem->GetValue();
 
             if( meHorAlignState == SvxCellHorJustify::Repeat )
             {
diff --git a/sc/source/ui/undo/areasave.cxx b/sc/source/ui/undo/areasave.cxx
index e250aac70e60..3d50fba4f826 100644
--- a/sc/source/ui/undo/areasave.cxx
+++ b/sc/source/ui/undo/areasave.cxx
@@ -92,9 +92,9 @@ bool ScAreaLinkSaveCollection::IsEqual( const ScDocument* pDoc ) const
         for (sal_uInt16 i=0; i<nLinkCount; i++)
         {
             ::sfx2::SvBaseLink* pBase = rLinks[i].get();
-            if (dynamic_cast<const ScAreaLink*>( pBase) !=  nullptr)
+            if (auto pAreaLink = dynamic_cast<ScAreaLink*>( pBase))
             {
-                if ( nPos >= size() || !(*this)[nPos].IsEqual( *static_cast<ScAreaLink*>(pBase) ) )
+                if ( nPos >= size() || !(*this)[nPos].IsEqual( *pAreaLink ) )
                     return false;
 
                 ++nPos;
@@ -113,11 +113,9 @@ static ScAreaLink* lcl_FindLink( const ::sfx2::SvBaseLinks& rLinks, const ScArea
     for (sal_uInt16 i=0; i<nLinkCount; i++)
     {
         ::sfx2::SvBaseLink* pBase = rLinks[i].get();
-        if ( dynamic_cast<const ScAreaLink*>( pBase) !=  nullptr &&
-             rSaver.IsEqualSource( *static_cast<ScAreaLink*>(pBase) ) )
-        {
-            return static_cast<ScAreaLink*>(pBase);     // found
-        }
+        if ( auto pAreaLink = dynamic_cast<ScAreaLink*>( pBase) )
+            if ( rSaver.IsEqualSource( *pAreaLink ) )
+                return pAreaLink;     // found
     }
     return nullptr;    // not found
 }
diff --git a/sc/source/ui/undo/undoblk.cxx b/sc/source/ui/undo/undoblk.cxx
index 36c016c0a8b5..be9e606b4915 100644
--- a/sc/source/ui/undo/undoblk.cxx
+++ b/sc/source/ui/undo/undoblk.cxx
@@ -107,20 +107,20 @@ bool ScUndoInsertCells::Merge( SfxUndoAction* pNextAction )
     if ( pPasteUndo )
         return pPasteUndo->Merge( pNextAction );
 
-    if ( bPartOfPaste && dynamic_cast<const ScUndoWrapper*>( pNextAction) !=  nullptr )
-    {
-        ScUndoWrapper* pWrapper = static_cast<ScUndoWrapper*>(pNextAction);
-        SfxUndoAction* pWrappedAction = pWrapper->GetWrappedUndo();
-        if ( dynamic_cast<const ScUndoPaste*>( pWrappedAction) )
+    if ( bPartOfPaste )
+        if ( auto pWrapper = dynamic_cast<ScUndoWrapper*>( pNextAction) )
         {
-            //  Store paste action if this is part of paste with inserting cells.
-            //  A list action isn't used because Repeat wouldn't work (insert wrong cells).
+            SfxUndoAction* pWrappedAction = pWrapper->GetWrappedUndo();
+            if ( dynamic_cast<const ScUndoPaste*>( pWrappedAction) )
+            {
+                //  Store paste action if this is part of paste with inserting cells.
+                //  A list action isn't used because Repeat wouldn't work (insert wrong cells).
 
-            pPasteUndo.reset( pWrappedAction );
-            pWrapper->ForgetWrappedUndo();      // pWrapper is deleted by UndoManager
-            return true;
+                pPasteUndo.reset( pWrappedAction );
+                pWrapper->ForgetWrappedUndo();      // pWrapper is deleted by UndoManager
+                return true;
+            }
         }
-    }
 
     //  Call base class for detective handling
     return ScMoveUndo::Merge( pNextAction );
@@ -627,8 +627,8 @@ void ScUndoDeleteCells::Redo()
 
 void ScUndoDeleteCells::Repeat(SfxRepeatTarget& rTarget)
 {
-    if (dynamic_cast<const ScTabViewTarget*>( &rTarget) !=  nullptr)
-        static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->DeleteCells( eCmd );
+    if (auto pViewTarget = dynamic_cast<ScTabViewTarget*>( &rTarget) )
+        pViewTarget->GetViewShell()->DeleteCells( eCmd );
 }
 
 bool ScUndoDeleteCells::CanRepeat(SfxRepeatTarget& rTarget) const
@@ -904,8 +904,8 @@ void ScUndoCut::Redo()
 
 void ScUndoCut::Repeat(SfxRepeatTarget& rTarget)
 {
-    if (dynamic_cast<const ScTabViewTarget*>( &rTarget) !=  nullptr)
-        static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->CutToClip();
+    if (auto pViewTarget = dynamic_cast<ScTabViewTarget*>( &rTarget))
+        pViewTarget->GetViewShell()->CutToClip();
 }
 
 bool ScUndoCut::CanRepeat(SfxRepeatTarget& rTarget) const
@@ -1169,10 +1169,11 @@ void ScUndoPaste::Redo()
 
 void ScUndoPaste::Repeat(SfxRepeatTarget& rTarget)
 {
-    if (dynamic_cast<const ScTabViewTarget*>( &rTarget) ==  nullptr)
+    auto pViewTarget = dynamic_cast<ScTabViewTarget*>( &rTarget);
+    if (!pViewTarget)
         return;
 
-    ScTabViewShell* pViewSh = static_cast<ScTabViewTarget&>(rTarget).GetViewShell();
+    ScTabViewShell* pViewSh = pViewTarget->GetViewShell();
     // keep a reference in case the clipboard is changed during PasteFromClip
     const ScTransferObj* pOwnClip = ScTransferObj::GetOwnClipboard(ScTabViewShell::GetClipData(pViewSh->GetViewData().GetActiveWin()));
     if (pOwnClip)
@@ -1758,18 +1759,18 @@ void ScUndoUseScenario::Redo()
 
 void ScUndoUseScenario::Repeat(SfxRepeatTarget& rTarget)
 {
-    if (dynamic_cast<const ScTabViewTarget*>( &rTarget) !=  nullptr)
+    if (auto pViewTarget = dynamic_cast<ScTabViewTarget*>( &rTarget))
     {
         OUString aTemp = aName;
-        static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->UseScenario(aTemp);
+        pViewTarget->GetViewShell()->UseScenario(aTemp);
     }
 }
 
 bool ScUndoUseScenario::CanRepeat(SfxRepeatTarget& rTarget) const
 {
-    if (dynamic_cast<const ScTabViewTarget*>( &rTarget) !=  nullptr)
+    if (auto pViewTarget = dynamic_cast<ScTabViewTarget*>( &rTarget))
     {
-        ScViewData& rViewData = static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->GetViewData();
+        ScViewData& rViewData = pViewTarget->GetViewShell()->GetViewData();
         return !rViewData.GetDocument().IsScenario( rViewData.GetTabNo() );
     }
     return false;
@@ -2019,8 +2020,8 @@ void ScUndoIndent::Redo()
 
 void ScUndoIndent::Repeat(SfxRepeatTarget& rTarget)
 {
-    if (dynamic_cast<const ScTabViewTarget*>( &rTarget) !=  nullptr)
-        static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->ChangeIndent( bIsIncrement );
+    if (auto pViewTarget = dynamic_cast<ScTabViewTarget*>( &rTarget))
+        pViewTarget->GetViewShell()->ChangeIndent( bIsIncrement );
 }
 
 bool ScUndoIndent::CanRepeat(SfxRepeatTarget& rTarget) const
@@ -2074,8 +2075,8 @@ void ScUndoTransliterate::Redo()
 
 void ScUndoTransliterate::Repeat(SfxRepeatTarget& rTarget)
 {
-    if (dynamic_cast<const ScTabViewTarget*>( &rTarget) !=  nullptr)
-        static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->TransliterateText( nTransliterationType );
+    if (auto pViewTarget = dynamic_cast<ScTabViewTarget*>( &rTarget))
+        pViewTarget->GetViewShell()->TransliterateText( nTransliterationType );
 }
 
 bool ScUndoTransliterate::CanRepeat(SfxRepeatTarget& rTarget) const
@@ -2132,9 +2133,9 @@ void ScUndoClearItems::Redo()
 
 void ScUndoClearItems::Repeat(SfxRepeatTarget& rTarget)
 {
-    if (dynamic_cast<const ScTabViewTarget*>( &rTarget) !=  nullptr)
+    if (auto pViewTarget = dynamic_cast<ScTabViewTarget*>( &rTarget))
     {
-        ScViewData& rViewData = static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->GetViewData();
+        ScViewData& rViewData = pViewTarget->GetViewShell()->GetViewData();
         rViewData.GetDocFunc().ClearItems( rViewData.GetMarkData(), pWhich.get(), false );
     }
 }
@@ -2195,9 +2196,9 @@ void ScUndoRemoveBreaks::Redo()
 
 void ScUndoRemoveBreaks::Repeat(SfxRepeatTarget& rTarget)
 {
-    if (dynamic_cast<const ScTabViewTarget*>( &rTarget) !=  nullptr)
+    if (auto pViewTarget = dynamic_cast<ScTabViewTarget*>( &rTarget))
     {
-        ScTabViewShell& rViewShell = *static_cast<ScTabViewTarget&>(rTarget).GetViewShell();
+        ScTabViewShell& rViewShell = *pViewTarget->GetViewShell();
         rViewShell.RemoveManualBreaks();
     }
 }
@@ -2325,8 +2326,8 @@ void ScUndoRemoveMerge::Redo()
 
 void ScUndoRemoveMerge::Repeat(SfxRepeatTarget& rTarget)
 {
-    if (dynamic_cast<const ScTabViewTarget*>( &rTarget) !=  nullptr)
-        static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->RemoveMerge();
+    if (auto pViewTarget = dynamic_cast<ScTabViewTarget*>( &rTarget))
+        pViewTarget->GetViewShell()->RemoveMerge();
 }
 
 bool ScUndoRemoveMerge::CanRepeat(SfxRepeatTarget& rTarget) const
diff --git a/sc/source/ui/undo/undoblk2.cxx b/sc/source/ui/undo/undoblk2.cxx
index 7e13a13ef25a..149da08b5be2 100644
--- a/sc/source/ui/undo/undoblk2.cxx
+++ b/sc/source/ui/undo/undoblk2.cxx
@@ -174,8 +174,8 @@ void ScUndoWidthOrHeight::Redo()
 
 void ScUndoWidthOrHeight::Repeat(SfxRepeatTarget& rTarget)
 {
-    if (dynamic_cast<const ScTabViewTarget*>( &rTarget) !=  nullptr)
-        static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->SetMarkedWidthOrHeight( bWidth, eMode, nNewSize );
+    if (auto pViewTarget = dynamic_cast<ScTabViewTarget*>( &rTarget))
+        pViewTarget->GetViewShell()->SetMarkedWidthOrHeight( bWidth, eMode, nNewSize );
 }
 
 bool ScUndoWidthOrHeight::CanRepeat(SfxRepeatTarget& rTarget) const
diff --git a/sc/source/ui/undo/undoblk3.cxx b/sc/source/ui/undo/undoblk3.cxx
index 4c966c4ae890..ef0a5eff9738 100644
--- a/sc/source/ui/undo/undoblk3.cxx
+++ b/sc/source/ui/undo/undoblk3.cxx
@@ -190,8 +190,8 @@ void ScUndoDeleteContents::Redo()
 
 void ScUndoDeleteContents::Repeat(SfxRepeatTarget& rTarget)
 {
-    if (dynamic_cast<const ScTabViewTarget*>( &rTarget) !=  nullptr)
-        static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->DeleteContents( nFlags );
+    if (auto pViewTarget = dynamic_cast<ScTabViewTarget*>( &rTarget))
+        pViewTarget->GetViewShell()->DeleteContents( nFlags );
 }
 
 bool ScUndoDeleteContents::CanRepeat(SfxRepeatTarget& rTarget) const
@@ -326,8 +326,8 @@ void ScUndoFillTable::Redo()
 
 void ScUndoFillTable::Repeat(SfxRepeatTarget& rTarget)
 {
-    if (dynamic_cast<const ScTabViewTarget*>( &rTarget) !=  nullptr)
-        static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->FillTab( nFlags, nFunction, bSkipEmpty, bAsLink );
+    if (auto pViewTarget = dynamic_cast<ScTabViewTarget*>( &rTarget))
+        pViewTarget->GetViewShell()->FillTab( nFlags, nFunction, bSkipEmpty, bAsLink );
 }
 
 bool ScUndoFillTable::CanRepeat(SfxRepeatTarget& rTarget) const
@@ -462,9 +462,9 @@ void ScUndoSelectionAttr::Redo()
 
 void ScUndoSelectionAttr::Repeat(SfxRepeatTarget& rTarget)
 {
-    if (dynamic_cast<const ScTabViewTarget*>( &rTarget) !=  nullptr)
+    if (auto pViewTarget = dynamic_cast<ScTabViewTarget*>( &rTarget))
     {
-        ScTabViewShell& rViewShell = *static_cast<ScTabViewTarget&>(rTarget).GetViewShell();
+        ScTabViewShell& rViewShell = *pViewTarget->GetViewShell();
         if (pLineOuter)
             rViewShell.ApplyPatternLines(*pApplyPattern, *pLineOuter, pLineInner);
         else
@@ -615,9 +615,9 @@ void ScUndoAutoFill::Redo()
 
 void ScUndoAutoFill::Repeat(SfxRepeatTarget& rTarget)
 {
-    if (dynamic_cast<const ScTabViewTarget*>( &rTarget) !=  nullptr)
+    if (auto pViewTarget = dynamic_cast<ScTabViewTarget*>( &rTarget))
     {
-        ScTabViewShell& rViewShell = *static_cast<ScTabViewTarget&>(rTarget).GetViewShell();
+        ScTabViewShell& rViewShell = *pViewTarget->GetViewShell();
         if (eFillCmd==FILL_SIMPLE)
             rViewShell.FillSimple( eFillDir );
         else
@@ -748,9 +748,9 @@ void ScUndoMerge::Redo()
 
 void ScUndoMerge::Repeat(SfxRepeatTarget& rTarget)
 {
-    if (dynamic_cast<const ScTabViewTarget*>( &rTarget) !=  nullptr)
+    if (auto pViewTarget = dynamic_cast<ScTabViewTarget*>( &rTarget))
     {
-        ScTabViewShell& rViewShell = *static_cast<ScTabViewTarget&>(rTarget).GetViewShell();
+        ScTabViewShell& rViewShell = *pViewTarget->GetViewShell();
         bool bCont = false;
         rViewShell.MergeCells( false, bCont, false );
     }
@@ -902,8 +902,8 @@ void ScUndoAutoFormat::Redo()
 
 void ScUndoAutoFormat::Repeat(SfxRepeatTarget& rTarget)
 {
-    if (dynamic_cast<const ScTabViewTarget*>( &rTarget) !=  nullptr)
-        static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->AutoFormat( nFormatNo );
+    if (auto pViewTarget = dynamic_cast<ScTabViewTarget*>( &rTarget))
+        pViewTarget->GetViewShell()->AutoFormat( nFormatNo );
 }
 
 bool ScUndoAutoFormat::CanRepeat(SfxRepeatTarget& rTarget) const
@@ -1081,8 +1081,8 @@ void ScUndoReplace::Redo()
 
 void ScUndoReplace::Repeat(SfxRepeatTarget& rTarget)
 {
-    if (dynamic_cast<const ScTabViewTarget*>( &rTarget) !=  nullptr)
-        static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->SearchAndReplace( pSearchItem.get(), true, false );
+    if (auto pViewTarget = dynamic_cast<ScTabViewTarget*>( &rTarget))
+        pViewTarget->GetViewShell()->SearchAndReplace( pSearchItem.get(), true, false );
 }
 
 bool ScUndoReplace::CanRepeat(SfxRepeatTarget& rTarget) const
@@ -1266,8 +1266,8 @@ void ScUndoConversion::Redo()
 
 void ScUndoConversion::Repeat( SfxRepeatTarget& rTarget )
 {
-    if( dynamic_cast<const ScTabViewTarget*>( &rTarget) !=  nullptr )
-        static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->DoSheetConversion( maConvParam );
+    if( auto pViewTarget = dynamic_cast<ScTabViewTarget*>( &rTarget) )
+        pViewTarget->GetViewShell()->DoSheetConversion( maConvParam );
 }
 
 bool ScUndoConversion::CanRepeat(SfxRepeatTarget& rTarget) const
@@ -1352,8 +1352,8 @@ void ScUndoRefConversion::Redo()
 
 void ScUndoRefConversion::Repeat(SfxRepeatTarget& rTarget)
 {
-    if (dynamic_cast<const ScTabViewTarget*>( &rTarget) !=  nullptr)
-        static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->DoRefConversion();
+    if (auto pViewTarget = dynamic_cast<ScTabViewTarget*>( &rTarget))
+        pViewTarget->GetViewShell()->DoRefConversion();
 }
 
 bool ScUndoRefConversion::CanRepeat(SfxRepeatTarget& rTarget) const
@@ -1471,9 +1471,9 @@ static ScAreaLink* lcl_FindAreaLink( const sfx2::LinkManager* pLinkManager, cons
     for (sal_uInt16 i=0; i<nCount; i++)
     {
         ::sfx2::SvBaseLink* pBase = rLinks[i].get();
-        if (dynamic_cast<const ScAreaLink*>( pBase) !=  nullptr)
-            if ( static_cast<ScAreaLink*>(pBase)->IsEqual( rDoc, rFlt, rOpt, rSrc, rDest ) )
-                return static_cast<ScAreaLink*>(pBase);
+        if (auto pAreaLink = dynamic_cast<ScAreaLink*>( pBase))
+            if ( pAreaLink->IsEqual( rDoc, rFlt, rOpt, rSrc, rDest ) )
+                return pAreaLink;
     }
 
     OSL_FAIL("ScAreaLink not found");
diff --git a/sc/source/ui/undo/undocell.cxx b/sc/source/ui/undo/undocell.cxx
index b34426c8f4d9..2e82399c879e 100644
--- a/sc/source/ui/undo/undocell.cxx
+++ b/sc/source/ui/undo/undocell.cxx
@@ -145,8 +145,8 @@ void ScUndoCursorAttr::Redo()
 
 void ScUndoCursorAttr::Repeat(SfxRepeatTarget& rTarget)
 {
-    if (dynamic_cast<const ScTabViewTarget*>( &rTarget) !=  nullptr)
-        static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->ApplySelectionPattern( *pApplyPattern );
+    if (auto pViewTarget = dynamic_cast<ScTabViewTarget*>( &rTarget))
+        pViewTarget->GetViewShell()->ApplySelectionPattern( *pApplyPattern );
 }
 
 bool ScUndoCursorAttr::CanRepeat(SfxRepeatTarget& rTarget) const
@@ -291,10 +291,10 @@ void ScUndoEnterData::Redo()
 
 void ScUndoEnterData::Repeat(SfxRepeatTarget& rTarget)
 {
-    if (dynamic_cast<const ScTabViewTarget*>( &rTarget) !=  nullptr)
+    if (auto pViewTarget = dynamic_cast<ScTabViewTarget*>( &rTarget))
     {
         OUString aTemp = maNewString;
-        static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->EnterDataAtCursor( aTemp );
+        pViewTarget->GetViewShell()->EnterDataAtCursor( aTemp );
     }
 }
 
@@ -551,9 +551,9 @@ void ScUndoPageBreak::Redo()
 
 void ScUndoPageBreak::Repeat(SfxRepeatTarget& rTarget)
 {
-    if (dynamic_cast<const ScTabViewTarget*>( &rTarget) !=  nullptr)
+    if (auto pViewTarget = dynamic_cast<ScTabViewTarget*>( &rTarget))
     {
-        ScTabViewShell& rViewShell = *static_cast<ScTabViewTarget&>(rTarget).GetViewShell();
+        ScTabViewShell& rViewShell = *pViewTarget->GetViewShell();
 
         if (bInsert)
             rViewShell.InsertPageBreak(bColumn);
@@ -624,9 +624,9 @@ void ScUndoPrintZoom::Redo()
 
 void ScUndoPrintZoom::Repeat(SfxRepeatTarget& rTarget)
 {
-    if (dynamic_cast<const ScTabViewTarget*>( &rTarget) !=  nullptr)
+    if (auto pViewTarget = dynamic_cast<ScTabViewTarget*>( &rTarget))
     {
-        ScTabViewShell& rViewShell = *static_cast<ScTabViewTarget&>(rTarget).GetViewShell();
+        ScTabViewShell& rViewShell = *pViewTarget->GetViewShell();
         ScViewData& rViewData = rViewShell.GetViewData();
         rViewData.GetDocShell()->SetPrintZoom( rViewData.GetTabNo(), nNewScale, nNewPages );
     }
@@ -709,8 +709,8 @@ void ScUndoThesaurus::Redo()
 
 void ScUndoThesaurus::Repeat(SfxRepeatTarget& rTarget)
 {
-    if (dynamic_cast<const ScTabViewTarget*>( &rTarget) !=  nullptr)
-        static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->DoThesaurus();
+    if (auto pViewTarget = dynamic_cast<ScTabViewTarget*>( &rTarget))
+        pViewTarget->GetViewShell()->DoThesaurus();
 }
 
 bool ScUndoThesaurus::CanRepeat(SfxRepeatTarget& rTarget) const
diff --git a/sw/source/core/layout/objectformatter.cxx b/sw/source/core/layout/objectformatter.cxx
index e48439a2bdf0..ca7d713273d4 100644
--- a/sw/source/core/layout/objectformatter.cxx
+++ b/sw/source/core/layout/objectformatter.cxx
@@ -267,13 +267,12 @@ void SwObjectFormatter::FormatObj_( SwAnchoredObject& _rAnchoredObj )
         mpPgNumAndTypeOfAnchors->Collect( _rAnchoredObj );
     }
 
-    if ( dynamic_cast<const SwFlyFrame*>( &_rAnchoredObj) !=  nullptr )
+    if ( auto pFlyFrame = dynamic_cast<SwFlyFrame*>( &_rAnchoredObj) )
     {
-        SwFlyFrame& rFlyFrame = static_cast<SwFlyFrame&>(_rAnchoredObj);
         // --> #i34753# - reset flag, which prevents a positioning
-        if ( rFlyFrame.IsFlyLayFrame() )
+        if ( pFlyFrame->IsFlyLayFrame() )
         {
-            static_cast<SwFlyLayFrame&>(rFlyFrame).SetNoMakePos( false );
+            static_cast<SwFlyLayFrame*>(pFlyFrame)->SetNoMakePos( false );
         }
 
         // #i81146# new loop control
@@ -283,7 +282,7 @@ void SwObjectFormatter::FormatObj_( SwAnchoredObject& _rAnchoredObj )
         do {
             if ( mpLayAction )
             {
-                mpLayAction->FormatLayoutFly( &rFlyFrame );
+                mpLayAction->FormatLayoutFly( pFlyFrame );
                 // --> consider, if the layout action
                 // has to be restarted due to a delete of a page frame.
                 if ( mpLayAction->IsAgain() )
@@ -293,22 +292,22 @@ void SwObjectFormatter::FormatObj_( SwAnchoredObject& _rAnchoredObj )
             }
             else
             {
-                FormatLayout_( rFlyFrame );
+                FormatLayout_( *pFlyFrame );
             }
             // --> #i34753# - prevent further positioning, if
             // to-page|to-fly anchored Writer fly frame is already clipped.
-            if ( rFlyFrame.IsFlyLayFrame() && rFlyFrame.IsClipped() )
+            if ( pFlyFrame->IsFlyLayFrame() && pFlyFrame->IsClipped() )
             {
-                static_cast<SwFlyLayFrame&>(rFlyFrame).SetNoMakePos( true );
+                static_cast<SwFlyLayFrame*>(pFlyFrame)->SetNoMakePos( true );
             }
             // #i23129#, #i36347# - pass correct page frame
             // to the object formatter
-            SwObjectFormatter::FormatObjsAtFrame( rFlyFrame,
-                                                *(rFlyFrame.FindPageFrame()),
+            SwObjectFormatter::FormatObjsAtFrame( *pFlyFrame,
+                                                *(pFlyFrame->FindPageFrame()),
                                                 mpLayAction );
             if ( mpLayAction )
             {
-                mpLayAction->FormatFlyContent( &rFlyFrame );
+                mpLayAction->FormatFlyContent( pFlyFrame );
                 // --> consider, if the layout action
                 // has to be restarted due to a delete of a page frame.
                 if ( mpLayAction->IsAgain() )
@@ -318,21 +317,21 @@ void SwObjectFormatter::FormatObj_( SwAnchoredObject& _rAnchoredObj )
             }
             else
             {
-                FormatObjContent( rFlyFrame );
+                FormatObjContent( *pFlyFrame );
             }
 
             if ( ++nLoopControlRuns >= nLoopControlMax )
             {
                 OSL_FAIL( "LoopControl in SwObjectFormatter::FormatObj_: Stage 3!!!" );
-                rFlyFrame.ValidateThisAndAllLowers( 2 );
+                pFlyFrame->ValidateThisAndAllLowers( 2 );
                 nLoopControlRuns = 0;
             }
 
         // --> #i57917#
         // stop formatting of anchored object, if restart of layout process is requested.
-        } while ( !rFlyFrame.isFrameAreaDefinitionValid() &&
+        } while ( !pFlyFrame->isFrameAreaDefinitionValid() &&
                   !_rAnchoredObj.RestartLayoutProcess() &&
-                  rFlyFrame.GetAnchorFrame() == &GetAnchorFrame() );
+                  pFlyFrame->GetAnchorFrame() == &GetAnchorFrame() );
     }
     else if ( dynamic_cast<const SwAnchoredDrawObject*>( &_rAnchoredObj) !=  nullptr )
     {
diff --git a/sw/source/core/layout/pagechg.cxx b/sw/source/core/layout/pagechg.cxx
index eee3bfb9ade5..73ca8c534e5f 100644
--- a/sw/source/core/layout/pagechg.cxx
+++ b/sw/source/core/layout/pagechg.cxx
@@ -430,9 +430,8 @@ static void lcl_MakeObjs( const SwFrameFormats &rTable, SwPageFrame *pPage )
                 // OD 23.06.2003 #108784# - consider 'virtual' drawing objects
                 SwDrawContact *pContact =
                             static_cast<SwDrawContact*>(::GetUserCall(pSdrObj));
-                if ( dynamic_cast< const SwDrawVirtObj *>( pSdrObj ) !=  nullptr )
+                if ( auto pDrawVirtObj = dynamic_cast<SwDrawVirtObj *>( pSdrObj ) )
                 {
-                    SwDrawVirtObj* pDrawVirtObj = static_cast<SwDrawVirtObj*>(pSdrObj);
                     if ( pContact )
                     {
                         pDrawVirtObj->RemoveFromWriterLayout();
@@ -851,9 +850,8 @@ void SwPageFrame::Cut()
                 // #i28701#
                 SwAnchoredObject* pAnchoredObj = (*GetSortedObjs())[i];
 
-                if ( dynamic_cast< const SwFlyAtContentFrame *>( pAnchoredObj ) !=  nullptr )
+                if ( auto pFly = dynamic_cast<SwFlyAtContentFrame *>( pAnchoredObj ) )
                 {
-                    SwFlyFrame* pFly = static_cast<SwFlyAtContentFrame*>(pAnchoredObj);
                     SwPageFrame *pAnchPage = pFly->GetAnchorFrame() ?
                                 pFly->AnchorFrame()->FindPageFrame() : nullptr;
                     if ( pAnchPage && (pAnchPage != this) )
@@ -949,9 +947,8 @@ static void lcl_PrepFlyInCntRegister( SwContentFrame *pFrame )
     for(SwAnchoredObject* pAnchoredObj : *pFrame->GetDrawObjs())
     {
         // #i28701#
-        if ( dynamic_cast< const SwFlyInContentFrame *>( pAnchoredObj ) !=  nullptr )
+        if ( auto pFly = dynamic_cast<SwFlyInContentFrame *>( pAnchoredObj ) )
         {
-            SwFlyFrame* pFly = static_cast<SwFlyInContentFrame*>(pAnchoredObj);
             SwContentFrame *pCnt = pFly->ContainsContent();
             while ( pCnt )
             {
@@ -978,9 +975,8 @@ void SwPageFrame::PrepareRegisterChg()
     for(SwAnchoredObject* pAnchoredObj : *GetSortedObjs())
     {
         // #i28701#
-        if ( dynamic_cast< const SwFlyFrame *>( pAnchoredObj ) !=  nullptr )
+        if ( auto pFly = dynamic_cast<SwFlyFrame *>( pAnchoredObj ) )
         {
-            SwFlyFrame *pFly = static_cast<SwFlyFrame*>(pAnchoredObj);
             pFrame = pFly->ContainsContent();
             while ( pFrame )
             {
@@ -1867,8 +1863,8 @@ void SwRootFrame::StartAllAction()
     if ( GetCurrShell() )
         for(SwViewShell& rSh : GetCurrShell()->GetRingContainer())
         {
-            if ( dynamic_cast<const SwCursorShell*>( &rSh) !=  nullptr )
-                static_cast<SwCursorShell*>(&rSh)->StartAction();
+            if ( auto pCursorShell = dynamic_cast<SwCursorShell*>( &rSh) )
+                pCursorShell->StartAction();
             else
                 rSh.StartAction();
         }
@@ -1883,12 +1879,12 @@ void SwRootFrame::EndAllAction( bool bVirDev )
     {
         const bool bOldEndActionByVirDev = rSh.IsEndActionByVirDev();
         rSh.SetEndActionByVirDev( bVirDev );
-        if ( dynamic_cast<const SwCursorShell*>( &rSh) !=  nullptr )
+        if ( auto pCursorShell = dynamic_cast<SwCursorShell*>( &rSh) )
         {
-            static_cast<SwCursorShell*>(&rSh)->EndAction();
-            static_cast<SwCursorShell*>(&rSh)->CallChgLnk();
-            if ( dynamic_cast<const SwFEShell*>( &rSh) !=  nullptr )
-                static_cast<SwFEShell*>(&rSh)->SetChainMarker();
+            pCursorShell->EndAction();
+            pCursorShell->CallChgLnk();
+            if ( auto pFEShell = dynamic_cast<SwFEShell*>( &rSh) )
+                pFEShell->SetChainMarker();
         }
         else
             rSh.EndAction();
@@ -1941,8 +1937,8 @@ void SwRootFrame::UnoRestoreAllActions()
         sal_uInt16 nActions = rSh.GetRestoreActions();
         while( nActions-- )
         {
-            if ( dynamic_cast<const SwCursorShell*>( &rSh) !=  nullptr )
-                static_cast<SwCursorShell*>(&rSh)->StartAction();
+            if ( auto pCursorShell = dynamic_cast<SwCursorShell*>( &rSh) )
+                pCursorShell->StartAction();
             else
                 rSh.StartAction();
         }
@@ -1979,9 +1975,8 @@ static void lcl_MoveAllLowerObjs( SwFrame* pFrame, const Point& rOffset )
 
         SwObjPositioningInProgress aPosInProgress( *pAnchoredObj );
 
-        if ( dynamic_cast< const SwFlyFrame *>( pAnchoredObj ) != nullptr )
+        if ( auto pFlyFrame = dynamic_cast<SwFlyFrame *>( pAnchoredObj ) )
         {
-            SwFlyFrame* pFlyFrame( static_cast<SwFlyFrame*>(pAnchoredObj) );
             lcl_MoveAllLowers( pFlyFrame, rOffset );
             pFlyFrame->NotifyDrawObj();
             // --> let the active embedded object be moved
@@ -2010,10 +2005,8 @@ static void lcl_MoveAllLowerObjs( SwFrame* pFrame, const Point& rOffset )
                 }
             }
         }
-        else if ( dynamic_cast< const SwAnchoredDrawObject *>( pAnchoredObj ) !=  nullptr )
+        else if ( auto pAnchoredDrawObj = dynamic_cast<SwAnchoredDrawObject *>( pAnchoredObj ) )
         {
-            SwAnchoredDrawObject* pAnchoredDrawObj( static_cast<SwAnchoredDrawObject*>(pAnchoredObj) );
-
             // don't touch objects that are not yet positioned:
             if ( pAnchoredDrawObj->NotYetPositioned() )
                 continue;
diff --git a/sw/source/core/layout/paintfrm.cxx b/sw/source/core/layout/paintfrm.cxx
index bbb6868a235f..39bc05d4d806 100644
--- a/sw/source/core/layout/paintfrm.cxx
+++ b/sw/source/core/layout/paintfrm.cxx
@@ -1395,11 +1395,10 @@ static void lcl_SubtractFlys( const SwFrame *pFrame, const SwPageFrame *pPage,
         if (!pPage->GetFormat()->GetDoc()->getIDocumentDrawModelAccess().IsVisibleLayerId(pSdrObj->GetLayer()))
             continue;
 
-        if (dynamic_cast< const SwFlyFrame *>( pAnchoredObj ) ==  nullptr)
+        const SwFlyFrame *pFly = dynamic_cast<const SwFlyFrame*>(pAnchoredObj);
+        if (!pFly)
             continue;
 
-        const SwFlyFrame *pFly = static_cast<const SwFlyFrame*>(pAnchoredObj);
-
         if (pSelfFly == pFly || gProp.pSRetoucheFly == pFly || !rRect.IsOver(pFly->getFrameArea()))
             continue;
 
@@ -3815,9 +3814,9 @@ bool SwFlyFrame::IsPaint( SdrObject *pObj, const SwViewShell *pSh )
         {
             bPaint = false;
         }
-        if ( dynamic_cast< const SwVirtFlyDrawObj *>( pObj ) !=  nullptr )
+        if ( auto pFlyDraw = dynamic_cast<SwVirtFlyDrawObj *>( pObj ) )
         {
-            SwFlyFrame *pFly = static_cast<SwVirtFlyDrawObj*>(pObj)->GetFlyFrame();
+            SwFlyFrame *pFly = pFlyDraw->GetFlyFrame();
             if ( gProp.pSFlyOnlyDraw && gProp.pSFlyOnlyDraw == pFly )
                 return true;
 
@@ -6472,18 +6471,16 @@ void SwLayoutFrame::RefreshLaySubsidiary( const SwPageFrame *pPage,
                 for (SwAnchoredObject* pAnchoredObj : rObjs)
                 {
                     if ( pPage->GetFormat()->GetDoc()->getIDocumentDrawModelAccess().IsVisibleLayerId(
-                                    pAnchoredObj->GetDrawObj()->GetLayer() ) &&
-                         dynamic_cast< const SwFlyFrame *>( pAnchoredObj ) !=  nullptr )
-                    {
-                        const SwFlyFrame *pFly =
-                                    static_cast<const SwFlyFrame*>(pAnchoredObj);
-                        if ( pFly->IsFlyInContentFrame() && pFly->getFrameArea().IsOver( rRect ) )
+                                    pAnchoredObj->GetDrawObj()->GetLayer() ) )
+                        if (auto pFly = dynamic_cast< const SwFlyFrame *>( pAnchoredObj ) )
                         {
-                            if ( !pFly->Lower() || !pFly->Lower()->IsNoTextFrame() ||
-                                 !static_cast<const SwNoTextFrame*>(pFly->Lower())->HasAnimation())
-                                pFly->RefreshLaySubsidiary( pPage, rRect );
+                            if ( pFly->IsFlyInContentFrame() && pFly->getFrameArea().IsOver( rRect ) )
+                            {
+                                if ( !pFly->Lower() || !pFly->Lower()->IsNoTextFrame() ||
+                                     !static_cast<const SwNoTextFrame*>(pFly->Lower())->HasAnimation())
+                                    pFly->RefreshLaySubsidiary( pPage, rRect );
+                            }
                         }
-                    }
                 }
             }
         }
diff --git a/sw/source/core/layout/sectfrm.cxx b/sw/source/core/layout/sectfrm.cxx
index 2e5ebf3f1c29..e6daa4b65ee8 100644
--- a/sw/source/core/layout/sectfrm.cxx
+++ b/sw/source/core/layout/sectfrm.cxx
@@ -866,8 +866,8 @@ const SwSectionFormat* SwSectionFrame::GetEndSectFormat_() const
     const SwSectionFormat *pFormat = m_pSection->GetFormat();
     while( !pFormat->GetEndAtTextEnd().IsAtEnd() )
     {
-        if( dynamic_cast< const SwSectionFormat *>( pFormat->GetRegisteredIn()) !=  nullptr )
-            pFormat = static_cast<const SwSectionFormat*>(pFormat->GetRegisteredIn());
+        if( auto pNewFormat = dynamic_cast< const SwSectionFormat *>( pFormat->GetRegisteredIn()) )
+            pFormat = pNewFormat;
         else
             return nullptr;
     }
@@ -2515,8 +2515,8 @@ bool SwSectionFrame::IsDescendantFrom( const SwSectionFormat* pFormat ) const
     const SwSectionFormat *pMyFormat = m_pSection->GetFormat();
     while( pFormat != pMyFormat )
     {
-        if( dynamic_cast< const SwSectionFormat *>( pMyFormat->GetRegisteredIn()) !=  nullptr )
-            pMyFormat = static_cast<const SwSectionFormat*>(pMyFormat->GetRegisteredIn());
+        if( auto pNewFormat = dynamic_cast< const SwSectionFormat *>( pMyFormat->GetRegisteredIn()) )
+            pMyFormat = pNewFormat;
         else
             return false;
     }
@@ -2532,8 +2532,8 @@ void SwSectionFrame::CalcFootnoteAtEndFlag()
                  FTNEND_ATTXTEND_OWNNUMANDFMT == nVal;
     while( !m_bFootnoteAtEnd && !m_bOwnFootnoteNum )
     {
-        if( dynamic_cast< const SwSectionFormat *>( pFormat->GetRegisteredIn()) !=  nullptr )
-            pFormat = static_cast<SwSectionFormat*>(pFormat->GetRegisteredIn());
+        if( auto pNewFormat = dynamic_cast<SwSectionFormat *>( pFormat->GetRegisteredIn()) )
+            pFormat = pNewFormat;
         else
             break;
         nVal = pFormat->GetFootnoteAtTextEnd( false ).GetValue();
@@ -2557,8 +2557,8 @@ void SwSectionFrame::CalcEndAtEndFlag()
     m_bEndnAtEnd = pFormat->GetEndAtTextEnd( false ).IsAtEnd();
     while( !m_bEndnAtEnd )
     {
-        if( dynamic_cast< const SwSectionFormat *>( pFormat->GetRegisteredIn()) !=  nullptr )
-            pFormat = static_cast<SwSectionFormat*>(pFormat->GetRegisteredIn());
+        if( auto pNewFormat = dynamic_cast<SwSectionFormat *>( pFormat->GetRegisteredIn()) )
+            pFormat = pNewFormat;
         else
             break;
         m_bEndnAtEnd = pFormat->GetEndAtTextEnd( false ).IsAtEnd();
diff --git a/sw/source/core/layout/ssfrm.cxx b/sw/source/core/layout/ssfrm.cxx
index 602ccab141b6..7fe3bc82b9fa 100644
--- a/sw/source/core/layout/ssfrm.cxx
+++ b/sw/source/core/layout/ssfrm.cxx
@@ -265,8 +265,8 @@ void SwFrame::CheckDirChange()
     for ( size_t i = 0; i < nCnt; ++i )
     {
         SwAnchoredObject* pAnchoredObj = (*pObjs)[i];
-        if( dynamic_cast< const SwFlyFrame *>( pAnchoredObj ) !=  nullptr )
-            static_cast<SwFlyFrame*>(pAnchoredObj)->CheckDirChange();
+        if( auto pFlyFrame = dynamic_cast<SwFlyFrame *>( pAnchoredObj ) )
+            pFlyFrame->CheckDirChange();
         else
         {
             // OD 2004-04-06 #i26791# - direct object
@@ -349,9 +349,9 @@ void SwFrame::DestroyImpl()
     for (size_t i = m_pDrawObjs->size(); i; )
     {
         SwAnchoredObject* pAnchoredObj = (*m_pDrawObjs)[--i];
-        if ( dynamic_cast< const SwFlyFrame *>( pAnchoredObj ) !=  nullptr )
+        if ( auto pFlyFrame = dynamic_cast<SwFlyFrame *>( pAnchoredObj ) )
         {
-            SwFrame::DestroyFrame(static_cast<SwFlyFrame*>(pAnchoredObj));
+            SwFrame::DestroyFrame(pFlyFrame);
         }
         else
         {
@@ -532,9 +532,9 @@ void SwLayoutFrame::DestroyImpl()
 
             // #i28701#
             SwAnchoredObject* pAnchoredObj = (*GetDrawObjs())[0];
-            if ( dynamic_cast< const SwFlyFrame *>( pAnchoredObj ) !=  nullptr )
+            if ( auto pFlyFrame = dynamic_cast<SwFlyFrame *>( pAnchoredObj ) )
             {
-                SwFrame::DestroyFrame(static_cast<SwFlyFrame*>(pAnchoredObj));
+                SwFrame::DestroyFrame(pFlyFrame);
                 assert(!GetDrawObjs() || nCnt > GetDrawObjs()->size());
             }
             else
diff --git a/sw/source/core/layout/tabfrm.cxx b/sw/source/core/layout/tabfrm.cxx
index 288ac0e760c8..103f8260037a 100644
--- a/sw/source/core/layout/tabfrm.cxx
+++ b/sw/source/core/layout/tabfrm.cxx
@@ -2746,9 +2746,8 @@ bool SwTabFrame::CalcFlyOffsets( SwTwips& rUpper,
         for ( size_t i = 0; i < pPage->GetSortedObjs()->size(); ++i )
         {
             SwAnchoredObject* pAnchoredObj = (*pPage->GetSortedObjs())[i];
-            if ( dynamic_cast< const SwFlyFrame *>( pAnchoredObj ) !=  nullptr )
+            if ( auto pFly = dynamic_cast<SwFlyFrame *>( pAnchoredObj ) )
             {
-                SwFlyFrame *pFly = static_cast<SwFlyFrame*>(pAnchoredObj);
                 const SwRect aFlyRect = pFly->GetObjRectWithSpaces();
                 // #i26945# - correction of conditions,
                 // if Writer fly frame has to be considered:
@@ -4868,9 +4867,8 @@ static bool lcl_ArrangeLowers( SwLayoutFrame *pLay, long lYStart, bool bInva )
                             default: break;
                         }
                     }
-                    if ( dynamic_cast< const SwFlyFrame *>( pAnchoredObj ) !=  nullptr )
+                    if ( auto pFly = dynamic_cast<SwFlyFrame *>( pAnchoredObj ) )
                     {
-                        SwFlyFrame *pFly = static_cast<SwFlyFrame*>(pAnchoredObj);
 
                         // OD 2004-05-18 #i28701# - no direct move of objects,
                         // which are anchored to-paragraph/to-character, if
diff --git a/sw/source/core/layout/trvlfrm.cxx b/sw/source/core/layout/trvlfrm.cxx
index 30633ba4bd2d..745cec996b5c 100644
--- a/sw/source/core/layout/trvlfrm.cxx
+++ b/sw/source/core/layout/trvlfrm.cxx
@@ -388,9 +388,9 @@ bool SwPageFrame::FillSelection( SwSelectionList& rList, const SwRect& rRect ) c
             const SwSortedObjs &rObjs = *GetSortedObjs();
             for (SwAnchoredObject* pAnchoredObj : rObjs)
             {
-                if( dynamic_cast< const SwFlyFrame *>( pAnchoredObj ) ==  nullptr )
+                const SwFlyFrame* pFly = dynamic_cast<const SwFlyFrame*>(pAnchoredObj);
+                if( !pFly )
                     continue;
-                const SwFlyFrame* pFly = static_cast<const SwFlyFrame*>(pAnchoredObj);
                 if( pFly->FillSelection( rList, rRect ) )
                     bRet = true;
             }
@@ -2568,9 +2568,9 @@ void SwRootFrame::CalcFrameRects(SwShellCursor &rCursor)
             const SwSortedObjs &rObjs = *pPage->GetSortedObjs();
             for (SwAnchoredObject* pAnchoredObj : rObjs)
             {
-                if ( dynamic_cast< const SwFlyFrame *>( pAnchoredObj ) ==  nullptr )
+                const SwFlyFrame* pFly = dynamic_cast<const SwFlyFrame*>(pAnchoredObj);
+                if ( !pFly )
                     continue;
-                const SwFlyFrame* pFly = static_cast<const SwFlyFrame*>(pAnchoredObj);
                 const SwVirtFlyDrawObj* pObj = pFly->GetVirtDrawObj();
                 const SwFormatSurround &rSur = pFly->GetFormat()->GetSurround();
                 SwFormatAnchor const& rAnchor(pAnchoredObj->GetFrameFormat().GetAnchor());
diff --git a/sw/source/core/layout/wsfrm.cxx b/sw/source/core/layout/wsfrm.cxx
index 70e3fdfaa92f..254c1640392a 100644
--- a/sw/source/core/layout/wsfrm.cxx
+++ b/sw/source/core/layout/wsfrm.cxx
@@ -1875,9 +1875,8 @@ SwTwips SwFrame::AdjustNeighbourhood( SwTwips nDiff, bool bTst )
             OSL_ENSURE( pBoss->IsPageFrame(), "Header/Footer out of page?" );
             for (SwAnchoredObject* pAnchoredObj : rObjs)
             {
-                if ( dynamic_cast< const SwFlyFrame *>( pAnchoredObj ) !=  nullptr )
+                if ( auto pFly = dynamic_cast<SwFlyFrame *>( pAnchoredObj ) )
                 {
-                    SwFlyFrame* pFly = static_cast<SwFlyFrame*>(pAnchoredObj);
                     OSL_ENSURE( !pFly->IsFlyInContentFrame(), "FlyInCnt at Page?" );
                     const SwFormatVertOrient &rVert =
                                         pFly->GetFormat()->GetVertOrient();
@@ -2045,10 +2044,10 @@ void SwFrame::ValidateThisAndAllLowers( const sal_uInt16 nStage )
             for ( size_t i = 0; i < nCnt; ++i )
             {
                 SwAnchoredObject* pAnchObj = (*pObjs)[i];
-                if ( dynamic_cast< const SwFlyFrame *>( pAnchObj ) !=  nullptr )
-                    static_cast<SwFlyFrame*>(pAnchObj)->ValidateThisAndAllLowers( 2 );
-                else if ( dynamic_cast< const SwAnchoredDrawObject *>( pAnchObj ) !=  nullptr )
-                    static_cast<SwAnchoredDrawObject*>(pAnchObj)->ValidateThis();
+                if ( auto pFlyFrame = dynamic_cast<SwFlyFrame *>( pAnchObj ) )
+                    pFlyFrame->ValidateThisAndAllLowers( 2 );
+                else if ( auto pAnchoredDrawObj = dynamic_cast<SwAnchoredDrawObject *>( pAnchObj ) )
+                    pAnchoredDrawObj->ValidateThis();
             }
         }
     }
@@ -3478,9 +3477,8 @@ static void InvaPercentFlys( SwFrame *pFrame, SwTwips nDiff )
     OSL_ENSURE( pFrame->GetDrawObjs(), "Can't find any Objects" );
     for (SwAnchoredObject* pAnchoredObj : *pFrame->GetDrawObjs())
     {
-        if ( dynamic_cast< const SwFlyFrame *>( pAnchoredObj ) !=  nullptr )
+        if ( auto pFly = dynamic_cast<SwFlyFrame *>( pAnchoredObj ) )
         {
-            SwFlyFrame *pFly = static_cast<SwFlyFrame*>(pAnchoredObj);
             const SwFormatFrameSize &rSz = pFly->GetFormat()->GetFrameSize();
             if ( rSz.GetWidthPercent() || rSz.GetHeightPercent() )
             {
@@ -3610,9 +3608,8 @@ static bool lcl_IsFlyHeightClipped( SwLayoutFrame *pLay )
             for ( size_t i = 0; i < nCnt; ++i )
             {
                 SwAnchoredObject* pAnchoredObj = (*pFrame->GetDrawObjs())[i];
-                if ( dynamic_cast< const SwFlyFrame *>( pAnchoredObj ) !=  nullptr )
+                if ( auto pFly = dynamic_cast<SwFlyFrame *>( pAnchoredObj ) )
                 {
-                    SwFlyFrame* pFly = static_cast<SwFlyFrame*>(pAnchoredObj);
                     if ( pFly->IsHeightClipped() &&
                          ( !pFly->IsFlyFreeFrame() || pFly->GetPageFrame() ) )
                         return true;
@@ -4088,9 +4085,8 @@ static void lcl_InvalidateAllContent( SwContentFrame *pCnt, SwInvalidateFlags nI
     SwSortedObjs &rObjs = *pCnt->GetDrawObjs();
     for (SwAnchoredObject* pAnchoredObj : rObjs)
     {
-        if ( dynamic_cast< const SwFlyFrame *>( pAnchoredObj ) !=  nullptr )
+        if ( auto pFly = dynamic_cast<SwFlyFrame *>( pAnchoredObj ) )
         {
-            SwFlyFrame *pFly = static_cast<SwFlyFrame*>(pAnchoredObj);
             if ( pFly->IsFlyInContentFrame() )
             {
                 ::lcl_InvalidateContent( pFly->ContainsContent(), nInv );
@@ -4119,9 +4115,8 @@ void SwRootFrame::InvalidateAllContent( SwInvalidateFlags nInv )
             const SwSortedObjs &rObjs = *pPage->GetSortedObjs();
             for (SwAnchoredObject* pAnchoredObj : rObjs)
             {
-                if ( dynamic_cast< const SwFlyFrame *>( pAnchoredObj ) !=  nullptr )
+                if ( auto pFly = dynamic_cast<SwFlyFrame *>( pAnchoredObj ) )
                 {
-                    SwFlyFrame* pFly = static_cast<SwFlyFrame*>(pAnchoredObj);
                     ::lcl_InvalidateContent( pFly->ContainsContent(), nInv );
                     if ( nInv & SwInvalidateFlags::Direction )
                         pFly->CheckDirChange();
diff --git a/sw/source/core/sw3io/swacorr.cxx b/sw/source/core/sw3io/swacorr.cxx
index 19c0b236fa05..97fcc55431b0 100644
--- a/sw/source/core/sw3io/swacorr.cxx
+++ b/sw/source/core/sw3io/swacorr.cxx
@@ -64,10 +64,10 @@ bool SwAutoCorrect::PutText( const uno::Reference < embed::XStorage >&  rStg,
                                  const OUString& rFileName, const OUString& rShort,
                                  SfxObjectShell& rObjSh, OUString& rLong )
 {
-    if( nullptr == dynamic_cast<const SwDocShell*>( &rObjSh) )
+    SwDocShell* pDShell = dynamic_cast<SwDocShell*>(&rObjSh);
+    if( !pDShell )
         return false;
 
-    SwDocShell& rDShell = static_cast<SwDocShell&>(rObjSh);
     ErrCode nRet = ERRCODE_NONE;
 
     // mba: relative URLs don't make sense here
@@ -77,7 +77,7 @@ bool SwAutoCorrect::PutText( const uno::Reference < embed::XStorage >&  rStg,
     nRet = aBlk.BeginPutDoc( rShort, rShort );
     if( ! nRet.IsError() )
     {
-        rDShell.GetEditShell()->CopySelToDoc( *pDoc );
+        pDShell->GetEditShell()->CopySelToDoc( *pDoc );
         nRet = aBlk.PutDoc();
         aBlk.AddName ( rShort, rShort );
         if( ! nRet.IsError() )
diff --git a/sw/source/core/text/itrcrsr.cxx b/sw/source/core/text/itrcrsr.cxx
index 9ca00be6df8d..a7e7752796f7 100644
--- a/sw/source/core/text/itrcrsr.cxx
+++ b/sw/source/core/text/itrcrsr.cxx
@@ -1910,9 +1910,9 @@ bool SwTextFrame::FillSelection( SwSelectionList& rSelList, const SwRect& rRect
         const SwSortedObjs &rObjs = *GetDrawObjs();
         for (SwAnchoredObject* pAnchoredObj : rObjs)
         {
-            if( dynamic_cast< const SwFlyFrame *>( pAnchoredObj ) ==  nullptr )
+            const SwFlyFrame* pFly = dynamic_cast<const SwFlyFrame*>(pAnchoredObj);
+            if( !pFly )
                 continue;
-            const SwFlyFrame* pFly = static_cast<const SwFlyFrame*>(pAnchoredObj);
             if( pFly->IsFlyInContentFrame() && pFly->FillSelection( rSelList, rRect ) )
                 bRet = true;
         }
diff --git a/sw/source/core/text/porfly.cxx b/sw/source/core/text/porfly.cxx
index 8a34966b7873..a352984aba18 100644
--- a/sw/source/core/text/porfly.cxx
+++ b/sw/source/core/text/porfly.cxx
@@ -163,10 +163,10 @@ void SwTextFrame::MoveFlyInCnt(SwTextFrame *pNew,
             TextFrameIndex const nIndex(MapModelToViewPos(*pPos));
             if (nStart <= nIndex && nIndex < nEnd)
             {
-                if ( dynamic_cast< const SwFlyFrame *>( pAnchoredObj ) !=  nullptr )
+                if ( auto pFlyFrame = dynamic_cast<SwFlyFrame *>( pAnchoredObj ) )
                 {
-                    RemoveFly( static_cast<SwFlyFrame*>(pAnchoredObj) );
-                    pNew->AppendFly( static_cast<SwFlyFrame*>(pAnchoredObj) );
+                    RemoveFly( pFlyFrame );
+                    pNew->AppendFly( pFlyFrame );
                 }
                 else if ( dynamic_cast< const SwAnchoredDrawObject *>( pAnchoredObj ) !=  nullptr )
                 {
diff --git a/sw/source/core/text/porrst.cxx b/sw/source/core/text/porrst.cxx
index c37e03e7b3a4..ec7d14e5e605 100644
--- a/sw/source/core/text/porrst.cxx
+++ b/sw/source/core/text/porrst.cxx
@@ -205,8 +205,7 @@ SwTwips SwTextFrame::EmptyHeight() const
 {
     if (IsCollapse()) {
         SwViewShell *pSh = getRootFrame()->GetCurrShell();
-        if ( dynamic_cast<const SwCursorShell*>( pSh ) !=  nullptr ) {
-            SwCursorShell *pCrSh = static_cast<SwCursorShell*>(pSh);
+        if ( auto pCrSh = dynamic_cast<SwCursorShell*>( pSh ) ) {
             // this is called during formatting so avoid recursive layout
             SwContentFrame const*const pCurrFrame = pCrSh->GetCurrFrame(false);
             if (pCurrFrame==static_cast<SwContentFrame const *>(this)) {
diff --git a/sw/source/core/text/txtfrm.cxx b/sw/source/core/text/txtfrm.cxx
index 93d9e775966b..0178f275e540 100644
--- a/sw/source/core/text/txtfrm.cxx
+++ b/sw/source/core/text/txtfrm.cxx
@@ -2412,9 +2412,8 @@ void SwTextFrame::SwClientNotify(SwModify const& rModify, SfxHint const& rHint)
                 for ( size_t i = 0; GetDrawObjs() && i < pObjs->size(); ++i )
                 {
                     SwAnchoredObject* pAnchoredObj = (*pObjs)[i];
-                    if ( dynamic_cast< const SwFlyFrame *>( pAnchoredObj ) !=  nullptr )
+                    if ( auto pFly = dynamic_cast<SwFlyFrame *>( pAnchoredObj ) )
                     {
-                        SwFlyFrame *pFly = static_cast<SwFlyFrame*>(pAnchoredObj);
                         if( !pFly->IsFlyInContentFrame() )
                         {
                             const SvxBrushItem &rBack =
diff --git a/sw/source/core/undo/rolbck.cxx b/sw/source/core/undo/rolbck.cxx
index d7464b6f58d2..54fcd33b6815 100644
--- a/sw/source/core/undo/rolbck.cxx
+++ b/sw/source/core/undo/rolbck.cxx
@@ -1510,15 +1510,13 @@ void SwRegHistory::MakeSetWhichIds()
         return;
 
     const SfxItemSet* pSet = nullptr;
-    if( dynamic_cast< const SwContentNode *>( GetRegisteredIn() ) != nullptr  )
+    if( auto pContentNode = dynamic_cast< const SwContentNode *>( GetRegisteredIn() )  )
     {
-        pSet = static_cast<SwContentNode*>(
-                GetRegisteredIn())->GetpSwAttrSet();
+        pSet = pContentNode->GetpSwAttrSet();
     }
-    else if ( dynamic_cast< const SwFormat *>( GetRegisteredIn() ) != nullptr  )
+    else if ( auto pSwFormat = dynamic_cast< const SwFormat *>( GetRegisteredIn() )  )
     {
-        pSet = &static_cast<SwFormat*>(
-                GetRegisteredIn())->GetAttrSet();
+        pSet = &pSwFormat->GetAttrSet();
     }
     if( pSet && pSet->Count() )
     {


More information about the Libreoffice-commits mailing list