]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/choicdgg.h
no changes
[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) wxWindows team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef __CHOICEDLGH_G__
13 #define __CHOICEDLGH_G__
14
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "choicdgg.h"
17 #endif
18
19 #include "wx/dynarray.h"
20 #include "wx/dialog.h"
21
22 class WXDLLEXPORT wxListBox;
23
24 // ----------------------------------------------------------------------------
25 // some (ugly...) constants
26 // ----------------------------------------------------------------------------
27
28 #define wxCHOICE_HEIGHT 150
29 #define wxCHOICE_WIDTH 200
30
31 #define wxCHOICEDLG_STYLE \
32 (wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxOK | wxCANCEL | wxCENTRE)
33
34 // ----------------------------------------------------------------------------
35 // wxAnyChoiceDialog: a base class for dialogs containing a listbox
36 // ----------------------------------------------------------------------------
37
38 class WXDLLEXPORT wxAnyChoiceDialog : public wxDialog
39 {
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;
65
66 DECLARE_NO_COPY_CLASS(wxAnyChoiceDialog)
67 };
68
69 // ----------------------------------------------------------------------------
70 // wxSingleChoiceDialog: a dialog with single selection listbox
71 // ----------------------------------------------------------------------------
72
73 class WXDLLEXPORT wxSingleChoiceDialog : public wxAnyChoiceDialog
74 {
75 public:
76 wxSingleChoiceDialog()
77 {
78 m_selection = -1;
79 }
80
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
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 protected:
111 int m_selection;
112 wxString m_stringSelection;
113
114 private:
115 DECLARE_DYNAMIC_CLASS_NO_COPY(wxSingleChoiceDialog)
116 DECLARE_EVENT_TABLE()
117 };
118
119 // ----------------------------------------------------------------------------
120 // wxMultiChoiceDialog: a dialog with multi selection listbox
121 // ----------------------------------------------------------------------------
122
123 class WXDLLEXPORT wxMultiChoiceDialog : public wxAnyChoiceDialog
124 {
125 public:
126 wxMultiChoiceDialog() { }
127
128 wxMultiChoiceDialog(wxWindow *parent,
129 const wxString& message,
130 const wxString& caption,
131 int n,
132 const wxString *choices,
133 long style = wxCHOICEDLG_STYLE,
134 const wxPoint& pos = wxDefaultPosition)
135 {
136 (void)Create(parent, message, caption, n, choices, style, pos);
137 }
138
139 bool Create(wxWindow *parent,
140 const wxString& message,
141 const wxString& caption,
142 int n,
143 const wxString *choices,
144 long style = wxCHOICEDLG_STYLE,
145 const wxPoint& pos = wxDefaultPosition);
146
147 void SetSelections(const wxArrayInt& selections);
148 wxArrayInt GetSelections() const { return m_selections; }
149
150 // implementation from now on
151 virtual bool TransferDataFromWindow();
152
153 protected:
154 wxArrayInt m_selections;
155
156 private:
157 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMultiChoiceDialog)
158 };
159
160 // ----------------------------------------------------------------------------
161 // wrapper functions which can be used to get selection(s) from the user
162 // ----------------------------------------------------------------------------
163
164 // get the user selection as a string
165 WXDLLEXPORT wxString wxGetSingleChoice(const wxString& message,
166 const wxString& caption,
167 const wxArrayString& choices,
168 wxWindow *parent = (wxWindow *) NULL,
169 int x = -1,
170 int y = -1,
171 bool centre = TRUE,
172 int width = wxCHOICE_WIDTH,
173 int height = wxCHOICE_HEIGHT);
174
175 WXDLLEXPORT wxString wxGetSingleChoice(const wxString& message,
176 const wxString& caption,
177 int n, const wxString *choices,
178 wxWindow *parent = (wxWindow *) NULL,
179 int x = -1,
180 int y = -1,
181 bool centre = TRUE,
182 int width = wxCHOICE_WIDTH,
183 int height = wxCHOICE_HEIGHT);
184
185 // Same as above but gets position in list of strings, instead of string,
186 // or -1 if no selection
187 WXDLLEXPORT int wxGetSingleChoiceIndex(const wxString& message,
188 const wxString& caption,
189 const wxArrayString& choices,
190 wxWindow *parent = (wxWindow *) NULL,
191 int x = -1,
192 int y = -1,
193 bool centre = TRUE,
194 int width = wxCHOICE_WIDTH,
195 int height = wxCHOICE_HEIGHT);
196
197 WXDLLEXPORT int wxGetSingleChoiceIndex(const wxString& message,
198 const wxString& caption,
199 int n, const wxString *choices,
200 wxWindow *parent = (wxWindow *) NULL,
201 int x = -1,
202 int y = -1,
203 bool centre = TRUE,
204 int width = wxCHOICE_WIDTH,
205 int height = wxCHOICE_HEIGHT);
206
207 // Return client data instead or NULL if cancelled
208 WXDLLEXPORT void* wxGetSingleChoiceData(const wxString& message,
209 const wxString& caption,
210 const wxArrayString& choices,
211 void **client_data,
212 wxWindow *parent = (wxWindow *) NULL,
213 int x = -1, int y = -1,
214 bool centre = TRUE,
215 int width = wxCHOICE_WIDTH,
216 int height = wxCHOICE_HEIGHT);
217
218 WXDLLEXPORT void* wxGetSingleChoiceData(const wxString& message,
219 const wxString& caption,
220 int n, const wxString *choices,
221 void **client_data,
222 wxWindow *parent = (wxWindow *) NULL,
223 int x = -1, int y = -1,
224 bool centre = TRUE,
225 int width = wxCHOICE_WIDTH,
226 int height = wxCHOICE_HEIGHT);
227
228 // fill the array with the indices of the chosen items, it will be empty
229 // if no items were selected or Cancel was pressed - return the number of
230 // selections
231 WXDLLEXPORT size_t wxGetMultipleChoices(wxArrayInt& selections,
232 const wxString& message,
233 const wxString& caption,
234 int n, const wxString *choices,
235 wxWindow *parent = (wxWindow *) NULL,
236 int x = -1,
237 int y = -1,
238 bool centre = TRUE,
239 int width = wxCHOICE_WIDTH,
240 int height = wxCHOICE_HEIGHT);
241
242 WXDLLEXPORT size_t wxGetMultipleChoices(wxArrayInt& selections,
243 const wxString& message,
244 const wxString& caption,
245 const wxArrayString& choices,
246 wxWindow *parent = (wxWindow *) NULL,
247 int x = -1,
248 int y = -1,
249 bool centre = TRUE,
250 int width = wxCHOICE_WIDTH,
251 int height = wxCHOICE_HEIGHT);
252
253 #endif // __CHOICEDLGH_G__
254