1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %% Purpose: wxControlWithItems documentation
4 %% Author: Vadim Zeitlin
8 %% Copyright: (c) 2003 Vadim Zeitlin
9 %% License: wxWindows license
10 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
12 \section{\class{wxControlWithItems
}}\label{wxcontrolwithitems
}
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
}.
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
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
}.
36 \wxheading{Derived from
}
38 \helpref{wxControl
}{wxcontrol
}\\
39 \helpref{wxWindow
}{wxwindow
}\\
40 \helpref{wxEvtHandler
}{wxevthandler
}\\
41 \helpref{wxObject
}{wxobject
}
43 \wxheading{Include files
}
45 <wx/ctrlsub.h> but usually never included directly
47 \latexignore{\rtfignore{\wxheading{Members
}}}
49 \membersection{wxControlWithItems::Append
}\label{wxcontrolwithitemsappend
}
51 \func{int
}{Append
}{\param{const wxString\&
}{ item
}}
53 Adds the item to the end of the list box.
55 \func{int
}{Append
}{\param{const wxString\&
}{ item
},
\param{void *
}{clientData
}}
57 \func{int
}{Append
}{\param{const wxString\&
}{ item
},
\param{wxClientData *
}{clientData
}}
59 Adds the item to the end of the list box, associating the given, typed or
60 untyped, client data pointer with the item.
62 \func{void
}{Append
}{\param{const wxArrayString\&
}{strings
}}
64 \func{void
}{Append
}{\param{unsigned int
}{n
},
\param{const wxString*
}{strings
}}
66 \func{void
}{Append
}{\param{unsigned int
}{n
},
\param{const wxString*
}{strings
},
\param{void **
}{clientData
}}
68 \func{void
}{Append
}{\param{unsigned int
}{n
},
\param{const wxString*
}{strings
},
\param{wxClientData **
}{clientData
}}
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
74 \wxheading{Parameters
}
76 \docparam{item
}{String to add.
}
78 \docparam{stringsArray
}{Contains items to append to the control.
}
80 \docparam{strings
}{Array of strings of size
\arg{n
}.
}
82 \docparam{n
}{Number of items in the
\arg{strings
} array.
}
84 \docparam{clientData
}{Array of client data pointers of size
\arg{n
} to associate with the new items.
}
86 \wxheading{Return value
}
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).
92 \membersection{wxControlWithItems::Clear
}\label{wxcontrolwithitemsclear
}
94 \func{void
}{Clear
}{\void}
96 Removes all items from the control.
98 {\it Clear()
} also deletes the client data of the existing items if it is owned
101 \membersection{wxControlWithItems::Delete
}\label{wxcontrolwithitemsdelete
}
103 \func{void
}{Delete
}{\param{unsigned int
}{ n
}}
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.
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.
112 \wxheading{Parameters
}
114 \docparam{n
}{The zero-based item index.
}
118 \helpref{Clear
}{wxcontrolwithitemsclear
}
120 \membersection{wxControlWithItems::FindString
}\label{wxcontrolwithitemsfindstring
}
122 \func{int
}{FindString
}{\param{const wxString\&
}{string
},
\param{bool
}{ caseSensitive = false
}}
124 Finds an item whose label matches the given string.
126 \wxheading{Parameters
}
128 \docparam{string
}{String to find.
}
130 \docparam{caseSensitive
}{Whether search is case sensitive (default is not).
}
132 \wxheading{Return value
}
134 The zero-based position of the item, or
{\tt wxNOT
\_FOUND} if the string was
138 \membersection{wxControlWithItems::GetClientData
}\label{wxcontrolwithitemsgetclientdata
}
140 \constfunc{void *
}{GetClientData
}{\param{unsigned int
}{ n
}}
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).
147 \wxheading{Parameters
}
149 \docparam{n
}{The zero-based position of the item.
}
151 \wxheading{Return value
}
153 A pointer to the client data, or
{\tt NULL
} if not present.
156 \membersection{wxControlWithItems::GetClientObject
}\label{wxcontrolwithitemsgetclientobject
}
158 \constfunc{wxClientData *
}{GetClientObject
}{\param{unsigned int
}{ n
}}
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).
165 \wxheading{Parameters
}
167 \docparam{n
}{The zero-based position of the item.
}
169 \wxheading{Return value
}
171 A pointer to the client data, or
{\tt NULL
} if not present.
174 \membersection{wxControlWithItems::GetCount
}\label{wxcontrolwithitemsgetcount
}
176 \constfunc{unsigned int
}{GetCount
}{\void}
178 Returns the number of items in the control.
182 \helpref{IsEmpty
}{wxcontrolwithitemsisempty
}
185 \membersection{wxControlWithItems::GetSelection
}\label{wxcontrolwithitemsgetselection
}
187 \constfunc{int
}{GetSelection
}{\void}
189 Returns the index of the selected item or
{\tt wxNOT
\_FOUND} if no item is
192 \wxheading{Return value
}
194 The position of the current selection.
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.
204 \helpref{SetSelection
}{wxcontrolwithitemssetselection
},
\rtfsp
205 \helpref{GetStringSelection
}{wxcontrolwithitemsgetstringselection
}
208 \membersection{wxControlWithItems::GetString
}\label{wxcontrolwithitemsgetstring
}
210 \constfunc{wxString
}{GetString
}{\param{unsigned int
}{ n
}}
212 Returns the label of the item with the given index.
214 \wxheading{Parameters
}
216 \docparam{n
}{The zero-based index.
}
218 \wxheading{Return value
}
220 The label of the item or an empty string if the position was invalid.
223 \membersection{wxControlWithItems::GetStrings
}\label{wxcontrolwithitemsgetstrings
}
225 \constfunc{wxArrayString
}{GetStrings
}{\void}
227 Returns the array of the labels of all items in the control.
230 \membersection{wxControlWithItems::GetStringSelection
}\label{wxcontrolwithitemsgetstringselection
}
232 \constfunc{wxString
}{GetStringSelection
}{\void}
234 Returns the label of the selected item or an empty string if no item is
239 \helpref{GetSelection
}{wxcontrolwithitemsgetselection
}
242 \membersection{wxControlWithItems::Insert
}\label{wxcontrolwithitemsinsert
}
244 \func{int
}{Insert
}{\param{const wxString\&
}{ item
},
\param{unsigned int
}{pos
}}
246 Inserts the item into the list before pos.
247 Not valid for
{\tt wxLB
\_SORT} or
{\tt wxCB
\_SORT} styles, use Append instead.
249 \func{int
}{Insert
}{\param{const wxString\&
}{ item
},
\param{unsigned int
}{pos
},
\param{void *
}{clientData
}}
251 \func{int
}{Insert
}{\param{const wxString\&
}{ item
},
\param{unsigned int
}{pos
},
\param{wxClientData *
}{clientData
}}
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.
257 \func{void
}{Insert
}{\param{const wxArrayString\&
}{strings
},
\param{unsigned int
}{pos
}}
259 \func{void
}{Insert
}{\param{const wxArrayString\&
}{strings
},
\param{unsigned int
}{pos
}}
261 \func{void
}{Insert
}{\param{unsigned int
}{n
},
\param{const wxString*
}{strings
},
\param{unsigned int
}{pos
}}
263 \func{void
}{Insert
}{\param{unsigned int
}{n
},
\param{const wxString*
}{strings
},
\param{unsigned int
}{pos
},
\param{void **
}{clientData
}}
265 \func{void
}{Insert
}{\param{unsigned int
}{n
},
\param{const wxString*
}{strings
},
\param{unsigned int
}{pos
},
\param{wxClientData **
}{clientData
}}
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
272 \wxheading{Parameters
}
274 \docparam{item
}{String to add.
}
276 \docparam{pos
}{Position to insert item before, zero based.
}
278 \docparam{stringsArray
}{Contains items to insert into the control content
}
280 \docparam{strings
}{Array of strings of size
\arg{n
}.
}
282 \docparam{n
}{Number of items in the
\arg{strings
} array.
}
284 \docparam{clientData
}{Array of client data pointers of size
\arg{n
} to associate with the new items.
}
286 \wxheading{Return value
}
288 The return value is the index of the newly inserted item. If the insertion failed
289 for some reason, -
1 is returned.
292 \membersection{wxControlWithItems::IsEmpty
}\label{wxcontrolwithitemsisempty
}
294 \constfunc{bool
}{IsEmpty
}{\void}
296 Returns
{\tt true
} if the control is empty or
{\tt false
} if it has some items.
300 \helpref{GetCount
}{wxcontrolwithitemsgetcount
}
303 \membersection{wxControlWithItems::Select
}\label{wxcontrolwithitemsselect
}
305 \func{void
}{Select
}{\param{int
}{ n
}}
307 This is the same as
\helpref{SetSelection
}{wxcontrolwithitemssetselection
} and
308 exists only because it is slightly more natural for controls which support
312 \membersection{wxControlWithItems::Set
}\label{wxcontrolwithitemsset
}
314 \func{int
}{Set
}{\param{const wxString\&
}{ item
}}
316 \func{int
}{Set
}{\param{const wxString\&
}{ item
},
\param{void *
}{clientData
}}
318 \func{int
}{Set
}{\param{const wxString\&
}{ item
},
\param{wxClientData *
}{clientData
}}
320 Replace control items with the (only) item specified, associating the typed or
321 untyped client data pointer with it if given.
323 \func{void
}{Set
}{\param{const wxArrayString\&
}{stringsArray
}}
325 \func{void
}{Set
}{\param{unsigned int
}{n
},
\param{const wxString*
}{strings
}}
327 \func{void
}{Set
}{\param{unsigned int
}{n
},
\param{const wxString*
}{strings
},
\param{void **
}{clientData
}}
329 \func{void
}{Set
}{\param{unsigned int
}{n
},
\param{const wxString*
}{strings
},
\param{wxClientData **
}{clientData
}}
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.
335 \wxheading{Parameters
}
337 \docparam{item
}{The single item to insert into the control.
}
339 \docparam{stringsArray
}{Contains items to set as control content.
}
341 \docparam{strings
}{Raw C++ array of strings. Only used in conjunction with 'n'.
}
343 \docparam{n
}{Number of items passed in 'strings'. Only used in conjunction with 'strings'.
}
345 \docparam{clientData
}{Client data to associate with the item(s).
}
347 \wxheading{Return value
}
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).
355 By default this method subsequently calls
\helpref{Clear
}{wxcontrolwithitemsclear
}
356 and
\helpref{Append
}{wxcontrolwithitemsappend
}.
359 \membersection{wxControlWithItems::SetClientData
}\label{wxcontrolwithitemssetclientdata
}
361 \func{void
}{SetClientData
}{\param{unsigned int
}{ n
},
\param{void *
}{data
}}
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.
367 \wxheading{Parameters
}
369 \docparam{n
}{The zero-based item index.
}
371 \docparam{data
}{The client data to associate with the item.
}
374 \membersection{wxControlWithItems::SetClientObject
}\label{wxcontrolwithitemssetclientobject
}
376 \func{void
}{SetClientObject
}{\param{unsigned int
}{ n
},
\param{wxClientData *
}{data
}}
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).
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.
386 \wxheading{Parameters
}
388 \docparam{n
}{The zero-based item index.
}
390 \docparam{data
}{The client data to associate with the item.
}
393 \membersection{wxControlWithItems::SetSelection
}\label{wxcontrolwithitemssetselection
}
395 \func{void
}{SetSelection
}{\param{int
}{ n
}}
397 Sets the selection to the given item
\arg{n
} or removes the selection entirely
398 if
\arg{n
} $==$
{\tt wxNOT
\_FOUND}.
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.
403 \wxheading{Parameters
}
405 \docparam{n
}{The string position to select, starting from zero.
}
409 \helpref{SetString
}{wxcontrolwithitemssetstring
},
\rtfsp
410 \helpref{SetStringSelection
}{wxcontrolwithitemssetstringselection
}
413 \membersection{wxControlWithItems::SetString
}\label{wxcontrolwithitemssetstring
}
415 \func{void
}{SetString
}{\param{unsigned int
}{ n
},
\param{const wxString\&
}{ string
}}
417 Sets the label for the given item.
419 \wxheading{Parameters
}
421 \docparam{n
}{The zero-based item index.
}
423 \docparam{string
}{The label to set.
}
426 \membersection{wxControlWithItems::SetStringSelection
}\label{wxcontrolwithitemssetstringselection
}
428 \func{bool
}{SetStringSelection
}{\param{const wxString\&
}{ string
}}
430 Selects the item with the specified string in the control. This doesn't cause
431 any command events to be emitted.
433 \wxheading{Parameters
}
435 \docparam{string
}{The string to select.
}
437 \wxheading{Return value
}
439 \true if the specified string has been selected,
\false if it wasn't found in
444 \helpref{SetSelection
}{wxcontrolwithitemssetselection
}