1 /*****************************************************************************
2 * win32_dragdrop.cpp: Win32 implementation of the drag & drop
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: win32_dragdrop.cpp,v 1.5 2003/10/22 19:12:56 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( bool playondrop ) : IDropTarget()
41 PlayOnDrop = playondrop;
43 //---------------------------------------------------------------------------
44 Win32DropObject::~Win32DropObject()
47 //---------------------------------------------------------------------------
48 void Win32DropObject::HandleDrop( HDROP HDrop )
50 // Get number of files that are dropped into vlc
51 int NbFiles = DragQueryFile( (HDROP)HDrop, 0xFFFFFFFF, NULL, 0 );
53 // For each dropped files
54 for( int i = 0; i < NbFiles; i++ )
56 // Get the name of the file
57 int NameLength = DragQueryFile( (HDROP)HDrop, i, NULL, 0 ) + 1;
58 char *FileName = new char[NameLength];
59 DragQueryFile( (HDROP)HDrop, i, FileName, NameLength );
63 // The pointer must not be deleted here because it will be deleted
64 // in the VLC specific messages processing function
65 PostMessage( NULL, VLC_DROP, (WPARAM)FileName, 1 );
69 // The pointer must not be deleted here because it will be deleted
70 // in the VLC specific messages processing function
71 PostMessage( NULL, VLC_DROP, (WPARAM)FileName, 0 );
75 DragFinish( (HDROP)HDrop );
77 //---------------------------------------------------------------------------
78 STDMETHODIMP Win32DropObject::QueryInterface( REFIID iid, void FAR* FAR* ppv )
80 // Tell other objects about our capabilities
81 if( iid == IID_IUnknown || iid == IID_IDropTarget )
88 return ResultFromScode( E_NOINTERFACE );
90 //---------------------------------------------------------------------------
91 STDMETHODIMP_(ULONG) Win32DropObject::AddRef()
95 //---------------------------------------------------------------------------
96 STDMETHODIMP_(ULONG) Win32DropObject::Release()
98 if( --References == 0 )
105 //---------------------------------------------------------------------------
106 STDMETHODIMP Win32DropObject::DragEnter( LPDATAOBJECT pDataObj,
107 DWORD grfKeyState, POINTL pt, DWORD *pdwEffect )
111 fmtetc.cfFormat = CF_HDROP;
113 fmtetc.dwAspect = DVASPECT_CONTENT;
115 fmtetc.tymed = TYMED_HGLOBAL;
117 // Check that the drag source provides CF_HDROP,
118 // which is the only format we accept
119 if( pDataObj->QueryGetData( &fmtetc ) == S_OK )
120 *pdwEffect = DROPEFFECT_COPY;
122 *pdwEffect = DROPEFFECT_NONE;
126 //---------------------------------------------------------------------------
127 STDMETHODIMP Win32DropObject::DragOver( DWORD grfKeyState, POINTL pt,
130 // For visual feedback
134 //---------------------------------------------------------------------------
135 STDMETHODIMP Win32DropObject::DragLeave()
137 // Remove visual feedback
141 //---------------------------------------------------------------------------
142 STDMETHODIMP Win32DropObject::Drop( LPDATAOBJECT pDataObj, DWORD grfKeyState,
143 POINTL pt, DWORD *pdwEffect )
145 // User has dropped on us -- get the CF_HDROP data from drag source
147 fmtetc.cfFormat = CF_HDROP;
149 fmtetc.dwAspect = DVASPECT_CONTENT;
151 fmtetc.tymed = TYMED_HGLOBAL;
154 HRESULT hr = pDataObj->GetData( &fmtetc, &medium );
158 // Grab a pointer to the data
159 HGLOBAL HFiles = medium.hGlobal;
160 HDROP HDrop = (HDROP)GlobalLock( HFiles );
162 // Notify the Form of the drop
165 // Release the pointer to the memory
166 GlobalUnlock( HFiles );
167 // ReleaseStgMedium( &medium );
171 *pdwEffect = DROPEFFECT_NONE;