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