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