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


Hi

Attached patch converts SdPresLayoutDlg to use std::map.

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

Regards, Noel Grandin

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


diff --git a/sd/source/ui/dlg/sdpreslt.cxx b/sd/source/ui/dlg/sdpreslt.cxx
index 98f2df5..c8b1495 100644
--- a/sd/source/ui/dlg/sdpreslt.cxx
+++ b/sd/source/ui/dlg/sdpreslt.cxx
@@ -76,8 +76,6 @@ SdPresLayoutDlg::SdPresLayoutDlg(
 {
     FreeResource();
 
-    mpLayoutNames = new List;
-
     maVS.SetDoubleClickHdl(LINK(this, SdPresLayoutDlg, ClickLayoutHdl));
     maBtnLoad.SetClickHdl(LINK(this, SdPresLayoutDlg, ClickLoadHdl));
 
@@ -92,14 +90,7 @@ SdPresLayoutDlg::SdPresLayoutDlg(
 
 SdPresLayoutDlg::~SdPresLayoutDlg()
 {
-    String* pName = (String*)mpLayoutNames->First();
-    while (pName)
-    {
-        delete pName;
-        pName = (String*)mpLayoutNames->Next();
-    }
-
-    delete mpLayoutNames;
+    maLayoutNames.clear();
 }
 
 /*************************************************************************
@@ -131,10 +122,10 @@ void SdPresLayoutDlg::Reset()
 
     FillValueSet();
 
-    mnLayoutCount = mpLayoutNames->Count();
+    mnLayoutCount = maLayoutNames.size();
     for( nName = 0; nName < mnLayoutCount; nName++ )
     {
-        if (*((String*)mpLayoutNames->GetObject(nName)) == maName)
+        if (maLayoutNames[nName] == maName)
             break;
     }
     DBG_ASSERT(nName < mnLayoutCount, "Layout nicht gefunden");
@@ -161,11 +152,11 @@ void SdPresLayoutDlg::GetAttr(SfxItemSet& rOutAttrs)
     {
         aLayoutName = maName;
         aLayoutName.Append( DOCUMENT_TOKEN );
-        aLayoutName.Append( *(String*)mpLayoutNames->GetObject( nId - 1 ) );
+        aLayoutName.Append( maLayoutNames[ nId - 1 ] );
     }
     else
     {
-        aLayoutName = *(String*)mpLayoutNames->GetObject( nId - 1 );
+        aLayoutName = maLayoutNames[ nId - 1 ];
         if( aLayoutName == maStrNone )
             aLayoutName.Erase(); //  so wird "- keine -" codiert (s.u.)
     }
@@ -202,10 +193,10 @@ void SdPresLayoutDlg::FillValueSet()
         {
             String aLayoutName(pMaster->GetLayoutName());
             aLayoutName.Erase( aLayoutName.SearchAscii( SD_LT_SEPARATOR ) );
-            mpLayoutNames->Insert(new String(aLayoutName), LIST_APPEND);
+            maLayoutNames.push_back(new String(aLayoutName));
 
             Bitmap aBitmap(mpDocSh->GetPagePreviewBitmap(pMaster, 90));
-            maVS.InsertItem((sal_uInt16)mpLayoutNames->Count(), aBitmap, aLayoutName);
+            maVS.InsertItem((sal_uInt16)maLayoutNames.size(), aBitmap, aLayoutName);
         }
     }
 
@@ -274,21 +265,22 @@ IMPL_LINK(SdPresLayoutDlg, ClickLoadHdl, void *, EMPTYARG)
     {
         // Pruefen, ob Vorlage schon vorhanden
         sal_Bool bExists = sal_False;
-        String* pName = (String*)mpLayoutNames->First();
         String aCompareStr( maName );
         if( maName.Len() == 0 )
             aCompareStr = maStrNone;
 
-        while( pName && !bExists )
+            int aPos = 0;
+            for (boost::ptr_vector<String>::iterator it = maLayoutNames.begin();
+                 it != maLayoutNames.end() && !bExists; ++it, ++aPos)
         {
-            if( aCompareStr == *pName )
+                String pName = *it;
+            if( aCompareStr == pName )
             {
                 bExists = sal_True;
                 // Vorlage selektieren
-                sal_uInt16 nId = (sal_uInt16) mpLayoutNames->GetCurPos() + 1;
+                sal_uInt16 nId = (sal_uInt16) aPos + 1;
                 maVS.SelectItem( nId );
             }
-            pName = (String*)mpLayoutNames->Next();
         }
 
         if( !bExists )
@@ -313,10 +305,10 @@ IMPL_LINK(SdPresLayoutDlg, ClickLoadHdl, void *, EMPTYARG)
                         {
                             String aLayoutName(pMaster->GetLayoutName());
                             aLayoutName.Erase( aLayoutName.SearchAscii( SD_LT_SEPARATOR ) );
-                            mpLayoutNames->Insert(new String(aLayoutName), LIST_APPEND);
+                            maLayoutNames.push_back(new String(aLayoutName));
 
                             Bitmap aBitmap(pTemplDocSh->GetPagePreviewBitmap(pMaster, 90));
-                            maVS.InsertItem((sal_uInt16)mpLayoutNames->Count(), aBitmap, 
aLayoutName);
+                            maVS.InsertItem((sal_uInt16)maLayoutNames.size(), aBitmap, 
aLayoutName);
                         }
                     }
                 }
@@ -330,15 +322,15 @@ IMPL_LINK(SdPresLayoutDlg, ClickLoadHdl, void *, EMPTYARG)
             else
             {
                 // leeres Layout
-                mpLayoutNames->Insert( new String( maStrNone ), LIST_APPEND );
-                maVS.InsertItem( (sal_uInt16) mpLayoutNames->Count(),
+                maLayoutNames.push_back( new String( maStrNone ) );
+                maVS.InsertItem( (sal_uInt16) maLayoutNames.size(),
                         Bitmap( SdResId( BMP_FOIL_NONE ) ), maStrNone );
             }
 
             if (!bCancel)
             {
                 // Vorlage selektieren
-                maVS.SelectItem( (sal_uInt16) mpLayoutNames->Count() );
+                maVS.SelectItem( (sal_uInt16) maLayoutNames.size() );
             }
         }
     }
diff --git a/sd/source/ui/inc/sdpreslt.hxx b/sd/source/ui/inc/sdpreslt.hxx
index d0a62d5..db74471 100644
--- a/sd/source/ui/inc/sdpreslt.hxx
+++ b/sd/source/ui/inc/sdpreslt.hxx
@@ -29,10 +29,11 @@
 #ifndef SD_PRES_LAYOUT_DLG_HXX
 #define SD_PRES_LAYOUT_DLG_HXX
 
+#include <boost/ptr_container/ptr_vector.hpp>
+
 #include <vcl/dialog.hxx>
 #include <vcl/button.hxx>
 #include <vcl/fixed.hxx>
-#include <tools/list.hxx>
 #include <svtools/valueset.hxx>
 
 class SfxItemSet;
@@ -75,7 +76,7 @@ private:
 
     const SfxItemSet&   mrOutAttrs;
 
-    List*               mpLayoutNames;
+    boost::ptr_vector<String> maLayoutNames;
 
     String              maName;          // Layoutname oder Dateiname
     long                mnLayoutCount;  // Anzahl, der im Dokument vorhandenen MasterPages

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.