From 0fff3dfcbbbe99a7a2046093f8b245ce87bbe583 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Tue, 8 Nov 2011 10:53:49 +0000 Subject: [PATCH] Use Enter and Space for cell editing in generic wxDVC too. If the normal Enter or Space processing (sending activate event or doing activatable editing respectively) isn't handled by the control, use these keys to trigger inline editing too, as F2 does. This makes the Windows control more similar to OS X and GTK+ ones and makes discovering editability easier. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@69695 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/generic/datavgen.cpp | 63 ++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index cb12deac68..562ead4d8e 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -3433,7 +3433,7 @@ void wxDataViewMainWindow::OnChar( wxKeyEvent &event ) { // 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). + // is normally done by Space) or even inline editing. const wxDataViewItem item = GetItemByRow(m_currentRow); @@ -3450,6 +3450,11 @@ void wxDataViewMainWindow::OnChar( wxKeyEvent &event ) case WXK_SPACE: { + // Space toggles activatable items or -- if not activatable -- + // starts inline editing (this is normally done using F2 on + // Windows, but Space is common everywhere else, so use it too + // for greater cross-platform compatibility). + const wxDataViewItem item = GetItemByRow(m_currentRow); // Activate the current activatable column. If not column is focused (typically @@ -3466,6 +3471,35 @@ void wxDataViewMainWindow::OnChar( wxKeyEvent &event ) wxDataViewRenderer *cell = activatableCol->GetRenderer(); cell->PrepareForItem(GetModel(), item, colIdx); cell->WXActivateCell(cell_rect, GetModel(), item, colIdx, NULL); + + break; + } + // else: fall through to WXK_F2 handling + } + + case WXK_F2: + { + if( !m_selection.empty() ) + { + // Mimic Windows 7 behavior: edit the item that has focus + // if it is selected and the first selected item if focus + // is out of selection. + int sel; + if ( m_selection.Index(m_currentRow) != wxNOT_FOUND ) + sel = m_currentRow; + else + sel = m_selection[0]; + + + const wxDataViewItem item = GetItemByRow(sel); + + // Edit the current column. If no column is focused + // (typically because the user has full row selected), try + // to find the first editable column. + wxDataViewColumn *editableCol = FindColumnForEditing(item, wxDATAVIEW_CELL_EDITABLE); + + if ( editableCol ) + GetOwner()->StartEditor(item, GetOwner()->GetColumnIndex(editableCol)); } } break; @@ -3522,33 +3556,6 @@ void wxDataViewMainWindow::OnChar( wxKeyEvent &event ) } break; - case WXK_F2: - { - if( !m_selection.empty() ) - { - // Mimic Windows 7 behavior: edit the item that has focus - // if it is selected and the first selected item if focus - // is out of selection. - int sel; - if ( m_selection.Index(m_currentRow) != wxNOT_FOUND ) - sel = m_currentRow; - else - sel = m_selection[0]; - - - const wxDataViewItem item = GetItemByRow(sel); - - // Edit the current column. If not column is focused - // (typically because the user has full row selected), try - // to find the first editable column. - wxDataViewColumn *editableCol = FindColumnForEditing(item, wxDATAVIEW_CELL_EDITABLE); - - if ( editableCol ) - GetOwner()->StartEditor(item, GetOwner()->GetColumnIndex(editableCol)); - } - } - break; - default: event.Skip(); }