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__
15 #if defined(__GNUG__) && !defined(__APPLE__)
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
);
65 DECLARE_NO_COPY_CLASS(wxAnyChoiceDialog
)
68 // ----------------------------------------------------------------------------
69 // wxSingleChoiceDialog: a dialog with single selection listbox
70 // ----------------------------------------------------------------------------
72 class WXDLLEXPORT wxSingleChoiceDialog
: public wxAnyChoiceDialog
75 wxSingleChoiceDialog()
80 wxSingleChoiceDialog(wxWindow
*parent
,
81 const wxString
& message
,
82 const wxString
& caption
,
84 const wxString
*choices
,
85 char **clientData
= (char **)NULL
,
86 long style
= wxCHOICEDLG_STYLE
,
87 const wxPoint
& pos
= wxDefaultPosition
);
89 bool Create(wxWindow
*parent
,
90 const wxString
& message
,
91 const wxString
& caption
,
93 const wxString
*choices
,
94 char **clientData
= (char **)NULL
,
95 long style
= wxCHOICEDLG_STYLE
,
96 const wxPoint
& pos
= wxDefaultPosition
);
98 void SetSelection(int sel
);
99 int GetSelection() const { return m_selection
; }
100 wxString
GetStringSelection() const { return m_stringSelection
; }
102 // obsolete function (NB: no need to make it return wxChar, it's untyped)
103 char *GetSelectionClientData() const { return (char *)m_clientData
; }
105 // implementation from now on
106 void OnOK(wxCommandEvent
& event
);
107 void OnListBoxDClick(wxCommandEvent
& event
);
109 // old, deprecated methods
110 #if WXWIN_COMPATIBILITY_2
111 wxSingleChoiceDialog(wxWindow
*parent
,
112 const wxString
& message
,
113 const wxString
& caption
,
114 const wxStringList
& choices
,
115 char **clientData
= (char **)NULL
,
116 long style
= wxCHOICEDLG_STYLE
,
117 const wxPoint
& pos
= wxDefaultPosition
);
119 bool Create(wxWindow
*parent
,
120 const wxString
& message
,
121 const wxString
& caption
,
122 const wxStringList
& choices
,
123 char **clientData
= (char **)NULL
,
124 long style
= wxCHOICEDLG_STYLE
,
125 const wxPoint
& pos
= wxDefaultPosition
);
126 #endif // WXWIN_COMPATIBILITY_2
130 wxString m_stringSelection
;
133 DECLARE_DYNAMIC_CLASS(wxSingleChoiceDialog
)
134 DECLARE_EVENT_TABLE()
137 // ----------------------------------------------------------------------------
138 // wxMultiChoiceDialog: a dialog with multi selection listbox
139 // ----------------------------------------------------------------------------
141 class WXDLLEXPORT wxMultiChoiceDialog
: public wxAnyChoiceDialog
144 wxMultiChoiceDialog() { }
146 wxMultiChoiceDialog(wxWindow
*parent
,
147 const wxString
& message
,
148 const wxString
& caption
,
150 const wxString
*choices
,
151 long style
= wxCHOICEDLG_STYLE
,
152 const wxPoint
& pos
= wxDefaultPosition
)
154 (void)Create(parent
, message
, caption
, n
, choices
, style
, pos
);
157 bool Create(wxWindow
*parent
,
158 const wxString
& message
,
159 const wxString
& caption
,
161 const wxString
*choices
,
162 long style
= wxCHOICEDLG_STYLE
,
163 const wxPoint
& pos
= wxDefaultPosition
);
165 void SetSelections(const wxArrayInt
& selections
);
166 wxArrayInt
GetSelections() const { return m_selections
; }
168 // implementation from now on
169 virtual bool TransferDataFromWindow();
172 wxArrayInt m_selections
;
175 DECLARE_DYNAMIC_CLASS(wxMultiChoiceDialog
)
178 // ----------------------------------------------------------------------------
179 // wrapper functions which can be used to get selection(s) from the user
180 // ----------------------------------------------------------------------------
182 // get the user selection as a string
183 WXDLLEXPORT wxString
wxGetSingleChoice(const wxString
& message
,
184 const wxString
& caption
,
185 const wxArrayString
& choices
,
186 wxWindow
*parent
= (wxWindow
*) NULL
,
190 int width
= wxCHOICE_WIDTH
,
191 int height
= wxCHOICE_HEIGHT
);
193 WXDLLEXPORT wxString
wxGetSingleChoice(const wxString
& message
,
194 const wxString
& caption
,
195 int n
, const wxString
*choices
,
196 wxWindow
*parent
= (wxWindow
*) NULL
,
200 int width
= wxCHOICE_WIDTH
,
201 int height
= wxCHOICE_HEIGHT
);
203 // Same as above but gets position in list of strings, instead of string,
204 // or -1 if no selection
205 WXDLLEXPORT
int wxGetSingleChoiceIndex(const wxString
& message
,
206 const wxString
& caption
,
207 const wxArrayString
& choices
,
208 wxWindow
*parent
= (wxWindow
*) NULL
,
212 int width
= wxCHOICE_WIDTH
,
213 int height
= wxCHOICE_HEIGHT
);
215 WXDLLEXPORT
int wxGetSingleChoiceIndex(const wxString
& message
,
216 const wxString
& caption
,
217 int n
, const wxString
*choices
,
218 wxWindow
*parent
= (wxWindow
*) NULL
,
222 int width
= wxCHOICE_WIDTH
,
223 int height
= wxCHOICE_HEIGHT
);
225 // Return client data instead or NULL if cancelled
226 WXDLLEXPORT
void* wxGetSingleChoiceData(const wxString
& message
,
227 const wxString
& caption
,
228 const wxArrayString
& choices
,
230 wxWindow
*parent
= (wxWindow
*) NULL
,
231 int x
= -1, int y
= -1,
233 int width
= wxCHOICE_WIDTH
,
234 int height
= wxCHOICE_HEIGHT
);
236 WXDLLEXPORT
void* wxGetSingleChoiceData(const wxString
& message
,
237 const wxString
& caption
,
238 int n
, const wxString
*choices
,
240 wxWindow
*parent
= (wxWindow
*) NULL
,
241 int x
= -1, int y
= -1,
243 int width
= wxCHOICE_WIDTH
,
244 int height
= wxCHOICE_HEIGHT
);
246 // fill the array with the indices of the chosen items, it will be empty
247 // if no items were selected or Cancel was pressed - return the number of
249 WXDLLEXPORT
size_t wxGetMultipleChoices(wxArrayInt
& selections
,
250 const wxString
& message
,
251 const wxString
& caption
,
252 int n
, const wxString
*choices
,
253 wxWindow
*parent
= (wxWindow
*) NULL
,
257 int width
= wxCHOICE_WIDTH
,
258 int height
= wxCHOICE_HEIGHT
);
260 WXDLLEXPORT
size_t wxGetMultipleChoices(wxArrayInt
& selections
,
261 const wxString
& message
,
262 const wxString
& caption
,
263 const wxArrayString
& choices
,
264 wxWindow
*parent
= (wxWindow
*) NULL
,
268 int width
= wxCHOICE_WIDTH
,
269 int height
= wxCHOICE_HEIGHT
);
271 // ----------------------------------------------------------------------------
272 // these methods are for backwards compatibility only, not documented and
274 // ----------------------------------------------------------------------------
276 #if WXWIN_COMPATIBILITY_2
278 WXDLLEXPORT wxString
wxGetSingleChoice(const wxString
& message
,
279 const wxString
& caption
,
280 int n
, wxChar
*choices
[],
281 wxWindow
*parent
= (wxWindow
*) NULL
,
285 int width
= wxCHOICE_WIDTH
,
286 int height
= wxCHOICE_HEIGHT
);
288 WXDLLEXPORT
int wxGetSingleChoiceIndex(const wxString
& message
,
289 const wxString
& caption
,
290 int n
, wxChar
*choices
[],
291 wxWindow
*parent
= (wxWindow
*) NULL
,
295 int width
= wxCHOICE_WIDTH
,
296 int height
= wxCHOICE_HEIGHT
);
298 WXDLLEXPORT
void* wxGetSingleChoiceData(const wxString
& message
,
299 const wxString
& caption
,
300 int n
, wxChar
**choices
,
302 wxWindow
*parent
= (wxWindow
*) NULL
,
303 int x
= -1, int y
= -1,
305 int width
= wxCHOICE_WIDTH
,
306 int height
= wxCHOICE_HEIGHT
);
309 #endif // WXWIN_COMPATIBILITY_2
311 #endif // __CHOICEDLGH_G__