1 /*****************************************************************************
2 * plugin.cpp: ActiveX control for VLC
3 *****************************************************************************
4 * Copyright (C) 2005 the VideoLAN team
6 * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>
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.
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.
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 *****************************************************************************/
25 #include "oleobject.h"
26 #include "olecontrol.h"
27 #include "oleinplaceobject.h"
28 #include "oleinplaceactiveobject.h"
29 #include "persistpropbag.h"
30 #include "persiststreaminit.h"
31 #include "persiststorage.h"
32 #include "provideclassinfo.h"
33 #include "connectioncontainer.h"
34 #include "objectsafety.h"
35 #include "vlccontrol.h"
36 #include "viewobject.h"
37 #include "dataobject.h"
50 ////////////////////////////////////////////////////////////////////////
53 // {E23FE9C6-778E-49d4-B537-38FCDE4887D8}
54 //const GUID CLSID_VLCPlugin =
55 // { 0xe23fe9c6, 0x778e, 0x49d4, { 0xb5, 0x37, 0x38, 0xfc, 0xde, 0x48, 0x87, 0xd8 } };
57 static LRESULT CALLBACK VLCInPlaceClassWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
65 if( GetUpdateRect(hWnd, NULL, FALSE) )
67 BeginPaint(hWnd, &ps);
73 return DefWindowProc(hWnd, uMsg, wParam, lParam);
77 static LRESULT CALLBACK VLCVideoClassWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
78 VLCPlugin *p_instance = reinterpret_cast<VLCPlugin *>(GetWindowLongPtr(hWnd, GWLP_USERDATA));
88 if( GetUpdateRect(hWnd, &pr, FALSE) )
91 GetClientRect(hWnd, &bounds);
92 BeginPaint(hWnd, &ps);
93 p_instance->onPaint(ps.hdc, bounds, pr);
99 return DefWindowProc(hWnd, uMsg, wParam, lParam);
103 VLCPluginClass::VLCPluginClass(LONG *p_class_ref, HINSTANCE hInstance) :
104 _p_class_ref(p_class_ref),
105 _hinstance(hInstance),
106 _inplace_picture(NULL)
110 if( ! GetClassInfo(hInstance, getInPlaceWndClassName(), &wClass) )
112 wClass.style = CS_NOCLOSE|CS_DBLCLKS;
113 wClass.lpfnWndProc = VLCInPlaceClassWndProc;
114 wClass.cbClsExtra = 0;
115 wClass.cbWndExtra = 0;
116 wClass.hInstance = hInstance;
118 wClass.hCursor = LoadCursor(NULL, IDC_ARROW);
119 wClass.hbrBackground = NULL;
120 wClass.lpszMenuName = NULL;
121 wClass.lpszClassName = getInPlaceWndClassName();
123 _inplace_wndclass_atom = RegisterClass(&wClass);
127 _inplace_wndclass_atom = 0;
130 if( ! GetClassInfo(hInstance, getVideoWndClassName(), &wClass) )
132 wClass.style = CS_NOCLOSE;
133 wClass.lpfnWndProc = VLCVideoClassWndProc;
134 wClass.cbClsExtra = 0;
135 wClass.cbWndExtra = 0;
136 wClass.hInstance = hInstance;
138 wClass.hCursor = LoadCursor(NULL, IDC_ARROW);
139 wClass.hbrBackground = NULL;
140 wClass.lpszMenuName = NULL;
141 wClass.lpszClassName = getVideoWndClassName();
143 _video_wndclass_atom = RegisterClass(&wClass);
147 _video_wndclass_atom = 0;
150 HBITMAP hbitmap = (HBITMAP)LoadImage(getHInstance(), TEXT("INPLACE-PICT"), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
151 if( NULL != hbitmap )
155 pictDesc.cbSizeofstruct = sizeof(PICTDESC);
156 pictDesc.picType = PICTYPE_BITMAP;
157 pictDesc.bmp.hbitmap = hbitmap;
158 pictDesc.bmp.hpal = NULL;
160 if( FAILED(OleCreatePictureIndirect(&pictDesc, IID_IPicture, TRUE, reinterpret_cast<LPVOID*>(&_inplace_picture))) )
161 _inplace_picture = NULL;
166 VLCPluginClass::~VLCPluginClass()
168 if( 0 != _inplace_wndclass_atom )
169 UnregisterClass(MAKEINTATOM(_inplace_wndclass_atom), _hinstance);
171 if( 0 != _video_wndclass_atom )
172 UnregisterClass(MAKEINTATOM(_video_wndclass_atom), _hinstance);
174 if( NULL != _inplace_picture )
175 _inplace_picture->Release();
178 STDMETHODIMP VLCPluginClass::QueryInterface(REFIID riid, void **ppv)
183 if( (IID_IUnknown == riid) || (IID_IClassFactory == riid) )
186 *ppv = reinterpret_cast<LPVOID>(this);
193 return E_NOINTERFACE;
196 STDMETHODIMP_(ULONG) VLCPluginClass::AddRef(void)
198 return InterlockedIncrement(_p_class_ref);
201 STDMETHODIMP_(ULONG) VLCPluginClass::Release(void)
203 ULONG refcount = InterlockedDecrement(_p_class_ref);
212 STDMETHODIMP VLCPluginClass::CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, void **ppv)
219 if( (NULL != pUnkOuter) && (IID_IUnknown != riid) ) {
220 return CLASS_E_NOAGGREGATION;
223 VLCPlugin *plugin = new VLCPlugin(this, pUnkOuter);
226 HRESULT hr = plugin->QueryInterface(riid, ppv);
230 return E_OUTOFMEMORY;
233 STDMETHODIMP VLCPluginClass::LockServer(BOOL fLock)
243 ////////////////////////////////////////////////////////////////////////
245 VLCPlugin::VLCPlugin(VLCPluginClass *p_class, LPUNKNOWN pUnkOuter) :
256 vlcOleControl = new VLCOleControl(this);
257 vlcOleInPlaceObject = new VLCOleInPlaceObject(this);
258 vlcOleInPlaceActiveObject = new VLCOleInPlaceActiveObject(this);
259 vlcPersistStorage = new VLCPersistStorage(this);
260 vlcPersistStreamInit = new VLCPersistStreamInit(this);
261 vlcPersistPropertyBag = new VLCPersistPropertyBag(this);
262 vlcProvideClassInfo = new VLCProvideClassInfo(this);
263 vlcConnectionPointContainer = new VLCConnectionPointContainer(this);
264 vlcObjectSafety = new VLCObjectSafety(this);
265 vlcControl = new VLCControl(this);
266 vlcViewObject = new VLCViewObject(this);
267 vlcDataObject = new VLCDataObject(this);
268 vlcOleObject = new VLCOleObject(this);
270 // configure controlling IUnknown interface for implemented interfaces
271 this->pUnkOuter = (NULL != pUnkOuter) ? pUnkOuter : dynamic_cast<LPUNKNOWN>(this);
274 _p_pict = p_class->getInPlacePict();
276 // make sure that persistable properties are initialized
280 VLCPlugin::~VLCPlugin()
283 delete vlcDataObject;
284 delete vlcViewObject;
286 delete vlcConnectionPointContainer;
287 delete vlcProvideClassInfo;
288 delete vlcPersistPropertyBag;
289 delete vlcPersistStreamInit;
290 delete vlcPersistStorage;
291 delete vlcOleInPlaceActiveObject;
292 delete vlcOleInPlaceObject;
293 delete vlcObjectSafety;
295 delete vlcOleControl;
299 SysFreeString(_bstr_mrl);
304 STDMETHODIMP VLCPlugin::QueryInterface(REFIID riid, void **ppv)
309 if( IID_IUnknown == riid )
310 *ppv = reinterpret_cast<LPVOID>(this);
311 else if( IID_IOleObject == riid )
312 *ppv = reinterpret_cast<LPVOID>(vlcOleObject);
313 else if( IID_IOleControl == riid )
314 *ppv = reinterpret_cast<LPVOID>(vlcOleControl);
315 else if( IID_IOleWindow == riid )
316 *ppv = reinterpret_cast<LPVOID>(vlcOleInPlaceObject);
317 else if( IID_IOleInPlaceObject == riid )
318 *ppv = reinterpret_cast<LPVOID>(vlcOleInPlaceObject);
319 else if( IID_IOleInPlaceActiveObject == riid )
320 *ppv = reinterpret_cast<LPVOID>(vlcOleInPlaceActiveObject);
321 else if( IID_IPersist == riid )
322 *ppv = reinterpret_cast<LPVOID>(vlcPersistStreamInit);
323 else if( IID_IPersistStreamInit == riid )
324 *ppv = reinterpret_cast<LPVOID>(vlcPersistStreamInit);
325 else if( IID_IPersistStorage == riid )
326 *ppv = reinterpret_cast<LPVOID>(vlcPersistStorage);
327 else if( IID_IPersistPropertyBag == riid )
328 *ppv = reinterpret_cast<LPVOID>(vlcPersistPropertyBag);
329 else if( IID_IProvideClassInfo == riid )
330 *ppv = reinterpret_cast<LPVOID>(vlcProvideClassInfo);
331 else if( IID_IProvideClassInfo2 == riid )
332 *ppv = reinterpret_cast<LPVOID>(vlcProvideClassInfo);
333 else if( IID_IConnectionPointContainer == riid )
334 *ppv = reinterpret_cast<LPVOID>(vlcConnectionPointContainer);
335 else if( IID_IObjectSafety == riid )
336 *ppv = reinterpret_cast<LPVOID>(vlcObjectSafety);
337 else if( IID_IDispatch == riid )
338 *ppv = reinterpret_cast<LPVOID>(vlcControl);
339 else if( IID_IVLCControl == riid )
340 *ppv = reinterpret_cast<LPVOID>(vlcControl);
341 else if( IID_IViewObject == riid )
342 *ppv = reinterpret_cast<LPVOID>(vlcViewObject);
343 else if( IID_IViewObject2 == riid )
344 *ppv = reinterpret_cast<LPVOID>(vlcViewObject);
345 else if( IID_IDataObject == riid )
346 *ppv = reinterpret_cast<LPVOID>(vlcDataObject);
350 return E_NOINTERFACE;
352 ((LPUNKNOWN)*ppv)->AddRef();
356 STDMETHODIMP_(ULONG) VLCPlugin::AddRef(void)
358 return InterlockedIncrement((LONG *)&_i_ref);
361 STDMETHODIMP_(ULONG) VLCPlugin::Release(void)
363 if( ! InterlockedDecrement((LONG *)&_i_ref) )
371 //////////////////////////////////////
374 ** we use a window to represent plugin viewport,
375 ** whose geometry is limited by the clipping rectangle
376 ** all drawing within this window must follow must
377 ** follow coordinates system described in lprPosRect
380 static void getViewportCoords(LPRECT lprPosRect, LPRECT lprClipRect)
383 bounds.right = lprPosRect->right-lprPosRect->left;
385 if( lprClipRect->left <= lprPosRect->left )
387 // left side is not clipped out
390 if( lprClipRect->right >= lprPosRect->right )
392 // right side is not clipped out, no change
394 else if( lprClipRect->right >= lprPosRect->left )
396 // right side is clipped out
397 lprPosRect->right = lprClipRect->right;
401 // outside of clipping rectange, not visible
402 lprPosRect->right = lprPosRect->left;
407 // left side is clipped out
408 bounds.left = lprPosRect->left-lprClipRect->left;
409 bounds.right += bounds.left;
411 lprPosRect->left = lprClipRect->left;
412 if( lprClipRect->right >= lprPosRect->right )
414 // right side is not clipped out
418 // right side is clipped out
419 lprPosRect->right = lprClipRect->right;
423 bounds.bottom = lprPosRect->bottom-lprPosRect->top;
425 if( lprClipRect->top <= lprPosRect->top )
427 // top side is not clipped out
430 if( lprClipRect->bottom >= lprPosRect->bottom )
432 // bottom side is not clipped out, no change
434 else if( lprClipRect->bottom >= lprPosRect->top )
436 // bottom side is clipped out
437 lprPosRect->bottom = lprClipRect->bottom;
441 // outside of clipping rectange, not visible
442 lprPosRect->right = lprPosRect->left;
447 bounds.top = lprPosRect->top-lprClipRect->top;
448 bounds.bottom += bounds.top;
450 lprPosRect->top = lprClipRect->top;
451 if( lprClipRect->bottom >= lprPosRect->bottom )
453 // bottom side is not clipped out
457 // bottom side is clipped out
458 lprPosRect->bottom = lprClipRect->bottom;
461 *lprClipRect = *lprPosRect;
462 *lprPosRect = bounds;
465 HRESULT VLCPlugin::onInit(void)
469 // initialize persistable properties
476 // set default/preferred size (320x240) pixels in HIMETRIC
477 HDC hDC = CreateDevDC(NULL);
480 HimetricFromDP(hDC, (LPPOINT)&_extent, 1);
485 return CO_E_ALREADYINITIALIZED;
488 HRESULT VLCPlugin::onLoad(void)
490 if( SysStringLen(_bstr_mrl) > 0 )
493 ** try to combine MRL with client site moniker, which for Internet Explorer
494 ** is the URL of the page the plugin is embedded into. Hence, if the MRL
495 ** is a relative URL, we should end up with an absolute URL
497 LPOLECLIENTSITE pClientSite;
498 if( SUCCEEDED(vlcOleObject->GetClientSite(&pClientSite)) && (NULL != pClientSite) )
501 if( SUCCEEDED(CreateBindCtx(0, &pBC)) )
503 LPMONIKER pContMoniker = NULL;
504 if( SUCCEEDED(pClientSite->GetMoniker(OLEGETMONIKER_ONLYIFTHERE,
505 OLEWHICHMK_CONTAINER, &pContMoniker)) )
508 if( SUCCEEDED(pContMoniker->GetDisplayName(pBC, NULL, &base_url)) )
511 ** check that the moniker name is a URL
513 if( UrlIsW(base_url, URLIS_URL) )
515 DWORD len = INTERNET_MAX_URL_LENGTH;
516 LPOLESTR abs_url = (LPOLESTR)CoTaskMemAlloc(sizeof(OLECHAR)*len);
517 if( NULL != abs_url )
519 if( SUCCEEDED(UrlCombineW(base_url, _bstr_mrl, abs_url, &len,
520 URL_ESCAPE_UNSAFE|URL_PLUGGABLE_PROTOCOL)) )
522 SysFreeString(_bstr_mrl);
523 _bstr_mrl = SysAllocStringLen(abs_url, len);
525 CoTaskMemFree(abs_url);
528 CoTaskMemFree(base_url);
530 pContMoniker->Release();
534 pClientSite->Release();
541 HRESULT VLCPlugin::onRun(void)
545 _i_vlc = VLC_Create();
553 ** default initialization options
555 char *ppsz_argv[10] = { "vlc", };
559 DWORD i_type, i_data = MAX_PATH + 1;
560 char p_data[MAX_PATH + 1];
561 if( RegOpenKeyEx( HKEY_LOCAL_MACHINE, "Software\\VideoLAN\\VLC",
562 0, KEY_READ, &h_key ) == ERROR_SUCCESS )
564 if( RegQueryValueEx( h_key, "InstallDir", 0, &i_type,
565 (LPBYTE)p_data, &i_data ) == ERROR_SUCCESS )
567 if( i_type == REG_SZ )
569 strcat( p_data, "\\vlc" );
570 ppsz_argv[0] = p_data;
573 RegCloseKey( h_key );
577 ppsz_argv[0] = "C:\\cygwin\\home\\Damien_Fouilleul\\dev\\videolan\\vlc-trunk\\vlc";
580 // make sure plugin isn't affected with VLC single instance mode
581 ppsz_argv[ppsz_argc++] = "--no-one-instance";
583 // loop mode is a configuration option only
585 ppsz_argv[ppsz_argc++] = "--loop";
587 if( IsDebuggerPresent() )
590 ** VLC default threading mechanism is designed to be as compatible
591 ** with POSIX as possible, however when debugged on win32, threads
592 ** lose signals and eventually VLC get stuck during initialization.
593 ** threading support can be configured to be more debugging friendly
594 ** but it will be less compatible with POSIX.
595 ** This is done by initializing with the following options
597 ppsz_argv[ppsz_argc++] = "--fast-mutex";
598 ppsz_argv[ppsz_argc++] = "--win9x-cv-method=1";
601 if( VLC_Init(_i_vlc, ppsz_argc, ppsz_argv) )
608 VLC_VolumeSet(_i_vlc, _i_volume);
611 VLC_VolumeMute(_i_vlc);
613 char *psz_mrl = CStrFromBSTR(CP_UTF8, _bstr_mrl);
614 if( NULL != psz_mrl )
616 // add default target to playlist
617 VLC_AddTarget(_i_vlc, psz_mrl, NULL, 0, PLAYLIST_APPEND, PLAYLIST_END);
618 CoTaskMemFree(psz_mrl);
624 HRESULT VLCPlugin::onAmbientChanged(LPUNKNOWN pContainer, DISPID dispID)
629 case DISPID_AMBIENT_BACKCOLOR:
631 case DISPID_AMBIENT_DISPLAYNAME:
633 case DISPID_AMBIENT_FONT:
635 case DISPID_AMBIENT_FORECOLOR:
637 case DISPID_AMBIENT_LOCALEID:
639 case DISPID_AMBIENT_MESSAGEREFLECT:
641 case DISPID_AMBIENT_SCALEUNITS:
643 case DISPID_AMBIENT_TEXTALIGN:
645 case DISPID_AMBIENT_USERMODE:
648 if( SUCCEEDED(GetObjectProperty(pContainer, dispID, v)) )
650 setUserMode(V_BOOL(&v) != VARIANT_FALSE);
653 case DISPID_AMBIENT_UIDEAD:
655 case DISPID_AMBIENT_SHOWGRABHANDLES:
657 case DISPID_AMBIENT_SHOWHATCHING:
659 case DISPID_AMBIENT_DISPLAYASDEFAULT:
661 case DISPID_AMBIENT_SUPPORTSMNEMONICS:
663 case DISPID_AMBIENT_AUTOCLIP:
665 case DISPID_AMBIENT_APPEARANCE:
667 case DISPID_AMBIENT_CODEPAGE:
670 if( SUCCEEDED(GetObjectProperty(pContainer, dispID, v)) )
672 setCodePage(V_I4(&v));
675 case DISPID_AMBIENT_PALETTE:
677 case DISPID_AMBIENT_CHARSET:
679 case DISPID_AMBIENT_RIGHTTOLEFT:
681 case DISPID_AMBIENT_TOPTOBOTTOM:
685 ** multiple property change, look up the ones we are interested in
689 if( SUCCEEDED(GetObjectProperty(pContainer, DISPID_AMBIENT_USERMODE, v)) )
691 setUserMode(V_BOOL(&v) != VARIANT_FALSE);
695 if( SUCCEEDED(GetObjectProperty(pContainer, DISPID_AMBIENT_CODEPAGE, v)) )
697 setCodePage(V_I4(&v));
704 HRESULT VLCPlugin::onClose(DWORD dwSaveOption)
706 if( isInPlaceActive() )
708 onInPlaceDeactivate();
715 vlcDataObject->onClose();
723 BOOL VLCPlugin::isInPlaceActive(void)
725 return (NULL != _inplacewnd);
728 HRESULT VLCPlugin::onActivateInPlace(LPMSG lpMesg, HWND hwndParent, LPCRECT lprcPosRect, LPCRECT lprcClipRect)
730 RECT posRect = *lprcPosRect;
731 RECT clipRect = *lprcClipRect;
734 ** record keeping of control geometry within container
739 ** convert posRect & clipRect to match control viewport coordinates
741 getViewportCoords(&posRect, &clipRect);
744 ** Create a window for in place activated control.
745 ** the window geometry matches the control viewport
746 ** within container so that embedded video is always
749 _inplacewnd = CreateWindow(_p_class->getInPlaceWndClassName(),
750 "VLC Plugin In-Place Window",
751 WS_CHILD|WS_CLIPCHILDREN|WS_CLIPSIBLINGS,
754 clipRect.right-clipRect.left,
755 clipRect.bottom-clipRect.top,
758 _p_class->getHInstance(),
762 if( NULL == _inplacewnd )
765 SetWindowLongPtr(_inplacewnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));
768 ** VLC embedded video automatically grows to cover client
769 ** area of parent window.
770 ** hence create a such a 'parent' window whose geometry
771 ** is always correct relative to the viewport bounds
773 _videownd = CreateWindow(_p_class->getVideoWndClassName(),
774 "VLC Plugin Video Window",
775 WS_CHILD|WS_CLIPCHILDREN|WS_VISIBLE,
778 posRect.right-posRect.left,
779 posRect.bottom-posRect.top,
782 _p_class->getHInstance(),
786 if( NULL == _videownd )
788 DestroyWindow(_inplacewnd);
792 SetWindowLongPtr(_videownd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));
795 ShowWindow(_inplacewnd, SW_SHOW);
799 /* run vlc if not done already */
800 HRESULT result = onRun();
804 /* set internal video width and height */
806 val.i_int = posRect.right-posRect.left;
807 VLC_VariableSet(_i_vlc, "conf::width", val);
808 val.i_int = posRect.bottom-posRect.top;
809 VLC_VariableSet(_i_vlc, "conf::height", val);
811 /* set internal video parent window */
812 /* horrible cast there */
813 val.i_int = reinterpret_cast<int>(_videownd);
814 VLC_VariableSet(_i_vlc, "drawable", val);
816 if( _b_autoplay & (VLC_PlaylistNumberOfItems(_i_vlc) > 0) )
825 HRESULT VLCPlugin::onInPlaceDeactivate(void)
833 DestroyWindow(_videownd);
835 DestroyWindow(_inplacewnd);
841 void VLCPlugin::setVisible(BOOL fVisible)
843 if( fVisible != _b_visible )
845 _b_visible = fVisible;
846 if( isInPlaceActive() )
848 ShowWindow(_inplacewnd, fVisible ? SW_SHOW : SW_HIDE);
850 InvalidateRect(_videownd, NULL, TRUE);
853 firePropChangedEvent(DISPID_Visible);
857 void VLCPlugin::setVolume(int volume)
861 else if( volume > 200 )
864 if( volume != _i_volume )
869 VLC_VolumeSet(_i_vlc, _i_volume);
875 void VLCPlugin::setFocus(BOOL fFocus)
878 SetActiveWindow(_inplacewnd);
881 BOOL VLCPlugin::hasFocus(void)
883 return GetActiveWindow() == _inplacewnd;
886 void VLCPlugin::onDraw(DVTARGETDEVICE * ptd, HDC hicTargetDev,
887 HDC hdcDraw, LPCRECTL lprcBounds, LPCRECTL lprcWBounds)
891 long width = lprcBounds->right-lprcBounds->left;
892 long height = lprcBounds->bottom-lprcBounds->top;
894 RECT bounds = { lprcBounds->left, lprcBounds->top, lprcBounds->right, lprcBounds->bottom };
895 FillRect(hdcDraw, &bounds, (HBRUSH)GetStockObject(WHITE_BRUSH));
897 LPPICTURE pict = getPicture();
900 OLE_XSIZE_HIMETRIC picWidth;
901 OLE_YSIZE_HIMETRIC picHeight;
903 pict->get_Width(&picWidth);
904 pict->get_Height(&picHeight);
906 SIZEL picSize = { picWidth, picHeight };
908 if( NULL != hicTargetDev )
910 DPFromHimetric(hicTargetDev, (LPPOINT)&picSize, 1);
912 else if( NULL != (hicTargetDev = CreateDevDC(ptd)) )
914 DPFromHimetric(hicTargetDev, (LPPOINT)&picSize, 1);
915 DeleteDC(hicTargetDev);
918 if( picSize.cx > width-4 )
919 picSize.cx = width-4;
920 if( picSize.cy > height-4 )
921 picSize.cy = height-4;
923 LONG dstX = lprcBounds->left+(width-picSize.cx)/2;
924 LONG dstY = lprcBounds->top+(height-picSize.cy)/2;
926 if( NULL != lprcWBounds )
928 RECT wBounds = { lprcWBounds->left, lprcWBounds->top, lprcWBounds->right, lprcWBounds->bottom };
929 pict->Render(hdcDraw, dstX, dstY, picSize.cx, picSize.cy,
930 0L, picHeight, picWidth, -picHeight, &wBounds);
933 pict->Render(hdcDraw, dstX, dstY, picSize.cx, picSize.cy,
934 0L, picHeight, picWidth, -picHeight, NULL);
939 SelectObject(hdcDraw, GetStockObject(BLACK_BRUSH));
941 MoveToEx(hdcDraw, bounds.left, bounds.top, NULL);
942 LineTo(hdcDraw, bounds.left+width-1, bounds.top);
943 LineTo(hdcDraw, bounds.left+width-1, bounds.top+height-1);
944 LineTo(hdcDraw, bounds.left, bounds.top+height-1);
945 LineTo(hdcDraw, bounds.left, bounds.top);
949 void VLCPlugin::onPaint(HDC hdc, const RECT &bounds, const RECT &clipRect)
953 /** if VLC is playing, it may not display any VIDEO content
954 ** hence, draw control logo*/
955 HDC hdcDraw = CreateCompatibleDC(hdc);
956 if( NULL != hdcDraw )
958 SIZEL size = getExtent();
959 DPFromHimetric(hdc, (LPPOINT)&size, 1);
960 RECTL posRect = { 0, 0, size.cx, size.cy };
962 int width = bounds.right-bounds.left;
963 int height = bounds.bottom-bounds.top;
965 HBITMAP hBitmap = CreateCompatibleBitmap(hdc, width, height);
966 if( NULL != hBitmap )
968 HBITMAP oldBmp = (HBITMAP)SelectObject(hdcDraw, hBitmap);
970 if( (size.cx != width) || (size.cy != height) )
972 // needs to scale canvas
973 SetMapMode(hdcDraw, MM_ANISOTROPIC);
974 SetWindowExtEx(hdcDraw, size.cx, size.cy, NULL);
975 SetViewportExtEx(hdcDraw, width, height, NULL);
978 onDraw(NULL, hdc, hdcDraw, &posRect, NULL);
980 SetMapMode(hdcDraw, MM_TEXT);
981 BitBlt(hdc, bounds.left, bounds.top,
986 SelectObject(hdcDraw, oldBmp);
987 DeleteObject(hBitmap);
994 void VLCPlugin::onPositionChange(LPCRECT lprcPosRect, LPCRECT lprcClipRect)
996 RECT clipRect = *lprcClipRect;
997 RECT posRect = *lprcPosRect;
999 //RedrawWindow(GetParent(_inplacewnd), &_posRect, NULL, RDW_INVALIDATE|RDW_ERASE|RDW_ALLCHILDREN);
1002 ** record keeping of control geometry within container
1007 ** convert posRect & clipRect to match control viewport coordinates
1009 getViewportCoords(&posRect, &clipRect);
1012 ** change in-place window geometry to match clipping region
1014 SetWindowPos(_inplacewnd, NULL,
1017 clipRect.right-clipRect.left,
1018 clipRect.bottom-clipRect.top,
1022 SWP_NOOWNERZORDER );
1025 ** change video window geometry to match object bounds within clipping region
1027 SetWindowPos(_videownd, NULL,
1030 posRect.right-posRect.left,
1031 posRect.bottom-posRect.top,
1035 SWP_NOOWNERZORDER );
1037 //RedrawWindow(_videownd, &posRect, NULL, RDW_INVALIDATE|RDW_ERASE|RDW_ALLCHILDREN);
1039 val.i_int = posRect.right-posRect.left;
1040 VLC_VariableSet(_i_vlc, "conf::width", val);
1041 val.i_int = posRect.bottom-posRect.top;
1042 VLC_VariableSet(_i_vlc, "conf::height", val);
1045 void VLCPlugin::freezeEvents(BOOL freeze)
1047 vlcConnectionPointContainer->freezeEvents(freeze);
1050 void VLCPlugin::firePropChangedEvent(DISPID dispid)
1052 vlcConnectionPointContainer->firePropChangedEvent(dispid);
1055 void VLCPlugin::fireOnPlayEvent(void)
1057 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1058 vlcConnectionPointContainer->fireEvent(DISPID_PlayEvent, &dispparamsNoArgs);
1061 void VLCPlugin::fireOnPauseEvent(void)
1063 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1064 vlcConnectionPointContainer->fireEvent(DISPID_PauseEvent, &dispparamsNoArgs);
1067 void VLCPlugin::fireOnStopEvent(void)
1069 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1070 vlcConnectionPointContainer->fireEvent(DISPID_StopEvent, &dispparamsNoArgs);