X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3f7f284d555df50912037296c5d74a2911975bce..4ed3f4abd801c9442c2eba3bcf3dcd22f8336c22:/samples/widgets/searchctrl.cpp diff --git a/samples/widgets/searchctrl.cpp b/samples/widgets/searchctrl.cpp index 2bd3905bb6..beedb630b2 100644 --- a/samples/widgets/searchctrl.cpp +++ b/samples/widgets/searchctrl.cpp @@ -5,8 +5,8 @@ // Author: Robin Dunn // Created: 9-Dec-2006 // Id: $Id$ -// Copyright: (c) 2006 -// License: wxWindows license +// Copyright: (c) 2006 +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// // ============================================================================ @@ -31,6 +31,7 @@ #include "wx/app.h" #include "wx/log.h" #include "wx/radiobox.h" + #include "wx/statbox.h" #endif #include "wx/artprov.h" @@ -71,7 +72,8 @@ public: virtual ~SearchCtrlWidgetsPage(){}; virtual wxControl *GetWidget() const { return m_srchCtrl; } - virtual void RecreateWidget() { CreateControl(); } + virtual wxTextEntryBase *GetTextEntry() const { return m_srchCtrl; } + virtual void RecreateWidget(); // lazy creation of the content virtual void CreateContent(); @@ -82,15 +84,15 @@ protected: void OnToggleCancelButton(wxCommandEvent&); 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; @@ -109,6 +111,9 @@ 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) + EVT_SEARCHCTRL_CANCEL_BTN(wxID_ANY, SearchCtrlWidgetsPage::OnSearchCancel) END_EVENT_TABLE() // ============================================================================ @@ -121,8 +126,8 @@ END_EVENT_TABLE() #define FAMILY_CTRLS GENERIC_CTRLS #endif -IMPLEMENT_WIDGETS_PAGE(SearchCtrlWidgetsPage, _T("SearchCtrl"), - FAMILY_CTRLS | ALL_CTRLS); +IMPLEMENT_WIDGETS_PAGE(SearchCtrlWidgetsPage, wxT("SearchCtrl"), + FAMILY_CTRLS | EDITABLE_CTRLS | ALL_CTRLS); SearchCtrlWidgetsPage::SearchCtrlWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist) @@ -134,7 +139,6 @@ void SearchCtrlWidgetsPage::CreateContent() { m_srchCtrl = NULL; - Reset(); CreateControl(); @@ -147,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); @@ -165,21 +169,25 @@ 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() { wxMenu* menu = new wxMenu; const int SEARCH_MENU_SIZE = 5; - wxMenuItem* menuItem = menu->Append(wxID_ANY, _T("Recent Searches"), wxT(""), wxITEM_NORMAL); + wxMenuItem* menuItem = menu->Append(wxID_ANY, wxT("Recent Searches"), wxT(""), wxITEM_NORMAL); menuItem->Enable(false); for ( int i = 0; i < SEARCH_MENU_SIZE; i++ ) { @@ -187,10 +195,10 @@ 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, +// wxEVT_MENU, // wxCommandEventHandler(MySearchCtrl::OnSearchMenu) // ); return menu; @@ -203,13 +211,13 @@ wxMenu* SearchCtrlWidgetsPage::CreateTestMenu() void SearchCtrlWidgetsPage::OnToggleSearchButton(wxCommandEvent&) { - m_srchCtrl->SetSearchButtonVisible( m_searchBtnCheck->GetValue() ); + m_srchCtrl->ShowSearchButton( m_searchBtnCheck->GetValue() ); } void SearchCtrlWidgetsPage::OnToggleCancelButton(wxCommandEvent&) { - m_srchCtrl->SetCancelButtonVisible( m_cancelBtnCheck->GetValue() ); - + m_srchCtrl->ShowCancelButton( m_cancelBtnCheck->GetValue() ); + } void SearchCtrlWidgetsPage::OnToggleSearchMenu(wxCommandEvent&) @@ -220,5 +228,16 @@ void SearchCtrlWidgetsPage::OnToggleSearchMenu(wxCommandEvent&) m_srchCtrl->SetMenu(NULL); } +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