]> git.saurik.com Git - wxWidgets.git/blob - include/wx/ctrlsub.h
forward declare wxMenu
[wxWidgets.git] / include / wx / ctrlsub.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/ctrlsub.h (read: "wxConTRoL with SUBitems")
3 // Purpose: wxControlWithItems interface
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 22.10.99
7 // RCS-ID: $Id$
8 // Copyright: (c) wxWindows team
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_CTRLSUB_H_BASE_
13 #define _WX_CTRLSUB_H_BASE_
14
15 #if defined(__GNUG__) && !defined(__APPLE__)
16 #pragma interface "controlwithitems.h"
17 #endif
18
19 #if wxUSE_CONTROLS
20
21 #include "wx/control.h" // base class
22
23 // ----------------------------------------------------------------------------
24 // wxItemContainer defines an interface which is implemented by all controls
25 // which have string subitems each of which may be selected.
26 //
27 // Examples: wxListBox, wxCheckListBox, wxChoice and wxComboBox (which
28 // implements an extended interface deriving from this one)
29 // ----------------------------------------------------------------------------
30
31 class WXDLLEXPORT wxItemContainer
32 {
33 public:
34 wxItemContainer() { m_clientDataItemsType = wxClientData_None; }
35 virtual ~wxItemContainer();
36
37 // adding items
38 // ------------
39
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; }
46
47 // append several items at once to the control
48 void Append(const wxArrayString& strings);
49
50 // deleting items
51 // --------------
52
53 virtual void Clear() = 0;
54 virtual void Delete(int n) = 0;
55
56 // accessing strings
57 // -----------------
58
59 virtual int GetCount() const = 0;
60 bool IsEmpty() const { return GetCount() == 0; }
61
62 virtual wxString GetString(int n) const = 0;
63 virtual void SetString(int n, const wxString& s) = 0;
64 virtual int FindString(const wxString& s) const = 0;
65
66 // selection
67 // ---------
68
69 virtual void Select(int n) = 0;
70 virtual int GetSelection() const = 0;
71
72 wxString GetStringSelection() const;
73
74 // misc
75 // ----
76
77 // client data stuff
78 void SetClientData(int n, void* clientData);
79 void* GetClientData(int n) const;
80
81 void SetClientObject(int n, wxClientData* clientData);
82 wxClientData* GetClientObject(int n) const;
83
84 bool HasClientObjectData() const
85 { return m_clientDataItemsType == wxClientData_Object; }
86 bool HasClientUntypedData() const
87 { return m_clientDataItemsType == wxClientData_Void; }
88
89 #if WXWIN_COMPATIBILITY_2_2
90 // compatibility - these functions are deprecated, use the new ones
91 // instead
92 int Number() const { return GetCount(); }
93 #endif // WXWIN_COMPATIBILITY_2_2
94
95 protected:
96 virtual int DoAppend(const wxString& item) = 0;
97
98 virtual void DoSetItemClientData(int n, void* clientData) = 0;
99 virtual void* DoGetItemClientData(int n) const = 0;
100 virtual void DoSetItemClientObject(int n, wxClientData* clientData) = 0;
101 virtual wxClientData* DoGetItemClientObject(int n) const = 0;
102
103 // the type of the client data for the items
104 wxClientDataType m_clientDataItemsType;
105 };
106
107 class WXDLLEXPORT wxControlWithItems : public wxControl, public wxItemContainer
108 {
109 public:
110 wxControlWithItems() { }
111 virtual ~wxControlWithItems();
112
113 // we have to redefine these functions here to avoid ambiguities in classes
114 // deriving from us which would arise otherwise because both base classses
115 // have the methods with the same names - hopefully, a smart compiler can
116 // optimize away these simple inline wrappers so we don't suffer much from
117 // this
118
119 void SetClientData(void *data)
120 {
121 wxControl::SetClientData(data);
122 }
123
124 void *GetClientData() const
125 {
126 return wxControl::GetClientData();
127 }
128
129 void SetClientObject(wxClientData *data)
130 {
131 wxControl::SetClientObject(data);
132 }
133
134 wxClientData *GetClientObject() const
135 {
136 return wxControl::GetClientObject();
137 }
138
139 void SetClientData(int n, void* clientData)
140 {
141 wxItemContainer::SetClientData(n, clientData);
142 }
143
144 void* GetClientData(int n) const
145 {
146 return wxItemContainer::GetClientData(n);
147 }
148
149 void SetClientObject(int n, wxClientData* clientData)
150 {
151 wxItemContainer::SetClientObject(n, clientData);
152 }
153
154 wxClientData* GetClientObject(int n) const
155 {
156 return wxItemContainer::GetClientObject(n);
157 }
158 };
159
160 #endif // wxUSE_CONTROLS
161
162 #endif // _WX_CTRLSUB_H_BASE_
163