]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/listbox.h
Fix header formatting problem in wxMessageBox() documentation.
[wxWidgets.git] / interface / wx / listbox.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: listbox.h
e54c96f1 3// Purpose: interface of wxListBox
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
526954c5 6// Licence: wxWindows licence
23324ae1
FM
7/////////////////////////////////////////////////////////////////////////////
8
9/**
10 @class wxListBox
7c913512 11
320ab87c
FM
12 A listbox is used to select one or more of a list of strings.
13
14 The strings are displayed in a scrolling box, with the selected string(s)
15 marked in reverse video. A listbox can be single selection (if an item is
16 selected, the previous selection is removed) or multiple selection
23324ae1
FM
17 (clicking an item toggles the item on or off independently of other
18 selections).
7c913512 19
320ab87c
FM
20 List box elements are numbered from zero.
21 Their number may be limited under some platforms.
7c913512 22
320ab87c
FM
23 A listbox callback gets an event @c wxEVT_COMMAND_LISTBOX_SELECTED for
24 single clicks, and @c wxEVT_COMMAND_LISTBOX_DOUBLECLICKED for double clicks.
7c913512 25
23324ae1 26 @beginStyleTable
8c6791e4 27 @style{wxLB_SINGLE}
3051a44a 28 Single-selection list.
8c6791e4 29 @style{wxLB_MULTIPLE}
3051a44a
FM
30 Multiple-selection list: the user can toggle multiple items on and off.
31 This is the same as wxLB_EXTENDED in wxGTK2 port.
8c6791e4 32 @style{wxLB_EXTENDED}
3051a44a
FM
33 Extended-selection list: the user can extend the selection by using
34 @c SHIFT or @c CTRL keys together with the cursor movement keys or
35 the mouse.
8c6791e4 36 @style{wxLB_HSCROLL}
3051a44a 37 Create horizontal scrollbar if contents are too wide (Windows only).
8c6791e4 38 @style{wxLB_ALWAYS_SB}
3051a44a 39 Always show a vertical scrollbar.
8c6791e4 40 @style{wxLB_NEEDED_SB}
3051a44a 41 Only create a vertical scrollbar if needed.
58dcd1ae
VZ
42 @style{wxLB_NO_SB}
43 Don't create vertical scrollbar (wxMSW only).
8c6791e4 44 @style{wxLB_SORT}
3051a44a 45 The listbox contents are sorted in alphabetical order.
23324ae1 46 @endStyleTable
7c913512 47
320ab87c
FM
48 Note that @c wxLB_SINGLE, @c wxLB_MULTIPLE and @c wxLB_EXTENDED styles are
49 mutually exclusive and you can specify at most one of them (single selection
50 is the default). See also @ref overview_windowstyles.
51
3051a44a 52 @beginEventEmissionTable{wxCommandEvent}
8c6791e4 53 @event{EVT_LISTBOX(id, func)}
3a194bda 54 Process a @c wxEVT_COMMAND_LISTBOX_SELECTED event, when an item on the
3051a44a 55 list is selected or the selection changes.
8c6791e4 56 @event{EVT_LISTBOX_DCLICK(id, func)}
3a194bda 57 Process a @c wxEVT_COMMAND_LISTBOX_DOUBLECLICKED event, when the listbox
3051a44a 58 is double-clicked.
23324ae1 59 @endEventTable
7c913512 60
23324ae1
FM
61 @library{wxcore}
62 @category{ctrl}
7e59b885 63 @appearance{listbox.png}
7c913512 64
d23914f8 65 @see wxEditableListBox, wxChoice, wxComboBox, wxListCtrl, wxCommandEvent
23324ae1
FM
66*/
67class wxListBox : public wxControlWithItems
68{
69public:
23324ae1 70 /**
021b6794
RR
71 Default constructor.
72 */
73 wxListBox();
320ab87c 74
021b6794 75 /**
320ab87c 76 Constructor, creating and showing a list box.
3c4f71cc 77
320ab87c
FM
78 @param parent
79 The parent window.
80 @param id
81 The ID of this control. A value of @c wxID_ANY indicates a default value.
82 @param pos
83 The initial position.
dc1b07fd 84 If ::wxDefaultPosition is specified then a default position is chosen.
320ab87c
FM
85 @param size
86 The initial size.
dc1b07fd 87 If ::wxDefaultSize is specified then the window is sized appropriately.
7c913512 88 @param n
4cc4bfaf 89 Number of strings with which to initialise the control.
320ab87c
FM
90 @param choices
91 The strings to use to initialize the control.
7c913512 92 @param style
4cc4bfaf 93 Window style. See wxListBox.
320ab87c
FM
94 @param validator
95 The validator for this control.
96 @param name
97 The name of this class.
1058f652
MB
98
99 @beginWxPerlOnly
100 Not supported by wxPerl.
101 @endWxPerlOnly
23324ae1 102 */
320ab87c 103
7c913512
FM
104 wxListBox(wxWindow* parent, wxWindowID id,
105 const wxPoint& pos = wxDefaultPosition,
106 const wxSize& size = wxDefaultSize,
107 int n = 0,
4cc4bfaf 108 const wxString choices[] = NULL,
7c913512
FM
109 long style = 0,
110 const wxValidator& validator = wxDefaultValidator,
320ab87c
FM
111 const wxString& name = wxListBoxNameStr);
112
021b6794 113 /**
320ab87c 114 Constructor, creating and showing a list box.
021b6794 115
320ab87c
FM
116 See the other wxListBox() constructor; the only difference is that
117 this overload takes a wxArrayString instead of a pointer to an array
118 of wxString.
1058f652
MB
119
120 @beginWxPerlOnly
121 Use an array reference for the @a choices parameter.
122 @endWxPerlOnly
021b6794 123 */
320ab87c 124
7c913512
FM
125 wxListBox(wxWindow* parent, wxWindowID id,
126 const wxPoint& pos,
127 const wxSize& size,
128 const wxArrayString& choices,
129 long style = 0,
130 const wxValidator& validator = wxDefaultValidator,
320ab87c 131 const wxString& name = wxListBoxNameStr);
23324ae1
FM
132
133 /**
134 Destructor, destroying the list box.
135 */
adaaa686 136 virtual ~wxListBox();
23324ae1
FM
137
138 //@{
139 /**
320ab87c
FM
140 Creates the listbox for two-step construction.
141 See wxListBox() for further details.
23324ae1 142 */
57bf907d 143 bool Create(wxWindow *parent, wxWindowID id,
23324ae1
FM
144 const wxPoint& pos = wxDefaultPosition,
145 const wxSize& size = wxDefaultSize,
57bf907d 146 int n = 0, const wxString choices[] = NULL,
23324ae1
FM
147 long style = 0,
148 const wxValidator& validator = wxDefaultValidator,
57bf907d
FM
149 const wxString& name = wxListBoxNameStr);
150 bool Create(wxWindow *parent, wxWindowID id,
7c913512
FM
151 const wxPoint& pos,
152 const wxSize& size,
153 const wxArrayString& choices,
154 long style = 0,
155 const wxValidator& validator = wxDefaultValidator,
57bf907d 156 const wxString& name = wxListBoxNameStr);
23324ae1
FM
157 //@}
158
159 /**
160 Deselects an item in the list box.
3c4f71cc 161
7c913512 162 @param n
4cc4bfaf 163 The zero-based item to deselect.
3c4f71cc 164
23324ae1
FM
165 @remarks This applies to multiple selection listboxes only.
166 */
167 void Deselect(int n);
168
e9321277
RD
169 virtual void SetSelection(int n);
170
171 virtual int GetSelection() const;
172
173 virtual bool SetStringSelection(const wxString& s, bool select);
174 virtual bool SetStringSelection(const wxString& s);
175
23324ae1
FM
176 /**
177 Fill an array of ints with the positions of the currently selected items.
3c4f71cc 178
7c913512 179 @param selections
4cc4bfaf 180 A reference to an wxArrayInt instance that is used to store the result of
320ab87c 181 the query.
3c4f71cc 182
d29a9a8a 183 @return The number of selections.
3c4f71cc 184
23324ae1 185 @remarks Use this with a multiple selection listbox.
3c4f71cc 186
1058f652
MB
187 @beginWxPerlOnly
188 In wxPerl this method takes no parameters and return the
189 selected items as a list.
190 @endWxPerlOnly
191
4cc4bfaf
FM
192 @see wxControlWithItems::GetSelection, wxControlWithItems::GetStringSelection,
193 wxControlWithItems::SetSelection
23324ae1 194 */
adaaa686 195 virtual int GetSelections(wxArrayInt& selections) const;
23324ae1
FM
196
197 /**
320ab87c
FM
198 Returns the item located at @a point, or @c wxNOT_FOUND if there
199 is no item located at @a point.
3c4f71cc 200
1e24c2af 201 It is currently implemented for wxMSW, wxMac and wxGTK2 ports.
3c4f71cc 202
7c913512 203 @param point
4cc4bfaf 204 Point of item (in client coordinates) to obtain
3c4f71cc 205
d29a9a8a 206 @return Item located at point, or wxNOT_FOUND if unimplemented or the
320ab87c 207 item does not exist.
1e24c2af
VS
208
209 @since 2.7.0
23324ae1 210 */
320ab87c 211 int HitTest(const wxPoint& point) const;
d4624460
FM
212
213 /**
214 @overload
215 */
0a03dc7a 216 int HitTest(int x, int y) const;
23324ae1 217
23324ae1
FM
218 /**
219 Insert the given number of strings before the specified position.
3c4f71cc 220
7c913512 221 @param nItems
4cc4bfaf 222 Number of items in the array items
7c913512 223 @param items
4cc4bfaf 224 Labels of items to be inserted
7c913512 225 @param pos
021b6794
RR
226 Position before which to insert the items: if pos is 0 the
227 items will be inserted in the beginning of the listbox
1058f652
MB
228
229 @beginWxPerlOnly
230 Not supported by wxPerl.
231 @endWxPerlOnly
23324ae1 232 */
0a98423e 233 void InsertItems(unsigned int nItems, const wxString *items,
23324ae1 234 unsigned int pos);
021b6794
RR
235
236 /**
237 Insert the given number of strings before the specified position.
238
239 @param items
240 Labels of items to be inserted
241 @param pos
320ab87c 242 Position before which to insert the items: if pos is @c 0 the
021b6794 243 items will be inserted in the beginning of the listbox
1058f652
MB
244
245 @beginWxPerlOnly
246 Use an array reference for the @a items parameter.
247 @endWxPerlOnly
021b6794
RR
248 */
249 void InsertItems(const wxArrayString& items,
7c913512 250 unsigned int pos);
23324ae1
FM
251
252 /**
253 Determines whether an item is selected.
3c4f71cc 254
7c913512 255 @param n
4cc4bfaf 256 The zero-based item index.
3c4f71cc 257
d29a9a8a 258 @return @true if the given item is selected, @false otherwise.
23324ae1 259 */
adaaa686 260 virtual bool IsSelected(int n) const;
23324ae1 261
23324ae1
FM
262 /**
263 Clears the list box and adds the given strings to it.
3c4f71cc 264
7c913512 265 @param n
4cc4bfaf 266 The number of strings to set.
7c913512 267 @param choices
4cc4bfaf 268 An array of strings to set.
7c913512 269 @param clientData
4cc4bfaf 270 Options array of client data pointers
021b6794 271 */
0a98423e 272 void Set(unsigned int n, const wxString* choices, void *clientData);
3c4f71cc 273
021b6794 274 /**
320ab87c
FM
275 Clears the list box and adds the given strings to it.
276 You may free the array from the calling program after this method
021b6794
RR
277 has been called.
278
279 @param choices
280 An array of strings to set.
281 @param clientData
282 Options array of client data pointers
23324ae1 283 */
0a98423e 284 void Set(const wxArrayString& choices, void *clientData);
23324ae1 285
23324ae1
FM
286 /**
287 Set the specified item to be the first visible item.
3c4f71cc 288
7c913512 289 @param n
021b6794
RR
290 The zero-based item index that should be visible.
291 */
292 void SetFirstItem(int n);
293
294 /**
295 Set the specified item to be the first visible item.
296
7c913512 297 @param string
4cc4bfaf 298 The string that should be visible.
23324ae1 299 */
7c913512 300 void SetFirstItem(const wxString& string);
e9321277
RD
301
302 virtual void EnsureVisible(int n);
303
304 virtual bool IsSorted() const;
305
306 // implement base class pure virtuals
307 virtual void Refresh(bool eraseBack = true, const wxRect *rect = NULL);
308
309 virtual unsigned int GetCount() const;
310 virtual wxString GetString(unsigned int n) const;
311 virtual void SetString(unsigned int n, const wxString& s);
312 virtual int FindString(const wxString& s, bool bCase = false) const;
23324ae1 313};
e54c96f1 314