]> git.sesse.net Git - vlc/blob - modules/gui/win32/dragdrop.cpp
Another attempt at fixing the soundstick issue (unconfirmed).
[vlc] / modules / gui / win32 / dragdrop.cpp
1 /*****************************************************************************\r
2  * dragdrop.cpp: drag and drop management\r
3  *****************************************************************************\r
4  * Copyright (C) 2002 VideoLAN\r
5  *\r
6  * Authors: Olivier Teuliere <ipkiss@via.ecp.fr>\r
7  *\r
8  * This program is free software; you can redistribute it and/or modify\r
9  * it under the terms of the GNU General Public License as published by\r
10  * the Free Software Foundation; either version 2 of the License, or\r
11  * (at your option) any later version.\r
12  *\r
13  * This program is distributed in the hope that it will be useful,\r
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
16  * GNU General Public License for more details.\r
17  *\r
18  * You should have received a copy of the GNU General Public License\r
19  * along with this program; if not, write to the Free Software\r
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.\r
21  *****************************************************************************/\r
22 \r
23 #include <vcl.h>\r
24 #pragma hdrstop\r
25 \r
26 #include "dragdrop.h"\r
27 \r
28 //---------------------------------------------------------------------------\r
29 __fastcall TDropTarget::TDropTarget( HWND HForm ) : IDropTarget()\r
30 {\r
31     FormHandle = HForm;\r
32     References = 1;\r
33 }\r
34 //---------------------------------------------------------------------------\r
35 __fastcall TDropTarget::~TDropTarget()\r
36 {\r
37 }\r
38 //---------------------------------------------------------------------------\r
39 /* helper routine to notify Form of drop on target */\r
40 void __fastcall TDropTarget::HandleDrop( HDROP HDrop )\r
41 {\r
42     SendMessage( FormHandle, WM_OLEDROP, (WPARAM)HDrop, 0 );\r
43 }\r
44 //---------------------------------------------------------------------------\r
45 STDMETHODIMP TDropTarget::QueryInterface( REFIID iid, void FAR* FAR* ppv )\r
46 {\r
47     /* tell other objects about our capabilities */\r
48     if( iid == IID_IUnknown || iid == IID_IDropTarget )\r
49     {\r
50         *ppv = this;\r
51         AddRef();\r
52         return S_OK;\r
53     }\r
54     *ppv = NULL;\r
55     return ResultFromScode( E_NOINTERFACE );\r
56 }\r
57 //---------------------------------------------------------------------------\r
58 STDMETHODIMP_(ULONG) TDropTarget::AddRef()\r
59 {\r
60     return ++References;\r
61 }\r
62 //---------------------------------------------------------------------------\r
63 STDMETHODIMP_(ULONG) TDropTarget::Release()\r
64 {\r
65     if( --References == 0 )\r
66     {\r
67         delete this;\r
68         return 0;\r
69     }\r
70     return References;\r
71 }\r
72 //---------------------------------------------------------------------------\r
73 /* Indicates whether a drop can be accepted, and, if so,\r
74  * the effect of the drop */\r
75 STDMETHODIMP TDropTarget::DragEnter( LPDATAOBJECT pDataObj, DWORD grfKeyState,\r
76    POINTL pt, DWORD *pdwEffect )\r
77 {\r
78     FORMATETC fmtetc;\r
79 \r
80     fmtetc.cfFormat = CF_HDROP;\r
81     fmtetc.ptd      = NULL;\r
82     fmtetc.dwAspect = DVASPECT_CONTENT;\r
83     fmtetc.lindex   = -1;\r
84     fmtetc.tymed    = TYMED_HGLOBAL;\r
85 \r
86     /* Check that the drag source provides CF_HDROP,\r
87      * which is the only format we accept */\r
88     if( pDataObj->QueryGetData( &fmtetc ) == S_OK )\r
89         *pdwEffect = DROPEFFECT_COPY;\r
90     else\r
91         *pdwEffect = DROPEFFECT_NONE;\r
92 \r
93     return S_OK;\r
94 }\r
95 //---------------------------------------------------------------------------\r
96 /* for visual feedback */\r
97 STDMETHODIMP TDropTarget::DragOver( DWORD grfKeyState, POINTL pt,\r
98    DWORD *pdwEffect )\r
99 {\r
100     return S_OK;\r
101 }\r
102 //---------------------------------------------------------------------------\r
103 /* remove visual feedback */\r
104 STDMETHODIMP TDropTarget::DragLeave()\r
105 {\r
106     return S_OK;\r
107 }\r
108 //---------------------------------------------------------------------------\r
109 /* something has been dropped */\r
110 STDMETHODIMP TDropTarget::Drop( LPDATAOBJECT pDataObj, DWORD grfKeyState,\r
111    POINTL pt, DWORD *pdwEffect )\r
112 {\r
113     /* user has dropped on us -- get the CF_HDROP data from drag source */\r
114     FORMATETC fmtetc;\r
115     fmtetc.cfFormat = CF_HDROP;\r
116     fmtetc.ptd      = NULL;\r
117     fmtetc.dwAspect = DVASPECT_CONTENT;\r
118     fmtetc.lindex   = -1;\r
119     fmtetc.tymed    = TYMED_HGLOBAL;\r
120 \r
121     STGMEDIUM medium;\r
122     HRESULT hr = pDataObj->GetData( &fmtetc, &medium );\r
123 \r
124     if( !FAILED(hr) )\r
125     {\r
126         /* grab a pointer to the data */\r
127         HGLOBAL HFiles = medium.hGlobal;\r
128         HDROP HDrop = (HDROP)GlobalLock( HFiles );\r
129 \r
130         /* call the helper routine which will notify the Form of the drop */\r
131         HandleDrop( HDrop );\r
132 \r
133         /* release the pointer to the memory */\r
134         GlobalUnlock( HFiles );\r
135         ReleaseStgMedium( &medium );\r
136     }\r
137     else\r
138     {\r
139         *pdwEffect = DROPEFFECT_NONE;\r
140         return hr;\r
141     }\r
142     return S_OK;\r
143 }\r
144 \r