update for HEAD-2003091401
[reactos.git] / subsys / system / explorer / Seashell / SeaShellExt / IEShellDragDrop.cpp
1 //*******************************************************************************
2 // COPYRIGHT NOTES
3 // ---------------
4 // You may use this source code, compile or redistribute it as part of your application 
5 // for free. You cannot redistribute it as a part of a software development 
6 // library without the agreement of the author. If the sources are 
7 // distributed along with the application, you should leave the original 
8 // copyright notes in the source code without any changes.
9 // This code can be used WITHOUT ANY WARRANTIES at your own risk.
10 // 
11 // For the latest updates to this code, check this site:
12 // http://www.masmex.com 
13 // after Sept 2000
14 // 
15 // Copyright(C) 2000 Philip Oldaker <email: philip@masmex.com>
16 //*******************************************************************************
17
18 #include "stdafx.h"
19 #include "IEShellDragDrop.h"
20 #include "cbformats.h"
21
22 #ifndef OleStdGetDropEffect
23 #define OleStdGetDropEffect(grfKeyState)    \
24    ( (grfKeyState & MK_CONTROL) ?          \
25       ( (grfKeyState & MK_SHIFT) ? DROPEFFECT_LINK : DROPEFFECT_COPY ) :  \
26       ( (grfKeyState & MK_SHIFT) ? DROPEFFECT_MOVE : DROPEFFECT_NONE ) )
27 #endif
28
29 bool CIEShellDragDrop::DragEnter(CDD_OleDropTargetInfo *pInfo,LPSHELLFOLDER psfFolder,LPITEMIDLIST pidl)
30 {
31 //      DWORD dwEffect = m_ShellPidl.GetDragDropAttributes(pInfo->GetDataObject()->m_lpDataObject);
32         IDropTarget *pdt=NULL;
33         if (psfFolder == NULL)
34                 psfFolder = m_psfDesktop;
35     HRESULT hr = psfFolder->GetUIObjectOf(pInfo->GetSafeHwnd(),1,(LPCITEMIDLIST*)&pidl, IID_IDropTarget, NULL, (LPVOID*)&pdt);
36         if (FAILED(hr))
37                 return false;
38         DWORD dwKeyState = pInfo->GetKeyboardState();
39         CPoint pt(pInfo->GetPoint());
40         ::ClientToScreen(pInfo->GetSafeHwnd(),&pt);
41         POINTL ptl;
42         ptl.x = pt.x;
43         ptl.y = pt.y;
44         DWORD dwEffect=0;
45     pdt->DragEnter(pInfo->GetDataObject()->m_lpDataObject, dwKeyState, ptl, &dwEffect);
46         pdt->DragLeave();
47         pInfo->SetDropEffect(dwEffect);
48         pdt->Release();
49         return true;
50 }
51
52 bool CIEShellDragDrop::DragLeave(CDD_OleDropTargetInfo *pInfo)
53 {
54         return false;
55 }
56
57 bool CIEShellDragDrop::DragOver(CDD_OleDropTargetInfo *pInfo,LPSHELLFOLDER psfFolder,LPITEMIDLIST pidl)
58 {
59         pInfo->SetDropEffect(DROPEFFECT_NONE);
60
61         IDropTarget *pdt=NULL;
62         if (psfFolder == NULL)
63                 psfFolder = m_psfDesktop;
64     HRESULT hr = psfFolder->GetUIObjectOf(pInfo->GetSafeHwnd(),1,(LPCITEMIDLIST*)&pidl, IID_IDropTarget, NULL, (LPVOID*)&pdt);
65         if (FAILED(hr))
66                 return false;
67
68         DWORD dwKeyState = pInfo->GetKeyboardState();
69         TRACE1("dwKeyState=%u\n",dwKeyState);
70         CPoint pt(pInfo->GetPoint());
71         ::ClientToScreen(pInfo->GetSafeHwnd(),&pt);
72         POINTL ptl;
73         ptl.x = pt.x;
74         ptl.y = pt.y;   
75         DWORD dwEffect=OleStdGetDropEffect(dwKeyState);
76         if (dwEffect == DROPEFFECT_NONE)
77                 dwEffect = DROPEFFECT_MOVE | DROPEFFECT_COPY | DROPEFFECT_LINK;
78         TRACE1("dropEffect=%u\n",dwEffect);
79         pdt->DragEnter(pInfo->GetDataObject()->m_lpDataObject, dwKeyState, ptl, &dwEffect);
80         pdt->DragOver(dwKeyState, ptl, &dwEffect);
81         pdt->DragLeave();
82         pdt->Release();
83         pInfo->SetDropEffect(dwEffect);
84         return true;
85 }
86
87 bool CIEShellDragDrop::DragDrop(CDD_OleDropTargetInfo *pInfo,LPSHELLFOLDER psfFolder,LPITEMIDLIST pidl)
88 {
89         IDropTarget *pdt=NULL;
90         if (psfFolder == NULL)
91                 psfFolder = m_psfDesktop;
92     HRESULT hr = psfFolder->GetUIObjectOf(pInfo->GetSafeHwnd(),1,(LPCITEMIDLIST*)&pidl, IID_IDropTarget, NULL, (LPVOID*)&pdt);
93         if (FAILED(hr))
94                 return false;
95         CPoint pt(pInfo->GetPoint());
96         TRACE2("Drop received at point(client) %d,%d\n",pt.x,pt.y);
97         ::ClientToScreen(pInfo->GetSafeHwnd(),&pt);
98         TRACE2("Drop received at point(screen) %d,%d\n",pt.x,pt.y);
99         CWDClipboardData::Instance()->IsDataAvailable(pInfo->GetDataObject());
100 #ifdef _DEBUG
101         if (pInfo->GetDataObject()->IsDataAvailable(CF_TEXT))
102         {
103                 CCF_String cfString;
104                 if (CWDClipboardData::Instance()->GetData(pInfo->GetDataObject(),&cfString,CWDClipboardData::e_cfString))
105                 {
106                         TRACE1("Received CF_TEXT %s\n",cfString.GetString());
107                 }
108         }
109         if (pInfo->GetDataObject()->IsDataAvailable(CF_HDROP))
110         {
111                 CCF_HDROP cfHDROP;
112                 if (CWDClipboardData::Instance()->GetData(pInfo->GetDataObject(),&cfHDROP,CWDClipboardData::e_cfHDROP))
113                 {
114                         for(UINT i=0;i < cfHDROP.GetCount();i++)
115                                 TRACE2("Received CF_HDROP %s (%u)\n",cfHDROP.GetFileName(i),i);
116                 }
117         }
118 #endif
119         POINTL ptl;
120         ptl.x = pt.x;
121         ptl.y = pt.y;
122         DWORD dwKeyState = pInfo->GetKeyboardState();
123     DWORD dw = DROPEFFECT_MOVE;
124     pdt->DragEnter(pInfo->GetDataObject()->m_lpDataObject, dwKeyState, ptl, &dw);
125     pdt->DragOver(dwKeyState, ptl, &dw);
126         DWORD dwEffect = m_ShellPidl.GetDragDropAttributes(pInfo->GetDataObject());
127         TRACE2("Keyboardstate=%u DragDropEffect=%u\n",dwKeyState,dwEffect);
128     pdt->Drop(pInfo->GetDataObject()->m_lpDataObject, dwKeyState, ptl, &dwEffect);
129         pdt->Release();
130         return true;
131 }