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
49 \helpref{wxCore
}{librarieslist
}
51 \latexignore{\rtfignore{\wxheading{Members
}}}
53 \membersection{wxControlWithItems::Append
}\label{wxcontrolwithitemsappend
}
55 \func{int
}{Append
}{\param{const wxString\&
}{ item
}}
57 Adds the item to the end of the list box.
59 \func{int
}{Append
}{\param{const wxString\&
}{ item
},
\param{void *
}{clientData
}}
61 \func{int
}{Append
}{\param{const wxString\&
}{ item
},
\param{wxClientData *
}{clientData
}}
63 Adds the item to the end of the list box, associating the given, typed or
64 untyped, client data pointer with the item.
66 \func{void
}{Append
}{\param{const wxArrayString\&
}{strings
}}
68 \func{void
}{Append
}{\param{unsigned int
}{n
},
\param{const wxString*
}{strings
}}
70 \func{void
}{Append
}{\param{unsigned int
}{n
},
\param{const wxString*
}{strings
},
\param{void **
}{clientData
}}
72 \func{void
}{Append
}{\param{unsigned int
}{n
},
\param{const wxString*
}{strings
},
\param{wxClientData **
}{clientData
}}
74 Appends several items at once to the control. Notice that calling this method
75 is usually much faster than appending them one by one if you need to add a lot
78 \wxheading{Parameters
}
80 \docparam{item
}{String to add.
}
82 \docparam{stringsArray
}{Contains items to append to the control.
}
84 \docparam{strings
}{Array of strings of size
\arg{n
}.
}
86 \docparam{n
}{Number of items in the
\arg{strings
} array.
}
88 \docparam{clientData
}{Array of client data pointers of size
\arg{n
} to associate with the new items.
}
90 \wxheading{Return value
}
92 When appending a single item, the return value is the index of the newly added
93 item which may be different from the last one if the control is sorted (e.g.
94 has
{\tt wxLB
\_SORT} or
{\tt wxCB
\_SORT} style).
96 \membersection{wxControlWithItems::Clear
}\label{wxcontrolwithitemsclear
}
98 \func{void
}{Clear
}{\void}
100 Removes all items from the control.
102 {\it Clear()
} also deletes the client data of the existing items if it is owned
105 \membersection{wxControlWithItems::Delete
}\label{wxcontrolwithitemsdelete
}
107 \func{void
}{Delete
}{\param{unsigned int
}{ n
}}
109 Deletes an item from the control. The client data associated with the item
110 will be also deleted if it is owned by the control.
112 Note that it is an error (signalled by an assert failure in debug builds) to
113 remove an item with the index negative or greater or equal than the number of
114 items in the control.
116 \wxheading{Parameters
}
118 \docparam{n
}{The zero-based item index.
}
122 \helpref{Clear
}{wxcontrolwithitemsclear
}
124 \membersection{wxControlWithItems::FindString
}\label{wxcontrolwithitemsfindstring
}
126 \func{int
}{FindString
}{\param{const wxString\&
}{string
},
\param{bool
}{ caseSensitive = false
}}
128 Finds an item whose label matches the given string.
130 \wxheading{Parameters
}
132 \docparam{string
}{String to find.
}
134 \docparam{caseSensitive
}{Whether search is case sensitive (default is not).
}
136 \wxheading{Return value
}
138 The zero-based position of the item, or
{\tt wxNOT
\_FOUND} if the string was
142 \membersection{wxControlWithItems::GetClientData
}\label{wxcontrolwithitemsgetclientdata
}
144 \constfunc{void *
}{GetClientData
}{\param{unsigned int
}{ n
}}
146 Returns a pointer to the client data associated with the given item (if any).
147 It is an error to call this function for a control which doesn't have untyped
148 client data at all although it is ok to call it even if the given item doesn't
149 have any client data associated with it (but other items do).
151 \wxheading{Parameters
}
153 \docparam{n
}{The zero-based position of the item.
}
155 \wxheading{Return value
}
157 A pointer to the client data, or
{\tt NULL
} if not present.
160 \membersection{wxControlWithItems::GetClientObject
}\label{wxcontrolwithitemsgetclientobject
}
162 \constfunc{wxClientData *
}{GetClientObject
}{\param{unsigned int
}{ n
}}
164 Returns a pointer to the client data associated with the given item (if any).
165 It is an error to call this function for a control which doesn't have typed
166 client data at all although it is ok to call it even if the given item doesn't
167 have any client data associated with it (but other items do).
169 \wxheading{Parameters
}
171 \docparam{n
}{The zero-based position of the item.
}
173 \wxheading{Return value
}
175 A pointer to the client data, or
{\tt NULL
} if not present.
178 \membersection{wxControlWithItems::GetCount
}\label{wxcontrolwithitemsgetcount
}
180 \constfunc{unsigned int
}{GetCount
}{\void}
182 Returns the number of items in the control.
186 \helpref{IsEmpty
}{wxcontrolwithitemsisempty
}
189 \membersection{wxControlWithItems::GetSelection
}\label{wxcontrolwithitemsgetselection
}
191 \constfunc{int
}{GetSelection
}{\void}
193 Returns the index of the selected item or
{\tt wxNOT
\_FOUND} if no item is
196 \wxheading{Return value
}
198 The position of the current selection.
202 This method can be used with single selection list boxes only, you should use
203 \helpref{wxListBox::GetSelections
}{wxlistboxgetselections
} for the list boxes
204 with
{\tt wxLB
\_MULTIPLE} style.
208 \helpref{SetSelection
}{wxcontrolwithitemssetselection
},
\rtfsp
209 \helpref{GetStringSelection
}{wxcontrolwithitemsgetstringselection
}
212 \membersection{wxControlWithItems::GetString
}\label{wxcontrolwithitemsgetstring
}
214 \constfunc{wxString
}{GetString
}{\param{unsigned int
}{ n
}}
216 Returns the label of the item with the given index.
218 \wxheading{Parameters
}
220 \docparam{n
}{The zero-based index.
}
222 \wxheading{Return value
}
224 The label of the item or an empty string if the position was invalid.
227 \membersection{wxControlWithItems::GetStrings
}\label{wxcontrolwithitemsgetstrings
}
229 \constfunc{wxArrayString
}{GetStrings
}{\void}
231 Returns the array of the labels of all items in the control.
234 \membersection{wxControlWithItems::GetStringSelection
}\label{wxcontrolwithitemsgetstringselection
}
236 \constfunc{wxString
}{GetStringSelection
}{\void}
238 Returns the label of the selected item or an empty string if no item is
243 \helpref{GetSelection
}{wxcontrolwithitemsgetselection
}
246 \membersection{wxControlWithItems::Insert
}\label{wxcontrolwithitemsinsert
}
248 \func{int
}{Insert
}{\param{const wxString\&
}{ item
},
\param{unsigned int
}{pos
}}
250 Inserts the item into the list before pos.
251 Not valid for
{\tt wxLB
\_SORT} or
{\tt wxCB
\_SORT} styles, use Append instead.
253 \func{int
}{Insert
}{\param{const wxString\&
}{ item
},
\param{unsigned int
}{pos
},
\param{void *
}{clientData
}}
255 \func{int
}{Insert
}{\param{const wxString\&
}{ item
},
\param{unsigned int
}{pos
},
\param{wxClientData *
}{clientData
}}
257 Inserts the item into the list before pos, associating the given, typed or
258 untyped, client data pointer with the item.
259 Not valid for
{\tt wxLB
\_SORT} or
{\tt wxCB
\_SORT} styles, use Append instead.
261 \func{void
}{Insert
}{\param{const wxArrayString\&
}{strings
},
\param{unsigned int
}{pos
}}
263 \func{void
}{Insert
}{\param{const wxArrayString\&
}{strings
},
\param{unsigned int
}{pos
}}
265 \func{void
}{Insert
}{\param{unsigned int
}{n
},
\param{const wxString*
}{strings
},
\param{unsigned int
}{pos
}}
267 \func{void
}{Insert
}{\param{unsigned int
}{n
},
\param{const wxString*
}{strings
},
\param{unsigned int
}{pos
},
\param{void **
}{clientData
}}
269 \func{void
}{Insert
}{\param{unsigned int
}{n
},
\param{const wxString*
}{strings
},
\param{unsigned int
}{pos
},
\param{wxClientData **
}{clientData
}}
271 Inserts several items at once into the control. Notice that calling this method
272 is usually much faster than inserting them one by one if you need to insert a lot
276 \wxheading{Parameters
}
278 \docparam{item
}{String to add.
}
280 \docparam{pos
}{Position to insert item before, zero based.
}
282 \docparam{stringsArray
}{Contains items to insert into the control content
}
284 \docparam{strings
}{Array of strings of size
\arg{n
}.
}
286 \docparam{n
}{Number of items in the
\arg{strings
} array.
}
288 \docparam{clientData
}{Array of client data pointers of size
\arg{n
} to associate with the new items.
}
290 \wxheading{Return value
}
292 The return value is the index of the newly inserted item. If the insertion failed
293 for some reason, -
1 is returned.
296 \membersection{wxControlWithItems::IsEmpty
}\label{wxcontrolwithitemsisempty
}
298 \constfunc{bool
}{IsEmpty
}{\void}
300 Returns
{\tt true
} if the control is empty or
{\tt false
} if it has some items.
304 \helpref{GetCount
}{wxcontrolwithitemsgetcount
}
307 \membersection{wxControlWithItems::Select
}\label{wxcontrolwithitemsselect
}
309 \func{void
}{Select
}{\param{int
}{ n
}}
311 This is the same as
\helpref{SetSelection
}{wxcontrolwithitemssetselection
} and
312 exists only because it is slightly more natural for controls which support
316 \membersection{wxControlWithItems::Set
}\label{wxcontrolwithitemsset
}
318 \func{int
}{Set
}{\param{const wxString\&
}{ item
}}
320 \func{int
}{Set
}{\param{const wxString\&
}{ item
},
\param{void *
}{clientData
}}
322 \func{int
}{Set
}{\param{const wxString\&
}{ item
},
\param{wxClientData *
}{clientData
}}
324 Replace control items with the (only) item specified, associating the typed or
325 untyped client data pointer with it if given.
327 \func{void
}{Set
}{\param{const wxArrayString\&
}{stringsArray
}}
329 \func{void
}{Set
}{\param{unsigned int
}{n
},
\param{const wxString*
}{strings
}}
331 \func{void
}{Set
}{\param{unsigned int
}{n
},
\param{const wxString*
}{strings
},
\param{void **
}{clientData
}}
333 \func{void
}{Set
}{\param{unsigned int
}{n
},
\param{const wxString*
}{strings
},
\param{wxClientData **
}{clientData
}}
335 Replaces the current control contents with the given items. Notice that calling
336 this method is much faster than appending the items one by one if you need to
337 append a lot of them.
339 \wxheading{Parameters
}
341 \docparam{item
}{The single item to insert into the control.
}
343 \docparam{stringsArray
}{Contains items to set as control content.
}
345 \docparam{strings
}{Raw C++ array of strings. Only used in conjunction with 'n'.
}
347 \docparam{n
}{Number of items passed in 'strings'. Only used in conjunction with 'strings'.
}
349 \docparam{clientData
}{Client data to associate with the item(s).
}
351 \wxheading{Return value
}
353 When the control is sorted (e.g. has
{\tt wxLB
\_SORT} or
{\tt wxCB
\_SORT} style)
354 the return value could be different from (GetCount() -
1).
355 When setting a single item to the container, the return value is the index of the
356 newly added item which may be different from the last one if the control is sorted
357 (e.g. has
{\tt wxLB
\_SORT} or
{\tt wxCB
\_SORT} style).
359 By default this method subsequently calls
\helpref{Clear
}{wxcontrolwithitemsclear
}
360 and
\helpref{Append
}{wxcontrolwithitemsappend
}.
363 \membersection{wxControlWithItems::SetClientData
}\label{wxcontrolwithitemssetclientdata
}
365 \func{void
}{SetClientData
}{\param{unsigned int
}{ n
},
\param{void *
}{data
}}
367 Associates the given untyped client data pointer with the given item. Note that
368 it is an error to call this function if any typed client data pointers had been
369 associated with the control items before.
371 \wxheading{Parameters
}
373 \docparam{n
}{The zero-based item index.
}
375 \docparam{data
}{The client data to associate with the item.
}
378 \membersection{wxControlWithItems::SetClientObject
}\label{wxcontrolwithitemssetclientobject
}
380 \func{void
}{SetClientObject
}{\param{unsigned int
}{ n
},
\param{wxClientData *
}{data
}}
382 Associates the given typed client data pointer with the given item: the
383 {\it data
} object will be deleted when the item is deleted (either explicitly
384 by using
\helpref{Deletes
}{wxcontrolwithitemsdelete
} or implicitly when the
385 control itself is destroyed).
387 Note that it is an error to call this function if any untyped client data
388 pointers had been associated with the control items before.
390 \wxheading{Parameters
}
392 \docparam{n
}{The zero-based item index.
}
394 \docparam{data
}{The client data to associate with the item.
}
397 \membersection{wxControlWithItems::SetSelection
}\label{wxcontrolwithitemssetselection
}
399 \func{void
}{SetSelection
}{\param{int
}{ n
}}
401 Sets the selection to the given item
\arg{n
} or removes the selection entirely
402 if
\arg{n
} $==$
{\tt wxNOT
\_FOUND}.
404 Note that this does not cause any command events to be emitted nor does it
405 deselect any other items in the controls which support multiple selections.
407 \wxheading{Parameters
}
409 \docparam{n
}{The string position to select, starting from zero.
}
413 \helpref{SetString
}{wxcontrolwithitemssetstring
},
\rtfsp
414 \helpref{SetStringSelection
}{wxcontrolwithitemssetstringselection
}
417 \membersection{wxControlWithItems::SetString
}\label{wxcontrolwithitemssetstring
}
419 \func{void
}{SetString
}{\param{unsigned int
}{ n
},
\param{const wxString\&
}{ string
}}
421 Sets the label for the given item.
423 \wxheading{Parameters
}
425 \docparam{n
}{The zero-based item index.
}
427 \docparam{string
}{The label to set.
}
430 \membersection{wxControlWithItems::SetStringSelection
}\label{wxcontrolwithitemssetstringselection
}
432 \func{bool
}{SetStringSelection
}{\param{const wxString\&
}{ string
}}
434 Selects the item with the specified string in the control. This doesn't cause
435 any command events to be emitted.
437 \wxheading{Parameters
}
439 \docparam{string
}{The string to select.
}
441 \wxheading{Return value
}
443 \true if the specified string has been selected,
\false if it wasn't found in
448 \helpref{SetSelection
}{wxcontrolwithitemssetselection
}