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