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
)
69 Assign(wxWindowID(id
));
73 wxWindowIDRef
& operator=(const wxWindowIDRef
& id
)
80 // access to the stored id value
81 wxWindowID
GetValue() const
86 operator wxWindowID() const
92 #if wxUSE_AUTOID_MANAGEMENT
93 // common part of all ctors: call Assign() for our new id
94 void Init(wxWindowID id
)
96 // m_id must be initialized before calling Assign()
101 // increase reference count of id, decrease the one of m_id
102 void Assign(wxWindowID id
);
103 #else // !wxUSE_AUTOID_MANAGEMENT
104 // trivial stubs for the functions above
105 void Init(wxWindowID id
)
110 void Assign(wxWindowID id
)
114 #endif // wxUSE_AUTOID_MANAGEMENT/!wxUSE_AUTOID_MANAGEMENT
120 // comparison operators
121 inline bool operator==(const wxWindowIDRef
& lhs
, const wxWindowIDRef
& rhs
)
123 return lhs
.GetValue() == rhs
.GetValue();
126 inline bool operator==(const wxWindowIDRef
& lhs
, int rhs
)
128 return lhs
.GetValue() == rhs
;
131 inline bool operator==(const wxWindowIDRef
& lhs
, long rhs
)
133 return lhs
.GetValue() == rhs
;
136 inline bool operator==(int lhs
, const wxWindowIDRef
& rhs
)
141 inline bool operator==(long lhs
, const wxWindowIDRef
& rhs
)
146 inline bool operator!=(const wxWindowIDRef
& lhs
, const wxWindowIDRef
& rhs
)
148 return !(lhs
== rhs
);
151 inline bool operator!=(const wxWindowIDRef
& lhs
, int rhs
)
153 return !(lhs
== rhs
);
156 inline bool operator!=(const wxWindowIDRef
& lhs
, long rhs
)
158 return !(lhs
== rhs
);
161 inline bool operator!=(int lhs
, const wxWindowIDRef
& rhs
)
163 return !(lhs
== rhs
);
166 inline bool operator!=(long lhs
, const wxWindowIDRef
& rhs
)
168 return !(lhs
== rhs
);
171 // ----------------------------------------------------------------------------
173 // ----------------------------------------------------------------------------
175 class WXDLLIMPEXP_CORE wxIdManager
178 // This returns an id value and not an wxWindowIDRef. The returned value
179 // should be assigned a.s.a.p to a wxWindowIDRef. The IDs are marked as
180 // reserved so that another call to ReserveId before assigning the id to a
181 // wxWindowIDRef will not use the same ID
182 static wxWindowID
ReserveId(int count
= 1);
184 // This will release an unused reserved ID. This should only be called
185 // if the ID returned by ReserveId was NOT assigned to a wxWindowIDRef
186 // for some purpose, maybe an early return from a function
187 static void UnreserveId(wxWindowID id
, int count
= 1);
190 #endif // _WX_WINDOWID_H_