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
8 // Copyright: (c) wxWindows team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef __CHOICEDLGH_G__
13 #define __CHOICEDLGH_G__
16 #pragma interface "choicdgg.h"
19 #include "wx/dynarray.h"
20 #include "wx/dialog.h"
22 class WXDLLEXPORT wxListBox
;
24 // ----------------------------------------------------------------------------
25 // some (ugly...) constants
26 // ----------------------------------------------------------------------------
28 #define wxCHOICE_HEIGHT 150
29 #define wxCHOICE_WIDTH 200
31 #define wxCHOICEDLG_STYLE (wxDEFAULT_DIALOG_STYLE|wxOK | wxCANCEL | wxCENTRE)
33 // ----------------------------------------------------------------------------
34 // wxAnyChoiceDialog: a base class for dialogs containing a listbox
35 // ----------------------------------------------------------------------------
37 class WXDLLEXPORT wxAnyChoiceDialog
: public wxDialog
40 wxAnyChoiceDialog() { }
42 wxAnyChoiceDialog(wxWindow
*parent
,
43 const wxString
& message
,
44 const wxString
& caption
,
45 int n
, const wxString
*choices
,
46 long styleDlg
= wxCHOICEDLG_STYLE
,
47 const wxPoint
& pos
= wxDefaultPosition
,
48 long styleLbox
= wxLB_ALWAYS_SB
)
50 (void)Create(parent
, message
, caption
, n
, choices
,
51 styleDlg
, pos
, styleLbox
);
54 bool Create(wxWindow
*parent
,
55 const wxString
& message
,
56 const wxString
& caption
,
57 int n
, const wxString
*choices
,
58 long styleDlg
= wxCHOICEDLG_STYLE
,
59 const wxPoint
& pos
= wxDefaultPosition
,
60 long styleLbox
= wxLB_ALWAYS_SB
);
66 // ----------------------------------------------------------------------------
67 // wxSingleChoiceDialog: a dialog with single selection listbox
68 // ----------------------------------------------------------------------------
70 class WXDLLEXPORT wxSingleChoiceDialog
: public wxAnyChoiceDialog
73 wxSingleChoiceDialog()
78 wxSingleChoiceDialog(wxWindow
*parent
,
79 const wxString
& message
,
80 const wxString
& caption
,
82 const wxString
*choices
,
83 char **clientData
= (char **)NULL
,
84 long style
= wxCHOICEDLG_STYLE
,
85 const wxPoint
& pos
= wxDefaultPosition
);
87 bool Create(wxWindow
*parent
,
88 const wxString
& message
,
89 const wxString
& caption
,
91 const wxString
*choices
,
92 char **clientData
= (char **)NULL
,
93 long style
= wxCHOICEDLG_STYLE
,
94 const wxPoint
& pos
= wxDefaultPosition
);
96 void SetSelection(int sel
);
97 int GetSelection() const { return m_selection
; }
98 wxString
GetStringSelection() const { return m_stringSelection
; }
100 // obsolete function (NB: no need to make it return wxChar, it's untyped)
101 char *GetSelectionClientData() const { return (char *)m_clientData
; }
103 // implementation from now on
104 void OnOK(wxCommandEvent
& event
);
105 void OnListBoxDClick(wxCommandEvent
& event
);
107 // old, deprecated methods
108 #ifdef WXWIN_COMPATIBILITY_2
109 wxSingleChoiceDialog(wxWindow
*parent
,
110 const wxString
& message
,
111 const wxString
& caption
,
112 const wxStringList
& choices
,
113 char **clientData
= (char **)NULL
,
114 long style
= wxCHOICEDLG_STYLE
,
115 const wxPoint
& pos
= wxDefaultPosition
);
117 bool Create(wxWindow
*parent
,
118 const wxString
& message
,
119 const wxString
& caption
,
120 const wxStringList
& choices
,
121 char **clientData
= (char **)NULL
,
122 long style
= wxCHOICEDLG_STYLE
,
123 const wxPoint
& pos
= wxDefaultPosition
);
124 #endif // WXWIN_COMPATIBILITY_2
128 wxString m_stringSelection
;
131 DECLARE_DYNAMIC_CLASS(wxSingleChoiceDialog
)
132 DECLARE_EVENT_TABLE()
135 // ----------------------------------------------------------------------------
136 // wxMultiChoiceDialog: a dialog with multi selection listbox
137 // ----------------------------------------------------------------------------
139 class WXDLLEXPORT wxMultiChoiceDialog
: public wxAnyChoiceDialog
142 wxMultiChoiceDialog() { }
144 wxMultiChoiceDialog(wxWindow
*parent
,
145 const wxString
& message
,
146 const wxString
& caption
,
148 const wxString
*choices
,
149 long style
= wxCHOICEDLG_STYLE
,
150 const wxPoint
& pos
= wxDefaultPosition
)
152 (void)Create(parent
, message
, caption
, n
, choices
, style
, pos
);
155 bool Create(wxWindow
*parent
,
156 const wxString
& message
,
157 const wxString
& caption
,
159 const wxString
*choices
,
160 long style
= wxCHOICEDLG_STYLE
,
161 const wxPoint
& pos
= wxDefaultPosition
);
163 void SetSelections(const wxArrayInt
& selections
);
164 wxArrayInt
GetSelections() const { return m_selections
; }
166 // implementation from now on
167 void OnOK(wxCommandEvent
& event
);
170 wxArrayInt m_selections
;
173 DECLARE_DYNAMIC_CLASS(wxMultiChoiceDialog
)
174 DECLARE_EVENT_TABLE()
177 // ----------------------------------------------------------------------------
178 // wrapper functions which can be used to get selection(s) from the user
179 // ----------------------------------------------------------------------------
181 // get the user selection as a string
182 WXDLLEXPORT wxString
wxGetSingleChoice(const wxString
& message
,
183 const wxString
& caption
,
184 const wxArrayString
& choices
,
185 wxWindow
*parent
= (wxWindow
*) NULL
,
189 int width
= wxCHOICE_WIDTH
,
190 int height
= wxCHOICE_HEIGHT
);
192 WXDLLEXPORT wxString
wxGetSingleChoice(const wxString
& message
,
193 const wxString
& caption
,
194 int n
, const wxString
*choices
,
195 wxWindow
*parent
= (wxWindow
*) NULL
,
199 int width
= wxCHOICE_WIDTH
,
200 int height
= wxCHOICE_HEIGHT
);
202 // Same as above but gets position in list of strings, instead of string,
203 // or -1 if no selection
204 WXDLLEXPORT
int wxGetSingleChoiceIndex(const wxString
& message
,
205 const wxString
& caption
,
206 const wxArrayString
& choices
,
207 wxWindow
*parent
= (wxWindow
*) NULL
,
211 int width
= wxCHOICE_WIDTH
,
212 int height
= wxCHOICE_HEIGHT
);
214 WXDLLEXPORT
int wxGetSingleChoiceIndex(const wxString
& message
,
215 const wxString
& caption
,
216 int n
, const wxString
*choices
,
217 wxWindow
*parent
= (wxWindow
*) NULL
,
221 int width
= wxCHOICE_WIDTH
,
222 int height
= wxCHOICE_HEIGHT
);
224 // Return client data instead or NULL if cancelled
225 WXDLLEXPORT
void* wxGetSingleChoiceData(const wxString
& message
,
226 const wxString
& caption
,
227 const wxArrayString
& choices
,
229 wxWindow
*parent
= (wxWindow
*) NULL
,
230 int x
= -1, int y
= -1,
232 int width
= wxCHOICE_WIDTH
,
233 int height
= wxCHOICE_HEIGHT
);
235 WXDLLEXPORT
void* wxGetSingleChoiceData(const wxString
& message
,
236 const wxString
& caption
,
237 int n
, const wxString
*choices
,
239 wxWindow
*parent
= (wxWindow
*) NULL
,
240 int x
= -1, int y
= -1,
242 int width
= wxCHOICE_WIDTH
,
243 int height
= wxCHOICE_HEIGHT
);
245 // fill the array with the indices of the chosen items, it will be empty
246 // if no items were selected or Cancel was pressed - return the number of
248 WXDLLEXPORT
size_t wxGetMultipleChoices(wxArrayInt
& selections
,
249 const wxString
& message
,
250 const wxString
& caption
,
251 int n
, const wxString
*choices
,
252 wxWindow
*parent
= (wxWindow
*) NULL
,
256 int width
= wxCHOICE_WIDTH
,
257 int height
= wxCHOICE_HEIGHT
);
259 WXDLLEXPORT
size_t wxGetMultipleChoices(wxArrayInt
& selections
,
260 const wxString
& message
,
261 const wxString
& caption
,
262 const wxArrayString
& choices
,
263 wxWindow
*parent
= (wxWindow
*) NULL
,
267 int width
= wxCHOICE_WIDTH
,
268 int height
= wxCHOICE_HEIGHT
);
270 // ----------------------------------------------------------------------------
271 // these methods are for backwards compatibility only, not documented and
273 // ----------------------------------------------------------------------------
275 WXDLLEXPORT wxString
wxGetSingleChoice(const wxString
& message
,
276 const wxString
& caption
,
277 int n
, wxChar
*choices
[],
278 wxWindow
*parent
= (wxWindow
*) NULL
,
282 int width
= wxCHOICE_WIDTH
,
283 int height
= wxCHOICE_HEIGHT
);
285 WXDLLEXPORT
int wxGetSingleChoiceIndex(const wxString
& message
,
286 const wxString
& caption
,
287 int n
, wxChar
*choices
[],
288 wxWindow
*parent
= (wxWindow
*) NULL
,
292 int width
= wxCHOICE_WIDTH
,
293 int height
= wxCHOICE_HEIGHT
);
295 WXDLLEXPORT
void* wxGetSingleChoiceData(const wxString
& message
,
296 const wxString
& caption
,
297 int n
, wxChar
**choices
,
299 wxWindow
*parent
= (wxWindow
*) NULL
,
300 int x
= -1, int y
= -1,
302 int width
= wxCHOICE_WIDTH
,
303 int height
= wxCHOICE_HEIGHT
);
306 #endif // __CHOICEDLGH_G__