]> git.saurik.com Git - wxWidgets.git/commitdiff
Set the string to search for in wxSearchCtrl events.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 11 Jul 2010 10:44:18 +0000 (10:44 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 11 Jul 2010 10:44:18 +0000 (10:44 +0000)
It's more convenient to have the string to search for directly in the event
object than to retrieve it from wxSearchCtrl itself as it had to be done
before.

Closes #4665.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64886 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

interface/wx/srchctrl.h
samples/widgets/searchctrl.cpp
src/generic/srchctlg.cpp
src/osx/srchctrl_osx.cpp

index 29b9294c41cca48444cfaf606c4064ce9b581d8b..bcfce39c9f520dd9e2cdbab036b14995c428e7c7 100644 (file)
     just as you would with wxTextCtrl.
     @event{EVT_SEARCHCTRL_SEARCH_BTN(id, func)}
         Respond to a wxEVT_SEARCHCTRL_SEARCH_BTN event, generated when the
-        search button is clicked. Note that this does not initiate a search.
+        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 wxEVT_SEARCHCTRL_CANCEL_BTN event, generated when the
         cancel button is clicked.
index 3c5bb3956a698b356c5f7a95f7ec3327b3e98099..4031dbd51ff4e8655f879645ed24d2e393f5e871 100644 (file)
@@ -84,6 +84,8 @@ protected:
     void OnToggleCancelButton(wxCommandEvent&);
     void OnToggleSearchMenu(wxCommandEvent&);
 
+    void OnSearch(wxCommandEvent& event);
+
     wxMenu* CreateTestMenu();
     
     // (re)create the control
@@ -111,6 +113,8 @@ BEGIN_EVENT_TABLE(SearchCtrlWidgetsPage, WidgetsPage)
     EVT_CHECKBOX(ID_SEARCH_CB, SearchCtrlWidgetsPage::OnToggleSearchButton)
     EVT_CHECKBOX(ID_CANCEL_CB, SearchCtrlWidgetsPage::OnToggleCancelButton)
     EVT_CHECKBOX(ID_MENU_CB, SearchCtrlWidgetsPage::OnToggleSearchMenu)
+
+    EVT_SEARCHCTRL_SEARCH_BTN(wxID_ANY, SearchCtrlWidgetsPage::OnSearch)
 END_EVENT_TABLE()
 
 // ============================================================================
@@ -222,5 +226,9 @@ void SearchCtrlWidgetsPage::OnToggleSearchMenu(wxCommandEvent&)
         m_srchCtrl->SetMenu(NULL);
 }
 
+void SearchCtrlWidgetsPage::OnSearch(wxCommandEvent& event)
+{
+    wxLogMessage("Search button: search for \"%s\".", event.GetString());
+}
 
 #endif  //  wxUSE_SEARCHCTRL
index 494ae1537f76d125fe5c95537a517ea974be1949..ce7d03c2a3c0334518ad9c3fab16ad0d00abddef 100644 (file)
@@ -242,6 +242,14 @@ protected:
         wxCommandEvent event(m_eventType, m_search->GetId());
         event.SetEventObject(m_search);
 
+        if ( m_eventType == wxEVT_COMMAND_SEARCHCTRL_SEARCH_BTN )
+        {
+            // 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
+            // event handler code later, so provide it here
+            event.SetString(m_search->GetValue());
+        }
+
         GetEventHandler()->ProcessEvent(event);
 
         m_search->SetFocus();
index 7881f00e349e94a3cd1a272c2fabb33c02961052..0b5f068eb45032d2815d7eeb031555209959524f 100644 (file)
@@ -205,6 +205,11 @@ bool wxSearchCtrl::HandleSearchFieldSearchHit()
 {
     wxCommandEvent event(wxEVT_COMMAND_SEARCHCTRL_SEARCH_BTN, m_windowId );
     event.SetEventObject(this);
+
+    // provide the string to search for directly in the event, this is more
+    // convenient than retrieving it from the control in event handler code
+    event.SetString(GetValue());
+
     return ProcessCommand(event);
 }