From 56d97cdd0af15c90c744d2ac66e879818c073ec6 Mon Sep 17 00:00:00 2001 From: Arkadiy Illarionov Date: Sat, 1 Dec 2018 15:19:04 +0300 Subject: Simplify containers iterations in sfx2, shell Use range-based loop or replace with STL functions Change-Id: I42361d6a73d201db8eb6dca09d79768e2d62051d Reviewed-on: https://gerrit.libreoffice.org/64389 Tested-by: Jenkins Reviewed-by: Noel Grandin --- sfx2/source/appl/linkmgr2.cxx | 5 +- sfx2/source/appl/linksrc.cxx | 10 ++- sfx2/source/appl/preventduplicateinteraction.cxx | 65 +++++++------------ sfx2/source/control/templatelocalview.cxx | 32 +++++----- sfx2/source/dialog/dinfdlg.cxx | 45 +++++++------ sfx2/source/dialog/filtergrouping.cxx | 14 ++--- sfx2/source/dialog/infobar.cxx | 23 +++---- sfx2/source/doc/DocumentMetadataAccess.cxx | 12 ++-- sfx2/source/doc/docfac.cxx | 7 +-- sfx2/source/doc/docinf.cxx | 7 +-- sfx2/source/notebookbar/PriorityHBox.cxx | 17 ++--- sfx2/source/notify/globalevents.cxx | 16 ++--- sfx2/source/sidebar/DeckLayouter.cxx | 73 +++++++++------------- sfx2/source/sidebar/SidebarController.cxx | 52 ++++++--------- sfx2/source/sidebar/Theme.cxx | 30 +++------ sfx2/source/sidebar/UnoDecks.cxx | 21 +++---- sfx2/source/sidebar/UnoPanels.cxx | 29 ++++----- sfx2/source/view/viewsh.cxx | 11 +--- .../shlxthandler/propsheets/listviewbuilder.cxx | 16 ++--- .../win32/shlxthandler/util/iso8601_converter.cxx | 17 +++-- 20 files changed, 189 insertions(+), 313 deletions(-) diff --git a/sfx2/source/appl/linkmgr2.cxx b/sfx2/source/appl/linkmgr2.cxx index fba3d944c225..1e631bc949aa 100644 --- a/sfx2/source/appl/linkmgr2.cxx +++ b/sfx2/source/appl/linkmgr2.cxx @@ -92,10 +92,9 @@ void LinkManager::InsertCachedComp(const Reference& xComp) void LinkManager::CloseCachedComps() { - CompVector::iterator itr = maCachedComps.begin(), itrEnd = maCachedComps.end(); - for (; itr != itrEnd; ++itr) + for (const auto& rxCachedComp : maCachedComps) { - Reference xCloseable(*itr, UNO_QUERY); + Reference xCloseable(rxCachedComp, UNO_QUERY); if (!xCloseable.is()) continue; diff --git a/sfx2/source/appl/linksrc.cxx b/sfx2/source/appl/linksrc.cxx index 16a94bad6abd..98c347713dfb 100644 --- a/sfx2/source/appl/linksrc.cxx +++ b/sfx2/source/appl/linksrc.cxx @@ -99,12 +99,10 @@ public: void DeleteAndDestroy(SvLinkSource_Entry_Impl const * p) { - for (auto it = mvData.begin(); it != mvData.end(); ++it) - if (it->get() == p) - { - mvData.erase(it); - break; - } + auto it = std::find_if(mvData.begin(), mvData.end(), + [&p](const std::unique_ptr& rxData) { return rxData.get() == p; }); + if (it != mvData.end()) + mvData.erase(it); } }; diff --git a/sfx2/source/appl/preventduplicateinteraction.cxx b/sfx2/source/appl/preventduplicateinteraction.cxx index ffe89813c0db..f9c38dd81132 100644 --- a/sfx2/source/appl/preventduplicateinteraction.cxx +++ b/sfx2/source/appl/preventduplicateinteraction.cxx @@ -88,20 +88,15 @@ void SAL_CALL PreventDuplicateInteraction::handle(const css::uno::Reference< css // SAFE -> ::osl::ResettableMutexGuard aLock(m_aLock); - InteractionList::iterator pIt; - for ( pIt = m_lInteractionRules.begin(); - pIt != m_lInteractionRules.end(); - ++pIt ) + auto pIt = std::find_if(m_lInteractionRules.begin(), m_lInteractionRules.end(), + [&aRequest](const InteractionInfo& rInfo) { return aRequest.isExtractableTo(rInfo.m_aInteraction); }); + if (pIt != m_lInteractionRules.end()) { InteractionInfo& rInfo = *pIt; - if (aRequest.isExtractableTo(rInfo.m_aInteraction)) - { - ++rInfo.m_nCallCount; - rInfo.m_xRequest = xRequest; - bHandleIt = (rInfo.m_nCallCount <= rInfo.m_nMaxCount); - break; - } + ++rInfo.m_nCallCount; + rInfo.m_xRequest = xRequest; + bHandleIt = (rInfo.m_nCallCount <= rInfo.m_nMaxCount); } css::uno::Reference< css::task::XInteractionHandler > xHandler = m_xHandler; @@ -138,20 +133,15 @@ sal_Bool SAL_CALL PreventDuplicateInteraction::handleInteractionRequest( const c // SAFE -> ::osl::ResettableMutexGuard aLock(m_aLock); - InteractionList::iterator pIt; - for ( pIt = m_lInteractionRules.begin(); - pIt != m_lInteractionRules.end(); - ++pIt ) + auto pIt = std::find_if(m_lInteractionRules.begin(), m_lInteractionRules.end(), + [&aRequest](const InteractionInfo& rInfo) { return aRequest.isExtractableTo(rInfo.m_aInteraction); }); + if (pIt != m_lInteractionRules.end()) { InteractionInfo& rInfo = *pIt; - if (aRequest.isExtractableTo(rInfo.m_aInteraction)) - { - ++rInfo.m_nCallCount; - rInfo.m_xRequest = xRequest; - bHandleIt = (rInfo.m_nCallCount <= rInfo.m_nMaxCount); - break; - } + ++rInfo.m_nCallCount; + rInfo.m_xRequest = xRequest; + bHandleIt = (rInfo.m_nCallCount <= rInfo.m_nMaxCount); } css::uno::Reference< css::task::XInteractionHandler2 > xHandler( m_xHandler, css::uno::UNO_QUERY ); @@ -188,18 +178,14 @@ void PreventDuplicateInteraction::addInteractionRule(const PreventDuplicateInter // SAFE -> ::osl::ResettableMutexGuard aLock(m_aLock); - InteractionList::iterator pIt; - for ( pIt = m_lInteractionRules.begin(); - pIt != m_lInteractionRules.end(); - ++pIt ) + auto pIt = std::find_if(m_lInteractionRules.begin(), m_lInteractionRules.end(), + [&aInteractionInfo](const InteractionInfo& rInfo) { return rInfo.m_aInteraction == aInteractionInfo.m_aInteraction; }); + if (pIt != m_lInteractionRules.end()) { InteractionInfo& rInfo = *pIt; - if (rInfo.m_aInteraction == aInteractionInfo.m_aInteraction) - { - rInfo.m_nMaxCount = aInteractionInfo.m_nMaxCount; - rInfo.m_nCallCount = aInteractionInfo.m_nCallCount; - return; - } + rInfo.m_nMaxCount = aInteractionInfo.m_nMaxCount; + rInfo.m_nCallCount = aInteractionInfo.m_nCallCount; + return; } m_lInteractionRules.push_back(aInteractionInfo); @@ -214,17 +200,12 @@ bool PreventDuplicateInteraction::getInteractionInfo(const css::uno::Type& // SAFE -> ::osl::ResettableMutexGuard aLock(m_aLock); - PreventDuplicateInteraction::InteractionList::const_iterator pIt; - for ( pIt = m_lInteractionRules.begin(); - pIt != m_lInteractionRules.end(); - ++pIt ) + auto pIt = std::find_if(m_lInteractionRules.begin(), m_lInteractionRules.end(), + [&aInteraction](const InteractionInfo& rInfo) { return rInfo.m_aInteraction == aInteraction; }); + if (pIt != m_lInteractionRules.end()) { - const PreventDuplicateInteraction::InteractionInfo& rInfo = *pIt; - if (rInfo.m_aInteraction == aInteraction) - { - *pReturn = rInfo; - return true; - } + *pReturn = *pIt; + return true; } aLock.clear(); diff --git a/sfx2/source/control/templatelocalview.cxx b/sfx2/source/control/templatelocalview.cxx index 7272780bd32d..bb909106097f 100644 --- a/sfx2/source/control/templatelocalview.cxx +++ b/sfx2/source/control/templatelocalview.cxx @@ -444,28 +444,24 @@ bool TemplateLocalView::removeTemplate (const sal_uInt16 nItemId, const sal_uInt if (pRegion->mnId == nSrcItemId) { TemplateContainerItem *pItem = pRegion.get(); - std::vector::iterator pIter; - for (pIter = pItem->maTemplates.begin(); pIter != pItem->maTemplates.end(); ++pIter) + auto pIter = std::find_if(pItem->maTemplates.begin(), pItem->maTemplates.end(), + [nItemId](const TemplateItemProperties& rTemplate) { return rTemplate.nId == nItemId; }); + if (pIter != pItem->maTemplates.end()) { - if (pIter->nId == nItemId) - { - if (!mpDocTemplates->Delete(pItem->mnRegionId,pIter->nDocId)) - return false; - - pIter = pItem->maTemplates.erase(pIter); - - if (pRegion->mnRegionId == mnCurRegionId-1) - { - RemoveItem(nItemId); - Invalidate(); - } + if (!mpDocTemplates->Delete(pItem->mnRegionId,pIter->nDocId)) + return false; - // Update Doc Idx for all templates that follow - for (; pIter != pItem->maTemplates.end(); ++pIter) - pIter->nDocId = pIter->nDocId - 1; + pIter = pItem->maTemplates.erase(pIter); - break; + if (pRegion->mnRegionId == mnCurRegionId-1) + { + RemoveItem(nItemId); + Invalidate(); } + + // Update Doc Idx for all templates that follow + for (; pIter != pItem->maTemplates.end(); ++pIter) + pIter->nDocId = pIter->nDocId - 1; } CalculateItemPositions(); diff --git a/sfx2/source/dialog/dinfdlg.cxx b/sfx2/source/dialog/dinfdlg.cxx index 6049c9e8462c..07cd83366b8f 100644 --- a/sfx2/source/dialog/dinfdlg.cxx +++ b/sfx2/source/dialog/dinfdlg.cxx @@ -38,6 +38,7 @@ #include +#include #include #include #include @@ -2353,10 +2354,9 @@ Sequence< document::CmisProperty > CmisPropertiesWindow::GetCmisProperties() con { Sequence< document::CmisProperty > aPropertiesSeq( m_aCmisPropertiesLines.size() ); sal_Int32 i = 0; - for ( auto pIter = m_aCmisPropertiesLines.begin(); - pIter != m_aCmisPropertiesLines.end(); ++pIter, ++i ) + for ( auto& rxLine : m_aCmisPropertiesLines ) { - CmisPropertyLine* pLine = pIter->get(); + CmisPropertyLine* pLine = rxLine.get(); aPropertiesSeq[i].Id = pLine->m_sId; aPropertiesSeq[i].Type = pLine->m_sType; @@ -2376,15 +2376,15 @@ Sequence< document::CmisProperty > CmisPropertiesWindow::GetCmisProperties() con m_aNumberFormatter ).GetFormatIndex( NF_NUMBER_SYSTEM ); Sequence< double > seqValue( pLine->m_aValues.size( ) ); sal_Int32 k = 0; - for ( auto it = pLine->m_aValues.begin(); - it != pLine->m_aValues.end(); ++it, ++k) + for ( auto& rxValue : pLine->m_aValues ) { double dValue = 0.0; - OUString sValue( (*it)->m_aValueEdit->GetText() ); + OUString sValue( rxValue->m_aValueEdit->GetText() ); bool bIsNum = const_cast< SvNumberFormatter& >( m_aNumberFormatter ). IsNumberFormat( sValue, nIndex, dValue ); if ( bIsNum ) seqValue[k] = dValue; + ++k; } aPropertiesSeq[i].Value <<= seqValue; } @@ -2394,15 +2394,15 @@ Sequence< document::CmisProperty > CmisPropertiesWindow::GetCmisProperties() con m_aNumberFormatter ).GetFormatIndex( NF_NUMBER_SYSTEM ); Sequence< sal_Int64 > seqValue( pLine->m_aValues.size( ) ); sal_Int32 k = 0; - for ( auto it = pLine->m_aValues.begin(); - it != pLine->m_aValues.end(); ++it, ++k) + for ( auto& rxValue : pLine->m_aValues ) { double dValue = 0; - OUString sValue( (*it)->m_aValueEdit->GetText() ); + OUString sValue( rxValue->m_aValueEdit->GetText() ); bool bIsNum = const_cast< SvNumberFormatter& >( m_aNumberFormatter ). IsNumberFormat( sValue, nIndex, dValue ); if ( bIsNum ) seqValue[k] = static_cast(dValue); + ++k; } aPropertiesSeq[i].Value <<= seqValue; } @@ -2410,11 +2410,11 @@ Sequence< document::CmisProperty > CmisPropertiesWindow::GetCmisProperties() con { Sequence seqValue( pLine->m_aYesNos.size( ) ); sal_Int32 k = 0; - for ( auto it = pLine->m_aYesNos.begin(); - it != pLine->m_aYesNos.end(); ++it, ++k) + for ( auto& rxYesNo : pLine->m_aYesNos ) { - bool bValue = (*it)->m_aYesButton->IsChecked(); + bool bValue = rxYesNo->m_aYesButton->IsChecked(); seqValue[k] = bValue; + ++k; } aPropertiesSeq[i].Value <<= seqValue; @@ -2423,16 +2423,16 @@ Sequence< document::CmisProperty > CmisPropertiesWindow::GetCmisProperties() con { Sequence< util::DateTime > seqValue( pLine->m_aDateTimes.size( ) ); sal_Int32 k = 0; - for ( auto it = pLine->m_aDateTimes.begin(); - it != pLine->m_aDateTimes.end(); ++it, ++k) + for ( auto& rxDateTime : pLine->m_aDateTimes ) { - Date aTmpDate = (*it)->m_aDateField->GetDate(); - tools::Time aTmpTime = (*it)->m_aTimeField->GetTime(); + Date aTmpDate = rxDateTime->m_aDateField->GetDate(); + tools::Time aTmpTime = rxDateTime->m_aTimeField->GetTime(); util::DateTime aDateTime( aTmpTime.GetNanoSec(), aTmpTime.GetSec(), aTmpTime.GetMin(), aTmpTime.GetHour(), aTmpDate.GetDay(), aTmpDate.GetMonth(), aTmpDate.GetYear(), true ); seqValue[k] = aDateTime; + ++k; } aPropertiesSeq[i].Value <<= seqValue; } @@ -2440,15 +2440,16 @@ Sequence< document::CmisProperty > CmisPropertiesWindow::GetCmisProperties() con { Sequence< OUString > seqValue( pLine->m_aValues.size( ) ); sal_Int32 k = 0; - for ( auto it = pLine->m_aValues.begin(); - it != pLine->m_aValues.end(); ++it, ++k) + for ( auto& rxValue : pLine->m_aValues ) { - OUString sValue( (*it)->m_aValueEdit->GetText() ); + OUString sValue( rxValue->m_aValueEdit->GetText() ); seqValue[k] = sValue; + ++k; } aPropertiesSeq[i].Value <<= seqValue; } } + ++i; } return aPropertiesSeq; @@ -2592,11 +2593,7 @@ bool SfxCmisPropertiesPage::FillItemSet( SfxItemSet* rSet ) } } } - Sequence< document::CmisProperty> aModifiedProps( modifiedNum ); - sal_Int32 nCount = 0; - for( std::vector< document::CmisProperty>::const_iterator pIter = changedProps.begin(); - pIter != changedProps.end( ); ++pIter ) - aModifiedProps[ nCount++ ] = *pIter; + Sequence< document::CmisProperty> aModifiedProps( comphelper::containerToSequence(changedProps) ); pInfo->SetCmisProperties( aModifiedProps ); rSet->Put( *pInfo ); if ( bMustDelete ) diff --git a/sfx2/source/dialog/filtergrouping.cxx b/sfx2/source/dialog/filtergrouping.cxx index ec81a7bcf049..70630396cb3b 100644 --- a/sfx2/source/dialog/filtergrouping.cxx +++ b/sfx2/source/dialog/filtergrouping.cxx @@ -623,15 +623,11 @@ namespace sfx2 "sfx2::lcl_GroupAndClassify: invalid all-filters array here!" ); // the loop below will work on invalid objects else ... ++aGroupPos; - auto aGlobalIter = aGlobalClassNames.begin(); - while ( ( aGroupPos != _rAllFilters.end() ) - && ( aGlobalIter != aGlobalClassNames.end() ) - && ( *aGlobalIter != aServiceName ) - ) - { - ++aGlobalIter; - ++aGroupPos; - } + auto aGlobalIter = std::find(aGlobalClassNames.begin(), aGlobalClassNames.end(), aServiceName); + auto nGroupPosShift = std::min( + std::distance(aGlobalClassNames.begin(), aGlobalIter), + std::distance(aGroupPos, _rAllFilters.end())); + std::advance(aGroupPos, nGroupPosShift); if ( aGroupPos != _rAllFilters.end() ) // we found a global class name which matches the doc service name -> fill the filters of this // group in the respective prepared group diff --git a/sfx2/source/dialog/infobar.cxx b/sfx2/source/dialog/infobar.cxx index 349d09cf405f..d1f753c8da71 100644 --- a/sfx2/source/dialog/infobar.cxx +++ b/sfx2/source/dialog/infobar.cxx @@ -222,8 +222,8 @@ void SfxInfoBarWindow::SetForeAndBackgroundColors(InfoBarType eType) void SfxInfoBarWindow::dispose() { - for ( auto it = m_aActionBtns.begin( ); it != m_aActionBtns.end( ); ++it ) - it->disposeAndClear(); + for ( auto& rxBtn : m_aActionBtns ) + rxBtn.disposeAndClear(); m_pImage.disposeAndClear(); m_pMessage.disposeAndClear(); @@ -382,14 +382,11 @@ bool SfxInfoBarContainerWindow::hasInfoBarWithID( const OUString &sId ) void SfxInfoBarContainerWindow::removeInfoBar(VclPtr const & pInfoBar) { // Remove - for (auto it = m_pInfoBars.begin(); it != m_pInfoBars.end(); ++it) + auto it = std::find(m_pInfoBars.begin(), m_pInfoBars.end(), pInfoBar); + if (it != m_pInfoBars.end()) { - if (pInfoBar == *it) - { - it->disposeAndClear(); - m_pInfoBars.erase(it); - break; - } + it->disposeAndClear(); + m_pInfoBars.erase(it); } // Resize @@ -412,12 +409,12 @@ void SfxInfoBarContainerWindow::Resize() // Only need to change the width of the infobars long nWidth = GetSizePixel().getWidth(); - for (auto it = m_pInfoBars.begin(); it != m_pInfoBars.end(); ++it) + for (auto& rxInfoBar : m_pInfoBars) { - Size aSize = (*it)->GetSizePixel(); + Size aSize = rxInfoBar->GetSizePixel(); aSize.setWidth(nWidth); - (*it)->SetSizePixel(aSize); - (*it)->Resize(); + rxInfoBar->SetSizePixel(aSize); + rxInfoBar->Resize(); } } diff --git a/sfx2/source/doc/DocumentMetadataAccess.cxx b/sfx2/source/doc/DocumentMetadataAccess.cxx index 8d5c1a6bc1ad..04c3fb4ea963 100644 --- a/sfx2/source/doc/DocumentMetadataAccess.cxx +++ b/sfx2/source/doc/DocumentMetadataAccess.cxx @@ -1079,10 +1079,8 @@ void SAL_CALL DocumentMetadataAccess::loadMetadataFromStorage( const uno::Reference& xMetadataFile( getURI(m_pImpl->m_xContext)); const sal_Int32 len( baseURI.getLength() ); - for (::std::vector< uno::Reference< rdf::XURI > >::const_iterator it - = parts.begin(); - it != parts.end(); ++it) { - const OUString name((*it)->getStringValue()); + for (const auto& rxPart : parts) { + const OUString name(rxPart->getStringValue()); if (!name.match(baseURI)) { SAL_WARN("sfx", "loadMetadataFromStorage: graph not in document: " << name); continue; @@ -1095,7 +1093,7 @@ void SAL_CALL DocumentMetadataAccess::loadMetadataFromStorage( // remove found items from StgFiles StgFiles.erase(relName); if (isContentFile(relName)) { - if (!isPartOfType(*m_pImpl, *it, xContentFile)) { + if (!isPartOfType(*m_pImpl, rxPart, xContentFile)) { const uno::Reference xName( getURIForStream(*m_pImpl, relName) ); // add missing type statement @@ -1104,7 +1102,7 @@ void SAL_CALL DocumentMetadataAccess::loadMetadataFromStorage( xContentFile.get()); } } else if (isStylesFile(relName)) { - if (!isPartOfType(*m_pImpl, *it, xStylesFile)) { + if (!isPartOfType(*m_pImpl, rxPart, xStylesFile)) { const uno::Reference xName( getURIForStream(*m_pImpl, relName) ); // add missing type statement @@ -1115,7 +1113,7 @@ void SAL_CALL DocumentMetadataAccess::loadMetadataFromStorage( } else if (isReservedFile(relName)) { SAL_WARN("sfx", "loadMetadataFromStorage: reserved file name in manifest"); } else { - if (isPartOfType(*m_pImpl, *it, xMetadataFile)) { + if (isPartOfType(*m_pImpl, rxPart, xMetadataFile)) { MfstMetadataFiles.push_back(relName); } // do not add statement for MetadataFile; it could be diff --git a/sfx2/source/doc/docfac.cxx b/sfx2/source/doc/docfac.cxx index 94205215ea51..ba045e50b803 100644 --- a/sfx2/source/doc/docfac.cxx +++ b/sfx2/source/doc/docfac.cxx @@ -110,11 +110,8 @@ void SfxObjectFactory::RegisterViewFactory } } #endif - SfxViewFactoryArr_Impl::iterator it = pImpl->aViewFactoryArr.begin(); - for ( ; it != pImpl->aViewFactoryArr.end() && - (*it)->GetOrdinal() <= rFactory.GetOrdinal(); - ++it ) - /* empty loop */; + auto it = std::find_if(pImpl->aViewFactoryArr.begin(), pImpl->aViewFactoryArr.end(), + [&rFactory](SfxViewFactory* pFactory) { return pFactory->GetOrdinal() > rFactory.GetOrdinal(); }); pImpl->aViewFactoryArr.insert(it, &rFactory); } diff --git a/sfx2/source/doc/docinf.cxx b/sfx2/source/doc/docinf.cxx index fa6595631acc..943b767151d1 100644 --- a/sfx2/source/doc/docinf.cxx +++ b/sfx2/source/doc/docinf.cxx @@ -149,11 +149,10 @@ ErrCode LoadOlePropertySet( i_xDocProps->getUserDefinedProperties(), uno::UNO_QUERY_THROW); ::std::vector< sal_Int32 > aPropIds; xCustomSect->GetPropertyIds( aPropIds ); - for( ::std::vector< sal_Int32 >::const_iterator aIt = aPropIds.begin(), - aEnd = aPropIds.end(); aIt != aEnd; ++aIt ) + for( const auto& rPropId : aPropIds ) { - const OUString aPropName = xCustomSect->GetPropertyName( *aIt ); - uno::Any aPropValue = xCustomSect->GetAnyValue( *aIt ); + const OUString aPropName = xCustomSect->GetPropertyName( rPropId ); + uno::Any aPropValue = xCustomSect->GetAnyValue( rPropId ); if( !aPropName.isEmpty() && aPropValue.hasValue() ) { try diff --git a/sfx2/source/notebookbar/PriorityHBox.cxx b/sfx2/source/notebookbar/PriorityHBox.cxx index 0a641e2c8259..cb4a1be51d8c 100644 --- a/sfx2/source/notebookbar/PriorityHBox.cxx +++ b/sfx2/source/notebookbar/PriorityHBox.cxx @@ -124,27 +124,20 @@ void PriorityHBox::Resize() long nCurrentWidth = VclHBox::calculateRequisition().getWidth(); // Hide lower priority controls - auto pChild = m_aSortedChildren.begin(); - while (nCurrentWidth > nWidth && pChild != m_aSortedChildren.end()) + for (vcl::IPrioritable* pPrioritable : m_aSortedChildren) { - vcl::Window* pWindow = dynamic_cast(*pChild); - vcl::IPrioritable* pPrioritable = *pChild; + if (nCurrentWidth <= nWidth) + break; - if(pWindow->GetParent() != this) - { - pChild++; - continue; - } + vcl::Window* pWindow = dynamic_cast(pPrioritable); - if (pWindow) + if (pWindow && pWindow->GetParent() == this) { nCurrentWidth -= pWindow->GetOutputWidthPixel() + get_spacing(); pWindow->Show(); pPrioritable->HideContent(); nCurrentWidth += pWindow->GetOutputWidthPixel() + get_spacing(); } - - pChild++; } auto pChildR = m_aSortedChildren.rbegin(); diff --git a/sfx2/source/notify/globalevents.cxx b/sfx2/source/notify/globalevents.cxx index ca3b680f295e..3cc3cc05500f 100644 --- a/sfx2/source/notify/globalevents.cxx +++ b/sfx2/source/notify/globalevents.cxx @@ -399,17 +399,11 @@ TModelList::iterator SfxGlobalEvents_Impl::impl_searchDoc(const uno::Reference< if (!xModel.is()) return m_lModels.end(); - TModelList::iterator pIt; - for ( pIt = m_lModels.begin(); - pIt != m_lModels.end() ; - ++pIt ) - { - uno::Reference< frame::XModel > xContainerDoc(*pIt, uno::UNO_QUERY); - if (xContainerDoc == xModel) - break; - } - - return pIt; + return std::find_if(m_lModels.begin(), m_lModels.end(), + [&xModel](const TModelList::value_type& rxModel) { + uno::Reference< frame::XModel > xContainerDoc(rxModel, uno::UNO_QUERY); + return xContainerDoc == xModel; + }); } struct Instance { diff --git a/sfx2/source/sidebar/DeckLayouter.cxx b/sfx2/source/sidebar/DeckLayouter.cxx index 2b7f7df382b5..3d40cd13a59e 100644 --- a/sfx2/source/sidebar/DeckLayouter.cxx +++ b/sfx2/source/sidebar/DeckLayouter.cxx @@ -155,13 +155,10 @@ tools::Rectangle LayoutPanels ( sal_Int32 nTotalPreferredHeight (0); sal_Int32 nTotalMinimumHeight (0); - for(::std::vector::const_iterator iItem(rLayoutItems.begin()), - iEnd(rLayoutItems.end()); - iItem!=iEnd; - ++iItem) + for (const auto& rItem : rLayoutItems) { - nTotalMinimumHeight += iItem->maLayoutSize.Minimum; - nTotalPreferredHeight += iItem->maLayoutSize.Preferred; + nTotalMinimumHeight += rItem.maLayoutSize.Minimum; + nTotalPreferredHeight += rItem.maLayoutSize.Preferred; } if (nTotalMinimumHeight > nAvailableHeight @@ -343,36 +340,32 @@ void GetRequestedSizes ( const sal_Int32 nDeckSeparatorHeight (Theme::GetInteger(Theme::Int_DeckSeparatorHeight)); - ::std::vector::const_iterator iEnd(rLayoutItems.end()); - - for(::std::vector::iterator iItem(rLayoutItems.begin()); - iItem!=iEnd; - ++iItem) + for (auto& rItem : rLayoutItems) { ui::LayoutSize aLayoutSize (ui::LayoutSize(0,0,0)); - if (iItem->mpPanel != nullptr) + if (rItem.mpPanel != nullptr) { if (rLayoutItems.size() == 1 - && iItem->mpPanel->IsTitleBarOptional()) + && rItem.mpPanel->IsTitleBarOptional()) { // There is only one panel and its title bar is // optional => hide it. rAvailableHeight -= nDeckSeparatorHeight; - iItem->mbShowTitleBar = false; + rItem.mbShowTitleBar = false; } else { // Show the title bar and a separator above and below // the title bar. - const sal_Int32 nPanelTitleBarHeight (Theme::GetInteger(Theme::Int_PanelTitleBarHeight) * iItem->mpPanel->GetDPIScaleFactor()); + const sal_Int32 nPanelTitleBarHeight (Theme::GetInteger(Theme::Int_PanelTitleBarHeight) * rItem.mpPanel->GetDPIScaleFactor()); rAvailableHeight -= nPanelTitleBarHeight; rAvailableHeight -= nDeckSeparatorHeight; } - if (iItem->mpPanel->IsExpanded()) + if (rItem.mpPanel->IsExpanded()) { - Reference xPanel (iItem->mpPanel->GetPanelComponent()); + Reference xPanel (rItem.mpPanel->GetPanelComponent()); if (xPanel.is()) { aLayoutSize = xPanel->getHeightForWidth(rContentBox.GetWidth()); @@ -385,7 +378,7 @@ void GetRequestedSizes ( aLayoutSize = ui::LayoutSize(MinimalPanelHeight, -1, 0); } } - iItem->maLayoutSize = aLayoutSize; + rItem.maLayoutSize = aLayoutSize; } } @@ -405,25 +398,21 @@ void DistributeHeights ( sal_Int32 nTotalWeight (0); sal_Int32 nNoMaximumCount (0); - ::std::vector::const_iterator iEnd(rLayoutItems.end()); - - for(::std::vector::iterator iItem(rLayoutItems.begin()); - iItem!=iEnd; - ++iItem) + for (auto& rItem : rLayoutItems) { - if (iItem->maLayoutSize.Maximum == 0) + if (rItem.maLayoutSize.Maximum == 0) continue; - if (iItem->maLayoutSize.Maximum < 0) + if (rItem.maLayoutSize.Maximum < 0) ++nNoMaximumCount; const sal_Int32 nBaseHeight ( bMinimumHeightIsBase - ? iItem->maLayoutSize.Minimum - : iItem->maLayoutSize.Preferred); + ? rItem.maLayoutSize.Minimum + : rItem.maLayoutSize.Preferred); if (nBaseHeight < nContainerHeight) { - iItem->mnWeight = nContainerHeight - nBaseHeight; - nTotalWeight += iItem->mnWeight; + rItem.mnWeight = nContainerHeight - nBaseHeight; + nTotalWeight += rItem.mnWeight; } } @@ -431,21 +420,19 @@ void DistributeHeights ( return; // First pass of height distribution. - for(::std::vector::iterator iItem(rLayoutItems.begin()); - iItem!=iEnd; - ++iItem) + for (auto& rItem : rLayoutItems) { const sal_Int32 nBaseHeight ( bMinimumHeightIsBase - ? iItem->maLayoutSize.Minimum - : iItem->maLayoutSize.Preferred); - sal_Int32 nDistributedHeight (iItem->mnWeight * nHeightToDistribute / nTotalWeight); - if (nBaseHeight+nDistributedHeight > iItem->maLayoutSize.Maximum - && iItem->maLayoutSize.Maximum >= 0) + ? rItem.maLayoutSize.Minimum + : rItem.maLayoutSize.Preferred); + sal_Int32 nDistributedHeight (rItem.mnWeight * nHeightToDistribute / nTotalWeight); + if (nBaseHeight+nDistributedHeight > rItem.maLayoutSize.Maximum + && rItem.maLayoutSize.Maximum >= 0) { - nDistributedHeight = ::std::max(0,iItem->maLayoutSize.Maximum - nBaseHeight); + nDistributedHeight = ::std::max(0, rItem.maLayoutSize.Maximum - nBaseHeight); } - iItem->mnDistributedHeight = nDistributedHeight; + rItem.mnDistributedHeight = nDistributedHeight; nRemainingHeightToDistribute -= nDistributedHeight; } @@ -467,13 +454,11 @@ void DistributeHeights ( sal_Int32 nAdditionalHeightForFirstPanel (nRemainingHeightToDistribute - nNoMaximumCount*nAdditionalHeightPerPanel); - for(::std::vector::iterator iItem(rLayoutItems.begin()); - iItem!=iEnd; - ++iItem) + for (auto& rItem : rLayoutItems) { - if (iItem->maLayoutSize.Maximum < 0) + if (rItem.maLayoutSize.Maximum < 0) { - iItem->mnDistributedHeight += nAdditionalHeightPerPanel + nAdditionalHeightForFirstPanel; + rItem.mnDistributedHeight += nAdditionalHeightPerPanel + nAdditionalHeightForFirstPanel; nRemainingHeightToDistribute -= nAdditionalHeightPerPanel + nAdditionalHeightForFirstPanel; } } diff --git a/sfx2/source/sidebar/SidebarController.cxx b/sfx2/source/sidebar/SidebarController.cxx index 95b33d7cde4a..f56534d02f46 100644 --- a/sfx2/source/sidebar/SidebarController.cxx +++ b/sfx2/source/sidebar/SidebarController.cxx @@ -229,11 +229,9 @@ void SAL_CALL SidebarController::disposing() IsDocumentReadOnly(), mxFrame->getController()); - for (ResourceManager::DeckContextDescriptorContainer::const_iterator - iDeck(aDecks.begin()), iEnd(aDecks.end()); - iDeck!=iEnd; ++iDeck) + for (const auto& rDeck : aDecks) { - std::shared_ptr deckDesc = mpResourceManager->GetDeckDescriptor(iDeck->msId); + std::shared_ptr deckDesc = mpResourceManager->GetDeckDescriptor(rDeck.msId); VclPtr aDeck = deckDesc->mpDeck; if (aDeck) @@ -480,21 +478,17 @@ void SidebarController::UpdateConfigurations() // one. If that is not set or not enabled, then choose the // first enabled deck (which is PropertyDeck). OUString sNewDeckId; - for (ResourceManager::DeckContextDescriptorContainer::const_iterator - iDeck(aDecks.begin()), - iEnd(aDecks.end()); - iDeck!=iEnd; - ++iDeck) + for (const auto& rDeck : aDecks) { - if (iDeck->mbIsEnabled) + if (rDeck.mbIsEnabled) { - if (iDeck->msId == msCurrentDeckId) + if (rDeck.msId == msCurrentDeckId) { sNewDeckId = msCurrentDeckId; break; } else if (sNewDeckId.getLength() == 0) - sNewDeckId = iDeck->msId; + sNewDeckId = rDeck.msId; } } @@ -996,29 +990,26 @@ VclPtr SidebarController::CreatePopupMenu ( // Add one entry for every tool panel element to individually make // them visible or hide them. sal_Int32 nIndex (0); - for(::std::vector::const_iterator - iItem(rMenuData.begin()), - iEnd(rMenuData.end()); - iItem!=iEnd; - ++iItem,++nIndex) + for (const auto& rItem : rMenuData) { const sal_Int32 nMenuIndex (nIndex+MID_FIRST_PANEL); - pMenu->InsertItem(nMenuIndex, iItem->msDisplayName, MenuItemBits::RADIOCHECK); - pMenu->CheckItem(nMenuIndex, iItem->mbIsCurrentDeck); - pMenu->EnableItem(nMenuIndex, iItem->mbIsEnabled&&iItem->mbIsActive); + pMenu->InsertItem(nMenuIndex, rItem.msDisplayName, MenuItemBits::RADIOCHECK); + pMenu->CheckItem(nMenuIndex, rItem.mbIsCurrentDeck); + pMenu->EnableItem(nMenuIndex, rItem.mbIsEnabled && rItem.mbIsActive); const sal_Int32 nSubMenuIndex (nIndex+MID_FIRST_HIDE); - if (iItem->mbIsCurrentDeck) + if (rItem.mbIsCurrentDeck) { // Don't allow the currently visible deck to be disabled. - pCustomizationMenu->InsertItem(nSubMenuIndex, iItem->msDisplayName, MenuItemBits::RADIOCHECK); + pCustomizationMenu->InsertItem(nSubMenuIndex, rItem.msDisplayName, MenuItemBits::RADIOCHECK); pCustomizationMenu->CheckItem(nSubMenuIndex); } else { - pCustomizationMenu->InsertItem(nSubMenuIndex, iItem->msDisplayName, MenuItemBits::CHECKABLE); - pCustomizationMenu->CheckItem(nSubMenuIndex, iItem->mbIsEnabled && iItem->mbIsActive); + pCustomizationMenu->InsertItem(nSubMenuIndex, rItem.msDisplayName, MenuItemBits::CHECKABLE); + pCustomizationMenu->CheckItem(nSubMenuIndex, rItem.mbIsEnabled && rItem.mbIsActive); } + ++nIndex; } pMenu->InsertSeparator(); @@ -1311,23 +1302,20 @@ void SidebarController::UpdateTitleBarIcons() // Update the panel icons. const SharedPanelContainer& rPanels (mpCurrentDeck->GetPanels()); - for (SharedPanelContainer::const_iterator - iPanel(rPanels.begin()), iEnd(rPanels.end()); - iPanel!=iEnd; - ++iPanel) + for (const auto& rxPanel : rPanels) { - if ( ! *iPanel) + if ( ! rxPanel) continue; - if (!(*iPanel)->GetTitleBar()) + if (!rxPanel->GetTitleBar()) continue; - std::shared_ptr xPanelDescriptor = rResourceManager.GetPanelDescriptor((*iPanel)->GetId()); + std::shared_ptr xPanelDescriptor = rResourceManager.GetPanelDescriptor(rxPanel->GetId()); if (!xPanelDescriptor) continue; const OUString sIconURL ( bIsHighContrastModeActive ? xPanelDescriptor->msHighContrastTitleBarIconURL : xPanelDescriptor->msTitleBarIconURL); - (*iPanel)->GetTitleBar()->SetIcon(Tools::GetImage(sIconURL, mxFrame)); + rxPanel->GetTitleBar()->SetIcon(Tools::GetImage(sIconURL, mxFrame)); } } diff --git a/sfx2/source/sidebar/Theme.cxx b/sfx2/source/sidebar/Theme.cxx index a6587a493a50..90911f159efa 100644 --- a/sfx2/source/sidebar/Theme.cxx +++ b/sfx2/source/sidebar/Theme.cxx @@ -350,21 +350,13 @@ void SAL_CALL Theme::disposing() const lang::EventObject aEvent (static_cast(this)); - for (ChangeListeners::const_iterator - iContainer(aListeners.begin()), - iContainerEnd(aListeners.end()); - iContainer != iContainerEnd; - ++iContainer) + for (const auto& rContainer : aListeners) { - for (ChangeListenerContainer::const_iterator - iListener(iContainer->second.begin()), - iEnd(iContainer->second.end()); - iListener!=iEnd; - ++iListener) + for (const auto& rxListener : rContainer.second) { try { - (*iListener)->disposing(aEvent); + rxListener->disposing(aEvent); } catch(const Exception&) { @@ -934,13 +926,9 @@ bool Theme::DoVetoableListenersVeto ( VetoableListenerContainer aListeners (*pListeners); try { - for (VetoableListenerContainer::const_iterator - iListener(aListeners.begin()), - iEnd(aListeners.end()); - iListener!=iEnd; - ++iListener) + for (const auto& rxListener : aListeners) { - (*iListener)->vetoableChange(rEvent); + rxListener->vetoableChange(rEvent); } } catch(const beans::PropertyVetoException&) @@ -964,13 +952,9 @@ void Theme::BroadcastPropertyChange ( const ChangeListenerContainer aListeners (*pListeners); try { - for (ChangeListenerContainer::const_iterator - iListener(aListeners.begin()), - iEnd(aListeners.end()); - iListener!=iEnd; - ++iListener) + for (const auto& rxListener : aListeners) { - (*iListener)->propertyChange(rEvent); + rxListener->propertyChange(rEvent); } } catch(const Exception&) diff --git a/sfx2/source/sidebar/UnoDecks.cxx b/sfx2/source/sidebar/UnoDecks.cxx index 9812bc5c6dfa..915a0656ae69 100644 --- a/sfx2/source/sidebar/UnoDecks.cxx +++ b/sfx2/source/sidebar/UnoDecks.cxx @@ -67,13 +67,11 @@ uno::Sequence< OUString > SAL_CALL SfxUnoDecks::getElementNames() long n = 0; - for (ResourceManager::DeckContextDescriptorContainer::const_iterator - iDeck(aDecks.begin()), iEnd(aDecks.end()); - iDeck!=iEnd; ++iDeck) - { - deckList[n] = iDeck->msId; - n++; - } + for (const auto& rDeck : aDecks) + { + deckList[n] = rDeck.msId; + n++; + } } return deckList; @@ -98,13 +96,8 @@ sal_Bool SAL_CALL SfxUnoDecks::hasByName( const OUString& aName ) pSidebarController->IsDocumentReadOnly(), xFrame->getController()); - for (ResourceManager::DeckContextDescriptorContainer::const_iterator - iDeck(aDecks.begin()), iEnd(aDecks.end()); - iDeck!=iEnd && !bFound; ++iDeck) - { - if (iDeck->msId == aName) - bFound = true; - } + bFound = std::any_of(aDecks.begin(), aDecks.end(), + [&aName](const ResourceManager::DeckContextDescriptor& rDeck) { return rDeck.msId == aName; }); } return bFound; diff --git a/sfx2/source/sidebar/UnoPanels.cxx b/sfx2/source/sidebar/UnoPanels.cxx index 49815a9ff649..a8c1f41a691e 100644 --- a/sfx2/source/sidebar/UnoPanels.cxx +++ b/sfx2/source/sidebar/UnoPanels.cxx @@ -76,13 +76,11 @@ uno::Sequence< OUString > SAL_CALL SfxUnoPanels::getElementNames() long n = 0; - for (ResourceManager::PanelContextDescriptorContainer::const_iterator - iPanel(aPanels.begin()), iEnd(aPanels.end()); - iPanel!=iEnd; ++iPanel) - { - panelList[n] = iPanel->msId; - n++; - } + for (const auto& rPanel : aPanels) + { + panelList[n] = rPanel.msId; + n++; + } } return panelList; @@ -104,16 +102,13 @@ sal_Bool SAL_CALL SfxUnoPanels::hasByName( const OUString& aName ) mDeckId, xFrame->getController()); - for (ResourceManager::PanelContextDescriptorContainer::const_iterator - iPanel(aPanels.begin()), iEnd(aPanels.end()); - iPanel!=iEnd; ++iPanel) - { - // Determine if the panel can be displayed. - if(pSidebarController->IsDocumentReadOnly() && !iPanel->mbShowForReadOnlyDocuments) - continue; - if (iPanel->msId == aName) - return true; - } + bool bIsDocumentReadOnly = pSidebarController->IsDocumentReadOnly(); + + return std::any_of(aPanels.begin(), aPanels.end(), + [&bIsDocumentReadOnly, &aName](const ResourceManager::PanelContextDescriptor& rPanel) { + return (!bIsDocumentReadOnly || rPanel.mbShowForReadOnlyDocuments) // Determine if the panel can be displayed. + && (rPanel.msId == aName); + }); } // nothing found diff --git a/sfx2/source/view/viewsh.cxx b/sfx2/source/view/viewsh.cxx index fa571944a96a..683d6a45f288 100644 --- a/sfx2/source/view/viewsh.cxx +++ b/sfx2/source/view/viewsh.cxx @@ -360,14 +360,9 @@ void SfxViewShell::IPClientGone_Impl( SfxInPlaceClient const *pIPClient ) { std::vector< SfxInPlaceClient* > *pClients = pImpl->GetIPClients_Impl(); - for(std::vector< SfxInPlaceClient* >::iterator it = pClients->begin(); it != pClients->end(); ++it) - { - if ( *it == pIPClient ) - { - pClients->erase( it ); - break; - } - } + auto it = std::find(pClients->begin(), pClients->end(), pIPClient); + if (it != pClients->end()) + pClients->erase( it ); } diff --git a/shell/source/win32/shlxthandler/propsheets/listviewbuilder.cxx b/shell/source/win32/shlxthandler/propsheets/listviewbuilder.cxx index 4b5342441cfe..663762e188fb 100644 --- a/shell/source/win32/shlxthandler/propsheets/listviewbuilder.cxx +++ b/shell/source/win32/shlxthandler/propsheets/listviewbuilder.cxx @@ -73,19 +73,13 @@ void list_view_builder::build(statistic_group_list_t& gl) { setup_list_view(); - statistic_group_list_t::iterator group_iter = gl.begin(); - statistic_group_list_t::iterator group_iter_end = gl.end(); - - for (/**/; group_iter != group_iter_end; ++group_iter) + for (const auto& group : gl) { - statistic_item_list_t::iterator item_iter = group_iter->second.begin(); - statistic_item_list_t::iterator item_iter_end = group_iter->second.end(); - - if (item_iter != item_iter_end) - insert_group(group_iter->first); + if (!group.second.empty()) + insert_group(group.first); - for (/**/; item_iter != item_iter_end; ++item_iter) - insert_item(item_iter->title_, item_iter->value_, item_iter->editable_); + for (const auto& item : group.second) + insert_item(item.title_, item.value_, item.editable_); } } diff --git a/shell/source/win32/shlxthandler/util/iso8601_converter.cxx b/shell/source/win32/shlxthandler/util/iso8601_converter.cxx index 331a76926a5f..bf5a23d4da90 100644 --- a/shell/source/win32/shlxthandler/util/iso8601_converter.cxx +++ b/shell/source/win32/shlxthandler/util/iso8601_converter.cxx @@ -114,26 +114,23 @@ std::wstring iso8601_duration_to_local_duration(const std::wstring& iso8601durat std::wstring minutes; std::wstring seconds; - std::wstring::const_iterator iter = iso8601duration.begin(); - std::wstring::const_iterator iter_end = iso8601duration.end(); - std::wstring num; - for (/**/; iter != iter_end; ++iter) + for (const auto& w_ch : iso8601duration) { - if (rtl::isAsciiDigit(*iter)) // wchar_t is unsigned under MSVC + if (rtl::isAsciiDigit(w_ch)) // wchar_t is unsigned under MSVC { - num += *iter; + num += w_ch; } else { - if (*iter == L'D' || *iter == L'd') + if (w_ch == L'D' || w_ch == L'd') days = num; - else if (*iter == L'H' || *iter == L'h') + else if (w_ch == L'H' || w_ch == L'h') hours = num; - else if (*iter == L'M' || *iter == L'm') + else if (w_ch == L'M' || w_ch == L'm') minutes = num; - else if (*iter == L'S' || *iter == L's') + else if (w_ch == L'S' || w_ch == L's') seconds = num; num.clear(); -- cgit v1.2.3