Forward wxEVT_CHAR events from wxDataViewMainWindow to the parent window so
that they could be processed at wxDataViewCtrl level.
Call DisableKeyboardScrolling() to ensure that cursor movement keys are not
always eaten by the parent window but can be used for the navigation in the
control if they're not processed by user.
Add a test keyboard handler to the dataview sample to check that handling keys
in wxDataViewCtrl does work.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64957
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
unsigned int nPanel,
unsigned long style = 0);
unsigned int nPanel,
unsigned long style = 0);
-public: // event handlers
-
+private:
+ // event handlers
void OnStyleChange(wxCommandEvent& event);
void OnSetBackgroundColour(wxCommandEvent& event);
void OnSetForegroundColour(wxCommandEvent& event);
void OnStyleChange(wxCommandEvent& event);
void OnSetBackgroundColour(wxCommandEvent& event);
void OnSetForegroundColour(wxCommandEvent& event);
void OnDropPossible( wxDataViewEvent &event );
void OnDrop( wxDataViewEvent &event );
void OnDropPossible( wxDataViewEvent &event );
void OnDrop( wxDataViewEvent &event );
+ void OnDataViewChar(wxKeyEvent& event);
+
+ // helper used by both OnDeleteSelected() and OnDataViewChar()
+ void DeleteSelectedItems();
+
+
wxNotebook* m_notebook;
// the controls stored in the various tabs of the main notebook:
wxNotebook* m_notebook;
// the controls stored in the various tabs of the main notebook:
m_ctrl[0] =
new wxDataViewCtrl( parent, ID_MUSIC_CTRL, wxDefaultPosition,
wxDefaultSize, style );
m_ctrl[0] =
new wxDataViewCtrl( parent, ID_MUSIC_CTRL, wxDefaultPosition,
wxDefaultSize, style );
+ m_ctrl[0]->Connect(wxEVT_CHAR,
+ wxKeyEventHandler(MyFrame::OnDataViewChar),
+ NULL, this);
m_music_model = new MyMusicTreeModel;
m_ctrl[0]->AssociateModel( m_music_model.get() );
m_music_model = new MyMusicTreeModel;
m_ctrl[0]->AssociateModel( m_music_model.get() );
m_music_model->AddToClassical( "Kleine Nachtmusik", "Wolfgang Mozart", 1787 );
}
m_music_model->AddToClassical( "Kleine Nachtmusik", "Wolfgang Mozart", 1787 );
}
-void MyFrame::OnDeleteSelected( wxCommandEvent& WXUNUSED(event) )
+void MyFrame::DeleteSelectedItems()
{
wxDataViewItemArray items;
int len = m_ctrl[0]->GetSelections( items );
{
wxDataViewItemArray items;
int len = m_ctrl[0]->GetSelections( items );
m_music_model->Delete( items[i] );
}
m_music_model->Delete( items[i] );
}
+void MyFrame::OnDeleteSelected( wxCommandEvent& WXUNUSED(event) )
+{
+ DeleteSelectedItems();
+}
+
void MyFrame::OnDeleteYear( wxCommandEvent& WXUNUSED(event) )
{
m_ctrl[0]->DeleteColumn( m_ctrl[0]->GetColumn( 2 ) );
void MyFrame::OnDeleteYear( wxCommandEvent& WXUNUSED(event) )
{
m_ctrl[0]->DeleteColumn( m_ctrl[0]->GetColumn( 2 ) );
event.GetX(), event.GetY() );
}
event.GetX(), event.GetY() );
}
+void MyFrame::OnDataViewChar(wxKeyEvent& event)
+{
+ if ( event.GetKeyCode() == WXK_DELETE )
+ DeleteSelectedItems();
+ else
+ event.Skip();
+}
// ----------------------------------------------------------------------------
// MyFrame - event handlers for the second page
// ----------------------------------------------------------------------------
// MyFrame - event handlers for the second page
void wxDataViewMainWindow::OnChar( wxKeyEvent &event )
{
void wxDataViewMainWindow::OnChar( wxKeyEvent &event )
{
- if ( GetParent()->HandleAsNavigationKey(event) )
+ wxWindow * const parent = GetParent();
+
+ // propagate the char event upwards
+ wxKeyEvent eventForParent(event);
+ eventForParent.SetEventObject(parent);
+ if ( parent->ProcessWindowEvent(eventForParent) )
+ return;
+
+ if ( parent->HandleAsNavigationKey(event) )
return;
// no item -> nothing to do
return;
// no item -> nothing to do
- wxWindow *parent = GetParent();
wxDataViewEvent le(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED,
parent->GetId());
le.SetItem( GetItemByRow(m_currentRow) );
wxDataViewEvent le(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED,
parent->GetId());
le.SetItem( GetItemByRow(m_currentRow) );
m_clientArea = new wxDataViewMainWindow( this, wxID_ANY );
m_clientArea = new wxDataViewMainWindow( this, wxID_ANY );
+ // We use the cursor keys for moving the selection, not scrolling, so call
+ // this method to ensure wxScrollHelperEvtHandler doesn't catch all
+ // keyboard events forwarded to us from wxListMainWindow.
+ DisableKeyboardScrolling();
+
if (HasFlag(wxDV_NO_HEADER))
m_headerArea = NULL;
else
if (HasFlag(wxDV_NO_HEADER))
m_headerArea = NULL;
else