Store tree list entry items in ptr_vector & const correct-ness.

Change-Id: I0e02b9ceb98f26a2b130ec978a992fcf889e718a
This commit is contained in:
Kohei Yoshida 2012-11-15 15:59:48 -05:00
parent a2baeffbde
commit cc0c8e5643
6 changed files with 85 additions and 59 deletions

View file

@ -3476,8 +3476,8 @@ IMPL_LINK( SbaTableQueryBrowser, OnTreeEntryCompare, const SvSortData*, _pSortDa
return COMPARE_EQUAL;
}
SvLBoxString* pLeftTextItem = static_cast<SvLBoxString*>(pLHS->GetFirstItem(SV_ITEM_ID_LBOXSTRING));
SvLBoxString* pRightTextItem = static_cast<SvLBoxString*>(pRHS->GetFirstItem(SV_ITEM_ID_LBOXSTRING));
const SvLBoxString* pLeftTextItem = static_cast<const SvLBoxString*>(pLHS->GetFirstItem(SV_ITEM_ID_LBOXSTRING));
const SvLBoxString* pRightTextItem = static_cast<const SvLBoxString*>(pRHS->GetFirstItem(SV_ITEM_ID_LBOXSTRING));
OSL_ENSURE(pLeftTextItem && pRightTextItem, "SbaTableQueryBrowser::OnTreeEntryCompare: invalid text items!");
String sLeftText = pLeftTextItem->GetText();

View file

@ -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);
}

View file

@ -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 );

View file

@ -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;

View file

@ -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)

View file

@ -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
{
pItem = GetItem( nCur );
if (pItem->GetType() == nId)
return pItem;
nCur++;
return rItem.GetType() == mnId;
}
return 0;
};
class FindByPointer : std::unary_function<SvLBoxItem, void>
{
const SvLBoxItem* mpItem;
public:
FindByPointer(const SvLBoxItem* p) : mpItem(p) {}
bool operator() (const SvLBoxItem& rItem) const
{
return &rItem == mpItem;
}
};
}
sal_uInt16 SvTreeListEntry::GetPos( SvLBoxItem* pItem ) const
const SvLBoxItem* SvTreeListEntry::GetFirstItem( sal_uInt16 nId ) 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(), 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);
}
size_t SvTreeListEntry::GetPos( const SvLBoxItem* pItem ) const
{
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