ReactOS 0.4.15-dev-8231-g29a56f3
CMyDocsDropHandler.cpp
Go to the documentation of this file.
1/*
2 * PROJECT: mydocs
3 * LICENSE: LGPL-2.1+ (https://spdx.org/licenses/LGPL-2.1+)
4 * PURPOSE: MyDocs implementation
5 * COPYRIGHT: Copyright 2020 Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com)
6 */
7
8#include "precomp.hpp"
9
11
13{
15}
16
18{
20}
21
22// IDropTarget
25 POINTL pt, DWORD *pdwEffect)
26{
27 TRACE("(%p)\n", this);
28
29 *pdwEffect &= DROPEFFECT_COPY; // Copy only
30
31 return S_OK;
32}
33
36{
37 TRACE("(%p)\n", this);
38
39 *pdwEffect &= DROPEFFECT_COPY; // Copy only
40
41 return S_OK;
42}
43
45{
46 TRACE("(%p)\n", this);
47 return S_OK;
48}
49
52 POINTL pt, DWORD *pdwEffect)
53{
54 TRACE("(%p)\n", this);
55
56 if (!pDataObject)
57 {
58 ERR("pDataObject is NULL\n");
59 *pdwEffect = 0;
60 DragLeave();
61 return E_POINTER;
62 }
63
64 CComPtr<IShellFolder> pDesktop;
65 HRESULT hr = SHGetDesktopFolder(&pDesktop);
67 return hr;
68
69 // Retrieve an HIDA (handle of IDA)
70 CDataObjectHIDA pida(pDataObject);
71 if (FAILED_UNEXPECTEDLY(pida.hr()))
72 {
73 *pdwEffect = 0;
74 DragLeave();
75 return pida.hr();
76 }
77
78 UINT iItem, cItems = pida->cidl;
79
80 // get the path of "My Documents"
81 WCHAR szzDir[MAX_PATH + 1];
83 szzDir[lstrlenW(szzDir) + 1] = 0; // ends with double NULs
84
85 // for all source items
86 CStringW strSrcList;
87 WCHAR szSrc[MAX_PATH];
88 PCIDLIST_ABSOLUTE pidlParent = HIDA_GetPIDLFolder(pida);
89 for (iItem = 0; iItem < cItems; ++iItem)
90 {
91 // query source pidl
92 PCITEMID_CHILD pidlChild = HIDA_GetPIDLItem(pida, iItem);
93 CComHeapPtr<ITEMIDLIST> pidl(ILCombine(pidlParent, pidlChild));
94
95 // can get path?
96 szSrc[0] = 0;
97 if (!SHGetPathFromIDListW(pidl, szSrc))
98 {
99 // try to retrieve path from desktop
100 STRRET strret;
101 hr = pDesktop->GetDisplayNameOf(pidl, SHGDN_INFOLDER, &strret);
103 break;
104 hr = StrRetToBufW(&strret, pidl, szSrc, _countof(szSrc));
106 break;
107 if (!PathFileExistsW(szSrc))
108 break;
109 }
110
111 if (iItem > 0)
112 strSrcList += L'|'; // separator is '|'
113 strSrcList += szSrc;
114 }
115
116 if (iItem != cItems)
117 {
118 // source not found
119 CStringW strText;
120 strText.Format(IDS_NOSRCFILEFOUND, szSrc[0] ? szSrc : L"(null)");
121 MessageBoxW(NULL, strText, NULL, MB_ICONERROR);
122
123 *pdwEffect = 0;
124 DragLeave();
125 return E_FAIL;
126 }
127
128 strSrcList += L"||"; // double separators
129
130 // lock the buffer
131 LPWSTR pszzSrcList = strSrcList.GetBuffer();
132
133 // convert every separator to a NUL
134 INT cch = strSrcList.GetLength();
135 for (INT i = 0; i < cch; ++i)
136 {
137 if (pszzSrcList[i] == L'|')
138 pszzSrcList[i] = L'\0';
139 }
140
141 // copy them
142 SHFILEOPSTRUCTW fileop = { NULL };
143 fileop.wFunc = FO_COPY;
144 fileop.pFrom = pszzSrcList;
145 fileop.pTo = szzDir;
147 int res = SHFileOperationW(&fileop);
148 if (res)
149 {
150 ERR("SHFileOperationW failed with 0x%x\n", res);
151 hr = E_FAIL;
152 }
153
154 // unlock buffer
155 strSrcList.ReleaseBuffer();
156
157 DragLeave();
158 return hr;
159}
160
161// IPersistFile
163{
164 FIXME("(%p)\n", this);
165 return E_NOTIMPL;
166}
167
169{
170 FIXME("(%p)\n", this);
171 return E_NOTIMPL;
172}
173
175{
176 return S_OK;
177}
178
180{
181 FIXME("(%p)\n", this);
182 return E_NOTIMPL;
183}
184
186{
187 FIXME("(%p)\n", this);
188 return E_NOTIMPL;
189}
190
191// IPersist
193{
194 TRACE("(%p)\n", this);
195
196 if (!lpClassId)
197 {
198 ERR("lpClassId is NULL\n");
199 return E_POINTER;
200 }
201
202 *lpClassId = CLSID_MyDocsDropHandler;
203
204 return S_OK;
205}
LONG g_ModuleRefCnt
Definition: ACPPage.cpp:13
HRESULT WINAPI SHGetDesktopFolder(IShellFolder **psf)
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define STDMETHODIMP
Definition: basetyps.h:43
#define FIXME(fmt,...)
Definition: debug.h:114
#define ERR(fmt,...)
Definition: debug.h:113
void ReleaseBuffer(_In_ int nNewLength=-1)
Definition: atlsimpstr.h:387
int GetLength() const noexcept
Definition: atlsimpstr.h:362
void __cdecl Format(UINT nFormatID,...)
Definition: cstringt.h:818
STDMETHODIMP DragLeave()
STDMETHODIMP GetCurFile(LPOLESTR *ppszFileName)
STDMETHODIMP DragOver(DWORD dwKeyState, POINTL pt, DWORD *pdwEffect)
STDMETHODIMP DragEnter(IDataObject *pDataObject, DWORD dwKeyState, POINTL pt, DWORD *pdwEffect)
STDMETHODIMP Drop(IDataObject *pDataObject, DWORD dwKeyState, POINTL pt, DWORD *pdwEffect)
STDMETHODIMP Load(LPCOLESTR pszFileName, DWORD dwMode)
STDMETHODIMP GetClassID(CLSID *lpClassId)
STDMETHODIMP SaveCompleted(LPCOLESTR pszFileName)
STDMETHODIMP Save(LPCOLESTR pszFileName, BOOL fRemember)
#define E_NOTIMPL
Definition: ddrawi.h:99
#define E_FAIL
Definition: ddrawi.h:102
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define IDS_NOSRCFILEFOUND
Definition: resource.h:13
#define MAX_PATH
Definition: compat.h:34
#define lstrlenW
Definition: compat.h:750
#define FAILED_UNEXPECTEDLY(hr)
Definition: precomp.h:121
BOOL WINAPI SHGetSpecialFolderPathW(HWND hwndOwner, LPWSTR szPath, int nFolder, BOOL bCreate)
Definition: shellpath.c:3092
BOOL WINAPI PathFileExistsW(LPCWSTR lpszPath)
Definition: path.c:1777
HRESULT WINAPI StrRetToBufW(LPSTRRET src, const ITEMIDLIST *pidl, LPWSTR dest, UINT len)
Definition: string.c:1530
#define pt(x, y)
Definition: drawing.c:79
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint res
Definition: glext.h:9613
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
const DWORD DROPEFFECT_COPY
Definition: oleidl.idl:930
#define S_OK
Definition: intsafe.h:52
static DWORD DWORD void LPSTR DWORD cch
Definition: str.c:202
static LPOLESTR
Definition: stg_prop.c:27
unsigned int UINT
Definition: ndis.h:50
#define L(x)
Definition: ntvdm.h:50
LPITEMIDLIST WINAPI ILCombine(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
Definition: pidl.c:712
BOOL WINAPI SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath)
Definition: pidl.c:1342
#define FOF_MULTIDESTFILES
Definition: shellapi.h:141
#define FOF_ALLOWUNDO
Definition: shellapi.h:147
#define FO_COPY
Definition: shellapi.h:137
#define FOF_FILESONLY
Definition: shellapi.h:148
#define FOF_NOCONFIRMMKDIR
Definition: shellapi.h:150
static PCUIDLIST_RELATIVE HIDA_GetPIDLItem(CIDA const *pida, SIZE_T i)
Definition: shellutils.h:619
static PCUIDLIST_ABSOLUTE HIDA_GetPIDLFolder(CIDA const *pida)
Definition: shellutils.h:614
int WINAPI SHFileOperationW(LPSHFILEOPSTRUCTW lpFileOp)
Definition: shlfileop.cpp:1987
HRESULT hr
Definition: shlfolder.c:183
#define CSIDL_PERSONAL
Definition: shlobj.h:2171
#define _countof(array)
Definition: sndvol32.h:70
#define TRACE(s)
Definition: solgame.cpp:4
LPCWSTR pFrom
Definition: shellapi.h:357
FILEOP_FLAGS fFlags
Definition: shellapi.h:359
int32_t INT
Definition: typedefs.h:58
WORD WORD PSZ PSZ pszFileName
Definition: vdmdbg.h:44
#define E_POINTER
Definition: winerror.h:2365
int WINAPI MessageBoxW(_In_opt_ HWND hWnd, _In_opt_ LPCWSTR lpText, _In_opt_ LPCWSTR lpCaption, _In_ UINT uType)
#define MB_ICONERROR
Definition: winuser.h:787
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184