+ virtual wxString GetStringSelection() const;
+
+ // this is the same as SetSelection( for single-selection controls but
+ // reads better for multi-selection ones
+ void Select(int n) { SetSelection(n); }
+
+
+protected:
+ // check that the index is valid
+ bool IsValid(unsigned int n) const { return n < GetCount(); }
+ bool IsValidInsert(unsigned int n) const { return n <= GetCount(); }
+};
+
+// ----------------------------------------------------------------------------
+// wxItemContainer extends wxItemContainerImmutable interface with methods
+// for adding/removing items.
+//
+// Classes deriving from this one must override DoInsertItems() to implement
+// adding items to the control. This can often be implemented more efficiently
+// than simply looping over the elements and inserting them but if this is not
+// the case, the generic DoInsertItemsInLoop can be used in implementation, but
+// in this case DoInsertItem() needs to be overridden.
+// ----------------------------------------------------------------------------
+
+class WXDLLIMPEXP_CORE wxItemContainer : public wxItemContainerImmutable
+{
+private:
+ // AppendItems() and InsertItems() helpers just call DoAppend/InsertItems()
+ // after doing some checks
+ //
+ // NB: they're defined here so that they're inlined when used in public part
+ int AppendItems(const wxArrayStringsAdapter& items,
+ void **clientData,
+ wxClientDataType type)
+ {
+ if ( items.IsEmpty() )
+ return wxNOT_FOUND;
+
+ return DoAppendItems(items, clientData, type);
+ }
+
+ int AppendItems(const wxArrayStringsAdapter& items)
+ {
+ return AppendItems(items, NULL, wxClientData_None);
+ }
+
+ int AppendItems(const wxArrayStringsAdapter& items, void **clientData)
+ {
+ wxASSERT_MSG( GetClientDataType() != wxClientData_Object,
+ _T("can't mix different types of client data") );
+
+ return AppendItems(items, clientData, wxClientData_Void);
+ }
+
+ int AppendItems(const wxArrayStringsAdapter& items,
+ wxClientData **clientData)
+ {
+ wxASSERT_MSG( GetClientDataType() != wxClientData_Void,
+ _T("can't mix different types of client data") );
+
+ return AppendItems(items, reinterpret_cast<void **>(clientData),
+ wxClientData_Object);
+ }
+
+ int InsertItems(const wxArrayStringsAdapter& items,
+ unsigned int pos,
+ void **clientData,
+ wxClientDataType type)
+ {
+ wxASSERT_MSG( !IsSorted(), _T("can't insert items in sorted control") );
+
+ wxCHECK_MSG( pos <= GetCount(), wxNOT_FOUND,
+ _T("position out of range") );
+
+ // not all derived classes handle empty arrays correctly in
+ // DoInsertItems() and besides it really doesn't make much sense to do
+ // this (for append it could correspond to creating an initially empty
+ // control but why would anybody need to insert 0 items?)
+ wxCHECK_MSG( !items.IsEmpty(), wxNOT_FOUND,
+ _T("need something to insert") );
+
+ return DoInsertItems(items, pos, clientData, type);
+ }
+
+ int InsertItems(const wxArrayStringsAdapter& items, unsigned int pos)
+ {
+ return InsertItems(items, pos, NULL, wxClientData_None);
+ }
+
+ int InsertItems(const wxArrayStringsAdapter& items,
+ unsigned int pos,
+ void **clientData)
+ {
+ wxASSERT_MSG( GetClientDataType() != wxClientData_Object,
+ _T("can't mix different types of client data") );
+
+ return InsertItems(items, pos, clientData, wxClientData_Void);
+ }
+
+ int InsertItems(const wxArrayStringsAdapter& items,
+ unsigned int pos,
+ wxClientData **clientData)
+ {
+ wxASSERT_MSG( GetClientDataType() != wxClientData_Void,
+ _T("can't mix different types of client data") );
+
+ return InsertItems(items, pos,
+ reinterpret_cast<void **>(clientData),
+ wxClientData_Object);
+ }
+
+public:
+ wxItemContainer() { m_clientDataItemsType = wxClientData_None; }
+ virtual ~wxItemContainer();
+
+ // adding items
+ // ------------
+
+ // append single item, return its position in the control (which can be
+ // different from the last one if the control is sorted)
+ int Append(const wxString& item)
+ { return AppendItems(item); }
+ int Append(const wxString& item, void *clientData)
+ { return AppendItems(item, &clientData); }
+ int Append(const wxString& item, wxClientData *clientData)
+ { return AppendItems(item, &clientData); }
+
+ // append several items at once to the control, return the position of the
+ // last item appended
+ int Append(const wxArrayString& items)
+ { return AppendItems(items); }
+ int Append(const wxArrayString& items, void **clientData)
+ { return AppendItems(items, clientData); }
+ int Append(const wxArrayString& items, wxClientData **clientData)
+ { return AppendItems(items, clientData); }
+ int Append(unsigned int n, const wxString *items)
+ { return AppendItems(wxArrayStringsAdapter(n, items)); }
+ int Append(unsigned int n, const wxString *items, void **clientData)
+ { return AppendItems(wxArrayStringsAdapter(n, items), clientData); }
+ int Append(unsigned int n,
+ const wxString *items,
+ wxClientData **clientData)
+ { return AppendItems(wxArrayStringsAdapter(n, items), clientData); }
+
+ // only for RTTI needs (separate name)
+ void AppendString(const wxString& item)
+ { Append(item); }
+
+
+ // inserting items: not for sorted controls!
+ // -----------------------------------------
+
+ // insert single item at the given position, return its effective position
+ int Insert(const wxString& item, unsigned int pos)
+ { return InsertItems(item, pos); }
+ int Insert(const wxString& item, unsigned int pos, void *clientData)
+ { return InsertItems(item, pos, &clientData); }
+ int Insert(const wxString& item, unsigned int pos, wxClientData *clientData)
+ { return InsertItems(item, pos, &clientData); }
+
+ // insert several items at once into the control, return the index of the
+ // last item inserted
+ int Insert(const wxArrayString& items, unsigned int pos)
+ { return InsertItems(items, pos); }
+ int Insert(const wxArrayString& items, unsigned int pos, void **clientData)
+ { return InsertItems(items, pos, clientData); }
+ int Insert(const wxArrayString& items,
+ unsigned int pos,
+ wxClientData **clientData)
+ { return InsertItems(items, pos, clientData); }
+ int Insert(unsigned int n, const wxString *items, unsigned int pos)
+ { return InsertItems(wxArrayStringsAdapter(n, items), pos); }
+ int Insert(unsigned int n,
+ const wxString *items,
+ unsigned int pos,
+ void **clientData)
+ { return InsertItems(wxArrayStringsAdapter(n, items), pos, clientData); }
+ int Insert(unsigned int n,
+ const wxString *items,
+ unsigned int pos,
+ wxClientData **clientData)
+ { return InsertItems(wxArrayStringsAdapter(n, items), pos, clientData); }
+
+
+ // replacing items
+ // ---------------
+
+ void Set(const wxArrayString& items)
+ { Clear(); Append(items); }
+ void Set(const wxArrayString& items, void **clientData)
+ { Clear(); Append(items, clientData); }
+ void Set(const wxArrayString& items, wxClientData **clientData)
+ { Clear(); Append(items, clientData); }
+ void Set(unsigned int n, const wxString *items)
+ { Clear(); Append(n, items); }
+ void Set(unsigned int n, const wxString *items, void **clientData)
+ { Clear(); Append(n, items, clientData); }
+ void Set(unsigned int n, const wxString *items, wxClientData **clientData)
+ { Clear(); Append(n, items, clientData); }
+
+ // deleting items
+ // --------------
+
+ void Clear();
+ void Delete(unsigned int pos);
+
+
+ // various accessors
+ // -----------------
+
+ // The control may maintain its items in a sorted order in which case
+ // items are automatically inserted at the right position when they are
+ // inserted or appended. Derived classes have to override this method if
+ // they implement sorting, typically by returning HasFlag(wxXX_SORT)
+ virtual bool IsSorted() const { return false; }