Activate cells from keyboard too in generic wxDataViewCtrl.

wxDataViewCtrl only called WXOnActivate() in reaction to double-click.
When Enter/Spacebar was pressed, only
wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED was sent, without calling
OnActivate() even if it was possible.

Fixed to handle both kinds of input identically.

Because there's currently no way to change current focus to a particular
column (as GtkTreeView can do), call WXOnActivate() on the first
activatable column.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@68952 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík
2011-08-29 17:25:25 +00:00
parent 07968bbdc5
commit 276227fcbb

View File

@@ -3313,13 +3313,43 @@ void wxDataViewMainWindow::OnChar( wxKeyEvent &event )
case WXK_RETURN:
case WXK_SPACE:
{
wxDataViewEvent le(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED,
parent->GetId());
le.SetItem( GetItemByRow(m_currentRow) );
le.SetEventObject(parent);
le.SetModel(GetModel());
const wxDataViewItem item = GetItemByRow(m_currentRow);
parent->GetEventHandler()->ProcessEvent(le);
// Activate the first activatable column if there is any:
wxDataViewColumn *activatableCol = NULL;
const unsigned cols = GetOwner()->GetColumnCount();
for ( unsigned i = 0; i < cols; i++ )
{
wxDataViewColumn *c = GetOwner()->GetColumnAt(i);
if ( c->IsHidden() )
continue;
if ( c->GetRenderer()->GetMode() == wxDATAVIEW_CELL_ACTIVATABLE )
{
activatableCol = c;
break;
}
}
if ( activatableCol )
{
const unsigned colIdx = activatableCol->GetModelColumn();
const wxRect cell_rect = GetOwner()->GetItemRect(item, activatableCol);
wxDataViewRenderer *cell = activatableCol->GetRenderer();
cell->PrepareForItem(GetModel(), item, colIdx);
cell->WXOnActivate(cell_rect, GetModel(), item, colIdx);
}
else
{
wxDataViewEvent le(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED,
parent->GetId());
le.SetItem(item);
le.SetEventObject(parent);
le.SetModel(GetModel());
parent->GetEventHandler()->ProcessEvent(le);
}
}
break;