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 \
32 (wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxOK | wxCANCEL | wxCENTRE)
34 // ----------------------------------------------------------------------------
35 // wxAnyChoiceDialog: a base class for dialogs containing a listbox
36 // ----------------------------------------------------------------------------
38 class WXDLLEXPORT wxAnyChoiceDialog
: public wxDialog
41 wxAnyChoiceDialog() { }
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
)
51 (void)Create(parent
, message
, caption
, n
, choices
,
52 styleDlg
, pos
, styleLbox
);
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
);
66 DECLARE_NO_COPY_CLASS(wxAnyChoiceDialog
)
69 // ----------------------------------------------------------------------------
70 // wxSingleChoiceDialog: a dialog with single selection listbox
71 // ----------------------------------------------------------------------------
73 class WXDLLEXPORT wxSingleChoiceDialog
: public wxAnyChoiceDialog
76 wxSingleChoiceDialog()
81 wxSingleChoiceDialog(wxWindow
*parent
,
82 const wxString
& message
,
83 const wxString
& caption
,
85 const wxString
*choices
,
86 char **clientData
= (char **)NULL
,
87 long style
= wxCHOICEDLG_STYLE
,
88 const wxPoint
& pos
= wxDefaultPosition
);
90 bool Create(wxWindow
*parent
,
91 const wxString
& message
,
92 const wxString
& caption
,
94 const wxString
*choices
,
95 char **clientData
= (char **)NULL
,
96 long style
= wxCHOICEDLG_STYLE
,
97 const wxPoint
& pos
= wxDefaultPosition
);
99 void SetSelection(int sel
);
100 int GetSelection() const { return m_selection
; }
101 wxString
GetStringSelection() const { return m_stringSelection
; }
103 // obsolete function (NB: no need to make it return wxChar, it's untyped)
104 char *GetSelectionClientData() const { return (char *)m_clientData
; }
106 // implementation from now on
107 void OnOK(wxCommandEvent
& event
);
108 void OnListBoxDClick(wxCommandEvent
& event
);
110 // old, deprecated methods
111 #if WXWIN_COMPATIBILITY_2
112 wxSingleChoiceDialog(wxWindow
*parent
,
113 const wxString
& message
,
114 const wxString
& caption
,
115 const wxStringList
& choices
,
116 char **clientData
= (char **)NULL
,
117 long style
= wxCHOICEDLG_STYLE
,
118 const wxPoint
& pos
= wxDefaultPosition
);
120 bool Create(wxWindow
*parent
,
121 const wxString
& message
,
122 const wxString
& caption
,
123 const wxStringList
& choices
,
124 char **clientData
= (char **)NULL
,
125 long style
= wxCHOICEDLG_STYLE
,
126 const wxPoint
& pos
= wxDefaultPosition
);
127 #endif // WXWIN_COMPATIBILITY_2
131 wxString m_stringSelection
;
134 DECLARE_DYNAMIC_CLASS(wxSingleChoiceDialog
)
135 DECLARE_EVENT_TABLE()
138 // ----------------------------------------------------------------------------
139 // wxMultiChoiceDialog: a dialog with multi selection listbox
140 // ----------------------------------------------------------------------------
142 class WXDLLEXPORT wxMultiChoiceDialog
: public wxAnyChoiceDialog
145 wxMultiChoiceDialog() { }
147 wxMultiChoiceDialog(wxWindow
*parent
,
148 const wxString
& message
,
149 const wxString
& caption
,
151 const wxString
*choices
,
152 long style
= wxCHOICEDLG_STYLE
,
153 const wxPoint
& pos
= wxDefaultPosition
)
155 (void)Create(parent
, message
, caption
, n
, choices
, style
, pos
);
158 bool Create(wxWindow
*parent
,
159 const wxString
& message
,
160 const wxString
& caption
,
162 const wxString
*choices
,
163 long style
= wxCHOICEDLG_STYLE
,
164 const wxPoint
& pos
= wxDefaultPosition
);
166 void SetSelections(const wxArrayInt
& selections
);
167 wxArrayInt
GetSelections() const { return m_selections
; }
169 // implementation from now on
170 virtual bool TransferDataFromWindow();
173 wxArrayInt m_selections
;
176 DECLARE_DYNAMIC_CLASS(wxMultiChoiceDialog
)
179 // ----------------------------------------------------------------------------
180 // wrapper functions which can be used to get selection(s) from the user
181 // ----------------------------------------------------------------------------
183 // get the user selection as a string
184 WXDLLEXPORT wxString
wxGetSingleChoice(const wxString
& message
,
185 const wxString
& caption
,
186 const wxArrayString
& choices
,
187 wxWindow
*parent
= (wxWindow
*) NULL
,
191 int width
= wxCHOICE_WIDTH
,
192 int height
= wxCHOICE_HEIGHT
);
194 WXDLLEXPORT wxString
wxGetSingleChoice(const wxString
& message
,
195 const wxString
& caption
,
196 int n
, const wxString
*choices
,
197 wxWindow
*parent
= (wxWindow
*) NULL
,
201 int width
= wxCHOICE_WIDTH
,
202 int height
= wxCHOICE_HEIGHT
);
204 // Same as above but gets position in list of strings, instead of string,
205 // or -1 if no selection
206 WXDLLEXPORT
int wxGetSingleChoiceIndex(const wxString
& message
,
207 const wxString
& caption
,
208 const wxArrayString
& choices
,
209 wxWindow
*parent
= (wxWindow
*) NULL
,
213 int width
= wxCHOICE_WIDTH
,
214 int height
= wxCHOICE_HEIGHT
);
216 WXDLLEXPORT
int wxGetSingleChoiceIndex(const wxString
& message
,
217 const wxString
& caption
,
218 int n
, const wxString
*choices
,
219 wxWindow
*parent
= (wxWindow
*) NULL
,
223 int width
= wxCHOICE_WIDTH
,
224 int height
= wxCHOICE_HEIGHT
);
226 // Return client data instead or NULL if cancelled
227 WXDLLEXPORT
void* wxGetSingleChoiceData(const wxString
& message
,
228 const wxString
& caption
,
229 const wxArrayString
& choices
,
231 wxWindow
*parent
= (wxWindow
*) NULL
,
232 int x
= -1, int y
= -1,
234 int width
= wxCHOICE_WIDTH
,
235 int height
= wxCHOICE_HEIGHT
);
237 WXDLLEXPORT
void* wxGetSingleChoiceData(const wxString
& message
,
238 const wxString
& caption
,
239 int n
, const wxString
*choices
,
241 wxWindow
*parent
= (wxWindow
*) NULL
,
242 int x
= -1, int y
= -1,
244 int width
= wxCHOICE_WIDTH
,
245 int height
= wxCHOICE_HEIGHT
);
247 // fill the array with the indices of the chosen items, it will be empty
248 // if no items were selected or Cancel was pressed - return the number of
250 WXDLLEXPORT
size_t wxGetMultipleChoices(wxArrayInt
& selections
,
251 const wxString
& message
,
252 const wxString
& caption
,
253 int n
, const wxString
*choices
,
254 wxWindow
*parent
= (wxWindow
*) NULL
,
258 int width
= wxCHOICE_WIDTH
,
259 int height
= wxCHOICE_HEIGHT
);
261 WXDLLEXPORT
size_t wxGetMultipleChoices(wxArrayInt
& selections
,
262 const wxString
& message
,
263 const wxString
& caption
,
264 const wxArrayString
& choices
,
265 wxWindow
*parent
= (wxWindow
*) NULL
,
269 int width
= wxCHOICE_WIDTH
,
270 int height
= wxCHOICE_HEIGHT
);
272 // ----------------------------------------------------------------------------
273 // these methods are for backwards compatibility only, not documented and
275 // ----------------------------------------------------------------------------
277 #if WXWIN_COMPATIBILITY_2
279 WXDLLEXPORT wxString
wxGetSingleChoice(const wxString
& message
,
280 const wxString
& caption
,
281 int n
, wxChar
*choices
[],
282 wxWindow
*parent
= (wxWindow
*) NULL
,
286 int width
= wxCHOICE_WIDTH
,
287 int height
= wxCHOICE_HEIGHT
);
289 WXDLLEXPORT
int wxGetSingleChoiceIndex(const wxString
& message
,
290 const wxString
& caption
,
291 int n
, wxChar
*choices
[],
292 wxWindow
*parent
= (wxWindow
*) NULL
,
296 int width
= wxCHOICE_WIDTH
,
297 int height
= wxCHOICE_HEIGHT
);
299 WXDLLEXPORT
void* wxGetSingleChoiceData(const wxString
& message
,
300 const wxString
& caption
,
301 int n
, wxChar
**choices
,
303 wxWindow
*parent
= (wxWindow
*) NULL
,
304 int x
= -1, int y
= -1,
306 int width
= wxCHOICE_WIDTH
,
307 int height
= wxCHOICE_HEIGHT
);
310 #endif // WXWIN_COMPATIBILITY_2
312 #endif // __CHOICEDLGH_G__