Consolidate common logic into a single function and revert original test for IsList() to minimize code changes.

This commit is contained in:
Jorge Moraleda
2020-04-13 18:40:31 -07:00
parent ea4a6ec0e9
commit 8a3b0a9fd6

View File

@@ -910,6 +910,22 @@ private:
// assumes that all columns were modified, otherwise just this one. // assumes that all columns were modified, otherwise just this one.
bool DoItemChanged(const wxDataViewItem& item, int view_column); bool DoItemChanged(const wxDataViewItem& item, int view_column);
// Return whether the item has more than one column that have values
bool HasItemMultipleValues(const wxDataViewItem& item)
{
unsigned int numColsWithValue = 0;
unsigned int cols = GetOwner()->GetColumnCount();
wxDataViewModel* model = GetModel();
for ( unsigned int i = 0; i < cols; i++ )
{
if ( model->HasValue(item, i) )
numColsWithValue++;
if ( numColsWithValue > 1 )
return true;
}
return false;
}
private: private:
wxDataViewCtrl *m_owner; wxDataViewCtrl *m_owner;
int m_lineHeight; int m_lineHeight;
@@ -2394,18 +2410,15 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
if ( m_useCellFocus && m_currentCol && m_currentColSetByKeyboard ) if ( m_useCellFocus && m_currentCol && m_currentColSetByKeyboard )
{ {
// If this is an item with a single column, render full-row focus: renderColumnFocus = true;
unsigned int numColsWithValue = 0;
unsigned int cols = GetOwner()->GetColumnCount(); // If this is container node without columns, render full-row focus:
for ( unsigned int i = 0; i < cols; i++ ) if ( !IsList() )
{ {
wxDataViewTreeNode *node = GetTreeNodeByRow(item); wxDataViewTreeNode *node = GetTreeNodeByRow(item);
if ( model->HasValue(node->GetItem(), i) ) if ( !HasItemMultipleValues(node->GetItem()) )
numColsWithValue++; renderColumnFocus = false;
if ( numColsWithValue > 1 )
break;
} }
renderColumnFocus = numColsWithValue<2;
} }
if ( renderColumnFocus ) if ( renderColumnFocus )
@@ -4498,12 +4511,7 @@ bool wxDataViewMainWindow::TryAdvanceCurrentColumn(wxDataViewTreeNode *node, wxK
if ( node ) if ( node )
{ {
// navigation shouldn't work in nodes with fewer than two columns // navigation shouldn't work in nodes with fewer than two columns
unsigned int numColsWithValue = 0; if ( !HasItemMultipleValues(node->GetItem()) )
unsigned int cols = GetOwner()->GetColumnCount();
for ( unsigned int i = 0; i < cols; i++ )
if ( GetModel()->HasValue(node->GetItem(), i) )
numColsWithValue++;
if (numColsWithValue<2)
return false; return false;
} }