]>
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$ | |
d6c9c1b7 | 8 | // Copyright: (c) wxWindows team |
c50f1fb9 | 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 VZ |
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; | |
22f3361e VZ |
65 | |
66 | DECLARE_NO_COPY_CLASS(wxAnyChoiceDialog) | |
d6c9c1b7 | 67 | }; |
257bf510 | 68 | |
d6c9c1b7 VZ |
69 | // ---------------------------------------------------------------------------- |
70 | // wxSingleChoiceDialog: a dialog with single selection listbox | |
71 | // ---------------------------------------------------------------------------- | |
72 | ||
73 | class WXDLLEXPORT wxSingleChoiceDialog : public wxAnyChoiceDialog | |
74 | { | |
c801d85f | 75 | public: |
d6c9c1b7 VZ |
76 | wxSingleChoiceDialog() |
77 | { | |
78 | m_selection = -1; | |
79 | } | |
80 | ||
257bf510 VZ |
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 | ||
d6c9c1b7 VZ |
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 | ||
d6c9c1b7 VZ |
110 | protected: |
111 | int m_selection; | |
112 | wxString m_stringSelection; | |
113 | ||
114 | private: | |
fc7a2a60 | 115 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxSingleChoiceDialog) |
d6c9c1b7 VZ |
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 | } | |
257bf510 VZ |
138 | |
139 | bool Create(wxWindow *parent, | |
140 | const wxString& message, | |
141 | const wxString& caption, | |
d6c9c1b7 VZ |
142 | int n, |
143 | const wxString *choices, | |
257bf510 VZ |
144 | long style = wxCHOICEDLG_STYLE, |
145 | const wxPoint& pos = wxDefaultPosition); | |
c801d85f | 146 | |
d6c9c1b7 VZ |
147 | void SetSelections(const wxArrayInt& selections); |
148 | wxArrayInt GetSelections() const { return m_selections; } | |
c801d85f | 149 | |
257bf510 | 150 | // implementation from now on |
3d49ce44 | 151 | virtual bool TransferDataFromWindow(); |
c801d85f | 152 | |
c801d85f | 153 | protected: |
d6c9c1b7 | 154 | wxArrayInt m_selections; |
257bf510 VZ |
155 | |
156 | private: | |
fc7a2a60 | 157 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxMultiChoiceDialog) |
c801d85f KB |
158 | }; |
159 | ||
d6c9c1b7 VZ |
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); | |
c801d85f | 174 | |
d6c9c1b7 VZ |
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); | |
c801d85f KB |
184 | |
185 | // Same as above but gets position in list of strings, instead of string, | |
186 | // or -1 if no selection | |
d6c9c1b7 VZ |
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 | ||
d6c9c1b7 | 253 | #endif // __CHOICEDLGH_G__ |
c801d85f | 254 |