1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/ctrlsub.h (read: "wxConTRoL with SUBitems")
3 // Purpose: wxControlWithItems interface
4 // Author: Vadim Zeitlin
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_CTRLSUB_H_BASE_
13 #define _WX_CTRLSUB_H_BASE_
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "controlwithitems.h"
21 #include "wx/control.h" // base class
23 // ----------------------------------------------------------------------------
24 // wxItemContainer defines an interface which is implemented by all controls
25 // which have string subitems each of which may be selected.
27 // Examples: wxListBox, wxCheckListBox, wxChoice and wxComboBox (which
28 // implements an extended interface deriving from this one)
29 // ----------------------------------------------------------------------------
31 class WXDLLEXPORT wxItemContainer
34 wxItemContainer() { m_clientDataItemsType
= wxClientData_None
; }
35 virtual ~wxItemContainer();
40 int Append(const wxString
& item
)
41 { return DoAppend(item
); }
42 int Append(const wxString
& item
, void *clientData
)
43 { int n
= DoAppend(item
); SetClientData(n
, clientData
); return n
; }
44 int Append(const wxString
& item
, wxClientData
*clientData
)
45 { int n
= DoAppend(item
); SetClientObject(n
, clientData
); return n
; }
47 // only for rtti needs (separate name)
48 void AppendString( const wxString
& item
)
51 // append several items at once to the control
52 void Append(const wxArrayString
& strings
);
54 int Insert(const wxString
& item
, int pos
)
55 { return DoInsert(item
, pos
); }
56 int Insert(const wxString
& item
, int pos
, void *clientData
);
57 int Insert(const wxString
& item
, int pos
, wxClientData
*clientData
);
62 virtual void Clear() = 0;
63 virtual void Delete(int n
) = 0;
68 virtual int GetCount() const = 0;
69 bool IsEmpty() const { return GetCount() == 0; }
71 virtual wxString
GetString(int n
) const = 0;
72 wxArrayString
GetStrings() const;
73 virtual void SetString(int n
, const wxString
& s
) = 0;
74 virtual int FindString(const wxString
& s
) const = 0;
79 virtual void Select(int n
) = 0;
80 virtual int GetSelection() const = 0;
82 // set selection to the specified string, return false if not found
83 bool SetStringSelection(const wxString
& s
);
85 // return the selected string or empty string if none
86 wxString
GetStringSelection() const;
92 void SetClientData(int n
, void* clientData
);
93 void* GetClientData(int n
) const;
95 void SetClientObject(int n
, wxClientData
* clientData
);
96 wxClientData
* GetClientObject(int n
) const;
98 bool HasClientObjectData() const
99 { return m_clientDataItemsType
== wxClientData_Object
; }
100 bool HasClientUntypedData() const
101 { return m_clientDataItemsType
== wxClientData_Void
; }
103 #if WXWIN_COMPATIBILITY_2_2
104 // compatibility - these functions are deprecated, use the new ones
106 wxDEPRECATED( int Number() const );
107 #endif // WXWIN_COMPATIBILITY_2_2
110 virtual int DoAppend(const wxString
& item
) = 0;
111 virtual int DoInsert(const wxString
& item
, int pos
) = 0;
113 virtual void DoSetItemClientData(int n
, void* clientData
) = 0;
114 virtual void* DoGetItemClientData(int n
) const = 0;
115 virtual void DoSetItemClientObject(int n
, wxClientData
* clientData
) = 0;
116 virtual wxClientData
* DoGetItemClientObject(int n
) const = 0;
118 // the type of the client data for the items
119 wxClientDataType m_clientDataItemsType
;
122 // this macro must (unfortunately) be used in any class deriving from both
123 // wxItemContainer and wxControl because otherwise there is ambiguity when
124 // calling GetClientXXX() functions -- the compiler can't choose between the
126 #define wxCONTROL_ITEMCONTAINER_CLIENTDATAOBJECT_RECAST \
127 void SetClientData(void *data) \
128 { wxControl::SetClientData(data); } \
129 void *GetClientData() const \
130 { return wxControl::GetClientData(); } \
131 void SetClientObject(wxClientData *data) \
132 { wxControl::SetClientObject(data); } \
133 wxClientData *GetClientObject() const \
134 { return wxControl::GetClientObject(); } \
135 void SetClientData(int n, void* clientData) \
136 { wxItemContainer::SetClientData(n, clientData); } \
137 void* GetClientData(int n) const \
138 { return wxItemContainer::GetClientData(n); } \
139 void SetClientObject(int n, wxClientData* clientData) \
140 { wxItemContainer::SetClientObject(n, clientData); } \
141 wxClientData* GetClientObject(int n) const \
142 { return wxItemContainer::GetClientObject(n); }
144 class WXDLLEXPORT wxControlWithItems
: public wxControl
, public wxItemContainer
147 wxControlWithItems() { }
148 virtual ~wxControlWithItems();
150 // we have to redefine these functions here to avoid ambiguities in classes
151 // deriving from us which would arise otherwise because both base classses
152 // have the methods with the same names - hopefully, a smart compiler can
153 // optimize away these simple inline wrappers so we don't suffer much from
155 wxCONTROL_ITEMCONTAINER_CLIENTDATAOBJECT_RECAST
157 // usually the controls like list/combo boxes have their own background
159 virtual bool ShouldInheritColours() const { return false; }
162 // we can't compute our best size before the items are added to the control
163 // which is done after calling SetInitialBestSize() (it is called from the
164 // base class ctor and the items are added in the derived class ctor), so
165 // don't do anything at all here as our size will be changed later anyhow
167 // of course, all derived classes *must* call SetBestSize() from their
168 // ctors for this to work!
169 virtual void SetInitialBestSize(const wxSize
& WXUNUSED(size
)) { }
172 DECLARE_NO_COPY_CLASS(wxControlWithItems
)
175 #endif // wxUSE_CONTROLS
177 #endif // _WX_CTRLSUB_H_BASE_