+public:
+ wxItemContainerImmutable() { }
+ virtual ~wxItemContainerImmutable();
+
+ // accessing strings
+ // -----------------
+
+ virtual unsigned int GetCount() const = 0;
+ bool IsEmpty() const { return GetCount() == 0; }
+
+ virtual wxString GetString(unsigned int n) const = 0;
+ wxArrayString GetStrings() const;
+ virtual void SetString(unsigned int n, const wxString& s) = 0;
+
+ // finding string natively is either case sensitive or insensitive
+ // but never both so fall back to this base version for not
+ // supported search type
+ virtual int FindString(const wxString& s, bool bCase = false) const
+ {
+ unsigned int count = GetCount();
+
+ for ( unsigned int i = 0; i < count ; ++i )
+ {
+ if (GetString(i).IsSameAs( s , bCase ))
+ return (int)i;
+ }
+
+ return wxNOT_FOUND;
+ }
+
+
+ // selection
+ // ---------
+
+ virtual void SetSelection(int n) = 0;
+ virtual int GetSelection() const = 0;
+
+ // set selection to the specified string, return false if not found
+ bool SetStringSelection(const wxString& s);
+
+ // return the selected string or empty string if none
+ 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,
+ wxT("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,
+ wxT("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(), wxT("can't insert items in sorted control") );
+
+ wxCHECK_MSG( pos <= GetCount(), wxNOT_FOUND,
+ wxT("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,
+ wxT("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,
+ wxT("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,
+ wxT("can't mix different types of client data") );
+
+ return InsertItems(items, pos,
+ reinterpret_cast<void **>(clientData),
+ wxClientData_Object);
+ }
+