]>
Commit | Line | Data |
---|---|---|
c801d85f | 1 | ///////////////////////////////////////////////////////////////////////////// |
d6c9c1b7 | 2 | // Name: wx/generic/choicdgg.h |
c801d85f KB |
3 | // Purpose: Generic choice dialogs |
4 | // Author: Julian Smart | |
d6c9c1b7 | 5 | // Modified by: 03.11.00: VZ to add wxArrayString and multiple sel functions |
c801d85f KB |
6 | // Created: 01/02/97 |
7 | // RCS-ID: $Id$ | |
77ffb593 | 8 | // Copyright: (c) wxWidgets team |
65571936 | 9 | // Licence: wxWindows licence |
c801d85f KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
84498436 VZ |
12 | #ifndef _WX_GENERIC_CHOICDGG_H_ |
13 | #define _WX_GENERIC_CHOICDGG_H_ | |
c801d85f | 14 | |
d6c9c1b7 | 15 | #include "wx/dynarray.h" |
c801d85f | 16 | #include "wx/dialog.h" |
8ee9d618 | 17 | |
b5dbe15d | 18 | class WXDLLIMPEXP_FWD_CORE wxListBoxBase; |
c801d85f | 19 | |
d6c9c1b7 VZ |
20 | // ---------------------------------------------------------------------------- |
21 | // some (ugly...) constants | |
22 | // ---------------------------------------------------------------------------- | |
23 | ||
c801d85f KB |
24 | #define wxCHOICE_HEIGHT 150 |
25 | #define wxCHOICE_WIDTH 200 | |
26 | ||
259a6e38 JS |
27 | #ifdef __WXWINCE__ |
28 | #define wxCHOICEDLG_STYLE \ | |
29 | (wxDEFAULT_DIALOG_STYLE | wxOK | wxCANCEL | wxCENTRE) | |
30 | #else | |
abd9b10e VZ |
31 | #define wxCHOICEDLG_STYLE \ |
32 | (wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxOK | wxCANCEL | wxCENTRE) | |
259a6e38 | 33 | #endif |
c801d85f | 34 | |
d6c9c1b7 VZ |
35 | // ---------------------------------------------------------------------------- |
36 | // wxAnyChoiceDialog: a base class for dialogs containing a listbox | |
37 | // ---------------------------------------------------------------------------- | |
38 | ||
53a2db12 | 39 | class WXDLLIMPEXP_CORE wxAnyChoiceDialog : public wxDialog |
c801d85f | 40 | { |
d6c9c1b7 | 41 | public: |
6463b9f5 | 42 | wxAnyChoiceDialog() { } |
d6c9c1b7 VZ |
43 | |
44 | wxAnyChoiceDialog(wxWindow *parent, | |
45 | const wxString& message, | |
46 | const wxString& caption, | |
47 | int n, const wxString *choices, | |
48 | long styleDlg = wxCHOICEDLG_STYLE, | |
49 | const wxPoint& pos = wxDefaultPosition, | |
6463b9f5 JS |
50 | long styleLbox = wxLB_ALWAYS_SB) |
51 | { | |
52 | (void)Create(parent, message, caption, n, choices, | |
53 | styleDlg, pos, styleLbox); | |
54 | } | |
584ad2a3 MB |
55 | wxAnyChoiceDialog(wxWindow *parent, |
56 | const wxString& message, | |
57 | const wxString& caption, | |
58 | const wxArrayString& choices, | |
59 | long styleDlg = wxCHOICEDLG_STYLE, | |
60 | const wxPoint& pos = wxDefaultPosition, | |
61 | long styleLbox = wxLB_ALWAYS_SB) | |
62 | { | |
63 | (void)Create(parent, message, caption, choices, | |
64 | styleDlg, pos, styleLbox); | |
65 | } | |
d6c9c1b7 VZ |
66 | |
67 | bool Create(wxWindow *parent, | |
68 | const wxString& message, | |
69 | const wxString& caption, | |
70 | int n, const wxString *choices, | |
71 | long styleDlg = wxCHOICEDLG_STYLE, | |
72 | const wxPoint& pos = wxDefaultPosition, | |
73 | long styleLbox = wxLB_ALWAYS_SB); | |
584ad2a3 MB |
74 | bool Create(wxWindow *parent, |
75 | const wxString& message, | |
76 | const wxString& caption, | |
77 | const wxArrayString& choices, | |
78 | long styleDlg = wxCHOICEDLG_STYLE, | |
79 | const wxPoint& pos = wxDefaultPosition, | |
80 | long styleLbox = wxLB_ALWAYS_SB); | |
d6c9c1b7 VZ |
81 | |
82 | protected: | |
60104cba WS |
83 | wxListBoxBase *m_listbox; |
84 | ||
85 | virtual wxListBoxBase *CreateList(int n, | |
86 | const wxString *choices, | |
87 | long styleLbox); | |
22f3361e | 88 | |
c0c133e1 | 89 | wxDECLARE_NO_COPY_CLASS(wxAnyChoiceDialog); |
d6c9c1b7 | 90 | }; |
257bf510 | 91 | |
d6c9c1b7 VZ |
92 | // ---------------------------------------------------------------------------- |
93 | // wxSingleChoiceDialog: a dialog with single selection listbox | |
94 | // ---------------------------------------------------------------------------- | |
95 | ||
53a2db12 | 96 | class WXDLLIMPEXP_CORE wxSingleChoiceDialog : public wxAnyChoiceDialog |
d6c9c1b7 | 97 | { |
c801d85f | 98 | public: |
6463b9f5 JS |
99 | wxSingleChoiceDialog() |
100 | { | |
101 | m_selection = -1; | |
102 | } | |
d6c9c1b7 | 103 | |
257bf510 VZ |
104 | wxSingleChoiceDialog(wxWindow *parent, |
105 | const wxString& message, | |
106 | const wxString& caption, | |
107 | int n, | |
108 | const wxString *choices, | |
fc12b1f1 | 109 | void **clientData = NULL, |
257bf510 | 110 | long style = wxCHOICEDLG_STYLE, |
fc12b1f1 VZ |
111 | const wxPoint& pos = wxDefaultPosition) |
112 | { | |
113 | Create(parent, message, caption, n, choices, clientData, style, pos); | |
114 | } | |
115 | ||
584ad2a3 MB |
116 | wxSingleChoiceDialog(wxWindow *parent, |
117 | const wxString& message, | |
118 | const wxString& caption, | |
119 | const wxArrayString& choices, | |
fc12b1f1 | 120 | void **clientData = NULL, |
584ad2a3 | 121 | long style = wxCHOICEDLG_STYLE, |
fc12b1f1 VZ |
122 | const wxPoint& pos = wxDefaultPosition) |
123 | { | |
124 | Create(parent, message, caption, choices, clientData, style, pos); | |
125 | } | |
257bf510 | 126 | |
d6c9c1b7 VZ |
127 | bool Create(wxWindow *parent, |
128 | const wxString& message, | |
129 | const wxString& caption, | |
130 | int n, | |
131 | const wxString *choices, | |
fc12b1f1 | 132 | void **clientData = NULL, |
d6c9c1b7 VZ |
133 | long style = wxCHOICEDLG_STYLE, |
134 | const wxPoint& pos = wxDefaultPosition); | |
584ad2a3 MB |
135 | bool Create(wxWindow *parent, |
136 | const wxString& message, | |
137 | const wxString& caption, | |
138 | const wxArrayString& choices, | |
fc12b1f1 | 139 | void **clientData = NULL, |
584ad2a3 MB |
140 | long style = wxCHOICEDLG_STYLE, |
141 | const wxPoint& pos = wxDefaultPosition); | |
d6c9c1b7 VZ |
142 | |
143 | void SetSelection(int sel); | |
144 | int GetSelection() const { return m_selection; } | |
145 | wxString GetStringSelection() const { return m_stringSelection; } | |
805b7b21 | 146 | void* GetSelectionData() const { return m_clientData; } |
fc12b1f1 VZ |
147 | |
148 | #if WXWIN_COMPATIBILITY_2_8 | |
149 | // Deprecated overloads taking "char**" client data. | |
150 | wxDEPRECATED_CONSTRUCTOR | |
151 | ( | |
152 | wxSingleChoiceDialog(wxWindow *parent, | |
153 | const wxString& message, | |
154 | const wxString& caption, | |
155 | int n, | |
156 | const wxString *choices, | |
157 | char **clientData, | |
158 | long style = wxCHOICEDLG_STYLE, | |
159 | const wxPoint& pos = wxDefaultPosition) | |
160 | ) | |
161 | { | |
162 | Create(parent, message, caption, n, choices, | |
163 | (void**)clientData, style, pos); | |
164 | } | |
165 | ||
166 | wxDEPRECATED_CONSTRUCTOR | |
167 | ( | |
168 | wxSingleChoiceDialog(wxWindow *parent, | |
169 | const wxString& message, | |
170 | const wxString& caption, | |
171 | const wxArrayString& choices, | |
172 | char **clientData, | |
173 | long style = wxCHOICEDLG_STYLE, | |
174 | const wxPoint& pos = wxDefaultPosition) | |
175 | ) | |
176 | { | |
177 | Create(parent, message, caption, choices, | |
178 | (void**)clientData, style, pos); | |
179 | } | |
d6c9c1b7 | 180 | |
fc12b1f1 VZ |
181 | wxDEPRECATED_INLINE |
182 | ( | |
183 | bool Create(wxWindow *parent, | |
184 | const wxString& message, | |
185 | const wxString& caption, | |
186 | int n, | |
187 | const wxString *choices, | |
188 | char **clientData, | |
189 | long style = wxCHOICEDLG_STYLE, | |
190 | const wxPoint& pos = wxDefaultPosition), | |
191 | return Create(parent, message, caption, n, choices, | |
192 | (void**)clientData, style, pos); | |
193 | ) | |
194 | ||
195 | wxDEPRECATED_INLINE | |
196 | ( | |
197 | bool Create(wxWindow *parent, | |
198 | const wxString& message, | |
199 | const wxString& caption, | |
200 | const wxArrayString& choices, | |
201 | char **clientData, | |
202 | long style = wxCHOICEDLG_STYLE, | |
203 | const wxPoint& pos = wxDefaultPosition), | |
204 | return Create(parent, message, caption, choices, | |
205 | (void**)clientData, style, pos); | |
206 | ) | |
207 | ||
208 | // NB: no need to make it return wxChar, it's untyped | |
209 | wxDEPRECATED_ACCESSOR | |
210 | ( | |
805b7b21 VZ |
211 | char* GetSelectionClientData() const, |
212 | (char*)GetSelectionData() | |
fc12b1f1 VZ |
213 | ) |
214 | #endif // WXWIN_COMPATIBILITY_2_8 | |
d6c9c1b7 VZ |
215 | |
216 | // implementation from now on | |
217 | void OnOK(wxCommandEvent& event); | |
7b504551 | 218 | #ifndef __SMARTPHONE__ |
d6c9c1b7 | 219 | void OnListBoxDClick(wxCommandEvent& event); |
7b504551 WS |
220 | #endif |
221 | #ifdef __WXWINCE__ | |
222 | void OnJoystickButtonDown(wxJoystickEvent& event); | |
223 | #endif | |
d6c9c1b7 | 224 | |
d6c9c1b7 VZ |
225 | protected: |
226 | int m_selection; | |
227 | wxString m_stringSelection; | |
228 | ||
7b504551 WS |
229 | void DoChoice(); |
230 | ||
d6c9c1b7 | 231 | private: |
fc7a2a60 | 232 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxSingleChoiceDialog) |
d6c9c1b7 VZ |
233 | DECLARE_EVENT_TABLE() |
234 | }; | |
235 | ||
236 | // ---------------------------------------------------------------------------- | |
237 | // wxMultiChoiceDialog: a dialog with multi selection listbox | |
238 | // ---------------------------------------------------------------------------- | |
239 | ||
53a2db12 | 240 | class WXDLLIMPEXP_CORE wxMultiChoiceDialog : public wxAnyChoiceDialog |
d6c9c1b7 VZ |
241 | { |
242 | public: | |
6463b9f5 | 243 | wxMultiChoiceDialog() { } |
d6c9c1b7 VZ |
244 | |
245 | wxMultiChoiceDialog(wxWindow *parent, | |
246 | const wxString& message, | |
247 | const wxString& caption, | |
248 | int n, | |
249 | const wxString *choices, | |
250 | long style = wxCHOICEDLG_STYLE, | |
6463b9f5 JS |
251 | const wxPoint& pos = wxDefaultPosition) |
252 | { | |
253 | (void)Create(parent, message, caption, n, choices, style, pos); | |
254 | } | |
584ad2a3 MB |
255 | wxMultiChoiceDialog(wxWindow *parent, |
256 | const wxString& message, | |
257 | const wxString& caption, | |
258 | const wxArrayString& choices, | |
259 | long style = wxCHOICEDLG_STYLE, | |
260 | const wxPoint& pos = wxDefaultPosition) | |
261 | { | |
262 | (void)Create(parent, message, caption, choices, style, pos); | |
263 | } | |
257bf510 VZ |
264 | |
265 | bool Create(wxWindow *parent, | |
266 | const wxString& message, | |
267 | const wxString& caption, | |
d6c9c1b7 VZ |
268 | int n, |
269 | const wxString *choices, | |
257bf510 VZ |
270 | long style = wxCHOICEDLG_STYLE, |
271 | const wxPoint& pos = wxDefaultPosition); | |
584ad2a3 MB |
272 | bool Create(wxWindow *parent, |
273 | const wxString& message, | |
274 | const wxString& caption, | |
275 | const wxArrayString& choices, | |
276 | long style = wxCHOICEDLG_STYLE, | |
277 | const wxPoint& pos = wxDefaultPosition); | |
c801d85f | 278 | |
d6c9c1b7 VZ |
279 | void SetSelections(const wxArrayInt& selections); |
280 | wxArrayInt GetSelections() const { return m_selections; } | |
c801d85f | 281 | |
257bf510 | 282 | // implementation from now on |
3d49ce44 | 283 | virtual bool TransferDataFromWindow(); |
c801d85f | 284 | |
c801d85f | 285 | protected: |
60104cba WS |
286 | #if wxUSE_CHECKLISTBOX |
287 | virtual wxListBoxBase *CreateList(int n, | |
288 | const wxString *choices, | |
289 | long styleLbox); | |
290 | #endif // wxUSE_CHECKLISTBOX | |
291 | ||
d6c9c1b7 | 292 | wxArrayInt m_selections; |
257bf510 VZ |
293 | |
294 | private: | |
fc7a2a60 | 295 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxMultiChoiceDialog) |
c801d85f KB |
296 | }; |
297 | ||
d6c9c1b7 VZ |
298 | // ---------------------------------------------------------------------------- |
299 | // wrapper functions which can be used to get selection(s) from the user | |
300 | // ---------------------------------------------------------------------------- | |
301 | ||
302 | // get the user selection as a string | |
53a2db12 | 303 | WXDLLIMPEXP_CORE wxString wxGetSingleChoice(const wxString& message, |
d6c9c1b7 VZ |
304 | const wxString& caption, |
305 | const wxArrayString& choices, | |
84498436 | 306 | wxWindow *parent = NULL, |
422d0ff0 WS |
307 | int x = wxDefaultCoord, |
308 | int y = wxDefaultCoord, | |
ca65c044 | 309 | bool centre = true, |
d6c9c1b7 | 310 | int width = wxCHOICE_WIDTH, |
697f4a96 VZ |
311 | int height = wxCHOICE_HEIGHT, |
312 | int initialSelection = 0); | |
c801d85f | 313 | |
53a2db12 | 314 | WXDLLIMPEXP_CORE wxString wxGetSingleChoice(const wxString& message, |
d6c9c1b7 VZ |
315 | const wxString& caption, |
316 | int n, const wxString *choices, | |
84498436 | 317 | wxWindow *parent = NULL, |
422d0ff0 WS |
318 | int x = wxDefaultCoord, |
319 | int y = wxDefaultCoord, | |
ca65c044 | 320 | bool centre = true, |
d6c9c1b7 | 321 | int width = wxCHOICE_WIDTH, |
697f4a96 VZ |
322 | int height = wxCHOICE_HEIGHT, |
323 | int initialSelection = 0); | |
324 | ||
325 | WXDLLIMPEXP_CORE wxString wxGetSingleChoice(const wxString& message, | |
326 | const wxString& caption, | |
327 | const wxArrayString& choices, | |
328 | int initialSelection, | |
329 | wxWindow *parent = NULL); | |
330 | ||
331 | WXDLLIMPEXP_CORE wxString wxGetSingleChoice(const wxString& message, | |
332 | const wxString& caption, | |
333 | int n, const wxString *choices, | |
334 | int initialSelection, | |
335 | wxWindow *parent = NULL); | |
c801d85f KB |
336 | |
337 | // Same as above but gets position in list of strings, instead of string, | |
338 | // or -1 if no selection | |
53a2db12 | 339 | WXDLLIMPEXP_CORE int wxGetSingleChoiceIndex(const wxString& message, |
d6c9c1b7 VZ |
340 | const wxString& caption, |
341 | const wxArrayString& choices, | |
84498436 | 342 | wxWindow *parent = NULL, |
422d0ff0 WS |
343 | int x = wxDefaultCoord, |
344 | int y = wxDefaultCoord, | |
ca65c044 | 345 | bool centre = true, |
d6c9c1b7 | 346 | int width = wxCHOICE_WIDTH, |
697f4a96 VZ |
347 | int height = wxCHOICE_HEIGHT, |
348 | int initialSelection = 0); | |
d6c9c1b7 | 349 | |
53a2db12 | 350 | WXDLLIMPEXP_CORE int wxGetSingleChoiceIndex(const wxString& message, |
d6c9c1b7 VZ |
351 | const wxString& caption, |
352 | int n, const wxString *choices, | |
84498436 | 353 | wxWindow *parent = NULL, |
422d0ff0 WS |
354 | int x = wxDefaultCoord, |
355 | int y = wxDefaultCoord, | |
ca65c044 | 356 | bool centre = true, |
d6c9c1b7 | 357 | int width = wxCHOICE_WIDTH, |
697f4a96 VZ |
358 | int height = wxCHOICE_HEIGHT, |
359 | int initialSelection = 0); | |
d6c9c1b7 | 360 | |
697f4a96 VZ |
361 | WXDLLIMPEXP_CORE int wxGetSingleChoiceIndex(const wxString& message, |
362 | const wxString& caption, | |
363 | const wxArrayString& choices, | |
364 | int initialSelection, | |
365 | wxWindow *parent = NULL); | |
366 | ||
367 | WXDLLIMPEXP_CORE int wxGetSingleChoiceIndex(const wxString& message, | |
368 | const wxString& caption, | |
369 | int n, const wxString *choices, | |
370 | int initialSelection, | |
371 | wxWindow *parent = NULL); | |
372 | ||
373 | // Return client data instead or NULL if canceled | |
53a2db12 | 374 | WXDLLIMPEXP_CORE void* wxGetSingleChoiceData(const wxString& message, |
d6c9c1b7 VZ |
375 | const wxString& caption, |
376 | const wxArrayString& choices, | |
377 | void **client_data, | |
84498436 | 378 | wxWindow *parent = NULL, |
422d0ff0 WS |
379 | int x = wxDefaultCoord, |
380 | int y = wxDefaultCoord, | |
ca65c044 | 381 | bool centre = true, |
d6c9c1b7 | 382 | int width = wxCHOICE_WIDTH, |
697f4a96 VZ |
383 | int height = wxCHOICE_HEIGHT, |
384 | int initialSelection = 0); | |
d6c9c1b7 | 385 | |
53a2db12 | 386 | WXDLLIMPEXP_CORE void* wxGetSingleChoiceData(const wxString& message, |
d6c9c1b7 VZ |
387 | const wxString& caption, |
388 | int n, const wxString *choices, | |
389 | void **client_data, | |
84498436 | 390 | wxWindow *parent = NULL, |
422d0ff0 WS |
391 | int x = wxDefaultCoord, |
392 | int y = wxDefaultCoord, | |
ca65c044 | 393 | bool centre = true, |
d6c9c1b7 | 394 | int width = wxCHOICE_WIDTH, |
697f4a96 VZ |
395 | int height = wxCHOICE_HEIGHT, |
396 | int initialSelection = 0); | |
397 | ||
398 | WXDLLIMPEXP_CORE void* wxGetSingleChoiceData(const wxString& message, | |
399 | const wxString& caption, | |
400 | const wxArrayString& choices, | |
401 | void **client_data, | |
402 | int initialSelection, | |
403 | wxWindow *parent = NULL); | |
404 | ||
405 | ||
406 | WXDLLIMPEXP_CORE void* wxGetSingleChoiceData(const wxString& message, | |
407 | const wxString& caption, | |
408 | int n, const wxString *choices, | |
409 | void **client_data, | |
410 | int initialSelection, | |
411 | wxWindow *parent = NULL); | |
d6c9c1b7 VZ |
412 | |
413 | // fill the array with the indices of the chosen items, it will be empty | |
414 | // if no items were selected or Cancel was pressed - return the number of | |
e5cfb314 VZ |
415 | // selections or -1 if cancelled |
416 | WXDLLIMPEXP_CORE int wxGetSelectedChoices(wxArrayInt& selections, | |
d6c9c1b7 VZ |
417 | const wxString& message, |
418 | const wxString& caption, | |
419 | int n, const wxString *choices, | |
84498436 | 420 | wxWindow *parent = NULL, |
422d0ff0 WS |
421 | int x = wxDefaultCoord, |
422 | int y = wxDefaultCoord, | |
ca65c044 | 423 | bool centre = true, |
d6c9c1b7 VZ |
424 | int width = wxCHOICE_WIDTH, |
425 | int height = wxCHOICE_HEIGHT); | |
426 | ||
e5cfb314 | 427 | WXDLLIMPEXP_CORE int wxGetSelectedChoices(wxArrayInt& selections, |
d6c9c1b7 VZ |
428 | const wxString& message, |
429 | const wxString& caption, | |
430 | const wxArrayString& choices, | |
84498436 | 431 | wxWindow *parent = NULL, |
422d0ff0 WS |
432 | int x = wxDefaultCoord, |
433 | int y = wxDefaultCoord, | |
ca65c044 | 434 | bool centre = true, |
d6c9c1b7 VZ |
435 | int width = wxCHOICE_WIDTH, |
436 | int height = wxCHOICE_HEIGHT); | |
437 | ||
e5cfb314 VZ |
438 | #if WXWIN_COMPATIBILITY_2_8 |
439 | // fill the array with the indices of the chosen items, it will be empty | |
440 | // if no items were selected or Cancel was pressed - return the number of | |
441 | // selections | |
442 | wxDEPRECATED( WXDLLIMPEXP_CORE size_t wxGetMultipleChoices(wxArrayInt& selections, | |
443 | const wxString& message, | |
444 | const wxString& caption, | |
445 | int n, const wxString *choices, | |
446 | wxWindow *parent = NULL, | |
447 | int x = wxDefaultCoord, | |
448 | int y = wxDefaultCoord, | |
449 | bool centre = true, | |
450 | int width = wxCHOICE_WIDTH, | |
451 | int height = wxCHOICE_HEIGHT) ); | |
452 | ||
453 | wxDEPRECATED( WXDLLIMPEXP_CORE size_t wxGetMultipleChoices(wxArrayInt& selections, | |
454 | const wxString& message, | |
455 | const wxString& caption, | |
456 | const wxArrayString& choices, | |
457 | wxWindow *parent = NULL, | |
458 | int x = wxDefaultCoord, | |
459 | int y = wxDefaultCoord, | |
460 | bool centre = true, | |
461 | int width = wxCHOICE_WIDTH, | |
462 | int height = wxCHOICE_HEIGHT)); | |
463 | #endif // WXWIN_COMPATIBILITY_2_8 | |
464 | ||
84498436 | 465 | #endif // _WX_GENERIC_CHOICDGG_H_ |