]>
Commit | Line | Data |
---|---|---|
23324ae1 FM |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: listbox.h | |
e54c96f1 | 3 | // Purpose: interface of wxListBox |
23324ae1 FM |
4 | // Author: wxWidgets team |
5 | // RCS-ID: $Id$ | |
6 | // Licence: wxWindows license | |
7 | ///////////////////////////////////////////////////////////////////////////// | |
8 | ||
9 | /** | |
10 | @class wxListBox | |
11 | @wxheader{listbox.h} | |
7c913512 | 12 | |
23324ae1 FM |
13 | A listbox is used to select one or more of a list of strings. The |
14 | 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 | |
16 | is selected, the previous selection is removed) or multiple selection | |
17 | (clicking an item toggles the item on or off independently of other | |
18 | selections). | |
7c913512 | 19 | |
23324ae1 FM |
20 | List box elements are numbered from zero. Their number may be limited |
21 | under some platforms. | |
7c913512 | 22 | |
23324ae1 FM |
23 | A listbox callback gets an event wxEVT_COMMAND_LISTBOX_SELECTED for single |
24 | clicks, and | |
25 | wxEVT_COMMAND_LISTBOX_DOUBLE_CLICKED for double clicks. | |
7c913512 | 26 | |
23324ae1 FM |
27 | @beginStyleTable |
28 | @style{wxLB_SINGLE}: | |
29 | Single-selection list. | |
30 | @style{wxLB_MULTIPLE}: | |
31 | Multiple-selection list: the user can toggle multiple items on and | |
32 | off. | |
33 | @style{wxLB_EXTENDED}: | |
34 | Extended-selection list: the user can select multiple items using | |
35 | the SHIFT key and the mouse or special key combinations. | |
36 | @style{wxLB_HSCROLL}: | |
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. | |
42 | @style{wxLB_SORT}: | |
43 | The listbox contents are sorted in alphabetical order. | |
44 | @endStyleTable | |
7c913512 | 45 | |
23324ae1 | 46 | @beginEventTable |
4cc4bfaf | 47 | @event{EVT_LISTBOX(id, func)}: |
23324ae1 FM |
48 | Process a wxEVT_COMMAND_LISTBOX_SELECTED event, when an item on the |
49 | list is selected or the selection changes. | |
4cc4bfaf | 50 | @event{EVT_LISTBOX_DCLICK(id, func)}: |
23324ae1 FM |
51 | Process a wxEVT_COMMAND_LISTBOX_DOUBLECLICKED event, when the |
52 | listbox is double-clicked. | |
53 | @endEventTable | |
7c913512 | 54 | |
23324ae1 FM |
55 | @library{wxcore} |
56 | @category{ctrl} | |
57 | @appearance{listbox.png} | |
7c913512 | 58 | |
e54c96f1 | 59 | @see wxChoice, wxComboBox, wxListCtrl, wxCommandEvent |
23324ae1 FM |
60 | */ |
61 | class wxListBox : public wxControlWithItems | |
62 | { | |
63 | public: | |
64 | //@{ | |
65 | /** | |
66 | Constructor, creating and showing a list box. | |
67 | ||
7c913512 | 68 | @param parent |
4cc4bfaf | 69 | Parent window. Must not be @NULL. |
7c913512 | 70 | @param id |
4cc4bfaf | 71 | Window identifier. The value wxID_ANY indicates a default value. |
7c913512 | 72 | @param pos |
4cc4bfaf | 73 | Window position. |
7c913512 | 74 | @param size |
4cc4bfaf FM |
75 | Window size. If wxDefaultSize is specified then the window is |
76 | sized | |
77 | appropriately. | |
7c913512 | 78 | @param n |
4cc4bfaf | 79 | Number of strings with which to initialise the control. |
7c913512 | 80 | @param choices |
4cc4bfaf | 81 | An array of strings with which to initialise the control. |
7c913512 | 82 | @param style |
4cc4bfaf | 83 | Window style. See wxListBox. |
7c913512 | 84 | @param validator |
4cc4bfaf | 85 | Window validator. |
7c913512 | 86 | @param name |
4cc4bfaf | 87 | Window name. |
23324ae1 | 88 | |
4cc4bfaf | 89 | @see Create(), wxValidator |
23324ae1 FM |
90 | */ |
91 | wxListBox(); | |
7c913512 FM |
92 | wxListBox(wxWindow* parent, wxWindowID id, |
93 | const wxPoint& pos = wxDefaultPosition, | |
94 | const wxSize& size = wxDefaultSize, | |
95 | int n = 0, | |
4cc4bfaf | 96 | const wxString choices[] = NULL, |
7c913512 FM |
97 | long style = 0, |
98 | const wxValidator& validator = wxDefaultValidator, | |
99 | const wxString& name = "listBox"); | |
100 | wxListBox(wxWindow* parent, wxWindowID id, | |
101 | const wxPoint& pos, | |
102 | const wxSize& size, | |
103 | const wxArrayString& choices, | |
104 | long style = 0, | |
105 | const wxValidator& validator = wxDefaultValidator, | |
106 | const wxString& name = "listBox"); | |
23324ae1 FM |
107 | //@} |
108 | ||
109 | /** | |
110 | Destructor, destroying the list box. | |
111 | */ | |
112 | ~wxListBox(); | |
113 | ||
114 | //@{ | |
115 | /** | |
116 | Creates the listbox for two-step construction. See wxListBox() | |
117 | for further details. | |
118 | */ | |
119 | bool Create(wxWindow* parent, wxWindowID id, | |
120 | const wxPoint& pos = wxDefaultPosition, | |
121 | const wxSize& size = wxDefaultSize, | |
122 | int n, | |
4cc4bfaf | 123 | const wxString choices[] = NULL, |
23324ae1 FM |
124 | long style = 0, |
125 | const wxValidator& validator = wxDefaultValidator, | |
126 | const wxString& name = "listBox"); | |
7c913512 FM |
127 | bool Create(wxWindow* parent, wxWindowID id, |
128 | const wxPoint& pos, | |
129 | const wxSize& size, | |
130 | const wxArrayString& choices, | |
131 | long style = 0, | |
132 | const wxValidator& validator = wxDefaultValidator, | |
133 | const wxString& name = "listBox"); | |
23324ae1 FM |
134 | //@} |
135 | ||
136 | /** | |
137 | Deselects an item in the list box. | |
138 | ||
7c913512 | 139 | @param n |
4cc4bfaf | 140 | The zero-based item to deselect. |
23324ae1 FM |
141 | |
142 | @remarks This applies to multiple selection listboxes only. | |
143 | */ | |
144 | void Deselect(int n); | |
145 | ||
146 | /** | |
147 | Fill an array of ints with the positions of the currently selected items. | |
148 | ||
7c913512 | 149 | @param selections |
4cc4bfaf FM |
150 | A reference to an wxArrayInt instance that is used to store the result of |
151 | the query. | |
23324ae1 FM |
152 | |
153 | @returns The number of selections. | |
154 | ||
155 | @remarks Use this with a multiple selection listbox. | |
156 | ||
4cc4bfaf FM |
157 | @see wxControlWithItems::GetSelection, wxControlWithItems::GetStringSelection, |
158 | wxControlWithItems::SetSelection | |
23324ae1 | 159 | */ |
328f5751 | 160 | int GetSelections(wxArrayInt& selections) const; |
23324ae1 FM |
161 | |
162 | /** | |
163 | Returns the item located at @e point, or @c wxNOT_FOUND if there | |
164 | is no item located at @e point. | |
e54c96f1 FM |
165 | |
166 | @wxsince{2.7.0}. It is currently implemented | |
23324ae1 FM |
167 | for wxMSW, wxMac and wxGTK2 |
168 | ports. | |
169 | ||
7c913512 | 170 | @param point |
4cc4bfaf | 171 | Point of item (in client coordinates) to obtain |
23324ae1 FM |
172 | |
173 | @returns Item located at point, or wxNOT_FOUND if unimplemented or the | |
4cc4bfaf | 174 | item does not exist. |
23324ae1 | 175 | */ |
328f5751 | 176 | int HitTest(const wxPoint point) const; |
23324ae1 FM |
177 | |
178 | //@{ | |
179 | /** | |
180 | Insert the given number of strings before the specified position. | |
181 | ||
7c913512 | 182 | @param nItems |
4cc4bfaf | 183 | Number of items in the array items |
7c913512 | 184 | @param items |
4cc4bfaf | 185 | Labels of items to be inserted |
7c913512 | 186 | @param pos |
4cc4bfaf FM |
187 | Position before which to insert the items: for example, if pos is 0 the |
188 | items | |
189 | will be inserted in the beginning of the listbox | |
23324ae1 FM |
190 | */ |
191 | void InsertItems(int nItems, const wxString items, | |
192 | unsigned int pos); | |
7c913512 FM |
193 | void InsertItems(const wxArrayString& nItems, |
194 | unsigned int pos); | |
23324ae1 FM |
195 | //@} |
196 | ||
197 | /** | |
198 | Determines whether an item is selected. | |
199 | ||
7c913512 | 200 | @param n |
4cc4bfaf | 201 | The zero-based item index. |
23324ae1 FM |
202 | |
203 | @returns @true if the given item is selected, @false otherwise. | |
204 | */ | |
328f5751 | 205 | bool IsSelected(int n) const; |
23324ae1 FM |
206 | |
207 | //@{ | |
208 | /** | |
209 | Clears the list box and adds the given strings to it. | |
210 | ||
7c913512 | 211 | @param n |
4cc4bfaf | 212 | The number of strings to set. |
7c913512 | 213 | @param choices |
4cc4bfaf | 214 | An array of strings to set. |
7c913512 | 215 | @param clientData |
4cc4bfaf | 216 | Options array of client data pointers |
23324ae1 FM |
217 | |
218 | @remarks You may free the array from the calling program after this | |
4cc4bfaf | 219 | function has been called. |
23324ae1 | 220 | */ |
4cc4bfaf | 221 | void Set(int n, const wxString* choices, void clientData = NULL); |
7c913512 | 222 | void Set(const wxArrayString& choices, |
4cc4bfaf | 223 | void clientData = NULL); |
23324ae1 FM |
224 | //@} |
225 | ||
226 | //@{ | |
227 | /** | |
228 | Set the specified item to be the first visible item. | |
229 | ||
7c913512 | 230 | @param n |
4cc4bfaf | 231 | The zero-based item index. |
7c913512 | 232 | @param string |
4cc4bfaf | 233 | The string that should be visible. |
23324ae1 FM |
234 | */ |
235 | void SetFirstItem(int n); | |
7c913512 | 236 | void SetFirstItem(const wxString& string); |
23324ae1 FM |
237 | //@} |
238 | }; | |
e54c96f1 | 239 |