]> git.saurik.com Git - wxWidgets.git/commitdiff
Activate cells from keyboard too in generic wxDataViewCtrl.
authorVáclav Slavík <vslavik@fastmail.fm>
Mon, 29 Aug 2011 17:25:25 +0000 (17:25 +0000)
committerVáclav Slavík <vslavik@fastmail.fm>
Mon, 29 Aug 2011 17:25:25 +0000 (17:25 +0000)
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

src/generic/datavgen.cpp

index 13233aa7e8bf7acb6c5571b69af79e5892d784be..e5cb0ce44d94fc27b6a73ea557eb5d299d0fa57d 100644 (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;