diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2023-06-01 14:22:57 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2023-06-11 18:24:29 +0200 |
commit | 7c66fc45239d2589e90fd694d54b3ff826b1bd15 (patch) | |
tree | 064a3ba4eaeaf05ae13ebcebfc6d8beb9234d8f2 | |
parent | 3a6d360b5e585b8e92cc0d58d5fbc497448e11fb (diff) |
use internal iterator for SfxBroadcaster
So we can avoid exposing the internal listener vector.
(which allows further optimisations)
Change-Id: If288141a37314dcc01d203029dc51c71ec2b7f54
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152857
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r-- | include/svl/SfxBroadcaster.hxx | 13 | ||||
-rw-r--r-- | include/svx/svdviter.hxx | 26 | ||||
-rw-r--r-- | sc/source/core/data/stlsheet.cxx | 22 | ||||
-rw-r--r-- | sd/source/core/stlpool.cxx | 17 | ||||
-rw-r--r-- | sd/source/core/stlsheet.cxx | 46 | ||||
-rw-r--r-- | sd/source/ui/view/unmodpg.cxx | 30 | ||||
-rw-r--r-- | svl/source/notify/SfxBroadcaster.cxx | 29 | ||||
-rw-r--r-- | svx/source/svdraw/svdedtv.cxx | 18 | ||||
-rw-r--r-- | svx/source/svdraw/svdedxv.cxx | 27 | ||||
-rw-r--r-- | svx/source/svdraw/svdmark.cxx | 68 | ||||
-rw-r--r-- | svx/source/svdraw/svdouno.cxx | 17 | ||||
-rw-r--r-- | svx/source/svdraw/svdpntv.cxx | 27 | ||||
-rw-r--r-- | svx/source/svdraw/svdundo.cxx | 10 | ||||
-rw-r--r-- | svx/source/svdraw/svdviter.cxx | 125 | ||||
-rw-r--r-- | svx/source/unodraw/unoshap2.cxx | 15 | ||||
-rw-r--r-- | sw/source/core/draw/dcontact.cxx | 11 | ||||
-rw-r--r-- | sw/source/core/unocore/unostyle.cxx | 22 |
17 files changed, 240 insertions, 283 deletions
diff --git a/include/svl/SfxBroadcaster.hxx b/include/svl/SfxBroadcaster.hxx index 2c05a6abfe5a..fba30061f574 100644 --- a/include/svl/SfxBroadcaster.hxx +++ b/include/svl/SfxBroadcaster.hxx @@ -21,6 +21,7 @@ #include <svl/svldllapi.h> #include <vector> +#include <functional> class SfxListener; class SfxHint; @@ -52,15 +53,13 @@ public: /** Get the number of listeners which are registered at this broadcaster */ size_t GetListenerCount() const; - /** Get the size of the internally stored vector. - * Use it to iterate over all listeners. - */ - size_t GetSizeOfVector() const; + /** Iterate over all the listeners and call the passed function. + return true to break the loop. */ + void ForAllListeners(std::function<bool(SfxListener*)> f) const; - /** Get a listener by its position in the internally stored vector. - * Note that this method may return NULL + /** Get a vector of the current listeners - used by unit test code. */ - SfxListener* GetListener( size_t nNo ) const; + std::vector<SfxListener*> GetListenersForUnitTest() const; friend class SfxListener; friend class ::SfxBroadcasterTest; diff --git a/include/svx/svdviter.hxx b/include/svx/svdviter.hxx index bdb28469c5f2..9782efa033e8 100644 --- a/include/svx/svdviter.hxx +++ b/include/svx/svdviter.hxx @@ -20,6 +20,7 @@ #pragma once #include <svx/svxdllapi.h> +#include <functional> /* @@ -50,34 +51,15 @@ Not considered are: */ -class OutputDevice; class SdrView; -class SdrPageView; class SdrModel; class SdrPage; class SdrObject; -class SdrLayerIDSet; -class SVXCORE_DLLPUBLIC SdrViewIter +namespace SdrViewIter { - const SdrModel* mpModel; - const SdrPage* mpPage; - const SdrObject* mpObject; - SdrView* mpCurrentView; - - size_t mnListenerNum; - -private: - SVX_DLLPRIVATE void ImpInitVars(); - SVX_DLLPRIVATE SdrView* ImpFindView(); - SVX_DLLPRIVATE bool ImpCheckPageView(SdrPageView const * pPV) const; - -public: - SdrViewIter(const SdrPage* pPage); - SdrViewIter(const SdrObject* pObject); - - SdrView* FirstView(); - SdrView* NextView(); + SVXCORE_DLLPUBLIC void ForAllViews(const SdrPage* pPage, std::function<void(SdrView*)> f); + SVXCORE_DLLPUBLIC void ForAllViews(const SdrObject* pObject, std::function<void(SdrView*)> f); }; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/core/data/stlsheet.cxx b/sc/source/core/data/stlsheet.cxx index 062be0a05280..7679f1936a6b 100644 --- a/sc/source/core/data/stlsheet.cxx +++ b/sc/source/core/data/stlsheet.cxx @@ -297,18 +297,18 @@ bool ScStyleSheet::IsUsed() const } case SfxStyleFamily::Frame: { - const size_t nListenerCount = GetSizeOfVector(); - for (size_t n = 0; n < nListenerCount; ++n) - { - auto pUser(dynamic_cast<svl::StyleSheetUser*>(GetListener(n))); - if (pUser && pUser->isUsedByModel()) + ForAllListeners([this] (SfxListener* pListener) { - eUsage = Usage::USED; - break; - } - else - eUsage = Usage::NOTUSED; - } + auto pUser(dynamic_cast<svl::StyleSheetUser*>(pListener)); + if (pUser && pUser->isUsedByModel()) + { + eUsage = Usage::USED; + return true; // break loop + } + else + eUsage = Usage::NOTUSED; + return false; + }); return eUsage == Usage::USED; } default: diff --git a/sd/source/core/stlpool.cxx b/sd/source/core/stlpool.cxx index 2134cec147f5..1d90ed00bca4 100644 --- a/sd/source/core/stlpool.cxx +++ b/sd/source/core/stlpool.cxx @@ -1369,15 +1369,16 @@ SdStyleSheetVector SdStyleSheetPool::CreateChildList( SdStyleSheet const * pShee { SdStyleSheetVector aResult; - const size_t nListenerCount = pSheet->GetSizeOfVector(); - for (size_t n = 0; n < nListenerCount; ++n) - { - SdStyleSheet* pChild = dynamic_cast< SdStyleSheet* >( pSheet->GetListener(n) ); - if(pChild && pChild->GetParent() == pSheet->GetName()) + pSheet->ForAllListeners( + [&pSheet, &aResult] (SfxListener* pListener) { - aResult.emplace_back( pChild ); - } - } + SdStyleSheet* pChild = dynamic_cast< SdStyleSheet* >( pListener ); + if(pChild && pChild->GetParent() == pSheet->GetName()) + { + aResult.emplace_back( pChild ); + } + return false; + }); return aResult; } diff --git a/sd/source/core/stlsheet.cxx b/sd/source/core/stlsheet.cxx index a544e7f198d3..fe981d8bca45 100644 --- a/sd/source/core/stlsheet.cxx +++ b/sd/source/core/stlsheet.cxx @@ -282,19 +282,19 @@ bool SdStyleSheet::IsUsed() const { bool bResult = false; - const size_t nListenerCount = GetSizeOfVector(); - for (size_t n = 0; n < nListenerCount; ++n) - { - SfxListener* pListener = GetListener(n); - if( pListener == this ) - continue; - - const svl::StyleSheetUser* const pUser(dynamic_cast<svl::StyleSheetUser*>(pListener)); - if (pUser) - bResult = pUser->isUsedByModel(); - if (bResult) - break; - } + ForAllListeners( + [this, &bResult] (SfxListener* pListener) + { + if( pListener == this ) + return false; // continue + + const svl::StyleSheetUser* const pUser(dynamic_cast<svl::StyleSheetUser*>(pListener)); + if (pUser) + bResult = pUser->isUsedByModel(); + if (bResult) + return true; // break loop + return false; + }); if( !bResult ) { @@ -335,15 +335,19 @@ bool SdStyleSheet::IsEditable() if (!IsUserDefined()) return false; - const size_t nListenerCount = GetSizeOfVector(); - for (size_t n = 0; n < nListenerCount; ++n) - { - SfxListener* pListener = GetListener(n); - if (pListener == this) - continue; - if (dynamic_cast<SdStyleSheet*>(pListener)) + bool bFoundOne = false; + ForAllListeners( + [this, &bFoundOne] (SfxListener* pListener) + { + if (pListener != this && dynamic_cast<SdStyleSheet*>(pListener)) + { + bFoundOne = true; + return true; // break loop + } return false; - } + }); + if (bFoundOne) + return false; std::unique_lock aGuard(m_aMutex); return maModifyListeners.getLength(aGuard) <= 1; diff --git a/sd/source/ui/view/unmodpg.cxx b/sd/source/ui/view/unmodpg.cxx index afd454a5f183..383a84a7b2ba 100644 --- a/sd/source/ui/view/unmodpg.cxx +++ b/sd/source/ui/view/unmodpg.cxx @@ -83,15 +83,12 @@ void ModifyPageUndoAction::Undo() { // invalidate Selection, there could be objects deleted in this UNDO // which are no longer allowed to be selected then. - SdrViewIter aIter(mpPage); - SdrView* pView = aIter.FirstView(); - - while(pView) - { - if(pView->AreObjectsMarked()) - pView->UnmarkAll(); - pView = aIter.NextView(); - } + SdrViewIter::ForAllViews(mpPage, + [] (SdrView* pView) + { + if(pView->AreObjectsMarked()) + pView->UnmarkAll(); + }); mpPage->SetAutoLayout( meOldAutoLayout ); @@ -130,15 +127,12 @@ void ModifyPageUndoAction::Redo() { // invalidate Selection, there could be objects deleted in this UNDO // which are no longer allowed to be selected then. - SdrViewIter aIter(mpPage); - SdrView* pView = aIter.FirstView(); - - while(pView) - { - if(pView->AreObjectsMarked()) - pView->UnmarkAll(); - pView = aIter.NextView(); - } + SdrViewIter::ForAllViews(mpPage, + [] (SdrView* pView) + { + if(pView->AreObjectsMarked()) + pView->UnmarkAll(); + }); mpPage->meAutoLayout = meNewAutoLayout; diff --git a/svl/source/notify/SfxBroadcaster.cxx b/svl/source/notify/SfxBroadcaster.cxx index ae1be1475c91..c1c5bee51f34 100644 --- a/svl/source/notify/SfxBroadcaster.cxx +++ b/svl/source/notify/SfxBroadcaster.cxx @@ -131,16 +131,33 @@ void SfxBroadcaster::RemoveListener(SfxListener& rListener) m_RemovedPositions.push_back(positionOfRemovedElement); } -bool SfxBroadcaster::HasListeners() const { return (GetListenerCount() != 0); } +void SfxBroadcaster::ForAllListeners(std::function<bool(SfxListener*)> f) const +{ + for (size_t i = 0; i < m_Listeners.size(); ++i) + { + SfxListener* const pListener = m_Listeners[i]; + if (pListener) + f(pListener); + } +} -size_t SfxBroadcaster::GetListenerCount() const +std::vector<SfxListener*> SfxBroadcaster::GetListenersForUnitTest() const { - assert(m_Listeners.size() >= m_RemovedPositions.size()); - return m_Listeners.size() - m_RemovedPositions.size(); + std::vector<SfxListener*> rv; + for (size_t i = 0; i < m_Listeners.size(); ++i) + { + SfxListener* const pListener = m_Listeners[i]; + if (pListener) + rv.push_back(pListener); + } + return rv; } -size_t SfxBroadcaster::GetSizeOfVector() const { return m_Listeners.size(); } +bool SfxBroadcaster::HasListeners() const { return GetListenerCount() != 0; } -SfxListener* SfxBroadcaster::GetListener(size_t nNo) const { return m_Listeners[nNo]; } +size_t SfxBroadcaster::GetListenerCount() const +{ + return m_Listeners.size() - m_RemovedPositions.size(); +} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/svdraw/svdedtv.cxx b/svx/source/svdraw/svdedtv.cxx index 27015e410e9d..88589a52271f 100644 --- a/svx/source/svdraw/svdedtv.cxx +++ b/svx/source/svdraw/svdedtv.cxx @@ -1060,16 +1060,14 @@ bool SdrEditView::IsUndoEnabled() const void SdrEditView::EndTextEditAllViews() const { - size_t nViews = GetModel().GetListenerCount(); - for (size_t nView = 0; nView < nViews; ++nView) - { - SdrObjEditView* pView = dynamic_cast<SdrObjEditView*>(GetModel().GetListener(nView)); - if (!pView) - continue; - - if (pView->IsTextEdit()) - pView->SdrEndTextEdit(); - } + GetModel().ForAllListeners( + [](SfxListener* pListener) + { + SdrObjEditView* pView = dynamic_cast<SdrObjEditView*>(pListener); + if (pView && pView->IsTextEdit()) + pView->SdrEndTextEdit(); + return false; + }); } void SdrEditView::EndTextEditCurrentView(bool bDontDeleteReally) diff --git a/svx/source/svdraw/svdedxv.cxx b/svx/source/svdraw/svdedxv.cxx index ae19c26496f3..c2d35cc75b6b 100644 --- a/svx/source/svdraw/svdedxv.cxx +++ b/svx/source/svdraw/svdedxv.cxx @@ -136,15 +136,13 @@ SdrPageView* SdrObjEditView::ShowSdrPage(SdrPage* pPage) { // Check if other views have an active text edit on the same page as // this one. - SdrViewIter aIter(pPageView->GetPage()); - for (SdrView* pView = aIter.FirstView(); pView; pView = aIter.NextView()) - { + SdrViewIter::ForAllViews(pPageView->GetPage(), [this](SdrView* pView) { if (pView == this || !pView->IsTextEdit()) - continue; + return; OutputDevice* pOutDev = GetFirstOutputDevice(); if (!pOutDev || pOutDev->GetOutDevType() != OUTDEV_WINDOW) - continue; + return; // Found one, so create an outliner view, to get invalidations when // the text edit changes. @@ -155,7 +153,7 @@ SdrPageView* SdrObjEditView::ShowSdrPage(SdrPage* pPage) = pView->ImpMakeOutlinerView(pOutDev->GetOwnerWindow(), nullptr, GetSfxViewShell()); pOutlinerView->HideCursor(); pView->GetTextEditOutliner()->InsertView(pOutlinerView); - } + }); } return pPageView; @@ -176,11 +174,9 @@ void lcl_RemoveTextEditOutlinerViews(SdrObjEditView const* pThis, SdrPageView co if (!pOutputDevice || pOutputDevice->GetOutDevType() != OUTDEV_WINDOW) return; - SdrViewIter aIter(pPageView->GetPage()); - for (SdrView* pView = aIter.FirstView(); pView; pView = aIter.NextView()) - { + SdrViewIter::ForAllViews(pPageView->GetPage(), [&pThis, &pOutputDevice](SdrView* pView) { if (pView == pThis || !pView->IsTextEdit()) - continue; + return; SdrOutliner* pOutliner = pView->GetTextEditOutliner(); for (size_t nView = 0; nView < pOutliner->GetViewCount(); ++nView) @@ -192,7 +188,7 @@ void lcl_RemoveTextEditOutlinerViews(SdrObjEditView const* pThis, SdrPageView co pOutliner->RemoveView(pOutlinerView); delete pOutlinerView; } - } + }); } } @@ -1457,11 +1453,10 @@ bool SdrObjEditView::SdrBeginTextEdit(SdrObject* pObj_, SdrPageView* pPV, vcl::W // Register an outliner view for all other sdr views that // show the same page, so that when the text edit changes, // all interested windows get an invalidation. - SdrViewIter aIter(pObj->getSdrPageFromSdrObject()); - for (SdrView* pView = aIter.FirstView(); pView; pView = aIter.NextView()) - { + SdrViewIter::ForAllViews(pObj->getSdrPageFromSdrObject(), [this, &pWin]( + SdrView* pView) { if (pView == this) - continue; + return; for (sal_uInt32 nViewPaintWindow = 0; nViewPaintWindow < pView->PaintWindowCount(); ++nViewPaintWindow) @@ -1479,7 +1474,7 @@ bool SdrObjEditView::SdrBeginTextEdit(SdrObject* pObj_, SdrPageView* pPV, vcl::W mpTextEditOutliner->InsertView(pOutlView); } } - } + }); } } diff --git a/svx/source/svdraw/svdmark.cxx b/svx/source/svdraw/svdmark.cxx index 9df4b8dc32f1..c92fbebef7a1 100644 --- a/svx/source/svdraw/svdmark.cxx +++ b/svx/source/svdraw/svdmark.cxx @@ -736,53 +736,49 @@ namespace sdr for(size_t a = 0; a < nMarkCount; ++a) { SdrObject* pCandidate = maMarkedObjectList.GetMark(a)->GetMarkedSdrObj(); + if(!pCandidate) + continue; - if(pCandidate) - { - // build transitive hull - ImplCollectCompleteSelection(pCandidate); + // build transitive hull + ImplCollectCompleteSelection(pCandidate); - // travel over broadcaster/listener to access edges connected to the selected object - const SfxBroadcaster* pBC = pCandidate->GetBroadcaster(); + // travel over broadcaster/listener to access edges connected to the selected object + const SfxBroadcaster* pBC = pCandidate->GetBroadcaster(); + if(!pBC) + continue; - if(pBC) + pBC->ForAllListeners( + [this, &pCandidate, &a] (SfxListener* pLst) { - const size_t nLstCnt(pBC->GetSizeOfVector()); + SdrEdgeObj* pEdge = dynamic_cast<SdrEdgeObj*>( pLst ); - for(size_t nl=0; nl < nLstCnt; ++nl) + if(pEdge && pEdge->IsInserted() && pEdge->getSdrPageFromSdrObject() == pCandidate->getSdrPageFromSdrObject()) { - SfxListener* pLst = pBC->GetListener(nl); - SdrEdgeObj* pEdge = dynamic_cast<SdrEdgeObj*>( pLst ); + SdrMark aM(pEdge, maMarkedObjectList.GetMark(a)->GetPageView()); + + if(pEdge->GetConnectedNode(true) == pCandidate) + { + aM.SetCon1(true); + } + + if(pEdge->GetConnectedNode(false) == pCandidate) + { + aM.SetCon2(true); + } - if(pEdge && pEdge->IsInserted() && pEdge->getSdrPageFromSdrObject() == pCandidate->getSdrPageFromSdrObject()) + if(SAL_MAX_SIZE == maMarkedObjectList.FindObject(pEdge)) + { + // check if it itself is selected + maEdgesOfMarkedNodes.InsertEntry(aM); + } + else { - SdrMark aM(pEdge, maMarkedObjectList.GetMark(a)->GetPageView()); - - if(pEdge->GetConnectedNode(true) == pCandidate) - { - aM.SetCon1(true); - } - - if(pEdge->GetConnectedNode(false) == pCandidate) - { - aM.SetCon2(true); - } - - if(SAL_MAX_SIZE == maMarkedObjectList.FindObject(pEdge)) - { - // check if it itself is selected - maEdgesOfMarkedNodes.InsertEntry(aM); - } - else - { - maMarkedEdgesOfMarkedNodes.InsertEntry(aM); - } + maMarkedEdgesOfMarkedNodes.InsertEntry(aM); } } - } - } + return false; + }); } - maEdgesOfMarkedNodes.ForceSort(); maMarkedEdgesOfMarkedNodes.ForceSort(); } diff --git a/svx/source/svdraw/svdouno.cxx b/svx/source/svdraw/svdouno.cxx index 6ea734a7341c..5cf4a5e55709 100644 --- a/svx/source/svdraw/svdouno.cxx +++ b/svx/source/svdraw/svdouno.cxx @@ -334,9 +334,12 @@ void SdrUnoObj::NbcSetLayer( SdrLayerID _nLayer ) o3tl::sorted_vector< SdrView* > aPreviouslyVisible; { - SdrViewIter aIter( this ); - for ( SdrView* pView = aIter.FirstView(); pView; pView = aIter.NextView() ) - aPreviouslyVisible.insert( pView ); + SdrViewIter::ForAllViews(this, + [&aPreviouslyVisible] (SdrView* pView) + { + aPreviouslyVisible.insert( pView ); + return false; + }); } SdrRectObj::NbcSetLayer( _nLayer ); @@ -344,9 +347,8 @@ void SdrUnoObj::NbcSetLayer( SdrLayerID _nLayer ) // collect all views in which our new layer is visible o3tl::sorted_vector< SdrView* > aNewlyVisible; - { - SdrViewIter aIter( this ); - for ( SdrView* pView = aIter.FirstView(); pView; pView = aIter.NextView() ) + SdrViewIter::ForAllViews( this, + [&aPreviouslyVisible, &aNewlyVisible] (SdrView* pView) { if ( aPreviouslyVisible.erase(pView) == 0 ) { @@ -355,8 +357,7 @@ void SdrUnoObj::NbcSetLayer( SdrLayerID _nLayer ) // => remember this view, as our visibility there changed aNewlyVisible.insert( pView ); } - } - } + }); // now aPreviouslyVisible contains all views where we became invisible for (const auto& rpView : aPreviouslyVisible) diff --git a/svx/source/svdraw/svdpntv.cxx b/svx/source/svdraw/svdpntv.cxx index 825129b716b5..ca4fee08b8b4 100644 --- a/svx/source/svdraw/svdpntv.cxx +++ b/svx/source/svdraw/svdpntv.cxx @@ -649,22 +649,23 @@ void SdrPaintView::EndCompleteRedraw(SdrPaintWindow& rPaintWindow, bool bPaintFo { // Look for active text edits in other views showing the same page, // and show them as well. Show only if Page/MasterPage mode is matching. - SdrViewIter aIter(pPageView->GetPage()); bool bRequireMasterPage = pPageView->GetPage() ? pPageView->GetPage()->IsMasterPage() : false; - for (SdrView* pView = aIter.FirstView(); pView; pView = aIter.NextView()) - { - SdrPageView* pCurrentPageView = pView->GetSdrPageView(); - bool bIsCurrentMasterPage = (pCurrentPageView && pCurrentPageView->GetPage()) ? - pCurrentPageView->GetPage()->IsMasterPage() : false; + SdrViewIter::ForAllViews(pPageView->GetPage(), + [this, &bRequireMasterPage, &rPaintWindow] (SdrView* pView) + { + SdrPageView* pCurrentPageView = pView->GetSdrPageView(); + bool bIsCurrentMasterPage = (pCurrentPageView && pCurrentPageView->GetPage()) ? + pCurrentPageView->GetPage()->IsMasterPage() : false; - if (pView == this || bRequireMasterPage != bIsCurrentMasterPage) - continue; + if (pView == this || bRequireMasterPage != bIsCurrentMasterPage) + return false; - if (pView->IsTextEdit() && pView->GetSdrPageView()) - { - pView->TextEditDrawing(rPaintWindow); - } - } + if (pView->IsTextEdit() && pView->GetSdrPageView()) + { + pView->TextEditDrawing(rPaintWindow); + } + return false; + }); } // draw Overlay, also to PreRender device if exists diff --git a/svx/source/svdraw/svdundo.cxx b/svx/source/svdraw/svdundo.cxx index c0ad2f392833..9df18d9eb1f7 100644 --- a/svx/source/svdraw/svdundo.cxx +++ b/svx/source/svdraw/svdundo.cxx @@ -53,11 +53,11 @@ // iterates over all views and unmarks this SdrObject if it is marked static void ImplUnmarkObject( SdrObject* pObj ) { - SdrViewIter aIter( pObj ); - for ( SdrView* pView = aIter.FirstView(); pView; pView = aIter.NextView() ) - { - pView->MarkObj( pObj, pView->GetSdrPageView(), true ); - } + SdrViewIter::ForAllViews( pObj, + [&pObj] (SdrView* pView) + { + pView->MarkObj( pObj, pView->GetSdrPageView(), true ); + }); } SdrUndoAction::SdrUndoAction(SdrModel& rNewMod) diff --git a/svx/source/svdraw/svdviter.cxx b/svx/source/svdraw/svdviter.cxx index baa13909b6c7..65450efb42a5 100644 --- a/svx/source/svdraw/svdviter.cxx +++ b/svx/source/svdraw/svdviter.cxx @@ -25,72 +25,43 @@ #include <svx/svdpagv.hxx> #include <svx/svdsob.hxx> -void SdrViewIter::ImpInitVars() +static bool ImpCheckPageView(const SdrPage* pPage, const SdrObject* pObject, SdrPageView const* pPV) { - mnListenerNum = 0; - mpCurrentView = nullptr; -} - -SdrViewIter::SdrViewIter(const SdrPage* pPage) -{ - mpPage = pPage; - mpModel = pPage ? &pPage->getSdrModelFromSdrPage() : nullptr; - mpObject = nullptr; - ImpInitVars(); -} - -SdrViewIter::SdrViewIter(const SdrObject* pObject) -{ - mpObject = pObject; - mpModel = pObject ? &pObject->getSdrModelFromSdrObject() : nullptr; - mpPage = pObject ? pObject->getSdrPageFromSdrObject() : nullptr; - - if (!mpModel || !mpPage) - { - mpModel = nullptr; - mpPage = nullptr; - } - - ImpInitVars(); -} - -bool SdrViewIter::ImpCheckPageView(SdrPageView const* pPV) const -{ - if (!mpPage) + if (!pPage) return true; - bool bMaster(mpPage->IsMasterPage()); + bool bMaster(pPage->IsMasterPage()); SdrPage* pPg = pPV->GetPage(); - if (pPg == mpPage) + if (pPg == pPage) { - if (mpObject) + if (pObject) { // Looking for an object? First, determine if it visible in // this PageView. - return mpObject->isVisibleOnAnyOfTheseLayers(pPV->GetVisibleLayers()); + return pObject->isVisibleOnAnyOfTheseLayers(pPV->GetVisibleLayers()); } else { return true; } } - else if (bMaster && (!mpObject || !mpObject->IsNotVisibleAsMaster())) + else if (bMaster && (!pObject || !pObject->IsNotVisibleAsMaster())) { if (pPg->TRG_HasMasterPage()) { SdrPage& rMasterPage = pPg->TRG_GetMasterPage(); - if (&rMasterPage == mpPage) + if (&rMasterPage == pPage) { // the page we're looking for is a master page in this PageView - if (mpObject) + if (pObject) { // Looking for an object? First, determine if it visible in // this PageView. SdrLayerIDSet aObjLay = pPV->GetVisibleLayers(); aObjLay &= pPg->TRG_GetMasterPageVisibleLayers(); - if (mpObject->isVisibleOnAnyOfTheseLayers(aObjLay)) + if (pObject->isVisibleOnAnyOfTheseLayers(aObjLay)) { return true; } // else, look at the next master page of this page... @@ -107,53 +78,49 @@ bool SdrViewIter::ImpCheckPageView(SdrPageView const* pPV) const return false; } -SdrView* SdrViewIter::ImpFindView() +namespace SdrViewIter { - if (mpModel) - { - const size_t nLsCnt(mpModel->GetSizeOfVector()); - - while (mnListenerNum < nLsCnt) - { - SfxListener* pLs = mpModel->GetListener(mnListenerNum); - mpCurrentView - = pLs ? (pLs->IsSdrView() ? static_cast<SdrView*>(pLs) : nullptr) : nullptr; - - if (mpCurrentView) - { - if (mpPage) - { - SdrPageView* pPV = mpCurrentView->GetSdrPageView(); +void ForAllViews(const SdrPage* pPage, std::function<void(SdrView*)> f) +{ + if (!pPage) + return; + const SdrModel* pModel = &pPage->getSdrModelFromSdrPage(); - if (pPV && ImpCheckPageView(pPV)) - { - return mpCurrentView; - } - } - else - { - return mpCurrentView; - } - } + pModel->ForAllListeners([&pPage, &f](SfxListener* pLs) { + if (!pLs->IsSdrView()) + return false; + SdrView* pCurrentView = static_cast<SdrView*>(pLs); + SdrPageView* pPV = pCurrentView->GetSdrPageView(); - mnListenerNum++; + if (pPV && ImpCheckPageView(pPage, nullptr, pPV)) + { + f(pCurrentView); } - } - - mpCurrentView = nullptr; - return mpCurrentView; + return false; + }); } -SdrView* SdrViewIter::FirstView() +void ForAllViews(const SdrObject* pObject, std::function<void(SdrView*)> f) { - ImpInitVars(); - return ImpFindView(); + if (!pObject) + return; + const SdrModel* pModel = &pObject->getSdrModelFromSdrObject(); + const SdrPage* pPage = pObject->getSdrPageFromSdrObject(); + if (!pPage) + return; + + pModel->ForAllListeners([&pPage, &pObject, &f](SfxListener* pLs) { + if (!pLs->IsSdrView()) + return false; + SdrView* pCurrentView = static_cast<SdrView*>(pLs); + SdrPageView* pPV = pCurrentView->GetSdrPageView(); + + if (pPV && ImpCheckPageView(pPage, pObject, pPV)) + { + f(pCurrentView); + } + return false; + }); } - -SdrView* SdrViewIter::NextView() -{ - mnListenerNum++; - return ImpFindView(); } - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/unodraw/unoshap2.cxx b/svx/source/unodraw/unoshap2.cxx index b6dd018e6474..8ae6879ef337 100644 --- a/svx/source/unodraw/unoshap2.cxx +++ b/svx/source/unodraw/unoshap2.cxx @@ -260,15 +260,14 @@ void SAL_CALL SvxShapeGroup::remove( const uno::Reference< drawing::XShape >& xS // #i29181# // If the SdrObject which is about to be deleted is in any selection, // deselect it first. - SdrViewIter aIter( pSdrShape ); - - for ( SdrView* pView = aIter.FirstView(); pView; pView = aIter.NextView() ) - { - if(SAL_MAX_SIZE != pView->TryToFindMarkedObject(pSdrShape)) + SdrViewIter::ForAllViews( pSdrShape, + [&pSdrShape] (SdrView* pView) { - pView->MarkObj(pSdrShape, pView->GetSdrPageView(), true); - } - } + if(SAL_MAX_SIZE != pView->TryToFindMarkedObject(pSdrShape)) + { + pView->MarkObj(pSdrShape, pView->GetSdrPageView(), true); + } + }); rList.NbcRemoveObject( nObjNum ); } diff --git a/sw/source/core/draw/dcontact.cxx b/sw/source/core/draw/dcontact.cxx index 456241b660c0..d1de10fa0a9e 100644 --- a/sw/source/core/draw/dcontact.cxx +++ b/sw/source/core/draw/dcontact.cxx @@ -1702,12 +1702,11 @@ void SwDrawContact::DisconnectFromLayout( bool _bMoveMasterToInvisibleLayer ) if ( _bMoveMasterToInvisibleLayer && GetMaster() && GetMaster()->IsInserted() ) { - SdrViewIter aIter( GetMaster() ); - for( SdrView* pView = aIter.FirstView(); pView; - pView = aIter.NextView() ) - { - pView->MarkObj( GetMaster(), pView->GetSdrPageView(), true ); - } + SdrViewIter::ForAllViews( GetMaster(), + [this] (SdrView* pView) + { + pView->MarkObj( GetMaster(), pView->GetSdrPageView(), true ); + }); // Instead of removing 'master' object from drawing page, move the // 'master' drawing object into the corresponding invisible layer. diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx index 0f0faa227351..75428e103eab 100644 --- a/sw/source/core/unocore/unostyle.cxx +++ b/sw/source/core/unocore/unostyle.cxx @@ -1226,15 +1226,19 @@ uno::Any SAL_CALL XStyleFamily::getPropertyValue( const OUString& sPropertyName SwXStyle* XStyleFamily::FindStyle(std::u16string_view rStyleName) const { - const size_t nLCount = m_pBasePool->GetSizeOfVector(); - for(size_t i = 0; i < nLCount; ++i) - { - SfxListener* pListener = m_pBasePool->GetListener(i); - SwXStyle* pTempStyle = dynamic_cast<SwXStyle*>(pListener); - if(pTempStyle && pTempStyle->GetFamily() == m_rEntry.family() && pTempStyle->GetStyleName() == rStyleName) - return pTempStyle; - } - return nullptr; + SwXStyle* pFoundStyle = nullptr; + m_pBasePool->ForAllListeners( + [this, &pFoundStyle, &rStyleName] (SfxListener* pListener) + { + SwXStyle* pTempStyle = dynamic_cast<SwXStyle*>(pListener); + if(pTempStyle && pTempStyle->GetFamily() == m_rEntry.family() && pTempStyle->GetStyleName() == rStyleName) + { + pFoundStyle = pTempStyle; + return true; // break + } + return false; + }); + return pFoundStyle; } static SwGetPoolIdFromName lcl_GetSwEnumFromSfxEnum(SfxStyleFamily eFamily) |