]> git.saurik.com Git - wxWidgets.git/blob - include/wx/ctrlsub.h
1. added SetSelection() to wxItemContainer and removed its declarations
[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 // 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 // only for rtti needs (separate name)
48 void AppendString( const wxString& item)
49 { Append( item ); }
50
51 // append several items at once to the control
52 void Append(const wxArrayString& strings);
53
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);
58
59 // deleting items
60 // --------------
61
62 virtual void Clear() = 0;
63 virtual void Delete(int n) = 0;
64
65 // accessing strings
66 // -----------------
67
68 virtual int GetCount() const = 0;
69 bool IsEmpty() const { return GetCount() == 0; }
70
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;
75
76 // selection
77 // ---------
78
79 virtual void SetSelection(int n) = 0;
80 virtual int GetSelection() const = 0;
81
82 // set selection to the specified string, return false if not found
83 bool SetStringSelection(const wxString& s);
84
85 // return the selected string or empty string if none
86 wxString GetStringSelection() const;
87
88 // this is the same as SetSelection( for single-selection controls but
89 // reads better for multi-selection ones
90 void Select(int n) { SetSelection(n); }
91
92 // misc
93 // ----
94
95 // client data stuff
96 void SetClientData(int n, void* clientData);
97 void* GetClientData(int n) const;
98
99 void SetClientObject(int n, wxClientData* clientData);
100 wxClientData* GetClientObject(int n) const;
101
102 bool HasClientObjectData() const
103 { return m_clientDataItemsType == wxClientData_Object; }
104 bool HasClientUntypedData() const
105 { return m_clientDataItemsType == wxClientData_Void; }
106
107 #if WXWIN_COMPATIBILITY_2_2
108 // compatibility - these functions are deprecated, use the new ones
109 // instead
110 wxDEPRECATED( int Number() const );
111 #endif // WXWIN_COMPATIBILITY_2_2
112
113 protected:
114 virtual int DoAppend(const wxString& item) = 0;
115 virtual int DoInsert(const wxString& item, int pos) = 0;
116
117 virtual void DoSetItemClientData(int n, void* clientData) = 0;
118 virtual void* DoGetItemClientData(int n) const = 0;
119 virtual void DoSetItemClientObject(int n, wxClientData* clientData) = 0;
120 virtual wxClientData* DoGetItemClientObject(int n) const = 0;
121
122 // the type of the client data for the items
123 wxClientDataType m_clientDataItemsType;
124 };
125
126 // this macro must (unfortunately) be used in any class deriving from both
127 // wxItemContainer and wxControl because otherwise there is ambiguity when
128 // calling GetClientXXX() functions -- the compiler can't choose between the
129 // two versions
130 #define wxCONTROL_ITEMCONTAINER_CLIENTDATAOBJECT_RECAST \
131 void SetClientData(void *data) \
132 { wxControl::SetClientData(data); } \
133 void *GetClientData() const \
134 { return wxControl::GetClientData(); } \
135 void SetClientObject(wxClientData *data) \
136 { wxControl::SetClientObject(data); } \
137 wxClientData *GetClientObject() const \
138 { return wxControl::GetClientObject(); } \
139 void SetClientData(int n, void* clientData) \
140 { wxItemContainer::SetClientData(n, clientData); } \
141 void* GetClientData(int n) const \
142 { return wxItemContainer::GetClientData(n); } \
143 void SetClientObject(int n, wxClientData* clientData) \
144 { wxItemContainer::SetClientObject(n, clientData); } \
145 wxClientData* GetClientObject(int n) const \
146 { return wxItemContainer::GetClientObject(n); }
147
148 class WXDLLEXPORT wxControlWithItems : public wxControl, public wxItemContainer
149 {
150 public:
151 wxControlWithItems() { }
152 virtual ~wxControlWithItems();
153
154 // we have to redefine these functions here to avoid ambiguities in classes
155 // deriving from us which would arise otherwise because both base classses
156 // have the methods with the same names - hopefully, a smart compiler can
157 // optimize away these simple inline wrappers so we don't suffer much from
158 // this
159 wxCONTROL_ITEMCONTAINER_CLIENTDATAOBJECT_RECAST
160
161 // usually the controls like list/combo boxes have their own background
162 // colour
163 virtual bool ShouldInheritColours() const { return false; }
164
165 protected:
166 // we can't compute our best size before the items are added to the control
167 // which is done after calling SetInitialBestSize() (it is called from the
168 // base class ctor and the items are added in the derived class ctor), so
169 // don't do anything at all here as our size will be changed later anyhow
170 //
171 // of course, all derived classes *must* call SetBestSize() from their
172 // ctors for this to work!
173 virtual void SetInitialBestSize(const wxSize& WXUNUSED(size)) { }
174
175 private:
176 DECLARE_NO_COPY_CLASS(wxControlWithItems)
177 };
178
179
180 // ----------------------------------------------------------------------------
181 // inline functions
182 // ----------------------------------------------------------------------------
183
184 #if WXWIN_COMPATIBILITY_2_2
185
186 inline int wxItemContainer::Number() const
187 {
188 return GetCount();
189 }
190
191 #endif // WXWIN_COMPATIBILITY_2_2
192
193 #endif // wxUSE_CONTROLS
194
195 #endif // _WX_CTRLSUB_H_BASE_
196