]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/listbox.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxListBox
4 // Author: wxWidgets team
6 // Licence: wxWindows license
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.
21 Their number may be limited under some platforms.
23 A listbox callback gets an event @c wxEVT_COMMAND_LISTBOX_SELECTED for
24 single clicks, and @c wxEVT_COMMAND_LISTBOX_DOUBLECLICKED for double clicks.
28 Single-selection list.
30 Multiple-selection list: the user can toggle multiple items on and off.
31 This is the same as wxLB_EXTENDED in wxGTK2 port.
33 Extended-selection list: the user can extend the selection by using
34 @c SHIFT or @c CTRL keys together with the cursor movement keys or
37 Create horizontal scrollbar if contents are too wide (Windows only).
38 @style{wxLB_ALWAYS_SB}
39 Always show a vertical scrollbar.
40 @style{wxLB_NEEDED_SB}
41 Only create a vertical scrollbar if needed.
43 The listbox contents are sorted in alphabetical order.
46 Note that @c wxLB_SINGLE, @c wxLB_MULTIPLE and @c wxLB_EXTENDED styles are
47 mutually exclusive and you can specify at most one of them (single selection
48 is the default). See also @ref overview_windowstyles.
50 @beginEventEmissionTable{wxCommandEvent}
51 @event{EVT_LISTBOX(id, func)}
52 Process a wxEVT_COMMAND_LISTBOX_SELECTED event, when an item on the
53 list is selected or the selection changes.
54 @event{EVT_LISTBOX_DCLICK(id, func)}
55 Process a wxEVT_COMMAND_LISTBOXDOUBLECLICKED event, when the listbox
61 @appearance{listbox.png}
63 @see wxEditableListBox, wxChoice, wxComboBox, wxListCtrl, wxCommandEvent
65 class wxListBox
: public wxControlWithItems
74 Constructor, creating and showing a list box.
79 The ID of this control. A value of @c wxID_ANY indicates a default value.
82 If ::wxDefaultPosition is specified then a default position is chosen.
85 If ::wxDefaultSize is specified then the window is sized appropriately.
87 Number of strings with which to initialise the control.
89 The strings to use to initialize the control.
91 Window style. See wxListBox.
93 The validator for this control.
95 The name of this class.
98 wxListBox(wxWindow
* parent
, wxWindowID id
,
99 const wxPoint
& pos
= wxDefaultPosition
,
100 const wxSize
& size
= wxDefaultSize
,
102 const wxString choices
[] = NULL
,
104 const wxValidator
& validator
= wxDefaultValidator
,
105 const wxString
& name
= wxListBoxNameStr
);
108 Constructor, creating and showing a list box.
110 See the other wxListBox() constructor; the only difference is that
111 this overload takes a wxArrayString instead of a pointer to an array
115 wxListBox(wxWindow
* parent
, wxWindowID id
,
118 const wxArrayString
& choices
,
120 const wxValidator
& validator
= wxDefaultValidator
,
121 const wxString
& name
= wxListBoxNameStr
);
124 Destructor, destroying the list box.
126 virtual ~wxListBox();
130 Creates the listbox for two-step construction.
131 See wxListBox() for further details.
133 bool Create(wxWindow
*parent
, wxWindowID id
,
134 const wxPoint
& pos
= wxDefaultPosition
,
135 const wxSize
& size
= wxDefaultSize
,
136 int n
= 0, const wxString choices
[] = NULL
,
138 const wxValidator
& validator
= wxDefaultValidator
,
139 const wxString
& name
= wxListBoxNameStr
);
140 bool Create(wxWindow
*parent
, wxWindowID id
,
143 const wxArrayString
& choices
,
145 const wxValidator
& validator
= wxDefaultValidator
,
146 const wxString
& name
= wxListBoxNameStr
);
150 Deselects an item in the list box.
153 The zero-based item to deselect.
155 @remarks This applies to multiple selection listboxes only.
157 void Deselect(int n
);
160 Fill an array of ints with the positions of the currently selected items.
163 A reference to an wxArrayInt instance that is used to store the result of
166 @return The number of selections.
168 @remarks Use this with a multiple selection listbox.
170 @see wxControlWithItems::GetSelection, wxControlWithItems::GetStringSelection,
171 wxControlWithItems::SetSelection
173 virtual int GetSelections(wxArrayInt
& selections
) const;
176 Returns the item located at @a point, or @c wxNOT_FOUND if there
177 is no item located at @a point.
179 It is currently implemented for wxMSW, wxMac and wxGTK2 ports.
182 Point of item (in client coordinates) to obtain
184 @return Item located at point, or wxNOT_FOUND if unimplemented or the
189 int HitTest(const wxPoint
& point
) const;
194 int HitTest(int x
, int y
) const;
197 Insert the given number of strings before the specified position.
200 Number of items in the array items
202 Labels of items to be inserted
204 Position before which to insert the items: if pos is 0 the
205 items will be inserted in the beginning of the listbox
207 void InsertItems(unsigned int nItems
, const wxString
*items
,
211 Insert the given number of strings before the specified position.
214 Labels of items to be inserted
216 Position before which to insert the items: if pos is @c 0 the
217 items will be inserted in the beginning of the listbox
219 void InsertItems(const wxArrayString
& items
,
223 Determines whether an item is selected.
226 The zero-based item index.
228 @return @true if the given item is selected, @false otherwise.
230 virtual bool IsSelected(int n
) const;
233 Clears the list box and adds the given strings to it.
236 The number of strings to set.
238 An array of strings to set.
240 Options array of client data pointers
242 void Set(unsigned int n
, const wxString
* choices
, void *clientData
);
245 Clears the list box and adds the given strings to it.
246 You may free the array from the calling program after this method
250 An array of strings to set.
252 Options array of client data pointers
254 void Set(const wxArrayString
& choices
, void *clientData
);
257 Set the specified item to be the first visible item.
260 The zero-based item index that should be visible.
262 void SetFirstItem(int n
);
265 Set the specified item to be the first visible item.
268 The string that should be visible.
270 void SetFirstItem(const wxString
& string
);