]>
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.
128 This method doesn't cause any command events to be emitted.
130 Notice that this method is case-insensitive, i.e. the string is
131 compared with all the elements of the control case-insensitively and
132 the first matching entry is selected, even if it doesn't have exactly
133 the same case as this string and there is an exact match afterwards.
136 The string to select.
137 @return @true if the specified string has been selected, @false if it
138 wasn't found in the control.
140 bool SetStringSelection(const wxString
& string
);
143 Returns the label of the selected item or an empty string if no item is
148 virtual wxString
GetStringSelection() const;
151 This is the same as SetSelection() and exists only because it is
152 slightly more natural for controls which support multiple selection.
161 @class wxItemContainer
163 This class is an abstract base class for some wxWidgets controls which
164 contain several items such as wxListBox, wxCheckListBox, wxComboBox or
165 wxChoice. It defines an interface which is implemented by all controls
166 which have string subitems each of which may be selected.
168 wxItemContainer extends wxItemContainerImmutable interface with methods
169 for adding/removing items.
171 It defines the methods for accessing the controls items and although each
172 of the derived classes implements them differently, they still all conform
173 to the same interface.
175 The items in a wxItemContainer have (non-empty) string labels and,
176 optionally, client data associated with them. Client data may be of two
177 different kinds: either simple untyped (@c void *) pointers which are
178 simply stored by the control but not used in any way by it, or typed
179 pointers (wxClientData*) which are owned by the control meaning that the
180 typed client data (and only it) will be deleted when an item is deleted
181 using Delete() or the entire control is cleared using Clear(), which also
182 happens when it is destroyed.
184 Finally note that in the same control all items must have client data of
185 the same type (typed or untyped), if any. This type is determined by the
186 first call to Append() (the version with client data pointer) or
189 Note that this is not a control, it's a mixin interface that classes
190 have to derive from in addition to wxControl or wxWindow. Convenience
191 class wxControlWithItems is provided for this purpose.
196 @see wxControlWithItems, wxItemContainerImmutable
198 class wxItemContainer
: public wxItemContainerImmutable
204 Appends item into the control.
209 @return The return value is the index of the newly inserted item.
210 Note that this may be different from the last one if the
211 control is sorted (e.g. has @c wxLB_SORT or @c wxCB_SORT
214 int Append(const wxString
& item
);
217 Appends item into the control.
222 Pointer to client data to associate with the new item.
224 @return The return value is the index of the newly inserted item.
225 Note that this may be different from the last one if the
226 control is sorted (e.g. has @c wxLB_SORT or @c wxCB_SORT
229 int Append(const wxString
& item
, void* clientData
);
232 Appends item into the control.
237 Pointer to client data to associate with the new item.
239 @return The return value is the index of the newly inserted item.
240 Note that this may be different from the last one if the
241 control is sorted (e.g. has @c wxLB_SORT or @c wxCB_SORT
244 int Append(const wxString
& item
, wxClientData
* clientData
);
247 Appends several items at once into the control.
249 Notice that calling this method is usually much faster than appending
250 them one by one if you need to add a lot of items.
253 Array of strings to insert.
255 int Append(const wxArrayString
& items
);
258 Appends several items at once into the control.
260 Notice that calling this method is usually much faster than appending
261 them one by one if you need to add a lot of items.
264 Array of strings to insert.
266 Array of client data pointers of the same size as @a items to
267 associate with the new items.
269 int Append(const wxArrayString
& items
, void **clientData
);
272 Appends several items at once into the control.
274 Notice that calling this method is usually much faster than appending
275 them one by one if you need to add a lot of items.
278 Array of strings to insert.
280 Array of client data pointers of the same size as @a items to
281 associate with the new items.
283 int Append(const wxArrayString
& items
, wxClientData
**clientData
);
286 Appends several items at once into the control.
288 Notice that calling this method is usually much faster than appending
289 them one by one if you need to add a lot of items.
292 Number of items in the @a items array.
294 Array of strings of size @a n.
296 int Append(unsigned int n
, const wxString
* items
);
299 Appends several items at once into the control.
301 Notice that calling this method is usually much faster than appending
302 them one by one if you need to add a lot of items.
305 Number of items in the @a items array.
307 Array of strings of size @a n.
309 Array of client data pointers of size @a n to associate with the
312 int Append(unsigned int n
, const wxString
* items
,
316 Appends several items at once into the control.
318 Notice that calling this method is usually much faster than appending
319 them one by one if you need to add a lot of items.
322 Number of items in the @a items array.
324 Array of strings of size @a n.
326 Array of client data pointers of size @a n to associate with the
329 int Append(unsigned int n
, const wxString
* items
,
330 wxClientData
** clientData
);
334 Removes all items from the control.
335 Clear() also deletes the client data of the existing items if it is
336 owned by the control.
341 Deletes an item from the control.
343 The client data associated with the item will be also deleted if it is
344 owned by the control. Note that it is an error (signalled by an assert
345 failure in debug builds) to remove an item with the index negative or
346 greater or equal than the number of items in the control.
349 The zero-based item index.
353 void Delete(unsigned int n
);
357 Returns the client object associated with the given item and transfers
358 its ownership to the caller.
360 This method, unlike GetClientObject(), expects the caller to delete the
361 returned pointer. It also replaces the internally stored pointer with
362 @NULL, i.e. completely detaches the client object pointer from the
365 It's an error to call this method unless HasClientObjectData() returns
369 The zero-based item index.
370 @return The associated client object pointer to be deleted by caller or
375 wxClientData
*DetachClientObject(unsigned int n
);
378 Returns true, if either untyped data (@c void*) or object data (wxClientData*)
379 is associated with the items of the control.
381 bool HasClientData() const;
384 Returns true, if object data is associated with the items of the
387 Object data pointers have the type @c wxClientData* instead of @c void*
388 and, importantly, are owned by the control, i.e. will be deleted by it,
389 unlike their untyped counterparts.
391 bool HasClientObjectData() const;
394 Returns true, if untyped data (@c void*)
395 is associated with the items of the control.
397 bool HasClientUntypedData() const;
403 Returns a pointer to the client data associated with the given item (if
404 any). It is an error to call this function for a control which doesn't
405 have untyped client data at all although it is OK to call it even if
406 the given item doesn't have any client data associated with it (but
410 The zero-based position of the item.
412 @return A pointer to the client data, or @NULL if not present.
414 void* GetClientData(unsigned int n
) const;
417 Returns a pointer to the client data associated with the given item (if
418 any). It is an error to call this function for a control which doesn't
419 have typed client data at all although it is OK to call it even if the
420 given item doesn't have any client data associated with it (but other
423 Notice that the returned pointer is still owned by the control and will
424 be deleted by it, use DetachClientObject() if you want to remove the
425 pointer from the control.
428 The zero-based position of the item.
430 @return A pointer to the client data, or @NULL if not present.
432 wxClientData
* GetClientObject(unsigned int n
) const;
435 Associates the given untyped client data pointer with the given item.
436 Note that it is an error to call this function if any typed client data
437 pointers had been associated with the control items before.
440 The zero-based item index.
442 The client data to associate with the item.
444 void SetClientData(unsigned int n
, void* data
);
447 Associates the given typed client data pointer with the given item: the
448 @a data object will be deleted when the item is deleted (either
449 explicitly by using Delete() or implicitly when the control itself is
450 destroyed). Note that it is an error to call this function if any
451 untyped client data pointers had been associated with the control items
455 The zero-based item index.
457 The client data to associate with the item.
459 void SetClientObject(unsigned int n
, wxClientData
* data
);
466 Inserts item into the control.
471 Position to insert item before, zero based.
473 @return The return value is the index of the newly inserted item.
474 If the insertion failed for some reason, -1 is returned.
476 int Insert(const wxString
& item
, unsigned int pos
);
479 Inserts item into the control.
484 Position to insert item before, zero based.
486 Pointer to client data to associate with the new item.
488 @return The return value is the index of the newly inserted item.
489 If the insertion failed for some reason, -1 is returned.
491 int Insert(const wxString
& item
, unsigned int pos
, void* clientData
);
494 Inserts item into the control.
499 Position to insert item before, zero based.
501 Pointer to client data to associate with the new item.
503 @return The return value is the index of the newly inserted item.
504 If the insertion failed for some reason, -1 is returned.
506 int Insert(const wxString
& item
, unsigned int pos
,
507 wxClientData
* clientData
);
510 Inserts several items at once into the control.
512 Notice that calling this method is usually much faster than inserting
513 them one by one if you need to insert a lot of items.
516 Array of strings to insert.
518 Position to insert the items before, zero based.
519 @return The return value is the index of the last inserted item.
520 If the insertion failed for some reason, -1 is returned.
522 int Insert(const wxArrayString
& items
, unsigned int pos
);
525 Inserts several items at once into the control.
527 Notice that calling this method is usually much faster than inserting
528 them one by one if you need to insert a lot of items.
531 Array of strings to insert.
533 Position to insert the items before, zero based.
535 Array of client data pointers of the same size as @a items to
536 associate with the new items.
537 @return The return value is the index of the last inserted item.
538 If the insertion failed for some reason, -1 is returned.
540 int Insert(const wxArrayString
& items
, unsigned int pos
,
544 Inserts several items at once into the control.
546 Notice that calling this method is usually much faster than inserting
547 them one by one if you need to insert a lot of items.
550 Array of strings to insert.
552 Position to insert the items before, zero based.
554 Array of client data pointers of the same size as @a items to
555 associate with the new items.
556 @return The return value is the index of the last inserted item.
557 If the insertion failed for some reason, -1 is returned.
559 int Insert(const wxArrayString
& items
, unsigned int pos
,
560 wxClientData
**clientData
);
563 Inserts several items at once into the control.
565 Notice that calling this method is usually much faster than inserting
566 them one by one if you need to insert a lot of items.
569 Number of items in the @a items array.
571 Array of strings of size @a n.
573 Position to insert the items before, zero based.
574 @return The return value is the index of the last inserted item.
575 If the insertion failed for some reason, -1 is returned.
577 int Insert(unsigned int n
, const wxString
* items
,
581 Inserts several items at once into the control.
583 Notice that calling this method is usually much faster than inserting
584 them one by one if you need to insert a lot of items.
587 Number of items in the @a items array.
589 Array of strings of size @a n.
591 Position to insert the new items before, zero based.
593 Array of client data pointers of size @a n to associate with the
595 @return The return value is the index of the last inserted item.
596 If the insertion failed for some reason, -1 is returned.
598 int Insert(unsigned int n
, const wxString
* items
,
603 Inserts several items at once into the control.
605 Notice that calling this method is usually much faster than inserting
606 them one by one if you need to insert a lot of items.
609 Number of items in the @a items array.
611 Array of strings of size @a n.
613 Position to insert the new items before, zero based.
615 Array of client data pointers of size @a n to associate with the
617 @return The return value is the index of the last inserted item.
618 If the insertion failed for some reason, -1 is returned.
620 int Insert(unsigned int n
, const wxString
* items
,
622 wxClientData
** clientData
);
627 Replaces the current control contents with the given items.
629 Notice that calling this method is usually much faster than appending
630 them one by one if you need to add a lot of items.
633 Array of strings to insert.
635 void Set(const wxArrayString
& items
);
638 Replaces the current control contents with the given items.
640 Notice that calling this method is usually much faster than appending
641 them one by one if you need to add a lot of items.
644 Array of strings to insert.
646 Array of client data pointers of the same size as @a items to
647 associate with the new items.
649 void Set(const wxArrayString
& items
, void **clientData
);
652 Replaces the current control contents with the given items.
654 Notice that calling this method is usually much faster than appending
655 them one by one if you need to add a lot of items.
658 Array of strings to insert.
660 Array of client data pointers of the same size as @a items to
661 associate with the new items.
663 void Set(const wxArrayString
& items
, wxClientData
**clientData
);
666 Replaces the current control contents with the given items.
668 Notice that calling this method is usually much faster than appending
669 them one by one if you need to add a lot of items.
672 Number of items in the @a items array.
674 Array of strings of size @a n.
676 void Set(unsigned int n
, const wxString
* items
);
679 Replaces the current control contents with the given items.
681 Notice that calling this method is usually much faster than appending
682 them one by one if you need to add a lot of items.
685 Number of items in the @a items array.
687 Array of strings of size @a n.
689 Array of client data pointers of size @a n to associate with the
692 void Set(unsigned int n
, const wxString
* items
, void** clientData
);
695 Replaces the current control contents with the given items.
697 Notice that calling this method is usually much faster than appending
698 them one by one if you need to add a lot of items.
701 Number of items in the @a items array.
703 Array of strings of size @a n.
705 Array of client data pointers of size @a n to associate with the
708 void Set(unsigned int n
, const wxString
* items
, wxClientData
** clientData
);
714 @class wxControlWithItems
716 This is convenience class that derives from both wxControl and
717 wxItemContainer. It is used as basis for some wxWidgets controls
718 (wxChoice and wxListBox).
723 @see wxItemContainer, wxItemContainerImmutable
725 class wxControlWithItems
: public wxControl
, public wxItemContainer