]> git.saurik.com Git - wxWidgets.git/blob - include/wx/ctrlsub.h
0. extracted toolbar colour mapping stuff to its own function
[wxWidgets.git] / include / wx / ctrlsub.h
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) wxWindows team
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_CTRLSUB_H_BASE_
13 #define _WX_CTRLSUB_H_BASE_
14
15 #ifdef __GNUG__
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 // Examples: wxListBox, wxCheckListBox, wxChoice and wxComboBox (which
28 // implements an extended interface deriving from this one)
29 // ----------------------------------------------------------------------------
30
31 class WXDLLEXPORT wxItemContainer
32 {
33 public:
34 wxItemContainer() { m_clientDataItemsType = wxClientData_None; }
35 virtual ~wxItemContainer();
36
37 // adding items
38 // ------------
39
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; }
46
47 // deleting items
48 // --------------
49
50 virtual void Clear() = 0;
51 virtual void Delete(int n) = 0;
52
53 // accessing strings
54 // -----------------
55
56 virtual int GetCount() const = 0;
57 virtual wxString GetString(int n) const = 0;
58 virtual void SetString(int n, const wxString& s) = 0;
59 virtual int FindString(const wxString& s) const = 0;
60
61 // selection
62 // ---------
63
64 virtual void Select(int n) = 0;
65 virtual int GetSelection() const = 0;
66
67 wxString GetStringSelection() const;
68
69 // misc
70 // ----
71
72 // client data stuff
73 void SetClientData(int n, void* clientData);
74 void* GetClientData(int n) const;
75
76 void SetClientObject(int n, wxClientData* clientData);
77 wxClientData* GetClientObject(int n) const;
78
79 bool HasClientObjectData() const
80 { return m_clientDataItemsType == wxClientData_Object; }
81 bool HasClientUntypedData() const
82 { return m_clientDataItemsType == wxClientData_Void; }
83
84 #if WXWIN_COMPATIBILITY_2_2
85 // compatibility - these functions are deprecated, use the new ones
86 // instead
87 int Number() const { return GetCount(); }
88 #endif // WXWIN_COMPATIBILITY_2_2
89
90 protected:
91 virtual int DoAppend(const wxString& item) = 0;
92
93 virtual void DoSetItemClientData(int n, void* clientData) = 0;
94 virtual void* DoGetItemClientData(int n) const = 0;
95 virtual void DoSetItemClientObject(int n, wxClientData* clientData) = 0;
96 virtual wxClientData* DoGetItemClientObject(int n) const = 0;
97
98 // the type of the client data for the items
99 wxClientDataType m_clientDataItemsType;
100 };
101
102 class WXDLLEXPORT wxControlWithItems : public wxControl, public wxItemContainer
103 {
104 public:
105 // we have to redefine these functions here to avoid ambiguities in classes
106 // deriving from us which would arise otherwise because both base classses
107 // have the methods with the same names - hopefully, a smart compiler can
108 // optimize away these simple inline wrappers so we don't suffer much from
109 // this
110
111 void SetClientData(void *data)
112 {
113 wxControl::SetClientData(data);
114 }
115
116 void *GetClientData() const
117 {
118 return wxControl::GetClientData();
119 }
120
121 void SetClientObject(wxClientData *data)
122 {
123 wxControl::SetClientObject(data);
124 }
125
126 wxClientData *GetClientObject() const
127 {
128 return wxControl::GetClientObject();
129 }
130
131 void SetClientData(int n, void* clientData)
132 {
133 wxItemContainer::SetClientData(n, clientData);
134 }
135
136 void* GetClientData(int n) const
137 {
138 return wxItemContainer::GetClientData(n);
139 }
140
141 void SetClientObject(int n, wxClientData* clientData)
142 {
143 wxItemContainer::SetClientObject(n, clientData);
144 }
145
146 wxClientData* GetClientObject(int n) const
147 {
148 return wxItemContainer::GetClientObject(n);
149 }
150 };
151
152 #endif // wxUSE_CONTROLS
153
154 #endif // _WX_CTRLSUB_H_BASE_
155