]>
git.saurik.com Git - wxWidgets.git/blob - samples/widgets/searchctrl.cpp
2bd3905bb6690ac254ad72b1ba53a1eb1005b4bc
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"
36 #include "wx/artprov.h"
38 #include "wx/stattext.h"
39 #include "wx/checkbox.h"
42 #include "wx/srchctrl.h"
46 #include "icons/text.xpm"
48 // ----------------------------------------------------------------------------
50 // ----------------------------------------------------------------------------
55 ID_SEARCH_CB
= wxID_HIGHEST
,
63 // ----------------------------------------------------------------------------
64 // ColourPickerWidgetsPage
65 // ----------------------------------------------------------------------------
67 class SearchCtrlWidgetsPage
: public WidgetsPage
70 SearchCtrlWidgetsPage(WidgetsBookCtrl
*book
, wxImageList
*imaglist
);
71 virtual ~SearchCtrlWidgetsPage(){};
73 virtual wxControl
*GetWidget() const { return m_srchCtrl
; }
74 virtual void RecreateWidget() { CreateControl(); }
76 // lazy creation of the content
77 virtual void CreateContent();
81 void OnToggleSearchButton(wxCommandEvent
&);
82 void OnToggleCancelButton(wxCommandEvent
&);
83 void OnToggleSearchMenu(wxCommandEvent
&);
85 wxMenu
* CreateTestMenu();
87 // (re)create the control
90 // reset the control parameters
94 wxSearchCtrl
* m_srchCtrl
;
95 wxCheckBox
* m_searchBtnCheck
;
96 wxCheckBox
* m_cancelBtnCheck
;
97 wxCheckBox
* m_menuBtnCheck
;
100 DECLARE_EVENT_TABLE()
101 DECLARE_WIDGETS_PAGE(SearchCtrlWidgetsPage
)
104 // ----------------------------------------------------------------------------
106 // ----------------------------------------------------------------------------
108 BEGIN_EVENT_TABLE(SearchCtrlWidgetsPage
, WidgetsPage
)
109 EVT_CHECKBOX(ID_SEARCH_CB
, SearchCtrlWidgetsPage::OnToggleSearchButton
)
110 EVT_CHECKBOX(ID_CANCEL_CB
, SearchCtrlWidgetsPage::OnToggleCancelButton
)
111 EVT_CHECKBOX(ID_MENU_CB
, SearchCtrlWidgetsPage::OnToggleSearchMenu
)
114 // ============================================================================
116 // ============================================================================
118 #if defined(__WXMAC__)
119 #define FAMILY_CTRLS NATIVE_CTRLS
121 #define FAMILY_CTRLS GENERIC_CTRLS
124 IMPLEMENT_WIDGETS_PAGE(SearchCtrlWidgetsPage
, _T("SearchCtrl"),
125 FAMILY_CTRLS
| ALL_CTRLS
);
127 SearchCtrlWidgetsPage::SearchCtrlWidgetsPage(WidgetsBookCtrl
*book
,
128 wxImageList
*imaglist
)
129 : WidgetsPage(book
, imaglist
, text_xpm
)
133 void SearchCtrlWidgetsPage::CreateContent()
141 wxSizer
* box
= new wxStaticBoxSizer(
142 new wxStaticBox(this, -1, wxT("Options")),
145 m_searchBtnCheck
= new wxCheckBox(this, ID_SEARCH_CB
, wxT("Search button"));
146 m_cancelBtnCheck
= new wxCheckBox(this, ID_CANCEL_CB
, wxT("Cancel button"));
147 m_menuBtnCheck
= new wxCheckBox(this, ID_MENU_CB
, wxT("Search menu"));
149 m_searchBtnCheck
->SetValue(true);
151 box
->Add(m_searchBtnCheck
, 0, wxALL
, 5);
152 box
->Add(m_cancelBtnCheck
, 0, wxALL
, 5);
153 box
->Add(m_menuBtnCheck
, 0, wxALL
, 5);
155 wxSizer
* sizer
= new wxBoxSizer(wxHORIZONTAL
);
156 sizer
->Add(box
, 0, wxALL
|wxEXPAND
, 15);
157 sizer
->Add(m_srchCtrl
, 0, wxALL
|wxALIGN_CENTER
, 15);
162 void SearchCtrlWidgetsPage::CreateControl()
165 m_srchCtrl
->Destroy();
169 m_srchCtrl
= new wxSearchCtrl(this, -1, wxEmptyString
, wxDefaultPosition
,
170 wxSize(150, -1), style
);
173 void SearchCtrlWidgetsPage::Reset()
178 wxMenu
* SearchCtrlWidgetsPage::CreateTestMenu()
180 wxMenu
* menu
= new wxMenu
;
181 const int SEARCH_MENU_SIZE
= 5;
182 wxMenuItem
* menuItem
= menu
->Append(wxID_ANY
, _T("Recent Searches"), wxT(""), wxITEM_NORMAL
);
183 menuItem
->Enable(false);
184 for ( int i
= 0; i
< SEARCH_MENU_SIZE
; i
++ )
186 wxString itemText
= wxString::Format(wxT("item %i"),i
);
187 wxString tipText
= wxString::Format(wxT("tip %i"),i
);
188 menu
->Append(ID_SEARCHMENU
+i
, itemText
, tipText
, wxITEM_NORMAL
);
192 // ID_SEARCHMENU+SEARCH_MENU_SIZE,
193 // wxEVT_COMMAND_MENU_SELECTED,
194 // wxCommandEventHandler(MySearchCtrl::OnSearchMenu)
200 // ----------------------------------------------------------------------------
202 // ----------------------------------------------------------------------------
204 void SearchCtrlWidgetsPage::OnToggleSearchButton(wxCommandEvent
&)
206 m_srchCtrl
->SetSearchButtonVisible( m_searchBtnCheck
->GetValue() );
209 void SearchCtrlWidgetsPage::OnToggleCancelButton(wxCommandEvent
&)
211 m_srchCtrl
->SetCancelButtonVisible( m_cancelBtnCheck
->GetValue() );
215 void SearchCtrlWidgetsPage::OnToggleSearchMenu(wxCommandEvent
&)
217 if ( m_menuBtnCheck
->GetValue() )
218 m_srchCtrl
->SetMenu( CreateTestMenu() );
220 m_srchCtrl
->SetMenu(NULL
);
224 #endif // wxUSE_SEARCHCTRL