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