viewobject.cpp 3.93 KB
Newer Older
1 2 3
/*****************************************************************************
 * viewobject.cpp: ActiveX control for VLC
 *****************************************************************************
4
 * Copyright (C) 2005 the VideoLAN team
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 *
 * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
Antoine Cellerier's avatar
Antoine Cellerier committed
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 22 23 24 25
 *****************************************************************************/

#include "plugin.h"
#include "viewobject.h"

Damien Fouilleul's avatar
Damien Fouilleul committed
26
#include "utils.h"
27 28 29 30 31 32 33

using namespace std;

STDMETHODIMP VLCViewObject::Draw(DWORD dwAspect, LONG lindex, PVOID pvAspect,
        DVTARGETDEVICE *ptd, HDC hicTargetDev, HDC hdcDraw, LPCRECTL lprcBounds,
        LPCRECTL lprcWBounds, BOOL(CALLBACK *pfnContinue)(DWORD), DWORD dwContinue)
{
Damien Fouilleul's avatar
Damien Fouilleul committed
34
    if( dwAspect & DVASPECT_CONTENT )
35
    {
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
        if( NULL == lprcBounds )
            return E_INVALIDARG;

        BOOL releaseDC = FALSE;
        SIZEL size = _p_instance->getExtent();

        if( NULL == ptd )
        {
            hicTargetDev = CreateDevDC(NULL);
            releaseDC = TRUE;
        }
        DPFromHimetric(hicTargetDev, (LPPOINT)&size, 1);

        RECTL bounds = { 0L, 0L, size.cx, size.cy };

        int sdc = SaveDC(hdcDraw);
        SetMapMode(hdcDraw, MM_ANISOTROPIC);
        SetWindowOrgEx(hdcDraw, 0, 0, NULL);
        SetWindowExtEx(hdcDraw, size.cx, size.cy, NULL);
        OffsetViewportOrgEx(hdcDraw, lprcBounds->left, lprcBounds->top, NULL);
        SetViewportExtEx(hdcDraw, lprcBounds->right-lprcBounds->left,
                lprcBounds->bottom-lprcBounds->top, NULL);

        _p_instance->onDraw(ptd, hicTargetDev, hdcDraw, &bounds, lprcWBounds);
        RestoreDC(hdcDraw, sdc);

        if( releaseDC )
            DeleteDC(hicTargetDev);

Damien Fouilleul's avatar
Damien Fouilleul committed
65
        return S_OK;
66 67 68 69 70 71 72
    }
    return E_NOTIMPL;
};

STDMETHODIMP VLCViewObject::Freeze(DWORD dwAspect, LONG lindex,
        PVOID pvAspect, LPDWORD pdwFreeze)
{
Damien Fouilleul's avatar
Damien Fouilleul committed
73
    return E_NOTIMPL;
74 75 76 77 78
};

STDMETHODIMP VLCViewObject::GetAdvise(LPDWORD pdwAspect, LPDWORD padvf,
        LPADVISESINK *ppAdviseSink)
{
Damien Fouilleul's avatar
Damien Fouilleul committed
79
    if( NULL != pdwAspect )
80
        *pdwAspect = _dwAspect;
Damien Fouilleul's avatar
Damien Fouilleul committed
81 82

    if( NULL != padvf )
83
        *padvf = _advf;
Damien Fouilleul's avatar
Damien Fouilleul committed
84 85

    if( NULL != ppAdviseSink )
86 87 88 89 90
    {
        *ppAdviseSink = _pAdvSink;
        if( NULL != _pAdvSink )
            _pAdvSink->AddRef();
    }
Damien Fouilleul's avatar
Damien Fouilleul committed
91 92

    return S_OK;
93 94
};

95
STDMETHODIMP VLCViewObject::GetColorSet(DWORD dwAspect, LONG lindex,
96 97
        PVOID pvAspect, DVTARGETDEVICE *ptd, HDC hicTargetDev, LPLOGPALETTE *ppColorSet)
{
Damien Fouilleul's avatar
Damien Fouilleul committed
98
    return S_FALSE;
99 100 101 102 103
};

STDMETHODIMP VLCViewObject::SetAdvise(DWORD dwAspect, DWORD advf,
        LPADVISESINK pAdvSink)
{
104 105 106
    if( NULL != pAdvSink )
        pAdvSink->AddRef();

107 108 109
    if( NULL != _pAdvSink )
        _pAdvSink->Release();

110 111
    _dwAspect = dwAspect;
    _advf = advf;
112 113
    _pAdvSink = pAdvSink;

114 115 116
    if( (dwAspect & DVASPECT_CONTENT) && (advf & ADVF_PRIMEFIRST) && (NULL != _pAdvSink) )
    {
        _pAdvSink->OnViewChange(DVASPECT_CONTENT, -1);
117
    }
118

119
    return S_OK;
120 121 122 123 124 125 126
};

STDMETHODIMP VLCViewObject::Unfreeze(DWORD dwFreeze)
{
    return E_NOTIMPL;
};

Damien Fouilleul's avatar
Damien Fouilleul committed
127 128 129 130 131 132 133 134 135 136 137 138 139
STDMETHODIMP VLCViewObject::GetExtent(DWORD dwAspect, LONG lindex,
        DVTARGETDEVICE *ptd, LPSIZEL lpSizel)
{
    if( dwAspect & DVASPECT_CONTENT )
    {
        *lpSizel = _p_instance->getExtent();
        return S_OK;
    }
    lpSizel->cx= 0L;
    lpSizel->cy= 0L;
    return E_NOTIMPL;
};