]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/listbox.h
Applied patch #15286: documentation and col/rowspan demo by dghart
[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)}
ce7fe42e 61 Process a @c wxEVT_LISTBOX event, when an item on the
3051a44a 62 list is selected or the selection changes.
8c6791e4 63 @event{EVT_LISTBOX_DCLICK(id, func)}
ce7fe42e 64 Process a @c wxEVT_LISTBOX_DCLICK event, when the listbox
3051a44a 65 is double-clicked.
23324ae1 66 @endEventTable
7c913512 67
23324ae1
FM
68 @library{wxcore}
69 @category{ctrl}
ce154616 70 @appearance{listbox}
7c913512 71
d23914f8 72 @see wxEditableListBox, wxChoice, wxComboBox, wxListCtrl, wxCommandEvent
23324ae1 73*/
3bb9348f
VZ
74class wxListBox : public wxControl,
75 public wxItemContainer
23324ae1
FM
76{
77public:
23324ae1 78 /**
021b6794
RR
79 Default constructor.
80 */
81 wxListBox();
320ab87c 82
021b6794 83 /**
320ab87c 84 Constructor, creating and showing a list box.
3c4f71cc 85
320ab87c
FM
86 @param parent
87 The parent window.
88 @param id
89 The ID of this control. A value of @c wxID_ANY indicates a default value.
90 @param pos
91 The initial position.
dc1b07fd 92 If ::wxDefaultPosition is specified then a default position is chosen.
320ab87c
FM
93 @param size
94 The initial size.
dc1b07fd 95 If ::wxDefaultSize is specified then the window is sized appropriately.
7c913512 96 @param n
4cc4bfaf 97 Number of strings with which to initialise the control.
320ab87c
FM
98 @param choices
99 The strings to use to initialize the control.
7c913512 100 @param style
4cc4bfaf 101 Window style. See wxListBox.
320ab87c
FM
102 @param validator
103 The validator for this control.
104 @param name
105 The name of this class.
1058f652
MB
106
107 @beginWxPerlOnly
108 Not supported by wxPerl.
109 @endWxPerlOnly
23324ae1 110 */
320ab87c 111
7c913512
FM
112 wxListBox(wxWindow* parent, wxWindowID id,
113 const wxPoint& pos = wxDefaultPosition,
114 const wxSize& size = wxDefaultSize,
115 int n = 0,
4cc4bfaf 116 const wxString choices[] = NULL,
7c913512
FM
117 long style = 0,
118 const wxValidator& validator = wxDefaultValidator,
320ab87c
FM
119 const wxString& name = wxListBoxNameStr);
120
021b6794 121 /**
320ab87c 122 Constructor, creating and showing a list box.
021b6794 123
320ab87c
FM
124 See the other wxListBox() constructor; the only difference is that
125 this overload takes a wxArrayString instead of a pointer to an array
126 of wxString.
1058f652
MB
127
128 @beginWxPerlOnly
129 Use an array reference for the @a choices parameter.
130 @endWxPerlOnly
021b6794 131 */
320ab87c 132
7c913512
FM
133 wxListBox(wxWindow* parent, wxWindowID id,
134 const wxPoint& pos,
135 const wxSize& size,
136 const wxArrayString& choices,
137 long style = 0,
138 const wxValidator& validator = wxDefaultValidator,
320ab87c 139 const wxString& name = wxListBoxNameStr);
23324ae1
FM
140
141 /**
142 Destructor, destroying the list box.
143 */
adaaa686 144 virtual ~wxListBox();
23324ae1
FM
145
146 //@{
147 /**
320ab87c
FM
148 Creates the listbox for two-step construction.
149 See wxListBox() for further details.
23324ae1 150 */
57bf907d 151 bool Create(wxWindow *parent, wxWindowID id,
23324ae1
FM
152 const wxPoint& pos = wxDefaultPosition,
153 const wxSize& size = wxDefaultSize,
57bf907d 154 int n = 0, const wxString choices[] = NULL,
23324ae1
FM
155 long style = 0,
156 const wxValidator& validator = wxDefaultValidator,
57bf907d
FM
157 const wxString& name = wxListBoxNameStr);
158 bool Create(wxWindow *parent, wxWindowID id,
7c913512
FM
159 const wxPoint& pos,
160 const wxSize& size,
161 const wxArrayString& choices,
162 long style = 0,
163 const wxValidator& validator = wxDefaultValidator,
57bf907d 164 const wxString& name = wxListBoxNameStr);
23324ae1
FM
165 //@}
166
167 /**
168 Deselects an item in the list box.
3c4f71cc 169
7c913512 170 @param n
4cc4bfaf 171 The zero-based item to deselect.
3c4f71cc 172
23324ae1
FM
173 @remarks This applies to multiple selection listboxes only.
174 */
175 void Deselect(int n);
176
e9321277
RD
177 virtual void SetSelection(int n);
178
179 virtual int GetSelection() const;
180
181 virtual bool SetStringSelection(const wxString& s, bool select);
182 virtual bool SetStringSelection(const wxString& s);
183
23324ae1
FM
184 /**
185 Fill an array of ints with the positions of the currently selected items.
3c4f71cc 186
7c913512 187 @param selections
4cc4bfaf 188 A reference to an wxArrayInt instance that is used to store the result of
320ab87c 189 the query.
3c4f71cc 190
d29a9a8a 191 @return The number of selections.
3c4f71cc 192
23324ae1 193 @remarks Use this with a multiple selection listbox.
3c4f71cc 194
1058f652
MB
195 @beginWxPerlOnly
196 In wxPerl this method takes no parameters and return the
197 selected items as a list.
198 @endWxPerlOnly
199
4cc4bfaf
FM
200 @see wxControlWithItems::GetSelection, wxControlWithItems::GetStringSelection,
201 wxControlWithItems::SetSelection
23324ae1 202 */
adaaa686 203 virtual int GetSelections(wxArrayInt& selections) const;
23324ae1
FM
204
205 /**
320ab87c
FM
206 Returns the item located at @a point, or @c wxNOT_FOUND if there
207 is no item located at @a point.
3c4f71cc 208
1e24c2af 209 It is currently implemented for wxMSW, wxMac and wxGTK2 ports.
3c4f71cc 210
7c913512 211 @param point
4cc4bfaf 212 Point of item (in client coordinates) to obtain
3c4f71cc 213
d29a9a8a 214 @return Item located at point, or wxNOT_FOUND if unimplemented or the
320ab87c 215 item does not exist.
1e24c2af
VS
216
217 @since 2.7.0
23324ae1 218 */
320ab87c 219 int HitTest(const wxPoint& point) const;
d4624460
FM
220
221 /**
222 @overload
223 */
0a03dc7a 224 int HitTest(int x, int y) const;
23324ae1 225
23324ae1
FM
226 /**
227 Insert the given number of strings before the specified position.
3c4f71cc 228
7c913512 229 @param nItems
4cc4bfaf 230 Number of items in the array items
7c913512 231 @param items
4cc4bfaf 232 Labels of items to be inserted
7c913512 233 @param pos
021b6794
RR
234 Position before which to insert the items: if pos is 0 the
235 items will be inserted in the beginning of the listbox
1058f652
MB
236
237 @beginWxPerlOnly
238 Not supported by wxPerl.
239 @endWxPerlOnly
23324ae1 240 */
0a98423e 241 void InsertItems(unsigned int nItems, const wxString *items,
23324ae1 242 unsigned int pos);
021b6794
RR
243
244 /**
245 Insert the given number of strings before the specified position.
246
247 @param items
248 Labels of items to be inserted
249 @param pos
320ab87c 250 Position before which to insert the items: if pos is @c 0 the
021b6794 251 items will be inserted in the beginning of the listbox
1058f652
MB
252
253 @beginWxPerlOnly
254 Use an array reference for the @a items parameter.
255 @endWxPerlOnly
021b6794
RR
256 */
257 void InsertItems(const wxArrayString& items,
7c913512 258 unsigned int pos);
23324ae1
FM
259
260 /**
261 Determines whether an item is selected.
3c4f71cc 262
7c913512 263 @param n
4cc4bfaf 264 The zero-based item index.
3c4f71cc 265
d29a9a8a 266 @return @true if the given item is selected, @false otherwise.
23324ae1 267 */
adaaa686 268 virtual bool IsSelected(int n) const;
23324ae1 269
23324ae1
FM
270 /**
271 Set the specified item to be the first visible item.
3c4f71cc 272
7c913512 273 @param n
021b6794
RR
274 The zero-based item index that should be visible.
275 */
276 void SetFirstItem(int n);
277
278 /**
279 Set the specified item to be the first visible item.
280
7c913512 281 @param string
4cc4bfaf 282 The string that should be visible.
23324ae1 283 */
7c913512 284 void SetFirstItem(const wxString& string);
659334e1
VZ
285
286 /**
287 Ensure that the item with the given index is currently shown.
288
289 Scroll the listbox if necessary.
290
291 This method is currently only implemented in wxGTK and wxOSX and does
292 nothing in other ports.
293
294 @see SetFirstItem()
295 */
e9321277 296 virtual void EnsureVisible(int n);
659334e1
VZ
297
298 /**
299 Return true if the listbox has ::wxLB_SORT style.
300
301 This method is mostly meant for internal use only.
302 */
e9321277 303 virtual bool IsSorted() const;
f115bfec
RD
304
305
306 // NOTE: Phoenix needs to see the implementation of pure virtuals so it
307 // knows that this class is not abstract.
308 virtual unsigned int GetCount() const;
309 virtual wxString GetString(unsigned int n) const;
310 virtual void SetString(unsigned int n, const wxString& s);
311 virtual int FindString(const wxString& s, bool bCase = false) const;
23324ae1 312};
e54c96f1 313