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