Cleanup setting of 'sysroot' in common.gypi
[chromium-blink-merge.git] / third_party / wtl / include / atlwinx.h
blobd0f1c4808dccbd0bfc8a768b5116c9e10ff4772d
1 // Windows Template Library - WTL version 8.0
2 // Copyright (C) Microsoft Corporation. All rights reserved.
3 //
4 // This file is a part of the Windows Template Library.
5 // The use and distribution terms for this software are covered by the
6 // Microsoft Permissive License (Ms-PL) which can be found in the file
7 // Ms-PL.txt at the root of this distribution.
9 #ifndef __ATLWINX_H__
10 #define __ATLWINX_H__
12 #pragma once
14 #ifndef __cplusplus
15 #error ATL requires C++ compilation (use a .cpp suffix)
16 #endif
18 #ifndef __ATLAPP_H__
19 #error atlwinx.h requires atlapp.h to be included first
20 #endif
22 #if (_ATL_VER >= 0x0700)
23 #include <atlwin.h>
24 #endif // (_ATL_VER >= 0x0700)
27 ///////////////////////////////////////////////////////////////////////////////
28 // Classes in this file:
30 // _U_RECT
31 // _U_MENUorID
32 // _U_STRINGorID
35 ///////////////////////////////////////////////////////////////////////////////
36 // Command Chaining Macros
38 #define CHAIN_COMMANDS(theChainClass) \
39 if(uMsg == WM_COMMAND) \
40 CHAIN_MSG_MAP(theChainClass)
42 #define CHAIN_COMMANDS_ALT(theChainClass, msgMapID) \
43 if(uMsg == WM_COMMAND) \
44 CHAIN_MSG_MAP_ALT(theChainClass, msgMapID)
46 #define CHAIN_COMMANDS_MEMBER(theChainMember) \
47 if(uMsg == WM_COMMAND) \
48 CHAIN_MSG_MAP_MEMBER(theChainMember)
50 #define CHAIN_COMMANDS_ALT_MEMBER(theChainMember, msgMapID) \
51 if(uMsg == WM_COMMAND) \
52 CHAIN_MSG_MAP_ALT_MEMBER(theChainMember, msgMapID)
55 ///////////////////////////////////////////////////////////////////////////////
56 // Macros for parent message map to selectively reflect control messages
58 // NOTE: ReflectNotifications is a member of ATL's CWindowImplRoot
59 // (and overridden in 2 cases - CContainedWindowT and CAxHostWindow)
60 // Since we can't modify ATL, we'll provide the needed additions
61 // in a separate function (that is not a member of CWindowImplRoot)
63 namespace WTL
66 inline LRESULT WtlReflectNotificationsFiltered(HWND hWndParent, UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled,
67 UINT uMsgFilter = WM_NULL, UINT_PTR idFromFilter = 0, HWND hWndChildFilter = NULL)
69 if((uMsgFilter != WM_NULL) && (uMsgFilter != uMsg))
71 // The notification message doesn't match the filter.
72 bHandled = FALSE;
73 return 1;
76 HWND hWndChild = NULL;
77 UINT_PTR idFrom = 0;
79 switch(uMsg)
81 case WM_COMMAND:
82 if(lParam != NULL) // not from a menu
84 hWndChild = (HWND)lParam;
85 idFrom = (UINT_PTR)LOWORD(wParam);
87 break;
88 case WM_NOTIFY:
89 hWndChild = ((LPNMHDR)lParam)->hwndFrom;
90 idFrom = ((LPNMHDR)lParam)->idFrom;
91 break;
92 #ifndef _WIN32_WCE
93 case WM_PARENTNOTIFY:
94 switch(LOWORD(wParam))
96 case WM_CREATE:
97 case WM_DESTROY:
98 hWndChild = (HWND)lParam;
99 idFrom = (UINT_PTR)HIWORD(wParam);
100 break;
101 default:
102 hWndChild = ::GetDlgItem(hWndParent, HIWORD(wParam));
103 idFrom = (UINT_PTR)::GetDlgCtrlID(hWndChild);
104 break;
106 break;
107 #endif // !_WIN32_WCE
108 case WM_DRAWITEM:
109 if(wParam) // not from a menu
111 hWndChild = ((LPDRAWITEMSTRUCT)lParam)->hwndItem;
112 idFrom = (UINT_PTR)wParam;
114 break;
115 case WM_MEASUREITEM:
116 if(wParam) // not from a menu
118 hWndChild = ::GetDlgItem(hWndParent, ((LPMEASUREITEMSTRUCT)lParam)->CtlID);
119 idFrom = (UINT_PTR)wParam;
121 break;
122 case WM_COMPAREITEM:
123 if(wParam) // not from a menu
125 hWndChild = ((LPCOMPAREITEMSTRUCT)lParam)->hwndItem;
126 idFrom = (UINT_PTR)wParam;
128 break;
129 case WM_DELETEITEM:
130 if(wParam) // not from a menu
132 hWndChild = ((LPDELETEITEMSTRUCT)lParam)->hwndItem;
133 idFrom = (UINT_PTR)wParam;
135 break;
136 case WM_VKEYTOITEM:
137 case WM_CHARTOITEM:
138 case WM_HSCROLL:
139 case WM_VSCROLL:
140 hWndChild = (HWND)lParam;
141 idFrom = (UINT_PTR)::GetDlgCtrlID(hWndChild);
142 break;
143 case WM_CTLCOLORBTN:
144 case WM_CTLCOLORDLG:
145 case WM_CTLCOLOREDIT:
146 case WM_CTLCOLORLISTBOX:
147 case WM_CTLCOLORMSGBOX:
148 case WM_CTLCOLORSCROLLBAR:
149 case WM_CTLCOLORSTATIC:
150 hWndChild = (HWND)lParam;
151 idFrom = (UINT_PTR)::GetDlgCtrlID(hWndChild);
152 break;
153 default:
154 break;
157 if((hWndChild == NULL) ||
158 ((hWndChildFilter != NULL) && (hWndChildFilter != hWndChild)))
160 // Either hWndChild isn't valid, or
161 // hWndChild doesn't match the filter.
162 bHandled = FALSE;
163 return 1;
166 if((idFromFilter != 0) && (idFromFilter != idFrom))
168 // The dialog control id doesn't match the filter.
169 bHandled = FALSE;
170 return 1;
173 ATLASSERT(::IsWindow(hWndChild));
174 LRESULT lResult = ::SendMessage(hWndChild, OCM__BASE + uMsg, wParam, lParam);
175 if((lResult == 0) && (uMsg >= WM_CTLCOLORMSGBOX) && (uMsg <= WM_CTLCOLORSTATIC))
177 // Try to prevent problems with WM_CTLCOLOR* messages when
178 // the message wasn't really handled
179 bHandled = FALSE;
182 return lResult;
185 }; // namespace WTL
187 // Try to prevent problems with WM_CTLCOLOR* messages when
188 // the message wasn't really handled
189 #define REFLECT_NOTIFICATIONS_EX() \
191 bHandled = TRUE; \
192 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
193 if((lResult == 0) && (uMsg >= WM_CTLCOLORMSGBOX) && (uMsg <= WM_CTLCOLORSTATIC)) \
194 bHandled = FALSE; \
195 if(bHandled) \
196 return TRUE; \
199 #define REFLECT_NOTIFICATIONS_MSG_FILTERED(uMsgFilter) \
201 bHandled = TRUE; \
202 lResult = WTL::WtlReflectNotificationsFiltered(m_hWnd, uMsg, wParam, lParam, bHandled, uMsgFilter, 0, NULL); \
203 if(bHandled) \
204 return TRUE; \
207 #define REFLECT_NOTIFICATIONS_ID_FILTERED(idFromFilter) \
209 bHandled = TRUE; \
210 lResult = WTL::WtlReflectNotificationsFiltered(m_hWnd, uMsg, wParam, lParam, bHandled, WM_NULL, idFromFilter, NULL); \
211 if(bHandled) \
212 return TRUE; \
215 #define REFLECT_NOTIFICATIONS_HWND_FILTERED(hWndChildFilter) \
217 bHandled = TRUE; \
218 lResult = WTL::WtlReflectNotificationsFiltered(m_hWnd, uMsg, wParam, lParam, bHandled, WM_NULL, 0, hWndChildFilter); \
219 if(bHandled) \
220 return TRUE; \
223 #define REFLECT_NOTIFICATIONS_MSG_ID_FILTERED(uMsgFilter, idFromFilter) \
225 bHandled = TRUE; \
226 lResult = WTL::WtlReflectNotificationsFiltered(m_hWnd, uMsg, wParam, lParam, bHandled, uMsgFilter, idFromFilter, NULL); \
227 if(bHandled) \
228 return TRUE; \
231 #define REFLECT_NOTIFICATIONS_MSG_HWND_FILTERED(uMsgFilter, hWndChildFilter) \
233 bHandled = TRUE; \
234 lResult = WTL::WtlReflectNotificationsFiltered(m_hWnd, uMsg, wParam, lParam, bHandled, uMsgFilter, 0, hWndChildFilter); \
235 if(bHandled) \
236 return TRUE; \
239 #define REFLECT_COMMAND(id, code) \
240 if(uMsg == WM_COMMAND && id == LOWORD(wParam) && code == HIWORD(wParam)) \
242 bHandled = TRUE; \
243 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
244 if(bHandled) \
245 return TRUE; \
248 #define REFLECT_COMMAND_ID(id) \
249 if(uMsg == WM_COMMAND && id == LOWORD(wParam)) \
251 bHandled = TRUE; \
252 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
253 if(bHandled) \
254 return TRUE; \
257 #define REFLECT_COMMAND_CODE(code) \
258 if(uMsg == WM_COMMAND && code == HIWORD(wParam)) \
260 bHandled = TRUE; \
261 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
262 if(bHandled) \
263 return TRUE; \
266 #define REFLECT_COMMAND_RANGE(idFirst, idLast) \
267 if(uMsg == WM_COMMAND && LOWORD(wParam) >= idFirst && LOWORD(wParam) <= idLast) \
269 bHandled = TRUE; \
270 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
271 if(bHandled) \
272 return TRUE; \
275 #define REFLECT_COMMAND_RANGE_CODE(idFirst, idLast, code) \
276 if(uMsg == WM_COMMAND && code == HIWORD(wParam) && LOWORD(wParam) >= idFirst && LOWORD(wParam) <= idLast) \
278 bHandled = TRUE; \
279 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
280 if(bHandled) \
281 return TRUE; \
284 #define REFLECT_NOTIFY(id, cd) \
285 if(uMsg == WM_NOTIFY && id == ((LPNMHDR)lParam)->idFrom && cd == ((LPNMHDR)lParam)->code) \
287 bHandled = TRUE; \
288 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
289 if(bHandled) \
290 return TRUE; \
293 #define REFLECT_NOTIFY_ID(id) \
294 if(uMsg == WM_NOTIFY && id == ((LPNMHDR)lParam)->idFrom) \
296 bHandled = TRUE; \
297 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
298 if(bHandled) \
299 return TRUE; \
302 #define REFLECT_NOTIFY_CODE(cd) \
303 if(uMsg == WM_NOTIFY && cd == ((LPNMHDR)lParam)->code) \
305 bHandled = TRUE; \
306 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
307 if(bHandled) \
308 return TRUE; \
311 #define REFLECT_NOTIFY_RANGE(idFirst, idLast) \
312 if(uMsg == WM_NOTIFY && ((LPNMHDR)lParam)->idFrom >= idFirst && ((LPNMHDR)lParam)->idFrom <= idLast) \
314 bHandled = TRUE; \
315 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
316 if(bHandled) \
317 return TRUE; \
320 #define REFLECT_NOTIFY_RANGE_CODE(idFirst, idLast, cd) \
321 if(uMsg == WM_NOTIFY && cd == ((LPNMHDR)lParam)->code && ((LPNMHDR)lParam)->idFrom >= idFirst && ((LPNMHDR)lParam)->idFrom <= idLast) \
323 bHandled = TRUE; \
324 lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
325 if(bHandled) \
326 return TRUE; \
330 ///////////////////////////////////////////////////////////////////////////////
331 // Reflected message handler macros for message maps (for ATL 3.0)
333 #if (_ATL_VER < 0x0700)
335 #define REFLECTED_COMMAND_HANDLER(id, code, func) \
336 if(uMsg == OCM_COMMAND && id == LOWORD(wParam) && code == HIWORD(wParam)) \
338 bHandled = TRUE; \
339 lResult = func(HIWORD(wParam), LOWORD(wParam), (HWND)lParam, bHandled); \
340 if(bHandled) \
341 return TRUE; \
344 #define REFLECTED_COMMAND_ID_HANDLER(id, func) \
345 if(uMsg == OCM_COMMAND && id == LOWORD(wParam)) \
347 bHandled = TRUE; \
348 lResult = func(HIWORD(wParam), LOWORD(wParam), (HWND)lParam, bHandled); \
349 if(bHandled) \
350 return TRUE; \
353 #define REFLECTED_COMMAND_CODE_HANDLER(code, func) \
354 if(uMsg == OCM_COMMAND && code == HIWORD(wParam)) \
356 bHandled = TRUE; \
357 lResult = func(HIWORD(wParam), LOWORD(wParam), (HWND)lParam, bHandled); \
358 if(bHandled) \
359 return TRUE; \
362 #define REFLECTED_COMMAND_RANGE_HANDLER(idFirst, idLast, func) \
363 if(uMsg == OCM_COMMAND && LOWORD(wParam) >= idFirst && LOWORD(wParam) <= idLast) \
365 bHandled = TRUE; \
366 lResult = func(HIWORD(wParam), LOWORD(wParam), (HWND)lParam, bHandled); \
367 if(bHandled) \
368 return TRUE; \
371 #define REFLECTED_COMMAND_RANGE_CODE_HANDLER(idFirst, idLast, code, func) \
372 if(uMsg == OCM_COMMAND && code == HIWORD(wParam) && LOWORD(wParam) >= idFirst && LOWORD(wParam) <= idLast) \
374 bHandled = TRUE; \
375 lResult = func(HIWORD(wParam), LOWORD(wParam), (HWND)lParam, bHandled); \
376 if(bHandled) \
377 return TRUE; \
380 #define REFLECTED_NOTIFY_HANDLER(id, cd, func) \
381 if(uMsg == OCM_NOTIFY && id == ((LPNMHDR)lParam)->idFrom && cd == ((LPNMHDR)lParam)->code) \
383 bHandled = TRUE; \
384 lResult = func((int)wParam, (LPNMHDR)lParam, bHandled); \
385 if(bHandled) \
386 return TRUE; \
389 #define REFLECTED_NOTIFY_ID_HANDLER(id, func) \
390 if(uMsg == OCM_NOTIFY && id == ((LPNMHDR)lParam)->idFrom) \
392 bHandled = TRUE; \
393 lResult = func((int)wParam, (LPNMHDR)lParam, bHandled); \
394 if(bHandled) \
395 return TRUE; \
398 #define REFLECTED_NOTIFY_CODE_HANDLER(cd, func) \
399 if(uMsg == OCM_NOTIFY && cd == ((LPNMHDR)lParam)->code) \
401 bHandled = TRUE; \
402 lResult = func((int)wParam, (LPNMHDR)lParam, bHandled); \
403 if(bHandled) \
404 return TRUE; \
407 #define REFLECTED_NOTIFY_RANGE_HANDLER(idFirst, idLast, func) \
408 if(uMsg == OCM_NOTIFY && ((LPNMHDR)lParam)->idFrom >= idFirst && ((LPNMHDR)lParam)->idFrom <= idLast) \
410 bHandled = TRUE; \
411 lResult = func((int)wParam, (LPNMHDR)lParam, bHandled); \
412 if(bHandled) \
413 return TRUE; \
416 #define REFLECTED_NOTIFY_RANGE_CODE_HANDLER(idFirst, idLast, cd, func) \
417 if(uMsg == OCM_NOTIFY && cd == ((LPNMHDR)lParam)->code && ((LPNMHDR)lParam)->idFrom >= idFirst && ((LPNMHDR)lParam)->idFrom <= idLast) \
419 bHandled = TRUE; \
420 lResult = func((int)wParam, (LPNMHDR)lParam, bHandled); \
421 if(bHandled) \
422 return TRUE; \
425 #endif // (_ATL_VER < 0x0700)
428 ///////////////////////////////////////////////////////////////////////////////
429 // Dual argument helper classes (for ATL 3.0)
431 #if (_ATL_VER < 0x0700)
433 namespace ATL
436 class _U_RECT
438 public:
439 _U_RECT(LPRECT lpRect) : m_lpRect(lpRect)
441 _U_RECT(RECT& rc) : m_lpRect(&rc)
443 LPRECT m_lpRect;
446 class _U_MENUorID
448 public:
449 _U_MENUorID(HMENU hMenu) : m_hMenu(hMenu)
451 _U_MENUorID(UINT nID) : m_hMenu((HMENU)LongToHandle(nID))
453 HMENU m_hMenu;
456 class _U_STRINGorID
458 public:
459 _U_STRINGorID(LPCTSTR lpString) : m_lpstr(lpString)
461 _U_STRINGorID(UINT nID) : m_lpstr(MAKEINTRESOURCE(nID))
463 LPCTSTR m_lpstr;
466 }; // namespace ATL
468 #endif // (_ATL_VER < 0x0700)
471 namespace WTL
474 ///////////////////////////////////////////////////////////////////////////////
475 // Forward notifications support for message maps (for ATL 3.0)
477 #if (_ATL_VER < 0x0700)
479 // forward notifications support
480 #define FORWARD_NOTIFICATIONS() \
482 bHandled = TRUE; \
483 lResult = WTL::Atl3ForwardNotifications(m_hWnd, uMsg, wParam, lParam, bHandled); \
484 if(bHandled) \
485 return TRUE; \
488 static LRESULT Atl3ForwardNotifications(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
490 LRESULT lResult = 0;
491 switch(uMsg)
493 case WM_COMMAND:
494 case WM_NOTIFY:
495 #ifndef _WIN32_WCE
496 case WM_PARENTNOTIFY:
497 #endif // !_WIN32_WCE
498 case WM_DRAWITEM:
499 case WM_MEASUREITEM:
500 case WM_COMPAREITEM:
501 case WM_DELETEITEM:
502 case WM_VKEYTOITEM:
503 case WM_CHARTOITEM:
504 case WM_HSCROLL:
505 case WM_VSCROLL:
506 case WM_CTLCOLORBTN:
507 case WM_CTLCOLORDLG:
508 case WM_CTLCOLOREDIT:
509 case WM_CTLCOLORLISTBOX:
510 case WM_CTLCOLORMSGBOX:
511 case WM_CTLCOLORSCROLLBAR:
512 case WM_CTLCOLORSTATIC:
513 lResult = ::SendMessage(::GetParent(hWnd), uMsg, wParam, lParam);
514 break;
515 default:
516 bHandled = FALSE;
517 break;
519 return lResult;
522 #endif // (_ATL_VER < 0x0700)
524 }; // namespace WTL
526 #endif // __ATLWINX_H__