]> git.saurik.com Git - wxWidgets.git/blob - docs/latex/wx/listbox.tex
more LaTeX error fixes
[wxWidgets.git] / docs / latex / wx / listbox.tex
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. Their number may be limited
11 under some platforms.
12
13 A listbox callback gets an event wxEVT\_COMMAND\_LISTBOX\_SELECTED for single clicks, and
14 wxEVT\_COMMAND\_LISTBOX\_DOUBLE\_CLICKED for double clicks.
15
16 \wxheading{Derived from}
17
18 \helpref{wxControlWithItems}{wxcontrolwithitems}\\
19 \helpref{wxControl}{wxcontrol}\\
20 \helpref{wxWindow}{wxwindow}\\
21 \helpref{wxEvtHandler}{wxevthandler}\\
22 \helpref{wxObject}{wxobject}
23
24 \wxheading{Include files}
25
26 <wx/listbox.h>
27
28 \wxheading{Library}
29
30 \helpref{wxCore}{librarieslist}
31
32 \wxheading{Window styles}
33
34 \twocolwidtha{5cm}%
35 \begin{twocollist}\itemsep=0pt
36 \twocolitem{\windowstyle{wxLB\_SINGLE}}{Single-selection list.}
37 \twocolitem{\windowstyle{wxLB\_MULTIPLE}}{Multiple-selection list: the user can toggle multiple
38 items on and off.}
39 \twocolitem{\windowstyle{wxLB\_EXTENDED}}{Extended-selection list: the user can
40 select multiple items using the SHIFT key and the mouse or special key combinations.}
41 \twocolitem{\windowstyle{wxLB\_HSCROLL}}{Create horizontal scrollbar if contents are too wide (Windows only).}
42 \twocolitem{\windowstyle{wxLB\_ALWAYS\_SB}}{Always show a vertical scrollbar.}
43 \twocolitem{\windowstyle{wxLB\_NEEDED\_SB}}{Only create a vertical scrollbar if needed.}
44 \twocolitem{\windowstyle{wxLB\_SORT}}{The listbox contents are sorted in alphabetical order.}
45 \end{twocollist}
46
47 Note that {\tt wxLB\_SINGLE}, {\tt wxLB\_MULTIPLE} and {\tt wxLB\_EXTENDED}
48 styles are mutually exclusive and you can specify at most one of them (single
49 selection is the default).
50
51 See also \helpref{window styles overview}{windowstyles}.
52
53 \wxheading{Event handling}
54
55 \twocolwidtha{7cm}
56 \begin{twocollist}\itemsep=0pt
57 \twocolitem{{\bf EVT\_LISTBOX(id, func)}}{Process a wxEVT\_COMMAND\_LISTBOX\_SELECTED event,
58 when an item on the list is selected or the selection changes.}
59 \twocolitem{{\bf EVT\_LISTBOX\_DCLICK(id, func)}}{Process a wxEVT\_COMMAND\_LISTBOX\_DOUBLECLICKED event,
60 when the listbox is double-clicked.}
61 \end{twocollist}
62
63 \wxheading{See also}
64
65 \helpref{wxChoice}{wxchoice}, \helpref{wxComboBox}{wxcombobox}, \helpref{wxListCtrl}{wxlistctrl},
66 \rtfsp\helpref{wxCommandEvent}{wxcommandevent}
67
68 \latexignore{\rtfignore{\wxheading{Members}}}
69
70 \membersection{wxListBox::wxListBox}\label{wxlistboxctor}
71
72 \func{}{wxListBox}{\void}
73
74 Default constructor.
75
76 \func{}{wxListBox}{\param{wxWindow*}{ parent}, \param{wxWindowID}{ id},\rtfsp
77 \param{const wxPoint\&}{ pos = wxDefaultPosition}, \param{const wxSize\&}{ size = wxDefaultSize},\rtfsp
78 \param{int}{ n = 0}, \param{const wxString }{choices[] = NULL},\rtfsp
79 \param{long}{ style = 0}, \param{const wxValidator\& }{validator = wxDefaultValidator}, \param{const wxString\& }{name = ``listBox"}}
80
81 \func{}{wxListBox}{\param{wxWindow*}{ parent}, \param{wxWindowID}{ id},\rtfsp
82 \param{const wxPoint\&}{ pos}, \param{const wxSize\&}{ size},\rtfsp
83 \param{const wxArrayString\& }{choices},\rtfsp
84 \param{long}{ style = 0}, \param{const wxValidator\& }{validator = wxDefaultValidator}, \param{const wxString\& }{name = ``listBox"}}
85
86 Constructor, creating and showing a list box.
87
88 \wxheading{Parameters}
89
90 \docparam{parent}{Parent window. Must not be NULL.}
91
92 \docparam{id}{Window identifier. A value of -1 indicates a default value.}
93
94 \docparam{pos}{Window position.}
95
96 \docparam{size}{Window size. If the default size (-1, -1) is specified then the window is sized
97 appropriately.}
98
99 \docparam{n}{Number of strings with which to initialise the control.}
100
101 \docparam{choices}{An array of strings with which to initialise the control.}
102
103 \docparam{style}{Window style. See \helpref{wxListBox}{wxlistbox}.}
104
105 \docparam{validator}{Window validator.}
106
107 \docparam{name}{Window name.}
108
109 \wxheading{See also}
110
111 \helpref{wxListBox::Create}{wxlistboxcreate}, \helpref{wxValidator}{wxvalidator}
112
113 \pythonnote{The wxListBox constructor in wxPython reduces the {\tt n}
114 and {\tt choices} arguments are to a single argument, which is
115 a list of strings.}
116
117 \perlnote{In wxPerl there is just an array reference in place of {\tt n}
118 and {\tt choices}.}
119
120 \membersection{wxListBox::\destruct{wxListBox}}\label{wxlistboxdtor}
121
122 \func{void}{\destruct{wxListBox}}{\void}
123
124 Destructor, destroying the list box.
125
126 \membersection{wxListBox::Create}\label{wxlistboxcreate}
127
128 \func{bool}{Create}{\param{wxWindow*}{ parent}, \param{wxWindowID}{ id},\rtfsp
129 \param{const wxPoint\&}{ pos = wxDefaultPosition}, \param{const wxSize\&}{ size = wxDefaultSize},\rtfsp
130 \param{int}{ n}, \param{const wxString }{choices[] = NULL},\rtfsp
131 \param{long}{ style = 0}, \param{const wxValidator\& }{validator = wxDefaultValidator}, \param{const wxString\& }{name = ``listBox"}}
132
133 \func{bool}{Create}{\param{wxWindow*}{ parent}, \param{wxWindowID}{ id},\rtfsp
134 \param{const wxPoint\&}{ pos}, \param{const wxSize\&}{ size},\rtfsp
135 \param{const wxArrayString\& }{choices},\rtfsp
136 \param{long}{ style = 0}, \param{const wxValidator\& }{validator = wxDefaultValidator}, \param{const wxString\& }{name = ``listBox"}}
137
138 Creates the listbox for two-step construction. See \helpref{wxListBox::wxListBox}{wxlistboxctor}\rtfsp
139 for further details.
140
141 \membersection{wxListBox::Deselect}\label{wxlistboxdeselect}
142
143 \func{void}{Deselect}{\param{int}{ n}}
144
145 Deselects an item in the list box.
146
147 \wxheading{Parameters}
148
149 \docparam{n}{The zero-based item to deselect.}
150
151 \wxheading{Remarks}
152
153 This applies to multiple selection listboxes only.
154
155 \membersection{wxListBox::GetSelections}\label{wxlistboxgetselections}
156
157 \constfunc{int}{GetSelections}{\param{wxArrayInt\& }{selections}}
158
159 Fill an array of ints with the positions of the currently selected items.
160
161 \wxheading{Parameters}
162
163 \docparam{selections}{A reference to an wxArrayInt instance that is used to store the result of the query.}
164
165 \wxheading{Return value}
166
167 The number of selections.
168
169 \wxheading{Remarks}
170
171 Use this with a multiple selection listbox.
172
173 \wxheading{See also}
174
175 \helpref{wxControlWithItems::GetSelection}{wxcontrolwithitemsgetselection},\rtfsp
176 \helpref{wxControlWithItems::GetStringSelection}{wxcontrolwithitemsgetstringselection},\rtfsp
177 \helpref{wxControlWithItems::SetSelection}{wxcontrolwithitemssetselection}
178
179 \pythonnote{The wxPython version of this method takes no parameters
180 and returns a tuple of the selected items.}
181
182 \perlnote{In wxPerl this method takes no parameters and return the
183 selected items as a list.}
184
185 \membersection{wxListBox::InsertItems}\label{wxlistboxinsertitems}
186
187 \func{void}{InsertItems}{\param{int}{ nItems}, \param{const wxString}{ *items}, \param{unsigned int}{ pos}}
188
189 \func{void}{InsertItems}{\param{const wxArrayString\&}{ nItems}, \param{unsigned int}{ pos}}
190
191 Insert the given number of strings before the specified position.
192
193 \wxheading{Parameters}
194
195 \docparam{nItems}{Number of items in the array {\it items}}
196
197 \docparam{items}{Labels of items to be inserted}
198
199 \docparam{pos}{Position before which to insert the items: for example, if {\it pos} is 0 the items
200 will be inserted in the beginning of the listbox}
201
202 \pythonnote{The first two parameters are collapsed into a single
203 parameter for wxPython, which is a list of strings.}
204
205 \perlnote{In wxPerl there is just an array reference in place of {\tt nItems}
206 and {\tt items}.}
207
208 \membersection{wxListBox::HitTest}\label{wxlistboxhittest}
209
210 \constfunc{int}{HitTest}{\param{const wxPoint&}{ point}}
211
212 Returns the item located at \arg{point}, or \texttt{wxNOT\_FOUND} if there
213 is no item located at \arg{point}.
214
215 \newsince{2.7.0}. It is currently implemented for wxMSW, wxMac and wxGTK2
216 ports.
217
218 \wxheading{Parameters}
219
220 \docparam{point}{Point of item (in client coordinates) to obtain}
221
222 \wxheading{Return value}
223
224 Item located at \arg{point}, or \texttt{wxNOT\_FOUND} if unimplemented
225 or the item does not exist.
226
227 \membersection{wxListBox::IsSelected}\label{wxlistboxisselected}
228
229 \constfunc{bool}{IsSelected}{\param{int}{ n}}
230
231 Determines whether an item is selected.
232
233 \wxheading{Parameters}
234
235 \docparam{n}{The zero-based item index.}
236
237 \wxheading{Return value}
238
239 true if the given item is selected, false otherwise.
240
241 \membersection{wxListBox::Set}\label{wxlistboxset}
242
243 \func{void}{Set}{\param{int}{ n}, \param{const wxString*}{ choices}, \param{void}{ **clientData = {\tt NULL}}}
244
245 \func{void}{Set}{\param{const wxArrayString\&}{ choices}, \param{void}{ **clientData = {\tt NULL}}}
246
247 Clears the list box and adds the given strings to it.
248
249 \wxheading{Parameters}
250
251 \docparam{n}{The number of strings to set.}
252
253 \docparam{choices}{An array of strings to set.}
254
255 \docparam{clientData}{Options array of client data pointers}
256
257 \wxheading{Remarks}
258
259 You may free the array from the calling program after this function has been
260 called.
261
262 \membersection{wxListBox::SetFirstItem}\label{wxlistboxsetfirstitem}
263
264 \func{void}{SetFirstItem}{\param{int}{ n}}
265
266 \func{void}{SetFirstItem}{\param{const wxString\& }{string}}
267
268 Set the specified item to be the first visible item.
269
270 \wxheading{Parameters}
271
272 \docparam{n}{The zero-based item index.}
273
274 \docparam{string}{The string that should be visible.}
275