From 25a2bae83611e768403d4485fadb0f13053d9d38 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 23 Jul 2018 00:29:31 +0200 Subject: [PATCH] Test focus event generation for all pages of the widgets sample Previously this was done only for wxSearchCtrl, extend this now to all the widgets in order to be able to check whether the expected events are generated. --- samples/widgets/searchctrl.cpp | 20 -------------------- samples/widgets/widgets.cpp | 31 +++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/samples/widgets/searchctrl.cpp b/samples/widgets/searchctrl.cpp index a4607cafa7..ec295e87e9 100644 --- a/samples/widgets/searchctrl.cpp +++ b/samples/widgets/searchctrl.cpp @@ -88,9 +88,6 @@ protected: void OnSearch(wxCommandEvent& event); void OnSearchCancel(wxCommandEvent& event); - void OnSetFocus(wxFocusEvent& event); - void OnKillFocus(wxFocusEvent& event); - wxMenu* CreateTestMenu(); // (re)create the control @@ -179,9 +176,6 @@ void SearchCtrlWidgetsPage::CreateControl() m_srchCtrl = new wxSearchCtrl(this, -1, wxEmptyString, wxDefaultPosition, FromDIP(wxSize(150, -1)), style); - - m_srchCtrl->Bind(wxEVT_SET_FOCUS, &SearchCtrlWidgetsPage::OnSetFocus, this); - m_srchCtrl->Bind(wxEVT_KILL_FOCUS, &SearchCtrlWidgetsPage::OnKillFocus, this); } void SearchCtrlWidgetsPage::RecreateWidget() @@ -256,18 +250,4 @@ void SearchCtrlWidgetsPage::OnSearchCancel(wxCommandEvent& event) event.Skip(); } -void SearchCtrlWidgetsPage::OnSetFocus(wxFocusEvent& event) -{ - wxLogMessage("Search control got focus"); - - event.Skip(); -} - -void SearchCtrlWidgetsPage::OnKillFocus(wxFocusEvent& event) -{ - wxLogMessage("Search control lost focus"); - - event.Skip(); -} - #endif // wxUSE_SEARCHCTRL diff --git a/samples/widgets/widgets.cpp b/samples/widgets/widgets.cpp index 3cd4f6c6a3..5df2d6972c 100644 --- a/samples/widgets/widgets.cpp +++ b/samples/widgets/widgets.cpp @@ -210,6 +210,10 @@ protected: WidgetsPage *CurrentPage(); private: + void OnWidgetFocus(wxFocusEvent& event); + + void ConnectToWidgetEvents(); + // the panel containing everything wxPanel *m_panel; @@ -668,6 +672,19 @@ WidgetsPage *WidgetsFrame::CurrentPage() return wxStaticCast(page, WidgetsPage); } +void WidgetsFrame::ConnectToWidgetEvents() +{ + const Widgets& widgets = CurrentPage()->GetWidgets(); + + for ( Widgets::const_iterator it = widgets.begin(); + it != widgets.end(); + ++it ) + { + (*it)->Bind(wxEVT_SET_FOCUS, &WidgetsFrame::OnWidgetFocus, this); + (*it)->Bind(wxEVT_KILL_FOCUS, &WidgetsFrame::OnWidgetFocus, this); + } +} + WidgetsFrame::~WidgetsFrame() { #if USE_LOG @@ -723,7 +740,10 @@ void WidgetsFrame::OnPageChanged(WidgetsBookCtrlEvent& event) wxWindowUpdateLocker noUpdates(curPage); curPage->CreateContent(); curPage->Layout(); + + ConnectToWidgetEvents(); } + // re-apply the attributes to the widget(s) curPage->SetUpWidget(); @@ -890,6 +910,9 @@ void WidgetsFrame::OnSetBorder(wxCommandEvent& event) WidgetsPage *page = CurrentPage(); page->RecreateWidget(); + + ConnectToWidgetEvents(); + // re-apply the attributes to the widget(s) page->SetUpWidget(); } @@ -1172,6 +1195,14 @@ void WidgetsFrame::OnSetHint(wxCommandEvent& WXUNUSED(event)) #endif // wxUSE_MENUS +void WidgetsFrame::OnWidgetFocus(wxFocusEvent& event) +{ + wxLogMessage("Widgets %s focus", + event.GetEventType() == wxEVT_SET_FOCUS ? "got" : "lost"); + + event.Skip(); +} + // ---------------------------------------------------------------------------- // WidgetsPageInfo // ----------------------------------------------------------------------------