]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/ctrlsub.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxControlWithItems
4 // Author: wxWidgets team
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
11 @class wxItemContainerImmutable
13 wxItemContainer defines an interface which is implemented by all controls
14 which have string subitems each of which may be selected.
16 It is decomposed in wxItemContainerImmutable which omits all methods
17 adding/removing items and is used by wxRadioBox and wxItemContainer itself.
19 Note that this is not a control, it's a mixin interface that classes
20 have to derive from in addition to wxControl or wxWindow.
22 Examples: wxListBox, wxCheckListBox, wxChoice and wxComboBox (which
23 implements an extended interface deriving from this one)
28 @see wxControlWithItems, wxItemContainer
30 class wxItemContainerImmutable
34 wxItemContainerImmutable();
39 Returns the number of items in the control.
43 virtual unsigned int GetCount() const = 0;
46 Returns @true if the control is empty or @false if it has some items.
53 Returns the label of the item with the given index.
58 @return The label of the item or an empty string if the position was
61 virtual wxString
GetString(unsigned int n
) const = 0;
64 Returns the array of the labels of all items in the control.
66 wxArrayString
GetStrings() const;
69 Sets the label for the given item.
72 The zero-based item index.
76 virtual void SetString(unsigned int n
, const wxString
& string
) = 0;
79 Finds an item whose label matches the given string.
84 Whether search is case sensitive (default is not).
86 @return The zero-based position of the item, or wxNOT_FOUND if the
89 virtual int FindString(const wxString
& string
, bool caseSensitive
= false) const;
97 Sets the selection to the given item @a n or removes the selection
98 entirely if @a n == @c wxNOT_FOUND.
100 Note that this does not cause any command events to be emitted nor does
101 it deselect any other items in the controls which support multiple
105 The string position to select, starting from zero.
107 @see SetString(), SetStringSelection()
109 virtual void SetSelection(int n
) = 0;
112 Returns the index of the selected item or @c wxNOT_FOUND if no item is
115 @return The position of the current selection.
117 @remarks This method can be used with single selection list boxes only,
118 you should use wxListBox::GetSelections() for the list
119 boxes with wxLB_MULTIPLE style.
121 @see SetSelection(), GetStringSelection()
123 virtual int GetSelection() const = 0;
126 Selects the item with the specified string in the control. This doesn't
127 cause any command events to be emitted.
130 The string to select.
132 @return @true if the specified string has been selected, @false if it
133 wasn't found in the control.
135 bool SetStringSelection(const wxString
& string
);
138 Returns the label of the selected item or an empty string if no item is
143 virtual wxString
GetStringSelection() const;
146 This is the same as SetSelection() and exists only because it is
147 slightly more natural for controls which support multiple selection.
156 @class wxItemContainer
158 This class is an abstract base class for some wxWidgets controls which
159 contain several items such as wxListBox, wxCheckListBox, wxComboBox or
160 wxChoice. It defines an interface which is implemented by all controls
161 which have string subitems each of which may be selected.
163 wxItemContainer extends wxItemContainerImmutable interface with methods
164 for adding/removing items.
166 It defines the methods for accessing the controls items and although each
167 of the derived classes implements them differently, they still all conform
168 to the same interface.
170 The items in a wxItemContainer have (non-empty) string labels and,
171 optionally, client data associated with them. Client data may be of two
172 different kinds: either simple untyped (@c void *) pointers which are
173 simply stored by the control but not used in any way by it, or typed
174 pointers (wxClientData*) which are owned by the control meaning that the
175 typed client data (and only it) will be deleted when an item is deleted
176 using Delete() or the entire control is cleared using Clear(), which also
177 happens when it is destroyed.
179 Finally note that in the same control all items must have client data of
180 the same type (typed or untyped), if any. This type is determined by the
181 first call to Append() (the version with client data pointer) or
184 Note that this is not a control, it's a mixin interface that classes
185 have to derive from in addition to wxControl or wxWindow. Convenience
186 class wxControlWithItems is provided for this purpose.
191 @see wxControlWithItems, wxItemContainerImmutable
193 class wxItemContainer
: public wxItemContainerImmutable
199 Appends item into the control.
204 @return The return value is the index of the newly inserted item.
205 Note that this may be different from the last one if the
206 control is sorted (e.g. has @c wxLB_SORT or @c wxCB_SORT
209 int Append(const wxString
& item
);
212 Appends item into the control.
217 Pointer to client data to associate with the new item.
219 @return The return value is the index of the newly inserted item.
220 Note that this may be different from the last one if the
221 control is sorted (e.g. has @c wxLB_SORT or @c wxCB_SORT
224 int Append(const wxString
& item
, void* clientData
);
227 Appends item into the control.
232 Pointer to client data to associate with the new item.
234 @return The return value is the index of the newly inserted item.
235 Note that this may be different from the last one if the
236 control is sorted (e.g. has @c wxLB_SORT or @c wxCB_SORT
239 int Append(const wxString
& item
, wxClientData
* clientData
);
242 Appends several items at once into the control.
244 Notice that calling this method is usually much faster than appending
245 them one by one if you need to add a lot of items.
248 Array of strings to insert.
250 int Append(const wxArrayString
& items
);
253 Appends several items at once into the control.
255 Notice that calling this method is usually much faster than appending
256 them one by one if you need to add a lot of items.
259 Array of strings to insert.
261 Array of client data pointers of the same size as @a items to
262 associate with the new items.
264 int Append(const wxArrayString
& items
, void **clientData
);
267 Appends several items at once into the control.
269 Notice that calling this method is usually much faster than appending
270 them one by one if you need to add a lot of items.
273 Array of strings to insert.
275 Array of client data pointers of the same size as @a items to
276 associate with the new items.
278 int Append(const wxArrayString
& items
, wxClientData
**clientData
);
281 Appends several items at once into the control.
283 Notice that calling this method is usually much faster than appending
284 them one by one if you need to add a lot of items.
287 Number of items in the @a items array.
289 Array of strings of size @a n.
291 int Append(unsigned int n
, const wxString
* items
);
294 Appends several items at once into the control.
296 Notice that calling this method is usually much faster than appending
297 them one by one if you need to add a lot of items.
300 Number of items in the @a items array.
302 Array of strings of size @a n.
304 Array of client data pointers of size @a n to associate with the
307 int Append(unsigned int n
, const wxString
* items
,
311 Appends several items at once into the control.
313 Notice that calling this method is usually much faster than appending
314 them one by one if you need to add a lot of items.
317 Number of items in the @a items array.
319 Array of strings of size @a n.
321 Array of client data pointers of size @a n to associate with the
324 int Append(unsigned int n
, const wxString
* items
,
325 wxClientData
** clientData
);
329 Removes all items from the control.
330 Clear() also deletes the client data of the existing items if it is
331 owned by the control.
336 Deletes an item from the control.
338 The client data associated with the item will be also deleted if it is
339 owned by the control. Note that it is an error (signalled by an assert
340 failure in debug builds) to remove an item with the index negative or
341 greater or equal than the number of items in the control.
344 The zero-based item index.
348 void Delete(unsigned int n
);
352 Returns the client object associated with the given item and transfers
353 its ownership to the caller.
355 This method, unlike GetClientObject(), expects the caller to delete the
356 returned pointer. It also replaces the internally stored pointer with
357 @NULL, i.e. completely detaches the client object pointer from the
360 It's an error to call this method unless HasClientObjectData() returns
364 The zero-based item index.
365 @return The associated client object pointer to be deleted by caller or
370 wxClientData
*DetachClientObject(unsigned int n
);
373 Returns true, if either untyped data (@c void*) or object data (wxClientData*)
374 is associated with the items of the control.
376 bool HasClientData() const;
379 Returns true, if object data is associated with the items of the
382 Object data pointers have the type @c wxClientData* instead of @c void*
383 and, importantly, are owned by the control, i.e. will be deleted by it,
384 unlike their untyped counterparts.
386 bool HasClientObjectData() const;
389 Returns true, if untyped data (@c void*)
390 is associated with the items of the control.
392 bool HasClientUntypedData() const;
398 Returns a pointer to the client data associated with the given item (if
399 any). It is an error to call this function for a control which doesn't
400 have untyped client data at all although it is OK to call it even if
401 the given item doesn't have any client data associated with it (but
405 The zero-based position of the item.
407 @return A pointer to the client data, or @NULL if not present.
409 void* GetClientData(unsigned int n
) const;
412 Returns a pointer to the client data associated with the given item (if
413 any). It is an error to call this function for a control which doesn't
414 have typed client data at all although it is OK to call it even if the
415 given item doesn't have any client data associated with it (but other
418 Notice that the returned pointer is still owned by the control and will
419 be deleted by it, use DetachClientObject() if you want to remove the
420 pointer from the control.
423 The zero-based position of the item.
425 @return A pointer to the client data, or @NULL if not present.
427 wxClientData
* GetClientObject(unsigned int n
) const;
430 Associates the given untyped client data pointer with the given item.
431 Note that it is an error to call this function if any typed client data
432 pointers had been associated with the control items before.
435 The zero-based item index.
437 The client data to associate with the item.
439 void SetClientData(unsigned int n
, void* data
);
442 Associates the given typed client data pointer with the given item: the
443 @a data object will be deleted when the item is deleted (either
444 explicitly by using Delete() or implicitly when the control itself is
445 destroyed). Note that it is an error to call this function if any
446 untyped client data pointers had been associated with the control items
450 The zero-based item index.
452 The client data to associate with the item.
454 void SetClientObject(unsigned int n
, wxClientData
* data
);
461 Inserts item into the control.
466 Position to insert item before, zero based.
468 @return The return value is the index of the newly inserted item.
469 If the insertion failed for some reason, -1 is returned.
471 int Insert(const wxString
& item
, unsigned int pos
);
474 Inserts item into the control.
479 Position to insert item before, zero based.
481 Pointer to client data to associate with the new item.
483 @return The return value is the index of the newly inserted item.
484 If the insertion failed for some reason, -1 is returned.
486 int Insert(const wxString
& item
, unsigned int pos
, void* clientData
);
489 Inserts item into the control.
494 Position to insert item before, zero based.
496 Pointer to client data to associate with the new item.
498 @return The return value is the index of the newly inserted item.
499 If the insertion failed for some reason, -1 is returned.
501 int Insert(const wxString
& item
, 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 Array of strings to insert.
513 Position to insert the items before, zero based.
514 @return The return value is the index of the last inserted item.
515 If the insertion failed for some reason, -1 is returned.
517 int Insert(const wxArrayString
& items
, unsigned int pos
);
520 Inserts several items at once into the control.
522 Notice that calling this method is usually much faster than inserting
523 them one by one if you need to insert a lot of items.
526 Array of strings to insert.
528 Position to insert the items before, zero based.
530 Array of client data pointers of the same size as @a items to
531 associate with the new items.
532 @return The return value is the index of the last inserted item.
533 If the insertion failed for some reason, -1 is returned.
535 int Insert(const wxArrayString
& items
, unsigned int pos
,
539 Inserts several items at once into the control.
541 Notice that calling this method is usually much faster than inserting
542 them one by one if you need to insert a lot of items.
545 Array of strings to insert.
547 Position to insert the items before, zero based.
549 Array of client data pointers of the same size as @a items to
550 associate with the new items.
551 @return The return value is the index of the last inserted item.
552 If the insertion failed for some reason, -1 is returned.
554 int Insert(const wxArrayString
& items
, unsigned int pos
,
555 wxClientData
**clientData
);
558 Inserts several items at once into the control.
560 Notice that calling this method is usually much faster than inserting
561 them one by one if you need to insert a lot of items.
564 Number of items in the @a items array.
566 Array of strings of size @a n.
568 Position to insert the items before, zero based.
569 @return The return value is the index of the last inserted item.
570 If the insertion failed for some reason, -1 is returned.
572 int Insert(unsigned int n
, const wxString
* items
,
576 Inserts several items at once into the control.
578 Notice that calling this method is usually much faster than inserting
579 them one by one if you need to insert a lot of items.
582 Number of items in the @a items array.
584 Array of strings of size @a n.
586 Position to insert the new items before, zero based.
588 Array of client data pointers of size @a n to associate with the
590 @return The return value is the index of the last inserted item.
591 If the insertion failed for some reason, -1 is returned.
593 int Insert(unsigned int n
, const wxString
* items
,
598 Inserts several items at once into the control.
600 Notice that calling this method is usually much faster than inserting
601 them one by one if you need to insert a lot of items.
604 Number of items in the @a items array.
606 Array of strings of size @a n.
608 Position to insert the new items before, zero based.
610 Array of client data pointers of size @a n to associate with the
612 @return The return value is the index of the last inserted item.
613 If the insertion failed for some reason, -1 is returned.
615 int Insert(unsigned int n
, const wxString
* items
,
617 wxClientData
** clientData
);
622 Replaces the current control contents with the given items.
624 Notice that calling this method is usually much faster than appending
625 them one by one if you need to add a lot of items.
628 Array of strings to insert.
630 void Set(const wxArrayString
& items
);
633 Replaces the current control contents with the given items.
635 Notice that calling this method is usually much faster than appending
636 them one by one if you need to add a lot of items.
639 Array of strings to insert.
641 Array of client data pointers of the same size as @a items to
642 associate with the new items.
644 void Set(const wxArrayString
& items
, void **clientData
);
647 Replaces the current control contents with the given items.
649 Notice that calling this method is usually much faster than appending
650 them one by one if you need to add a lot of items.
653 Array of strings to insert.
655 Array of client data pointers of the same size as @a items to
656 associate with the new items.
658 void Set(const wxArrayString
& items
, wxClientData
**clientData
);
661 Replaces the current control contents with the given items.
663 Notice that calling this method is usually much faster than appending
664 them one by one if you need to add a lot of items.
667 Number of items in the @a items array.
669 Array of strings of size @a n.
671 void Set(unsigned int n
, const wxString
* items
);
674 Replaces the current control contents with the given items.
676 Notice that calling this method is usually much faster than appending
677 them one by one if you need to add a lot of items.
680 Number of items in the @a items array.
682 Array of strings of size @a n.
684 Array of client data pointers of size @a n to associate with the
687 void Set(unsigned int n
, const wxString
* items
, void** clientData
);
690 Replaces the current control contents with the given items.
692 Notice that calling this method is usually much faster than appending
693 them one by one if you need to add a lot of items.
696 Number of items in the @a items array.
698 Array of strings of size @a n.
700 Array of client data pointers of size @a n to associate with the
703 void Set(unsigned int n
, const wxString
* items
, wxClientData
** clientData
);
709 @class wxControlWithItems
711 This is convenience class that derives from both wxControl and
712 wxItemContainer. It is used as basis for some wxWidgets controls
713 (wxChoice and wxListBox).
718 @see wxItemContainer, wxItemContainerImmutable
720 class wxControlWithItems
: public wxControl
, public wxItemContainer