]>
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 /////////////////////////////////////////////////////////////////////////////
11 @class wxItemContainerImmutable
14 wxItemContainer defines an interface which is implemented by all controls
15 which have string subitems each of which may be selected.
17 It is decomposed in wxItemContainerImmutable which omits all methods
18 adding/removing items and is used by wxRadioBox and wxItemContainer itself.
20 Note that this is not a control, it's a mixin interface that classes
21 have to derive from in addition to wxControl or wxWindow.
23 Examples: wxListBox, wxCheckListBox, wxChoice and wxComboBox (which
24 implements an extended interface deriving from this one)
29 @see wxControlWithItems, wxItemContainer
31 class wxItemContainerImmutable
35 wxItemContainerImmutable();
40 Returns the number of items in the control.
44 virtual unsigned int GetCount() const;
47 Returns @true if the control is empty or @false if it has some items.
54 Returns the label of the item with the given index.
59 @returns The label of the item or an empty string if the position was
62 virtual wxString
GetString(unsigned int n
) const;
65 Returns the array of the labels of all items in the control.
67 wxArrayString
GetStrings() const;
70 Sets the label for the given item.
73 The zero-based item index.
77 virtual void SetString(unsigned int n
, const wxString
& s
);
80 Finds an item whose label matches the given string.
85 Whether search is case sensitive (default is not).
87 @returns The zero-based position of the item, or wxNOT_FOUND if the
90 virtual int FindString(const wxString
& s
, bool bCase
= false) const;
98 Sets the selection to the given item @a n or removes the selection
99 entirely if @a n == @c wxNOT_FOUND.
101 Note that this does not cause any command events to be emitted nor does
102 it deselect any other items in the controls which support multiple
106 The string position to select, starting from zero.
108 @see SetString(), SetStringSelection()
110 virtual void SetSelection(int n
);
113 Returns the index of the selected item or @c wxNOT_FOUND if no item is
116 @returns The position of the current selection.
118 @remarks This method can be used with single selection list boxes only,
119 you should use wxListBox::GetSelections() for the list
120 boxes with wxLB_MULTIPLE style.
122 @see SetSelection(), GetStringSelection()
124 virtual int GetSelection() const;
127 Selects the item with the specified string in the control. This doesn't
128 cause any command events to be emitted.
131 The string to select.
133 @returns @true if the specified string has been selected, @false if it
134 wasn't found in the control.
136 bool SetStringSelection(const wxString
& string
);
139 Returns the label of the selected item or an empty string if no item is
144 virtual wxString
GetStringSelection() const;
147 This is the same as SetSelection() and exists only because it is
148 slightly more natural for controls which support multiple selection.
157 @class wxItemContainer
160 This class is an abstract base class for some wxWidgets controls which
161 contain several items such as wxListBox, wxCheckListBox, wxComboBox or
162 wxChoice. It defines an interface which is implemented by all controls
163 which have string subitems each of which may be selected.
165 wxItemContainer extends wxItemContainerImmutable interface with methods
166 for adding/removing items.
168 It defines the methods for accessing the controls items and although each
169 of the derived classes implements them differently, they still all conform
170 to the same interface.
172 The items in a wxItemContainer have (non-empty) string labels and,
173 optionally, client data associated with them. Client data may be of two
174 different kinds: either simple untyped (@c void *) pointers which are
175 simply stored by the control but not used in any way by it, or typed
176 pointers (wxClientData*) which are owned by the control meaning that the
177 typed client data (and only it) will be deleted when an item is deleted
178 using Delete() or the entire control is cleared using Clear(), which also
179 happens when it is destroyed.
181 Finally note that in the same control all items must have client data of
182 the same type (typed or untyped), if any. This type is determined by the
183 first call to Append() (the version with client data pointer) or
186 Note that this is not a control, it's a mixin interface that classes
187 have to derive from in addition to wxControl or wxWindow. Convenience
188 class wxControlWithItems is provided for this purpose.
193 @see wxControlWithItems, wxItemContainerImmutable
195 class wxItemContainer
: public wxItemContainerImmutable
201 Appends item into the control.
206 @returns The return value is the index of the newly inserted item.
207 Note that this may be different from the last one if the
208 control is sorted (e.g. has @c wxLB_SORT or @c wxCB_SORT
211 int Append(const wxString
& item
);
214 Appends item into the control.
219 Pointer to client data to associate with the new item.
221 @returns The return value is the index of the newly inserted item.
222 Note that this may be different from the last one if the
223 control is sorted (e.g. has @c wxLB_SORT or @c wxCB_SORT
226 int Append(const wxString
& item
, void* clientData
);
229 Appends item into the control.
234 Pointer to client data to associate with the new item.
236 @returns The return value is the index of the newly inserted item.
237 Note that this may be different from the last one if the
238 control is sorted (e.g. has @c wxLB_SORT or @c wxCB_SORT
241 int Append(const wxString
& item
, wxClientData
* clientData
);
244 Appends several items at once into the control.
246 Notice that calling this method is usually much faster than appending
247 them one by one if you need to add a lot of items.
250 Array of strings to insert.
252 void Append(const wxArrayString
& items
);
255 Appends several items at once into the control.
257 Notice that calling this method is usually much faster than appending
258 them one by one if you need to add a lot of items.
261 Array of strings to insert.
263 Array of client data pointers of the same size as @a items to
264 associate with the new items.
266 void Append(const wxArrayString
& items
, void **clientData
);
269 Appends several items at once into the control.
271 Notice that calling this method is usually much faster than appending
272 them one by one if you need to add a lot of items.
275 Array of strings to insert.
277 Array of client data pointers of the same size as @a items to
278 associate with the new items.
280 void Append(const wxArrayString
& items
, wxClientData
**clientData
);
283 Appends several items at once into the control.
285 Notice that calling this method is usually much faster than appending
286 them one by one if you need to add a lot of items.
289 Number of items in the @a items array.
291 Array of strings of size @a n.
293 void Append(unsigned int n
, const wxString
* items
);
296 Appends several items at once into the control.
298 Notice that calling this method is usually much faster than appending
299 them one by one if you need to add a lot of items.
302 Number of items in the @a items array.
304 Array of strings of size @a n.
306 Array of client data pointers of size @a n to associate with the
309 void Append(unsigned int n
, const wxString
* items
,
313 Appends several items at once into the control.
315 Notice that calling this method is usually much faster than appending
316 them one by one if you need to add a lot of items.
319 Number of items in the @a items array.
321 Array of strings of size @a n.
323 Array of client data pointers of size @a n to associate with the
326 void Append(unsigned int n
, const wxString
* items
,
327 wxClientData
** clientData
);
331 Removes all items from the control.
332 Clear() also deletes the client data of the existing items if it is
333 owned by the control.
338 Deletes an item from the control.
340 The client data associated with the item will be also deleted if it is
341 owned by the control. Note that it is an error (signalled by an assert
342 failure in debug builds) to remove an item with the index negative or
343 greater or equal than the number of items in the control.
346 The zero-based item index.
350 void Delete(unsigned int n
);
355 Returns a pointer to the client data associated with the given item (if
356 any). It is an error to call this function for a control which doesn't
357 have untyped client data at all although it is OK to call it even if
358 the given item doesn't have any client data associated with it (but
362 The zero-based position of the item.
364 @returns A pointer to the client data, or @NULL if not present.
366 void* GetClientData(unsigned int n
) const;
369 Returns a pointer to the client data associated with the given item (if
370 any). It is an error to call this function for a control which doesn't
371 have typed client data at all although it is OK to call it even if the
372 given item doesn't have any client data associated with it (but other
376 The zero-based position of the item.
378 @returns A pointer to the client data, or @NULL if not present.
380 wxClientData
* GetClientObject(unsigned int n
) const;
383 Associates the given untyped client data pointer with the given item.
384 Note that it is an error to call this function if any typed client data
385 pointers had been associated with the control items before.
388 The zero-based item index.
390 The client data to associate with the item.
392 void SetClientData(unsigned int n
, void* data
);
395 Associates the given typed client data pointer with the given item: the
396 @a data object will be deleted when the item is deleted (either
397 explicitly by using Delete() or implicitly when the control itself is
398 destroyed). Note that it is an error to call this function if any
399 untyped client data pointers had been associated with the control items
403 The zero-based item index.
405 The client data to associate with the item.
407 void SetClientObject(unsigned int n
, wxClientData
* data
);
414 Inserts item into the control.
419 Position to insert item before, zero based.
421 @returns The return value is the index of the newly inserted item.
422 If the insertion failed for some reason, -1 is returned.
424 int Insert(const wxString
& item
, unsigned int pos
);
427 Inserts item into the control.
432 Position to insert item before, zero based.
434 Pointer to client data to associate with the new item.
436 @returns The return value is the index of the newly inserted item.
437 If the insertion failed for some reason, -1 is returned.
439 int Insert(const wxString
& item
, unsigned int pos
, void* clientData
);
442 Inserts item into the control.
447 Position to insert item before, zero based.
449 Pointer to client data to associate with the new item.
451 @returns The return value is the index of the newly inserted item.
452 If the insertion failed for some reason, -1 is returned.
454 int Insert(const wxString
& item
, unsigned int pos
,
455 wxClientData
* clientData
);
458 Inserts several items at once into the control.
460 Notice that calling this method is usually much faster than inserting
461 them one by one if you need to insert a lot of items.
464 Array of strings to insert.
466 Position to insert the items before, zero based.
468 void Insert(const wxArrayString
& items
, unsigned int pos
);
471 Inserts several items at once into the control.
473 Notice that calling this method is usually much faster than inserting
474 them one by one if you need to insert a lot of items.
477 Array of strings to insert.
479 Position to insert the items before, zero based.
481 Array of client data pointers of the same size as @a items to
482 associate with the new items.
484 void Insert(const wxArrayString
& items
, unsigned int pos
,
488 Inserts several items at once into the control.
490 Notice that calling this method is usually much faster than inserting
491 them one by one if you need to insert a lot of items.
494 Array of strings to insert.
496 Position to insert the items before, zero based.
498 Array of client data pointers of the same size as @a items to
499 associate with the new items.
501 void Insert(const wxArrayString
& items
, unsigned int pos
,
502 wxClientData
**clientData
);
505 Inserts several items at once into the control.
507 Notice that calling this method is usually much faster than inserting
508 them one by one if you need to insert a lot of items.
511 Number of items in the @a items array.
513 Array of strings of size @a n.
515 Position to insert the items before, zero based.
517 void Insert(unsigned int n
, const wxString
* items
,
521 Inserts several items at once into the control.
523 Notice that calling this method is usually much faster than inserting
524 them one by one if you need to insert a lot of items.
527 Number of items in the @a items array.
529 Array of strings of size @a n.
531 Position to insert the new items before, zero based.
533 Array of client data pointers of size @a n to associate with the
536 void Insert(unsigned int n
, const wxString
* items
,
541 Inserts several items at once into the control.
543 Notice that calling this method is usually much faster than inserting
544 them one by one if you need to insert a lot of items.
547 Number of items in the @a items array.
549 Array of strings of size @a n.
551 Position to insert the new items before, zero based.
553 Array of client data pointers of size @a n to associate with the
556 void Insert(unsigned int n
, const wxString
* items
,
558 wxClientData
** clientData
);
563 Replaces the current control contents with the given items.
565 Notice that calling this method is usually much faster than appending
566 them one by one if you need to add a lot of items.
569 Array of strings to insert.
571 void Set(const wxArrayString
& items
);
574 Replaces the current control contents with the given items.
576 Notice that calling this method is usually much faster than appending
577 them one by one if you need to add a lot of items.
580 Array of strings to insert.
582 Array of client data pointers of the same size as @a items to
583 associate with the new items.
585 void Set(const wxArrayString
& items
, void **clientData
);
588 Replaces the current control contents with the given items.
590 Notice that calling this method is usually much faster than appending
591 them one by one if you need to add a lot of items.
594 Array of strings to insert.
596 Array of client data pointers of the same size as @a items to
597 associate with the new items.
599 void Set(const wxArrayString
& items
, wxClientData
**clientData
);
602 Replaces the current control contents with the given items.
604 Notice that calling this method is usually much faster than appending
605 them one by one if you need to add a lot of items.
608 Number of items in the @a items array.
610 Array of strings of size @a n.
612 void Set(unsigned int n
, const wxString
* items
);
615 Replaces the current control contents with the given items.
617 Notice that calling this method is usually much faster than appending
618 them one by one if you need to add a lot of items.
621 Number of items in the @a items array.
623 Array of strings of size @a n.
625 Array of client data pointers of size @a n to associate with the
628 void Set(unsigned int n
, const wxString
* items
, void** clientData
);
631 Replaces the current control contents with the given items.
633 Notice that calling this method is usually much faster than appending
634 them one by one if you need to add a lot of items.
637 Number of items in the @a items array.
639 Array of strings of size @a n.
641 Array of client data pointers of size @a n to associate with the
644 void Set(unsigned int n
, const wxString
* items
, wxClientData
** clientData
);
650 @class wxControlWithItems
653 This is convenience class that derives from both wxControl and
654 wxItemContainer. It is used as basis for some wxWidgets controls
655 (wxChoice and wxListBox).
660 @see wxItemContainer, wxItemContainerImmutable
662 class wxControlWithItems
: public wxControl
, public wxItemContainer