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
);
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
);
112 wxString m_stringSelection
;
115 DECLARE_DYNAMIC_CLASS_NO_COPY(wxSingleChoiceDialog
)
116 DECLARE_EVENT_TABLE()
119 // ----------------------------------------------------------------------------
120 // wxMultiChoiceDialog: a dialog with multi selection listbox
121 // ----------------------------------------------------------------------------
123 class WXDLLEXPORT wxMultiChoiceDialog
: public wxAnyChoiceDialog
126 wxMultiChoiceDialog() { }
128 wxMultiChoiceDialog(wxWindow
*parent
,
129 const wxString
& message
,
130 const wxString
& caption
,
132 const wxString
*choices
,
133 long style
= wxCHOICEDLG_STYLE
,
134 const wxPoint
& pos
= wxDefaultPosition
)
136 (void)Create(parent
, message
, caption
, n
, choices
, style
, pos
);
139 bool Create(wxWindow
*parent
,
140 const wxString
& message
,
141 const wxString
& caption
,
143 const wxString
*choices
,
144 long style
= wxCHOICEDLG_STYLE
,
145 const wxPoint
& pos
= wxDefaultPosition
);
147 void SetSelections(const wxArrayInt
& selections
);
148 wxArrayInt
GetSelections() const { return m_selections
; }
150 // implementation from now on
151 virtual bool TransferDataFromWindow();
154 wxArrayInt m_selections
;
157 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMultiChoiceDialog
)
160 // ----------------------------------------------------------------------------
161 // wrapper functions which can be used to get selection(s) from the user
162 // ----------------------------------------------------------------------------
164 // get the user selection as a string
165 WXDLLEXPORT wxString
wxGetSingleChoice(const wxString
& message
,
166 const wxString
& caption
,
167 const wxArrayString
& choices
,
168 wxWindow
*parent
= (wxWindow
*) NULL
,
172 int width
= wxCHOICE_WIDTH
,
173 int height
= wxCHOICE_HEIGHT
);
175 WXDLLEXPORT wxString
wxGetSingleChoice(const wxString
& message
,
176 const wxString
& caption
,
177 int n
, const wxString
*choices
,
178 wxWindow
*parent
= (wxWindow
*) NULL
,
182 int width
= wxCHOICE_WIDTH
,
183 int height
= wxCHOICE_HEIGHT
);
185 // Same as above but gets position in list of strings, instead of string,
186 // or -1 if no selection
187 WXDLLEXPORT
int wxGetSingleChoiceIndex(const wxString
& message
,
188 const wxString
& caption
,
189 const wxArrayString
& choices
,
190 wxWindow
*parent
= (wxWindow
*) NULL
,
194 int width
= wxCHOICE_WIDTH
,
195 int height
= wxCHOICE_HEIGHT
);
197 WXDLLEXPORT
int wxGetSingleChoiceIndex(const wxString
& message
,
198 const wxString
& caption
,
199 int n
, const wxString
*choices
,
200 wxWindow
*parent
= (wxWindow
*) NULL
,
204 int width
= wxCHOICE_WIDTH
,
205 int height
= wxCHOICE_HEIGHT
);
207 // Return client data instead or NULL if cancelled
208 WXDLLEXPORT
void* wxGetSingleChoiceData(const wxString
& message
,
209 const wxString
& caption
,
210 const wxArrayString
& choices
,
212 wxWindow
*parent
= (wxWindow
*) NULL
,
213 int x
= -1, int y
= -1,
215 int width
= wxCHOICE_WIDTH
,
216 int height
= wxCHOICE_HEIGHT
);
218 WXDLLEXPORT
void* wxGetSingleChoiceData(const wxString
& message
,
219 const wxString
& caption
,
220 int n
, const wxString
*choices
,
222 wxWindow
*parent
= (wxWindow
*) NULL
,
223 int x
= -1, int y
= -1,
225 int width
= wxCHOICE_WIDTH
,
226 int height
= wxCHOICE_HEIGHT
);
228 // fill the array with the indices of the chosen items, it will be empty
229 // if no items were selected or Cancel was pressed - return the number of
231 WXDLLEXPORT
size_t wxGetMultipleChoices(wxArrayInt
& selections
,
232 const wxString
& message
,
233 const wxString
& caption
,
234 int n
, const wxString
*choices
,
235 wxWindow
*parent
= (wxWindow
*) NULL
,
239 int width
= wxCHOICE_WIDTH
,
240 int height
= wxCHOICE_HEIGHT
);
242 WXDLLEXPORT
size_t wxGetMultipleChoices(wxArrayInt
& selections
,
243 const wxString
& message
,
244 const wxString
& caption
,
245 const wxArrayString
& choices
,
246 wxWindow
*parent
= (wxWindow
*) NULL
,
250 int width
= wxCHOICE_WIDTH
,
251 int height
= wxCHOICE_HEIGHT
);
253 #endif // __CHOICEDLGH_G__