1 /*****************************************************************************
\r
2 * dragdrop.cpp: drag and drop management
\r
3 *****************************************************************************
\r
4 * Copyright (C) 2002 VideoLAN
\r
6 * Authors: Olivier Teuliere <ipkiss@via.ecp.fr>
\r
8 * This program is free software; you can redistribute it and/or modify
\r
9 * it under the terms of the GNU General Public License as published by
\r
10 * the Free Software Foundation; either version 2 of the License, or
\r
11 * (at your option) any later version.
\r
13 * This program is distributed in the hope that it will be useful,
\r
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
16 * GNU General Public License for more details.
\r
18 * You should have received a copy of the GNU General Public License
\r
19 * along with this program; if not, write to the Free Software
\r
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
\r
21 *****************************************************************************/
\r
26 #include "dragdrop.h"
\r
28 //---------------------------------------------------------------------------
\r
29 __fastcall TDropTarget::TDropTarget( HWND HForm ) : IDropTarget()
\r
34 //---------------------------------------------------------------------------
\r
35 __fastcall TDropTarget::~TDropTarget()
\r
38 //---------------------------------------------------------------------------
\r
39 /* helper routine to notify Form of drop on target */
\r
40 void __fastcall TDropTarget::HandleDrop( HDROP HDrop )
\r
42 SendMessage( FormHandle, WM_OLEDROP, (WPARAM)HDrop, 0 );
\r
44 //---------------------------------------------------------------------------
\r
45 STDMETHODIMP TDropTarget::QueryInterface( REFIID iid, void FAR* FAR* ppv )
\r
47 /* tell other objects about our capabilities */
\r
48 if( iid == IID_IUnknown || iid == IID_IDropTarget )
\r
55 return ResultFromScode( E_NOINTERFACE );
\r
57 //---------------------------------------------------------------------------
\r
58 STDMETHODIMP_(ULONG) TDropTarget::AddRef()
\r
60 return ++References;
\r
62 //---------------------------------------------------------------------------
\r
63 STDMETHODIMP_(ULONG) TDropTarget::Release()
\r
65 if( --References == 0 )
\r
72 //---------------------------------------------------------------------------
\r
73 /* Indicates whether a drop can be accepted, and, if so,
\r
74 * the effect of the drop */
\r
75 STDMETHODIMP TDropTarget::DragEnter( LPDATAOBJECT pDataObj, DWORD grfKeyState,
\r
76 POINTL pt, DWORD *pdwEffect )
\r
80 fmtetc.cfFormat = CF_HDROP;
\r
82 fmtetc.dwAspect = DVASPECT_CONTENT;
\r
84 fmtetc.tymed = TYMED_HGLOBAL;
\r
86 /* Check that the drag source provides CF_HDROP,
\r
87 * which is the only format we accept */
\r
88 if( pDataObj->QueryGetData( &fmtetc ) == S_OK )
\r
89 *pdwEffect = DROPEFFECT_COPY;
\r
91 *pdwEffect = DROPEFFECT_NONE;
\r
95 //---------------------------------------------------------------------------
\r
96 /* for visual feedback */
\r
97 STDMETHODIMP TDropTarget::DragOver( DWORD grfKeyState, POINTL pt,
\r
102 //---------------------------------------------------------------------------
\r
103 /* remove visual feedback */
\r
104 STDMETHODIMP TDropTarget::DragLeave()
\r
108 //---------------------------------------------------------------------------
\r
109 /* something has been dropped */
\r
110 STDMETHODIMP TDropTarget::Drop( LPDATAOBJECT pDataObj, DWORD grfKeyState,
\r
111 POINTL pt, DWORD *pdwEffect )
\r
113 /* user has dropped on us -- get the CF_HDROP data from drag source */
\r
115 fmtetc.cfFormat = CF_HDROP;
\r
117 fmtetc.dwAspect = DVASPECT_CONTENT;
\r
118 fmtetc.lindex = -1;
\r
119 fmtetc.tymed = TYMED_HGLOBAL;
\r
122 HRESULT hr = pDataObj->GetData( &fmtetc, &medium );
\r
126 /* grab a pointer to the data */
\r
127 HGLOBAL HFiles = medium.hGlobal;
\r
128 HDROP HDrop = (HDROP)GlobalLock( HFiles );
\r
130 /* call the helper routine which will notify the Form of the drop */
\r
131 HandleDrop( HDrop );
\r
133 /* release the pointer to the memory */
\r
134 GlobalUnlock( HFiles );
\r
135 ReleaseStgMedium( &medium );
\r
139 *pdwEffect = DROPEFFECT_NONE;
\r