Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

win32_dragdrop.cpp

00001 /*****************************************************************************
00002  * win32_dragdrop.cpp
00003  *****************************************************************************
00004  * Copyright (C) 2003 the VideoLAN team
00005  * $Id: win32_dragdrop.cpp 11664 2005-07-09 06:17:09Z courmisch $
00006  *
00007  * Authors: Cyril Deguet     <[email protected]>
00008  *          Olivier Teulière <[email protected]>
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00023  *****************************************************************************/
00024 
00025 #ifdef WIN32_SKINS
00026 
00027 #include <windows.h>
00028 #include "win32_dragdrop.hpp"
00029 #include "../commands/cmd_add_item.hpp"
00030 
00031 
00032 Win32DragDrop::Win32DragDrop( intf_thread_t *pIntf, bool playOnDrop ):
00033     SkinObject( pIntf ), IDropTarget(), m_references( 1 ),
00034     m_playOnDrop( playOnDrop )
00035 {
00036 }
00037 
00038 
00039 STDMETHODIMP Win32DragDrop::QueryInterface( REFIID iid, void FAR* FAR* ppv )
00040 {
00041     // Tell other objects about our capabilities
00042     if( iid == IID_IUnknown || iid == IID_IDropTarget )
00043     {
00044         *ppv = this;
00045         AddRef();
00046         return S_OK;
00047     }
00048     *ppv = NULL;
00049     return ResultFromScode( E_NOINTERFACE );
00050 }
00051 
00052 
00053 STDMETHODIMP_(ULONG) Win32DragDrop::AddRef()
00054 {
00055     return ++m_references;
00056 }
00057 
00058 
00059 STDMETHODIMP_(ULONG) Win32DragDrop::Release()
00060 {
00061     if( --m_references == 0 )
00062     {
00063         delete this;
00064         return 0;
00065     }
00066     return m_references;
00067 }
00068 
00069 
00070 STDMETHODIMP Win32DragDrop::DragEnter( LPDATAOBJECT pDataObj,
00071     DWORD grfKeyState, POINTL pt, DWORD *pdwEffect )
00072 {
00073     FORMATETC fmtetc;
00074 
00075     fmtetc.cfFormat = CF_HDROP;
00076     fmtetc.ptd      = NULL;
00077     fmtetc.dwAspect = DVASPECT_CONTENT;
00078     fmtetc.lindex   = -1;
00079     fmtetc.tymed    = TYMED_HGLOBAL;
00080 
00081     // Check that the drag source provides CF_HDROP,
00082     // which is the only format we accept
00083     if( pDataObj->QueryGetData( &fmtetc ) == S_OK )
00084     {
00085         *pdwEffect = DROPEFFECT_COPY;
00086     }
00087     else
00088     {
00089         *pdwEffect = DROPEFFECT_NONE;
00090     }
00091 
00092     return S_OK;
00093 }
00094 
00095 
00096 STDMETHODIMP Win32DragDrop::DragOver( DWORD grfKeyState, POINTL pt,
00097                                       DWORD *pdwEffect )
00098 {
00099     // For visual feedback
00100     return S_OK;
00101 }
00102 
00103 
00104 STDMETHODIMP Win32DragDrop::DragLeave()
00105 {
00106     // Remove visual feedback
00107     return S_OK;
00108 }
00109 
00110 
00111 STDMETHODIMP Win32DragDrop::Drop( LPDATAOBJECT pDataObj, DWORD grfKeyState,
00112     POINTL pt, DWORD *pdwEffect )
00113 {
00114     // User has dropped on us -- get the CF_HDROP data from drag source
00115     FORMATETC fmtetc;
00116     fmtetc.cfFormat = CF_HDROP;
00117     fmtetc.ptd      = NULL;
00118     fmtetc.dwAspect = DVASPECT_CONTENT;
00119     fmtetc.lindex   = -1;
00120     fmtetc.tymed    = TYMED_HGLOBAL;
00121 
00122     STGMEDIUM medium;
00123     HRESULT hr = pDataObj->GetData( &fmtetc, &medium );
00124 
00125     if( !FAILED(hr) )
00126     {
00127         // Grab a pointer to the data
00128         HGLOBAL HFiles = medium.hGlobal;
00129         HDROP HDrop = (HDROP)GlobalLock( HFiles );
00130 
00131         // Notify VLC of the drop
00132         HandleDrop( HDrop );
00133 
00134         // Release the pointer to the memory
00135         GlobalUnlock( HFiles );
00136 //        ReleaseStgMedium( &medium );
00137     }
00138     else
00139     {
00140         *pdwEffect = DROPEFFECT_NONE;
00141         return hr;
00142     }
00143     return S_OK;
00144 }
00145 
00146 
00147 void Win32DragDrop::HandleDrop( HDROP HDrop )
00148 {
00149     // Get the number of dropped files
00150     int nbFiles = DragQueryFile( HDrop, 0xFFFFFFFF, NULL, 0 );
00151 
00152     // For each dropped file
00153     for( int i = 0; i < nbFiles; i++ )
00154     {
00155         // Get the name of the file
00156         int nameLength = DragQueryFile( HDrop, i, NULL, 0 ) + 1;
00157         char *psz_fileName = new char[nameLength];
00158         DragQueryFile( HDrop, i, psz_fileName, nameLength );
00159 
00160         // Add the file
00161         CmdAddItem cmd( getIntf(), psz_fileName, m_playOnDrop );
00162         cmd.execute();
00163 
00164         delete[] psz_fileName;
00165     }
00166 
00167     DragFinish( HDrop );
00168 }
00169 
00170 
00171 #endif

Generated on Tue Dec 20 10:14:44 2005 for vlc-0.8.4a by  doxygen 1.4.2