]> git.saurik.com Git - wxWidgets.git/blame - interface/ctrlsub.h
revised base64.h;bitmap.h
[wxWidgets.git] / interface / ctrlsub.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: ctrlsub.h
e54c96f1 3// Purpose: interface of wxControlWithItems
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
6// Licence: wxWindows license
7/////////////////////////////////////////////////////////////////////////////
8
9/**
10 @class wxControlWithItems
11 @wxheader{ctrlsub.h}
7c913512 12
23324ae1
FM
13 This class is an abstract base class for some wxWidgets controls which contain
14 several items, such as wxListBox and
15 wxCheckListBox derived from it,
16 wxChoice and wxComboBox.
7c913512 17
23324ae1
FM
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
20 same interface.
7c913512 21
23324ae1
FM
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
28 @ref wxControlWithItems::delete deleted or the entire control is
29 @ref wxControlWithItems::clear cleared (which also happens when it is
30 destroyed). Finally note that in the same control all items must have client
31 data of the same type (typed or untyped), if any. This type is determined by
32 the first call to wxControlWithItems::Append (the version with
33 client data pointer) or wxControlWithItems::SetClientData.
7c913512 34
23324ae1
FM
35 @library{wxcore}
36 @category{FIXME}
7c913512 37
e54c96f1 38 @see wxControlWithItems::Clear
23324ae1
FM
39*/
40class wxControlWithItems : public wxControl
41{
42public:
43 //@{
44 /**
45 Appends several items at once to the control. Notice that calling this method
46 is usually much faster than appending them one by one if you need to add a lot
47 of items.
48
7c913512 49 @param item
4cc4bfaf 50 String to add.
7c913512 51 @param stringsArray
4cc4bfaf 52 Contains items to append to the control.
7c913512 53 @param strings
4cc4bfaf 54 Array of strings of size n.
7c913512 55 @param n
4cc4bfaf 56 Number of items in the strings array.
7c913512 57 @param clientData
4cc4bfaf 58 Array of client data pointers of size n to associate with the new items.
23324ae1
FM
59
60 @returns When appending a single item, the return value is the index of
4cc4bfaf
FM
61 the newly added item which may be different from the
62 last one if the control is sorted (e.g. has wxLB_SORT
63 or wxCB_SORT style).
23324ae1
FM
64 */
65 int Append(const wxString& item);
4cc4bfaf
FM
66 int Append(const wxString& item, void* clientData);
67 int Append(const wxString& item, wxClientData* clientData);
7c913512
FM
68 void Append(const wxArrayString& strings);
69 void Append(unsigned int n, const wxString* strings);
70 void Append(unsigned int n, const wxString* strings,
4cc4bfaf 71 void** clientData);
7c913512 72 void Append(unsigned int n, const wxString* strings,
4cc4bfaf 73 wxClientData** clientData);
23324ae1
FM
74 //@}
75
76 /**
77 Removes all items from the control.
23324ae1
FM
78 @e Clear() also deletes the client data of the existing items if it is owned
79 by the control.
80 */
81 void Clear();
82
83 /**
84 Deletes an item from the control. The client data associated with the item
85 will be also deleted if it is owned by the control.
23324ae1
FM
86 Note that it is an error (signalled by an assert failure in debug builds) to
87 remove an item with the index negative or greater or equal than the number of
88 items in the control.
89
7c913512 90 @param n
4cc4bfaf 91 The zero-based item index.
23324ae1 92
4cc4bfaf 93 @see Clear()
23324ae1
FM
94 */
95 void Delete(unsigned int n);
96
97 /**
98 Finds an item whose label matches the given string.
99
7c913512 100 @param string
4cc4bfaf 101 String to find.
7c913512 102 @param caseSensitive
4cc4bfaf 103 Whether search is case sensitive (default is not).
23324ae1
FM
104
105 @returns The zero-based position of the item, or wxNOT_FOUND if the
4cc4bfaf 106 string was not found.
23324ae1
FM
107 */
108 int FindString(const wxString& string,
4cc4bfaf 109 bool caseSensitive = false);
23324ae1
FM
110
111 /**
112 Returns a pointer to the client data associated with the given item (if any).
113 It is an error to call this function for a control which doesn't have untyped
114 client data at all although it is ok to call it even if the given item doesn't
115 have any client data associated with it (but other items do).
116
7c913512 117 @param n
4cc4bfaf 118 The zero-based position of the item.
23324ae1
FM
119
120 @returns A pointer to the client data, or @NULL if not present.
121 */
328f5751 122 void* GetClientData(unsigned int n) const;
23324ae1
FM
123
124 /**
125 Returns a pointer to the client data associated with the given item (if any).
126 It is an error to call this function for a control which doesn't have typed
127 client data at all although it is ok to call it even if the given item doesn't
128 have any client data associated with it (but other items do).
129
7c913512 130 @param n
4cc4bfaf 131 The zero-based position of the item.
23324ae1
FM
132
133 @returns A pointer to the client data, or @NULL if not present.
134 */
328f5751 135 wxClientData* GetClientObject(unsigned int n) const;
23324ae1
FM
136
137 /**
138 Returns the number of items in the control.
139
4cc4bfaf 140 @see IsEmpty()
23324ae1 141 */
328f5751 142 unsigned int GetCount() const;
23324ae1
FM
143
144 /**
145 Returns the index of the selected item or @c wxNOT_FOUND if no item is
146 selected.
147
148 @returns The position of the current selection.
149
150 @remarks This method can be used with single selection list boxes only,
4cc4bfaf
FM
151 you should use wxListBox::GetSelections for the list
152 boxes with wxLB_MULTIPLE style.
23324ae1 153
4cc4bfaf 154 @see SetSelection(), GetStringSelection()
23324ae1 155 */
328f5751 156 int GetSelection() const;
23324ae1
FM
157
158 /**
159 Returns the label of the item with the given index.
160
7c913512 161 @param n
4cc4bfaf 162 The zero-based index.
23324ae1
FM
163
164 @returns The label of the item or an empty string if the position was
4cc4bfaf 165 invalid.
23324ae1 166 */
328f5751 167 wxString GetString(unsigned int n) const;
23324ae1
FM
168
169 /**
170 Returns the label of the selected item or an empty string if no item is
171 selected.
172
4cc4bfaf 173 @see GetSelection()
23324ae1 174 */
328f5751 175 wxString GetStringSelection() const;
23324ae1
FM
176
177 /**
178 Returns the array of the labels of all items in the control.
179 */
328f5751 180 wxArrayString GetStrings() const;
23324ae1
FM
181
182 //@{
183 /**
184 Inserts several items at once into the control. Notice that calling this method
185 is usually much faster than inserting them one by one if you need to insert a
186 lot
187 of items.
188
7c913512 189 @param item
4cc4bfaf 190 String to add.
7c913512 191 @param pos
4cc4bfaf 192 Position to insert item before, zero based.
7c913512 193 @param stringsArray
4cc4bfaf 194 Contains items to insert into the control content
7c913512 195 @param strings
4cc4bfaf 196 Array of strings of size n.
7c913512 197 @param n
4cc4bfaf 198 Number of items in the strings array.
7c913512 199 @param clientData
4cc4bfaf 200 Array of client data pointers of size n to associate with the new items.
23324ae1
FM
201
202 @returns The return value is the index of the newly inserted item. If the
4cc4bfaf 203 insertion failed for some reason, -1 is returned.
23324ae1
FM
204 */
205 int Insert(const wxString& item, unsigned int pos);
7c913512 206 int Insert(const wxString& item, unsigned int pos,
4cc4bfaf 207 void* clientData);
7c913512 208 int Insert(const wxString& item, unsigned int pos,
4cc4bfaf 209 wxClientData* clientData);
7c913512
FM
210 void Insert(const wxArrayString& strings, unsigned int pos);
211 void Insert(const wxArrayString& strings, unsigned int pos);
212 void Insert(unsigned int n, const wxString* strings,
213 unsigned int pos);
214 void Insert(unsigned int n, const wxString* strings,
215 unsigned int pos,
4cc4bfaf 216 void** clientData);
7c913512
FM
217 void Insert(unsigned int n, const wxString* strings,
218 unsigned int pos,
4cc4bfaf 219 wxClientData** clientData);
23324ae1
FM
220 //@}
221
222 /**
223 Returns @true if the control is empty or @false if it has some items.
224
4cc4bfaf 225 @see GetCount()
23324ae1 226 */
328f5751 227 bool IsEmpty() const;
23324ae1
FM
228
229 /**
230 This is the same as SetSelection() and
231 exists only because it is slightly more natural for controls which support
232 multiple selection.
233 */
234 void Select(int n);
235
236 //@{
237 /**
238 Replaces the current control contents with the given items. Notice that calling
239 this method is much faster than appending the items one by one if you need to
240 append a lot of them.
241
7c913512 242 @param item
4cc4bfaf 243 The single item to insert into the control.
7c913512 244 @param stringsArray
4cc4bfaf 245 Contains items to set as control content.
7c913512 246 @param strings
4cc4bfaf 247 Raw C++ array of strings. Only used in conjunction with 'n'.
7c913512 248 @param n
4cc4bfaf
FM
249 Number of items passed in 'strings'. Only used in conjunction with
250 'strings'.
7c913512 251 @param clientData
4cc4bfaf 252 Client data to associate with the item(s).
23324ae1
FM
253
254 @returns When the control is sorted (e.g. has wxLB_SORT or wxCB_SORT
4cc4bfaf
FM
255 style) the return value could be different from
256 (GetCount() - 1). When setting a single item to the
257 container, the return value is the index of the newly
258 added item which may be different from the last one if
259 the control is sorted (e.g. has wxLB_SORT or wxCB_SORT
260 style).
23324ae1
FM
261 */
262 int Set(const wxString& item);
4cc4bfaf
FM
263 int Set(const wxString& item, void* clientData);
264 int Set(const wxString& item, wxClientData* clientData);
7c913512
FM
265 void Set(const wxArrayString& stringsArray);
266 void Set(unsigned int n, const wxString* strings);
267 void Set(unsigned int n, const wxString* strings,
4cc4bfaf 268 void** clientData);
7c913512 269 void Set(unsigned int n, const wxString* strings,
4cc4bfaf 270 wxClientData** clientData);
23324ae1
FM
271 //@}
272
273 /**
274 Associates the given untyped client data pointer with the given item. Note that
275 it is an error to call this function if any typed client data pointers had been
276 associated with the control items before.
277
7c913512 278 @param n
4cc4bfaf 279 The zero-based item index.
7c913512 280 @param data
4cc4bfaf 281 The client data to associate with the item.
23324ae1 282 */
4cc4bfaf 283 void SetClientData(unsigned int n, void* data);
23324ae1
FM
284
285 /**
286 Associates the given typed client data pointer with the given item: the
4cc4bfaf 287 @a data object will be deleted when the item is deleted (either explicitly
23324ae1
FM
288 by using @ref delete() Deletes or implicitly when the
289 control itself is destroyed).
23324ae1
FM
290 Note that it is an error to call this function if any untyped client data
291 pointers had been associated with the control items before.
292
7c913512 293 @param n
4cc4bfaf 294 The zero-based item index.
7c913512 295 @param data
4cc4bfaf 296 The client data to associate with the item.
23324ae1 297 */
4cc4bfaf 298 void SetClientObject(unsigned int n, wxClientData* data);
23324ae1
FM
299
300 /**
4cc4bfaf
FM
301 Sets the selection to the given item @a n or removes the selection entirely
302 if @a n == @c wxNOT_FOUND.
23324ae1
FM
303 Note that this does not cause any command events to be emitted nor does it
304 deselect any other items in the controls which support multiple selections.
305
7c913512 306 @param n
4cc4bfaf 307 The string position to select, starting from zero.
23324ae1 308
4cc4bfaf 309 @see SetString(), SetStringSelection()
23324ae1
FM
310 */
311 void SetSelection(int n);
312
313 /**
314 Sets the label for the given item.
315
7c913512 316 @param n
4cc4bfaf 317 The zero-based item index.
7c913512 318 @param string
4cc4bfaf 319 The label to set.
23324ae1
FM
320 */
321 void SetString(unsigned int n, const wxString& string);
322
323 /**
324 Selects the item with the specified string in the control. This doesn't cause
325 any command events to be emitted.
326
7c913512 327 @param string
4cc4bfaf 328 The string to select.
23324ae1
FM
329
330 @returns @true if the specified string has been selected, @false if it
4cc4bfaf 331 wasn't found in the control.
23324ae1
FM
332 */
333 bool SetStringSelection(const wxString& string);
334};
e54c96f1 335