update for HEAD-2003091401
[reactos.git] / subsys / system / explorer / utility / treedroptarget.h
diff --git a/subsys/system/explorer/utility/treedroptarget.h b/subsys/system/explorer/utility/treedroptarget.h
new file mode 100644 (file)
index 0000000..753f2ad
--- /dev/null
@@ -0,0 +1,79 @@
+/**************************************************************************
+   THIS CODE AND INFORMATION IS PROVIDED 'AS IS' WITHOUT WARRANTY OF
+   ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
+   THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
+   PARTICULAR PURPOSE.
+   Author: Leon Finker  01/2001
+   Modifications: removed ATL dependencies, Martin Fuchs 7/2003
+**************************************************************************/
+
+#include "dragdropimpl.h"
+
+class TreeDropTarget : public IDropTargetImpl
+{
+public:
+       TreeDropTarget(HWND hTargetWnd) : IDropTargetImpl(hTargetWnd) {}
+
+       virtual bool OnDrop(FORMATETC* pFmtEtc, STGMEDIUM& medium, DWORD *pdwEffect)
+       {
+               if (pFmtEtc->cfFormat == CF_HDROP && medium.tymed == TYMED_HGLOBAL)
+               {
+                       HDROP hDrop = (HDROP)GlobalLock(medium.hGlobal);
+                       if (hDrop != NULL)
+                       {
+                               TCHAR szFileName[MAX_PATH];
+
+                               UINT cFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0);
+
+                               for(UINT i = 0; i < cFiles; ++i)
+                               {
+                                       DragQueryFile(hDrop, i, szFileName, sizeof(szFileName));
+
+                                       if (DROPEFFECT_COPY & *pdwEffect)
+                                       {
+                                                // copy the file or dir
+
+                                               //TODO: Add the code to handle Copy
+
+                                       }
+                                       else if (DROPEFFECT_MOVE & *pdwEffect)
+                                       {
+                                                // move the file or dir
+
+                                               //TODO: Add the code to handle Move
+
+                                       }
+                               }
+                               //DragFinish(hDrop); // base class calls ReleaseStgMedium
+                       }
+                       GlobalUnlock(medium.hGlobal);
+               }
+               TreeView_SelectDropTarget(m_hTargetWnd, NULL);
+               return true; //let base free the medium
+       }
+
+       virtual HRESULT STDMETHODCALLTYPE DragOver(
+        /* [in] */ DWORD grfKeyState,
+        /* [in] */ POINTL pt,
+        /* [out][in] */ DWORD __RPC_FAR *pdwEffect)
+       {
+               TVHITTESTINFO hit;
+               hit.pt = (POINT&)pt;
+               ScreenToClient(m_hTargetWnd,&hit.pt);
+               hit.flags = TVHT_ONITEM;
+               HTREEITEM hItem = TreeView_HitTest(m_hTargetWnd,&hit);
+
+               if (hItem != NULL)
+               {
+                       TreeView_SelectDropTarget(m_hTargetWnd, hItem);
+               }
+
+               return IDropTargetImpl::DragOver(grfKeyState, pt, pdwEffect);
+       }
+
+       virtual HRESULT STDMETHODCALLTYPE DragLeave(void)
+       {
+               TreeView_SelectDropTarget(m_hTargetWnd, NULL);
+               return IDropTargetImpl::DragLeave();
+       }
+};