ReactOS 0.4.16-dev-1040-g85afe48
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-2021 Mark Jansen <mark.jansen@reactos.org>
6 */
7
8#include "precomp.h"
9
11
12#if 0
13static inline void DumpDataObjectFormats(IDataObject* pObject)
14{
16 HRESULT hr = pObject->EnumFormatEtc(DATADIR_GET, &pEnumFmt);
17
19 return;
20
21 FORMATETC fmt;
22 while (S_OK == pEnumFmt->Next(1, &fmt, NULL))
23 {
24 char szBuf[512];
25 GetClipboardFormatNameA(fmt.cfFormat, szBuf, sizeof(szBuf));
26 ERR("Format: %s\n", szBuf);
27 ERR("Tymed: %u\n", fmt.tymed);
28 if (fmt.tymed & TYMED_HGLOBAL)
29 {
30 ERR("TYMED_HGLOBAL supported\n");
31 }
32 }
33}
34#endif
35
37 REFIID riid, LPVOID* ppvOut)
38{
39 HRESULT hr = CIDLData_CreateFromIDArray(folder, cidl, apidl, (IDataObject**)ppvOut);
41 return hr;
42
43 // Now that we have an IDataObject with the shell itemid list (CFSTR_SHELLIDLIST, aka HIDA) format
44 // we will augment this IDataObject with the CF_HDROP format. (Full filepaths)
45 // This enabled the objects for the 'copy' and drag to copy actions
46
48
49 // First we allocate room for the DROPFILES structure
50 data.AllocateBytes(sizeof(DROPFILES));
51 UINT offset = sizeof(DROPFILES);
52
53 // Then we walk all files
54 for (UINT n = 0; n < cidl; ++n)
55 {
56 const FontPidlEntry* fontEntry = _FontFromIL(apidl[n]);
57 if (fontEntry)
58 {
59 CStringW File = g_FontCache->Filename(g_FontCache->Find(fontEntry), true);
60 if (!File.IsEmpty())
61 {
62 // Now append the path (+ nullterminator) to the buffer
63 UINT len = offset + (File.GetLength() + 1) * sizeof(WCHAR);
64 data.ReallocateBytes(len);
65 if (!data)
66 {
67 ERR("Unable to allocate memory for the CF_HDROP\n");
68 return hr;
69 }
70 BYTE* dataPtr = data;
72 offset = len;
73 }
74 else
75 {
76 ERR("No file found for %S\n", fontEntry->Name);
77 }
78 }
79 }
80
81 // Append the final nullterminator (double null terminated list)
82 data.ReallocateBytes(offset + sizeof(UNICODE_NULL));
85 offset += sizeof(UNICODE_NULL);
86
87 // Fill in the required fields
88 DROPFILES* pDrop = (DROPFILES*)(BYTE*)data;
89 pDrop->fWide = 1;
90 pDrop->pFiles = sizeof(DROPFILES);
91 // Zero out the rest
92 pDrop->pt.x = pDrop->pt.y = 0;
93 pDrop-> fNC = NULL;
94
97
98 return hr;
99}
HRESULT _CDataObject_CreateInstance(PCIDLIST_ABSOLUTE folder, UINT cidl, PCUITEMID_CHILD_ARRAY apidl, REFIID riid, LPVOID *ppvOut)
Definition: CDataObject.cpp:36
CFontCache * g_FontCache
Definition: CFontCache.cpp:12
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define CF_HDROP
Definition: constants.h:410
#define ERR(fmt,...)
Definition: precomp.h:57
CStringW Filename(CFontInfo *info, bool alwaysFullPath=false)
Definition: CFontCache.cpp:164
CFontInfo * Find(const FontPidlEntry *fontEntry)
Definition: CFontCache.cpp:145
Definition: File.h:16
#define NULL
Definition: types.h:112
static HRESULT WINAPI DataObject_SetData(LPDATAOBJECT iface, LPFORMATETC pformatetc, STGMEDIUM *pmedium, BOOL fRelease)
Definition: view.c:203
#define FAILED_UNEXPECTEDLY(hr)
Definition: debug.h:83
const FontPidlEntry * _FontFromIL(LPCITEMIDLIST pidl)
Definition: fontpidl.cpp:31
FxObject * pObject
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLdouble n
Definition: glext.h:7729
GLintptr offset
Definition: glext.h:5920
GLenum GLsizei len
Definition: glext.h:6722
REFIID riid
Definition: atlbase.h:39
#define S_OK
Definition: intsafe.h:52
unsigned int UINT
Definition: ndis.h:50
#define UNICODE_NULL
wchar_t * STRSAFE_LPWSTR
Definition: ntstrsafe.h:53
#define REFIID
Definition: guiddef.h:118
const WCHAR * str
HRESULT WINAPI CIDLData_CreateFromIDArray(PCIDLIST_ABSOLUTE pidlFolder, UINT cpidlFiles, PCUIDLIST_RELATIVE_ARRAY lppidlFiles, LPDATAOBJECT *ppdataObject)
Definition: shellord.c:2419
HRESULT hr
Definition: shlfolder.c:183
struct _DROPFILES DROPFILES
const PCUITEMID_CHILD * PCUITEMID_CHILD_ARRAY
Definition: shtypes.idl:71
STRSAFEAPI StringCbCopyW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:166
WCHAR Name[1]
Definition: fontpidl.hpp:17
DWORD pFiles
Definition: shlobj.h:2315
BOOL fWide
Definition: shlobj.h:2318
POINT pt
Definition: shlobj.h:2316
Definition: dsound.c:943
Definition: fci.c:116
long y
Definition: polytest.cpp:48
long x
Definition: polytest.cpp:48
int WINAPI GetClipboardFormatNameA(_In_ UINT format, _Out_writes_(cchMaxCount) LPSTR lpszFormatName, _In_ int cchMaxCount)
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184
unsigned char BYTE
Definition: xxhash.c:193