Kaydet (Commit) 7d5922ca authored tarafından Noel Grandin's avatar Noel Grandin Kaydeden (comit) Michael Stahl

Convert aList in SdrHdlList class from Container to std::deque

Change-Id: I54c60fefe2e808b5e6251286a72537e5a88bf566
üst aa11e7ba
...@@ -32,7 +32,6 @@ ...@@ -32,7 +32,6 @@
#include <tools/gen.hxx> #include <tools/gen.hxx>
#include <vcl/pointr.hxx> #include <vcl/pointr.hxx>
#include <tools/contnr.hxx>
#include <svl/solar.hrc> #include <svl/solar.hrc>
...@@ -449,15 +448,15 @@ class SVX_DLLPUBLIC SdrHdlList ...@@ -449,15 +448,15 @@ class SVX_DLLPUBLIC SdrHdlList
protected: protected:
sal_uIntPtr mnFocusIndex; sal_uIntPtr mnFocusIndex;
SdrMarkView* pView; SdrMarkView* pView;
Container aList; std::deque<SdrHdl*> aList;
sal_uInt16 nHdlSize; sal_uInt16 nHdlSize;
unsigned bRotateShear : 1; unsigned bRotateShear : 1;
unsigned bDistortShear : 1; unsigned bDistortShear : 1;
unsigned bMoveOutside : 1; // Handles nach aussen ruecken (fuer TextEdit) unsigned bMoveOutside : 1; // Handles nach aussen ruecken (fuer TextEdit)
private: private:
SVX_DLLPRIVATE SdrHdlList(const SdrHdlList&): aList(1024,64,64) {} SVX_DLLPRIVATE SdrHdlList(const SdrHdlList&): aList() {}
SVX_DLLPRIVATE void operator=(const SdrHdlList&) {} SVX_DLLPRIVATE void operator=(const SdrHdlList&) {}
SVX_DLLPRIVATE sal_Bool operator==(const SdrHdlList&) const { return sal_False; } SVX_DLLPRIVATE sal_Bool operator==(const SdrHdlList&) const { return sal_False; }
SVX_DLLPRIVATE sal_Bool operator!=(const SdrHdlList&) const { return sal_False; } SVX_DLLPRIVATE sal_Bool operator!=(const SdrHdlList&) const { return sal_False; }
...@@ -480,8 +479,8 @@ public: ...@@ -480,8 +479,8 @@ public:
// 2.Level PageView (Pointer) // 2.Level PageView (Pointer)
// 3.Level Position (x+y) // 3.Level Position (x+y)
void Sort(); void Sort();
sal_uIntPtr GetHdlCount() const { return aList.Count(); } sal_uIntPtr GetHdlCount() const { return aList.size(); }
SdrHdl* GetHdl(sal_uIntPtr nNum) const { return (SdrHdl*)(aList.GetObject(nNum)); } SdrHdl* GetHdl(sal_uIntPtr nNum) const { return aList[nNum]; }
sal_uIntPtr GetHdlNum(const SdrHdl* pHdl) const; sal_uIntPtr GetHdlNum(const SdrHdl* pHdl) const;
void SetHdlSize(sal_uInt16 nSiz); void SetHdlSize(sal_uInt16 nSiz);
sal_uInt16 GetHdlSize() const { return nHdlSize; } sal_uInt16 GetHdlSize() const { return nHdlSize; }
......
...@@ -1666,17 +1666,10 @@ void ImpTextframeHdl::CreateB2dIAObject() ...@@ -1666,17 +1666,10 @@ void ImpTextframeHdl::CreateB2dIAObject()
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
class ImpSdrHdlListSorter: public ContainerSorter { static bool ImpSdrHdlListSorter(SdrHdl* const& lhs, SdrHdl* const& rhs)
public:
ImpSdrHdlListSorter(Container& rNewCont): ContainerSorter(rNewCont) {}
virtual ~ImpSdrHdlListSorter() {}
virtual int Compare(const void* pElem1, const void* pElem2) const;
};
int ImpSdrHdlListSorter::Compare(const void* pElem1, const void* pElem2) const
{ {
SdrHdlKind eKind1=((SdrHdl*)pElem1)->GetKind(); SdrHdlKind eKind1=lhs->GetKind();
SdrHdlKind eKind2=((SdrHdl*)pElem2)->GetKind(); SdrHdlKind eKind2=rhs->GetKind();
// Level 1: first normal handles, then Glue, then User, then Plus handles, then reference point handles // Level 1: first normal handles, then Glue, then User, then Plus handles, then reference point handles
unsigned n1=1; unsigned n1=1;
unsigned n2=1; unsigned n2=1;
...@@ -1691,44 +1684,44 @@ int ImpSdrHdlListSorter::Compare(const void* pElem1, const void* pElem2) const ...@@ -1691,44 +1684,44 @@ int ImpSdrHdlListSorter::Compare(const void* pElem1, const void* pElem2) const
else if (eKind2==HDL_USER) n2=3; else if (eKind2==HDL_USER) n2=3;
else if (eKind2==HDL_SMARTTAG) n2=0; else if (eKind2==HDL_SMARTTAG) n2=0;
} }
if (((SdrHdl*)pElem1)->IsPlusHdl()) n1=4; if (lhs->IsPlusHdl()) n1=4;
if (((SdrHdl*)pElem2)->IsPlusHdl()) n2=4; if (rhs->IsPlusHdl()) n2=4;
if (n1==n2) if (n1==n2)
{ {
// Level 2: PageView (Pointer) // Level 2: PageView (Pointer)
SdrPageView* pPV1=((SdrHdl*)pElem1)->GetPageView(); SdrPageView* pPV1=lhs->GetPageView();
SdrPageView* pPV2=((SdrHdl*)pElem2)->GetPageView(); SdrPageView* pPV2=rhs->GetPageView();
if (pPV1==pPV2) if (pPV1==pPV2)
{ {
// Level 3: Position (x+y) // Level 3: Position (x+y)
SdrObject* pObj1=((SdrHdl*)pElem1)->GetObj(); SdrObject* pObj1=lhs->GetObj();
SdrObject* pObj2=((SdrHdl*)pElem2)->GetObj(); SdrObject* pObj2=rhs->GetObj();
if (pObj1==pObj2) if (pObj1==pObj2)
{ {
sal_uInt32 nNum1=((SdrHdl*)pElem1)->GetObjHdlNum(); sal_uInt32 nNum1=lhs->GetObjHdlNum();
sal_uInt32 nNum2=((SdrHdl*)pElem2)->GetObjHdlNum(); sal_uInt32 nNum2=rhs->GetObjHdlNum();
if (nNum1==nNum2) if (nNum1==nNum2)
{ {
if (eKind1==eKind2) if (eKind1==eKind2)
return (long)pElem1<(long)pElem2 ? -1 : 1; // Hack, to always get to the same sorting return (long)lhs<(long)rhs; // Hack, to always get to the same sorting
return (sal_uInt16)eKind1<(sal_uInt16)eKind2 ? -1 : 1; return (sal_uInt16)eKind1<(sal_uInt16)eKind2;
} }
else else
return nNum1<nNum2 ? -1 : 1; return nNum1<nNum2;
} }
else else
{ {
return (long)pObj1<(long)pObj2 ? -1 : 1; return (long)pObj1<(long)pObj2;
} }
} }
else else
{ {
return (long)pPV1<(long)pPV2 ? -1 : 1; return (long)pPV1<(long)pPV2;
} }
} }
else else
{ {
return n1<n2 ? -1 : 1; return n1<n2;
} }
} }
...@@ -1828,7 +1821,7 @@ void SdrHdlList::TravelFocusHdl(sal_Bool bForward) ...@@ -1828,7 +1821,7 @@ void SdrHdlList::TravelFocusHdl(sal_Bool bForward)
if(mnFocusIndex != CONTAINER_ENTRY_NOTFOUND && mnFocusIndex >= GetHdlCount()) if(mnFocusIndex != CONTAINER_ENTRY_NOTFOUND && mnFocusIndex >= GetHdlCount())
mnFocusIndex = CONTAINER_ENTRY_NOTFOUND; mnFocusIndex = CONTAINER_ENTRY_NOTFOUND;
if(aList.Count()) if(!aList.empty())
{ {
// take care of old handle // take care of old handle
const sal_uIntPtr nOldHdlNum(mnFocusIndex); const sal_uIntPtr nOldHdlNum(mnFocusIndex);
...@@ -1842,24 +1835,24 @@ void SdrHdlList::TravelFocusHdl(sal_Bool bForward) ...@@ -1842,24 +1835,24 @@ void SdrHdlList::TravelFocusHdl(sal_Bool bForward)
} }
// allocate pointer array for sorted handle list // allocate pointer array for sorted handle list
ImplHdlAndIndex* pHdlAndIndex = new ImplHdlAndIndex[aList.Count()]; ImplHdlAndIndex* pHdlAndIndex = new ImplHdlAndIndex[aList.size()];
// build sorted handle list // build sorted handle list
sal_uInt32 a; sal_uInt32 a;
for( a = 0; a < aList.Count(); a++) for( a = 0; a < aList.size(); a++)
{ {
pHdlAndIndex[a].mpHdl = (SdrHdl*)aList.GetObject(a); pHdlAndIndex[a].mpHdl = aList[a];
pHdlAndIndex[a].mnIndex = a; pHdlAndIndex[a].mnIndex = a;
} }
qsort(pHdlAndIndex, aList.Count(), sizeof(ImplHdlAndIndex), ImplSortHdlFunc); qsort(pHdlAndIndex, aList.size(), sizeof(ImplHdlAndIndex), ImplSortHdlFunc);
// look for old num in sorted array // look for old num in sorted array
sal_uIntPtr nOldHdl(nOldHdlNum); sal_uIntPtr nOldHdl(nOldHdlNum);
if(nOldHdlNum != CONTAINER_ENTRY_NOTFOUND) if(nOldHdlNum != CONTAINER_ENTRY_NOTFOUND)
{ {
for(a = 0; a < aList.Count(); a++) for(a = 0; a < aList.size(); a++)
{ {
if(pHdlAndIndex[a].mpHdl == pOld) if(pHdlAndIndex[a].mpHdl == pOld)
{ {
...@@ -1877,7 +1870,7 @@ void SdrHdlList::TravelFocusHdl(sal_Bool bForward) ...@@ -1877,7 +1870,7 @@ void SdrHdlList::TravelFocusHdl(sal_Bool bForward)
{ {
if(nOldHdl != CONTAINER_ENTRY_NOTFOUND) if(nOldHdl != CONTAINER_ENTRY_NOTFOUND)
{ {
if(nOldHdl == aList.Count() - 1) if(nOldHdl == aList.size() - 1)
{ {
// end forward run // end forward run
nNewHdl = CONTAINER_ENTRY_NOTFOUND; nNewHdl = CONTAINER_ENTRY_NOTFOUND;
...@@ -1899,7 +1892,7 @@ void SdrHdlList::TravelFocusHdl(sal_Bool bForward) ...@@ -1899,7 +1892,7 @@ void SdrHdlList::TravelFocusHdl(sal_Bool bForward)
if(nOldHdl == CONTAINER_ENTRY_NOTFOUND) if(nOldHdl == CONTAINER_ENTRY_NOTFOUND)
{ {
// start backward run at last entry // start backward run at last entry
nNewHdl = aList.Count() - 1; nNewHdl = aList.size() - 1;
} }
else else
...@@ -1925,9 +1918,9 @@ void SdrHdlList::TravelFocusHdl(sal_Bool bForward) ...@@ -1925,9 +1918,9 @@ void SdrHdlList::TravelFocusHdl(sal_Bool bForward)
{ {
SdrHdl* pNew = pHdlAndIndex[nNewHdl].mpHdl; SdrHdl* pNew = pHdlAndIndex[nNewHdl].mpHdl;
for(a = 0; a < aList.Count(); a++) for(a = 0; a < aList.size(); a++)
{ {
if((SdrHdl*)aList.GetObject(a) == pNew) if(aList[a] == pNew)
{ {
nNewHdlNum = a; nNewHdlNum = a;
break; break;
...@@ -2006,7 +1999,7 @@ void SdrHdlList::ResetFocusHdl() ...@@ -2006,7 +1999,7 @@ void SdrHdlList::ResetFocusHdl()
SdrHdlList::SdrHdlList(SdrMarkView* pV) SdrHdlList::SdrHdlList(SdrMarkView* pV)
: mnFocusIndex(CONTAINER_ENTRY_NOTFOUND), : mnFocusIndex(CONTAINER_ENTRY_NOTFOUND),
pView(pV), pView(pV),
aList(1024,32,32) aList()
{ {
nHdlSize = 3; nHdlSize = 3;
bRotateShear = sal_False; bRotateShear = sal_False;
...@@ -2063,28 +2056,24 @@ void SdrHdlList::SetDistortShear(sal_Bool bOn) ...@@ -2063,28 +2056,24 @@ void SdrHdlList::SetDistortShear(sal_Bool bOn)
SdrHdl* SdrHdlList::RemoveHdl(sal_uIntPtr nNum) SdrHdl* SdrHdlList::RemoveHdl(sal_uIntPtr nNum)
{ {
SdrHdl* pRetval = (SdrHdl*)aList.Remove(nNum); SdrHdl* pRetval = aList[nNum];
aList.erase(aList.begin() + nNum);
return pRetval; return pRetval;
} }
void SdrHdlList::RemoveAllByKind(SdrHdlKind eKind) void SdrHdlList::RemoveAllByKind(SdrHdlKind eKind)
{ {
SdrHdl* p = static_cast<SdrHdl*>(aList.Last()); for(std::deque<SdrHdl*>::iterator it = aList.begin(); it != aList.end(); )
while (p)
{ {
SdrHdl* p = *it;
if (p->GetKind() == eKind) if (p->GetKind() == eKind)
{ {
// If removing an item doesn't invalidate the current position, it = aList.erase( it );
// then perhaps it's safe to keep calling Prev here. But then I'm
// too lazy to find out & this Container needs to be replaced by
// STL anyways... :-P
aList.Remove(p);
delete p; delete p;
p = static_cast<SdrHdl*>(aList.Last()); // start from the back again.
} }
else else
p = static_cast<SdrHdl*>(aList.Prev()); ++it;
} }
} }
...@@ -2095,7 +2084,7 @@ void SdrHdlList::Clear() ...@@ -2095,7 +2084,7 @@ void SdrHdlList::Clear()
SdrHdl* pHdl=GetHdl(i); SdrHdl* pHdl=GetHdl(i);
delete pHdl; delete pHdl;
} }
aList.Clear(); aList.clear();
bRotateShear=sal_False; bRotateShear=sal_False;
bDistortShear=sal_False; bDistortShear=sal_False;
...@@ -2106,8 +2095,7 @@ void SdrHdlList::Sort() ...@@ -2106,8 +2095,7 @@ void SdrHdlList::Sort()
// remember currently focused handle // remember currently focused handle
SdrHdl* pPrev = GetFocusHdl(); SdrHdl* pPrev = GetFocusHdl();
ImpSdrHdlListSorter aSort(aList); std::sort( aList.begin(), aList.end(), ImpSdrHdlListSorter );
aSort.DoSort();
// get now and compare // get now and compare
SdrHdl* pNow = GetFocusHdl(); SdrHdl* pNow = GetFocusHdl();
...@@ -2131,8 +2119,10 @@ sal_uIntPtr SdrHdlList::GetHdlNum(const SdrHdl* pHdl) const ...@@ -2131,8 +2119,10 @@ sal_uIntPtr SdrHdlList::GetHdlNum(const SdrHdl* pHdl) const
{ {
if (pHdl==NULL) if (pHdl==NULL)
return CONTAINER_ENTRY_NOTFOUND; return CONTAINER_ENTRY_NOTFOUND;
sal_uIntPtr nPos=aList.GetPos(pHdl); std::deque<SdrHdl*>::const_iterator it = std::find( aList.begin(), aList.end(), pHdl);
return nPos; if( it == aList.end() )
return CONTAINER_ENTRY_NOTFOUND;
return it - aList.begin();
} }
void SdrHdlList::AddHdl(SdrHdl* pHdl, sal_Bool bAtBegin) void SdrHdlList::AddHdl(SdrHdl* pHdl, sal_Bool bAtBegin)
...@@ -2141,11 +2131,11 @@ void SdrHdlList::AddHdl(SdrHdl* pHdl, sal_Bool bAtBegin) ...@@ -2141,11 +2131,11 @@ void SdrHdlList::AddHdl(SdrHdl* pHdl, sal_Bool bAtBegin)
{ {
if (bAtBegin) if (bAtBegin)
{ {
aList.Insert(pHdl,sal_uIntPtr(0)); aList.push_front(pHdl);
} }
else else
{ {
aList.Insert(pHdl,CONTAINER_APPEND); aList.push_back(pHdl);
} }
pHdl->SetHdlList(this); pHdl->SetHdlList(this);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment