diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-12-06 16:36:25 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-12-07 10:42:55 +0100 |
commit | 74816dd665fb2980823e01f81446147fe7fe6688 (patch) | |
tree | a6df62c64863cf99084901c18dcaf62847dd5f25 /vcl | |
parent | 67ff7348756ec88d09fc00e6d284ba5b579e9b33 (diff) |
SvTreeList only ever belongs to one and only one SvListView
so simplify that
Change-Id: I6db807c5aa8ed1e6487bdb4f5ac5c96cf8abbcf6
Reviewed-on: https://gerrit.libreoffice.org/64752
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/source/treelist/treelist.cxx | 59 | ||||
-rw-r--r-- | vcl/source/treelist/treelistbox.cxx | 35 |
2 files changed, 13 insertions, 81 deletions
diff --git a/vcl/source/treelist/treelist.cxx b/vcl/source/treelist/treelist.cxx index cafccba11c13..5637b8ba2529 100644 --- a/vcl/source/treelist/treelist.cxx +++ b/vcl/source/treelist/treelist.cxx @@ -58,19 +58,18 @@ struct SvListView::Impl }; -SvTreeList::SvTreeList() : +SvTreeList::SvTreeList(SvListView* listView) : + mpOwnerListView(listView), mbEnableInvalidate(true) { nEntryCount = 0; bAbsPositionsValid = false; - nRefCount = 1; pRootItem.reset(new SvTreeListEntry); eSortMode = SortNone; } SvTreeList::~SvTreeList() { - Clear(); } void SvTreeList::Broadcast( @@ -78,34 +77,11 @@ void SvTreeList::Broadcast( SvTreeListEntry* pEntry1, SvTreeListEntry* pEntry2, sal_uLong nPos -) { - for (auto const& view : aViewList) - { - if(view) - view->ModelNotification(nActionId, pEntry1, pEntry2, nPos); - } -} - -void SvTreeList::InsertView( SvListView* pView ) -{ - if (std::find(aViewList.begin(), aViewList.end(), pView) != aViewList.end()) - return; - - aViewList.push_back( pView ); - nRefCount++; -} - -void SvTreeList::RemoveView( SvListView const * pView ) +) { - auto viewFound = std::find(aViewList.begin(), aViewList.end(), pView); - if (viewFound != aViewList.end()) - { - aViewList.erase( viewFound ); - --nRefCount; - } + mpOwnerListView->ModelNotification(nActionId, pEntry1, pEntry2, nPos); } - // an entry is visible if all parents are expanded bool SvTreeList::IsEntryVisible( const SvListView* pView, SvTreeListEntry* pEntry ) const { @@ -1098,8 +1074,14 @@ std::pair<SvTreeListEntries::iterator, SvTreeListEntries::iterator> SvListView::SvListView() : m_pImpl(new Impl(*this)) - , pModel(nullptr) { + pModel.reset(new SvTreeList(this)); + m_pImpl->InitTable(); +} + +void SvListView::dispose() +{ + pModel.reset(); } SvListView::~SvListView() @@ -1169,25 +1151,6 @@ void SvListView::Clear() } } -void SvListView::SetModel( SvTreeList* pNewModel ) -{ - bool bBroadcastCleared = false; - if ( pModel ) - { - pModel->RemoveView( this ); - bBroadcastCleared = true; - ModelNotification( SvListAction::CLEARING,nullptr,nullptr,0 ); - if ( pModel->GetRefCount() == 0 ) - delete pModel; - } - pModel = pNewModel; - m_pImpl->InitTable(); - pNewModel->InsertView( this ); - if( bBroadcastCleared ) - ModelNotification( SvListAction::CLEARED,nullptr,nullptr,0 ); -} - - void SvListView::ModelHasCleared() { } diff --git a/vcl/source/treelist/treelistbox.cxx b/vcl/source/treelist/treelistbox.cxx index e4f41a51957a..cc79854dfb41 100644 --- a/vcl/source/treelist/treelistbox.cxx +++ b/vcl/source/treelist/treelistbox.cxx @@ -347,17 +347,14 @@ SvTreeListBox::SvTreeListBox(vcl::Window* pParent, WinBits nWinStyle) : nImpFlags = SvTreeListBoxFlags::NONE; pTargetEntry = nullptr; nDragDropMode = DragDropMode::NONE; - SvTreeList* pTempModel = new SvTreeList; - pTempModel->SetRefCount( 0 ); - SetBaseModel(pTempModel); pModel->SetCloneLink( LINK(this, SvTreeListBox, CloneHdl_Impl )); - pModel->InsertView( this ); pHdlEntry = nullptr; eSelMode = SelectionMode::Single; nDragDropMode = DragDropMode::NONE; SetType(WindowType::TREELISTBOX); InitTreeView(); + pImpl->SetModel( pModel.get() ); SetSublistOpenWithLeftRight(); } @@ -1353,16 +1350,7 @@ void SvTreeListBox::dispose() pEdCtrl.reset(); - if( pModel ) - { - pModel->RemoveView( this ); - if ( pModel->GetRefCount() == 0 ) - { - pModel->Clear(); - delete pModel; - pModel = nullptr; - } - } + SvListView::dispose(); SvTreeListBox::RemoveBoxFromDDList_Impl( *this ); @@ -1383,25 +1371,6 @@ void SvTreeListBox::SetNoAutoCurEntry( bool b ) pImpl->SetNoAutoCurEntry( b ); } -void SvTreeListBox::SetModel( SvTreeList* pNewModel ) -{ - pImpl->SetModel( pNewModel ); - SetBaseModel(pNewModel); -} - -void SvTreeListBox::SetBaseModel( SvTreeList* pNewModel ) -{ - // does the CleanUp - SvListView::SetModel( pNewModel ); - pModel->SetCloneLink( LINK(this, SvTreeListBox, CloneHdl_Impl )); - SvTreeListEntry* pEntry = First(); - while( pEntry ) - { - ModelHasInserted( pEntry ); - pEntry = Next( pEntry ); - } -} - void SvTreeListBox::SetSublistOpenWithReturn() { pImpl->bSubLstOpRet = true; |