[Libreoffice-commits] .: svtools/inc svtools/source
Joseph Powers
jpowers at kemper.freedesktop.org
Mon May 23 19:50:30 PDT 2011
svtools/inc/svtools/treelist.hxx | 181 ++++++++++++++++++++-----------------
svtools/source/contnr/treelist.cxx | 31 +++---
2 files changed, 115 insertions(+), 97 deletions(-)
New commits:
commit ea6f2fa1898e3fc593ede05bbbf01beac10711a4
Author: Joseph Powers <jpowers27 at cox.net>
Date: Mon May 23 19:49:46 2011 -0700
Replace the List in SvTreeList with a vector<>
Also fixed a small bug:
SvTreeEntryList::GetPos() would return 0 for not found; however, everywhere
the function was used, it was checked against ULONG_MAX as beging not found.
diff --git a/svtools/inc/svtools/treelist.hxx b/svtools/inc/svtools/treelist.hxx
index 53d6ff7..b757570 100644
--- a/svtools/inc/svtools/treelist.hxx
+++ b/svtools/inc/svtools/treelist.hxx
@@ -31,7 +31,6 @@
#include "svtools/svtdllapi.h"
#include <tools/solar.h>
-#include <tools/list.hxx>
#include <vector>
#include <tools/table.hxx>
@@ -192,57 +191,63 @@ struct SvSortData
//=============================================================================
+typedef ::std::vector< SvListView* > SvViewList_impl;
+
class SVT_DLLPUBLIC SvTreeList
{
friend class SvListView;
- List aViewList;
- sal_uLong nEntryCount;
+ SvViewList_impl aViewList;
+ sal_uLong nEntryCount;
- Link aCloneLink;
- Link aCompareLink;
- SvSortMode eSortMode;
+ Link aCloneLink;
+ Link aCompareLink;
+ SvSortMode eSortMode;
- sal_uInt16 nRefCount;
+ sal_uInt16 nRefCount;
- sal_Bool bAbsPositionsValid;
+ sal_Bool bAbsPositionsValid;
SvListEntry* FirstVisible() const { return First(); }
SvListEntry* NextVisible( const SvListView*,SvListEntry* pEntry, sal_uInt16* pDepth=0 ) const;
- SvListEntry* PrevVisible( const SvListView*,SvListEntry* pEntry, sal_uInt16* pDepth=0 ) const;
- SvListEntry* LastVisible( const SvListView*,sal_uInt16* pDepth=0 ) const;
- SvListEntry* NextVisible( const SvListView*,SvListEntry* pEntry, sal_uInt16& rDelta ) const;
- SvListEntry* PrevVisible( const SvListView*,SvListEntry* pEntry, sal_uInt16& rDelta ) const;
+ SvListEntry* PrevVisible( const SvListView*,SvListEntry* pEntry, sal_uInt16* pDepth=0 ) const;
+ SvListEntry* LastVisible( const SvListView*,sal_uInt16* pDepth=0 ) const;
+ SvListEntry* NextVisible( const SvListView*,SvListEntry* pEntry, sal_uInt16& rDelta ) const;
+ SvListEntry* PrevVisible( const SvListView*,SvListEntry* pEntry, sal_uInt16& rDelta ) const;
- sal_Bool IsEntryVisible( const SvListView*,SvListEntry* pEntry ) const;
- SvListEntry* GetEntryAtVisPos( const SvListView*,sal_uLong nVisPos ) const;
- sal_uLong GetVisiblePos( const SvListView*,SvListEntry* pEntry ) const;
- sal_uLong GetVisibleCount( const SvListView* ) const;
- sal_uLong GetVisibleChildCount( const SvListView*,SvListEntry* pParent ) const;
+ sal_Bool IsEntryVisible( const SvListView*,SvListEntry* pEntry ) const;
+ SvListEntry* GetEntryAtVisPos( const SvListView*,sal_uLong nVisPos ) const;
+ sal_uLong GetVisiblePos( const SvListView*,SvListEntry* pEntry ) const;
+ sal_uLong GetVisibleCount( const SvListView* ) const;
+ sal_uLong GetVisibleChildCount( const SvListView*,SvListEntry* pParent ) const;
SvListEntry* FirstSelected( const SvListView*) const;
SvListEntry* NextSelected( const SvListView*,SvListEntry* pEntry ) const;
- SvListEntry* PrevSelected( const SvListView*,SvListEntry* pEntry ) const;
- SvListEntry* LastSelected( const SvListView*) const;
+ SvListEntry* PrevSelected( const SvListView*,SvListEntry* pEntry ) const;
+ SvListEntry* LastSelected( const SvListView*) const;
- sal_Bool Select( SvListView*,SvListEntry* pEntry, sal_Bool bSelect=sal_True );
- sal_uLong SelectChilds( SvListView*,SvListEntry* pParent, sal_Bool bSelect );
- void SelectAll( SvListView*,sal_Bool bSelect ); // ruft nicht Select-Hdl
- sal_uLong GetChildSelectionCount( const SvListView*,SvListEntry* pParent ) const;
+ sal_Bool Select( SvListView*,SvListEntry* pEntry, sal_Bool bSelect=sal_True );
+ sal_uLong SelectChilds( SvListView*,SvListEntry* pParent, sal_Bool bSelect );
+ void SelectAll( SvListView*,sal_Bool bSelect ); // ruft nicht Select-Hdl
+ sal_uLong GetChildSelectionCount( const SvListView*,SvListEntry* pParent ) const;
void Expand( SvListView*,SvListEntry* pParent );
void Collapse( SvListView*,SvListEntry* pParent );
- SVT_DLLPRIVATE void SetAbsolutePositions();
- SVT_DLLPRIVATE SvTreeEntryList*CloneChilds( SvTreeEntryList* pChilds,
- SvListEntry* pNewParent,
- sal_uLong& nCloneCount ) const;
- SVT_DLLPRIVATE void SetListPositions( SvTreeEntryList* );
+ SVT_DLLPRIVATE void SetAbsolutePositions();
+ SVT_DLLPRIVATE SvTreeEntryList* CloneChilds( SvTreeEntryList* pChilds,
+ SvListEntry* pNewParent,
+ sal_uLong& nCloneCount
+ ) const;
+ SVT_DLLPRIVATE void SetListPositions( SvTreeEntryList* );
// rPos wird bei SortModeNone nicht geaendert
- SVT_DLLPRIVATE void GetInsertionPos( SvListEntry* pEntry, SvListEntry* pParent,
- sal_uLong& rPos );
- SVT_DLLPRIVATE void ResortChilds( SvListEntry* pParent );
+ SVT_DLLPRIVATE void GetInsertionPos(
+ SvListEntry* pEntry,
+ SvListEntry* pParent,
+ sal_uLong& rPos
+ );
+ SVT_DLLPRIVATE void ResortChilds( SvListEntry* pParent );
protected:
@@ -250,62 +255,72 @@ protected:
public:
- SvTreeList();
- virtual ~SvTreeList();
-
- void InsertView( SvListView* );
- void RemoveView( SvListView* );
- sal_uLong GetViewCount() const { return aViewList.Count(); }
- SvListView* GetView(sal_uLong nPos) const {return (SvListView*)aViewList.GetObject(nPos);}
- void Broadcast( sal_uInt16 nActionId, SvListEntry* pEntry1=0,
- SvListEntry* pEntry2=0, sal_uLong nPos=0 );
+ SvTreeList();
+ virtual ~SvTreeList();
+
+ void InsertView( SvListView* );
+ void RemoveView( SvListView* );
+ sal_uLong GetViewCount() const { return aViewList.size(); }
+ SvListView* GetView(sal_uLong nPos) const {
+ return ( nPos < aViewList.size() ) ? aViewList[ nPos ] : NULL;
+ }
+
+ void Broadcast(
+ sal_uInt16 nActionId,
+ SvListEntry* pEntry1=0,
+ SvListEntry* pEntry2=0,
+ sal_uLong nPos=0
+ );
// informiert alle Listener
- void InvalidateEntry( SvListEntry* );
+ void InvalidateEntry( SvListEntry* );
- sal_uLong GetEntryCount() const { return nEntryCount; }
+ sal_uLong GetEntryCount() const { return nEntryCount; }
SvListEntry* First() const;
SvListEntry* Next( SvListEntry* pEntry, sal_uInt16* pDepth=0 ) const;
- SvListEntry* Prev( SvListEntry* pEntry, sal_uInt16* pDepth=0 ) const;
- SvListEntry* Last( sal_uInt16* pDepth=0 ) const;
-
- SvListEntry* FirstChild( SvListEntry* pParent ) const;
- SvListEntry* NextSibling( SvListEntry* pEntry ) const;
- SvListEntry* PrevSibling( SvListEntry* pEntry ) const;
- SvListEntry* LastSibling( SvListEntry* pEntry ) const;
-
- sal_uLong Insert( SvListEntry* pEntry,SvListEntry* pPar,sal_uLong nPos=LIST_APPEND);
- sal_uLong Insert( SvListEntry* pEntry,sal_uLong nRootPos = LIST_APPEND ) { return Insert(pEntry, pRootItem, nRootPos ); }
- void InsertTree( SvListEntry* pTree, SvListEntry* pTarget );
- void InsertTree( SvListEntry* pTree, SvListEntry* pTargetParent,
- sal_uLong nListPos );
+ SvListEntry* Prev( SvListEntry* pEntry, sal_uInt16* pDepth=0 ) const;
+ SvListEntry* Last( sal_uInt16* pDepth=0 ) const;
+
+ SvListEntry* FirstChild( SvListEntry* pParent ) const;
+ SvListEntry* NextSibling( SvListEntry* pEntry ) const;
+ SvListEntry* PrevSibling( SvListEntry* pEntry ) const;
+ SvListEntry* LastSibling( SvListEntry* pEntry ) const;
+
+ sal_uLong Insert( SvListEntry* pEntry,SvListEntry* pPar,sal_uLong nPos=ULONG_MAX);
+ sal_uLong Insert( SvListEntry* pEntry,sal_uLong nRootPos = ULONG_MAX ) { return Insert(pEntry, pRootItem, nRootPos ); }
+ void InsertTree( SvListEntry* pTree, SvListEntry* pTarget );
+ void InsertTree(
+ SvListEntry* pTree,
+ SvListEntry* pTargetParent,
+ sal_uLong nListPos
+ );
// Entries muessen im gleichen Model stehen!
void Move( SvListEntry* pSource, SvListEntry* pTarget );
// erzeugt ggf. Child-List
- sal_uLong Move( SvListEntry* pSource, SvListEntry* pTargetParent,
+ sal_uLong Move( SvListEntry* pSource, SvListEntry* pTargetParent,
sal_uLong nListPos);
- void Copy( SvListEntry* pSource, SvListEntry* pTarget );
- sal_uLong Copy( SvListEntry* pSource, SvListEntry* pTargetParent,
+ void Copy( SvListEntry* pSource, SvListEntry* pTarget );
+ sal_uLong Copy( SvListEntry* pSource, SvListEntry* pTargetParent,
sal_uLong nListPos);
- sal_Bool Remove( SvListEntry* pEntry );
+ sal_Bool Remove( SvListEntry* pEntry );
void Clear();
- sal_Bool HasChilds( SvListEntry* pEntry ) const;
- sal_Bool HasParent( SvListEntry* pEntry ) const { return (sal_Bool)(pEntry->pParent!=pRootItem); }
- sal_Bool IsChild( SvListEntry* pParent, SvListEntry* pChild ) const;
- sal_Bool IsInChildList( SvListEntry* pParent, SvListEntry* pChild) const;
- SvListEntry* GetEntry( SvListEntry* pParent, sal_uLong nPos ) const;
- SvListEntry* GetEntry( sal_uLong nRootPos ) const;
- SvListEntry* GetEntryAtAbsPos( sal_uLong nAbsPos ) const;
- SvListEntry* GetParent( SvListEntry* pEntry ) const;
- SvListEntry* GetRootLevelParent( SvListEntry* pEntry ) const;
- SvTreeEntryList* GetChildList( SvListEntry* pParent ) const;
-
- sal_uLong GetAbsPos( SvListEntry* pEntry ) const;
- sal_uLong GetRelPos( SvListEntry* pChild ) const { return pChild->GetChildListPos(); }
- sal_uLong GetChildCount( SvListEntry* pParent ) const;
- sal_uInt16 GetDepth( SvListEntry* pEntry ) const;
- sal_Bool IsAtRootDepth( SvListEntry* pEntry ) const { return (sal_Bool)(pEntry->pParent==pRootItem); }
+ sal_Bool HasChilds( SvListEntry* pEntry ) const;
+ sal_Bool HasParent( SvListEntry* pEntry ) const { return (sal_Bool)(pEntry->pParent!=pRootItem); }
+ sal_Bool IsChild( SvListEntry* pParent, SvListEntry* pChild ) const;
+ sal_Bool IsInChildList( SvListEntry* pParent, SvListEntry* pChild) const;
+ SvListEntry* GetEntry( SvListEntry* pParent, sal_uLong nPos ) const;
+ SvListEntry* GetEntry( sal_uLong nRootPos ) const;
+ SvListEntry* GetEntryAtAbsPos( sal_uLong nAbsPos ) const;
+ SvListEntry* GetParent( SvListEntry* pEntry ) const;
+ SvListEntry* GetRootLevelParent( SvListEntry* pEntry ) const;
+ SvTreeEntryList* GetChildList( SvListEntry* pParent ) const;
+
+ sal_uLong GetAbsPos( SvListEntry* pEntry ) const;
+ sal_uLong GetRelPos( SvListEntry* pChild ) const { return pChild->GetChildListPos(); }
+ sal_uLong GetChildCount( SvListEntry* pParent ) const;
+ sal_uInt16 GetDepth( SvListEntry* pEntry ) const;
+ sal_Bool IsAtRootDepth( SvListEntry* pEntry ) const { return (sal_Bool)(pEntry->pParent==pRootItem); }
// das Model ruft zum Clonen von Entries den Clone-Link auf,
// damit man sich nicht vom Model ableiten muss, wenn man
@@ -319,18 +334,18 @@ public:
virtual SvListEntry* CloneEntry( SvListEntry* ) const; // ruft den Clone-Link
virtual SvListEntry* CreateEntry() const; // zum 'new'en von Entries
- sal_uInt16 GetRefCount() const { return nRefCount; }
- void SetRefCount( sal_uInt16 nRef ) { nRefCount = nRef; }
+ sal_uInt16 GetRefCount() const { return nRefCount; }
+ void SetRefCount( sal_uInt16 nRef ) { nRefCount = nRef; }
- void SetSortMode( SvSortMode eMode ) { eSortMode = eMode; }
- SvSortMode GetSortMode() const { return eSortMode; }
+ void SetSortMode( SvSortMode eMode ) { eSortMode = eMode; }
+ SvSortMode GetSortMode() const { return eSortMode; }
virtual StringCompare Compare( SvListEntry*, SvListEntry* ) const;
- void SetCompareHdl( const Link& rLink ) { aCompareLink = rLink; }
- const Link& GetCompareHdl() const { return aCompareLink; }
- void Resort();
+ void SetCompareHdl( const Link& rLink ) { aCompareLink = rLink; }
+ const Link& GetCompareHdl() const { return aCompareLink; }
+ void Resort();
#ifdef CHECK_INTEGRITY
- void CheckIntegrity() const;
+ void CheckIntegrity() const;
#endif
};
diff --git a/svtools/source/contnr/treelist.cxx b/svtools/source/contnr/treelist.cxx
index ae304e9..264e168 100644
--- a/svtools/source/contnr/treelist.cxx
+++ b/svtools/source/contnr/treelist.cxx
@@ -184,7 +184,7 @@ size_t SvTreeEntryList::GetPos( SvListEntry* pItem )
if ( aTreeEntryList[ i ] == pItem )
return i;
}
- return 0;
+ return ULONG_MAX;
}
void SvTreeEntryList::push_back( SvListEntry* pItem )
@@ -246,10 +246,10 @@ SvTreeList::~SvTreeList()
void SvTreeList::Broadcast( sal_uInt16 nActionId, SvListEntry* pEntry1,
SvListEntry* pEntry2, sal_uLong nPos )
{
- sal_uLong nViewCount = aViewList.Count();
+ sal_uLong nViewCount = aViewList.size();
for( sal_uLong nCurView = 0; nCurView < nViewCount; nCurView++ )
{
- SvListView* pView = (SvListView*)aViewList.GetObject( nCurView );
+ SvListView* pView = aViewList[ nCurView ];
if( pView )
pView->ModelNotification( nActionId, pEntry1, pEntry2, nPos );
}
@@ -257,21 +257,24 @@ void SvTreeList::Broadcast( sal_uInt16 nActionId, SvListEntry* pEntry1,
void SvTreeList::InsertView( SvListView* pView)
{
- sal_uLong nPos = aViewList.GetPos( pView );
- if ( nPos == LIST_ENTRY_NOTFOUND )
- {
- aViewList.Insert( pView, LIST_APPEND );
- nRefCount++;
+ for (sal_uLong i = 0, n = aViewList.size(); i < n; ++i ) {
+ if ( pView == aViewList[ i ] ) {
+ return;
+ }
}
+ aViewList.push_back( pView );
+ nRefCount++;
}
void SvTreeList::RemoveView( SvListView* pView )
{
- sal_uLong nPos = aViewList.GetPos( pView );
- if ( nPos != LIST_ENTRY_NOTFOUND )
+ for ( SvViewList_impl::iterator it = aViewList.begin(); it < aViewList.end(); ++it )
{
- aViewList.Remove( pView );
- nRefCount--;
+ if ( pView == *it ) {
+ aViewList.erase( it );
+ nRefCount--;
+ break;
+ }
}
}
@@ -1210,7 +1213,7 @@ sal_uLong SvTreeList::Insert( SvListEntry* pEntry,SvListEntry* pParent,sal_uLong
pList->insert( nPos, pEntry );
nEntryCount++;
- if( nPos != LIST_APPEND && (nPos != (pList->size()-1)) )
+ if( nPos != ULONG_MAX && (nPos != (pList->size()-1)) )
SetListPositions( pList );
else
pEntry->nListPos = pList->size()-1;
@@ -1515,7 +1518,7 @@ sal_Bool SvTreeList::IsInChildList( SvListEntry* pParent, SvListEntry* pChild) c
pParent = pRootItem;
sal_Bool bIsChild = sal_False;
if ( pParent->pChilds )
- bIsChild = (sal_Bool)(pParent->pChilds->GetPos(pChild) != LIST_ENTRY_NOTFOUND);
+ bIsChild = (sal_Bool)(pParent->pChilds->GetPos(pChild) != ULONG_MAX);
return bIsChild;
}
More information about the Libreoffice-commits
mailing list