From e139edfa1df7e7353b420be20d298fd2882d9289 Mon Sep 17 00:00:00 2001 From: Jan Holesovsky Date: Mon, 8 Aug 2016 10:32:31 +0200 Subject: Simplify dynamic_cast followed by a static_cast. Change-Id: I258906a66f83f5b9b63bd034a22bad3648117819 --- sw/source/uibase/docvw/edtwin3.cxx | 59 +++++++++++++++++++++---------------- sw/source/uibase/docvw/srcedtw.cxx | 8 ++--- sw/source/uibase/ribbar/conrect.cxx | 21 +++++++------ 3 files changed, 49 insertions(+), 39 deletions(-) (limited to 'sw') diff --git a/sw/source/uibase/docvw/edtwin3.cxx b/sw/source/uibase/docvw/edtwin3.cxx index 52c56de46ecb..b059ca314ea2 100644 --- a/sw/source/uibase/docvw/edtwin3.cxx +++ b/sw/source/uibase/docvw/edtwin3.cxx @@ -40,47 +40,51 @@ void ScrollMDI( SwViewShell* pVwSh, const SwRect &rRect, sal_uInt16 nRangeX, sal_uInt16 nRangeY) { - SfxViewShell *pSfxVwSh = pVwSh->GetSfxViewShell(); - if (pSfxVwSh && dynamic_cast< const SwView *>( pSfxVwSh ) != nullptr) - static_cast(pSfxVwSh)->Scroll( rRect.SVRect(), nRangeX, nRangeY ); + SfxViewShell *pSfxViewShell = pVwSh->GetSfxViewShell(); + + if (SwView* pSwView = dynamic_cast(pSfxViewShell)) + pSwView->Scroll(rRect.SVRect(), nRangeX, nRangeY); } // Docmdi - movable bool IsScrollMDI( SwViewShell* pVwSh, const SwRect &rRect ) { - SfxViewShell *pSfxVwSh = pVwSh->GetSfxViewShell(); - if (pSfxVwSh && dynamic_cast< const SwView *>( pSfxVwSh ) != nullptr) - return static_cast(pSfxVwSh)->IsScroll(rRect.SVRect()); + SfxViewShell *pSfxViewShell = pVwSh->GetSfxViewShell(); + + if (SwView* pSwView = dynamic_cast(pSfxViewShell)) + return pSwView->IsScroll(rRect.SVRect()); + return false; } // Notify for size change void SizeNotify(SwViewShell* pVwSh, const Size &rSize) { - SfxViewShell *pSfxVwSh = pVwSh->GetSfxViewShell(); - if (pSfxVwSh) - { - if (dynamic_cast< const SwView *>( pSfxVwSh ) != nullptr) - static_cast(pSfxVwSh)->DocSzChgd(rSize); - else if (dynamic_cast< const SwPagePreview *>( pSfxVwSh ) != nullptr) - static_cast(pSfxVwSh)->DocSzChgd( rSize ); - } + SfxViewShell *pSfxViewShell = pVwSh->GetSfxViewShell(); + + if (SwView* pSwView = dynamic_cast(pSfxViewShell)) + pSwView->DocSzChgd(rSize); + else if (SwPagePreview* pSwPageView = dynamic_cast(pSfxViewShell)) + pSwPageView->DocSzChgd(rSize); } // Notify for page number update void PageNumNotify( SwViewShell* pVwSh, sal_uInt16 nPhyNum, sal_uInt16 nVirtNum, const OUString& rPgStr) { - SfxViewShell *pSfxVwSh = pVwSh->GetSfxViewShell(); - if ( pSfxVwSh && dynamic_cast< const SwView *>( pSfxVwSh ) != nullptr && - static_cast(pSfxVwSh)->GetCurShell() ) - static_cast(pSfxVwSh)->UpdatePageNums(nPhyNum, nVirtNum, rPgStr); + SfxViewShell *pSfxViewShell = pVwSh->GetSfxViewShell(); + + if (SwView* pSwView = dynamic_cast(pSfxViewShell)) + { + if (pSwView->GetCurShell()) + pSwView->UpdatePageNums(nPhyNum, nVirtNum, rPgStr); + } } void FrameNotify( SwViewShell* pVwSh, FlyMode eMode ) { - if ( dynamic_cast< const SwCursorShell *>( pVwSh ) != nullptr ) - SwBaseShell::SetFrameMode( eMode, static_cast(pVwSh) ); + if (SwWrtShell* pWrtShell = dynamic_cast(pVwSh)) + SwBaseShell::SetFrameMode(eMode, pWrtShell); } // Notify for page number update @@ -110,16 +114,19 @@ TableChgMode GetTableChgDefaultMode() void RepaintPagePreview( SwViewShell* pVwSh, const SwRect& rRect ) { - SfxViewShell *pSfxVwSh = pVwSh->GetSfxViewShell(); - if (pSfxVwSh && dynamic_cast< const SwPagePreview *>( pSfxVwSh ) != nullptr) - static_cast(pSfxVwSh)->RepaintCoreRect( rRect ); + SfxViewShell *pSfxViewShell = pVwSh->GetSfxViewShell(); + + if (SwPagePreview* pSwPagePreview = dynamic_cast(pSfxViewShell)) + pSwPagePreview->RepaintCoreRect(rRect); } bool JumpToSwMark( SwViewShell* pVwSh, const OUString& rMark ) { - SfxViewShell *pSfxVwSh = pVwSh->GetSfxViewShell(); - if( pSfxVwSh && dynamic_cast< const SwView *>( pSfxVwSh ) != nullptr ) - return static_cast(pSfxVwSh)->JumpToSwMark( rMark ); + SfxViewShell *pSfxViewShell = pVwSh->GetSfxViewShell(); + + if (SwView* pSwView = dynamic_cast(pSfxViewShell)) + return pSwView->JumpToSwMark(rMark); + return false; } diff --git a/sw/source/uibase/docvw/srcedtw.cxx b/sw/source/uibase/docvw/srcedtw.cxx index 749d53ceab9f..09741aa7e17d 100644 --- a/sw/source/uibase/docvw/srcedtw.cxx +++ b/sw/source/uibase/docvw/srcedtw.cxx @@ -742,11 +742,11 @@ void SwSrcEditWindow::ImpDoHighlight( const OUString& rSource, sal_uInt16 nLineO void SwSrcEditWindow::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) { - if ( !dynamic_cast(&rHint) ) + const TextHint* pTextHint = dynamic_cast(&rHint); + if (!pTextHint) return; - const TextHint& rTextHint = static_cast(rHint); - switch (rTextHint.GetId()) + switch (pTextHint->GetId()) { case TEXT_HINT_VIEWSCROLLED: m_pHScrollbar->SetThumbPos( m_pTextView->GetStartDocPos().X() ); @@ -762,7 +762,7 @@ void SwSrcEditWindow::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) case TEXT_HINT_PARAINSERTED: case TEXT_HINT_PARACONTENTCHANGED: - DoDelayedSyntaxHighlight( (sal_uInt16)rTextHint.GetValue() ); + DoDelayedSyntaxHighlight(static_cast(pTextHint->GetValue())); break; } } diff --git a/sw/source/uibase/ribbar/conrect.cxx b/sw/source/uibase/ribbar/conrect.cxx index 9966394a04d8..14465603fcca 100644 --- a/sw/source/uibase/ribbar/conrect.cxx +++ b/sw/source/uibase/ribbar/conrect.cxx @@ -95,20 +95,23 @@ bool ConstRectangle::MouseButtonUp(const MouseEvent& rMEvt) pObj->SetMergedItemSetAndBroadcast(aItemSet); } } - else if(mbVertical && pObj && dynamic_cast< const SdrTextObj *>( pObj ) != nullptr) + else if(mbVertical) { - SdrTextObj* pText = static_cast(pObj); - SfxItemSet aSet(pSdrView->GetModel()->GetItemPool()); + if (SdrTextObj* pText = dynamic_cast(pObj)) + { + SfxItemSet aSet(pSdrView->GetModel()->GetItemPool()); - pText->SetVerticalWriting(true); + pText->SetVerticalWriting(true); - aSet.Put(makeSdrTextAutoGrowWidthItem(true)); - aSet.Put(makeSdrTextAutoGrowHeightItem(false)); - aSet.Put(SdrTextVertAdjustItem(SDRTEXTVERTADJUST_TOP)); - aSet.Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_RIGHT)); + aSet.Put(makeSdrTextAutoGrowWidthItem(true)); + aSet.Put(makeSdrTextAutoGrowHeightItem(false)); + aSet.Put(SdrTextVertAdjustItem(SDRTEXTVERTADJUST_TOP)); + aSet.Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_RIGHT)); - pText->SetMergedItemSet(aSet); + pText->SetMergedItemSet(aSet); + } } + if( pObj ) { SdrPageView* pPV = pSdrView->GetSdrPageView(); -- cgit