00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
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
00082
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
00100 return S_OK;
00101 }
00102
00103
00104 STDMETHODIMP Win32DragDrop::DragLeave()
00105 {
00106
00107 return S_OK;
00108 }
00109
00110
00111 STDMETHODIMP Win32DragDrop::Drop( LPDATAOBJECT pDataObj, DWORD grfKeyState,
00112 POINTL pt, DWORD *pdwEffect )
00113 {
00114
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
00128 HGLOBAL HFiles = medium.hGlobal;
00129 HDROP HDrop = (HDROP)GlobalLock( HFiles );
00130
00131
00132 HandleDrop( HDrop );
00133
00134
00135 GlobalUnlock( HFiles );
00136
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
00150 int nbFiles = DragQueryFile( HDrop, 0xFFFFFFFF, NULL, 0 );
00151
00152
00153 for( int i = 0; i < nbFiles; i++ )
00154 {
00155
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
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