ReactOS 0.4.15-dev-8434-g155a7c7
CDefaultContextMenu.cpp File Reference
#include "precomp.h"
#include <compat_undoc.h>
Include dependency graph for CDefaultContextMenu.cpp:

Go to the source code of this file.

Classes

struct  _DynamicShellEntry_
 
struct  _StaticShellEntry_
 
struct  _StaticInvokeCommandMap_
 
class  CDefaultContextMenu
 

Macros

#define MAX_VERB   260
 
#define DCM_FCIDM_SHVIEW_OFFSET   0x7000
 

Typedefs

typedef struct _DynamicShellEntry_ DynamicShellEntry
 
typedef struct _DynamicShellEntry_PDynamicShellEntry
 
typedef struct _StaticShellEntry_ StaticShellEntry
 
typedef struct _StaticShellEntry_PStaticShellEntry
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (dmenu)
 
static HRESULT SHELL_GetRegCLSID (HKEY hKey, LPCWSTR SubKey, LPCWSTR Value, CLSID &clsid)
 
static bool RegValueExists (HKEY hKey, LPCWSTR Name)
 
static BOOL InsertMenuItemAt (HMENU hMenu, UINT Pos, UINT Flags)
 
UINT MapVerbToDfmCmd (_In_ LPCSTR verba)
 
static bool IsVerbListSeparator (WCHAR Ch)
 
static int FindVerbInDefaultVerbList (LPCWSTR List, LPCWSTR Verb)
 
EXTERN_C HRESULT SHELL32_EnumDefaultVerbList (LPCWSTR List, UINT Index, LPWSTR Verb, SIZE_T cchMax)
 
static BOOL HasClipboardData ()
 
void WINAPI _InsertMenuItemW (HMENU hMenu, UINT indexMenu, BOOL fByPosition, UINT wID, UINT fType, LPCWSTR dwTypeData, UINT fState)
 
HRESULT SHGetMenuIdFromMenuMsg (UINT uMsg, LPARAM lParam, UINT *CmdId)
 
HRESULT SHSetMenuIdInMenuMsg (UINT uMsg, LPARAM lParam, UINT CmdId)
 
static HRESULT CDefaultContextMenu_CreateInstance (const DEFCONTEXTMENU *pdcm, LPFNDFMCALLBACK lpfn, REFIID riid, void **ppv)
 
HRESULT WINAPI SHCreateDefaultContextMenu (const DEFCONTEXTMENU *pdcm, REFIID riid, void **ppv)
 
HRESULT WINAPI CDefFolderMenu_Create2 (PCIDLIST_ABSOLUTE pidlFolder, HWND hwnd, UINT cidl, PCUITEMID_CHILD_ARRAY apidl, IShellFolder *psf, LPFNDFMCALLBACK lpfn, UINT nKeys, const HKEY *ahkeyClsKeys, IContextMenu **ppcm)
 

Variables

static const struct _StaticInvokeCommandMap_ g_StaticInvokeCmdMap []
 

Macro Definition Documentation

◆ DCM_FCIDM_SHVIEW_OFFSET

#define DCM_FCIDM_SHVIEW_OFFSET   0x7000

Definition at line 54 of file CDefaultContextMenu.cpp.

◆ MAX_VERB

#define MAX_VERB   260

Definition at line 15 of file CDefaultContextMenu.cpp.

Typedef Documentation

◆ DynamicShellEntry

◆ PDynamicShellEntry

◆ PStaticShellEntry

◆ StaticShellEntry

Function Documentation

◆ _InsertMenuItemW()

void WINAPI _InsertMenuItemW ( HMENU  hMenu,
UINT  indexMenu,
BOOL  fByPosition,
UINT  wID,
UINT  fType,
LPCWSTR  dwTypeData,
UINT  fState 
)

Definition at line 745 of file CDefaultContextMenu.cpp.

753{
754 MENUITEMINFOW mii;
755 WCHAR wszText[100];
756
757 ZeroMemory(&mii, sizeof(mii));
758 mii.cbSize = sizeof(mii);
759 if (fType == MFT_SEPARATOR)
760 mii.fMask = MIIM_ID | MIIM_TYPE;
761 else if (fType == MFT_STRING)
762 {
764 if (IS_INTRESOURCE(dwTypeData))
765 {
766 if (LoadStringW(shell32_hInstance, LOWORD((ULONG_PTR)dwTypeData), wszText, _countof(wszText)))
767 mii.dwTypeData = wszText;
768 else
769 {
770 ERR("failed to load string %p\n", dwTypeData);
771 return;
772 }
773 }
774 else
775 mii.dwTypeData = (LPWSTR)dwTypeData;
776 mii.fState = fState;
777 }
778
779 mii.wID = wID;
780 mii.fType = fType;
781 InsertMenuItemW(hMenu, indexMenu, fByPosition, &mii);
782}
#define shell32_hInstance
#define ERR(fmt,...)
Definition: precomp.h:57
#define LOWORD(l)
Definition: pedump.c:82
#define _countof(array)
Definition: sndvol32.h:70
LPWSTR dwTypeData
Definition: winuser.h:3269
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define ZeroMemory
Definition: winbase.h:1712
#define MIIM_ID
Definition: winuser.h:722
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
#define IS_INTRESOURCE(i)
Definition: winuser.h:580
#define MFT_SEPARATOR
Definition: winuser.h:744
#define MIIM_STATE
Definition: winuser.h:721
#define MFT_STRING
Definition: winuser.h:746
#define MIIM_TYPE
Definition: winuser.h:725
BOOL WINAPI InsertMenuItemW(_In_ HMENU, _In_ UINT, _In_ BOOL, _In_ LPCMENUITEMINFOW)
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184

◆ CDefaultContextMenu_CreateInstance()

static HRESULT CDefaultContextMenu_CreateInstance ( const DEFCONTEXTMENU pdcm,
LPFNDFMCALLBACK  lpfn,
REFIID  riid,
void **  ppv 
)
static

Definition at line 1753 of file CDefaultContextMenu.cpp.

1754{
1755 return ShellObjectCreatorInit<CDefaultContextMenu>(pdcm, lpfn, riid, ppv);
1756}
REFIID riid
Definition: atlbase.h:39
REFIID LPVOID * ppv
Definition: atlbase.h:39

Referenced by CDefFolderMenu_Create2(), and SHCreateDefaultContextMenu().

◆ CDefFolderMenu_Create2()

HRESULT WINAPI CDefFolderMenu_Create2 ( PCIDLIST_ABSOLUTE  pidlFolder,
HWND  hwnd,
UINT  cidl,
PCUITEMID_CHILD_ARRAY  apidl,
IShellFolder psf,
LPFNDFMCALLBACK  lpfn,
UINT  nKeys,
const HKEY ahkeyClsKeys,
IContextMenu **  ppcm 
)

Definition at line 1786 of file CDefaultContextMenu.cpp.

1796{
1797 DEFCONTEXTMENU dcm;
1798 dcm.hwnd = hwnd;
1799 dcm.pcmcb = NULL;
1800 dcm.pidlFolder = pidlFolder;
1801 dcm.psf = psf;
1802 dcm.cidl = cidl;
1803 dcm.apidl = apidl;
1805 dcm.cKeys = nKeys;
1806 dcm.aKeys = ahkeyClsKeys;
1807
1810 return hr;
1811
1812 return S_OK;
1813}
static HRESULT CDefaultContextMenu_CreateInstance(const DEFCONTEXTMENU *pdcm, LPFNDFMCALLBACK lpfn, REFIID riid, void **ppv)
#define NULL
Definition: types.h:112
#define FAILED_UNEXPECTEDLY(hr)
Definition: precomp.h:121
#define S_OK
Definition: intsafe.h:52
HRESULT hr
Definition: shlfolder.c:183
IContextMenuCB * pcmcb
Definition: shlobj.h:2549
IShellFolder * psf
Definition: shlobj.h:2551
IUnknown * punkAssociationInfo
Definition: shlobj.h:2554
PCUITEMID_CHILD_ARRAY apidl
Definition: shlobj.h:2553
const HKEY * aKeys
Definition: shlobj.h:2556
PCIDLIST_ABSOLUTE pidlFolder
Definition: shlobj.h:2550
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
#define IID_PPV_ARG(Itype, ppType)

Referenced by _CFontMenu_CreateInstance(), CDrivesContextMenu_CreateInstance(), CGuidItemContextMenu_CreateInstance(), CZipFolder::GetUIObjectOf(), CNetFolder::GetUIObjectOf(), and CCommonFolder< TSelf, TItemId, TExtractIcon >::GetUIObjectOf().

◆ FindVerbInDefaultVerbList()

static int FindVerbInDefaultVerbList ( LPCWSTR  List,
LPCWSTR  Verb 
)
static

Definition at line 97 of file CDefaultContextMenu.cpp.

98{
99 for (UINT index = 0; *List; ++index)
100 {
101 while (IsVerbListSeparator(*List))
102 List++;
104 while (*List && !IsVerbListSeparator(*List))
105 List++;
106 // "List > Start" to verify that the list item is non-empty to avoid the edge case where Verb is "" and the list contains ",,"
107 if (!_wcsnicmp(Verb, Start, List - Start) && List > Start)
108 return index;
109 }
110 return -1;
111}
static bool IsVerbListSeparator(WCHAR Ch)
#define index(s, c)
Definition: various.h:29
return pTarget Start()
GLuint index
Definition: glext.h:6031
unsigned int UINT
Definition: ndis.h:50
_Check_return_ _CRTIMP int __cdecl _wcsnicmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

Referenced by CDefaultContextMenu::AddStaticContextMenusToMenu().

◆ HasClipboardData()

static BOOL HasClipboardData ( )
static

Definition at line 382 of file CDefaultContextMenu.cpp.

383{
384 BOOL bRet = FALSE;
385 CComPtr<IDataObject> pDataObj;
386
387 if (SUCCEEDED(OleGetClipboard(&pDataObj)))
388 {
389 FORMATETC formatetc;
390
391 TRACE("pDataObj=%p\n", pDataObj.p);
392
393 /* Set the FORMATETC structure*/
394 InitFormatEtc(formatetc, RegisterClipboardFormatW(CFSTR_SHELLIDLIST), TYMED_HGLOBAL);
395 bRet = SUCCEEDED(pDataObj->QueryGetData(&formatetc));
396 }
397
398 return bRet;
399}
#define FALSE
Definition: types.h:117
HRESULT WINAPI OleGetClipboard(IDataObject **obj)
Definition: clipboard.c:2249
#define InitFormatEtc(fe, cf, med)
Definition: editor.h:32
unsigned int BOOL
Definition: ntddk_ex.h:94
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define CFSTR_SHELLIDLIST
Definition: shlobj.h:550
#define TRACE(s)
Definition: solgame.cpp:4
UINT WINAPI RegisterClipboardFormatW(_In_ LPCWSTR)

Referenced by CDefaultContextMenu::QueryContextMenu().

◆ InsertMenuItemAt()

static BOOL InsertMenuItemAt ( HMENU  hMenu,
UINT  Pos,
UINT  Flags 
)
static

Definition at line 31 of file CDefaultContextMenu.cpp.

32{
33 MENUITEMINFOW mii;
34 mii.cbSize = FIELD_OFFSET(MENUITEMINFOW, hbmpItem); // USER32 version agnostic
35 mii.fMask = MIIM_TYPE;
36 mii.fType = Flags;
37 return InsertMenuItemW(hMenu, Pos, TRUE, &mii);
38}
ush Pos
Definition: deflate.h:92
#define TRUE
Definition: types.h:120
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170

Referenced by CDefaultContextMenu::AddStaticContextMenusToMenu().

◆ IsVerbListSeparator()

static bool IsVerbListSeparator ( WCHAR  Ch)
inlinestatic

Definition at line 92 of file CDefaultContextMenu.cpp.

93{
94 return Ch == L' ' || Ch == L','; // learn.microsoft.com/en-us/windows/win32/shell/context-menu-handlers
95}
#define L(x)
Definition: ntvdm.h:50
#define Ch(x, y, z)
Definition: sha2.c:141

Referenced by FindVerbInDefaultVerbList(), and SHELL32_EnumDefaultVerbList().

◆ MapVerbToDfmCmd()

UINT MapVerbToDfmCmd ( _In_ LPCSTR  verba)

Definition at line 82 of file CDefaultContextMenu.cpp.

83{
84 for (UINT i = 0; i < _countof(g_StaticInvokeCmdMap); ++i)
85 {
86 if (!lstrcmpiA(g_StaticInvokeCmdMap[i].szStringVerb, verba))
87 return (int)g_StaticInvokeCmdMap[i].DfmCmd;
88 }
89 return 0;
90}
static const struct _StaticInvokeCommandMap_ g_StaticInvokeCmdMap[]
int WINAPI lstrcmpiA(LPCSTR str1, LPCSTR str2)
Definition: locale.c:4223
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

Referenced by GetDfmCmd().

◆ RegValueExists()

static bool RegValueExists ( HKEY  hKey,
LPCWSTR  Name 
)
inlinestatic

Definition at line 26 of file CDefaultContextMenu.cpp.

27{
29}
#define ERROR_SUCCESS
Definition: deptool.c:10
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
FxAutoRegKey hKey

Referenced by CDefaultContextMenu::AddStaticContextMenusToMenu().

◆ SHCreateDefaultContextMenu()

HRESULT WINAPI SHCreateDefaultContextMenu ( const DEFCONTEXTMENU pdcm,
REFIID  riid,
void **  ppv 
)

Definition at line 1765 of file CDefaultContextMenu.cpp.

1766{
1767 HRESULT hr;
1768
1769 if (!ppv)
1770 return E_INVALIDARG;
1771
1774 return hr;
1775
1776 return S_OK;
1777}
#define E_INVALIDARG
Definition: ddrawi.h:101

Referenced by CDesktopFolder::CreateViewObject(), CDrivesFolder::CreateViewObject(), CFSFolder::CreateViewObject(), CDesktopFolder::GetUIObjectOf(), CFSFolder::GetUIObjectOf(), and init_function_pointers().

◆ SHELL32_EnumDefaultVerbList()

EXTERN_C HRESULT SHELL32_EnumDefaultVerbList ( LPCWSTR  List,
UINT  Index,
LPWSTR  Verb,
SIZE_T  cchMax 
)

Definition at line 113 of file CDefaultContextMenu.cpp.

114{
115 for (UINT i = 0; *List; ++i)
116 {
117 while (IsVerbListSeparator(*List))
118 List++;
120 while (*List && !IsVerbListSeparator(*List))
121 List++;
122 if (List > Start && i == Index)
123 return StringCchCopyNW(Verb, cchMax, Start, List - Start);
124 }
126}
UINT cchMax
#define ERROR_NO_MORE_ITEMS
Definition: compat.h:105
STRSAFEAPI StringCchCopyNW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc, size_t cchToCopy)
Definition: strsafe.h:236
_In_ WDFCOLLECTION _In_ ULONG Index
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92

Referenced by HCR_GetDefaultVerbW().

◆ SHELL_GetRegCLSID()

static HRESULT SHELL_GetRegCLSID ( HKEY  hKey,
LPCWSTR  SubKey,
LPCWSTR  Value,
CLSID clsid 
)
static

Definition at line 18 of file CDefaultContextMenu.cpp.

19{
20 WCHAR buf[42];
21 DWORD cb = sizeof(buf);
24}
LSTATUS WINAPI RegGetValueW(HKEY hKey, LPCWSTR pszSubKey, LPCWSTR pszValue, DWORD dwFlags, LPDWORD pdwType, PVOID pvData, LPDWORD pcbData)
Definition: reg.c:1931
HRESULT WINAPI CLSIDFromString(LPCOLESTR idstr, LPCLSID id)
Definition: compobj.c:2338
#define RRF_RT_REG_SZ
Definition: driver.c:575
unsigned long DWORD
Definition: ntddk_ex.h:95
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
static HMODULE MODULEINFO DWORD cb
Definition: module.c:33
REFCLSID clsid
Definition: msctf.c:82
#define err(...)
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413

Referenced by CDefaultContextMenu::InvokeRegVerb().

◆ SHGetMenuIdFromMenuMsg()

HRESULT SHGetMenuIdFromMenuMsg ( UINT  uMsg,
LPARAM  lParam,
UINT CmdId 
)

Definition at line 1659 of file CDefaultContextMenu.cpp.

1660{
1661 if (uMsg == WM_DRAWITEM)
1662 {
1663 DRAWITEMSTRUCT* pDrawStruct = reinterpret_cast<DRAWITEMSTRUCT*>(lParam);
1664 *CmdId = pDrawStruct->itemID;
1665 return S_OK;
1666 }
1667 else if (uMsg == WM_MEASUREITEM)
1668 {
1669 MEASUREITEMSTRUCT* pMeasureStruct = reinterpret_cast<MEASUREITEMSTRUCT*>(lParam);
1670 *CmdId = pMeasureStruct->itemID;
1671 return S_OK;
1672 }
1673
1674 return E_FAIL;
1675}
LPARAM lParam
Definition: combotst.c:139
#define E_FAIL
Definition: ddrawi.h:102
#define WM_DRAWITEM
Definition: winuser.h:1645
#define WM_MEASUREITEM
Definition: winuser.h:1646

Referenced by CDefaultContextMenu::HandleMenuMsg2(), and CDefView::OnCustomItem().

◆ SHSetMenuIdInMenuMsg()

HRESULT SHSetMenuIdInMenuMsg ( UINT  uMsg,
LPARAM  lParam,
UINT  CmdId 
)

Definition at line 1677 of file CDefaultContextMenu.cpp.

1678{
1679 if (uMsg == WM_DRAWITEM)
1680 {
1681 DRAWITEMSTRUCT* pDrawStruct = reinterpret_cast<DRAWITEMSTRUCT*>(lParam);
1682 pDrawStruct->itemID = CmdId;
1683 return S_OK;
1684 }
1685 else if (uMsg == WM_MEASUREITEM)
1686 {
1687 MEASUREITEMSTRUCT* pMeasureStruct = reinterpret_cast<MEASUREITEMSTRUCT*>(lParam);
1688 pMeasureStruct->itemID = CmdId;
1689 return S_OK;
1690 }
1691
1692 return E_FAIL;
1693}

Referenced by CDefaultContextMenu::HandleMenuMsg2(), and CDefView::OnCustomItem().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( dmenu  )

Variable Documentation

◆ g_StaticInvokeCmdMap

const struct _StaticInvokeCommandMap_ g_StaticInvokeCmdMap[]
static
Initial value:
=
{
{ "RunAs", 0 },
{ "Print", 0 },
{ "Preview", 0 },
{ "Open", FCIDM_SHVIEW_OPEN },
{ "cut", FCIDM_SHVIEW_CUT, },
{ "copyto", FCIDM_SHVIEW_COPYTO },
{ "moveto", FCIDM_SHVIEW_MOVETO },
}
short SHORT
Definition: pedump.c:59
#define DFM_CMD_DELETE
Definition: shlobj.h:2607
#define DFM_CMD_NEWFOLDER
Definition: shlobj.h:2612
#define DFM_CMD_COPY
Definition: shlobj.h:2609
#define DFM_CMD_PASTE
Definition: shlobj.h:2613
#define DFM_CMD_PROPERTIES
Definition: shlobj.h:2611
#define DFM_CMD_RENAME
Definition: shlobj.h:2619
#define DFM_CMD_LINK
Definition: shlobj.h:2610
#define FCIDM_SHVIEW_CUT
Definition: shresdef.h:831
#define FCIDM_SHVIEW_OPEN
Definition: shresdef.h:858
#define FCIDM_SHVIEW_COPY
Definition: shresdef.h:832
#define FCIDM_SHVIEW_NEWFOLDER
Definition: shresdef.h:854
#define FCIDM_SHVIEW_PROPERTIES
Definition: shresdef.h:830
#define FCIDM_SHVIEW_COPYTO
Definition: shresdef.h:836
#define FCIDM_SHVIEW_MOVETO
Definition: shresdef.h:837
#define FCIDM_SHVIEW_DELETE
Definition: shresdef.h:829
#define FCIDM_SHVIEW_RENAME
Definition: shresdef.h:851
#define FCIDM_SHVIEW_CREATELINK
Definition: shresdef.h:852
#define FCIDM_SHVIEW_INSERT
Definition: shresdef.h:833

Referenced by CDefaultContextMenu::GetCommandString(), CDefaultContextMenu::MapVerbToCmdId(), MapVerbToDfmCmd(), and CDefaultContextMenu::TryPickDefault().