]> git.saurik.com Git - wxWidgets.git/blame - interface/ctrlsub.h
reverted wxVideoMode API breakage by r53049, finished documentation for it
[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 13 This class is an abstract base class for some wxWidgets controls which contain
7690a4ca
RR
14 several items such as wxListBox, wxCheckListBox, wxChoice and wxComboBox derive
15 from it.
16
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
7690a4ca
RR
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
30 destroyed.
31
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
23324ae1
FM
34 the first call to wxControlWithItems::Append (the version with
35 client data pointer) or wxControlWithItems::SetClientData.
7c913512 36
23324ae1 37 @library{wxcore}
7690a4ca 38 @category{controls}
7c913512 39
e54c96f1 40 @see wxControlWithItems::Clear
23324ae1
FM
41*/
42class wxControlWithItems : public wxControl
43{
44public:
45 //@{
46 /**
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
49 of items.
3c4f71cc 50
7c913512 51 @param item
4cc4bfaf 52 String to add.
7c913512 53 @param stringsArray
4cc4bfaf 54 Contains items to append to the control.
7c913512 55 @param strings
4cc4bfaf 56 Array of strings of size n.
7c913512 57 @param n
4cc4bfaf 58 Number of items in the strings array.
7c913512 59 @param clientData
4cc4bfaf 60 Array of client data pointers of size n to associate with the new items.
3c4f71cc 61
23324ae1 62 @returns When appending a single item, the return value is the index of
4cc4bfaf
FM
63 the newly added item which may be different from the
64 last one if the control is sorted (e.g. has wxLB_SORT
65 or wxCB_SORT style).
23324ae1
FM
66 */
67 int Append(const wxString& item);
4cc4bfaf
FM
68 int Append(const wxString& item, void* clientData);
69 int Append(const wxString& item, wxClientData* clientData);
7c913512
FM
70 void Append(const wxArrayString& strings);
71 void Append(unsigned int n, const wxString* strings);
72 void Append(unsigned int n, const wxString* strings,
4cc4bfaf 73 void** clientData);
7c913512 74 void Append(unsigned int n, const wxString* strings,
4cc4bfaf 75 wxClientData** clientData);
23324ae1
FM
76 //@}
77
78 /**
79 Removes all items from the control.
23324ae1
FM
80 @e Clear() also deletes the client data of the existing items if it is owned
81 by the control.
82 */
83 void Clear();
84
85 /**
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.
23324ae1
FM
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
90 items in the control.
3c4f71cc 91
7c913512 92 @param n
4cc4bfaf 93 The zero-based item index.
3c4f71cc 94
4cc4bfaf 95 @see Clear()
23324ae1
FM
96 */
97 void Delete(unsigned int n);
98
99 /**
100 Finds an item whose label matches the given string.
3c4f71cc 101
7c913512 102 @param string
4cc4bfaf 103 String to find.
7c913512 104 @param caseSensitive
4cc4bfaf 105 Whether search is case sensitive (default is not).
3c4f71cc 106
23324ae1 107 @returns The zero-based position of the item, or wxNOT_FOUND if the
4cc4bfaf 108 string was not found.
23324ae1
FM
109 */
110 int FindString(const wxString& string,
4cc4bfaf 111 bool caseSensitive = false);
23324ae1
FM
112
113 /**
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).
3c4f71cc 118
7c913512 119 @param n
4cc4bfaf 120 The zero-based position of the item.
3c4f71cc 121
23324ae1
FM
122 @returns A pointer to the client data, or @NULL if not present.
123 */
328f5751 124 void* GetClientData(unsigned int n) const;
23324ae1
FM
125
126 /**
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).
3c4f71cc 131
7c913512 132 @param n
4cc4bfaf 133 The zero-based position of the item.
3c4f71cc 134
23324ae1
FM
135 @returns A pointer to the client data, or @NULL if not present.
136 */
328f5751 137 wxClientData* GetClientObject(unsigned int n) const;
23324ae1
FM
138
139 /**
140 Returns the number of items in the control.
3c4f71cc 141
4cc4bfaf 142 @see IsEmpty()
23324ae1 143 */
328f5751 144 unsigned int GetCount() const;
23324ae1
FM
145
146 /**
147 Returns the index of the selected item or @c wxNOT_FOUND if no item is
148 selected.
3c4f71cc 149
23324ae1 150 @returns The position of the current selection.
3c4f71cc 151
23324ae1 152 @remarks This method can be used with single selection list boxes only,
4cc4bfaf
FM
153 you should use wxListBox::GetSelections for the list
154 boxes with wxLB_MULTIPLE style.
3c4f71cc 155
4cc4bfaf 156 @see SetSelection(), GetStringSelection()
23324ae1 157 */
328f5751 158 int GetSelection() const;
23324ae1
FM
159
160 /**
161 Returns the label of the item with the given index.
3c4f71cc 162
7c913512 163 @param n
4cc4bfaf 164 The zero-based index.
3c4f71cc 165
23324ae1 166 @returns The label of the item or an empty string if the position was
4cc4bfaf 167 invalid.
23324ae1 168 */
328f5751 169 wxString GetString(unsigned int n) const;
23324ae1
FM
170
171 /**
172 Returns the label of the selected item or an empty string if no item is
173 selected.
3c4f71cc 174
4cc4bfaf 175 @see GetSelection()
23324ae1 176 */
328f5751 177 wxString GetStringSelection() const;
23324ae1
FM
178
179 /**
180 Returns the array of the labels of all items in the control.
181 */
328f5751 182 wxArrayString GetStrings() const;
23324ae1
FM
183
184 //@{
185 /**
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
188 lot
189 of items.
3c4f71cc 190
7c913512 191 @param item
4cc4bfaf 192 String to add.
7c913512 193 @param pos
4cc4bfaf 194 Position to insert item before, zero based.
7c913512 195 @param stringsArray
4cc4bfaf 196 Contains items to insert into the control content
7c913512 197 @param strings
4cc4bfaf 198 Array of strings of size n.
7c913512 199 @param n
4cc4bfaf 200 Number of items in the strings array.
7c913512 201 @param clientData
4cc4bfaf 202 Array of client data pointers of size n to associate with the new items.
3c4f71cc 203
23324ae1 204 @returns The return value is the index of the newly inserted item. If the
4cc4bfaf 205 insertion failed for some reason, -1 is returned.
23324ae1
FM
206 */
207 int Insert(const wxString& item, unsigned int pos);
7c913512 208 int Insert(const wxString& item, unsigned int pos,
4cc4bfaf 209 void* clientData);
7c913512 210 int Insert(const wxString& item, unsigned int pos,
4cc4bfaf 211 wxClientData* clientData);
7c913512
FM
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,
215 unsigned int pos);
216 void Insert(unsigned int n, const wxString* strings,
217 unsigned int pos,
4cc4bfaf 218 void** clientData);
7c913512
FM
219 void Insert(unsigned int n, const wxString* strings,
220 unsigned int pos,
4cc4bfaf 221 wxClientData** clientData);
23324ae1
FM
222 //@}
223
224 /**
225 Returns @true if the control is empty or @false if it has some items.
3c4f71cc 226
4cc4bfaf 227 @see GetCount()
23324ae1 228 */
328f5751 229 bool IsEmpty() const;
23324ae1
FM
230
231 /**
232 This is the same as SetSelection() and
233 exists only because it is slightly more natural for controls which support
234 multiple selection.
235 */
236 void Select(int n);
237
238 //@{
239 /**
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.
3c4f71cc 243
7c913512 244 @param item
4cc4bfaf 245 The single item to insert into the control.
7c913512 246 @param stringsArray
4cc4bfaf 247 Contains items to set as control content.
7c913512 248 @param strings
4cc4bfaf 249 Raw C++ array of strings. Only used in conjunction with 'n'.
7c913512 250 @param n
4cc4bfaf
FM
251 Number of items passed in 'strings'. Only used in conjunction with
252 'strings'.
7c913512 253 @param clientData
4cc4bfaf 254 Client data to associate with the item(s).
3c4f71cc 255
23324ae1 256 @returns When the control is sorted (e.g. has wxLB_SORT or wxCB_SORT
4cc4bfaf
FM
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
262 style).
23324ae1
FM
263 */
264 int Set(const wxString& item);
4cc4bfaf
FM
265 int Set(const wxString& item, void* clientData);
266 int Set(const wxString& item, wxClientData* clientData);
7c913512
FM
267 void Set(const wxArrayString& stringsArray);
268 void Set(unsigned int n, const wxString* strings);
269 void Set(unsigned int n, const wxString* strings,
4cc4bfaf 270 void** clientData);
7c913512 271 void Set(unsigned int n, const wxString* strings,
4cc4bfaf 272 wxClientData** clientData);
23324ae1
FM
273 //@}
274
275 /**
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.
3c4f71cc 279
7c913512 280 @param n
4cc4bfaf 281 The zero-based item index.
7c913512 282 @param data
4cc4bfaf 283 The client data to associate with the item.
23324ae1 284 */
4cc4bfaf 285 void SetClientData(unsigned int n, void* data);
23324ae1
FM
286
287 /**
288 Associates the given typed client data pointer with the given item: the
4cc4bfaf 289 @a data object will be deleted when the item is deleted (either explicitly
23324ae1
FM
290 by using @ref delete() Deletes or implicitly when the
291 control itself is destroyed).
23324ae1
FM
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.
3c4f71cc 294
7c913512 295 @param n
4cc4bfaf 296 The zero-based item index.
7c913512 297 @param data
4cc4bfaf 298 The client data to associate with the item.
23324ae1 299 */
4cc4bfaf 300 void SetClientObject(unsigned int n, wxClientData* data);
23324ae1
FM
301
302 /**
4cc4bfaf
FM
303 Sets the selection to the given item @a n or removes the selection entirely
304 if @a n == @c wxNOT_FOUND.
23324ae1
FM
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.
3c4f71cc 307
7c913512 308 @param n
4cc4bfaf 309 The string position to select, starting from zero.
3c4f71cc 310
4cc4bfaf 311 @see SetString(), SetStringSelection()
23324ae1
FM
312 */
313 void SetSelection(int n);
314
315 /**
316 Sets the label for the given item.
3c4f71cc 317
7c913512 318 @param n
4cc4bfaf 319 The zero-based item index.
7c913512 320 @param string
4cc4bfaf 321 The label to set.
23324ae1
FM
322 */
323 void SetString(unsigned int n, const wxString& string);
324
325 /**
326 Selects the item with the specified string in the control. This doesn't cause
327 any command events to be emitted.
3c4f71cc 328
7c913512 329 @param string
4cc4bfaf 330 The string to select.
3c4f71cc 331
23324ae1 332 @returns @true if the specified string has been selected, @false if it
4cc4bfaf 333 wasn't found in the control.
23324ae1
FM
334 */
335 bool SetStringSelection(const wxString& string);
336};
e54c96f1 337