]> git.sesse.net Git - vlc/blob - modules/gui/skins/gtk2/gtk2_dragdrop.cpp
da185aeb2ddcd22a6d21abba830c36cf5146a78c
[vlc] / modules / gui / skins / gtk2 / gtk2_dragdrop.cpp
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 $
6  *
7  * Authors: Cyril Deguet     <asmax@videolan.org>
8  *
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.
13  *
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.
18  *
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,
22  * USA.
23  *****************************************************************************/
24
25
26 //--- GTK2 -----------------------------------------------------------------
27 //#include <windows.h>
28
29 //--- SKIN ------------------------------------------------------------------
30 #include "event.h"
31 #include "gtk2_dragdrop.h"
32
33
34 /*
35 //---------------------------------------------------------------------------
36 GTK2DropObject::GTK2DropObject() : IDropTarget()
37 {
38     References = 1;
39 }
40 //---------------------------------------------------------------------------
41 GTK2DropObject::~GTK2DropObject()
42 {
43 }
44 //---------------------------------------------------------------------------
45 void GTK2DropObject::HandleDrop( HDROP HDrop )
46 {
47     // Get number of files that are dropped into vlc
48     int NbFiles = DragQueryFile( (HDROP)HDrop, 0xFFFFFFFF, NULL, 0 );
49
50     // For each dropped files
51     for( int i = 0; i < NbFiles; i++ )
52     {
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 );
57
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 );
61     }
62
63     DragFinish( (HDROP)HDrop );
64
65 }
66 //---------------------------------------------------------------------------
67 STDMETHODIMP GTK2DropObject::QueryInterface( REFIID iid, void FAR* FAR* ppv )
68 {
69     // Tell other objects about our capabilities
70     if( iid == IID_IUnknown || iid == IID_IDropTarget )
71     {
72         *ppv = this;
73         AddRef();
74         return S_OK;
75     }
76     *ppv = NULL;
77     return ResultFromScode( E_NOINTERFACE );
78 }
79 //---------------------------------------------------------------------------
80 STDMETHODIMP_(ULONG) GTK2DropObject::AddRef()
81 {
82     return ++References;
83 }
84 //---------------------------------------------------------------------------
85 STDMETHODIMP_(ULONG) GTK2DropObject::Release()
86 {
87     if( --References == 0 )
88     {
89         delete this;
90         return 0;
91     }
92     return References;
93 }
94 //---------------------------------------------------------------------------
95 STDMETHODIMP GTK2DropObject::DragEnter( LPDATAOBJECT pDataObj,
96     DWORD grfKeyState, POINTL pt, DWORD *pdwEffect )
97 {
98     FORMATETC fmtetc;
99
100     fmtetc.cfFormat = CF_HDROP;
101     fmtetc.ptd      = NULL;
102     fmtetc.dwAspect = DVASPECT_CONTENT;
103     fmtetc.lindex   = -1;
104     fmtetc.tymed    = TYMED_HGLOBAL;
105
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;
110     else
111         *pdwEffect = DROPEFFECT_NONE;
112
113     return S_OK;
114 }
115 //---------------------------------------------------------------------------
116 STDMETHODIMP GTK2DropObject::DragOver( DWORD grfKeyState, POINTL pt,
117    DWORD *pdwEffect )
118 {
119     // For visual feedback
120     // TODO
121     return S_OK;
122 }
123 //---------------------------------------------------------------------------
124 STDMETHODIMP GTK2DropObject::DragLeave()
125 {
126     // Remove visual feedback
127     // TODO
128     return S_OK;
129 }
130 //---------------------------------------------------------------------------
131 STDMETHODIMP GTK2DropObject::Drop( LPDATAOBJECT pDataObj, DWORD grfKeyState,
132    POINTL pt, DWORD *pdwEffect )
133 {
134     // User has dropped on us -- get the CF_HDROP data from drag source
135     FORMATETC fmtetc;
136     fmtetc.cfFormat = CF_HDROP;
137     fmtetc.ptd      = NULL;
138     fmtetc.dwAspect = DVASPECT_CONTENT;
139     fmtetc.lindex   = -1;
140     fmtetc.tymed    = TYMED_HGLOBAL;
141
142     STGMEDIUM medium;
143     HRESULT hr = pDataObj->GetData( &fmtetc, &medium );
144
145     if( !FAILED(hr) )
146     {
147         // Grab a pointer to the data
148         HGLOBAL HFiles = medium.hGlobal;
149         HDROP HDrop = (HDROP)GlobalLock( HFiles );
150
151         // Notify the Form of the drop
152         HandleDrop( HDrop );
153
154         // Release the pointer to the memory
155         GlobalUnlock( HFiles );
156 //        ReleaseStgMedium( &medium );
157     }
158     else
159     {
160         *pdwEffect = DROPEFFECT_NONE;
161         return hr;
162     }
163     return S_OK;
164 }
165 */