1 /*****************************************************************************
2 * gtk2_dragdrop.cpp: GTK2 implementation of the drag & drop
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: gtk2_dragdrop.cpp,v 1.1 2003/04/12 21:43:27 asmax Exp $
7 * Authors: Cyril Deguet <asmax@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111,
23 *****************************************************************************/
26 //--- GTK2 -----------------------------------------------------------------
27 //#include <windows.h>
29 //--- SKIN ------------------------------------------------------------------
31 #include "gtk2_dragdrop.h"
35 //---------------------------------------------------------------------------
36 GTK2DropObject::GTK2DropObject() : IDropTarget()
40 //---------------------------------------------------------------------------
41 GTK2DropObject::~GTK2DropObject()
44 //---------------------------------------------------------------------------
45 void GTK2DropObject::HandleDrop( HDROP HDrop )
47 // Get number of files that are dropped into vlc
48 int NbFiles = DragQueryFile( (HDROP)HDrop, 0xFFFFFFFF, NULL, 0 );
50 // For each dropped files
51 for( int i = 0; i < NbFiles; i++ )
53 // Get the name of the file
54 int NameLength = DragQueryFile( (HDROP)HDrop, i, NULL, 0 ) + 1;
55 char *FileName = new char[NameLength];
56 DragQueryFile( (HDROP)HDrop, i, FileName, NameLength );
58 // The pointer must not be deleted here because it will be deleted
59 // in the VLC specific messages processing function
60 PostMessage( NULL, VLC_DROP, (WPARAM)FileName, 0 );
63 DragFinish( (HDROP)HDrop );
66 //---------------------------------------------------------------------------
67 STDMETHODIMP GTK2DropObject::QueryInterface( REFIID iid, void FAR* FAR* ppv )
69 // Tell other objects about our capabilities
70 if( iid == IID_IUnknown || iid == IID_IDropTarget )
77 return ResultFromScode( E_NOINTERFACE );
79 //---------------------------------------------------------------------------
80 STDMETHODIMP_(ULONG) GTK2DropObject::AddRef()
84 //---------------------------------------------------------------------------
85 STDMETHODIMP_(ULONG) GTK2DropObject::Release()
87 if( --References == 0 )
94 //---------------------------------------------------------------------------
95 STDMETHODIMP GTK2DropObject::DragEnter( LPDATAOBJECT pDataObj,
96 DWORD grfKeyState, POINTL pt, DWORD *pdwEffect )
100 fmtetc.cfFormat = CF_HDROP;
102 fmtetc.dwAspect = DVASPECT_CONTENT;
104 fmtetc.tymed = TYMED_HGLOBAL;
106 // Check that the drag source provides CF_HDROP,
107 // which is the only format we accept
108 if( pDataObj->QueryGetData( &fmtetc ) == S_OK )
109 *pdwEffect = DROPEFFECT_COPY;
111 *pdwEffect = DROPEFFECT_NONE;
115 //---------------------------------------------------------------------------
116 STDMETHODIMP GTK2DropObject::DragOver( DWORD grfKeyState, POINTL pt,
119 // For visual feedback
123 //---------------------------------------------------------------------------
124 STDMETHODIMP GTK2DropObject::DragLeave()
126 // Remove visual feedback
130 //---------------------------------------------------------------------------
131 STDMETHODIMP GTK2DropObject::Drop( LPDATAOBJECT pDataObj, DWORD grfKeyState,
132 POINTL pt, DWORD *pdwEffect )
134 // User has dropped on us -- get the CF_HDROP data from drag source
136 fmtetc.cfFormat = CF_HDROP;
138 fmtetc.dwAspect = DVASPECT_CONTENT;
140 fmtetc.tymed = TYMED_HGLOBAL;
143 HRESULT hr = pDataObj->GetData( &fmtetc, &medium );
147 // Grab a pointer to the data
148 HGLOBAL HFiles = medium.hGlobal;
149 HDROP HDrop = (HDROP)GlobalLock( HFiles );
151 // Notify the Form of the drop
154 // Release the pointer to the memory
155 GlobalUnlock( HFiles );
156 // ReleaseStgMedium( &medium );
160 *pdwEffect = DROPEFFECT_NONE;