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