ReactOS 0.4.16-dev-306-g647d351
shldataobject.cpp
Go to the documentation of this file.
1/*
2 * PROJECT: shell32
3 * LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
4 * PURPOSE: SHGetAttributesFromDataObject implementation
5 * COPYRIGHT: Copyright 2021 Mark Jansen <mark.jansen@reactos.org>
6 */
7
8
9#include "precomp.h"
10
12
13
14static CLIPFORMAT g_DataObjectAttributes = 0;
15static const DWORD dwDefaultAttributeMask = SFGAO_CANCOPY | SFGAO_CANMOVE | SFGAO_STORAGE | SFGAO_CANRENAME |
16 SFGAO_CANDELETE | SFGAO_READONLY | SFGAO_STREAM | SFGAO_FOLDER;
17
19{
23};
24
25static_assert(sizeof(DataObjectAttributes) == 0xc, "Unexpected struct size!");
26
27
28static
30{
31 return SHBindToObject(NULL, pidl, IID_PPV_ARG(IShellFolder, &spFolder));
32}
33
35HRESULT WINAPI SHGetAttributesFromDataObject(IDataObject* pDataObject, DWORD dwAttributeMask, DWORD* pdwAttributes, UINT* pcItems)
36{
38 DWORD cItems = 0;
39 HRESULT hr = S_OK;
40
41 TRACE("(%p, 0x%x, %p, %p)\n", pDataObject, dwAttributeMask, pdwAttributes, pcItems);
42
44 g_DataObjectAttributes = (CLIPFORMAT)RegisterClipboardFormatW(L"DataObjectAttributes");
45
46 if (pDataObject)
47 {
49 if (FAILED(DataObject_GetData(pDataObject, g_DataObjectAttributes, &data, sizeof(data))))
50 {
51 TRACE("No attributes yet, creating new\n");
52 memset(&data, 0, sizeof(data));
53 }
54
55 DWORD dwQueryAttributes = dwAttributeMask | dwDefaultAttributeMask;
56
57 if ((data.dwMask & dwQueryAttributes) != dwQueryAttributes)
58 {
59 CDataObjectHIDA hida(pDataObject);
60 CComPtr<IShellFolder> spFolder;
61
62 if (!FAILED_UNEXPECTEDLY(hr = hida.hr()) &&
64 {
66 for (UINT n = 0; n < hida->cidl; ++n)
67 {
68 apidl.Add(HIDA_GetPIDLItem(hida, n));
69 }
70
71 SFGAOF rgfInOut = dwQueryAttributes;
72 hr = spFolder->GetAttributesOf(apidl.GetSize(), apidl.GetData(), &rgfInOut);
74 {
75 data.dwMask = dwQueryAttributes;
76 // Only store what we asked for
77 data.dwAttributes = rgfInOut & dwQueryAttributes;
78 data.cItems = apidl.GetSize();
79
80 hr = DataObject_SetData(pDataObject, g_DataObjectAttributes, &data, sizeof(data));
82 }
83 }
84 }
85
86 // Only give the user what they asked for, not everything else we have!
87 dwAttributes = data.dwAttributes & dwAttributeMask;
88 cItems = data.cItems;
89 }
90
91 if (pdwAttributes)
92 *pdwAttributes = dwAttributes;
93
94 if (pcItems)
95 *pcItems = cItems;
96
97 return hr;
98}
99
101{
102 if (Index < pCIDA->cidl)
103 return ILCombine(HIDA_GetPIDLFolder(pCIDA), HIDA_GetPIDLItem(pCIDA, Index));
104 return NULL;
105}
106
108{
109 if (!pDO)
110 return NULL;
111 CDataObjectHIDA cida(pDO);
112 return SUCCEEDED(cida.hr()) ? SHELL_CIDA_ILCloneFull(cida, Index) : NULL;
113}
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
void shell(int argc, const char *argv[])
Definition: cmds.c:1231
#define EXTERN_C
Definition: basetyps.h:12
#define NULL
Definition: types.h:112
static HRESULT WINAPI DataObject_GetData(LPDATAOBJECT iface, LPFORMATETC pformatetcIn, STGMEDIUM *pmedium)
Definition: view.c:175
static HRESULT WINAPI DataObject_SetData(LPDATAOBJECT iface, LPFORMATETC pformatetc, STGMEDIUM *pmedium, BOOL fRelease)
Definition: view.c:203
#define FAILED_UNEXPECTEDLY(hr)
Definition: precomp.h:121
EXTERN_C HRESULT SHBindToObject(_In_opt_ IShellFolder *psf, _In_ LPCITEMIDLIST pidl, _In_ REFIID riid, _Out_ void **ppvObj)
Definition: utils.cpp:253
static IShellFolder IShellItem **static IBindCtx LPITEMIDLIST SFGAOF
Definition: ebrowser.c:83
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLdouble n
Definition: glext.h:7729
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define FAILED(hr)
Definition: intsafe.h:51
static int int const SCRIPT_CONTROL const SCRIPT_STATE SCRIPT_ITEM ULONG int * pcItems
Definition: usp10.c:62
unsigned int UINT
Definition: ndis.h:50
#define _In_
Definition: no_sal2.h:158
#define L(x)
Definition: ntvdm.h:50
LPITEMIDLIST WINAPI ILCombine(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
Definition: pidl.c:814
#define memset(x, y, z)
Definition: compat.h:39
static PCUIDLIST_RELATIVE HIDA_GetPIDLItem(CIDA const *pida, SIZE_T i)
Definition: shellutils.h:637
static PCUIDLIST_ABSOLUTE HIDA_GetPIDLFolder(CIDA const *pida)
Definition: shellutils.h:632
static HRESULT _BindToObject(PCUIDLIST_ABSOLUTE pidl, CComPtr< IShellFolder > &spFolder)
static const DWORD dwDefaultAttributeMask
PIDLIST_ABSOLUTE SHELL_CIDA_ILCloneFull(_In_ const CIDA *pCIDA, _In_ UINT Index)
EXTERN_C HRESULT WINAPI SHGetAttributesFromDataObject(IDataObject *pDataObject, DWORD dwAttributeMask, DWORD *pdwAttributes, UINT *pcItems)
PIDLIST_ABSOLUTE SHELL_DataObject_ILCloneFullItem(_In_ IDataObject *pDO, _In_ UINT Index)
static CLIPFORMAT g_DataObjectAttributes
HRESULT hr
Definition: shlfolder.c:183
const ITEMIDLIST_ABSOLUTE UNALIGNED * PCUIDLIST_ABSOLUTE
Definition: shtypes.idl:63
#define TRACE(s)
Definition: solgame.cpp:4
Definition: shlobj.h:572
DWORD dwAttributes
Definition: vdmdbg.h:34
_In_ WDFCOLLECTION _In_ ULONG Index
#define WINAPI
Definition: msvc.h:6
UINT WINAPI RegisterClipboardFormatW(_In_ LPCWSTR)
#define IID_PPV_ARG(Itype, ppType)