2014-02-24 11:59:34 +00:00
|
|
|
/*
|
|
|
|
* Shell Menu Band
|
|
|
|
*
|
|
|
|
* Copyright 2014 David Quintana
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
2015-02-02 22:06:59 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
This file implements the CMenuFocusManager class.
|
|
|
|
|
|
|
|
This class manages the shell menus, by overriding the hot-tracking behaviour.
|
|
|
|
|
|
|
|
For the shell menus, it uses a GetMessage hook,
|
|
|
|
where it intercepts messages directed to the menu windows.
|
|
|
|
|
|
|
|
In order to show submenus using system popups, it also has a MessageFilter hook.
|
|
|
|
|
|
|
|
The menu is tracked using a stack structure. When a CMenuBand wants to open a submenu,
|
|
|
|
it pushes the submenu band, or HMENU to track in case of system popups,
|
|
|
|
and when the menu has closed, it pops the same pointer or handle.
|
|
|
|
|
|
|
|
While a shell menu is open, it overrides the menu toolbar's hottracking behaviour,
|
|
|
|
using its own logic to track both the active menu item, and the opened submenu's parent item.
|
|
|
|
|
|
|
|
While a system popup is open, it tracks the mouse movements so that it can cancel the popup,
|
|
|
|
and switch to another submenu when the mouse goes over another item from the parent.
|
|
|
|
|
|
|
|
*/
|
2015-08-19 09:05:54 +00:00
|
|
|
#include "shellmenu.h"
|
2014-02-24 11:59:34 +00:00
|
|
|
#include <windowsx.h>
|
2014-03-20 15:39:25 +00:00
|
|
|
#include <commoncontrols.h>
|
2014-02-24 11:59:34 +00:00
|
|
|
#include <shlwapi_undoc.h>
|
|
|
|
|
|
|
|
#include "CMenuFocusManager.h"
|
2014-03-19 15:33:41 +00:00
|
|
|
#include "CMenuToolbars.h"
|
2014-02-24 11:59:34 +00:00
|
|
|
#include "CMenuBand.h"
|
|
|
|
|
2014-04-09 11:45:02 +00:00
|
|
|
#if DBG
|
|
|
|
# undef _ASSERT
|
|
|
|
# define _ASSERT(x) DbgAssert(!!(x), __FILE__, __LINE__, #x)
|
2014-03-26 11:33:52 +00:00
|
|
|
|
|
|
|
bool DbgAssert(bool x, const char * filename, int line, const char * expr)
|
|
|
|
{
|
|
|
|
if (!x)
|
|
|
|
{
|
|
|
|
char szMsg[512];
|
|
|
|
const char *fname;
|
|
|
|
|
|
|
|
fname = strrchr(filename, '\\');
|
|
|
|
if (fname == NULL)
|
|
|
|
{
|
|
|
|
fname = strrchr(filename, '/');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fname == NULL)
|
|
|
|
fname = filename;
|
|
|
|
else
|
|
|
|
fname++;
|
|
|
|
|
|
|
|
sprintf(szMsg, "%s:%d: Assertion failed: %s\n", fname, line, expr);
|
|
|
|
|
|
|
|
OutputDebugStringA(szMsg);
|
|
|
|
|
|
|
|
__debugbreak();
|
|
|
|
}
|
|
|
|
return x;
|
|
|
|
}
|
2014-04-09 11:45:02 +00:00
|
|
|
#else
|
|
|
|
# undef _ASSERT
|
|
|
|
# define _ASSERT(x) (!!(x))
|
|
|
|
#endif
|
2014-03-26 11:33:52 +00:00
|
|
|
|
2014-02-24 11:59:34 +00:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(CMenuFocus);
|
|
|
|
|
|
|
|
DWORD CMenuFocusManager::TlsIndex = 0;
|
|
|
|
|
2015-02-02 22:06:59 +00:00
|
|
|
// Gets the thread's assigned manager without refcounting
|
2014-02-24 11:59:34 +00:00
|
|
|
CMenuFocusManager * CMenuFocusManager::GetManager()
|
|
|
|
{
|
|
|
|
return reinterpret_cast<CMenuFocusManager *>(TlsGetValue(TlsIndex));
|
|
|
|
}
|
|
|
|
|
2015-02-02 22:06:59 +00:00
|
|
|
// Obtains a manager for the thread, with refcounting
|
2014-02-24 11:59:34 +00:00
|
|
|
CMenuFocusManager * CMenuFocusManager::AcquireManager()
|
|
|
|
{
|
|
|
|
CMenuFocusManager * obj = NULL;
|
|
|
|
|
|
|
|
if (!TlsIndex)
|
|
|
|
{
|
|
|
|
if ((TlsIndex = TlsAlloc()) == TLS_OUT_OF_INDEXES)
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
obj = GetManager();
|
|
|
|
|
|
|
|
if (!obj)
|
|
|
|
{
|
|
|
|
obj = new CComObject<CMenuFocusManager>();
|
|
|
|
TlsSetValue(TlsIndex, obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
obj->AddRef();
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2015-02-02 22:06:59 +00:00
|
|
|
// Releases a previously acquired manager, and deletes it if the refcount reaches 0
|
2014-02-24 11:59:34 +00:00
|
|
|
void CMenuFocusManager::ReleaseManager(CMenuFocusManager * obj)
|
|
|
|
{
|
|
|
|
if (!obj->Release())
|
|
|
|
{
|
|
|
|
TlsSetValue(TlsIndex, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-19 15:33:41 +00:00
|
|
|
LRESULT CALLBACK CMenuFocusManager::s_MsgFilterHook(INT nCode, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
return GetManager()->MsgFilterHook(nCode, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
2014-02-24 11:59:34 +00:00
|
|
|
LRESULT CALLBACK CMenuFocusManager::s_GetMsgHook(INT nCode, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
return GetManager()->GetMsgHook(nCode, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
2014-03-26 11:33:52 +00:00
|
|
|
HRESULT CMenuFocusManager::PushToArray(StackEntryType type, CMenuBand * mb, HMENU hmenu)
|
2014-02-24 11:59:34 +00:00
|
|
|
{
|
|
|
|
if (m_bandCount >= MAX_RECURSE)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2014-03-26 11:33:52 +00:00
|
|
|
m_bandStack[m_bandCount].type = type;
|
|
|
|
m_bandStack[m_bandCount].mb = mb;
|
|
|
|
m_bandStack[m_bandCount].hmenu = hmenu;
|
|
|
|
m_bandCount++;
|
2014-02-24 11:59:34 +00:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2014-03-26 11:33:52 +00:00
|
|
|
HRESULT CMenuFocusManager::PopFromArray(StackEntryType * pType, CMenuBand ** pMb, HMENU * pHmenu)
|
2014-02-24 11:59:34 +00:00
|
|
|
{
|
2014-03-26 11:33:52 +00:00
|
|
|
if (pType) *pType = NoEntry;
|
|
|
|
if (pMb) *pMb = NULL;
|
|
|
|
if (pHmenu) *pHmenu = NULL;
|
2014-02-24 11:59:34 +00:00
|
|
|
|
|
|
|
if (m_bandCount <= 0)
|
2014-03-16 09:28:51 +00:00
|
|
|
return S_FALSE;
|
2014-02-24 11:59:34 +00:00
|
|
|
|
2014-03-26 11:33:52 +00:00
|
|
|
m_bandCount--;
|
2014-02-24 11:59:34 +00:00
|
|
|
|
2014-03-26 11:33:52 +00:00
|
|
|
if (pType) *pType = m_bandStack[m_bandCount].type;
|
|
|
|
if (*pType == TrackedMenuEntry)
|
|
|
|
{
|
|
|
|
if (pHmenu) *pHmenu = m_bandStack[m_bandCount].hmenu;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (pMb) *pMb = m_bandStack[m_bandCount].mb;
|
|
|
|
}
|
|
|
|
|
2014-02-24 11:59:34 +00:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
CMenuFocusManager::CMenuFocusManager() :
|
2014-03-26 11:33:52 +00:00
|
|
|
m_current(NULL),
|
|
|
|
m_parent(NULL),
|
2014-03-19 15:33:41 +00:00
|
|
|
m_hMsgFilterHook(NULL),
|
|
|
|
m_hGetMsgHook(NULL),
|
2014-03-15 21:38:15 +00:00
|
|
|
m_mouseTrackDisabled(FALSE),
|
2014-03-26 11:33:52 +00:00
|
|
|
m_captureHwnd(0),
|
2014-04-03 18:30:25 +00:00
|
|
|
m_hwndUnderMouse(NULL),
|
|
|
|
m_entryUnderMouse(NULL),
|
2014-04-15 22:30:37 +00:00
|
|
|
m_selectedMenu(NULL),
|
|
|
|
m_selectedItem(0),
|
|
|
|
m_selectedItemFlags(0),
|
2014-06-29 15:42:06 +00:00
|
|
|
m_movedSinceDown(FALSE),
|
|
|
|
m_windowAtDown(NULL),
|
2014-12-20 17:45:45 +00:00
|
|
|
m_PreviousForeground(NULL),
|
2014-12-18 17:34:46 +00:00
|
|
|
m_bandCount(0),
|
|
|
|
m_menuDepth(0)
|
2014-02-24 11:59:34 +00:00
|
|
|
{
|
2014-03-26 11:33:52 +00:00
|
|
|
m_ptPrev.x = 0;
|
|
|
|
m_ptPrev.y = 0;
|
2014-02-24 11:59:34 +00:00
|
|
|
m_threadId = GetCurrentThreadId();
|
|
|
|
}
|
|
|
|
|
|
|
|
CMenuFocusManager::~CMenuFocusManager()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-02-02 22:06:59 +00:00
|
|
|
// Used so that the toolbar can properly ignore mouse events, when the menu is being used with the keyboard
|
2014-03-26 11:33:52 +00:00
|
|
|
void CMenuFocusManager::DisableMouseTrack(HWND parent, BOOL disableThis)
|
2014-03-15 21:38:15 +00:00
|
|
|
{
|
|
|
|
BOOL bDisable = FALSE;
|
2014-03-26 11:33:52 +00:00
|
|
|
BOOL lastDisable = FALSE;
|
2014-03-15 21:38:15 +00:00
|
|
|
|
|
|
|
int i = m_bandCount;
|
|
|
|
while (--i >= 0)
|
|
|
|
{
|
2014-03-26 11:33:52 +00:00
|
|
|
StackEntry& entry = m_bandStack[i];
|
2014-03-15 21:38:15 +00:00
|
|
|
|
2014-04-02 17:37:37 +00:00
|
|
|
if (entry.type != TrackedMenuEntry)
|
2014-03-15 21:38:15 +00:00
|
|
|
{
|
2014-03-26 11:33:52 +00:00
|
|
|
HWND hwnd;
|
|
|
|
HRESULT hr = entry.mb->_GetTopLevelWindow(&hwnd);
|
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (hwnd == parent)
|
|
|
|
{
|
|
|
|
lastDisable = disableThis;
|
|
|
|
entry.mb->_DisableMouseTrack(disableThis);
|
|
|
|
bDisable = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
lastDisable = bDisable;
|
|
|
|
entry.mb->_DisableMouseTrack(bDisable);
|
|
|
|
}
|
2014-03-15 21:38:15 +00:00
|
|
|
}
|
|
|
|
}
|
2014-03-26 11:33:52 +00:00
|
|
|
m_mouseTrackDisabled = lastDisable;
|
|
|
|
}
|
2014-03-15 21:38:15 +00:00
|
|
|
|
2014-12-18 17:34:46 +00:00
|
|
|
void CMenuFocusManager::SetMenuCapture(HWND child)
|
2014-03-26 11:33:52 +00:00
|
|
|
{
|
|
|
|
if (m_captureHwnd != child)
|
2014-03-15 21:38:15 +00:00
|
|
|
{
|
2014-03-26 11:33:52 +00:00
|
|
|
if (child)
|
2014-03-15 21:38:15 +00:00
|
|
|
{
|
2014-03-26 11:33:52 +00:00
|
|
|
::SetCapture(child);
|
|
|
|
m_captureHwnd = child;
|
2014-12-18 17:34:46 +00:00
|
|
|
TRACE("Capturing %p\n", child);
|
2014-03-15 21:38:15 +00:00
|
|
|
}
|
|
|
|
else
|
2014-03-26 11:33:52 +00:00
|
|
|
{
|
|
|
|
::ReleaseCapture();
|
|
|
|
m_captureHwnd = NULL;
|
2014-12-18 17:34:46 +00:00
|
|
|
TRACE("Capture is now off\n");
|
2014-03-26 11:33:52 +00:00
|
|
|
}
|
2014-03-15 21:38:15 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-02 17:37:37 +00:00
|
|
|
HRESULT CMenuFocusManager::IsTrackedWindow(HWND hWnd, StackEntry ** pentry)
|
2014-03-15 21:38:15 +00:00
|
|
|
{
|
2014-04-02 17:37:37 +00:00
|
|
|
if (pentry)
|
|
|
|
*pentry = NULL;
|
|
|
|
|
|
|
|
for (int i = m_bandCount; --i >= 0;)
|
2014-03-15 21:38:15 +00:00
|
|
|
{
|
2014-03-26 11:33:52 +00:00
|
|
|
StackEntry& entry = m_bandStack[i];
|
2014-03-15 21:38:15 +00:00
|
|
|
|
2014-04-02 17:37:37 +00:00
|
|
|
if (entry.type != TrackedMenuEntry)
|
2014-03-21 10:13:18 +00:00
|
|
|
{
|
2014-03-26 11:33:52 +00:00
|
|
|
HRESULT hr = entry.mb->IsWindowOwner(hWnd);
|
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
|
|
|
return hr;
|
|
|
|
if (hr == S_OK)
|
2014-04-02 17:37:37 +00:00
|
|
|
{
|
|
|
|
if (pentry)
|
|
|
|
*pentry = &entry;
|
2014-03-26 11:33:52 +00:00
|
|
|
return S_OK;
|
2014-04-02 17:37:37 +00:00
|
|
|
}
|
2014-03-21 10:13:18 +00:00
|
|
|
}
|
2014-03-15 21:38:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
2014-05-16 11:12:51 +00:00
|
|
|
HRESULT CMenuFocusManager::IsTrackedWindowOrParent(HWND hWnd)
|
|
|
|
{
|
|
|
|
for (int i = m_bandCount; --i >= 0;)
|
|
|
|
{
|
|
|
|
StackEntry& entry = m_bandStack[i];
|
|
|
|
|
|
|
|
if (entry.type != TrackedMenuEntry)
|
|
|
|
{
|
|
|
|
HRESULT hr = entry.mb->IsWindowOwner(hWnd);
|
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
|
|
|
return hr;
|
|
|
|
if (hr == S_OK)
|
|
|
|
return S_OK;
|
|
|
|
if (entry.mb->_IsPopup() == S_OK)
|
|
|
|
{
|
|
|
|
CComPtr<IUnknown> site;
|
|
|
|
CComPtr<IOleWindow> pw;
|
|
|
|
hr = entry.mb->GetSite(IID_PPV_ARG(IUnknown, &site));
|
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
|
|
|
continue;
|
|
|
|
hr = IUnknown_QueryService(site, SID_SMenuBandParent, IID_PPV_ARG(IOleWindow, &pw));
|
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
HWND hParent;
|
|
|
|
if (pw->GetWindow(&hParent) == S_OK && hParent == hWnd)
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
2014-03-20 15:39:25 +00:00
|
|
|
LRESULT CMenuFocusManager::ProcessMouseMove(MSG* msg)
|
2014-03-19 15:33:41 +00:00
|
|
|
{
|
|
|
|
HWND child;
|
2014-04-09 11:45:02 +00:00
|
|
|
int iHitTestResult = -1;
|
2014-03-19 15:33:41 +00:00
|
|
|
|
2014-04-02 17:37:37 +00:00
|
|
|
POINT pt2 = { GET_X_LPARAM(msg->lParam), GET_Y_LPARAM(msg->lParam) };
|
|
|
|
ClientToScreen(msg->hwnd, &pt2);
|
2014-03-19 15:33:41 +00:00
|
|
|
|
2014-04-02 17:37:37 +00:00
|
|
|
POINT pt = msg->pt;
|
2014-03-19 15:33:41 +00:00
|
|
|
|
2014-04-07 10:12:41 +00:00
|
|
|
// Don't do anything if another window is capturing the mouse.
|
|
|
|
HWND cCapture = ::GetCapture();
|
2014-04-07 18:41:47 +00:00
|
|
|
if (cCapture && cCapture != m_captureHwnd && m_current->type != TrackedMenuEntry)
|
2014-04-07 10:12:41 +00:00
|
|
|
return TRUE;
|
|
|
|
|
2014-06-29 15:42:06 +00:00
|
|
|
m_movedSinceDown = TRUE;
|
|
|
|
|
2014-04-02 17:37:37 +00:00
|
|
|
m_ptPrev = pt;
|
|
|
|
|
|
|
|
child = WindowFromPoint(pt);
|
2014-03-19 15:33:41 +00:00
|
|
|
|
2014-04-03 18:30:25 +00:00
|
|
|
StackEntry * entry = NULL;
|
2014-06-29 15:42:06 +00:00
|
|
|
if (IsTrackedWindow(child, &entry) == S_OK)
|
|
|
|
{
|
2016-08-20 22:05:12 +00:00
|
|
|
TRACE("MouseMove");
|
2014-06-29 15:42:06 +00:00
|
|
|
}
|
2014-04-03 18:30:25 +00:00
|
|
|
|
2014-04-09 11:45:02 +00:00
|
|
|
BOOL isTracking = FALSE;
|
2014-07-09 00:42:05 +00:00
|
|
|
if (entry && (entry->type == MenuBarEntry || m_current->type != TrackedMenuEntry))
|
2014-03-20 15:39:25 +00:00
|
|
|
{
|
2014-04-02 17:37:37 +00:00
|
|
|
ScreenToClient(child, &pt);
|
|
|
|
iHitTestResult = SendMessageW(child, TB_HITTEST, 0, (LPARAM) &pt);
|
2014-04-09 11:45:02 +00:00
|
|
|
isTracking = entry->mb->_IsTracking();
|
2014-04-02 17:37:37 +00:00
|
|
|
|
2014-04-09 11:45:02 +00:00
|
|
|
if (SendMessage(child, WM_USER_ISTRACKEDITEM, iHitTestResult, 0) == S_FALSE)
|
2014-03-20 15:39:25 +00:00
|
|
|
{
|
2015-02-02 22:06:59 +00:00
|
|
|
// The current tracked item has changed, notify the toolbar
|
|
|
|
|
2014-05-18 14:20:27 +00:00
|
|
|
TRACE("Hot item tracking detected a change (capture=%p / cCapture=%p)...\n", m_captureHwnd, cCapture);
|
2014-04-02 17:37:37 +00:00
|
|
|
DisableMouseTrack(NULL, FALSE);
|
2014-06-29 15:42:06 +00:00
|
|
|
if (isTracking && iHitTestResult >= 0 && m_current->type == TrackedMenuEntry)
|
2014-04-02 17:37:37 +00:00
|
|
|
SendMessage(entry->hwnd, WM_CANCELMODE, 0, 0);
|
2014-04-22 17:44:19 +00:00
|
|
|
PostMessage(child, WM_USER_CHANGETRACKEDITEM, iHitTestResult, MAKELPARAM(isTracking, TRUE));
|
2014-04-07 18:41:47 +00:00
|
|
|
if (m_current->type == TrackedMenuEntry)
|
|
|
|
return FALSE;
|
2014-03-20 15:39:25 +00:00
|
|
|
}
|
2014-04-03 18:30:25 +00:00
|
|
|
}
|
2014-04-02 17:37:37 +00:00
|
|
|
|
2014-04-09 11:45:02 +00:00
|
|
|
if (m_entryUnderMouse != entry)
|
|
|
|
{
|
|
|
|
// Mouse moved away from a tracked window
|
|
|
|
if (m_entryUnderMouse)
|
|
|
|
{
|
|
|
|
m_entryUnderMouse->mb->_ChangeHotItem(NULL, -1, HICF_MOUSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-03 18:30:25 +00:00
|
|
|
if (m_hwndUnderMouse != child)
|
|
|
|
{
|
|
|
|
if (entry)
|
2014-04-02 17:37:37 +00:00
|
|
|
{
|
2014-04-09 11:45:02 +00:00
|
|
|
// Mouse moved to a tracked window
|
2014-04-03 18:30:25 +00:00
|
|
|
if (m_current->type == MenuPopupEntry)
|
|
|
|
{
|
|
|
|
ScreenToClient(child, &pt2);
|
|
|
|
SendMessage(child, WM_MOUSEMOVE, msg->wParam, MAKELPARAM(pt2.x, pt2.y));
|
|
|
|
}
|
2014-04-02 17:37:37 +00:00
|
|
|
}
|
2014-04-03 18:30:25 +00:00
|
|
|
|
|
|
|
m_hwndUnderMouse = child;
|
|
|
|
m_entryUnderMouse = entry;
|
2014-04-02 17:37:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m_current->type == MenuPopupEntry)
|
|
|
|
{
|
|
|
|
HWND parent = GetAncestor(child, GA_ROOT);
|
|
|
|
DisableMouseTrack(parent, FALSE);
|
2014-03-20 15:39:25 +00:00
|
|
|
}
|
2014-03-19 15:33:41 +00:00
|
|
|
|
2014-03-20 15:39:25 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2014-03-19 15:33:41 +00:00
|
|
|
|
2014-12-18 17:34:46 +00:00
|
|
|
LRESULT CMenuFocusManager::ProcessMouseDown(MSG* msg, BOOL isLButton)
|
2014-06-29 15:42:06 +00:00
|
|
|
{
|
|
|
|
HWND child;
|
|
|
|
int iHitTestResult = -1;
|
|
|
|
|
2014-10-08 15:25:52 +00:00
|
|
|
TRACE("ProcessMouseDown %d %d %d\n", msg->message, msg->wParam, msg->lParam);
|
|
|
|
|
2014-06-29 15:42:06 +00:00
|
|
|
// Don't do anything if another window is capturing the mouse.
|
|
|
|
HWND cCapture = ::GetCapture();
|
|
|
|
if (cCapture && cCapture != m_captureHwnd && m_current->type != TrackedMenuEntry)
|
2014-11-11 01:05:39 +00:00
|
|
|
{
|
|
|
|
TRACE("Foreign capture active.\n");
|
2014-06-29 15:42:06 +00:00
|
|
|
return TRUE;
|
2014-11-11 01:05:39 +00:00
|
|
|
}
|
2014-06-29 15:42:06 +00:00
|
|
|
|
|
|
|
POINT pt = msg->pt;
|
|
|
|
|
|
|
|
child = WindowFromPoint(pt);
|
|
|
|
|
|
|
|
StackEntry * entry = NULL;
|
|
|
|
if (IsTrackedWindow(child, &entry) != S_OK)
|
2014-11-11 01:05:39 +00:00
|
|
|
{
|
|
|
|
TRACE("Foreign window detected.\n");
|
2014-06-29 15:42:06 +00:00
|
|
|
return TRUE;
|
2014-11-11 01:05:39 +00:00
|
|
|
}
|
2014-06-29 15:42:06 +00:00
|
|
|
|
2014-11-11 01:05:39 +00:00
|
|
|
if (entry->type == MenuBarEntry)
|
|
|
|
{
|
|
|
|
if (entry != m_current)
|
|
|
|
{
|
|
|
|
TRACE("Menubar with popup active.\n");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-29 15:42:06 +00:00
|
|
|
if (entry)
|
|
|
|
{
|
|
|
|
ScreenToClient(child, &pt);
|
|
|
|
iHitTestResult = SendMessageW(child, TB_HITTEST, 0, (LPARAM) &pt);
|
|
|
|
|
|
|
|
if (iHitTestResult >= 0)
|
|
|
|
{
|
2014-07-02 14:48:21 +00:00
|
|
|
TRACE("MouseDown send %d\n", iHitTestResult);
|
2014-12-18 17:34:46 +00:00
|
|
|
entry->mb->_MenuBarMouseDown(child, iHitTestResult, isLButton);
|
2014-06-29 15:42:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
msg->message = WM_NULL;
|
|
|
|
|
|
|
|
m_movedSinceDown = FALSE;
|
|
|
|
m_windowAtDown = child;
|
|
|
|
|
2016-08-20 22:05:12 +00:00
|
|
|
TRACE("MouseDown end\n");
|
2014-06-29 15:42:06 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2016-08-20 22:05:12 +00:00
|
|
|
LRESULT CMenuFocusManager::ProcessMouseUp(MSG* msg, BOOL isLButton)
|
2014-06-29 15:42:06 +00:00
|
|
|
{
|
|
|
|
HWND child;
|
|
|
|
int iHitTestResult = -1;
|
|
|
|
|
2014-10-08 15:25:52 +00:00
|
|
|
TRACE("ProcessMouseUp %d %d %d\n", msg->message, msg->wParam, msg->lParam);
|
|
|
|
|
2014-06-29 15:42:06 +00:00
|
|
|
// Don't do anything if another window is capturing the mouse.
|
|
|
|
HWND cCapture = ::GetCapture();
|
|
|
|
if (cCapture && cCapture != m_captureHwnd && m_current->type != TrackedMenuEntry)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
POINT pt = msg->pt;
|
|
|
|
|
|
|
|
child = WindowFromPoint(pt);
|
|
|
|
|
|
|
|
StackEntry * entry = NULL;
|
|
|
|
if (IsTrackedWindow(child, &entry) != S_OK)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (entry)
|
|
|
|
{
|
|
|
|
ScreenToClient(child, &pt);
|
|
|
|
iHitTestResult = SendMessageW(child, TB_HITTEST, 0, (LPARAM) &pt);
|
|
|
|
|
|
|
|
if (iHitTestResult >= 0)
|
|
|
|
{
|
2014-07-02 14:48:21 +00:00
|
|
|
TRACE("MouseUp send %d\n", iHitTestResult);
|
2016-08-20 22:05:12 +00:00
|
|
|
entry->mb->_MenuBarMouseUp(child, iHitTestResult, isLButton);
|
2014-06-29 15:42:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-04-16 12:14:02 +00:00
|
|
|
LRESULT CMenuFocusManager::MsgFilterHook(INT nCode, WPARAM hookWParam, LPARAM hookLParam)
|
2014-03-20 15:39:25 +00:00
|
|
|
{
|
|
|
|
if (nCode < 0)
|
2014-04-16 12:14:02 +00:00
|
|
|
return CallNextHookEx(m_hMsgFilterHook, nCode, hookWParam, hookLParam);
|
2014-03-19 15:33:41 +00:00
|
|
|
|
2014-03-20 15:39:25 +00:00
|
|
|
if (nCode == MSGF_MENU)
|
|
|
|
{
|
|
|
|
BOOL callNext = TRUE;
|
2014-04-16 12:14:02 +00:00
|
|
|
MSG* msg = reinterpret_cast<MSG*>(hookLParam);
|
2014-04-02 17:37:37 +00:00
|
|
|
|
2014-03-20 15:39:25 +00:00
|
|
|
switch (msg->message)
|
|
|
|
{
|
2014-04-02 17:37:37 +00:00
|
|
|
case WM_LBUTTONDOWN:
|
2014-05-26 12:26:47 +00:00
|
|
|
case WM_RBUTTONDOWN:
|
2014-11-11 01:05:39 +00:00
|
|
|
if (m_menuBar && m_current->type == TrackedMenuEntry)
|
2014-04-02 17:37:37 +00:00
|
|
|
{
|
|
|
|
POINT pt = msg->pt;
|
|
|
|
HWND child = WindowFromPoint(pt);
|
|
|
|
BOOL hoveringMenuBar = m_menuBar->mb->IsWindowOwner(child) == S_OK;
|
|
|
|
if (hoveringMenuBar)
|
|
|
|
{
|
2014-11-11 01:05:39 +00:00
|
|
|
m_menuBar->mb->_BeforeCancelPopup();
|
2014-04-02 17:37:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2014-03-20 15:39:25 +00:00
|
|
|
case WM_MOUSEMOVE:
|
|
|
|
callNext = ProcessMouseMove(msg);
|
2014-03-19 15:33:41 +00:00
|
|
|
break;
|
2014-04-15 22:30:37 +00:00
|
|
|
case WM_INITMENUPOPUP:
|
2014-05-18 14:20:27 +00:00
|
|
|
TRACE("WM_INITMENUPOPUP %p %p\n", msg->wParam, msg->lParam);
|
2014-04-16 12:14:02 +00:00
|
|
|
m_selectedMenu = reinterpret_cast<HMENU>(msg->lParam);
|
2014-04-15 22:30:37 +00:00
|
|
|
m_selectedItem = -1;
|
|
|
|
m_selectedItemFlags = 0;
|
|
|
|
break;
|
|
|
|
case WM_MENUSELECT:
|
2014-05-18 14:20:27 +00:00
|
|
|
TRACE("WM_MENUSELECT %p %p\n", msg->wParam, msg->lParam);
|
2014-04-16 12:14:02 +00:00
|
|
|
m_selectedMenu = reinterpret_cast<HMENU>(msg->lParam);
|
|
|
|
m_selectedItem = GET_X_LPARAM(msg->wParam);
|
|
|
|
m_selectedItemFlags = HIWORD(msg->wParam);
|
2014-04-15 22:30:37 +00:00
|
|
|
break;
|
|
|
|
case WM_KEYDOWN:
|
|
|
|
switch (msg->wParam)
|
|
|
|
{
|
|
|
|
case VK_LEFT:
|
|
|
|
if (m_current->hmenu == m_selectedMenu)
|
|
|
|
{
|
2014-12-18 17:34:46 +00:00
|
|
|
m_parent->mb->_MenuItemSelect(VK_LEFT);
|
2014-04-15 22:30:37 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case VK_RIGHT:
|
2014-04-16 12:14:02 +00:00
|
|
|
if (m_selectedItem < 0 || !(m_selectedItemFlags & MF_POPUP))
|
2014-04-15 22:30:37 +00:00
|
|
|
{
|
2014-12-18 17:34:46 +00:00
|
|
|
m_parent->mb->_MenuItemSelect(VK_RIGHT);
|
2014-04-15 22:30:37 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2014-03-19 15:33:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!callNext)
|
2014-04-02 17:37:37 +00:00
|
|
|
return 1;
|
2014-03-19 15:33:41 +00:00
|
|
|
}
|
|
|
|
|
2014-04-16 12:14:02 +00:00
|
|
|
return CallNextHookEx(m_hMsgFilterHook, nCode, hookWParam, hookLParam);
|
2014-03-19 15:33:41 +00:00
|
|
|
}
|
|
|
|
|
2014-04-16 12:14:02 +00:00
|
|
|
LRESULT CMenuFocusManager::GetMsgHook(INT nCode, WPARAM hookWParam, LPARAM hookLParam)
|
2014-02-24 11:59:34 +00:00
|
|
|
{
|
2014-06-29 15:42:06 +00:00
|
|
|
BOOL isLButton = FALSE;
|
2014-02-24 11:59:34 +00:00
|
|
|
if (nCode < 0)
|
2014-04-16 12:14:02 +00:00
|
|
|
return CallNextHookEx(m_hGetMsgHook, nCode, hookWParam, hookLParam);
|
2014-04-02 17:37:37 +00:00
|
|
|
|
2014-02-24 11:59:34 +00:00
|
|
|
if (nCode == HC_ACTION)
|
|
|
|
{
|
|
|
|
BOOL callNext = TRUE;
|
2014-04-16 12:14:02 +00:00
|
|
|
MSG* msg = reinterpret_cast<MSG*>(hookLParam);
|
2014-04-02 17:37:37 +00:00
|
|
|
POINT pt = msg->pt;
|
2014-04-03 18:30:25 +00:00
|
|
|
|
2014-02-24 11:59:34 +00:00
|
|
|
switch (msg->message)
|
|
|
|
{
|
2014-12-18 17:34:46 +00:00
|
|
|
case WM_CAPTURECHANGED:
|
|
|
|
if (m_captureHwnd)
|
|
|
|
{
|
|
|
|
TRACE("Capture lost.\n");
|
|
|
|
m_captureHwnd = NULL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2014-03-19 15:33:41 +00:00
|
|
|
case WM_NCLBUTTONDOWN:
|
2014-03-17 12:33:03 +00:00
|
|
|
case WM_LBUTTONDOWN:
|
2014-06-29 15:42:06 +00:00
|
|
|
isLButton = TRUE;
|
2014-12-18 17:34:46 +00:00
|
|
|
TRACE("LB\n");
|
2014-06-29 15:42:06 +00:00
|
|
|
|
2014-11-11 01:05:39 +00:00
|
|
|
if (m_menuBar && m_current->type == MenuPopupEntry)
|
|
|
|
{
|
|
|
|
POINT pt = msg->pt;
|
|
|
|
HWND child = WindowFromPoint(pt);
|
|
|
|
BOOL hoveringMenuBar = m_menuBar->mb->IsWindowOwner(child) == S_OK;
|
|
|
|
if (hoveringMenuBar)
|
|
|
|
{
|
2014-12-18 17:34:46 +00:00
|
|
|
m_current->mb->_MenuItemSelect(MPOS_FULLCANCEL);
|
2014-11-11 01:05:39 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-26 11:33:52 +00:00
|
|
|
if (m_current->type == MenuPopupEntry)
|
2014-03-15 21:38:15 +00:00
|
|
|
{
|
2014-03-26 11:33:52 +00:00
|
|
|
HWND child = WindowFromPoint(pt);
|
2014-04-03 18:30:25 +00:00
|
|
|
|
2014-05-16 11:12:51 +00:00
|
|
|
if (IsTrackedWindowOrParent(child) != S_OK)
|
2014-03-15 21:38:15 +00:00
|
|
|
{
|
2014-12-18 17:34:46 +00:00
|
|
|
m_current->mb->_MenuItemSelect(MPOS_FULLCANCEL);
|
2014-06-29 15:42:06 +00:00
|
|
|
break;
|
2014-03-15 21:38:15 +00:00
|
|
|
}
|
2014-03-26 11:33:52 +00:00
|
|
|
}
|
2014-12-18 17:34:46 +00:00
|
|
|
|
|
|
|
ProcessMouseDown(msg, isLButton);
|
|
|
|
|
2016-08-20 22:05:12 +00:00
|
|
|
break;
|
|
|
|
case WM_NCRBUTTONUP:
|
|
|
|
case WM_RBUTTONUP:
|
|
|
|
ProcessMouseUp(msg, isLButton);
|
2014-06-29 15:42:06 +00:00
|
|
|
break;
|
|
|
|
case WM_NCLBUTTONUP:
|
|
|
|
case WM_LBUTTONUP:
|
2016-08-20 22:05:12 +00:00
|
|
|
isLButton = TRUE;
|
|
|
|
ProcessMouseUp(msg, isLButton);
|
2014-03-26 11:33:52 +00:00
|
|
|
break;
|
|
|
|
case WM_MOUSEMOVE:
|
2014-04-02 17:37:37 +00:00
|
|
|
callNext = ProcessMouseMove(msg);
|
2014-03-15 21:38:15 +00:00
|
|
|
break;
|
2014-04-07 18:41:47 +00:00
|
|
|
case WM_MOUSELEAVE:
|
|
|
|
callNext = ProcessMouseMove(msg);
|
|
|
|
//callNext = ProcessMouseLeave(msg);
|
|
|
|
break;
|
2014-02-24 11:59:34 +00:00
|
|
|
case WM_SYSKEYDOWN:
|
|
|
|
case WM_KEYDOWN:
|
2014-04-03 18:30:25 +00:00
|
|
|
if (m_current->type == MenuPopupEntry)
|
2014-02-24 11:59:34 +00:00
|
|
|
{
|
2014-04-03 18:30:25 +00:00
|
|
|
DisableMouseTrack(m_current->hwnd, TRUE);
|
|
|
|
switch (msg->wParam)
|
|
|
|
{
|
2014-04-07 18:41:47 +00:00
|
|
|
case VK_ESCAPE:
|
2014-04-03 18:30:25 +00:00
|
|
|
case VK_MENU:
|
|
|
|
case VK_LMENU:
|
|
|
|
case VK_RMENU:
|
2014-12-18 17:34:46 +00:00
|
|
|
m_current->mb->_MenuItemSelect(MPOS_FULLCANCEL);
|
2014-04-03 18:30:25 +00:00
|
|
|
break;
|
2014-04-24 11:25:46 +00:00
|
|
|
case VK_RETURN:
|
2014-12-18 17:34:46 +00:00
|
|
|
m_current->mb->_MenuItemSelect(MPOS_EXECUTE);
|
2014-04-24 11:25:46 +00:00
|
|
|
break;
|
2014-04-03 18:30:25 +00:00
|
|
|
case VK_LEFT:
|
2014-12-18 17:34:46 +00:00
|
|
|
m_current->mb->_MenuItemSelect(VK_LEFT);
|
2014-04-03 18:30:25 +00:00
|
|
|
break;
|
|
|
|
case VK_RIGHT:
|
2014-12-18 17:34:46 +00:00
|
|
|
m_current->mb->_MenuItemSelect(VK_RIGHT);
|
2014-04-03 18:30:25 +00:00
|
|
|
break;
|
|
|
|
case VK_UP:
|
2014-12-18 17:34:46 +00:00
|
|
|
m_current->mb->_MenuItemSelect(VK_UP);
|
2014-04-03 18:30:25 +00:00
|
|
|
break;
|
|
|
|
case VK_DOWN:
|
2014-12-18 17:34:46 +00:00
|
|
|
m_current->mb->_MenuItemSelect(VK_DOWN);
|
2014-04-03 18:30:25 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-04-24 11:25:46 +00:00
|
|
|
msg->message = WM_NULL;
|
|
|
|
msg->lParam = 0;
|
|
|
|
msg->wParam = 0;
|
2014-02-24 11:59:34 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!callNext)
|
2014-04-02 17:37:37 +00:00
|
|
|
return 1;
|
2014-02-24 11:59:34 +00:00
|
|
|
}
|
|
|
|
|
2014-04-16 12:14:02 +00:00
|
|
|
return CallNextHookEx(m_hGetMsgHook, nCode, hookWParam, hookLParam);
|
2014-02-24 11:59:34 +00:00
|
|
|
}
|
|
|
|
|
2014-03-19 15:33:41 +00:00
|
|
|
HRESULT CMenuFocusManager::PlaceHooks()
|
2014-02-24 11:59:34 +00:00
|
|
|
{
|
2016-07-30 16:00:10 +00:00
|
|
|
if (m_hGetMsgHook)
|
2014-10-23 19:50:29 +00:00
|
|
|
{
|
|
|
|
WARN("GETMESSAGE hook already placed!\n");
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
if (m_hMsgFilterHook)
|
|
|
|
{
|
|
|
|
WARN("MSGFILTER hook already placed!\n");
|
|
|
|
return S_OK;
|
|
|
|
}
|
2014-04-02 17:37:37 +00:00
|
|
|
if (m_current->type == TrackedMenuEntry)
|
2014-03-19 15:33:41 +00:00
|
|
|
{
|
2014-05-18 14:20:27 +00:00
|
|
|
TRACE("Entering MSGFILTER hook...\n");
|
2014-03-19 15:33:41 +00:00
|
|
|
m_hMsgFilterHook = SetWindowsHookEx(WH_MSGFILTER, s_MsgFilterHook, NULL, m_threadId);
|
|
|
|
}
|
2014-04-03 18:30:25 +00:00
|
|
|
else
|
2014-03-19 15:33:41 +00:00
|
|
|
{
|
2014-05-18 14:20:27 +00:00
|
|
|
TRACE("Entering GETMESSAGE hook...\n");
|
2014-03-19 15:33:41 +00:00
|
|
|
m_hGetMsgHook = SetWindowsHookEx(WH_GETMESSAGE, s_GetMsgHook, NULL, m_threadId);
|
|
|
|
}
|
2014-02-24 11:59:34 +00:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2014-03-19 15:33:41 +00:00
|
|
|
HRESULT CMenuFocusManager::RemoveHooks()
|
2014-02-24 11:59:34 +00:00
|
|
|
{
|
2014-03-19 15:33:41 +00:00
|
|
|
if (m_hMsgFilterHook)
|
2014-12-18 17:34:46 +00:00
|
|
|
{
|
|
|
|
TRACE("Removing MSGFILTER hook...\n");
|
2014-03-19 15:33:41 +00:00
|
|
|
UnhookWindowsHookEx(m_hMsgFilterHook);
|
2014-12-18 17:34:46 +00:00
|
|
|
m_hMsgFilterHook = NULL;
|
|
|
|
}
|
2014-03-19 15:33:41 +00:00
|
|
|
if (m_hGetMsgHook)
|
2014-12-18 17:34:46 +00:00
|
|
|
{
|
|
|
|
TRACE("Removing GETMESSAGE hook...\n");
|
2014-03-19 15:33:41 +00:00
|
|
|
UnhookWindowsHookEx(m_hGetMsgHook);
|
2014-12-18 17:34:46 +00:00
|
|
|
m_hGetMsgHook = NULL;
|
|
|
|
}
|
2014-02-24 11:59:34 +00:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2015-02-02 22:06:59 +00:00
|
|
|
// Used to update the tracking info to account for a change in the top-level menu
|
2014-03-26 11:33:52 +00:00
|
|
|
HRESULT CMenuFocusManager::UpdateFocus()
|
2014-03-15 21:38:15 +00:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
2014-03-26 11:33:52 +00:00
|
|
|
StackEntry * old = m_current;
|
|
|
|
|
2014-10-08 15:25:52 +00:00
|
|
|
TRACE("UpdateFocus\n");
|
|
|
|
|
2015-02-02 22:06:59 +00:00
|
|
|
// Assign the new current item
|
2014-03-26 11:33:52 +00:00
|
|
|
if (m_bandCount > 0)
|
|
|
|
m_current = &(m_bandStack[m_bandCount - 1]);
|
|
|
|
else
|
|
|
|
m_current = NULL;
|
|
|
|
|
2015-02-02 22:06:59 +00:00
|
|
|
// Remove the menu capture if necesary
|
2014-12-18 17:34:46 +00:00
|
|
|
if (!m_current || m_current->type != MenuPopupEntry)
|
2014-12-20 17:45:45 +00:00
|
|
|
{
|
2014-12-18 17:34:46 +00:00
|
|
|
SetMenuCapture(NULL);
|
2014-12-20 17:45:45 +00:00
|
|
|
if (old && old->type == MenuPopupEntry && m_PreviousForeground)
|
|
|
|
{
|
|
|
|
::SetForegroundWindow(m_PreviousForeground);
|
|
|
|
m_PreviousForeground = NULL;
|
|
|
|
}
|
|
|
|
}
|
2014-12-18 17:34:46 +00:00
|
|
|
|
2015-02-02 22:06:59 +00:00
|
|
|
// Obtain the top-level window for the new active menu
|
2014-03-26 11:33:52 +00:00
|
|
|
if (m_current && m_current->type != TrackedMenuEntry)
|
2014-03-15 21:38:15 +00:00
|
|
|
{
|
2014-03-26 11:33:52 +00:00
|
|
|
hr = m_current->mb->_GetTopLevelWindow(&(m_current->hwnd));
|
2014-03-15 21:38:15 +00:00
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2015-02-02 22:06:59 +00:00
|
|
|
// Refresh the parent pointer
|
2014-03-26 11:33:52 +00:00
|
|
|
if (m_bandCount >= 2)
|
2014-03-19 15:33:41 +00:00
|
|
|
{
|
2014-03-26 11:33:52 +00:00
|
|
|
m_parent = &(m_bandStack[m_bandCount - 2]);
|
|
|
|
_ASSERT(m_parent->type != TrackedMenuEntry);
|
2014-03-19 15:33:41 +00:00
|
|
|
}
|
2014-03-26 11:33:52 +00:00
|
|
|
else
|
2014-03-20 15:39:25 +00:00
|
|
|
{
|
2014-03-26 11:33:52 +00:00
|
|
|
m_parent = NULL;
|
2014-03-20 15:39:25 +00:00
|
|
|
}
|
2014-02-24 11:59:34 +00:00
|
|
|
|
2015-02-02 22:06:59 +00:00
|
|
|
// Refresh the menubar pointer, if applicable
|
2014-04-02 17:37:37 +00:00
|
|
|
if (m_bandCount >= 1 && m_bandStack[0].type == MenuBarEntry)
|
|
|
|
{
|
|
|
|
m_menuBar = &(m_bandStack[0]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_menuBar = NULL;
|
|
|
|
}
|
|
|
|
|
2015-02-02 22:06:59 +00:00
|
|
|
// Remove the old hooks if the menu type changed, or we don't have a menu anymore
|
2014-03-26 11:33:52 +00:00
|
|
|
if (old && (!m_current || old->type != m_current->type))
|
2014-02-24 11:59:34 +00:00
|
|
|
{
|
2014-04-03 18:30:25 +00:00
|
|
|
if (m_current && m_current->type != TrackedMenuEntry)
|
2014-04-02 17:37:37 +00:00
|
|
|
{
|
|
|
|
DisableMouseTrack(m_current->hwnd, FALSE);
|
|
|
|
}
|
2014-03-16 09:28:51 +00:00
|
|
|
|
2014-03-19 15:33:41 +00:00
|
|
|
hr = RemoveHooks();
|
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
|
|
|
return hr;
|
2014-02-24 11:59:34 +00:00
|
|
|
}
|
2014-03-26 11:33:52 +00:00
|
|
|
|
2015-02-02 22:06:59 +00:00
|
|
|
// And place new ones if necessary
|
2014-03-26 11:33:52 +00:00
|
|
|
if (m_current && (!old || old->type != m_current->type))
|
2014-02-24 11:59:34 +00:00
|
|
|
{
|
2014-03-19 15:33:41 +00:00
|
|
|
hr = PlaceHooks();
|
2014-03-03 16:11:47 +00:00
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
2014-02-24 11:59:34 +00:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2015-02-02 22:06:59 +00:00
|
|
|
// Give the user a chance to move the mouse to the new menu
|
2014-04-02 17:37:37 +00:00
|
|
|
if (m_parent)
|
|
|
|
{
|
|
|
|
DisableMouseTrack(m_parent->hwnd, TRUE);
|
|
|
|
}
|
|
|
|
|
2014-12-18 17:34:46 +00:00
|
|
|
if (m_current && m_current->type == MenuPopupEntry)
|
2014-03-26 11:33:52 +00:00
|
|
|
{
|
2014-12-18 17:34:46 +00:00
|
|
|
if (m_captureHwnd == NULL)
|
|
|
|
{
|
|
|
|
// We need to restore the capture after a non-shell submenu or context menu is shown
|
|
|
|
StackEntry * topMenu = m_bandStack;
|
|
|
|
if (topMenu->type == MenuBarEntry)
|
|
|
|
topMenu++;
|
|
|
|
|
|
|
|
// Get the top-level window from the top popup
|
|
|
|
CComPtr<IServiceProvider> bandSite;
|
|
|
|
CComPtr<IOleWindow> deskBar;
|
|
|
|
hr = topMenu->mb->GetSite(IID_PPV_ARG(IServiceProvider, &bandSite));
|
2015-08-19 11:45:21 +00:00
|
|
|
if (FAILED(hr))
|
|
|
|
goto NoCapture;
|
2015-01-12 18:03:39 +00:00
|
|
|
hr = bandSite->QueryService(SID_SMenuPopup, IID_PPV_ARG(IOleWindow, &deskBar));
|
2015-08-19 11:45:21 +00:00
|
|
|
if (FAILED(hr))
|
|
|
|
goto NoCapture;
|
2014-12-18 17:34:46 +00:00
|
|
|
|
2014-12-20 17:45:45 +00:00
|
|
|
CComPtr<IOleWindow> deskBarSite;
|
|
|
|
hr = IUnknown_GetSite(deskBar, IID_PPV_ARG(IOleWindow, &deskBarSite));
|
2015-08-19 11:45:21 +00:00
|
|
|
if (FAILED(hr))
|
|
|
|
goto NoCapture;
|
2014-12-20 17:45:45 +00:00
|
|
|
|
|
|
|
// FIXME: Find the correct place for this
|
|
|
|
HWND hWndOwner;
|
2015-08-19 11:45:21 +00:00
|
|
|
hr = deskBarSite->GetWindow(&hWndOwner);
|
|
|
|
if (FAILED(hr))
|
|
|
|
goto NoCapture;
|
2014-12-20 17:45:45 +00:00
|
|
|
|
|
|
|
m_PreviousForeground = ::GetForegroundWindow();
|
|
|
|
if (m_PreviousForeground != hWndOwner)
|
|
|
|
::SetForegroundWindow(hWndOwner);
|
|
|
|
else
|
|
|
|
m_PreviousForeground = NULL;
|
|
|
|
|
2014-12-18 17:34:46 +00:00
|
|
|
// Get the HWND of the top-level window
|
|
|
|
HWND hWndSite;
|
|
|
|
hr = deskBar->GetWindow(&hWndSite);
|
2015-08-19 11:45:21 +00:00
|
|
|
if (FAILED(hr))
|
|
|
|
goto NoCapture;
|
2014-12-18 17:34:46 +00:00
|
|
|
SetMenuCapture(hWndSite);
|
|
|
|
}
|
2015-08-19 11:45:21 +00:00
|
|
|
NoCapture:
|
2014-04-02 17:37:37 +00:00
|
|
|
|
2014-12-18 17:34:46 +00:00
|
|
|
if (!m_parent || m_parent->type == MenuBarEntry)
|
2014-04-09 11:45:02 +00:00
|
|
|
{
|
2014-12-18 17:34:46 +00:00
|
|
|
if (old && old->type == TrackedMenuEntry)
|
|
|
|
{
|
|
|
|
// FIXME: Debugging code, probably not right
|
|
|
|
POINT pt2;
|
|
|
|
RECT rc2;
|
|
|
|
GetCursorPos(&pt2);
|
|
|
|
ScreenToClient(m_current->hwnd, &pt2);
|
|
|
|
GetClientRect(m_current->hwnd, &rc2);
|
|
|
|
if (PtInRect(&rc2, pt2))
|
|
|
|
SendMessage(m_current->hwnd, WM_MOUSEMOVE, 0, MAKELPARAM(pt2.x, pt2.y));
|
|
|
|
else
|
|
|
|
SendMessage(m_current->hwnd, WM_MOUSELEAVE, 0, 0);
|
|
|
|
}
|
2014-04-09 11:45:02 +00:00
|
|
|
}
|
2014-03-26 11:33:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_ASSERT(!m_parent || m_parent->type != TrackedMenuEntry);
|
2014-02-24 11:59:34 +00:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2015-02-02 22:06:59 +00:00
|
|
|
// Begin tracking top-level menu bar (for file browser windows)
|
2014-03-26 11:33:52 +00:00
|
|
|
HRESULT CMenuFocusManager::PushMenuBar(CMenuBand * mb)
|
2014-02-24 11:59:34 +00:00
|
|
|
{
|
2014-12-18 17:34:46 +00:00
|
|
|
TRACE("PushMenuBar %p\n", mb);
|
2014-10-23 17:17:16 +00:00
|
|
|
|
|
|
|
mb->AddRef();
|
2014-10-08 15:25:52 +00:00
|
|
|
|
2014-03-26 11:33:52 +00:00
|
|
|
_ASSERT(m_bandCount == 0);
|
2014-02-24 11:59:34 +00:00
|
|
|
|
2014-03-26 11:33:52 +00:00
|
|
|
HRESULT hr = PushToArray(MenuBarEntry, mb, NULL);
|
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
return UpdateFocus();
|
|
|
|
}
|
2014-03-19 15:33:41 +00:00
|
|
|
|
2015-02-02 22:06:59 +00:00
|
|
|
// Begin tracking a shell menu popup (start menu or submenus)
|
2014-03-26 11:33:52 +00:00
|
|
|
HRESULT CMenuFocusManager::PushMenuPopup(CMenuBand * mb)
|
|
|
|
{
|
2014-12-18 17:34:46 +00:00
|
|
|
TRACE("PushTrackedPopup %p\n", mb);
|
2014-10-23 17:17:16 +00:00
|
|
|
|
|
|
|
mb->AddRef();
|
2014-10-08 15:25:52 +00:00
|
|
|
|
2014-03-26 11:33:52 +00:00
|
|
|
_ASSERT(!m_current || m_current->type != TrackedMenuEntry);
|
|
|
|
|
|
|
|
HRESULT hr = PushToArray(MenuPopupEntry, mb, NULL);
|
2014-03-03 16:11:47 +00:00
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
2014-02-24 11:59:34 +00:00
|
|
|
return hr;
|
|
|
|
|
2014-03-26 11:33:52 +00:00
|
|
|
hr = UpdateFocus();
|
|
|
|
|
2014-12-18 17:34:46 +00:00
|
|
|
m_menuDepth++;
|
|
|
|
|
2014-03-26 11:33:52 +00:00
|
|
|
if (m_parent && m_parent->type != TrackedMenuEntry)
|
2014-03-19 15:33:41 +00:00
|
|
|
{
|
2014-03-26 11:33:52 +00:00
|
|
|
m_parent->mb->_SetChildBand(mb);
|
|
|
|
mb->_SetParentBand(m_parent->mb);
|
2014-03-19 15:33:41 +00:00
|
|
|
}
|
|
|
|
|
2014-03-26 11:33:52 +00:00
|
|
|
return hr;
|
2014-02-24 11:59:34 +00:00
|
|
|
}
|
|
|
|
|
2015-02-02 22:06:59 +00:00
|
|
|
// Begin tracking a system popup submenu (submenu of the file browser windows)
|
2014-03-26 11:33:52 +00:00
|
|
|
HRESULT CMenuFocusManager::PushTrackedPopup(HMENU popup)
|
2014-02-24 11:59:34 +00:00
|
|
|
{
|
2014-12-18 17:34:46 +00:00
|
|
|
TRACE("PushTrackedPopup %p\n", popup);
|
2014-10-08 15:25:52 +00:00
|
|
|
|
2014-03-26 11:33:52 +00:00
|
|
|
_ASSERT(m_bandCount > 0);
|
|
|
|
_ASSERT(!m_current || m_current->type != TrackedMenuEntry);
|
2014-02-24 11:59:34 +00:00
|
|
|
|
2014-03-26 11:33:52 +00:00
|
|
|
HRESULT hr = PushToArray(TrackedMenuEntry, NULL, popup);
|
2014-03-03 16:11:47 +00:00
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
2014-02-24 11:59:34 +00:00
|
|
|
return hr;
|
|
|
|
|
2014-12-18 17:34:46 +00:00
|
|
|
TRACE("PushTrackedPopup %p\n", popup);
|
2014-04-16 12:14:02 +00:00
|
|
|
m_selectedMenu = popup;
|
|
|
|
m_selectedItem = -1;
|
|
|
|
m_selectedItemFlags = 0;
|
|
|
|
|
2014-03-26 11:33:52 +00:00
|
|
|
return UpdateFocus();
|
|
|
|
}
|
|
|
|
|
2015-02-02 22:06:59 +00:00
|
|
|
// Stop tracking the menubar
|
2014-03-26 11:33:52 +00:00
|
|
|
HRESULT CMenuFocusManager::PopMenuBar(CMenuBand * mb)
|
|
|
|
{
|
|
|
|
StackEntryType type;
|
|
|
|
CMenuBand * mbc;
|
|
|
|
HRESULT hr;
|
2014-02-24 11:59:34 +00:00
|
|
|
|
2014-12-18 17:34:46 +00:00
|
|
|
TRACE("PopMenuBar %p\n", mb);
|
2014-10-08 15:25:52 +00:00
|
|
|
|
2014-10-28 01:27:02 +00:00
|
|
|
if (m_current == m_entryUnderMouse)
|
|
|
|
{
|
|
|
|
m_entryUnderMouse = NULL;
|
|
|
|
}
|
|
|
|
|
2014-03-26 11:33:52 +00:00
|
|
|
hr = PopFromArray(&type, &mbc, NULL);
|
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
|
|
|
{
|
|
|
|
UpdateFocus();
|
|
|
|
return hr;
|
2014-03-15 21:38:15 +00:00
|
|
|
}
|
2014-03-26 11:33:52 +00:00
|
|
|
|
|
|
|
_ASSERT(type == MenuBarEntry);
|
|
|
|
if (type != MenuBarEntry)
|
|
|
|
return E_FAIL;
|
2014-03-19 15:33:41 +00:00
|
|
|
|
|
|
|
if (!mbc)
|
|
|
|
return E_FAIL;
|
2014-03-15 21:38:15 +00:00
|
|
|
|
2014-03-26 11:33:52 +00:00
|
|
|
mbc->_SetParentBand(NULL);
|
|
|
|
|
2014-10-23 17:17:16 +00:00
|
|
|
mbc->Release();
|
|
|
|
|
2014-03-26 11:33:52 +00:00
|
|
|
hr = UpdateFocus();
|
2014-03-15 21:38:15 +00:00
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
|
|
|
return hr;
|
|
|
|
|
2014-03-26 11:33:52 +00:00
|
|
|
if (m_current)
|
2014-03-19 15:33:41 +00:00
|
|
|
{
|
2014-03-26 11:33:52 +00:00
|
|
|
_ASSERT(m_current->type != TrackedMenuEntry);
|
|
|
|
m_current->mb->_SetChildBand(NULL);
|
2014-03-19 15:33:41 +00:00
|
|
|
}
|
2014-02-24 11:59:34 +00:00
|
|
|
|
2014-03-15 21:38:15 +00:00
|
|
|
return S_OK;
|
2014-02-24 11:59:34 +00:00
|
|
|
}
|
2014-03-17 12:33:03 +00:00
|
|
|
|
2015-02-02 22:06:59 +00:00
|
|
|
// Stop tracking a shell menu
|
2014-03-26 11:33:52 +00:00
|
|
|
HRESULT CMenuFocusManager::PopMenuPopup(CMenuBand * mb)
|
2014-03-17 12:33:03 +00:00
|
|
|
{
|
2014-03-26 11:33:52 +00:00
|
|
|
StackEntryType type;
|
|
|
|
CMenuBand * mbc;
|
2014-03-17 12:33:03 +00:00
|
|
|
HRESULT hr;
|
|
|
|
|
2014-12-18 17:34:46 +00:00
|
|
|
TRACE("PopMenuPopup %p\n", mb);
|
2014-10-08 15:25:52 +00:00
|
|
|
|
2014-10-28 01:27:02 +00:00
|
|
|
if (m_current == m_entryUnderMouse)
|
|
|
|
{
|
|
|
|
m_entryUnderMouse = NULL;
|
|
|
|
}
|
|
|
|
|
2014-12-18 17:34:46 +00:00
|
|
|
m_menuDepth--;
|
|
|
|
|
2014-03-26 11:33:52 +00:00
|
|
|
hr = PopFromArray(&type, &mbc, NULL);
|
2014-03-17 12:33:03 +00:00
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
2014-03-26 11:33:52 +00:00
|
|
|
{
|
|
|
|
UpdateFocus();
|
2014-03-17 12:33:03 +00:00
|
|
|
return hr;
|
2014-03-26 11:33:52 +00:00
|
|
|
}
|
2014-03-17 12:33:03 +00:00
|
|
|
|
2014-03-26 11:33:52 +00:00
|
|
|
_ASSERT(type == MenuPopupEntry);
|
|
|
|
if (type != MenuPopupEntry)
|
|
|
|
return E_FAIL;
|
2014-03-17 12:33:03 +00:00
|
|
|
|
2014-03-26 11:33:52 +00:00
|
|
|
if (!mbc)
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
mbc->_SetParentBand(NULL);
|
2014-03-19 15:33:41 +00:00
|
|
|
|
2014-10-23 17:17:16 +00:00
|
|
|
mbc->Release();
|
|
|
|
|
2014-03-26 11:33:52 +00:00
|
|
|
hr = UpdateFocus();
|
2014-03-19 15:33:41 +00:00
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
|
|
|
return hr;
|
|
|
|
|
2014-03-26 11:33:52 +00:00
|
|
|
if (m_current)
|
|
|
|
{
|
|
|
|
_ASSERT(m_current->type != TrackedMenuEntry);
|
|
|
|
m_current->mb->_SetChildBand(NULL);
|
|
|
|
}
|
2014-03-19 15:33:41 +00:00
|
|
|
|
2014-03-26 11:33:52 +00:00
|
|
|
return S_OK;
|
|
|
|
}
|
2014-03-19 15:33:41 +00:00
|
|
|
|
2015-02-02 22:06:59 +00:00
|
|
|
// Stop tracking a system popup submenu
|
2014-03-26 11:33:52 +00:00
|
|
|
HRESULT CMenuFocusManager::PopTrackedPopup(HMENU popup)
|
|
|
|
{
|
|
|
|
StackEntryType type;
|
|
|
|
HMENU hmenu;
|
|
|
|
HRESULT hr;
|
2014-03-19 15:33:41 +00:00
|
|
|
|
2014-12-18 17:34:46 +00:00
|
|
|
TRACE("PopTrackedPopup %p\n", popup);
|
2014-10-08 15:25:52 +00:00
|
|
|
|
2014-03-26 11:33:52 +00:00
|
|
|
hr = PopFromArray(&type, NULL, &hmenu);
|
2014-03-19 15:33:41 +00:00
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
2014-03-26 11:33:52 +00:00
|
|
|
{
|
|
|
|
UpdateFocus();
|
2014-03-19 15:33:41 +00:00
|
|
|
return hr;
|
2014-03-26 11:33:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_ASSERT(type == TrackedMenuEntry);
|
|
|
|
if (type != TrackedMenuEntry)
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
if (hmenu != popup)
|
|
|
|
return E_FAIL;
|
2014-03-19 15:33:41 +00:00
|
|
|
|
2014-03-26 11:33:52 +00:00
|
|
|
hr = UpdateFocus();
|
2014-03-19 15:33:41 +00:00
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
return S_OK;
|
2014-03-17 12:33:03 +00:00
|
|
|
}
|