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
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_GENERIC_CHOICDGG_H_
13 #define _WX_GENERIC_CHOICDGG_H_
15 #include "wx/dynarray.h"
16 #include "wx/dialog.h"
18 class WXDLLIMPEXP_FWD_CORE wxListBoxBase
;
20 // ----------------------------------------------------------------------------
21 // some (ugly...) constants
22 // ----------------------------------------------------------------------------
24 #define wxCHOICE_HEIGHT 150
25 #define wxCHOICE_WIDTH 200
28 #define wxCHOICEDLG_STYLE \
29 (wxDEFAULT_DIALOG_STYLE | wxOK | wxCANCEL | wxCENTRE)
31 #define wxCHOICEDLG_STYLE \
32 (wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxOK | wxCANCEL | wxCENTRE)
35 // ----------------------------------------------------------------------------
36 // wxAnyChoiceDialog: a base class for dialogs containing a listbox
37 // ----------------------------------------------------------------------------
39 class WXDLLIMPEXP_CORE wxAnyChoiceDialog
: public wxDialog
42 wxAnyChoiceDialog() { }
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
)
52 (void)Create(parent
, message
, caption
, n
, choices
,
53 styleDlg
, pos
, styleLbox
);
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
)
63 (void)Create(parent
, message
, caption
, choices
,
64 styleDlg
, pos
, styleLbox
);
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
);
83 wxListBoxBase
*m_listbox
;
85 virtual wxListBoxBase
*CreateList(int n
,
86 const wxString
*choices
,
89 wxDECLARE_NO_COPY_CLASS(wxAnyChoiceDialog
);
92 // ----------------------------------------------------------------------------
93 // wxSingleChoiceDialog: a dialog with single selection listbox
94 // ----------------------------------------------------------------------------
96 class WXDLLIMPEXP_CORE wxSingleChoiceDialog
: public wxAnyChoiceDialog
99 wxSingleChoiceDialog()
104 wxSingleChoiceDialog(wxWindow
*parent
,
105 const wxString
& message
,
106 const wxString
& caption
,
108 const wxString
*choices
,
109 void **clientData
= NULL
,
110 long style
= wxCHOICEDLG_STYLE
,
111 const wxPoint
& pos
= wxDefaultPosition
)
113 Create(parent
, message
, caption
, n
, choices
, clientData
, style
, pos
);
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
)
124 Create(parent
, message
, caption
, choices
, clientData
, style
, pos
);
127 bool Create(wxWindow
*parent
,
128 const wxString
& message
,
129 const wxString
& caption
,
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
);
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
; }
148 #if WXWIN_COMPATIBILITY_2_8
149 // Deprecated overloads taking "char**" client data.
150 wxDEPRECATED_CONSTRUCTOR
152 wxSingleChoiceDialog(wxWindow
*parent
,
153 const wxString
& message
,
154 const wxString
& caption
,
156 const wxString
*choices
,
158 long style
= wxCHOICEDLG_STYLE
,
159 const wxPoint
& pos
= wxDefaultPosition
)
162 Create(parent
, message
, caption
, n
, choices
,
163 (void**)clientData
, style
, pos
);
166 wxDEPRECATED_CONSTRUCTOR
168 wxSingleChoiceDialog(wxWindow
*parent
,
169 const wxString
& message
,
170 const wxString
& caption
,
171 const wxArrayString
& choices
,
173 long style
= wxCHOICEDLG_STYLE
,
174 const wxPoint
& pos
= wxDefaultPosition
)
177 Create(parent
, message
, caption
, choices
,
178 (void**)clientData
, style
, pos
);
183 bool Create(wxWindow
*parent
,
184 const wxString
& message
,
185 const wxString
& caption
,
187 const wxString
*choices
,
189 long style
= wxCHOICEDLG_STYLE
,
190 const wxPoint
& pos
= wxDefaultPosition
),
191 return Create(parent
, message
, caption
, n
, choices
,
192 (void**)clientData
, style
, pos
);
197 bool Create(wxWindow
*parent
,
198 const wxString
& message
,
199 const wxString
& caption
,
200 const wxArrayString
& choices
,
202 long style
= wxCHOICEDLG_STYLE
,
203 const wxPoint
& pos
= wxDefaultPosition
),
204 return Create(parent
, message
, caption
, choices
,
205 (void**)clientData
, style
, pos
);
208 // NB: no need to make it return wxChar, it's untyped
209 wxDEPRECATED_ACCESSOR
211 char* GetSelectionClientData() const,
212 (char*)GetSelectionData()
214 #endif // WXWIN_COMPATIBILITY_2_8
216 // implementation from now on
217 void OnOK(wxCommandEvent
& event
);
218 #ifndef __SMARTPHONE__
219 void OnListBoxDClick(wxCommandEvent
& event
);
222 void OnJoystickButtonDown(wxJoystickEvent
& event
);
227 wxString m_stringSelection
;
232 DECLARE_DYNAMIC_CLASS_NO_COPY(wxSingleChoiceDialog
)
233 DECLARE_EVENT_TABLE()
236 // ----------------------------------------------------------------------------
237 // wxMultiChoiceDialog: a dialog with multi selection listbox
238 // ----------------------------------------------------------------------------
240 class WXDLLIMPEXP_CORE wxMultiChoiceDialog
: public wxAnyChoiceDialog
243 wxMultiChoiceDialog() { }
245 wxMultiChoiceDialog(wxWindow
*parent
,
246 const wxString
& message
,
247 const wxString
& caption
,
249 const wxString
*choices
,
250 long style
= wxCHOICEDLG_STYLE
,
251 const wxPoint
& pos
= wxDefaultPosition
)
253 (void)Create(parent
, message
, caption
, n
, choices
, style
, pos
);
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
)
262 (void)Create(parent
, message
, caption
, choices
, style
, pos
);
265 bool Create(wxWindow
*parent
,
266 const wxString
& message
,
267 const wxString
& caption
,
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
);
279 void SetSelections(const wxArrayInt
& selections
);
280 wxArrayInt
GetSelections() const { return m_selections
; }
282 // implementation from now on
283 virtual bool TransferDataFromWindow();
286 #if wxUSE_CHECKLISTBOX
287 virtual wxListBoxBase
*CreateList(int n
,
288 const wxString
*choices
,
290 #endif // wxUSE_CHECKLISTBOX
292 wxArrayInt m_selections
;
295 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMultiChoiceDialog
)
298 // ----------------------------------------------------------------------------
299 // wrapper functions which can be used to get selection(s) from the user
300 // ----------------------------------------------------------------------------
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
,
310 int width
= wxCHOICE_WIDTH
,
311 int height
= wxCHOICE_HEIGHT
,
312 int initialSelection
= 0);
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
,
321 int width
= wxCHOICE_WIDTH
,
322 int height
= wxCHOICE_HEIGHT
,
323 int initialSelection
= 0);
325 WXDLLIMPEXP_CORE wxString
wxGetSingleChoice(const wxString
& message
,
326 const wxString
& caption
,
327 const wxArrayString
& choices
,
328 int initialSelection
,
329 wxWindow
*parent
= NULL
);
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
);
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
,
346 int width
= wxCHOICE_WIDTH
,
347 int height
= wxCHOICE_HEIGHT
,
348 int initialSelection
= 0);
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
,
357 int width
= wxCHOICE_WIDTH
,
358 int height
= wxCHOICE_HEIGHT
,
359 int initialSelection
= 0);
361 WXDLLIMPEXP_CORE
int wxGetSingleChoiceIndex(const wxString
& message
,
362 const wxString
& caption
,
363 const wxArrayString
& choices
,
364 int initialSelection
,
365 wxWindow
*parent
= NULL
);
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
);
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
,
378 wxWindow
*parent
= NULL
,
379 int x
= wxDefaultCoord
,
380 int y
= wxDefaultCoord
,
382 int width
= wxCHOICE_WIDTH
,
383 int height
= wxCHOICE_HEIGHT
,
384 int initialSelection
= 0);
386 WXDLLIMPEXP_CORE
void* wxGetSingleChoiceData(const wxString
& message
,
387 const wxString
& caption
,
388 int n
, const wxString
*choices
,
390 wxWindow
*parent
= NULL
,
391 int x
= wxDefaultCoord
,
392 int y
= wxDefaultCoord
,
394 int width
= wxCHOICE_WIDTH
,
395 int height
= wxCHOICE_HEIGHT
,
396 int initialSelection
= 0);
398 WXDLLIMPEXP_CORE
void* wxGetSingleChoiceData(const wxString
& message
,
399 const wxString
& caption
,
400 const wxArrayString
& choices
,
402 int initialSelection
,
403 wxWindow
*parent
= NULL
);
406 WXDLLIMPEXP_CORE
void* wxGetSingleChoiceData(const wxString
& message
,
407 const wxString
& caption
,
408 int n
, const wxString
*choices
,
410 int initialSelection
,
411 wxWindow
*parent
= NULL
);
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
,
424 int width
= wxCHOICE_WIDTH
,
425 int height
= wxCHOICE_HEIGHT
);
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
,
435 int width
= wxCHOICE_WIDTH
,
436 int height
= wxCHOICE_HEIGHT
);
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
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
,
450 int width
= wxCHOICE_WIDTH
,
451 int height
= wxCHOICE_HEIGHT
) );
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
,
461 int width
= wxCHOICE_WIDTH
,
462 int height
= wxCHOICE_HEIGHT
));
463 #endif // WXWIN_COMPATIBILITY_2_8
465 #endif // _WX_GENERIC_CHOICDGG_H_