]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/ctrlsub.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxControlWithItems
4 // Author: wxWidgets team
5 // Licence: wxWindows licence
6 /////////////////////////////////////////////////////////////////////////////
10 @class wxItemContainerImmutable
12 wxItemContainer defines an interface which is implemented by all controls
13 which have string subitems each of which may be selected.
15 It is decomposed in wxItemContainerImmutable which omits all methods
16 adding/removing items and is used by wxRadioBox and wxItemContainer itself.
18 Note that this is not a control, it's a mixin interface that classes
19 have to derive from in addition to wxControl or wxWindow.
21 Examples: wxListBox, wxCheckListBox, wxChoice and wxComboBox (which
22 implements an extended interface deriving from this one)
27 @see wxControlWithItems, wxItemContainer
29 class wxItemContainerImmutable
33 wxItemContainerImmutable();
38 Returns the number of items in the control.
42 virtual unsigned int GetCount() const = 0;
45 Returns @true if the control is empty or @false if it has some items.
52 Returns the label of the item with the given index.
57 @return The label of the item or an empty string if the position was
60 virtual wxString
GetString(unsigned int n
) const = 0;
63 Returns the array of the labels of all items in the control.
65 wxArrayString
GetStrings() const;
68 Sets the label for the given item.
71 The zero-based item index.
75 virtual void SetString(unsigned int n
, const wxString
& string
) = 0;
78 Finds an item whose label matches the given string.
83 Whether search is case sensitive (default is not).
85 @return The zero-based position of the item, or wxNOT_FOUND if the
88 virtual int FindString(const wxString
& string
, bool caseSensitive
= false) const;
96 Sets the selection to the given item @a n or removes the selection
97 entirely if @a n == @c wxNOT_FOUND.
99 Note that this does not cause any command events to be emitted nor does
100 it deselect any other items in the controls which support multiple
104 The string position to select, starting from zero.
106 @see SetString(), SetStringSelection()
108 virtual void SetSelection(int n
) = 0;
111 Returns the index of the selected item or @c wxNOT_FOUND if no item is
114 @return The position of the current selection.
116 @remarks This method can be used with single selection list boxes only,
117 you should use wxListBox::GetSelections() for the list
118 boxes with wxLB_MULTIPLE style.
120 @see SetSelection(), GetStringSelection()
122 virtual int GetSelection() const = 0;
125 Selects the item with the specified string in the control.
127 This method doesn't cause any command events to be emitted.
129 Notice that this method is case-insensitive, i.e. the string is
130 compared with all the elements of the control case-insensitively and
131 the first matching entry is selected, even if it doesn't have exactly
132 the same case as this string and there is an exact match afterwards.
135 The string to select.
136 @return @true if the specified string has been selected, @false if it
137 wasn't found in the control.
139 bool SetStringSelection(const wxString
& string
);
142 Returns the label of the selected item or an empty string if no item is
147 virtual wxString
GetStringSelection() const;
150 This is the same as SetSelection() and exists only because it is
151 slightly more natural for controls which support multiple selection.
160 @class wxItemContainer
162 This class is an abstract base class for some wxWidgets controls which
163 contain several items such as wxListBox, wxCheckListBox, wxComboBox or
164 wxChoice. It defines an interface which is implemented by all controls
165 which have string subitems each of which may be selected.
167 wxItemContainer extends wxItemContainerImmutable interface with methods
168 for adding/removing items.
170 It defines the methods for accessing the controls items and although each
171 of the derived classes implements them differently, they still all conform
172 to the same interface.
174 The items in a wxItemContainer have (non-empty) string labels and,
175 optionally, client data associated with them. Client data may be of two
176 different kinds: either simple untyped (@c void *) pointers which are
177 simply stored by the control but not used in any way by it, or typed
178 pointers (wxClientData*) which are owned by the control meaning that the
179 typed client data (and only it) will be deleted when an item is deleted
180 using Delete() or the entire control is cleared using Clear(), which also
181 happens when it is destroyed.
183 Finally note that in the same control all items must have client data of
184 the same type (typed or untyped), if any. This type is determined by the
185 first call to Append() (the version with client data pointer) or
188 Note that this is not a control, it's a mixin interface that classes
189 have to derive from in addition to wxControl or wxWindow. Convenience
190 class wxControlWithItems is provided for this purpose.
195 @see wxControlWithItems, wxItemContainerImmutable
197 class wxItemContainer
: public wxItemContainerImmutable
203 Appends item into the control.
208 @return The return value is the index of the newly inserted item.
209 Note that this may be different from the last one if the
210 control is sorted (e.g. has @c wxLB_SORT or @c wxCB_SORT
213 int Append(const wxString
& item
);
216 Appends item into the control.
221 Pointer to client data to associate with the new item.
223 @return The return value is the index of the newly inserted item.
224 Note that this may be different from the last one if the
225 control is sorted (e.g. has @c wxLB_SORT or @c wxCB_SORT
228 int Append(const wxString
& item
, void* clientData
);
231 Appends item into the control.
236 Pointer to client data to associate with the new item.
238 @return The return value is the index of the newly inserted item.
239 Note that this may be different from the last one if the
240 control is sorted (e.g. has @c wxLB_SORT or @c wxCB_SORT
243 int Append(const wxString
& item
, wxClientData
* clientData
);
246 Appends several items at once into the control.
248 Notice that calling this method is usually much faster than appending
249 them one by one if you need to add a lot of items.
252 Array of strings to insert.
254 int Append(const wxArrayString
& items
);
257 Appends several items at once into the control.
259 Notice that calling this method is usually much faster than appending
260 them one by one if you need to add a lot of items.
263 Array of strings to insert.
265 Array of client data pointers of the same size as @a items to
266 associate with the new items.
268 int Append(const wxArrayString
& items
, void **clientData
);
271 Appends several items at once into the control.
273 Notice that calling this method is usually much faster than appending
274 them one by one if you need to add a lot of items.
277 Array of strings to insert.
279 Array of client data pointers of the same size as @a items to
280 associate with the new items.
282 int Append(const wxArrayString
& items
, wxClientData
**clientData
);
285 Appends several items at once into the control.
287 Notice that calling this method is usually much faster than appending
288 them one by one if you need to add a lot of items.
291 Number of items in the @a items array.
293 Array of strings of size @a n.
295 int Append(unsigned int n
, const wxString
* items
);
298 Appends several items at once into the control.
300 Notice that calling this method is usually much faster than appending
301 them one by one if you need to add a lot of items.
304 Number of items in the @a items array.
306 Array of strings of size @a n.
308 Array of client data pointers of size @a n to associate with the
311 int Append(unsigned int n
, const wxString
* items
,
315 Appends several items at once into the control.
317 Notice that calling this method is usually much faster than appending
318 them one by one if you need to add a lot of items.
321 Number of items in the @a items array.
323 Array of strings of size @a n.
325 Array of client data pointers of size @a n to associate with the
328 int Append(unsigned int n
, const wxString
* items
,
329 wxClientData
** clientData
);
333 Removes all items from the control.
334 Clear() also deletes the client data of the existing items if it is
335 owned by the control.
340 Deletes an item from the control.
342 The client data associated with the item will be also deleted if it is
343 owned by the control. Note that it is an error (signalled by an assert
344 failure in debug builds) to remove an item with the index negative or
345 greater or equal than the number of items in the control.
348 The zero-based item index.
352 void Delete(unsigned int n
);
356 Returns the client object associated with the given item and transfers
357 its ownership to the caller.
359 This method, unlike GetClientObject(), expects the caller to delete the
360 returned pointer. It also replaces the internally stored pointer with
361 @NULL, i.e. completely detaches the client object pointer from the
364 It's an error to call this method unless HasClientObjectData() returns
368 The zero-based item index.
369 @return The associated client object pointer to be deleted by caller or
374 wxClientData
*DetachClientObject(unsigned int n
);
377 Returns true, if either untyped data (@c void*) or object data (wxClientData*)
378 is associated with the items of the control.
380 bool HasClientData() const;
383 Returns true, if object data is associated with the items of the
386 Object data pointers have the type @c wxClientData* instead of @c void*
387 and, importantly, are owned by the control, i.e. will be deleted by it,
388 unlike their untyped counterparts.
390 bool HasClientObjectData() const;
393 Returns true, if untyped data (@c void*)
394 is associated with the items of the control.
396 bool HasClientUntypedData() const;
402 Returns a pointer to the client data associated with the given item (if
403 any). It is an error to call this function for a control which doesn't
404 have untyped client data at all although it is OK to call it even if
405 the given item doesn't have any client data associated with it (but
409 The zero-based position of the item.
411 @return A pointer to the client data, or @NULL if not present.
413 void* GetClientData(unsigned int n
) const;
416 Returns a pointer to the client data associated with the given item (if
417 any). It is an error to call this function for a control which doesn't
418 have typed client data at all although it is OK to call it even if the
419 given item doesn't have any client data associated with it (but other
422 Notice that the returned pointer is still owned by the control and will
423 be deleted by it, use DetachClientObject() if you want to remove the
424 pointer from the control.
427 The zero-based position of the item.
429 @return A pointer to the client data, or @NULL if not present.
431 wxClientData
* GetClientObject(unsigned int n
) const;
434 Associates the given untyped client data pointer with the given item.
435 Note that it is an error to call this function if any typed client data
436 pointers had been associated with the control items before.
439 The zero-based item index.
441 The client data to associate with the item.
443 void SetClientData(unsigned int n
, void* data
);
446 Associates the given typed client data pointer with the given item: the
447 @a data object will be deleted when the item is deleted (either
448 explicitly by using Delete() or implicitly when the control itself is
449 destroyed). Note that it is an error to call this function if any
450 untyped client data pointers had been associated with the control items
454 The zero-based item index.
456 The client data to associate with the item.
458 void SetClientObject(unsigned int n
, wxClientData
* data
);
465 Inserts item into the control.
470 Position to insert item before, zero based.
472 @return The return value is the index of the newly inserted item.
473 If the insertion failed for some reason, -1 is returned.
475 int Insert(const wxString
& item
, unsigned int pos
);
478 Inserts item into the control.
483 Position to insert item before, zero based.
485 Pointer to client data to associate with the new item.
487 @return The return value is the index of the newly inserted item.
488 If the insertion failed for some reason, -1 is returned.
490 int Insert(const wxString
& item
, unsigned int pos
, void* clientData
);
493 Inserts item into the control.
498 Position to insert item before, zero based.
500 Pointer to client data to associate with the new item.
502 @return The return value is the index of the newly inserted item.
503 If the insertion failed for some reason, -1 is returned.
505 int Insert(const wxString
& item
, unsigned int pos
,
506 wxClientData
* clientData
);
509 Inserts several items at once into the control.
511 Notice that calling this method is usually much faster than inserting
512 them one by one if you need to insert a lot of items.
515 Array of strings to insert.
517 Position to insert the items before, zero based.
518 @return The return value is the index of the last inserted item.
519 If the insertion failed for some reason, -1 is returned.
521 int Insert(const wxArrayString
& items
, unsigned int pos
);
524 Inserts several items at once into the control.
526 Notice that calling this method is usually much faster than inserting
527 them one by one if you need to insert a lot of items.
530 Array of strings to insert.
532 Position to insert the items before, zero based.
534 Array of client data pointers of the same size as @a items to
535 associate with the new items.
536 @return The return value is the index of the last inserted item.
537 If the insertion failed for some reason, -1 is returned.
539 int Insert(const wxArrayString
& items
, unsigned int pos
,
543 Inserts several items at once into the control.
545 Notice that calling this method is usually much faster than inserting
546 them one by one if you need to insert a lot of items.
549 Array of strings to insert.
551 Position to insert the items before, zero based.
553 Array of client data pointers of the same size as @a items to
554 associate with the new items.
555 @return The return value is the index of the last inserted item.
556 If the insertion failed for some reason, -1 is returned.
558 int Insert(const wxArrayString
& items
, unsigned int pos
,
559 wxClientData
**clientData
);
562 Inserts several items at once into the control.
564 Notice that calling this method is usually much faster than inserting
565 them one by one if you need to insert a lot of items.
568 Number of items in the @a items array.
570 Array of strings of size @a n.
572 Position to insert the items before, zero based.
573 @return The return value is the index of the last inserted item.
574 If the insertion failed for some reason, -1 is returned.
576 int Insert(unsigned int n
, const wxString
* items
,
580 Inserts several items at once into the control.
582 Notice that calling this method is usually much faster than inserting
583 them one by one if you need to insert a lot of items.
586 Number of items in the @a items array.
588 Array of strings of size @a n.
590 Position to insert the new items before, zero based.
592 Array of client data pointers of size @a n to associate with the
594 @return The return value is the index of the last inserted item.
595 If the insertion failed for some reason, -1 is returned.
597 int Insert(unsigned int n
, const wxString
* items
,
602 Inserts several items at once into the control.
604 Notice that calling this method is usually much faster than inserting
605 them one by one if you need to insert a lot of items.
608 Number of items in the @a items array.
610 Array of strings of size @a n.
612 Position to insert the new items before, zero based.
614 Array of client data pointers of size @a n to associate with the
616 @return The return value is the index of the last inserted item.
617 If the insertion failed for some reason, -1 is returned.
619 int Insert(unsigned int n
, const wxString
* items
,
621 wxClientData
** clientData
);
626 Replaces the current control contents with the given items.
628 Notice that calling this method is usually much faster than appending
629 them one by one if you need to add a lot of items.
632 Array of strings to insert.
634 void Set(const wxArrayString
& items
);
637 Replaces the current control contents with the given items.
639 Notice that calling this method is usually much faster than appending
640 them one by one if you need to add a lot of items.
643 Array of strings to insert.
645 Array of client data pointers of the same size as @a items to
646 associate with the new items.
648 void Set(const wxArrayString
& items
, void **clientData
);
651 Replaces the current control contents with the given items.
653 Notice that calling this method is usually much faster than appending
654 them one by one if you need to add a lot of items.
657 Array of strings to insert.
659 Array of client data pointers of the same size as @a items to
660 associate with the new items.
662 void Set(const wxArrayString
& items
, wxClientData
**clientData
);
665 Replaces the current control contents with the given items.
667 Notice that calling this method is usually much faster than appending
668 them one by one if you need to add a lot of items.
671 Number of items in the @a items array.
673 Array of strings of size @a n.
675 void Set(unsigned int n
, const wxString
* items
);
678 Replaces the current control contents with the given items.
680 Notice that calling this method is usually much faster than appending
681 them one by one if you need to add a lot of items.
684 Number of items in the @a items array.
686 Array of strings of size @a n.
688 Array of client data pointers of size @a n to associate with the
691 void Set(unsigned int n
, const wxString
* items
, void** clientData
);
694 Replaces the current control contents with the given items.
696 Notice that calling this method is usually much faster than appending
697 them one by one if you need to add a lot of items.
700 Number of items in the @a items array.
702 Array of strings of size @a n.
704 Array of client data pointers of size @a n to associate with the
707 void Set(unsigned int n
, const wxString
* items
, wxClientData
** clientData
);
713 @class wxControlWithItems
715 This is convenience class that derives from both wxControl and
716 wxItemContainer. It is used as basis for some wxWidgets controls
717 (wxChoice and wxListBox).
722 @see wxItemContainer, wxItemContainerImmutable
724 class wxControlWithItems
: public wxControl
, public wxItemContainer