neoWidgets
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Pages
MessageId.h
1 #ifndef NEO_MESSAGE_ID_H
2 #define NEO_MESSAGE_ID_H
3 
4 namespace neo
5 {
6 
14 class MessageId
15 {
16 public:
17  MessageId(UINT message);
18 
22  bool EqualOrSpecializationOf(const MessageId& rhs) const;
23  bool operator==(const MessageId& rhs) const;
27  bool operator<(const MessageId& rhs) const;
28 
29  void SetParam1(UINT_PTR param) { paramMask |= 0x1; p1 = param; }
30  void SetParam2(UINT_PTR param) { paramMask |= 0x2; p2 = param; }
31  void SetParam3(UINT_PTR param) { paramMask |= 0x4; p3 = param; }
32 
33  UINT message;
34  UINT paramMask; //<! which parameters are in use
35  UINT_PTR p1;
36  UINT_PTR p2;
37  UINT_PTR p3;
38 };
39 
41 {
42 public:
44  CommandMessageId(UINT notifyCode, HWND control);
45  CommandMessageId(UINT notifyCode, UINT_PTR idOfControl);
46  CommandMessageId(UINT notifyCode, UINT_PTR idOfControl, HWND control);
47 
48  CommandMessageId& NotifyCode(UINT code) { SetParam1(code); return *this; }
49  CommandMessageId& ControlId(UINT_PTR id) { SetParam2(id); return *this; }
50  CommandMessageId& Control(HWND control) { SetParam3(reinterpret_cast<UINT_PTR>(control)); return *this; }
51 };
52 
54 {
55 public:
57  ButtonMessageId(HWND control);
58  ButtonMessageId(UINT idOfControl);
59 };
60 
66 {
67 public:
69  NotifyMessageId(UINT notifyCode, HWND control);
70  NotifyMessageId(UINT notifyCode, UINT_PTR idOfControl);
71  NotifyMessageId(UINT notifyCode, UINT_PTR idOfControl, HWND control);
72 };
73 
77 class ScrollMessageId : public MessageId
78 {
79 public:
80  ScrollMessageId(UINT message, HWND scrollbar);
81 };
82 
84 {
85 public:
86  WindowScrollMessageId(UINT message) : ScrollMessageId(message, 0) {}
87 };
88 
89 //-----------------------------------------------------------------------------
90 
91 inline MessageId::MessageId(UINT pMessage)
92 {
93  message = pMessage;
94  paramMask = 0;
95  p1 = 0;
96  p2 = 0;
97  p3 = 0;
98 }
99 
100 /*
101 tricky: this function also returns true if rhs is a generalization of this
102 e.g.
103 CommandMessageId id1(EN_UPDATE, edit);
104 MessageId id2(WM_COMMAND);
105 
106 id1.EqualOrSpecializationOf(id1) -> true
107 id2.EqualOrSpecializationOf(id2) -> true
108 id1.EqualOrSpecializationOf(id2) -> true
109 id2.EqualOrSpecializationOf(id1) -> false
110 */
111 inline bool MessageId::EqualOrSpecializationOf(const MessageId& rhs) const
112 {
113  UINT combinedMask = paramMask & rhs.paramMask;
114 
115  return message == rhs.message
116  && combinedMask == rhs.paramMask
117  && ((combinedMask & 0x1) ? p1 == rhs.p1 : true)
118  && ((combinedMask & 0x2) ? p2 == rhs.p2 : true)
119  && ((combinedMask & 0x4) ? p3 == rhs.p3 : true);
120 }
121 
122 inline bool MessageId::operator==(const MessageId& rhs) const
123 {
124  return message == rhs.message
125  && paramMask == rhs.paramMask
126  && p1 == rhs.p1
127  && p2 == rhs.p2
128  && p3 == rhs.p3;
129 }
130 
131 inline bool MessageId::operator<(const MessageId& rhs) const
132 {
133  if(message != rhs.message)
134  return message < rhs.message;
135 
136  if(paramMask != rhs.paramMask)
137  return paramMask > rhs.paramMask; // reverse order, means special masks are before general masks
138 
139  if(p1 != rhs.p1)
140  return p1 < rhs.p1;
141  if(p2 != rhs.p2)
142  return p2 < rhs.p2;
143  if(p3 != rhs.p3)
144  return p3 < rhs.p3;
145  return false;
146 }
147 
148 //-----------------------------------------------------------------------------
149 
150 inline CommandMessageId::CommandMessageId()
151  : MessageId(WM_COMMAND)
152 {
153 }
154 
155 inline CommandMessageId::CommandMessageId(UINT notifyCode, HWND control)
156  : MessageId(WM_COMMAND)
157 {
158  NotifyCode(notifyCode);
159  Control(control);
160 }
161 
162 inline CommandMessageId::CommandMessageId(UINT notifyCode, UINT_PTR idOfControl)
163  : MessageId(WM_COMMAND)
164 {
165  NotifyCode(notifyCode);
166  ControlId(idOfControl);
167 }
168 
169 inline CommandMessageId::CommandMessageId(UINT notifyCode, UINT_PTR idOfControl, HWND control)
170  : MessageId(WM_COMMAND)
171 {
172  NotifyCode(notifyCode);
173  ControlId(idOfControl);
174  Control(control);
175 }
176 
177 //-----------------------------------------------------------------------------
178 
179 inline ButtonMessageId::ButtonMessageId()
180  : CommandMessageId()
181 {
182  NotifyCode(BN_CLICKED);
183 }
184 
185 inline ButtonMessageId::ButtonMessageId(HWND control)
186  : CommandMessageId(BN_CLICKED, control)
187 {}
188 
189 inline ButtonMessageId::ButtonMessageId(UINT idOfControl)
190  : CommandMessageId(BN_CLICKED, idOfControl)
191 {}
192 
193 //-----------------------------------------------------------------------------
194 
195 inline NotifyMessageId::NotifyMessageId()
196  : CommandMessageId()
197 {
198  message = WM_NOTIFY;
199 }
200 
201 inline NotifyMessageId::NotifyMessageId(UINT notifyCode, HWND control)
202  : CommandMessageId(notifyCode, control)
203 {
204  message = WM_NOTIFY;
205 }
206 
207 inline NotifyMessageId::NotifyMessageId(UINT notifyCode, UINT_PTR idOfControl)
208  : CommandMessageId(notifyCode, idOfControl)
209 {
210  message = WM_NOTIFY;
211 }
212 
213 inline NotifyMessageId::NotifyMessageId(UINT notifyCode, UINT_PTR idOfControl, HWND control)
214  : CommandMessageId(notifyCode, idOfControl, control)
215 {
216  message = WM_NOTIFY;
217 }
218 
219 //-----------------------------------------------------------------------------
220 
221 inline ScrollMessageId::ScrollMessageId(UINT pMessage, HWND scrollbar)
222  : MessageId(pMessage)
223 {
224  assert(message == WM_HSCROLL || message == WM_VSCROLL);
225  SetParam1(reinterpret_cast<UINT_PTR>(scrollbar));
226 }
227 
228 } // namespace neo
229 
230 #endif
Definition: MessageId.h:77
Base class for standard Windows controls.
Definition: Control.h:73
Definition: MessageId.h:65
Definition: MessageId.h:53
Unified message identifier.
Definition: MessageId.h:14
Definition: MessageId.h:83
bool EqualOrSpecializationOf(const MessageId &rhs) const
For map lookup.
Definition: MessageId.h:111
bool operator<(const MessageId &rhs) const
For sorting.
Definition: MessageId.h:131
Definition: MessageId.h:40