#include "connectioncontainer.h"
#include "objectsafety.h"
#include "vlccontrol.h"
+#include "viewobject.h"
#include "utils.h"
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;
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()
vlcOleInPlaceObject->UIDeactivate();
vlcOleInPlaceObject->InPlaceDeactivate();
+ delete vlcViewObject;
delete vlcControl;
delete vlcObjectSafety;
delete vlcConnectionPointContainer;
*ppv = reinterpret_cast<LPVOID>(vlcControl);
return NOERROR;
}
+ else if( IID_IViewObject == riid )
+ {
+ AddRef();
+ *ppv = reinterpret_cast<LPVOID>(vlcViewObject);
+ return NOERROR;
+ }
+ else if( IID_IViewObject2 == riid )
+ {
+ AddRef();
+ *ppv = reinterpret_cast<LPVOID>(vlcViewObject);
+ return NOERROR;
+ }
*ppv = NULL;
//////////////////////////////////////
/*
-** 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
{
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
{
}
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;
};
-#include <iostream>
-
HRESULT VLCPlugin::onInit(BOOL isNew)
{
if( 0 == _i_vlc )
{
+#ifdef ACTIVEX_DEBUG
+ char *ppsz_argv[] = { "vlc", "-vvv", "--fast-mutex", "--win9x-cv-method=1" };
+#else
char *ppsz_argv[] = { "vlc", "-vv" };
+#endif
HKEY h_key;
DWORD i_type, i_data = MAX_PATH + 1;
char p_data[MAX_PATH + 1];
#endif
_i_vlc = VLC_Create();
-
+
if( VLC_Init(_i_vlc, sizeof(ppsz_argv)/sizeof(char*), ppsz_argv) )
{
VLC_Destroy(_i_vlc);
HRESULT VLCPlugin::onActivateInPlace(LPMSG lpMesg, HWND hwndParent, LPCRECT lprcPosRect, LPCRECT lprcClipRect)
{
RECT posRect = *lprcPosRect;
+ RECT clipRect = *lprcClipRect;
- calcPositionChange(&posRect, lprcClipRect);
+ /*
+ ** record keeping of control geometry within container
+ */
+ _posRect = posRect;
+
+ /*
+ ** 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(),
SetWindowLongPtr(_inplacewnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(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(),
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;
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);