ReactOS 0.4.15-dev-6669-g8227c5d
CRecyclerDropTarget.cpp
Go to the documentation of this file.
1/*
2 * Trash virtual folder support. The trashing engine is implemented in trash.c
3 *
4 * Copyright (C) 2006 Mikolaj Zalewski
5 * Copyright (C) 2009 Andrew Hill
6 * Copyright (C) 2017 Giannis Adamopoulos
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 */
22
23#include <precomp.h>
24
26
28 public CComObjectRootEx<CComMultiThreadModelNoCS>,
29 public IDropTarget
30{
31 private:
32 BOOL fAcceptFmt; /* flag for pending Drop */
34
36 {
37 HRESULT hr;
38 STGMEDIUM medium;
39 FORMATETC formatetc;
40 InitFormatEtc (formatetc, CF_HDROP, TYMED_HGLOBAL);
41 hr = pda->GetData(&formatetc, &medium);
43 return hr;
44
45 LPDROPFILES lpdf = (LPDROPFILES) GlobalLock(medium.hGlobal);
46 if (!lpdf)
47 {
48 ERR("Error locking global\n");
49 ReleaseStgMedium(&medium);
50 return E_FAIL;
51 }
52
53 /* Delete them */
54 SHFILEOPSTRUCTW FileOp;
55 ZeroMemory(&FileOp, sizeof(FileOp));
56 FileOp.wFunc = FO_DELETE;
57 FileOp.pFrom = (LPWSTR) (((byte*) lpdf) + lpdf->pFiles);;
58 if ((fMask & CMIC_MASK_SHIFT_DOWN) == 0)
59 FileOp.fFlags = FOF_ALLOWUNDO;
60 TRACE("Deleting file (just the first) = %s, allowundo: %d\n", debugstr_w(FileOp.pFrom), (FileOp.fFlags == FOF_ALLOWUNDO));
61
62 int res = SHFileOperationW(&FileOp);
63 if (res)
64 {
65 ERR("SHFileOperation failed with 0x%x\n", res);
66 hr = E_FAIL;
67 }
68
69 GlobalUnlock(medium.hGlobal);
70 ReleaseStgMedium(&medium);
71
72 return hr;
73 }
74
78 };
79
81 {
82 DeleteThreadData *data = static_cast<DeleteThreadData*>(lpParameter);
84 IDataObject *pDataObject;
86 if (SUCCEEDED(hr))
87 {
88 _DoDeleteDataObject(pDataObject, data->fMask);
89 }
90 pDataObject->Release();
93 return 0;
94 }
95
96 static void _DoDeleteAsync(IDataObject *pda, DWORD fMask)
97 {
99 data->fMask = fMask;
102 }
103
104 public:
105
107 {
110 }
111
113 DWORD dwKeyState, POINTL pt, DWORD *pdwEffect)
114 {
115 TRACE("Recycle bin drag over (%p)\n", this);
116 /* The recycle bin accepts pretty much everything, and sets a CSIDL flag. */
118
119 *pdwEffect = DROPEFFECT_MOVE;
120 return S_OK;
121 }
122
123 HRESULT WINAPI DragOver(DWORD dwKeyState, POINTL pt, DWORD *pdwEffect)
124 {
125 TRACE("(%p)\n", this);
126
127 if (!pdwEffect)
128 return E_INVALIDARG;
129
130 *pdwEffect = DROPEFFECT_MOVE;
131
132 return S_OK;
133 }
134
136 {
137 TRACE("(%p)\n", this);
138
140
141 return S_OK;
142 }
143
145 DWORD grfKeyState, POINTL pt, DWORD *pdwEffect)
146 {
147 TRACE("(%p) object dropped on recycle bin, effect %u\n", this, *pdwEffect);
148
149 FORMATETC fmt;
150 TRACE("(%p)->(DataObject=%p)\n", this, pDataObject);
151 InitFormatEtc (fmt, cfShellIDList, TYMED_HGLOBAL);
152
153 /* Handle cfShellIDList Drop objects here, otherwise send the appropriate message to other software */
154 if (SUCCEEDED(pDataObject->QueryGetData(&fmt)))
155 {
156 DWORD fMask = 0;
157
158 if ((grfKeyState & MK_SHIFT) == MK_SHIFT)
159 fMask |= CMIC_MASK_SHIFT_DOWN;
160
161 _DoDeleteAsync(pDataObject, fMask);
162 }
163 else
164 {
165 /*
166 * TODO call SetData on the data object with format CFSTR_TARGETCLSID
167 * set to the Recycle Bin's class identifier CLSID_RecycleBin.
168 */
169 }
170 return S_OK;
171 }
172
174
176
178 COM_INTERFACE_ENTRY_IID(IID_IDropTarget, IDropTarget)
180};
181
183{
184 return ShellObjectCreator<CRecyclerDropTarget>(riid, ppvOut);
185}
HRESULT CRecyclerDropTarget_CreateInstance(REFIID riid, LPVOID *ppvOut)
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define CF_HDROP
Definition: constants.h:410
void shell(int argc, const char *argv[])
Definition: cmds.c:1231
#define ERR(fmt,...)
Definition: debug.h:110
HRESULT WINAPI DragLeave()
HRESULT WINAPI DragOver(DWORD dwKeyState, POINTL pt, DWORD *pdwEffect)
static HRESULT _DoDeleteDataObject(IDataObject *pda, DWORD fMask)
HRESULT WINAPI Drop(IDataObject *pDataObject, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect)
HRESULT WINAPI DragEnter(IDataObject *pDataObject, DWORD dwKeyState, POINTL pt, DWORD *pdwEffect)
static DWORD WINAPI _DoDeleteThreadProc(LPVOID lpParameter)
static void _DoDeleteAsync(IDataObject *pda, DWORD fMask)
#define E_INVALIDARG
Definition: ddrawi.h:101
#define E_FAIL
Definition: ddrawi.h:102
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
HRESULT WINAPI CoInitialize(LPVOID lpReserved)
Definition: compobj.c:1964
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:2067
HRESULT WINAPI CoMarshalInterThreadInterfaceInStream(REFIID riid, LPUNKNOWN pUnk, LPSTREAM *ppStm)
Definition: marshal.c:2100
HRESULT WINAPI CoGetInterfaceAndReleaseStream(LPSTREAM pStm, REFIID riid, LPVOID *ppv)
Definition: marshal.c:2144
void WINAPI ReleaseStgMedium(STGMEDIUM *pmedium)
Definition: ole2.c:2033
BOOL WINAPI SHCreateThread(LPTHREAD_START_ROUTINE pfnThreadProc, VOID *pData, DWORD dwFlags, LPTHREAD_START_ROUTINE pfnCallback)
Definition: thread.c:356
#define pt(x, y)
Definition: drawing.c:79
#define InitFormatEtc(fe, cf, med)
Definition: editor.h:32
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLuint res
Definition: glext.h:9613
LPVOID NTAPI GlobalLock(HGLOBAL hMem)
Definition: heapmem.c:755
BOOL NTAPI GlobalUnlock(HGLOBAL hMem)
Definition: heapmem.c:1190
REFIID riid
Definition: atlbase.h:39
HRESULT GetData([in, unique] FORMATETC *pformatetcIn, [out] STGMEDIUM *pmedium)
HRESULT QueryGetData([in, unique] FORMATETC *pformatetc)
const DWORD DROPEFFECT_MOVE
Definition: oleidl.idl:931
ULONG Release()
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define debugstr_w
Definition: kernel32.h:32
#define BEGIN_COM_MAP(x)
Definition: atlcom.h:581
#define COM_INTERFACE_ENTRY_IID(iid, x)
Definition: atlcom.h:601
#define DECLARE_PROTECT_FINAL_CONSTRUCT()
Definition: atlcom.h:679
#define DECLARE_NOT_AGGREGATABLE(x)
Definition: atlcom.h:651
#define END_COM_MAP()
Definition: atlcom.h:592
unsigned int UINT
Definition: ndis.h:50
const GUID IID_IDataObject
#define REFIID
Definition: guiddef.h:118
#define FOF_ALLOWUNDO
Definition: shellapi.h:144
#define FO_DELETE
Definition: shellapi.h:135
#define FAILED_UNEXPECTEDLY(hr)
Definition: shellutils.h:82
int WINAPI SHFileOperationW(LPSHFILEOPSTRUCTW lpFileOp)
Definition: shlfileop.cpp:2035
HRESULT hr
Definition: shlfolder.c:183
#define CFSTR_SHELLIDLIST
Definition: shlobj.h:481
struct _DROPFILES * LPDROPFILES
#define TRACE(s)
Definition: solgame.cpp:4
DWORD pFiles
Definition: shlobj.h:2163
LPCWSTR pFrom
Definition: shellapi.h:354
FILEOP_FLAGS fFlags
Definition: shellapi.h:356
Definition: dsound.c:943
#define ZeroMemory
Definition: winbase.h:1700
#define WINAPI
Definition: msvc.h:6
#define MK_SHIFT
Definition: winuser.h:2359
UINT WINAPI RegisterClipboardFormatW(_In_ LPCWSTR)
#define IID_PPV_ARG(Itype, ppType)
WCHAR * LPWSTR
Definition: xmlstorage.h:184