]>
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 | ||
12028905 | 15 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
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 | ||
259a6e38 JS |
31 | #ifdef __WXWINCE__ |
32 | #define wxCHOICEDLG_STYLE \ | |
33 | (wxDEFAULT_DIALOG_STYLE | wxOK | wxCANCEL | wxCENTRE) | |
34 | #else | |
abd9b10e VZ |
35 | #define wxCHOICEDLG_STYLE \ |
36 | (wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxOK | wxCANCEL | wxCENTRE) | |
259a6e38 | 37 | #endif |
c801d85f | 38 | |
d6c9c1b7 VZ |
39 | // ---------------------------------------------------------------------------- |
40 | // wxAnyChoiceDialog: a base class for dialogs containing a listbox | |
41 | // ---------------------------------------------------------------------------- | |
42 | ||
43 | class WXDLLEXPORT wxAnyChoiceDialog : public wxDialog | |
c801d85f | 44 | { |
d6c9c1b7 | 45 | public: |
6463b9f5 | 46 | wxAnyChoiceDialog() { } |
d6c9c1b7 VZ |
47 | |
48 | wxAnyChoiceDialog(wxWindow *parent, | |
49 | const wxString& message, | |
50 | const wxString& caption, | |
51 | int n, const wxString *choices, | |
52 | long styleDlg = wxCHOICEDLG_STYLE, | |
53 | const wxPoint& pos = wxDefaultPosition, | |
6463b9f5 JS |
54 | long styleLbox = wxLB_ALWAYS_SB) |
55 | { | |
56 | (void)Create(parent, message, caption, n, choices, | |
57 | styleDlg, pos, styleLbox); | |
58 | } | |
584ad2a3 MB |
59 | wxAnyChoiceDialog(wxWindow *parent, |
60 | const wxString& message, | |
61 | const wxString& caption, | |
62 | const wxArrayString& choices, | |
63 | long styleDlg = wxCHOICEDLG_STYLE, | |
64 | const wxPoint& pos = wxDefaultPosition, | |
65 | long styleLbox = wxLB_ALWAYS_SB) | |
66 | { | |
67 | (void)Create(parent, message, caption, choices, | |
68 | styleDlg, pos, styleLbox); | |
69 | } | |
d6c9c1b7 VZ |
70 | |
71 | bool Create(wxWindow *parent, | |
72 | const wxString& message, | |
73 | const wxString& caption, | |
74 | int n, const wxString *choices, | |
75 | long styleDlg = wxCHOICEDLG_STYLE, | |
76 | const wxPoint& pos = wxDefaultPosition, | |
77 | long styleLbox = wxLB_ALWAYS_SB); | |
584ad2a3 MB |
78 | bool Create(wxWindow *parent, |
79 | const wxString& message, | |
80 | const wxString& caption, | |
81 | const wxArrayString& choices, | |
82 | long styleDlg = wxCHOICEDLG_STYLE, | |
83 | const wxPoint& pos = wxDefaultPosition, | |
84 | long styleLbox = wxLB_ALWAYS_SB); | |
d6c9c1b7 VZ |
85 | |
86 | protected: | |
87 | wxListBox *m_listbox; | |
22f3361e VZ |
88 | |
89 | DECLARE_NO_COPY_CLASS(wxAnyChoiceDialog) | |
d6c9c1b7 | 90 | }; |
257bf510 | 91 | |
d6c9c1b7 VZ |
92 | // ---------------------------------------------------------------------------- |
93 | // wxSingleChoiceDialog: a dialog with single selection listbox | |
94 | // ---------------------------------------------------------------------------- | |
95 | ||
96 | class WXDLLEXPORT wxSingleChoiceDialog : public wxAnyChoiceDialog | |
97 | { | |
c801d85f | 98 | public: |
6463b9f5 JS |
99 | wxSingleChoiceDialog() |
100 | { | |
101 | m_selection = -1; | |
102 | } | |
d6c9c1b7 | 103 | |
257bf510 VZ |
104 | wxSingleChoiceDialog(wxWindow *parent, |
105 | const wxString& message, | |
106 | const wxString& caption, | |
107 | int n, | |
108 | const wxString *choices, | |
109 | char **clientData = (char **)NULL, | |
110 | long style = wxCHOICEDLG_STYLE, | |
111 | const wxPoint& pos = wxDefaultPosition); | |
584ad2a3 MB |
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); | |
257bf510 | 119 | |
d6c9c1b7 VZ |
120 | bool Create(wxWindow *parent, |
121 | const wxString& message, | |
122 | const wxString& caption, | |
123 | int n, | |
124 | const wxString *choices, | |
125 | char **clientData = (char **)NULL, | |
126 | long style = wxCHOICEDLG_STYLE, | |
127 | const wxPoint& pos = wxDefaultPosition); | |
584ad2a3 MB |
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); | |
d6c9c1b7 VZ |
135 | |
136 | void SetSelection(int sel); | |
137 | int GetSelection() const { return m_selection; } | |
138 | wxString GetStringSelection() const { return m_stringSelection; } | |
139 | ||
140 | // obsolete function (NB: no need to make it return wxChar, it's untyped) | |
141 | char *GetSelectionClientData() const { return (char *)m_clientData; } | |
142 | ||
143 | // implementation from now on | |
144 | void OnOK(wxCommandEvent& event); | |
145 | void OnListBoxDClick(wxCommandEvent& event); | |
146 | ||
d6c9c1b7 VZ |
147 | protected: |
148 | int m_selection; | |
149 | wxString m_stringSelection; | |
150 | ||
151 | private: | |
fc7a2a60 | 152 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxSingleChoiceDialog) |
d6c9c1b7 VZ |
153 | DECLARE_EVENT_TABLE() |
154 | }; | |
155 | ||
156 | // ---------------------------------------------------------------------------- | |
157 | // wxMultiChoiceDialog: a dialog with multi selection listbox | |
158 | // ---------------------------------------------------------------------------- | |
159 | ||
160 | class WXDLLEXPORT wxMultiChoiceDialog : public wxAnyChoiceDialog | |
161 | { | |
162 | public: | |
6463b9f5 | 163 | wxMultiChoiceDialog() { } |
d6c9c1b7 VZ |
164 | |
165 | wxMultiChoiceDialog(wxWindow *parent, | |
166 | const wxString& message, | |
167 | const wxString& caption, | |
168 | int n, | |
169 | const wxString *choices, | |
170 | long style = wxCHOICEDLG_STYLE, | |
6463b9f5 JS |
171 | const wxPoint& pos = wxDefaultPosition) |
172 | { | |
173 | (void)Create(parent, message, caption, n, choices, style, pos); | |
174 | } | |
584ad2a3 MB |
175 | wxMultiChoiceDialog(wxWindow *parent, |
176 | const wxString& message, | |
177 | const wxString& caption, | |
178 | const wxArrayString& choices, | |
179 | long style = wxCHOICEDLG_STYLE, | |
180 | const wxPoint& pos = wxDefaultPosition) | |
181 | { | |
182 | (void)Create(parent, message, caption, choices, style, pos); | |
183 | } | |
257bf510 VZ |
184 | |
185 | bool Create(wxWindow *parent, | |
186 | const wxString& message, | |
187 | const wxString& caption, | |
d6c9c1b7 VZ |
188 | int n, |
189 | const wxString *choices, | |
257bf510 VZ |
190 | long style = wxCHOICEDLG_STYLE, |
191 | const wxPoint& pos = wxDefaultPosition); | |
584ad2a3 MB |
192 | bool Create(wxWindow *parent, |
193 | const wxString& message, | |
194 | const wxString& caption, | |
195 | const wxArrayString& choices, | |
196 | long style = wxCHOICEDLG_STYLE, | |
197 | const wxPoint& pos = wxDefaultPosition); | |
c801d85f | 198 | |
d6c9c1b7 VZ |
199 | void SetSelections(const wxArrayInt& selections); |
200 | wxArrayInt GetSelections() const { return m_selections; } | |
c801d85f | 201 | |
257bf510 | 202 | // implementation from now on |
3d49ce44 | 203 | virtual bool TransferDataFromWindow(); |
c801d85f | 204 | |
c801d85f | 205 | protected: |
d6c9c1b7 | 206 | wxArrayInt m_selections; |
257bf510 VZ |
207 | |
208 | private: | |
fc7a2a60 | 209 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxMultiChoiceDialog) |
c801d85f KB |
210 | }; |
211 | ||
d6c9c1b7 VZ |
212 | // ---------------------------------------------------------------------------- |
213 | // wrapper functions which can be used to get selection(s) from the user | |
214 | // ---------------------------------------------------------------------------- | |
215 | ||
216 | // get the user selection as a string | |
217 | WXDLLEXPORT wxString wxGetSingleChoice(const wxString& message, | |
218 | const wxString& caption, | |
219 | const wxArrayString& choices, | |
220 | wxWindow *parent = (wxWindow *) NULL, | |
422d0ff0 WS |
221 | int x = wxDefaultCoord, |
222 | int y = wxDefaultCoord, | |
ca65c044 | 223 | bool centre = true, |
d6c9c1b7 VZ |
224 | int width = wxCHOICE_WIDTH, |
225 | int height = wxCHOICE_HEIGHT); | |
c801d85f | 226 | |
d6c9c1b7 VZ |
227 | WXDLLEXPORT wxString wxGetSingleChoice(const wxString& message, |
228 | const wxString& caption, | |
229 | int n, const wxString *choices, | |
230 | wxWindow *parent = (wxWindow *) NULL, | |
422d0ff0 WS |
231 | int x = wxDefaultCoord, |
232 | int y = wxDefaultCoord, | |
ca65c044 | 233 | bool centre = true, |
d6c9c1b7 VZ |
234 | int width = wxCHOICE_WIDTH, |
235 | int height = wxCHOICE_HEIGHT); | |
c801d85f KB |
236 | |
237 | // Same as above but gets position in list of strings, instead of string, | |
238 | // or -1 if no selection | |
d6c9c1b7 VZ |
239 | WXDLLEXPORT int wxGetSingleChoiceIndex(const wxString& message, |
240 | const wxString& caption, | |
241 | const wxArrayString& choices, | |
242 | wxWindow *parent = (wxWindow *) NULL, | |
422d0ff0 WS |
243 | int x = wxDefaultCoord, |
244 | int y = wxDefaultCoord, | |
ca65c044 | 245 | bool centre = true, |
d6c9c1b7 VZ |
246 | int width = wxCHOICE_WIDTH, |
247 | int height = wxCHOICE_HEIGHT); | |
248 | ||
249 | WXDLLEXPORT int wxGetSingleChoiceIndex(const wxString& message, | |
250 | const wxString& caption, | |
251 | int n, const wxString *choices, | |
252 | wxWindow *parent = (wxWindow *) NULL, | |
422d0ff0 WS |
253 | int x = wxDefaultCoord, |
254 | int y = wxDefaultCoord, | |
ca65c044 | 255 | bool centre = true, |
d6c9c1b7 VZ |
256 | int width = wxCHOICE_WIDTH, |
257 | int height = wxCHOICE_HEIGHT); | |
258 | ||
259 | // Return client data instead or NULL if cancelled | |
260 | WXDLLEXPORT void* wxGetSingleChoiceData(const wxString& message, | |
261 | const wxString& caption, | |
262 | const wxArrayString& choices, | |
263 | void **client_data, | |
264 | wxWindow *parent = (wxWindow *) NULL, | |
422d0ff0 WS |
265 | int x = wxDefaultCoord, |
266 | int y = wxDefaultCoord, | |
ca65c044 | 267 | bool centre = true, |
d6c9c1b7 VZ |
268 | int width = wxCHOICE_WIDTH, |
269 | int height = wxCHOICE_HEIGHT); | |
270 | ||
271 | WXDLLEXPORT void* wxGetSingleChoiceData(const wxString& message, | |
272 | const wxString& caption, | |
273 | int n, const wxString *choices, | |
274 | void **client_data, | |
275 | wxWindow *parent = (wxWindow *) NULL, | |
422d0ff0 WS |
276 | int x = wxDefaultCoord, |
277 | int y = wxDefaultCoord, | |
ca65c044 | 278 | bool centre = true, |
d6c9c1b7 VZ |
279 | int width = wxCHOICE_WIDTH, |
280 | int height = wxCHOICE_HEIGHT); | |
281 | ||
282 | // fill the array with the indices of the chosen items, it will be empty | |
283 | // if no items were selected or Cancel was pressed - return the number of | |
284 | // selections | |
285 | WXDLLEXPORT size_t wxGetMultipleChoices(wxArrayInt& selections, | |
286 | const wxString& message, | |
287 | const wxString& caption, | |
288 | int n, const wxString *choices, | |
289 | wxWindow *parent = (wxWindow *) NULL, | |
422d0ff0 WS |
290 | int x = wxDefaultCoord, |
291 | int y = wxDefaultCoord, | |
ca65c044 | 292 | bool centre = true, |
d6c9c1b7 VZ |
293 | int width = wxCHOICE_WIDTH, |
294 | int height = wxCHOICE_HEIGHT); | |
295 | ||
296 | WXDLLEXPORT size_t wxGetMultipleChoices(wxArrayInt& selections, | |
297 | const wxString& message, | |
298 | const wxString& caption, | |
299 | const wxArrayString& choices, | |
300 | wxWindow *parent = (wxWindow *) NULL, | |
422d0ff0 WS |
301 | int x = wxDefaultCoord, |
302 | int y = wxDefaultCoord, | |
ca65c044 | 303 | bool centre = true, |
d6c9c1b7 VZ |
304 | int width = wxCHOICE_WIDTH, |
305 | int height = wxCHOICE_HEIGHT); | |
306 | ||
d6c9c1b7 | 307 | #endif // __CHOICEDLGH_G__ |
c801d85f | 308 |