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