]>
git.saurik.com Git - wxWidgets.git/blob - interface/ctrlsub.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxControlWithItems
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
10 @class wxControlWithItems
13 This class is an abstract base class for some wxWidgets controls which contain
14 several items such as wxListBox, wxCheckListBox, wxChoice and wxComboBox derive
18 It defines the methods for accessing the controls items and although each of
19 the derived classes implements them differently, they still all conform to the
22 The items in a wxControlWithItems have (non-empty) string labels and,
23 optionally, client data associated with them. Client data may be of two
24 different kinds: either simple untyped (@c void *) pointers which are simply
25 stored by the control but not used in any way by it, or typed pointers
26 (@c wxClientData *) which are owned by the control meaning that the typed
27 client data (and only it) will be deleted when an item is deleted
28 (using wxControlWithItems::Delete) or the entire control is cleared
29 (using wxControlWithItems::Clear) which also happens when it is
32 Finally note that in the same control all items must have client data of the
33 same type (typed or untyped), if any. This type is determined by
34 the first call to wxControlWithItems::Append (the version with
35 client data pointer) or wxControlWithItems::SetClientData.
40 @see wxControlWithItems::Clear
42 class wxControlWithItems
: public wxControl
47 Appends several items at once to the control. Notice that calling this method
48 is usually much faster than appending them one by one if you need to add a lot
54 Contains items to append to the control.
56 Array of strings of size n.
58 Number of items in the strings array.
60 Array of client data pointers of size n to associate with the new items.
62 @returns When appending a single item, the return value is the index of
63 the newly added item which may be different from the
64 last one if the control is sorted (e.g. has wxLB_SORT
67 int Append(const wxString
& item
);
68 int Append(const wxString
& item
, void* clientData
);
69 int Append(const wxString
& item
, wxClientData
* clientData
);
70 void Append(const wxArrayString
& strings
);
71 void Append(unsigned int n
, const wxString
* strings
);
72 void Append(unsigned int n
, const wxString
* strings
,
74 void Append(unsigned int n
, const wxString
* strings
,
75 wxClientData
** clientData
);
79 Removes all items from the control.
80 @e Clear() also deletes the client data of the existing items if it is owned
86 Deletes an item from the control. The client data associated with the item
87 will be also deleted if it is owned by the control.
88 Note that it is an error (signalled by an assert failure in debug builds) to
89 remove an item with the index negative or greater or equal than the number of
93 The zero-based item index.
97 void Delete(unsigned int n
);
100 Finds an item whose label matches the given string.
105 Whether search is case sensitive (default is not).
107 @returns The zero-based position of the item, or wxNOT_FOUND if the
108 string was not found.
110 int FindString(const wxString
& string
,
111 bool caseSensitive
= false);
114 Returns a pointer to the client data associated with the given item (if any).
115 It is an error to call this function for a control which doesn't have untyped
116 client data at all although it is ok to call it even if the given item doesn't
117 have any client data associated with it (but other items do).
120 The zero-based position of the item.
122 @returns A pointer to the client data, or @NULL if not present.
124 void* GetClientData(unsigned int n
) const;
127 Returns a pointer to the client data associated with the given item (if any).
128 It is an error to call this function for a control which doesn't have typed
129 client data at all although it is ok to call it even if the given item doesn't
130 have any client data associated with it (but other items do).
133 The zero-based position of the item.
135 @returns A pointer to the client data, or @NULL if not present.
137 wxClientData
* GetClientObject(unsigned int n
) const;
140 Returns the number of items in the control.
144 unsigned int GetCount() const;
147 Returns the index of the selected item or @c wxNOT_FOUND if no item is
150 @returns The position of the current selection.
152 @remarks This method can be used with single selection list boxes only,
153 you should use wxListBox::GetSelections for the list
154 boxes with wxLB_MULTIPLE style.
156 @see SetSelection(), GetStringSelection()
158 int GetSelection() const;
161 Returns the label of the item with the given index.
164 The zero-based index.
166 @returns The label of the item or an empty string if the position was
169 wxString
GetString(unsigned int n
) const;
172 Returns the label of the selected item or an empty string if no item is
177 wxString
GetStringSelection() const;
180 Returns the array of the labels of all items in the control.
182 wxArrayString
GetStrings() const;
186 Inserts several items at once into the control. Notice that calling this method
187 is usually much faster than inserting them one by one if you need to insert a
194 Position to insert item before, zero based.
196 Contains items to insert into the control content
198 Array of strings of size n.
200 Number of items in the strings array.
202 Array of client data pointers of size n to associate with the new items.
204 @returns The return value is the index of the newly inserted item. If the
205 insertion failed for some reason, -1 is returned.
207 int Insert(const wxString
& item
, unsigned int pos
);
208 int Insert(const wxString
& item
, unsigned int pos
,
210 int Insert(const wxString
& item
, unsigned int pos
,
211 wxClientData
* clientData
);
212 void Insert(const wxArrayString
& strings
, unsigned int pos
);
213 void Insert(const wxArrayString
& strings
, unsigned int pos
);
214 void Insert(unsigned int n
, const wxString
* strings
,
216 void Insert(unsigned int n
, const wxString
* strings
,
219 void Insert(unsigned int n
, const wxString
* strings
,
221 wxClientData
** clientData
);
225 Returns @true if the control is empty or @false if it has some items.
229 bool IsEmpty() const;
232 This is the same as SetSelection() and
233 exists only because it is slightly more natural for controls which support
240 Replaces the current control contents with the given items. Notice that calling
241 this method is much faster than appending the items one by one if you need to
242 append a lot of them.
245 The single item to insert into the control.
247 Contains items to set as control content.
249 Raw C++ array of strings. Only used in conjunction with 'n'.
251 Number of items passed in 'strings'. Only used in conjunction with
254 Client data to associate with the item(s).
256 @returns When the control is sorted (e.g. has wxLB_SORT or wxCB_SORT
257 style) the return value could be different from
258 (GetCount() - 1). When setting a single item to the
259 container, the return value is the index of the newly
260 added item which may be different from the last one if
261 the control is sorted (e.g. has wxLB_SORT or wxCB_SORT
264 int Set(const wxString
& item
);
265 int Set(const wxString
& item
, void* clientData
);
266 int Set(const wxString
& item
, wxClientData
* clientData
);
267 void Set(const wxArrayString
& stringsArray
);
268 void Set(unsigned int n
, const wxString
* strings
);
269 void Set(unsigned int n
, const wxString
* strings
,
271 void Set(unsigned int n
, const wxString
* strings
,
272 wxClientData
** clientData
);
276 Associates the given untyped client data pointer with the given item. Note that
277 it is an error to call this function if any typed client data pointers had been
278 associated with the control items before.
281 The zero-based item index.
283 The client data to associate with the item.
285 void SetClientData(unsigned int n
, void* data
);
288 Associates the given typed client data pointer with the given item: the
289 @a data object will be deleted when the item is deleted (either explicitly
290 by using @ref delete() Deletes or implicitly when the
291 control itself is destroyed).
292 Note that it is an error to call this function if any untyped client data
293 pointers had been associated with the control items before.
296 The zero-based item index.
298 The client data to associate with the item.
300 void SetClientObject(unsigned int n
, wxClientData
* data
);
303 Sets the selection to the given item @a n or removes the selection entirely
304 if @a n == @c wxNOT_FOUND.
305 Note that this does not cause any command events to be emitted nor does it
306 deselect any other items in the controls which support multiple selections.
309 The string position to select, starting from zero.
311 @see SetString(), SetStringSelection()
313 void SetSelection(int n
);
316 Sets the label for the given item.
319 The zero-based item index.
323 void SetString(unsigned int n
, const wxString
& string
);
326 Selects the item with the specified string in the control. This doesn't cause
327 any command events to be emitted.
330 The string to select.
332 @returns @true if the specified string has been selected, @false if it
333 wasn't found in the control.
335 bool SetStringSelection(const wxString
& string
);