Use simple wxEVT_SEARCH[_CANCEL] names for wxSearchCtrl events
The old wxEVT_SEARCHCTRL_{SEARCH,CANCEL}_BTN event names were unwieldy and misleading because both of these events can be generated without using the buttons, but by pressing Enter or Esc (the latter currently works under macOS only, but this could change in the future).
This commit is contained in:
parent
ce43f772a9
commit
94620f6c59
@ -177,7 +177,8 @@ All (GUI):
|
||||
- Add Set/GetFooter/Text/Icon() to wxRichMessageDialog (Tobias Taschner)
|
||||
- Add wxFloatingPointValidator::SetFactor().
|
||||
- Add "hint" property to wxSearchCtrl XRC handler.
|
||||
- Generate wxEVT_SEARCHCTRL_SEARCH_BTN on Enter under all platforms.
|
||||
- Add wxEVT_SEARCH[_CANCEL] synonyms for wxSearchCtrl events.
|
||||
- Generate wxEVT_SEARCH on Enter under all platforms.
|
||||
|
||||
wxGTK:
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -35,19 +35,19 @@
|
||||
@endStyleTable
|
||||
|
||||
@beginEventEmissionTable{wxCommandEvent}
|
||||
To react to the changes in the control contents, use EVT_TEXT event, just
|
||||
To react to the changes in the control contents, use wxEVT_TEXT event, just
|
||||
as you would do with wxTextCtrl. However it is recommended to use
|
||||
EVT_SEARCHCTRL_SEARCH_BTN to actually start searching to avoid doing it too
|
||||
soon, while the user is still typing (note that EVT_SEARCHCTRL_SEARCH_BTN
|
||||
is also triggered by pressing Enter in the control).
|
||||
@event{EVT_SEARCHCTRL_SEARCH_BTN(id, func)}
|
||||
Respond to a @c wxEVT_SEARCHCTRL_SEARCH_BTN event, generated when the
|
||||
wxEVT_SEARCH to actually start searching to avoid doing it too soon, while
|
||||
the user is still typing (note that wxEVT_SEARCH is also triggered by
|
||||
pressing Enter in the control).
|
||||
@event{EVT_SEARCH(id, func)}
|
||||
Respond to a @c wxEVT_SEARCH event, generated when the
|
||||
search button is clicked. Note that this does not initiate a search on
|
||||
its own, you need to perform the appropriate action in your event
|
||||
handler. You may use @code event.GetString() @endcode to retrieve the
|
||||
string to search for in the event handler code.
|
||||
@event{EVT_SEARCHCTRL_CANCEL_BTN(id, func)}
|
||||
Respond to a @c wxEVT_SEARCHCTRL_CANCEL_BTN event, generated when the
|
||||
@event{EVT_SEARCH_CANCEL(id, func)}
|
||||
Respond to a @c wxEVT_SEARCH_CANCEL event, generated when the
|
||||
cancel button is clicked.
|
||||
@endEventTable
|
||||
|
||||
@ -161,5 +161,5 @@ public:
|
||||
};
|
||||
|
||||
|
||||
wxEventType wxEVT_SEARCHCTRL_CANCEL_BTN;
|
||||
wxEventType wxEVT_SEARCHCTRL_SEARCH_BTN;
|
||||
wxEventType wxEVT_SEARCH_CANCEL;
|
||||
wxEventType wxEVT_SEARCH;
|
||||
|
@ -120,8 +120,8 @@ wxBEGIN_EVENT_TABLE(SearchCtrlWidgetsPage, WidgetsPage)
|
||||
EVT_TEXT(wxID_ANY, SearchCtrlWidgetsPage::OnText)
|
||||
EVT_TEXT_ENTER(wxID_ANY, SearchCtrlWidgetsPage::OnTextEnter)
|
||||
|
||||
EVT_SEARCHCTRL_SEARCH_BTN(wxID_ANY, SearchCtrlWidgetsPage::OnSearch)
|
||||
EVT_SEARCHCTRL_CANCEL_BTN(wxID_ANY, SearchCtrlWidgetsPage::OnSearchCancel)
|
||||
EVT_SEARCH(wxID_ANY, SearchCtrlWidgetsPage::OnSearch)
|
||||
EVT_SEARCH_CANCEL(wxID_ANY, SearchCtrlWidgetsPage::OnSearchCancel)
|
||||
wxEND_EVENT_TABLE()
|
||||
|
||||
// ============================================================================
|
||||
|
@ -34,8 +34,8 @@
|
||||
|
||||
const char wxSearchCtrlNameStr[] = "searchCtrl";
|
||||
|
||||
wxDEFINE_EVENT(wxEVT_SEARCHCTRL_CANCEL_BTN, wxCommandEvent);
|
||||
wxDEFINE_EVENT(wxEVT_SEARCHCTRL_SEARCH_BTN, wxCommandEvent);
|
||||
wxDEFINE_EVENT(wxEVT_SEARCH_CANCEL, wxCommandEvent);
|
||||
wxDEFINE_EVENT(wxEVT_SEARCH, wxCommandEvent);
|
||||
|
||||
|
||||
#endif // wxUSE_SEARCHCTRL
|
||||
|
@ -96,7 +96,7 @@ protected:
|
||||
{
|
||||
if ( !IsEmpty() )
|
||||
{
|
||||
wxCommandEvent event(wxEVT_SEARCHCTRL_SEARCH_BTN, m_search->GetId());
|
||||
wxCommandEvent event(wxEVT_SEARCH, m_search->GetId());
|
||||
event.SetEventObject(m_search);
|
||||
event.SetString(m_search->GetValue());
|
||||
|
||||
@ -196,7 +196,7 @@ protected:
|
||||
wxCommandEvent event(m_eventType, m_search->GetId());
|
||||
event.SetEventObject(m_search);
|
||||
|
||||
if ( m_eventType == wxEVT_SEARCHCTRL_SEARCH_BTN )
|
||||
if ( m_eventType == wxEVT_SEARCH )
|
||||
{
|
||||
// it's convenient to have the string to search for directly in the
|
||||
// event instead of having to retrieve it from the control in the
|
||||
@ -209,7 +209,7 @@ protected:
|
||||
m_search->SetFocus();
|
||||
|
||||
#if wxUSE_MENUS
|
||||
if ( m_eventType == wxEVT_SEARCHCTRL_SEARCH_BTN )
|
||||
if ( m_eventType == wxEVT_SEARCH )
|
||||
{
|
||||
// this happens automatically, just like on Mac OS X
|
||||
m_search->PopupSearchMenu();
|
||||
@ -238,7 +238,7 @@ wxBEGIN_EVENT_TABLE(wxSearchButton, wxControl)
|
||||
wxEND_EVENT_TABLE()
|
||||
|
||||
wxBEGIN_EVENT_TABLE(wxSearchCtrl, wxSearchCtrlBase)
|
||||
EVT_SEARCHCTRL_CANCEL_BTN(wxID_ANY, wxSearchCtrl::OnCancelButton)
|
||||
EVT_SEARCH_CANCEL(wxID_ANY, wxSearchCtrl::OnCancelButton)
|
||||
EVT_SIZE(wxSearchCtrl::OnSize)
|
||||
wxEND_EVENT_TABLE()
|
||||
|
||||
@ -322,10 +322,10 @@ bool wxSearchCtrl::Create(wxWindow *parent, wxWindowID id,
|
||||
m_text = new wxSearchTextCtrl(this, value, style);
|
||||
|
||||
m_searchButton = new wxSearchButton(this,
|
||||
wxEVT_SEARCHCTRL_SEARCH_BTN,
|
||||
wxEVT_SEARCH,
|
||||
m_searchBitmap);
|
||||
m_cancelButton = new wxSearchButton(this,
|
||||
wxEVT_SEARCHCTRL_CANCEL_BTN,
|
||||
wxEVT_SEARCH_CANCEL,
|
||||
m_cancelBitmap);
|
||||
|
||||
SetBackgroundColour( m_text->GetBackgroundColour() );
|
||||
|
@ -209,7 +209,7 @@ bool wxSearchCtrl::Create(wxWindow *parent, wxWindowID id,
|
||||
|
||||
bool wxSearchCtrl::HandleSearchFieldSearchHit()
|
||||
{
|
||||
wxCommandEvent event(wxEVT_SEARCHCTRL_SEARCH_BTN, m_windowId );
|
||||
wxCommandEvent event(wxEVT_SEARCH, m_windowId );
|
||||
event.SetEventObject(this);
|
||||
|
||||
// provide the string to search for directly in the event, this is more
|
||||
@ -221,7 +221,7 @@ bool wxSearchCtrl::HandleSearchFieldSearchHit()
|
||||
|
||||
bool wxSearchCtrl::HandleSearchFieldCancelHit()
|
||||
{
|
||||
wxCommandEvent event(wxEVT_SEARCHCTRL_CANCEL_BTN, m_windowId );
|
||||
wxCommandEvent event(wxEVT_SEARCH_CANCEL, m_windowId );
|
||||
event.SetEventObject(this);
|
||||
return ProcessCommand(event);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user