Make wxDataViewCtrl::Expand() expand ancestors in native ports too

Expand() called ExpandAncestors() in the generic wxDataViewCtrl implementation
but not in the native ones, resulting in observable difference in the
behaviour: for example, the wxDataViewTreeCtrl in the dataview sample appeared
initially expanded under MSW, using the generic version, but collapsed under
GTK and OSX.

Harmonize this among all ports. This also has a nice side effect of making
Expand() less horribly inefficient as it is not recursively called by
ExpandAncestors() which it itself used to call: now ExpandAncestors() only
calls DoExpand() which is a simple function that only expands the item passed
to it and does nothing else.

Closes #14803.
This commit is contained in:
Vadim Zeitlin 2016-03-22 21:22:36 +01:00
parent aa9e7d3326
commit 716dace3d6
12 changed files with 30 additions and 14 deletions

View File

@ -67,6 +67,7 @@ All (GUI):
- Add support for wxAuiManager and wxAuiPaneInfo to XRC (Andrea Zanellato).
- Update Scintilla to v3.6.3 (Paul Kulchenko).
- Make wxDataViewCtrl::Expand() expand ancestors in native ports too.
wxGTK:

View File

@ -705,7 +705,7 @@ public:
virtual void SelectAll() = 0;
virtual void UnselectAll() = 0;
virtual void Expand( const wxDataViewItem & item ) = 0;
void Expand( const wxDataViewItem & item );
void ExpandAncestors( const wxDataViewItem & item );
virtual void Collapse( const wxDataViewItem & item ) = 0;
virtual bool IsExpanded( const wxDataViewItem & item ) const = 0;
@ -747,6 +747,10 @@ protected:
virtual void DoSetExpanderColumn() = 0 ;
virtual void DoSetIndent() = 0;
// Just expand this item assuming it is already shown, i.e. its parent has
// been already expanded using ExpandAncestors().
virtual void DoExpand(const wxDataViewItem & item) = 0;
private:
// Implementation of the public Set/GetCurrentItem() methods which are only
// called in multi selection case (for single selection controls their

View File

@ -236,7 +236,6 @@ public:
virtual bool SetRowHeight( int rowHeight ) wxOVERRIDE;
virtual void Expand( const wxDataViewItem & item ) wxOVERRIDE;
virtual void Collapse( const wxDataViewItem & item ) wxOVERRIDE;
virtual bool IsExpanded( const wxDataViewItem & item ) const wxOVERRIDE;
@ -318,6 +317,8 @@ private:
virtual wxDataViewItem DoGetCurrentItem() const wxOVERRIDE;
virtual void DoSetCurrentItem(const wxDataViewItem& item) wxOVERRIDE;
virtual void DoExpand(const wxDataViewItem& item) wxOVERRIDE;
void InvalidateColBestWidths();
void InvalidateColBestWidth(int idx);
void UpdateColWidths();

View File

@ -161,7 +161,6 @@ public:
virtual void EditItem(const wxDataViewItem& item, const wxDataViewColumn *column) wxOVERRIDE;
virtual void Expand( const wxDataViewItem & item ) wxOVERRIDE;
virtual void Collapse( const wxDataViewItem & item ) wxOVERRIDE;
virtual bool IsExpanded( const wxDataViewItem & item ) const wxOVERRIDE;
@ -190,6 +189,8 @@ protected:
virtual void DoSetExpanderColumn() wxOVERRIDE;
virtual void DoSetIndent() wxOVERRIDE;
virtual void DoExpand(const wxDataViewItem& item) wxOVERRIDE;
virtual void DoApplyWidgetStyle(GtkRcStyle *style) wxOVERRIDE;
private:

View File

@ -447,7 +447,6 @@ public:
virtual void Collapse(const wxDataViewItem& item);
virtual void EnsureVisible(const wxDataViewItem& item,
wxDataViewColumn const* columnPtr);
virtual void Expand(const wxDataViewItem& item);
virtual unsigned int GetCount() const;
virtual wxRect GetRectangle(const wxDataViewItem& item,
wxDataViewColumn const* columnPtr);
@ -490,6 +489,9 @@ public:
// other methods (inherited from wxDataViewWidgetImpl)
//
virtual void DoSetIndent(int indent);
virtual void DoExpand(const wxDataViewItem& item);
virtual void HitTest(const wxPoint& point,
wxDataViewItem& item,
wxDataViewColumn*& columnPtr) const;

View File

@ -62,7 +62,6 @@ public:
virtual bool Add (wxDataViewItem const& parent, wxDataViewItemArray const& itesm) = 0; // adds a items to the native control
virtual void Collapse (wxDataViewItem const& item) = 0; // collapses the passed item in the native control
virtual void EnsureVisible(wxDataViewItem const& item, wxDataViewColumn const* columnPtr) = 0; // ensures that the passed item's value in the passed column is visible (column pointer can be NULL)
virtual void Expand (wxDataViewItem const& item) = 0; // expands the passed item in the native control
virtual unsigned int GetCount (void) const = 0; // returns the number of items in the native control
virtual wxRect GetRectangle (wxDataViewItem const& item, wxDataViewColumn const* columnPtr) = 0; // returns the rectangle that is used by the passed item and column in the native control
virtual bool IsExpanded (wxDataViewItem const& item) const = 0; // checks if the passed item is expanded in the native control
@ -104,6 +103,8 @@ public:
// other methods
//
virtual void DoSetIndent (int indent) = 0; // sets the indention in the native control
virtual void DoExpand (wxDataViewItem const& item) = 0; // expands the passed item in the native control
virtual void HitTest (wxPoint const& point, wxDataViewItem& item, wxDataViewColumn*& columnPtr) const = 0; // return the item and column pointer that contains with the passed point
virtual void SetRowHeight(wxDataViewItem const& item, unsigned int height) = 0; // sets the height of the row containg the passed item in the native control
virtual void OnSize (void) = 0; // updates the layout of the native control after a size event

View File

@ -169,7 +169,6 @@ public:
virtual void Collapse( const wxDataViewItem& item) wxOVERRIDE;
virtual void EnsureVisible(const wxDataViewItem& item, const wxDataViewColumn* columnPtr=NULL) wxOVERRIDE;
virtual void Expand(const wxDataViewItem& item) wxOVERRIDE;
virtual bool IsExpanded(const wxDataViewItem & item) const wxOVERRIDE;
virtual unsigned int GetCount() const;
@ -271,6 +270,8 @@ protected:
virtual void DoSetExpanderColumn() wxOVERRIDE;
virtual void DoSetIndent() wxOVERRIDE;
virtual void DoExpand(const wxDataViewItem& item) wxOVERRIDE;
virtual wxSize DoGetBestSize() const wxOVERRIDE;
// event handling

View File

@ -1166,6 +1166,13 @@ const wxDataViewModel* wxDataViewCtrlBase::GetModel() const
return m_model;
}
void wxDataViewCtrlBase::Expand(const wxDataViewItem& item)
{
ExpandAncestors(item);
DoExpand(item);
}
void wxDataViewCtrlBase::ExpandAncestors( const wxDataViewItem & item )
{
if (!m_model) return;
@ -1185,7 +1192,7 @@ void wxDataViewCtrlBase::ExpandAncestors( const wxDataViewItem & item )
// then we expand the parents, starting at the root
while (!parentChain.empty())
{
Expand(parentChain.back());
DoExpand(parentChain.back());
parentChain.pop_back();
}
}

View File

@ -5273,10 +5273,8 @@ int wxDataViewCtrl::GetRowByItem( const wxDataViewItem & item ) const
return m_clientArea->GetRowByItem( item );
}
void wxDataViewCtrl::Expand( const wxDataViewItem & item )
void wxDataViewCtrl::DoExpand( const wxDataViewItem & item )
{
ExpandAncestors( item );
int row = m_clientArea->GetRowByItem( item );
if (row != -1)
m_clientArea->Expand(row);

View File

@ -4820,7 +4820,7 @@ wxDataViewColumn *wxDataViewCtrl::GetSortingColumn() const
return m_internal->GetDataViewSortColumn();
}
void wxDataViewCtrl::Expand( const wxDataViewItem & item )
void wxDataViewCtrl::DoExpand( const wxDataViewItem & item )
{
GtkTreeIter iter;
iter.user_data = item.GetID();

View File

@ -2156,7 +2156,7 @@ void wxCocoaDataViewControl::EnsureVisible(const wxDataViewItem& item, const wxD
}
}
void wxCocoaDataViewControl::Expand(const wxDataViewItem& item)
void wxCocoaDataViewControl::DoExpand(const wxDataViewItem& item)
{
[m_OutlineView expandItem:[m_DataSource getDataViewItemFromBuffer:item]];
}

View File

@ -506,9 +506,9 @@ void wxDataViewCtrl::EnsureVisible(wxDataViewItem const& item, wxDataViewColumn
}
}
void wxDataViewCtrl::Expand(wxDataViewItem const& item)
void wxDataViewCtrl::DoExpand(wxDataViewItem const& item)
{
return GetDataViewPeer()->Expand(item);
return GetDataViewPeer()->DoExpand(item);
}
bool wxDataViewCtrl::IsExpanded( const wxDataViewItem & item ) const