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
This commit is contained in:
Václav Slavík 2011-11-08 10:53:49 +00:00
parent 5ced53e599
commit 0fff3dfcbb

View File

@ -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();
}