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(NO_GCC_PRAGMA)
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
);
54 wxAnyChoiceDialog(wxWindow
*parent
,
55 const wxString
& message
,
56 const wxString
& caption
,
57 const wxArrayString
& choices
,
58 long styleDlg
= wxCHOICEDLG_STYLE
,
59 const wxPoint
& pos
= wxDefaultPosition
,
60 long styleLbox
= wxLB_ALWAYS_SB
)
62 (void)Create(parent
, message
, caption
, choices
,
63 styleDlg
, pos
, styleLbox
);
66 bool Create(wxWindow
*parent
,
67 const wxString
& message
,
68 const wxString
& caption
,
69 int n
, const wxString
*choices
,
70 long styleDlg
= wxCHOICEDLG_STYLE
,
71 const wxPoint
& pos
= wxDefaultPosition
,
72 long styleLbox
= wxLB_ALWAYS_SB
);
73 bool Create(wxWindow
*parent
,
74 const wxString
& message
,
75 const wxString
& caption
,
76 const wxArrayString
& choices
,
77 long styleDlg
= wxCHOICEDLG_STYLE
,
78 const wxPoint
& pos
= wxDefaultPosition
,
79 long styleLbox
= wxLB_ALWAYS_SB
);
84 DECLARE_NO_COPY_CLASS(wxAnyChoiceDialog
)
87 // ----------------------------------------------------------------------------
88 // wxSingleChoiceDialog: a dialog with single selection listbox
89 // ----------------------------------------------------------------------------
91 class WXDLLEXPORT wxSingleChoiceDialog
: public wxAnyChoiceDialog
94 wxSingleChoiceDialog()
99 wxSingleChoiceDialog(wxWindow
*parent
,
100 const wxString
& message
,
101 const wxString
& caption
,
103 const wxString
*choices
,
104 char **clientData
= (char **)NULL
,
105 long style
= wxCHOICEDLG_STYLE
,
106 const wxPoint
& pos
= wxDefaultPosition
);
107 wxSingleChoiceDialog(wxWindow
*parent
,
108 const wxString
& message
,
109 const wxString
& caption
,
110 const wxArrayString
& choices
,
111 char **clientData
= (char **)NULL
,
112 long style
= wxCHOICEDLG_STYLE
,
113 const wxPoint
& pos
= wxDefaultPosition
);
115 bool Create(wxWindow
*parent
,
116 const wxString
& message
,
117 const wxString
& caption
,
119 const wxString
*choices
,
120 char **clientData
= (char **)NULL
,
121 long style
= wxCHOICEDLG_STYLE
,
122 const wxPoint
& pos
= wxDefaultPosition
);
123 bool Create(wxWindow
*parent
,
124 const wxString
& message
,
125 const wxString
& caption
,
126 const wxArrayString
& choices
,
127 char **clientData
= (char **)NULL
,
128 long style
= wxCHOICEDLG_STYLE
,
129 const wxPoint
& pos
= wxDefaultPosition
);
131 void SetSelection(int sel
);
132 int GetSelection() const { return m_selection
; }
133 wxString
GetStringSelection() const { return m_stringSelection
; }
135 // obsolete function (NB: no need to make it return wxChar, it's untyped)
136 char *GetSelectionClientData() const { return (char *)m_clientData
; }
138 // implementation from now on
139 void OnOK(wxCommandEvent
& event
);
140 void OnListBoxDClick(wxCommandEvent
& event
);
144 wxString m_stringSelection
;
147 DECLARE_DYNAMIC_CLASS_NO_COPY(wxSingleChoiceDialog
)
148 DECLARE_EVENT_TABLE()
151 // ----------------------------------------------------------------------------
152 // wxMultiChoiceDialog: a dialog with multi selection listbox
153 // ----------------------------------------------------------------------------
155 class WXDLLEXPORT wxMultiChoiceDialog
: public wxAnyChoiceDialog
158 wxMultiChoiceDialog() { }
160 wxMultiChoiceDialog(wxWindow
*parent
,
161 const wxString
& message
,
162 const wxString
& caption
,
164 const wxString
*choices
,
165 long style
= wxCHOICEDLG_STYLE
,
166 const wxPoint
& pos
= wxDefaultPosition
)
168 (void)Create(parent
, message
, caption
, n
, choices
, style
, pos
);
170 wxMultiChoiceDialog(wxWindow
*parent
,
171 const wxString
& message
,
172 const wxString
& caption
,
173 const wxArrayString
& choices
,
174 long style
= wxCHOICEDLG_STYLE
,
175 const wxPoint
& pos
= wxDefaultPosition
)
177 (void)Create(parent
, message
, caption
, choices
, style
, pos
);
180 bool Create(wxWindow
*parent
,
181 const wxString
& message
,
182 const wxString
& caption
,
184 const wxString
*choices
,
185 long style
= wxCHOICEDLG_STYLE
,
186 const wxPoint
& pos
= wxDefaultPosition
);
187 bool Create(wxWindow
*parent
,
188 const wxString
& message
,
189 const wxString
& caption
,
190 const wxArrayString
& choices
,
191 long style
= wxCHOICEDLG_STYLE
,
192 const wxPoint
& pos
= wxDefaultPosition
);
194 void SetSelections(const wxArrayInt
& selections
);
195 wxArrayInt
GetSelections() const { return m_selections
; }
197 // implementation from now on
198 virtual bool TransferDataFromWindow();
201 wxArrayInt m_selections
;
204 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMultiChoiceDialog
)
207 // ----------------------------------------------------------------------------
208 // wrapper functions which can be used to get selection(s) from the user
209 // ----------------------------------------------------------------------------
211 // get the user selection as a string
212 WXDLLEXPORT wxString
wxGetSingleChoice(const wxString
& message
,
213 const wxString
& caption
,
214 const wxArrayString
& choices
,
215 wxWindow
*parent
= (wxWindow
*) NULL
,
219 int width
= wxCHOICE_WIDTH
,
220 int height
= wxCHOICE_HEIGHT
);
222 WXDLLEXPORT wxString
wxGetSingleChoice(const wxString
& message
,
223 const wxString
& caption
,
224 int n
, const wxString
*choices
,
225 wxWindow
*parent
= (wxWindow
*) NULL
,
229 int width
= wxCHOICE_WIDTH
,
230 int height
= wxCHOICE_HEIGHT
);
232 // Same as above but gets position in list of strings, instead of string,
233 // or -1 if no selection
234 WXDLLEXPORT
int wxGetSingleChoiceIndex(const wxString
& message
,
235 const wxString
& caption
,
236 const wxArrayString
& choices
,
237 wxWindow
*parent
= (wxWindow
*) NULL
,
241 int width
= wxCHOICE_WIDTH
,
242 int height
= wxCHOICE_HEIGHT
);
244 WXDLLEXPORT
int wxGetSingleChoiceIndex(const wxString
& message
,
245 const wxString
& caption
,
246 int n
, const wxString
*choices
,
247 wxWindow
*parent
= (wxWindow
*) NULL
,
251 int width
= wxCHOICE_WIDTH
,
252 int height
= wxCHOICE_HEIGHT
);
254 // Return client data instead or NULL if cancelled
255 WXDLLEXPORT
void* wxGetSingleChoiceData(const wxString
& message
,
256 const wxString
& caption
,
257 const wxArrayString
& choices
,
259 wxWindow
*parent
= (wxWindow
*) NULL
,
260 int x
= -1, int y
= -1,
262 int width
= wxCHOICE_WIDTH
,
263 int height
= wxCHOICE_HEIGHT
);
265 WXDLLEXPORT
void* wxGetSingleChoiceData(const wxString
& message
,
266 const wxString
& caption
,
267 int n
, const wxString
*choices
,
269 wxWindow
*parent
= (wxWindow
*) NULL
,
270 int x
= -1, int y
= -1,
272 int width
= wxCHOICE_WIDTH
,
273 int height
= wxCHOICE_HEIGHT
);
275 // fill the array with the indices of the chosen items, it will be empty
276 // if no items were selected or Cancel was pressed - return the number of
278 WXDLLEXPORT
size_t wxGetMultipleChoices(wxArrayInt
& selections
,
279 const wxString
& message
,
280 const wxString
& caption
,
281 int n
, const wxString
*choices
,
282 wxWindow
*parent
= (wxWindow
*) NULL
,
286 int width
= wxCHOICE_WIDTH
,
287 int height
= wxCHOICE_HEIGHT
);
289 WXDLLEXPORT
size_t wxGetMultipleChoices(wxArrayInt
& selections
,
290 const wxString
& message
,
291 const wxString
& caption
,
292 const wxArrayString
& choices
,
293 wxWindow
*parent
= (wxWindow
*) NULL
,
297 int width
= wxCHOICE_WIDTH
,
298 int height
= wxCHOICE_HEIGHT
);
300 #endif // __CHOICEDLGH_G__