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