]>
Commit | Line | Data |
---|---|---|
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 | ||
36 | // adding items | |
37 | // ------------ | |
38 | ||
39 | int Append(const wxString& item) | |
40 | { return DoAppend(item); } | |
41 | int Append(const wxString& item, void *clientData) | |
42 | { int n = DoAppend(item); SetClientData(n, clientData); return n; } | |
43 | int Append(const wxString& item, wxClientData *clientData) | |
44 | { int n = DoAppend(item); SetClientObject(n, clientData); return n; } | |
45 | ||
46 | // deleting items | |
47 | // -------------- | |
48 | ||
49 | virtual void Clear() = 0; | |
50 | virtual void Delete(int n) = 0; | |
51 | ||
52 | // accessing strings | |
53 | // ----------------- | |
54 | ||
55 | virtual int GetCount() const = 0; | |
56 | virtual wxString GetString(int n) const = 0; | |
57 | virtual void SetString(int n, const wxString& s) = 0; | |
58 | virtual int FindString(const wxString& s) const = 0; | |
59 | ||
60 | // selection | |
61 | // --------- | |
62 | ||
63 | virtual void Select(int n) = 0; | |
64 | virtual int GetSelection() const = 0; | |
65 | ||
66 | wxString GetStringSelection() const; | |
67 | ||
68 | // misc | |
69 | // ---- | |
70 | ||
71 | // client data stuff | |
72 | void SetClientData(int n, void* clientData); | |
73 | void* GetClientData(int n) const; | |
74 | ||
75 | void SetClientObject(int n, wxClientData* clientData); | |
76 | wxClientData* GetClientObject(int n) const; | |
77 | ||
78 | bool HasClientObjectData() const | |
79 | { return m_clientDataItemsType == wxClientData_Object; } | |
80 | bool HasClientUntypedData() const | |
81 | { return m_clientDataItemsType == wxClientData_Void; } | |
82 | ||
83 | #if WXWIN_COMPATIBILITY_2 | |
84 | // compatibility - these functions are deprecated, use the new ones | |
85 | // instead | |
86 | int Number() const { return GetCount(); } | |
87 | #endif // WXWIN_COMPATIBILITY_2 | |
88 | ||
89 | #ifdef __WXMAC_X__ | |
90 | virtual ~wxItemContainer() {} // Added min for Mac X | |
91 | #endif | |
92 | ||
93 | protected: | |
94 | virtual int DoAppend(const wxString& item) = 0; | |
95 | ||
96 | virtual void DoSetItemClientData(int n, void* clientData) = 0; | |
97 | virtual void* DoGetItemClientData(int n) const = 0; | |
98 | virtual void DoSetItemClientObject(int n, wxClientData* clientData) = 0; | |
99 | virtual wxClientData* DoGetItemClientObject(int n) const = 0; | |
100 | ||
101 | // the type of the client data for the items | |
102 | wxClientDataType m_clientDataItemsType; | |
103 | }; | |
104 | ||
105 | class WXDLLEXPORT wxControlWithItems : public wxControl, public wxItemContainer | |
106 | { | |
107 | public: | |
108 | // we have to redefine these functions here to avoid ambiguities in classes | |
109 | // deriving from us which would arise otherwise because both base classses | |
110 | // have the methods with the same names - hopefully, a smart compiler can | |
111 | // optimize away these simple inline wrappers so we don't suffer much from | |
112 | // this | |
113 | ||
114 | void SetClientData(void *data) | |
115 | { | |
116 | wxControl::SetClientData(data); | |
117 | } | |
118 | ||
119 | void *GetClientData() const | |
120 | { | |
121 | return wxControl::GetClientData(); | |
122 | } | |
123 | ||
124 | void SetClientObject(wxClientData *data) | |
125 | { | |
126 | wxControl::SetClientObject(data); | |
127 | } | |
128 | ||
129 | wxClientData *GetClientObject() const | |
130 | { | |
131 | return wxControl::GetClientObject(); | |
132 | } | |
133 | ||
134 | void SetClientData(int n, void* clientData) | |
135 | { | |
136 | wxItemContainer::SetClientData(n, clientData); | |
137 | } | |
138 | ||
139 | void* GetClientData(int n) const | |
140 | { | |
141 | return wxItemContainer::GetClientData(n); | |
142 | } | |
143 | ||
144 | void SetClientObject(int n, wxClientData* clientData) | |
145 | { | |
146 | wxItemContainer::SetClientObject(n, clientData); | |
147 | } | |
148 | ||
149 | wxClientData* GetClientObject(int n) const | |
150 | { | |
151 | return wxItemContainer::GetClientObject(n); | |
152 | } | |
153 | }; | |
154 | ||
155 | #endif // wxUSE_CONTROLS | |
156 | ||
157 | #endif // _WX_CTRLSUB_H_BASE_ | |
158 |