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