Generate key events in generic wxDataViewCtrl implementation.

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
This commit is contained in:
Vadim Zeitlin
2010-07-14 11:12:03 +00:00
parent e0ff229573
commit 63ced01b22
2 changed files with 38 additions and 6 deletions

View File

@@ -71,8 +71,8 @@ public:
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);
@@ -127,7 +127,12 @@ public: // event handlers
void OnDropPossible( wxDataViewEvent &event );
void OnDrop( wxDataViewEvent &event );
private:
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:
@@ -510,6 +515,9 @@ void MyFrame::BuildDataViewCtrl(wxPanel* parent, unsigned int nPanel, unsigned l
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() );
@@ -851,7 +859,7 @@ void MyFrame::OnAddMozart( wxCommandEvent& WXUNUSED(event) )
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 );
@@ -860,6 +868,11 @@ void MyFrame::OnDeleteSelected( wxCommandEvent& WXUNUSED(event) )
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 ) );
@@ -1074,6 +1087,13 @@ void MyFrame::OnRightClick( wxMouseEvent &event )
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