From d5f48d742ac1fea9fd341244bbcea09bcd78b476 Mon Sep 17 00:00:00 2001 From: Michael Weghorn Date: Sat, 10 Jan 2015 15:52:17 +0100 Subject: fdo#39440 reduce scope of local variables This addresses some cppcheck warnings. Change-Id: I46b9293eed0cba2ebca119cc1fb0a6334ea66308 Reviewed-on: https://gerrit.libreoffice.org/13844 Tested-by: Jenkins Reviewed-by: Noel Grandin --- svtools/source/contnr/treelistbox.cxx | 10 ++++------ svtools/source/contnr/treelistentry.cxx | 3 +-- svtools/source/control/calendar.cxx | 9 +++------ svtools/source/control/headbar.cxx | 3 ++- svtools/source/control/roadmap.cxx | 10 +++------- svtools/source/control/ruler.cxx | 13 +++++-------- svtools/source/control/tabbar.cxx | 9 ++++----- svtools/source/control/toolbarmenu.cxx | 2 +- svtools/source/misc/imap.cxx | 6 +++--- svtools/source/misc/imap2.cxx | 6 ++---- 10 files changed, 28 insertions(+), 43 deletions(-) (limited to 'svtools') diff --git a/svtools/source/contnr/treelistbox.cxx b/svtools/source/contnr/treelistbox.cxx index e9c00302fb32..28de1224101b 100644 --- a/svtools/source/contnr/treelistbox.cxx +++ b/svtools/source/contnr/treelistbox.cxx @@ -1502,11 +1502,10 @@ OUString SvTreeListBox::SearchEntryTextWithHeadTitle( SvTreeListEntry* pEntry ) sal_uInt16 nCount = pEntry->ItemCount(); sal_uInt16 nCur = 0; sal_uInt16 nHeaderCur = 0; - SvLBoxItem* pItem; while( nCur < nCount ) { // MT: SV_ITEM_ID_EXTENDRLBOXSTRING / GetExtendText() was in use in IA2 cws, but only used in sc: ScSolverOptionsString. Needed? - pItem = pEntry->GetItem( nCur ); + SvLBoxItem* pItem = pEntry->GetItem( nCur ); if ( (pItem->GetType() == SV_ITEM_ID_LBOXSTRING ) && !static_cast( pItem )->GetText().isEmpty() ) { @@ -1775,13 +1774,12 @@ void SvTreeListBox::InitEntry(SvTreeListEntry* pEntry, const OUString& aStr, const Image& aCollEntryBmp, const Image& aExpEntryBmp, SvLBoxButtonKind eButtonKind) { - SvLBoxButton* pButton; SvLBoxString* pString; SvLBoxContextBmp* pContextBmp; if( nTreeFlags & TREEFLAG_CHKBTN ) { - pButton= new SvLBoxButton( pEntry,eButtonKind,0,pCheckButtonData ); + SvLBoxButton* pButton= new SvLBoxButton( pEntry,eButtonKind,0,pCheckButtonData ); pEntry->AddItem( pButton ); } @@ -2319,14 +2317,14 @@ short SvTreeListBox::GetHeightOffset(const vcl::Font& /* rFont */, Size& aSizeLo void SvTreeListBox::SetEntryHeight( SvTreeListEntry* pEntry ) { - short nHeight, nHeightMax=0; + short nHeightMax=0; sal_uInt16 nCount = pEntry->ItemCount(); sal_uInt16 nCur = 0; SvViewDataEntry* pViewData = GetViewDataEntry( pEntry ); while( nCur < nCount ) { SvLBoxItem* pItem = pEntry->GetItem( nCur ); - nHeight = (short)(pItem->GetSize( pViewData, nCur ).Height()); + short nHeight = (short)(pItem->GetSize( pViewData, nCur ).Height()); if( nHeight > nHeightMax ) nHeightMax = nHeight; nCur++; diff --git a/svtools/source/contnr/treelistentry.cxx b/svtools/source/contnr/treelistentry.cxx index e294b9944129..e8bf2de05e5f 100644 --- a/svtools/source/contnr/treelistentry.cxx +++ b/svtools/source/contnr/treelistentry.cxx @@ -112,13 +112,12 @@ void SvTreeListEntry::Clone(SvTreeListEntry* pSource) nListPos |= ( pSource->nListPos & 0x7fffffff); nAbsPos = pSource->nAbsPos; - SvLBoxItem* pNewItem; maItems.clear(); ItemsType::iterator it = pSource->maItems.begin(), itEnd = pSource->maItems.end(); for (; it != itEnd; ++it) { SvLBoxItem* pItem = &(*it); - pNewItem = pItem->Create(); + SvLBoxItem* pNewItem = pItem->Create(); pNewItem->Clone(pItem); maItems.push_back(pNewItem); } diff --git a/svtools/source/control/calendar.cxx b/svtools/source/control/calendar.cxx index 45bd8aafe5ad..fa20f9910d91 100644 --- a/svtools/source/control/calendar.cxx +++ b/svtools/source/control/calendar.cxx @@ -506,10 +506,8 @@ sal_uInt16 Calendar::ImplHitTest( const Point& rPos, Date& rDate ) const else if ( maNextRect.IsInside( rPos ) ) return CALENDAR_HITTEST_NEXT; - long nX; long nY; long nOffX; - long nYMonth; sal_uInt16 nDay; DayOfWeek eStartDay = ImplGetWeekStart(); @@ -520,8 +518,8 @@ sal_uInt16 Calendar::ImplHitTest( const Point& rPos, Date& rDate ) const if ( rPos.Y() < nY ) return 0; - nX = 0; - nYMonth = nY+mnMonthHeight; + long nX = 0; + long nYMonth = nY+mnMonthHeight; for ( long j = 0; j < mnMonthPerLine; j++ ) { if ( (rPos.X() < nX) && (rPos.Y() < nYMonth) ) @@ -802,7 +800,6 @@ void Calendar::ImplDraw( bool bPaint ) Size aOutSize = GetOutputSizePixel(); long i; long j; - long nX; long nY; long nDeltaX; long nDeltaY; @@ -868,7 +865,7 @@ void Calendar::ImplDraw( bool bPaint ) DrawLine( aSepPos1, aSepPos2 ); } - nX = 0; + long nX = 0; for ( j = 0; j < mnMonthPerLine; j++ ) { nMonth = aDate.GetMonth(); diff --git a/svtools/source/control/headbar.cxx b/svtools/source/control/headbar.cxx index e3d455413e55..8913ca006edc 100644 --- a/svtools/source/control/headbar.cxx +++ b/svtools/source/control/headbar.cxx @@ -776,12 +776,13 @@ void HeaderBar::ImplStartDrag( const Point& rMousePos, bool bCommand ) void HeaderBar::ImplDrag( const Point& rMousePos ) { - bool bNewOutDrag; sal_uInt16 nPos = GetItemPos( mnCurItemId ); mnDragPos = rMousePos.X()-mnMouseOff; if ( mbItemMode ) { + bool bNewOutDrag; + Rectangle aItemRect = ImplGetItemRect( nPos ); if ( aItemRect.IsInside( rMousePos ) ) bNewOutDrag = false; diff --git a/svtools/source/control/roadmap.cxx b/svtools/source/control/roadmap.cxx index 093390848d32..7d8705eab97b 100644 --- a/svtools/source/control/roadmap.cxx +++ b/svtools/source/control/roadmap.cxx @@ -314,13 +314,12 @@ namespace svt const HL_Vector& rItems = m_pImpl->getHyperLabels(); if ( _nIndex < (ItemIndex)rItems.size() ) { - RoadmapItem* pItem = NULL; for ( HL_Vector::const_iterator i = rItems.begin() + _nIndex; i != rItems.end(); ++i, ++_nIndex ) { - pItem = *i; + RoadmapItem* pItem = *i; pItem->SetIndex( _nIndex ); pItem->SetPosition( GetPreviousHyperLabel( _nIndex ) ); @@ -463,12 +462,10 @@ namespace svt RoadmapTypes::ItemId ORoadmap::GetNextAvailableItemId( ItemIndex _nNewIndex ) { - RoadmapItem* pItem = NULL; - ItemIndex searchIndex = ++_nNewIndex; while ( searchIndex < m_pImpl->getItemCount() ) { - pItem = GetByIndex( searchIndex ); + RoadmapItem* pItem = GetByIndex( searchIndex ); if ( pItem->IsEnabled() ) return pItem->GetID( ); @@ -480,11 +477,10 @@ namespace svt RoadmapTypes::ItemId ORoadmap::GetPreviousAvailableItemId( ItemIndex _nNewIndex ) { - RoadmapItem* pItem = NULL; ItemIndex searchIndex = --_nNewIndex; while ( searchIndex > -1 ) { - pItem = GetByIndex( searchIndex ); + RoadmapItem* pItem = GetByIndex( searchIndex ); if ( pItem->IsEnabled() ) return pItem->GetID( ); diff --git a/svtools/source/control/ruler.cxx b/svtools/source/control/ruler.cxx index 1656813640d4..43584cd76acc 100644 --- a/svtools/source/control/ruler.cxx +++ b/svtools/source/control/ruler.cxx @@ -371,7 +371,6 @@ void Ruler::ImplInvertLines( bool bErase ) mbActive && !mbDrag && !mbFormat && !(mnUpdateFlags & RULER_UPDATE_LINES) ) { - long n; long nNullWinOff = mpData->nNullVirOff + mnVirOff; long nRulX1 = mpData->nRulVirOff + mnVirOff; long nRulX2 = nRulX1 + mpData->nRulWidth; @@ -387,7 +386,7 @@ void Ruler::ImplInvertLines( bool bErase ) // Draw lines for ( sal_uInt32 i = 0; i < mpData->pLines.size(); i++ ) { - n = mpData->pLines[i].nPos + nNullWinOff; + const long n = mpData->pLines[i].nPos + nNullWinOff; if ( (n >= nRulX1) && (n < nRulX2) ) { if ( mnWinStyle & WB_HORZ ) @@ -437,14 +436,11 @@ void Ruler::ImplDrawTicks( long nMin, long nMax, long nStart, long nTop, long nB long nTickLength2 = nTickLength3 * 0.66; long nTickLength1 = nTickLength2 * 0.66; - long n = 0; double nTick4 = aImplRulerUnitTab[mnUnitIndex].nTick4; - double nTick3 = 0; double nTick2 = 0; double nTickCount = aImplRulerUnitTab[mnUnitIndex].nTick1; double nTickUnit = 0; long nTickWidth; - long nTickLength; bool bNoTicks = false; double nAcceptanceDelta = 0.0001; @@ -544,7 +540,9 @@ void Ruler::ImplDrawTicks( long nMin, long nMax, long nStart, long nTop, long nB if ( !bNoTicks ) { + long n = 0; double nTick = 0.0; + double nTick3 = 0; if ( ( mnUnitIndex != RULER_UNIT_CHAR ) && ( mnUnitIndex != RULER_UNIT_LINE ) ) { @@ -617,7 +615,7 @@ void Ruler::ImplDrawTicks( long nMin, long nMax, long nStart, long nTop, long nB // Tick/Tick2 - Output (Strokes) else { - nTickLength = nTickLength1; + long nTickLength = nTickLength1; aStep = (nTick / nTick2); aRest = std::abs(aStep - std::floor(aStep)); @@ -1443,7 +1441,6 @@ bool Ruler::ImplHitTest( const Point& rPos, RulerSelection* pHitTest, long nX; long nY; long n1; - long n2; if ( !mbActive ) return false; @@ -1596,7 +1593,7 @@ bool Ruler::ImplHitTest( const Point& rPos, RulerSelection* pHitTest, for ( i = mpData->pBorders.size(); i; i-- ) { n1 = mpData->pBorders[i-1].nPos; - n2 = n1 + mpData->pBorders[i-1].nWidth; + long n2 = n1 + mpData->pBorders[i-1].nWidth; // borders have at least 3 pixel padding if ( !mpData->pBorders[i-1].nWidth ) diff --git a/svtools/source/control/tabbar.cxx b/svtools/source/control/tabbar.cxx index e3a6f15a5db8..629e52d6aa70 100644 --- a/svtools/source/control/tabbar.cxx +++ b/svtools/source/control/tabbar.cxx @@ -904,11 +904,12 @@ void TabBar::MouseButtonDown( const MouseEvent& rMEvt ) if ( nSelId ) { sal_uInt16 nPos = GetPagePos( nSelId ); - bool bSelectTab = false; pItem = (*mpItemList)[ nPos ]; if ( pItem->mbEnable ) { + bool bSelectTab = false; + if ( (rMEvt.GetMode() & MouseEventModifiers::MULTISELECT) && (mnWinStyle & WB_MULTISELECT) ) { if ( nSelId != mnCurPageId ) @@ -1672,7 +1673,6 @@ void TabBar::ImplPrePaint() if (!nItemCount) return; - ImplTabBarItem* pItem; // tabbar should be formatted ImplFormat(); @@ -1684,7 +1684,7 @@ void TabBar::ImplPrePaint() if ( mnCurPageId && (mnFirstPos == 0) && !mbDropPos ) { - pItem = (*mpItemList)[ GetPagePos( mnCurPageId ) ]; + ImplTabBarItem* pItem = (*mpItemList)[ GetPagePos( mnCurPageId ) ]; if ( pItem->maRect.IsEmpty() ) { // set mbDropPos (or misuse) to prevent Invalidate() @@ -1823,10 +1823,9 @@ Color TabBar::GetTabBgColor( sal_uInt16 nPageId ) const void TabBar::SetTabBgColor( sal_uInt16 nPageId, const Color& aTabBgColor ) { sal_uInt16 nPos = GetPagePos( nPageId ); - ImplTabBarItem* pItem; if ( nPos != PAGE_NOT_FOUND ) { - pItem = (*mpItemList)[ nPos ]; + ImplTabBarItem* pItem = (*mpItemList)[ nPos ]; if ( aTabBgColor != Color( COL_AUTO ) ) { pItem->maTabBgColor = aTabBgColor; diff --git a/svtools/source/control/toolbarmenu.cxx b/svtools/source/control/toolbarmenu.cxx index 825221de53be..beb142b21c0a 100644 --- a/svtools/source/control/toolbarmenu.cxx +++ b/svtools/source/control/toolbarmenu.cxx @@ -987,11 +987,11 @@ void ToolbarMenu::MouseMove( const MouseEvent& rMEvt ) void ToolbarMenu::implHighlightEntry( const MouseEvent& rMEvt, bool /*bMBDown*/ ) { - long nY = 0; long nMouseY = rMEvt.GetPosPixel().Y(); Size aOutSz = GetOutputSizePixel(); if ( ( nMouseY >= 0 ) && ( nMouseY < aOutSz.Height() ) ) { + long nY = 0; bool bHighlighted = false; const int nEntryCount = mpImpl->maEntryVector.size(); diff --git a/svtools/source/misc/imap.cxx b/svtools/source/misc/imap.cxx index 37f794cc0d3d..d3174ee7d276 100644 --- a/svtools/source/misc/imap.cxx +++ b/svtools/source/misc/imap.cxx @@ -537,10 +537,11 @@ bool IMapPolygonObject::IsEqual( const IMapPolygonObject& rEqObj ) const Polygon& rEqPoly = rEqObj.aPoly; const sal_uInt16 nCount = aPoly.GetSize(); const sal_uInt16 nEqCount = rEqPoly.GetSize(); - bool bDifferent = false; if ( nCount == nEqCount ) { + bool bDifferent = false; + for ( sal_uInt16 i = 0; i < nCount; i++ ) { if ( aPoly[ i ] != rEqPoly[ i ] ) @@ -865,12 +866,11 @@ void ImageMap::Scale( const Fraction& rFracX, const Fraction& rFracY ) void ImageMap::ImpWriteImageMap( SvStream& rOStm, const OUString& rBaseURL ) const { - IMapObject* pObj; size_t nCount = maList.size(); for ( size_t i = 0; i < nCount; i++ ) { - pObj = maList[ i ]; + IMapObject* pObj = maList[ i ]; pObj->Write( rOStm, rBaseURL ); } } diff --git a/svtools/source/misc/imap2.cxx b/svtools/source/misc/imap2.cxx index 3164f8a57e36..5edf20315975 100644 --- a/svtools/source/misc/imap2.cxx +++ b/svtools/source/misc/imap2.cxx @@ -157,12 +157,11 @@ void ImageMap::Write( SvStream& rOStm, sal_uLong nFormat, const OUString& rBaseU void ImageMap::ImpWriteCERN( SvStream& rOStm, const OUString& rBaseURL ) const { - IMapObject* pObj; size_t nCount = maList.size(); for ( size_t i = 0; i < nCount; i++ ) { - pObj = maList[ i ]; + IMapObject* pObj = maList[ i ]; switch( pObj->GetType() ) { @@ -186,12 +185,11 @@ void ImageMap::ImpWriteCERN( SvStream& rOStm, const OUString& rBaseURL ) const void ImageMap::ImpWriteNCSA( SvStream& rOStm, const OUString& rBaseURL ) const { - IMapObject* pObj; size_t nCount = maList.size(); for ( size_t i = 0; i < nCount; i++ ) { - pObj = maList[ i ]; + IMapObject* pObj = maList[ i ]; switch( pObj->GetType() ) { -- cgit