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         DWORD m_AllowedEffects;
39         CComPtr<IUnknown> m_site;
40 
41         BOOL _QueryDrop (DWORD dwKeyState, LPDWORD pdwEffect);
42         HRESULT _DoDrop(IDataObject *pDataObject, DWORD dwKeyState, POINTL pt, DWORD *pdwEffect);
43         HRESULT _CopyItems(IShellFolder *pSFFrom, UINT cidl, LPCITEMIDLIST *apidl, BOOL bCopy);
44         BOOL _GetUniqueFileName(LPCWSTR pwszBasePath, LPCWSTR pwszExt, LPWSTR pwszTarget, BOOL bShortcut);
45         static DWORD WINAPI _DoDropThreadProc(LPVOID lpParameter);
46         HRESULT _GetEffectFromMenu(IDataObject *pDataObject, POINTL pt, DWORD *pdwEffect, DWORD dwAvailableEffects);
47         HRESULT _RepositionItems(IShellFolderView *psfv, IDataObject *pDataObject, POINTL pt);
48 
49     public:
50         CFSDropTarget();
51         ~CFSDropTarget();
52         HRESULT Initialize(LPWSTR PathTarget);
53 
54         // IDropTarget
55         STDMETHOD(DragEnter)(IDataObject *pDataObject, DWORD dwKeyState, POINTL pt, DWORD *pdwEffect) override;
56         STDMETHOD(DragOver)(DWORD dwKeyState, POINTL pt, DWORD *pdwEffect) override;
57         STDMETHOD(DragLeave)() override;
58         STDMETHOD(Drop)(IDataObject *pDataObject, DWORD dwKeyState, POINTL pt, DWORD *pdwEffect) override;
59 
60         // IObjectWithSite
61         STDMETHOD(SetSite)(IUnknown *pUnkSite) override;
62         STDMETHOD(GetSite)(REFIID riid, void **ppvSite) override;
63 
64         DECLARE_NOT_AGGREGATABLE(CFSDropTarget)
65 
66         DECLARE_PROTECT_FINAL_CONSTRUCT()
67 
68         BEGIN_COM_MAP(CFSDropTarget)
69         COM_INTERFACE_ENTRY_IID(IID_IDropTarget, IDropTarget)
70         COM_INTERFACE_ENTRY_IID(IID_IObjectWithSite, IObjectWithSite)
71         END_COM_MAP()
72 
73 };
74 
75 struct _DoDropData {
76     CFSDropTarget *This;
77     IStream *pStream;
78     DWORD dwKeyState;
79     POINTL pt;
80     DWORD pdwEffect;
81 };
82 
83 HRESULT CFSDropTarget_CreateInstance(LPWSTR sPathTarget, REFIID riid, LPVOID * ppvOut);
84 
85 #endif /* _CFSFOLDER_H_ */
86