2014-11-02 22:26:44 +00:00
|
|
|
/*
|
|
|
|
* ReactOS Explorer
|
|
|
|
*
|
|
|
|
* Copyright 2006 - 2007 Thomas Weidenmueller <w3seek@reactos.org>
|
|
|
|
*
|
|
|
|
* 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 Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "precomp.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Start menu button context menu
|
|
|
|
*/
|
|
|
|
|
2014-11-06 03:05:33 +00:00
|
|
|
class CStartMenuBtnCtxMenu :
|
|
|
|
public CComCoClass<CStartMenuBtnCtxMenu>,
|
|
|
|
public CComObjectRootEx<CComMultiThreadModelNoCS>,
|
|
|
|
public IContextMenu
|
2014-11-02 22:26:44 +00:00
|
|
|
{
|
2024-05-21 10:57:54 +00:00
|
|
|
/* AddStartContextMenuItems uses ID_SHELL_CMD IDs directly and relies on idCmdFirst being 0.
|
|
|
|
* CTrayWindow::TrackCtxMenu must pass 0 because DeleteMenu ID_SHELL_CMD_UNDO_ACTION would
|
|
|
|
* delete the wrong item if it used 1. m_Inner->QueryContextMenu is not aware of this game
|
|
|
|
* so we have to reserve the entire ID_SHELL_CMD range for ourselves here. */
|
|
|
|
enum { INNERIDOFFSET = ID_SHELL_CMD_LAST + 1 };
|
|
|
|
static BOOL IsShellCmdId(UINT_PTR id) { return id < INNERIDOFFSET; }
|
|
|
|
|
2014-12-11 16:32:07 +00:00
|
|
|
CComPtr<ITrayWindow> m_TrayWnd;
|
|
|
|
CComPtr<IContextMenu> m_Inner;
|
|
|
|
CComPtr<IShellFolder> m_Folder;
|
|
|
|
|
|
|
|
HWND m_Owner;
|
|
|
|
LPITEMIDLIST m_FolderPidl;
|
2014-11-02 22:26:44 +00:00
|
|
|
|
2024-05-21 10:57:54 +00:00
|
|
|
HRESULT CreateContextMenuFromShellFolderPidl(HMENU hPopup, UINT idCmdFirst, UINT idCmdLast)
|
2014-11-02 22:26:44 +00:00
|
|
|
{
|
2014-11-06 03:05:33 +00:00
|
|
|
HRESULT hRet;
|
2014-11-02 22:26:44 +00:00
|
|
|
|
2014-12-11 16:32:07 +00:00
|
|
|
hRet = m_Folder->GetUIObjectOf(m_Owner, 1, (LPCITEMIDLIST *) &m_FolderPidl, IID_NULL_PPV_ARG(IContextMenu, &m_Inner));
|
2014-11-06 03:05:33 +00:00
|
|
|
if (SUCCEEDED(hRet))
|
2014-11-02 22:26:44 +00:00
|
|
|
{
|
2014-11-06 03:05:33 +00:00
|
|
|
if (hPopup != NULL)
|
2014-11-02 22:26:44 +00:00
|
|
|
{
|
2014-12-11 16:32:07 +00:00
|
|
|
hRet = m_Inner->QueryContextMenu(
|
2014-11-06 03:05:33 +00:00
|
|
|
hPopup,
|
|
|
|
0,
|
2024-05-21 10:57:54 +00:00
|
|
|
idCmdFirst,
|
|
|
|
idCmdLast,
|
2014-11-06 03:05:33 +00:00
|
|
|
CMF_VERBSONLY);
|
2014-11-02 22:26:44 +00:00
|
|
|
|
2014-11-06 03:05:33 +00:00
|
|
|
if (SUCCEEDED(hRet))
|
|
|
|
{
|
|
|
|
return hRet;
|
|
|
|
}
|
2014-11-02 22:26:44 +00:00
|
|
|
}
|
|
|
|
}
|
2014-11-06 03:05:33 +00:00
|
|
|
return E_FAIL;
|
2014-11-02 22:26:44 +00:00
|
|
|
}
|
|
|
|
|
2014-11-06 03:05:33 +00:00
|
|
|
VOID AddStartContextMenuItems(IN HMENU hPopup)
|
2014-11-02 22:26:44 +00:00
|
|
|
{
|
2014-11-06 03:05:33 +00:00
|
|
|
WCHAR szBuf[MAX_PATH];
|
|
|
|
HRESULT hRet;
|
2024-05-21 10:57:54 +00:00
|
|
|
C_ASSERT(ID_SHELL_CMD_FIRST != 0);
|
|
|
|
/* If this ever asserts, let m_Inner use 1..ID_SHELL_CMD_FIRST-1 instead */
|
|
|
|
C_ASSERT(ID_SHELL_CMD_LAST < 0xffff / 2);
|
2014-11-06 03:05:33 +00:00
|
|
|
|
|
|
|
/* Add the "Open All Users" menu item */
|
2016-06-04 14:09:20 +00:00
|
|
|
if (LoadStringW(hExplorerInstance,
|
|
|
|
IDS_PROPERTIES,
|
|
|
|
szBuf,
|
|
|
|
_countof(szBuf)))
|
2014-11-02 22:26:44 +00:00
|
|
|
{
|
2014-11-06 03:05:33 +00:00
|
|
|
AppendMenu(hPopup,
|
|
|
|
MF_STRING,
|
|
|
|
ID_SHELL_CMD_PROPERTIES,
|
|
|
|
szBuf);
|
|
|
|
}
|
2014-11-02 22:26:44 +00:00
|
|
|
|
2014-11-06 03:05:33 +00:00
|
|
|
if (!SHRestricted(REST_NOCOMMONGROUPS))
|
|
|
|
{
|
|
|
|
/* Check if we should add menu items for the common start menu */
|
2014-12-11 16:32:07 +00:00
|
|
|
hRet = SHGetFolderPath(m_Owner,
|
2014-11-06 03:05:33 +00:00
|
|
|
CSIDL_COMMON_STARTMENU,
|
|
|
|
NULL,
|
|
|
|
SHGFP_TYPE_CURRENT,
|
|
|
|
szBuf);
|
|
|
|
if (SUCCEEDED(hRet) && hRet != S_FALSE)
|
|
|
|
{
|
|
|
|
/* The directory exists, but only show the items if the
|
|
|
|
user can actually make any changes to the common start
|
|
|
|
menu. This is most likely only the case if the user
|
|
|
|
has administrative rights! */
|
|
|
|
if (IsUserAnAdmin())
|
2014-11-02 22:26:44 +00:00
|
|
|
{
|
|
|
|
AppendMenu(hPopup,
|
2014-11-06 03:05:33 +00:00
|
|
|
MF_SEPARATOR,
|
|
|
|
0,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
/* Add the "Open All Users" menu item */
|
2016-06-04 14:09:20 +00:00
|
|
|
if (LoadStringW(hExplorerInstance,
|
|
|
|
IDS_OPEN_ALL_USERS,
|
|
|
|
szBuf,
|
|
|
|
_countof(szBuf)))
|
2014-11-06 03:05:33 +00:00
|
|
|
{
|
|
|
|
AppendMenu(hPopup,
|
|
|
|
MF_STRING,
|
|
|
|
ID_SHELL_CMD_OPEN_ALL_USERS,
|
|
|
|
szBuf);
|
|
|
|
}
|
2014-11-02 22:26:44 +00:00
|
|
|
|
2014-11-06 03:05:33 +00:00
|
|
|
/* Add the "Explore All Users" menu item */
|
2016-06-04 14:09:20 +00:00
|
|
|
if (LoadStringW(hExplorerInstance,
|
|
|
|
IDS_EXPLORE_ALL_USERS,
|
|
|
|
szBuf,
|
|
|
|
_countof(szBuf)))
|
2014-11-06 03:05:33 +00:00
|
|
|
{
|
|
|
|
AppendMenu(hPopup,
|
|
|
|
MF_STRING,
|
|
|
|
ID_SHELL_CMD_EXPLORE_ALL_USERS,
|
|
|
|
szBuf);
|
|
|
|
}
|
2014-11-02 22:26:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-06 03:05:33 +00:00
|
|
|
public:
|
|
|
|
HRESULT Initialize(ITrayWindow * pTrayWnd, IN HWND hWndOwner)
|
|
|
|
{
|
2014-12-11 16:32:07 +00:00
|
|
|
m_TrayWnd = pTrayWnd;
|
|
|
|
m_Owner = hWndOwner;
|
2014-11-06 03:05:33 +00:00
|
|
|
return S_OK;
|
|
|
|
}
|
2014-11-02 22:26:44 +00:00
|
|
|
|
2014-11-06 03:05:33 +00:00
|
|
|
virtual HRESULT STDMETHODCALLTYPE
|
|
|
|
QueryContextMenu(HMENU hPopup,
|
|
|
|
UINT indexMenu,
|
|
|
|
UINT idCmdFirst,
|
|
|
|
UINT idCmdLast,
|
|
|
|
UINT uFlags)
|
2014-11-02 22:26:44 +00:00
|
|
|
{
|
2014-11-06 03:05:33 +00:00
|
|
|
LPITEMIDLIST pidlStart;
|
|
|
|
CComPtr<IShellFolder> psfDesktop;
|
2024-05-21 10:57:54 +00:00
|
|
|
HRESULT hRet = S_OK;
|
|
|
|
UINT idInnerFirst = idCmdFirst + INNERIDOFFSET;
|
2014-11-02 22:26:44 +00:00
|
|
|
|
2014-11-06 03:05:33 +00:00
|
|
|
psfDesktop = NULL;
|
2014-12-11 16:32:07 +00:00
|
|
|
m_Inner = NULL;
|
2014-11-06 03:05:33 +00:00
|
|
|
|
2014-12-11 16:32:07 +00:00
|
|
|
pidlStart = SHCloneSpecialIDList(m_Owner, CSIDL_STARTMENU, TRUE);
|
2014-11-06 03:05:33 +00:00
|
|
|
if (pidlStart != NULL)
|
2014-11-02 22:26:44 +00:00
|
|
|
{
|
2014-12-11 16:32:07 +00:00
|
|
|
m_FolderPidl = ILClone(ILFindLastID(pidlStart));
|
2014-11-06 03:05:33 +00:00
|
|
|
ILRemoveLastID(pidlStart);
|
|
|
|
|
2014-12-11 16:32:07 +00:00
|
|
|
if (m_FolderPidl != NULL)
|
2014-11-02 22:26:44 +00:00
|
|
|
{
|
2014-11-06 03:05:33 +00:00
|
|
|
hRet = SHGetDesktopFolder(&psfDesktop);
|
2014-11-02 22:26:44 +00:00
|
|
|
if (SUCCEEDED(hRet))
|
|
|
|
{
|
2014-12-11 16:32:07 +00:00
|
|
|
hRet = psfDesktop->BindToObject(pidlStart, NULL, IID_PPV_ARG(IShellFolder, &m_Folder));
|
2014-11-06 03:05:33 +00:00
|
|
|
if (SUCCEEDED(hRet))
|
2014-11-02 22:26:44 +00:00
|
|
|
{
|
2024-05-21 10:57:54 +00:00
|
|
|
hRet = CreateContextMenuFromShellFolderPidl(hPopup, idInnerFirst, idCmdLast);
|
2014-11-06 03:05:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-11-02 22:26:44 +00:00
|
|
|
|
2014-11-06 03:05:33 +00:00
|
|
|
ILFree(pidlStart);
|
|
|
|
}
|
2024-05-21 10:57:54 +00:00
|
|
|
if (idCmdLast - idCmdFirst >= ID_SHELL_CMD_LAST - ID_SHELL_CMD_FIRST)
|
|
|
|
{
|
|
|
|
AddStartContextMenuItems(hPopup);
|
|
|
|
hRet = SUCCEEDED(hRet) ? hRet + idInnerFirst : idInnerFirst;
|
|
|
|
}
|
|
|
|
return hRet;
|
2014-11-06 03:05:33 +00:00
|
|
|
}
|
2014-11-02 22:26:44 +00:00
|
|
|
|
2014-11-06 03:05:33 +00:00
|
|
|
virtual HRESULT STDMETHODCALLTYPE
|
|
|
|
InvokeCommand(LPCMINVOKECOMMANDINFO lpici)
|
|
|
|
{
|
2018-07-07 14:09:03 +00:00
|
|
|
UINT uiCmdId = PtrToUlong(lpici->lpVerb);
|
2024-05-21 10:57:54 +00:00
|
|
|
if (!IsShellCmdId((UINT_PTR)lpici->lpVerb))
|
2014-11-06 03:05:33 +00:00
|
|
|
{
|
2024-05-21 10:57:54 +00:00
|
|
|
CMINVOKECOMMANDINFO cmici = { 0 };
|
|
|
|
CHAR szDir[MAX_PATH];
|
|
|
|
|
|
|
|
/* Setup and invoke the shell command */
|
|
|
|
cmici.cbSize = sizeof(cmici);
|
|
|
|
cmici.hwnd = m_Owner;
|
|
|
|
if (IS_INTRESOURCE(lpici->lpVerb))
|
|
|
|
cmici.lpVerb = MAKEINTRESOURCEA(uiCmdId - INNERIDOFFSET);
|
2014-11-06 03:05:33 +00:00
|
|
|
else
|
2024-05-21 10:57:54 +00:00
|
|
|
cmici.lpVerb = lpici->lpVerb;
|
|
|
|
cmici.nShow = SW_NORMAL;
|
|
|
|
|
|
|
|
/* FIXME: Support Unicode!!! */
|
|
|
|
if (SHGetPathFromIDListA(m_FolderPidl, szDir))
|
2014-11-06 03:05:33 +00:00
|
|
|
{
|
2024-05-21 10:57:54 +00:00
|
|
|
cmici.lpDirectory = szDir;
|
2014-11-06 03:05:33 +00:00
|
|
|
}
|
2024-05-21 10:57:54 +00:00
|
|
|
|
|
|
|
return m_Inner->InvokeCommand(&cmici);
|
2014-11-02 22:26:44 +00:00
|
|
|
}
|
2024-05-21 10:57:54 +00:00
|
|
|
m_TrayWnd->ExecContextMenuCmd(uiCmdId);
|
2014-11-06 03:05:33 +00:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2021-09-13 01:33:14 +00:00
|
|
|
virtual HRESULT STDMETHODCALLTYPE
|
2014-11-06 03:05:33 +00:00
|
|
|
GetCommandString(UINT_PTR idCmd,
|
|
|
|
UINT uType,
|
|
|
|
UINT *pwReserved,
|
|
|
|
LPSTR pszName,
|
|
|
|
UINT cchMax)
|
|
|
|
{
|
2024-05-21 10:57:54 +00:00
|
|
|
if (!IsShellCmdId(idCmd) && m_Inner)
|
|
|
|
return m_Inner->GetCommandString(idCmd, uType, pwReserved, pszName, cchMax);
|
2014-11-06 03:05:33 +00:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
CStartMenuBtnCtxMenu()
|
|
|
|
{
|
|
|
|
}
|
2014-11-02 22:26:44 +00:00
|
|
|
|
2014-11-06 03:05:33 +00:00
|
|
|
virtual ~CStartMenuBtnCtxMenu()
|
|
|
|
{
|
2014-12-11 16:32:07 +00:00
|
|
|
if (m_FolderPidl)
|
|
|
|
ILFree(m_FolderPidl);
|
2014-11-02 22:26:44 +00:00
|
|
|
}
|
|
|
|
|
2014-11-06 03:05:33 +00:00
|
|
|
BEGIN_COM_MAP(CStartMenuBtnCtxMenu)
|
|
|
|
COM_INTERFACE_ENTRY_IID(IID_IContextMenu, IContextMenu)
|
|
|
|
END_COM_MAP()
|
|
|
|
};
|
2016-06-04 14:09:20 +00:00
|
|
|
|
2018-11-23 17:50:42 +00:00
|
|
|
HRESULT CStartMenuBtnCtxMenu_CreateInstance(ITrayWindow * m_TrayWnd, IN HWND m_Owner, IContextMenu ** ppCtxMenu)
|
2014-11-06 03:05:33 +00:00
|
|
|
{
|
2022-09-18 18:59:00 +00:00
|
|
|
return ShellObjectCreatorInit<CStartMenuBtnCtxMenu>(m_TrayWnd, m_Owner, IID_PPV_ARG(IContextMenu, ppCtxMenu));
|
2014-11-02 22:26:44 +00:00
|
|
|
}
|