]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/listbox.h
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
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.
35 Single-selection list.
37 Multiple-selection list: the user can toggle multiple items on and off.
38 This is the same as wxLB_EXTENDED in wxGTK2 port.
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
44 Create horizontal scrollbar if contents are too wide (Windows only).
45 @style{wxLB_ALWAYS_SB}
46 Always show a vertical scrollbar.
47 @style{wxLB_NEEDED_SB}
48 Only create a vertical scrollbar if needed.
50 Don't create vertical scrollbar (wxMSW only).
52 The listbox contents are sorted in alphabetical order.
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.
59 @beginEventEmissionTable{wxCommandEvent}
60 @event{EVT_LISTBOX(id, func)}
61 Process a @c wxEVT_COMMAND_LISTBOX_SELECTED event, when an item on the
62 list is selected or the selection changes.
63 @event{EVT_LISTBOX_DCLICK(id, func)}
64 Process a @c wxEVT_COMMAND_LISTBOX_DOUBLECLICKED event, when the listbox
72 @see wxEditableListBox, wxChoice, wxComboBox, wxListCtrl, wxCommandEvent
74 class wxListBox
: public wxControl
,
75 public wxItemContainer
84 Constructor, creating and showing a list box.
89 The ID of this control. A value of @c wxID_ANY indicates a default value.
92 If ::wxDefaultPosition is specified then a default position is chosen.
95 If ::wxDefaultSize is specified then the window is sized appropriately.
97 Number of strings with which to initialise the control.
99 The strings to use to initialize the control.
101 Window style. See wxListBox.
103 The validator for this control.
105 The name of this class.
108 Not supported by wxPerl.
112 wxListBox(wxWindow
* parent
, wxWindowID id
,
113 const wxPoint
& pos
= wxDefaultPosition
,
114 const wxSize
& size
= wxDefaultSize
,
116 const wxString choices
[] = NULL
,
118 const wxValidator
& validator
= wxDefaultValidator
,
119 const wxString
& name
= wxListBoxNameStr
);
122 Constructor, creating and showing a list box.
124 See the other wxListBox() constructor; the only difference is that
125 this overload takes a wxArrayString instead of a pointer to an array
129 Use an array reference for the @a choices parameter.
133 wxListBox(wxWindow
* parent
, wxWindowID id
,
136 const wxArrayString
& choices
,
138 const wxValidator
& validator
= wxDefaultValidator
,
139 const wxString
& name
= wxListBoxNameStr
);
142 Destructor, destroying the list box.
144 virtual ~wxListBox();
148 Creates the listbox for two-step construction.
149 See wxListBox() for further details.
151 bool Create(wxWindow
*parent
, wxWindowID id
,
152 const wxPoint
& pos
= wxDefaultPosition
,
153 const wxSize
& size
= wxDefaultSize
,
154 int n
= 0, const wxString choices
[] = NULL
,
156 const wxValidator
& validator
= wxDefaultValidator
,
157 const wxString
& name
= wxListBoxNameStr
);
158 bool Create(wxWindow
*parent
, wxWindowID id
,
161 const wxArrayString
& choices
,
163 const wxValidator
& validator
= wxDefaultValidator
,
164 const wxString
& name
= wxListBoxNameStr
);
168 Deselects an item in the list box.
171 The zero-based item to deselect.
173 @remarks This applies to multiple selection listboxes only.
175 void Deselect(int n
);
177 virtual void SetSelection(int n
);
179 virtual int GetSelection() const;
181 virtual bool SetStringSelection(const wxString
& s
, bool select
);
182 virtual bool SetStringSelection(const wxString
& s
);
185 Fill an array of ints with the positions of the currently selected items.
188 A reference to an wxArrayInt instance that is used to store the result of
191 @return The number of selections.
193 @remarks Use this with a multiple selection listbox.
196 In wxPerl this method takes no parameters and return the
197 selected items as a list.
200 @see wxControlWithItems::GetSelection, wxControlWithItems::GetStringSelection,
201 wxControlWithItems::SetSelection
203 virtual int GetSelections(wxArrayInt
& selections
) const;
206 Returns the item located at @a point, or @c wxNOT_FOUND if there
207 is no item located at @a point.
209 It is currently implemented for wxMSW, wxMac and wxGTK2 ports.
212 Point of item (in client coordinates) to obtain
214 @return Item located at point, or wxNOT_FOUND if unimplemented or the
219 int HitTest(const wxPoint
& point
) const;
224 int HitTest(int x
, int y
) const;
227 Insert the given number of strings before the specified position.
230 Number of items in the array items
232 Labels of items to be inserted
234 Position before which to insert the items: if pos is 0 the
235 items will be inserted in the beginning of the listbox
238 Not supported by wxPerl.
241 void InsertItems(unsigned int nItems
, const wxString
*items
,
245 Insert the given number of strings before the specified position.
248 Labels of items to be inserted
250 Position before which to insert the items: if pos is @c 0 the
251 items will be inserted in the beginning of the listbox
254 Use an array reference for the @a items parameter.
257 void InsertItems(const wxArrayString
& items
,
261 Determines whether an item is selected.
264 The zero-based item index.
266 @return @true if the given item is selected, @false otherwise.
268 virtual bool IsSelected(int n
) const;
271 Set the specified item to be the first visible item.
274 The zero-based item index that should be visible.
276 void SetFirstItem(int n
);
279 Set the specified item to be the first visible item.
282 The string that should be visible.
284 void SetFirstItem(const wxString
& string
);
287 Ensure that the item with the given index is currently shown.
289 Scroll the listbox if necessary.
291 This method is currently only implemented in wxGTK and wxOSX and does
292 nothing in other ports.
296 virtual void EnsureVisible(int n
);
299 Return true if the listbox has ::wxLB_SORT style.
301 This method is mostly meant for internal use only.
303 virtual bool IsSorted() const;
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;