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)
10 WINE_DEFAULT_DEBUG_CHANNEL(mydocs
);
12 CMyDocsDropHandler::CMyDocsDropHandler()
14 InterlockedIncrement(&g_ModuleRefCnt
);
17 CMyDocsDropHandler::~CMyDocsDropHandler()
19 InterlockedDecrement(&g_ModuleRefCnt
);
24 CMyDocsDropHandler::DragEnter(IDataObject
*pDataObject
, DWORD dwKeyState
,
25 POINTL pt
, DWORD
*pdwEffect
)
27 TRACE("(%p)\n", this);
29 *pdwEffect
&= DROPEFFECT_COPY
; // Copy only
35 CMyDocsDropHandler::DragOver(DWORD dwKeyState
, POINTL pt
, DWORD
*pdwEffect
)
37 TRACE("(%p)\n", this);
39 *pdwEffect
&= DROPEFFECT_COPY
; // Copy only
44 STDMETHODIMP
CMyDocsDropHandler::DragLeave()
46 TRACE("(%p)\n", this);
51 CMyDocsDropHandler::Drop(IDataObject
*pDataObject
, DWORD dwKeyState
,
52 POINTL pt
, DWORD
*pdwEffect
)
54 TRACE("(%p)\n", this);
58 ERR("pDataObject is NULL\n");
64 CComPtr
<IShellFolder
> pDesktop
;
65 HRESULT hr
= SHGetDesktopFolder(&pDesktop
);
66 if (FAILED_UNEXPECTEDLY(hr
))
69 // Retrieve an HIDA (handle of IDA)
70 CDataObjectHIDA
pida(pDataObject
);
71 if (FAILED_UNEXPECTEDLY(pida
.hr()))
78 UINT iItem
, cItems
= pida
->cidl
;
80 // get the path of "My Documents"
81 WCHAR szzDir
[MAX_PATH
+ 1];
82 SHGetSpecialFolderPathW(NULL
, szzDir
, CSIDL_PERSONAL
, FALSE
);
83 szzDir
[lstrlenW(szzDir
) + 1] = 0; // ends with double NULs
85 // for all source items
87 WCHAR szSrc
[MAX_PATH
];
88 PCIDLIST_ABSOLUTE pidlParent
= HIDA_GetPIDLFolder(pida
);
89 for (iItem
= 0; iItem
< cItems
; ++iItem
)
92 PCITEMID_CHILD pidlChild
= HIDA_GetPIDLItem(pida
, iItem
);
93 CComHeapPtr
<ITEMIDLIST
> pidl(ILCombine(pidlParent
, pidlChild
));
97 if (!SHGetPathFromIDListW(pidl
, szSrc
))
99 // try to retrieve path from desktop
101 hr
= pDesktop
->GetDisplayNameOf(pidl
, SHGDN_INFOLDER
, &strret
);
102 if (FAILED_UNEXPECTEDLY(hr
))
104 hr
= StrRetToBufW(&strret
, pidl
, szSrc
, _countof(szSrc
));
105 if (FAILED_UNEXPECTEDLY(hr
))
107 if (!PathFileExistsW(szSrc
))
112 strSrcList
+= L
'|'; // separator is '|'
120 strText
.Format(IDS_NOSRCFILEFOUND
, szSrc
[0] ? szSrc
: L
"(null)");
121 MessageBoxW(NULL
, strText
, NULL
, MB_ICONERROR
);
128 strSrcList
+= L
"||"; // double separators
131 LPWSTR pszzSrcList
= strSrcList
.GetBuffer();
133 // convert every separator to a NUL
134 INT cch
= strSrcList
.GetLength();
135 for (INT i
= 0; i
< cch
; ++i
)
137 if (pszzSrcList
[i
] == L
'|')
138 pszzSrcList
[i
] = L
'\0';
142 SHFILEOPSTRUCTW fileop
= { NULL
};
143 fileop
.wFunc
= FO_COPY
;
144 fileop
.pFrom
= pszzSrcList
;
146 fileop
.fFlags
= FOF_ALLOWUNDO
| FOF_FILESONLY
| FOF_MULTIDESTFILES
| FOF_NOCONFIRMMKDIR
;
147 int res
= SHFileOperationW(&fileop
);
150 ERR("SHFileOperationW failed with 0x%x\n", res
);
155 strSrcList
.ReleaseBuffer();
162 STDMETHODIMP
CMyDocsDropHandler::GetCurFile(LPOLESTR
*ppszFileName
)
164 FIXME("(%p)\n", this);
168 STDMETHODIMP
CMyDocsDropHandler::IsDirty()
170 FIXME("(%p)\n", this);
174 STDMETHODIMP
CMyDocsDropHandler::Load(LPCOLESTR pszFileName
, DWORD dwMode
)
179 STDMETHODIMP
CMyDocsDropHandler::Save(LPCOLESTR pszFileName
, BOOL fRemember
)
181 FIXME("(%p)\n", this);
185 STDMETHODIMP
CMyDocsDropHandler::SaveCompleted(LPCOLESTR pszFileName
)
187 FIXME("(%p)\n", this);
192 STDMETHODIMP
CMyDocsDropHandler::GetClassID(CLSID
* lpClassId
)
194 TRACE("(%p)\n", this);
198 ERR("lpClassId is NULL\n");
202 *lpClassId
= CLSID_MyDocsDropHandler
;