diff options
author | Arkadiy Illarionov <qarkai@gmail.com> | 2018-10-14 12:00:03 +0300 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-10-14 17:30:32 +0200 |
commit | 19be86249dcc5b13b3c95f5469600fa2bc1b749b (patch) | |
tree | e1468590650eea60e3897a8cb8b7c36bb9ab996b /vcl/source/window/toolbox.cxx | |
parent | 7758115d15ded2afd81946df0865ecc831b179aa (diff) |
Simplify containers iterations in vcl
Use range-based loop or replace with STL functions.
Change-Id: Ide2f89194238ae6a1f21e8132e2297710d9e6dcd
Reviewed-on: https://gerrit.libreoffice.org/61756
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'vcl/source/window/toolbox.cxx')
-rw-r--r-- | vcl/source/window/toolbox.cxx | 61 |
1 files changed, 17 insertions, 44 deletions
diff --git a/vcl/source/window/toolbox.cxx b/vcl/source/window/toolbox.cxx index 66563c6b9ee7..149aa0b99ef6 100644 --- a/vcl/source/window/toolbox.cxx +++ b/vcl/source/window/toolbox.cxx @@ -1916,16 +1916,9 @@ void lcl_hideDoubleSeparators( ToolBox::ImplToolItems& rItems ) if ( !bLastSep ) { // check if any visible items have to appear behind it - ToolBox::ImplToolItems::iterator temp_it; - for ( temp_it = it+1; temp_it != rItems.end(); ++temp_it ) - { - if ( (temp_it->meType == ToolBoxItemType::BUTTON) && - temp_it->mbVisible ) - { - it->mbVisible = true; - break; - } - } + if (std::any_of(it + 1, rItems.end(), [](const ImplToolItem& rItem) { + return (rItem.meType == ToolBoxItemType::BUTTON) && rItem.mbVisible; })) + it->mbVisible = true; } bLastSep = true; } @@ -4889,30 +4882,20 @@ bool ToolBox::ImplChangeHighlightUpDn( bool bUp, bool bNoCycle ) if( bUp ) { // select last valid non-clipped item - ImplToolItems::iterator it = mpData->m_aItems.end(); ImplToolItem* pItem = nullptr; - while( it != mpData->m_aItems.begin() ) - { - --it; - if ( ImplIsValidItem( &(*it), true ) ) - { - pItem = &(*it); - break; - } - } + auto it = std::find_if(mpData->m_aItems.rbegin(), mpData->m_aItems.rend(), + [](const ImplToolItem& rItem) { return ImplIsValidItem( &rItem, true ); }); + if( it != mpData->m_aItems.rend() ) + pItem = &(*it); + InvalidateMenuButton(); ImplChangeHighlight( pItem ); } else { // select first valid non-clipped item - ImplToolItems::iterator it = mpData->m_aItems.begin(); - while( it != mpData->m_aItems.end() ) - { - if ( ImplIsValidItem( &(*it), true ) ) - break; - ++it; - } + ImplToolItems::iterator it = std::find_if(mpData->m_aItems.begin(), mpData->m_aItems.end(), + [](const ImplToolItem& rItem) { return ImplIsValidItem( &rItem, true ); }); if( it != mpData->m_aItems.end() ) { InvalidateMenuButton(); @@ -4925,13 +4908,8 @@ bool ToolBox::ImplChangeHighlightUpDn( bool bUp, bool bNoCycle ) if( bUp ) { // Select first valid item - ImplToolItems::iterator it = mpData->m_aItems.begin(); - while( it != mpData->m_aItems.end() ) - { - if ( ImplIsValidItem( &(*it), false ) ) - break; - ++it; - } + ImplToolItems::iterator it = std::find_if(mpData->m_aItems.begin(), mpData->m_aItems.end(), + [](const ImplToolItem& rItem) { return ImplIsValidItem( &rItem, false ); }); // select the menu button if a clipped item would be selected if( (it != mpData->m_aItems.end() && &(*it) == ImplGetFirstClippedItem()) && IsMenuEnabled() ) @@ -4955,17 +4933,12 @@ bool ToolBox::ImplChangeHighlightUpDn( bool bUp, bool bNoCycle ) } else { - ImplToolItems::iterator it = mpData->m_aItems.end(); ImplToolItem* pItem = nullptr; - while( it != mpData->m_aItems.begin() ) - { - --it; - if ( ImplIsValidItem( &(*it), false ) ) - { - pItem = &(*it); - break; - } - } + auto it = std::find_if(mpData->m_aItems.rbegin(), mpData->m_aItems.rend(), + [](const ImplToolItem& rItem) { return ImplIsValidItem( &rItem, false ); }); + if( it != mpData->m_aItems.rend() ) + pItem = &(*it); + ImplChangeHighlight( pItem ); } return true; |