1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWindowID class - a class for managing window ids
4 // Author: Brian Vanderburg II
7 // Copyright: (c) 2007 Brian Vanderburg II
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_WINDOWID_H_
12 #define _WX_WINDOWID_H_
14 // NB: do not include defs.h as we are included from it
16 typedef int wxWindowID
;
18 // ----------------------------------------------------------------------------
19 // wxWindowIDRef: reference counted id value
20 // ----------------------------------------------------------------------------
22 // A wxWindowIDRef object wraps an id value and marks it as (un)used as
23 // necessary. All ids returned from wxWindow::NewControlId() should be assigned
24 // to an instance of this class to ensure that the id is marked as being in
27 // This class is always defined but it is trivial if wxUSE_AUTOID_MANAGEMENT is
29 class WXDLLIMPEXP_CORE wxWindowIDRef
38 // ctor taking id values
44 wxWindowIDRef(long id
)
49 wxWindowIDRef(const wxWindowIDRef
& id
)
61 wxWindowIDRef
& operator=(int id
)
67 wxWindowIDRef
& operator=(long id
)
73 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_