X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;ds=sidebyside;f=activex%2Fplugin.cpp;h=057ea88ea16da78790a7c56475ca6bbe6e53cf58;hb=423003a574154fb94c851f4ad10ca57ddf0aa269;hp=416fb2b7256a62baec0f2891f1c86ba326e5e042;hpb=722b1c1a231f5e779fc7940d0fa561fd52dbcdf1;p=vlc diff --git a/activex/plugin.cpp b/activex/plugin.cpp index 416fb2b725..057ea88ea1 100644 --- a/activex/plugin.cpp +++ b/activex/plugin.cpp @@ -33,6 +33,7 @@ #include "connectioncontainer.h" #include "objectsafety.h" #include "vlccontrol.h" +#include "viewobject.h" #include "utils.h" @@ -81,8 +82,10 @@ static LRESULT CALLBACK VLCVideoClassWndProc(HWND hWnd, UINT uMsg, WPARAM wParam RECT pr; if( GetUpdateRect(hWnd, &pr, FALSE) ) { + RECT bounds; + GetClientRect(hWnd, &bounds); BeginPaint(hWnd, &ps); - p_instance->onPaint(ps, pr); + p_instance->onPaint(ps.hdc, bounds, pr); EndPaint(hWnd, &ps); } return 0L; @@ -246,6 +249,13 @@ VLCPlugin::VLCPlugin(VLCPluginClass *p_class) : vlcConnectionPointContainer = new VLCConnectionPointContainer(this); vlcObjectSafety = new VLCObjectSafety(this); vlcControl = new VLCControl(this); + vlcViewObject = new VLCViewObject(this); + + // set default/preferred size (320x240) pixels in HIMETRIC + HDC hDC = CreateDevDC(NULL); + _extent.cx = (320*2540L)/GetDeviceCaps(hDC, LOGPIXELSX); + _extent.cy = (240*2540L)/GetDeviceCaps(hDC, LOGPIXELSY); + DeleteDC(hDC); }; VLCPlugin::~VLCPlugin() @@ -253,6 +263,7 @@ VLCPlugin::~VLCPlugin() vlcOleInPlaceObject->UIDeactivate(); vlcOleInPlaceObject->InPlaceDeactivate(); + delete vlcViewObject; delete vlcControl; delete vlcObjectSafety; delete vlcConnectionPointContainer; @@ -372,6 +383,18 @@ STDMETHODIMP VLCPlugin::QueryInterface(REFIID riid, void **ppv) *ppv = reinterpret_cast(vlcControl); return NOERROR; } + else if( IID_IViewObject == riid ) + { + AddRef(); + *ppv = reinterpret_cast(vlcViewObject); + return NOERROR; + } + else if( IID_IViewObject2 == riid ) + { + AddRef(); + *ppv = reinterpret_cast(vlcViewObject); + return NOERROR; + } *ppv = NULL; @@ -396,29 +419,30 @@ STDMETHODIMP_(ULONG) VLCPlugin::Release(void) ////////////////////////////////////// /* -** we use an in-place child window to represent plugin viewport, -** whose size is limited by the clipping rectangle -** all drawing within this window must follow -** cartesian coordinate system represented by _bounds. +** we use a window to represent plugin viewport, +** whose geometry is limited by the clipping rectangle +** all drawing within this window must follow must +** follow coordinates system described in lprPosRect */ -void VLCPlugin::calcPositionChange(LPRECT lprPosRect, LPCRECT lprcClipRect) +static void getViewportCoords(LPRECT lprPosRect, LPRECT lprClipRect) { - _bounds.right = lprPosRect->right-lprPosRect->left; + RECT bounds; + bounds.right = lprPosRect->right-lprPosRect->left; - if( lprcClipRect->left <= lprPosRect->left ) + if( lprClipRect->left <= lprPosRect->left ) { // left side is not clipped out - _bounds.left = 0; + bounds.left = 0; - if( lprcClipRect->right >= lprPosRect->right ) + if( lprClipRect->right >= lprPosRect->right ) { // right side is not clipped out, no change } - else if( lprcClipRect->right >= lprPosRect->left ) + else if( lprClipRect->right >= lprPosRect->left ) { // right side is clipped out - lprPosRect->right = lprcClipRect->right; + lprPosRect->right = lprClipRect->right; } else { @@ -429,36 +453,36 @@ void VLCPlugin::calcPositionChange(LPRECT lprPosRect, LPCRECT lprcClipRect) else { // left side is clipped out - _bounds.left = lprPosRect->left-lprcClipRect->left; - _bounds.right += _bounds.left; + bounds.left = lprPosRect->left-lprClipRect->left; + bounds.right += bounds.left; - lprPosRect->left = lprcClipRect->left; - if( lprcClipRect->right >= lprPosRect->right ) + lprPosRect->left = lprClipRect->left; + if( lprClipRect->right >= lprPosRect->right ) { // right side is not clipped out } else { // right side is clipped out - lprPosRect->right = lprcClipRect->right; + lprPosRect->right = lprClipRect->right; } } - _bounds.bottom = lprPosRect->bottom-lprPosRect->top; + bounds.bottom = lprPosRect->bottom-lprPosRect->top; - if( lprcClipRect->top <= lprPosRect->top ) + if( lprClipRect->top <= lprPosRect->top ) { // top side is not clipped out - _bounds.top = 0; + bounds.top = 0; - if( lprcClipRect->bottom >= lprPosRect->bottom ) + if( lprClipRect->bottom >= lprPosRect->bottom ) { // bottom side is not clipped out, no change } - else if( lprcClipRect->bottom >= lprPosRect->top ) + else if( lprClipRect->bottom >= lprPosRect->top ) { // bottom side is clipped out - lprPosRect->bottom = lprcClipRect->bottom; + lprPosRect->bottom = lprClipRect->bottom; } else { @@ -468,20 +492,22 @@ void VLCPlugin::calcPositionChange(LPRECT lprPosRect, LPCRECT lprcClipRect) } else { - _bounds.top = lprPosRect->top-lprcClipRect->top; - _bounds.bottom += _bounds.top; + bounds.top = lprPosRect->top-lprClipRect->top; + bounds.bottom += bounds.top; - lprPosRect->top = lprcClipRect->top; - if( lprcClipRect->bottom >= lprPosRect->bottom ) + lprPosRect->top = lprClipRect->top; + if( lprClipRect->bottom >= lprPosRect->bottom ) { // bottom side is not clipped out } else { // bottom side is clipped out - lprPosRect->bottom = lprcClipRect->bottom; + lprPosRect->bottom = lprClipRect->bottom; } } + *lprClipRect = *lprPosRect; + *lprPosRect = bounds; }; HRESULT VLCPlugin::onInit(BOOL isNew) @@ -599,16 +625,30 @@ BOOL VLCPlugin::isInPlaceActive(void) HRESULT VLCPlugin::onActivateInPlace(LPMSG lpMesg, HWND hwndParent, LPCRECT lprcPosRect, LPCRECT lprcClipRect) { RECT posRect = *lprcPosRect; + RECT clipRect = *lprcClipRect; + + /* + ** record keeping of control geometry within container + */ + _posRect = posRect; - calcPositionChange(&posRect, lprcClipRect); + /* + ** convert posRect & clipRect to match control viewport coordinates + */ + getViewportCoords(&posRect, &clipRect); + /* + ** Create a window for in place activated control. + ** the window geometry represents the control viewport + ** so that embedded video is always properly clipped. + */ _inplacewnd = CreateWindow(_p_class->getInPlaceWndClassName(), "VLC Plugin In-Place Window", WS_CHILD|WS_CLIPCHILDREN|WS_TABSTOP, - posRect.left, - posRect.top, - posRect.right-posRect.left, - posRect.bottom-posRect.top, + clipRect.left, + clipRect.top, + clipRect.right-clipRect.left, + clipRect.bottom-clipRect.top, hwndParent, 0, _p_class->getHInstance(), @@ -620,13 +660,18 @@ HRESULT VLCPlugin::onActivateInPlace(LPMSG lpMesg, HWND hwndParent, LPCRECT lprc SetWindowLongPtr(_inplacewnd, GWLP_USERDATA, reinterpret_cast(this)); + /* + ** VLC embedded video geometry automatically matches parent window. + ** hence create a child window so that video position and size + ** is always correct relative to the viewport bounds + */ _videownd = CreateWindow(_p_class->getVideoWndClassName(), "VLC Plugin Video Window", WS_CHILD|WS_CLIPCHILDREN|WS_VISIBLE, - _bounds.left, - _bounds.top, - _bounds.right-_bounds.left, - _bounds.bottom-_bounds.top, + posRect.left, + posRect.top, + posRect.right-posRect.left, + posRect.bottom-posRect.top, _inplacewnd, 0, _p_class->getHInstance(), @@ -702,19 +747,19 @@ BOOL VLCPlugin::hasFocus(void) return GetActiveWindow() == _inplacewnd; }; -void VLCPlugin::onPaint(PAINTSTRUCT &ps, RECT &pr) +void VLCPlugin::onPaint(HDC hdc, const RECT &bounds, const RECT &pr) { /* ** if VLC is playing, it may not display any VIDEO content ** hence, draw control logo */ - int width = _bounds.right-_bounds.left; - int height = _bounds.bottom-_bounds.top; + int width = bounds.right-bounds.left; + int height = bounds.bottom-bounds.top; HBITMAP pict = _p_class->getInPlacePict(); if( NULL != pict ) { - HDC hdcPict = CreateCompatibleDC(ps.hdc); + HDC hdcPict = CreateCompatibleDC(hdc); if( NULL != hdcPict ) { BITMAP bm; @@ -728,60 +773,72 @@ void VLCPlugin::onPaint(PAINTSTRUCT &ps, RECT &pr) if( dstHeight > height-4 ) dstHeight = height-4; - int dstX = (width-dstWidth)/2; - int dstY = (height-dstHeight)/2; + int dstX = bounds.left+(width-dstWidth)/2; + int dstY = bounds.top+(height-dstHeight)/2; SelectObject(hdcPict, pict); - StretchBlt(ps.hdc, dstX, dstY, dstWidth, dstHeight, + StretchBlt(hdc, dstX, dstY, dstWidth, dstHeight, hdcPict, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY); DeleteDC(hdcPict); - ExcludeClipRect(ps.hdc, dstX, dstY, dstWidth+dstX, dstHeight+dstY); + ExcludeClipRect(hdc, dstX, dstY, dstWidth+dstX, dstHeight+dstY); } } } - FillRect(ps.hdc, &pr, (HBRUSH)GetStockObject(WHITE_BRUSH)); - SelectObject(ps.hdc, GetStockObject(BLACK_BRUSH)); + FillRect(hdc, &pr, (HBRUSH)GetStockObject(WHITE_BRUSH)); + SelectObject(hdc, GetStockObject(BLACK_BRUSH)); - MoveToEx(ps.hdc, 0, 0, NULL); - LineTo(ps.hdc, width-1, 0); - LineTo(ps.hdc, width-1, height-1); - LineTo(ps.hdc, 0, height-1); - LineTo(ps.hdc, 0, 0); + MoveToEx(hdc, bounds.left, bounds.top, NULL); + LineTo(hdc, bounds.left+width-1, bounds.top); + LineTo(hdc, bounds.left+width-1, bounds.top+height-1); + LineTo(hdc, bounds.left, bounds.top+height-1); + LineTo(hdc, bounds.left, bounds.top); }; void VLCPlugin::onPositionChange(LPCRECT lprcPosRect, LPCRECT lprcClipRect) { - RECT posRect = *lprcPosRect; + RECT clipRect = *lprcClipRect; + RECT posRect = *lprcPosRect; - calcPositionChange(&posRect, lprcClipRect); + /* + ** record keeping of control geometry within container + */ + _posRect = posRect; + + /* + ** convert posRect & clipRect to match control viewport coordinates + */ + getViewportCoords(&posRect, &clipRect); /* ** change in-place window geometry to match clipping region */ MoveWindow(_inplacewnd, - posRect.left, - posRect.top, - posRect.right-posRect.left, - posRect.bottom-posRect.top, + clipRect.left, + clipRect.top, + clipRect.right-clipRect.left, + clipRect.bottom-clipRect.top, FALSE); /* ** change video window geometry to match object bounds within clipping region */ MoveWindow(_videownd, - _bounds.left, - _bounds.top, - _bounds.right-_bounds.left, - _bounds.bottom-_bounds.top, + posRect.left, + posRect.top, + posRect.right-posRect.left, + posRect.bottom-posRect.top, FALSE); - RECT updateRect; - updateRect.left = -_bounds.left; - updateRect.top = -_bounds.top; - updateRect.right = _bounds.right-_bounds.left; - updateRect.bottom = _bounds.bottom-_bounds.top; + /* + ** force a full refresh of control content + */ + RECT updateRect; + updateRect.left = -posRect.left; + updateRect.top = -posRect.top; + updateRect.right = posRect.right-posRect.left; + updateRect.bottom = posRect.bottom-posRect.top; ValidateRect(_videownd, NULL); InvalidateRect(_videownd, &updateRect, FALSE);