]> git.saurik.com Git - wxWidgets.git/blob - include/wx/windowid.h
Somehow, setting a tint color makes gauge work :/.
[wxWidgets.git] / include / wx / windowid.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/windowid.h
3 // Purpose: wxWindowID class - a class for managing window ids
4 // Author: Brian Vanderburg II
5 // Created: 2007-09-21
6 // Copyright: (c) 2007 Brian Vanderburg II
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
9
10 #ifndef _WX_WINDOWID_H_
11 #define _WX_WINDOWID_H_
12
13 // NB: do not include defs.h as we are included from it
14
15 typedef int wxWindowID;
16
17 // ----------------------------------------------------------------------------
18 // wxWindowIDRef: reference counted id value
19 // ----------------------------------------------------------------------------
20
21 // A wxWindowIDRef object wraps an id value and marks it as (un)used as
22 // necessary. All ids returned from wxWindow::NewControlId() should be assigned
23 // to an instance of this class to ensure that the id is marked as being in
24 // use.
25 //
26 // This class is always defined but it is trivial if wxUSE_AUTOID_MANAGEMENT is
27 // off.
28 class WXDLLIMPEXP_CORE wxWindowIDRef
29 {
30 public:
31 // default ctor
32 wxWindowIDRef()
33 {
34 m_id = wxID_NONE;
35 }
36
37 // ctor taking id values
38 wxWindowIDRef(int id)
39 {
40 Init(id);
41 }
42
43 wxWindowIDRef(long id)
44 {
45 Init(wxWindowID(id));
46 }
47
48 wxWindowIDRef(const wxWindowIDRef& id)
49 {
50 Init(id.m_id);
51 }
52
53 // dtor
54 ~wxWindowIDRef()
55 {
56 Assign(wxID_NONE);
57 }
58
59 // assignment
60 wxWindowIDRef& operator=(int id)
61 {
62 Assign(id);
63 return *this;
64 }
65
66 wxWindowIDRef& operator=(long id)
67 {
68 Assign(wxWindowID(id));
69 return *this;
70 }
71
72 wxWindowIDRef& operator=(const wxWindowIDRef& id)
73 {
74 if (&id != this)
75 Assign(id.m_id);
76 return *this;
77 }
78
79 // access to the stored id value
80 wxWindowID GetValue() const
81 {
82 return m_id;
83 }
84
85 operator wxWindowID() const
86 {
87 return m_id;
88 }
89
90 private:
91 #if wxUSE_AUTOID_MANAGEMENT
92 // common part of all ctors: call Assign() for our new id
93 void Init(wxWindowID id)
94 {
95 // m_id must be initialized before calling Assign()
96 m_id = wxID_NONE;
97 Assign(id);
98 }
99
100 // increase reference count of id, decrease the one of m_id
101 void Assign(wxWindowID id);
102 #else // !wxUSE_AUTOID_MANAGEMENT
103 // trivial stubs for the functions above
104 void Init(wxWindowID id)
105 {
106 m_id = id;
107 }
108
109 void Assign(wxWindowID id)
110 {
111 m_id = id;
112 }
113 #endif // wxUSE_AUTOID_MANAGEMENT/!wxUSE_AUTOID_MANAGEMENT
114
115
116 wxWindowID m_id;
117 };
118
119 // comparison operators
120 inline bool operator==(const wxWindowIDRef& lhs, const wxWindowIDRef& rhs)
121 {
122 return lhs.GetValue() == rhs.GetValue();
123 }
124
125 inline bool operator==(const wxWindowIDRef& lhs, int rhs)
126 {
127 return lhs.GetValue() == rhs;
128 }
129
130 inline bool operator==(const wxWindowIDRef& lhs, long rhs)
131 {
132 return lhs.GetValue() == rhs;
133 }
134
135 inline bool operator==(int lhs, const wxWindowIDRef& rhs)
136 {
137 return rhs == lhs;
138 }
139
140 inline bool operator==(long lhs, const wxWindowIDRef& rhs)
141 {
142 return rhs == lhs;
143 }
144
145 inline bool operator!=(const wxWindowIDRef& lhs, const wxWindowIDRef& rhs)
146 {
147 return !(lhs == rhs);
148 }
149
150 inline bool operator!=(const wxWindowIDRef& lhs, int rhs)
151 {
152 return !(lhs == rhs);
153 }
154
155 inline bool operator!=(const wxWindowIDRef& lhs, long rhs)
156 {
157 return !(lhs == rhs);
158 }
159
160 inline bool operator!=(int lhs, const wxWindowIDRef& rhs)
161 {
162 return !(lhs == rhs);
163 }
164
165 inline bool operator!=(long lhs, const wxWindowIDRef& rhs)
166 {
167 return !(lhs == rhs);
168 }
169
170 // ----------------------------------------------------------------------------
171 // wxIdManager
172 // ----------------------------------------------------------------------------
173
174 class WXDLLIMPEXP_CORE wxIdManager
175 {
176 public:
177 // This returns an id value and not an wxWindowIDRef. The returned value
178 // should be assigned a.s.a.p to a wxWindowIDRef. The IDs are marked as
179 // reserved so that another call to ReserveId before assigning the id to a
180 // wxWindowIDRef will not use the same ID
181 static wxWindowID ReserveId(int count = 1);
182
183 // This will release an unused reserved ID. This should only be called
184 // if the ID returned by ReserveId was NOT assigned to a wxWindowIDRef
185 // for some purpose, maybe an early return from a function
186 static void UnreserveId(wxWindowID id, int count = 1);
187 };
188
189 #endif // _WX_WINDOWID_H_