ReactOS  0.4.15-dev-1197-g8081ba9
CDataObject.cpp
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Font Shell Extension
3  * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4  * PURPOSE: CFontMenu implementation
5  * COPYRIGHT: Copyright 2019,2020 Mark Jansen (mark.jansen@reactos.org)
6  */
7 
8 #include "precomp.h"
9 
11 
12 
13 #if 0
14 static inline void DumpDataObjectFormats(IDataObject* pObject)
15 {
16  CComPtr<IEnumFORMATETC> pEnumFmt;
17  HRESULT hr = pObject->EnumFormatEtc(DATADIR_GET, &pEnumFmt);
18 
20  return;
21 
22  FORMATETC fmt;
23  while (S_OK == pEnumFmt->Next(1, &fmt, NULL))
24  {
25  char szBuf[512];
26  GetClipboardFormatNameA(fmt.cfFormat, szBuf, sizeof(szBuf));
27  ERR("Format: %s\n", szBuf);
28  ERR("Tymed: %u\n", fmt.tymed);
29  if (fmt.tymed & TYMED_HGLOBAL)
30  {
31  ERR("TYMED_HGLOBAL supported\n");
32  }
33  }
34 }
35 #endif
36 
37 
39  REFIID riid, LPVOID* ppvOut)
40 {
41  HRESULT hr = CIDLData_CreateFromIDArray(folder, cidl, apidl, (IDataObject**)ppvOut);
43  return hr;
44 
45  // Now that we have an IDataObject with the shell itemid list (CFSTR_SHELLIDLIST, aka HIDA) format
46  // we will augment this IDataObject with the CF_HDROP format. (Full filepaths)
47  // This enabled the objects for the 'copy' and drag to copy actions
48 
50 
51  // First we allocate room for the DROPFILES structure
52  data.AllocateBytes(sizeof(DROPFILES));
53  UINT offset = sizeof(DROPFILES);
54 
55  // Then we walk all files
56  for (UINT n = 0; n < cidl; ++n)
57  {
58  const FontPidlEntry* fontEntry = _FontFromIL(apidl[n]);
59  if (fontEntry)
60  {
61  CStringW File = g_FontCache->Filename(fontEntry, true);
62  if (!File.IsEmpty())
63  {
64  // Now append the path (+ nullterminator) to the buffer
65  UINT len = offset + (File.GetLength() + 1) * sizeof(WCHAR);
66  data.ReallocateBytes(len);
67  if (!data)
68  {
69  ERR("Unable to allocate memory for the CF_HDROP\n");
70  return hr;
71  }
72  BYTE* dataPtr = data;
74  offset = len;
75  }
76  else
77  {
78  ERR("No file found for %S\n", fontEntry->Name);
79  }
80  }
81  }
82 
83  // Append the final nullterminator (double null terminated list)
84  data.ReallocateBytes(offset + sizeof(UNICODE_NULL));
85  LPWSTR str = (LPWSTR)((BYTE*)data + offset);
86  *str = UNICODE_NULL;
87  offset += sizeof(UNICODE_NULL);
88 
89  // Fill in the required fields
90  DROPFILES* pDrop = (DROPFILES*)(BYTE*)data;
91  pDrop->fWide = 1;
92  pDrop->pFiles = sizeof(DROPFILES);
93  // Zero out the rest
94  pDrop->pt.x = pDrop->pt.y = 0;
95  pDrop-> fNC = NULL;
96 
97  // Prepare the format descriptors
98  STGMEDIUM medium = {0};
99  medium.tymed = TYMED_HGLOBAL;
100 
101  // Copy the data to an HGLOBAL
102  medium.hGlobal = GlobalAlloc(GHND, offset);
103  if (medium.hGlobal)
104  {
105  LPVOID blob = GlobalLock(medium.hGlobal);
106  if (blob)
107  {
109  GlobalUnlock(medium.hGlobal);
110 
111  CComPtr<IDataObject> spDataObject(*(IDataObject**)ppvOut);
112  if (spDataObject)
113  {
114  FORMATETC etc = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
115  hr = spDataObject->SetData(&etc, &medium, TRUE);
116  }
117  }
118  else
119  {
120  ERR("Unable to lock the hGlobal?!\n");
121  }
122  }
123  else
124  {
125  ERR("Unable to allocate %u bytes for the hGlobal\n", offset);
126  }
127 
128  return hr;
129 }
130 
#define REFIID
Definition: guiddef.h:118
HGLOBAL NTAPI GlobalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:368
Definition: fci.c:115
long y
Definition: polytest.cpp:48
HRESULT hr
Definition: shlfolder.c:183
Definition: image.c:133
POINT pt
Definition: shlobj.h:2125
long x
Definition: polytest.cpp:48
#define TRUE
Definition: types.h:120
REFIID riid
Definition: precomp.h:44
GLintptr offset
Definition: glext.h:5920
const char * fmt
Definition: wsprintf.c:30
GLdouble n
Definition: glext.h:7729
const FontPidlEntry * _FontFromIL(LPCITEMIDLIST pidl)
Definition: fontpidl.cpp:32
wchar_t * STRSAFE_LPWSTR
Definition: ntstrsafe.h:53
#define GHND
Definition: winbase.h:294
#define UNICODE_NULL
const PCUITEMID_CHILD * PCUITEMID_CHILD_ARRAY
Definition: shtypes.idl:71
const WCHAR * str
smooth NULL
Definition: ftsmooth.c:416
#define CF_HDROP
Definition: constants.h:410
HRESULT EnumFormatEtc([in] DWORD dwDirection, [out] IEnumFORMATETC **ppenumFormatEtc)
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:79
#define FAILED_UNEXPECTEDLY(hr)
Definition: shellutils.h:71
BOOL fWide
Definition: shlobj.h:2127
#define CopyMemory
Definition: winbase.h:1646
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
LPVOID NTAPI GlobalLock(HGLOBAL hMem)
Definition: heapmem.c:755
GLenum GLsizei len
Definition: glext.h:6722
CFontCache * g_FontCache
Definition: CFontCache.cpp:12
WCHAR Name[1]
Definition: fontpidl.hpp:17
unsigned char BYTE
Definition: xxhash.c:193
#define ERR(fmt,...)
Definition: debug.h:110
#define S_OK
Definition: intsafe.h:51
CStringW Filename(const FontPidlEntry *fontEntry, bool alwaysFullPath=false)
Definition: CFontCache.cpp:96
unsigned int UINT
Definition: ndis.h:50
BOOL NTAPI GlobalUnlock(HGLOBAL hMem)
Definition: heapmem.c:1190
HRESULT _CDataObject_CreateInstance(PCIDLIST_ABSOLUTE folder, UINT cidl, PCUITEMID_CHILD_ARRAY apidl, REFIID riid, LPVOID *ppvOut)
Definition: CDataObject.cpp:38
Definition: File.h:15
HRESULT WINAPI CIDLData_CreateFromIDArray(PCIDLIST_ABSOLUTE pidlFolder, UINT cpidlFiles, PCUIDLIST_RELATIVE_ARRAY lppidlFiles, LPDATAOBJECT *ppdataObject)
Definition: shellord.c:2185
WCHAR * LPWSTR
Definition: xmlstorage.h:184
struct _DROPFILES DROPFILES
STRSAFEAPI StringCbCopyW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:166
DWORD pFiles
Definition: shlobj.h:2124
Definition: dsound.c:943
int WINAPI GetClipboardFormatNameA(_In_ UINT format, _Out_writes_(cchMaxCount) LPSTR lpszFormatName, _In_ int cchMaxCount)
WINE_DEFAULT_DEBUG_CHANNEL(fontext)