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.
This commit is contained in:
Vadim Zeitlin 2021-05-23 14:32:39 +01:00
parent 3ed930c736
commit f16b502f66
2 changed files with 7 additions and 3 deletions

View File

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

View File

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