]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/vlbox.tex
many wxItemContainer-related changes:
[wxWidgets.git] / docs / latex / wx / vlbox.tex
CommitLineData
e0c6027b
VZ
1%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2%% Name: vlbox.tex
3%% Purpose: wxVListBox documentation
4%% Author: Vadim Zeitlin
5%% Modified by:
6%% Created: 01.06.03
7%% RCS-ID: $Id$
8%% Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwindows.org>
8795498c 9%% License: wxWindows license
e0c6027b
VZ
10%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
11
12\section{\class{wxVListBox}}\label{wxvlistbox}
13
14wxVListBox is a listbox-like control with the following two main differences
15from a regular listbox: it can have an arbitrarily huge number of items because
410bfc93 16it doesn't store them itself but uses \helpref{OnDrawItem()}{wxvlistboxondrawitem}
e0c6027b 17callback to draw them (so it is a {\Large V}irtual listbox) and its items can
410bfc93 18have variable height as determined by
e0c6027b
VZ
19\helpref{OnMeasureItem()}{wxvlistboxonmeasureitem} (so it is also a listbox
20with the lines of {\Large V}ariable height).
21
22Also, as a consequence of its virtual nature, it doesn't have any methods to
23append or insert items in it as it isn't necessary to do it: you just have to
24call \helpref{SetItemCount()}{wxvlistboxsetitemcount} to tell the control how
25many items it should display. Of course, this also means that you will never
26use this class directly because it has pure virtual functions, but will need to
27derive your own class, such as \helpref{wxHtmlListBox}{wxhtmllistbox}, from it.
28
29However it emits the same events as \helpref{wxListBox}{wxlistbox} and the same
2fe90784
RR
30event macros may be used with it. Since wxVListBox does not store its items
31itself, the events will only contain the index, not any contents such as the
32string of an item.
410bfc93 33
e0c6027b
VZ
34\wxheading{Derived from}
35
410bfc93
WS
36\helpref{wxVScrolledWindow}{wxvscrolledwindow}\\
37\helpref{wxPanel}{wxpanel}\\
38\helpref{wxWindow}{wxwindow}\\
39\helpref{wxEvtHandler}{wxevthandler}\\
40\helpref{wxObject}{wxobject}
e0c6027b
VZ
41
42\wxheading{Include files}
43
44<wx/vlbox.h>
45
9ebb7cad
VZ
46\wxheading{See also}
47
48\helpref{wxSimpleHtmlListBox}{wxsimplehtmllistbox}, \helpref{wxHtmlListBox}{wxhtmllistbox}
49
e0c6027b
VZ
50\latexignore{\rtfignore{\wxheading{Members}}}
51
52
53\membersection{wxVListBox::wxVListBox}\label{wxvlistboxctor}
54
55\func{}{wxVListBox}{\param{wxWindow* }{parent}, \param{wxWindowID }{id = wxID\_ANY}, \param{const wxPoint\& }{pos = wxDefaultPosition}, \param{const wxSize\& }{size = wxDefaultSize}, \param{size\_t }{countItems = 0}, \param{long }{style = 0}, \param{const wxString\& }{name = wxVListBoxNameStr}}
56
57Normal constructor which calls \helpref{Create()}{wxvlistboxcreate} internally.
58
59\func{}{wxVListBox}{\void}
60
61Default constructor, you must call \helpref{Create()}{wxvlistboxcreate} later.
62
63
64\membersection{wxVListBox::Clear}\label{wxvlistboxclear}
65
66\func{void}{Clear}{\void}
67
68Deletes all items from the control.
69
70
71\membersection{wxVListBox::Create}\label{wxvlistboxcreate}
72
0063c169 73\func{bool}{Create}{\param{wxWindow* }{parent}, \param{wxWindowID }{id = wxID\_ANY}, \param{const wxPoint\& }{pos = wxDefaultPosition}, \param{const wxSize\& }{size = wxDefaultSize}, \param{long }{style = 0}, \param{const wxString\& }{name = wxVListBoxNameStr}}
e0c6027b 74
410bfc93 75Creates the control. To finish creating it you also should call
0063c169
VZ
76\helpref{SetItemCount()}{wxvlistboxsetitemcount} to let it know about the
77number of items it contains.
e0c6027b 78
410bfc93 79The only special style which may be used with wxVListBox is {\tt wxLB\_MULTIPLE}
0063c169 80which indicates that the listbox should support multiple selection.
e0c6027b
VZ
81
82Returns {\tt true} on success or {\tt false} if the control couldn't be created
83
84
0063c169
VZ
85\membersection{wxVListBox::DeselectAll}\label{wxvlistboxdeselectall}
86
87\func{bool}{DeselectAll}{\void}
88
89Deselects all the items in the listbox.
90
91Returns {\tt true} if any items were changed, i.e. if there had been any
92selected items before, or {\tt false} if all the items were already deselected.
93
94This method is only valid for multi selection listboxes.
95
96\wxheading{See also}
97
98\helpref{SelectAll}{wxvlistboxselectall}, \helpref{Select}{wxvlistboxselect}
99
100
101\membersection{wxVListBox::GetFirstSelected}\label{wxvlistboxgetfirstselected}
102
103\constfunc{int}{GetFirstSelected}{\param{unsigned long\& }{cookie}}
104
410bfc93 105Returns the index of the first selected item in the listbox or
0063c169
VZ
106{\tt wxNOT\_FOUND} if no items are currently selected.
107
b52401b2 108\arg{cookie} is an opaque parameter which should be passed to the subsequent
0063c169
VZ
109calls to \helpref{GetNextSelected}{wxvlistboxgetnextselected}. It is needed in
110order to allow parallel iterations over the selected items.
111
112Here is a typical example of using these functions:
113\begin{verbatim}
114unsigned long cookie;
115int item = hlbox->GetFirstSelected(cookie);
116while ( item != wxNOT_FOUND )
117{
118 ... process item ...
119 item = hlbox->GetNextSelected(cookie);
120}
121\end{verbatim}
122
123This method is only valid for multi selection listboxes.
124
125
e0c6027b
VZ
126\membersection{wxVListBox::GetItemCount}\label{wxvlistboxgetitemcount}
127
128\constfunc{size\_t}{GetItemCount}{\void}
129
130Get the number of items in the control.
131
132\wxheading{See also}
133
134\helpref{SetItemCount()}{wxvlistboxsetitemcount}
135
136
0063c169
VZ
137\membersection{wxVListBox::GetMargins}\label{wxvlistboxgetmargins}
138
139\constfunc{wxPoint}{GetMargins}{\void}
140
141Returns the margins used by the control. The {\tt x} field of the returned
dbd94b75 142point is the horizontal margin and the {\tt y} field is the vertical one.
0063c169
VZ
143
144\wxheading{See also}
145
146\helpref{SetMargins}{wxvlistboxsetmargins}
147
148
149\membersection{wxVListBox::GetNextSelected}\label{wxvlistboxgetnextselected}
150
151\constfunc{int}{GetNextSelected}{\param{unsigned long\& }{cookie}}
152
153Returns the index of the next selected item or {\tt wxNOT\_FOUND} if there are
154no more.
155
156This method is only valid for multi selection listboxes.
157
158\wxheading{See also}
159
160\helpref{GetFirstSelected}{wxvlistboxgetfirstselected}
161
162
163\membersection{wxVListBox::GetSelectedCount}\label{wxvlistboxgetselectedcount}
164
165\constfunc{size\_t}{GetSelectedCount}{\void}
166
167Returns the number of the items currently selected.
168
169It is valid for both single and multi selection controls. In the former case it
170may only return $0$ or $1$ however.
171
172\wxheading{See also}
173
174\helpref{IsSelected}{wxvlistboxisselected},\\
175\helpref{GetFirstSelected}{wxvlistboxgetfirstselected},\\
176\helpref{GetNextSelected}{wxvlistboxgetnextselected}
177
178
e0c6027b
VZ
179\membersection{wxVListBox::GetSelection}\label{wxvlistboxgetselection}
180
181\constfunc{int}{GetSelection}{\void}
182
410bfc93 183Get the currently selected item or {\tt wxNOT\_FOUND} if there is no selection.
e0c6027b
VZ
184
185
de5d3a20
VZ
186\membersection{wxVListBox::GetSelectionBackground}\label{wxvlistboxgetselectionbackground}
187
188\constfunc{const wxColour\&}{GetSelectionBackground}{\void}
189
190Returns the background colour used for the selected cells. By default the
191standard system colour is used.
192
193\wxheading{See also}
194
195\helpref{wxSystemSettings::GetColour}{wxsystemsettingsgetcolour},\\
196\helpref{SetSelectionBackground}{wxvlistboxsetselectionbackground}
197
198
0063c169
VZ
199\membersection{wxVListBox::HasMultipleSelection}\label{wxvlistboxishasmultipleselection}
200
201\constfunc{bool}{HasMultipleSelection}{\void}
202
203Returns {\tt true} if the listbox was created with {\tt wxLB\_MULTIPLE} style
204and so supports multiple selection or {\tt false} if it is a single selection
205listbox.
206
207
208\membersection{wxVListBox::IsCurrent}\label{wxvlistboxiscurrent}
209
210\constfunc{bool}{IsCurrent}{\param{size\_t }{item}}
211
212Returns {\tt true} if this item is the current one, {\tt false} otherwise.
213
214Current item is always the same as selected one for the single selection
410bfc93 215listbox and in this case this method is equivalent to
0063c169
VZ
216\helpref{IsSelected}{wxvlistboxisselected} but they are different for multi
217selection listboxes where many items may be selected but only one (at most) is
218current.
219
220
e0c6027b
VZ
221\membersection{wxVListBox::IsSelected}\label{wxvlistboxisselected}
222
0063c169 223\constfunc{bool}{IsSelected}{\param{size\_t }{item}}
e0c6027b
VZ
224
225Returns {\tt true} if this item is selected, {\tt false} otherwise.
226
227
b52401b2
VZ
228\membersection{wxVListBox::OnDrawBackground}\label{wxvlistboxondrawbackground}
229
230\constfunc{void}{OnDrawBackground}{\param{wxDC\& }{dc}, \param{const wxRect\& }{rect}, \param{size\_t }{n}}
231
232This method is used to draw the items background and, maybe, a border
233around it.
234
235The base class version implements a reasonable default behaviour which
236consists in drawing the selected item with the standard background
237colour and drawing a border around the item if it is either selected or
238current.
239
240
e0c6027b
VZ
241\membersection{wxVListBox::OnDrawItem}\label{wxvlistboxondrawitem}
242
243\constfunc{void}{OnDrawItem}{\param{wxDC\& }{dc}, \param{const wxRect\& }{rect}, \param{size\_t }{n}}
244
245The derived class must implement this function to actually draw the item
246with the given index on the provided DC.
247
248\wxheading{Parameters}
249
250\docparam{dc}{The device context to use for drawing}
251
252\docparam{rect}{The bounding rectangle for the item being drawn (DC clipping
253region is set to this rectangle before calling this function)}
254
255\docparam{n}{The index of the item to be drawn}
256
257
258\membersection{wxVListBox::OnDrawSeparator}\label{wxvlistboxondrawseparator}
259
260\constfunc{void}{OnDrawSeparator}{\param{wxDC\& }{dc}, \param{wxRect\& }{rect}, \param{size\_t }{n}}
261
262This method may be used to draw separators between the lines. The rectangle
263passed to it may be modified, typically to deflate it a bit before passing to
264\helpref{OnDrawItem()}{wxvlistboxondrawitem}.
265
266The base class version of this method doesn't do anything.
267
268\wxheading{Parameters}
269
270\docparam{dc}{The device context to use for drawing}
271
272\docparam{rect}{The bounding rectangle for the item}
273
274\docparam{n}{The index of the item}
275
276
277\membersection{wxVListBox::OnMeasureItem}\label{wxvlistboxonmeasureitem}
278
279\constfunc{wxCoord}{OnMeasureItem}{\param{size\_t }{n}}
280
281The derived class must implement this method to return the height of the
282specified item (in pixels).
283
284
0063c169
VZ
285\membersection{wxVListBox::Select}\label{wxvlistboxselect}
286
287\func{bool}{Select}{\param{size\_t }{item}, \param{bool }{select = true}}
288
289Selects or deselects the specified item which must be valid (i.e. not
290equal to {\tt wxNOT\_FOUND}).
291
292Return {\tt true} if the items selection status has changed or {\tt false}
293otherwise.
294
410bfc93 295This function is only valid for the multiple selection listboxes, use
0063c169
VZ
296\helpref{SetSelection}{wxvlistboxsetselection} for the single selection ones.
297
298
299\membersection{wxVListBox::SelectAll}\label{wxvlistboxselectall}
300
301\func{bool}{SelectAll}{\void}
302
303Selects all the items in the listbox.
304
305Returns {\tt true} if any items were changed, i.e. if there had been any
306unselected items before, or {\tt false} if all the items were already selected.
307
308This method is only valid for multi selection listboxes.
309
310\wxheading{See also}
311
312\helpref{DeselectAll}{wxvlistboxdeselectall}, \helpref{Select}{wxvlistboxselect}
313
314
315\membersection{wxVListBox::SelectRange}\label{wxvlistboxselectrange}
316
317\func{bool}{SelectRange}{\param{size\_t }{from}, \param{size\_t }{to}}
318
319Selects all items in the specified range which may be given in any order.
320
321Return {\tt true} if the items selection status has changed or {\tt false}
322otherwise.
323
324This method is only valid for multi selection listboxes.
325
326\wxheading{See also}
327
328\helpref{SelectAll}{wxvlistboxselectall}, \helpref{Select}{wxvlistboxselect}
329
684761db 330\membersection{wxVListBox::SetItemCount}\label{wxvlistboxsetitemcount}
e0c6027b
VZ
331
332\func{void}{SetItemCount}{\param{size\_t }{count}}
333
334Set the number of items to be shown in the control.
335
336This is just a synonym for
b1fd5b35 337\helpref{wxVScrolledWindow::SetRowCount()}{wxvarvscrollhelpersetrowcount}.
e0c6027b
VZ
338
339
340\membersection{wxVListBox::SetMargins}\label{wxvlistboxsetmargins}
341
342\func{void}{SetMargins}{\param{const wxPoint\& }{pt}}
343
344\func{void}{SetMargins}{\param{wxCoord }{x}, \param{wxCoord }{y}}
345
346Set the margins: horizontal margin is the distance between the window
347border and the item contents while vertical margin is half of the
348distance between items.
349
350By default both margins are $0$.
351
352
353\membersection{wxVListBox::SetSelection}\label{wxvlistboxsetselection}
354
355\func{void}{SetSelection}{\param{int }{selection}}
356
357Set the selection to the specified item, if it is $-1$ the selection is
358unset. The selected item will be automatically scrolled into view if it isn't
359currently visible.
360
de5d3a20
VZ
361This method may be used both with single and multiple selection listboxes.
362
363
364\membersection{wxVListBox::SetSelectionBackground}\label{wxvlistboxsetselectionbackground}
365
366\func{void}{SetSelectionBackground}{\param{const wxColour\& }{col}}
367
368Sets the colour to be used for the selected cells background. The background of
410bfc93 369the standard cells may be changed by simply calling
de5d3a20
VZ
370\helpref{SetBackgroundColour}{wxwindowsetbackgroundcolour}.
371
63e02796
VZ
372Notice that using non-default background colour may result in control having
373appearance different from the similar native controls and so should in general
374be avoided.
375
de5d3a20
VZ
376\wxheading{See also}
377
378\helpref{GetSelectionBackground}{wxvlistboxgetselectionbackground}
379
0063c169
VZ
380
381\membersection{wxVListBox::Toggle}\label{wxvlistboxtoggle}
382
383\func{void}{Toggle}{\param{size\_t }{item}}
384
b52401b2 385Toggles the state of the specified \arg{item}, i.e. selects it if it was
0063c169
VZ
386unselected and deselects it if it was selected.
387
388This method is only valid for multi selection listboxes.
389
390\wxheading{See also}
391
392\helpref{Select}{wxvlistboxselect}
b67a86d5 393