summaryrefslogtreecommitdiff
path: root/svtools
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@gmail.com>2012-11-15 15:59:48 -0500
committerKohei Yoshida <kohei.yoshida@gmail.com>2012-11-15 16:02:46 -0500
commitcc0c8e56436d35e726efe7f8d06cf403fcaf827e (patch)
tree1b6639f5bb390a2228a795f49bb56ffcc406bfa4 /svtools
parenta2baeffbde83535c8cb2056006345b4d01265b90 (diff)
Store tree list entry items in ptr_vector & const correct-ness.
Change-Id: I0e02b9ceb98f26a2b130ec978a992fcf889e718a
Diffstat (limited to 'svtools')
-rw-r--r--svtools/inc/svtools/treelistbox.hxx2
-rw-r--r--svtools/inc/svtools/treelistentry.hxx20
-rw-r--r--svtools/source/contnr/svimpbox.cxx2
-rw-r--r--svtools/source/contnr/svtabbx.cxx2
-rw-r--r--svtools/source/contnr/treelistentry.cxx114
5 files changed, 83 insertions, 57 deletions
diff --git a/svtools/inc/svtools/treelistbox.hxx b/svtools/inc/svtools/treelistbox.hxx
index ce4bba1b170f..8ec235de4408 100644
--- a/svtools/inc/svtools/treelistbox.hxx
+++ b/svtools/inc/svtools/treelistbox.hxx
@@ -835,7 +835,7 @@ inline SvViewDataItem* SvTreeListBox::GetViewDataItem( SvTreeListEntry* pEntry,
(SvViewDataEntry*)SvListView::GetViewData(pEntry);
DBG_ASSERT(pEntryData,"Entry not in View");
DBG_ASSERT(pEntryData->pItemData,"No ItemData");
- sal_uInt16 nItemPos = ((SvTreeListEntry*)pEntry)->GetPos( pItem );
+ sal_uInt16 nItemPos = pEntry->GetPos(pItem);
return (pEntryData->pItemData+nItemPos);
}
diff --git a/svtools/inc/svtools/treelistentry.hxx b/svtools/inc/svtools/treelistentry.hxx
index 37a0ba131d49..7eb015c7199b 100644
--- a/svtools/inc/svtools/treelistentry.hxx
+++ b/svtools/inc/svtools/treelistentry.hxx
@@ -32,7 +32,6 @@
#include "svtdllapi.h"
#include "tools/solar.h"
-#include <vector>
#include <boost/ptr_container/ptr_vector.hpp>
// Flags, die am Model haengen
@@ -58,11 +57,13 @@ class SVT_DLLPUBLIC SvTreeListEntry
friend class SvListView;
friend class SvTreeListBox;
+ typedef boost::ptr_vector<SvLBoxItem> ItemsType;
+
SvTreeListEntry* pParent;
SvTreeListEntries maChildren;
sal_uLong nAbsPos;
sal_uLong nListPos;
- std::vector<SvLBoxItem*> aItems;
+ ItemsType maItems;
void* pUserData;
sal_uInt16 nEntryFlags;
@@ -70,9 +71,10 @@ private:
void ClearChildren();
void SetListPositions();
void InvalidateChildrensListPositions();
- void DeleteItems_Impl();
public:
+ static size_t ITEM_NOT_FOUND;
+
SvTreeListEntry();
SvTreeListEntry(const SvTreeListEntry& r);
virtual ~SvTreeListEntry();
@@ -86,16 +88,18 @@ public:
void Clone(SvTreeListEntry* pSource);
- sal_uInt16 ItemCount() const;
+ size_t ItemCount() const;
// DARF NUR GERUFEN WERDEN, WENN DER EINTRAG NOCH NICHT IM MODEL
// EINGEFUEGT IST, DA SONST FUER DAS ITEM KEINE VIEW-ABHAENGIGEN
// DATEN ALLOZIERT WERDEN!
void AddItem( SvLBoxItem* pItem );
- void ReplaceItem( SvLBoxItem* pNewItem, sal_uInt16 nPos );
- SvLBoxItem* GetItem( sal_uInt16 nPos ) const;
- SvLBoxItem* GetFirstItem( sal_uInt16 nId ) const;
- sal_uInt16 GetPos( SvLBoxItem* pItem ) const;
+ void ReplaceItem( SvLBoxItem* pNewItem, size_t nPos );
+ const SvLBoxItem* GetItem( size_t nPos ) const;
+ SvLBoxItem* GetItem( size_t nPos );
+ const SvLBoxItem* GetFirstItem( sal_uInt16 nId ) const;
+ SvLBoxItem* GetFirstItem( sal_uInt16 nId );
+ size_t GetPos( const SvLBoxItem* pItem ) const;
void* GetUserData() const;
void SetUserData( void* pPtr );
void EnableChildrenOnDemand( bool bEnable=true );
diff --git a/svtools/source/contnr/svimpbox.cxx b/svtools/source/contnr/svimpbox.cxx
index 5f90b8fd7c7f..06145918f11d 100644
--- a/svtools/source/contnr/svimpbox.cxx
+++ b/svtools/source/contnr/svimpbox.cxx
@@ -229,7 +229,7 @@ void SvImpLBox::CalcCellFocusRect( SvTreeListEntry* pEntry, Rectangle& rRect )
SvLBoxItem* pItem = pCursor->GetItem( nCurTabPos );
rRect.Left() = pView->GetTab( pCursor, pItem )->GetPos();
}
- if ( pCursor->ItemCount() > ( nCurTabPos + 1 ) )
+ if (pCursor->ItemCount() > static_cast<size_t>(nCurTabPos+1))
{
SvLBoxItem* pNextItem = pCursor->GetItem( nCurTabPos + 1 );
long nRight = pView->GetTab( pCursor, pNextItem )->GetPos() - 1;
diff --git a/svtools/source/contnr/svtabbx.cxx b/svtools/source/contnr/svtabbx.cxx
index 8938104c8937..929c429cc00c 100644
--- a/svtools/source/contnr/svtabbx.cxx
+++ b/svtools/source/contnr/svtabbx.cxx
@@ -375,7 +375,7 @@ String SvTabListBox::GetCellText( sal_uLong nPos, sal_uInt16 nCol ) const
SvTreeListEntry* pEntry = GetEntryOnPos( nPos );
DBG_ASSERT( pEntry, "SvTabListBox::GetCellText(): Invalid Entry" );
XubString aResult;
- if ( pEntry && pEntry->ItemCount() > ( nCol + 1 ) )
+ if (pEntry && pEntry->ItemCount() > static_cast<size_t>(nCol+1))
{
const SvLBoxItem* pStr = pEntry->GetItem( nCol + 1 );
if (pStr && pStr->GetType() == SV_ITEM_ID_LBOXSTRING)
diff --git a/svtools/source/contnr/treelistentry.cxx b/svtools/source/contnr/treelistentry.cxx
index b6a5977fe553..b98b24af9bf5 100644
--- a/svtools/source/contnr/treelistentry.cxx
+++ b/svtools/source/contnr/treelistentry.cxx
@@ -30,6 +30,10 @@
#include "svtools/treelist.hxx"
#include "svtools/treelistbox.hxx"
+#include <limits>
+
+size_t SvTreeListEntry::ITEM_NOT_FOUND = std::numeric_limits<size_t>::max();
+
void SvTreeListEntry::ClearChildren()
{
maChildren.clear();
@@ -55,18 +59,6 @@ void SvTreeListEntry::InvalidateChildrensListPositions()
nListPos |= 0x80000000;
}
-void SvTreeListEntry::DeleteItems_Impl()
-{
- sal_uInt16 nCount = aItems.size();
- while( nCount )
- {
- nCount--;
- SvLBoxItem* pItem = aItems[ nCount ];
- delete pItem;
- }
- aItems.clear();
-}
-
SvTreeListEntry::SvTreeListEntry() :
pParent(NULL),
nAbsPos(0),
@@ -93,7 +85,7 @@ SvTreeListEntry::~SvTreeListEntry()
#endif
maChildren.clear();
- DeleteItems_Impl();
+ maItems.clear();
}
bool SvTreeListEntry::HasChildren() const
@@ -132,29 +124,28 @@ void SvTreeListEntry::Clone(SvTreeListEntry* pSource)
nAbsPos = pSource->nAbsPos;
SvLBoxItem* pNewItem;
- DeleteItems_Impl();
- sal_uInt16 nCount = ((SvTreeListEntry*)pSource)->ItemCount();
- sal_uInt16 nCurPos = 0;
- while( nCurPos < nCount )
+ maItems.clear();
+ ItemsType::iterator it = pSource->maItems.begin(), itEnd = pSource->maItems.end();
+ for (; it != itEnd; ++it)
{
- SvLBoxItem* pItem = ((SvTreeListEntry*)pSource)->GetItem( nCurPos );
+ SvLBoxItem* pItem = &(*it);
pNewItem = pItem->Create();
- pNewItem->Clone( pItem );
- AddItem( pNewItem );
- nCurPos++;
+ pNewItem->Clone(pItem);
+ maItems.push_back(pNewItem);
}
- pUserData = ((SvTreeListEntry*)pSource)->GetUserData();
- nEntryFlags = ((SvTreeListEntry*)pSource)->nEntryFlags;
+
+ pUserData = pSource->GetUserData();
+ nEntryFlags = pSource->nEntryFlags;
}
-sal_uInt16 SvTreeListEntry::ItemCount() const
+size_t SvTreeListEntry::ItemCount() const
{
- return (sal_uInt16)aItems.size();
+ return maItems.size();
}
void SvTreeListEntry::AddItem( SvLBoxItem* pItem )
{
- aItems.push_back( pItem );
+ maItems.push_back( pItem );
}
void SvTreeListEntry::EnableChildrenOnDemand( bool bEnable )
@@ -165,41 +156,72 @@ void SvTreeListEntry::EnableChildrenOnDemand( bool bEnable )
nEntryFlags &= (~SV_ENTRYFLAG_CHILDREN_ON_DEMAND);
}
-void SvTreeListEntry::ReplaceItem( SvLBoxItem* pNewItem, sal_uInt16 nPos )
+void SvTreeListEntry::ReplaceItem( SvLBoxItem* pNewItem, size_t nPos )
{
DBG_ASSERT(pNewItem,"ReplaceItem:No Item");
- SvLBoxItem* pOld = GetItem( nPos );
- if ( pOld )
+ if (nPos >= maItems.size())
{
- aItems[ nPos ] = pNewItem;
- delete pOld;
+ // Out of bound. Bail out.
+ delete pNewItem;
+ return;
}
+
+ maItems.erase(maItems.begin()+nPos);
+ maItems.insert(maItems.begin()+nPos, pNewItem);
}
-SvLBoxItem* SvTreeListEntry::GetItem( sal_uInt16 nPos ) const
+const SvLBoxItem* SvTreeListEntry::GetItem( size_t nPos ) const
{
- return aItems[nPos];
+ return &maItems[nPos];
}
-SvLBoxItem* SvTreeListEntry::GetFirstItem( sal_uInt16 nId ) const
+SvLBoxItem* SvTreeListEntry::GetItem( size_t nPos )
{
- sal_uInt16 nCount = aItems.size();
- sal_uInt16 nCur = 0;
- SvLBoxItem* pItem;
- while( nCur < nCount )
+ return &maItems[nPos];
+}
+
+namespace {
+
+class FindByType : std::unary_function<SvLBoxItem, void>
+{
+ sal_uInt16 mnId;
+public:
+ FindByType(sal_uInt16 nId) : mnId(nId) {}
+ bool operator() (const SvLBoxItem& rItem) const
+ {
+ return rItem.GetType() == mnId;
+ }
+};
+
+class FindByPointer : std::unary_function<SvLBoxItem, void>
+{
+ const SvLBoxItem* mpItem;
+public:
+ FindByPointer(const SvLBoxItem* p) : mpItem(p) {}
+ bool operator() (const SvLBoxItem& rItem) const
{
- pItem = GetItem( nCur );
- if (pItem->GetType() == nId)
- return pItem;
- nCur++;
+ return &rItem == mpItem;
}
- return 0;
+};
+
+}
+
+const SvLBoxItem* SvTreeListEntry::GetFirstItem( sal_uInt16 nId ) const
+{
+ ItemsType::const_iterator it = std::find_if(maItems.begin(), maItems.end(), FindByType(nId));
+ return it == maItems.end() ? NULL : &(*it);
+}
+
+SvLBoxItem* SvTreeListEntry::GetFirstItem( sal_uInt16 nId )
+{
+ ItemsType::iterator it = std::find_if(maItems.begin(), maItems.end(), FindByType(nId));
+ return it == maItems.end() ? NULL : &(*it);
}
-sal_uInt16 SvTreeListEntry::GetPos( SvLBoxItem* pItem ) const
+size_t SvTreeListEntry::GetPos( const SvLBoxItem* pItem ) const
{
- std::vector<SvLBoxItem*>::const_iterator it = std::find( aItems.begin(), aItems.end(), pItem );
- return it == aItems.end() ? USHRT_MAX : it - aItems.begin();
+ ItemsType::const_iterator it = std::find_if(maItems.begin(), maItems.end(), FindByPointer(pItem));
+ return it == maItems.end() ? ITEM_NOT_FOUND : std::distance(maItems.begin(), it);
}
void* SvTreeListEntry::GetUserData() const