]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/listbox.h
undo the last change as it results in buildbot configuration error
[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$
6// Licence: wxWindows license
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.
8c6791e4 42 @style{wxLB_SORT}
3051a44a 43 The listbox contents are sorted in alphabetical order.
23324ae1 44 @endStyleTable
7c913512 45
320ab87c
FM
46 Note that @c wxLB_SINGLE, @c wxLB_MULTIPLE and @c wxLB_EXTENDED styles are
47 mutually exclusive and you can specify at most one of them (single selection
48 is the default). See also @ref overview_windowstyles.
49
3051a44a 50 @beginEventEmissionTable{wxCommandEvent}
8c6791e4 51 @event{EVT_LISTBOX(id, func)}
3051a44a
FM
52 Process a wxEVT_COMMAND_LISTBOX_SELECTED event, when an item on the
53 list is selected or the selection changes.
8c6791e4 54 @event{EVT_LISTBOX_DCLICK(id, func)}
3051a44a
FM
55 Process a wxEVT_COMMAND_LISTBOXDOUBLECLICKED event, when the listbox
56 is double-clicked.
23324ae1 57 @endEventTable
7c913512 58
23324ae1
FM
59 @library{wxcore}
60 @category{ctrl}
7e59b885 61 @appearance{listbox.png}
7c913512 62
d23914f8 63 @see wxEditableListBox, wxChoice, wxComboBox, wxListCtrl, wxCommandEvent
23324ae1
FM
64*/
65class wxListBox : public wxControlWithItems
66{
67public:
23324ae1 68 /**
021b6794
RR
69 Default constructor.
70 */
71 wxListBox();
320ab87c 72
021b6794 73 /**
320ab87c 74 Constructor, creating and showing a list box.
3c4f71cc 75
320ab87c
FM
76 @param parent
77 The parent window.
78 @param id
79 The ID of this control. A value of @c wxID_ANY indicates a default value.
80 @param pos
81 The initial position.
dc1b07fd 82 If ::wxDefaultPosition is specified then a default position is chosen.
320ab87c
FM
83 @param size
84 The initial size.
dc1b07fd 85 If ::wxDefaultSize is specified then the window is sized appropriately.
7c913512 86 @param n
4cc4bfaf 87 Number of strings with which to initialise the control.
320ab87c
FM
88 @param choices
89 The strings to use to initialize the control.
7c913512 90 @param style
4cc4bfaf 91 Window style. See wxListBox.
320ab87c
FM
92 @param validator
93 The validator for this control.
94 @param name
95 The name of this class.
23324ae1 96 */
320ab87c 97
7c913512
FM
98 wxListBox(wxWindow* parent, wxWindowID id,
99 const wxPoint& pos = wxDefaultPosition,
100 const wxSize& size = wxDefaultSize,
101 int n = 0,
4cc4bfaf 102 const wxString choices[] = NULL,
7c913512
FM
103 long style = 0,
104 const wxValidator& validator = wxDefaultValidator,
320ab87c
FM
105 const wxString& name = wxListBoxNameStr);
106
021b6794 107 /**
320ab87c 108 Constructor, creating and showing a list box.
021b6794 109
320ab87c
FM
110 See the other wxListBox() constructor; the only difference is that
111 this overload takes a wxArrayString instead of a pointer to an array
112 of wxString.
021b6794 113 */
320ab87c 114
7c913512
FM
115 wxListBox(wxWindow* parent, wxWindowID id,
116 const wxPoint& pos,
117 const wxSize& size,
118 const wxArrayString& choices,
119 long style = 0,
120 const wxValidator& validator = wxDefaultValidator,
320ab87c 121 const wxString& name = wxListBoxNameStr);
23324ae1
FM
122
123 /**
124 Destructor, destroying the list box.
125 */
adaaa686 126 virtual ~wxListBox();
23324ae1
FM
127
128 //@{
129 /**
320ab87c
FM
130 Creates the listbox for two-step construction.
131 See wxListBox() for further details.
23324ae1 132 */
57bf907d 133 bool Create(wxWindow *parent, wxWindowID id,
23324ae1
FM
134 const wxPoint& pos = wxDefaultPosition,
135 const wxSize& size = wxDefaultSize,
57bf907d 136 int n = 0, const wxString choices[] = NULL,
23324ae1
FM
137 long style = 0,
138 const wxValidator& validator = wxDefaultValidator,
57bf907d
FM
139 const wxString& name = wxListBoxNameStr);
140 bool Create(wxWindow *parent, wxWindowID id,
7c913512
FM
141 const wxPoint& pos,
142 const wxSize& size,
143 const wxArrayString& choices,
144 long style = 0,
145 const wxValidator& validator = wxDefaultValidator,
57bf907d 146 const wxString& name = wxListBoxNameStr);
23324ae1
FM
147 //@}
148
149 /**
150 Deselects an item in the list box.
3c4f71cc 151
7c913512 152 @param n
4cc4bfaf 153 The zero-based item to deselect.
3c4f71cc 154
23324ae1
FM
155 @remarks This applies to multiple selection listboxes only.
156 */
157 void Deselect(int n);
158
159 /**
160 Fill an array of ints with the positions of the currently selected items.
3c4f71cc 161
7c913512 162 @param selections
4cc4bfaf 163 A reference to an wxArrayInt instance that is used to store the result of
320ab87c 164 the query.
3c4f71cc 165
d29a9a8a 166 @return The number of selections.
3c4f71cc 167
23324ae1 168 @remarks Use this with a multiple selection listbox.
3c4f71cc 169
4cc4bfaf
FM
170 @see wxControlWithItems::GetSelection, wxControlWithItems::GetStringSelection,
171 wxControlWithItems::SetSelection
23324ae1 172 */
adaaa686 173 virtual int GetSelections(wxArrayInt& selections) const;
23324ae1
FM
174
175 /**
320ab87c
FM
176 Returns the item located at @a point, or @c wxNOT_FOUND if there
177 is no item located at @a point.
3c4f71cc 178
1e24c2af 179 It is currently implemented for wxMSW, wxMac and wxGTK2 ports.
3c4f71cc 180
7c913512 181 @param point
4cc4bfaf 182 Point of item (in client coordinates) to obtain
3c4f71cc 183
d29a9a8a 184 @return Item located at point, or wxNOT_FOUND if unimplemented or the
320ab87c 185 item does not exist.
1e24c2af
VS
186
187 @since 2.7.0
23324ae1 188 */
320ab87c 189 int HitTest(const wxPoint& point) const;
d4624460
FM
190
191 /**
192 @overload
193 */
0a03dc7a 194 int HitTest(int x, int y) const;
23324ae1 195
23324ae1
FM
196 /**
197 Insert the given number of strings before the specified position.
3c4f71cc 198
7c913512 199 @param nItems
4cc4bfaf 200 Number of items in the array items
7c913512 201 @param items
4cc4bfaf 202 Labels of items to be inserted
7c913512 203 @param pos
021b6794
RR
204 Position before which to insert the items: if pos is 0 the
205 items will be inserted in the beginning of the listbox
23324ae1 206 */
0a98423e 207 void InsertItems(unsigned int nItems, const wxString *items,
23324ae1 208 unsigned int pos);
021b6794
RR
209
210 /**
211 Insert the given number of strings before the specified position.
212
213 @param items
214 Labels of items to be inserted
215 @param pos
320ab87c 216 Position before which to insert the items: if pos is @c 0 the
021b6794
RR
217 items will be inserted in the beginning of the listbox
218 */
219 void InsertItems(const wxArrayString& items,
7c913512 220 unsigned int pos);
23324ae1
FM
221
222 /**
223 Determines whether an item is selected.
3c4f71cc 224
7c913512 225 @param n
4cc4bfaf 226 The zero-based item index.
3c4f71cc 227
d29a9a8a 228 @return @true if the given item is selected, @false otherwise.
23324ae1 229 */
adaaa686 230 virtual bool IsSelected(int n) const;
23324ae1 231
23324ae1
FM
232 /**
233 Clears the list box and adds the given strings to it.
3c4f71cc 234
7c913512 235 @param n
4cc4bfaf 236 The number of strings to set.
7c913512 237 @param choices
4cc4bfaf 238 An array of strings to set.
7c913512 239 @param clientData
4cc4bfaf 240 Options array of client data pointers
021b6794 241 */
0a98423e 242 void Set(unsigned int n, const wxString* choices, void *clientData);
3c4f71cc 243
021b6794 244 /**
320ab87c
FM
245 Clears the list box and adds the given strings to it.
246 You may free the array from the calling program after this method
021b6794
RR
247 has been called.
248
249 @param choices
250 An array of strings to set.
251 @param clientData
252 Options array of client data pointers
23324ae1 253 */
0a98423e 254 void Set(const wxArrayString& choices, void *clientData);
23324ae1 255
23324ae1
FM
256 /**
257 Set the specified item to be the first visible item.
3c4f71cc 258
7c913512 259 @param n
021b6794
RR
260 The zero-based item index that should be visible.
261 */
262 void SetFirstItem(int n);
263
264 /**
265 Set the specified item to be the first visible item.
266
7c913512 267 @param string
4cc4bfaf 268 The string that should be visible.
23324ae1 269 */
7c913512 270 void SetFirstItem(const wxString& string);
23324ae1 271};
e54c96f1 272