1 /*****************************************************************************
2 * win32_dragdrop.cpp: Win32 implementation of the drag & drop
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: win32_dragdrop.cpp,v 1.4 2003/04/16 21:40:07 ipkiss Exp $
7 * Authors: Olivier Teulière <ipkiss@via.ecp.fr>
8 * Emmanuel Puig <karibu@via.ecp.fr>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111,
24 *****************************************************************************/
28 //--- WIN32 -----------------------------------------------------------------
31 //--- SKIN ------------------------------------------------------------------
32 #include "../src/event.h"
33 #include "win32_dragdrop.h"
37 //---------------------------------------------------------------------------
38 Win32DropObject::Win32DropObject() : IDropTarget()
42 //---------------------------------------------------------------------------
43 Win32DropObject::~Win32DropObject()
46 //---------------------------------------------------------------------------
47 void Win32DropObject::HandleDrop( HDROP HDrop )
49 // Get number of files that are dropped into vlc
50 int NbFiles = DragQueryFile( (HDROP)HDrop, 0xFFFFFFFF, NULL, 0 );
52 // For each dropped files
53 for( int i = 0; i < NbFiles; i++ )
55 // Get the name of the file
56 int NameLength = DragQueryFile( (HDROP)HDrop, i, NULL, 0 ) + 1;
57 char *FileName = new char[NameLength];
58 DragQueryFile( (HDROP)HDrop, i, FileName, NameLength );
60 // The pointer must not be deleted here because it will be deleted
61 // in the VLC specific messages processing function
62 PostMessage( NULL, VLC_DROP, (WPARAM)FileName, 0 );
65 DragFinish( (HDROP)HDrop );
68 //---------------------------------------------------------------------------
69 STDMETHODIMP Win32DropObject::QueryInterface( REFIID iid, void FAR* FAR* ppv )
71 // Tell other objects about our capabilities
72 if( iid == IID_IUnknown || iid == IID_IDropTarget )
79 return ResultFromScode( E_NOINTERFACE );
81 //---------------------------------------------------------------------------
82 STDMETHODIMP_(ULONG) Win32DropObject::AddRef()
86 //---------------------------------------------------------------------------
87 STDMETHODIMP_(ULONG) Win32DropObject::Release()
89 if( --References == 0 )
96 //---------------------------------------------------------------------------
97 STDMETHODIMP Win32DropObject::DragEnter( LPDATAOBJECT pDataObj,
98 DWORD grfKeyState, POINTL pt, DWORD *pdwEffect )
102 fmtetc.cfFormat = CF_HDROP;
104 fmtetc.dwAspect = DVASPECT_CONTENT;
106 fmtetc.tymed = TYMED_HGLOBAL;
108 // Check that the drag source provides CF_HDROP,
109 // which is the only format we accept
110 if( pDataObj->QueryGetData( &fmtetc ) == S_OK )
111 *pdwEffect = DROPEFFECT_COPY;
113 *pdwEffect = DROPEFFECT_NONE;
117 //---------------------------------------------------------------------------
118 STDMETHODIMP Win32DropObject::DragOver( DWORD grfKeyState, POINTL pt,
121 // For visual feedback
125 //---------------------------------------------------------------------------
126 STDMETHODIMP Win32DropObject::DragLeave()
128 // Remove visual feedback
132 //---------------------------------------------------------------------------
133 STDMETHODIMP Win32DropObject::Drop( LPDATAOBJECT pDataObj, DWORD grfKeyState,
134 POINTL pt, DWORD *pdwEffect )
136 // User has dropped on us -- get the CF_HDROP data from drag source
138 fmtetc.cfFormat = CF_HDROP;
140 fmtetc.dwAspect = DVASPECT_CONTENT;
142 fmtetc.tymed = TYMED_HGLOBAL;
145 HRESULT hr = pDataObj->GetData( &fmtetc, &medium );
149 // Grab a pointer to the data
150 HGLOBAL HFiles = medium.hGlobal;
151 HDROP HDrop = (HDROP)GlobalLock( HFiles );
153 // Notify the Form of the drop
156 // Release the pointer to the memory
157 GlobalUnlock( HFiles );
158 // ReleaseStgMedium( &medium );
162 *pdwEffect = DROPEFFECT_NONE;