]> git.saurik.com Git - wxWidgets.git/blob - docs/latex/wx/ctrlsub.tex
many wxItemContainer-related changes:
[wxWidgets.git] / docs / latex / wx / ctrlsub.tex
1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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
9 %% License: wxWindows license
10 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
11
12 \section{\class{wxControlWithItems}}\label{wxcontrolwithitems}
13
14 This class is an abstract base class for some wxWidgets controls which contain
15 several items, such as \helpref{wxListBox}{wxlistbox} and
16 \helpref{wxCheckListBox}{wxchecklistbox} derived from it,
17 \helpref{wxChoice}{wxchoice} and \helpref{wxComboBox}{wxcombobox}.
18
19 It defines the methods for accessing the controls items and although each of
20 the derived classes implements them differently, they still all conform to the
21 same interface.
22
23 The items in a wxControlWithItems have (non-empty) string labels and,
24 optionally, client data associated with them. Client data may be of two
25 different kinds: either simple untyped ({\tt void *}) pointers which are simply
26 stored 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
28 client data (and only it) will be deleted when an item is
29 \helpref{deleted}{wxcontrolwithitemsdelete} or the entire control is
30 \helpref{cleared}{wxcontrolwithitemsclear} (which also happens when it is
31 destroyed). Finally note that in the same control all items must have client
32 data of the same type (typed or untyped), if any. This type is determined by
33 the first call to \helpref{Append}{wxcontrolwithitemsappend} (the version with
34 client 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
53 Adds 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
59 Adds the item to the end of the list box, associating the given, typed or
60 untyped, client data pointer with the item.
61
62 \func{void}{Append}{\param{const wxArrayString\& }{strings}}
63
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
70 Appends several items at once to the control. Notice that calling this method
71 is usually much faster than appending them one by one if you need to add a lot
72 of items.
73
74 \wxheading{Parameters}
75
76 \docparam{item}{String to add.}
77
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.}
85
86 \wxheading{Return value}
87
88 When appending a single item, the return value is the index of the newly added
89 item which may be different from the last one if the control is sorted (e.g.
90 has {\tt wxLB\_SORT} or {\tt wxCB\_SORT} style).
91
92 \membersection{wxControlWithItems::Clear}\label{wxcontrolwithitemsclear}
93
94 \func{void}{Clear}{\void}
95
96 Removes all items from the control.
97
98 {\it Clear()} also deletes the client data of the existing items if it is owned
99 by the control.
100
101 \membersection{wxControlWithItems::Delete}\label{wxcontrolwithitemsdelete}
102
103 \func{void}{Delete}{\param{unsigned int}{ n}}
104
105 Deletes an item from the control. The client data associated with the item
106 will be also deleted if it is owned by the control.
107
108 Note that it is an error (signalled by an assert failure in debug builds) to
109 remove an item with the index negative or greater or equal than the number of
110 items 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
122 \func{int}{FindString}{\param{const wxString\& }{string}, \param{bool}{ caseSensitive = false}}
123
124 Finds an item whose label matches the given string.
125
126 \wxheading{Parameters}
127
128 \docparam{string}{String to find.}
129
130 \docparam{caseSensitive}{Whether search is case sensitive (default is not).}
131
132 \wxheading{Return value}
133
134 The zero-based position of the item, or {\tt wxNOT\_FOUND} if the string was
135 not found.
136
137
138 \membersection{wxControlWithItems::GetClientData}\label{wxcontrolwithitemsgetclientdata}
139
140 \constfunc{void *}{GetClientData}{\param{unsigned int}{ n}}
141
142 Returns a pointer to the client data associated with the given item (if any).
143 It is an error to call this function for a control which doesn't have untyped
144 client data at all although it is ok to call it even if the given item doesn't
145 have 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
153 A pointer to the client data, or {\tt NULL} if not present.
154
155
156 \membersection{wxControlWithItems::GetClientObject}\label{wxcontrolwithitemsgetclientobject}
157
158 \constfunc{wxClientData *}{GetClientObject}{\param{unsigned int}{ n}}
159
160 Returns a pointer to the client data associated with the given item (if any).
161 It is an error to call this function for a control which doesn't have typed
162 client data at all although it is ok to call it even if the given item doesn't
163 have 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
171 A pointer to the client data, or {\tt NULL} if not present.
172
173
174 \membersection{wxControlWithItems::GetCount}\label{wxcontrolwithitemsgetcount}
175
176 \constfunc{unsigned int}{GetCount}{\void}
177
178 Returns 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
189 Returns the index of the selected item or {\tt wxNOT\_FOUND} if no item is
190 selected.
191
192 \wxheading{Return value}
193
194 The position of the current selection.
195
196 \wxheading{Remarks}
197
198 This method can be used with single selection list boxes only, you should use
199 \helpref{wxListBox::GetSelections}{wxlistboxgetselections} for the list boxes
200 with {\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
210 \constfunc{wxString}{GetString}{\param{unsigned int}{ n}}
211
212 Returns 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
220 The label of the item or an empty string if the position was invalid.
221
222
223 \membersection{wxControlWithItems::GetStrings}\label{wxcontrolwithitemsgetstrings}
224
225 \constfunc{wxArrayString}{GetStrings}{\void}
226
227 Returns the array of the labels of all items in the control.
228
229
230 \membersection{wxControlWithItems::GetStringSelection}\label{wxcontrolwithitemsgetstringselection}
231
232 \constfunc{wxString}{GetStringSelection}{\void}
233
234 Returns the label of the selected item or an empty string if no item is
235 selected.
236
237 \wxheading{See also}
238
239 \helpref{GetSelection}{wxcontrolwithitemsgetselection}
240
241
242 \membersection{wxControlWithItems::Insert}\label{wxcontrolwithitemsinsert}
243
244 \func{int}{Insert}{\param{const wxString\& }{ item}, \param{unsigned int }{pos}}
245
246 Inserts the item into the list before pos.
247 Not valid for {\tt wxLB\_SORT} or {\tt wxCB\_SORT} styles, use Append instead.
248
249 \func{int}{Insert}{\param{const wxString\& }{ item}, \param{unsigned int }{pos}, \param{void *}{clientData}}
250
251 \func{int}{Insert}{\param{const wxString\& }{ item}, \param{unsigned int }{pos}, \param{wxClientData *}{clientData}}
252
253 Inserts the item into the list before pos, associating the given, typed or
254 untyped, client data pointer with the item.
255 Not valid for {\tt wxLB\_SORT} or {\tt wxCB\_SORT} styles, use Append instead.
256
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
267 Inserts several items at once into the control. Notice that calling this method
268 is usually much faster than inserting them one by one if you need to insert a lot
269 of items.
270
271
272 \wxheading{Parameters}
273
274 \docparam{item}{String to add.}
275
276 \docparam{pos}{Position to insert item before, zero based.}
277
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.}
285
286 \wxheading{Return value}
287
288 The return value is the index of the newly inserted item. If the insertion failed
289 for some reason, -1 is returned.
290
291
292 \membersection{wxControlWithItems::IsEmpty}\label{wxcontrolwithitemsisempty}
293
294 \constfunc{bool}{IsEmpty}{\void}
295
296 Returns {\tt true} if the control is empty or {\tt false} if it has some items.
297
298 \wxheading{See also}
299
300 \helpref{GetCount}{wxcontrolwithitemsgetcount}
301
302
303 \membersection{wxControlWithItems::Select}\label{wxcontrolwithitemsselect}
304
305 \func{void}{Select}{\param{int}{ n}}
306
307 This is the same as \helpref{SetSelection}{wxcontrolwithitemssetselection} and
308 exists only because it is slightly more natural for controls which support
309 multiple selection.
310
311
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
320 Replace control items with the (only) item specified, associating the typed or
321 untyped 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
331 Replaces the current control contents with the given items. Notice that calling
332 this method is much faster than appending the items one by one if you need to
333 append 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
349 When the control is sorted (e.g. has {\tt wxLB\_SORT} or {\tt wxCB\_SORT} style)
350 the return value could be different from (GetCount() - 1).
351 When setting a single item to the container, the return value is the index of the
352 newly 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
355 By default this method subsequently calls \helpref{Clear}{wxcontrolwithitemsclear}
356 and \helpref{Append}{wxcontrolwithitemsappend}.
357
358
359 \membersection{wxControlWithItems::SetClientData}\label{wxcontrolwithitemssetclientdata}
360
361 \func{void}{SetClientData}{\param{unsigned int}{ n}, \param{void *}{data}}
362
363 Associates the given untyped client data pointer with the given item. Note that
364 it is an error to call this function if any typed client data pointers had been
365 associated 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
376 \func{void}{SetClientObject}{\param{unsigned int}{ n}, \param{wxClientData *}{data}}
377
378 Associates the given typed client data pointer with the given item: the
379 {\it data} object will be deleted when the item is deleted (either explicitly
380 by using \helpref{Deletes}{wxcontrolwithitemsdelete} or implicitly when the
381 control itself is destroyed).
382
383 Note that it is an error to call this function if any untyped client data
384 pointers 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
397 Sets the selection to the given item \arg{n} or removes the selection entirely
398 if \arg{n} $==$ {\tt wxNOT\_FOUND}.
399
400 Note that this does not cause any command events to be emitted nor does it
401 deselect any other items in the controls which support multiple selections.
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
415 \func{void}{SetString}{\param{unsigned int}{ n}, \param{const wxString\& }{ string}}
416
417 Sets 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
428 \func{bool}{SetStringSelection}{\param{const wxString\& }{ string}}
429
430 Selects the item with the specified string in the control. This doesn't cause
431 any command events to be emitted.
432
433 \wxheading{Parameters}
434
435 \docparam{string}{The string to select.}
436
437 \wxheading{Return value}
438
439 \true if the specified string has been selected, \false if it wasn't found in
440 the control.
441
442 \wxheading{See also}
443
444 \helpref{SetSelection}{wxcontrolwithitemssetselection}
445