From 4c075c2128c9de7a78399d1587ff79778c04f076 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 8 Sep 2019 18:48:30 +0200 Subject: [PATCH] Replace Bind() call with an event table in Enter handling tests For once, using the event table macros is preferable because this bypasses the (generally helpful, but not here) test done by Bind() verifying that wxEVT_TEXT_ENTER handler is bound to a window with wxTE_PROCESS_ENTER style. Doing it like this will allow to check that controls without this style really do not receive the corresponding event. --- tests/controls/textentrytest.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/controls/textentrytest.cpp b/tests/controls/textentrytest.cpp index 7e40d42bec..4d1178a555 100644 --- a/tests/controls/textentrytest.cpp +++ b/tests/controls/textentrytest.cpp @@ -398,11 +398,6 @@ public: m_processEnter(processEnter), m_gotEnter(false) { - // We can't always bind this handler because wx will helpfully - // complain if we bind it without using wxTE_PROCESS_ENTER. - if ( processEnter != ProcessEnter_No ) - m_control->Bind(wxEVT_TEXT_ENTER, &TestDialog::OnTextEnter, this); - wxSizer* const sizer = new wxBoxSizer(wxVERTICAL); sizer->Add(m_control, wxSizerFlags().Expand()); sizer->Add(CreateStdDialogButtonSizer(wxOK)); @@ -455,8 +450,18 @@ private: const ProcessEnter m_processEnter; wxTimer m_timer; bool m_gotEnter; + + wxDECLARE_EVENT_TABLE(); }; +// Note that we must use event table macros here instead of Bind() because +// binding wxEVT_TEXT_ENTER handler for a control without wxTE_PROCESS_ENTER +// style would fail with an assertion failure, due to wx helpfully complaining +// about it. +wxBEGIN_EVENT_TABLE(TestDialog, wxDialog) + EVT_TEXT_ENTER(wxID_ANY, TestDialog::OnTextEnter) +wxEND_EVENT_TABLE() + } // anonymous namespace void TestProcessEnter(const TextLikeControlCreator& controlCreator)