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 __CHOICEDLGH_G__
13 #define __CHOICEDLGH_G__
15 #include "wx/dynarray.h"
16 #include "wx/dialog.h"
17 #include "wx/listbox.h"
19 class WXDLLEXPORT wxListBox
;
21 // ----------------------------------------------------------------------------
22 // some (ugly...) constants
23 // ----------------------------------------------------------------------------
25 #define wxCHOICE_HEIGHT 150
26 #define wxCHOICE_WIDTH 200
29 #define wxCHOICEDLG_STYLE \
30 (wxDEFAULT_DIALOG_STYLE | wxOK | wxCANCEL | wxCENTRE)
32 #define wxCHOICEDLG_STYLE \
33 (wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxOK | wxCANCEL | wxCENTRE)
36 // ----------------------------------------------------------------------------
37 // wxAnyChoiceDialog: a base class for dialogs containing a listbox
38 // ----------------------------------------------------------------------------
40 class WXDLLEXPORT wxAnyChoiceDialog
: public wxDialog
43 wxAnyChoiceDialog() { }
45 wxAnyChoiceDialog(wxWindow
*parent
,
46 const wxString
& message
,
47 const wxString
& caption
,
48 int n
, const wxString
*choices
,
49 long styleDlg
= wxCHOICEDLG_STYLE
,
50 const wxPoint
& pos
= wxDefaultPosition
,
51 long styleLbox
= wxLB_ALWAYS_SB
)
53 (void)Create(parent
, message
, caption
, n
, choices
,
54 styleDlg
, pos
, styleLbox
);
56 wxAnyChoiceDialog(wxWindow
*parent
,
57 const wxString
& message
,
58 const wxString
& caption
,
59 const wxArrayString
& choices
,
60 long styleDlg
= wxCHOICEDLG_STYLE
,
61 const wxPoint
& pos
= wxDefaultPosition
,
62 long styleLbox
= wxLB_ALWAYS_SB
)
64 (void)Create(parent
, message
, caption
, choices
,
65 styleDlg
, pos
, styleLbox
);
68 bool Create(wxWindow
*parent
,
69 const wxString
& message
,
70 const wxString
& caption
,
71 int n
, const wxString
*choices
,
72 long styleDlg
= wxCHOICEDLG_STYLE
,
73 const wxPoint
& pos
= wxDefaultPosition
,
74 long styleLbox
= wxLB_ALWAYS_SB
);
75 bool Create(wxWindow
*parent
,
76 const wxString
& message
,
77 const wxString
& caption
,
78 const wxArrayString
& choices
,
79 long styleDlg
= wxCHOICEDLG_STYLE
,
80 const wxPoint
& pos
= wxDefaultPosition
,
81 long styleLbox
= wxLB_ALWAYS_SB
);
84 wxListBoxBase
*m_listbox
;
86 virtual wxListBoxBase
*CreateList(int n
,
87 const wxString
*choices
,
90 DECLARE_NO_COPY_CLASS(wxAnyChoiceDialog
)
93 // ----------------------------------------------------------------------------
94 // wxSingleChoiceDialog: a dialog with single selection listbox
95 // ----------------------------------------------------------------------------
97 class WXDLLEXPORT wxSingleChoiceDialog
: public wxAnyChoiceDialog
100 wxSingleChoiceDialog()
105 wxSingleChoiceDialog(wxWindow
*parent
,
106 const wxString
& message
,
107 const wxString
& caption
,
109 const wxString
*choices
,
110 char **clientData
= (char **)NULL
,
111 long style
= wxCHOICEDLG_STYLE
,
112 const wxPoint
& pos
= wxDefaultPosition
);
113 wxSingleChoiceDialog(wxWindow
*parent
,
114 const wxString
& message
,
115 const wxString
& caption
,
116 const wxArrayString
& choices
,
117 char **clientData
= (char **)NULL
,
118 long style
= wxCHOICEDLG_STYLE
,
119 const wxPoint
& pos
= wxDefaultPosition
);
121 bool Create(wxWindow
*parent
,
122 const wxString
& message
,
123 const wxString
& caption
,
125 const wxString
*choices
,
126 char **clientData
= (char **)NULL
,
127 long style
= wxCHOICEDLG_STYLE
,
128 const wxPoint
& pos
= wxDefaultPosition
);
129 bool Create(wxWindow
*parent
,
130 const wxString
& message
,
131 const wxString
& caption
,
132 const wxArrayString
& choices
,
133 char **clientData
= (char **)NULL
,
134 long style
= wxCHOICEDLG_STYLE
,
135 const wxPoint
& pos
= wxDefaultPosition
);
137 void SetSelection(int sel
);
138 int GetSelection() const { return m_selection
; }
139 wxString
GetStringSelection() const { return m_stringSelection
; }
141 // obsolete function (NB: no need to make it return wxChar, it's untyped)
142 char *GetSelectionClientData() const { return (char *)m_clientData
; }
144 // implementation from now on
145 void OnOK(wxCommandEvent
& event
);
146 #ifndef __SMARTPHONE__
147 void OnListBoxDClick(wxCommandEvent
& event
);
150 void OnJoystickButtonDown(wxJoystickEvent
& event
);
155 wxString m_stringSelection
;
160 DECLARE_DYNAMIC_CLASS_NO_COPY(wxSingleChoiceDialog
)
161 DECLARE_EVENT_TABLE()
164 // ----------------------------------------------------------------------------
165 // wxMultiChoiceDialog: a dialog with multi selection listbox
166 // ----------------------------------------------------------------------------
168 class WXDLLEXPORT wxMultiChoiceDialog
: public wxAnyChoiceDialog
171 wxMultiChoiceDialog() { }
173 wxMultiChoiceDialog(wxWindow
*parent
,
174 const wxString
& message
,
175 const wxString
& caption
,
177 const wxString
*choices
,
178 long style
= wxCHOICEDLG_STYLE
,
179 const wxPoint
& pos
= wxDefaultPosition
)
181 (void)Create(parent
, message
, caption
, n
, choices
, style
, pos
);
183 wxMultiChoiceDialog(wxWindow
*parent
,
184 const wxString
& message
,
185 const wxString
& caption
,
186 const wxArrayString
& choices
,
187 long style
= wxCHOICEDLG_STYLE
,
188 const wxPoint
& pos
= wxDefaultPosition
)
190 (void)Create(parent
, message
, caption
, choices
, style
, pos
);
193 bool Create(wxWindow
*parent
,
194 const wxString
& message
,
195 const wxString
& caption
,
197 const wxString
*choices
,
198 long style
= wxCHOICEDLG_STYLE
,
199 const wxPoint
& pos
= wxDefaultPosition
);
200 bool Create(wxWindow
*parent
,
201 const wxString
& message
,
202 const wxString
& caption
,
203 const wxArrayString
& choices
,
204 long style
= wxCHOICEDLG_STYLE
,
205 const wxPoint
& pos
= wxDefaultPosition
);
207 void SetSelections(const wxArrayInt
& selections
);
208 wxArrayInt
GetSelections() const { return m_selections
; }
210 // implementation from now on
211 virtual bool TransferDataFromWindow();
214 #if wxUSE_CHECKLISTBOX
215 virtual wxListBoxBase
*CreateList(int n
,
216 const wxString
*choices
,
218 #endif // wxUSE_CHECKLISTBOX
220 wxArrayInt m_selections
;
223 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMultiChoiceDialog
)
226 // ----------------------------------------------------------------------------
227 // wrapper functions which can be used to get selection(s) from the user
228 // ----------------------------------------------------------------------------
230 // get the user selection as a string
231 WXDLLEXPORT wxString
wxGetSingleChoice(const wxString
& message
,
232 const wxString
& caption
,
233 const wxArrayString
& choices
,
234 wxWindow
*parent
= (wxWindow
*) NULL
,
235 int x
= wxDefaultCoord
,
236 int y
= wxDefaultCoord
,
238 int width
= wxCHOICE_WIDTH
,
239 int height
= wxCHOICE_HEIGHT
);
241 WXDLLEXPORT wxString
wxGetSingleChoice(const wxString
& message
,
242 const wxString
& caption
,
243 int n
, const wxString
*choices
,
244 wxWindow
*parent
= (wxWindow
*) NULL
,
245 int x
= wxDefaultCoord
,
246 int y
= wxDefaultCoord
,
248 int width
= wxCHOICE_WIDTH
,
249 int height
= wxCHOICE_HEIGHT
);
251 // Same as above but gets position in list of strings, instead of string,
252 // or -1 if no selection
253 WXDLLEXPORT
int wxGetSingleChoiceIndex(const wxString
& message
,
254 const wxString
& caption
,
255 const wxArrayString
& choices
,
256 wxWindow
*parent
= (wxWindow
*) NULL
,
257 int x
= wxDefaultCoord
,
258 int y
= wxDefaultCoord
,
260 int width
= wxCHOICE_WIDTH
,
261 int height
= wxCHOICE_HEIGHT
);
263 WXDLLEXPORT
int wxGetSingleChoiceIndex(const wxString
& message
,
264 const wxString
& caption
,
265 int n
, const wxString
*choices
,
266 wxWindow
*parent
= (wxWindow
*) NULL
,
267 int x
= wxDefaultCoord
,
268 int y
= wxDefaultCoord
,
270 int width
= wxCHOICE_WIDTH
,
271 int height
= wxCHOICE_HEIGHT
);
273 // Return client data instead or NULL if cancelled
274 WXDLLEXPORT
void* wxGetSingleChoiceData(const wxString
& message
,
275 const wxString
& caption
,
276 const wxArrayString
& choices
,
278 wxWindow
*parent
= (wxWindow
*) NULL
,
279 int x
= wxDefaultCoord
,
280 int y
= wxDefaultCoord
,
282 int width
= wxCHOICE_WIDTH
,
283 int height
= wxCHOICE_HEIGHT
);
285 WXDLLEXPORT
void* wxGetSingleChoiceData(const wxString
& message
,
286 const wxString
& caption
,
287 int n
, const wxString
*choices
,
289 wxWindow
*parent
= (wxWindow
*) NULL
,
290 int x
= wxDefaultCoord
,
291 int y
= wxDefaultCoord
,
293 int width
= wxCHOICE_WIDTH
,
294 int height
= wxCHOICE_HEIGHT
);
296 // fill the array with the indices of the chosen items, it will be empty
297 // if no items were selected or Cancel was pressed - return the number of
299 WXDLLEXPORT
size_t wxGetMultipleChoices(wxArrayInt
& selections
,
300 const wxString
& message
,
301 const wxString
& caption
,
302 int n
, const wxString
*choices
,
303 wxWindow
*parent
= (wxWindow
*) NULL
,
304 int x
= wxDefaultCoord
,
305 int y
= wxDefaultCoord
,
307 int width
= wxCHOICE_WIDTH
,
308 int height
= wxCHOICE_HEIGHT
);
310 WXDLLEXPORT
size_t wxGetMultipleChoices(wxArrayInt
& selections
,
311 const wxString
& message
,
312 const wxString
& caption
,
313 const wxArrayString
& choices
,
314 wxWindow
*parent
= (wxWindow
*) NULL
,
315 int x
= wxDefaultCoord
,
316 int y
= wxDefaultCoord
,
318 int width
= wxCHOICE_WIDTH
,
319 int height
= wxCHOICE_HEIGHT
);
321 #endif // __CHOICEDLGH_G__