diff options
author | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2012-02-20 06:31:12 +0100 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2012-02-20 06:41:12 +0100 |
commit | 1c9f0a6ddb48f7b6d62670901e117b25a0e59713 (patch) | |
tree | c7c7061e1321b8d890aa02fd92de2a0aac8477d1 /svtools | |
parent | cfae02e4c4f018ed9761fff7930a845b3b06114a (diff) |
move SvListView from Table to ptr_map, related fdo#45679
Diffstat (limited to 'svtools')
-rw-r--r-- | svtools/inc/svtools/treelist.hxx | 61 | ||||
-rw-r--r-- | svtools/source/contnr/treelist.cxx | 52 |
2 files changed, 58 insertions, 55 deletions
diff --git a/svtools/inc/svtools/treelist.hxx b/svtools/inc/svtools/treelist.hxx index 9db33bbe887a..b2a7173912cb 100644 --- a/svtools/inc/svtools/treelist.hxx +++ b/svtools/inc/svtools/treelist.hxx @@ -32,6 +32,7 @@ #include "svtools/svtdllapi.h" #include <tools/solar.h> #include <vector> +#include <boost/ptr_container/ptr_map.hpp> #include <tools/table.hxx> #include <tools/link.hxx> @@ -280,7 +281,7 @@ class SVT_DLLPUBLIC SvTreeList 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 GetVisibleCount( SvListView* ) const; sal_uLong GetVisibleChildCount( const SvListView*,SvListEntry* pParent ) const; SvListEntry* FirstSelected( const SvListView*) const; @@ -421,6 +422,8 @@ class SVT_DLLPUBLIC SvListView { friend class SvTreeList; + typedef boost::ptr_map<SvListEntry*, SvViewData> SvDataTable; + sal_uLong nVisibleCount; sal_uLong nSelectionCount; sal_Bool bVisPositionsValid; @@ -430,7 +433,7 @@ class SVT_DLLPUBLIC SvListView SVT_DLLPRIVATE void RemoveViewData( SvListEntry* pParent ); protected: - Table aDataTable; // Mapping SvListEntry -> ViewData + SvDataTable maDataTable; // Mapping SvListEntry -> ViewData SvTreeList* pModel; void ActionMoving( SvListEntry* pEntry,SvListEntry* pTargetPrnt,sal_uLong nChildPos); @@ -527,10 +530,11 @@ public: sal_Bool IsExpanded( SvListEntry* pEntry ) const; sal_Bool IsSelected( SvListEntry* pEntry ) const; sal_Bool HasEntryFocus( SvListEntry* pEntry ) const; - void SetEntryFocus( SvListEntry* pEntry, sal_Bool bFocus ) const; - SvViewData* GetViewData( SvListEntry* pEntry ) const; + void SetEntryFocus( SvListEntry* pEntry, sal_Bool bFocus ); + const SvViewData* GetViewData( SvListEntry* pEntry ) const; + SvViewData* GetViewData( SvListEntry* pEntry ); sal_Bool HasViewData() const - { return aDataTable.Count() > 1; } // eine ROOT gibts immer + { return maDataTable.size() > 1; } // eine ROOT gibts immer virtual SvViewData* CreateViewData( SvListEntry* pEntry ); virtual void InitViewData( SvViewData*, SvListEntry* pEntry ); @@ -552,43 +556,54 @@ public: inline sal_Bool SvListView::IsExpanded( SvListEntry* pEntry ) const { DBG_ASSERT(pEntry,"IsExpanded:No Entry"); - SvViewData* pData = (SvViewData*)aDataTable.Get( (sal_uLong)pEntry ); - DBG_ASSERT(pData,"Entry not in Table"); - return pData->IsExpanded(); + SvDataTable::const_iterator itr = maDataTable.find(pEntry); + DBG_ASSERT(itr != maDataTable.end(),"Entry not in Table"); + return itr->second->IsExpanded(); } inline sal_Bool SvListView::IsSelected( SvListEntry* pEntry ) const { DBG_ASSERT(pEntry,"IsExpanded:No Entry"); - SvViewData* pData = (SvViewData*)aDataTable.Get( (sal_uLong)pEntry ); - DBG_ASSERT(pData,"Entry not in Table"); - return pData->IsSelected(); + SvDataTable::const_iterator itr = maDataTable.find(pEntry ); + DBG_ASSERT(itr != maDataTable.end(),"Entry not in Table"); + return itr->second->IsSelected(); } inline sal_Bool SvListView::HasEntryFocus( SvListEntry* pEntry ) const { DBG_ASSERT(pEntry,"IsExpanded:No Entry"); - SvViewData* pData = (SvViewData*)aDataTable.Get( (sal_uLong)pEntry ); - DBG_ASSERT(pData,"Entry not in Table"); - return pData->HasFocus(); + SvDataTable::const_iterator itr = maDataTable.find(pEntry ); + DBG_ASSERT(itr != maDataTable.end(),"Entry not in Table"); + return itr->second->HasFocus(); } -inline void SvListView::SetEntryFocus( SvListEntry* pEntry, sal_Bool bFocus ) const +inline void SvListView::SetEntryFocus( SvListEntry* pEntry, sal_Bool bFocus ) { DBG_ASSERT(pEntry,"SetEntryFocus:No Entry"); - SvViewData* pData = (SvViewData*)aDataTable.Get( (sal_uLong)pEntry ); - DBG_ASSERT(pData,"Entry not in Table"); - pData->SetFocus(bFocus); + SvDataTable::iterator itr = maDataTable.find(pEntry); + DBG_ASSERT(itr != maDataTable.end(),"Entry not in Table"); + itr->second->SetFocus(bFocus); +} + +inline const SvViewData* SvListView::GetViewData( SvListEntry* pEntry ) const +{ +#ifndef DBG_UTIL + return maDataTable.find( pEntry )->second; +#else + SvDataTable::const_iterator itr = maDataTable.find( pEntry ); + DBG_ASSERT(itr != maDataTable.end(),"Entry not in model or wrong view"); + return itr->second; +#endif } -inline SvViewData* SvListView::GetViewData( SvListEntry* pEntry ) const +inline SvViewData* SvListView::GetViewData( SvListEntry* pEntry ) { #ifndef DBG_UTIL - return (SvViewData*)aDataTable.Get( (sal_uLong)pEntry ); + return maDataTable.find( pEntry )->second; #else - SvViewData* pResult = (SvViewData*)aDataTable.Get( (sal_uLong)pEntry ); - DBG_ASSERT(pResult,"Entry not in model or wrong view"); - return pResult; + SvDataTable::iterator itr = maDataTable.find( pEntry ); + DBG_ASSERT(itr != maDataTable.end(),"Entry not in model or wrong view"); + return itr->second; #endif } diff --git a/svtools/source/contnr/treelist.cxx b/svtools/source/contnr/treelist.cxx index 7ea23f39bcac..a6ad1efed705 100644 --- a/svtools/source/contnr/treelist.cxx +++ b/svtools/source/contnr/treelist.cxx @@ -732,9 +732,9 @@ sal_uLong SvTreeList::GetVisiblePos( const SvListView* pView, SvListEntry* pEntr { // damit GetVisibleCount die Positionen aktualisiert ((SvListView*)pView)->nVisibleCount = 0; - GetVisibleCount( pView ); + GetVisibleCount( const_cast<SvListView*>(pView) ); } - SvViewData* pViewData = pView->GetViewData( pEntry ); + const SvViewData* pViewData = pView->GetViewData( pEntry ); return pViewData->nVisPos; } @@ -744,7 +744,7 @@ sal_uLong SvTreeList::GetVisiblePos( const SvListView* pView, SvListEntry* pEntr |* *************************************************************************/ -sal_uLong SvTreeList::GetVisibleCount( const SvListView* pView ) const +sal_uLong SvTreeList::GetVisibleCount( SvListView* pView ) const { DBG_ASSERT(pView,"GetVisCount:No View"); if( !pView->HasViewData() ) @@ -1445,15 +1445,13 @@ void SvListView::InitTable() DBG_ASSERT(pModel,"InitTable:No Model"); DBG_ASSERT(!nSelectionCount&&!nVisibleCount&&!bVisPositionsValid,"InitTable: Not cleared!"); - if( aDataTable.Count() ) + if( maDataTable.size() ) { - DBG_ASSERT(aDataTable.Count()==1,"InitTable: TableCount != 1"); + DBG_ASSERT(maDataTable.size()==1,"InitTable: TableCount != 1"); // die im Clear fuer die Root allozierten View-Daten loeschen // Achtung: Das zu dem RootEntry (und damit auch der Entry) // gehoerende Model kann bereits geloescht sein! - SvViewData* pViewData = (SvViewData*)aDataTable.GetObject( 0 ); - delete pViewData; - aDataTable.Clear(); + maDataTable.clear(); } SvListEntry* pEntry; @@ -1463,7 +1461,7 @@ void SvListView::InitTable() pEntry = pModel->pRootItem; pViewData = new SvViewData; pViewData->nFlags = SVLISTENTRYFLAG_EXPANDED; - aDataTable.Insert( (sal_uLong)pEntry, pViewData ); + maDataTable.insert( pEntry, pViewData ); // Jetzt alle anderen Entries pEntry = pModel->First(); while( pEntry ) @@ -1471,7 +1469,7 @@ void SvListView::InitTable() pViewData = CreateViewData( pEntry ); DBG_ASSERT(pViewData,"InitTable:No ViewData"); InitViewData( pViewData, pEntry ); - aDataTable.Insert( (sal_uLong)pEntry, pViewData ); + maDataTable.insert( pEntry, pViewData ); pEntry = pModel->Next( pEntry ); } } @@ -1485,13 +1483,7 @@ SvViewData* SvListView::CreateViewData( SvListEntry* ) void SvListView::ClearTable() { DBG_CHKTHIS(SvListView,0); - SvViewData* pViewData = (SvViewData*)aDataTable.First(); - while( pViewData ) - { - delete pViewData; - pViewData = (SvViewData*)aDataTable.Next(); - } - aDataTable.Clear(); + maDataTable.clear(); } void SvListView::Clear() @@ -1506,7 +1498,7 @@ void SvListView::Clear() SvListEntry* pEntry = pModel->pRootItem; SvViewData* pViewData = new SvViewData; pViewData->nFlags = SVLISTENTRYFLAG_EXPANDED; - aDataTable.Insert( (sal_uLong)pEntry, pViewData ); + maDataTable.insert( pEntry, pViewData ); } } @@ -1579,7 +1571,7 @@ void SvListView::ActionMoving( SvListEntry* pEntry,SvListEntry*,sal_uLong) DBG_ASSERT(pParent,"Model not consistent"); if( pParent != pModel->pRootItem && pParent->pChildren->size() == 1 ) { - SvViewData* pViewData = (SvViewData*)aDataTable.Get( (sal_uLong)pParent ); + SvViewData* pViewData = maDataTable.find( pParent )->second; pViewData->nFlags &= (~SVLISTENTRYFLAG_EXPANDED); } // vorlaeufig @@ -1603,10 +1595,10 @@ void SvListView::ActionInserted( SvListEntry* pEntry ) SvViewData* pData = CreateViewData( pEntry ); InitViewData( pData, pEntry ); #ifdef DBG_UTIL - sal_Bool bSuccess = + std::pair<SvDataTable::iterator, bool> aSuccess = #endif - aDataTable.Insert( (sal_uLong)pEntry, pData ); - DBG_ASSERT(bSuccess,"Entry already in View"); + maDataTable.insert( pEntry, pData ); + DBG_ASSERT(aSuccess.second,"Entry already in View"); if ( nVisibleCount && pModel->IsEntryVisible( this, pEntry )) { nVisibleCount = 0; @@ -1627,11 +1619,11 @@ void SvListView::ActionInsertedTree( SvListEntry* pEntry ) sal_uInt16 nRefDepth = pModel->GetDepth( pCurEntry ); while( pCurEntry ) { - DBG_ASSERT(aDataTable.Get((sal_uLong)pCurEntry)==0,"Entry already in Table"); + DBG_ASSERT(maDataTable.find(pCurEntry) != maDataTable.end(),"Entry already in Table"); SvViewData* pViewData = CreateViewData( pCurEntry ); DBG_ASSERT(pViewData,"No ViewData"); InitViewData( pViewData, pEntry ); - aDataTable.Insert( (sal_uLong)pCurEntry, pViewData ); + maDataTable.insert( pCurEntry, pViewData ); pCurEntry = pModel->Next( pCurEntry ); if ( pCurEntry && pModel->GetDepth(pCurEntry) <= nRefDepth) pCurEntry = 0; @@ -1646,9 +1638,7 @@ void SvListView::RemoveViewData( SvListEntry* pParent ) SvListEntry* pCur = (SvListEntry*)pChildren->First(); while( pCur ) { - SvViewData* pViewData = (SvViewData*)aDataTable.Get((sal_uLong)pCur); - delete pViewData; - aDataTable.Remove( (sal_uLong)pCur ); + maDataTable.erase(pCur); if( pCur->HasChildren()) RemoveViewData( pCur ); pCur = (SvListEntry*)pChildren->Next(); @@ -1663,7 +1653,7 @@ void SvListView::ActionRemoving( SvListEntry* pEntry ) DBG_CHKTHIS(SvListView,0); DBG_ASSERT(pEntry,"Remove:No Entry"); - SvViewData* pViewData = (SvViewData*)aDataTable.Get( (sal_uLong)pEntry ); + SvViewData* pViewData = maDataTable.find( pEntry )->second; sal_uLong nSelRemoved = 0; if ( pViewData->IsSelected() ) nSelRemoved = 1 + pModel->GetChildSelectionCount( this, pEntry ); @@ -1683,16 +1673,14 @@ void SvListView::ActionRemoving( SvListEntry* pEntry ) } bVisPositionsValid = sal_False; - pViewData = (SvViewData*)aDataTable.Get((sal_uLong)pEntry); - delete pViewData; - aDataTable.Remove( (sal_uLong)pEntry ); + maDataTable.erase(pEntry); RemoveViewData( pEntry ); SvListEntry* pCurEntry = pEntry->pParent; if ( pCurEntry && pCurEntry != pModel->pRootItem && pCurEntry->pChildren->size() == 1 ) { - pViewData = (SvViewData*)aDataTable.Get((sal_uLong)pCurEntry); + pViewData = maDataTable.find(pCurEntry)->second; pViewData->nFlags &= (~SVLISTENTRYFLAG_EXPANDED); } } |