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