ReactOS  0.4.15-dev-5089-g555bec6
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 
51 CMyDocsDropHandler::Drop(IDataObject *pDataObject, DWORD dwKeyState,
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);
102  if (FAILED_UNEXPECTEDLY(hr))
103  break;
104  hr = StrRetToBufW(&strret, pidl, szSrc, _countof(szSrc));
105  if (FAILED_UNEXPECTEDLY(hr))
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 }
WINE_DEFAULT_DEBUG_CHANNEL(mydocs)
int GetLength() const
Definition: atlsimpstr.h:356
HRESULT hr
Definition: shlfolder.c:183
STDMETHODIMP DragLeave()
#define pt(x, y)
Definition: drawing.c:79
#define FO_COPY
Definition: shellapi.h:134
LONG g_ModuleRefCnt
Definition: ACPPage.cpp:13
HRESULT WINAPI StrRetToBufW(LPSTRRET src, const ITEMIDLIST *pidl, LPWSTR dest, UINT len)
Definition: string.c:1522
LPITEMIDLIST WINAPI ILCombine(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
Definition: pidl.c:699
BOOL WINAPI SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath)
Definition: pidl.c:1294
static PCUIDLIST_RELATIVE HIDA_GetPIDLItem(CIDA const *pida, SIZE_T i)
Definition: shellutils.h:554
#define FOF_ALLOWUNDO
Definition: shellapi.h:144
void __cdecl Format(UINT nFormatID,...)
Definition: cstringt.h:753
#define IDS_NOSRCFILEFOUND
Definition: resource.h:13
STDMETHODIMP Load(LPCOLESTR pszFileName, DWORD dwMode)
int WINAPI MessageBoxW(_In_opt_ HWND hWnd, _In_opt_ LPCWSTR lpText, _In_opt_ LPCWSTR lpCaption, _In_ UINT uType)
FILEOP_FLAGS fFlags
Definition: shellapi.h:357
static LPOLESTR
Definition: stg_prop.c:27
#define lstrlenW
Definition: compat.h:609
#define E_FAIL
Definition: ddrawi.h:102
int32_t INT
Definition: typedefs.h:58
int WINAPI SHFileOperationW(LPSHFILEOPSTRUCTW lpFileOp)
Definition: shlfileop.cpp:1982
const DWORD DROPEFFECT_COPY
Definition: oleidl.idl:930
#define L(x)
Definition: ntvdm.h:50
void ReleaseBuffer(_In_ int nNewLength=-1)
Definition: atlsimpstr.h:372
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
#define FIXME(fmt,...)
Definition: debug.h:111
WORD WORD PSZ PSZ pszFileName
Definition: vdmdbg.h:41
#define STDMETHODIMP
Definition: basetyps.h:43
STDMETHODIMP Save(LPCOLESTR pszFileName, BOOL fRemember)
BOOL WINAPI PathFileExistsW(LPCWSTR lpszPath)
Definition: path.c:1776
STDMETHODIMP DragEnter(IDataObject *pDataObject, DWORD dwKeyState, POINTL pt, DWORD *pdwEffect)
#define TRACE(s)
Definition: solgame.cpp:4
HRESULT WINAPI SHGetDesktopFolder(IShellFolder **psf)
STDMETHODIMP DragOver(DWORD dwKeyState, POINTL pt, DWORD *pdwEffect)
__wchar_t WCHAR
Definition: xmlstorage.h:180
STDMETHODIMP GetCurFile(LPOLESTR *ppszFileName)
LONG HRESULT
Definition: typedefs.h:79
#define _countof(array)
Definition: sndvol32.h:68
#define FOF_FILESONLY
Definition: shellapi.h:145
#define FAILED_UNEXPECTEDLY(hr)
Definition: shellutils.h:82
#define MAX_PATH
Definition: compat.h:34
unsigned long DWORD
Definition: ntddk_ex.h:95
LPCWSTR pFrom
Definition: shellapi.h:355
#define InterlockedDecrement
Definition: armddk.h:52
#define MB_ICONERROR
Definition: winuser.h:781
static PCUIDLIST_ABSOLUTE HIDA_GetPIDLFolder(CIDA const *pida)
Definition: shellutils.h:549
#define ERR(fmt,...)
Definition: debug.h:110
#define S_OK
Definition: intsafe.h:52
STDMETHODIMP GetClassID(CLSID *lpClassId)
#define InterlockedIncrement
Definition: armddk.h:53
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
BOOL WINAPI SHGetSpecialFolderPathW(HWND hwndOwner, LPWSTR szPath, int nFolder, BOOL bCreate)
Definition: shellpath.c:2851
#define E_NOTIMPL
Definition: ddrawi.h:99
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
#define CSIDL_PERSONAL
Definition: shlobj.h:2017
GLuint res
Definition: glext.h:9613
STDMETHODIMP SaveCompleted(LPCOLESTR pszFileName)
#define FOF_MULTIDESTFILES
Definition: shellapi.h:138
STDMETHODIMP Drop(IDataObject *pDataObject, DWORD dwKeyState, POINTL pt, DWORD *pdwEffect)
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define E_POINTER
Definition: winerror.h:2365
IN PCTCH IN DWORD cch
Definition: pager.h:36
#define FOF_NOCONFIRMMKDIR
Definition: shellapi.h:147