1 /*
2  * file system folder drop target
3  *
4  * Copyright 1997             Marcus Meissner
5  * Copyright 1998, 1999, 2002 Juergen Schmied
6  * Copyright 2009             Andrew Hill
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 #ifndef _CFSDROPTARGET_H_
24 #define _CFSDROPTARGET_H_
25 
26 class CFSDropTarget :
27     public CComObjectRootEx<CComMultiThreadModelNoCS>,
28     public IDropTarget,
29     public IObjectWithSite
30 {
31     private:
32         UINT m_cfShellIDList;    /* clipboardformat for IDropTarget */
33         BOOL m_fAcceptFmt;       /* flag for pending Drop */
34         LPWSTR m_sPathTarget;
35         HWND m_hwndSite;
36         DWORD m_grfKeyState;
37         DWORD m_dwDefaultEffect;
38         CComPtr<IUnknown> m_site;
39 
40         BOOL _QueryDrop (DWORD dwKeyState, LPDWORD pdwEffect);
41         HRESULT _DoDrop(IDataObject *pDataObject, DWORD dwKeyState, POINTL pt, DWORD *pdwEffect);
42         HRESULT _CopyItems(IShellFolder *pSFFrom, UINT cidl, LPCITEMIDLIST *apidl, BOOL bCopy);
43         BOOL _GetUniqueFileName(LPCWSTR pwszBasePath, LPCWSTR pwszExt, LPWSTR pwszTarget, BOOL bShortcut);
44         static DWORD WINAPI _DoDropThreadProc(LPVOID lpParameter);
45         HRESULT _GetEffectFromMenu(IDataObject *pDataObject, POINTL pt, DWORD *pdwEffect, DWORD dwAvailableEffects);
46         HRESULT _RepositionItems(IShellFolderView *psfv, IDataObject *pDataObject, POINTL pt);
47 
48     public:
49         CFSDropTarget();
50         ~CFSDropTarget();
51         HRESULT Initialize(LPWSTR PathTarget);
52 
53         // IDropTarget
54         virtual HRESULT WINAPI DragEnter(IDataObject *pDataObject, DWORD dwKeyState, POINTL pt, DWORD *pdwEffect);
55         virtual HRESULT WINAPI DragOver(DWORD dwKeyState, POINTL pt, DWORD *pdwEffect);
56         virtual HRESULT WINAPI DragLeave();
57         virtual HRESULT WINAPI Drop(IDataObject *pDataObject, DWORD dwKeyState, POINTL pt, DWORD *pdwEffect);
58 
59         // IObjectWithSite
60         virtual HRESULT STDMETHODCALLTYPE SetSite(IUnknown *pUnkSite);
61         virtual HRESULT STDMETHODCALLTYPE GetSite(REFIID riid, void **ppvSite);
62 
63         DECLARE_NOT_AGGREGATABLE(CFSDropTarget)
64 
65         DECLARE_PROTECT_FINAL_CONSTRUCT()
66 
67         BEGIN_COM_MAP(CFSDropTarget)
68         COM_INTERFACE_ENTRY_IID(IID_IDropTarget, IDropTarget)
69         COM_INTERFACE_ENTRY_IID(IID_IObjectWithSite, IObjectWithSite)
70         END_COM_MAP()
71 
72 };
73 
74 struct _DoDropData {
75     CFSDropTarget *This;
76     IStream *pStream;
77     DWORD dwKeyState;
78     POINTL pt;
79     DWORD pdwEffect;
80 };
81 
82 HRESULT CFSDropTarget_CreateInstance(LPWSTR sPathTarget, REFIID riid, LPVOID * ppvOut);
83 
84 #endif /* _CFSFOLDER_H_ */
85