]> git.sesse.net Git - vlc/blob - modules/gui/skins/win32/win32_dragdrop.cpp
517fc67a05bac39396aff9ae4adcae85da42517a
[vlc] / modules / gui / skins / win32 / win32_dragdrop.cpp
1 /*****************************************************************************
2  * win32_dragdrop.cpp: Win32 implementation of the drag & drop
3  *****************************************************************************
4  * Copyright (C) 2003 VideoLAN
5  * $Id: win32_dragdrop.cpp,v 1.4 2003/04/16 21:40:07 ipkiss Exp $
6  *
7  * Authors: Olivier Teulière <ipkiss@via.ecp.fr>
8  *          Emmanuel Puig    <karibu@via.ecp.fr>
9  *
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.
14  *
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.
19  *
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,
23  * USA.
24  *****************************************************************************/
25
26 #ifdef WIN32
27
28 //--- WIN32 -----------------------------------------------------------------
29 #include <windows.h>
30
31 //--- SKIN ------------------------------------------------------------------
32 #include "../src/event.h"
33 #include "win32_dragdrop.h"
34
35
36
37 //---------------------------------------------------------------------------
38 Win32DropObject::Win32DropObject() : IDropTarget()
39 {
40     References = 1;
41 }
42 //---------------------------------------------------------------------------
43 Win32DropObject::~Win32DropObject()
44 {
45 }
46 //---------------------------------------------------------------------------
47 void Win32DropObject::HandleDrop( HDROP HDrop )
48 {
49     // Get number of files that are dropped into vlc
50     int NbFiles = DragQueryFile( (HDROP)HDrop, 0xFFFFFFFF, NULL, 0 );
51
52     // For each dropped files
53     for( int i = 0; i < NbFiles; i++ )
54     {
55         // Get the name of the file
56         int NameLength = DragQueryFile( (HDROP)HDrop, i, NULL, 0 ) + 1;
57         char *FileName = new char[NameLength];
58         DragQueryFile( (HDROP)HDrop, i, FileName, NameLength );
59
60         // The pointer must not be deleted here because it will be deleted
61         // in the VLC specific messages processing function
62         PostMessage( NULL, VLC_DROP, (WPARAM)FileName, 0 );
63     }
64
65     DragFinish( (HDROP)HDrop );
66
67 }
68 //---------------------------------------------------------------------------
69 STDMETHODIMP Win32DropObject::QueryInterface( REFIID iid, void FAR* FAR* ppv )
70 {
71     // Tell other objects about our capabilities
72     if( iid == IID_IUnknown || iid == IID_IDropTarget )
73     {
74         *ppv = this;
75         AddRef();
76         return S_OK;
77     }
78     *ppv = NULL;
79     return ResultFromScode( E_NOINTERFACE );
80 }
81 //---------------------------------------------------------------------------
82 STDMETHODIMP_(ULONG) Win32DropObject::AddRef()
83 {
84     return ++References;
85 }
86 //---------------------------------------------------------------------------
87 STDMETHODIMP_(ULONG) Win32DropObject::Release()
88 {
89     if( --References == 0 )
90     {
91         delete this;
92         return 0;
93     }
94     return References;
95 }
96 //---------------------------------------------------------------------------
97 STDMETHODIMP Win32DropObject::DragEnter( LPDATAOBJECT pDataObj,
98     DWORD grfKeyState, POINTL pt, DWORD *pdwEffect )
99 {
100     FORMATETC fmtetc;
101
102     fmtetc.cfFormat = CF_HDROP;
103     fmtetc.ptd      = NULL;
104     fmtetc.dwAspect = DVASPECT_CONTENT;
105     fmtetc.lindex   = -1;
106     fmtetc.tymed    = TYMED_HGLOBAL;
107
108     // Check that the drag source provides CF_HDROP,
109     // which is the only format we accept
110     if( pDataObj->QueryGetData( &fmtetc ) == S_OK )
111         *pdwEffect = DROPEFFECT_COPY;
112     else
113         *pdwEffect = DROPEFFECT_NONE;
114
115     return S_OK;
116 }
117 //---------------------------------------------------------------------------
118 STDMETHODIMP Win32DropObject::DragOver( DWORD grfKeyState, POINTL pt,
119    DWORD *pdwEffect )
120 {
121     // For visual feedback
122     // TODO
123     return S_OK;
124 }
125 //---------------------------------------------------------------------------
126 STDMETHODIMP Win32DropObject::DragLeave()
127 {
128     // Remove visual feedback
129     // TODO
130     return S_OK;
131 }
132 //---------------------------------------------------------------------------
133 STDMETHODIMP Win32DropObject::Drop( LPDATAOBJECT pDataObj, DWORD grfKeyState,
134    POINTL pt, DWORD *pdwEffect )
135 {
136     // User has dropped on us -- get the CF_HDROP data from drag source
137     FORMATETC fmtetc;
138     fmtetc.cfFormat = CF_HDROP;
139     fmtetc.ptd      = NULL;
140     fmtetc.dwAspect = DVASPECT_CONTENT;
141     fmtetc.lindex   = -1;
142     fmtetc.tymed    = TYMED_HGLOBAL;
143
144     STGMEDIUM medium;
145     HRESULT hr = pDataObj->GetData( &fmtetc, &medium );
146
147     if( !FAILED(hr) )
148     {
149         // Grab a pointer to the data
150         HGLOBAL HFiles = medium.hGlobal;
151         HDROP HDrop = (HDROP)GlobalLock( HFiles );
152
153         // Notify the Form of the drop
154         HandleDrop( HDrop );
155
156         // Release the pointer to the memory
157         GlobalUnlock( HFiles );
158 //        ReleaseStgMedium( &medium );
159     }
160     else
161     {
162         *pdwEffect = DROPEFFECT_NONE;
163         return hr;
164     }
165     return S_OK;
166 }
167
168 #endif