ReactOS 0.4.16-dev-109-gf4cb10f
CCopyAsPathMenu.cpp
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS shell32
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: Copy as Path Menu implementation
5 * COPYRIGHT: Copyright 2024 Whindmar Saksit <whindsaks@proton.me>
6 * Copyright 2024 Thamatip Chitpong <thamatip.chitpong@reactos.org>
7 */
8
9#include "precomp.h"
10
12
13#define IDC_COPYASPATH 0
14
16{
17}
18
20{
21}
22
23static DWORD
25{
26 BOOL succ = FALSE;
28 if (handle)
29 {
30 LPVOID clipdata = GlobalLock(handle);
31 if (clipdata)
32 {
33 CopyMemory(clipdata, data, size);
36 {
38 succ = SetClipboardData(cf, handle) != NULL;
40 }
41 }
42 if (!succ)
43 {
45 }
46 }
47 return succ ? ERROR_SUCCESS : GetLastError();
48}
49
50static DWORD
52{
53 SIZE_T cch = lstrlenW(str) + 1, size = cch * sizeof(WCHAR);
54 if (size > cch)
56 else
58}
59
60static void
62{
63 if (index)
64 paths += L"\r\n";
65 LPCWSTR quote = StrChrW(path, L' ');
66 if (quote)
67 paths += L'\"';
68 paths += path;
69 if (quote)
70 paths += L'\"';
71}
72
75{
77 DWORD i, count;
80 if (SUCCEEDED(hr))
81 {
82 for (i = 0, array->GetCount(&count); i < count && SUCCEEDED(hr); ++i)
83 {
85 hr = array->GetItemAt(i, &item);
86 if (SUCCEEDED(hr))
87 {
89 hr = item->GetDisplayName(SIGDN_DESKTOPABSOLUTEPARSING, &path);
90 if (SUCCEEDED(hr))
91 {
93 }
94 }
95 }
96 }
97 if (SUCCEEDED(hr))
98 {
101 }
102
103 return hr;
104}
105
107CCopyAsPathMenu::QueryContextMenu(HMENU hMenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags)
108{
109 MENUITEMINFOW mii;
110
111 TRACE("CCopyAsPathMenu::QueryContextMenu(%p %p %u %u %u %u)\n", this,
112 hMenu, indexMenu, idCmdFirst, idCmdLast, uFlags);
113
114 if ((uFlags & CMF_NOVERBS) || !(uFlags & CMF_EXTENDEDVERBS))
115 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, 0);
116
117 // Insert "Copy as path"
119 ZeroMemory(&mii, sizeof(mii));
120 mii.cbSize = sizeof(mii);
121 mii.fMask = MIIM_ID | MIIM_TYPE;
122 mii.fType = MFT_STRING;
123 mii.wID = idCmdFirst + IDC_COPYASPATH;
124 mii.dwTypeData = strText.GetBuffer();
125 if (InsertMenuItemW(hMenu, indexMenu, TRUE, &mii))
126 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, mii.wID - idCmdFirst + 1);
127
128 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, 0);
129}
130
133{
134 TRACE("CCopyAsPathMenu::InvokeCommand(%p %p)\n", this, lpcmi);
135
136 if (IS_INTRESOURCE(lpcmi->lpVerb) && LOWORD(lpcmi->lpVerb) == IDC_COPYASPATH)
138
139 return E_FAIL;
140}
141
143CCopyAsPathMenu::GetCommandString(UINT_PTR idCommand, UINT uFlags, UINT *lpReserved, LPSTR lpszName, UINT uMaxNameLen)
144{
145 FIXME("CCopyAsPathMenu::GetCommandString(%p %lu %u %p %p %u)\n", this,
146 idCommand, uFlags, lpReserved, lpszName, uMaxNameLen);
147
148 return E_NOTIMPL;
149}
150
153{
154 m_pDataObject = pdtobj;
155 return S_OK;
156}
#define IDC_COPYASPATH
static DWORD SetClipboard(UINT cf, const void *data, SIZE_T size)
static DWORD SetClipboardFromString(LPCWSTR str)
static void AppendToPathList(CStringW &paths, LPCWSTR path, DWORD index)
EXTERN_C HRESULT WINAPI SHCreateShellItemArrayFromDataObject(_In_ IDataObject *pdo, _In_ REFIID riid, _Out_ void **ppv)
Definition: CShellItem.cpp:429
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define CF_UNICODETEXT
Definition: constants.h:408
void shell(int argc, const char *argv[])
Definition: cmds.c:1231
#define FIXME(fmt,...)
Definition: precomp.h:53
#define STDMETHODIMP
Definition: basetyps.h:43
CComPtr< IDataObject > m_pDataObject
STDMETHODIMP GetCommandString(UINT_PTR idCommand, UINT uFlags, UINT *lpReserved, LPSTR lpszName, UINT uMaxNameLen) override
STDMETHODIMP InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi) override
STDMETHODIMP Initialize(PCIDLIST_ABSOLUTE pidlFolder, IDataObject *pdtobj, HKEY hkeyProgID) override
STDMETHODIMP QueryContextMenu(HMENU hMenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags) override
HRESULT DoCopyAsPath(IDataObject *pdto)
#define E_NOTIMPL
Definition: ddrawi.h:99
#define E_FAIL
Definition: ddrawi.h:102
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
static const WCHAR quote[]
Definition: reg.c:40
UINT uFlags
Definition: api.c:59
LPWSTR WINAPI StrChrW(LPCWSTR lpszStr, WCHAR ch)
Definition: string.c:464
#define lstrlenW
Definition: compat.h:750
#define MAKE_HRESULT(sev, fac, code)
Definition: dmerror.h:30
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLsizeiptr size
Definition: glext.h:5919
GLuint index
Definition: glext.h:6031
GLsizei const GLuint * paths
Definition: glext.h:11717
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
LPVOID NTAPI GlobalLock(HGLOBAL hMem)
Definition: heapmem.c:755
HGLOBAL NTAPI GlobalFree(HGLOBAL hMem)
Definition: heapmem.c:611
BOOL NTAPI GlobalUnlock(HGLOBAL hMem)
Definition: heapmem.c:1190
HGLOBAL NTAPI GlobalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:368
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
static DWORD DWORD void LPSTR DWORD cch
Definition: str.c:202
static const CLSID *static CLSID *static const GUID VARIANT VARIANT *static IServiceProvider DWORD *static HMENU
Definition: ordinal.c:63
static ATOM item
Definition: dde.c:856
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
unsigned int UINT
Definition: ndis.h:50
#define L(x)
Definition: ntvdm.h:50
#define LOWORD(l)
Definition: pedump.c:82
#define err(...)
const WCHAR * str
HRESULT hr
Definition: shlfolder.c:183
#define IDS_COPYASPATHMENU
Definition: shresdef.h:249
#define TRACE(s)
Definition: solgame.cpp:4
LPWSTR dwTypeData
Definition: winuser.h:3272
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define ZeroMemory
Definition: winbase.h:1712
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define CopyMemory
Definition: winbase.h:1710
#define GMEM_MOVEABLE
Definition: winbase.h:294
#define GMEM_SHARE
Definition: winbase.h:305
#define ERROR_BUFFER_OVERFLOW
Definition: winerror.h:185
#define SEVERITY_SUCCESS
Definition: winerror.h:64
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92
#define MIIM_ID
Definition: winuser.h:725
HANDLE WINAPI SetClipboardData(_In_ UINT, _In_opt_ HANDLE)
#define IS_INTRESOURCE(i)
Definition: winuser.h:580
BOOL WINAPI CloseClipboard(void)
Definition: ntwrapper.h:178
BOOL WINAPI OpenClipboard(_In_opt_ HWND)
BOOL WINAPI EmptyClipboard(void)
Definition: ntwrapper.h:190
#define MFT_STRING
Definition: winuser.h:749
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
#define MIIM_TYPE
Definition: winuser.h:728
BOOL WINAPI InsertMenuItemW(_In_ HMENU, _In_ UINT, _In_ BOOL, _In_ LPCMENUITEMINFOW)
#define IID_PPV_ARG(Itype, ppType)
char * LPSTR
Definition: xmlstorage.h:182
__wchar_t WCHAR
Definition: xmlstorage.h:180
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185