]> git.sesse.net Git - vlc/blob - activex/dataobject.cpp
Removes trailing spaces. Removes tabs.
[vlc] / activex / dataobject.cpp
1 /*****************************************************************************
2  * viewobject.cpp: ActiveX control for VLC
3  *****************************************************************************
4  * Copyright (C) 2005 VideoLAN
5  *
6  * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21  *****************************************************************************/
22
23 #include "plugin.h"
24 #include "dataobject.h"
25
26 #include "utils.h"
27
28 using namespace std;
29
30 ////////////////////////////////////////////////////////////////////////////////////////////////
31
32 static const FORMATETC _metaFileFormatEtc =
33     {
34         CF_METAFILEPICT,
35         NULL,
36         DVASPECT_CONTENT,
37         -1,
38         TYMED_MFPICT,
39     };
40 static const FORMATETC _enhMetaFileFormatEtc =
41     {
42         CF_ENHMETAFILE,
43         NULL,
44         DVASPECT_CONTENT,
45         -1,
46         TYMED_ENHMF,
47     };
48
49 class VLCEnumFORMATETC : public VLCEnumIterator<IID_IEnumFORMATETC,
50     IEnumFORMATETC,
51     FORMATETC,
52     vector<FORMATETC>::iterator>
53 {
54 public:
55     VLCEnumFORMATETC(vector<FORMATETC> v) :
56         VLCEnumIterator<IID_IEnumFORMATETC,
57         IEnumFORMATETC,
58         FORMATETC,
59         vector<FORMATETC>::iterator>(v.begin(), v.end())
60     {};
61 };
62
63 ////////////////////////////////////////////////////////////////////////////////////////////////
64
65 VLCDataObject::VLCDataObject(VLCPlugin *p_instance) : _p_instance(p_instance)
66 {
67     _v_formatEtc.push_back(_enhMetaFileFormatEtc);
68     _v_formatEtc.push_back(_metaFileFormatEtc);
69     CreateDataAdviseHolder(&_p_adviseHolder);
70 };
71
72 VLCDataObject::~VLCDataObject()
73 {
74     _p_adviseHolder->Release();
75 };
76
77 ////////////////////////////////////////////////////////////////////////////////////////////////
78
79 STDMETHODIMP VLCDataObject::DAdvise(LPFORMATETC pFormatEtc, DWORD padvf, LPADVISESINK pAdviseSink, LPDWORD pdwConnection)
80 {
81     return _p_adviseHolder->Advise(this,
82             pFormatEtc, padvf,pAdviseSink, pdwConnection);
83 };
84
85 STDMETHODIMP VLCDataObject::DUnadvise(DWORD dwConnection)
86 {
87     return _p_adviseHolder->Unadvise(dwConnection);
88 };
89
90 STDMETHODIMP VLCDataObject::EnumDAdvise(IEnumSTATDATA **ppenumAdvise)
91 {
92     return _p_adviseHolder->EnumAdvise(ppenumAdvise);
93 };
94
95 STDMETHODIMP VLCDataObject::EnumFormatEtc(DWORD dwDirection, IEnumFORMATETC **ppEnum)
96 {
97     if( NULL == ppEnum )
98         return E_POINTER;
99
100     *ppEnum = dynamic_cast<IEnumFORMATETC *>(new VLCEnumFORMATETC(_v_formatEtc));
101
102     return (NULL != *ppEnum ) ? S_OK : E_OUTOFMEMORY;
103 };
104
105 STDMETHODIMP VLCDataObject::GetCanonicalFormatEtc(LPFORMATETC pFormatEtcIn, LPFORMATETC pFormatEtcOut)
106 {
107     HRESULT result = QueryGetData(pFormatEtcIn);
108     if( FAILED(result) )
109         return result;
110
111     if( NULL == pFormatEtcOut )
112         return E_POINTER;
113
114     *pFormatEtcOut = *pFormatEtcIn;
115     pFormatEtcOut->ptd = NULL;
116
117     return DATA_S_SAMEFORMATETC;
118 };
119
120 STDMETHODIMP VLCDataObject::GetData(LPFORMATETC pFormatEtc, LPSTGMEDIUM pMedium)
121 {
122     if( NULL == pMedium )
123         return E_POINTER;
124
125     HRESULT result = QueryGetData(pFormatEtc);
126     if( SUCCEEDED(result) )
127     {
128         switch( pFormatEtc->cfFormat )
129         {
130             case CF_METAFILEPICT:
131                 pMedium->tymed = TYMED_MFPICT;
132                 pMedium->hMetaFilePict = NULL;
133                 pMedium->pUnkForRelease = NULL;
134                 result = getMetaFileData(pFormatEtc, pMedium);
135                 break;
136             case CF_ENHMETAFILE:
137                 pMedium->tymed = TYMED_ENHMF;
138                 pMedium->hEnhMetaFile = NULL;
139                 pMedium->pUnkForRelease = NULL;
140                 result = getEnhMetaFileData(pFormatEtc, pMedium);
141                 break;
142             default:
143                 result = DV_E_FORMATETC;
144         }
145     }
146     return result;
147 };
148
149 STDMETHODIMP VLCDataObject::GetDataHere(LPFORMATETC pFormatEtc, LPSTGMEDIUM pMedium)
150 {
151     if( NULL == pMedium )
152         return E_POINTER;
153
154     return E_NOTIMPL;
155 }
156
157 ////////////////////////////////////////////////////////////////////////////////////////////////
158
159 HRESULT VLCDataObject::getMetaFileData(LPFORMATETC pFormatEtc, LPSTGMEDIUM pMedium)
160 {
161     HDC hicTargetDev = CreateDevDC(pFormatEtc->ptd);
162     if( NULL == hicTargetDev )
163         return E_FAIL;
164
165     HDC hdcMeta = CreateMetaFile(NULL);
166     if( NULL != hdcMeta )
167     {
168         LPMETAFILEPICT pMetaFilePict = (LPMETAFILEPICT)CoTaskMemAlloc(sizeof(METAFILEPICT));
169         if( NULL != pMetaFilePict )
170         {
171             SIZEL size = _p_instance->getExtent();
172             RECTL wBounds = { 0L, 0L, size.cx, size.cy };
173
174             pMetaFilePict->mm   = MM_ANISOTROPIC;
175             pMetaFilePict->xExt = size.cx;
176             pMetaFilePict->yExt = size.cy;
177
178             DPFromHimetric(hicTargetDev, (LPPOINT)&size, 1);
179
180             SetMapMode(hdcMeta, MM_ANISOTROPIC);
181             SetWindowExtEx(hdcMeta, size.cx, size.cy, NULL);
182
183             RECTL bounds = { 0L, 0L, size.cx, size.cy };
184
185             _p_instance->onDraw(pFormatEtc->ptd, hicTargetDev, hdcMeta, &bounds, &wBounds);
186             pMetaFilePict->hMF = CloseMetaFile(hdcMeta);
187             if( NULL != pMetaFilePict->hMF )
188                 pMedium->hMetaFilePict = pMetaFilePict;
189             else
190                 CoTaskMemFree(pMetaFilePict);
191         }
192     }
193     DeleteDC(hicTargetDev);
194     return (NULL != pMedium->hMetaFilePict) ? S_OK : E_FAIL;
195 };
196
197 HRESULT VLCDataObject::getEnhMetaFileData(LPFORMATETC pFormatEtc, LPSTGMEDIUM pMedium)
198 {
199     HDC hicTargetDev = CreateDevDC(pFormatEtc->ptd);
200     if( NULL == hicTargetDev )
201         return E_FAIL;
202
203     SIZEL size = _p_instance->getExtent();
204
205     HDC hdcMeta = CreateEnhMetaFile(hicTargetDev, NULL, NULL, NULL);
206     if( NULL != hdcMeta )
207     {
208         RECTL wBounds = { 0L, 0L, size.cx, size.cy };
209
210         DPFromHimetric(hicTargetDev, (LPPOINT)&size, 1);
211
212         RECTL bounds = { 0L, 0L, size.cx, size.cy };
213
214         _p_instance->onDraw(pFormatEtc->ptd, hicTargetDev, hdcMeta, &bounds, &wBounds);
215         pMedium->hEnhMetaFile = CloseEnhMetaFile(hdcMeta);
216     }
217     DeleteDC(hicTargetDev);
218
219     return (NULL != pMedium->hEnhMetaFile) ? S_OK : E_FAIL;
220 };
221
222 STDMETHODIMP VLCDataObject::QueryGetData(LPFORMATETC pFormatEtc)
223 {
224     if( NULL == pFormatEtc )
225         return E_POINTER;
226
227     const FORMATETC *formatEtc;
228
229     switch( pFormatEtc->cfFormat )
230     {
231         case CF_METAFILEPICT:
232             formatEtc = &_metaFileFormatEtc;
233             break;
234         case CF_ENHMETAFILE:
235             formatEtc = &_enhMetaFileFormatEtc;
236             break;
237         default:
238             return DV_E_FORMATETC;
239     }
240  
241     if( pFormatEtc->dwAspect != formatEtc->dwAspect )
242         return DV_E_DVASPECT;
243
244     if( pFormatEtc->lindex != formatEtc->lindex )
245         return DV_E_LINDEX;
246
247     if( pFormatEtc->tymed != formatEtc->tymed )
248         return DV_E_TYMED;
249
250     return S_OK;
251 };
252
253 STDMETHODIMP VLCDataObject::SetData(LPFORMATETC pFormatEtc, LPSTGMEDIUM pMedium, BOOL fRelease)
254 {
255     return E_NOTIMPL;
256 };
257
258 /*void VLCDataObject::onDataChange(void)
259 {
260     _p_adviseHolder->SendOnDataChange(this, 0, 0);
261 };*/
262
263 void VLCDataObject::onClose(void)
264 {
265     _p_adviseHolder->SendOnDataChange(this, 0, ADVF_DATAONSTOP);
266     if( S_OK == OleIsCurrentClipboard(dynamic_cast<LPDATAOBJECT>(this)) )
267         OleFlushClipboard();
268 };
269