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