1 //*******************************************************************************
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.
11 // For the latest updates to this code, check this site:
12 // http://www.masmex.com
15 // Copyright(C) 2000 Philip Oldaker <email: philip@masmex.com>
16 //*******************************************************************************
19 #include "IEShellDragDrop.h"
20 #include "cbformats.h"
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 ) )
29 bool CIEShellDragDrop::DragEnter(CDD_OleDropTargetInfo *pInfo,LPSHELLFOLDER psfFolder,LPITEMIDLIST pidl)
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);
38 DWORD dwKeyState = pInfo->GetKeyboardState();
39 CPoint pt(pInfo->GetPoint());
40 ::ClientToScreen(pInfo->GetSafeHwnd(),&pt);
45 pdt->DragEnter(pInfo->GetDataObject()->m_lpDataObject, dwKeyState, ptl, &dwEffect);
47 pInfo->SetDropEffect(dwEffect);
52 bool CIEShellDragDrop::DragLeave(CDD_OleDropTargetInfo *pInfo)
57 bool CIEShellDragDrop::DragOver(CDD_OleDropTargetInfo *pInfo,LPSHELLFOLDER psfFolder,LPITEMIDLIST pidl)
59 pInfo->SetDropEffect(DROPEFFECT_NONE);
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);
68 DWORD dwKeyState = pInfo->GetKeyboardState();
69 TRACE1("dwKeyState=%u\n",dwKeyState);
70 CPoint pt(pInfo->GetPoint());
71 ::ClientToScreen(pInfo->GetSafeHwnd(),&pt);
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);
83 pInfo->SetDropEffect(dwEffect);
87 bool CIEShellDragDrop::DragDrop(CDD_OleDropTargetInfo *pInfo,LPSHELLFOLDER psfFolder,LPITEMIDLIST pidl)
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);
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());
101 if (pInfo->GetDataObject()->IsDataAvailable(CF_TEXT))
104 if (CWDClipboardData::Instance()->GetData(pInfo->GetDataObject(),&cfString,CWDClipboardData::e_cfString))
106 TRACE1("Received CF_TEXT %s\n",cfString.GetString());
109 if (pInfo->GetDataObject()->IsDataAvailable(CF_HDROP))
112 if (CWDClipboardData::Instance()->GetData(pInfo->GetDataObject(),&cfHDROP,CWDClipboardData::e_cfHDROP))
114 for(UINT i=0;i < cfHDROP.GetCount();i++)
115 TRACE2("Received CF_HDROP %s (%u)\n",cfHDROP.GetFileName(i),i);
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);