]>
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 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) wxWidgets team | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef _WX_GENERIC_CHOICDGG_H_ | |
13 | #define _WX_GENERIC_CHOICDGG_H_ | |
14 | ||
15 | #include "wx/dynarray.h" | |
16 | #include "wx/dialog.h" | |
17 | ||
18 | class WXDLLIMPEXP_FWD_CORE wxListBoxBase; | |
19 | ||
20 | // ---------------------------------------------------------------------------- | |
21 | // some (ugly...) constants | |
22 | // ---------------------------------------------------------------------------- | |
23 | ||
24 | #define wxCHOICE_HEIGHT 150 | |
25 | #define wxCHOICE_WIDTH 200 | |
26 | ||
27 | #ifdef __WXWINCE__ | |
28 | #define wxCHOICEDLG_STYLE \ | |
29 | (wxDEFAULT_DIALOG_STYLE | wxOK | wxCANCEL | wxCENTRE) | |
30 | #else | |
31 | #define wxCHOICEDLG_STYLE \ | |
32 | (wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxOK | wxCANCEL | wxCENTRE) | |
33 | #endif | |
34 | ||
35 | // ---------------------------------------------------------------------------- | |
36 | // wxAnyChoiceDialog: a base class for dialogs containing a listbox | |
37 | // ---------------------------------------------------------------------------- | |
38 | ||
39 | class WXDLLIMPEXP_CORE wxAnyChoiceDialog : public wxDialog | |
40 | { | |
41 | public: | |
42 | wxAnyChoiceDialog() { } | |
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, | |
50 | long styleLbox = wxLB_ALWAYS_SB) | |
51 | { | |
52 | (void)Create(parent, message, caption, n, choices, | |
53 | styleDlg, pos, styleLbox); | |
54 | } | |
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 | } | |
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); | |
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); | |
81 | ||
82 | protected: | |
83 | wxListBoxBase *m_listbox; | |
84 | ||
85 | virtual wxListBoxBase *CreateList(int n, | |
86 | const wxString *choices, | |
87 | long styleLbox); | |
88 | ||
89 | wxDECLARE_NO_COPY_CLASS(wxAnyChoiceDialog); | |
90 | }; | |
91 | ||
92 | // ---------------------------------------------------------------------------- | |
93 | // wxSingleChoiceDialog: a dialog with single selection listbox | |
94 | // ---------------------------------------------------------------------------- | |
95 | ||
96 | class WXDLLIMPEXP_CORE wxSingleChoiceDialog : public wxAnyChoiceDialog | |
97 | { | |
98 | public: | |
99 | wxSingleChoiceDialog() | |
100 | { | |
101 | m_selection = -1; | |
102 | } | |
103 | ||
104 | wxSingleChoiceDialog(wxWindow *parent, | |
105 | const wxString& message, | |
106 | const wxString& caption, | |
107 | int n, | |
108 | const wxString *choices, | |
109 | void **clientData = NULL, | |
110 | long style = wxCHOICEDLG_STYLE, | |
111 | const wxPoint& pos = wxDefaultPosition) | |
112 | { | |
113 | Create(parent, message, caption, n, choices, clientData, style, pos); | |
114 | } | |
115 | ||
116 | wxSingleChoiceDialog(wxWindow *parent, | |
117 | const wxString& message, | |
118 | const wxString& caption, | |
119 | const wxArrayString& choices, | |
120 | void **clientData = NULL, | |
121 | long style = wxCHOICEDLG_STYLE, | |
122 | const wxPoint& pos = wxDefaultPosition) | |
123 | { | |
124 | Create(parent, message, caption, choices, clientData, style, pos); | |
125 | } | |
126 | ||
127 | bool Create(wxWindow *parent, | |
128 | const wxString& message, | |
129 | const wxString& caption, | |
130 | int n, | |
131 | const wxString *choices, | |
132 | void **clientData = NULL, | |
133 | long style = wxCHOICEDLG_STYLE, | |
134 | const wxPoint& pos = wxDefaultPosition); | |
135 | bool Create(wxWindow *parent, | |
136 | const wxString& message, | |
137 | const wxString& caption, | |
138 | const wxArrayString& choices, | |
139 | void **clientData = NULL, | |
140 | long style = wxCHOICEDLG_STYLE, | |
141 | const wxPoint& pos = wxDefaultPosition); | |
142 | ||
143 | void SetSelection(int sel); | |
144 | int GetSelection() const { return m_selection; } | |
145 | wxString GetStringSelection() const { return m_stringSelection; } | |
146 | void* GetSelectionData() const { return m_clientData; } | |
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 | } | |
180 | ||
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 | ( | |
211 | char* GetSelectionClientData() const, | |
212 | (char*)GetSelectionData() | |
213 | ) | |
214 | #endif // WXWIN_COMPATIBILITY_2_8 | |
215 | ||
216 | // implementation from now on | |
217 | void OnOK(wxCommandEvent& event); | |
218 | #ifndef __SMARTPHONE__ | |
219 | void OnListBoxDClick(wxCommandEvent& event); | |
220 | #endif | |
221 | #ifdef __WXWINCE__ | |
222 | void OnJoystickButtonDown(wxJoystickEvent& event); | |
223 | #endif | |
224 | ||
225 | protected: | |
226 | int m_selection; | |
227 | wxString m_stringSelection; | |
228 | ||
229 | void DoChoice(); | |
230 | ||
231 | private: | |
232 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxSingleChoiceDialog) | |
233 | DECLARE_EVENT_TABLE() | |
234 | }; | |
235 | ||
236 | // ---------------------------------------------------------------------------- | |
237 | // wxMultiChoiceDialog: a dialog with multi selection listbox | |
238 | // ---------------------------------------------------------------------------- | |
239 | ||
240 | class WXDLLIMPEXP_CORE wxMultiChoiceDialog : public wxAnyChoiceDialog | |
241 | { | |
242 | public: | |
243 | wxMultiChoiceDialog() { } | |
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, | |
251 | const wxPoint& pos = wxDefaultPosition) | |
252 | { | |
253 | (void)Create(parent, message, caption, n, choices, style, pos); | |
254 | } | |
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 | } | |
264 | ||
265 | bool Create(wxWindow *parent, | |
266 | const wxString& message, | |
267 | const wxString& caption, | |
268 | int n, | |
269 | const wxString *choices, | |
270 | long style = wxCHOICEDLG_STYLE, | |
271 | const wxPoint& pos = wxDefaultPosition); | |
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); | |
278 | ||
279 | void SetSelections(const wxArrayInt& selections); | |
280 | wxArrayInt GetSelections() const { return m_selections; } | |
281 | ||
282 | // implementation from now on | |
283 | virtual bool TransferDataFromWindow(); | |
284 | ||
285 | protected: | |
286 | #if wxUSE_CHECKLISTBOX | |
287 | virtual wxListBoxBase *CreateList(int n, | |
288 | const wxString *choices, | |
289 | long styleLbox); | |
290 | #endif // wxUSE_CHECKLISTBOX | |
291 | ||
292 | wxArrayInt m_selections; | |
293 | ||
294 | private: | |
295 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxMultiChoiceDialog) | |
296 | }; | |
297 | ||
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 | |
303 | WXDLLIMPEXP_CORE wxString wxGetSingleChoice(const wxString& message, | |
304 | const wxString& caption, | |
305 | const wxArrayString& choices, | |
306 | wxWindow *parent = NULL, | |
307 | int x = wxDefaultCoord, | |
308 | int y = wxDefaultCoord, | |
309 | bool centre = true, | |
310 | int width = wxCHOICE_WIDTH, | |
311 | int height = wxCHOICE_HEIGHT, | |
312 | int initialSelection = 0); | |
313 | ||
314 | WXDLLIMPEXP_CORE wxString wxGetSingleChoice(const wxString& message, | |
315 | const wxString& caption, | |
316 | int n, const wxString *choices, | |
317 | wxWindow *parent = NULL, | |
318 | int x = wxDefaultCoord, | |
319 | int y = wxDefaultCoord, | |
320 | bool centre = true, | |
321 | int width = wxCHOICE_WIDTH, | |
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); | |
336 | ||
337 | // Same as above but gets position in list of strings, instead of string, | |
338 | // or -1 if no selection | |
339 | WXDLLIMPEXP_CORE int wxGetSingleChoiceIndex(const wxString& message, | |
340 | const wxString& caption, | |
341 | const wxArrayString& choices, | |
342 | wxWindow *parent = NULL, | |
343 | int x = wxDefaultCoord, | |
344 | int y = wxDefaultCoord, | |
345 | bool centre = true, | |
346 | int width = wxCHOICE_WIDTH, | |
347 | int height = wxCHOICE_HEIGHT, | |
348 | int initialSelection = 0); | |
349 | ||
350 | WXDLLIMPEXP_CORE int wxGetSingleChoiceIndex(const wxString& message, | |
351 | const wxString& caption, | |
352 | int n, const wxString *choices, | |
353 | wxWindow *parent = NULL, | |
354 | int x = wxDefaultCoord, | |
355 | int y = wxDefaultCoord, | |
356 | bool centre = true, | |
357 | int width = wxCHOICE_WIDTH, | |
358 | int height = wxCHOICE_HEIGHT, | |
359 | int initialSelection = 0); | |
360 | ||
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 | |
374 | WXDLLIMPEXP_CORE void* wxGetSingleChoiceData(const wxString& message, | |
375 | const wxString& caption, | |
376 | const wxArrayString& choices, | |
377 | void **client_data, | |
378 | wxWindow *parent = NULL, | |
379 | int x = wxDefaultCoord, | |
380 | int y = wxDefaultCoord, | |
381 | bool centre = true, | |
382 | int width = wxCHOICE_WIDTH, | |
383 | int height = wxCHOICE_HEIGHT, | |
384 | int initialSelection = 0); | |
385 | ||
386 | WXDLLIMPEXP_CORE void* wxGetSingleChoiceData(const wxString& message, | |
387 | const wxString& caption, | |
388 | int n, const wxString *choices, | |
389 | void **client_data, | |
390 | wxWindow *parent = NULL, | |
391 | int x = wxDefaultCoord, | |
392 | int y = wxDefaultCoord, | |
393 | bool centre = true, | |
394 | int width = wxCHOICE_WIDTH, | |
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); | |
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 | |
415 | // selections or -1 if cancelled | |
416 | WXDLLIMPEXP_CORE int wxGetSelectedChoices(wxArrayInt& selections, | |
417 | const wxString& message, | |
418 | const wxString& caption, | |
419 | int n, const wxString *choices, | |
420 | wxWindow *parent = NULL, | |
421 | int x = wxDefaultCoord, | |
422 | int y = wxDefaultCoord, | |
423 | bool centre = true, | |
424 | int width = wxCHOICE_WIDTH, | |
425 | int height = wxCHOICE_HEIGHT); | |
426 | ||
427 | WXDLLIMPEXP_CORE int wxGetSelectedChoices(wxArrayInt& selections, | |
428 | const wxString& message, | |
429 | const wxString& caption, | |
430 | const wxArrayString& choices, | |
431 | wxWindow *parent = NULL, | |
432 | int x = wxDefaultCoord, | |
433 | int y = wxDefaultCoord, | |
434 | bool centre = true, | |
435 | int width = wxCHOICE_WIDTH, | |
436 | int height = wxCHOICE_HEIGHT); | |
437 | ||
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 | ||
465 | #endif // _WX_GENERIC_CHOICDGG_H_ |