Modernize a bit forms

by using for-range loops
+ use returned iterator by erase call

Change-Id: Ia41c9fae190dbad6a25b62a9b15ad51e89dd2906
Reviewed-on: https://gerrit.libreoffice.org/48759
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Julien Nabet <serval2412@yahoo.fr>
diff --git a/forms/source/component/imgprod.cxx b/forms/source/component/imgprod.cxx
index cd5bcb6..44cb05d 100644
--- a/forms/source/component/imgprod.cxx
+++ b/forms/source/component/imgprod.cxx
@@ -277,10 +277,10 @@ void ImageProducer::startProduction()
            ConsumerList_t aTmp = maConsList;

            // iterate through interfaces
            for( ConsumerList_t::iterator iter = aTmp.begin(); iter != aTmp.end(); ++iter )
            for (auto const& elem : aTmp)
            {
                (*iter)->init( 0, 0 );
                (*iter)->complete( css::awt::ImageStatus::IMAGESTATUS_STATICIMAGEDONE, this );
                elem->init( 0, 0 );
                elem->complete( css::awt::ImageStatus::IMAGESTATUS_STATICIMAGEDONE, this );
            }

            maDoneHdl.Call( nullptr );
@@ -321,8 +321,8 @@ void ImageProducer::ImplUpdateData( const Graphic& rGraphic )
        mbConsInit = false;

        // iterate through interfaces
        for( ConsumerList_t::iterator iter = aTmp.begin(); iter != aTmp.end(); ++iter )
            (*iter)->complete( css::awt::ImageStatus::IMAGESTATUS_STATICIMAGEDONE, this );
        for (auto const& elem : aTmp)
            elem->complete( css::awt::ImageStatus::IMAGESTATUS_STATICIMAGEDONE, this );
    }
}

@@ -385,10 +385,10 @@ void ImageProducer::ImplInitConsumer( const Graphic& rGraphic )
        ConsumerList_t aTmp = maConsList;

        // iterate through interfaces
        for( ConsumerList_t::iterator iter = aTmp.begin(); iter != aTmp.end(); ++iter)
        for (auto const& elem : aTmp)
        {
            (*iter)->init( pBmpAcc->Width(), pBmpAcc->Height() );
            (*iter)->setColorModel( pBmpAcc->GetBitCount(),aRGBPal, nRMask, nGMask, nBMask, nAMask );
            elem->init( pBmpAcc->Width(), pBmpAcc->Height() );
            elem->setColorModel( pBmpAcc->GetBitCount(),aRGBPal, nRMask, nGMask, nBMask, nAMask );
        }

        Bitmap::ReleaseAccess( pBmpAcc );
@@ -448,8 +448,8 @@ void ImageProducer::ImplUpdateConsumer( const Graphic& rGraphic )
                }

                // iterate through interfaces
                for (ConsumerList_t::iterator iter = aTmp.begin(); iter != aTmp.end(); ++iter)
                    (*iter)->setPixelsByBytes( nStartX, nStartY, nPartWidth, nPartHeight, aData, 0UL, nPartWidth );
                for (auto const& elem : aTmp)
                    elem->setPixelsByBytes( nStartX, nStartY, nPartWidth, nPartHeight, aData, 0UL, nPartWidth );
            }
            else
            {
@@ -468,8 +468,8 @@ void ImageProducer::ImplUpdateConsumer( const Graphic& rGraphic )
                }

                // iterate through interfaces
                for (ConsumerList_t::iterator iter = aTmp.begin(); iter != aTmp.end(); ++iter)
                    (*iter)->setPixelsByLongs( nStartX, nStartY, nPartWidth, nPartHeight, aData, 0UL, nPartWidth );
                for (auto const& elem : aTmp)
                    elem->setPixelsByLongs( nStartX, nStartY, nPartWidth, nPartHeight, aData, 0UL, nPartWidth );
            }
        }
        else
@@ -494,8 +494,8 @@ void ImageProducer::ImplUpdateConsumer( const Graphic& rGraphic )
            }

            // iterate through interfaces
                for (ConsumerList_t::iterator iter = aTmp.begin(); iter != aTmp.end(); ++iter)
                    (*iter)->setPixelsByLongs( nStartX, nStartY, nPartWidth, nPartHeight, aData, 0UL, nPartWidth );
            for (auto const& elem : aTmp)
                elem->setPixelsByLongs( nStartX, nStartY, nPartWidth, nPartHeight, aData, 0UL, nPartWidth );
        }

        Bitmap::ReleaseAccess( pBmpAcc );
diff --git a/forms/source/helper/formnavigation.cxx b/forms/source/helper/formnavigation.cxx
index 89f2e7a..7c7186e 100644
--- a/forms/source/helper/formnavigation.cxx
+++ b/forms/source/helper/formnavigation.cxx
@@ -93,22 +93,19 @@ namespace frm

    void SAL_CALL OFormNavigationHelper::statusChanged( const FeatureStateEvent& _rState )
    {
        for (   FeatureMap::iterator aFeature = m_aSupportedFeatures.begin();
                aFeature != m_aSupportedFeatures.end();
                ++aFeature
            )
        for (auto & feature : m_aSupportedFeatures)
        {
            if ( aFeature->second.aURL.Main == _rState.FeatureURL.Main )
            if ( feature.second.aURL.Main == _rState.FeatureURL.Main )
            {
                if  (  ( aFeature->second.bCachedState != bool(_rState.IsEnabled) )
                    || ( aFeature->second.aCachedAdditionalState != _rState.State )
                if  (  ( feature.second.bCachedState != bool(_rState.IsEnabled) )
                    || ( feature.second.aCachedAdditionalState != _rState.State )
                    )
                {
                    // change the cached state
                    aFeature->second.bCachedState           = _rState.IsEnabled;
                    aFeature->second.aCachedAdditionalState = _rState.State;
                    feature.second.bCachedState           = _rState.IsEnabled;
                    feature.second.aCachedAdditionalState = _rState.State;
                    // tell derivees what happened
                    featureStateChanged( aFeature->first, _rState.IsEnabled );
                    featureStateChanged( feature.first, _rState.IsEnabled );
                }
                return;
            }
@@ -124,20 +121,17 @@ namespace frm
        // was it one of our external dispatchers?
        if ( m_nConnectedFeatures )
        {
            for (   FeatureMap::iterator aFeature = m_aSupportedFeatures.begin();
                    aFeature != m_aSupportedFeatures.end();
                    ++aFeature
                )
            for (auto & feature : m_aSupportedFeatures)
            {
                if ( aFeature->second.xDispatcher == _rSource.Source )
                if ( feature.second.xDispatcher == _rSource.Source )
                {
                    aFeature->second.xDispatcher->removeStatusListener( static_cast< XStatusListener* >( this ), aFeature->second.aURL );
                    aFeature->second.xDispatcher = nullptr;
                    aFeature->second.bCachedState = false;
                    aFeature->second.aCachedAdditionalState.clear();
                    feature.second.xDispatcher->removeStatusListener( static_cast< XStatusListener* >( this ), feature.second.aURL );
                    feature.second.xDispatcher = nullptr;
                    feature.second.bCachedState = false;
                    feature.second.aCachedAdditionalState.clear();
                    --m_nConnectedFeatures;

                    featureStateChanged( aFeature->first, false );
                    featureStateChanged( feature.first, false );
                    break;
                }
            }
@@ -160,29 +154,26 @@ namespace frm
        Reference< XDispatch >  xNewDispatcher;
        Reference< XDispatch >  xCurrentDispatcher;

        for (   FeatureMap::iterator aFeature = m_aSupportedFeatures.begin();
                aFeature != m_aSupportedFeatures.end();
                ++aFeature
            )
        for (auto & feature : m_aSupportedFeatures)
        {
            xNewDispatcher = queryDispatch( aFeature->second.aURL );
            xCurrentDispatcher = aFeature->second.xDispatcher;
            xNewDispatcher = queryDispatch( feature.second.aURL );
            xCurrentDispatcher = feature.second.xDispatcher;
            if ( xNewDispatcher != xCurrentDispatcher )
            {
                // the dispatcher for this particular URL changed
                if ( xCurrentDispatcher.is() )
                    xCurrentDispatcher->removeStatusListener( static_cast< XStatusListener* >( this ), aFeature->second.aURL );
                    xCurrentDispatcher->removeStatusListener( static_cast< XStatusListener* >( this ), feature.second.aURL );

                xCurrentDispatcher = aFeature->second.xDispatcher = xNewDispatcher;
                xCurrentDispatcher = feature.second.xDispatcher = xNewDispatcher;

                if ( xCurrentDispatcher.is() )
                    xCurrentDispatcher->addStatusListener( static_cast< XStatusListener* >( this ), aFeature->second.aURL );
                    xCurrentDispatcher->addStatusListener( static_cast< XStatusListener* >( this ), feature.second.aURL );
            }

            if ( xCurrentDispatcher.is() )
                ++m_nConnectedFeatures;
            else
                aFeature->second.bCachedState = false;
                feature.second.bCachedState = false;
        }

        // notify derivee that (potentially) all features changed their state
@@ -202,18 +193,15 @@ namespace frm

        m_nConnectedFeatures = 0;

        for (   FeatureMap::iterator aFeature = m_aSupportedFeatures.begin();
                aFeature != m_aSupportedFeatures.end();
                ++aFeature
            )
        for (auto & feature : m_aSupportedFeatures)
        {
            aFeature->second.bCachedState = false;
            aFeature->second.aCachedAdditionalState.clear();
            aFeature->second.xDispatcher = queryDispatch( aFeature->second.aURL );
            if ( aFeature->second.xDispatcher.is() )
            feature.second.bCachedState = false;
            feature.second.aCachedAdditionalState.clear();
            feature.second.xDispatcher = queryDispatch( feature.second.aURL );
            if ( feature.second.xDispatcher.is() )
            {
                ++m_nConnectedFeatures;
                aFeature->second.xDispatcher->addStatusListener( static_cast< XStatusListener* >( this ), aFeature->second.aURL );
                feature.second.xDispatcher->addStatusListener( static_cast< XStatusListener* >( this ), feature.second.aURL );
            }
        }

@@ -226,17 +214,14 @@ namespace frm
    {
        if ( m_nConnectedFeatures )
        {
            for (   FeatureMap::iterator aFeature = m_aSupportedFeatures.begin();
                    aFeature != m_aSupportedFeatures.end();
                    ++aFeature
                )
            for (auto & feature : m_aSupportedFeatures)
            {
                if ( aFeature->second.xDispatcher.is() )
                    aFeature->second.xDispatcher->removeStatusListener( static_cast< XStatusListener* >( this ), aFeature->second.aURL );
                if ( feature.second.xDispatcher.is() )
                    feature.second.xDispatcher->removeStatusListener( static_cast< XStatusListener* >( this ), feature.second.aURL );

                aFeature->second.xDispatcher = nullptr;
                aFeature->second.bCachedState = false;
                aFeature->second.aCachedAdditionalState.clear();
                feature.second.xDispatcher = nullptr;
                feature.second.bCachedState = false;
                feature.second.aCachedAdditionalState.clear();
            }

            m_nConnectedFeatures = 0;
@@ -257,20 +242,17 @@ namespace frm

            OFormNavigationMapper aUrlMapper( m_xORB );

            for (   ::std::vector< sal_Int16 >::const_iterator aLoop = aFeatureIds.begin();
                    aLoop != aFeatureIds.end();
                    ++aLoop
                )
            for (auto const& feature : aFeatureIds)
            {
                FeatureInfo aFeatureInfo;

                bool bKnownId =
                    aUrlMapper.getFeatureURL( *aLoop, aFeatureInfo.aURL );
                    aUrlMapper.getFeatureURL( feature, aFeatureInfo.aURL );
                DBG_ASSERT( bKnownId, "OFormNavigationHelper::initializeSupportedFeatures: unknown feature id!" );

                if ( bKnownId )
                    // add to our map
                    m_aSupportedFeatures.emplace( *aLoop, aFeatureInfo );
                    m_aSupportedFeatures.emplace( feature, aFeatureInfo );
            }
        }
    }
diff --git a/forms/source/solar/control/navtoolbar.cxx b/forms/source/solar/control/navtoolbar.cxx
index 7cf1689..1cc3c42 100644
--- a/forms/source/solar/control/navtoolbar.cxx
+++ b/forms/source/solar/control/navtoolbar.cxx
@@ -151,8 +151,8 @@ namespace frm

    void NavigationToolBar::dispose()
    {
        for (auto i = m_aChildWins.begin(); i != m_aChildWins.end(); ++i)
            i->disposeAndClear();
        for (auto & childWin : m_aChildWins)
            childWin.disposeAndClear();
        m_aChildWins.clear();
        m_pToolbar.disposeAndClear();
        vcl::Window::dispose();
@@ -358,12 +358,10 @@ namespace frm

        // translate them into command URLs
        css::uno::Sequence< OUString > aCommandURLs( aFormFeatures.size() );
        for (   FormFeatures::const_iterator formFeature = aFormFeatures.begin();
                formFeature != aFormFeatures.end();
                ++formFeature
            )
        size_t i = 0;
        for (auto const& formFeature : aFormFeatures)
        {
            aCommandURLs[ formFeature - aFormFeatures.begin() ] = lcl_getCommandURL( *formFeature );
            aCommandURLs[i++] = lcl_getCommandURL(formFeature);
        }

        // retrieve the images for the command URLs
@@ -371,12 +369,10 @@ namespace frm

        // and set them at the toolbar
        CommandImages::const_iterator commandImage = aCommandImages.begin();
        for (   FormFeatures::const_iterator formFeature = aFormFeatures.begin();
                formFeature != aFormFeatures.end();
                ++formFeature, ++commandImage
            )
        for (auto const& formFeature : aFormFeatures)
        {
            m_pToolbar->SetItemImage( *formFeature, *commandImage );
            m_pToolbar->SetItemImage( formFeature, *commandImage );
            ++commandImage;
        }

        // parts of our layout is dependent on the size of our icons
diff --git a/forms/source/xforms/binding.cxx b/forms/source/xforms/binding.cxx
index 1627621..05d4043 100644
--- a/forms/source/xforms/binding.cxx
+++ b/forms/source/xforms/binding.cxx
@@ -524,15 +524,12 @@ static void lcl_removeListenerFromNode( const Reference<XNode>& xNode,
    // EvaluationContext for each
    PathExpression::NodeVector_t aNodes = maBindingExpression.getNodeList();
    ::std::vector<EvaluationContext> aVector;
    sal_Int32 nCount = 0; // count nodes for context position
    for( PathExpression::NodeVector_t::iterator aIter = aNodes.begin();
         aIter != aNodes.end();
         ++aIter, ++nCount )
    for (auto const& node : aNodes)
    {
        OSL_ENSURE( aIter->is(), "no node?" );
        OSL_ENSURE( node.is(), "no node?" );

        // create proper evaluation context for this MIP
        aVector.emplace_back( *aIter, getModel(), getBindingNamespaces() );
        aVector.emplace_back( node, getModel(), getBindingNamespaces() );
    }
    return aVector;
}
@@ -578,23 +575,17 @@ void Binding::bind( bool bForceRebind )
    // 2) register suitable listeners on the instance (and remove old ones)
    if( maEventNodes.empty() || bForceRebind )
    {
        for( auto aIter = maEventNodes.begin();
             aIter != maEventNodes.end();
             ++aIter )
            lcl_removeListenerFromNode( *aIter, this );
        for (auto const& eventNode : maEventNodes)
            lcl_removeListenerFromNode( eventNode, this );
        maEventNodes.clear();
        if( isSimpleBinding() )
            for( PathExpression::NodeVector_t::iterator aIter = aNodes.begin();
                 aIter != aNodes.end();
                 ++aIter )
                maEventNodes.push_back( *aIter );
            for (auto const& node : aNodes)
                maEventNodes.push_back(node);
        else
            maEventNodes.emplace_back( aContext.mxContextNode->getOwnerDocument(),
                                  UNO_QUERY_THROW );
        for( PathExpression::NodeVector_t::iterator aIter2 = maEventNodes.begin();
             aIter2 != maEventNodes.end();
             ++aIter2 )
            lcl_addListenerToNode( *aIter2, this );
        for (auto const& eventNode : maEventNodes)
            lcl_addListenerToNode( eventNode, this );
    }

    // 3) remove old MIPs defined by this binding
@@ -604,11 +595,9 @@ void Binding::bind( bool bForceRebind )

    // 4) calculate all MIPs
    ::std::vector<EvaluationContext> aMIPContexts = _getMIPEvaluationContexts();
    for( ::std::vector<EvaluationContext>::iterator aIter = aMIPContexts.begin();
         aIter != aMIPContexts.end();
         ++aIter )
    for (auto & context : aMIPContexts)
    {
        EvaluationContext& rContext = *aIter;
        EvaluationContext& rContext = context;

        // evaluate calculate expression (and push value into instance)
        // (prevent recursion using mbInCalculate
@@ -812,10 +801,8 @@ void Binding::clear()
        pModel->removeMIPs( this );

    // remove all references
    for( auto aIter = maEventNodes.begin();
         aIter != maEventNodes.end();
         ++aIter )
        lcl_removeListenerFromNode( *aIter, this );
    for (auto const& eventNode : maEventNodes)
        lcl_removeListenerFromNode( eventNode, this );
    maEventNodes.clear();

    // clear expressions
diff --git a/forms/source/xforms/collection.hxx b/forms/source/xforms/collection.hxx
index f38d75c..3ffc1f7 100644
--- a/forms/source/xforms/collection.hxx
+++ b/forms/source/xforms/collection.hxx
@@ -245,11 +245,9 @@ protected:
            css::uno::makeAny( nPos ),
            css::uno::makeAny( getItem( nPos ) ),
            css::uno::Any() );
        for( Listeners_t::iterator aIter = maListeners.begin();
             aIter != maListeners.end();
             ++aIter )
        for (auto const& listener : maListeners)
        {
            (*aIter)->elementInserted( aEvent );
            listener->elementInserted( aEvent );
        }
    }

@@ -260,11 +258,9 @@ protected:
            css::uno::Any(),
            css::uno::makeAny( aOld ),
            css::uno::Any() );
        for( Listeners_t::iterator aIter = maListeners.begin();
             aIter != maListeners.end();
             ++aIter )
        for (auto const& listener : maListeners)
        {
            (*aIter)->elementRemoved( aEvent );
            listener->elementRemoved( aEvent );
        }
    }

@@ -276,11 +272,9 @@ protected:
            css::uno::makeAny( nPos ),
            css::uno::makeAny( getItem( nPos ) ),
            css::uno::makeAny( aNew ) );
        for( Listeners_t::iterator aIter = maListeners.begin();
             aIter != maListeners.end();
             ++aIter )
        for (auto const& listener : maListeners)
        {
            (*aIter)->elementReplaced( aEvent );
            listener->elementReplaced( aEvent );
        }
    }

diff --git a/forms/source/xforms/model.cxx b/forms/source/xforms/model.cxx
index c714d5b..ad6ccbc 100644
--- a/forms/source/xforms/model.cxx
+++ b/forms/source/xforms/model.cxx
@@ -207,9 +207,7 @@ void Model::removeMIPs( void const * pTag )
    {
        if( aIter->second.first == pTag )
        {
            MIPs_t::iterator next( aIter ); ++next;
            maMIPs.erase( aIter );
            aIter = next;
            aIter = maMIPs.erase( aIter );
        }
        else
            ++aIter;
diff --git a/forms/source/xforms/model_ui.cxx b/forms/source/xforms/model_ui.cxx
index c66bdfe..f6da0ce 100644
--- a/forms/source/xforms/model_ui.cxx
+++ b/forms/source/xforms/model_ui.cxx
@@ -881,11 +881,9 @@ OUString Model::getResultForExpression(
        // MIP (not binding): iterate over bindings contexts
        std::vector<EvaluationContext> aContext =
            pBinding->getMIPEvaluationContexts();
        for( std::vector<EvaluationContext>::iterator aIter = aContext.begin();
             aIter != aContext.end();
             ++aIter )
        for (auto const& elem : aContext)
        {
            aExpression.evaluate( *aIter );
            aExpression.evaluate(elem);
            aBuffer.append( lcl_serializeForDisplay(aExpression.getXPath()) );
            aBuffer.append( '\n' );
        }