Date: prev next · Thread: first prev next last
2012 Archives by date, by thread · List index


Hi

Attached patch converts ScCustomShow to use std::vector.

Not exactly sure how these kinds of classes that extend tools/List should be converted. I exposed an accessor method PagesVector(), but I'm happy to modify the patch if there is a better idiom.

Code is contributed under MPL+/LGPL+/GPL+

Regards, Noel Grandin

Disclaimer: http://www.peralex.com/disclaimer.html


diff --git a/sd/inc/cusshow.hxx b/sd/inc/cusshow.hxx
index 1f981e9..eeadeb8 100644
--- a/sd/inc/cusshow.hxx
+++ b/sd/inc/cusshow.hxx
@@ -29,7 +29,7 @@
 #ifndef _SD_CUSSHOW_HXX
 #define _SD_CUSSHOW_HXX
 
-#include <tools/list.hxx>
+#include <vector>
 #include <tools/stream.hxx>
 #include <tools/string.hxx>
 #include <cppuhelper/weakref.hxx>
@@ -38,14 +38,17 @@
 class SdDrawDocument;
 class SdPage;
 
+typedef ::std::vector<const SdPage*> SdPageVec;
+
 /*************************************************************************
 |*
 |* CustomShow
 |*
 \************************************************************************/
-class SD_DLLPUBLIC SdCustomShow : public List
+class SD_DLLPUBLIC SdCustomShow
 {
 private:
+    SdPageVec       maPages;
     String          aName;
     SdDrawDocument* pDoc;
 
@@ -65,14 +68,14 @@ public:
     // @@@ copy ctor, but no copy assignment? @@@
     SdCustomShow( const SdCustomShow& rShow );
 
+    inline SdPageVec& PagesVector() { return maPages; }
+    void ReplacePage( const SdPage* pOldPage, const SdPage* pNewPage );
+
     void   SetName(const String& rName);
     String GetName() const;
 
     SdDrawDocument* GetDoc() const { return pDoc; }
 
-    void ReplacePage( const SdPage* pOldPage, const SdPage* pNewPage );
-    void RemovePage( const SdPage* pPage );
-
     ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > getUnoCustomShow();
 };
 
diff --git a/sd/source/core/cusshow.cxx b/sd/source/core/cusshow.cxx
index c604344..04bcf13 100644
--- a/sd/source/core/cusshow.cxx
+++ b/sd/source/core/cusshow.cxx
@@ -45,7 +45,7 @@ using namespace ::com::sun::star;
 |*
 \************************************************************************/
 SdCustomShow::SdCustomShow(SdDrawDocument* pDrawDoc)
-  : List(),
+  : maPages(),
   pDoc(pDrawDoc)
 {
 }
@@ -56,14 +56,15 @@ SdCustomShow::SdCustomShow(SdDrawDocument* pDrawDoc)
 |*
 \************************************************************************/
 SdCustomShow::SdCustomShow( const SdCustomShow& rShow )
-    : List( rShow )
+    : maPages()
 {
+    maPages = rShow.maPages;
     aName = rShow.GetName();
     pDoc = rShow.GetDoc();
 }
 
 SdCustomShow::SdCustomShow(SdDrawDocument* pDrawDoc, ::com::sun::star::uno::Reference< 
::com::sun::star::uno::XInterface > xShow )
-  : List(),
+  : maPages(),
   pDoc(pDrawDoc),
   mxUnoCustomShow( xShow )
 {
@@ -101,24 +102,11 @@ void SdCustomShow::ReplacePage( const SdPage* pOldPage, const SdPage* 
pNewPage )
 {
     if( !pNewPage )
     {
-        RemovePage( pOldPage );
+        ::std::remove(maPages.begin(), maPages.end(), pOldPage);
     }
     else
     {
-        sal_uLong nPos;
-        while( (nPos = GetPos( (void*)pOldPage )) != CONTAINER_ENTRY_NOTFOUND  )
-        {
-            Replace( (void*)pNewPage, nPos );
-        }
-    }
-}
-
-void SdCustomShow::RemovePage( const SdPage* pPage )
-{
-    sal_uLong nPos;
-    while( (nPos = GetPos( (void*)pPage )) != CONTAINER_ENTRY_NOTFOUND  )
-    {
-        Remove( nPos );
+        ::std::replace(maPages.begin(), maPages.end(), pOldPage, pNewPage);
     }
 }
 
diff --git a/sd/source/core/drawdoc_animations.cxx b/sd/source/core/drawdoc_animations.cxx
index 5b41d0c..de62ec5 100644
--- a/sd/source/core/drawdoc_animations.cxx
+++ b/sd/source/core/drawdoc_animations.cxx
@@ -44,7 +44,8 @@ void SdDrawDocument::ReplacePageInCustomShows( const SdPage* pOldPage, const SdP
         {
             SdCustomShow* pCustomShow = (SdCustomShow*) mpCustomShowList->GetObject(i);
             if( pNewPage == 0 )
-                pCustomShow->RemovePage(pOldPage);
+                ::std::remove(pCustomShow->PagesVector().begin(), pCustomShow->PagesVector().end(),
+                    pOldPage);
             else
                 pCustomShow->ReplacePage(pOldPage,pNewPage);
         }
diff --git a/sd/source/filter/ppt/pptin.cxx b/sd/source/filter/ppt/pptin.cxx
index 203d2f3..af5dd14 100644
--- a/sd/source/filter/ppt/pptin.cxx
+++ b/sd/source/filter/ppt/pptin.cxx
@@ -1301,7 +1301,7 @@ sal_Bool ImplSdPPTImport::Import()
                                                 SdPage* pPage = mpDoc->GetSdPage( nPage, 
PK_STANDARD );
                                                 if ( pPage )
                                                 {
-                                                    pSdCustomShow->Insert( pPage, LIST_APPEND );
+                                                    pSdCustomShow->PagesVector().push_back( pPage 
);
                                                     nFound++;
                                                 }
                                             }
diff --git a/sd/source/ui/dlg/custsdlg.cxx b/sd/source/ui/dlg/custsdlg.cxx
index 2a56b7e..8fde17c 100644
--- a/sd/source/ui/dlg/custsdlg.cxx
+++ b/sd/source/ui/dlg/custsdlg.cxx
@@ -356,12 +356,11 @@ SdDefineCustomShowDlg::SdDefineCustomShowDlg( Window* pWindow,
         aEdtName.SetText( aOldName );
 
         // ListBox mit CustomShow-Seiten fuellen
-        for( pPage = (SdPage*) rpCustomShow->First();
-             pPage != NULL;
-             pPage = (SdPage*) rpCustomShow->Next() )
+        for( SdPageVec::iterator it = rpCustomShow->PagesVector().begin(); 
+             it != rpCustomShow->PagesVector().end(); ++it )
         {
-            SvLBoxEntry* pEntry = aLbCustomPages.InsertEntry( pPage->GetName() );
-            pEntry->SetUserData( pPage );
+            SvLBoxEntry* pEntry = aLbCustomPages.InsertEntry( (*it)->GetName() );
+            pEntry->SetUserData( (SdPage*) (*it) );
         }
     }
     else
@@ -464,7 +463,7 @@ IMPL_LINK( SdDefineCustomShowDlg, ClickButtonHdl, void *, p )
 /*************************************************************************
 |* CheckCustomShow():
 |* Ueberprueft die Page-Pointer der Show, da die Eintraege ueber die
-|* TreeLB verschoben und kopiert werden kĀ”nnen
+|* TreeLB verschoben und kopiert werden k\94nnen
 \************************************************************************/
 void SdDefineCustomShowDlg::CheckCustomShow()
 {
@@ -473,22 +472,23 @@ void SdDefineCustomShowDlg::CheckCustomShow()
     SvLBoxEntry* pEntry = NULL;
 
     // Anzahl vergleichen
-    if( rpCustomShow->Count() != aLbCustomPages.GetEntryCount() )
+    if( rpCustomShow->PagesVector().size() != aLbCustomPages.GetEntryCount() )
     {
-        rpCustomShow->Clear();
+        rpCustomShow->PagesVector().clear();
         bDifferent = sal_True;
     }
 
     // Seiten-Pointer vergleichen
     if( !bDifferent )
     {
-        for( pPage = (SdPage*) rpCustomShow->First(), pEntry = aLbCustomPages.First();
-             pPage != NULL && pEntry != NULL && !bDifferent;
-             pPage = (SdPage*) rpCustomShow->Next(), pEntry = aLbCustomPages.Next( pEntry ) )
+        SdPageVec::iterator it1 = rpCustomShow->PagesVector().begin(); 
+        pEntry = aLbCustomPages.First();
+        for( ; it1 != rpCustomShow->PagesVector().end() && pEntry != NULL && !bDifferent;
+             ++it1, pEntry = aLbCustomPages.Next( pEntry ) )
         {
-            if( pPage != pEntry->GetUserData() )
+            if( *it1 != pEntry->GetUserData() )
             {
-                rpCustomShow->Clear();
+                rpCustomShow->PagesVector().clear();
                 bDifferent = sal_True;
             }
         }
@@ -502,7 +502,7 @@ void SdDefineCustomShowDlg::CheckCustomShow()
              pEntry = aLbCustomPages.Next( pEntry ) )
         {
             pPage = (SdPage*) pEntry->GetUserData();
-            rpCustomShow->Insert( pPage, LIST_APPEND );
+            rpCustomShow->PagesVector().push_back( pPage );
         }
         bModified = sal_True;
     }
diff --git a/sd/source/ui/dlg/sdtreelb.cxx b/sd/source/ui/dlg/sdtreelb.cxx
index ed79b24..7132739 100644
--- a/sd/source/ui/dlg/sdtreelb.cxx
+++ b/sd/source/ui/dlg/sdtreelb.cxx
@@ -1201,9 +1201,9 @@ bool SdPageObjsTLB::PageBelongsToCurrentShow (const SdPage* pPage) const
         if (pCustomShow != NULL)
         {
             bBelongsToShow = false;
-            sal_uLong nPageCount = pCustomShow->Count();
+            sal_uLong nPageCount = pCustomShow->PagesVector().size();
             for (sal_uInt16 i=0; i<nPageCount && !bBelongsToShow; i++)
-                if (pPage == static_cast<SdPage*>(pCustomShow->GetObject (i)))
+                if (pPage == pCustomShow->PagesVector()[i])
                     bBelongsToShow = true;
         }
     }
diff --git a/sd/source/ui/slideshow/slideshowimpl.cxx b/sd/source/ui/slideshow/slideshowimpl.cxx
index 8df6407..3fc06cf 100644
--- a/sd/source/ui/slideshow/slideshowimpl.cxx
+++ b/sd/source/ui/slideshow/slideshowimpl.cxx
@@ -2485,7 +2485,7 @@ void SlideshowImpl::createSlideList( bool bAll, bool bStartWithActualSlide, 
cons
 
         // create animation slide controller
         AnimationSlideController::Mode eMode =
-            ( pCustomShow && pCustomShow->Count() ) ? AnimationSlideController::CUSTOM :
+            ( pCustomShow && pCustomShow->PagesVector().size() ) ? 
AnimationSlideController::CUSTOM :
                 (bAll ? AnimationSlideController::ALL : AnimationSlideController::FROM);
 
         Reference< XDrawPagesSupplier > xDrawPages( mpDoc->getUnoModel(), UNO_QUERY_THROW );
@@ -2546,11 +2546,11 @@ void SlideshowImpl::createSlideList( bool bAll, bool bStartWithActualSlide, 
cons
                     mpSlideController->insertSlideNumber( (sal_uInt16) nSlide );
             }
 
-            void* pCustomSlide;
-            sal_Int32 nSlideIndex;
-            for( pCustomSlide = pCustomShow->First(),nSlideIndex=0; pCustomSlide; pCustomSlide = 
pCustomShow->Next(), nSlideIndex++ )
+            sal_Int32 nSlideIndex = 0;
+            for( SdPageVec::iterator it = pCustomShow->PagesVector().begin(); 
+                 it != pCustomShow->PagesVector().end(); ++it, nSlideIndex++ )
             {
-                const sal_uInt16 nSdSlide = ( ( (SdPage*) pCustomSlide )->GetPageNum() - 1 ) / 2;
+                const sal_uInt16 nSdSlide = ( ( (SdPage*) (*it) )->GetPageNum() - 1 ) / 2;
 
                 if( !( mpDoc->GetSdPage( nSdSlide, PK_STANDARD ) )->IsExcluded())
                     mpSlideController->insertSlideNumber( nSdSlide );
diff --git a/sd/source/ui/unoidl/unocpres.cxx b/sd/source/ui/unoidl/unocpres.cxx
index 71f70fa..f718aa7 100644
--- a/sd/source/ui/unoidl/unocpres.cxx
+++ b/sd/source/ui/unoidl/unocpres.cxx
@@ -26,6 +26,8 @@
  *
  ************************************************************************/
 
+#include <algorithm>
+
 #include <com/sun/star/lang/DisposedException.hpp>
 #include <osl/mutex.hxx>
 #include <osl/mutex.hxx>
@@ -100,7 +102,7 @@ void SAL_CALL SdXCustomPresentation::insertByIndex( sal_Int32 Index, const uno::
     if( bDisposing )
         throw lang::DisposedException();
 
-    if( Index < 0 || Index > (sal_Int32)( mpSdCustomShow ? mpSdCustomShow->Count() : 0 ) )
+    if( Index < 0 || Index > (sal_Int32)( mpSdCustomShow ? mpSdCustomShow->PagesVector().size() : 
0 ) )
         throw lang::IndexOutOfBoundsException();
 
     uno::Reference< drawing::XDrawPage > xPage;
@@ -119,7 +121,8 @@ void SAL_CALL SdXCustomPresentation::insertByIndex( sal_Int32 Index, const uno::
         if( NULL != mpModel && NULL == mpSdCustomShow && mpModel->GetDoc() )
             mpSdCustomShow = new SdCustomShow( mpModel->GetDoc() );
 
-        mpSdCustomShow->Insert(pPage->GetSdrPage(), Index);
+        mpSdCustomShow->PagesVector().insert(mpSdCustomShow->PagesVector().begin() + Index, 
+            (SdPage*) pPage->GetSdrPage());
     }
 
     if( mpModel )
@@ -143,7 +146,8 @@ void SAL_CALL SdXCustomPresentation::removeByIndex( sal_Int32 Index )
         {
             SvxDrawPage* pPage = SvxDrawPage::getImplementation(  xPage );
             if(pPage)
-                mpSdCustomShow->Remove(pPage->GetSdrPage());
+                ::std::remove(mpSdCustomShow->PagesVector().begin(), 
mpSdCustomShow->PagesVector().end(),
+                    pPage->GetSdrPage());
         }
     }
 
@@ -185,7 +189,7 @@ sal_Int32 SAL_CALL SdXCustomPresentation::getCount()
     if( bDisposing )
         throw lang::DisposedException();
 
-    return mpSdCustomShow?mpSdCustomShow->Count():0;
+    return mpSdCustomShow ? mpSdCustomShow->PagesVector().size() : 0;
 }
 
 uno::Any SAL_CALL SdXCustomPresentation::getByIndex( sal_Int32 Index )
@@ -196,13 +200,13 @@ uno::Any SAL_CALL SdXCustomPresentation::getByIndex( sal_Int32 Index )
     if( bDisposing )
         throw lang::DisposedException();
 
-    if( Index < 0 || Index >= (sal_Int32)mpSdCustomShow->Count() )
+    if( Index < 0 || Index >= (sal_Int32)mpSdCustomShow->PagesVector().size() )
         throw lang::IndexOutOfBoundsException();
 
     uno::Any aAny;
     if(mpSdCustomShow )
     {
-        SdrPage* pPage = (SdrPage*)mpSdCustomShow->GetObject(Index);
+        SdrPage* pPage = (SdrPage*)mpSdCustomShow->PagesVector()[Index];
 
         if( pPage )
         {

Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.