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