1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxListBox
4 // Author: wxWidgets team
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
12 A listbox is used to select one or more of a list of strings.
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
17 (clicking an item toggles the item on or off independently of other
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
31 Single-selection list.
33 Multiple-selection list: the user can toggle multiple items on and off.
34 This is the same as wxLB_EXTENDED in wxGTK2 port.
36 Extended-selection list: the user can extend the selection by using
37 @c SHIFT or @c CTRL keys together with the cursor movement keys or
40 Create horizontal scrollbar if contents are too wide (Windows only).
41 @style{wxLB_ALWAYS_SB}
42 Always show a vertical scrollbar.
43 @style{wxLB_NEEDED_SB}
44 Only create a vertical scrollbar if needed.
46 Don't create vertical scrollbar (wxMSW only).
48 The listbox contents are sorted in alphabetical order.
51 Note that @c wxLB_SINGLE, @c wxLB_MULTIPLE and @c wxLB_EXTENDED styles are
52 mutually exclusive and you can specify at most one of them (single selection
53 is the default). See also @ref overview_windowstyles.
55 @beginEventEmissionTable{wxCommandEvent}
56 @event{EVT_LISTBOX(id, func)}
57 Process a @c wxEVT_COMMAND_LISTBOX_SELECTED event, when an item on the
58 list is selected or the selection changes.
59 @event{EVT_LISTBOX_DCLICK(id, func)}
60 Process a @c wxEVT_COMMAND_LISTBOX_DOUBLECLICKED event, when the listbox
66 @appearance{listbox.png}
68 @see wxEditableListBox, wxChoice, wxComboBox, wxListCtrl, wxCommandEvent
70 class wxListBox
: public wxControlWithItems
79 Constructor, creating and showing a list box.
84 The ID of this control. A value of @c wxID_ANY indicates a default value.
87 If ::wxDefaultPosition is specified then a default position is chosen.
90 If ::wxDefaultSize is specified then the window is sized appropriately.
92 Number of strings with which to initialise the control.
94 The strings to use to initialize the control.
96 Window style. See wxListBox.
98 The validator for this control.
100 The name of this class.
103 Not supported by wxPerl.
107 wxListBox(wxWindow
* parent
, wxWindowID id
,
108 const wxPoint
& pos
= wxDefaultPosition
,
109 const wxSize
& size
= wxDefaultSize
,
111 const wxString choices
[] = NULL
,
113 const wxValidator
& validator
= wxDefaultValidator
,
114 const wxString
& name
= wxListBoxNameStr
);
117 Constructor, creating and showing a list box.
119 See the other wxListBox() constructor; the only difference is that
120 this overload takes a wxArrayString instead of a pointer to an array
124 Use an array reference for the @a choices parameter.
128 wxListBox(wxWindow
* parent
, wxWindowID id
,
131 const wxArrayString
& choices
,
133 const wxValidator
& validator
= wxDefaultValidator
,
134 const wxString
& name
= wxListBoxNameStr
);
137 Destructor, destroying the list box.
139 virtual ~wxListBox();
143 Creates the listbox for two-step construction.
144 See wxListBox() for further details.
146 bool Create(wxWindow
*parent
, wxWindowID id
,
147 const wxPoint
& pos
= wxDefaultPosition
,
148 const wxSize
& size
= wxDefaultSize
,
149 int n
= 0, const wxString choices
[] = NULL
,
151 const wxValidator
& validator
= wxDefaultValidator
,
152 const wxString
& name
= wxListBoxNameStr
);
153 bool Create(wxWindow
*parent
, wxWindowID id
,
156 const wxArrayString
& choices
,
158 const wxValidator
& validator
= wxDefaultValidator
,
159 const wxString
& name
= wxListBoxNameStr
);
163 Deselects an item in the list box.
166 The zero-based item to deselect.
168 @remarks This applies to multiple selection listboxes only.
170 void Deselect(int n
);
172 virtual void SetSelection(int n
);
174 virtual int GetSelection() const;
176 virtual bool SetStringSelection(const wxString
& s
, bool select
);
177 virtual bool SetStringSelection(const wxString
& s
);
180 Fill an array of ints with the positions of the currently selected items.
183 A reference to an wxArrayInt instance that is used to store the result of
186 @return The number of selections.
188 @remarks Use this with a multiple selection listbox.
191 In wxPerl this method takes no parameters and return the
192 selected items as a list.
195 @see wxControlWithItems::GetSelection, wxControlWithItems::GetStringSelection,
196 wxControlWithItems::SetSelection
198 virtual int GetSelections(wxArrayInt
& selections
) const;
201 Returns the item located at @a point, or @c wxNOT_FOUND if there
202 is no item located at @a point.
204 It is currently implemented for wxMSW, wxMac and wxGTK2 ports.
207 Point of item (in client coordinates) to obtain
209 @return Item located at point, or wxNOT_FOUND if unimplemented or the
214 int HitTest(const wxPoint
& point
) const;
219 int HitTest(int x
, int y
) const;
222 Insert the given number of strings before the specified position.
225 Number of items in the array items
227 Labels of items to be inserted
229 Position before which to insert the items: if pos is 0 the
230 items will be inserted in the beginning of the listbox
233 Not supported by wxPerl.
236 void InsertItems(unsigned int nItems
, const wxString
*items
,
240 Insert the given number of strings before the specified position.
243 Labels of items to be inserted
245 Position before which to insert the items: if pos is @c 0 the
246 items will be inserted in the beginning of the listbox
249 Use an array reference for the @a items parameter.
252 void InsertItems(const wxArrayString
& items
,
256 Determines whether an item is selected.
259 The zero-based item index.
261 @return @true if the given item is selected, @false otherwise.
263 virtual bool IsSelected(int n
) const;
266 Set the specified item to be the first visible item.
269 The zero-based item index that should be visible.
271 void SetFirstItem(int n
);
274 Set the specified item to be the first visible item.
277 The string that should be visible.
279 void SetFirstItem(const wxString
& string
);
282 Ensure that the item with the given index is currently shown.
284 Scroll the listbox if necessary.
286 This method is currently only implemented in wxGTK and wxOSX and does
287 nothing in other ports.
291 virtual void EnsureVisible(int n
);
294 Return true if the listbox has ::wxLB_SORT style.
296 This method is mostly meant for internal use only.
298 virtual bool IsSorted() const;
301 // NOTE: Phoenix needs to see the implementation of pure virtuals so it
302 // knows that this class is not abstract.
303 virtual unsigned int GetCount() const;
304 virtual wxString
GetString(unsigned int n
) const;
305 virtual void SetString(unsigned int n
, const wxString
& s
);
306 virtual int FindString(const wxString
& s
, bool bCase
= false) const;