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"
18 class WXDLLEXPORT 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 WXDLLEXPORT 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 DECLARE_NO_COPY_CLASS(wxAnyChoiceDialog
)
92 // ----------------------------------------------------------------------------
93 // wxSingleChoiceDialog: a dialog with single selection listbox
94 // ----------------------------------------------------------------------------
96 class WXDLLEXPORT wxSingleChoiceDialog
: public wxAnyChoiceDialog
99 wxSingleChoiceDialog()
104 wxSingleChoiceDialog(wxWindow
*parent
,
105 const wxString
& message
,
106 const wxString
& caption
,
108 const wxString
*choices
,
109 char **clientData
= (char **)NULL
,
110 long style
= wxCHOICEDLG_STYLE
,
111 const wxPoint
& pos
= wxDefaultPosition
);
112 wxSingleChoiceDialog(wxWindow
*parent
,
113 const wxString
& message
,
114 const wxString
& caption
,
115 const wxArrayString
& choices
,
116 char **clientData
= (char **)NULL
,
117 long style
= wxCHOICEDLG_STYLE
,
118 const wxPoint
& pos
= wxDefaultPosition
);
120 bool Create(wxWindow
*parent
,
121 const wxString
& message
,
122 const wxString
& caption
,
124 const wxString
*choices
,
125 char **clientData
= (char **)NULL
,
126 long style
= wxCHOICEDLG_STYLE
,
127 const wxPoint
& pos
= wxDefaultPosition
);
128 bool Create(wxWindow
*parent
,
129 const wxString
& message
,
130 const wxString
& caption
,
131 const wxArrayString
& choices
,
132 char **clientData
= (char **)NULL
,
133 long style
= wxCHOICEDLG_STYLE
,
134 const wxPoint
& pos
= wxDefaultPosition
);
136 void SetSelection(int sel
);
137 int GetSelection() const { return m_selection
; }
138 wxString
GetStringSelection() const { return m_stringSelection
; }
140 // obsolete function (NB: no need to make it return wxChar, it's untyped)
141 char *GetSelectionClientData() const { return (char *)m_clientData
; }
143 // implementation from now on
144 void OnOK(wxCommandEvent
& event
);
145 #ifndef __SMARTPHONE__
146 void OnListBoxDClick(wxCommandEvent
& event
);
149 void OnJoystickButtonDown(wxJoystickEvent
& event
);
154 wxString m_stringSelection
;
159 DECLARE_DYNAMIC_CLASS_NO_COPY(wxSingleChoiceDialog
)
160 DECLARE_EVENT_TABLE()
163 // ----------------------------------------------------------------------------
164 // wxMultiChoiceDialog: a dialog with multi selection listbox
165 // ----------------------------------------------------------------------------
167 class WXDLLEXPORT wxMultiChoiceDialog
: public wxAnyChoiceDialog
170 wxMultiChoiceDialog() { }
172 wxMultiChoiceDialog(wxWindow
*parent
,
173 const wxString
& message
,
174 const wxString
& caption
,
176 const wxString
*choices
,
177 long style
= wxCHOICEDLG_STYLE
,
178 const wxPoint
& pos
= wxDefaultPosition
)
180 (void)Create(parent
, message
, caption
, n
, choices
, style
, pos
);
182 wxMultiChoiceDialog(wxWindow
*parent
,
183 const wxString
& message
,
184 const wxString
& caption
,
185 const wxArrayString
& choices
,
186 long style
= wxCHOICEDLG_STYLE
,
187 const wxPoint
& pos
= wxDefaultPosition
)
189 (void)Create(parent
, message
, caption
, choices
, style
, pos
);
192 bool Create(wxWindow
*parent
,
193 const wxString
& message
,
194 const wxString
& caption
,
196 const wxString
*choices
,
197 long style
= wxCHOICEDLG_STYLE
,
198 const wxPoint
& pos
= wxDefaultPosition
);
199 bool Create(wxWindow
*parent
,
200 const wxString
& message
,
201 const wxString
& caption
,
202 const wxArrayString
& choices
,
203 long style
= wxCHOICEDLG_STYLE
,
204 const wxPoint
& pos
= wxDefaultPosition
);
206 void SetSelections(const wxArrayInt
& selections
);
207 wxArrayInt
GetSelections() const { return m_selections
; }
209 // implementation from now on
210 virtual bool TransferDataFromWindow();
213 #if wxUSE_CHECKLISTBOX
214 virtual wxListBoxBase
*CreateList(int n
,
215 const wxString
*choices
,
217 #endif // wxUSE_CHECKLISTBOX
219 wxArrayInt m_selections
;
222 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMultiChoiceDialog
)
225 // ----------------------------------------------------------------------------
226 // wrapper functions which can be used to get selection(s) from the user
227 // ----------------------------------------------------------------------------
229 // get the user selection as a string
230 WXDLLEXPORT wxString
wxGetSingleChoice(const wxString
& message
,
231 const wxString
& caption
,
232 const wxArrayString
& choices
,
233 wxWindow
*parent
= (wxWindow
*) NULL
,
234 int x
= wxDefaultCoord
,
235 int y
= wxDefaultCoord
,
237 int width
= wxCHOICE_WIDTH
,
238 int height
= wxCHOICE_HEIGHT
);
240 WXDLLEXPORT wxString
wxGetSingleChoice(const wxString
& message
,
241 const wxString
& caption
,
242 int n
, const wxString
*choices
,
243 wxWindow
*parent
= (wxWindow
*) NULL
,
244 int x
= wxDefaultCoord
,
245 int y
= wxDefaultCoord
,
247 int width
= wxCHOICE_WIDTH
,
248 int height
= wxCHOICE_HEIGHT
);
250 // Same as above but gets position in list of strings, instead of string,
251 // or -1 if no selection
252 WXDLLEXPORT
int wxGetSingleChoiceIndex(const wxString
& message
,
253 const wxString
& caption
,
254 const wxArrayString
& choices
,
255 wxWindow
*parent
= (wxWindow
*) NULL
,
256 int x
= wxDefaultCoord
,
257 int y
= wxDefaultCoord
,
259 int width
= wxCHOICE_WIDTH
,
260 int height
= wxCHOICE_HEIGHT
);
262 WXDLLEXPORT
int wxGetSingleChoiceIndex(const wxString
& message
,
263 const wxString
& caption
,
264 int n
, const wxString
*choices
,
265 wxWindow
*parent
= (wxWindow
*) NULL
,
266 int x
= wxDefaultCoord
,
267 int y
= wxDefaultCoord
,
269 int width
= wxCHOICE_WIDTH
,
270 int height
= wxCHOICE_HEIGHT
);
272 // Return client data instead or NULL if cancelled
273 WXDLLEXPORT
void* wxGetSingleChoiceData(const wxString
& message
,
274 const wxString
& caption
,
275 const wxArrayString
& choices
,
277 wxWindow
*parent
= (wxWindow
*) NULL
,
278 int x
= wxDefaultCoord
,
279 int y
= wxDefaultCoord
,
281 int width
= wxCHOICE_WIDTH
,
282 int height
= wxCHOICE_HEIGHT
);
284 WXDLLEXPORT
void* wxGetSingleChoiceData(const wxString
& message
,
285 const wxString
& caption
,
286 int n
, const wxString
*choices
,
288 wxWindow
*parent
= (wxWindow
*) NULL
,
289 int x
= wxDefaultCoord
,
290 int y
= wxDefaultCoord
,
292 int width
= wxCHOICE_WIDTH
,
293 int height
= wxCHOICE_HEIGHT
);
295 // fill the array with the indices of the chosen items, it will be empty
296 // if no items were selected or Cancel was pressed - return the number of
298 WXDLLEXPORT
size_t wxGetMultipleChoices(wxArrayInt
& selections
,
299 const wxString
& message
,
300 const wxString
& caption
,
301 int n
, const wxString
*choices
,
302 wxWindow
*parent
= (wxWindow
*) NULL
,
303 int x
= wxDefaultCoord
,
304 int y
= wxDefaultCoord
,
306 int width
= wxCHOICE_WIDTH
,
307 int height
= wxCHOICE_HEIGHT
);
309 WXDLLEXPORT
size_t wxGetMultipleChoices(wxArrayInt
& selections
,
310 const wxString
& message
,
311 const wxString
& caption
,
312 const wxArrayString
& choices
,
313 wxWindow
*parent
= (wxWindow
*) NULL
,
314 int x
= wxDefaultCoord
,
315 int y
= wxDefaultCoord
,
317 int width
= wxCHOICE_WIDTH
,
318 int height
= wxCHOICE_HEIGHT
);
320 #endif // __CHOICEDLGH_G__