]>
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$ | |
77ffb593 | 8 | // Copyright: (c) wxWidgets team |
65571936 | 9 | // Licence: wxWindows licence |
c801d85f KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifndef __CHOICEDLGH_G__ | |
13 | #define __CHOICEDLGH_G__ | |
14 | ||
d6c9c1b7 | 15 | #include "wx/dynarray.h" |
c801d85f | 16 | #include "wx/dialog.h" |
8ee9d618 VZ |
17 | |
18 | class WXDLLEXPORT wxListBox; | |
c801d85f | 19 | |
d6c9c1b7 VZ |
20 | // ---------------------------------------------------------------------------- |
21 | // some (ugly...) constants | |
22 | // ---------------------------------------------------------------------------- | |
23 | ||
c801d85f KB |
24 | #define wxCHOICE_HEIGHT 150 |
25 | #define wxCHOICE_WIDTH 200 | |
26 | ||
259a6e38 JS |
27 | #ifdef __WXWINCE__ |
28 | #define wxCHOICEDLG_STYLE \ | |
29 | (wxDEFAULT_DIALOG_STYLE | wxOK | wxCANCEL | wxCENTRE) | |
30 | #else | |
abd9b10e VZ |
31 | #define wxCHOICEDLG_STYLE \ |
32 | (wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxOK | wxCANCEL | wxCENTRE) | |
259a6e38 | 33 | #endif |
c801d85f | 34 | |
d6c9c1b7 VZ |
35 | // ---------------------------------------------------------------------------- |
36 | // wxAnyChoiceDialog: a base class for dialogs containing a listbox | |
37 | // ---------------------------------------------------------------------------- | |
38 | ||
39 | class WXDLLEXPORT wxAnyChoiceDialog : public wxDialog | |
c801d85f | 40 | { |
d6c9c1b7 | 41 | public: |
6463b9f5 | 42 | wxAnyChoiceDialog() { } |
d6c9c1b7 VZ |
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, | |
6463b9f5 JS |
50 | long styleLbox = wxLB_ALWAYS_SB) |
51 | { | |
52 | (void)Create(parent, message, caption, n, choices, | |
53 | styleDlg, pos, styleLbox); | |
54 | } | |
584ad2a3 MB |
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 | } | |
d6c9c1b7 VZ |
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); | |
584ad2a3 MB |
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); | |
d6c9c1b7 VZ |
81 | |
82 | protected: | |
83 | wxListBox *m_listbox; | |
22f3361e VZ |
84 | |
85 | DECLARE_NO_COPY_CLASS(wxAnyChoiceDialog) | |
d6c9c1b7 | 86 | }; |
257bf510 | 87 | |
d6c9c1b7 VZ |
88 | // ---------------------------------------------------------------------------- |
89 | // wxSingleChoiceDialog: a dialog with single selection listbox | |
90 | // ---------------------------------------------------------------------------- | |
91 | ||
92 | class WXDLLEXPORT wxSingleChoiceDialog : public wxAnyChoiceDialog | |
93 | { | |
c801d85f | 94 | public: |
6463b9f5 JS |
95 | wxSingleChoiceDialog() |
96 | { | |
97 | m_selection = -1; | |
98 | } | |
d6c9c1b7 | 99 | |
257bf510 VZ |
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); | |
584ad2a3 MB |
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); | |
257bf510 | 115 | |
d6c9c1b7 VZ |
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); | |
584ad2a3 MB |
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); | |
d6c9c1b7 VZ |
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); | |
7b504551 | 141 | #ifndef __SMARTPHONE__ |
d6c9c1b7 | 142 | void OnListBoxDClick(wxCommandEvent& event); |
7b504551 WS |
143 | #endif |
144 | #ifdef __WXWINCE__ | |
145 | void OnJoystickButtonDown(wxJoystickEvent& event); | |
146 | #endif | |
d6c9c1b7 | 147 | |
d6c9c1b7 VZ |
148 | protected: |
149 | int m_selection; | |
150 | wxString m_stringSelection; | |
151 | ||
7b504551 WS |
152 | void DoChoice(); |
153 | ||
d6c9c1b7 | 154 | private: |
fc7a2a60 | 155 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxSingleChoiceDialog) |
d6c9c1b7 VZ |
156 | DECLARE_EVENT_TABLE() |
157 | }; | |
158 | ||
159 | // ---------------------------------------------------------------------------- | |
160 | // wxMultiChoiceDialog: a dialog with multi selection listbox | |
161 | // ---------------------------------------------------------------------------- | |
162 | ||
163 | class WXDLLEXPORT wxMultiChoiceDialog : public wxAnyChoiceDialog | |
164 | { | |
165 | public: | |
6463b9f5 | 166 | wxMultiChoiceDialog() { } |
d6c9c1b7 VZ |
167 | |
168 | wxMultiChoiceDialog(wxWindow *parent, | |
169 | const wxString& message, | |
170 | const wxString& caption, | |
171 | int n, | |
172 | const wxString *choices, | |
173 | long style = wxCHOICEDLG_STYLE, | |
6463b9f5 JS |
174 | const wxPoint& pos = wxDefaultPosition) |
175 | { | |
176 | (void)Create(parent, message, caption, n, choices, style, pos); | |
177 | } | |
584ad2a3 MB |
178 | wxMultiChoiceDialog(wxWindow *parent, |
179 | const wxString& message, | |
180 | const wxString& caption, | |
181 | const wxArrayString& choices, | |
182 | long style = wxCHOICEDLG_STYLE, | |
183 | const wxPoint& pos = wxDefaultPosition) | |
184 | { | |
185 | (void)Create(parent, message, caption, choices, style, pos); | |
186 | } | |
257bf510 VZ |
187 | |
188 | bool Create(wxWindow *parent, | |
189 | const wxString& message, | |
190 | const wxString& caption, | |
d6c9c1b7 VZ |
191 | int n, |
192 | const wxString *choices, | |
257bf510 VZ |
193 | long style = wxCHOICEDLG_STYLE, |
194 | const wxPoint& pos = wxDefaultPosition); | |
584ad2a3 MB |
195 | bool Create(wxWindow *parent, |
196 | const wxString& message, | |
197 | const wxString& caption, | |
198 | const wxArrayString& choices, | |
199 | long style = wxCHOICEDLG_STYLE, | |
200 | const wxPoint& pos = wxDefaultPosition); | |
c801d85f | 201 | |
d6c9c1b7 VZ |
202 | void SetSelections(const wxArrayInt& selections); |
203 | wxArrayInt GetSelections() const { return m_selections; } | |
c801d85f | 204 | |
257bf510 | 205 | // implementation from now on |
3d49ce44 | 206 | virtual bool TransferDataFromWindow(); |
c801d85f | 207 | |
c801d85f | 208 | protected: |
d6c9c1b7 | 209 | wxArrayInt m_selections; |
257bf510 VZ |
210 | |
211 | private: | |
fc7a2a60 | 212 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxMultiChoiceDialog) |
c801d85f KB |
213 | }; |
214 | ||
d6c9c1b7 VZ |
215 | // ---------------------------------------------------------------------------- |
216 | // wrapper functions which can be used to get selection(s) from the user | |
217 | // ---------------------------------------------------------------------------- | |
218 | ||
219 | // get the user selection as a string | |
220 | WXDLLEXPORT wxString wxGetSingleChoice(const wxString& message, | |
221 | const wxString& caption, | |
222 | const wxArrayString& choices, | |
223 | wxWindow *parent = (wxWindow *) NULL, | |
422d0ff0 WS |
224 | int x = wxDefaultCoord, |
225 | int y = wxDefaultCoord, | |
ca65c044 | 226 | bool centre = true, |
d6c9c1b7 VZ |
227 | int width = wxCHOICE_WIDTH, |
228 | int height = wxCHOICE_HEIGHT); | |
c801d85f | 229 | |
d6c9c1b7 VZ |
230 | WXDLLEXPORT wxString wxGetSingleChoice(const wxString& message, |
231 | const wxString& caption, | |
232 | int n, const wxString *choices, | |
233 | wxWindow *parent = (wxWindow *) NULL, | |
422d0ff0 WS |
234 | int x = wxDefaultCoord, |
235 | int y = wxDefaultCoord, | |
ca65c044 | 236 | bool centre = true, |
d6c9c1b7 VZ |
237 | int width = wxCHOICE_WIDTH, |
238 | int height = wxCHOICE_HEIGHT); | |
c801d85f KB |
239 | |
240 | // Same as above but gets position in list of strings, instead of string, | |
241 | // or -1 if no selection | |
d6c9c1b7 VZ |
242 | WXDLLEXPORT int wxGetSingleChoiceIndex(const wxString& message, |
243 | const wxString& caption, | |
244 | const wxArrayString& choices, | |
245 | wxWindow *parent = (wxWindow *) NULL, | |
422d0ff0 WS |
246 | int x = wxDefaultCoord, |
247 | int y = wxDefaultCoord, | |
ca65c044 | 248 | bool centre = true, |
d6c9c1b7 VZ |
249 | int width = wxCHOICE_WIDTH, |
250 | int height = wxCHOICE_HEIGHT); | |
251 | ||
252 | WXDLLEXPORT int wxGetSingleChoiceIndex(const wxString& message, | |
253 | const wxString& caption, | |
254 | int n, const wxString *choices, | |
255 | wxWindow *parent = (wxWindow *) NULL, | |
422d0ff0 WS |
256 | int x = wxDefaultCoord, |
257 | int y = wxDefaultCoord, | |
ca65c044 | 258 | bool centre = true, |
d6c9c1b7 VZ |
259 | int width = wxCHOICE_WIDTH, |
260 | int height = wxCHOICE_HEIGHT); | |
261 | ||
262 | // Return client data instead or NULL if cancelled | |
263 | WXDLLEXPORT void* wxGetSingleChoiceData(const wxString& message, | |
264 | const wxString& caption, | |
265 | const wxArrayString& choices, | |
266 | void **client_data, | |
267 | wxWindow *parent = (wxWindow *) NULL, | |
422d0ff0 WS |
268 | int x = wxDefaultCoord, |
269 | int y = wxDefaultCoord, | |
ca65c044 | 270 | bool centre = true, |
d6c9c1b7 VZ |
271 | int width = wxCHOICE_WIDTH, |
272 | int height = wxCHOICE_HEIGHT); | |
273 | ||
274 | WXDLLEXPORT void* wxGetSingleChoiceData(const wxString& message, | |
275 | const wxString& caption, | |
276 | int n, const wxString *choices, | |
277 | void **client_data, | |
278 | wxWindow *parent = (wxWindow *) NULL, | |
422d0ff0 WS |
279 | int x = wxDefaultCoord, |
280 | int y = wxDefaultCoord, | |
ca65c044 | 281 | bool centre = true, |
d6c9c1b7 VZ |
282 | int width = wxCHOICE_WIDTH, |
283 | int height = wxCHOICE_HEIGHT); | |
284 | ||
285 | // fill the array with the indices of the chosen items, it will be empty | |
286 | // if no items were selected or Cancel was pressed - return the number of | |
287 | // selections | |
288 | WXDLLEXPORT size_t wxGetMultipleChoices(wxArrayInt& selections, | |
289 | const wxString& message, | |
290 | const wxString& caption, | |
291 | int n, const wxString *choices, | |
292 | wxWindow *parent = (wxWindow *) NULL, | |
422d0ff0 WS |
293 | int x = wxDefaultCoord, |
294 | int y = wxDefaultCoord, | |
ca65c044 | 295 | bool centre = true, |
d6c9c1b7 VZ |
296 | int width = wxCHOICE_WIDTH, |
297 | int height = wxCHOICE_HEIGHT); | |
298 | ||
299 | WXDLLEXPORT size_t wxGetMultipleChoices(wxArrayInt& selections, | |
300 | const wxString& message, | |
301 | const wxString& caption, | |
302 | const wxArrayString& choices, | |
303 | wxWindow *parent = (wxWindow *) NULL, | |
422d0ff0 WS |
304 | int x = wxDefaultCoord, |
305 | int y = wxDefaultCoord, | |
ca65c044 | 306 | bool centre = true, |
d6c9c1b7 VZ |
307 | int width = wxCHOICE_WIDTH, |
308 | int height = wxCHOICE_HEIGHT); | |
309 | ||
d6c9c1b7 | 310 | #endif // __CHOICEDLGH_G__ |