1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 the VideoLAN team
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, 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 if( GetVersion() < 0x80000000 )
151 // Use Unicode for Windows NT and above
153 // Get the number of dropped files
154 int nbFiles = DragQueryFileW( HDrop, 0xFFFFFFFF, NULL, 0 );
156 // For each dropped file
157 for( int i = 0; i < nbFiles; i++ )
159 // Get the name of the file
160 int nameLength = DragQueryFileW( HDrop, i, NULL, 0 ) + 1;
161 wchar_t *psz_fileName = new WCHAR[nameLength];
162 DragQueryFileW( HDrop, i, psz_fileName, nameLength );
165 CmdAddItem cmd(getIntf(),sFromWide(psz_fileName),m_playOnDrop);
168 delete[] psz_fileName;
173 int nbFiles = DragQueryFile( HDrop, 0xFFFFFFFF, NULL, 0 );
175 for( int i = 0; i < nbFiles; i++ )
177 int nameLength = DragQueryFile( HDrop, i, NULL, 0 ) + 1;
178 char *psz_fileName = new char[nameLength];
179 DragQueryFile( HDrop, i, psz_fileName, nameLength );
181 CmdAddItem cmd(getIntf(),sFromLocale(psz_fileName),m_playOnDrop);
184 delete[] psz_fileName;