diff options
author | Arkadiy Illarionov <qarkai@gmail.com> | 2018-08-15 21:32:27 +0300 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-08-20 17:12:11 +0200 |
commit | 0787ce8814e37972a0c968f60008d4e8722b6e27 (patch) | |
tree | 9d2803ebda8813e6b3f2bc2e6f8a74953b2931c1 /vcl/source/window/splitwin.cxx | |
parent | d2c9c60fefb9687adbde4be61ed66a5123a2587f (diff) |
Simplify containers iterations, tdf#96099 follow-up
Use range-based loop or replace with std::any_of, std::find and
std::find_if where applicable.
Change-Id: I2f80788c49d56094c29b102eb96a7a7c079567c6
Reviewed-on: https://gerrit.libreoffice.org/59143
Tested-by: Jenkins
Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'vcl/source/window/splitwin.cxx')
-rw-r--r-- | vcl/source/window/splitwin.cxx | 267 |
1 files changed, 131 insertions, 136 deletions
diff --git a/vcl/source/window/splitwin.cxx b/vcl/source/window/splitwin.cxx index d43da0bd2411..2674bf7199cf 100644 --- a/vcl/source/window/splitwin.cxx +++ b/vcl/source/window/splitwin.cxx @@ -279,20 +279,19 @@ static ImplSplitSet* ImplFindSet( ImplSplitSet* pSet, sal_uInt16 nId ) if ( pSet->mnId == nId ) return pSet; - size_t nItems = pSet->mvItems.size(); std::vector< ImplSplitItem >& rItems = pSet->mvItems; - for ( size_t i = 0; i < nItems; i++ ) + for ( auto& rItem : rItems ) { - if ( rItems[i].mnId == nId ) - return rItems[i].mpSet.get(); + if ( rItem.mnId == nId ) + return rItem.mpSet.get(); } - for ( size_t i = 0; i < nItems; i++ ) + for ( auto& rItem : rItems ) { - if ( rItems[i].mpSet ) + if ( rItem.mpSet ) { - ImplSplitSet* pFindSet = ImplFindSet( rItems[i].mpSet.get(), nId ); + ImplSplitSet* pFindSet = ImplFindSet( rItem.mpSet.get(), nId ); if ( pFindSet ) return pFindSet; } @@ -315,11 +314,11 @@ static ImplSplitSet* ImplFindItem( ImplSplitSet* pSet, sal_uInt16 nId, sal_uInt1 } } - for ( size_t i = 0; i < nItems; i++ ) + for ( auto& rItem : rItems ) { - if ( rItems[i].mpSet ) + if ( rItem.mpSet ) { - ImplSplitSet* pFindSet = ImplFindItem( rItems[i].mpSet.get(), nId, rPos ); + ImplSplitSet* pFindSet = ImplFindItem( rItem.mpSet.get(), nId, rPos ); if ( pFindSet ) return pFindSet; } @@ -330,18 +329,17 @@ static ImplSplitSet* ImplFindItem( ImplSplitSet* pSet, sal_uInt16 nId, sal_uInt1 static sal_uInt16 ImplFindItem( ImplSplitSet* pSet, vcl::Window* pWindow ) { - size_t nItems = pSet->mvItems.size(); std::vector< ImplSplitItem >& rItems = pSet->mvItems; - for ( size_t i = 0; i < nItems; i++ ) + for ( auto& rItem : rItems ) { - if ( rItems[i].mpWindow == pWindow ) - return rItems[i].mnId; + if ( rItem.mpWindow == pWindow ) + return rItem.mnId; else { - if ( rItems[i].mpSet ) + if ( rItem.mpSet ) { - sal_uInt16 nId = ImplFindItem( rItems[i].mpSet.get(), pWindow ); + sal_uInt16 nId = ImplFindItem( rItem.mpSet.get(), pWindow ); if ( nId ) return nId; } @@ -354,15 +352,14 @@ static sal_uInt16 ImplFindItem( ImplSplitSet* pSet, vcl::Window* pWindow ) static sal_uInt16 ImplFindItem( ImplSplitSet* pSet, const Point& rPos, bool bRows, bool bDown = true ) { - size_t nItems = pSet->mvItems.size(); std::vector< ImplSplitItem >& rItems = pSet->mvItems; - for ( size_t i = 0; i < nItems; i++ ) + for ( auto& rItem : rItems ) { - if ( rItems[i].mnWidth && rItems[i].mnHeight ) + if ( rItem.mnWidth && rItem.mnHeight ) { - Point aPoint( rItems[i].mnLeft, rItems[i].mnTop ); - Size aSize( rItems[i].mnWidth, rItems[i].mnHeight ); + Point aPoint( rItem.mnLeft, rItem.mnTop ); + Size aSize( rItem.mnWidth, rItem.mnHeight ); tools::Rectangle aRect( aPoint, aSize ); if ( bRows ) { @@ -381,13 +378,13 @@ static sal_uInt16 ImplFindItem( ImplSplitSet* pSet, const Point& rPos, if ( aRect.IsInside( rPos ) ) { - if ( rItems[i].mpSet && !rItems[i].mpSet->mvItems.empty() ) + if ( rItem.mpSet && !rItem.mpSet->mvItems.empty() ) { - return ImplFindItem( rItems[i].mpSet.get(), rPos, - !(rItems[i].mnBits & SplitWindowItemFlags::ColSet) ); + return ImplFindItem( rItem.mpSet.get(), rPos, + !(rItem.mnBits & SplitWindowItemFlags::ColSet) ); } else - return rItems[i].mnId; + return rItem.mnId; } } } @@ -416,9 +413,9 @@ static void ImplCalcSet( ImplSplitSet* pSet, // get number of visible items nVisItems = 0; - for ( size_t i = 0; i < nItems; i++ ) + for ( auto& rItem : rItems ) { - if ( !(rItems[i].mnBits & SplitWindowItemFlags::Invisible) ) + if ( !(rItem.mnBits & SplitWindowItemFlags::Invisible) ) nVisItems++; } @@ -436,16 +433,16 @@ static void ImplCalcSet( ImplSplitSet* pSet, long nRelPercent = 0; long nAbsSize = 0; long nCurSize = 0; - for ( size_t i = 0; i < nItems; i++ ) + for ( auto& rItem : rItems ) { - if ( !(rItems[i].mnBits & SplitWindowItemFlags::Invisible) ) + if ( !(rItem.mnBits & SplitWindowItemFlags::Invisible) ) { - if ( rItems[i].mnBits & SplitWindowItemFlags::RelativeSize ) - nRelCount += rItems[i].mnSize; - else if ( rItems[i].mnBits & SplitWindowItemFlags::PercentSize ) - nPercent += rItems[i].mnSize; + if ( rItem.mnBits & SplitWindowItemFlags::RelativeSize ) + nRelCount += rItem.mnSize; + else if ( rItem.mnBits & SplitWindowItemFlags::PercentSize ) + nPercent += rItem.mnSize; else - nAbsSize += rItems[i].mnSize; + nAbsSize += rItem.mnSize; } } // map relative values to percentages (percentage here one tenth of a procent) @@ -469,27 +466,27 @@ static void ImplCalcSet( ImplSplitSet* pSet, if ( !nPercent ) nPercent = 1; long nSizeDelta = nCalcSize-nAbsSize; - for ( size_t i = 0; i < nItems; i++ ) + for ( auto& rItem : rItems ) { - if ( rItems[i].mnBits & SplitWindowItemFlags::Invisible ) - rItems[i].mnPixSize = 0; - else if ( rItems[i].mnBits & SplitWindowItemFlags::RelativeSize ) + if ( rItem.mnBits & SplitWindowItemFlags::Invisible ) + rItem.mnPixSize = 0; + else if ( rItem.mnBits & SplitWindowItemFlags::RelativeSize ) { if ( nSizeDelta <= 0 ) - rItems[i].mnPixSize = 0; + rItem.mnPixSize = 0; else - rItems[i].mnPixSize = (nSizeDelta*rItems[i].mnSize*nRelPercent)/nPercent; + rItem.mnPixSize = (nSizeDelta*rItem.mnSize*nRelPercent)/nPercent; } - else if ( rItems[i].mnBits & SplitWindowItemFlags::PercentSize ) + else if ( rItem.mnBits & SplitWindowItemFlags::PercentSize ) { if ( nSizeDelta <= 0 ) - rItems[i].mnPixSize = 0; + rItem.mnPixSize = 0; else - rItems[i].mnPixSize = (nSizeDelta*rItems[i].mnSize*nPercentFactor)/nPercent; + rItem.mnPixSize = (nSizeDelta*rItem.mnSize*nPercentFactor)/nPercent; } else - rItems[i].mnPixSize = rItems[i].mnSize; - nCurSize += rItems[i].mnPixSize; + rItem.mnPixSize = rItem.mnSize; + nCurSize += rItem.mnPixSize; } pSet->mbCalcPix = false; @@ -503,14 +500,14 @@ static void ImplCalcSet( ImplSplitSet* pSet, long nSizeWinSize = 0; // first resize absolute items relative - for ( size_t i = 0; i < nItems; i++ ) + for ( auto& rItem : rItems ) { - if ( !(rItems[i].mnBits & SplitWindowItemFlags::Invisible) ) + if ( !(rItem.mnBits & SplitWindowItemFlags::Invisible) ) { - if ( !(rItems[i].mnBits & (SplitWindowItemFlags::RelativeSize | SplitWindowItemFlags::PercentSize)) ) + if ( !(rItem.mnBits & (SplitWindowItemFlags::RelativeSize | SplitWindowItemFlags::PercentSize)) ) { nAbsItems++; - nSizeWinSize += rItems[i].mnPixSize; + nSizeWinSize += rItem.mnPixSize; } } } @@ -519,14 +516,14 @@ static void ImplCalcSet( ImplSplitSet* pSet, { long nNewSizeWinSize = 0; - for ( size_t i = 0; i < nItems; i++ ) + for ( auto& rItem : rItems ) { - if ( !(rItems[i].mnBits & SplitWindowItemFlags::Invisible) ) + if ( !(rItem.mnBits & SplitWindowItemFlags::Invisible) ) { - if ( !(rItems[i].mnBits & (SplitWindowItemFlags::RelativeSize | SplitWindowItemFlags::PercentSize)) ) + if ( !(rItem.mnBits & (SplitWindowItemFlags::RelativeSize | SplitWindowItemFlags::PercentSize)) ) { - rItems[i].mnPixSize += (nSizeDelta*rItems[i].mnPixSize)/nSizeWinSize; - nNewSizeWinSize += rItems[i].mnPixSize; + rItem.mnPixSize += (nSizeDelta*rItem.mnPixSize)/nSizeWinSize; + nNewSizeWinSize += rItem.mnPixSize; } } } @@ -543,30 +540,30 @@ static void ImplCalcSet( ImplSplitSet* pSet, nCalcItems = 0; while ( !nCalcItems ) { - for ( size_t i = 0; i < nItems; i++ ) + for ( auto& rItem : rItems ) { - rItems[i].mbSubSize = false; + rItem.mbSubSize = false; if ( j >= 2 ) - rItems[i].mbSubSize = true; + rItem.mbSubSize = true; else { - if ( !(rItems[i].mnBits & SplitWindowItemFlags::Invisible) ) + if ( !(rItem.mnBits & SplitWindowItemFlags::Invisible) ) { - if ( (nSizeDelta > 0) || rItems[i].mnPixSize ) + if ( (nSizeDelta > 0) || rItem.mnPixSize ) { if ( j >= 1 ) - rItems[i].mbSubSize = true; + rItem.mbSubSize = true; else { - if ( (j == 0) && (rItems[i].mnBits & (SplitWindowItemFlags::RelativeSize | SplitWindowItemFlags::PercentSize)) ) - rItems[i].mbSubSize = true; + if ( (j == 0) && (rItem.mnBits & (SplitWindowItemFlags::RelativeSize | SplitWindowItemFlags::PercentSize)) ) + rItem.mbSubSize = true; } } } } - if ( rItems[i].mbSubSize ) + if ( rItem.mbSubSize ) nCalcItems++; } @@ -577,13 +574,13 @@ static void ImplCalcSet( ImplSplitSet* pSet, long nErrorSum = nSizeDelta % nCalcItems; long nCurSizeDelta = nSizeDelta / nCalcItems; nMins = 0; - for ( size_t i = 0; i < nItems; i++ ) + for ( auto& rItem : rItems ) { - if ( rItems[i].mnBits & SplitWindowItemFlags::Invisible ) + if ( rItem.mnBits & SplitWindowItemFlags::Invisible ) nMins++; - else if ( rItems[i].mbSubSize ) + else if ( rItem.mbSubSize ) { - long* pSize = &(rItems[i].mnPixSize); + long* pSize = &(rItem.mnPixSize); long nTempErr; if ( nErrorSum ) @@ -720,34 +717,34 @@ static void ImplCalcSet( ImplSplitSet* pSet, } // calculate Sub-Set's - for ( size_t i = 0; i < nItems; i++ ) + for ( auto& rItem : rItems ) { - if ( rItems[i].mpSet && rItems[i].mnWidth && rItems[i].mnHeight ) + if ( rItem.mpSet && rItem.mnWidth && rItem.mnHeight ) { - ImplCalcSet( rItems[i].mpSet.get(), - rItems[i].mnLeft, rItems[i].mnTop, - rItems[i].mnWidth, rItems[i].mnHeight, - !(rItems[i].mnBits & SplitWindowItemFlags::ColSet) ); + ImplCalcSet( rItem.mpSet.get(), + rItem.mnLeft, rItem.mnTop, + rItem.mnWidth, rItem.mnHeight, + !(rItem.mnBits & SplitWindowItemFlags::ColSet) ); } } // set fixed - for ( size_t i = 0; i < nItems; i++ ) + for ( auto& rItem : rItems ) { - rItems[i].mbFixed = false; - if ( rItems[i].mnBits & SplitWindowItemFlags::Fixed ) - rItems[i].mbFixed = true; + rItem.mbFixed = false; + if ( rItem.mnBits & SplitWindowItemFlags::Fixed ) + rItem.mbFixed = true; else { // this item is also fixed if Child-Set is available, // if a child is fixed - if ( rItems[i].mpSet ) + if ( rItem.mpSet ) { - for ( auto const & j: rItems[i].mpSet->mvItems ) + for ( auto const & j: rItem.mpSet->mvItems ) { if ( j.mbFixed ) { - rItems[i].mbFixed = true; + rItem.mbFixed = true; break; } } @@ -759,64 +756,63 @@ static void ImplCalcSet( ImplSplitSet* pSet, void SplitWindow::ImplCalcSet2( SplitWindow* pWindow, ImplSplitSet* pSet, bool bHide, bool bRows ) { - size_t nItems = pSet->mvItems.size(); std::vector< ImplSplitItem >& rItems = pSet->mvItems; if ( pWindow->IsReallyVisible() && pWindow->IsUpdateMode() && pWindow->mbInvalidate ) { - for ( size_t i = 0; i < nItems; i++ ) + for ( auto& rItem : rItems ) { - if ( rItems[i].mnSplitSize ) + if ( rItem.mnSplitSize ) { // invalidate all, if applicable or only a small part - if ( (rItems[i].mnOldSplitPos != rItems[i].mnSplitPos) || - (rItems[i].mnOldSplitSize != rItems[i].mnSplitSize) || - (rItems[i].mnOldWidth != rItems[i].mnWidth) || - (rItems[i].mnOldHeight != rItems[i].mnHeight) ) + if ( (rItem.mnOldSplitPos != rItem.mnSplitPos) || + (rItem.mnOldSplitSize != rItem.mnSplitSize) || + (rItem.mnOldWidth != rItem.mnWidth) || + (rItem.mnOldHeight != rItem.mnHeight) ) { tools::Rectangle aRect; // invalidate old rectangle if ( bRows ) { - aRect.SetLeft( rItems[i].mnLeft ); - aRect.SetRight( rItems[i].mnLeft+rItems[i].mnOldWidth-1 ); - aRect.SetTop( rItems[i].mnOldSplitPos ); - aRect.SetBottom( aRect.Top() + rItems[i].mnOldSplitSize ); + aRect.SetLeft( rItem.mnLeft ); + aRect.SetRight( rItem.mnLeft+rItem.mnOldWidth-1 ); + aRect.SetTop( rItem.mnOldSplitPos ); + aRect.SetBottom( aRect.Top() + rItem.mnOldSplitSize ); } else { - aRect.SetTop( rItems[i].mnTop ); - aRect.SetBottom( rItems[i].mnTop+rItems[i].mnOldHeight-1 ); - aRect.SetLeft( rItems[i].mnOldSplitPos ); - aRect.SetRight( aRect.Left() + rItems[i].mnOldSplitSize ); + aRect.SetTop( rItem.mnTop ); + aRect.SetBottom( rItem.mnTop+rItem.mnOldHeight-1 ); + aRect.SetLeft( rItem.mnOldSplitPos ); + aRect.SetRight( aRect.Left() + rItem.mnOldSplitSize ); } pWindow->Invalidate( aRect ); // invalidate new rectangle if ( bRows ) { - aRect.SetLeft( rItems[i].mnLeft ); - aRect.SetRight( rItems[i].mnLeft+rItems[i].mnWidth-1 ); - aRect.SetTop( rItems[i].mnSplitPos ); - aRect.SetBottom( aRect.Top() + rItems[i].mnSplitSize ); + aRect.SetLeft( rItem.mnLeft ); + aRect.SetRight( rItem.mnLeft+rItem.mnWidth-1 ); + aRect.SetTop( rItem.mnSplitPos ); + aRect.SetBottom( aRect.Top() + rItem.mnSplitSize ); } else { - aRect.SetTop( rItems[i].mnTop ); - aRect.SetBottom( rItems[i].mnTop+rItems[i].mnHeight-1 ); - aRect.SetLeft( rItems[i].mnSplitPos ); - aRect.SetRight( aRect.Left() + rItems[i].mnSplitSize ); + aRect.SetTop( rItem.mnTop ); + aRect.SetBottom( rItem.mnTop+rItem.mnHeight-1 ); + aRect.SetLeft( rItem.mnSplitPos ); + aRect.SetRight( aRect.Left() + rItem.mnSplitSize ); } pWindow->Invalidate( aRect ); // invalidate complete set, as these areas // are not cluttered by windows - if ( rItems[i].mpSet && rItems[i].mpSet->mvItems.empty() ) + if ( rItem.mpSet && rItem.mpSet->mvItems.empty() ) { - aRect.SetLeft( rItems[i].mnLeft ); - aRect.SetTop( rItems[i].mnTop ); - aRect.SetRight( rItems[i].mnLeft+rItems[i].mnWidth-1 ); - aRect.SetBottom( rItems[i].mnTop+rItems[i].mnHeight-1 ); + aRect.SetLeft( rItem.mnLeft ); + aRect.SetTop( rItem.mnTop ); + aRect.SetRight( rItem.mnLeft+rItem.mnWidth-1 ); + aRect.SetBottom( rItem.mnTop+rItem.mnHeight-1 ); pWindow->Invalidate( aRect ); } } @@ -825,34 +821,34 @@ void SplitWindow::ImplCalcSet2( SplitWindow* pWindow, ImplSplitSet* pSet, bool b } // position windows - for ( size_t i = 0; i < nItems; i++ ) + for ( auto& rItem : rItems ) { - if ( rItems[i].mpSet ) + if ( rItem.mpSet ) { bool bTempHide = bHide; - if ( !rItems[i].mnWidth || !rItems[i].mnHeight ) + if ( !rItem.mnWidth || !rItem.mnHeight ) bTempHide = true; - ImplCalcSet2( pWindow, rItems[i].mpSet.get(), bTempHide, - !(rItems[i].mnBits & SplitWindowItemFlags::ColSet) ); + ImplCalcSet2( pWindow, rItem.mpSet.get(), bTempHide, + !(rItem.mnBits & SplitWindowItemFlags::ColSet) ); } else { - if ( rItems[i].mnWidth && rItems[i].mnHeight && !bHide ) + if ( rItem.mnWidth && rItem.mnHeight && !bHide ) { - Point aPos( rItems[i].mnLeft, rItems[i].mnTop ); - Size aSize( rItems[i].mnWidth, rItems[i].mnHeight ); - rItems[i].mpWindow->SetPosSizePixel( aPos, aSize ); + Point aPos( rItem.mnLeft, rItem.mnTop ); + Size aSize( rItem.mnWidth, rItem.mnHeight ); + rItem.mpWindow->SetPosSizePixel( aPos, aSize ); } else - rItems[i].mpWindow->Hide(); + rItem.mpWindow->Hide(); } } // show windows and reset flag - for ( size_t i = 0; i < nItems; i++ ) + for ( auto& rItem : rItems ) { - if ( rItems[i].mpWindow && rItems[i].mnWidth && rItems[i].mnHeight && !bHide ) - rItems[i].mpWindow->Show(); + if ( rItem.mpWindow && rItem.mnWidth && rItem.mnHeight && !bHide ) + rItem.mpWindow->Show(); } } @@ -894,28 +890,27 @@ static void ImplCalcLogSize( std::vector< ImplSplitItem > & rItems, size_t nItem void SplitWindow::ImplDrawBack(vcl::RenderContext& rRenderContext, ImplSplitSet* pSet) { - size_t nItems = pSet->mvItems.size(); std::vector< ImplSplitItem >& rItems = pSet->mvItems; - for (size_t i = 0; i < nItems; i++) + for ( auto& rItem : rItems ) { - pSet = rItems[i].mpSet.get(); + pSet = rItem.mpSet.get(); if (pSet) { if (pSet->mpWallpaper) { - Point aPoint(rItems[i].mnLeft, rItems[i].mnTop); - Size aSize(rItems[i].mnWidth, rItems[i].mnHeight); + Point aPoint(rItem.mnLeft, rItem.mnTop); + Size aSize(rItem.mnWidth, rItem.mnHeight); tools::Rectangle aRect(aPoint, aSize); rRenderContext.DrawWallpaper(aRect, *pSet->mpWallpaper); } } } - for (size_t i = 0; i < nItems; i++) + for ( auto& rItem : rItems ) { - if (rItems[i].mpSet) - ImplDrawBack(rRenderContext, rItems[i].mpSet.get()); + if (rItem.mpSet) + ImplDrawBack(rRenderContext, rItem.mpSet.get()); } } @@ -990,11 +985,11 @@ static void ImplDrawSplit(vcl::RenderContext& rRenderContext, ImplSplitSet* pSet } } - for (size_t i = 0; i < nItems; i++) + for ( auto& rItem : rItems ) { - if (rItems[i].mpSet && rItems[i].mnWidth && rItems[i].mnHeight) + if (rItem.mpSet && rItem.mnWidth && rItem.mnHeight) { - ImplDrawSplit(rRenderContext, rItems[i].mpSet.get(), !(rItems[i].mnBits & SplitWindowItemFlags::ColSet), true/*bDown*/); + ImplDrawSplit(rRenderContext, rItem.mpSet.get(), !(rItem.mnBits & SplitWindowItemFlags::ColSet), true/*bDown*/); } } } @@ -1061,13 +1056,13 @@ sal_uInt16 SplitWindow::ImplTestSplit( ImplSplitSet* pSet, const Point& rPos, } } - for ( size_t i = 0; i < nItems; i++ ) + for ( auto& rItem : rItems ) { - if ( rItems[i].mpSet ) + if ( rItem.mpSet ) { - nSplitTest = ImplTestSplit( rItems[i].mpSet.get(), rPos, + nSplitTest = ImplTestSplit( rItem.mpSet.get(), rPos, rMouseOff, ppFoundSet, rFoundPos, - !(rItems[i].mnBits & SplitWindowItemFlags::ColSet) ); + !(rItem.mnBits & SplitWindowItemFlags::ColSet) ); if ( nSplitTest ) return nSplitTest; } |