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 virtual bool TransferDataFromWindow();
170 wxArrayInt m_selections
;
173 DECLARE_DYNAMIC_CLASS(wxMultiChoiceDialog
)
176 // ----------------------------------------------------------------------------
177 // wrapper functions which can be used to get selection(s) from the user
178 // ----------------------------------------------------------------------------
180 // get the user selection as a string
181 WXDLLEXPORT wxString
wxGetSingleChoice(const wxString
& message
,
182 const wxString
& caption
,
183 const wxArrayString
& choices
,
184 wxWindow
*parent
= (wxWindow
*) NULL
,
188 int width
= wxCHOICE_WIDTH
,
189 int height
= wxCHOICE_HEIGHT
);
191 WXDLLEXPORT wxString
wxGetSingleChoice(const wxString
& message
,
192 const wxString
& caption
,
193 int n
, const wxString
*choices
,
194 wxWindow
*parent
= (wxWindow
*) NULL
,
198 int width
= wxCHOICE_WIDTH
,
199 int height
= wxCHOICE_HEIGHT
);
201 // Same as above but gets position in list of strings, instead of string,
202 // or -1 if no selection
203 WXDLLEXPORT
int wxGetSingleChoiceIndex(const wxString
& message
,
204 const wxString
& caption
,
205 const wxArrayString
& choices
,
206 wxWindow
*parent
= (wxWindow
*) NULL
,
210 int width
= wxCHOICE_WIDTH
,
211 int height
= wxCHOICE_HEIGHT
);
213 WXDLLEXPORT
int wxGetSingleChoiceIndex(const wxString
& message
,
214 const wxString
& caption
,
215 int n
, const wxString
*choices
,
216 wxWindow
*parent
= (wxWindow
*) NULL
,
220 int width
= wxCHOICE_WIDTH
,
221 int height
= wxCHOICE_HEIGHT
);
223 // Return client data instead or NULL if cancelled
224 WXDLLEXPORT
void* wxGetSingleChoiceData(const wxString
& message
,
225 const wxString
& caption
,
226 const wxArrayString
& choices
,
228 wxWindow
*parent
= (wxWindow
*) NULL
,
229 int x
= -1, int y
= -1,
231 int width
= wxCHOICE_WIDTH
,
232 int height
= wxCHOICE_HEIGHT
);
234 WXDLLEXPORT
void* wxGetSingleChoiceData(const wxString
& message
,
235 const wxString
& caption
,
236 int n
, const wxString
*choices
,
238 wxWindow
*parent
= (wxWindow
*) NULL
,
239 int x
= -1, int y
= -1,
241 int width
= wxCHOICE_WIDTH
,
242 int height
= wxCHOICE_HEIGHT
);
244 // fill the array with the indices of the chosen items, it will be empty
245 // if no items were selected or Cancel was pressed - return the number of
247 WXDLLEXPORT
size_t wxGetMultipleChoices(wxArrayInt
& selections
,
248 const wxString
& message
,
249 const wxString
& caption
,
250 int n
, const wxString
*choices
,
251 wxWindow
*parent
= (wxWindow
*) NULL
,
255 int width
= wxCHOICE_WIDTH
,
256 int height
= wxCHOICE_HEIGHT
);
258 WXDLLEXPORT
size_t wxGetMultipleChoices(wxArrayInt
& selections
,
259 const wxString
& message
,
260 const wxString
& caption
,
261 const wxArrayString
& choices
,
262 wxWindow
*parent
= (wxWindow
*) NULL
,
266 int width
= wxCHOICE_WIDTH
,
267 int height
= wxCHOICE_HEIGHT
);
269 // ----------------------------------------------------------------------------
270 // these methods are for backwards compatibility only, not documented and
272 // ----------------------------------------------------------------------------
274 WXDLLEXPORT wxString
wxGetSingleChoice(const wxString
& message
,
275 const wxString
& caption
,
276 int n
, wxChar
*choices
[],
277 wxWindow
*parent
= (wxWindow
*) NULL
,
281 int width
= wxCHOICE_WIDTH
,
282 int height
= wxCHOICE_HEIGHT
);
284 WXDLLEXPORT
int wxGetSingleChoiceIndex(const wxString
& message
,
285 const wxString
& caption
,
286 int n
, wxChar
*choices
[],
287 wxWindow
*parent
= (wxWindow
*) NULL
,
291 int width
= wxCHOICE_WIDTH
,
292 int height
= wxCHOICE_HEIGHT
);
294 WXDLLEXPORT
void* wxGetSingleChoiceData(const wxString
& message
,
295 const wxString
& caption
,
296 int n
, wxChar
**choices
,
298 wxWindow
*parent
= (wxWindow
*) NULL
,
299 int x
= -1, int y
= -1,
301 int width
= wxCHOICE_WIDTH
,
302 int height
= wxCHOICE_HEIGHT
);
305 #endif // __CHOICEDLGH_G__