Kaydet (Commit) 74816dd6 authored tarafından Noel Grandin's avatar Noel Grandin

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: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 67ff7348
......@@ -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,
......
......@@ -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;
......
......@@ -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()
{
}
......
......@@ -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;
......
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