]>
Commit | Line | Data |
---|---|---|
32b8ec41 | 1 | ///////////////////////////////////////////////////////////////////////////// |
be5a51fb | 2 | // Program: wxWidgets Widgets Sample |
32b8ec41 VZ |
3 | // Name: combobox.cpp |
4 | // Purpose: Part of the widgets sample showing wxComboBox | |
5 | // Author: Vadim Zeitlin | |
6 | // Created: 27.03.01 | |
7 | // Id: $Id$ | |
8 | // Copyright: (c) 2001 Vadim Zeitlin | |
9 | // License: wxWindows license | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
20 | // for compilers that support precompilation, includes "wx/wx.h". | |
21 | #include "wx/wxprec.h" | |
22 | ||
23 | #ifdef __BORLANDC__ | |
24 | #pragma hdrstop | |
25 | #endif | |
26 | ||
3379ed37 VZ |
27 | #if wxUSE_COMBOBOX |
28 | ||
32b8ec41 VZ |
29 | // for all others, include the necessary headers |
30 | #ifndef WX_PRECOMP | |
31 | #include "wx/log.h" | |
32 | ||
3bb70c40 | 33 | #include "wx/bitmap.h" |
32b8ec41 VZ |
34 | #include "wx/button.h" |
35 | #include "wx/checkbox.h" | |
36 | #include "wx/combobox.h" | |
37 | #include "wx/radiobox.h" | |
38 | #include "wx/statbox.h" | |
39 | #include "wx/textctrl.h" | |
40 | #endif | |
41 | ||
42 | #include "wx/sizer.h" | |
43 | ||
44 | #include "widgets.h" | |
7b127900 | 45 | #if 1 |
32b8ec41 VZ |
46 | #include "icons/combobox.xpm" |
47 | ||
48 | // ---------------------------------------------------------------------------- | |
49 | // constants | |
50 | // ---------------------------------------------------------------------------- | |
51 | ||
52 | // control ids | |
53 | enum | |
54 | { | |
f0fa4312 | 55 | ComboPage_Reset = wxID_HIGHEST, |
32b8ec41 | 56 | ComboPage_CurText, |
9849a944 | 57 | ComboPage_InsertionPointText, |
243dbf1a VZ |
58 | ComboPage_Insert, |
59 | ComboPage_InsertText, | |
32b8ec41 VZ |
60 | ComboPage_Add, |
61 | ComboPage_AddText, | |
62 | ComboPage_AddSeveral, | |
63 | ComboPage_AddMany, | |
64 | ComboPage_Clear, | |
65 | ComboPage_Change, | |
66 | ComboPage_ChangeText, | |
67 | ComboPage_Delete, | |
68 | ComboPage_DeleteText, | |
69 | ComboPage_DeleteSel, | |
70 | ComboPage_Combo | |
71 | }; | |
72 | ||
73 | // kinds of comboboxes | |
74 | enum | |
75 | { | |
76 | ComboKind_Default, | |
77 | ComboKind_Simple, | |
78 | ComboKind_DropDown | |
79 | }; | |
80 | ||
81 | // ---------------------------------------------------------------------------- | |
82 | // ComboboxWidgetsPage | |
83 | // ---------------------------------------------------------------------------- | |
84 | ||
85 | class ComboboxWidgetsPage : public WidgetsPage | |
86 | { | |
87 | public: | |
f2fdc4d5 | 88 | ComboboxWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist); |
32b8ec41 | 89 | |
195df7a7 | 90 | virtual wxControl *GetWidget() const { return m_combobox; } |
1301e228 | 91 | virtual void RecreateWidget() { CreateCombo(); } |
195df7a7 | 92 | |
453535a7 WS |
93 | // lazy creation of the content |
94 | virtual void CreateContent(); | |
95 | ||
32b8ec41 VZ |
96 | protected: |
97 | // event handlers | |
98 | void OnButtonReset(wxCommandEvent& event); | |
99 | void OnButtonChange(wxCommandEvent& event); | |
100 | void OnButtonDelete(wxCommandEvent& event); | |
101 | void OnButtonDeleteSel(wxCommandEvent& event); | |
102 | void OnButtonClear(wxCommandEvent& event); | |
243dbf1a | 103 | void OnButtonInsert(wxCommandEvent &event); |
32b8ec41 VZ |
104 | void OnButtonAdd(wxCommandEvent& event); |
105 | void OnButtonAddSeveral(wxCommandEvent& event); | |
106 | void OnButtonAddMany(wxCommandEvent& event); | |
107 | ||
108 | void OnComboBox(wxCommandEvent& event); | |
109 | void OnComboText(wxCommandEvent& event); | |
110 | ||
111 | void OnCheckOrRadioBox(wxCommandEvent& event); | |
112 | ||
113 | void OnUpdateUICurText(wxUpdateUIEvent& event); | |
9849a944 | 114 | void OnUpdateUIInsertionPointText(wxUpdateUIEvent& event); |
32b8ec41 | 115 | |
243dbf1a | 116 | void OnUpdateUIInsert(wxUpdateUIEvent& event); |
32b8ec41 VZ |
117 | void OnUpdateUIAddSeveral(wxUpdateUIEvent& event); |
118 | void OnUpdateUIClearButton(wxUpdateUIEvent& event); | |
119 | void OnUpdateUIDeleteButton(wxUpdateUIEvent& event); | |
120 | void OnUpdateUIDeleteSelButton(wxUpdateUIEvent& event); | |
121 | void OnUpdateUIResetButton(wxUpdateUIEvent& event); | |
122 | ||
123 | // reset the combobox parameters | |
124 | void Reset(); | |
125 | ||
126 | // (re)create the combobox | |
127 | void CreateCombo(); | |
128 | ||
129 | // the controls | |
130 | // ------------ | |
131 | ||
132 | // the sel mode radiobox | |
133 | wxRadioBox *m_radioKind; | |
134 | ||
135 | // the checkboxes for styles | |
136 | wxCheckBox *m_chkSort, | |
5f6475c1 VZ |
137 | *m_chkReadonly, |
138 | *m_chkFilename; | |
32b8ec41 VZ |
139 | |
140 | // the combobox itself and the sizer it is in | |
141 | wxComboBox *m_combobox; | |
142 | wxSizer *m_sizerCombo; | |
143 | ||
144 | // the text entries for "Add/change string" and "Delete" buttons | |
243dbf1a VZ |
145 | wxTextCtrl *m_textInsert, |
146 | *m_textAdd, | |
32b8ec41 VZ |
147 | *m_textChange, |
148 | *m_textDelete; | |
149 | ||
150 | private: | |
5e173f35 GD |
151 | DECLARE_EVENT_TABLE() |
152 | DECLARE_WIDGETS_PAGE(ComboboxWidgetsPage) | |
32b8ec41 VZ |
153 | }; |
154 | ||
155 | // ---------------------------------------------------------------------------- | |
156 | // event tables | |
157 | // ---------------------------------------------------------------------------- | |
158 | ||
159 | BEGIN_EVENT_TABLE(ComboboxWidgetsPage, WidgetsPage) | |
160 | EVT_BUTTON(ComboPage_Reset, ComboboxWidgetsPage::OnButtonReset) | |
161 | EVT_BUTTON(ComboPage_Change, ComboboxWidgetsPage::OnButtonChange) | |
162 | EVT_BUTTON(ComboPage_Delete, ComboboxWidgetsPage::OnButtonDelete) | |
163 | EVT_BUTTON(ComboPage_DeleteSel, ComboboxWidgetsPage::OnButtonDeleteSel) | |
164 | EVT_BUTTON(ComboPage_Clear, ComboboxWidgetsPage::OnButtonClear) | |
243dbf1a | 165 | EVT_BUTTON(ComboPage_Insert, ComboboxWidgetsPage::OnButtonInsert) |
32b8ec41 VZ |
166 | EVT_BUTTON(ComboPage_Add, ComboboxWidgetsPage::OnButtonAdd) |
167 | EVT_BUTTON(ComboPage_AddSeveral, ComboboxWidgetsPage::OnButtonAddSeveral) | |
168 | EVT_BUTTON(ComboPage_AddMany, ComboboxWidgetsPage::OnButtonAddMany) | |
169 | ||
243dbf1a | 170 | EVT_TEXT_ENTER(ComboPage_InsertText, ComboboxWidgetsPage::OnButtonInsert) |
32b8ec41 VZ |
171 | EVT_TEXT_ENTER(ComboPage_AddText, ComboboxWidgetsPage::OnButtonAdd) |
172 | EVT_TEXT_ENTER(ComboPage_DeleteText, ComboboxWidgetsPage::OnButtonDelete) | |
173 | ||
174 | EVT_UPDATE_UI(ComboPage_CurText, ComboboxWidgetsPage::OnUpdateUICurText) | |
9849a944 | 175 | EVT_UPDATE_UI(ComboPage_InsertionPointText, ComboboxWidgetsPage::OnUpdateUIInsertionPointText) |
32b8ec41 VZ |
176 | |
177 | EVT_UPDATE_UI(ComboPage_Reset, ComboboxWidgetsPage::OnUpdateUIResetButton) | |
243dbf1a | 178 | EVT_UPDATE_UI(ComboPage_Insert, ComboboxWidgetsPage::OnUpdateUIInsert) |
32b8ec41 VZ |
179 | EVT_UPDATE_UI(ComboPage_AddSeveral, ComboboxWidgetsPage::OnUpdateUIAddSeveral) |
180 | EVT_UPDATE_UI(ComboPage_Clear, ComboboxWidgetsPage::OnUpdateUIClearButton) | |
181 | EVT_UPDATE_UI(ComboPage_DeleteText, ComboboxWidgetsPage::OnUpdateUIClearButton) | |
182 | EVT_UPDATE_UI(ComboPage_Delete, ComboboxWidgetsPage::OnUpdateUIDeleteButton) | |
183 | EVT_UPDATE_UI(ComboPage_Change, ComboboxWidgetsPage::OnUpdateUIDeleteSelButton) | |
184 | EVT_UPDATE_UI(ComboPage_ChangeText, ComboboxWidgetsPage::OnUpdateUIDeleteSelButton) | |
185 | EVT_UPDATE_UI(ComboPage_DeleteSel, ComboboxWidgetsPage::OnUpdateUIDeleteSelButton) | |
186 | ||
187 | EVT_COMBOBOX(ComboPage_Combo, ComboboxWidgetsPage::OnComboBox) | |
188 | EVT_TEXT(ComboPage_Combo, ComboboxWidgetsPage::OnComboText) | |
243dbf1a | 189 | EVT_TEXT_ENTER(ComboPage_Combo, ComboboxWidgetsPage::OnComboText) |
32b8ec41 | 190 | |
206d3a16 JS |
191 | EVT_CHECKBOX(wxID_ANY, ComboboxWidgetsPage::OnCheckOrRadioBox) |
192 | EVT_RADIOBOX(wxID_ANY, ComboboxWidgetsPage::OnCheckOrRadioBox) | |
32b8ec41 VZ |
193 | END_EVENT_TABLE() |
194 | ||
195 | // ============================================================================ | |
196 | // implementation | |
197 | // ============================================================================ | |
198 | ||
f0fa4312 WS |
199 | #if defined(__WXUNIVERSAL__) |
200 | #define FAMILY_CTRLS UNIVERSAL_CTRLS | |
201 | #else | |
202 | #define FAMILY_CTRLS NATIVE_CTRLS | |
203 | #endif | |
204 | ||
f2fdc4d5 | 205 | IMPLEMENT_WIDGETS_PAGE(ComboboxWidgetsPage, _T("Combobox"), |
f0fa4312 | 206 | FAMILY_CTRLS | WITH_ITEMS_CTRLS | COMBO_CTRLS |
f2fdc4d5 | 207 | ); |
32b8ec41 | 208 | |
f2fdc4d5 | 209 | ComboboxWidgetsPage::ComboboxWidgetsPage(WidgetsBookCtrl *book, |
61c083e7 | 210 | wxImageList *imaglist) |
261357eb | 211 | : WidgetsPage(book, imaglist, combobox_xpm) |
32b8ec41 | 212 | { |
32b8ec41 VZ |
213 | // init everything |
214 | m_chkSort = | |
5f6475c1 VZ |
215 | m_chkReadonly = |
216 | m_chkFilename = (wxCheckBox *)NULL; | |
32b8ec41 VZ |
217 | |
218 | m_combobox = (wxComboBox *)NULL; | |
219 | m_sizerCombo = (wxSizer *)NULL; | |
453535a7 | 220 | } |
32b8ec41 | 221 | |
453535a7 WS |
222 | void ComboboxWidgetsPage::CreateContent() |
223 | { | |
32b8ec41 VZ |
224 | /* |
225 | What we create here is a frame having 3 panes: style pane is the | |
226 | leftmost one, in the middle the pane with buttons allowing to perform | |
227 | miscellaneous combobox operations and the pane containing the combobox | |
228 | itself to the right | |
229 | */ | |
230 | wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL); | |
231 | ||
232 | // left pane | |
206d3a16 | 233 | wxStaticBox *box = new wxStaticBox(this, wxID_ANY, _T("&Set style")); |
32b8ec41 VZ |
234 | |
235 | // should be in sync with ComboKind_XXX values | |
236 | static const wxString kinds[] = | |
237 | { | |
238 | _T("default"), | |
239 | _T("simple"), | |
240 | _T("drop down"), | |
241 | }; | |
242 | ||
206d3a16 | 243 | m_radioKind = new wxRadioBox(this, wxID_ANY, _T("Combobox &kind:"), |
32b8ec41 VZ |
244 | wxDefaultPosition, wxDefaultSize, |
245 | WXSIZEOF(kinds), kinds, | |
246 | 1, wxRA_SPECIFY_COLS); | |
247 | ||
248 | wxSizer *sizerLeft = new wxStaticBoxSizer(box, wxVERTICAL); | |
249 | ||
250 | m_chkSort = CreateCheckBoxAndAddToSizer(sizerLeft, _T("&Sort items")); | |
251 | m_chkReadonly = CreateCheckBoxAndAddToSizer(sizerLeft, _T("&Read only")); | |
5f6475c1 | 252 | m_chkFilename = CreateCheckBoxAndAddToSizer(sizerLeft, _T("&File name")); |
32b8ec41 VZ |
253 | |
254 | sizerLeft->Add(5, 5, 0, wxGROW | wxALL, 5); // spacer | |
255 | sizerLeft->Add(m_radioKind, 0, wxGROW | wxALL, 5); | |
256 | ||
257 | wxButton *btn = new wxButton(this, ComboPage_Reset, _T("&Reset")); | |
258 | sizerLeft->Add(btn, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 15); | |
259 | ||
260 | // middle pane | |
206d3a16 JS |
261 | wxStaticBox *box2 = new wxStaticBox(this, wxID_ANY, |
262 | _T("&Change combobox contents")); | |
32b8ec41 VZ |
263 | wxSizer *sizerMiddle = new wxStaticBoxSizer(box2, wxVERTICAL); |
264 | ||
265 | wxSizer *sizerRow; | |
266 | ||
267 | wxTextCtrl *text; | |
268 | sizerRow = CreateSizerWithTextAndLabel(_T("Current selection"), | |
269 | ComboPage_CurText, | |
270 | &text); | |
206d3a16 | 271 | text->SetEditable(false); |
32b8ec41 VZ |
272 | |
273 | sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5); | |
274 | ||
9849a944 VZ |
275 | sizerRow = CreateSizerWithTextAndLabel(_T("Insertion Point"), |
276 | ComboPage_InsertionPointText, | |
277 | &text); | |
278 | text->SetEditable(false); | |
279 | ||
280 | sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5); | |
281 | ||
243dbf1a VZ |
282 | sizerRow = CreateSizerWithTextAndButton(ComboPage_Insert, |
283 | _T("&Insert this string"), | |
284 | ComboPage_InsertText, | |
285 | &m_textInsert); | |
286 | sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5); | |
287 | ||
32b8ec41 VZ |
288 | sizerRow = CreateSizerWithTextAndButton(ComboPage_Add, |
289 | _T("&Add this string"), | |
290 | ComboPage_AddText, | |
291 | &m_textAdd); | |
292 | sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5); | |
293 | ||
243dbf1a | 294 | btn = new wxButton(this, ComboPage_AddSeveral, _T("&Append a few strings")); |
32b8ec41 VZ |
295 | sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5); |
296 | ||
243dbf1a | 297 | btn = new wxButton(this, ComboPage_AddMany, _T("Append &many strings")); |
32b8ec41 VZ |
298 | sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5); |
299 | ||
300 | sizerRow = CreateSizerWithTextAndButton(ComboPage_Change, | |
301 | _T("C&hange current"), | |
302 | ComboPage_ChangeText, | |
303 | &m_textChange); | |
304 | sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5); | |
305 | ||
306 | sizerRow = CreateSizerWithTextAndButton(ComboPage_Delete, | |
307 | _T("&Delete this item"), | |
308 | ComboPage_DeleteText, | |
309 | &m_textDelete); | |
310 | sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5); | |
311 | ||
312 | btn = new wxButton(this, ComboPage_DeleteSel, _T("Delete &selection")); | |
313 | sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5); | |
314 | ||
315 | btn = new wxButton(this, ComboPage_Clear, _T("&Clear")); | |
316 | sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5); | |
317 | ||
318 | // right pane | |
319 | wxSizer *sizerRight = new wxBoxSizer(wxVERTICAL); | |
206d3a16 | 320 | m_combobox = new wxComboBox(this, ComboPage_Combo, wxEmptyString, |
32b8ec41 VZ |
321 | wxDefaultPosition, wxDefaultSize, |
322 | 0, NULL, | |
323 | 0); | |
6f002df4 | 324 | sizerRight->Add(m_combobox, 0, wxGROW | wxALL, 5); |
7b127900 | 325 | sizerRight->SetMinSize(150, 0); |
32b8ec41 VZ |
326 | m_sizerCombo = sizerRight; // save it to modify it later |
327 | ||
328 | // the 3 panes panes compose the window | |
329 | sizerTop->Add(sizerLeft, 0, wxGROW | (wxALL & ~wxLEFT), 10); | |
330 | sizerTop->Add(sizerMiddle, 1, wxGROW | wxALL, 10); | |
331 | sizerTop->Add(sizerRight, 1, wxGROW | (wxALL & ~wxRIGHT), 10); | |
332 | ||
333 | // final initializations | |
334 | Reset(); | |
335 | ||
32b8ec41 VZ |
336 | SetSizer(sizerTop); |
337 | ||
338 | sizerTop->Fit(this); | |
339 | } | |
340 | ||
341 | // ---------------------------------------------------------------------------- | |
342 | // operations | |
343 | // ---------------------------------------------------------------------------- | |
344 | ||
345 | void ComboboxWidgetsPage::Reset() | |
346 | { | |
206d3a16 JS |
347 | m_chkSort->SetValue(false); |
348 | m_chkReadonly->SetValue(false); | |
5f6475c1 | 349 | m_chkFilename->SetValue(false); |
32b8ec41 VZ |
350 | } |
351 | ||
352 | void ComboboxWidgetsPage::CreateCombo() | |
353 | { | |
1301e228 | 354 | int flags = ms_defaultFlags; |
32b8ec41 VZ |
355 | |
356 | if ( m_chkSort->GetValue() ) | |
357 | flags |= wxCB_SORT; | |
358 | if ( m_chkReadonly->GetValue() ) | |
359 | flags |= wxCB_READONLY; | |
5f6475c1 VZ |
360 | if ( m_chkFilename->GetValue() ) |
361 | flags |= wxCB_FILENAME; | |
32b8ec41 VZ |
362 | |
363 | switch ( m_radioKind->GetSelection() ) | |
364 | { | |
365 | default: | |
366 | wxFAIL_MSG( _T("unknown combo kind") ); | |
367 | // fall through | |
368 | ||
369 | case ComboKind_Default: | |
370 | break; | |
371 | ||
372 | case ComboKind_Simple: | |
373 | flags |= wxCB_SIMPLE; | |
374 | break; | |
375 | ||
376 | case ComboKind_DropDown: | |
377 | flags = wxCB_DROPDOWN; | |
378 | break; | |
379 | } | |
380 | ||
381 | wxArrayString items; | |
382 | if ( m_combobox ) | |
383 | { | |
aa61d352 VZ |
384 | unsigned int count = m_combobox->GetCount(); |
385 | for ( unsigned int n = 0; n < count; n++ ) | |
32b8ec41 VZ |
386 | { |
387 | items.Add(m_combobox->GetString(n)); | |
388 | } | |
389 | ||
12a3f227 | 390 | m_sizerCombo->Detach( m_combobox ); |
32b8ec41 VZ |
391 | delete m_combobox; |
392 | } | |
393 | ||
206d3a16 | 394 | m_combobox = new wxComboBox(this, ComboPage_Combo, wxEmptyString, |
32b8ec41 VZ |
395 | wxDefaultPosition, wxDefaultSize, |
396 | 0, NULL, | |
397 | flags); | |
398 | ||
aa61d352 VZ |
399 | unsigned int count = items.GetCount(); |
400 | for ( unsigned int n = 0; n < count; n++ ) | |
32b8ec41 VZ |
401 | { |
402 | m_combobox->Append(items[n]); | |
403 | } | |
404 | ||
405 | m_sizerCombo->Add(m_combobox, 1, wxGROW | wxALL, 5); | |
406 | m_sizerCombo->Layout(); | |
407 | } | |
408 | ||
409 | // ---------------------------------------------------------------------------- | |
410 | // event handlers | |
411 | // ---------------------------------------------------------------------------- | |
412 | ||
413 | void ComboboxWidgetsPage::OnButtonReset(wxCommandEvent& WXUNUSED(event)) | |
414 | { | |
415 | Reset(); | |
416 | ||
417 | CreateCombo(); | |
418 | } | |
419 | ||
420 | void ComboboxWidgetsPage::OnButtonChange(wxCommandEvent& WXUNUSED(event)) | |
421 | { | |
422 | int sel = m_combobox->GetSelection(); | |
453535a7 | 423 | if ( sel != wxNOT_FOUND ) |
32b8ec41 VZ |
424 | { |
425 | #ifndef __WXGTK__ | |
426 | m_combobox->SetString(sel, m_textChange->GetValue()); | |
427 | #else | |
428 | wxLogMessage(_T("Not implemented in wxGTK")); | |
429 | #endif | |
430 | } | |
431 | } | |
432 | ||
433 | void ComboboxWidgetsPage::OnButtonDelete(wxCommandEvent& WXUNUSED(event)) | |
434 | { | |
435 | unsigned long n; | |
436 | if ( !m_textDelete->GetValue().ToULong(&n) || | |
aa61d352 | 437 | (n >= m_combobox->GetCount()) ) |
32b8ec41 VZ |
438 | { |
439 | return; | |
440 | } | |
441 | ||
442 | m_combobox->Delete(n); | |
443 | } | |
444 | ||
445 | void ComboboxWidgetsPage::OnButtonDeleteSel(wxCommandEvent& WXUNUSED(event)) | |
446 | { | |
447 | int sel = m_combobox->GetSelection(); | |
aa61d352 | 448 | if ( sel != wxNOT_FOUND ) |
32b8ec41 VZ |
449 | { |
450 | m_combobox->Delete(sel); | |
451 | } | |
452 | } | |
453 | ||
c02e5a31 | 454 | void ComboboxWidgetsPage::OnButtonClear(wxCommandEvent& WXUNUSED(event)) |
32b8ec41 VZ |
455 | { |
456 | m_combobox->Clear(); | |
457 | } | |
458 | ||
c02e5a31 | 459 | void ComboboxWidgetsPage::OnButtonInsert(wxCommandEvent& WXUNUSED(event)) |
243dbf1a VZ |
460 | { |
461 | static unsigned int s_item = 0; | |
462 | ||
463 | wxString s = m_textInsert->GetValue(); | |
464 | if ( !m_textInsert->IsModified() ) | |
465 | { | |
466 | // update the default string | |
467 | m_textInsert->SetValue(wxString::Format(_T("test item %u"), ++s_item)); | |
468 | } | |
469 | ||
470 | if (m_combobox->GetSelection() >= 0) | |
471 | m_combobox->Insert(s, m_combobox->GetSelection()); | |
472 | } | |
473 | ||
c02e5a31 | 474 | void ComboboxWidgetsPage::OnButtonAdd(wxCommandEvent& WXUNUSED(event)) |
32b8ec41 | 475 | { |
0c61716c | 476 | static unsigned int s_item = 0; |
32b8ec41 VZ |
477 | |
478 | wxString s = m_textAdd->GetValue(); | |
479 | if ( !m_textAdd->IsModified() ) | |
480 | { | |
481 | // update the default string | |
482 | m_textAdd->SetValue(wxString::Format(_T("test item %u"), ++s_item)); | |
483 | } | |
484 | ||
485 | m_combobox->Append(s); | |
486 | } | |
487 | ||
488 | void ComboboxWidgetsPage::OnButtonAddMany(wxCommandEvent& WXUNUSED(event)) | |
489 | { | |
490 | // "many" means 1000 here | |
0c61716c | 491 | for ( unsigned int n = 0; n < 1000; n++ ) |
32b8ec41 VZ |
492 | { |
493 | m_combobox->Append(wxString::Format(_T("item #%u"), n)); | |
494 | } | |
495 | } | |
496 | ||
c02e5a31 | 497 | void ComboboxWidgetsPage::OnButtonAddSeveral(wxCommandEvent& WXUNUSED(event)) |
32b8ec41 VZ |
498 | { |
499 | m_combobox->Append(_T("First")); | |
500 | m_combobox->Append(_T("another one")); | |
501 | m_combobox->Append(_T("and the last (very very very very very very very very very very long) one")); | |
502 | } | |
503 | ||
504 | void ComboboxWidgetsPage::OnUpdateUICurText(wxUpdateUIEvent& event) | |
505 | { | |
e640f823 JS |
506 | if (m_combobox) |
507 | event.SetText( wxString::Format(_T("%d"), m_combobox->GetSelection()) ); | |
32b8ec41 VZ |
508 | } |
509 | ||
9849a944 VZ |
510 | void ComboboxWidgetsPage::OnUpdateUIInsertionPointText(wxUpdateUIEvent& event) |
511 | { | |
512 | if (m_combobox) | |
e95c145c | 513 | event.SetText( wxString::Format(_T("%ld"), m_combobox->GetInsertionPoint()) ); |
9849a944 VZ |
514 | } |
515 | ||
32b8ec41 VZ |
516 | void ComboboxWidgetsPage::OnUpdateUIResetButton(wxUpdateUIEvent& event) |
517 | { | |
5f6475c1 VZ |
518 | event.Enable( m_chkSort->GetValue() || |
519 | m_chkReadonly->GetValue() || | |
520 | m_chkFilename->GetValue() ); | |
32b8ec41 VZ |
521 | } |
522 | ||
243dbf1a VZ |
523 | void ComboboxWidgetsPage::OnUpdateUIInsert(wxUpdateUIEvent& event) |
524 | { | |
525 | if (m_combobox) | |
526 | { | |
527 | bool enable = !(m_combobox->GetWindowStyle() & wxCB_SORT) && | |
528 | (m_combobox->GetSelection() >= 0); | |
529 | ||
530 | event.Enable(enable); | |
531 | } | |
532 | } | |
533 | ||
32b8ec41 VZ |
534 | void ComboboxWidgetsPage::OnUpdateUIDeleteButton(wxUpdateUIEvent& event) |
535 | { | |
e640f823 JS |
536 | if (m_combobox) |
537 | { | |
538 | unsigned long n; | |
539 | event.Enable(m_textDelete->GetValue().ToULong(&n) && | |
2f6c54eb | 540 | (n < (unsigned)m_combobox->GetCount())); |
e640f823 | 541 | } |
32b8ec41 VZ |
542 | } |
543 | ||
544 | void ComboboxWidgetsPage::OnUpdateUIDeleteSelButton(wxUpdateUIEvent& event) | |
545 | { | |
e640f823 | 546 | if (m_combobox) |
453535a7 | 547 | event.Enable(m_combobox->GetSelection() != wxNOT_FOUND); |
32b8ec41 VZ |
548 | } |
549 | ||
550 | void ComboboxWidgetsPage::OnUpdateUIClearButton(wxUpdateUIEvent& event) | |
551 | { | |
e640f823 JS |
552 | if (m_combobox) |
553 | event.Enable(m_combobox->GetCount() != 0); | |
32b8ec41 VZ |
554 | } |
555 | ||
556 | void ComboboxWidgetsPage::OnUpdateUIAddSeveral(wxUpdateUIEvent& event) | |
557 | { | |
e640f823 JS |
558 | if (m_combobox) |
559 | event.Enable(!(m_combobox->GetWindowStyle() & wxCB_SORT)); | |
32b8ec41 VZ |
560 | } |
561 | ||
562 | void ComboboxWidgetsPage::OnComboText(wxCommandEvent& event) | |
563 | { | |
e640f823 | 564 | if (!m_combobox) |
2f6c54eb VZ |
565 | return; |
566 | ||
32b8ec41 VZ |
567 | wxString s = event.GetString(); |
568 | ||
569 | wxASSERT_MSG( s == m_combobox->GetValue(), | |
570 | _T("event and combobox values should be the same") ); | |
571 | ||
243dbf1a VZ |
572 | if (event.GetEventType() == wxEVT_COMMAND_TEXT_ENTER) |
573 | wxLogMessage(_T("Combobox enter pressed (now '%s')"), s.c_str()); | |
574 | else | |
bfd84575 | 575 | wxLogMessage(_T("Combobox text changed (now '%s')"), s.c_str()); |
32b8ec41 VZ |
576 | } |
577 | ||
578 | void ComboboxWidgetsPage::OnComboBox(wxCommandEvent& event) | |
579 | { | |
aec18ff7 | 580 | long sel = event.GetInt(); |
32b8ec41 VZ |
581 | m_textDelete->SetValue(wxString::Format(_T("%ld"), sel)); |
582 | ||
aec18ff7 | 583 | wxLogMessage(_T("Combobox item %ld selected"), sel); |
bfd84575 | 584 | |
78b3b018 | 585 | wxLogMessage(_T("Combobox GetValue(): %s"), m_combobox->GetValue().c_str() ); |
32b8ec41 VZ |
586 | } |
587 | ||
c02e5a31 | 588 | void ComboboxWidgetsPage::OnCheckOrRadioBox(wxCommandEvent& WXUNUSED(event)) |
32b8ec41 VZ |
589 | { |
590 | CreateCombo(); | |
591 | } | |
592 | ||
3379ed37 VZ |
593 | #endif //wxUSE_COMBOBOX |
594 | ||
7b127900 | 595 | #endif |