]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/ctrlsub.tex
escape underscores
[wxWidgets.git] / docs / latex / wx / ctrlsub.tex
CommitLineData
243dbf1a 1%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
bed5584e
VZ
2%% Name: ctrlsub.tex
3%% Purpose: wxControlWithItems documentation
4%% Author: Vadim Zeitlin
5%% Modified by:
6%% Created: 01.01.03
7%% RCS-ID: $Id$
8%% Copyright: (c) 2003 Vadim Zeitlin
8795498c 9%% License: wxWindows license
243dbf1a 10%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
bed5584e
VZ
11
12\section{\class{wxControlWithItems}}\label{wxcontrolwithitems}
13
fc2171bd 14This class is an abstract base class for some wxWidgets controls which contain
afbe150a
WS
15several items, such as \helpref{wxListBox}{wxlistbox} and
16\helpref{wxCheckListBox}{wxchecklistbox} derived from it,
bed5584e
VZ
17\helpref{wxChoice}{wxchoice} and \helpref{wxComboBox}{wxcombobox}.
18
19It defines the methods for accessing the controls items and although each of
20the derived classes implements them differently, they still all conform to the
21same interface.
22
154b6b0f 23The items in a wxControlWithItems have (non-empty) string labels and,
bed5584e
VZ
24optionally, client data associated with them. Client data may be of two
25different kinds: either simple untyped ({\tt void *}) pointers which are simply
26stored by the control but not used in any way by it, or typed pointers
27({\tt wxClientData *}) which are owned by the control meaning that the typed
afbe150a
WS
28client data (and only it) will be deleted when an item is
29\helpref{deleted}{wxcontrolwithitemsdelete} or the entire control is
bed5584e
VZ
30\helpref{cleared}{wxcontrolwithitemsclear} (which also happens when it is
31destroyed). Finally note that in the same control all items must have client
32data of the same type (typed or untyped), if any. This type is determined by
33the first call to \helpref{Append}{wxcontrolwithitemsappend} (the version with
34client data pointer) or \helpref{SetClientData}{wxcontrolwithitemssetclientdata}.
35
36\wxheading{Derived from}
37
38\helpref{wxControl}{wxcontrol}\\
39\helpref{wxWindow}{wxwindow}\\
40\helpref{wxEvtHandler}{wxevthandler}\\
41\helpref{wxObject}{wxobject}
42
43\wxheading{Include files}
44
45<wx/ctrlsub.h> but usually never included directly
46
47\latexignore{\rtfignore{\wxheading{Members}}}
48
49\membersection{wxControlWithItems::Append}\label{wxcontrolwithitemsappend}
50
51\func{int}{Append}{\param{const wxString\& }{ item}}
52
53Adds the item to the end of the list box.
54
55\func{int}{Append}{\param{const wxString\& }{ item}, \param{void *}{clientData}}
56
57\func{int}{Append}{\param{const wxString\& }{ item}, \param{wxClientData *}{clientData}}
58
59Adds the item to the end of the list box, associating the given, typed or
60untyped, client data pointer with the item.
61
62\func{void}{Append}{\param{const wxArrayString\& }{strings}}
63
a236aa20
VZ
64\func{void}{Append}{\param{unsigned int }{n},\param{const wxString* }{strings}}
65
66\func{void}{Append}{\param{unsigned int }{n},\param{const wxString* }{strings}, \param{void **}{clientData}}
67
68\func{void}{Append}{\param{unsigned int }{n},\param{const wxString* }{strings}, \param{wxClientData **}{clientData}}
69
bed5584e 70Appends several items at once to the control. Notice that calling this method
a236aa20 71is usually much faster than appending them one by one if you need to add a lot
bed5584e
VZ
72of items.
73
74\wxheading{Parameters}
75
76\docparam{item}{String to add.}
77
a236aa20
VZ
78\docparam{stringsArray}{Contains items to append to the control.}
79
80\docparam{strings}{Array of strings of size \arg{n}.}
81
82\docparam{n}{Number of items in the \arg{strings} array.}
83
84\docparam{clientData}{Array of client data pointers of size \arg{n} to associate with the new items.}
bed5584e
VZ
85
86\wxheading{Return value}
87
88When appending a single item, the return value is the index of the newly added
89item which may be different from the last one if the control is sorted (e.g.
90has {\tt wxLB\_SORT} or {\tt wxCB\_SORT} style).
91
92\membersection{wxControlWithItems::Clear}\label{wxcontrolwithitemsclear}
93
94\func{void}{Clear}{\void}
95
96Removes all items from the control.
97
98{\it Clear()} also deletes the client data of the existing items if it is owned
99by the control.
100
101\membersection{wxControlWithItems::Delete}\label{wxcontrolwithitemsdelete}
102
aa61d352 103\func{void}{Delete}{\param{unsigned int}{ n}}
bed5584e
VZ
104
105Deletes an item from the control. The client data associated with the item
106will be also deleted if it is owned by the control.
107
108Note that it is an error (signalled by an assert failure in debug builds) to
109remove an item with the index negative or greater or equal than the number of
110items in the control.
111
112\wxheading{Parameters}
113
114\docparam{n}{The zero-based item index.}
115
116\wxheading{See also}
117
118\helpref{Clear}{wxcontrolwithitemsclear}
119
120\membersection{wxControlWithItems::FindString}\label{wxcontrolwithitemsfindstring}
121
f7c40316 122\func{int}{FindString}{\param{const wxString\& }{string}, \param{bool}{ caseSensitive = false}}
bed5584e
VZ
123
124Finds an item whose label matches the given string.
125
126\wxheading{Parameters}
127
128\docparam{string}{String to find.}
129
f7c40316
WS
130\docparam{caseSensitive}{Whether search is case sensitive (default is not).}
131
bed5584e
VZ
132\wxheading{Return value}
133
134The zero-based position of the item, or {\tt wxNOT\_FOUND} if the string was
135not found.
136
137
138\membersection{wxControlWithItems::GetClientData}\label{wxcontrolwithitemsgetclientdata}
139
aa61d352 140\constfunc{void *}{GetClientData}{\param{unsigned int}{ n}}
bed5584e
VZ
141
142Returns a pointer to the client data associated with the given item (if any).
143It is an error to call this function for a control which doesn't have untyped
144client data at all although it is ok to call it even if the given item doesn't
145have any client data associated with it (but other items do).
146
147\wxheading{Parameters}
148
149\docparam{n}{The zero-based position of the item.}
150
151\wxheading{Return value}
152
153A pointer to the client data, or {\tt NULL} if not present.
154
155
156\membersection{wxControlWithItems::GetClientObject}\label{wxcontrolwithitemsgetclientobject}
157
aa61d352 158\constfunc{wxClientData *}{GetClientObject}{\param{unsigned int}{ n}}
bed5584e
VZ
159
160Returns a pointer to the client data associated with the given item (if any).
161It is an error to call this function for a control which doesn't have typed
162client data at all although it is ok to call it even if the given item doesn't
163have any client data associated with it (but other items do).
164
165\wxheading{Parameters}
166
167\docparam{n}{The zero-based position of the item.}
168
169\wxheading{Return value}
170
171A pointer to the client data, or {\tt NULL} if not present.
172
173
174\membersection{wxControlWithItems::GetCount}\label{wxcontrolwithitemsgetcount}
175
aa61d352 176\constfunc{unsigned int}{GetCount}{\void}
bed5584e
VZ
177
178Returns the number of items in the control.
179
180\wxheading{See also}
181
182\helpref{IsEmpty}{wxcontrolwithitemsisempty}
183
184
185\membersection{wxControlWithItems::GetSelection}\label{wxcontrolwithitemsgetselection}
186
187\constfunc{int}{GetSelection}{\void}
188
189Returns the index of the selected item or {\tt wxNOT\_FOUND} if no item is
190selected.
191
192\wxheading{Return value}
193
194The position of the current selection.
195
196\wxheading{Remarks}
197
afbe150a 198This method can be used with single selection list boxes only, you should use
bed5584e
VZ
199\helpref{wxListBox::GetSelections}{wxlistboxgetselections} for the list boxes
200with {\tt wxLB\_MULTIPLE} style.
201
202\wxheading{See also}
203
204\helpref{SetSelection}{wxcontrolwithitemssetselection},\rtfsp
205\helpref{GetStringSelection}{wxcontrolwithitemsgetstringselection}
206
207
208\membersection{wxControlWithItems::GetString}\label{wxcontrolwithitemsgetstring}
209
aa61d352 210\constfunc{wxString}{GetString}{\param{unsigned int}{ n}}
bed5584e
VZ
211
212Returns the label of the item with the given index.
213
214\wxheading{Parameters}
215
216\docparam{n}{The zero-based index.}
217
218\wxheading{Return value}
219
220The label of the item or an empty string if the position was invalid.
221
222
003fa4a7
VZ
223\membersection{wxControlWithItems::GetStrings}\label{wxcontrolwithitemsgetstrings}
224
225\constfunc{wxArrayString}{GetStrings}{\void}
226
227Returns the array of the labels of all items in the control.
228
229
bed5584e
VZ
230\membersection{wxControlWithItems::GetStringSelection}\label{wxcontrolwithitemsgetstringselection}
231
232\constfunc{wxString}{GetStringSelection}{\void}
233
234Returns the label of the selected item or an empty string if no item is
235selected.
236
237\wxheading{See also}
238
239\helpref{GetSelection}{wxcontrolwithitemsgetselection}
240
241
243dbf1a
VZ
242\membersection{wxControlWithItems::Insert}\label{wxcontrolwithitemsinsert}
243
aa61d352 244\func{int}{Insert}{\param{const wxString\& }{ item}, \param{unsigned int }{pos}}
243dbf1a
VZ
245
246Inserts the item into the list before pos.
247Not valid for {\tt wxLB\_SORT} or {\tt wxCB\_SORT} styles, use Append instead.
248
aa61d352 249\func{int}{Insert}{\param{const wxString\& }{ item}, \param{unsigned int }{pos}, \param{void *}{clientData}}
243dbf1a 250
aa61d352 251\func{int}{Insert}{\param{const wxString\& }{ item}, \param{unsigned int }{pos}, \param{wxClientData *}{clientData}}
243dbf1a
VZ
252
253Inserts the item into the list before pos, associating the given, typed or
254untyped, client data pointer with the item.
255Not valid for {\tt wxLB\_SORT} or {\tt wxCB\_SORT} styles, use Append instead.
256
a236aa20
VZ
257\func{void}{Insert}{\param{const wxArrayString\& }{strings}, \param{unsigned int }{pos}}
258
259\func{void}{Insert}{\param{const wxArrayString\& }{strings}, \param{unsigned int }{pos}}
260
261\func{void}{Insert}{\param{unsigned int }{n},\param{const wxString* }{strings}, \param{unsigned int }{pos}}
262
263\func{void}{Insert}{\param{unsigned int }{n},\param{const wxString* }{strings}, \param{unsigned int }{pos}, \param{void **}{clientData}}
264
265\func{void}{Insert}{\param{unsigned int }{n},\param{const wxString* }{strings}, \param{unsigned int }{pos}, \param{wxClientData **}{clientData}}
266
267Inserts several items at once into the control. Notice that calling this method
268is usually much faster than inserting them one by one if you need to insert a lot
269of items.
270
271
243dbf1a
VZ
272\wxheading{Parameters}
273
274\docparam{item}{String to add.}
275
276\docparam{pos}{Position to insert item before, zero based.}
277
a236aa20
VZ
278\docparam{stringsArray}{Contains items to insert into the control content}
279
280\docparam{strings}{Array of strings of size \arg{n}.}
281
282\docparam{n}{Number of items in the \arg{strings} array.}
283
284\docparam{clientData}{Array of client data pointers of size \arg{n} to associate with the new items.}
243dbf1a
VZ
285
286\wxheading{Return value}
287
288The return value is the index of the newly inserted item. If the insertion failed
289for some reason, -1 is returned.
290
291
bed5584e
VZ
292\membersection{wxControlWithItems::IsEmpty}\label{wxcontrolwithitemsisempty}
293
294\constfunc{bool}{IsEmpty}{\void}
295
cc81d32f 296Returns {\tt true} if the control is empty or {\tt false} if it has some items.
bed5584e
VZ
297
298\wxheading{See also}
299
300\helpref{GetCount}{wxcontrolwithitemsgetcount}
301
302
c6179a84
VZ
303\membersection{wxControlWithItems::Select}\label{wxcontrolwithitemsselect}
304
305\func{void}{Select}{\param{int}{ n}}
306
307This is the same as \helpref{SetSelection}{wxcontrolwithitemssetselection} and
308exists only because it is slightly more natural for controls which support
309multiple selection.
310
311
a236aa20
VZ
312\membersection{wxControlWithItems::Set}\label{wxcontrolwithitemsset}
313
314\func{int}{Set}{\param{const wxString\& }{ item}}
315
316\func{int}{Set}{\param{const wxString\& }{ item}, \param{void *}{clientData}}
317
318\func{int}{Set}{\param{const wxString\& }{ item}, \param{wxClientData *}{clientData}}
319
320Replace control items with the (only) item specified, associating the typed or
321untyped client data pointer with it if given.
322
323\func{void}{Set}{\param{const wxArrayString\& }{stringsArray}}
324
325\func{void}{Set}{\param{unsigned int }{n},\param{const wxString* }{strings}}
326
327\func{void}{Set}{\param{unsigned int }{n},\param{const wxString* }{strings}, \param{void **}{clientData}}
328
329\func{void}{Set}{\param{unsigned int }{n},\param{const wxString* }{strings}, \param{wxClientData **}{clientData}}
330
331Replaces the current control contents with the given items. Notice that calling
332this method is much faster than appending the items one by one if you need to
333append a lot of them.
334
335\wxheading{Parameters}
336
337\docparam{item}{The single item to insert into the control.}
338
339\docparam{stringsArray}{Contains items to set as control content.}
340
341\docparam{strings}{Raw C++ array of strings. Only used in conjunction with 'n'.}
342
343\docparam{n}{Number of items passed in 'strings'. Only used in conjunction with 'strings'.}
344
345\docparam{clientData}{Client data to associate with the item(s).}
346
347\wxheading{Return value}
348
349When the control is sorted (e.g. has {\tt wxLB\_SORT} or {\tt wxCB\_SORT} style)
350the return value could be different from (GetCount() - 1).
351When setting a single item to the container, the return value is the index of the
352newly added item which may be different from the last one if the control is sorted
353(e.g. has {\tt wxLB\_SORT} or {\tt wxCB\_SORT} style).
354
355By default this method subsequently calls \helpref{Clear}{wxcontrolwithitemsclear}
356and \helpref{Append}{wxcontrolwithitemsappend}.
357
358
bed5584e
VZ
359\membersection{wxControlWithItems::SetClientData}\label{wxcontrolwithitemssetclientdata}
360
aa61d352 361\func{void}{SetClientData}{\param{unsigned int}{ n}, \param{void *}{data}}
bed5584e
VZ
362
363Associates the given untyped client data pointer with the given item. Note that
364it is an error to call this function if any typed client data pointers had been
365associated with the control items before.
366
367\wxheading{Parameters}
368
369\docparam{n}{The zero-based item index.}
370
371\docparam{data}{The client data to associate with the item.}
372
373
374\membersection{wxControlWithItems::SetClientObject}\label{wxcontrolwithitemssetclientobject}
375
aa61d352 376\func{void}{SetClientObject}{\param{unsigned int}{ n}, \param{wxClientData *}{data}}
bed5584e 377
afbe150a 378Associates the given typed client data pointer with the given item: the
bed5584e
VZ
379{\it data} object will be deleted when the item is deleted (either explicitly
380by using \helpref{Deletes}{wxcontrolwithitemsdelete} or implicitly when the
381control itself is destroyed).
382
383Note that it is an error to call this function if any untyped client data
384pointers had been associated with the control items before.
385
386\wxheading{Parameters}
387
388\docparam{n}{The zero-based item index.}
389
390\docparam{data}{The client data to associate with the item.}
391
392
393\membersection{wxControlWithItems::SetSelection}\label{wxcontrolwithitemssetselection}
394
395\func{void}{SetSelection}{\param{int}{ n}}
396
26f2b058 397Sets the selection to the given item \arg{n} or removes the selection entirely
a8d08dbd 398if \arg{n} $==$ {\tt wxNOT\_FOUND}.
26f2b058 399
c6179a84
VZ
400Note that this does not cause any command events to be emitted nor does it
401deselect any other items in the controls which support multiple selections.
bed5584e
VZ
402
403\wxheading{Parameters}
404
405\docparam{n}{The string position to select, starting from zero.}
406
407\wxheading{See also}
408
409\helpref{SetString}{wxcontrolwithitemssetstring},\rtfsp
410\helpref{SetStringSelection}{wxcontrolwithitemssetstringselection}
411
412
413\membersection{wxControlWithItems::SetString}\label{wxcontrolwithitemssetstring}
414
aa61d352 415\func{void}{SetString}{\param{unsigned int}{ n}, \param{const wxString\& }{ string}}
bed5584e
VZ
416
417Sets the label for the given item.
418
419\wxheading{Parameters}
420
421\docparam{n}{The zero-based item index.}
422
423\docparam{string}{The label to set.}
424
425
426\membersection{wxControlWithItems::SetStringSelection}\label{wxcontrolwithitemssetstringselection}
427
64fa6f16 428\func{bool}{SetStringSelection}{\param{const wxString\& }{ string}}
bed5584e
VZ
429
430Selects the item with the specified string in the control. This doesn't cause
fab86f26 431any command events to be emitted.
bed5584e
VZ
432
433\wxheading{Parameters}
434
435\docparam{string}{The string to select.}
436
64fa6f16
VZ
437\wxheading{Return value}
438
439\true if the specified string has been selected, \false if it wasn't found in
440the control.
441
bed5584e
VZ
442\wxheading{See also}
443
444\helpref{SetSelection}{wxcontrolwithitemssetselection}
b67a86d5 445