1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/ctrlsub.h (read: "wxConTRoL with SUBitems")
3 // Purpose: wxControlWithItems interface
4 // Author: Vadim Zeitlin
8 // Copyright: (c) wxWindows team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_CTRLSUB_H_BASE_
13 #define _WX_CTRLSUB_H_BASE_
15 #if defined(__GNUG__) && !defined(__APPLE__)
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 // append several items at once to the control
48 void Append(const wxArrayString
& strings
);
50 int Insert(const wxString
& item
, int pos
)
51 { return DoInsert(item
, pos
); }
52 int Insert(const wxString
& item
, int pos
, void *clientData
);
53 int Insert(const wxString
& item
, int pos
, wxClientData
*clientData
);
58 virtual void Clear() = 0;
59 virtual void Delete(int n
) = 0;
64 virtual int GetCount() const = 0;
65 bool IsEmpty() const { return GetCount() == 0; }
67 virtual wxString
GetString(int n
) const = 0;
68 virtual void SetString(int n
, const wxString
& s
) = 0;
69 virtual int FindString(const wxString
& s
) const = 0;
74 virtual void Select(int n
) = 0;
75 virtual int GetSelection() const = 0;
77 wxString
GetStringSelection() const;
83 void SetClientData(int n
, void* clientData
);
84 void* GetClientData(int n
) const;
86 void SetClientObject(int n
, wxClientData
* clientData
);
87 wxClientData
* GetClientObject(int n
) const;
89 bool HasClientObjectData() const
90 { return m_clientDataItemsType
== wxClientData_Object
; }
91 bool HasClientUntypedData() const
92 { return m_clientDataItemsType
== wxClientData_Void
; }
94 #if WXWIN_COMPATIBILITY_2_2
95 // compatibility - these functions are deprecated, use the new ones
97 int Number() const { return GetCount(); }
98 #endif // WXWIN_COMPATIBILITY_2_2
101 virtual int DoAppend(const wxString
& item
) = 0;
102 virtual int DoInsert(const wxString
& item
, int pos
) = 0;
104 virtual void DoSetItemClientData(int n
, void* clientData
) = 0;
105 virtual void* DoGetItemClientData(int n
) const = 0;
106 virtual void DoSetItemClientObject(int n
, wxClientData
* clientData
) = 0;
107 virtual wxClientData
* DoGetItemClientObject(int n
) const = 0;
109 // the type of the client data for the items
110 wxClientDataType m_clientDataItemsType
;
113 class WXDLLEXPORT wxControlWithItems
: public wxControl
, public wxItemContainer
116 wxControlWithItems() { }
117 virtual ~wxControlWithItems();
119 // we have to redefine these functions here to avoid ambiguities in classes
120 // deriving from us which would arise otherwise because both base classses
121 // have the methods with the same names - hopefully, a smart compiler can
122 // optimize away these simple inline wrappers so we don't suffer much from
125 void SetClientData(void *data
)
127 wxControl::SetClientData(data
);
130 void *GetClientData() const
132 return wxControl::GetClientData();
135 void SetClientObject(wxClientData
*data
)
137 wxControl::SetClientObject(data
);
140 wxClientData
*GetClientObject() const
142 return wxControl::GetClientObject();
145 void SetClientData(int n
, void* clientData
)
147 wxItemContainer::SetClientData(n
, clientData
);
150 void* GetClientData(int n
) const
152 return wxItemContainer::GetClientData(n
);
155 void SetClientObject(int n
, wxClientData
* clientData
)
157 wxItemContainer::SetClientObject(n
, clientData
);
160 wxClientData
* GetClientObject(int n
) const
162 return wxItemContainer::GetClientObject(n
);
166 #endif // wxUSE_CONTROLS
168 #endif // _WX_CTRLSUB_H_BASE_