added wxGetMultiChoice() (which refuses to work for some reason - will fix
[wxWidgets.git] / include / wx / generic / choicdgg.h
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) wxWindows team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef __CHOICEDLGH_G__
13 #define __CHOICEDLGH_G__
14
15 #ifdef __GNUG__
16 #pragma interface "choicdgg.h"
17 #endif
18
19 #include "wx/dynarray.h"
20 #include "wx/dialog.h"
21
22 class WXDLLEXPORT wxListBox;
23
24 // ----------------------------------------------------------------------------
25 // some (ugly...) constants
26 // ----------------------------------------------------------------------------
27
28 #define wxCHOICE_HEIGHT 150
29 #define wxCHOICE_WIDTH 200
30
31 #define wxCHOICEDLG_STYLE (wxDEFAULT_DIALOG_STYLE|wxOK | wxCANCEL | wxCENTRE)
32
33 // ----------------------------------------------------------------------------
34 // wxAnyChoiceDialog: a base class for dialogs containing a listbox
35 // ----------------------------------------------------------------------------
36
37 class WXDLLEXPORT wxAnyChoiceDialog : public wxDialog
38 {
39 public:
40 wxAnyChoiceDialog() { }
41
42 wxAnyChoiceDialog(wxWindow *parent,
43 const wxString& message,
44 const wxString& caption,
45 int n, const wxString *choices,
46 long styleDlg = wxCHOICEDLG_STYLE,
47 const wxPoint& pos = wxDefaultPosition,
48 long styleLbox = wxLB_ALWAYS_SB)
49 {
50 (void)Create(parent, message, caption, n, choices,
51 styleDlg, pos, styleLbox);
52 }
53
54 bool Create(wxWindow *parent,
55 const wxString& message,
56 const wxString& caption,
57 int n, const wxString *choices,
58 long styleDlg = wxCHOICEDLG_STYLE,
59 const wxPoint& pos = wxDefaultPosition,
60 long styleLbox = wxLB_ALWAYS_SB);
61
62 protected:
63 wxListBox *m_listbox;
64 };
65
66 // ----------------------------------------------------------------------------
67 // wxSingleChoiceDialog: a dialog with single selection listbox
68 // ----------------------------------------------------------------------------
69
70 class WXDLLEXPORT wxSingleChoiceDialog : public wxAnyChoiceDialog
71 {
72 public:
73 wxSingleChoiceDialog()
74 {
75 m_selection = -1;
76 }
77
78 wxSingleChoiceDialog(wxWindow *parent,
79 const wxString& message,
80 const wxString& caption,
81 int n,
82 const wxString *choices,
83 char **clientData = (char **)NULL,
84 long style = wxCHOICEDLG_STYLE,
85 const wxPoint& pos = wxDefaultPosition);
86
87 bool Create(wxWindow *parent,
88 const wxString& message,
89 const wxString& caption,
90 int n,
91 const wxString *choices,
92 char **clientData = (char **)NULL,
93 long style = wxCHOICEDLG_STYLE,
94 const wxPoint& pos = wxDefaultPosition);
95
96 void SetSelection(int sel);
97 int GetSelection() const { return m_selection; }
98 wxString GetStringSelection() const { return m_stringSelection; }
99
100 // obsolete function (NB: no need to make it return wxChar, it's untyped)
101 char *GetSelectionClientData() const { return (char *)m_clientData; }
102
103 // implementation from now on
104 void OnOK(wxCommandEvent& event);
105 void OnListBoxDClick(wxCommandEvent& event);
106
107 // old, deprecated methods
108 #ifdef WXWIN_COMPATIBILITY_2
109 wxSingleChoiceDialog(wxWindow *parent,
110 const wxString& message,
111 const wxString& caption,
112 const wxStringList& choices,
113 char **clientData = (char **)NULL,
114 long style = wxCHOICEDLG_STYLE,
115 const wxPoint& pos = wxDefaultPosition);
116
117 bool Create(wxWindow *parent,
118 const wxString& message,
119 const wxString& caption,
120 const wxStringList& choices,
121 char **clientData = (char **)NULL,
122 long style = wxCHOICEDLG_STYLE,
123 const wxPoint& pos = wxDefaultPosition);
124 #endif // WXWIN_COMPATIBILITY_2
125
126 protected:
127 int m_selection;
128 wxString m_stringSelection;
129
130 private:
131 DECLARE_DYNAMIC_CLASS(wxSingleChoiceDialog)
132 DECLARE_EVENT_TABLE()
133 };
134
135 // ----------------------------------------------------------------------------
136 // wxMultiChoiceDialog: a dialog with multi selection listbox
137 // ----------------------------------------------------------------------------
138
139 class WXDLLEXPORT wxMultiChoiceDialog : public wxAnyChoiceDialog
140 {
141 public:
142 wxMultiChoiceDialog() { }
143
144 wxMultiChoiceDialog(wxWindow *parent,
145 const wxString& message,
146 const wxString& caption,
147 int n,
148 const wxString *choices,
149 long style = wxCHOICEDLG_STYLE,
150 const wxPoint& pos = wxDefaultPosition)
151 {
152 (void)Create(parent, message, caption, n, choices, style, pos);
153 }
154
155 bool Create(wxWindow *parent,
156 const wxString& message,
157 const wxString& caption,
158 int n,
159 const wxString *choices,
160 long style = wxCHOICEDLG_STYLE,
161 const wxPoint& pos = wxDefaultPosition);
162
163 void SetSelections(const wxArrayInt& selections);
164 wxArrayInt GetSelections() const { return m_selections; }
165
166 // implementation from now on
167 void OnOK(wxCommandEvent& event);
168
169 protected:
170 wxArrayInt m_selections;
171
172 private:
173 DECLARE_DYNAMIC_CLASS(wxMultiChoiceDialog)
174 DECLARE_EVENT_TABLE()
175 };
176
177 // ----------------------------------------------------------------------------
178 // wrapper functions which can be used to get selection(s) from the user
179 // ----------------------------------------------------------------------------
180
181 // get the user selection as a string
182 WXDLLEXPORT wxString wxGetSingleChoice(const wxString& message,
183 const wxString& caption,
184 const wxArrayString& choices,
185 wxWindow *parent = (wxWindow *) NULL,
186 int x = -1,
187 int y = -1,
188 bool centre = TRUE,
189 int width = wxCHOICE_WIDTH,
190 int height = wxCHOICE_HEIGHT);
191
192 WXDLLEXPORT wxString wxGetSingleChoice(const wxString& message,
193 const wxString& caption,
194 int n, const wxString *choices,
195 wxWindow *parent = (wxWindow *) NULL,
196 int x = -1,
197 int y = -1,
198 bool centre = TRUE,
199 int width = wxCHOICE_WIDTH,
200 int height = wxCHOICE_HEIGHT);
201
202 // Same as above but gets position in list of strings, instead of string,
203 // or -1 if no selection
204 WXDLLEXPORT int wxGetSingleChoiceIndex(const wxString& message,
205 const wxString& caption,
206 const wxArrayString& choices,
207 wxWindow *parent = (wxWindow *) NULL,
208 int x = -1,
209 int y = -1,
210 bool centre = TRUE,
211 int width = wxCHOICE_WIDTH,
212 int height = wxCHOICE_HEIGHT);
213
214 WXDLLEXPORT int wxGetSingleChoiceIndex(const wxString& message,
215 const wxString& caption,
216 int n, const wxString *choices,
217 wxWindow *parent = (wxWindow *) NULL,
218 int x = -1,
219 int y = -1,
220 bool centre = TRUE,
221 int width = wxCHOICE_WIDTH,
222 int height = wxCHOICE_HEIGHT);
223
224 // Return client data instead or NULL if cancelled
225 WXDLLEXPORT void* wxGetSingleChoiceData(const wxString& message,
226 const wxString& caption,
227 const wxArrayString& choices,
228 void **client_data,
229 wxWindow *parent = (wxWindow *) NULL,
230 int x = -1, int y = -1,
231 bool centre = TRUE,
232 int width = wxCHOICE_WIDTH,
233 int height = wxCHOICE_HEIGHT);
234
235 WXDLLEXPORT void* wxGetSingleChoiceData(const wxString& message,
236 const wxString& caption,
237 int n, const wxString *choices,
238 void **client_data,
239 wxWindow *parent = (wxWindow *) NULL,
240 int x = -1, int y = -1,
241 bool centre = TRUE,
242 int width = wxCHOICE_WIDTH,
243 int height = wxCHOICE_HEIGHT);
244
245 // fill the array with the indices of the chosen items, it will be empty
246 // if no items were selected or Cancel was pressed - return the number of
247 // selections
248 WXDLLEXPORT size_t wxGetMultipleChoices(wxArrayInt& selections,
249 const wxString& message,
250 const wxString& caption,
251 int n, const wxString *choices,
252 wxWindow *parent = (wxWindow *) NULL,
253 int x = -1,
254 int y = -1,
255 bool centre = TRUE,
256 int width = wxCHOICE_WIDTH,
257 int height = wxCHOICE_HEIGHT);
258
259 WXDLLEXPORT size_t wxGetMultipleChoices(wxArrayInt& selections,
260 const wxString& message,
261 const wxString& caption,
262 const wxArrayString& choices,
263 wxWindow *parent = (wxWindow *) NULL,
264 int x = -1,
265 int y = -1,
266 bool centre = TRUE,
267 int width = wxCHOICE_WIDTH,
268 int height = wxCHOICE_HEIGHT);
269
270 // ----------------------------------------------------------------------------
271 // these methods are for backwards compatibility only, not documented and
272 // deprecated
273 // ----------------------------------------------------------------------------
274
275 WXDLLEXPORT wxString wxGetSingleChoice(const wxString& message,
276 const wxString& caption,
277 int n, wxChar *choices[],
278 wxWindow *parent = (wxWindow *) NULL,
279 int x = -1,
280 int y = -1,
281 bool centre = TRUE,
282 int width = wxCHOICE_WIDTH,
283 int height = wxCHOICE_HEIGHT);
284
285 WXDLLEXPORT int wxGetSingleChoiceIndex(const wxString& message,
286 const wxString& caption,
287 int n, wxChar *choices[],
288 wxWindow *parent = (wxWindow *) NULL,
289 int x = -1,
290 int y = -1,
291 bool centre = TRUE,
292 int width = wxCHOICE_WIDTH,
293 int height = wxCHOICE_HEIGHT);
294
295 WXDLLEXPORT void* wxGetSingleChoiceData(const wxString& message,
296 const wxString& caption,
297 int n, wxChar **choices,
298 void **client_data,
299 wxWindow *parent = (wxWindow *) NULL,
300 int x = -1, int y = -1,
301 bool centre = TRUE,
302 int width = wxCHOICE_WIDTH,
303 int height = wxCHOICE_HEIGHT);
304
305
306 #endif // __CHOICEDLGH_G__
307