From f16b502f66d0466fa5d1921bb24fcac8add92891 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 23 May 2021 14:32:39 +0100 Subject: [PATCH] Forward key down/up events from wxCompositeWindow children too There doesn't seem to be any reason to only forward CHAR events, but not KEY_{DOWN,UP} ones, so do the same thing for the latter ones too. This allows to get rid of GetMainWindow() call in wxDataViewCtrl unit tests, as wxEVT_KEY_DOWN are now correctly received in the control itself and not just its main window. --- include/wx/compositewin.h | 8 ++++++-- tests/controls/dataviewctrltest.cpp | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/include/wx/compositewin.h b/include/wx/compositewin.h index a5d93b02bf..32bfcdd9cf 100644 --- a/include/wx/compositewin.h +++ b/include/wx/compositewin.h @@ -218,10 +218,14 @@ private: win = win->GetParent(); } - child->Bind(wxEVT_CHAR, &wxCompositeWindow::OnChar, this); + // Make all keyboard events occurring in sub-windows appear as coming + // from the main window itself. + child->Bind(wxEVT_KEY_DOWN, &wxCompositeWindow::OnKeyEvent, this); + child->Bind(wxEVT_CHAR, &wxCompositeWindow::OnKeyEvent, this); + child->Bind(wxEVT_KEY_UP, &wxCompositeWindow::OnKeyEvent, this); } - void OnChar(wxKeyEvent& event) + void OnKeyEvent(wxKeyEvent& event) { wxEventObjectOriginSetter setThis(event, this, this->GetId()); diff --git a/tests/controls/dataviewctrltest.cpp b/tests/controls/dataviewctrltest.cpp index a22a5aad11..d1c7053af1 100644 --- a/tests/controls/dataviewctrltest.cpp +++ b/tests/controls/dataviewctrltest.cpp @@ -423,7 +423,7 @@ TEST_CASE_METHOD(SingleSelectDataViewCtrlTestCase, if ( !EnableUITests() ) return; - EventCounter keyEvents(m_dvc->GetMainWindow(), wxEVT_KEY_DOWN); + EventCounter keyEvents(m_dvc, wxEVT_KEY_DOWN); m_dvc->SetFocus();