update for HEAD-2003091401
[reactos.git] / subsys / system / explorer / utility / treedroptarget.h
1 /**************************************************************************
2    THIS CODE AND INFORMATION IS PROVIDED 'AS IS' WITHOUT WARRANTY OF
3    ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
4    THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
5    PARTICULAR PURPOSE.
6    Author: Leon Finker  01/2001
7    Modifications: removed ATL dependencies, Martin Fuchs 7/2003
8 **************************************************************************/
9
10 #include "dragdropimpl.h"
11
12 class TreeDropTarget : public IDropTargetImpl
13 {
14 public:
15         TreeDropTarget(HWND hTargetWnd) : IDropTargetImpl(hTargetWnd) {}
16
17         virtual bool OnDrop(FORMATETC* pFmtEtc, STGMEDIUM& medium, DWORD *pdwEffect)
18         {
19                 if (pFmtEtc->cfFormat == CF_HDROP && medium.tymed == TYMED_HGLOBAL)
20                 {
21                         HDROP hDrop = (HDROP)GlobalLock(medium.hGlobal);
22                         if (hDrop != NULL)
23                         {
24                                 TCHAR szFileName[MAX_PATH];
25
26                                 UINT cFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0);
27
28                                 for(UINT i = 0; i < cFiles; ++i)
29                                 {
30                                         DragQueryFile(hDrop, i, szFileName, sizeof(szFileName));
31
32                                         if (DROPEFFECT_COPY & *pdwEffect)
33                                         {
34                                                  // copy the file or dir
35
36                                                 //TODO: Add the code to handle Copy
37
38                                         }
39                                         else if (DROPEFFECT_MOVE & *pdwEffect)
40                                         {
41                                                  // move the file or dir
42
43                                                 //TODO: Add the code to handle Move
44
45                                         }
46                                 }
47                                 //DragFinish(hDrop); // base class calls ReleaseStgMedium
48                         }
49                         GlobalUnlock(medium.hGlobal);
50                 }
51                 TreeView_SelectDropTarget(m_hTargetWnd, NULL);
52                 return true; //let base free the medium
53         }
54
55         virtual HRESULT STDMETHODCALLTYPE DragOver(
56         /* [in] */ DWORD grfKeyState,
57         /* [in] */ POINTL pt,
58         /* [out][in] */ DWORD __RPC_FAR *pdwEffect)
59         {
60                 TVHITTESTINFO hit;
61                 hit.pt = (POINT&)pt;
62                 ScreenToClient(m_hTargetWnd,&hit.pt);
63                 hit.flags = TVHT_ONITEM;
64                 HTREEITEM hItem = TreeView_HitTest(m_hTargetWnd,&hit);
65
66                 if (hItem != NULL)
67                 {
68                         TreeView_SelectDropTarget(m_hTargetWnd, hItem);
69                 }
70
71                 return IDropTargetImpl::DragOver(grfKeyState, pt, pdwEffect);
72         }
73
74         virtual HRESULT STDMETHODCALLTYPE DragLeave(void)
75         {
76                 TreeView_SelectDropTarget(m_hTargetWnd, NULL);
77                 return IDropTargetImpl::DragLeave();
78         }
79 };