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
7 // Copyright: (c) wxWidgets team
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_GENERIC_CHOICDGG_H_
12 #define _WX_GENERIC_CHOICDGG_H_
14 #include "wx/dynarray.h"
15 #include "wx/dialog.h"
17 class WXDLLIMPEXP_FWD_CORE wxListBoxBase
;
19 // ----------------------------------------------------------------------------
20 // some (ugly...) constants
21 // ----------------------------------------------------------------------------
23 #define wxCHOICE_HEIGHT 150
24 #define wxCHOICE_WIDTH 200
27 #define wxCHOICEDLG_STYLE \
28 (wxDEFAULT_DIALOG_STYLE | wxOK | wxCANCEL | wxCENTRE)
30 #define wxCHOICEDLG_STYLE \
31 (wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxOK | wxCANCEL | wxCENTRE)
34 // ----------------------------------------------------------------------------
35 // wxAnyChoiceDialog: a base class for dialogs containing a listbox
36 // ----------------------------------------------------------------------------
38 class WXDLLIMPEXP_CORE wxAnyChoiceDialog
: public wxDialog
41 wxAnyChoiceDialog() { }
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
)
51 (void)Create(parent
, message
, caption
, n
, choices
,
52 styleDlg
, pos
, styleLbox
);
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
)
62 (void)Create(parent
, message
, caption
, choices
,
63 styleDlg
, pos
, styleLbox
);
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
);
82 wxListBoxBase
*m_listbox
;
84 virtual wxListBoxBase
*CreateList(int n
,
85 const wxString
*choices
,
88 wxDECLARE_NO_COPY_CLASS(wxAnyChoiceDialog
);
91 // ----------------------------------------------------------------------------
92 // wxSingleChoiceDialog: a dialog with single selection listbox
93 // ----------------------------------------------------------------------------
95 class WXDLLIMPEXP_CORE wxSingleChoiceDialog
: public wxAnyChoiceDialog
98 wxSingleChoiceDialog()
103 wxSingleChoiceDialog(wxWindow
*parent
,
104 const wxString
& message
,
105 const wxString
& caption
,
107 const wxString
*choices
,
108 void **clientData
= NULL
,
109 long style
= wxCHOICEDLG_STYLE
,
110 const wxPoint
& pos
= wxDefaultPosition
)
112 Create(parent
, message
, caption
, n
, choices
, clientData
, style
, pos
);
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
)
123 Create(parent
, message
, caption
, choices
, clientData
, style
, pos
);
126 bool Create(wxWindow
*parent
,
127 const wxString
& message
,
128 const wxString
& caption
,
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
);
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
; }
147 #if WXWIN_COMPATIBILITY_2_8
148 // Deprecated overloads taking "char**" client data.
149 wxDEPRECATED_CONSTRUCTOR
151 wxSingleChoiceDialog(wxWindow
*parent
,
152 const wxString
& message
,
153 const wxString
& caption
,
155 const wxString
*choices
,
157 long style
= wxCHOICEDLG_STYLE
,
158 const wxPoint
& pos
= wxDefaultPosition
)
161 Create(parent
, message
, caption
, n
, choices
,
162 (void**)clientData
, style
, pos
);
165 wxDEPRECATED_CONSTRUCTOR
167 wxSingleChoiceDialog(wxWindow
*parent
,
168 const wxString
& message
,
169 const wxString
& caption
,
170 const wxArrayString
& choices
,
172 long style
= wxCHOICEDLG_STYLE
,
173 const wxPoint
& pos
= wxDefaultPosition
)
176 Create(parent
, message
, caption
, choices
,
177 (void**)clientData
, style
, pos
);
182 bool Create(wxWindow
*parent
,
183 const wxString
& message
,
184 const wxString
& caption
,
186 const wxString
*choices
,
188 long style
= wxCHOICEDLG_STYLE
,
189 const wxPoint
& pos
= wxDefaultPosition
),
190 return Create(parent
, message
, caption
, n
, choices
,
191 (void**)clientData
, style
, pos
);
196 bool Create(wxWindow
*parent
,
197 const wxString
& message
,
198 const wxString
& caption
,
199 const wxArrayString
& choices
,
201 long style
= wxCHOICEDLG_STYLE
,
202 const wxPoint
& pos
= wxDefaultPosition
),
203 return Create(parent
, message
, caption
, choices
,
204 (void**)clientData
, style
, pos
);
207 // NB: no need to make it return wxChar, it's untyped
208 wxDEPRECATED_ACCESSOR
210 char* GetSelectionClientData() const,
211 (char*)GetSelectionData()
213 #endif // WXWIN_COMPATIBILITY_2_8
215 // implementation from now on
216 void OnOK(wxCommandEvent
& event
);
217 #ifndef __SMARTPHONE__
218 void OnListBoxDClick(wxCommandEvent
& event
);
221 void OnJoystickButtonDown(wxJoystickEvent
& event
);
226 wxString m_stringSelection
;
231 DECLARE_DYNAMIC_CLASS_NO_COPY(wxSingleChoiceDialog
)
232 DECLARE_EVENT_TABLE()
235 // ----------------------------------------------------------------------------
236 // wxMultiChoiceDialog: a dialog with multi selection listbox
237 // ----------------------------------------------------------------------------
239 class WXDLLIMPEXP_CORE wxMultiChoiceDialog
: public wxAnyChoiceDialog
242 wxMultiChoiceDialog() { }
244 wxMultiChoiceDialog(wxWindow
*parent
,
245 const wxString
& message
,
246 const wxString
& caption
,
248 const wxString
*choices
,
249 long style
= wxCHOICEDLG_STYLE
,
250 const wxPoint
& pos
= wxDefaultPosition
)
252 (void)Create(parent
, message
, caption
, n
, choices
, style
, pos
);
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
)
261 (void)Create(parent
, message
, caption
, choices
, style
, pos
);
264 bool Create(wxWindow
*parent
,
265 const wxString
& message
,
266 const wxString
& caption
,
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
);
278 void SetSelections(const wxArrayInt
& selections
);
279 wxArrayInt
GetSelections() const { return m_selections
; }
281 // implementation from now on
282 virtual bool TransferDataFromWindow();
285 #if wxUSE_CHECKLISTBOX
286 virtual wxListBoxBase
*CreateList(int n
,
287 const wxString
*choices
,
289 #endif // wxUSE_CHECKLISTBOX
291 wxArrayInt m_selections
;
294 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMultiChoiceDialog
)
297 // ----------------------------------------------------------------------------
298 // wrapper functions which can be used to get selection(s) from the user
299 // ----------------------------------------------------------------------------
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
,
309 int width
= wxCHOICE_WIDTH
,
310 int height
= wxCHOICE_HEIGHT
,
311 int initialSelection
= 0);
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
,
320 int width
= wxCHOICE_WIDTH
,
321 int height
= wxCHOICE_HEIGHT
,
322 int initialSelection
= 0);
324 WXDLLIMPEXP_CORE wxString
wxGetSingleChoice(const wxString
& message
,
325 const wxString
& caption
,
326 const wxArrayString
& choices
,
327 int initialSelection
,
328 wxWindow
*parent
= NULL
);
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
);
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
,
345 int width
= wxCHOICE_WIDTH
,
346 int height
= wxCHOICE_HEIGHT
,
347 int initialSelection
= 0);
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
,
356 int width
= wxCHOICE_WIDTH
,
357 int height
= wxCHOICE_HEIGHT
,
358 int initialSelection
= 0);
360 WXDLLIMPEXP_CORE
int wxGetSingleChoiceIndex(const wxString
& message
,
361 const wxString
& caption
,
362 const wxArrayString
& choices
,
363 int initialSelection
,
364 wxWindow
*parent
= NULL
);
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
);
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
,
377 wxWindow
*parent
= NULL
,
378 int x
= wxDefaultCoord
,
379 int y
= wxDefaultCoord
,
381 int width
= wxCHOICE_WIDTH
,
382 int height
= wxCHOICE_HEIGHT
,
383 int initialSelection
= 0);
385 WXDLLIMPEXP_CORE
void* wxGetSingleChoiceData(const wxString
& message
,
386 const wxString
& caption
,
387 int n
, const wxString
*choices
,
389 wxWindow
*parent
= NULL
,
390 int x
= wxDefaultCoord
,
391 int y
= wxDefaultCoord
,
393 int width
= wxCHOICE_WIDTH
,
394 int height
= wxCHOICE_HEIGHT
,
395 int initialSelection
= 0);
397 WXDLLIMPEXP_CORE
void* wxGetSingleChoiceData(const wxString
& message
,
398 const wxString
& caption
,
399 const wxArrayString
& choices
,
401 int initialSelection
,
402 wxWindow
*parent
= NULL
);
405 WXDLLIMPEXP_CORE
void* wxGetSingleChoiceData(const wxString
& message
,
406 const wxString
& caption
,
407 int n
, const wxString
*choices
,
409 int initialSelection
,
410 wxWindow
*parent
= NULL
);
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
,
423 int width
= wxCHOICE_WIDTH
,
424 int height
= wxCHOICE_HEIGHT
);
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
,
434 int width
= wxCHOICE_WIDTH
,
435 int height
= wxCHOICE_HEIGHT
);
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
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
,
449 int width
= wxCHOICE_WIDTH
,
450 int height
= wxCHOICE_HEIGHT
) );
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
,
460 int width
= wxCHOICE_WIDTH
,
461 int height
= wxCHOICE_HEIGHT
));
462 #endif // WXWIN_COMPATIBILITY_2_8
464 #endif // _WX_GENERIC_CHOICDGG_H_