]> git.saurik.com Git - wxWidgets.git/blame - include/wx/ctrlsub.h
Tinderbox build fix for wxUnivGTK build.
[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
aa61d352 41 virtual unsigned int GetCount() const = 0;
8ba7c771
VZ
42 bool IsEmpty() const { return GetCount() == 0; }
43
aa61d352 44 virtual wxString GetString(unsigned int n) const = 0;
8ba7c771 45 wxArrayString GetStrings() const;
aa61d352 46 virtual void SetString(unsigned 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 {
aa61d352 53 unsigned int count = GetCount();
853dcc57 54
aa61d352 55 for ( unsigned int i = 0; i < count ; ++i )
853dcc57
WS
56 {
57 if (GetString(i).IsSameAs( s , bCase ))
aa61d352 58 return (int)i;
853dcc57
WS
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
aa61d352
VZ
85 inline bool IsValid(unsigned int n) const { return n < GetCount(); }
86 inline bool IsValidInsert(unsigned int n) const { return n <= GetCount(); }
8ba7c771
VZ
87};
88
89class WXDLLEXPORT wxItemContainer : public wxItemContainerImmutable
6c8a980f
VZ
90{
91public:
6463b9f5 92 wxItemContainer() { m_clientDataItemsType = wxClientData_None; }
799ea011 93 virtual ~wxItemContainer();
6c8a980f
VZ
94
95 // adding items
96 // ------------
97
1e6feb95
VZ
98 int Append(const wxString& item)
99 { return DoAppend(item); }
100 int Append(const wxString& item, void *clientData)
101 { int n = DoAppend(item); SetClientData(n, clientData); return n; }
102 int Append(const wxString& item, wxClientData *clientData)
103 { int n = DoAppend(item); SetClientObject(n, clientData); return n; }
6c8a980f 104
1978421a
SC
105 // only for rtti needs (separate name)
106 void AppendString( const wxString& item)
64fa6f16 107 { Append( item ); }
1978421a 108
0e0bc921
VZ
109 // append several items at once to the control
110 void Append(const wxArrayString& strings);
111
aa61d352 112 int Insert(const wxString& item, unsigned int pos)
243dbf1a 113 { return DoInsert(item, pos); }
aa61d352
VZ
114 int Insert(const wxString& item, unsigned int pos, void *clientData);
115 int Insert(const wxString& item, unsigned int pos, wxClientData *clientData);
243dbf1a 116
6c8a980f
VZ
117 // deleting items
118 // --------------
119
120 virtual void Clear() = 0;
aa61d352 121 virtual void Delete(unsigned int n) = 0;
6c8a980f 122
6c8a980f
VZ
123 // misc
124 // ----
125
126 // client data stuff
aa61d352
VZ
127 void SetClientData(unsigned int n, void* clientData);
128 void* GetClientData(unsigned int n) const;
6c8a980f 129
aa61d352
VZ
130 void SetClientObject(unsigned int n, wxClientData* clientData);
131 wxClientData* GetClientObject(unsigned int n) const;
6c8a980f
VZ
132
133 bool HasClientObjectData() const
1e6feb95 134 { return m_clientDataItemsType == wxClientData_Object; }
6c8a980f 135 bool HasClientUntypedData() const
1e6feb95 136 { return m_clientDataItemsType == wxClientData_Void; }
6c8a980f 137
6c8a980f
VZ
138protected:
139 virtual int DoAppend(const wxString& item) = 0;
aa61d352 140 virtual int DoInsert(const wxString& item, unsigned int pos) = 0;
6c8a980f 141
aa61d352
VZ
142 virtual void DoSetItemClientData(unsigned int n, void* clientData) = 0;
143 virtual void* DoGetItemClientData(unsigned int n) const = 0;
144 virtual void DoSetItemClientObject(unsigned int n, wxClientData* clientData) = 0;
145 virtual wxClientData* DoGetItemClientObject(unsigned int n) const = 0;
6c8a980f
VZ
146
147 // the type of the client data for the items
148 wxClientDataType m_clientDataItemsType;
149};
150
0ae0bb79
VZ
151// this macro must (unfortunately) be used in any class deriving from both
152// wxItemContainer and wxControl because otherwise there is ambiguity when
153// calling GetClientXXX() functions -- the compiler can't choose between the
154// two versions
155#define wxCONTROL_ITEMCONTAINER_CLIENTDATAOBJECT_RECAST \
156 void SetClientData(void *data) \
157 { wxControl::SetClientData(data); } \
158 void *GetClientData() const \
159 { return wxControl::GetClientData(); } \
160 void SetClientObject(wxClientData *data) \
161 { wxControl::SetClientObject(data); } \
162 wxClientData *GetClientObject() const \
163 { return wxControl::GetClientObject(); } \
aa61d352 164 void SetClientData(unsigned int n, void* clientData) \
0ae0bb79 165 { wxItemContainer::SetClientData(n, clientData); } \
aa61d352 166 void* GetClientData(unsigned int n) const \
0ae0bb79 167 { return wxItemContainer::GetClientData(n); } \
aa61d352 168 void SetClientObject(unsigned int n, wxClientData* clientData) \
0ae0bb79 169 { wxItemContainer::SetClientObject(n, clientData); } \
aa61d352 170 wxClientData* GetClientObject(unsigned int n) const \
0ae0bb79
VZ
171 { return wxItemContainer::GetClientObject(n); }
172
1e6feb95
VZ
173class WXDLLEXPORT wxControlWithItems : public wxControl, public wxItemContainer
174{
175public:
6463b9f5 176 wxControlWithItems() { }
7c720ce6 177 virtual ~wxControlWithItems();
0ae0bb79 178
1e6feb95
VZ
179 // we have to redefine these functions here to avoid ambiguities in classes
180 // deriving from us which would arise otherwise because both base classses
181 // have the methods with the same names - hopefully, a smart compiler can
182 // optimize away these simple inline wrappers so we don't suffer much from
183 // this
0ae0bb79 184 wxCONTROL_ITEMCONTAINER_CLIENTDATAOBJECT_RECAST
fc7a2a60 185
d4864e97
VZ
186 // usually the controls like list/combo boxes have their own background
187 // colour
188 virtual bool ShouldInheritColours() const { return false; }
189
929bd5fd
VZ
190protected:
191 // we can't compute our best size before the items are added to the control
192 // which is done after calling SetInitialBestSize() (it is called from the
193 // base class ctor and the items are added in the derived class ctor), so
194 // don't do anything at all here as our size will be changed later anyhow
195 //
196 // of course, all derived classes *must* call SetBestSize() from their
197 // ctors for this to work!
198 virtual void SetInitialBestSize(const wxSize& WXUNUSED(size)) { }
199
fc7a2a60 200private:
1440bc7a 201 DECLARE_ABSTRACT_CLASS(wxControlWithItems)
aa3d520a 202 DECLARE_NO_COPY_CLASS(wxControlWithItems)
1e6feb95
VZ
203};
204
c6179a84
VZ
205
206// ----------------------------------------------------------------------------
207// inline functions
208// ----------------------------------------------------------------------------
209
1e6feb95 210#endif // wxUSE_CONTROLS
6c8a980f 211
1e6feb95 212#endif // _WX_CTRLSUB_H_BASE_