1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: win32_dragdrop.cpp,v 1.1 2004/01/03 23:31:34 asmax Exp $
7 * Authors: Cyril Deguet <asmax@via.ecp.fr>
8 * Olivier Teulière <ipkiss@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, USA.
23 *****************************************************************************/
28 #include "win32_dragdrop.hpp"
29 #include "../commands/cmd_add_item.hpp"
32 Win32DragDrop::Win32DragDrop( intf_thread_t *pIntf, bool playOnDrop ):
33 SkinObject( pIntf ), IDropTarget(), m_references( 1 ),
34 m_playOnDrop( playOnDrop )
39 STDMETHODIMP Win32DragDrop::QueryInterface( REFIID iid, void FAR* FAR* ppv )
41 // Tell other objects about our capabilities
42 if( iid == IID_IUnknown || iid == IID_IDropTarget )
49 return ResultFromScode( E_NOINTERFACE );
53 STDMETHODIMP_(ULONG) Win32DragDrop::AddRef()
55 return ++m_references;
59 STDMETHODIMP_(ULONG) Win32DragDrop::Release()
61 if( --m_references == 0 )
70 STDMETHODIMP Win32DragDrop::DragEnter( LPDATAOBJECT pDataObj,
71 DWORD grfKeyState, POINTL pt, DWORD *pdwEffect )
75 fmtetc.cfFormat = CF_HDROP;
77 fmtetc.dwAspect = DVASPECT_CONTENT;
79 fmtetc.tymed = TYMED_HGLOBAL;
81 // Check that the drag source provides CF_HDROP,
82 // which is the only format we accept
83 if( pDataObj->QueryGetData( &fmtetc ) == S_OK )
85 *pdwEffect = DROPEFFECT_COPY;
89 *pdwEffect = DROPEFFECT_NONE;
96 STDMETHODIMP Win32DragDrop::DragOver( DWORD grfKeyState, POINTL pt,
99 // For visual feedback
104 STDMETHODIMP Win32DragDrop::DragLeave()
106 // Remove visual feedback
111 STDMETHODIMP Win32DragDrop::Drop( LPDATAOBJECT pDataObj, DWORD grfKeyState,
112 POINTL pt, DWORD *pdwEffect )
114 // User has dropped on us -- get the CF_HDROP data from drag source
116 fmtetc.cfFormat = CF_HDROP;
118 fmtetc.dwAspect = DVASPECT_CONTENT;
120 fmtetc.tymed = TYMED_HGLOBAL;
123 HRESULT hr = pDataObj->GetData( &fmtetc, &medium );
127 // Grab a pointer to the data
128 HGLOBAL HFiles = medium.hGlobal;
129 HDROP HDrop = (HDROP)GlobalLock( HFiles );
131 // Notify VLC of the drop
134 // Release the pointer to the memory
135 GlobalUnlock( HFiles );
136 // ReleaseStgMedium( &medium );
140 *pdwEffect = DROPEFFECT_NONE;
147 void Win32DragDrop::HandleDrop( HDROP HDrop )
149 // Get the number of dropped files
150 int nbFiles = DragQueryFile( HDrop, 0xFFFFFFFF, NULL, 0 );
152 // For each dropped file
153 for( int i = 0; i < nbFiles; i++ )
155 // Get the name of the file
156 int nameLength = DragQueryFile( HDrop, i, NULL, 0 ) + 1;
157 char *psz_fileName = new char[nameLength];
158 DragQueryFile( HDrop, i, psz_fileName, nameLength );
161 CmdAddItem cmd( getIntf(), psz_fileName, m_playOnDrop );
164 delete[] psz_fileName;