ReactOS 0.4.16-dev-1264-g92ff994
CMenuFocusManager Class Reference

#include <CMenuFocusManager.h>

Inheritance diagram for CMenuFocusManager:
Collaboration diagram for CMenuFocusManager:

Classes

struct  StackEntry
 

Public Member Functions

HRESULT PushMenuBar (CMenuBand *mb)
 
HRESULT PushMenuPopup (CMenuBand *mb)
 
HRESULT PushTrackedPopup (HMENU popup)
 
HRESULT PopMenuBar (CMenuBand *mb)
 
HRESULT PopMenuPopup (CMenuBand *mb)
 
HRESULT PopTrackedPopup (HMENU popup)
 
- Public Member Functions inherited from ATL::CComObjectRootEx< CComMultiThreadModelNoCS >
 ~CComObjectRootEx ()
 
ULONG InternalAddRef ()
 
ULONG InternalRelease ()
 
void Lock ()
 
void Unlock ()
 
HRESULT _AtlInitialConstruct ()
 
- Public Member Functions inherited from ATL::CComObjectRootBase
 CComObjectRootBase ()
 
 ~CComObjectRootBase ()
 
void SetVoid (void *)
 
HRESULT _AtlFinalConstruct ()
 
HRESULT FinalConstruct ()
 
void InternalFinalConstructAddRef ()
 
void InternalFinalConstructRelease ()
 
void FinalRelease ()
 

Static Public Member Functions

static CMenuFocusManagerAcquireManager ()
 
static void ReleaseManager (CMenuFocusManager *obj)
 
- Static Public Member Functions inherited from ATL::CComObjectRootBase
static void WINAPI ObjectMain (bool)
 
static const struct _ATL_CATMAP_ENTRYGetCategoryMap ()
 
static HRESULT WINAPI InternalQueryInterface (void *pThis, const _ATL_INTMAP_ENTRY *pEntries, REFIID iid, void **ppvObject)
 

Protected Member Functions

 CMenuFocusManager ()
 
 ~CMenuFocusManager ()
 

Private Types

enum  StackEntryType { NoEntry , MenuBarEntry , MenuPopupEntry , TrackedMenuEntry }
 

Private Member Functions

HRESULT PushToArray (StackEntryType type, CMenuBand *mb, HMENU hmenu)
 
HRESULT PopFromArray (StackEntryType *pType, CMenuBand **pMb, HMENU *pHmenu)
 
LRESULT GetMsgHook (INT nCode, WPARAM wParam, LPARAM lParam)
 
LRESULT MsgFilterHook (INT nCode, WPARAM wParam, LPARAM lParam)
 
HRESULT PlaceHooks ()
 
HRESULT RemoveHooks ()
 
HRESULT UpdateFocus ()
 
HRESULT IsTrackedWindow (HWND hWnd, StackEntry **pentry=NULL)
 
HRESULT IsTrackedWindowOrParent (HWND hWnd)
 
void DisableMouseTrack (HWND parent, BOOL disableThis)
 
void SetMenuCapture (HWND child)
 
LRESULT ProcessMouseMove (MSG *msg)
 
LRESULT ProcessMouseDown (MSG *msg, BOOL isLButton)
 
LRESULT ProcessMouseUp (MSG *msg, BOOL isLButton)
 

Static Private Member Functions

static CMenuFocusManagerGetManager ()
 
static LRESULT CALLBACK s_MsgFilterHook (INT nCode, WPARAM wParam, LPARAM lParam)
 
static LRESULT CALLBACK s_GetMsgHook (INT nCode, WPARAM wParam, LPARAM lParam)
 

Private Attributes

StackEntrym_current
 
StackEntrym_parent
 
StackEntrym_menuBar
 
HHOOK m_hMsgFilterHook
 
HHOOK m_hGetMsgHook
 
DWORD m_threadId
 
BOOL m_mouseTrackDisabled
 
POINT m_ptPrev
 
HWND m_captureHwnd
 
HWND m_hwndUnderMouse
 
StackEntrym_entryUnderMouse
 
HMENU m_selectedMenu
 
INT m_selectedItem
 
DWORD m_selectedItemFlags
 
BOOL m_movedSinceDown
 
HWND m_windowAtDown
 
HWND m_PreviousForeground
 
StackEntry m_bandStack [MAX_RECURSE]
 
int m_bandCount
 
int m_menuDepth
 

Static Private Attributes

static DWORD TlsIndex = 0
 

Additional Inherited Members

- Public Attributes inherited from ATL::CComObjectRootBase
LONG m_dwRef
 

Detailed Description

Definition at line 24 of file CMenuFocusManager.h.

Member Enumeration Documentation

◆ StackEntryType

Enumerator
NoEntry 
MenuBarEntry 
MenuPopupEntry 
TrackedMenuEntry 

Definition at line 33 of file CMenuFocusManager.h.

Constructor & Destructor Documentation

◆ CMenuFocusManager()

CMenuFocusManager::CMenuFocusManager ( )
protected

Definition at line 176 of file CMenuFocusManager.cpp.

176 :
178 m_parent(NULL),
182 m_captureHwnd(0),
191 m_bandCount(0),
192 m_menuDepth(0)
193{
194 m_ptPrev.x = 0;
195 m_ptPrev.y = 0;
197}
StackEntry * m_entryUnderMouse
StackEntry * m_current
StackEntry * m_parent
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
long y
Definition: polytest.cpp:48
long x
Definition: polytest.cpp:48
DWORD WINAPI GetCurrentThreadId(void)
Definition: thread.c:459

◆ ~CMenuFocusManager()

CMenuFocusManager::~CMenuFocusManager ( )
protected

Definition at line 199 of file CMenuFocusManager.cpp.

200{
201}

Member Function Documentation

◆ AcquireManager()

CMenuFocusManager * CMenuFocusManager::AcquireManager ( )
static

Definition at line 97 of file CMenuFocusManager.cpp.

98{
100
101 if (!TlsIndex)
102 {
104 return NULL;
105 }
106
107 obj = GetManager();
108
109 if (!obj)
110 {
111 obj = new CComObject<CMenuFocusManager>();
113 }
114
115 obj->AddRef();
116
117 return obj;
118}
static CMenuFocusManager * GetManager()
static DWORD TlsIndex
BOOL WINAPI TlsSetValue(IN DWORD Index, IN LPVOID Value)
Definition: thread.c:1276
DWORD WINAPI DECLSPEC_HOTPATCH TlsAlloc(void)
Definition: thread.c:657
#define TLS_OUT_OF_INDEXES
Definition: winbase.h:585

Referenced by CMenuBand::CMenuBand().

◆ DisableMouseTrack()

void CMenuFocusManager::DisableMouseTrack ( HWND  parent,
BOOL  disableThis 
)
private

Definition at line 204 of file CMenuFocusManager.cpp.

205{
206 BOOL bDisable = FALSE;
207 BOOL lastDisable = FALSE;
208
209 int i = m_bandCount;
210 while (--i >= 0)
211 {
212 StackEntry& entry = m_bandStack[i];
213
214 if (entry.type != TrackedMenuEntry)
215 {
216 HWND hwnd;
217 HRESULT hr = entry.mb->_GetTopLevelWindow(&hwnd);
219 break;
220
221 if (hwnd == parent)
222 {
223 lastDisable = disableThis;
224 entry.mb->_DisableMouseTrack(disableThis);
225 bDisable = TRUE;
226 }
227 else
228 {
229 lastDisable = bDisable;
230 entry.mb->_DisableMouseTrack(bDisable);
231 }
232 }
233 }
234 m_mouseTrackDisabled = lastDisable;
235}
StackEntry m_bandStack[MAX_RECURSE]
#define TRUE
Definition: types.h:120
#define FAILED_UNEXPECTEDLY
Definition: utils.cpp:30
r parent
Definition: btrfs.c:3010
unsigned int BOOL
Definition: ntddk_ex.h:94
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
uint32_t entry
Definition: isohybrid.c:63
HRESULT hr
Definition: shlfolder.c:183
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023

Referenced by GetMsgHook(), ProcessMouseMove(), and UpdateFocus().

◆ GetManager()

CMenuFocusManager * CMenuFocusManager::GetManager ( )
staticprivate

Definition at line 91 of file CMenuFocusManager.cpp.

92{
93 return reinterpret_cast<CMenuFocusManager *>(TlsGetValue(TlsIndex));
94}
LPVOID WINAPI TlsGetValue(IN DWORD Index)
Definition: thread.c:1240

Referenced by AcquireManager(), s_GetMsgHook(), and s_MsgFilterHook().

◆ GetMsgHook()

LRESULT CMenuFocusManager::GetMsgHook ( INT  nCode,
WPARAM  wParam,
LPARAM  lParam 
)
private

Definition at line 574 of file CMenuFocusManager.cpp.

575{
576 BOOL isLButton = FALSE;
577 if (nCode < 0)
578 return CallNextHookEx(m_hGetMsgHook, nCode, hookWParam, hookLParam);
579
580 if (nCode == HC_ACTION)
581 {
582 BOOL callNext = TRUE;
583 MSG* msg = reinterpret_cast<MSG*>(hookLParam);
584 POINT pt = msg->pt;
585
586 switch (msg->message)
587 {
589 if (m_captureHwnd)
590 {
591 TRACE("Capture lost.\n");
593 }
594 break;
595
596 case WM_NCLBUTTONDOWN:
597 case WM_LBUTTONDBLCLK:
598 case WM_LBUTTONDOWN:
599 isLButton = TRUE;
600 TRACE("LB\n");
601
603 {
604 POINT pt = msg->pt;
606 BOOL hoveringMenuBar = m_menuBar->mb->IsWindowOwner(child) == S_OK;
607 if (hoveringMenuBar)
608 {
609 m_current->mb->_MenuItemSelect(MPOS_FULLCANCEL);
610 break;
611 }
612 }
613
615 {
617
619 {
620 m_current->mb->_MenuItemSelect(MPOS_FULLCANCEL);
621 break;
622 }
623 }
624
625 ProcessMouseDown(msg, isLButton);
626
627 break;
628 case WM_NCRBUTTONUP:
629 case WM_RBUTTONUP:
630 ProcessMouseUp(msg, isLButton);
631 break;
632 case WM_NCLBUTTONUP:
633 case WM_LBUTTONUP:
634 isLButton = TRUE;
635 ProcessMouseUp(msg, isLButton);
636 break;
637 case WM_MOUSEMOVE:
638 callNext = ProcessMouseMove(msg);
639 break;
640 case WM_MOUSELEAVE:
641 callNext = ProcessMouseMove(msg);
642 //callNext = ProcessMouseLeave(msg);
643 break;
644 case WM_SYSKEYDOWN:
645 case WM_KEYDOWN:
647 {
649 switch (msg->wParam)
650 {
651 case VK_ESCAPE:
652 case VK_MENU:
653 case VK_LMENU:
654 case VK_RMENU:
655 m_current->mb->_MenuItemSelect(MPOS_FULLCANCEL);
656 break;
657 case VK_RETURN:
658 m_current->mb->_MenuItemSelect(MPOS_EXECUTE);
659 break;
660 case VK_LEFT:
662 break;
663 case VK_RIGHT:
665 break;
666 case VK_UP:
668 break;
669 case VK_DOWN:
671 break;
672 }
673 msg->message = WM_NULL;
674 msg->lParam = 0;
675 msg->wParam = 0;
676 }
677 break;
678 }
679
680 if (!callNext)
681 return 1;
682 }
683
684 return CallNextHookEx(m_hGetMsgHook, nCode, hookWParam, hookLParam);
685}
#define msg(x)
Definition: auth_time.c:54
STDMETHOD() IsWindowOwner(HWND hWnd) override
Definition: CMenuBand.cpp:759
HRESULT _MenuItemSelect(DWORD changeType)
Definition: CMenuBand.cpp:965
LRESULT ProcessMouseMove(MSG *msg)
HRESULT IsTrackedWindowOrParent(HWND hWnd)
LRESULT ProcessMouseUp(MSG *msg, BOOL isLButton)
void DisableMouseTrack(HWND parent, BOOL disableThis)
LRESULT ProcessMouseDown(MSG *msg, BOOL isLButton)
StackEntry * m_menuBar
#define pt(x, y)
Definition: drawing.c:79
#define S_OK
Definition: intsafe.h:52
static HWND child
Definition: cursoricon.c:298
#define WM_MOUSELEAVE
Definition: commctrl.h:4980
#define TRACE(s)
Definition: solgame.cpp:4
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
#define WM_CAPTURECHANGED
Definition: winuser.h:1827
#define WM_LBUTTONDBLCLK
Definition: winuser.h:1797
#define HC_ACTION
Definition: winuser.h:48
#define WM_RBUTTONUP
Definition: winuser.h:1799
#define VK_UP
Definition: winuser.h:2244
#define WM_MOUSEMOVE
Definition: winuser.h:1794
#define WM_LBUTTONDOWN
Definition: winuser.h:1795
#define VK_RETURN
Definition: winuser.h:2220
#define VK_RMENU
Definition: winuser.h:2306
#define WM_NULL
Definition: winuser.h:1626
#define WM_LBUTTONUP
Definition: winuser.h:1796
LRESULT WINAPI CallNextHookEx(_In_opt_ HHOOK, _In_ int, _In_ WPARAM, _In_ LPARAM)
#define VK_LEFT
Definition: winuser.h:2243
#define VK_RIGHT
Definition: winuser.h:2245
#define WM_NCLBUTTONUP
Definition: winuser.h:1712
#define VK_DOWN
Definition: winuser.h:2246
HWND WINAPI WindowFromPoint(_In_ POINT)
#define WM_NCRBUTTONUP
Definition: winuser.h:1715
#define WM_KEYDOWN
Definition: winuser.h:1734
#define VK_ESCAPE
Definition: winuser.h:2233
#define WM_SYSKEYDOWN
Definition: winuser.h:1738
#define WM_NCLBUTTONDOWN
Definition: winuser.h:1711
#define VK_LMENU
Definition: winuser.h:2305
#define VK_MENU
Definition: winuser.h:2223

Referenced by s_GetMsgHook().

◆ IsTrackedWindow()

HRESULT CMenuFocusManager::IsTrackedWindow ( HWND  hWnd,
StackEntry **  pentry = NULL 
)
private

Definition at line 257 of file CMenuFocusManager.cpp.

258{
259 if (pentry)
260 *pentry = NULL;
261
262 for (int i = m_bandCount; --i >= 0;)
263 {
264 StackEntry& entry = m_bandStack[i];
265
266 if (entry.type != TrackedMenuEntry)
267 {
268 HRESULT hr = entry.mb->IsWindowOwner(hWnd);
270 return hr;
271 if (hr == S_OK)
272 {
273 if (pentry)
274 *pentry = &entry;
275 return S_OK;
276 }
277 }
278 }
279
280 return S_FALSE;
281}
HWND hWnd
Definition: settings.c:17
#define S_FALSE
Definition: winerror.h:2357

Referenced by ProcessMouseDown(), ProcessMouseMove(), and ProcessMouseUp().

◆ IsTrackedWindowOrParent()

HRESULT CMenuFocusManager::IsTrackedWindowOrParent ( HWND  hWnd)
private

Definition at line 283 of file CMenuFocusManager.cpp.

284{
285 for (int i = m_bandCount; --i >= 0;)
286 {
287 StackEntry& entry = m_bandStack[i];
288
289 if (entry.type != TrackedMenuEntry)
290 {
291 HRESULT hr = entry.mb->IsWindowOwner(hWnd);
293 return hr;
294 if (hr == S_OK)
295 return S_OK;
296 if (entry.mb->_IsPopup() == S_OK)
297 {
298 CComPtr<IUnknown> site;
299 CComPtr<IOleWindow> pw;
300 hr = entry.mb->GetSite(IID_PPV_ARG(IUnknown, &site));
302 continue;
303 hr = IUnknown_QueryService(site, SID_SMenuBandParent, IID_PPV_ARG(IOleWindow, &pw));
305 continue;
306
307 HWND hParent;
308 if (pw->GetWindow(&hParent) == S_OK && hParent == hWnd)
309 return S_OK;
310 }
311 }
312 }
313
314 return S_FALSE;
315}
HRESULT WINAPI IUnknown_QueryService(IUnknown *, REFGUID, REFIID, LPVOID *)
Definition: ordinal.c:1501
static IActiveScriptSite * site
Definition: script.c:149
#define IID_PPV_ARG(Itype, ppType)

Referenced by GetMsgHook().

◆ MsgFilterHook()

LRESULT CMenuFocusManager::MsgFilterHook ( INT  nCode,
WPARAM  wParam,
LPARAM  lParam 
)
private

Definition at line 508 of file CMenuFocusManager.cpp.

509{
510 if (nCode < 0)
511 return CallNextHookEx(m_hMsgFilterHook, nCode, hookWParam, hookLParam);
512
513 if (nCode == MSGF_MENU)
514 {
515 BOOL callNext = TRUE;
516 MSG* msg = reinterpret_cast<MSG*>(hookLParam);
517
518 switch (msg->message)
519 {
520 case WM_LBUTTONDOWN:
521 case WM_RBUTTONDOWN:
523 {
524 POINT pt = msg->pt;
526 BOOL hoveringMenuBar = m_menuBar->mb->IsWindowOwner(child) == S_OK;
527 if (hoveringMenuBar)
528 {
530 }
531 }
532 break;
533 case WM_MOUSEMOVE:
534 callNext = ProcessMouseMove(msg);
535 break;
536 case WM_INITMENUPOPUP:
537 TRACE("WM_INITMENUPOPUP %p %p\n", msg->wParam, msg->lParam);
538 m_selectedMenu = reinterpret_cast<HMENU>(msg->lParam);
539 m_selectedItem = -1;
541 break;
542 case WM_MENUSELECT:
543 TRACE("WM_MENUSELECT %p %p\n", msg->wParam, msg->lParam);
544 m_selectedMenu = reinterpret_cast<HMENU>(msg->lParam);
546 m_selectedItemFlags = HIWORD(msg->wParam);
547 break;
548 case WM_KEYDOWN:
549 switch (msg->wParam)
550 {
551 case VK_LEFT:
553 {
555 }
556 break;
557 case VK_RIGHT:
559 {
561 }
562 break;
563 }
564 break;
565 }
566
567 if (!callNext)
568 return 1;
569 }
570
571 return CallNextHookEx(m_hMsgFilterHook, nCode, hookWParam, hookLParam);
572}
HRESULT _BeforeCancelPopup()
Definition: CMenuBand.cpp:1112
static const CLSID *static CLSID *static const GUID VARIANT VARIANT *static IServiceProvider DWORD *static HMENU
Definition: ordinal.c:63
#define HIWORD(l)
Definition: typedefs.h:247
#define GET_X_LPARAM(lp)
Definition: windowsx.h:299
#define MF_POPUP
Definition: winuser.h:136
#define WM_RBUTTONDOWN
Definition: winuser.h:1798
#define WM_INITMENUPOPUP
Definition: winuser.h:1765
#define MSGF_MENU
Definition: winuser.h:1186
#define WM_MENUSELECT
Definition: winuser.h:1766

Referenced by s_MsgFilterHook().

◆ PlaceHooks()

HRESULT CMenuFocusManager::PlaceHooks ( )
private

Definition at line 687 of file CMenuFocusManager.cpp.

688{
689 if (m_hGetMsgHook)
690 {
691 WARN("GETMESSAGE hook already placed!\n");
692 return S_OK;
693 }
695 {
696 WARN("MSGFILTER hook already placed!\n");
697 return S_OK;
698 }
700 {
701 TRACE("Entering MSGFILTER hook...\n");
703 }
704 else
705 {
706 TRACE("Entering GETMESSAGE hook...\n");
708 }
709 return S_OK;
710}
#define WARN(fmt,...)
Definition: precomp.h:61
static LRESULT CALLBACK s_MsgFilterHook(INT nCode, WPARAM wParam, LPARAM lParam)
static LRESULT CALLBACK s_GetMsgHook(INT nCode, WPARAM wParam, LPARAM lParam)
#define WH_MSGFILTER
Definition: winuser.h:29
#define SetWindowsHookEx
Definition: winuser.h:5941
#define WH_GETMESSAGE
Definition: winuser.h:33

Referenced by UpdateFocus().

◆ PopFromArray()

HRESULT CMenuFocusManager::PopFromArray ( StackEntryType pType,
CMenuBand **  pMb,
HMENU pHmenu 
)
private

Definition at line 152 of file CMenuFocusManager.cpp.

153{
154 if (pType) *pType = NoEntry;
155 if (pMb) *pMb = NULL;
156 if (pHmenu) *pHmenu = NULL;
157
158 if (m_bandCount <= 0)
159 return S_FALSE;
160
161 m_bandCount--;
162
163 if (pType) *pType = m_bandStack[m_bandCount].type;
164 if (*pType == TrackedMenuEntry)
165 {
166 if (pHmenu) *pHmenu = m_bandStack[m_bandCount].hmenu;
167 }
168 else
169 {
170 if (pMb) *pMb = m_bandStack[m_bandCount].mb;
171 }
172
173 return S_OK;
174}

Referenced by PopMenuBar(), PopMenuPopup(), and PopTrackedPopup().

◆ PopMenuBar()

HRESULT CMenuFocusManager::PopMenuBar ( CMenuBand mb)

Definition at line 941 of file CMenuFocusManager.cpp.

942{
944 CMenuBand * mbc;
945 HRESULT hr;
946
947 TRACE("PopMenuBar %p\n", mb);
948
950 {
952 }
953
954 hr = PopFromArray(&type, &mbc, NULL);
956 {
957 UpdateFocus();
958 return hr;
959 }
960
962 if (type != MenuBarEntry)
963 return E_FAIL;
964
965 if (!mbc)
966 return E_FAIL;
967
968 mbc->_SetParentBand(NULL);
969
970 mbc->Release();
971
972 hr = UpdateFocus();
974 return hr;
975
976 if (m_current)
977 {
980 }
981
982 return S_OK;
983}
#define _ASSERT(x)
HRESULT _SetChildBand(CMenuBand *child)
Definition: CMenuBand.cpp:605
HRESULT PopFromArray(StackEntryType *pType, CMenuBand **pMb, HMENU *pHmenu)
#define E_FAIL
Definition: ddrawi.h:102
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
char mbc

Referenced by CMenuBand::ShowDW().

◆ PopMenuPopup()

HRESULT CMenuFocusManager::PopMenuPopup ( CMenuBand mb)

Definition at line 986 of file CMenuFocusManager.cpp.

987{
989 CMenuBand * mbc;
990 HRESULT hr;
991
992 TRACE("PopMenuPopup %p\n", mb);
993
995 {
997 }
998
999 m_menuDepth--;
1000
1001 hr = PopFromArray(&type, &mbc, NULL);
1003 {
1004 UpdateFocus();
1005 return hr;
1006 }
1007
1009 if (type != MenuPopupEntry)
1010 return E_FAIL;
1011
1012 if (!mbc)
1013 return E_FAIL;
1014
1015 mbc->_SetParentBand(NULL);
1016
1017 mbc->Release();
1018
1019 hr = UpdateFocus();
1021 return hr;
1022
1023 if (m_current)
1024 {
1027 }
1028
1029 return S_OK;
1030}

Referenced by CMenuBand::ShowDW().

◆ PopTrackedPopup()

HRESULT CMenuFocusManager::PopTrackedPopup ( HMENU  popup)

Definition at line 1033 of file CMenuFocusManager.cpp.

1034{
1036 HMENU hmenu;
1037 HRESULT hr;
1038
1039 TRACE("PopTrackedPopup %p\n", popup);
1040
1041 hr = PopFromArray(&type, NULL, &hmenu);
1043 {
1044 UpdateFocus();
1045 return hr;
1046 }
1047
1049 if (type != TrackedMenuEntry)
1050 return E_FAIL;
1051
1052 if (hmenu != popup)
1053 return E_FAIL;
1054
1055 hr = UpdateFocus();
1057 return hr;
1058
1059 return S_OK;
1060}
static HMENU hmenu
Definition: win.c:66

Referenced by CMenuBand::_TrackContextMenu(), and CMenuBand::_TrackSubMenu().

◆ ProcessMouseDown()

LRESULT CMenuFocusManager::ProcessMouseDown ( MSG msg,
BOOL  isLButton 
)
private

Definition at line 416 of file CMenuFocusManager.cpp.

417{
418 HWND child;
419 int iHitTestResult = -1;
420
421 TRACE("ProcessMouseDown %d %d %d\n", msg->message, msg->wParam, msg->lParam);
422
423 // Don't do anything if another window is capturing the mouse.
424 HWND cCapture = ::GetCapture();
425 if (cCapture && cCapture != m_captureHwnd && m_current->type != TrackedMenuEntry)
426 {
427 TRACE("Foreign capture active.\n");
428 return TRUE;
429 }
430
431 POINT pt = msg->pt;
432
434
435 StackEntry * entry = NULL;
437 {
438 TRACE("Foreign window detected.\n");
439 return TRUE;
440 }
441
442 if (entry->type == MenuBarEntry)
443 {
444 if (entry != m_current)
445 {
446 TRACE("Menubar with popup active.\n");
447 return TRUE;
448 }
449 }
450
451 if (entry)
452 {
454 iHitTestResult = SendMessageW(child, TB_HITTEST, 0, (LPARAM) &pt);
455
456 if (iHitTestResult >= 0)
457 {
458 TRACE("MouseDown send %d\n", iHitTestResult);
459 entry->mb->_MenuBarMouseDown(child, iHitTestResult, isLButton);
460 }
461 }
462
463 msg->message = WM_NULL;
464
467
468 TRACE("MouseDown end\n");
469
470 return TRUE;
471}
HRESULT IsTrackedWindow(HWND hWnd, StackEntry **pentry=NULL)
#define TB_HITTEST
Definition: commctrl.h:1268
LONG_PTR LPARAM
Definition: windef.h:208
HWND WINAPI GetCapture(void)
Definition: message.c:2881
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
BOOL WINAPI ScreenToClient(_In_ HWND, _Inout_ LPPOINT)

Referenced by GetMsgHook().

◆ ProcessMouseMove()

LRESULT CMenuFocusManager::ProcessMouseMove ( MSG msg)
private

Definition at line 317 of file CMenuFocusManager.cpp.

318{
319 HWND child;
320 int iHitTestResult = -1;
321
322 POINT pt2 = { GET_X_LPARAM(msg->lParam), GET_Y_LPARAM(msg->lParam) };
323 ClientToScreen(msg->hwnd, &pt2);
324
325 POINT pt = msg->pt;
326
327 // Don't do anything if another window is capturing the mouse.
328 HWND cCapture = ::GetCapture();
329 if (cCapture && cCapture != m_captureHwnd && m_current->type != TrackedMenuEntry)
330 return TRUE;
331
333
334 m_ptPrev = pt;
335
337
338 StackEntry * entry = NULL;
340 {
341 TRACE("MouseMove\n");
342 }
343
344 BOOL isTracking = FALSE;
345 if (entry && (entry->type == MenuBarEntry || m_current->type != TrackedMenuEntry))
346 {
348 iHitTestResult = SendMessageW(child, TB_HITTEST, 0, (LPARAM) &pt);
349 isTracking = entry->mb->_IsTracking();
350
351 if (iHitTestResult < -1)
352 {
353 // TB_HITTEST would return negative numbers for separators
354 iHitTestResult = -iHitTestResult;
355 }
356 else if (iHitTestResult == -1)
357 {
358 // TB_HITTEST would return -1 in two cases:
359 // 1. the mouse is outside the toolbar;
360 // 2. the mouse is over the first item, and that item is a separator.
361 // Confirm the second scenario by checking first item's rect.
362 RECT rc;
364 if (PtInRect(&rc, pt))
365 iHitTestResult = 1;
366 }
367
368 if (SendMessage(child, WM_USER_ISTRACKEDITEM, iHitTestResult, 0) == S_FALSE)
369 {
370 // The current tracked item has changed, notify the toolbar
371
372 TRACE("Hot item tracking detected a change (capture=%p / cCapture=%p)...\n", m_captureHwnd, cCapture);
374 if (isTracking && iHitTestResult >= 0 && m_current->type == TrackedMenuEntry)
375 SendMessage(entry->hwnd, WM_CANCELMODE, 0, 0);
376 PostMessage(child, WM_USER_CHANGETRACKEDITEM, iHitTestResult, MAKELPARAM(isTracking, TRUE));
378 return FALSE;
379 }
380 }
381
383 {
384 // Mouse moved away from a tracked window
386 {
388 }
389 }
390
391 if (m_hwndUnderMouse != child)
392 {
393 if (entry)
394 {
395 // Mouse moved to a tracked window
397 {
398 ScreenToClient(child, &pt2);
399 SendMessage(child, WM_MOUSEMOVE, msg->wParam, MAKELPARAM(pt2.x, pt2.y));
400 }
401 }
402
405 }
406
408 {
411 }
412
413 return TRUE;
414}
#define WM_USER_CHANGETRACKEDITEM
Definition: CMenuToolbars.h:26
#define WM_USER_ISTRACKEDITEM
Definition: CMenuToolbars.h:25
HRESULT _ChangeHotItem(CMenuToolbarBase *tb, INT id, DWORD dwFlags)
Definition: CMenuBand.cpp:891
#define HICF_MOUSE
Definition: commctrl.h:1326
#define TB_GETITEMRECT
Definition: commctrl.h:1133
#define GET_Y_LPARAM(lp)
Definition: windowsx.h:300
#define GA_ROOT
Definition: winuser.h:2865
#define MAKELPARAM(l, h)
Definition: winuser.h:4084
#define WM_CANCELMODE
Definition: winuser.h:1654
BOOL WINAPI ClientToScreen(_In_ HWND, _Inout_ LPPOINT)
BOOL WINAPI PtInRect(_In_ LPCRECT, _In_ POINT)
#define SendMessage
Definition: winuser.h:5928
#define PostMessage
Definition: winuser.h:5917
HWND WINAPI GetAncestor(_In_ HWND, _In_ UINT)
Definition: window.c:929

Referenced by GetMsgHook(), and MsgFilterHook().

◆ ProcessMouseUp()

LRESULT CMenuFocusManager::ProcessMouseUp ( MSG msg,
BOOL  isLButton 
)
private

Definition at line 473 of file CMenuFocusManager.cpp.

474{
475 HWND child;
476 int iHitTestResult = -1;
477
478 TRACE("ProcessMouseUp %d %d %d\n", msg->message, msg->wParam, msg->lParam);
479
480 // Don't do anything if another window is capturing the mouse.
481 HWND cCapture = ::GetCapture();
482 if (cCapture && cCapture != m_captureHwnd && m_current->type != TrackedMenuEntry)
483 return TRUE;
484
485 POINT pt = msg->pt;
486
488
489 StackEntry * entry = NULL;
491 return TRUE;
492
493 if (entry)
494 {
496 iHitTestResult = SendMessageW(child, TB_HITTEST, 0, (LPARAM) &pt);
497
498 if (iHitTestResult >= 0)
499 {
500 TRACE("MouseUp send %d\n", iHitTestResult);
501 entry->mb->_MenuBarMouseUp(child, iHitTestResult, isLButton);
502 }
503 }
504
505 return TRUE;
506}

Referenced by GetMsgHook().

◆ PushMenuBar()

HRESULT CMenuFocusManager::PushMenuBar ( CMenuBand mb)

Definition at line 879 of file CMenuFocusManager.cpp.

880{
881 TRACE("PushMenuBar %p\n", mb);
882
883 mb->AddRef();
884
885 _ASSERT(m_bandCount == 0);
886
889 return hr;
890
891 return UpdateFocus();
892}
HRESULT PushToArray(StackEntryType type, CMenuBand *mb, HMENU hmenu)
ULONG AddRef()

Referenced by CMenuBand::ShowDW().

◆ PushMenuPopup()

HRESULT CMenuFocusManager::PushMenuPopup ( CMenuBand mb)

Definition at line 895 of file CMenuFocusManager.cpp.

896{
897 TRACE("PushTrackedPopup %p\n", mb);
898
899 mb->AddRef();
900
902
905 return hr;
906
907 hr = UpdateFocus();
908
909 m_menuDepth++;
910
912 {
915 }
916
917 return hr;
918}
HRESULT _SetParentBand(CMenuBand *parent)
Definition: CMenuBand.cpp:616

Referenced by CMenuBand::ShowDW().

◆ PushToArray()

HRESULT CMenuFocusManager::PushToArray ( StackEntryType  type,
CMenuBand mb,
HMENU  hmenu 
)
private

Definition at line 139 of file CMenuFocusManager.cpp.

140{
142 return E_OUTOFMEMORY;
143
147 m_bandCount++;
148
149 return S_OK;
150}
#define MAX_RECURSE
#define E_OUTOFMEMORY
Definition: ddrawi.h:100

Referenced by PushMenuBar(), PushMenuPopup(), and PushTrackedPopup().

◆ PushTrackedPopup()

HRESULT CMenuFocusManager::PushTrackedPopup ( HMENU  popup)

Definition at line 921 of file CMenuFocusManager.cpp.

922{
923 TRACE("PushTrackedPopup %p\n", popup);
924
925 _ASSERT(m_bandCount > 0);
927
930 return hr;
931
932 TRACE("PushTrackedPopup %p\n", popup);
933 m_selectedMenu = popup;
934 m_selectedItem = -1;
936
937 return UpdateFocus();
938}

Referenced by CMenuBand::_TrackContextMenu(), and CMenuBand::_TrackSubMenu().

◆ ReleaseManager()

void CMenuFocusManager::ReleaseManager ( CMenuFocusManager obj)
static

Definition at line 121 of file CMenuFocusManager.cpp.

122{
123 if (!obj->Release())
124 {
126 }
127}

Referenced by CMenuBand::~CMenuBand().

◆ RemoveHooks()

HRESULT CMenuFocusManager::RemoveHooks ( )
private

Definition at line 712 of file CMenuFocusManager.cpp.

713{
715 {
716 TRACE("Removing MSGFILTER hook...\n");
719 }
720 if (m_hGetMsgHook)
721 {
722 TRACE("Removing GETMESSAGE hook...\n");
725 }
726 return S_OK;
727}
BOOL WINAPI UnhookWindowsHookEx(_In_ HHOOK)

Referenced by UpdateFocus().

◆ s_GetMsgHook()

LRESULT CALLBACK CMenuFocusManager::s_GetMsgHook ( INT  nCode,
WPARAM  wParam,
LPARAM  lParam 
)
staticprivate

Definition at line 134 of file CMenuFocusManager.cpp.

135{
136 return GetManager()->GetMsgHook(nCode, wParam, lParam);
137}
LRESULT GetMsgHook(INT nCode, WPARAM wParam, LPARAM lParam)
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139

Referenced by PlaceHooks().

◆ s_MsgFilterHook()

LRESULT CALLBACK CMenuFocusManager::s_MsgFilterHook ( INT  nCode,
WPARAM  wParam,
LPARAM  lParam 
)
staticprivate

Definition at line 129 of file CMenuFocusManager.cpp.

130{
131 return GetManager()->MsgFilterHook(nCode, wParam, lParam);
132}
LRESULT MsgFilterHook(INT nCode, WPARAM wParam, LPARAM lParam)

Referenced by PlaceHooks().

◆ SetMenuCapture()

void CMenuFocusManager::SetMenuCapture ( HWND  child)
private

Definition at line 237 of file CMenuFocusManager.cpp.

238{
239 if (m_captureHwnd != child)
240 {
241 if (child)
242 {
245 TRACE("Capturing %p\n", child);
246 }
247 else
248 {
251 TRACE("Capture is now off\n");
252 }
253
254 }
255}
HWND WINAPI SetCapture(_In_ HWND hWnd)
BOOL WINAPI ReleaseCapture(void)
Definition: message.c:2890

Referenced by UpdateFocus().

◆ UpdateFocus()

HRESULT CMenuFocusManager::UpdateFocus ( )
private

Definition at line 730 of file CMenuFocusManager.cpp.

731{
732 HRESULT hr;
733 StackEntry * old = m_current;
734
735 TRACE("UpdateFocus\n");
736
737 // Assign the new current item
738 if (m_bandCount > 0)
740 else
741 m_current = NULL;
742
743 // Remove the menu capture if necesary
745 {
747 if (old && old->type == MenuPopupEntry && m_PreviousForeground)
748 {
751 }
752 }
753
754 // Obtain the top-level window for the new active menu
756 {
759 return hr;
760 }
761
762 // Refresh the parent pointer
763 if (m_bandCount >= 2)
764 {
767 }
768 else
769 {
770 m_parent = NULL;
771 }
772
773 // Refresh the menubar pointer, if applicable
774 if (m_bandCount >= 1 && m_bandStack[0].type == MenuBarEntry)
775 {
776 m_menuBar = &(m_bandStack[0]);
777 }
778 else
779 {
780 m_menuBar = NULL;
781 }
782
783 // Remove the old hooks if the menu type changed, or we don't have a menu anymore
784 if (old && (!m_current || old->type != m_current->type))
785 {
787 {
789 }
790
791 hr = RemoveHooks();
793 return hr;
794 }
795
796 // And place new ones if necessary
797 if (m_current && (!old || old->type != m_current->type))
798 {
799 hr = PlaceHooks();
801 return hr;
802 }
803
804 // Give the user a chance to move the mouse to the new menu
805 if (m_parent)
806 {
808 }
809
811 {
812 if (m_captureHwnd == NULL)
813 {
814 // We need to restore the capture after a non-shell submenu or context menu is shown
815 StackEntry * topMenu = m_bandStack;
816 if (topMenu->type == MenuBarEntry)
817 topMenu++;
818
819 // Get the top-level window from the top popup
820 CComPtr<IServiceProvider> bandSite;
821 CComPtr<IOleWindow> deskBar;
822 hr = topMenu->mb->GetSite(IID_PPV_ARG(IServiceProvider, &bandSite));
823 if (FAILED(hr))
824 goto NoCapture;
825 hr = bandSite->QueryService(SID_SMenuPopup, IID_PPV_ARG(IOleWindow, &deskBar));
826 if (FAILED(hr))
827 goto NoCapture;
828
829 CComPtr<IOleWindow> deskBarSite;
830 hr = IUnknown_GetSite(deskBar, IID_PPV_ARG(IOleWindow, &deskBarSite));
831 if (FAILED(hr))
832 goto NoCapture;
833
834 // FIXME: Find the correct place for this
835 HWND hWndOwner;
836 hr = deskBarSite->GetWindow(&hWndOwner);
837 if (FAILED(hr))
838 goto NoCapture;
839
841 if (m_PreviousForeground != hWndOwner)
842 ::SetForegroundWindow(hWndOwner);
843 else
845
846 // Get the HWND of the top-level window
847 HWND hWndSite;
848 hr = deskBar->GetWindow(&hWndSite);
849 if (FAILED(hr))
850 goto NoCapture;
851 SetMenuCapture(hWndSite);
852 }
853NoCapture:
854
856 {
857 if (old && old->type == TrackedMenuEntry)
858 {
859 // FIXME: Debugging code, probably not right
860 POINT pt2;
861 RECT rc2;
862 GetCursorPos(&pt2);
865 if (PtInRect(&rc2, pt2))
867 else
869 }
870 }
871 }
872
874
875 return S_OK;
876}
HRESULT _GetTopLevelWindow(HWND *topLevel)
Definition: CMenuBand.cpp:885
void SetMenuCapture(HWND child)
static const WCHAR rc2[]
Definition: oid.c:1216
HRESULT WINAPI IUnknown_GetSite(LPUNKNOWN lpUnknown, REFIID iid, PVOID *lppSite)
Definition: ordinal.c:2642
#define FAILED(hr)
Definition: intsafe.h:51
HWND WINAPI GetForegroundWindow(void)
Definition: ntwrapper.h:392
BOOL WINAPI SetForegroundWindow(_In_ HWND)
BOOL WINAPI GetCursorPos(_Out_ LPPOINT)
Definition: cursoricon.c:3032
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)

Referenced by PopMenuBar(), PopMenuPopup(), PopTrackedPopup(), PushMenuBar(), PushMenuPopup(), and PushTrackedPopup().

Member Data Documentation

◆ m_bandCount

int CMenuFocusManager::m_bandCount
private

◆ m_bandStack

StackEntry CMenuFocusManager::m_bandStack[MAX_RECURSE]
private

◆ m_captureHwnd

HWND CMenuFocusManager::m_captureHwnd
private

◆ m_current

◆ m_entryUnderMouse

StackEntry* CMenuFocusManager::m_entryUnderMouse
private

Definition at line 74 of file CMenuFocusManager.h.

Referenced by PopMenuBar(), PopMenuPopup(), and ProcessMouseMove().

◆ m_hGetMsgHook

HHOOK CMenuFocusManager::m_hGetMsgHook
private

Definition at line 64 of file CMenuFocusManager.h.

Referenced by GetMsgHook(), PlaceHooks(), and RemoveHooks().

◆ m_hMsgFilterHook

HHOOK CMenuFocusManager::m_hMsgFilterHook
private

Definition at line 63 of file CMenuFocusManager.h.

Referenced by MsgFilterHook(), PlaceHooks(), and RemoveHooks().

◆ m_hwndUnderMouse

HWND CMenuFocusManager::m_hwndUnderMouse
private

Definition at line 73 of file CMenuFocusManager.h.

Referenced by ProcessMouseMove().

◆ m_menuBar

StackEntry* CMenuFocusManager::m_menuBar
private

Definition at line 61 of file CMenuFocusManager.h.

Referenced by GetMsgHook(), MsgFilterHook(), and UpdateFocus().

◆ m_menuDepth

int CMenuFocusManager::m_menuDepth
private

Definition at line 89 of file CMenuFocusManager.h.

Referenced by PopMenuPopup(), and PushMenuPopup().

◆ m_mouseTrackDisabled

BOOL CMenuFocusManager::m_mouseTrackDisabled
private

Definition at line 67 of file CMenuFocusManager.h.

Referenced by DisableMouseTrack().

◆ m_movedSinceDown

BOOL CMenuFocusManager::m_movedSinceDown
private

Definition at line 80 of file CMenuFocusManager.h.

Referenced by ProcessMouseDown(), and ProcessMouseMove().

◆ m_parent

StackEntry* CMenuFocusManager::m_parent
private

Definition at line 60 of file CMenuFocusManager.h.

Referenced by MsgFilterHook(), PushMenuPopup(), and UpdateFocus().

◆ m_PreviousForeground

HWND CMenuFocusManager::m_PreviousForeground
private

Definition at line 83 of file CMenuFocusManager.h.

Referenced by UpdateFocus().

◆ m_ptPrev

POINT CMenuFocusManager::m_ptPrev
private

Definition at line 69 of file CMenuFocusManager.h.

Referenced by CMenuFocusManager(), and ProcessMouseMove().

◆ m_selectedItem

INT CMenuFocusManager::m_selectedItem
private

Definition at line 77 of file CMenuFocusManager.h.

Referenced by MsgFilterHook(), and PushTrackedPopup().

◆ m_selectedItemFlags

DWORD CMenuFocusManager::m_selectedItemFlags
private

Definition at line 78 of file CMenuFocusManager.h.

Referenced by MsgFilterHook(), and PushTrackedPopup().

◆ m_selectedMenu

HMENU CMenuFocusManager::m_selectedMenu
private

Definition at line 76 of file CMenuFocusManager.h.

Referenced by MsgFilterHook(), and PushTrackedPopup().

◆ m_threadId

DWORD CMenuFocusManager::m_threadId
private

Definition at line 65 of file CMenuFocusManager.h.

Referenced by CMenuFocusManager(), and PlaceHooks().

◆ m_windowAtDown

HWND CMenuFocusManager::m_windowAtDown
private

Definition at line 81 of file CMenuFocusManager.h.

Referenced by ProcessMouseDown().

◆ TlsIndex

DWORD CMenuFocusManager::TlsIndex = 0
staticprivate

Definition at line 29 of file CMenuFocusManager.h.

Referenced by AcquireManager(), GetManager(), and ReleaseManager().


The documentation for this class was generated from the following files: