]> git.sesse.net Git - vlc/blob - activex/viewobject.cpp
8eb8cd9e85a6bd18213bc5cd34ef689e21465dce
[vlc] / activex / viewobject.cpp
1 /*****************************************************************************
2  * viewobject.cpp: ActiveX control for VLC
3  *****************************************************************************
4  * Copyright (C) 2005 the VideoLAN team
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 "viewobject.h"
25
26 #include "utils.h"
27
28 using namespace std;
29
30 STDMETHODIMP VLCViewObject::Draw(DWORD dwAspect, LONG lindex, PVOID pvAspect,
31         DVTARGETDEVICE *ptd, HDC hicTargetDev, HDC hdcDraw, LPCRECTL lprcBounds,
32         LPCRECTL lprcWBounds, BOOL(CALLBACK *pfnContinue)(DWORD), DWORD dwContinue)
33 {
34     if( dwAspect & DVASPECT_CONTENT )
35     {
36         if( NULL == lprcBounds )
37             return E_INVALIDARG;
38
39         BOOL releaseDC = FALSE;
40         SIZEL size = _p_instance->getExtent();
41
42         if( NULL == ptd )
43         {
44             hicTargetDev = CreateDevDC(NULL);
45             releaseDC = TRUE;
46         }
47         DPFromHimetric(hicTargetDev, (LPPOINT)&size, 1);
48
49         RECTL bounds = { 0L, 0L, size.cx, size.cy };
50
51         int sdc = SaveDC(hdcDraw);
52         SetMapMode(hdcDraw, MM_ANISOTROPIC);
53         SetWindowOrgEx(hdcDraw, 0, 0, NULL);
54         SetWindowExtEx(hdcDraw, size.cx, size.cy, NULL);
55         OffsetViewportOrgEx(hdcDraw, lprcBounds->left, lprcBounds->top, NULL);
56         SetViewportExtEx(hdcDraw, lprcBounds->right-lprcBounds->left,
57                 lprcBounds->bottom-lprcBounds->top, NULL);
58
59         _p_instance->onDraw(ptd, hicTargetDev, hdcDraw, &bounds, lprcWBounds);
60         RestoreDC(hdcDraw, sdc);
61
62         if( releaseDC )
63             DeleteDC(hicTargetDev);
64
65         return S_OK;
66     }
67     return E_NOTIMPL;
68 };
69
70 STDMETHODIMP VLCViewObject::Freeze(DWORD dwAspect, LONG lindex,
71         PVOID pvAspect, LPDWORD pdwFreeze)
72 {
73     return E_NOTIMPL;
74 };
75
76 STDMETHODIMP VLCViewObject::GetAdvise(LPDWORD pdwAspect, LPDWORD padvf,
77         LPADVISESINK *ppAdviseSink)
78 {
79     if( NULL != pdwAspect )
80         *pdwAspect = _dwAspect;
81
82     if( NULL != padvf )
83         *padvf = _advf;
84
85     if( NULL != ppAdviseSink )
86     {
87         *ppAdviseSink = _pAdvSink;
88         if( NULL != _pAdvSink )
89             _pAdvSink->AddRef();
90     }
91
92     return S_OK;
93 };
94
95 STDMETHODIMP VLCViewObject::GetColorSet(DWORD dwAspect, LONG lindex, 
96         PVOID pvAspect, DVTARGETDEVICE *ptd, HDC hicTargetDev, LPLOGPALETTE *ppColorSet)
97 {
98     return S_FALSE;
99 };
100
101 STDMETHODIMP VLCViewObject::SetAdvise(DWORD dwAspect, DWORD advf,
102         LPADVISESINK pAdvSink)
103 {
104     if( NULL != pAdvSink )
105         pAdvSink->AddRef();
106
107     if( NULL != _pAdvSink )
108         _pAdvSink->Release();
109
110     _dwAspect = dwAspect;
111     _advf = advf;
112     _pAdvSink = pAdvSink;
113
114     if( (dwAspect & DVASPECT_CONTENT) && (advf & ADVF_PRIMEFIRST) && (NULL != _pAdvSink) )
115     {
116         _pAdvSink->OnViewChange(DVASPECT_CONTENT, -1);
117     }
118
119     return S_OK;
120 };
121
122 STDMETHODIMP VLCViewObject::Unfreeze(DWORD dwFreeze)
123 {
124     return E_NOTIMPL;
125 };
126
127 STDMETHODIMP VLCViewObject::GetExtent(DWORD dwAspect, LONG lindex,
128         DVTARGETDEVICE *ptd, LPSIZEL lpSizel)
129 {
130     if( dwAspect & DVASPECT_CONTENT )
131     {
132         *lpSizel = _p_instance->getExtent();
133         return S_OK;
134     }
135     lpSizel->cx= 0L;
136     lpSizel->cy= 0L;
137     return E_NOTIMPL;
138 };
139