Merge branch 'dvc-kbd-shortcuts'
Add wxDVC::ExpandChildren() and handle standard keyboard shortcuts in the generic version. See https://github.com/wxWidgets/wxWidgets/pull/2135
This commit is contained in:
@@ -740,6 +740,7 @@ public:
|
||||
virtual void UnselectAll() = 0;
|
||||
|
||||
void Expand( const wxDataViewItem & item );
|
||||
void ExpandChildren( const wxDataViewItem & item );
|
||||
void ExpandAncestors( const wxDataViewItem & item );
|
||||
virtual void Collapse( const wxDataViewItem & item ) = 0;
|
||||
virtual bool IsExpanded( const wxDataViewItem & item ) const = 0;
|
||||
@@ -793,7 +794,9 @@ protected:
|
||||
|
||||
// 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;
|
||||
//
|
||||
// If expandChildren is true, also expand all its children recursively.
|
||||
virtual void DoExpand(const wxDataViewItem & item, bool expandChildren) = 0;
|
||||
|
||||
private:
|
||||
// Implementation of the public Set/GetCurrentItem() methods which are only
|
||||
|
@@ -364,7 +364,7 @@ private:
|
||||
virtual wxDataViewItem DoGetCurrentItem() const wxOVERRIDE;
|
||||
virtual void DoSetCurrentItem(const wxDataViewItem& item) wxOVERRIDE;
|
||||
|
||||
virtual void DoExpand(const wxDataViewItem& item) wxOVERRIDE;
|
||||
virtual void DoExpand(const wxDataViewItem& item, bool expandChildren) wxOVERRIDE;
|
||||
|
||||
void InvalidateColBestWidths();
|
||||
void InvalidateColBestWidth(int idx);
|
||||
|
@@ -218,7 +218,7 @@ protected:
|
||||
virtual void DoSetExpanderColumn() wxOVERRIDE;
|
||||
virtual void DoSetIndent() wxOVERRIDE;
|
||||
|
||||
virtual void DoExpand(const wxDataViewItem& item) wxOVERRIDE;
|
||||
virtual void DoExpand(const wxDataViewItem& item, bool expandChildren) wxOVERRIDE;
|
||||
|
||||
virtual void DoApplyWidgetStyle(GtkRcStyle *style) wxOVERRIDE;
|
||||
virtual GdkWindow* GTKGetWindow(wxArrayGdkWindows& windows) const wxOVERRIDE;
|
||||
|
@@ -530,7 +530,7 @@ public:
|
||||
//
|
||||
virtual void DoSetIndent(int indent);
|
||||
|
||||
virtual void DoExpand(const wxDataViewItem& item);
|
||||
virtual void DoExpand(const wxDataViewItem& item, bool expandChildren);
|
||||
|
||||
virtual void HitTest(const wxPoint& point,
|
||||
wxDataViewItem& item,
|
||||
|
@@ -105,7 +105,7 @@ public:
|
||||
// other methods
|
||||
//
|
||||
virtual void DoSetIndent (int indent) = 0; // sets the indentation in the native control
|
||||
virtual void DoExpand (wxDataViewItem const& item) = 0; // expands the passed item in the native control
|
||||
virtual void DoExpand (wxDataViewItem const& item, bool expandChildren) = 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(int height) = 0; // sets the height of all rows
|
||||
|
@@ -276,7 +276,7 @@ protected:
|
||||
virtual void DoSetExpanderColumn() wxOVERRIDE;
|
||||
virtual void DoSetIndent() wxOVERRIDE;
|
||||
|
||||
virtual void DoExpand(const wxDataViewItem& item) wxOVERRIDE;
|
||||
virtual void DoExpand(const wxDataViewItem& item, bool expandChildren) wxOVERRIDE;
|
||||
|
||||
virtual wxSize DoGetBestSize() const wxOVERRIDE;
|
||||
|
||||
|
@@ -115,7 +115,6 @@ public:
|
||||
virtual wxRect GetItemRect( const wxDataViewItem &item,
|
||||
const wxDataViewColumn *column = NULL ) const;
|
||||
|
||||
virtual void Expand( const wxDataViewItem & item );
|
||||
virtual void Collapse( const wxDataViewItem & item );
|
||||
virtual bool IsExpanded( const wxDataViewItem & item ) const;
|
||||
|
||||
@@ -132,6 +131,7 @@ public:
|
||||
protected:
|
||||
virtual void DoSetExpanderColumn();
|
||||
virtual void DoSetIndent();
|
||||
virtual void DoExpand( const wxDataViewItem & item, bool expandChildren );
|
||||
|
||||
private:
|
||||
virtual wxDataViewItem DoGetCurrentItem() const;
|
||||
|
@@ -1402,6 +1402,16 @@ public:
|
||||
*/
|
||||
void ExpandAncestors( const wxDataViewItem & item );
|
||||
|
||||
/**
|
||||
Expand all all children of the given item recursively.
|
||||
|
||||
This is the same as calling Expand() on the @a item itself and then
|
||||
calling it for all of its children, grandchildren etc recursively.
|
||||
|
||||
@since 3.1.5
|
||||
*/
|
||||
void ExpandChildren( const wxDataViewItem & item );
|
||||
|
||||
/**
|
||||
Returns pointer to the column. @a pos refers to the position in the
|
||||
control which may change after reordering columns by the user.
|
||||
|
@@ -742,6 +742,9 @@ MyFrame::MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int
|
||||
mainSizer->Add( m_log, 0, wxGROW );
|
||||
|
||||
SetSizerAndFit(mainSizer);
|
||||
|
||||
// Allow using the control from keyboard on startup.
|
||||
m_ctrl[Page_Music]->SetFocus();
|
||||
}
|
||||
|
||||
MyFrame::~MyFrame()
|
||||
|
@@ -1265,7 +1265,14 @@ void wxDataViewCtrlBase::Expand(const wxDataViewItem& item)
|
||||
{
|
||||
ExpandAncestors(item);
|
||||
|
||||
DoExpand(item);
|
||||
DoExpand(item, false);
|
||||
}
|
||||
|
||||
void wxDataViewCtrlBase::ExpandChildren(const wxDataViewItem& item)
|
||||
{
|
||||
ExpandAncestors(item);
|
||||
|
||||
DoExpand(item, true);
|
||||
}
|
||||
|
||||
void wxDataViewCtrlBase::ExpandAncestors( const wxDataViewItem & item )
|
||||
@@ -1287,7 +1294,7 @@ void wxDataViewCtrlBase::ExpandAncestors( const wxDataViewItem & item )
|
||||
// then we expand the parents, starting at the root
|
||||
while (!parentChain.empty())
|
||||
{
|
||||
DoExpand(parentChain.back());
|
||||
DoExpand(parentChain.back(), false);
|
||||
parentChain.pop_back();
|
||||
}
|
||||
}
|
||||
|
@@ -874,7 +874,7 @@ public:
|
||||
void HitTest( const wxPoint & point, wxDataViewItem & item, wxDataViewColumn* &column );
|
||||
wxRect GetItemRect( const wxDataViewItem & item, const wxDataViewColumn* column );
|
||||
|
||||
void Expand( unsigned int row );
|
||||
void Expand( unsigned int row, bool expandChildren = false );
|
||||
void Collapse( unsigned int row );
|
||||
bool IsExpanded( unsigned int row ) const;
|
||||
bool HasChildren( unsigned int row ) const;
|
||||
@@ -990,6 +990,9 @@ private:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Helper of public Expand(), must be called with a valid node.
|
||||
void DoExpand(wxDataViewTreeNode* node, unsigned int row, bool expandChildren);
|
||||
|
||||
private:
|
||||
wxDataViewCtrl *m_owner;
|
||||
int m_lineHeight;
|
||||
@@ -3907,7 +3910,7 @@ bool wxDataViewMainWindow::HasChildren( unsigned int row ) const
|
||||
return true;
|
||||
}
|
||||
|
||||
void wxDataViewMainWindow::Expand( unsigned int row )
|
||||
void wxDataViewMainWindow::Expand( unsigned int row, bool expandChildren )
|
||||
{
|
||||
if (IsList())
|
||||
return;
|
||||
@@ -3916,16 +3919,17 @@ void wxDataViewMainWindow::Expand( unsigned int row )
|
||||
if (!node)
|
||||
return;
|
||||
|
||||
return DoExpand(node, row, expandChildren);
|
||||
}
|
||||
|
||||
void
|
||||
wxDataViewMainWindow::DoExpand(wxDataViewTreeNode* node,
|
||||
unsigned int row,
|
||||
bool expandChildren)
|
||||
{
|
||||
if (!node->HasChildren())
|
||||
return;
|
||||
|
||||
if ( m_rowHeightCache )
|
||||
{
|
||||
// Expand makes new rows visible thus we invalidates all following
|
||||
// rows in the height cache
|
||||
m_rowHeightCache->Remove(row);
|
||||
}
|
||||
|
||||
if (!node->IsOpen())
|
||||
{
|
||||
if ( !SendExpanderEvent(wxEVT_DATAVIEW_ITEM_EXPANDING, node->GetItem()) )
|
||||
@@ -3934,6 +3938,13 @@ void wxDataViewMainWindow::Expand( unsigned int row )
|
||||
return;
|
||||
}
|
||||
|
||||
if ( m_rowHeightCache )
|
||||
{
|
||||
// Expand makes new rows visible thus we invalidates all following
|
||||
// rows in the height cache
|
||||
m_rowHeightCache->Remove(row);
|
||||
}
|
||||
|
||||
node->ToggleOpen(this);
|
||||
|
||||
// build the children of current node
|
||||
@@ -3961,6 +3972,28 @@ void wxDataViewMainWindow::Expand( unsigned int row )
|
||||
// Send the expanded event
|
||||
SendExpanderEvent(wxEVT_DATAVIEW_ITEM_EXPANDED,node->GetItem());
|
||||
}
|
||||
|
||||
// Note that we have to expand the children when expanding recursively even
|
||||
// when this node itself was already open.
|
||||
if ( expandChildren )
|
||||
{
|
||||
const wxDataViewTreeNodes& children = node->GetChildNodes();
|
||||
|
||||
for ( wxDataViewTreeNodes::const_iterator i = children.begin();
|
||||
i != children.end();
|
||||
++i )
|
||||
{
|
||||
wxDataViewTreeNode* const child = *i;
|
||||
|
||||
// Row currently corresponds to the previous item, so increment it
|
||||
// first to correspond to this child.
|
||||
DoExpand(child, ++row, true);
|
||||
|
||||
// We don't need +1 here because we'll increment the row during the
|
||||
// next loop iteration.
|
||||
row += child->GetSubTreeCount();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wxDataViewMainWindow::Collapse(unsigned int row)
|
||||
@@ -4579,7 +4612,27 @@ void wxDataViewMainWindow::OnChar( wxKeyEvent &event )
|
||||
case WXK_DOWN:
|
||||
OnVerticalNavigation(event, +1);
|
||||
break;
|
||||
// Add the process for tree expanding/collapsing
|
||||
|
||||
case '+':
|
||||
case WXK_ADD:
|
||||
Expand(m_currentRow);
|
||||
break;
|
||||
|
||||
case '*':
|
||||
case WXK_MULTIPLY:
|
||||
if ( !IsExpanded(m_currentRow) )
|
||||
{
|
||||
Expand(m_currentRow, true /* recursively */);
|
||||
break;
|
||||
}
|
||||
//else: fall through to Collapse()
|
||||
wxFALLTHROUGH;
|
||||
|
||||
case '-':
|
||||
case WXK_SUBTRACT:
|
||||
Collapse(m_currentRow);
|
||||
break;
|
||||
|
||||
case WXK_LEFT:
|
||||
OnLeftKey(event);
|
||||
break;
|
||||
@@ -6309,11 +6362,11 @@ int wxDataViewCtrl::GetRowByItem( const wxDataViewItem & item ) const
|
||||
return m_clientArea->GetRowByItem( item );
|
||||
}
|
||||
|
||||
void wxDataViewCtrl::DoExpand( const wxDataViewItem & item )
|
||||
void wxDataViewCtrl::DoExpand( const wxDataViewItem & item, bool expandChildren )
|
||||
{
|
||||
int row = m_clientArea->GetRowByItem( item );
|
||||
if (row != -1)
|
||||
m_clientArea->Expand(row);
|
||||
m_clientArea->Expand(row, expandChildren);
|
||||
}
|
||||
|
||||
void wxDataViewCtrl::Collapse( const wxDataViewItem & item )
|
||||
|
@@ -5068,12 +5068,13 @@ wxDataViewColumn *wxDataViewCtrl::GetSortingColumn() const
|
||||
return m_internal->GetDataViewSortColumn();
|
||||
}
|
||||
|
||||
void wxDataViewCtrl::DoExpand( const wxDataViewItem & item )
|
||||
void wxDataViewCtrl::DoExpand( const wxDataViewItem & item, bool expandChildren )
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
iter.user_data = item.GetID();
|
||||
wxGtkTreePath path(m_internal->get_path( &iter ));
|
||||
gtk_tree_view_expand_row( GTK_TREE_VIEW(m_treeview), path, false );
|
||||
gtk_tree_view_expand_row( GTK_TREE_VIEW(m_treeview), path,
|
||||
expandChildren ? TRUE : FALSE );
|
||||
}
|
||||
|
||||
void wxDataViewCtrl::Collapse( const wxDataViewItem & item )
|
||||
|
@@ -2314,9 +2314,9 @@ void wxCocoaDataViewControl::EnsureVisible(const wxDataViewItem& item, const wxD
|
||||
}
|
||||
}
|
||||
|
||||
void wxCocoaDataViewControl::DoExpand(const wxDataViewItem& item)
|
||||
void wxCocoaDataViewControl::DoExpand(const wxDataViewItem& item, bool expandChildren)
|
||||
{
|
||||
[m_OutlineView expandItem:[m_DataSource getDataViewItemFromBuffer:item]];
|
||||
[m_OutlineView expandItem:[m_DataSource getDataViewItemFromBuffer:item] expandChildren:expandChildren];
|
||||
}
|
||||
|
||||
unsigned int wxCocoaDataViewControl::GetCount() const
|
||||
|
@@ -516,9 +516,9 @@ void wxDataViewCtrl::EnsureVisible(wxDataViewItem const& item, wxDataViewColumn
|
||||
}
|
||||
}
|
||||
|
||||
void wxDataViewCtrl::DoExpand(wxDataViewItem const& item)
|
||||
void wxDataViewCtrl::DoExpand(wxDataViewItem const& item, bool expandChildren)
|
||||
{
|
||||
return GetDataViewPeer()->DoExpand(item);
|
||||
return GetDataViewPeer()->DoExpand(item, expandChildren);
|
||||
}
|
||||
|
||||
bool wxDataViewCtrl::IsExpanded( const wxDataViewItem & item ) const
|
||||
|
@@ -267,7 +267,7 @@ wxRect wxDataViewCtrl::GetItemRect( const wxDataViewItem &item,
|
||||
return wxRect();
|
||||
}
|
||||
|
||||
void wxDataViewCtrl::Expand( const wxDataViewItem & item )
|
||||
void wxDataViewCtrl::DoExpand( const wxDataViewItem & item, bool expandChildren )
|
||||
{
|
||||
}
|
||||
|
||||
|
@@ -271,6 +271,19 @@ TEST_CASE_METHOD(SingleSelectDataViewCtrlTestCase,
|
||||
CHECK( !m_dvc->IsExpanded(m_grandchild) );
|
||||
#endif
|
||||
CHECK( !m_dvc->IsExpanded(m_child2) );
|
||||
|
||||
m_dvc->Collapse(m_root);
|
||||
CHECK( !m_dvc->IsExpanded(m_root) );
|
||||
|
||||
m_dvc->ExpandChildren(m_root);
|
||||
CHECK( m_dvc->IsExpanded(m_root) );
|
||||
CHECK( m_dvc->IsExpanded(m_child1) );
|
||||
|
||||
// Expanding an already expanded node must still expand all its children.
|
||||
m_dvc->Collapse(m_child1);
|
||||
CHECK( !m_dvc->IsExpanded(m_child1) );
|
||||
m_dvc->ExpandChildren(m_root);
|
||||
CHECK( m_dvc->IsExpanded(m_child1) );
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(SingleSelectDataViewCtrlTestCase,
|
||||
|
Reference in New Issue
Block a user