From 8f453c674f19188360ba5895c2bd9bd80273a83b Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Sun, 10 Jan 2021 13:58:50 +0200 Subject: static_cast after dynamic_cast Change-Id: I3792ddadad9582a7e6f4740829c081d9571ddaff Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109049 Tested-by: Jenkins Reviewed-by: Noel Grandin --- sw/source/core/frmedt/feshview.cxx | 8 ++++---- sw/source/core/layout/fly.cxx | 4 ++-- sw/source/core/view/vdraw.cxx | 7 +++++-- sw/source/filter/ww8/ww8graf.cxx | 11 ++++++----- sw/source/filter/xml/xmltble.cxx | 5 ++--- sw/source/ui/dialog/docstdlg.cxx | 8 ++++---- sw/source/uibase/app/apphdl.cxx | 8 ++++---- sw/source/uibase/app/docsh.cxx | 12 ++++++------ sw/source/uibase/uiview/view.cxx | 4 ++-- 9 files changed, 35 insertions(+), 32 deletions(-) (limited to 'sw') diff --git a/sw/source/core/frmedt/feshview.cxx b/sw/source/core/frmedt/feshview.cxx index 4250a11f8684..691f60ca3592 100644 --- a/sw/source/core/frmedt/feshview.cxx +++ b/sw/source/core/frmedt/feshview.cxx @@ -3087,11 +3087,11 @@ void SwFEShell::CreateDefaultShape( SdrObjKind eSdrObjectKind, const tools::Rect SetLineEnds(aAttr, *pObj, nSlotId); pObj->SetMergedItemSet(aAttr); } - else if(auto pCationObj = dynamic_cast( pObj)) + else if(auto pCaptionObj = dynamic_cast( pObj)) { bool bVerticalText = ( SID_DRAW_TEXT_VERTICAL == nSlotId || SID_DRAW_CAPTION_VERTICAL == nSlotId ); - static_cast(pObj)->SetVerticalWriting(bVerticalText); + pCaptionObj->SetVerticalWriting(bVerticalText); if(bVerticalText) { SfxItemSet aSet(pObj->GetMergedItemSet()); @@ -3100,8 +3100,8 @@ void SwFEShell::CreateDefaultShape( SdrObjKind eSdrObjectKind, const tools::Rect pObj->SetMergedItemSet(aSet); } - pCationObj->SetLogicRect(aRect); - pCationObj->SetTailPos( + pCaptionObj->SetLogicRect(aRect); + pCaptionObj->SetTailPos( aRect.TopLeft() - Point(aRect.GetWidth() / 2, aRect.GetHeight() / 2)); } else if(auto pText = dynamic_cast( pObj)) diff --git a/sw/source/core/layout/fly.cxx b/sw/source/core/layout/fly.cxx index 299932e8fa7c..9d79621c5d15 100644 --- a/sw/source/core/layout/fly.cxx +++ b/sw/source/core/layout/fly.cxx @@ -319,9 +319,9 @@ void SwFlyFrame::DeleteCnt() while ( pFrame->GetDrawObjs() && pFrame->GetDrawObjs()->size() ) { SwAnchoredObject *pAnchoredObj = (*pFrame->GetDrawObjs())[0]; - if ( dynamic_cast( pAnchoredObj) != nullptr ) + if ( auto pFlyFrame = dynamic_cast( pAnchoredObj) ) { - SwFrame::DestroyFrame(static_cast(pAnchoredObj)); + SwFrame::DestroyFrame(pFlyFrame); } else if ( dynamic_cast( pAnchoredObj) != nullptr ) { diff --git a/sw/source/core/view/vdraw.cxx b/sw/source/core/view/vdraw.cxx index c0a30276b251..94f2f2240655 100644 --- a/sw/source/core/view/vdraw.cxx +++ b/sw/source/core/view/vdraw.cxx @@ -223,10 +223,13 @@ void SwViewShellImp::NotifySizeChg( const Size &rNewSz ) // this function might be called by the InsertDocument, when // a PageDesc-Attribute is set on a node. Then the SdrObject // must not have an UserCall. - if( !pCont || dynamic_cast( pCont) == nullptr ) + if( !pCont ) + continue; + auto pDrawContact = dynamic_cast( pCont); + if( !pDrawContact ) continue; - const SwFrame *pAnchor = static_cast(pCont)->GetAnchorFrame(); + const SwFrame *pAnchor = pDrawContact->GetAnchorFrame(); if ( !pAnchor || pAnchor->IsInFly() || !pAnchor->isFrameAreaDefinitionValid() || !pAnchor->GetUpper() || !pAnchor->FindPageFrame() || (RndStdIds::FLY_AS_CHAR == pCont->GetFormat()->GetAnchor().GetAnchorId()) ) diff --git a/sw/source/filter/ww8/ww8graf.cxx b/sw/source/filter/ww8/ww8graf.cxx index c2efe73c3830..de8a1866ba36 100644 --- a/sw/source/filter/ww8/ww8graf.cxx +++ b/sw/source/filter/ww8/ww8graf.cxx @@ -2200,11 +2200,12 @@ SdrObject* SwWW8ImplReader::CreateContactObject(SwFrameFormat* pFlyFormat) SdrObject* pNewObject = m_bNewDoc ? nullptr : pFlyFormat->FindRealSdrObject(); if (!pNewObject) pNewObject = pFlyFormat->FindSdrObject(); - if (!pNewObject && dynamic_cast< const SwFlyFrameFormat *>( pFlyFormat ) != nullptr) - { - SwFlyDrawContact* pContactObject(static_cast(pFlyFormat)->GetOrCreateContact()); - pNewObject = pContactObject->GetMaster(); - } + if (!pNewObject ) + if (auto pFlyFrameFormat = dynamic_cast( pFlyFormat )) + { + SwFlyDrawContact* pContactObject = pFlyFrameFormat->GetOrCreateContact(); + pNewObject = pContactObject->GetMaster(); + } return pNewObject; } return nullptr; diff --git a/sw/source/filter/xml/xmltble.cxx b/sw/source/filter/xml/xmltble.cxx index a681fc4cf38d..ad79a92e3732 100644 --- a/sw/source/filter/xml/xmltble.cxx +++ b/sw/source/filter/xml/xmltble.cxx @@ -1122,11 +1122,10 @@ void SwXMLExport::ExportTable( const SwTableNode& rTableNd ) SvXMLElementExport aElem(*this, *oPrefix, XML_TABLE, true, true); // export DDE source (if this is a DDE table) - if ( dynamic_cast( &rTable) != nullptr ) + if ( auto pSwDdeTable = dynamic_cast( &rTable) ) { // get DDE Field Type (contains the DDE connection) - const SwDDEFieldType* pDDEFieldType = - static_cast(rTable).GetDDEFieldType(); + const SwDDEFieldType* pDDEFieldType = pSwDdeTable->GetDDEFieldType(); // connection name AddAttribute( XML_NAMESPACE_OFFICE, XML_NAME, diff --git a/sw/source/ui/dialog/docstdlg.cxx b/sw/source/ui/dialog/docstdlg.cxx index 7aacfd94cd5f..c9b362355c6e 100644 --- a/sw/source/ui/dialog/docstdlg.cxx +++ b/sw/source/ui/dialog/docstdlg.cxx @@ -95,10 +95,10 @@ void SwDocStatPage::Update() { SfxViewShell *pVSh = SfxViewShell::Current(); SwViewShell *pSh = nullptr; - if ( dynamic_cast< const SwView *>( pVSh ) != nullptr ) - pSh = static_cast(pVSh)->GetWrtShellPtr(); - else if ( dynamic_cast< const SwPagePreview *>( pVSh ) != nullptr ) - pSh = static_cast(pVSh)->GetViewShell(); + if ( auto pSwView = dynamic_cast( pVSh ) ) + pSh = pSwView->GetWrtShellPtr(); + else if ( auto pPagePreview = dynamic_cast( pVSh ) ) + pSh = pPagePreview->GetViewShell(); OSL_ENSURE( pSh, "Shell not found" ); diff --git a/sw/source/uibase/app/apphdl.cxx b/sw/source/uibase/app/apphdl.cxx index d4bcf37d4fca..3074d96f7bab 100644 --- a/sw/source/uibase/app/apphdl.cxx +++ b/sw/source/uibase/app/apphdl.cxx @@ -964,10 +964,10 @@ void SwModule::ConfigurationChanged( utl::ConfigurationBroadcaster* pBrdCst, Con { if(bAccessibility) { - if(dynamic_cast< const SwView *>( pViewShell ) != nullptr) - static_cast(pViewShell)->ApplyAccessibilityOptions(*m_pAccessibilityOptions); - else if(dynamic_cast< const SwPagePreview *>( pViewShell ) != nullptr) - static_cast(pViewShell)->ApplyAccessibilityOptions(*m_pAccessibilityOptions); + if(auto pSwView = dynamic_cast( pViewShell )) + pSwView->ApplyAccessibilityOptions(*m_pAccessibilityOptions); + else if(auto pPagePreview = dynamic_cast( pViewShell )) + pPagePreview->ApplyAccessibilityOptions(*m_pAccessibilityOptions); } pViewShell->GetWindow()->Invalidate(); } diff --git a/sw/source/uibase/app/docsh.cxx b/sw/source/uibase/app/docsh.cxx index 16b3a66d8460..b6937382ebe8 100644 --- a/sw/source/uibase/app/docsh.cxx +++ b/sw/source/uibase/app/docsh.cxx @@ -994,12 +994,12 @@ void SwDocShell::GetState(SfxItemSet& rSet) SfxViewFrame *pTmpFrame = SfxViewFrame::GetFirst(this); while (pTmpFrame) // Look for Preview { - if ( dynamic_cast( pTmpFrame->GetViewShell() ) && - static_cast(pTmpFrame->GetViewShell())->GetWrtShell().GetViewOptions()->getBrowseMode() ) - { - bDisable = true; - break; - } + if ( auto pSwView = dynamic_cast( pTmpFrame->GetViewShell() ) ) + if (pSwView->GetWrtShell().GetViewOptions()->getBrowseMode()) + { + bDisable = true; + break; + } pTmpFrame = SfxViewFrame::GetNext(*pTmpFrame, this); } } diff --git a/sw/source/uibase/uiview/view.cxx b/sw/source/uibase/uiview/view.cxx index 0e12a868f88d..5f5fd34029af 100644 --- a/sw/source/uibase/uiview/view.cxx +++ b/sw/source/uibase/uiview/view.cxx @@ -1613,9 +1613,9 @@ SwGlossaryHdl* SwView::GetGlosHdl() void SwView::Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) { bool bCallBase = true; - if(dynamic_cast(&rHint)) + if(auto pChangedHint = dynamic_cast(&rHint)) { - bool bDesignMode = static_cast(rHint).GetDesignMode(); + bool bDesignMode = pChangedHint->GetDesignMode(); if (!bDesignMode && GetDrawFuncPtr()) { GetDrawFuncPtr()->Deactivate(); -- cgit