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