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