]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/listbox.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxListBox
4 // Author: wxWidgets team
5 // Licence: wxWindows licence
6 /////////////////////////////////////////////////////////////////////////////
11 A listbox is used to select one or more of a list of strings.
13 The strings are displayed in a scrolling box, with the selected string(s)
14 marked in reverse video. A listbox can be single selection (if an item is
15 selected, the previous selection is removed) or multiple selection
16 (clicking an item toggles the item on or off independently of other
19 List box elements are numbered from zero and while the maximal number of
20 elements is unlimited, it is usually better to use a virtual control, not
21 requiring to add all the items to it at once, such as wxDataViewCtrl or
22 wxListCtrl with @c wxLC_VIRTUAL style, once more than a few hundreds items
23 need to be displayed because this control is not optimized, neither from
24 performance nor from user interface point of view, for large number of
27 Notice that currently @c TAB characters in list box items text are not
28 handled consistently under all platforms, so they should be replaced by
29 spaces to display strings properly everywhere. The list box doesn't
30 support any other control characters at all.
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_LISTBOX 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_LISTBOX_DCLICK event, when the listbox
71 @see wxEditableListBox, wxChoice, wxComboBox, wxListCtrl, wxCommandEvent
73 class wxListBox
: public wxControl
,
74 public wxItemContainer
83 Constructor, creating and showing a list box.
88 The ID of this control. A value of @c wxID_ANY indicates a default value.
91 If ::wxDefaultPosition is specified then a default position is chosen.
94 If ::wxDefaultSize is specified then the window is sized appropriately.
96 Number of strings with which to initialise the control.
98 The strings to use to initialize the control.
100 Window style. See wxListBox.
102 The validator for this control.
104 The name of this class.
107 Not supported by wxPerl.
111 wxListBox(wxWindow
* parent
, wxWindowID id
,
112 const wxPoint
& pos
= wxDefaultPosition
,
113 const wxSize
& size
= wxDefaultSize
,
115 const wxString choices
[] = NULL
,
117 const wxValidator
& validator
= wxDefaultValidator
,
118 const wxString
& name
= wxListBoxNameStr
);
121 Constructor, creating and showing a list box.
123 See the other wxListBox() constructor; the only difference is that
124 this overload takes a wxArrayString instead of a pointer to an array
128 Use an array reference for the @a choices parameter.
132 wxListBox(wxWindow
* parent
, wxWindowID id
,
135 const wxArrayString
& choices
,
137 const wxValidator
& validator
= wxDefaultValidator
,
138 const wxString
& name
= wxListBoxNameStr
);
141 Destructor, destroying the list box.
143 virtual ~wxListBox();
147 Creates the listbox for two-step construction.
148 See wxListBox() for further details.
150 bool Create(wxWindow
*parent
, wxWindowID id
,
151 const wxPoint
& pos
= wxDefaultPosition
,
152 const wxSize
& size
= wxDefaultSize
,
153 int n
= 0, const wxString choices
[] = NULL
,
155 const wxValidator
& validator
= wxDefaultValidator
,
156 const wxString
& name
= wxListBoxNameStr
);
157 bool Create(wxWindow
*parent
, wxWindowID id
,
160 const wxArrayString
& choices
,
162 const wxValidator
& validator
= wxDefaultValidator
,
163 const wxString
& name
= wxListBoxNameStr
);
167 Deselects an item in the list box.
170 The zero-based item to deselect.
172 @remarks This applies to multiple selection listboxes only.
174 void Deselect(int n
);
176 virtual void SetSelection(int n
);
178 virtual int GetSelection() const;
180 virtual bool SetStringSelection(const wxString
& s
, bool select
);
181 virtual bool SetStringSelection(const wxString
& s
);
184 Fill an array of ints with the positions of the currently selected items.
187 A reference to an wxArrayInt instance that is used to store the result of
190 @return The number of selections.
192 @remarks Use this with a multiple selection listbox.
195 In wxPerl this method takes no parameters and return the
196 selected items as a list.
199 @see wxControlWithItems::GetSelection, wxControlWithItems::GetStringSelection,
200 wxControlWithItems::SetSelection
202 virtual int GetSelections(wxArrayInt
& selections
) const;
205 Returns the item located at @a point, or @c wxNOT_FOUND if there
206 is no item located at @a point.
208 It is currently implemented for wxMSW, wxMac and wxGTK2 ports.
211 Point of item (in client coordinates) to obtain
213 @return Item located at point, or wxNOT_FOUND if unimplemented or the
218 int HitTest(const wxPoint
& point
) const;
223 int HitTest(int x
, int y
) const;
226 Insert the given number of strings before the specified position.
229 Number of items in the array items
231 Labels of items to be inserted
233 Position before which to insert the items: if pos is 0 the
234 items will be inserted in the beginning of the listbox
237 Not supported by wxPerl.
240 void InsertItems(unsigned int nItems
, const wxString
*items
,
244 Insert the given number of strings before the specified position.
247 Labels of items to be inserted
249 Position before which to insert the items: if pos is @c 0 the
250 items will be inserted in the beginning of the listbox
253 Use an array reference for the @a items parameter.
256 void InsertItems(const wxArrayString
& items
,
260 Determines whether an item is selected.
263 The zero-based item index.
265 @return @true if the given item is selected, @false otherwise.
267 virtual bool IsSelected(int n
) const;
270 Set the specified item to be the first visible item.
273 The zero-based item index that should be visible.
275 void SetFirstItem(int n
);
278 Set the specified item to be the first visible item.
281 The string that should be visible.
283 void SetFirstItem(const wxString
& string
);
286 Ensure that the item with the given index is currently shown.
288 Scroll the listbox if necessary.
290 This method is currently only implemented in wxGTK and wxOSX and does
291 nothing in other ports.
295 virtual void EnsureVisible(int n
);
298 Return true if the listbox has ::wxLB_SORT style.
300 This method is mostly meant for internal use only.
302 virtual bool IsSorted() const;
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;