X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/526954c5968baa29218c994ec48e476ae2bd4b9f..2aee45f63afa24557ffc9465ed9ea4df8e2c54a7:/samples/widgets/searchctrl.cpp diff --git a/samples/widgets/searchctrl.cpp b/samples/widgets/searchctrl.cpp index 6ccf62e1f6..4c8e900c40 100644 --- a/samples/widgets/searchctrl.cpp +++ b/samples/widgets/searchctrl.cpp @@ -5,7 +5,7 @@ // Author: Robin Dunn // Created: 9-Dec-2006 // Id: $Id$ -// Copyright: (c) 2006 +// Copyright: (c) 2006 // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -73,7 +73,7 @@ public: virtual wxControl *GetWidget() const { return m_srchCtrl; } virtual wxTextEntryBase *GetTextEntry() const { return m_srchCtrl; } - virtual void RecreateWidget() { CreateControl(); } + virtual void RecreateWidget(); // lazy creation of the content virtual void CreateContent(); @@ -85,16 +85,14 @@ protected: void OnToggleSearchMenu(wxCommandEvent&); void OnSearch(wxCommandEvent& event); + void OnSearchCancel(wxCommandEvent& event); wxMenu* CreateTestMenu(); - + // (re)create the control void CreateControl(); - // reset the control parameters - void Reset(); - - + wxSearchCtrl* m_srchCtrl; wxCheckBox* m_searchBtnCheck; wxCheckBox* m_cancelBtnCheck; @@ -115,6 +113,7 @@ BEGIN_EVENT_TABLE(SearchCtrlWidgetsPage, WidgetsPage) EVT_CHECKBOX(ID_MENU_CB, SearchCtrlWidgetsPage::OnToggleSearchMenu) EVT_SEARCHCTRL_SEARCH_BTN(wxID_ANY, SearchCtrlWidgetsPage::OnSearch) + EVT_SEARCHCTRL_CANCEL_BTN(wxID_ANY, SearchCtrlWidgetsPage::OnSearchCancel) END_EVENT_TABLE() // ============================================================================ @@ -140,7 +139,6 @@ void SearchCtrlWidgetsPage::CreateContent() { m_srchCtrl = NULL; - Reset(); CreateControl(); @@ -153,7 +151,7 @@ void SearchCtrlWidgetsPage::CreateContent() m_menuBtnCheck = new wxCheckBox(this, ID_MENU_CB, wxT("Search menu")); m_searchBtnCheck->SetValue(true); - + box->Add(m_searchBtnCheck, 0, wxALL, 5); box->Add(m_cancelBtnCheck, 0, wxALL, 5); box->Add(m_menuBtnCheck, 0, wxALL, 5); @@ -171,15 +169,19 @@ void SearchCtrlWidgetsPage::CreateControl() m_srchCtrl->Destroy(); int style = 0; - + m_srchCtrl = new wxSearchCtrl(this, -1, wxEmptyString, wxDefaultPosition, wxSize(150, -1), style); } -void SearchCtrlWidgetsPage::Reset() -{ -} +void SearchCtrlWidgetsPage::RecreateWidget() +{ + CreateControl(); + GetSizer()->Add(m_srchCtrl, wxSizerFlags().Centre().TripleBorder()); + + Layout(); +} wxMenu* SearchCtrlWidgetsPage::CreateTestMenu() { @@ -193,7 +195,7 @@ wxMenu* SearchCtrlWidgetsPage::CreateTestMenu() wxString tipText = wxString::Format(wxT("tip %i"),i); menu->Append(ID_SEARCHMENU+i, itemText, tipText, wxITEM_NORMAL); } -// target->Connect( +// target->Connect( // ID_SEARCHMENU, // ID_SEARCHMENU+SEARCH_MENU_SIZE, // wxEVT_COMMAND_MENU_SELECTED, @@ -215,7 +217,7 @@ void SearchCtrlWidgetsPage::OnToggleSearchButton(wxCommandEvent&) void SearchCtrlWidgetsPage::OnToggleCancelButton(wxCommandEvent&) { m_srchCtrl->ShowCancelButton( m_cancelBtnCheck->GetValue() ); - + } void SearchCtrlWidgetsPage::OnToggleSearchMenu(wxCommandEvent&) @@ -231,4 +233,11 @@ void SearchCtrlWidgetsPage::OnSearch(wxCommandEvent& event) wxLogMessage("Search button: search for \"%s\".", event.GetString()); } +void SearchCtrlWidgetsPage::OnSearchCancel(wxCommandEvent& event) +{ + wxLogMessage("Cancel button pressed."); + + event.Skip(); +} + #endif // wxUSE_SEARCHCTRL