diff options
author | Noel Grandin <noel@peralex.com> | 2012-08-15 11:30:54 +0200 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2012-08-16 15:14:59 +0200 |
commit | 81b5ecc5a68cd15497301e6b10b462673f93655f (patch) | |
tree | 884a7cfe88c0431ad29a03af2d4846009c3bbac8 /svx | |
parent | Convert aList field in SdrHelpLineList class from Container to std::vector (diff) | |
download | core-81b5ecc5a68cd15497301e6b10b462673f93655f.tar.gz core-81b5ecc5a68cd15497301e6b10b462673f93655f.zip |
Convert aLayer field in SdrLayerAdmin class from Container to std::vector
Change-Id: I884f8e76d0bc7b2eb9f99434809fa824409446e4
Diffstat (limited to 'svx')
-rw-r--r-- | svx/inc/svx/svdlayer.hxx | 35 | ||||
-rw-r--r-- | svx/source/svdraw/svdlayer.cxx | 37 |
2 files changed, 50 insertions, 22 deletions
diff --git a/svx/inc/svx/svdlayer.hxx b/svx/inc/svx/svdlayer.hxx index aac75c9b009c..f0b468baa755 100644 --- a/svx/inc/svx/svdlayer.hxx +++ b/svx/inc/svx/svdlayer.hxx @@ -35,6 +35,7 @@ #include <svx/svdsob.hxx> #include <svx/svdtypes.hxx> // fuer typedef SdrLayerID #include "svx/svxdllapi.h" +#include <algorithm> class SdrModel; @@ -84,7 +85,7 @@ friend class SdrModel; friend class SdrPage; protected: - Container aLayer; + std::vector<SdrLayer*> aLayer; Container aLSets; SdrLayerAdmin* pParent; // Der Admin der Seite kennt den Admin des Docs SdrModel* pModel; // zum Broadcasten @@ -107,20 +108,42 @@ public: void SetParent(SdrLayerAdmin* pNewParent) { pParent=pNewParent; } void SetModel(SdrModel* pNewModel); SdrModel* GetModel() const { return pModel; } - void InsertLayer(SdrLayer* pLayer, sal_uInt16 nPos=0xFFFF) { aLayer.Insert(pLayer,nPos); pLayer->SetModel(pModel); Broadcast(); } + void InsertLayer(SdrLayer* pLayer) + { + aLayer.push_back(pLayer); + pLayer->SetModel(pModel); + Broadcast(); + } + void InsertLayer(SdrLayer* pLayer, sal_uInt16 nPos) + { + if(nPos==0xFFFF) + aLayer.push_back(pLayer); + else + aLayer.insert(aLayer.begin() + nPos, pLayer); + pLayer->SetModel(pModel); + Broadcast(); + } SdrLayer* RemoveLayer(sal_uInt16 nPos); // Alle Layer loeschen void ClearLayer(); // Neuer Layer wird angelegt und eingefuegt SdrLayer* NewLayer(const String& rName, sal_uInt16 nPos=0xFFFF); - void DeleteLayer(SdrLayer* pLayer) { aLayer.Remove(pLayer); delete pLayer; Broadcast(); } + void DeleteLayer(SdrLayer* pLayer) + { + std::vector<SdrLayer*>::iterator it = std::find(aLayer.begin(), aLayer.end(), pLayer); + if( it == aLayer.end() ) + return; + aLayer.erase(it); + delete pLayer; + Broadcast(); + } // Neuer Layer, Name wird aus der Resource geholt SdrLayer* NewStandardLayer(sal_uInt16 nPos=0xFFFF); // Iterieren ueber alle Layer - sal_uInt16 GetLayerCount() const { return sal_uInt16(aLayer.Count()); } - SdrLayer* GetLayer(sal_uInt16 i) { return (SdrLayer*)(aLayer.GetObject(i)); } - const SdrLayer* GetLayer(sal_uInt16 i) const { return (SdrLayer*)(aLayer.GetObject(i)); } + sal_uInt16 GetLayerCount() const { return sal_uInt16(aLayer.size()); } + SdrLayer* GetLayer(sal_uInt16 i) { return aLayer[i]; } + const SdrLayer* GetLayer(sal_uInt16 i) const { return aLayer[i]; } sal_uInt16 GetLayerPos(SdrLayer* pLayer) const; diff --git a/svx/source/svdraw/svdlayer.cxx b/svx/source/svdraw/svdlayer.cxx index f946fc01a90e..4b0282231f31 100644 --- a/svx/source/svdraw/svdlayer.cxx +++ b/svx/source/svdraw/svdlayer.cxx @@ -159,7 +159,7 @@ bool SdrLayer::operator==(const SdrLayer& rCmpLayer) const //////////////////////////////////////////////////////////////////////////////////////////////////// SdrLayerAdmin::SdrLayerAdmin(SdrLayerAdmin* pNewParent): - aLayer(1024,16,16), + aLayer(), aLSets(1024,16,16), pModel(NULL) { @@ -168,7 +168,7 @@ SdrLayerAdmin::SdrLayerAdmin(SdrLayerAdmin* pNewParent): } SdrLayerAdmin::SdrLayerAdmin(const SdrLayerAdmin& rSrcLayerAdmin): - aLayer(1024,16,16), + aLayer(), aLSets(1024,16,16), pParent(NULL), pModel(NULL) @@ -184,13 +184,9 @@ SdrLayerAdmin::~SdrLayerAdmin() void SdrLayerAdmin::ClearLayer() { - SdrLayer* pL; - pL=(SdrLayer*)aLayer.First(); - while (pL!=NULL) { - delete pL; - pL=(SdrLayer*)aLayer.Next(); - } - aLayer.Clear(); + for( std::vector<SdrLayer*>::const_iterator it = aLayer.begin(); it != aLayer.end(); ++it ) + delete *it; + aLayer.clear(); } const SdrLayerAdmin& SdrLayerAdmin::operator=(const SdrLayerAdmin& rSrcLayerAdmin) @@ -200,7 +196,7 @@ const SdrLayerAdmin& SdrLayerAdmin::operator=(const SdrLayerAdmin& rSrcLayerAdmi sal_uInt16 i; sal_uInt16 nAnz=rSrcLayerAdmin.GetLayerCount(); for (i=0; i<nAnz; i++) { - aLayer.Insert(new SdrLayer(*rSrcLayerAdmin.GetLayer(i)),CONTAINER_APPEND); + aLayer.push_back(new SdrLayer(*rSrcLayerAdmin.GetLayer(i))); } return *this; } @@ -208,7 +204,7 @@ const SdrLayerAdmin& SdrLayerAdmin::operator=(const SdrLayerAdmin& rSrcLayerAdmi bool SdrLayerAdmin::operator==(const SdrLayerAdmin& rCmpLayerAdmin) const { if (pParent!=rCmpLayerAdmin.pParent || - aLayer.Count()!=rCmpLayerAdmin.aLayer.Count() || + aLayer.size()!=rCmpLayerAdmin.aLayer.size() || aLSets.Count()!=rCmpLayerAdmin.aLSets.Count()) return sal_False; bool bOk = true; sal_uInt16 nAnz=GetLayerCount(); @@ -243,7 +239,8 @@ void SdrLayerAdmin::Broadcast() const SdrLayer* SdrLayerAdmin::RemoveLayer(sal_uInt16 nPos) { - SdrLayer* pRetLayer=(SdrLayer*)(aLayer.Remove(nPos)); + SdrLayer* pRetLayer=aLayer[nPos]; + aLayer.erase(aLayer.begin()+nPos); Broadcast(); return pRetLayer; } @@ -253,7 +250,10 @@ SdrLayer* SdrLayerAdmin::NewLayer(const XubString& rName, sal_uInt16 nPos) SdrLayerID nID=GetUniqueLayerID(); SdrLayer* pLay=new SdrLayer(nID,rName); pLay->SetModel(pModel); - aLayer.Insert(pLay,nPos); + if(nPos==0xFFFF) + aLayer.push_back(pLay); + else + aLayer.insert(aLayer.begin() + nPos, pLay); Broadcast(); return pLay; } @@ -264,7 +264,10 @@ SdrLayer* SdrLayerAdmin::NewStandardLayer(sal_uInt16 nPos) SdrLayer* pLay=new SdrLayer(nID,String()); pLay->SetStandardLayer(); pLay->SetModel(pModel); - aLayer.Insert(pLay,nPos); + if(nPos==0xFFFF) + aLayer.push_back(pLay); + else + aLayer.insert(aLayer.begin() + nPos, pLay); Broadcast(); return pLay; } @@ -273,9 +276,11 @@ sal_uInt16 SdrLayerAdmin::GetLayerPos(SdrLayer* pLayer) const { sal_uIntPtr nRet=SDRLAYER_NOTFOUND; if (pLayer!=NULL) { - nRet=aLayer.GetPos(pLayer); - if (nRet==CONTAINER_ENTRY_NOTFOUND) { + std::vector<SdrLayer*>::const_iterator it = std::find(aLayer.begin(), aLayer.end(), pLayer); + if (it==aLayer.end()) { nRet=SDRLAYER_NOTFOUND; + } else { + nRet=it - aLayer.begin(); } } return sal_uInt16(nRet); |