Merge branch 'search-events'

Harmonize the behaviour across platforms.

Also fix ChangeValue() for this control.

And finally rename the events to use simpler names.

See https://github.com/wxWidgets/wxWidgets/pull/699
This commit is contained in:
Vadim Zeitlin
2018-01-30 14:12:30 +01:00
10 changed files with 150 additions and 91 deletions

View File

@@ -193,7 +193,10 @@ private:
if ( child == this )
return; // not a child, we don't want to Connect() to ourselves
// Always capture wxEVT_KILL_FOCUS:
child->Connect(wxEVT_SET_FOCUS,
wxFocusEventHandler(wxCompositeWindow::OnSetFocus),
NULL, this);
child->Connect(wxEVT_KILL_FOCUS,
wxFocusEventHandler(wxCompositeWindow::OnKillFocus),
NULL, this);
@@ -221,6 +224,27 @@ private:
event.Skip();
}
void OnSetFocus(wxFocusEvent& event)
{
event.Skip();
// When a child of a composite window gains focus, the entire composite
// focus gains focus as well -- unless it had it already.
//
// We suppose that we hadn't had focus if the event doesn't carry the
// previously focused window as it normally means that it comes from
// outside of this program.
wxWindow* const oldFocus = event.GetWindow();
if ( !oldFocus || oldFocus->GetMainWindowOfCompositeControl() != this )
{
wxFocusEvent eventThis(wxEVT_SET_FOCUS, this->GetId());
eventThis.SetEventObject(this);
eventThis.SetWindow(event.GetWindow());
this->ProcessWindowEvent(eventThis);
}
}
void OnKillFocus(wxFocusEvent& event)
{
// Ignore focus changes within the composite control:

View File

@@ -88,6 +88,8 @@ public:
// operations
// ----------
virtual void ChangeValue(const wxString& value) wxOVERRIDE;
// editing
virtual void Clear() wxOVERRIDE;
virtual void Replace(long from, long to, const wxString& value) wxOVERRIDE;
@@ -223,7 +225,6 @@ protected:
void OnCancelButton( wxCommandEvent& event );
void OnSetFocus( wxFocusEvent& event );
void OnSize( wxSizeEvent& event );
bool HasMenu() const

View File

@@ -41,8 +41,8 @@
extern WXDLLIMPEXP_DATA_CORE(const char) wxSearchCtrlNameStr[];
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SEARCHCTRL_CANCEL_BTN, wxCommandEvent);
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SEARCHCTRL_SEARCH_BTN, wxCommandEvent);
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SEARCH_CANCEL, wxCommandEvent);
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SEARCH, wxCommandEvent);
// ----------------------------------------------------------------------------
// a search ctrl is a text control with a search button and a cancel button
@@ -90,13 +90,20 @@ private:
// macros for handling search events
// ----------------------------------------------------------------------------
#define EVT_SEARCHCTRL_CANCEL_BTN(id, fn) \
wx__DECLARE_EVT1(wxEVT_SEARCHCTRL_CANCEL_BTN, id, wxCommandEventHandler(fn))
#define EVT_SEARCH_CANCEL(id, fn) \
wx__DECLARE_EVT1(wxEVT_SEARCH_CANCEL, id, wxCommandEventHandler(fn))
#define EVT_SEARCHCTRL_SEARCH_BTN(id, fn) \
wx__DECLARE_EVT1(wxEVT_SEARCHCTRL_SEARCH_BTN, id, wxCommandEventHandler(fn))
#define EVT_SEARCH(id, fn) \
wx__DECLARE_EVT1(wxEVT_SEARCH, id, wxCommandEventHandler(fn))
// old wxEVT_COMMAND_* constants
// old synonyms
#define wxEVT_SEARCHCTRL_CANCEL_BTN wxEVT_SEARCH_CANCEL
#define wxEVT_SEARCHCTRL_SEARCH_BTN wxEVT_SEARCH
#define EVT_SEARCHCTRL_CANCEL_BTN(id, fn) EVT_SEARCH_CANCEL(id, fn)
#define EVT_SEARCHCTRL_SEARCH_BTN(id, fn) EVT_SEARCH(id, fn)
// even older wxEVT_COMMAND_* constants
#define wxEVT_COMMAND_SEARCHCTRL_CANCEL_BTN wxEVT_SEARCHCTRL_CANCEL_BTN
#define wxEVT_COMMAND_SEARCHCTRL_SEARCH_BTN wxEVT_SEARCHCTRL_SEARCH_BTN