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
29 A listbox callback gets an event @c wxEVT_COMMAND_LISTBOX_SELECTED for
30 single clicks, and @c wxEVT_COMMAND_LISTBOX_DOUBLECLICKED for double clicks.
34 Single-selection list.
36 Multiple-selection list: the user can toggle multiple items on and off.
37 This is the same as wxLB_EXTENDED in wxGTK2 port.
39 Extended-selection list: the user can extend the selection by using
40 @c SHIFT or @c CTRL keys together with the cursor movement keys or
43 Create horizontal scrollbar if contents are too wide (Windows only).
44 @style{wxLB_ALWAYS_SB}
45 Always show a vertical scrollbar.
46 @style{wxLB_NEEDED_SB}
47 Only create a vertical scrollbar if needed.
49 Don't create vertical scrollbar (wxMSW only).
51 The listbox contents are sorted in alphabetical order.
54 Note that @c wxLB_SINGLE, @c wxLB_MULTIPLE and @c wxLB_EXTENDED styles are
55 mutually exclusive and you can specify at most one of them (single selection
56 is the default). See also @ref overview_windowstyles.
58 @beginEventEmissionTable{wxCommandEvent}
59 @event{EVT_LISTBOX(id, func)}
60 Process a @c wxEVT_COMMAND_LISTBOX_SELECTED event, when an item on the
61 list is selected or the selection changes.
62 @event{EVT_LISTBOX_DCLICK(id, func)}
63 Process a @c wxEVT_COMMAND_LISTBOX_DOUBLECLICKED event, when the listbox
69 @appearance{listbox.png}
71 @see wxEditableListBox, wxChoice, wxComboBox, wxListCtrl, wxCommandEvent
73 class wxListBox
: public wxControlWithItems
82 Constructor, creating and showing a list box.
87 The ID of this control. A value of @c wxID_ANY indicates a default value.
90 If ::wxDefaultPosition is specified then a default position is chosen.
93 If ::wxDefaultSize is specified then the window is sized appropriately.
95 Number of strings with which to initialise the control.
97 The strings to use to initialize the control.
99 Window style. See wxListBox.
101 The validator for this control.
103 The name of this class.
106 Not supported by wxPerl.
110 wxListBox(wxWindow
* parent
, wxWindowID id
,
111 const wxPoint
& pos
= wxDefaultPosition
,
112 const wxSize
& size
= wxDefaultSize
,
114 const wxString choices
[] = NULL
,
116 const wxValidator
& validator
= wxDefaultValidator
,
117 const wxString
& name
= wxListBoxNameStr
);
120 Constructor, creating and showing a list box.
122 See the other wxListBox() constructor; the only difference is that
123 this overload takes a wxArrayString instead of a pointer to an array
127 Use an array reference for the @a choices parameter.
131 wxListBox(wxWindow
* parent
, wxWindowID id
,
134 const wxArrayString
& choices
,
136 const wxValidator
& validator
= wxDefaultValidator
,
137 const wxString
& name
= wxListBoxNameStr
);
140 Destructor, destroying the list box.
142 virtual ~wxListBox();
146 Creates the listbox for two-step construction.
147 See wxListBox() for further details.
149 bool Create(wxWindow
*parent
, wxWindowID id
,
150 const wxPoint
& pos
= wxDefaultPosition
,
151 const wxSize
& size
= wxDefaultSize
,
152 int n
= 0, const wxString choices
[] = NULL
,
154 const wxValidator
& validator
= wxDefaultValidator
,
155 const wxString
& name
= wxListBoxNameStr
);
156 bool Create(wxWindow
*parent
, wxWindowID id
,
159 const wxArrayString
& choices
,
161 const wxValidator
& validator
= wxDefaultValidator
,
162 const wxString
& name
= wxListBoxNameStr
);
166 Deselects an item in the list box.
169 The zero-based item to deselect.
171 @remarks This applies to multiple selection listboxes only.
173 void Deselect(int n
);
175 virtual void SetSelection(int n
);
177 virtual int GetSelection() const;
179 virtual bool SetStringSelection(const wxString
& s
, bool select
);
180 virtual bool SetStringSelection(const wxString
& s
);
183 Fill an array of ints with the positions of the currently selected items.
186 A reference to an wxArrayInt instance that is used to store the result of
189 @return The number of selections.
191 @remarks Use this with a multiple selection listbox.
194 In wxPerl this method takes no parameters and return the
195 selected items as a list.
198 @see wxControlWithItems::GetSelection, wxControlWithItems::GetStringSelection,
199 wxControlWithItems::SetSelection
201 virtual int GetSelections(wxArrayInt
& selections
) const;
204 Returns the item located at @a point, or @c wxNOT_FOUND if there
205 is no item located at @a point.
207 It is currently implemented for wxMSW, wxMac and wxGTK2 ports.
210 Point of item (in client coordinates) to obtain
212 @return Item located at point, or wxNOT_FOUND if unimplemented or the
217 int HitTest(const wxPoint
& point
) const;
222 int HitTest(int x
, int y
) const;
225 Insert the given number of strings before the specified position.
228 Number of items in the array items
230 Labels of items to be inserted
232 Position before which to insert the items: if pos is 0 the
233 items will be inserted in the beginning of the listbox
236 Not supported by wxPerl.
239 void InsertItems(unsigned int nItems
, const wxString
*items
,
243 Insert the given number of strings before the specified position.
246 Labels of items to be inserted
248 Position before which to insert the items: if pos is @c 0 the
249 items will be inserted in the beginning of the listbox
252 Use an array reference for the @a items parameter.
255 void InsertItems(const wxArrayString
& items
,
259 Determines whether an item is selected.
262 The zero-based item index.
264 @return @true if the given item is selected, @false otherwise.
266 virtual bool IsSelected(int n
) const;
269 Set the specified item to be the first visible item.
272 The zero-based item index that should be visible.
274 void SetFirstItem(int n
);
277 Set the specified item to be the first visible item.
280 The string that should be visible.
282 void SetFirstItem(const wxString
& string
);
285 Ensure that the item with the given index is currently shown.
287 Scroll the listbox if necessary.
289 This method is currently only implemented in wxGTK and wxOSX and does
290 nothing in other ports.
294 virtual void EnsureVisible(int n
);
297 Return true if the listbox has ::wxLB_SORT style.
299 This method is mostly meant for internal use only.
301 virtual bool IsSorted() const;
304 // NOTE: Phoenix needs to see the implementation of pure virtuals so it
305 // knows that this class is not abstract.
306 virtual unsigned int GetCount() const;
307 virtual wxString
GetString(unsigned int n
) const;
308 virtual void SetString(unsigned int n
, const wxString
& s
);
309 virtual int FindString(const wxString
& s
, bool bCase
= false) const;