1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWindowID class - a class for managing window ids
4 // Author: Brian Vanderburg II
6 // Copyright: (c) 2007 Brian Vanderburg II
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
10 #ifndef _WX_WINDOWID_H_
11 #define _WX_WINDOWID_H_
13 // NB: do not include defs.h as we are included from it
15 typedef int wxWindowID
;
17 // ----------------------------------------------------------------------------
18 // wxWindowIDRef: reference counted id value
19 // ----------------------------------------------------------------------------
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
26 // This class is always defined but it is trivial if wxUSE_AUTOID_MANAGEMENT is
28 class WXDLLIMPEXP_CORE wxWindowIDRef
37 // ctor taking id values
43 wxWindowIDRef(long id
)
48 wxWindowIDRef(const wxWindowIDRef
& id
)
60 wxWindowIDRef
& operator=(int id
)
66 wxWindowIDRef
& operator=(long id
)
68 Assign(wxWindowID(id
));
72 wxWindowIDRef
& operator=(const wxWindowIDRef
& id
)
79 // access to the stored id value
80 wxWindowID
GetValue() const
85 operator wxWindowID() const
91 #if wxUSE_AUTOID_MANAGEMENT
92 // common part of all ctors: call Assign() for our new id
93 void Init(wxWindowID id
)
95 // m_id must be initialized before calling Assign()
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
)
109 void Assign(wxWindowID id
)
113 #endif // wxUSE_AUTOID_MANAGEMENT/!wxUSE_AUTOID_MANAGEMENT
119 // comparison operators
120 inline bool operator==(const wxWindowIDRef
& lhs
, const wxWindowIDRef
& rhs
)
122 return lhs
.GetValue() == rhs
.GetValue();
125 inline bool operator==(const wxWindowIDRef
& lhs
, int rhs
)
127 return lhs
.GetValue() == rhs
;
130 inline bool operator==(const wxWindowIDRef
& lhs
, long rhs
)
132 return lhs
.GetValue() == rhs
;
135 inline bool operator==(int lhs
, const wxWindowIDRef
& rhs
)
140 inline bool operator==(long lhs
, const wxWindowIDRef
& rhs
)
145 inline bool operator!=(const wxWindowIDRef
& lhs
, const wxWindowIDRef
& rhs
)
147 return !(lhs
== rhs
);
150 inline bool operator!=(const wxWindowIDRef
& lhs
, int rhs
)
152 return !(lhs
== rhs
);
155 inline bool operator!=(const wxWindowIDRef
& lhs
, long rhs
)
157 return !(lhs
== rhs
);
160 inline bool operator!=(int lhs
, const wxWindowIDRef
& rhs
)
162 return !(lhs
== rhs
);
165 inline bool operator!=(long lhs
, const wxWindowIDRef
& rhs
)
167 return !(lhs
== rhs
);
170 // ----------------------------------------------------------------------------
172 // ----------------------------------------------------------------------------
174 class WXDLLIMPEXP_CORE wxIdManager
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);
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);
189 #endif // _WX_WINDOWID_H_