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 //*******************************************************************************
18 // IM_OleImageDropTarget.cpp : implementation file
22 #include "UIDragImage.h"
23 #include "UIImageDropTarget.h"
28 static char THIS_FILE[] = __FILE__;
31 /////////////////////////////////////////////////////////////////////////////
32 // CUI_ImageDropTarget
34 CUI_ImageDropTarget::CUI_ImageDropTarget() : m_pImage(NULL),m_pWnd(NULL)
36 m_nCFFormat = ::RegisterClipboardFormat(_T("APP_CF_DD_LISTCTRL_IMAGE"));
40 CUI_ImageDropTarget::~CUI_ImageDropTarget()
45 /////////////////////////////////////////////////
47 // For OLE drag and drop
49 /////////////////////////////////////////////////
50 void CUI_ImageDropTarget::OnDragLeave( CWnd* pWnd)
55 // Erase the old drag image and delete the temporary widget.
56 CClientDC dc(GetImageWin(pWnd));
57 m_pImage->DrawDragImage (&dc,m_ptOldImage,m_ptItem);
61 COleDropTarget::OnDragLeave(pWnd);
64 DROPEFFECT CUI_ImageDropTarget::OnDragEnter( CWnd* pWnd, COleDataObject* pDataObject, DWORD dwKeyState, CPoint point )
66 DROPEFFECT dwEffect = COleDropTarget::OnDragEnter(pWnd,pDataObject,dwKeyState,point);
67 HGLOBAL hData = pDataObject->GetGlobalData(GetClipboardFormat());
71 // Create a temporary image for drag imaging.
73 int *pData = (int*)::GlobalLock(hData);
75 int nSelected = *pData++;
76 DD_ImageData *pImageData = (DD_ImageData*)pData;
77 CPoint pt = pImageData->m_ptDrag;
85 m_pImage = new CDragDropImage(nSelected,nType);
86 for(i=0;i < nSelected;i++)
88 m_pImage->AddItem(&pImageData->m_rcItem,&pImageData->m_rcIcon);
95 ::GlobalUnlock(hData);
96 return DROPEFFECT_NONE;
100 pData = (int*)pImageData;
101 rcItem.left = *pData++;
102 rcItem.right = *pData++;
103 rcItem.top = *pData++;
104 rcItem.bottom = *pData;
105 ::GlobalUnlock(hData);
110 CClientDC dc(GetImageWin(pWnd));
111 pWnd->ClientToScreen(&point);
112 m_pWnd->ScreenToClient(&point);
116 CPoint ptDrag (point.x, point.y);
117 m_ptOldImage.x = m_ptOldImage.y = -32000;
123 DROPEFFECT CUI_ImageDropTarget::OnDragOver( CWnd* pWnd, COleDataObject* pDataObject, DWORD dwKeyState, CPoint point )
125 DROPEFFECT dwEffect = COleDropTarget::OnDragOver(pWnd,pDataObject,dwKeyState,point);
126 if (!pDataObject->IsDataAvailable(GetClipboardFormat()))
128 // Erase the old drag image and draw a new one if the cursor has moved.
129 CClientDC dc(GetImageWin(pWnd));
130 pWnd->ClientToScreen(&point);
131 m_pWnd->ScreenToClient(&point);
133 if (m_pImage && point != m_ptPrevPos)
135 // erase the old image
136 m_pImage->DrawDragImage(&dc,m_ptOldImage,m_ptItem);
137 // CPoint ptDrag (point.x - m_sizeDelta.cx, point.y - m_sizeDelta.cy);
138 CPoint ptDrag (point.x, point.y);
139 // draw the new image
140 m_pImage->DrawDragImage (&dc, ptDrag, m_ptItem);
142 m_ptOldImage = ptDrag;
148 BOOL CUI_ImageDropTarget::OnDrop( CWnd* pWnd, COleDataObject* pDataObject, DROPEFFECT dropEffect, CPoint point )
150 BOOL bRet = COleDropTarget::OnDrop(pWnd,pDataObject,dropEffect,point);
151 if (!pDataObject->IsDataAvailable(GetClipboardFormat()))
154 // Erase the old drag image and delete the temporary widget.
156 CClientDC dc(GetImageWin(pWnd));
157 if (m_pImage != NULL)
159 m_pImage->DrawDragImage (&dc,m_ptOldImage,m_ptItem);
166 void CUI_ImageDropTarget::EraseOldImage()
168 if (m_pImage == NULL)
170 CClientDC dc(GetImageWin(NULL));
171 m_pImage->DrawDragImage(&dc,m_ptOldImage,m_ptItem);
172 m_ptOldImage.x = m_ptOldImage.y = -32000;