Merge branch 'gtk-datapick-focus'

Fix focus event generation for generic wxDatePickerCtrl and other
wxCompositeWindows.

See https://github.com/wxWidgets/wxWidgets/pull/860

Closes #18120.
This commit is contained in:
Vadim Zeitlin
2018-07-25 20:15:32 +02:00
7 changed files with 145 additions and 50 deletions

View File

@@ -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

View File

@@ -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
// ----------------------------------------------------------------------------