]>
Commit | Line | Data |
---|---|---|
a660d684 KB |
1 | \section{\class{wxListBox}}\label{wxlistbox} |
2 | ||
3 | A listbox is used to select one or more of a list of strings. The | |
4 | strings are displayed in a scrolling box, with the selected string(s) | |
5 | marked in reverse video. A listbox can be single selection (if an item | |
6 | is selected, the previous selection is removed) or multiple selection | |
7 | (clicking an item toggles the item on or off independently of other | |
8 | selections). | |
9 | ||
10 | List box elements are numbered from zero. | |
11 | ||
12 | A listbox callback gets an event wxEVT\_COMMAND\_LISTBOX\_SELECT for single clicks, and | |
13 | wxEVT\_COMMAND\_LISTBOX\_DOUBLE\_CLICKED for double clicks. Another way of intercepting | |
14 | double clicks is to override \helpref{wxWindow::OnDefaultAction}{wxwindowondefaultaction}. | |
15 | ||
16 | \wxheading{Derived from} | |
17 | ||
18 | \helpref{wxControl}{wxcontrol}\\ | |
19 | \helpref{wxWindow}{wxwindow}\\ | |
20 | \helpref{wxEvtHandler}{wxevthandler}\\ | |
21 | \helpref{wxObject}{wxobject} | |
22 | ||
23 | \wxheading{Window styles} | |
24 | ||
25 | \twocolwidtha{5cm}% | |
26 | \begin{twocollist}\itemsep=0pt | |
27 | \twocolitem{\windowstyle{wxLB\_SINGLE}}{Single-selection list.} | |
28 | \twocolitem{\windowstyle{wxLB\_MULTIPLE}}{Multiple-selection list: the user can toggle multiple | |
29 | items on and off.} | |
30 | \twocolitem{\windowstyle{wxLB\_EXTENDED}}{Extended-selection list: the user can | |
31 | select multiple items using the SHIFT key and the mouse or special key combinations.} | |
32 | \twocolitem{\windowstyle{wxLB\_HSCROLL}}{Create horizontal scrollbar if contents are too wide (Windows only).} | |
33 | \twocolitem{\windowstyle{wxLB\_ALWAYS\_SB}}{Always show a vertical scrollbar.} | |
34 | \twocolitem{\windowstyle{wxLB\_NEEDED\_SB}}{Only create a vertical scrollbar if needed.} | |
35 | \twocolitem{\windowstyle{wxLB\_SORT}}{The listbox contents are sorted in alphabetical order.} | |
36 | \end{twocollist} | |
37 | ||
38 | See also \helpref{window styles overview}{windowstyles}. | |
39 | ||
40 | \wxheading{See also} | |
41 | ||
42 | \helpref{wxChoice}{wxchoice}, \helpref{wxComboBox}{wxcombobox}, \helpref{wxListCtrl}{wxlistctrl} | |
43 | ||
44 | \latexignore{\rtfignore{\wxheading{Members}}} | |
45 | ||
46 | \membersection{wxListBox::wxListBox}\label{wxlistboxconstr} | |
47 | ||
48 | \func{}{wxListBox}{\void} | |
49 | ||
50 | Default constructor. | |
51 | ||
52 | \func{}{wxListBox}{\param{wxWindow*}{ parent}, \param{const wxWindowID}{ id},\rtfsp | |
53 | \param{const wxPoint\&}{ pos = wxDefaultPosition}, \param{const wxSize\&}{ size = wxDefaultSize},\rtfsp | |
54 | \param{const int}{ n}, \param{const wxString }{choices[] = NULL},\rtfsp | |
55 | \param{const long}{ style = 0}, \param{const wxValidator\& }{validator = wxDefaultValidator}, \param{const wxString\& }{name = ``listBox"}} | |
56 | ||
57 | Constructor, creating and showing a list box. | |
58 | ||
59 | \wxheading{Parameters} | |
60 | ||
61 | \docparam{parent}{Parent window. Must not be NULL.} | |
62 | ||
63 | \docparam{id}{Window identifier. A value of -1 indicates a default value.} | |
64 | ||
65 | \docparam{pos}{Window position.} | |
66 | ||
67 | \docparam{size}{Window size. If the default size (-1, -1) is specified then the window is sized | |
68 | appropriately.} | |
69 | ||
70 | \docparam{n}{Number of strings with which to initialise the control.} | |
71 | ||
72 | \docparam{choices}{An array of strings with which to initialise the control.} | |
73 | ||
74 | \docparam{style}{Window style. See \helpref{wxListBox}{wxlistbox}.} | |
75 | ||
76 | \docparam{validator}{Window validator.} | |
77 | ||
78 | \docparam{name}{Window name.} | |
79 | ||
80 | \wxheading{See also} | |
81 | ||
82 | \helpref{wxListBox::Create}{wxlistboxcreate}, \helpref{wxValidator}{wxvalidator} | |
83 | ||
84 | \membersection{wxListBox::\destruct{wxListBox}} | |
85 | ||
86 | \func{void}{\destruct{wxListBox}}{\void} | |
87 | ||
88 | Destructor, destroying the list box. | |
89 | ||
90 | \membersection{wxListBox::Append}\label{wxlistboxappend} | |
91 | ||
92 | \func{void}{Append}{\param{const wxString\& }{ item}} | |
93 | ||
94 | Adds the item to the end of the list box. | |
95 | ||
96 | \func{void}{Append}{\param{const wxString\& }{ item}, \param{char* }{clientData}} | |
97 | ||
98 | Adds the item to the end of the list box, associating the given data | |
99 | with the item. | |
100 | ||
101 | \wxheading{Parameters} | |
102 | ||
103 | \docparam{item}{String to add.} | |
104 | ||
105 | \docparam{clientData}{Client data to associate with the item.} | |
106 | ||
107 | \membersection{wxListBox::Clear}\label{wxlistboxclear} | |
108 | ||
109 | \func{void}{Clear}{\void} | |
110 | ||
111 | Clears all strings from the list box. | |
112 | ||
113 | \membersection{wxListBox::Create}\label{wxlistboxcreate} | |
114 | ||
115 | \func{bool}{Create}{\param{wxWindow*}{ parent}, \param{const wxWindowID}{ id},\rtfsp | |
116 | \param{const wxPoint\&}{ pos = wxDefaultPosition}, \param{const wxSize\&}{ size = wxDefaultSize},\rtfsp | |
117 | \param{const int}{ n}, \param{const wxString }{choices[] = NULL},\rtfsp | |
118 | \param{const long}{ style = 0}, \param{const wxValidator\& }{validator = wxDefaultValidator}, \param{const wxString\& }{name = ``listBox"}} | |
119 | ||
120 | Creates the listbox for two-step construction. See \helpref{wxListBox::wxListBox}{wxlistboxconstr}\rtfsp | |
121 | for further details. | |
122 | ||
123 | \membersection{wxListBox::Delete}\label{wxlistboxdelete} | |
124 | ||
125 | \func{void}{Delete}{\param{int}{ n}} | |
126 | ||
127 | Deletes an item from the listbox. | |
128 | ||
129 | \wxheading{Parameters} | |
130 | ||
131 | \docparam{n}{The zero-based item index.} | |
132 | ||
133 | \membersection{wxListBox::Deselect}\label{wxlistboxdeselect} | |
134 | ||
135 | \func{void}{Deselect}{\param{int}{ n}} | |
136 | ||
137 | Deselects an item in the list box. | |
138 | ||
139 | \wxheading{Parameters} | |
140 | ||
141 | \docparam{n}{The zero-based item to deselect.} | |
142 | ||
143 | \wxheading{Remarks} | |
144 | ||
145 | This applies to multiple selection listboxes only. | |
146 | ||
147 | \membersection{wxListBox::FindString}\label{wxlistboxfindstring} | |
148 | ||
149 | \func{int}{FindString}{\param{const wxString\& }{string}} | |
150 | ||
151 | Finds an item matching the given string. | |
152 | ||
153 | \wxheading{Parameters} | |
154 | ||
155 | \docparam{string}{String to find.} | |
156 | ||
157 | \wxheading{Return value} | |
158 | ||
159 | The zero-based position of the item, or -1 if the string was not found. | |
160 | ||
161 | \membersection{wxListBox::GetClientData}\label{wxlistboxgetclientdata} | |
162 | ||
163 | \constfunc{char*}{GetClientData}{\param{const int}{ n}} | |
164 | ||
165 | Returns a pointer to the client data associated with the given item (if any). | |
166 | ||
167 | \wxheading{Parameters} | |
168 | ||
169 | \docparam{n}{The zero-based position of the item.} | |
170 | ||
171 | \wxheading{Return value} | |
172 | ||
173 | A pointer to the client data, or NULL if not present. | |
174 | ||
175 | \membersection{wxListBox::GetSelection}\label{wxlistboxgetselection} | |
176 | ||
177 | \constfunc{int}{GetSelection}{\void} | |
178 | ||
179 | Gets the position of the selected item. | |
180 | ||
181 | \wxheading{Return value} | |
182 | ||
183 | The position of the current selection. | |
184 | ||
185 | \wxheading{Remarks} | |
186 | ||
187 | Applicable to single selection list boxes only. | |
188 | ||
189 | \wxheading{See also} | |
190 | ||
191 | \helpref{wxListBox::SetSelection}{wxlistboxsetselection},\rtfsp | |
192 | \helpref{wxListBox::GetStringSelection}{wxlistboxgetstringselection},\rtfsp | |
193 | \helpref{wxListBox::GetSelections}{wxlistboxgetselections} | |
194 | ||
195 | \membersection{wxListBox::GetSelections}\label{wxlistboxgetselections} | |
196 | ||
197 | \constfunc{int}{GetSelections}{\param{int **}{selections}} | |
198 | ||
199 | Gets an array containing the positions of the selected strings. | |
200 | ||
201 | \wxheading{Parameters} | |
202 | ||
203 | \docparam{selections}{A pointer to an integer array, which will be allocated by the function if | |
204 | selects are present. Do not deallocate the returned array - it will be deallocated by the listbox.} | |
205 | ||
206 | \wxheading{Return value} | |
207 | ||
208 | The number of selections. | |
209 | ||
210 | \wxheading{Remarks} | |
211 | ||
212 | Use this with a multiple selection listbox. | |
213 | ||
214 | \wxheading{See also} | |
215 | ||
216 | \helpref{wxListBox::GetSelection}{wxlistboxgetselection},\rtfsp | |
217 | \helpref{wxListBox::GetStringSelection}{wxlistboxgetstringselection},\rtfsp | |
218 | \helpref{wxListBox::SetSelection}{wxlistboxsetselection} | |
219 | ||
220 | \membersection{wxListBox::GetString}\label{wxlistboxgetstring} | |
221 | ||
222 | \constfunc{wxString}{GetString}{\param{const int}{ n}} | |
223 | ||
224 | Returns the string at the given position. | |
225 | ||
226 | \wxheading{Parameters} | |
227 | ||
228 | \docparam{n}{The zero-based position.} | |
229 | ||
230 | \wxheading{Return value} | |
231 | ||
232 | The string, or an empty string if the position was invalid. | |
233 | ||
234 | \membersection{wxListBox::GetStringSelection}\label{wxlistboxgetstringselection} | |
235 | ||
236 | \constfunc{wxString}{GetStringSelection}{\void} | |
237 | ||
238 | Gets the selected string - for single selection list boxes only. This | |
239 | must be copied by the calling program if long term use is to be made of | |
240 | it. | |
241 | ||
242 | \wxheading{See also} | |
243 | ||
244 | \helpref{wxListBox::GetSelection}{wxlistboxgetselection},\rtfsp | |
245 | \helpref{wxListBox::GetSelections}{wxlistboxgetselections},\rtfsp | |
246 | \helpref{wxListBox::SetSelection}{wxlistboxsetselection} | |
247 | ||
248 | \membersection{wxListBox::Number}\label{wxlistboxnumber} | |
249 | ||
250 | \constfunc{int}{Number}{\void} | |
251 | ||
252 | Returns the number of items in the listbox. | |
253 | ||
254 | \membersection{wxListBox::Selected}\label{wxlistboxselected} | |
255 | ||
256 | \constfunc{bool}{Selected}{\param{const int}{ n}} | |
257 | ||
258 | Determines whether an item is selected. | |
259 | ||
260 | \wxheading{Parameters} | |
261 | ||
262 | \docparam{n}{The zero-based item index.} | |
263 | ||
264 | \wxheading{Return value} | |
265 | ||
266 | TRUE if the given item is selected, FALSE otherwise. | |
267 | ||
268 | \membersection{wxListBox::Set}\label{wxlistboxset} | |
269 | ||
270 | \func{void}{Set}{\param{const int}{ n}, \param{const wxString*}{ choices}} | |
271 | ||
272 | Clears the list box and adds the given strings. | |
273 | ||
274 | \wxheading{Parameters} | |
275 | ||
276 | \docparam{n}{The number of strings to set.} | |
277 | ||
278 | \docparam{choices}{An array of strings to set.} | |
279 | ||
280 | \wxheading{Remarks} | |
281 | ||
282 | Deallocate the array from the calling program | |
283 | after this function has been called. | |
284 | ||
285 | \membersection{wxListBox::SetClientData}\label{wxlistboxsetclientdata} | |
286 | ||
287 | \func{void}{SetClientData}{\param{const int}{ n}, \param{char* }{data}} | |
288 | ||
289 | Associates the given client data pointer with the given item. | |
290 | ||
291 | \wxheading{Parameters} | |
292 | ||
293 | \docparam{n}{The zero-based item index.} | |
294 | ||
295 | \docparam{data}{The client data to associate with the item.} | |
296 | ||
297 | \membersection{wxListBox::SetFirstItem}\label{wxlistboxsetfirstitem} | |
298 | ||
299 | \func{void}{SetFirstItem}{\param{int}{ n}} | |
300 | ||
301 | \func{void}{SetFirstItem}{\param{const wxString\& }{string}} | |
302 | ||
303 | Set the specified item to be the first visible item. | |
304 | ||
305 | \wxheading{Parameters} | |
306 | ||
307 | \docparam{n}{The zero-based item index.} | |
308 | ||
309 | \docparam{string}{The string that should be visible.} | |
310 | ||
311 | \membersection{wxListBox::SetSelection}\label{wxlistboxsetselection} | |
312 | ||
313 | \func{void}{SetSelection}{\param{const int}{ n}, \param{const bool }{select = TRUE}} | |
314 | ||
315 | Selects or deselects the given item. | |
316 | ||
317 | \wxheading{Parameters} | |
318 | ||
319 | \docparam{n}{The zero-based item index.} | |
320 | ||
321 | \docparam{select}{If TRUE, will select the item. If FALSE, will deselect it.} | |
322 | ||
323 | \membersection{wxListBox::SetString}\label{wxlistboxsetstring} | |
324 | ||
325 | \func{void}{SetString}{\param{const int}{ n}, \param{const wxString\& }{ string}} | |
326 | ||
327 | Sets the string value of an item. | |
328 | ||
329 | \wxheading{Parameters} | |
330 | ||
331 | \docparam{n}{The zero-based item index.} | |
332 | ||
333 | \docparam{string}{The string to set.} | |
334 | ||
335 | \membersection{wxListBox::SetStringSelection}\label{wxlistboxsetstringselection} | |
336 | ||
337 | \func{void}{SetStringSelection}{\param{const wxString\& }{ string}, \param{const bool}{ select = TRUE}} | |
338 | ||
339 | Sets the current selection. | |
340 | ||
341 | \wxheading{Parameters} | |
342 | ||
343 | \docparam{string}{The item to select.} | |
344 | ||
345 | \docparam{select}{If TRUE, will select the item. If FALSE, will deselect it.} | |
346 |