]>
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 Don't create vertical scrollbar (wxMSW only).
45 The listbox contents are sorted in alphabetical order.
48 Note that @c wxLB_SINGLE, @c wxLB_MULTIPLE and @c wxLB_EXTENDED styles are
49 mutually exclusive and you can specify at most one of them (single selection
50 is the default). See also @ref overview_windowstyles.
52 @beginEventEmissionTable{wxCommandEvent}
53 @event{EVT_LISTBOX(id, func)}
54 Process a wxEVT_COMMAND_LISTBOX_SELECTED event, when an item on the
55 list is selected or the selection changes.
56 @event{EVT_LISTBOX_DCLICK(id, func)}
57 Process a wxEVT_COMMAND_LISTBOXDOUBLECLICKED event, when the listbox
63 @appearance{listbox.png}
65 @see wxEditableListBox, wxChoice, wxComboBox, wxListCtrl, wxCommandEvent
67 class wxListBox
: public wxControlWithItems
76 Constructor, creating and showing a list box.
81 The ID of this control. A value of @c wxID_ANY indicates a default value.
84 If ::wxDefaultPosition is specified then a default position is chosen.
87 If ::wxDefaultSize is specified then the window is sized appropriately.
89 Number of strings with which to initialise the control.
91 The strings to use to initialize the control.
93 Window style. See wxListBox.
95 The validator for this control.
97 The name of this class.
100 wxListBox(wxWindow
* parent
, wxWindowID id
,
101 const wxPoint
& pos
= wxDefaultPosition
,
102 const wxSize
& size
= wxDefaultSize
,
104 const wxString choices
[] = NULL
,
106 const wxValidator
& validator
= wxDefaultValidator
,
107 const wxString
& name
= wxListBoxNameStr
);
110 Constructor, creating and showing a list box.
112 See the other wxListBox() constructor; the only difference is that
113 this overload takes a wxArrayString instead of a pointer to an array
117 wxListBox(wxWindow
* parent
, wxWindowID id
,
120 const wxArrayString
& choices
,
122 const wxValidator
& validator
= wxDefaultValidator
,
123 const wxString
& name
= wxListBoxNameStr
);
126 Destructor, destroying the list box.
128 virtual ~wxListBox();
132 Creates the listbox for two-step construction.
133 See wxListBox() for further details.
135 bool Create(wxWindow
*parent
, wxWindowID id
,
136 const wxPoint
& pos
= wxDefaultPosition
,
137 const wxSize
& size
= wxDefaultSize
,
138 int n
= 0, const wxString choices
[] = NULL
,
140 const wxValidator
& validator
= wxDefaultValidator
,
141 const wxString
& name
= wxListBoxNameStr
);
142 bool Create(wxWindow
*parent
, wxWindowID id
,
145 const wxArrayString
& choices
,
147 const wxValidator
& validator
= wxDefaultValidator
,
148 const wxString
& name
= wxListBoxNameStr
);
152 Deselects an item in the list box.
155 The zero-based item to deselect.
157 @remarks This applies to multiple selection listboxes only.
159 void Deselect(int n
);
162 Fill an array of ints with the positions of the currently selected items.
165 A reference to an wxArrayInt instance that is used to store the result of
168 @return The number of selections.
170 @remarks Use this with a multiple selection listbox.
172 @see wxControlWithItems::GetSelection, wxControlWithItems::GetStringSelection,
173 wxControlWithItems::SetSelection
175 virtual int GetSelections(wxArrayInt
& selections
) const;
178 Returns the item located at @a point, or @c wxNOT_FOUND if there
179 is no item located at @a point.
181 It is currently implemented for wxMSW, wxMac and wxGTK2 ports.
184 Point of item (in client coordinates) to obtain
186 @return Item located at point, or wxNOT_FOUND if unimplemented or the
191 int HitTest(const wxPoint
& point
) const;
196 int HitTest(int x
, int y
) const;
199 Insert the given number of strings before the specified position.
202 Number of items in the array items
204 Labels of items to be inserted
206 Position before which to insert the items: if pos is 0 the
207 items will be inserted in the beginning of the listbox
209 void InsertItems(unsigned int nItems
, const wxString
*items
,
213 Insert the given number of strings before the specified position.
216 Labels of items to be inserted
218 Position before which to insert the items: if pos is @c 0 the
219 items will be inserted in the beginning of the listbox
221 void InsertItems(const wxArrayString
& items
,
225 Determines whether an item is selected.
228 The zero-based item index.
230 @return @true if the given item is selected, @false otherwise.
232 virtual bool IsSelected(int n
) const;
235 Clears the list box and adds the given strings to it.
238 The number of strings to set.
240 An array of strings to set.
242 Options array of client data pointers
244 void Set(unsigned int n
, const wxString
* choices
, void *clientData
);
247 Clears the list box and adds the given strings to it.
248 You may free the array from the calling program after this method
252 An array of strings to set.
254 Options array of client data pointers
256 void Set(const wxArrayString
& choices
, void *clientData
);
259 Set the specified item to be the first visible item.
262 The zero-based item index that should be visible.
264 void SetFirstItem(int n
);
267 Set the specified item to be the first visible item.
270 The string that should be visible.
272 void SetFirstItem(const wxString
& string
);