ReactOS 0.4.15-dev-7906-g1b85a5f
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 CComPtr<IShellFolder> spDesktop;
32 HRESULT hr = SHGetDesktopFolder(&spDesktop);
33 if (FAILED(hr))
34 return hr;
35
36 return spDesktop->BindToObject(pidl, NULL, IID_PPV_ARG(IShellFolder, &spFolder));
37}
38
40HRESULT WINAPI SHGetAttributesFromDataObject(IDataObject* pDataObject, DWORD dwAttributeMask, DWORD* pdwAttributes, UINT* pcItems)
41{
43 DWORD cItems = 0;
44 HRESULT hr = S_OK;
45
46 TRACE("(%p, 0x%x, %p, %p)\n", pDataObject, dwAttributeMask, pdwAttributes, pcItems);
47
49 g_DataObjectAttributes = (CLIPFORMAT)RegisterClipboardFormatW(L"DataObjectAttributes");
50
51 if (pDataObject)
52 {
54 if (FAILED(DataObject_GetData(pDataObject, g_DataObjectAttributes, &data, sizeof(data))))
55 {
56 TRACE("No attributes yet, creating new\n");
57 memset(&data, 0, sizeof(data));
58 }
59
60 DWORD dwQueryAttributes = dwAttributeMask | dwDefaultAttributeMask;
61
62 if ((data.dwMask & dwQueryAttributes) != dwQueryAttributes)
63 {
64 CDataObjectHIDA hida(pDataObject);
65 CComPtr<IShellFolder> spFolder;
66
67 if (!FAILED_UNEXPECTEDLY(hr = hida.hr()) &&
69 {
71 for (UINT n = 0; n < hida->cidl; ++n)
72 {
73 apidl.Add(HIDA_GetPIDLItem(hida, n));
74 }
75
76 SFGAOF rgfInOut = dwQueryAttributes;
77 hr = spFolder->GetAttributesOf(apidl.GetSize(), apidl.GetData(), &rgfInOut);
79 {
80 data.dwMask = dwQueryAttributes;
81 // Only store what we asked for
82 data.dwAttributes = rgfInOut & dwQueryAttributes;
83 data.cItems = apidl.GetSize();
84
85 hr = DataObject_SetData(pDataObject, g_DataObjectAttributes, &data, sizeof(data));
87 }
88 }
89 }
90
91 // Only give the user what they asked for, not everything else we have!
92 dwAttributes = data.dwAttributes & dwAttributeMask;
93 cItems = data.cItems;
94 }
95
96 if (pdwAttributes)
97 *pdwAttributes = dwAttributes;
98
99 if (pcItems)
100 *pcItems = cItems;
101
102 return hr;
103}
HRESULT WINAPI SHGetDesktopFolder(IShellFolder **psf)
#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
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 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 L(x)
Definition: ntvdm.h:50
#define memset(x, y, z)
Definition: compat.h:39
static PCUIDLIST_RELATIVE HIDA_GetPIDLItem(CIDA const *pida, SIZE_T i)
Definition: shellutils.h:591
static PCUIDLIST_ABSOLUTE HIDA_GetPIDLFolder(CIDA const *pida)
Definition: shellutils.h:586
static HRESULT _BindToObject(PCUIDLIST_ABSOLUTE pidl, CComPtr< IShellFolder > &spFolder)
static const DWORD dwDefaultAttributeMask
EXTERN_C HRESULT WINAPI SHGetAttributesFromDataObject(IDataObject *pDataObject, DWORD dwAttributeMask, DWORD *pdwAttributes, UINT *pcItems)
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
DWORD dwAttributes
Definition: vdmdbg.h:34
#define WINAPI
Definition: msvc.h:6
UINT WINAPI RegisterClipboardFormatW(_In_ LPCWSTR)
#define IID_PPV_ARG(Itype, ppType)