Modernize a bit vcl (part4)

by using for range loops
Remark: some iterators were used outside loops,
these have been replaced by the counterpart origin variable

Change-Id: I0b1e69811f16752b0962f5c5e662ea20064e26b4
Reviewed-on: https://gerrit.libreoffice.org/48829
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Julien Nabet <serval2412@yahoo.fr>
diff --git a/vcl/source/window/clipping.cxx b/vcl/source/window/clipping.cxx
index 9a45d03..b7c6fbf 100644
--- a/vcl/source/window/clipping.cxx
+++ b/vcl/source/window/clipping.cxx
@@ -329,13 +329,13 @@ bool Window::ImplSysObjClip( const vcl::Region* pOldRegion )
                    aRegion.GetRegionRectangles(aRectangles);
                    mpWindowImpl->mpSysObj->BeginSetClipRegion(aRectangles.size());

                    for(RectangleVector::const_iterator aRectIter(aRectangles.begin()); aRectIter != aRectangles.end(); ++aRectIter)
                    for (auto const& rectangle : aRectangles)
                    {
                        mpWindowImpl->mpSysObj->UnionClipRegion(
                            aRectIter->Left(),
                            aRectIter->Top(),
                            aRectIter->GetWidth(),   // orig nWidth was ((R - L) + 1), same as GetWidth does
                            aRectIter->GetHeight()); // same for height
                            rectangle.Left(),
                            rectangle.Top(),
                            rectangle.GetWidth(),   // orig nWidth was ((R - L) + 1), same as GetWidth does
                            rectangle.GetHeight()); // same for height
                    }

                    mpWindowImpl->mpSysObj->EndSetClipRegion();
diff --git a/vcl/source/window/dockingarea.cxx b/vcl/source/window/dockingarea.cxx
index 0f2f712..bbed7a0 100644
--- a/vcl/source/window/dockingarea.cxx
+++ b/vcl/source/window/dockingarea.cxx
@@ -226,21 +226,20 @@ void DockingAreaWindow::Paint(vcl::RenderContext& rRenderContext, const tools::R
            }

            // draw multiple toolbar backgrounds, i.e., one for each toolbar line
            std::map<int, int>::const_iterator it;
            for (it = ranges.begin(); it != ranges.end(); ++it)
            for (auto const& range : ranges)
            {
                tools::Rectangle aTBRect;
                if (IsHorizontal())
                {
                    aTBRect.Left()   = 0;
                    aTBRect.Right()  = aOutSz.Width() - 1;
                    aTBRect.Top()    = it->first;
                    aTBRect.Bottom() = it->first + it->second - 1;
                    aTBRect.Top()    = range.first;
                    aTBRect.Bottom() = range.first + range.second - 1;
                }
                else
                {
                    aTBRect.Left()   = it->first;
                    aTBRect.Right()  = it->first + it->second - 1;
                    aTBRect.Left()   = range.first;
                    aTBRect.Right()  = range.first + range.second - 1;
                    aTBRect.Top()    = 0;
                    aTBRect.Bottom() = aOutSz.Height() - 1;
                }
diff --git a/vcl/source/window/layout.cxx b/vcl/source/window/layout.cxx
index dc305db..83f9616 100644
--- a/vcl/source/window/layout.cxx
+++ b/vcl/source/window/layout.cxx
@@ -430,9 +430,9 @@ void VclBox::setAllocation(const Size &rAllocation)
            setPrimaryCoordinate(aPos, nPrimaryCoordinate + nAllocPrimaryDimension);
        }

        for (std::vector<vcl::Window*>::iterator aI = aWindows[ePackType].begin(), aEnd = aWindows[ePackType].end(); aI != aEnd; ++aI)
        for (auto const& window : aWindows[ePackType])
        {
            vcl::Window *pChild = *aI;
            vcl::Window *pChild = window;

            long nPadding = pChild->get_padding();

@@ -546,10 +546,9 @@ Size VclButtonBox::addReqGroups(const VclButtonBox::Requisition &rReq) const
static long getMaxNonOutlier(const std::vector<long> &rG, long nAvgDimension)
{
    long nMaxDimensionNonOutlier = 0;
    for (std::vector<long>::const_iterator aI = rG.begin(),
        aEnd = rG.end(); aI != aEnd; ++aI)
    for (auto const& elem : rG)
    {
        long nPrimaryChildDimension = *aI;
        long nPrimaryChildDimension = elem;
        if (nPrimaryChildDimension < nAvgDimension * 1.5)
        {
            nMaxDimensionNonOutlier = std::max(nPrimaryChildDimension,
@@ -567,10 +566,9 @@ static std::vector<long> setButtonSizes(const std::vector<long> &rG,
    //set everything < 1.5 times the average to the same width, leave the
    //outliers un-touched
    std::vector<bool>::const_iterator aJ = rNonHomogeneous.begin();
    for (std::vector<long>::const_iterator aI = rG.begin(), aEnd = rG.end();
        aI != aEnd; ++aI, ++aJ)
    for (auto const& elem : rG)
    {
        long nPrimaryChildDimension = *aI;
        long nPrimaryChildDimension = elem;
        bool bNonHomogeneous = *aJ;
        if (!bNonHomogeneous && nPrimaryChildDimension < nAvgDimension * 1.5)
        {
@@ -580,6 +578,7 @@ static std::vector<long> setButtonSizes(const std::vector<long> &rG,
        {
            aVec.push_back(std::max(nPrimaryChildDimension, nMinWidth));
        }
        ++aJ;
    }
    return aVec;
}
@@ -1044,10 +1043,9 @@ array_type assembleGrid(const VclGrid &rGrid)
                GridEntry &rEntry = A[rSpan.x][rSpan.y];
                candidates.insert(&rEntry);
            }
            for (std::set<GridEntry*>::iterator aI = candidates.begin(), aEnd = candidates.end();
                aI != aEnd; ++aI)
            for (auto const& candidate : candidates)
            {
                GridEntry *pEntry = *aI;
                GridEntry *pEntry = candidate;
                --pEntry->nSpanWidth;
            }
        }
@@ -1075,10 +1073,9 @@ array_type assembleGrid(const VclGrid &rGrid)
                GridEntry &rEntry = A[rSpan.x][rSpan.y];
                candidates.insert(&rEntry);
            }
            for (std::set<GridEntry*>::iterator aI = candidates.begin(), aEnd = candidates.end();
                aI != aEnd; ++aI)
            for (auto const& candidate : candidates)
            {
                GridEntry *pEntry = *aI;
                GridEntry *pEntry = candidate;
                --pEntry->nSpanHeight;
            }
        }
diff --git a/vcl/source/window/paint.cxx b/vcl/source/window/paint.cxx
index 17e6db7..53b4e8c 100644
--- a/vcl/source/window/paint.cxx
+++ b/vcl/source/window/paint.cxx
@@ -1062,13 +1062,13 @@ void Window::SetWindowRegionPixel( const vcl::Region& rRegion )
                mpWindowImpl->maWinRegion.GetRegionRectangles(aRectangles);
                mpWindowImpl->mpFrame->BeginSetClipRegion(aRectangles.size());

                for(RectangleVector::const_iterator aRectIter(aRectangles.begin()); aRectIter != aRectangles.end(); ++aRectIter)
                for (auto const& rectangle : aRectangles)
                {
                    mpWindowImpl->mpFrame->UnionClipRegion(
                        aRectIter->Left(),
                        aRectIter->Top(),
                        aRectIter->GetWidth(),       // orig nWidth was ((R - L) + 1), same as GetWidth does
                        aRectIter->GetHeight());     // same for height
                        rectangle.Left(),
                        rectangle.Top(),
                        rectangle.GetWidth(),       // orig nWidth was ((R - L) + 1), same as GetWidth does
                        rectangle.GetHeight());     // same for height
                }

                mpWindowImpl->mpFrame->EndSetClipRegion();
diff --git a/vcl/source/window/tabdlg.cxx b/vcl/source/window/tabdlg.cxx
index fa82012..a6559d8 100644
--- a/vcl/source/window/tabdlg.cxx
+++ b/vcl/source/window/tabdlg.cxx
@@ -302,9 +302,11 @@ std::vector<OString> TabDialog::getAllPageUIXMLDescriptions() const
                        // Use the UIXMLDescription without trailing '.ui', with one trailing '/'
                        bool bAlreadyAdded(false);

                        for (auto i = aRetval.begin(); !bAlreadyAdded && i != aRetval.end(); i++)
                        for (auto const& elem : aRetval)
                        {
                            bAlreadyAdded = (*i == aNewName);
                            bAlreadyAdded = (elem == aNewName);
                            if (bAlreadyAdded)
                                break;
                        }

                        if (bAlreadyAdded)
diff --git a/vcl/source/window/toolbox.cxx b/vcl/source/window/toolbox.cxx
index 24b8cac..111c875 100644
--- a/vcl/source/window/toolbox.cxx
+++ b/vcl/source/window/toolbox.cxx
@@ -619,13 +619,10 @@ static bool ImplIsFixedControl( const ImplToolItem *pItem )

const ImplToolItem *ToolBox::ImplGetFirstClippedItem() const
{
    ImplToolItems::const_iterator it;
    it = mpData->m_aItems.begin();
    while ( it != mpData->m_aItems.end() )
    for (auto & item : mpData->m_aItems)
    {
        if( it->IsClipped() )
            return &(*it);
        ++it;
        if( item.IsClipped() )
            return &item;
    }
    return nullptr;
}
@@ -754,25 +751,22 @@ void ToolBox::ImplCalcFloatSizes()
    // calculate the minimal size, i.e. where the biggest item just fits
    long            nCalcSize = 0;

    ImplToolItems::const_iterator it;
    it = mpData->m_aItems.begin();
    while ( it != mpData->m_aItems.end() )
    for (auto const& item : mpData->m_aItems)
    {
        if ( it->mbVisible )
        if ( item.mbVisible )
        {
            if ( it->mpWindow )
            if ( item.mpWindow )
            {
                long nTempSize = it->mpWindow->GetSizePixel().Width();
                long nTempSize = item.mpWindow->GetSizePixel().Width();
                if ( nTempSize > nCalcSize )
                    nCalcSize = nTempSize;
            }
            else
            {
                if( it->maItemSize.Width() > nCalcSize )
                    nCalcSize = it->maItemSize.Width();
                if( item.maItemSize.Width() > nCalcSize )
                    nCalcSize = item.maItemSize.Width();
            }
        }
        ++it;
    }

    // calc an upper bound for ImplCalcBreaks below
@@ -1385,12 +1379,10 @@ ImplToolItem* ToolBox::ImplGetItem( sal_uInt16 nItemId ) const
    if (!mpData)
        return nullptr;

    ImplToolItems::iterator it = mpData->m_aItems.begin();
    while ( it != mpData->m_aItems.end() )
    for (auto & item : mpData->m_aItems)
    {
        if ( it->mnId == nItemId )
            return &(*it);
        ++it;
        if ( item.mnId == nItemId )
            return &item;
    }

    return nullptr;
@@ -1502,37 +1494,36 @@ bool ToolBox::ImplCalcItem()

    if ( ! mpData->m_aItems.empty() )
    {
        ImplToolItems::iterator it = mpData->m_aItems.begin();
        while ( it != mpData->m_aItems.end() )
        for (auto & item : mpData->m_aItems)
        {
            it->mbVisibleText = false;  // indicates if text will definitely be drawn, influences dropdown pos
            item.mbVisibleText = false;  // indicates if text will definitely be drawn, influences dropdown pos

            if ( it->meType == ToolBoxItemType::BUTTON )
            if ( item.meType == ToolBoxItemType::BUTTON )
            {
                bool bImage;
                bool bText;

                // check if image and/or text exists
                bImage = !!it->maImage;
                bText = !it->maText.isEmpty();
                ButtonType tmpButtonType = determineButtonType( &(*it), meButtonType ); // default to toolbox setting
                bImage = !!item.maImage;
                bText = !item.maText.isEmpty();
                ButtonType tmpButtonType = determineButtonType( &item, meButtonType ); // default to toolbox setting
                if ( bImage || bText )
                {

                    it->mbEmptyBtn = false;
                    item.mbEmptyBtn = false;

                    if ( tmpButtonType == ButtonType::SYMBOLONLY )
                    {
                        // we're drawing images only
                        if ( bImage || !bText )
                        {
                            it->maItemSize = it->maImage.GetSizePixel();
                            item.maItemSize = item.maImage.GetSizePixel();
                        }
                        else
                        {
                            it->maItemSize = Size( GetCtrlTextWidth( it->maText )+TB_TEXTOFFSET,
                            item.maItemSize = Size( GetCtrlTextWidth( item.maText )+TB_TEXTOFFSET,
                                                   GetTextHeight() );
                            it->mbVisibleText = true;
                            item.mbVisibleText = true;
                        }
                    }
                    else if ( tmpButtonType == ButtonType::TEXT )
@@ -1540,135 +1531,133 @@ bool ToolBox::ImplCalcItem()
                        // we're drawing text only
                        if ( bText || !bImage )
                        {
                            it->maItemSize = Size( GetCtrlTextWidth( it->maText )+TB_TEXTOFFSET,
                            item.maItemSize = Size( GetCtrlTextWidth( item.maText )+TB_TEXTOFFSET,
                                                   GetTextHeight() );
                            it->mbVisibleText = true;
                            item.mbVisibleText = true;
                        }
                        else
                        {
                            it->maItemSize = it->maImage.GetSizePixel();
                            item.maItemSize = item.maImage.GetSizePixel();
                        }
                    }
                    else
                    {
                        // we're drawing images and text
                        it->maItemSize.Width() = bText ? GetCtrlTextWidth( it->maText )+TB_TEXTOFFSET : 0;
                        it->maItemSize.Height() = bText ? GetTextHeight() : 0;
                        item.maItemSize.Width() = bText ? GetCtrlTextWidth( item.maText )+TB_TEXTOFFSET : 0;
                        item.maItemSize.Height() = bText ? GetTextHeight() : 0;

                        if ( meTextPosition == ToolBoxTextPosition::Right )
                        {
                            // leave space between image and text
                            if( bText )
                                it->maItemSize.Width() += TB_IMAGETEXTOFFSET;
                                item.maItemSize.Width() += TB_IMAGETEXTOFFSET;

                            // image and text side by side
                            it->maItemSize.Width() += it->maImage.GetSizePixel().Width();
                            if ( it->maImage.GetSizePixel().Height() > it->maItemSize.Height() )
                                it->maItemSize.Height() = it->maImage.GetSizePixel().Height();
                            item.maItemSize.Width() += item.maImage.GetSizePixel().Width();
                            if ( item.maImage.GetSizePixel().Height() > item.maItemSize.Height() )
                                item.maItemSize.Height() = item.maImage.GetSizePixel().Height();
                        }
                        else
                        {
                            // leave space between image and text
                            if( bText )
                                it->maItemSize.Height() += TB_IMAGETEXTOFFSET;
                                item.maItemSize.Height() += TB_IMAGETEXTOFFSET;

                            // text below image
                            it->maItemSize.Height() += it->maImage.GetSizePixel().Height();
                            if ( it->maImage.GetSizePixel().Width() > it->maItemSize.Width() )
                                it->maItemSize.Width() = it->maImage.GetSizePixel().Width();
                            item.maItemSize.Height() += item.maImage.GetSizePixel().Height();
                            if ( item.maImage.GetSizePixel().Width() > item.maItemSize.Width() )
                                item.maItemSize.Width() = item.maImage.GetSizePixel().Width();
                        }

                        it->mbVisibleText = bText;
                        item.mbVisibleText = bText;
                    }
                }
                else
                {   // no image and no text
                    it->maItemSize = Size( nDefWidth, nDefHeight );
                    it->mbEmptyBtn = true;
                    item.maItemSize = Size( nDefWidth, nDefHeight );
                    item.mbEmptyBtn = true;
                }

                // save the content size
                it->maContentSize = it->maItemSize;
                item.maContentSize = item.maItemSize;

                // if required, take window height into consideration
                if ( it->mpWindow )
                if ( item.mpWindow )
                {
                    long nHeight = it->mpWindow->GetSizePixel().Height();
                    long nHeight = item.mpWindow->GetSizePixel().Height();
                    if ( nHeight > mnWinHeight )
                        mnWinHeight = nHeight;
                }

                // add in drop down arrow
                if( it->mnBits & ToolBoxItemBits::DROPDOWN )
                if( item.mnBits & ToolBoxItemBits::DROPDOWN )
                {
                    if ( meTextPosition == ToolBoxTextPosition::Right )
                    {
                        it->maItemSize.Width() += nDropDownArrowWidth;
                        it->mnDropDownArrowWidth = nDropDownArrowWidth;
                        item.maItemSize.Width() += nDropDownArrowWidth;
                        item.mnDropDownArrowWidth = nDropDownArrowWidth;
                    }
                    else
                    {
                        it->maItemSize.Height() += nDropDownArrowWidth;
                        it->mnDropDownArrowWidth = nDropDownArrowWidth;
                        item.maItemSize.Height() += nDropDownArrowWidth;
                        item.mnDropDownArrowWidth = nDropDownArrowWidth;
                    }
                }

                // text items will be rotated in vertical mode
                // -> swap width and height
                if( it->mbVisibleText && !mbHorz )
                if( item.mbVisibleText && !mbHorz )
                {
                    long tmp = it->maItemSize.Width();
                    it->maItemSize.Width() = it->maItemSize.Height();
                    it->maItemSize.Height() = tmp;
                    long tmp = item.maItemSize.Width();
                    item.maItemSize.Width() = item.maItemSize.Height();
                    item.maItemSize.Height() = tmp;

                    tmp = it->maContentSize.Width();
                    it->maContentSize.Width() = it->maContentSize.Height();
                    it->maContentSize.Height() = tmp;
                    tmp = item.maContentSize.Width();
                    item.maContentSize.Width() = item.maContentSize.Height();
                    item.maContentSize.Height() = tmp;
                }
            }
            else if ( it->meType == ToolBoxItemType::SPACE )
            else if ( item.meType == ToolBoxItemType::SPACE )
            {
                it->maItemSize = Size( nDefWidth, nDefHeight );
                it->maContentSize = it->maItemSize;
                item.maItemSize = Size( nDefWidth, nDefHeight );
                item.maContentSize = item.maItemSize;
            }

            if ( it->meType == ToolBoxItemType::BUTTON || it->meType == ToolBoxItemType::SPACE )
            if ( item.meType == ToolBoxItemType::BUTTON || item.meType == ToolBoxItemType::SPACE )
            {
                // add borders
                ImplAddButtonBorder( it->maItemSize.Width(), it->maItemSize.Height(), mpData->mbNativeButtons );
                ImplAddButtonBorder( item.maItemSize.Width(), item.maItemSize.Height(), mpData->mbNativeButtons );

                if( it->meType == ToolBoxItemType::BUTTON )
                if( item.meType == ToolBoxItemType::BUTTON )
                {
                    long nMinW = std::max(nMinWidth, it->maMinimalItemSize.Width());
                    long nMinH = std::max(nMinHeight, it->maMinimalItemSize.Height());
                    long nMinW = std::max(nMinWidth, item.maMinimalItemSize.Width());
                    long nMinH = std::max(nMinHeight, item.maMinimalItemSize.Height());

                    long nGrowContentWidth = 0;
                    long nGrowContentHeight = 0;

                    if( it->maItemSize.Width() < nMinW )
                    if( item.maItemSize.Width() < nMinW )
                    {
                        nGrowContentWidth = nMinW - it->maItemSize.Width();
                        it->maItemSize.Width() = nMinW;
                        nGrowContentWidth = nMinW - item.maItemSize.Width();
                        item.maItemSize.Width() = nMinW;
                    }
                    if( it->maItemSize.Height() < nMinH )
                    if( item.maItemSize.Height() < nMinH )
                    {
                        nGrowContentHeight = nMinH - it->maItemSize.Height();
                        it->maItemSize.Height() = nMinH;
                        nGrowContentHeight = nMinH - item.maItemSize.Height();
                        item.maItemSize.Height() = nMinH;
                    }

                    // grow the content size by the additional available space
                    it->maContentSize.Width() += nGrowContentWidth;
                    it->maContentSize.Height() += nGrowContentHeight;
                    item.maContentSize.Width() += nGrowContentWidth;
                    item.maContentSize.Height() += nGrowContentHeight;
                }

                // keep track of max item size
                if ( it->maItemSize.Width() > nMaxWidth )
                    nMaxWidth = it->maItemSize.Width();
                if ( it->maItemSize.Height() > nMaxHeight )
                    nMaxHeight = it->maItemSize.Height();
                if ( item.maItemSize.Width() > nMaxWidth )
                    nMaxWidth = item.maItemSize.Width();
                if ( item.maItemSize.Height() > nMaxHeight )
                    nMaxHeight = item.maItemSize.Height();
            }

            ++it;
        }
    }
    else
@@ -1972,8 +1961,6 @@ void ToolBox::ImplFormat( bool bResize )
    ImplToolItems::size_type nFormatLine;
    bool            bMustFullPaint;

    ImplToolItems::iterator   it;

    ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( this );
    bool bIsInPopupMode = ImplIsInPopupMode();

@@ -2094,11 +2081,9 @@ void ToolBox::ImplFormat( bool bResize )
        mnCurLine    = 1;
        mnCurLines   = 1;

        it = mpData->m_aItems.begin();
        while ( it != mpData->m_aItems.end() )
        for (auto & item : mpData->m_aItems)
        {
            it->maRect = aEmptyRect;
            ++it;
            item.maRect = aEmptyRect;
        }

        maLowerRect = aEmptyRect;
@@ -2217,13 +2202,12 @@ void ToolBox::ImplFormat( bool bResize )
            else if ( mnCurLine+mnVisLines-1 > mnCurLines )
                mnCurLine = mnCurLines - (mnVisLines-1);

            it = mpData->m_aItems.begin();
            while ( it != mpData->m_aItems.end() )
            for (auto & item : mpData->m_aItems)
            {
                it->mbShowWindow = false;
                item.mbShowWindow = false;

                // check for line break and advance nX/nY accordingly
                if ( it->mbBreak )
                if ( item.mbBreak )
                {
                    nFormatLine++;

@@ -2249,23 +2233,23 @@ void ToolBox::ImplFormat( bool bResize )
                    }
                }

                if ( !it->mbVisible || (nFormatLine < mnCurLine) ||
                if ( !item.mbVisible || (nFormatLine < mnCurLine) ||
                     (nFormatLine > mnCurLine+mnVisLines-1) )
                     // item is not visible
                    it->maCalcRect = aEmptyRect;
                    item.maCalcRect = aEmptyRect;
                else
                {
                    // 1. determine current item width/height
                    // take window size and orientation into account, because this affects the size of item windows

                    Size aCurrentItemSize( it->GetSize( mbHorz, mbScroll, nMax, Size(mnMaxItemWidth, mnMaxItemHeight) ) );
                    Size aCurrentItemSize( item.GetSize( mbHorz, mbScroll, nMax, Size(mnMaxItemWidth, mnMaxItemHeight) ) );

                    // 2. position item rect and use size from step 1
                    //  items will be centered horizontally (if mbHorz) or vertically
                    //  advance nX and nY accordingly
                    if ( mbHorz )
                    {
                        it->maCalcRect.Left()     = nX;
                        item.maCalcRect.Left()     = nX;
                        // if special ToolBoxLayoutMode::LockVert lock vertical position
                        // don't recalculate the vertical position of the item
                        if ( meLayoutMode == ToolBoxLayoutMode::LockVert && mnLines == 1 )
@@ -2274,55 +2258,53 @@ void ToolBox::ImplFormat( bool bResize )
                            // the sum/assign & ok/cancel items dynamically.
                            // Because ToolBoxLayoutMode::LockVert effectively prevents
                            // recalculation of the vertical pos of an item the
                            // it->maRect.Top() for those newly added items is
                            // item.maRect.Top() for those newly added items is
                            // 0. The hack here is that we want to effectively
                            // recalculate the vertical pos for those added
                            // items here. ( Note: assume mnMaxItemHeight is
                            // equal to the LineSize when multibar has a single
                            // line size )
                            if ( it->maRect.Top() ||
                                 (it->mpWindow && it->mpWindow->GetType() == WindowType::CALCINPUTLINE) ) // tdf#83099
                            if ( item.maRect.Top() ||
                                 (item.mpWindow && item.mpWindow->GetType() == WindowType::CALCINPUTLINE) ) // tdf#83099
                            {
                                it->maCalcRect.Top()  = it->maRect.Top();
                                item.maCalcRect.Top()  = item.maRect.Top();
                            }
                            else
                            {
                                it->maCalcRect.Top()  = nY+(mnMaxItemHeight-aCurrentItemSize.Height())/2;
                                item.maCalcRect.Top()  = nY+(mnMaxItemHeight-aCurrentItemSize.Height())/2;
                            }
                        }
                        else
                            it->maCalcRect.Top()      = nY+(nLineSize-aCurrentItemSize.Height())/2;
                        it->maCalcRect.Right()    = nX+aCurrentItemSize.Width()-1;
                        it->maCalcRect.Bottom()   = it->maCalcRect.Top()+aCurrentItemSize.Height()-1;
                            item.maCalcRect.Top()      = nY+(nLineSize-aCurrentItemSize.Height())/2;
                        item.maCalcRect.Right()    = nX+aCurrentItemSize.Width()-1;
                        item.maCalcRect.Bottom()   = item.maCalcRect.Top()+aCurrentItemSize.Height()-1;
                        nX += aCurrentItemSize.Width();
                    }
                    else
                    {
                        it->maCalcRect.Left()     = nX+(nLineSize-aCurrentItemSize.Width())/2;
                        it->maCalcRect.Top()      = nY;
                        it->maCalcRect.Right()    = it->maCalcRect.Left()+aCurrentItemSize.Width()-1;
                        it->maCalcRect.Bottom()   = nY+aCurrentItemSize.Height()-1;
                        item.maCalcRect.Left()     = nX+(nLineSize-aCurrentItemSize.Width())/2;
                        item.maCalcRect.Top()      = nY;
                        item.maCalcRect.Right()    = item.maCalcRect.Left()+aCurrentItemSize.Width()-1;
                        item.maCalcRect.Bottom()   = nY+aCurrentItemSize.Height()-1;
                        nY += aCurrentItemSize.Height();
                    }
                }

                // position window items into calculated item rect
                if ( it->mpWindow )
                if ( item.mpWindow )
                {
                    if ( it->mbShowWindow )
                    if ( item.mbShowWindow )
                    {
                        Point aPos( it->maCalcRect.Left(), it->maCalcRect.Top() );
                        Point aPos( item.maCalcRect.Left(), item.maCalcRect.Top() );

                        assert( it->maCalcRect.Top() >= 0 );
                        assert( item.maCalcRect.Top() >= 0 );

                        it->mpWindow->SetPosPixel( aPos );
                        it->mpWindow->Show();
                        item.mpWindow->SetPosPixel( aPos );
                        item.mpWindow->Show();
                    }
                    else
                        it->mpWindow->Hide();
                        item.mpWindow->Hide();
                }

                ++it;
            } // end of loop over all items
        }
        else
@@ -2383,15 +2365,13 @@ void ToolBox::ImplFormat( bool bResize )
                    maPaintRect.Union( aOldDragRect );
                }

                it = mpData->m_aItems.begin();
                while ( it != mpData->m_aItems.end() )
                for (auto const& item : mpData->m_aItems)
                {
                    if ( it->maRect != it->maCalcRect )
                    if ( item.maRect != item.maCalcRect )
                    {
                        maPaintRect.Union( it->maRect );
                        maPaintRect.Union( it->maCalcRect );
                        maPaintRect.Union( item.maRect );
                        maPaintRect.Union( item.maCalcRect );
                    }
                    ++it;
                }
            }

@@ -2400,12 +2380,8 @@ void ToolBox::ImplFormat( bool bResize )

        // store the new calculated item rects
        maPaintRect = aEmptyRect;
        it = mpData->m_aItems.begin();
        while ( it != mpData->m_aItems.end() )
        {
            it->maRect = it->maCalcRect;
            ++it;
        }
        for (auto & item : mpData->m_aItems)
            item.maRect = item.maCalcRect;
    }

    // indicate formatting is done
@@ -3266,29 +3242,25 @@ void ToolBox::MouseMove( const MouseEvent& rMEvt )
        ImplToolItems::size_type nNewPos = ITEM_NOTFOUND;

        // search the item that has been clicked
        ImplToolItems::const_iterator it = mpData->m_aItems.begin();
        while ( it != mpData->m_aItems.end() )
        for (auto const& item : mpData->m_aItems)
        {
            // if the mouse position is in this item,
            // we can stop the search
            if ( it->maRect.IsInside( aMousePos ) )
            if ( item.maRect.IsInside( aMousePos ) )
            {
                // select it if it is a button
                if ( it->meType == ToolBoxItemType::BUTTON )
                if ( item.meType == ToolBoxItemType::BUTTON )
                {
                    // if button is disabled, do not
                    // change it
                    if ( !it->mbEnabled || it->mbShowWindow )
                    if ( !item.mbEnabled || item.mbShowWindow )
                        nNewPos = mnCurPos;
                    else
                        nNewPos = i;
                }

                break;
            }

            i++;
            ++it;
            ++i;
        }

        // was a new entry selected?
@@ -3305,7 +3277,7 @@ void ToolBox::MouseMove( const MouseEvent& rMEvt )
            mnCurPos = nNewPos;
            if ( mnCurPos != ITEM_NOTFOUND )
            {
                mnCurItemId = mnHighItemId = it->mnId;
                mnCurItemId = mnHighItemId = mpData->m_aItems[mnCurPos].mnId;
                InvalidateItem(mnCurPos);
            }
            else
@@ -3357,19 +3329,18 @@ void ToolBox::MouseMove( const MouseEvent& rMEvt )
        bool bClearHigh = true;
        if ( !rMEvt.IsLeaveWindow() && (mnCurPos == ITEM_NOTFOUND) )
        {
            ImplToolItems::const_iterator it = mpData->m_aItems.begin();
            while ( it != mpData->m_aItems.end() )
            ImplToolItems::size_type nTempPos = 0;
            for (auto const& item : mpData->m_aItems)
            {
                if ( it->maRect.IsInside( aMousePos ) )
                if ( item.maRect.IsInside( aMousePos ) )
                {
                    if ( (it->meType == ToolBoxItemType::BUTTON) && it->mbEnabled )
                    if ( (item.meType == ToolBoxItemType::BUTTON) && item.mbEnabled )
                    {
                        if ( !mnOutStyle || (mnOutStyle & TOOLBOX_STYLE_FLAT) )
                        {
                            bClearHigh = false;
                            if ( mnHighItemId != it->mnId )
                            if ( mnHighItemId != item.mnId )
                            {
                                ImplToolItems::size_type nTempPos = it - mpData->m_aItems.begin();
                                if ( mnHighItemId )
                                {
                                    ImplHideFocus();
@@ -3382,7 +3353,7 @@ void ToolBox::MouseMove( const MouseEvent& rMEvt )
                                    // remove highlight from menubutton
                                    InvalidateMenuButton();
                                }
                                mnHighItemId = it->mnId;
                                mnHighItemId = item.mnId;
                                InvalidateItem(nTempPos);
                                ImplShowFocus();
                                CallEventListeners( VclEventId::ToolboxHighlight );
@@ -3391,8 +3362,7 @@ void ToolBox::MouseMove( const MouseEvent& rMEvt )
                    }
                    break;
                }

                ++it;
                ++nTempPos;
            }
        }

@@ -3458,29 +3428,27 @@ void ToolBox::MouseButtonDown( const MouseEvent& rMEvt )
        ImplToolItems::size_type nNewPos = ITEM_NOTFOUND;

        // search for item that was clicked
        ImplToolItems::const_iterator it = mpData->m_aItems.begin();
        while ( it != mpData->m_aItems.end() )
        for (auto const& item : mpData->m_aItems)
        {
            // is this the item?
            if ( it->maRect.IsInside( aMousePos ) )
            if ( item.maRect.IsInside( aMousePos ) )
            {
                // do nothing if it is a separator or
                // if the item has been disabled
                if ( (it->meType == ToolBoxItemType::BUTTON) &&
                     !it->mbShowWindow )
                if ( (item.meType == ToolBoxItemType::BUTTON) &&
                     !item.mbShowWindow )
                    nNewPos = i;

                break;
            }

            i++;
            ++it;
        }

        // item found
        if ( nNewPos != ITEM_NOTFOUND )
        {
            if ( !it->mbEnabled )
            if ( !mpData->m_aItems[nNewPos].mbEnabled )
            {
                Deactivate();
                return;
@@ -3489,10 +3457,10 @@ void ToolBox::MouseButtonDown( const MouseEvent& rMEvt )
            // update actual data
            StartTrackingFlags nTrackFlags = StartTrackingFlags::NONE;
            mnCurPos         = i;
            mnCurItemId      = it->mnId;
            mnCurItemId      = mpData->m_aItems[nNewPos].mnId;
            mnDownItemId     = mnCurItemId;
            mnMouseModifier  = rMEvt.GetModifier();
            if ( it->mnBits & ToolBoxItemBits::REPEAT )
            if ( mpData->m_aItems[nNewPos].mnBits & ToolBoxItemBits::REPEAT )
                nTrackFlags |= StartTrackingFlags::ButtonRepeat;

            if ( mbSelection )
@@ -3518,10 +3486,10 @@ void ToolBox::MouseButtonDown( const MouseEvent& rMEvt )
                }

                // was dropdown arrow pressed
                if( it->mnBits & ToolBoxItemBits::DROPDOWN )
                if( mpData->m_aItems[nNewPos].mnBits & ToolBoxItemBits::DROPDOWN )
                {
                    if( ( (it->mnBits & ToolBoxItemBits::DROPDOWNONLY) == ToolBoxItemBits::DROPDOWNONLY)
                        || it->GetDropDownRect( mbHorz && ( meTextPosition == ToolBoxTextPosition::Right ) ).IsInside( aMousePos ))
                    if( ( (mpData->m_aItems[nNewPos].mnBits & ToolBoxItemBits::DROPDOWNONLY) == ToolBoxItemBits::DROPDOWNONLY)
                        || mpData->m_aItems[nNewPos].GetDropDownRect( mbHorz && ( meTextPosition == ToolBoxTextPosition::Right ) ).IsInside( aMousePos ))
                    {
                        // dropdownonly always triggers the dropdown handler, over the whole button area

@@ -4002,19 +3970,16 @@ bool ToolBox::EventNotify( NotifyEvent& rNEvt )
        {
            // a child window got the focus so update current item to
            // allow for proper lose focus handling in keyboard navigation
            ImplToolItems::const_iterator it = mpData->m_aItems.begin();
            while( it != mpData->m_aItems.end() )
            for (auto const& item : mpData->m_aItems)
            {
                if ( it->mbVisible )
                if ( item.mbVisible )
                {
                    if ( it->mpWindow && it->mpWindow->ImplIsWindowOrChild( rNEvt.GetWindow() ) )
                    if ( item.mpWindow && item.mpWindow->ImplIsWindowOrChild( rNEvt.GetWindow() ) )
                    {
                        mnHighItemId = it->mnId;
                        mnHighItemId = item.mnId;
                        break;
                    }
                }

                ++it;
            }
            return DockingWindow::EventNotify( rNEvt );
        }
@@ -4124,12 +4089,12 @@ void ToolBox::statusChanged( const css::frame::FeatureStateEvent& Event )

        // update image orientation
        OUString aModuleName(vcl::CommandInfoProvider::GetModuleIdentifier(mpStatusListener->getFrame()));
        for (ImplToolItems::const_iterator it = mpData->m_aItems.begin(); it != mpData->m_aItems.end(); ++it)
        for (auto const& item : mpData->m_aItems)
        {
            if (vcl::CommandInfoProvider::IsMirrored(it->maCommandStr, aModuleName))
                SetItemImageMirrorMode(it->mnId, mbImagesMirrored);
            if (vcl::CommandInfoProvider::IsRotated(it->maCommandStr, aModuleName))
                SetItemImageAngle(it->mnId, mnImagesRotationAngle);
            if (vcl::CommandInfoProvider::IsMirrored(item.maCommandStr, aModuleName))
                SetItemImageMirrorMode(item.mnId, mbImagesMirrored);
            if (vcl::CommandInfoProvider::IsRotated(item.maCommandStr, aModuleName))
                SetItemImageAngle(item.mnId, mnImagesRotationAngle);
        }
    }
}
@@ -4315,10 +4280,10 @@ Size ToolBox::GetOptimalSize() const

    Size aSize(const_cast<ToolBox *>(this)->ImplCalcSize( mnLines ));

    for (std::map<vcl::Window*, Size>::iterator aI = aExpandables.begin(); aI != aExpandables.end(); ++aI)
    for (auto const& expandable : aExpandables)
    {
        vcl::Window *pWindow = aI->first;
        Size aWinSize = aI->second;
        vcl::Window *pWindow = expandable.first;
        Size aWinSize = expandable.second;
        pWindow->SetSizePixel(aWinSize);
    }

@@ -4340,12 +4305,10 @@ ToolBox::ImplToolItems::size_type ToolBox::ImplCountLineBreaks() const
{
    ImplToolItems::size_type nLines = 0;

    ImplToolItems::const_iterator it = mpData->m_aItems.begin();
    while ( it != mpData->m_aItems.end() )
    for (auto const& item : mpData->m_aItems)
    {
        if( it->meType == ToolBoxItemType::BREAK )
        if( item.meType == ToolBoxItemType::BREAK )
            ++nLines;
        ++it;
    }
    return nLines;
}
@@ -4407,14 +4370,11 @@ Size ToolBox::CalcMinimumWindowSizePixel()
        VclPtrInstance< ToolBox > pToolBox( GetParent(), GetStyle() );

        // copy until first useful item
        ImplToolItems::iterator it = mpData->m_aItems.begin();
        while( it != mpData->m_aItems.end() )
        for (auto const& item : mpData->m_aItems)
        {
            pToolBox->CopyItem( *this, it->mnId );
            if( (it->meType != ToolBoxItemType::BUTTON) ||
                !it->mbVisible || ImplIsFixedControl( &(*it) ) )
                ++it;
            else
            pToolBox->CopyItem( *this, item.mnId );
            if( (item.meType == ToolBoxItemType::BUTTON) &&
                item.mbVisible && !ImplIsFixedControl( &item ) )
                break;
        }

@@ -4776,15 +4736,13 @@ void ToolBox::KeyInput( const KeyEvent& rKEvt )
// returns the current toolbox line of the item
ToolBox::ImplToolItems::size_type ToolBox::ImplGetItemLine( ImplToolItem const * pCurrentItem )
{
    ImplToolItems::const_iterator it = mpData->m_aItems.begin();
    ImplToolItems::size_type nLine = 1;
    while( it != mpData->m_aItems.end() )
    for (auto const& item : mpData->m_aItems)
    {
        if ( it->mbBreak )
        if ( item.mbBreak )
            ++nLine;
        if( &(*it) == pCurrentItem)
        if( &item == pCurrentItem)
            break;
        ++it;
    }
    return nLine;
}