2014-02-12 16:35:29 +00:00
|
|
|
/*
|
|
|
|
* Shell Menu Site
|
|
|
|
*
|
|
|
|
* 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-08-19 09:05:54 +00:00
|
|
|
#include "shellmenu.h"
|
2014-02-12 16:35:29 +00:00
|
|
|
#include <atlwin.h>
|
|
|
|
#include <shlwapi_undoc.h>
|
|
|
|
|
2014-02-24 11:59:34 +00:00
|
|
|
#include "CMenuSite.h"
|
2014-02-13 20:16:30 +00:00
|
|
|
|
2014-02-12 16:35:29 +00:00
|
|
|
CMenuSite::CMenuSite() :
|
|
|
|
m_DeskBarSite(NULL),
|
|
|
|
m_BandObject(NULL),
|
|
|
|
m_DeskBand(NULL),
|
|
|
|
m_WinEventHandler(NULL),
|
|
|
|
m_hWndBand(NULL)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-02-02 22:06:59 +00:00
|
|
|
// Child Band management (simplified due to only supporting one single child)
|
2014-02-12 16:35:29 +00:00
|
|
|
HRESULT STDMETHODCALLTYPE CMenuSite::AddBand(IUnknown * punk)
|
|
|
|
{
|
2014-02-20 16:18:49 +00:00
|
|
|
HRESULT hr;
|
2014-02-12 16:35:29 +00:00
|
|
|
|
2015-02-02 22:06:59 +00:00
|
|
|
// Little helper, for readability
|
2014-02-20 16:18:49 +00:00
|
|
|
#define TO_HRESULT(x) ((HRESULT)(S_OK+(x)))
|
2014-02-12 16:35:29 +00:00
|
|
|
|
2014-03-05 13:14:51 +00:00
|
|
|
CComPtr<IUnknown> pUnknown;
|
|
|
|
|
|
|
|
punk->QueryInterface(IID_PPV_ARG(IUnknown, &pUnknown));
|
|
|
|
|
|
|
|
if (pUnknown == m_BandObject)
|
2014-02-20 16:18:49 +00:00
|
|
|
return TO_HRESULT(0);
|
|
|
|
|
|
|
|
if (m_BandObject)
|
|
|
|
{
|
|
|
|
hr = IUnknown_SetSite(m_BandObject, NULL);
|
2014-03-03 16:11:47 +00:00
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
2014-02-20 16:18:49 +00:00
|
|
|
return hr;
|
|
|
|
}
|
2014-02-12 16:35:29 +00:00
|
|
|
|
2014-02-16 12:48:09 +00:00
|
|
|
m_BandObject = NULL;
|
|
|
|
m_DeskBand = NULL;
|
|
|
|
m_WinEventHandler = NULL;
|
2014-02-12 16:35:29 +00:00
|
|
|
m_hWndBand = NULL;
|
|
|
|
|
2014-03-05 13:14:51 +00:00
|
|
|
if (!pUnknown)
|
2014-02-20 16:18:49 +00:00
|
|
|
return TO_HRESULT(0);
|
|
|
|
|
2014-03-05 13:14:51 +00:00
|
|
|
hr = pUnknown->QueryInterface(IID_PPV_ARG(IDeskBand, &m_DeskBand));
|
2014-03-03 16:11:47 +00:00
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
2014-02-20 16:18:49 +00:00
|
|
|
return hr;
|
2014-02-12 16:35:29 +00:00
|
|
|
|
2014-03-05 13:14:51 +00:00
|
|
|
hr = pUnknown->QueryInterface(IID_PPV_ARG(IWinEventHandler, &m_WinEventHandler));
|
2014-03-03 16:11:47 +00:00
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
2014-02-20 16:18:49 +00:00
|
|
|
return hr;
|
2014-02-12 16:35:29 +00:00
|
|
|
|
2014-03-05 13:14:51 +00:00
|
|
|
hr = IUnknown_SetSite(pUnknown, this->ToIUnknown());
|
2014-03-03 16:11:47 +00:00
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
2014-02-20 16:18:49 +00:00
|
|
|
return hr;
|
|
|
|
|
2014-03-05 13:14:51 +00:00
|
|
|
hr = IUnknown_GetWindow(pUnknown, &m_hWndBand);
|
2014-03-03 16:11:47 +00:00
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
2014-02-20 16:18:49 +00:00
|
|
|
return hr;
|
2014-02-12 16:35:29 +00:00
|
|
|
|
2014-03-05 13:14:51 +00:00
|
|
|
m_BandObject = pUnknown;
|
2014-02-12 16:35:29 +00:00
|
|
|
|
2014-02-20 16:18:49 +00:00
|
|
|
return TO_HRESULT(0);
|
2014-02-12 16:35:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE CMenuSite::EnumBands(UINT uBand, DWORD* pdwBandID)
|
|
|
|
{
|
|
|
|
if (uBand != 0)
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
*pdwBandID = 0;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE CMenuSite::GetBandObject(DWORD dwBandID, REFIID riid, VOID **ppv)
|
|
|
|
{
|
2014-02-20 16:18:49 +00:00
|
|
|
if (dwBandID != 0 || m_BandObject == NULL)
|
2014-02-12 16:35:29 +00:00
|
|
|
{
|
|
|
|
*ppv = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return m_BandObject->QueryInterface(riid, ppv);
|
|
|
|
}
|
|
|
|
|
2015-02-02 22:06:59 +00:00
|
|
|
HRESULT STDMETHODCALLTYPE CMenuSite::QueryBand(DWORD dwBandID, IDeskBand **ppstb, DWORD *pdwState, LPWSTR pszName, int cchName)
|
|
|
|
{
|
|
|
|
if (dwBandID != 0)
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
if (!m_BandObject)
|
|
|
|
{
|
|
|
|
*ppstb = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT hr = m_BandObject->QueryInterface(IID_PPV_ARG(IDeskBand, ppstb));
|
|
|
|
|
|
|
|
*pdwState = 1;
|
|
|
|
|
|
|
|
if (cchName > 0)
|
|
|
|
pszName[0] = 0;
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2014-02-12 16:35:29 +00:00
|
|
|
HRESULT STDMETHODCALLTYPE CMenuSite::GetSize(DWORD dwWhich, LPRECT prc)
|
|
|
|
{
|
|
|
|
memset(prc, 0, sizeof(*prc));
|
|
|
|
|
|
|
|
if (dwWhich != 0)
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
if (m_DeskBand == NULL)
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
DESKBANDINFO info = { 0 };
|
2014-02-13 20:16:30 +00:00
|
|
|
info.dwMask = DBIM_MAXSIZE;
|
2014-02-12 16:35:29 +00:00
|
|
|
|
|
|
|
m_DeskBand->GetBandInfo(0, 0, &info);
|
|
|
|
|
|
|
|
prc->right = info.ptMaxSize.x;
|
|
|
|
prc->bottom = info.ptMaxSize.y;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE CMenuSite::GetWindow(HWND *phwnd)
|
|
|
|
{
|
2014-02-20 16:18:49 +00:00
|
|
|
if (!IsWindow())
|
|
|
|
return E_FAIL;
|
2014-02-12 16:35:29 +00:00
|
|
|
|
|
|
|
*phwnd = m_hWnd;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE CMenuSite::IsWindowOwner(HWND hWnd)
|
|
|
|
{
|
|
|
|
if (hWnd == m_hWnd)
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
if (!m_WinEventHandler)
|
|
|
|
return S_FALSE;
|
|
|
|
|
|
|
|
return m_WinEventHandler->IsWindowOwner(hWnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE CMenuSite::OnWinEvent(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *theResult)
|
|
|
|
{
|
|
|
|
if (!m_WinEventHandler)
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
return m_WinEventHandler->OnWinEvent(hWnd, uMsg, wParam, lParam, theResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE CMenuSite::QueryService(REFGUID guidService, REFIID riid, void **ppvObject)
|
|
|
|
{
|
|
|
|
*ppvObject = NULL;
|
|
|
|
|
|
|
|
if (IsEqualGUID(guidService, SID_SMenuBandBottom) ||
|
|
|
|
IsEqualGUID(guidService, SID_SMenuBandBottomSelected) ||
|
|
|
|
IsEqualGUID(guidService, SID_SMenuBandChild))
|
|
|
|
{
|
|
|
|
if (m_BandObject == NULL)
|
2014-03-19 15:33:41 +00:00
|
|
|
return E_NOINTERFACE;
|
2014-02-12 16:35:29 +00:00
|
|
|
|
|
|
|
return IUnknown_QueryService(m_BandObject, guidService, riid, ppvObject);
|
|
|
|
}
|
|
|
|
|
2014-02-20 16:18:49 +00:00
|
|
|
if (!m_DeskBarSite)
|
2014-03-19 15:33:41 +00:00
|
|
|
return E_NOINTERFACE;
|
2014-02-12 16:35:29 +00:00
|
|
|
|
|
|
|
return IUnknown_QueryService(m_DeskBarSite, guidService, riid, ppvObject);
|
|
|
|
}
|
|
|
|
|
2015-02-02 22:06:59 +00:00
|
|
|
HRESULT STDMETHODCALLTYPE CMenuSite::Exec(const GUID * pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
|
2014-02-12 16:35:29 +00:00
|
|
|
{
|
2015-02-02 22:06:59 +00:00
|
|
|
// Forward Exec calls directly to the parent deskbar
|
|
|
|
return IUnknown_Exec(m_DeskBarSite, *pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);
|
|
|
|
}
|
2014-02-20 16:18:49 +00:00
|
|
|
|
2015-02-02 22:06:59 +00:00
|
|
|
HRESULT STDMETHODCALLTYPE CMenuSite::QueryStatus(const GUID * pguidCmdGroup, ULONG cCmds, OLECMD prgCmds [], OLECMDTEXT *pCmdText)
|
|
|
|
{
|
|
|
|
// Forward QueryStatus calls directly to the parent deskbar
|
2014-02-12 16:35:29 +00:00
|
|
|
return IUnknown_QueryStatus(m_DeskBarSite, *pguidCmdGroup, cCmds, prgCmds, pCmdText);
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE CMenuSite::SetDeskBarSite(IUnknown *punkSite)
|
|
|
|
{
|
2014-02-16 12:48:09 +00:00
|
|
|
HRESULT hr;
|
2014-02-12 16:35:29 +00:00
|
|
|
|
2014-02-16 12:48:09 +00:00
|
|
|
CComPtr<IUnknown> protectThis(this->ToIUnknown());
|
2014-02-12 16:35:29 +00:00
|
|
|
|
2015-02-02 22:06:59 +00:00
|
|
|
// Only initialize if a parent site is being assigned
|
2014-02-12 16:35:29 +00:00
|
|
|
if (punkSite)
|
|
|
|
{
|
2014-02-16 12:48:09 +00:00
|
|
|
HWND hWndSite;
|
2014-02-12 16:35:29 +00:00
|
|
|
|
2014-02-16 12:48:09 +00:00
|
|
|
m_DeskBarSite = NULL;
|
2014-02-12 16:35:29 +00:00
|
|
|
|
2014-02-16 12:48:09 +00:00
|
|
|
hr = IUnknown_GetWindow(punkSite, &hWndSite);
|
2014-02-12 16:35:29 +00:00
|
|
|
|
2014-02-16 12:48:09 +00:00
|
|
|
if (FAILED(hr) || !hWndSite)
|
|
|
|
return E_FAIL;
|
2014-02-12 16:35:29 +00:00
|
|
|
|
2014-02-16 12:48:09 +00:00
|
|
|
if (!m_hWnd)
|
2014-02-12 16:35:29 +00:00
|
|
|
{
|
2014-02-16 12:48:09 +00:00
|
|
|
Create(hWndSite, NULL, L"MenuSite");
|
2014-02-12 16:35:29 +00:00
|
|
|
}
|
|
|
|
|
2014-02-16 12:48:09 +00:00
|
|
|
m_DeskBarSite = punkSite;
|
|
|
|
}
|
2015-02-02 22:06:59 +00:00
|
|
|
else
|
2014-02-16 12:48:09 +00:00
|
|
|
{
|
2015-02-02 22:06:59 +00:00
|
|
|
// Otherwise, deinitialize.
|
|
|
|
if (m_DeskBand)
|
|
|
|
{
|
|
|
|
m_DeskBand->CloseDW(0);
|
|
|
|
}
|
2014-02-12 16:35:29 +00:00
|
|
|
|
2015-02-02 22:06:59 +00:00
|
|
|
hr = IUnknown_SetSite(m_BandObject, NULL);
|
2014-02-12 16:35:29 +00:00
|
|
|
|
2015-02-02 22:06:59 +00:00
|
|
|
m_BandObject = NULL;
|
|
|
|
m_DeskBand = NULL;
|
|
|
|
m_WinEventHandler = NULL;
|
|
|
|
m_hWndBand = NULL;
|
|
|
|
m_hWnd = NULL;
|
|
|
|
m_DeskBarSite = NULL;
|
|
|
|
}
|
2014-02-12 16:35:29 +00:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE CMenuSite::UIActivateDBC(DWORD dwState)
|
|
|
|
{
|
2014-02-16 12:48:09 +00:00
|
|
|
if (!m_DeskBand)
|
2014-02-12 16:35:29 +00:00
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
return m_DeskBand->ShowDW(dwState != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE CMenuSite::UIActivateIO(BOOL fActivate, LPMSG lpMsg)
|
|
|
|
{
|
2014-02-16 12:48:09 +00:00
|
|
|
if (lpMsg)
|
2014-02-12 16:35:29 +00:00
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
return IUnknown_UIActivateIO(m_BandObject, fActivate, lpMsg);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL CMenuSite::ProcessWindowMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT &lResult, DWORD mapId)
|
|
|
|
{
|
2014-02-16 12:48:09 +00:00
|
|
|
HWND hWndTarget = NULL;
|
|
|
|
CComPtr<IUnknown> protectThis(this->ToIUnknown());
|
2014-02-12 16:35:29 +00:00
|
|
|
|
|
|
|
switch (uMsg)
|
|
|
|
{
|
|
|
|
case WM_SIZE:
|
|
|
|
if (m_BandObject)
|
|
|
|
{
|
2014-02-16 12:48:09 +00:00
|
|
|
CComPtr<IMenuPopup> pMenuPopup;
|
2014-02-12 16:35:29 +00:00
|
|
|
if (SUCCEEDED(m_BandObject->QueryInterface(IID_PPV_ARG(IMenuPopup, &pMenuPopup))))
|
|
|
|
{
|
|
|
|
RECT Rect = { 0 };
|
|
|
|
GetClientRect(&Rect);
|
|
|
|
pMenuPopup->OnPosRectChangeDB(&Rect);
|
|
|
|
}
|
|
|
|
}
|
2014-02-16 12:48:09 +00:00
|
|
|
hWndTarget = hWnd;
|
2014-02-12 16:35:29 +00:00
|
|
|
lResult = 1;
|
|
|
|
break;
|
|
|
|
case WM_NOTIFY:
|
2014-02-18 10:26:50 +00:00
|
|
|
hWndTarget = reinterpret_cast<LPNMHDR>(lParam)->hwndFrom;
|
2014-02-12 16:35:29 +00:00
|
|
|
break;
|
|
|
|
case WM_COMMAND:
|
2014-02-16 12:48:09 +00:00
|
|
|
hWndTarget = (HWND) lParam;
|
2014-02-12 16:35:29 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-02-16 12:48:09 +00:00
|
|
|
if (hWndTarget && m_WinEventHandler &&
|
|
|
|
m_WinEventHandler->IsWindowOwner(hWndTarget) == S_OK)
|
2014-02-12 16:35:29 +00:00
|
|
|
{
|
2014-02-16 12:48:09 +00:00
|
|
|
if (SUCCEEDED(m_WinEventHandler->OnWinEvent(hWndTarget, uMsg, wParam, lParam, &lResult)))
|
|
|
|
return TRUE;
|
2014-02-12 16:35:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
2015-02-02 22:06:59 +00:00
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE CMenuSite::ContextSensitiveHelp(BOOL fEnterMode)
|
|
|
|
{
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE CMenuSite::GetBandSiteInfo(BANDSITEINFO *pbsinfo)
|
|
|
|
{
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE CMenuSite::RemoveBand(DWORD dwBandID)
|
|
|
|
{
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE CMenuSite::SetBandSiteInfo(const BANDSITEINFO *pbsinfo)
|
|
|
|
{
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE CMenuSite::SetBandState(DWORD dwBandID, DWORD dwMask, DWORD dwState)
|
|
|
|
{
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE CMenuSite::SetModeDBC(DWORD dwMode)
|
|
|
|
{
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE CMenuSite::TranslateAcceleratorIO(LPMSG lpMsg)
|
|
|
|
{
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE CMenuSite::HasFocusIO()
|
|
|
|
{
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE CMenuSite::OnFocusChangeIS(IUnknown *punkObj, BOOL fSetFocus)
|
|
|
|
{
|
|
|
|
return S_OK;
|
|
|
|
}
|
2017-06-19 14:27:51 +00:00
|
|
|
|
|
|
|
extern "C"
|
|
|
|
HRESULT WINAPI RSHELL_CMenuSite_CreateInstance(REFIID riid, LPVOID *ppv)
|
|
|
|
{
|
|
|
|
return ShellObjectCreator<CMenuSite>(riid, ppv);
|
|
|
|
}
|