]>
git.saurik.com Git - wxWidgets.git/blob - samples/widgets/searchctrl.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Program: wxWidgets Widgets Sample
3 // Name: searchctrl.cpp
4 // Purpose: Shows wxSearchCtrl
9 // License: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // for compilers that support precompilation, includes "wx/wx.h".
21 #include "wx/wxprec.h"
29 // for all others, include the necessary headers
33 #include "wx/radiobox.h"
34 #include "wx/statbox.h"
37 #include "wx/artprov.h"
39 #include "wx/stattext.h"
40 #include "wx/checkbox.h"
43 #include "wx/srchctrl.h"
47 #include "icons/text.xpm"
49 // ----------------------------------------------------------------------------
51 // ----------------------------------------------------------------------------
56 ID_SEARCH_CB
= wxID_HIGHEST
,
64 // ----------------------------------------------------------------------------
65 // ColourPickerWidgetsPage
66 // ----------------------------------------------------------------------------
68 class SearchCtrlWidgetsPage
: public WidgetsPage
71 SearchCtrlWidgetsPage(WidgetsBookCtrl
*book
, wxImageList
*imaglist
);
72 virtual ~SearchCtrlWidgetsPage(){};
74 virtual wxControl
*GetWidget() const { return m_srchCtrl
; }
75 virtual void RecreateWidget() { CreateControl(); }
77 // lazy creation of the content
78 virtual void CreateContent();
82 void OnToggleSearchButton(wxCommandEvent
&);
83 void OnToggleCancelButton(wxCommandEvent
&);
84 void OnToggleSearchMenu(wxCommandEvent
&);
86 wxMenu
* CreateTestMenu();
88 // (re)create the control
91 // reset the control parameters
95 wxSearchCtrl
* m_srchCtrl
;
96 wxCheckBox
* m_searchBtnCheck
;
97 wxCheckBox
* m_cancelBtnCheck
;
98 wxCheckBox
* m_menuBtnCheck
;
101 DECLARE_EVENT_TABLE()
102 DECLARE_WIDGETS_PAGE(SearchCtrlWidgetsPage
)
105 // ----------------------------------------------------------------------------
107 // ----------------------------------------------------------------------------
109 BEGIN_EVENT_TABLE(SearchCtrlWidgetsPage
, WidgetsPage
)
110 EVT_CHECKBOX(ID_SEARCH_CB
, SearchCtrlWidgetsPage::OnToggleSearchButton
)
111 EVT_CHECKBOX(ID_CANCEL_CB
, SearchCtrlWidgetsPage::OnToggleCancelButton
)
112 EVT_CHECKBOX(ID_MENU_CB
, SearchCtrlWidgetsPage::OnToggleSearchMenu
)
115 // ============================================================================
117 // ============================================================================
119 #if defined(__WXMAC__)
120 #define FAMILY_CTRLS NATIVE_CTRLS
122 #define FAMILY_CTRLS GENERIC_CTRLS
125 IMPLEMENT_WIDGETS_PAGE(SearchCtrlWidgetsPage
, _T("SearchCtrl"),
126 FAMILY_CTRLS
| EDITABLE_CTRLS
| ALL_CTRLS
);
128 SearchCtrlWidgetsPage::SearchCtrlWidgetsPage(WidgetsBookCtrl
*book
,
129 wxImageList
*imaglist
)
130 : WidgetsPage(book
, imaglist
, text_xpm
)
134 void SearchCtrlWidgetsPage::CreateContent()
142 wxSizer
* box
= new wxStaticBoxSizer(
143 new wxStaticBox(this, -1, wxT("Options")),
146 m_searchBtnCheck
= new wxCheckBox(this, ID_SEARCH_CB
, wxT("Search button"));
147 m_cancelBtnCheck
= new wxCheckBox(this, ID_CANCEL_CB
, wxT("Cancel button"));
148 m_menuBtnCheck
= new wxCheckBox(this, ID_MENU_CB
, wxT("Search menu"));
150 m_searchBtnCheck
->SetValue(true);
152 box
->Add(m_searchBtnCheck
, 0, wxALL
, 5);
153 box
->Add(m_cancelBtnCheck
, 0, wxALL
, 5);
154 box
->Add(m_menuBtnCheck
, 0, wxALL
, 5);
156 wxSizer
* sizer
= new wxBoxSizer(wxHORIZONTAL
);
157 sizer
->Add(box
, 0, wxALL
|wxEXPAND
, 15);
158 sizer
->Add(m_srchCtrl
, 0, wxALL
|wxALIGN_CENTER
, 15);
163 void SearchCtrlWidgetsPage::CreateControl()
166 m_srchCtrl
->Destroy();
170 m_srchCtrl
= new wxSearchCtrl(this, -1, wxEmptyString
, wxDefaultPosition
,
171 wxSize(150, -1), style
);
174 void SearchCtrlWidgetsPage::Reset()
179 wxMenu
* SearchCtrlWidgetsPage::CreateTestMenu()
181 wxMenu
* menu
= new wxMenu
;
182 const int SEARCH_MENU_SIZE
= 5;
183 wxMenuItem
* menuItem
= menu
->Append(wxID_ANY
, _T("Recent Searches"), wxT(""), wxITEM_NORMAL
);
184 menuItem
->Enable(false);
185 for ( int i
= 0; i
< SEARCH_MENU_SIZE
; i
++ )
187 wxString itemText
= wxString::Format(wxT("item %i"),i
);
188 wxString tipText
= wxString::Format(wxT("tip %i"),i
);
189 menu
->Append(ID_SEARCHMENU
+i
, itemText
, tipText
, wxITEM_NORMAL
);
193 // ID_SEARCHMENU+SEARCH_MENU_SIZE,
194 // wxEVT_COMMAND_MENU_SELECTED,
195 // wxCommandEventHandler(MySearchCtrl::OnSearchMenu)
201 // ----------------------------------------------------------------------------
203 // ----------------------------------------------------------------------------
205 void SearchCtrlWidgetsPage::OnToggleSearchButton(wxCommandEvent
&)
207 m_srchCtrl
->ShowSearchButton( m_searchBtnCheck
->GetValue() );
210 void SearchCtrlWidgetsPage::OnToggleCancelButton(wxCommandEvent
&)
212 m_srchCtrl
->ShowCancelButton( m_cancelBtnCheck
->GetValue() );
216 void SearchCtrlWidgetsPage::OnToggleSearchMenu(wxCommandEvent
&)
218 if ( m_menuBtnCheck
->GetValue() )
219 m_srchCtrl
->SetMenu( CreateTestMenu() );
221 m_srchCtrl
->SetMenu(NULL
);
225 #endif // wxUSE_SEARCHCTRL