Kaydet (Commit) fb01d8e1 authored tarafından Kohei Yoshida's avatar Kohei Yoshida

Use SvTreeListEntries to store child entries.

This replaces SvTreeEntryList.  The only thing to be wary of is that
now we use ptr_vector to store child entries, which changes the scheme
on the life cycle management of tree entries.

Change-Id: I92b6e41ea500bc9b9227259c010887b798194909
üst 9545c85d
......@@ -59,13 +59,13 @@ String SbaTableQueryBrowser::GetEntryText( SvTreeListEntry* _pEntry ) const
}
// -----------------------------------------------------------------------------
SbaTableQueryBrowser::EntryType SbaTableQueryBrowser::getEntryType( SvTreeListEntry* _pEntry ) const
SbaTableQueryBrowser::EntryType SbaTableQueryBrowser::getEntryType( const SvTreeListEntry* _pEntry ) const
{
if (!_pEntry)
return etUnknown;
SvTreeListEntry* pRootEntry = m_pTreeView->getListBox().GetRootLevelParent(_pEntry);
SvTreeListEntry* pEntryParent = m_pTreeView->getListBox().GetParent(_pEntry);
SvTreeListEntry* pRootEntry = m_pTreeView->getListBox().GetRootLevelParent(const_cast<SvTreeListEntry*>(_pEntry));
SvTreeListEntry* pEntryParent = m_pTreeView->getListBox().GetParent(const_cast<SvTreeListEntry*>(_pEntry));
SvTreeListEntry* pTables = m_pTreeView->getListBox().GetEntry(pRootEntry, CONTAINER_TABLES);
SvTreeListEntry* pQueries = m_pTreeView->getListBox().GetEntry(pRootEntry, CONTAINER_QUERIES);
......
......@@ -3440,8 +3440,8 @@ sal_Bool SbaTableQueryBrowser::ensureConnection( SvTreeListEntry* _pDSEntry, voi
// -----------------------------------------------------------------------------
IMPL_LINK( SbaTableQueryBrowser, OnTreeEntryCompare, const SvSortData*, _pSortData )
{
SvTreeListEntry* pLHS = static_cast<SvTreeListEntry*>(_pSortData->pLeft);
SvTreeListEntry* pRHS = static_cast<SvTreeListEntry*>(_pSortData->pRight);
const SvTreeListEntry* pLHS = static_cast<const SvTreeListEntry*>(_pSortData->pLeft);
const SvTreeListEntry* pRHS = static_cast<const SvTreeListEntry*>(_pSortData->pRight);
OSL_ENSURE(pLHS && pRHS, "SbaTableQueryBrowser::OnTreeEntryCompare: invalid tree entries!");
// we want the table entry and the end so we have to do a check
......@@ -3455,7 +3455,7 @@ IMPL_LINK( SbaTableQueryBrowser, OnTreeEntryCompare, const SvSortData*, _pSortDa
// every other container should be placed _before_ the bookmark container
return -1;
const String sLeft = m_pTreeView->getListBox().GetEntryText(pLHS);
const String sLeft = m_pTreeView->getListBox().GetEntryText(const_cast<SvTreeListEntry*>(pLHS));
EntryType eLeft = etTableContainer;
if (String(ModuleRes(RID_STR_TABLES_CONTAINER)) == sLeft)
......@@ -3866,14 +3866,14 @@ void SbaTableQueryBrowser::impl_cleanupDataSourceEntry( const String& _rDataSour
"SbaTableQueryBrowser::impl_cleanupDataSourceEntry: inconsistence (2)!");
// delete any user data of the child entries of the to-be-removed entry
std::pair<SvTreeEntryList::iterator,SvTreeEntryList::iterator> aIters =
std::pair<SvTreeListEntries::iterator, SvTreeListEntries::iterator> aIters =
m_pTreeModel->GetChildIterators(pDataSourceEntry);
SvTreeEntryList::const_iterator it = aIters.first, itEnd = aIters.second;
SvTreeListEntries::iterator it = aIters.first, itEnd = aIters.second;
for (; it != itEnd; ++it)
{
SvTreeListEntry* pEntry = *it;
SvTreeListEntry* pEntry = &(*it);
const DBTreeListUserData* pData = static_cast<const DBTreeListUserData*>(pEntry->GetUserData());
pEntry->SetUserData(NULL);
delete pData;
......
......@@ -111,14 +111,14 @@ DBTreeListBox::~DBTreeListBox()
SvTreeListEntry* DBTreeListBox::GetEntryPosByName( const String& aName, SvTreeListEntry* pStart, const IEntryFilter* _pFilter ) const
{
SvTreeList* myModel = GetModel();
std::pair<SvTreeEntryList::iterator,SvTreeEntryList::iterator> aIters =
std::pair<SvTreeListEntries::iterator,SvTreeListEntries::iterator> aIters =
myModel->GetChildIterators(pStart);
SvTreeListEntry* pEntry = NULL;
SvTreeEntryList::const_iterator it = aIters.first, itEnd = aIters.second;
SvTreeListEntries::iterator it = aIters.first, itEnd = aIters.second;
for (; it != itEnd; ++it)
{
pEntry = *it;
pEntry = &(*it);
const SvLBoxString* pItem = static_cast<const SvLBoxString*>(
pEntry->GetFirstItem(SV_ITEM_ID_LBOXSTRING));
......
......@@ -434,12 +434,12 @@ DBG_NAME(OTableSubscriptionPage)
//------------------------------------------------------------------------
IMPL_LINK( OTableSubscriptionPage, OnTreeEntryCompare, const SvSortData*, _pSortData )
{
SvTreeListEntry* pLHS = static_cast<SvTreeListEntry*>(_pSortData->pLeft);
SvTreeListEntry* pRHS = static_cast<SvTreeListEntry*>(_pSortData->pRight);
const SvTreeListEntry* pLHS = static_cast<const SvTreeListEntry*>(_pSortData->pLeft);
const SvTreeListEntry* pRHS = static_cast<const SvTreeListEntry*>(_pSortData->pRight);
OSL_ENSURE(pLHS && pRHS, "SbaTableQueryBrowser::OnTreeEntryCompare: invalid tree entries!");
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();
......
......@@ -342,11 +342,11 @@ namespace dbaui
TransferableHelper*
implCopyObject( SvTreeListEntry* _pApplyTo, sal_Int32 _nCommandType, sal_Bool _bAllowConnection = sal_True );
EntryType getEntryType( SvTreeListEntry* _pEntry ) const;
EntryType getEntryType( const SvTreeListEntry* _pEntry ) const;
EntryType getChildType( SvTreeListEntry* _pEntry ) const;
sal_Bool isObject( EntryType _eType ) const { return ( etTableOrView== _eType ) || ( etQuery == _eType ); }
sal_Bool isContainer( EntryType _eType ) const { return (etTableContainer == _eType) || (etQueryContainer == _eType); }
sal_Bool isContainer( SvTreeListEntry* _pEntry ) const { return isContainer( getEntryType( _pEntry ) ); }
bool isContainer( const SvTreeListEntry* _pEntry ) const { return isContainer( getEntryType( _pEntry ) ); }
// ensure that the xObject for the given entry is set on the user data
sal_Bool ensureEntryObject( SvTreeListEntry* _pEntry );
......
......@@ -167,8 +167,8 @@ enum SvSortMode { SortAscending, SortDescending, SortNone };
// ( Compare(a,b) ==> b.Compare(a) ==> strcmp(a,b) )
struct SvSortData
{
SvTreeListEntry* pLeft;
SvTreeListEntry* pRight;
const SvTreeListEntry* pLeft;
const SvTreeListEntry* pRight;
};
class SVT_DLLPUBLIC SvTreeList
......@@ -214,13 +214,15 @@ class SVT_DLLPUBLIC SvTreeList
void Collapse( SvListView*,SvTreeListEntry* pParent );
SVT_DLLPRIVATE void SetAbsolutePositions();
SVT_DLLPRIVATE SvTreeEntryList*CloneChildren(
SvTreeEntryList* pChildren,
SvTreeListEntry* pNewParent,
sal_uLong& nCloneCount
) const;
SVT_DLLPRIVATE void SetListPositions( SvTreeEntryList* );
SVT_DLLPRIVATE void CloneChildren(
SvTreeListEntries& rDst, sal_uLong& rCloneCount, SvTreeListEntries& rSrc, SvTreeListEntry* pNewParent) const;
/**
* Invalidate the cached position data to have them re-generated before
* the next access.
*/
SVT_DLLPRIVATE void SetListPositions( SvTreeListEntries& rEntries );
// rPos wird bei SortModeNone nicht geaendert
SVT_DLLPRIVATE void GetInsertionPos(
......@@ -295,12 +297,13 @@ public:
SvTreeListEntry* GetEntryAtAbsPos( sal_uLong nAbsPos ) const;
SvTreeListEntry* GetParent( SvTreeListEntry* pEntry ) const;
SvTreeListEntry* GetRootLevelParent( SvTreeListEntry* pEntry ) const;
SvTreeEntryList* GetChildList( SvTreeListEntry* pParent ) const;
const SvTreeListEntries& GetChildList( SvTreeListEntry* pParent ) const;
SvTreeListEntries& GetChildList( SvTreeListEntry* pParent );
std::pair<SvTreeEntryList::const_iterator,SvTreeEntryList::const_iterator>
std::pair<SvTreeListEntries::const_iterator, SvTreeListEntries::const_iterator>
GetChildIterators(const SvTreeListEntry* pParent) const;
std::pair<SvTreeEntryList::iterator,SvTreeEntryList::iterator>
std::pair<SvTreeListEntries::iterator, SvTreeListEntries::iterator>
GetChildIterators(SvTreeListEntry* pParent);
sal_uLong GetAbsPos( SvTreeListEntry* pEntry ) const;
......@@ -325,7 +328,7 @@ public:
const Link& GetCloneLink() const
{ return aCloneLink; }
virtual SvTreeListEntry* CloneEntry( SvTreeListEntry* ) const; // ruft den Clone-Link
virtual SvTreeListEntry* CloneEntry( SvTreeListEntry* pSource ) const; // ruft den Clone-Link
virtual SvTreeListEntry* CreateEntry() const; // zum 'new'en von Entries
sal_uInt16 GetRefCount() const { return nRefCount; }
......@@ -333,7 +336,7 @@ public:
void SetSortMode( SvSortMode eMode ) { eSortMode = eMode; }
SvSortMode GetSortMode() const { return eSortMode; }
virtual StringCompare Compare( SvTreeListEntry*, SvTreeListEntry* ) const;
StringCompare Compare(const SvTreeListEntry* pLeft, const SvTreeListEntry* pRight) const;
void SetCompareHdl( const Link& rLink ) { aCompareLink = rLink; }
const Link& GetCompareHdl() const { return aCompareLink; }
void Resort();
......
......@@ -33,6 +33,7 @@
#include "tools/solar.h"
#include <vector>
#include <boost/ptr_container/ptr_vector.hpp>
// Flags, die am Model haengen
#define SV_ENTRYFLAG_CHILDREN_ON_DEMAND 0x0001
......@@ -48,6 +49,9 @@
class SvTreeEntryList;
class SvLBoxItem;
class SvTreeListEntry;
typedef boost::ptr_vector<SvTreeListEntry> SvTreeListEntries;
class SVT_DLLPUBLIC SvTreeListEntry
{
......@@ -56,7 +60,7 @@ class SVT_DLLPUBLIC SvTreeListEntry
friend class SvTreeListBox;
SvTreeListEntry* pParent;
SvTreeEntryList* pChildren;
SvTreeListEntries maChildren;
sal_uLong nAbsPos;
sal_uLong nListPos;
std::vector<SvLBoxItem*> aItems;
......@@ -64,9 +68,10 @@ class SVT_DLLPUBLIC SvTreeListEntry
sal_uInt16 nEntryFlags;
private:
SVT_DLLPRIVATE void SetListPositions();
SVT_DLLPRIVATE void InvalidateChildrensListPositions();
SVT_DLLPRIVATE void DeleteItems_Impl();
void ClearChildren();
void SetListPositions();
void InvalidateChildrensListPositions();
void DeleteItems_Impl();
public:
SvTreeListEntry();
......@@ -87,7 +92,7 @@ public:
void AddItem( SvLBoxItem* pItem );
void ReplaceItem( SvLBoxItem* pNewItem, sal_uInt16 nPos );
SvLBoxItem* GetItem( sal_uInt16 nPos ) const;
SvLBoxItem* GetFirstItem( sal_uInt16 nId );
SvLBoxItem* GetFirstItem( sal_uInt16 nId ) const;
sal_uInt16 GetPos( SvLBoxItem* pItem ) const;
void* GetUserData() const;
void SetUserData( void* pPtr );
......
......@@ -1659,7 +1659,7 @@ void SvImpLBox::RemovingEntry( SvTreeListEntry* pEntry )
SvTreeListEntry* pParent = (SvTreeListEntry*)(pView->GetModel()->GetParent(pEntry));
if( pParent && pView->GetModel()->GetChildList(pParent)->size() == 1 )
if (pParent && pView->GetModel()->GetChildList(pParent).size() == 1)
{
DBG_ASSERT( pView->IsExpanded( pParent ), "Parent not expanded");
pParent->SetFlags( pParent->GetFlags() | SV_ENTRYFLAG_NO_NODEBMP);
......@@ -1825,7 +1825,7 @@ void SvImpLBox::EntryInserted( SvTreeListEntry* pEntry )
if( GetUpdateMode() )
{
SvTreeListEntry* pParent = (SvTreeListEntry*)pTree->GetParent(pEntry);
if( pParent && pTree->GetChildList(pParent)->size() == 1 )
if (pParent && pTree->GetChildList(pParent).size() == 1)
// draw plus sign
pTree->InvalidateEntry( pParent );
......@@ -2460,7 +2460,7 @@ bool SvImpLBox::KeyInput( const KeyEvent& rKEvt)
sal_uInt16 nRefDepth;
// special case explorer: if the root only has a single
// entry, don't collapse the root entry
if( pTree->GetChildList(0)->size() < 2 )
if (pTree->GetChildList(0).size() < 2)
{
nRefDepth = 1;
pParentToCollapse = pCursor;
......@@ -3303,15 +3303,12 @@ void SvImpLBox::FindMostRight( SvTreeListEntry* pParent, SvTreeListEntry* pEntry
void SvImpLBox::FindMostRight_Impl( SvTreeListEntry* pParent, SvTreeListEntry* pEntryToIgnore )
{
SvTreeEntryList* pList = pTree->GetChildList( pParent );
SvTreeListEntries& rList = pTree->GetChildList( pParent );
if( !pList )
return;
size_t nCount = pList->size();
size_t nCount = rList.size();
for( size_t nCur = 0; nCur < nCount; nCur++ )
{
SvTreeListEntry* pChild = (SvTreeListEntry*)(*pList)[ nCur ];
SvTreeListEntry* pChild = &rList[nCur];
if( pChild != pEntryToIgnore )
{
SetMostRight( pChild );
......
......@@ -30,21 +30,24 @@
#include "svtools/treelist.hxx"
#include "svtools/treelistbox.hxx"
void SvTreeListEntry::ClearChildren()
{
maChildren.clear();
}
void SvTreeListEntry::SetListPositions()
{
if( pChildren )
SvTreeListEntries::iterator it = maChildren.begin(), itEnd = maChildren.end();
sal_uLong nCur = 0;
for (; it != itEnd; ++it)
{
SvTreeEntryList::iterator it = pChildren->begin(), itEnd = pChildren->end();
sal_uLong nCur = 0;
for (; it != itEnd; ++it)
{
SvTreeListEntry* pEntry = *it;
pEntry->nListPos &= 0x80000000;
pEntry->nListPos |= nCur;
++nCur;
}
SvTreeListEntry& rEntry = *it;
rEntry.nListPos &= 0x80000000;
rEntry.nListPos |= nCur;
++nCur;
}
nListPos &= (~0x80000000);
nListPos &= (~0x80000000); // remove the invalid bit.
}
void SvTreeListEntry::InvalidateChildrensListPositions()
......@@ -66,7 +69,6 @@ void SvTreeListEntry::DeleteItems_Impl()
SvTreeListEntry::SvTreeListEntry() :
pParent(NULL),
pChildren(NULL),
nAbsPos(0),
nListPos(0),
pUserData(NULL),
......@@ -76,30 +78,27 @@ SvTreeListEntry::SvTreeListEntry() :
SvTreeListEntry::SvTreeListEntry(const SvTreeListEntry& r) :
pParent(NULL),
pChildren(NULL),
nAbsPos(r.nAbsPos),
nListPos(r.nListPos & 0x7FFFFFFF)
{
SvTreeListEntries::const_iterator it = r.maChildren.begin(), itEnd = r.maChildren.end();
for (; it != itEnd; ++it)
maChildren.push_back(new SvTreeListEntry(*it));
}
SvTreeListEntry::~SvTreeListEntry()
{
if ( pChildren )
{
pChildren->DestroyAll();
delete pChildren;
}
#ifdef DBG_UTIL
pChildren = 0;
pParent = 0;
#endif
maChildren.clear();
DeleteItems_Impl();
}
bool SvTreeListEntry::HasChildren() const
{
return pChildren != NULL;
return !maChildren.empty();
}
bool SvTreeListEntry::HasChildListPos() const
......@@ -172,7 +171,7 @@ SvLBoxItem* SvTreeListEntry::GetItem( sal_uInt16 nPos ) const
return aItems[nPos];
}
SvLBoxItem* SvTreeListEntry::GetFirstItem( sal_uInt16 nId )
SvLBoxItem* SvTreeListEntry::GetFirstItem( sal_uInt16 nId ) const
{
sal_uInt16 nCount = aItems.size();
sal_uInt16 nCur = 0;
......
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