From: Václav Slavík Date: Sat, 3 Sep 2011 13:14:20 +0000 (+0000) Subject: Fix generic wxDataViewCtrl Enter handling to conform to Windows UI. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/c2efa4b48aa1ff1d15caa6ef6ce23affe01cc946 Fix generic wxDataViewCtrl Enter handling to conform to Windows UI. Spacebar is used to activate columns (e.g. toggle a checkbox). Enter activates the item, i.e. sends wxEVT_COMMAND_ITEM_ACTIVATED. If that event isn't handled, Enter acts the same as Space. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@68992 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index 9959c748ff..8cd3e24a25 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -3325,10 +3325,26 @@ void wxDataViewMainWindow::OnChar( wxKeyEvent &event ) switch ( event.GetKeyCode() ) { case WXK_RETURN: - case WXK_SPACE: { + // Enter activates the item, i.e. sends wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED to + // it. Only if that event is not handled do we activate column renderer (which + // is normally done by Space). + const wxDataViewItem item = GetItemByRow(m_currentRow); + wxDataViewEvent le(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, + parent->GetId()); + le.SetItem(item); + le.SetEventObject(parent); + le.SetModel(GetModel()); + + if ( parent->GetEventHandler()->ProcessEvent(le) ) + break; + // else: fall through to WXK_SPACE handling + } + + case WXK_SPACE: + { // Activate the first activatable column if there is any: wxDataViewColumn *activatableCol = NULL; @@ -3345,27 +3361,16 @@ void wxDataViewMainWindow::OnChar( wxKeyEvent &event ) } } - bool activated = false; - if ( activatableCol ) { + const wxDataViewItem item = GetItemByRow(m_currentRow); + const unsigned colIdx = activatableCol->GetModelColumn(); const wxRect cell_rect = GetOwner()->GetItemRect(item, activatableCol); wxDataViewRenderer *cell = activatableCol->GetRenderer(); cell->PrepareForItem(GetModel(), item, colIdx); - activated = cell->WXOnActivate(cell_rect, GetModel(), item, colIdx); - } - - if ( !activated ) - { - wxDataViewEvent le(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, - parent->GetId()); - le.SetItem(item); - le.SetEventObject(parent); - le.SetModel(GetModel()); - - parent->GetEventHandler()->ProcessEvent(le); + cell->WXOnActivate(cell_rect, GetModel(), item, colIdx); } } break;