include/vcl/treelist.hxx | 19 +++-------- include/vcl/treelistbox.hxx | 8 ---- vcl/source/treelist/treelist.cxx | 59 ++++++------------------------------ vcl/source/treelist/treelistbox.cxx | 35 +-------------------- 4 files changed, 19 insertions(+), 102 deletions(-)
New commits: commit 74816dd665fb2980823e01f81446147fe7fe6688 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Thu Dec 6 16:36:25 2018 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Fri Dec 7 10:42:55 2018 +0100 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.gran...@collabora.co.uk> diff --git a/include/vcl/treelist.hxx b/include/vcl/treelist.hxx index 48fb5cb26c82..e4e2f21c0b3e 100644 --- a/include/vcl/treelist.hxx +++ b/include/vcl/treelist.hxx @@ -65,19 +65,15 @@ struct SvSortData class VCL_DLLPUBLIC SvTreeList final { - typedef std::vector<SvListView*> ListViewsType; - friend class SvListView; - ListViewsType aViewList; + SvListView* const mpOwnerListView; sal_uLong nEntryCount; Link<SvTreeListEntry*, SvTreeListEntry*> aCloneLink; Link<const SvSortData&, sal_Int32> aCompareLink; SvSortMode eSortMode; - sal_uInt16 nRefCount; - bool bAbsPositionsValid; bool mbEnableInvalidate; @@ -134,12 +130,10 @@ class VCL_DLLPUBLIC SvTreeList final public: - SvTreeList(); + SvTreeList() = delete; + SvTreeList(SvListView*); ~SvTreeList(); - void InsertView( SvListView* ); - void RemoveView( SvListView const * ); - void Broadcast( SvListAction nActionId, SvTreeListEntry* pEntry1=nullptr, @@ -213,9 +207,6 @@ public: SvTreeListEntry* CloneEntry( SvTreeListEntry* pSource ) const; // Calls the Clone Link - sal_uInt16 GetRefCount() const { return nRefCount; } - void SetRefCount( sal_uInt16 nRef ) { nRefCount = nRef; } - void SetSortMode( SvSortMode eMode ) { eSortMode = eMode; } SvSortMode GetSortMode() const { return eSortMode; } sal_Int32 Compare(const SvTreeListEntry* pLeft, const SvTreeListEntry* pRight) const; @@ -232,7 +223,7 @@ class VCL_DLLPUBLIC SvListView std::unique_ptr<Impl> m_pImpl; protected: - SvTreeList* pModel; + std::unique_ptr<SvTreeList> pModel; void ExpandListEntry( SvTreeListEntry* pParent ); void CollapseListEntry( SvTreeListEntry* pParent ); @@ -240,9 +231,9 @@ protected: public: SvListView(); // Sets the Model to 0 + void dispose(); virtual ~SvListView(); void Clear(); - virtual void SetModel( SvTreeList* ); virtual void ModelNotification( SvListAction nActionId, SvTreeListEntry* pEntry1, diff --git a/include/vcl/treelistbox.hxx b/include/vcl/treelistbox.hxx index 554bd734b421..43cee9dd8442 100644 --- a/include/vcl/treelistbox.hxx +++ b/include/vcl/treelistbox.hxx @@ -257,8 +257,6 @@ protected: sal_uInt16 nCurEntrySelPos; private: - void SetBaseModel(SvTreeList* pNewModel); - DECL_DLLPRIVATE_LINK( CheckButtonClick, SvLBoxButtonData *, void ); DECL_DLLPRIVATE_LINK( TextEditEndedHdl_Impl, SvInplaceEdit2&, void ); // Handler that is called by TreeList to clone an Entry @@ -335,13 +333,9 @@ public: SvTreeList* GetModel() const { - return pModel; + return pModel.get(); } - using SvListView::SetModel; - - void SetModel(SvTreeList* pNewModel) override; - sal_uLong GetEntryCount() const { return pModel ? pModel->GetEntryCount() : 0; 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; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits