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
|
|
|
|
*/
|
|
|
|
#include "precomp.h"
|
|
|
|
#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"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(CMenuFocus);
|
|
|
|
|
|
|
|
DWORD CMenuFocusManager::TlsIndex = 0;
|
|
|
|
|
|
|
|
CMenuFocusManager * CMenuFocusManager::GetManager()
|
|
|
|
{
|
|
|
|
return reinterpret_cast<CMenuFocusManager *>(TlsGetValue(TlsIndex));
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT CMenuFocusManager::PushToArray(CMenuBand * item)
|
|
|
|
{
|
|
|
|
if (m_bandCount >= MAX_RECURSE)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
m_bandStack[m_bandCount++] = item;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT CMenuFocusManager::PopFromArray(CMenuBand ** pItem)
|
|
|
|
{
|
|
|
|
if (pItem)
|
|
|
|
*pItem = NULL;
|
|
|
|
|
|
|
|
if (m_bandCount <= 0)
|
2014-03-19 15:33:41 +00:00
|
|
|
return S_FALSE;
|
2014-02-24 11:59:34 +00:00
|
|
|
|
|
|
|
m_bandCount--;
|
|
|
|
|
|
|
|
if (pItem)
|
|
|
|
*pItem = m_bandStack[m_bandCount];
|
|
|
|
|
|
|
|
m_bandStack[m_bandCount] = NULL;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT CMenuFocusManager::PeekArray(CMenuBand ** pItem)
|
|
|
|
{
|
|
|
|
if (!pItem)
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
*pItem = NULL;
|
|
|
|
|
|
|
|
if (m_bandCount <= 0)
|
2014-03-16 09:28:51 +00:00
|
|
|
return S_FALSE;
|
2014-02-24 11:59:34 +00:00
|
|
|
|
|
|
|
*pItem = m_bandStack[m_bandCount - 1];
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
CMenuFocusManager::CMenuFocusManager() :
|
|
|
|
m_currentBand(NULL),
|
|
|
|
m_currentFocus(NULL),
|
2014-03-19 15:33:41 +00:00
|
|
|
m_currentMenu(NULL),
|
|
|
|
m_parentToolbar(NULL),
|
|
|
|
m_hMsgFilterHook(NULL),
|
|
|
|
m_hGetMsgHook(NULL),
|
2014-03-15 21:38:15 +00:00
|
|
|
m_mouseTrackDisabled(FALSE),
|
|
|
|
m_lastMoveFlags(0),
|
2014-03-16 09:28:51 +00:00
|
|
|
m_lastMovePos(0),
|
|
|
|
m_bandCount(0)
|
2014-02-24 11:59:34 +00:00
|
|
|
{
|
|
|
|
m_threadId = GetCurrentThreadId();
|
|
|
|
}
|
|
|
|
|
|
|
|
CMenuFocusManager::~CMenuFocusManager()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-03-15 21:38:15 +00:00
|
|
|
void CMenuFocusManager::DisableMouseTrack(HWND enableTo, BOOL disableThis)
|
|
|
|
{
|
|
|
|
BOOL bDisable = FALSE;
|
|
|
|
|
|
|
|
int i = m_bandCount;
|
|
|
|
while (--i >= 0)
|
|
|
|
{
|
|
|
|
CMenuBand * band = m_bandStack[i];
|
|
|
|
|
|
|
|
HWND hwnd;
|
|
|
|
HRESULT hr = band->_GetTopLevelWindow(&hwnd);
|
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (hwnd == enableTo)
|
|
|
|
{
|
|
|
|
band->_DisableMouseTrack(disableThis);
|
|
|
|
bDisable = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
band->_DisableMouseTrack(bDisable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_mouseTrackDisabled == bDisable)
|
|
|
|
{
|
|
|
|
if (bDisable)
|
|
|
|
{
|
|
|
|
SetCapture(m_currentFocus);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ReleaseCapture();
|
|
|
|
|
|
|
|
m_mouseTrackDisabled = bDisable;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT CMenuFocusManager::IsTrackedWindow(HWND hWnd)
|
|
|
|
{
|
2014-03-19 15:33:41 +00:00
|
|
|
int i = m_bandCount;
|
2014-03-15 21:38:15 +00:00
|
|
|
while (--i >= 0)
|
|
|
|
{
|
|
|
|
CMenuBand * band = m_bandStack[i];
|
|
|
|
|
|
|
|
HWND hwnd;
|
|
|
|
HRESULT hr = band->_GetTopLevelWindow(&hwnd);
|
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
if (hwnd == hWnd)
|
2014-03-21 10:13:18 +00:00
|
|
|
{
|
|
|
|
return band->_IsPopup();
|
|
|
|
}
|
2014-03-15 21:38:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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 parent;
|
|
|
|
HWND child;
|
|
|
|
POINT pt;
|
|
|
|
int iHitTestResult;
|
|
|
|
|
2014-03-20 15:39:25 +00:00
|
|
|
pt = msg->pt;
|
2014-03-19 15:33:41 +00:00
|
|
|
|
2014-03-20 15:39:25 +00:00
|
|
|
parent = WindowFromPoint(pt);
|
2014-03-19 15:33:41 +00:00
|
|
|
|
2014-03-20 15:39:25 +00:00
|
|
|
ScreenToClient(parent, &pt);
|
2014-03-19 15:33:41 +00:00
|
|
|
|
2014-03-20 15:39:25 +00:00
|
|
|
child = ChildWindowFromPoint(parent, pt);
|
|
|
|
|
|
|
|
if (child != m_parentToolbar)
|
|
|
|
return TRUE;
|
2014-03-19 15:33:41 +00:00
|
|
|
|
2014-03-20 15:39:25 +00:00
|
|
|
ScreenToClient(m_parentToolbar, &msg->pt);
|
2014-03-19 15:33:41 +00:00
|
|
|
|
2014-03-20 15:39:25 +00:00
|
|
|
/* Don't do anything if the mouse has not been moved */
|
|
|
|
if (msg->pt.x == m_ptPrev.x && msg->pt.y == m_ptPrev.y)
|
|
|
|
return TRUE;
|
2014-03-19 15:33:41 +00:00
|
|
|
|
2014-03-20 15:39:25 +00:00
|
|
|
m_ptPrev = msg->pt;
|
2014-03-19 15:33:41 +00:00
|
|
|
|
2014-03-20 15:39:25 +00:00
|
|
|
iHitTestResult = SendMessageW(m_parentToolbar, TB_HITTEST, 0, (LPARAM) &msg->pt);
|
2014-03-19 15:33:41 +00:00
|
|
|
|
2014-03-20 15:39:25 +00:00
|
|
|
/* Make sure that iHitTestResult is one of the menu items and that it is not the current menu item */
|
|
|
|
if (iHitTestResult >= 0)
|
|
|
|
{
|
|
|
|
HWND hwndToolbar = m_parentToolbar;
|
|
|
|
if (SendMessage(hwndToolbar, WM_USER_ISTRACKEDITEM, iHitTestResult, 0))
|
|
|
|
{
|
|
|
|
DbgPrint("Hot item tracking detected a change...\n");
|
|
|
|
if (m_currentMenu)
|
|
|
|
SendMessage(m_currentFocus, WM_CANCELMODE, 0, 0);
|
|
|
|
else
|
2014-03-21 10:13:18 +00:00
|
|
|
m_currentBand->_MenuItemHotTrack(MPOS_CANCELLEVEL);
|
2014-03-20 15:39:25 +00:00
|
|
|
DbgPrint("Active popup cancelled, notifying of change...\n");
|
|
|
|
PostMessage(hwndToolbar, WM_USER_CHANGETRACKEDITEM, iHitTestResult, iHitTestResult);
|
2014-03-21 10:13:18 +00:00
|
|
|
return 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-03-20 15:39:25 +00:00
|
|
|
LRESULT CMenuFocusManager::MsgFilterHook(INT nCode, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
if (nCode < 0)
|
|
|
|
return CallNextHookEx(m_hMsgFilterHook, nCode, wParam, lParam);
|
2014-03-19 15:33:41 +00:00
|
|
|
|
2014-03-20 15:39:25 +00:00
|
|
|
if (nCode == MSGF_MENU)
|
|
|
|
{
|
|
|
|
BOOL callNext = TRUE;
|
|
|
|
MSG* msg = reinterpret_cast<MSG*>(lParam);
|
2014-03-19 15:33:41 +00:00
|
|
|
|
2014-03-20 15:39:25 +00:00
|
|
|
// Do whatever is necessary here
|
2014-03-19 15:33:41 +00:00
|
|
|
|
2014-03-20 15:39:25 +00:00
|
|
|
switch (msg->message)
|
|
|
|
{
|
|
|
|
case WM_MOUSEMOVE:
|
|
|
|
callNext = ProcessMouseMove(msg);
|
2014-03-19 15:33:41 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!callNext)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CallNextHookEx(m_hMsgFilterHook, nCode, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
2014-02-24 11:59:34 +00:00
|
|
|
LRESULT CMenuFocusManager::GetMsgHook(INT nCode, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
if (nCode < 0)
|
2014-03-19 15:33:41 +00:00
|
|
|
return CallNextHookEx(m_hGetMsgHook, nCode, wParam, lParam);
|
2014-02-24 11:59:34 +00:00
|
|
|
|
2014-03-16 09:36:28 +00:00
|
|
|
LPARAM pos = (LPARAM) GetMessagePos();
|
2014-03-15 21:38:15 +00:00
|
|
|
|
2014-02-24 11:59:34 +00:00
|
|
|
if (nCode == HC_ACTION)
|
|
|
|
{
|
|
|
|
BOOL callNext = TRUE;
|
|
|
|
MSG* msg = reinterpret_cast<MSG*>(lParam);
|
|
|
|
|
|
|
|
// Do whatever is necessary here
|
|
|
|
|
|
|
|
switch (msg->message)
|
|
|
|
{
|
|
|
|
case WM_CLOSE:
|
|
|
|
break;
|
2014-03-19 15:33:41 +00:00
|
|
|
|
|
|
|
case WM_NCLBUTTONDOWN:
|
2014-03-17 12:33:03 +00:00
|
|
|
case WM_LBUTTONDOWN:
|
|
|
|
{
|
|
|
|
POINT pt = { GET_X_LPARAM(pos), GET_Y_LPARAM(pos) };
|
|
|
|
|
2014-03-19 15:33:41 +00:00
|
|
|
HWND window = GetAncestor(WindowFromPoint(pt), GA_ROOT);
|
2014-03-17 12:33:03 +00:00
|
|
|
|
|
|
|
if (IsTrackedWindow(window) != S_OK)
|
|
|
|
{
|
|
|
|
DisableMouseTrack(NULL, FALSE);
|
|
|
|
m_currentBand->_MenuItemHotTrack(MPOS_FULLCANCEL);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2014-03-15 21:38:15 +00:00
|
|
|
case WM_MOUSEMOVE:
|
|
|
|
if (m_lastMoveFlags != wParam || m_lastMovePos != pos)
|
|
|
|
{
|
|
|
|
m_lastMoveFlags = wParam;
|
|
|
|
m_lastMovePos = pos;
|
|
|
|
|
|
|
|
POINT pt = { GET_X_LPARAM(pos), GET_Y_LPARAM(pos) };
|
|
|
|
|
|
|
|
HWND window = WindowFromPoint(pt);
|
|
|
|
|
|
|
|
if (IsTrackedWindow(window) == S_OK)
|
|
|
|
{
|
|
|
|
DisableMouseTrack(window, FALSE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DisableMouseTrack(NULL, FALSE);
|
|
|
|
}
|
|
|
|
}
|
2014-03-20 15:39:25 +00:00
|
|
|
callNext = ProcessMouseMove(msg);
|
2014-03-15 21:38:15 +00:00
|
|
|
break;
|
2014-02-24 11:59:34 +00:00
|
|
|
case WM_SYSKEYDOWN:
|
|
|
|
case WM_KEYDOWN:
|
2014-03-17 12:33:03 +00:00
|
|
|
//if (!m_currentMenu)
|
2014-02-24 11:59:34 +00:00
|
|
|
{
|
2014-03-17 12:33:03 +00:00
|
|
|
DisableMouseTrack(m_currentFocus, TRUE);
|
|
|
|
switch (msg->wParam)
|
|
|
|
{
|
|
|
|
case VK_MENU:
|
|
|
|
case VK_LMENU:
|
|
|
|
case VK_RMENU:
|
|
|
|
m_currentBand->_MenuItemHotTrack(MPOS_FULLCANCEL);
|
|
|
|
break;
|
|
|
|
case VK_LEFT:
|
|
|
|
m_currentBand->_MenuItemHotTrack(MPOS_SELECTLEFT);
|
|
|
|
break;
|
|
|
|
case VK_RIGHT:
|
|
|
|
m_currentBand->_MenuItemHotTrack(MPOS_SELECTRIGHT);
|
|
|
|
break;
|
|
|
|
case VK_UP:
|
|
|
|
m_currentBand->_MenuItemHotTrack(VK_UP);
|
|
|
|
break;
|
|
|
|
case VK_DOWN:
|
|
|
|
m_currentBand->_MenuItemHotTrack(VK_DOWN);
|
|
|
|
break;
|
|
|
|
}
|
2014-02-24 11:59:34 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!callNext)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-03-19 15:33:41 +00:00
|
|
|
return CallNextHookEx(m_hGetMsgHook, nCode, wParam, lParam);
|
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
|
|
|
{
|
|
|
|
//SetCapture(window);
|
2014-03-19 15:33:41 +00:00
|
|
|
if (m_currentMenu)
|
|
|
|
{
|
2014-03-20 15:39:25 +00:00
|
|
|
DbgPrint("Entering MSGFILTER hook...\n");
|
2014-03-19 15:33:41 +00:00
|
|
|
m_hMsgFilterHook = SetWindowsHookEx(WH_MSGFILTER, s_MsgFilterHook, NULL, m_threadId);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-03-20 15:39:25 +00:00
|
|
|
DbgPrint("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-20 15:39:25 +00:00
|
|
|
DbgPrint("Removing all hooks...\n");
|
2014-03-19 15:33:41 +00:00
|
|
|
if (m_hMsgFilterHook)
|
|
|
|
UnhookWindowsHookEx(m_hMsgFilterHook);
|
|
|
|
if (m_hGetMsgHook)
|
|
|
|
UnhookWindowsHookEx(m_hGetMsgHook);
|
|
|
|
m_hMsgFilterHook = NULL;
|
|
|
|
m_hGetMsgHook = NULL;
|
2014-02-24 11:59:34 +00:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2014-03-19 15:33:41 +00:00
|
|
|
HRESULT CMenuFocusManager::UpdateFocus(CMenuBand * newBand, HMENU popupToTrack)
|
2014-03-15 21:38:15 +00:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
2014-03-19 15:33:41 +00:00
|
|
|
HWND newFocus = NULL;
|
|
|
|
HWND oldFocus = m_currentFocus;
|
|
|
|
HMENU oldMenu = m_currentMenu;
|
2014-03-15 21:38:15 +00:00
|
|
|
|
2014-03-19 15:33:41 +00:00
|
|
|
if (newBand)
|
2014-03-15 21:38:15 +00:00
|
|
|
{
|
2014-03-19 15:33:41 +00:00
|
|
|
hr = newBand->_GetTopLevelWindow(&newFocus);
|
2014-03-15 21:38:15 +00:00
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2014-03-19 15:33:41 +00:00
|
|
|
m_currentBand = newBand;
|
|
|
|
m_currentMenu = popupToTrack;
|
|
|
|
m_currentFocus = newFocus;
|
2014-03-20 15:39:25 +00:00
|
|
|
m_parentToolbar = NULL;
|
|
|
|
if (popupToTrack)
|
2014-03-19 15:33:41 +00:00
|
|
|
{
|
|
|
|
m_currentBand->GetWindow(&m_parentToolbar);
|
|
|
|
}
|
2014-03-20 15:39:25 +00:00
|
|
|
else if (m_bandCount >= 2)
|
|
|
|
{
|
|
|
|
m_bandStack[m_bandCount - 2]->GetWindow(&m_parentToolbar);
|
|
|
|
}
|
2014-02-24 11:59:34 +00:00
|
|
|
|
2014-03-19 15:33:41 +00:00
|
|
|
if (oldFocus && (!newFocus || (oldMenu != popupToTrack)))
|
2014-02-24 11:59:34 +00:00
|
|
|
{
|
2014-03-16 09:28:51 +00:00
|
|
|
DisableMouseTrack(NULL, FALSE);
|
|
|
|
|
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-19 15:33:41 +00:00
|
|
|
|
|
|
|
if (newFocus && (!oldFocus || (oldMenu != popupToTrack)))
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT CMenuFocusManager::PushMenu(CMenuBand * mb)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
2014-03-19 15:33:41 +00:00
|
|
|
CMenuBand * mbParent = m_currentBand;
|
|
|
|
|
2014-02-24 11:59:34 +00:00
|
|
|
hr = PushToArray(mb);
|
2014-03-03 16:11:47 +00:00
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
2014-02-24 11:59:34 +00:00
|
|
|
return hr;
|
|
|
|
|
2014-03-19 15:33:41 +00:00
|
|
|
if (mbParent)
|
|
|
|
{
|
2014-03-20 15:39:25 +00:00
|
|
|
mbParent->_SetChildBand(mb);
|
2014-03-21 10:13:18 +00:00
|
|
|
mb->_SetParentBand(mbParent);
|
2014-03-19 15:33:41 +00:00
|
|
|
}
|
|
|
|
|
2014-02-24 11:59:34 +00:00
|
|
|
return UpdateFocus(mb);
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT CMenuFocusManager::PopMenu(CMenuBand * mb)
|
|
|
|
{
|
|
|
|
CMenuBand * mbc;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2014-03-21 10:13:18 +00:00
|
|
|
if (m_currentBand)
|
|
|
|
{
|
|
|
|
m_currentBand->_SetParentBand(NULL);
|
|
|
|
}
|
|
|
|
|
2014-03-15 21:38:15 +00:00
|
|
|
HWND newFocus;
|
|
|
|
hr = mb->_GetTopLevelWindow(&newFocus);
|
2014-03-03 16:11:47 +00:00
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
2014-02-24 11:59:34 +00:00
|
|
|
return hr;
|
|
|
|
|
2014-03-15 21:38:15 +00:00
|
|
|
DbgPrint("Trying to pop %08p, hwnd=%08x\n", mb, newFocus);
|
2014-02-24 11:59:34 +00:00
|
|
|
|
2014-03-15 21:38:15 +00:00
|
|
|
do {
|
|
|
|
hr = PopFromArray(&mbc);
|
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
|
|
|
{
|
2014-03-19 15:33:41 +00:00
|
|
|
UpdateFocus(NULL);
|
2014-03-15 21:38:15 +00:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (mbc && mb != mbc);
|
2014-03-19 15:33:41 +00:00
|
|
|
|
|
|
|
if (!mbc)
|
|
|
|
return E_FAIL;
|
2014-03-15 21:38:15 +00:00
|
|
|
|
|
|
|
hr = PeekArray(&mb);
|
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
hr = UpdateFocus(mb);
|
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
|
|
|
return hr;
|
|
|
|
|
2014-03-19 15:33:41 +00:00
|
|
|
if (mb)
|
|
|
|
{
|
2014-03-20 15:39:25 +00:00
|
|
|
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
|
|
|
|
|
|
|
HRESULT CMenuFocusManager::PushTrackedPopup(CMenuBand * mb, HMENU popup)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = PushToArray(mb);
|
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
return UpdateFocus(mb, popup);
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT CMenuFocusManager::PopTrackedPopup(CMenuBand * mb, HMENU popup)
|
|
|
|
{
|
2014-03-19 15:33:41 +00:00
|
|
|
CMenuBand * mbc;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
HWND newFocus;
|
|
|
|
hr = mb->_GetTopLevelWindow(&newFocus);
|
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
DbgPrint("Trying to pop %08p, hwnd=%08x\n", mb, newFocus);
|
|
|
|
|
|
|
|
do {
|
|
|
|
hr = PopFromArray(&mbc);
|
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
|
|
|
{
|
|
|
|
UpdateFocus(NULL);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
} while (mbc && mb != mbc);
|
|
|
|
|
|
|
|
if (!mbc)
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
hr = PeekArray(&mb);
|
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
hr = UpdateFocus(mb);
|
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
return S_OK;
|
2014-03-17 12:33:03 +00:00
|
|
|
}
|