sd/source/core/drawdoc2.cxx             |    6 ++----
 sd/source/core/drawdoc3.cxx             |   18 +++++++++---------
 sd/source/core/drawdoc4.cxx             |   12 ++++--------
 sd/source/core/sdpage.cxx               |   11 +++++------
 sd/source/core/sdpage2.cxx              |   13 ++++---------
 sd/source/filter/html/htmlex.cxx        |   19 ++++++++-----------
 sd/source/filter/xml/sdtransform.cxx    |    9 ++-------
 sd/source/ui/app/sdxfer.cxx             |    5 +----
 sd/source/ui/dlg/animobjs.cxx           |    3 +--
 sd/source/ui/docshell/docshel3.cxx      |    8 ++------
 sd/source/ui/tools/GraphicSizeCheck.cxx |   10 +++-------
 sd/source/ui/uitest/uiobject.cxx        |   18 +++++-------------
 sd/source/ui/unoidl/unopage.cxx         |    4 +---
 sd/source/ui/view/DocumentRenderer.cxx  |   16 ++++++++--------
 sd/source/ui/view/drawview.cxx          |   16 ++++------------
 sd/source/ui/view/drviews2.cxx          |   10 ++++------
 sd/source/ui/view/outlview.cxx          |   12 ++++--------
 slideshow/source/engine/box2dtools.cxx  |    6 ++----
 18 files changed, 69 insertions(+), 127 deletions(-)

New commits:
commit f3e010829ab9d6b0b0ef48b67661774dd19f6de0
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Wed Oct 18 13:59:22 2023 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Thu Oct 19 08:09:38 2023 +0200

    use more SdrObjList::begin/end in sd
    
    Change-Id: If39b6c561525bbf66d34edfbff0f1a3ef4531f85
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158129
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sd/source/core/drawdoc2.cxx b/sd/source/core/drawdoc2.cxx
index d591113fcca9..de82a8b95306 100644
--- a/sd/source/core/drawdoc2.cxx
+++ b/sd/source/core/drawdoc2.cxx
@@ -244,10 +244,8 @@ void SdDrawDocument::UpdatePageObjectsInNotes(sal_uInt16 
nStartPos)
         // number
         if (pPage && pPage->GetPageKind() == PageKind::Notes)
         {
-            const size_t nObjCount = pPage->GetObjCount();
-            for (size_t nObj = 0; nObj < nObjCount; ++nObj)
+            for (const rtl::Reference<SdrObject>& pObj : *pPage)
             {
-                SdrObject* pObj = pPage->GetObj(nObj);
                 if (pObj->GetObjIdentifier() == SdrObjKind::Page &&
                     pObj->GetObjInventor() == SdrInventor::Default)
                 {
@@ -257,7 +255,7 @@ void SdDrawDocument::UpdatePageObjectsInNotes(sal_uInt16 
nStartPos)
                     SAL_WARN_IF(nPage <= 1, "sd", "Page object must not be a 
handout.");
 
                     if (nStartPos > 0 && nPage > 1)
-                        
static_cast<SdrPageObj*>(pObj)->SetReferencedPage(GetPage(nPage - 1));
+                        
static_cast<SdrPageObj*>(pObj.get())->SetReferencedPage(GetPage(nPage - 1));
                 }
             }
         }
diff --git a/sd/source/core/drawdoc3.cxx b/sd/source/core/drawdoc3.cxx
index 357858f46222..b3c6e0595c8a 100644
--- a/sd/source/core/drawdoc3.cxx
+++ b/sd/source/core/drawdoc3.cxx
@@ -927,17 +927,17 @@ bool SdDrawDocument::InsertBookmarkAsPage(
         {
             for(sal_uInt32 p = nInsertPos; p < sal_uInt32(nInsertPos) + 
sal_uInt32(nBMSdPageCount); p++)
             {
-                SdPage *pPg = static_cast<SdPage *>( GetPage(p) );
-                for(size_t i = 0; pPg && (i < pPg->GetObjCount()); ++i)
-                {
-                    if(pPg->GetObj(i)->GetStyleSheet())
+                if (SdPage *pPg = static_cast<SdPage *>( GetPage(p) ))
+                    for (const rtl::Reference<SdrObject>& pObj : *pPg)
                     {
-                        OUString aStyleName = 
pPg->GetObj(i)->GetStyleSheet()->GetName();
-                        SfxStyleSheet *pSheet = 
lcl_findStyle(aNewGraphicStyles, Concat2View(aStyleName + aRenameStr));
-                        if(pSheet != nullptr)
-                            pPg->GetObj(i)->SetStyleSheet(pSheet, true);
+                        if(pObj->GetStyleSheet())
+                        {
+                            OUString aStyleName = 
pObj->GetStyleSheet()->GetName();
+                            SfxStyleSheet *pSheet = 
lcl_findStyle(aNewGraphicStyles, Concat2View(aStyleName + aRenameStr));
+                            if(pSheet != nullptr)
+                                pObj->SetStyleSheet(pSheet, true);
+                        }
                     }
-                }
             }
         }
         catch(...)
diff --git a/sd/source/core/drawdoc4.cxx b/sd/source/core/drawdoc4.cxx
index 91c4dc600703..577859d957bc 100644
--- a/sd/source/core/drawdoc4.cxx
+++ b/sd/source/core/drawdoc4.cxx
@@ -1067,10 +1067,8 @@ void SdDrawDocument::RenameLayoutTemplate(const 
OUString& rOldLayoutName, const
         {
             pPage->SetLayoutName(aPageLayoutName);
 
-            for (size_t nObj = 0; nObj < pPage->GetObjCount(); ++nObj)
+            for (const rtl::Reference<SdrObject>& pObj : *pPage)
             {
-                SdrObject* pObj = pPage->GetObj(nObj);
-
                 if (pObj->GetObjInventor() == SdrInventor::Default)
                 {
                     switch( pObj->GetObjIdentifier() )
@@ -1079,7 +1077,7 @@ void SdDrawDocument::RenameLayoutTemplate(const OUString& 
rOldLayoutName, const
                         case SdrObjKind::OutlineText:
                         case SdrObjKind::TitleText:
                         {
-                            OutlinerParaObject* pOPO = 
static_cast<SdrTextObj*>(pObj)->GetOutlinerParaObject();
+                            OutlinerParaObject* pOPO = 
static_cast<SdrTextObj*>(pObj.get())->GetOutlinerParaObject();
 
                             if (pOPO)
                             {
@@ -1109,10 +1107,8 @@ void SdDrawDocument::RenameLayoutTemplate(const 
OUString& rOldLayoutName, const
             pPage->SetLayoutName(aPageLayoutName);
             pPage->SetName(rNewName);
 
-            for (size_t nObj = 0; nObj < pPage->GetObjCount(); ++nObj)
+            for (const rtl::Reference<SdrObject>& pObj : *pPage)
             {
-                SdrObject* pObj = pPage->GetObj(nObj);
-
                 if (pObj->GetObjInventor() == SdrInventor::Default)
                 {
                     switch(pObj->GetObjIdentifier())
@@ -1121,7 +1117,7 @@ void SdDrawDocument::RenameLayoutTemplate(const OUString& 
rOldLayoutName, const
                         case SdrObjKind::OutlineText:
                         case SdrObjKind::TitleText:
                         {
-                            OutlinerParaObject* pOPO = 
static_cast<SdrTextObj*>(pObj)->GetOutlinerParaObject();
+                            OutlinerParaObject* pOPO = 
static_cast<SdrTextObj*>(pObj.get())->GetOutlinerParaObject();
 
                             if (pOPO)
                             {
diff --git a/sd/source/core/sdpage.cxx b/sd/source/core/sdpage.cxx
index 230b6b5aef79..3d6c20f09984 100644
--- a/sd/source/core/sdpage.cxx
+++ b/sd/source/core/sdpage.cxx
@@ -1809,7 +1809,6 @@ void SdPage::ScaleObjects(const Size& rNewPageSize, const 
::tools::Rectangle& rN
     sd::ScopeLockGuard aGuard( maLockAutoLayoutArrangement );
 
     mbScaleObjects = bScaleAllObj;
-    SdrObject* pObj = nullptr;
     Point aRefPnt(0, 0);
     Size aNewPageSize(rNewPageSize);
     sal_Int32 nLeft  = rNewBorderRect.Left();
@@ -1859,16 +1858,16 @@ void SdPage::ScaleObjects(const Size& rNewPageSize, 
const ::tools::Rectangle& rN
     Fraction aFractX(aNewPageSize.Width(), nOldWidth);
     Fraction aFractY(aNewPageSize.Height(), nOldHeight);
 
-    const size_t nObjCnt = (mbScaleObjects ? GetObjCount() : 0);
+    if (!mbScaleObjects)
+        return;
 
-    for (size_t nObj = 0; nObj < nObjCnt; ++nObj)
+    for (const rtl::Reference<SdrObject>& pObj : *this)
     {
         bool bIsPresObjOnMaster = false;
 
         // all Objects
-        pObj = GetObj(nObj);
 
-        if (mbMaster && IsPresObj(pObj))
+        if (mbMaster && IsPresObj(pObj.get()))
         {
             // There is a presentation object on the master page
             bIsPresObjOnMaster = true;
@@ -2012,7 +2011,7 @@ void SdPage::ScaleObjects(const Size& rNewPageSize, const 
::tools::Rectangle& rN
                     }
                     else if ( eObjKind != SdrObjKind::TitleText   &&
                               eObjKind != SdrObjKind::OutlineText &&
-                              DynCastSdrTextObj( pObj ) !=  nullptr       &&
+                              DynCastSdrTextObj( pObj.get() ) !=  nullptr      
 &&
                               pObj->GetOutlinerParaObject() )
                     {
                         /******************************************************
diff --git a/sd/source/core/sdpage2.cxx b/sd/source/core/sdpage2.cxx
index 6b2b73cda11c..49c4133f3bb3 100644
--- a/sd/source/core/sdpage2.cxx
+++ b/sd/source/core/sdpage2.cxx
@@ -139,12 +139,8 @@ void SdPage::SetPresentationLayout(std::u16string_view 
rLayoutName,
     std::vector<StyleReplaceData> aReplList;
     bool bListsFilled = false;
 
-    const size_t nObjCount = GetObjCount();
-
-    for (size_t nObj = 0; nObj < nObjCount; ++nObj)
+    for (const rtl::Reference<SdrObject>& pObj : *this)
     {
-        auto pObj = GetObj(nObj);
-
         if (pObj->GetObjInventor() == SdrInventor::Default &&
             pObj->GetObjIdentifier() == SdrObjKind::OutlineText)
         {
@@ -233,7 +229,7 @@ void SdPage::SetPresentationLayout(std::u16string_view 
rLayoutName,
         }
         else
         {
-            SfxStyleSheet* pSheet = 
GetStyleSheetForPresObj(GetPresObjKind(pObj));
+            SfxStyleSheet* pSheet = 
GetStyleSheetForPresObj(GetPresObjKind(pObj.get()));
 
             if (pSheet)
                 pObj->SetStyleSheet(pSheet, true);
@@ -610,10 +606,9 @@ void SdPage::removeAnnotation( const Reference< 
XAnnotation >& xAnnotation )
 
 void SdPage::getGraphicsForPrefetch(std::vector<Graphic*>& graphics) const
 {
-    for( size_t i = 0; i < GetObjCount(); ++i)
+    for (const rtl::Reference<SdrObject>& obj : *this)
     {
-        SdrObject* obj = GetObj(i);
-        if( SdrGrafObj* grafObj = dynamic_cast<SdrGrafObj*>(obj))
+        if( SdrGrafObj* grafObj = dynamic_cast<SdrGrafObj*>(obj.get()))
             if(!grafObj->GetGraphic().isAvailable())
                 graphics.push_back( 
const_cast<Graphic*>(&grafObj->GetGraphic()));
         if( const Graphic* fillGraphic = obj->getFillGraphic())
diff --git a/sd/source/filter/html/htmlex.cxx b/sd/source/filter/html/htmlex.cxx
index f1f9682f542d..fc3d00d14c66 100644
--- a/sd/source/filter/html/htmlex.cxx
+++ b/sd/source/filter/html/htmlex.cxx
@@ -534,16 +534,14 @@ void WriteObjectGroup(OUStringBuffer& aStr, SdrObjGroup 
const * pObjectGroup, Sd
 // get SdrTextObject with layout text of this page
 SdrTextObj* GetLayoutTextObject(SdrPage const * pPage)
 {
-    const size_t nObjectCount = pPage->GetObjCount();
     SdrTextObj*     pResult      = nullptr;
 
-    for (size_t nObject = 0; nObject < nObjectCount; ++nObject)
+    for (const rtl::Reference<SdrObject>& pObject : *pPage)
     {
-        SdrObject* pObject = pPage->GetObj(nObject);
         if (pObject->GetObjInventor() == SdrInventor::Default &&
             pObject->GetObjIdentifier() == SdrObjKind::OutlineText)
         {
-            pResult = static_cast<SdrTextObj*>(pObject);
+            pResult = static_cast<SdrTextObj*>(pObject.get());
             break;
         }
     }
@@ -579,10 +577,9 @@ OUString CreateTextForPage(SdrOutliner* pOutliner, SdPage 
const * pPage,
 {
     OUStringBuffer aStr;
 
-    for (size_t i = 0; i <pPage->GetObjCount(); ++i )
+    for (const rtl::Reference<SdrObject>& pObject : *pPage)
     {
-        SdrObject* pObject = pPage->GetObj(i);
-        PresObjKind eKind = pPage->GetPresObjKind(pObject);
+        PresObjKind eKind = pPage->GetPresObjKind(pObject.get());
 
         switch (eKind)
         {
@@ -590,12 +587,12 @@ OUString CreateTextForPage(SdrOutliner* pOutliner, SdPage 
const * pPage,
             {
                 if (pObject->GetObjIdentifier() == SdrObjKind::Group)
                 {
-                    SdrObjGroup* pObjectGroup = 
static_cast<SdrObjGroup*>(pObject);
+                    SdrObjGroup* pObjectGroup = 
static_cast<SdrObjGroup*>(pObject.get());
                     WriteObjectGroup(aStr, pObjectGroup, pOutliner, false);
                 }
                 else if (pObject->GetObjIdentifier() == SdrObjKind::Table)
                 {
-                    SdrTableObj* pTableObject = 
static_cast<SdrTableObj*>(pObject);
+                    SdrTableObj* pTableObject = 
static_cast<SdrTableObj*>(pObject.get());
                     WriteTable(aStr, pTableObject, pOutliner);
                 }
                 else
@@ -610,7 +607,7 @@ OUString CreateTextForPage(SdrOutliner* pOutliner, SdPage 
const * pPage,
 
             case PresObjKind::Table:
             {
-                SdrTableObj* pTableObject = static_cast<SdrTableObj*>(pObject);
+                SdrTableObj* pTableObject = 
static_cast<SdrTableObj*>(pObject.get());
                 WriteTable(aStr, pTableObject, pOutliner);
             }
             break;
@@ -618,7 +615,7 @@ OUString CreateTextForPage(SdrOutliner* pOutliner, SdPage 
const * pPage,
             case PresObjKind::Text:
             case PresObjKind::Outline:
             {
-                SdrTextObj* pTextObject = static_cast<SdrTextObj*>(pObject);
+                SdrTextObj* pTextObject = 
static_cast<SdrTextObj*>(pObject.get());
                 if (pTextObject->IsEmptyPresObj())
                     continue;
                 WriteOutlinerParagraph(aStr, pOutliner, 
pTextObject->GetOutlinerParaObject(), bHeadLine);
diff --git a/sd/source/filter/xml/sdtransform.cxx 
b/sd/source/filter/xml/sdtransform.cxx
index 2b4db59efa5d..7dd6c82e4761 100644
--- a/sd/source/filter/xml/sdtransform.cxx
+++ b/sd/source/filter/xml/sdtransform.cxx
@@ -154,13 +154,8 @@ void SdTransformOOo2xDocument::transformStyle( 
SfxStyleSheetBase& rSheet )
 
 void SdTransformOOo2xDocument::transformShapes( SdrObjList const & rShapes )
 {
-    const size_t nShapeCount = rShapes.GetObjCount();
-    for( size_t nShape = 0; nShape < nShapeCount; ++nShape )
-    {
-        SdrObject* pObj = rShapes.GetObj( nShape );
-        if( pObj )
-            transformShape( *pObj );
-    }
+    for (const rtl::Reference<SdrObject>& pObj : rShapes)
+        transformShape( *pObj );
 }
 
 void SdTransformOOo2xDocument::transformShape( SdrObject& rObj )
diff --git a/sd/source/ui/app/sdxfer.cxx b/sd/source/ui/app/sdxfer.cxx
index 11fc9017f64d..74728dd0e64a 100644
--- a/sd/source/ui/app/sdxfer.cxx
+++ b/sd/source/ui/app/sdxfer.cxx
@@ -316,11 +316,8 @@ void SdTransferable::CreateData()
         Point   aOrigin( maVisArea.TopLeft() );
         Size    aVector( -aOrigin.X(), -aOrigin.Y() );
 
-        for( size_t nObj = 0, nObjCount = pPage->GetObjCount(); nObj < 
nObjCount; ++nObj )
-        {
-            SdrObject* pObj = pPage->GetObj( nObj );
+        for (const rtl::Reference<SdrObject>& pObj : *pPage)
             pObj->NbcMove( aVector );
-        }
     }
     else
         maVisArea.SetSize( pPage->GetSize() );
diff --git a/sd/source/ui/dlg/animobjs.cxx b/sd/source/ui/dlg/animobjs.cxx
index 0174855e1825..1ab24e241c5a 100644
--- a/sd/source/ui/dlg/animobjs.cxx
+++ b/sd/source/ui/dlg/animobjs.cxx
@@ -759,9 +759,8 @@ void AnimationWindow::AddObj (::sd::View& rView )
             // several objects
             SdrObjList* pObjList = 
static_cast<SdrObjGroup*>(pObject)->GetSubList();
 
-            for( size_t nObject = 0; nObject < pObjList->GetObjCount(); 
++nObject )
+            for (const rtl::Reference<SdrObject>& pSnapShot : *pObjList)
             {
-                SdrObject* pSnapShot(pObjList->GetObj(nObject));
                 BitmapEx 
aBitmapEx(SdrExchangeView::GetObjGraphic(*pSnapShot).GetBitmapEx());
                 size_t nIndex = m_nCurrentFrame + 1;
                 m_FrameList.insert(
diff --git a/sd/source/ui/docshell/docshel3.cxx 
b/sd/source/ui/docshell/docshel3.cxx
index 19ae6796841c..f286cd3fc189 100644
--- a/sd/source/ui/docshell/docshel3.cxx
+++ b/sd/source/ui/docshell/docshel3.cxx
@@ -118,13 +118,9 @@ static void lcl_setLanguage( const SdDrawDocument *pDoc, 
std::u16string_view rLa
     for( sal_uInt16 nPage = 0; nPage < nPageCount; nPage++ )
     {
         const SdrPage *pPage = pDoc->GetPage( nPage );
-        const size_t nObjCount = pPage->GetObjCount();
-        for( size_t nObj = 0; nObj < nObjCount; ++nObj )
-        {
-            SdrObject *pObj = pPage->GetObj( nObj );
+        for (const rtl::Reference<SdrObject>& pObj : *pPage)
             if (pObj->GetObjIdentifier() != SdrObjKind::Page)
-                lcl_setLanguageForObj( pObj, nLang, bLanguageNone );
-        }
+                lcl_setLanguageForObj( pObj.get(), nLang, bLanguageNone );
     }
 }
 
diff --git a/sd/source/ui/tools/GraphicSizeCheck.cxx 
b/sd/source/ui/tools/GraphicSizeCheck.cxx
index 492a2d70b23e..68bd33a3e194 100644
--- a/sd/source/ui/tools/GraphicSizeCheck.cxx
+++ b/sd/source/ui/tools/GraphicSizeCheck.cxx
@@ -62,15 +62,11 @@ public:
             SdrPage* pPage = m_pDocument->GetPage(nPage);
             if (pPage)
             {
-                for (size_t nObject = 0; nObject < pPage->GetObjCount(); 
++nObject)
+                for (const rtl::Reference<SdrObject>& pObject : *pPage)
                 {
-                    SdrObject* pObject = pPage->GetObj(nObject);
-                    if (pObject)
+                    for (auto& pNodeHandler : m_pNodeHandler)
                     {
-                        for (auto& pNodeHandler : m_pNodeHandler)
-                        {
-                            pNodeHandler->handleSdrObject(pObject);
-                        }
+                        pNodeHandler->handleSdrObject(pObject.get());
                     }
                 }
             }
diff --git a/sd/source/ui/uitest/uiobject.cxx b/sd/source/ui/uitest/uiobject.cxx
index 403aa8555ca1..00884fc90d6f 100644
--- a/sd/source/ui/uitest/uiobject.cxx
+++ b/sd/source/ui/uitest/uiobject.cxx
@@ -58,13 +58,9 @@ SdrObject* getObject(const VclPtr<sd::Window>& xWindow, 
std::u16string_view rNam
     if (!pPage)
         return nullptr;
 
-    size_t nObjs = pPage->GetObjCount();
-    for (size_t i = 0; i < nObjs; ++i)
-    {
-        SdrObject* pObj = pPage->GetObj(i);
-        if (rName == getObjectName(pObj))
-            return pObj;
-    }
+    for (const rtl::Reference<SdrObject>& pObj : *pPage)
+        if (rName == getObjectName(pObj.get()))
+            return pObj.get();
 
     return nullptr;
 }
@@ -162,12 +158,8 @@ std::set<OUString> ImpressWindowUIObject::get_children() 
const
     if (!pPage)
         return aRet;
 
-    size_t nObjs = pPage->GetObjCount();
-    for (size_t i = 0; i < nObjs; ++i)
-    {
-        SdrObject* pObject = pPage->GetObj(i);
-        aRet.insert(getObjectName(pObject));
-    }
+    for (const rtl::Reference<SdrObject>& pObject : *pPage)
+        aRet.insert(getObjectName(pObject.get()));
 
     return aRet;
 }
diff --git a/sd/source/ui/unoidl/unopage.cxx b/sd/source/ui/unoidl/unopage.cxx
index d39b0ea596b1..9abea2e5b801 100644
--- a/sd/source/ui/unoidl/unopage.cxx
+++ b/sd/source/ui/unoidl/unopage.cxx
@@ -2595,10 +2595,8 @@ SdNavigationOrderAccess::SdNavigationOrderAccess( 
SdrPage const * pPage )
 {
     if( pPage )
     {
-        const size_t nCount = pPage->GetObjCount();
-        for( size_t nIndex = 0; nIndex < nCount; ++nIndex )
+        for (const rtl::Reference<SdrObject>& pObj : *pPage)
         {
-            SdrObject* pObj = pPage->GetObj( nIndex );
             sal_uInt32 nNavPos = pObj->GetNavigationPosition();
             DBG_ASSERT( !maShapes[nNavPos].is(), 
"sd::SdNavigationOrderAccess::SdNavigationOrderAccess(), duplicate navigation 
positions from core!" );
             maShapes[nNavPos].set( pObj->getUnoShape(), UNO_QUERY );
diff --git a/sd/source/ui/view/DocumentRenderer.cxx 
b/sd/source/ui/view/DocumentRenderer.cxx
index fb7cec583aff..8a797c066479 100644
--- a/sd/source/ui/view/DocumentRenderer.cxx
+++ b/sd/source/ui/view/DocumentRenderer.cxx
@@ -1634,15 +1634,15 @@ private:
                     continue;
 
                 SdrTextObj* pTextObj = nullptr;
-                size_t nObj (0);
 
-                while (pTextObj==nullptr && nObj < pPage->GetObjCount())
+                for (const rtl::Reference<SdrObject>& pObj : *pPage)
                 {
-                    SdrObject* pObj = pPage->GetObj(nObj++);
                     if (pObj->GetObjInventor() == SdrInventor::Default
                         && pObj->GetObjIdentifier() == SdrObjKind::TitleText)
                     {
-                        pTextObj = DynCastSdrTextObj(pObj);
+                        pTextObj = DynCastSdrTextObj(pObj.get());
+                        if (pTextObj)
+                            break;
                     }
                 }
 
@@ -1658,15 +1658,15 @@ private:
                     pOutliner->Insert(OUString());
 
                 pTextObj = nullptr;
-                nObj = 0;
 
-                while (pTextObj==nullptr && nObj<pPage->GetObjCount())
+                for (const rtl::Reference<SdrObject>& pObj : *pPage)
                 {
-                    SdrObject* pObj = pPage->GetObj(nObj++);
                     if (pObj->GetObjInventor() == SdrInventor::Default
                         && pObj->GetObjIdentifier() == SdrObjKind::OutlineText)
                     {
-                        pTextObj = DynCastSdrTextObj(pObj);
+                        pTextObj = DynCastSdrTextObj(pObj.get());
+                        if (pTextObj)
+                            break;
                     }
                 }
 
diff --git a/sd/source/ui/view/drawview.cxx b/sd/source/ui/view/drawview.cxx
index bd454bec194b..69555bb7419d 100644
--- a/sd/source/ui/view/drawview.cxx
+++ b/sd/source/ui/view/drawview.cxx
@@ -117,24 +117,16 @@ bool DrawView::SetAttributes(const SfxItemSet& rSet,
         SfxStyleSheetBasePool* pStShPool = mrDoc.GetStyleSheetPool();
         SdPage& rPage = *mpDrawViewShell->getCurrentPage();
         SdrPage& rMasterPage = rPage.TRG_GetMasterPage();
-        size_t nObjCount = rMasterPage.GetObjCount();
-        for (size_t nObj = 0; nObj < nObjCount; ++nObj)
-        {
-            SdrObject* pObject = rMasterPage.GetObj(nObj);
-            SetMasterAttributes(pObject, rPage, rSet, pStShPool, bOk, bMaster, 
bSlide);
-        }
+        for (const rtl::Reference<SdrObject>& pObject : rMasterPage)
+            SetMasterAttributes(pObject.get(), rPage, rSet, pStShPool, bOk, 
bMaster, bSlide);
         return bOk;
     }
     if (mpDrawViewShell && bSlide)
     {
         SfxStyleSheetBasePool* pStShPool = mrDoc.GetStyleSheetPool();
         SdPage& rPage = *mpDrawViewShell->getCurrentPage();
-        size_t nObjCount = rPage.GetObjCount();
-        for (size_t nObj = 0; nObj < nObjCount; ++nObj)
-        {
-            SdrObject* pObject = rPage.GetObj(nObj);
-            SetMasterAttributes(pObject, rPage, rSet, pStShPool, bOk, bMaster, 
bSlide);
-        }
+        for (const rtl::Reference<SdrObject>& pObject : rPage)
+            SetMasterAttributes(pObject.get(), rPage, rSet, pStShPool, bOk, 
bMaster, bSlide);
         return bOk;
     }
 
diff --git a/sd/source/ui/view/drviews2.cxx b/sd/source/ui/view/drviews2.cxx
index 4dc14204b53d..d7fefcecae72 100644
--- a/sd/source/ui/view/drviews2.cxx
+++ b/sd/source/ui/view/drviews2.cxx
@@ -338,10 +338,9 @@ public:
         for (sal_uInt16 nPageIndex = 0; nPageIndex < nCount; ++nPageIndex)
         {
             SdPage* pMasterPage = 
m_rDrawViewShell.GetDoc()->GetMasterSdPage(nPageIndex, PageKind::Standard);
-            for (size_t nObject = 0; nObject < pMasterPage->GetObjCount(); 
++nObject)
+            for (const rtl::Reference<SdrObject>& pObject : *pMasterPage)
             {
-                SdrObject* pObject = pMasterPage->GetObj(nObject);
-                SdrRectObj* pRectObject = dynamic_cast<SdrRectObj*>(pObject);
+                SdrRectObj* pRectObject = 
dynamic_cast<SdrRectObj*>(pObject.get());
                 if (pRectObject && pRectObject->GetTextKind() == 
SdrObjKind::Text)
                 {
                     OutlinerParaObject* pOutlinerParagraphObject = 
pRectObject->GetOutlinerParaObject();
@@ -377,10 +376,9 @@ private:
         for (sal_uInt16 nPageIndex = 0; nPageIndex < nCount; ++nPageIndex)
         {
             SdPage* pMasterPage = 
m_rDrawViewShell.GetDoc()->GetMasterSdPage(nPageIndex, PageKind::Standard);
-            for (size_t nObject = 0; nObject < pMasterPage->GetObjCount(); 
++nObject)
+            for (const rtl::Reference<SdrObject>& pObject : *pMasterPage)
             {
-                SdrObject* pObject = pMasterPage->GetObj(nObject);
-                SdrRectObj* pRectObject = dynamic_cast<SdrRectObj*>(pObject);
+                SdrRectObj* pRectObject = 
dynamic_cast<SdrRectObj*>(pObject.get());
                 if (pRectObject && pRectObject->GetTextKind() == 
SdrObjKind::Text)
                 {
                     OutlinerParaObject* pOutlinerParagraphObject = 
pRectObject->GetOutlinerParaObject();
diff --git a/sd/source/ui/view/outlview.cxx b/sd/source/ui/view/outlview.cxx
index 8ce0a5dcb874..ab994e235813 100644
--- a/sd/source/ui/view/outlview.cxx
+++ b/sd/source/ui/view/outlview.cxx
@@ -857,16 +857,14 @@ IMPL_LINK( OutlineView, EndMovingHdl, ::Outliner *, 
pOutliner, void )
  */
 SdrTextObj* OutlineView::GetTitleTextObject(SdrPage const * pPage)
 {
-    const size_t nObjectCount = pPage->GetObjCount();
     SdrTextObj*     pResult      = nullptr;
 
-    for (size_t nObject = 0; nObject < nObjectCount; ++nObject)
+    for (const rtl::Reference<SdrObject>& pObject : *pPage)
     {
-        SdrObject* pObject = pPage->GetObj(nObject);
         if (pObject->GetObjInventor() == SdrInventor::Default &&
             pObject->GetObjIdentifier() == SdrObjKind::TitleText)
         {
-            pResult = static_cast<SdrTextObj*>(pObject);
+            pResult = static_cast<SdrTextObj*>(pObject.get());
             break;
         }
     }
@@ -878,16 +876,14 @@ SdrTextObj* OutlineView::GetTitleTextObject(SdrPage const 
* pPage)
  */
 SdrTextObj* OutlineView::GetOutlineTextObject(SdrPage const * pPage)
 {
-    const size_t nObjectCount = pPage->GetObjCount();
     SdrTextObj*     pResult      = nullptr;
 
-    for (size_t nObject = 0; nObject < nObjectCount; ++nObject)
+    for (const rtl::Reference<SdrObject>& pObject : *pPage)
     {
-        SdrObject* pObject = pPage->GetObj(nObject);
         if (pObject->GetObjInventor() == SdrInventor::Default &&
             pObject->GetObjIdentifier() == SdrObjKind::OutlineText)
         {
-            pResult = static_cast<SdrTextObj*>(pObject);
+            pResult = static_cast<SdrTextObj*>(pObject.get());
             break;
         }
     }
diff --git a/slideshow/source/engine/box2dtools.cxx 
b/slideshow/source/engine/box2dtools.cxx
index 4e45bb47f543..97e172a4eb4e 100644
--- a/slideshow/source/engine/box2dtools.cxx
+++ b/slideshow/source/engine/box2dtools.cxx
@@ -411,13 +411,11 @@ void box2DWorld::initiateAllShapesAsStaticBodies(
             {
                 // if it is a group object iterate over its children and flag 
them
                 SdrObjList* aObjList = pTemp->GetSubList();
-                const size_t nObjCount(aObjList->GetObjCount());
 
-                for (size_t nObjIndex = 0; nObjIndex < nObjCount; ++nObjIndex)
+                for (const rtl::Reference<SdrObject>& pGroupMember : *aObjList)
                 {
-                    SdrObject* pGroupMember(aObjList->GetObj(nObjIndex));
                     aXShapeBelongsToAGroup.insert(
-                        std::make_pair(GetXShapeForSdrObject(pGroupMember), 
true));
+                        
std::make_pair(GetXShapeForSdrObject(pGroupMember.get()), true));
                 }
             }
         }

Reply via email to