]> git.saurik.com Git - wxWidgets.git/blob - include/wx/ctrlsub.h
Next step on bringing PalmOS build to the same filelist as in bakefiles: adjustements...
[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) wxWidgets team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_CTRLSUB_H_BASE_
13 #define _WX_CTRLSUB_H_BASE_
14
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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 // It is decomposed in wxItemContainerImmutable which omits all methods
28 // adding/removing items and is used by wxRadioBox and wxItemContainer itself.
29 //
30 // Examples: wxListBox, wxCheckListBox, wxChoice and wxComboBox (which
31 // implements an extended interface deriving from this one)
32 // ----------------------------------------------------------------------------
33
34 class WXDLLEXPORT wxItemContainerImmutable
35 {
36 public:
37 wxItemContainerImmutable() { }
38 virtual ~wxItemContainerImmutable();
39
40 // accessing strings
41 // -----------------
42
43 virtual int GetCount() const = 0;
44 bool IsEmpty() const { return GetCount() == 0; }
45
46 virtual wxString GetString(int n) const = 0;
47 wxArrayString GetStrings() const;
48 virtual void SetString(int n, const wxString& s) = 0;
49 virtual int FindString(const wxString& s) const = 0;
50
51
52 // selection
53 // ---------
54
55 virtual void SetSelection(int n) = 0;
56 virtual int GetSelection() const = 0;
57
58 // set selection to the specified string, return false if not found
59 bool SetStringSelection(const wxString& s);
60
61 // return the selected string or empty string if none
62 wxString GetStringSelection() const;
63
64 // this is the same as SetSelection( for single-selection controls but
65 // reads better for multi-selection ones
66 void Select(int n) { SetSelection(n); }
67
68
69 protected:
70
71 // check that the index is valid
72 inline bool IsValid(int n) const { return n >= 0 && n < GetCount(); }
73 };
74
75 class WXDLLEXPORT wxItemContainer : public wxItemContainerImmutable
76 {
77 public:
78 wxItemContainer() { m_clientDataItemsType = wxClientData_None; }
79 virtual ~wxItemContainer();
80
81 // adding items
82 // ------------
83
84 int Append(const wxString& item)
85 { return DoAppend(item); }
86 int Append(const wxString& item, void *clientData)
87 { int n = DoAppend(item); SetClientData(n, clientData); return n; }
88 int Append(const wxString& item, wxClientData *clientData)
89 { int n = DoAppend(item); SetClientObject(n, clientData); return n; }
90
91 // only for rtti needs (separate name)
92 void AppendString( const wxString& item)
93 { Append( item ); }
94
95 // append several items at once to the control
96 void Append(const wxArrayString& strings);
97
98 int Insert(const wxString& item, int pos)
99 { return DoInsert(item, pos); }
100 int Insert(const wxString& item, int pos, void *clientData);
101 int Insert(const wxString& item, int pos, wxClientData *clientData);
102
103 // deleting items
104 // --------------
105
106 virtual void Clear() = 0;
107 virtual void Delete(int n) = 0;
108
109 // misc
110 // ----
111
112 // client data stuff
113 void SetClientData(int n, void* clientData);
114 void* GetClientData(int n) const;
115
116 void SetClientObject(int n, wxClientData* clientData);
117 wxClientData* GetClientObject(int n) const;
118
119 bool HasClientObjectData() const
120 { return m_clientDataItemsType == wxClientData_Object; }
121 bool HasClientUntypedData() const
122 { return m_clientDataItemsType == wxClientData_Void; }
123
124 #if WXWIN_COMPATIBILITY_2_2
125 // compatibility - these functions are deprecated, use the new ones
126 // instead
127 wxDEPRECATED( int Number() const );
128 #endif // WXWIN_COMPATIBILITY_2_2
129
130 protected:
131 virtual int DoAppend(const wxString& item) = 0;
132 virtual int DoInsert(const wxString& item, int pos) = 0;
133
134 virtual void DoSetItemClientData(int n, void* clientData) = 0;
135 virtual void* DoGetItemClientData(int n) const = 0;
136 virtual void DoSetItemClientObject(int n, wxClientData* clientData) = 0;
137 virtual wxClientData* DoGetItemClientObject(int n) const = 0;
138
139 // the type of the client data for the items
140 wxClientDataType m_clientDataItemsType;
141 };
142
143 // this macro must (unfortunately) be used in any class deriving from both
144 // wxItemContainer and wxControl because otherwise there is ambiguity when
145 // calling GetClientXXX() functions -- the compiler can't choose between the
146 // two versions
147 #define wxCONTROL_ITEMCONTAINER_CLIENTDATAOBJECT_RECAST \
148 void SetClientData(void *data) \
149 { wxControl::SetClientData(data); } \
150 void *GetClientData() const \
151 { return wxControl::GetClientData(); } \
152 void SetClientObject(wxClientData *data) \
153 { wxControl::SetClientObject(data); } \
154 wxClientData *GetClientObject() const \
155 { return wxControl::GetClientObject(); } \
156 void SetClientData(int n, void* clientData) \
157 { wxItemContainer::SetClientData(n, clientData); } \
158 void* GetClientData(int n) const \
159 { return wxItemContainer::GetClientData(n); } \
160 void SetClientObject(int n, wxClientData* clientData) \
161 { wxItemContainer::SetClientObject(n, clientData); } \
162 wxClientData* GetClientObject(int n) const \
163 { return wxItemContainer::GetClientObject(n); }
164
165 class WXDLLEXPORT wxControlWithItems : public wxControl, public wxItemContainer
166 {
167 public:
168 wxControlWithItems() { }
169 virtual ~wxControlWithItems();
170
171 // we have to redefine these functions here to avoid ambiguities in classes
172 // deriving from us which would arise otherwise because both base classses
173 // have the methods with the same names - hopefully, a smart compiler can
174 // optimize away these simple inline wrappers so we don't suffer much from
175 // this
176 wxCONTROL_ITEMCONTAINER_CLIENTDATAOBJECT_RECAST
177
178 // usually the controls like list/combo boxes have their own background
179 // colour
180 virtual bool ShouldInheritColours() const { return false; }
181
182 protected:
183 // we can't compute our best size before the items are added to the control
184 // which is done after calling SetInitialBestSize() (it is called from the
185 // base class ctor and the items are added in the derived class ctor), so
186 // don't do anything at all here as our size will be changed later anyhow
187 //
188 // of course, all derived classes *must* call SetBestSize() from their
189 // ctors for this to work!
190 virtual void SetInitialBestSize(const wxSize& WXUNUSED(size)) { }
191
192 private:
193 DECLARE_NO_COPY_CLASS(wxControlWithItems)
194 };
195
196
197 // ----------------------------------------------------------------------------
198 // inline functions
199 // ----------------------------------------------------------------------------
200
201 #if WXWIN_COMPATIBILITY_2_2
202
203 inline int wxItemContainer::Number() const
204 {
205 return GetCount();
206 }
207
208 #endif // WXWIN_COMPATIBILITY_2_2
209
210 #endif // wxUSE_CONTROLS
211
212 #endif // _WX_CTRLSUB_H_BASE_
213