ReactOS 0.4.16-dev-13-ge2fc578
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 746 of file CDefaultContextMenu.cpp.

754{
755 MENUITEMINFOW mii;
756 WCHAR wszText[100];
757
758 ZeroMemory(&mii, sizeof(mii));
759 mii.cbSize = sizeof(mii);
760 if (fType == MFT_SEPARATOR)
761 mii.fMask = MIIM_ID | MIIM_TYPE;
762 else if (fType == MFT_STRING)
763 {
765 if (IS_INTRESOURCE(dwTypeData))
766 {
767 if (LoadStringW(shell32_hInstance, LOWORD((ULONG_PTR)dwTypeData), wszText, _countof(wszText)))
768 mii.dwTypeData = wszText;
769 else
770 {
771 ERR("failed to load string %p\n", dwTypeData);
772 return;
773 }
774 }
775 else
776 mii.dwTypeData = (LPWSTR)dwTypeData;
777 mii.fState = fState;
778 }
779
780 mii.wID = wID;
781 mii.fType = fType;
782 InsertMenuItemW(hMenu, indexMenu, fByPosition, &mii);
783}
#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:3272
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define ZeroMemory
Definition: winbase.h:1712
#define MIIM_ID
Definition: winuser.h:725
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:747
#define MIIM_STATE
Definition: winuser.h:724
#define MFT_STRING
Definition: winuser.h:749
#define MIIM_TYPE
Definition: winuser.h:728
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 1793 of file CDefaultContextMenu.cpp.

1794{
1795 return ShellObjectCreatorInit<CDefaultContextMenu>(pdcm, lpfn, riid, ppv);
1796}
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 1826 of file CDefaultContextMenu.cpp.

1836{
1837 DEFCONTEXTMENU dcm;
1838 dcm.hwnd = hwnd;
1839 dcm.pcmcb = NULL;
1840 dcm.pidlFolder = pidlFolder;
1841 dcm.psf = psf;
1842 dcm.cidl = cidl;
1843 dcm.apidl = apidl;
1845 dcm.cKeys = nKeys;
1846 dcm.aKeys = ahkeyClsKeys;
1847
1850 return hr;
1851
1852 return S_OK;
1853}
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:2550
IShellFolder * psf
Definition: shlobj.h:2552
IUnknown * punkAssociationInfo
Definition: shlobj.h:2555
PCUITEMID_CHILD_ARRAY apidl
Definition: shlobj.h:2554
const HKEY * aKeys
Definition: shlobj.h:2557
PCIDLIST_ABSOLUTE pidlFolder
Definition: shlobj.h:2551
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
#define IID_PPV_ARG(Itype, ppType)

Referenced by _CFontMenu_CreateInstance(), CDrivesContextMenu_CreateInstance(), CRegItemContextMenu_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 383 of file CDefaultContextMenu.cpp.

384{
385 BOOL bRet = FALSE;
386 CComPtr<IDataObject> pDataObj;
387
388 if (SUCCEEDED(OleGetClipboard(&pDataObj)))
389 {
390 FORMATETC formatetc;
391
392 TRACE("pDataObj=%p\n", pDataObj.p);
393
394 /* Set the FORMATETC structure*/
395 InitFormatEtc(formatetc, RegisterClipboardFormatW(CFSTR_SHELLIDLIST), TYMED_HGLOBAL);
396 bRet = SUCCEEDED(pDataObj->QueryGetData(&formatetc));
397 }
398
399 return bRet;
400}
#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 1805 of file CDefaultContextMenu.cpp.

1806{
1807 HRESULT hr;
1808
1809 if (!ppv)
1810 return E_INVALIDARG;
1811
1814 return hr;
1815
1816 return S_OK;
1817}
#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 1699 of file CDefaultContextMenu.cpp.

1700{
1701 if (uMsg == WM_DRAWITEM)
1702 {
1703 DRAWITEMSTRUCT* pDrawStruct = reinterpret_cast<DRAWITEMSTRUCT*>(lParam);
1704 *CmdId = pDrawStruct->itemID;
1705 return S_OK;
1706 }
1707 else if (uMsg == WM_MEASUREITEM)
1708 {
1709 MEASUREITEMSTRUCT* pMeasureStruct = reinterpret_cast<MEASUREITEMSTRUCT*>(lParam);
1710 *CmdId = pMeasureStruct->itemID;
1711 return S_OK;
1712 }
1713
1714 return E_FAIL;
1715}
LPARAM lParam
Definition: combotst.c:139
#define E_FAIL
Definition: ddrawi.h:102
#define WM_DRAWITEM
Definition: winuser.h:1648
#define WM_MEASUREITEM
Definition: winuser.h:1649

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

◆ SHSetMenuIdInMenuMsg()

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

Definition at line 1717 of file CDefaultContextMenu.cpp.

1718{
1719 if (uMsg == WM_DRAWITEM)
1720 {
1721 DRAWITEMSTRUCT* pDrawStruct = reinterpret_cast<DRAWITEMSTRUCT*>(lParam);
1722 pDrawStruct->itemID = CmdId;
1723 return S_OK;
1724 }
1725 else if (uMsg == WM_MEASUREITEM)
1726 {
1727 MEASUREITEMSTRUCT* pMeasureStruct = reinterpret_cast<MEASUREITEMSTRUCT*>(lParam);
1728 pMeasureStruct->itemID = CmdId;
1729 return S_OK;
1730 }
1731
1732 return E_FAIL;
1733}

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:2608
#define DFM_CMD_NEWFOLDER
Definition: shlobj.h:2613
#define DFM_CMD_COPY
Definition: shlobj.h:2610
#define DFM_CMD_PASTE
Definition: shlobj.h:2614
#define DFM_CMD_PROPERTIES
Definition: shlobj.h:2612
#define DFM_CMD_RENAME
Definition: shlobj.h:2620
#define DFM_CMD_LINK
Definition: shlobj.h:2611
#define FCIDM_SHVIEW_CUT
Definition: shresdef.h:829
#define FCIDM_SHVIEW_OPEN
Definition: shresdef.h:856
#define FCIDM_SHVIEW_COPY
Definition: shresdef.h:830
#define FCIDM_SHVIEW_NEWFOLDER
Definition: shresdef.h:852
#define FCIDM_SHVIEW_PROPERTIES
Definition: shresdef.h:828
#define FCIDM_SHVIEW_COPYTO
Definition: shresdef.h:834
#define FCIDM_SHVIEW_MOVETO
Definition: shresdef.h:835
#define FCIDM_SHVIEW_DELETE
Definition: shresdef.h:827
#define FCIDM_SHVIEW_RENAME
Definition: shresdef.h:849
#define FCIDM_SHVIEW_CREATELINK
Definition: shresdef.h:850
#define FCIDM_SHVIEW_INSERT
Definition: shresdef.h:831

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