[Libreoffice-commits] core.git: 2 commits - basic/source sc/source sw/source vcl/inc

Caolán McNamara caolanm at redhat.com
Tue Oct 6 07:11:17 PDT 2015


 basic/source/comp/parser.cxx      |    3 --
 basic/source/runtime/methods.cxx  |   22 ++++++--------
 basic/source/runtime/runtime.cxx  |   55 ++++++++++++++----------------------
 basic/source/sbx/sbxobj.cxx       |   20 ++++++-------
 sc/source/core/data/documen8.cxx  |   25 +++++++---------
 sc/source/core/data/documen9.cxx  |    3 --
 sc/source/core/data/drwlayer.cxx  |    7 ++--
 sc/source/core/data/validat.cxx   |    3 --
 sc/source/core/tool/editutil.cxx  |    9 ++----
 sc/source/core/tool/interpr2.cxx  |    3 --
 sc/source/filter/html/htmlexp.cxx |    4 --
 sc/source/ui/app/scmod.cxx        |   17 ++++-------
 sc/source/ui/docshell/docfunc.cxx |    4 +-
 sc/source/ui/docshell/docsh3.cxx  |    3 --
 sc/source/ui/docshell/docsh4.cxx  |   57 ++++++++++++++++++++++----------------
 sc/source/ui/docshell/docsh6.cxx  |    6 +---
 sc/source/ui/docshell/servobj.cxx |    8 ++---
 sc/source/ui/drawfunc/drtxtob.cxx |    6 +---
 sw/source/core/frmedt/fefly1.cxx  |   52 +++++++++++++++++++++++-----------
 vcl/inc/svdata.hxx                |    1 
 20 files changed, 150 insertions(+), 158 deletions(-)

New commits:
commit 70409a450f62736885cf596991cdb7b42a19a88a
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Tue Oct 6 12:30:18 2015 +0100

    test tool is gone
    
    Change-Id: I3d99a62c27b914cc6286ddf013f551111d677484

diff --git a/vcl/inc/svdata.hxx b/vcl/inc/svdata.hxx
index f45ade7..52ea411 100644
--- a/vcl/inc/svdata.hxx
+++ b/vcl/inc/svdata.hxx
@@ -342,7 +342,6 @@ struct ImplSVData
     VclPtr<vcl::Window>     mpIntroWindow;                  // the splash screen
     DockingManager*         mpDockingManager;
     BlendFrameCache*        mpBlendFrameCache;
-    bool                    mbIsTestTool;
 
     oslThreadIdentifier     mnMainThreadId;
     rtl::Reference< vcl::DisplayConnection > mxDisplayConnection;
commit 31ee230b6efac9a6a60ceb5c2367ae9a5cf98929
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Tue Oct 6 10:50:12 2015 +0100

    Related: tdf#94814 some cleanup of static_cast following dynamic_cast
    
    to the same type
    
    Change-Id: I197e88acbc30f8e8bb9e7f2d54803971df6062af

diff --git a/basic/source/comp/parser.cxx b/basic/source/comp/parser.cxx
index c3e7a89..2953387 100644
--- a/basic/source/comp/parser.cxx
+++ b/basic/source/comp/parser.cxx
@@ -156,10 +156,9 @@ SbiSymDef* SbiParser::CheckRTLForSym(const OUString& rSym, SbxDataType eType)
     if (!pVar)
         return nullptr;
 
-    if (dynamic_cast<const SbxMethod *>(pVar) != nullptr)
+    if (SbxMethod* pMethod = dynamic_cast<SbxMethod*>(pVar))
     {
         SbiProcDef* pProc_ = aRtlSyms.AddProc( rSym );
-        SbxMethod* pMethod = static_cast<SbxMethod*>(pVar);
         if (pMethod->IsRuntimeFunction())
         {
             pProc_->SetType( pMethod->GetRuntimeFunctionReturnType() );
diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx
index 9d83fcc..6c396ae 100644
--- a/basic/source/runtime/methods.cxx
+++ b/basic/source/runtime/methods.cxx
@@ -4449,13 +4449,13 @@ RTLFUNC(Load)
     SbxBase* pObj = static_cast<SbxObject*>(rPar.Get(1)->GetObject());
     if ( pObj )
     {
-        if( dynamic_cast<const SbUserFormModule *>(pObj) != nullptr )
+        if (SbUserFormModule* pModule = dynamic_cast<SbUserFormModule*>(pObj))
         {
-            static_cast<SbUserFormModule*>(pObj)->Load();
+            pModule->Load();
         }
-        else if( dynamic_cast<const SbxObject *>(pObj) != nullptr )
+        else if (SbxObject* pSbxObj = dynamic_cast<SbxObject*>(pObj))
         {
-            SbxVariable* pVar = static_cast<SbxObject*>(pObj)->Find( OUString("Load"), SbxCLASS_METHOD );
+            SbxVariable* pVar = pSbxObj->Find(OUString("Load"), SbxCLASS_METHOD);
             if( pVar )
             {
                 pVar->GetInteger();
@@ -4480,14 +4480,13 @@ RTLFUNC(Unload)
     SbxBase* pObj = static_cast<SbxObject*>(rPar.Get(1)->GetObject());
     if ( pObj )
     {
-        if( dynamic_cast<const SbUserFormModule *>(pObj) != nullptr )
+        if (SbUserFormModule* pFormModule = dynamic_cast<SbUserFormModule*>(pObj))
         {
-            SbUserFormModule* pFormModule = static_cast<SbUserFormModule*>(pObj);
             pFormModule->Unload();
         }
-        else if( dynamic_cast<const SbxObject *>(pObj) != nullptr )
+        else if (SbxObject *pSbxObj = dynamic_cast<SbxObject*>(pObj))
         {
-            SbxVariable* pVar = static_cast<SbxObject*>(pObj)->Find( OUString("Unload"), SbxCLASS_METHOD );
+            SbxVariable* pVar = pSbxObj->Find(OUString("Unload"), SbxCLASS_METHOD);
             if( pVar )
             {
                 pVar->GetInteger();
@@ -4534,17 +4533,14 @@ RTLFUNC(SavePicture)
     }
 
     SbxBase* pObj = static_cast<SbxObject*>(rPar.Get(1)->GetObject());
-    if( dynamic_cast<const SbStdPicture *>(pObj) != nullptr )
+    if (SbStdPicture *pPicture = dynamic_cast<SbStdPicture*>(pObj))
     {
         SvFileStream aOStream( rPar.Get(2)->GetOUString(), StreamMode::WRITE | StreamMode::TRUNC );
-        Graphic aGraphic = static_cast<SbStdPicture*>(pObj)->GetGraphic();
+        Graphic aGraphic = pPicture->GetGraphic();
         WriteGraphic( aOStream, aGraphic );
     }
 }
 
-
-
-
 RTLFUNC(MsgBox)
 {
     (void)pBasic;
diff --git a/basic/source/runtime/runtime.cxx b/basic/source/runtime/runtime.cxx
index 33ab052..6cff602 100644
--- a/basic/source/runtime/runtime.cxx
+++ b/basic/source/runtime/runtime.cxx
@@ -528,10 +528,8 @@ StarBASIC* GetCurrentBasic( StarBASIC* pRTBasic )
     if( pActiveModule )
     {
         SbxObject* pParent = pActiveModule->GetParent();
-        if( pParent && 0 != dynamic_cast<const StarBASIC*>( pParent) )
-        {
-            pCurBasic = static_cast<StarBASIC*>(pParent);
-        }
+        if (StarBASIC *pBasic = dynamic_cast<StarBASIC*>(pParent))
+            pCurBasic = pBasic;
     }
     return pCurBasic;
 }
@@ -1166,10 +1164,7 @@ void SbiRuntime::PushForEach()
     }
 
     bool bError_ = false;
-    BasicCollection* pCollection;
-    SbxDimArray* pArray;
-    SbUnoObject* pUnoObj;
-    if( (pArray = dynamic_cast<SbxDimArray*>( pObj)) != NULL  )
+    if (SbxDimArray* pArray = dynamic_cast<SbxDimArray*>(pObj))
     {
         p->eForType = FOR_EACH_ARRAY;
         p->refEnd = reinterpret_cast<SbxVariable*>(pArray);
@@ -1186,13 +1181,13 @@ void SbiRuntime::PushForEach()
             p->pArrayUpperBounds[i] = uBound;
         }
     }
-    else if( (pCollection = dynamic_cast<BasicCollection*>( pObj)) != NULL  )
+    else if (BasicCollection* pCollection = dynamic_cast<BasicCollection*>(pObj))
     {
         p->eForType = FOR_EACH_COLLECTION;
         p->refEnd = pCollection;
         p->nCurCollectionIndex = 0;
     }
-    else if( (pUnoObj = dynamic_cast<SbUnoObject*>( pObj)) != NULL  )
+    else if (SbUnoObject* pUnoObj = dynamic_cast<SbUnoObject*>(pObj))
     {
         // XEnumerationAccess?
         Any aAny = pUnoObj->getUnoAny();
@@ -3239,24 +3234,23 @@ bool SbiRuntime::checkClass_Impl( const SbxVariableRef& refVal,
     }
     if( t == SbxOBJECT )
     {
-        SbxObject* pObj;
-        if( dynamic_cast<const SbxObject *>(pVal) != nullptr )
-            pObj = static_cast<SbxObject*>( pVal );
-        else
+        SbxObject* pObj = dynamic_cast<SbxObject*>(pVal);
+        if (!pObj)
         {
-            pObj = static_cast<SbxObject*>( refVal->GetObject() );
-            if( pObj && dynamic_cast<const SbxObject *>(pObj) == nullptr )
-                pObj = NULL;
+            pObj = dynamic_cast<SbxObject*>(refVal->GetObject());
         }
         if( pObj )
         {
             if( !implIsClass( pObj, aClass ) )
             {
-                if ( ( bVBAEnabled || CodeCompleteOptions::IsExtendedTypeDeclaration() ) && dynamic_cast<const SbUnoObject *>(pObj) != nullptr )
+                SbUnoObject* pUnoObj(nullptr);
+                if (bVBAEnabled || CodeCompleteOptions::IsExtendedTypeDeclaration())
                 {
-                    SbUnoObject& rUnoObj = dynamic_cast<SbUnoObject&>(*pObj);
-                    bOk = checkUnoObjectType(rUnoObj, aClass);
+                    pUnoObj = dynamic_cast<SbUnoObject*>(pObj);
                 }
+
+                if (pUnoObj)
+                    bOk = checkUnoObjectType(*pUnoObj, aClass);
                 else
                     bOk = false;
                 if ( !bOk )
@@ -3540,7 +3534,7 @@ SbxVariable* SbiRuntime::FindElement( SbxObject* pObj, sal_uInt32 nOp1, sal_uInt
             SetupArgs( pElem, nOp1 );
         }
         // because a particular call-type is requested
-        if( dynamic_cast<const SbxMethod *>(pElem) != nullptr )
+        if (SbxMethod* pMethod = dynamic_cast<SbxMethod*>(pElem))
         {
             // shall the type be converted?
             SbxDataType t2 = pElem->GetType();
@@ -3567,7 +3561,7 @@ SbxVariable* SbiRuntime::FindElement( SbxObject* pObj, sal_uInt32 nOp1, sal_uInt
             // has to know the difference between Left$() and Left()
 
             // because the methods' parameters are cut away in PopVar()
-            SbxVariable* pNew = new SbxMethod( *(static_cast<SbxMethod*>(pElem)) );
+            SbxVariable* pNew = new SbxMethod(*pMethod);
             //OLD: SbxVariable* pNew = new SbxVariable( *pElem );
 
             pElem->SetParameters(0);
@@ -3853,9 +3847,8 @@ SbxVariable* SbiRuntime::CheckArray( SbxVariable* pElem )
             SbxBaseRef pObj = pElem->GetObject();
             if( pObj )
             {
-                if( 0 != dynamic_cast<const SbUnoObject*>( &pObj) )
+                if (SbUnoObject* pUnoObj = dynamic_cast<SbUnoObject*>(static_cast<SbxBase*>(pObj)))
                 {
-                    SbUnoObject* pUnoObj = static_cast<SbUnoObject*>(static_cast<SbxBase*>(pObj));
                     Any aAny = pUnoObj->getUnoAny();
 
                     if( aAny.getValueType().getTypeClass() == TypeClass_INTERFACE )
@@ -3924,9 +3917,9 @@ SbxVariable* SbiRuntime::CheckArray( SbxVariable* pElem )
                                 SbxBaseRef pDfltObj = pDflt->GetObject();
                                 if( pDfltObj )
                                 {
-                                    if( 0 != dynamic_cast<const SbUnoObject*>( &pDfltObj) )
+                                    if (SbUnoObject* pSbObj = dynamic_cast<SbUnoObject*>(static_cast<SbxBase*>(pDfltObj)))
                                     {
-                                        pUnoObj = static_cast<SbUnoObject*>(static_cast<SbxBase*>(pDfltObj));
+                                        pUnoObj = pSbObj;
                                         Any aUnoAny = pUnoObj->getUnoAny();
 
                                         if( aUnoAny.getValueType().getTypeClass() == TypeClass_INTERFACE )
@@ -3964,9 +3957,8 @@ SbxVariable* SbiRuntime::CheckArray( SbxVariable* pElem )
                     // #42940, set parameter 0 to NULL so that var doesn't contain itself
                     pPar->Put( NULL, 0 );
                 }
-                else if( 0 != dynamic_cast<const BasicCollection*>( &pObj) )
+                else if (BasicCollection* pCol = dynamic_cast<BasicCollection*>(static_cast<SbxBase*>(pObj)))
                 {
-                    BasicCollection* pCol = static_cast<BasicCollection*>(static_cast<SbxBase*>(pObj));
                     pElem = new SbxVariable( SbxVARIANT );
                     pPar->Put( pElem, 0 );
                     pCol->CollItem( pPar );
@@ -4382,12 +4374,9 @@ void SbiRuntime::StepDCREATE_IMPL( sal_uInt32 nOp1, sal_uInt32 nOp2 )
         return;
     }
 
-    SbxDimArray* pArray = 0;
-    if( 0 != dynamic_cast<const SbxDimArray*>( &xObj) )
+    SbxDimArray* pArray = dynamic_cast<SbxDimArray*>(static_cast<SbxBase*>(xObj));
+    if (pArray)
     {
-        SbxBase* pObj = static_cast<SbxBase*>(xObj);
-        pArray = static_cast<SbxDimArray*>(pObj);
-
         short nDims = pArray->GetDims();
         sal_Int32 nTotalSize = 0;
 
diff --git a/basic/source/sbx/sbxobj.cxx b/basic/source/sbx/sbxobj.cxx
index 46f34f1..f6babf5 100644
--- a/basic/source/sbx/sbxobj.cxx
+++ b/basic/source/sbx/sbxobj.cxx
@@ -463,9 +463,9 @@ void SbxObject::Insert( SbxVariable* pVar )
         static const char* pCls[] =
             { "DontCare","Array","Value","Variable","Method","Property","Object" };
         OUString aVarName( pVar->GetName() );
-        if ( aVarName.isEmpty() && 0 != dynamic_cast<const SbxObject*>( pVar) )
+        if (const SbxObject *pSbxObj = aVarName.isEmpty() ? dynamic_cast<const SbxObject*>(pVar) : nullptr)
         {
-            aVarName = dynamic_cast<SbxObject*>( pVar)->GetClassName( );
+            aVarName = pSbxObj->GetClassName();
         }
         SAL_INFO(
             "basic.sbx",
@@ -507,9 +507,9 @@ void SbxObject::QuickInsert( SbxVariable* pVar )
         static const char* pCls[] =
             { "DontCare","Array","Value","Variable","Method","Property","Object" };
         OUString aVarName( pVar->GetName() );
-        if ( aVarName.isEmpty() && 0 != dynamic_cast<const SbxObject*>( pVar) )
+        if (const SbxObject *pSbxObj = aVarName.isEmpty() ? dynamic_cast<const SbxObject*>(pVar) : nullptr)
         {
-            aVarName = dynamic_cast<SbxObject*>( pVar)->GetClassName( );
+            aVarName = pSbxObj->GetClassName();
         }
         SAL_INFO(
             "basic.sbx",
@@ -535,9 +535,9 @@ void SbxObject::Remove( SbxVariable* pVar )
     {
 #ifdef DBG_UTIL
         OUString aVarName( pVar->GetName() );
-        if ( aVarName.isEmpty() && 0 != dynamic_cast<const SbxObject*>( pVar) )
+        if (const SbxObject *pSbxObj = aVarName.isEmpty() ? dynamic_cast<const SbxObject*>(pVar) : nullptr)
         {
-            aVarName = dynamic_cast<SbxObject*>( pVar)->GetClassName( );
+            aVarName = pSbxObj->GetClassName();
         }
         SAL_INFO(
             "basic.sbx",
@@ -855,13 +855,13 @@ void SbxObject::Dump( SvStream& rStrm, bool bFill )
             if ( pVar )
             {
                 rStrm.WriteCharPtr( aIndentNameStr.getStr() ).WriteCharPtr( "  - Sub" );
-                if ( 0 != dynamic_cast<const SbxObject*>( pVar) )
+                if (SbxObject *pSbxObj = dynamic_cast<SbxObject*>(pVar))
                 {
-                    static_cast<SbxObject*>(pVar)->Dump( rStrm, bFill );
+                    pSbxObj->Dump(rStrm, bFill);
                 }
-                else if ( 0 != dynamic_cast<const SbxVariable*>( pVar) )
+                else if (SbxVariable *pSbxVar = dynamic_cast<SbxVariable*>(pVar))
                 {
-                    static_cast<SbxVariable*>(pVar)->Dump( rStrm, bFill );
+                    pSbxVar->Dump(rStrm, bFill);
                 }
             }
         }
diff --git a/sc/source/core/data/documen8.cxx b/sc/source/core/data/documen8.cxx
index 15818a9..fdd9049 100644
--- a/sc/source/core/data/documen8.cxx
+++ b/sc/source/core/data/documen8.cxx
@@ -726,8 +726,8 @@ void ScDocument::SaveDdeLinks(SvStream& rStream) const
     for (i=0; i<nCount; i++)
     {
         ::sfx2::SvBaseLink* pBase = *rLinks[i];
-        if (dynamic_cast<const ScDdeLink*>( pBase) !=  nullptr)
-            if ( !bExport40 || static_cast<ScDdeLink*>(pBase)->GetMode() == SC_DDE_DEFAULT )
+        if (ScDdeLink* pLink = dynamic_cast<ScDdeLink*>(pBase))
+            if ( !bExport40 || pLink->GetMode() == SC_DDE_DEFAULT )
                 ++nDdeCount;
     }
 
@@ -741,9 +741,8 @@ void ScDocument::SaveDdeLinks(SvStream& rStream) const
     for (i=0; i<nCount; i++)
     {
         ::sfx2::SvBaseLink* pBase = *rLinks[i];
-        if (dynamic_cast<const ScDdeLink*>( pBase) !=  nullptr)
+        if (ScDdeLink* pLink = dynamic_cast<ScDdeLink*>(pBase))
         {
-            ScDdeLink* pLink = static_cast<ScDdeLink*>(pBase);
             if ( !bExport40 || pLink->GetMode() == SC_DDE_DEFAULT )
                 pLink->Store( rStream, aHdr );
         }
@@ -893,9 +892,8 @@ void ScDocument::CopyDdeLinks( ScDocument* pDestDoc ) const
     for (size_t i = 0, n = rLinks.size(); i < n; ++i)
     {
         const sfx2::SvBaseLink* pBase = *rLinks[i];
-        if (dynamic_cast<const ScDdeLink*>( pBase) !=  nullptr)
+        if (const ScDdeLink* p = dynamic_cast<const ScDdeLink*>(pBase))
         {
-            const ScDdeLink* p = static_cast<const ScDdeLink*>(pBase);
             ScDdeLink* pNew = new ScDdeLink(pDestDoc, *p);
             pDestMgr->InsertDDELink(
                 pNew, pNew->GetAppl(), pNew->GetTopic(), pNew->GetItem());
@@ -1078,8 +1076,8 @@ void ScDocument::DeleteAreaLinksOnTab( SCTAB nTab )
     while ( nPos < rLinks.size() )
     {
         const ::sfx2::SvBaseLink* pBase = *rLinks[nPos];
-        if ( dynamic_cast<const ScAreaLink*>( pBase) !=  nullptr &&
-             static_cast<const ScAreaLink*>(pBase)->GetDestArea().aStart.Tab() == nTab )
+        const ScAreaLink* pLink = dynamic_cast<const ScAreaLink*>(pBase);
+        if (pLink && pLink->GetDestArea().aStart.Tab() == nTab)
             pMgr->Remove(nPos);
         else
             ++nPos;
@@ -1100,9 +1098,8 @@ void ScDocument::UpdateRefAreaLinks( UpdateRefMode eUpdateRefMode,
     for (sal_uInt16 i=0; i<nCount; i++)
     {
         ::sfx2::SvBaseLink* pBase = *rLinks[i];
-        if (dynamic_cast<const ScAreaLink*>( pBase) !=  nullptr)
+        if (ScAreaLink* pLink = dynamic_cast<ScAreaLink*>(pBase))
         {
-            ScAreaLink* pLink = static_cast<ScAreaLink*>(pBase);
             ScRange aOutRange = pLink->GetDestArea();
 
             SCCOL nCol1 = aOutRange.aStart.Col();
@@ -1136,14 +1133,14 @@ void ScDocument::UpdateRefAreaLinks( UpdateRefMode eUpdateRefMode,
         {
             bool bFound = false;
             ::sfx2::SvBaseLink* pFirst = *rLinks[nFirstIndex];
-            if ( dynamic_cast<const ScAreaLink*>( pFirst) !=  nullptr )
+            if (ScAreaLink* pFirstLink = dynamic_cast<ScAreaLink*>(pFirst))
             {
-                ScAddress aFirstPos = static_cast<ScAreaLink*>(pFirst)->GetDestArea().aStart;
+                ScAddress aFirstPos = pFirstLink->GetDestArea().aStart;
                 for ( sal_uInt16 nSecondIndex = nFirstIndex + 1; nSecondIndex < nCount && !bFound; ++nSecondIndex )
                 {
                     ::sfx2::SvBaseLink* pSecond = *rLinks[nSecondIndex];
-                    if ( dynamic_cast<const ScAreaLink*>( pSecond) !=  nullptr &&
-                         static_cast<ScAreaLink*>(pSecond)->GetDestArea().aStart == aFirstPos )
+                    ScAreaLink* pSecondLink = dynamic_cast<ScAreaLink*>(pSecond);
+                    if (pSecondLink && pSecondLink->GetDestArea().aStart == aFirstPos)
                     {
                         // remove the first link, exit the inner loop, don't increment nFirstIndex
                         pMgr->Remove(pFirst);
diff --git a/sc/source/core/data/documen9.cxx b/sc/source/core/data/documen9.cxx
index 9ca2092..e1d0479 100644
--- a/sc/source/core/data/documen9.cxx
+++ b/sc/source/core/data/documen9.cxx
@@ -344,9 +344,8 @@ void ScDocument::StartAnimations( SCTAB nTab, vcl::Window* pWin )
     SdrObject* pObject = aIter.Next();
     while (pObject)
     {
-        if (dynamic_cast<const SdrGrafObj*>( pObject) !=  nullptr)
+        if (SdrGrafObj* pGrafObj = dynamic_cast<SdrGrafObj*>(pObject))
         {
-            SdrGrafObj* pGrafObj = static_cast<SdrGrafObj*>(pObject);
             if ( pGrafObj->IsAnimated() )
             {
                 const Rectangle& rRect = pGrafObj->GetCurrentBoundRect();
diff --git a/sc/source/core/data/drwlayer.cxx b/sc/source/core/data/drwlayer.cxx
index f87954f..6a7429f 100644
--- a/sc/source/core/data/drwlayer.cxx
+++ b/sc/source/core/data/drwlayer.cxx
@@ -2047,9 +2047,8 @@ IMapObject* ScDrawLayer::GetHitIMapObject( SdrObject* pObj,
         Graphic     aGraphic;
         bool        bObjSupported = false;
 
-        if ( dynamic_cast<const SdrGrafObj*>( pObj) !=  nullptr  ) // Simple Graphics object
+        if (const SdrGrafObj* pGrafObj = dynamic_cast<const SdrGrafObj*>(pObj)) // Simple Graphics object
         {
-            const SdrGrafObj*   pGrafObj = static_cast<const SdrGrafObj*>( pObj );
             const GeoStat&      rGeo = pGrafObj->GetGeoStat();
             const Graphic&      rGraphic = pGrafObj->GetGraphic();
 
@@ -2075,10 +2074,10 @@ IMapObject* ScDrawLayer::GetHitIMapObject( SdrObject* pObj,
 
             bObjSupported = true;
         }
-        else if ( dynamic_cast<const SdrOle2Obj*>( pObj) !=  nullptr ) // OLE object
+        else if (const SdrOle2Obj* pOleObj = dynamic_cast<const SdrOle2Obj*>(pObj)) // OLE object
         {
             // TODO/LEAN: working with visual area needs running state
-            aGraphSize = static_cast<const SdrOle2Obj*>(pObj)->GetOrigObjSize();
+            aGraphSize = pOleObj->GetOrigObjSize();
             bObjSupported = true;
         }
 
diff --git a/sc/source/core/data/validat.cxx b/sc/source/core/data/validat.cxx
index 2e77ada..8d2efdb 100644
--- a/sc/source/core/data/validat.cxx
+++ b/sc/source/core/data/validat.cxx
@@ -289,9 +289,8 @@ bool ScValidationData::DoMacro( const ScAddress& rPos, const OUString& rInput,
 
     StarBASIC* pRoot = pDocSh->GetBasic();
     SbxVariable* pVar = pRoot->Find( aErrorTitle, SbxCLASS_METHOD );
-    if ( pVar && dynamic_cast<const SbMethod*>( pVar) !=  nullptr )
+    if (SbMethod* pMethod = dynamic_cast<SbMethod*>(pVar))
     {
-        SbMethod* pMethod = static_cast<SbMethod*>(pVar);
         SbModule* pModule = pMethod->GetModule();
         SbxObject* pObject = pModule->GetParent();
         OUStringBuffer aMacroStr = pObject->GetName();
diff --git a/sc/source/core/tool/editutil.cxx b/sc/source/core/tool/editutil.cxx
index c2fedb2..0576020 100644
--- a/sc/source/core/tool/editutil.cxx
+++ b/sc/source/core/tool/editutil.cxx
@@ -875,12 +875,11 @@ OUString ScFieldEditEngine::CalcFieldValue( const SvxFieldItem& rField,
 
 void ScFieldEditEngine::FieldClicked( const SvxFieldItem& rField, sal_Int32, sal_Int32 )
 {
-    const SvxFieldData* pFld = rField.GetField();
-
-    if ( pFld && dynamic_cast<const SvxURLField*>( pFld) !=  nullptr && bExecuteURL )
+    if (!bExecuteURL)
+        return;
+    if (const SvxURLField* pURLField = dynamic_cast<const SvxURLField*>(rField.GetField()))
     {
-        const SvxURLField* pURLField = static_cast<const SvxURLField*>(pFld);
-        ScGlobal::OpenURL( pURLField->GetURL(), pURLField->GetTargetFrame() );
+        ScGlobal::OpenURL(pURLField->GetURL(), pURLField->GetTargetFrame());
     }
 }
 
diff --git a/sc/source/core/tool/interpr2.cxx b/sc/source/core/tool/interpr2.cxx
index ce1fdda..5699816 100644
--- a/sc/source/core/tool/interpr2.cxx
+++ b/sc/source/core/tool/interpr2.cxx
@@ -2346,9 +2346,8 @@ static ScDdeLink* lcl_GetDdeLink( sfx2::LinkManager* pLinkMgr,
     for (size_t i=0; i<nCount; i++ )
     {
         ::sfx2::SvBaseLink* pBase = *pLinkMgr->GetLinks()[i];
-        if (dynamic_cast<const ScDdeLink*>( pBase) !=  nullptr)
+        if (ScDdeLink* pLink = dynamic_cast<ScDdeLink*>(pBase))
         {
-            ScDdeLink* pLink = static_cast<ScDdeLink*>(pBase);
             if ( pLink->GetAppl() == rA &&
                  pLink->GetTopic() == rT &&
                  pLink->GetItem() == rI &&
diff --git a/sc/source/filter/html/htmlexp.cxx b/sc/source/filter/html/htmlexp.cxx
index c8d3622..f274326 100644
--- a/sc/source/filter/html/htmlexp.cxx
+++ b/sc/source/filter/html/htmlexp.cxx
@@ -1268,11 +1268,9 @@ bool ScHTMLExport::WriteFieldText( const EditTextObject* pData )
                     if ( aSet.GetItemState( EE_FEATURE_FIELD, false, &pItem ) == SfxItemState::SET )
                     {
                         const SvxFieldData* pField = static_cast<const SvxFieldItem*>(pItem)->GetField();
-                        if ( pField && dynamic_cast<const SvxURLField*>( pField) !=  nullptr )
+                        if (const SvxURLField* pURLField = dynamic_cast<const SvxURLField*>(pField))
                         {
                             bUrl = true;
-                            const SvxURLField*  pURLField = static_cast<const SvxURLField*>(pField);
-//                          String              aFieldText = rEngine.GetText( aSel );
                             rStrm.WriteChar( '<' ).WriteCharPtr( OOO_STRING_SVTOOLS_HTML_anchor ).WriteChar( ' ' ).WriteCharPtr( OOO_STRING_SVTOOLS_HTML_O_href ).WriteCharPtr( "=\"" );
                             OUT_STR( pURLField->GetURL() );
                             rStrm.WriteCharPtr( "\">" );
diff --git a/sc/source/ui/app/scmod.cxx b/sc/source/ui/app/scmod.cxx
index 81626ab..5eda81d 100644
--- a/sc/source/ui/app/scmod.cxx
+++ b/sc/source/ui/app/scmod.cxx
@@ -246,9 +246,8 @@ void ScModule::ConfigurationChanged( utl::ConfigurationBroadcaster* p, sal_uInt3
         SfxViewShell* pViewShell = SfxViewShell::GetFirst();
         while(pViewShell)
         {
-            if ( dynamic_cast<const ScTabViewShell*>( pViewShell) !=  nullptr )
+            if (ScTabViewShell* pViewSh = dynamic_cast<ScTabViewShell*>(pViewShell))
             {
-                ScTabViewShell* pViewSh = static_cast<ScTabViewShell*>(pViewShell);
                 pViewSh->PaintGrid();
                 pViewSh->PaintTop();
                 pViewSh->PaintLeft();
@@ -293,10 +292,8 @@ void ScModule::ConfigurationChanged( utl::ConfigurationBroadcaster* p, sal_uInt3
         SfxViewShell* pSh = SfxViewShell::GetFirst();
         while ( pSh )
         {
-            if ( dynamic_cast<const ScTabViewShell*>( pSh) !=  nullptr )
+            if (ScTabViewShell* pViewSh = dynamic_cast<ScTabViewShell*>(pSh))
             {
-                ScTabViewShell* pViewSh = static_cast<ScTabViewShell*>(pSh);
-
                 // set ref-device for EditEngine (re-evaluates digit settings)
                 ScInputHandler* pHdl = GetInputHdl(pViewSh);
                 if (pHdl)
@@ -305,9 +302,8 @@ void ScModule::ConfigurationChanged( utl::ConfigurationBroadcaster* p, sal_uInt3
                 pViewSh->DigitLanguageChanged();
                 pViewSh->PaintGrid();
             }
-            else if ( dynamic_cast<const ScPreviewShell*>( pSh) !=  nullptr )
+            else if (ScPreviewShell* pPreviewSh = dynamic_cast<ScPreviewShell*>(pSh))
             {
-                ScPreviewShell* pPreviewSh = static_cast<ScPreviewShell*>(pSh);
                 ScPreview* pPreview = pPreviewSh->GetPreview();
 
                 pPreview->SetDigitLanguage( GetOptDigitLanguage() );
@@ -1551,8 +1547,8 @@ void ScModule::SetRefDialog( sal_uInt16 nId, bool bVis, SfxViewFrame* pViewFrm )
         {
             //  store the dialog id also in the view shell
             SfxViewShell* pViewSh = pViewFrm->GetViewShell();
-            if ( pViewSh && dynamic_cast<const ScTabViewShell*>( pViewSh) !=  nullptr )
-                static_cast<ScTabViewShell*>(pViewSh)->SetCurRefDlgId( nCurRefDlgId );
+            if (ScTabViewShell* pTabViewSh = dynamic_cast<ScTabViewShell*>(pViewSh))
+                pTabViewSh->SetCurRefDlgId(nCurRefDlgId);
             else
             {
                 // no ScTabViewShell - possible for example from a Basic macro
@@ -2146,10 +2142,9 @@ IMPL_LINK_TYPED( ScModule, CalcFieldValueHdl, EditFieldInfo*, pInfo, void )
     const SvxFieldItem& rField = pInfo->GetField();
     const SvxFieldData* pField = rField.GetField();
 
-    if (pField && dynamic_cast<const SvxURLField*>( pField) !=  nullptr)
+    if (const SvxURLField* pURLField = dynamic_cast<const SvxURLField*>(pField))
     {
         // URLField
-        const SvxURLField* pURLField = static_cast<const SvxURLField*>(pField);
         OUString aURL = pURLField->GetURL();
 
         switch ( pURLField->GetFormat() )
diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx
index b554dd2..52a8c71 100644
--- a/sc/source/ui/docshell/docfunc.cxx
+++ b/sc/source/ui/docshell/docfunc.cxx
@@ -5220,8 +5220,8 @@ bool ScDocFunc::InsertAreaLink( const OUString& rFile, const OUString& rFilter,
     while (nLinkPos<nLinkCount)
     {
         ::sfx2::SvBaseLink* pBase = *pLinkManager->GetLinks()[nLinkPos];
-        if ( dynamic_cast< const ScAreaLink *>( pBase ) !=  nullptr &&
-             static_cast<ScAreaLink*>(pBase)->GetDestArea().aStart == rDestRange.aStart )
+        ScAreaLink* pLink = dynamic_cast<ScAreaLink*>(pBase);
+        if (pLink && pLink->GetDestArea().aStart == rDestRange.aStart)
         {
             if ( bUndo )
             {
diff --git a/sc/source/ui/docshell/docsh3.cxx b/sc/source/ui/docshell/docsh3.cxx
index a1135db..4ac965f 100644
--- a/sc/source/ui/docshell/docsh3.cxx
+++ b/sc/source/ui/docshell/docsh3.cxx
@@ -480,9 +480,8 @@ sal_uInt16 ScDocShell::SetPrinter( SfxPrinter* pNewPrinter, SfxPrinterChangeFlag
             while (pFrame)
             {
                 SfxViewShell* pSh = pFrame->GetViewShell();
-                if (pSh && dynamic_cast<const ScTabViewShell*>( pSh) !=  nullptr)
+                if (ScTabViewShell* pViewSh = dynamic_cast<ScTabViewShell*>(pSh))
                 {
-                    ScTabViewShell* pViewSh = static_cast<ScTabViewShell*>(pSh);
                     ScInputHandler* pInputHdl = pScMod->GetInputHdl(pViewSh);
                     if (pInputHdl)
                         pInputHdl->UpdateRefDevice();
diff --git a/sc/source/ui/docshell/docsh4.cxx b/sc/source/ui/docshell/docsh4.cxx
index 79cabb1..d923654 100644
--- a/sc/source/ui/docshell/docsh4.cxx
+++ b/sc/source/ui/docshell/docsh4.cxx
@@ -674,31 +674,39 @@ void ScDocShell::Execute( SfxRequest& rReq )
                 }
                 SfxApplication* pApp = SfxGetpApp();
                 const SfxPoolItem* pItem;
+                const SfxStringItem* pStringItem(nullptr);
                 SfxMedium* pMed = NULL;
-                if ( pReqArgs &&
-                     pReqArgs->GetItemState( SID_FILE_NAME, true, &pItem ) == SfxItemState::SET &&
-                     dynamic_cast<const SfxStringItem*>( pItem) !=  nullptr )
+                if (pReqArgs && pReqArgs->GetItemState(SID_FILE_NAME, true, &pItem) == SfxItemState::SET)
                 {
-                    OUString aFileName =
-                        static_cast<const SfxStringItem*>(pItem)->GetValue();
+                    pStringItem = dynamic_cast<const SfxStringItem*>(pItem);
+                }
+                if (pStringItem)
+                {
+                    OUString aFileName = pStringItem->GetValue();
 
                     OUString aFilterName;
-                    if ( pReqArgs->GetItemState( SID_FILTER_NAME, true, &pItem ) == SfxItemState::SET &&
-                         dynamic_cast<const SfxStringItem*>( pItem) !=  nullptr )
+                    pStringItem = nullptr;
+                    if (pReqArgs->GetItemState(SID_FILTER_NAME, true, &pItem) == SfxItemState::SET)
+                        pStringItem = dynamic_cast<const SfxStringItem*>(pItem);
+                    if (pStringItem)
                     {
-                        aFilterName = static_cast<const SfxStringItem*>(pItem)->GetValue();
+                        aFilterName = pStringItem->GetValue();
                     }
                     OUString aOptions;
-                    if ( pReqArgs->GetItemState( SID_FILE_FILTEROPTIONS, true, &pItem ) == SfxItemState::SET &&
-                         dynamic_cast<const SfxStringItem*>( pItem) !=  nullptr )
+                    pStringItem = nullptr;
+                    if (pReqArgs->GetItemState(SID_FILE_FILTEROPTIONS, true, &pItem) == SfxItemState::SET)
+                        pStringItem = dynamic_cast<const SfxStringItem*>(pItem);
+                    if (pStringItem)
                     {
-                        aOptions = static_cast<const SfxStringItem*>(pItem)->GetValue();
+                        aOptions = pStringItem->GetValue();
                     }
                     short nVersion = 0;
-                    if ( pReqArgs->GetItemState( SID_VERSION, true, &pItem ) == SfxItemState::SET &&
-                         dynamic_cast<const SfxInt16Item*>( pItem) !=  nullptr )
+                    const SfxInt16Item* pInt16Item(nullptr);
+                    if (pReqArgs->GetItemState(SID_VERSION, true, &pItem) == SfxItemState::SET)
+                        pInt16Item = dynamic_cast<const SfxInt16Item*>(pItem);
+                    if (pInt16Item)
                     {
-                        nVersion = static_cast<const SfxInt16Item*>(pItem)->GetValue();
+                        nVersion = pInt16Item->GetValue();
                     }
 
                     //  kein Filter angegeben -> Detection
@@ -817,9 +825,9 @@ void ScDocShell::Execute( SfxRequest& rReq )
                 const SfxPoolItem* pItem;
                 if ( pReqArgs->GetItemState( nSlot, true, &pItem ) == SfxItemState::SET )
                 {
-                    if ( dynamic_cast<const SfxStringItem*>( pItem) !=  nullptr )
+                    if (const SfxStringItem* pStringItem = dynamic_cast<const SfxStringItem*>(pItem))
                     {
-                        OUString aName = static_cast<const SfxStringItem*>(pItem)->GetValue();
+                        OUString aName = pStringItem->GetValue();
                         SCTAB nTab;
                         if (aDocument.GetTable( aName, nTab ))
                         {
@@ -845,9 +853,9 @@ void ScDocShell::Execute( SfxRequest& rReq )
                 const SfxPoolItem* pItem;
                 if ( pReqArgs->GetItemState( nSlot, true, &pItem ) == SfxItemState::SET )
                 {
-                    if ( dynamic_cast<const SfxStringItem*>( pItem) !=  nullptr )
+                    if (const SfxStringItem* pStringItem = dynamic_cast<const SfxStringItem*>(pItem))
                     {
-                        OUString aName = static_cast<const SfxStringItem*>(pItem)->GetValue();
+                        OUString aName = pStringItem->GetValue();
                         SCTAB nTab;
                         if (aDocument.GetTable( aName, nTab ))
                         {
@@ -893,9 +901,9 @@ void ScDocShell::Execute( SfxRequest& rReq )
             const SfxPoolItem* pItem;
             if ( pReqArgs->GetItemState( nSlot, true, &pItem ) == SfxItemState::SET )
             {
-                if ( dynamic_cast<const SfxUInt16Item*>( pItem) !=  nullptr )
+                if (const SfxUInt16Item* pInt16Item = dynamic_cast<const SfxUInt16Item*>(pItem))
                 {
-                    sal_uInt16 nY2k = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
+                    sal_uInt16 nY2k = pInt16Item->GetValue();
                     // immer an den DocOptions setzen, damit das auch fuer SO50
                     // gespeichert wird (und alle Abfragen bisher auch darauf laufen).
                     // SetDocOptions propagiert das an den NumberFormatter
@@ -2292,10 +2300,13 @@ IMPL_LINK_TYPED( ScDocShell, DialogClosedHdl, sfx2::FileDialogHelper*, _pFileDlg
                     pImpl->pRequest->AppendItem( SfxStringItem( SID_FILE_FILTEROPTIONS, sOptions ) );
             }
             const SfxPoolItem* pItem = NULL;
+            const SfxInt16Item* pInt16Item(nullptr);
             SfxItemSet* pSet = pMed->GetItemSet();
-            if ( pSet &&
-                    pSet->GetItemState( SID_VERSION, true, &pItem ) == SfxItemState::SET &&
-                    dynamic_cast<const SfxInt16Item*>( pItem) !=  nullptr )
+            if (pSet && pSet->GetItemState(SID_VERSION, true, &pItem) == SfxItemState::SET)
+            {
+                pInt16Item = dynamic_cast<const SfxInt16Item*>(pItem);
+            }
+            if (pInt16Item)
             {
                 pImpl->pRequest->AppendItem( *pItem );
             }
diff --git a/sc/source/ui/docshell/docsh6.cxx b/sc/source/ui/docshell/docsh6.cxx
index 7374236..0a01292 100644
--- a/sc/source/ui/docshell/docsh6.cxx
+++ b/sc/source/ui/docshell/docsh6.cxx
@@ -354,9 +354,8 @@ void ScDocShell::UpdateLinks()
     {
         --k;
         ::sfx2::SvBaseLink* pBase = *pLinkManager->GetLinks()[k];
-        if (dynamic_cast<const ScTableLink*>( pBase) !=  nullptr)
+        if (ScTableLink* pTabLink = dynamic_cast<ScTableLink*>(pBase))
         {
-            ScTableLink* pTabLink = static_cast<ScTableLink*>(pBase);
             if (pTabLink->IsUsed())
                 aNames.insert(pTabLink->GetFileName());
             else        // nicht mehr benutzt -> loeschen
@@ -418,9 +417,8 @@ bool ScDocShell::ReloadTabLinks()
     for (size_t i=0; i<nCount; i++ )
     {
         ::sfx2::SvBaseLink* pBase = *pLinkManager->GetLinks()[i];
-        if (dynamic_cast<const ScTableLink*>( pBase) !=  nullptr)
+        if (ScTableLink* pTabLink = dynamic_cast<ScTableLink*>(pBase))
         {
-            ScTableLink* pTabLink = static_cast<ScTableLink*>(pBase);
 //			pTabLink->SetAddUndo(sal_False);		//! Undo's zusammenfassen
 
 			// Painting only after Update() makes no sense:
diff --git a/sc/source/ui/docshell/servobj.cxx b/sc/source/ui/docshell/servobj.cxx
index e090bd2..4e2d7a3 100644
--- a/sc/source/ui/docshell/servobj.cxx
+++ b/sc/source/ui/docshell/servobj.cxx
@@ -228,18 +228,18 @@ void ScServerObject::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
         const ScHint* pScHint = dynamic_cast<const ScHint*>( &rHint );
         if (pScHint && (pScHint->GetId() & SC_HINT_DATACHANGED))
             bDataChanged = true;
-        else if ( dynamic_cast<const ScAreaChangedHint*>(&rHint) )      // position of broadcaster changed
+        else if (const ScAreaChangedHint *pChgHint = dynamic_cast<const ScAreaChangedHint*>(&rHint))      // position of broadcaster changed
         {
-            ScRange aNewRange = static_cast<const ScAreaChangedHint&>(rHint).GetRange();
+            ScRange aNewRange = pChgHint->GetRange();
             if ( aRange != aNewRange )
             {
                 bRefreshListener = true;
                 bDataChanged = true;
             }
         }
-        else if ( dynamic_cast<const SfxSimpleHint*>(&rHint) )
+        else if (const SfxSimpleHint *pSplHint = dynamic_cast<const SfxSimpleHint*>(&rHint))
         {
-            sal_uLong nId = static_cast<const SfxSimpleHint&>(rHint).GetId();
+            sal_uLong nId = pSplHint->GetId();
             if (nId == SFX_HINT_DYING)
             {
                 //  If the range is being deleted, listening must be restarted
diff --git a/sc/source/ui/drawfunc/drtxtob.cxx b/sc/source/ui/drawfunc/drtxtob.cxx
index a0c2592..a09ca5d 100644
--- a/sc/source/ui/drawfunc/drtxtob.cxx
+++ b/sc/source/ui/drawfunc/drtxtob.cxx
@@ -323,9 +323,8 @@ void ScDrawTextObjectBar::Execute( SfxRequest &rReq )
                     if ( pFieldItem )
                     {
                         const SvxFieldData* pField = pFieldItem->GetField();
-                        if( pField && dynamic_cast<const SvxURLField*>( pField) !=  nullptr )
+                        if (const SvxURLField* pURLField = dynamic_cast<const SvxURLField*>(pField))
                         {
-                            const SvxURLField* pURLField = static_cast< const SvxURLField* >( pField );
                             ScGlobal::OpenURL( pURLField->GetURL(), pURLField->GetTargetFrame() );
                         }
                     }
@@ -391,9 +390,8 @@ void ScDrawTextObjectBar::GetState( SfxItemSet& rSet )
             if (pFieldItem)
             {
                 const SvxFieldData* pField = pFieldItem->GetField();
-                if ( pField && dynamic_cast<const SvxURLField*>( pField) !=  nullptr )
+                if (const SvxURLField* pURLField = dynamic_cast<const SvxURLField*>(pField))
                 {
-                    const SvxURLField* pURLField = static_cast<const SvxURLField*>(pField);
                     aHLinkItem.SetName( pURLField->GetRepresentation() );
                     aHLinkItem.SetURL( pURLField->GetURL() );
                     aHLinkItem.SetTargetFrame( pURLField->GetTargetFrame() );
diff --git a/sw/source/core/frmedt/fefly1.cxx b/sw/source/core/frmedt/fefly1.cxx
index 903e4ec..e83f3b1 100644
--- a/sw/source/core/frmedt/fefly1.cxx
+++ b/sw/source/core/frmedt/fefly1.cxx
@@ -265,7 +265,10 @@ SwFlyFrm* SwFEShell::GetSelectedFlyFrm() const
             return 0;
 
         SdrObject *pO = rMrkList.GetMark( 0 )->GetMarkedSdrObj();
-        return ( pO && dynamic_cast<const SwVirtFlyDrawObj*>( pO ) != nullptr ) ? static_cast<SwVirtFlyDrawObj*>(pO)->GetFlyFrm() : 0;
+
+        SwVirtFlyDrawObj *pFlyObj = dynamic_cast<SwVirtFlyDrawObj*>(pO);
+
+        return pFlyObj ? pFlyObj->GetFlyFrm() : nullptr;
     }
     return 0;
 }
@@ -311,9 +314,16 @@ const SwFrameFormat* SwFEShell::IsFlyInFly()
     SwFrameFormat *pFormat = FindFrameFormat( pObj );
     if( pFormat && FLY_AT_FLY == pFormat->GetAnchor().GetAnchorId() )
     {
-        const SwFrm* pFly = dynamic_cast<SwVirtFlyDrawObj *>(pObj) != nullptr ?
-            static_cast<SwVirtFlyDrawObj*>(pObj)->GetFlyFrm()->GetAnchorFrm() :
-            static_cast<SwDrawContact*>(GetUserCall(pObj))->GetAnchorFrm( pObj );
+        const SwFrm* pFly;
+        if (SwVirtFlyDrawObj* pFlyObj = dynamic_cast<SwVirtFlyDrawObj *>(pObj))
+        {
+            pFly = pFlyObj->GetFlyFrm()->GetAnchorFrm();
+        }
+        else
+        {
+            pFly = static_cast<SwDrawContact*>(GetUserCall(pObj))->GetAnchorFrm(pObj);
+        }
+
         OSL_ENSURE( pFly, "IsFlyInFly: Where's my anchor?" );
         OSL_ENSURE( pFly->IsFlyFrm(), "IsFlyInFly: Funny anchor!" );
         return static_cast<const SwFlyFrm*>(pFly)->GetFormat();
@@ -1159,8 +1169,8 @@ void SwFEShell::SetFrameFormat( SwFrameFormat *pNewFormat, bool bKeepOrient, Poi
     {
         const SwFrameFormat* pFormat = GetFormatFromObj( *pDocPos );
 
-        if(dynamic_cast<const SwFlyFrameFormat*>( pFormat) )
-            pFly = static_cast<const SwFlyFrameFormat*>(pFormat)->GetFrm();
+        if (const SwFlyFrameFormat* pFlyFormat = dynamic_cast<const SwFlyFrameFormat*>(pFormat))
+            pFly = pFlyFormat->GetFrm();
     }
     else
         pFly = GetSelectedFlyFrm();
@@ -1455,10 +1465,14 @@ const SwFrameFormat* SwFEShell::IsURLGrfAtPos( const Point& rPt, OUString* pURL,
     const auto nOld = pDView->GetHitTolerancePixel();
     pDView->SetHitTolerancePixel( 2 );
 
-    if( pDView->PickObj( rPt, pDView->getHitTolLog(), pObj, pPV,SdrSearchOptions::PICKMACRO ) &&
-         dynamic_cast<const SwVirtFlyDrawObj*>( pObj) != nullptr )
+    SwVirtFlyDrawObj* pFlyObj(nullptr);
+    if (pDView->PickObj(rPt, pDView->getHitTolLog(), pObj, pPV, SdrSearchOptions::PICKMACRO))
+    {
+        pFlyObj = dynamic_cast<SwVirtFlyDrawObj*>(pObj);
+    }
+    if (pFlyObj)
     {
-        SwFlyFrm *pFly = static_cast<SwVirtFlyDrawObj*>(pObj)->GetFlyFrm();
+        SwFlyFrm *pFly = pFlyObj->GetFlyFrm();
         const SwFormatURL &rURL = pFly->GetFormat()->GetURL();
         if( !rURL.GetURL().isEmpty() || rURL.GetMap() )
         {
@@ -1523,9 +1537,14 @@ const Graphic *SwFEShell::GetGrfAtPos( const Point &rPt,
     SdrPageView* pPV;
     SwDrawView *pDView = const_cast<SwDrawView*>(Imp()->GetDrawView());
 
-    if( pDView->PickObj( rPt, pDView->getHitTolLog(), pObj, pPV ) &&  dynamic_cast<const SwVirtFlyDrawObj*>( pObj) != nullptr )
+    SwVirtFlyDrawObj* pFlyObj(nullptr);
+    if (pDView->PickObj(rPt, pDView->getHitTolLog(), pObj, pPV))
+    {
+        pFlyObj = dynamic_cast<SwVirtFlyDrawObj*>(pObj);
+    }
+    if (pFlyObj)
     {
-        SwFlyFrm *pFly = static_cast<SwVirtFlyDrawObj*>(pObj)->GetFlyFrm();
+        SwFlyFrm *pFly = pFlyObj->GetFlyFrm();
         if ( pFly->Lower() && pFly->Lower()->IsNoTextFrm() )
         {
             SwGrfNode *pNd = static_cast<SwContentFrm*>(pFly->Lower())->GetNode()->GetGrfNode();
@@ -1568,8 +1587,8 @@ const SwFrameFormat* SwFEShell::GetFormatFromObj( const Point& rPt, SwRect** pRe
         if( pDView->PickObj( rPt, pDView->getHitTolLog(), pObj, pPView, SdrSearchOptions::PICKMARKABLE ) )
         {
            // first check it:
-            if ( dynamic_cast<const SwVirtFlyDrawObj*>( pObj) != nullptr )
-                pRet = static_cast<SwVirtFlyDrawObj*>(pObj)->GetFormat();
+            if (SwVirtFlyDrawObj* pFlyObj = dynamic_cast<SwVirtFlyDrawObj*>(pObj))
+                pRet = pFlyObj->GetFormat();
             else if ( pObj->GetUserCall() ) //not for group objects
                 pRet = static_cast<SwDrawContact*>(pObj->GetUserCall())->GetFormat();
             if(pRet && pRectToFill)
@@ -1603,9 +1622,8 @@ ObjCntType SwFEShell::GetObjCntType( const SdrObject& rObj ) const
     // investigate 'master' drawing object, if method
     // is called for a 'virtual' drawing object.
     const SdrObject* pInvestigatedObj;
-    if ( dynamic_cast<const SwDrawVirtObj*>( &rObj) != nullptr )
+    if (const SwDrawVirtObj* pDrawVirtObj = dynamic_cast<const SwDrawVirtObj*>( &rObj))
     {
-        const SwDrawVirtObj* pDrawVirtObj = static_cast<const SwDrawVirtObj*>(&rObj);
         pInvestigatedObj = &(pDrawVirtObj->GetReferencedObj());
     }
     else
@@ -1634,9 +1652,9 @@ ObjCntType SwFEShell::GetObjCntType( const SdrObject& rObj ) const
             }
         }
     }
-    else if( dynamic_cast<const SwVirtFlyDrawObj*>( pInvestigatedObj) != nullptr )
+    else if (const SwVirtFlyDrawObj *pFlyObj = dynamic_cast<const SwVirtFlyDrawObj*>(pInvestigatedObj))
     {
-        const SwFlyFrm *pFly = static_cast<const SwVirtFlyDrawObj&>(*pInvestigatedObj).GetFlyFrm();
+        const SwFlyFrm *pFly = pFlyObj->GetFlyFrm();
         if ( pFly->Lower() && pFly->Lower()->IsNoTextFrm() )
         {
             if ( static_cast<const SwContentFrm*>(pFly->Lower())->GetNode()->GetGrfNode() )


More information about the Libreoffice-commits mailing list