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)
184 || (IID_IClassFactory == riid) )
187 *ppv = reinterpret_cast<LPVOID>(this);
194 return E_NOINTERFACE;
197 STDMETHODIMP_(ULONG) VLCPluginClass::AddRef(void)
199 return InterlockedIncrement(_p_class_ref);
202 STDMETHODIMP_(ULONG) VLCPluginClass::Release(void)
204 ULONG refcount = InterlockedDecrement(_p_class_ref);
213 STDMETHODIMP VLCPluginClass::CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, void **ppv)
220 if( (NULL != pUnkOuter) && (IID_IUnknown != riid) ) {
221 return CLASS_E_NOAGGREGATION;
224 VLCPlugin *plugin = new VLCPlugin(this, pUnkOuter);
227 HRESULT hr = plugin->QueryInterface(riid, ppv);
231 return E_OUTOFMEMORY;
234 STDMETHODIMP VLCPluginClass::LockServer(BOOL fLock)
244 ////////////////////////////////////////////////////////////////////////
246 VLCPlugin::VLCPlugin(VLCPluginClass *p_class, LPUNKNOWN pUnkOuter) :
257 vlcOleControl = new VLCOleControl(this);
258 vlcOleInPlaceObject = new VLCOleInPlaceObject(this);
259 vlcOleInPlaceActiveObject = new VLCOleInPlaceActiveObject(this);
260 vlcPersistStorage = new VLCPersistStorage(this);
261 vlcPersistStreamInit = new VLCPersistStreamInit(this);
262 vlcPersistPropertyBag = new VLCPersistPropertyBag(this);
263 vlcProvideClassInfo = new VLCProvideClassInfo(this);
264 vlcConnectionPointContainer = new VLCConnectionPointContainer(this);
265 vlcObjectSafety = new VLCObjectSafety(this);
266 vlcControl = new VLCControl(this);
267 vlcViewObject = new VLCViewObject(this);
268 vlcDataObject = new VLCDataObject(this);
269 vlcOleObject = new VLCOleObject(this);
271 // configure controlling IUnknown interface for implemented interfaces
272 this->pUnkOuter = (NULL != pUnkOuter) ? pUnkOuter : dynamic_cast<LPUNKNOWN>(this);
275 _p_pict = p_class->getInPlacePict();
277 // make sure that persistable properties are initialized
281 VLCPlugin::~VLCPlugin()
284 delete vlcDataObject;
285 delete vlcViewObject;
287 delete vlcConnectionPointContainer;
288 delete vlcProvideClassInfo;
289 delete vlcPersistPropertyBag;
290 delete vlcPersistStreamInit;
291 delete vlcPersistStorage;
292 delete vlcOleInPlaceActiveObject;
293 delete vlcOleInPlaceObject;
294 delete vlcObjectSafety;
296 delete vlcOleControl;
300 SysFreeString(_bstr_mrl);
305 STDMETHODIMP VLCPlugin::QueryInterface(REFIID riid, void **ppv)
310 if( IID_IUnknown == riid )
311 *ppv = reinterpret_cast<LPVOID>(this);
312 else if( IID_IOleObject == riid )
313 *ppv = reinterpret_cast<LPVOID>(vlcOleObject);
314 else if( IID_IOleControl == riid )
315 *ppv = reinterpret_cast<LPVOID>(vlcOleControl);
316 else if( IID_IOleWindow == riid )
317 *ppv = reinterpret_cast<LPVOID>(vlcOleInPlaceObject);
318 else if( IID_IOleInPlaceObject == riid )
319 *ppv = reinterpret_cast<LPVOID>(vlcOleInPlaceObject);
320 else if( IID_IOleInPlaceActiveObject == riid )
321 *ppv = reinterpret_cast<LPVOID>(vlcOleInPlaceActiveObject);
322 else if( IID_IPersist == riid )
323 *ppv = reinterpret_cast<LPVOID>(vlcPersistStreamInit);
324 else if( IID_IPersistStreamInit == riid )
325 *ppv = reinterpret_cast<LPVOID>(vlcPersistStreamInit);
326 else if( IID_IPersistStorage == riid )
327 *ppv = reinterpret_cast<LPVOID>(vlcPersistStorage);
328 else if( IID_IPersistPropertyBag == riid )
329 *ppv = reinterpret_cast<LPVOID>(vlcPersistPropertyBag);
330 else if( IID_IProvideClassInfo == riid )
331 *ppv = reinterpret_cast<LPVOID>(vlcProvideClassInfo);
332 else if( IID_IProvideClassInfo2 == riid )
333 *ppv = reinterpret_cast<LPVOID>(vlcProvideClassInfo);
334 else if( IID_IConnectionPointContainer == riid )
335 *ppv = reinterpret_cast<LPVOID>(vlcConnectionPointContainer);
336 else if( IID_IObjectSafety == riid )
337 *ppv = reinterpret_cast<LPVOID>(vlcObjectSafety);
338 else if( IID_IDispatch == riid )
339 *ppv = reinterpret_cast<LPVOID>(vlcControl);
340 else if( IID_IVLCControl == riid )
341 *ppv = reinterpret_cast<LPVOID>(vlcControl);
342 else if( IID_IViewObject == riid )
343 *ppv = reinterpret_cast<LPVOID>(vlcViewObject);
344 else if( IID_IViewObject2 == riid )
345 *ppv = reinterpret_cast<LPVOID>(vlcViewObject);
346 else if( IID_IDataObject == riid )
347 *ppv = reinterpret_cast<LPVOID>(vlcDataObject);
351 return E_NOINTERFACE;
353 ((LPUNKNOWN)*ppv)->AddRef();
357 STDMETHODIMP_(ULONG) VLCPlugin::AddRef(void)
359 return InterlockedIncrement((LONG *)&_i_ref);
362 STDMETHODIMP_(ULONG) VLCPlugin::Release(void)
364 if( ! InterlockedDecrement((LONG *)&_i_ref) )
372 //////////////////////////////////////
375 ** we use a window to represent plugin viewport,
376 ** whose geometry is limited by the clipping rectangle
377 ** all drawing within this window must follow must
378 ** follow coordinates system described in lprPosRect
381 static void getViewportCoords(LPRECT lprPosRect, LPRECT lprClipRect)
384 bounds.right = lprPosRect->right-lprPosRect->left;
386 if( lprClipRect->left <= lprPosRect->left )
388 // left side is not clipped out
391 if( lprClipRect->right >= lprPosRect->right )
393 // right side is not clipped out, no change
395 else if( lprClipRect->right >= lprPosRect->left )
397 // right side is clipped out
398 lprPosRect->right = lprClipRect->right;
402 // outside of clipping rectange, not visible
403 lprPosRect->right = lprPosRect->left;
408 // left side is clipped out
409 bounds.left = lprPosRect->left-lprClipRect->left;
410 bounds.right += bounds.left;
412 lprPosRect->left = lprClipRect->left;
413 if( lprClipRect->right >= lprPosRect->right )
415 // right side is not clipped out
419 // right side is clipped out
420 lprPosRect->right = lprClipRect->right;
424 bounds.bottom = lprPosRect->bottom-lprPosRect->top;
426 if( lprClipRect->top <= lprPosRect->top )
428 // top side is not clipped out
431 if( lprClipRect->bottom >= lprPosRect->bottom )
433 // bottom side is not clipped out, no change
435 else if( lprClipRect->bottom >= lprPosRect->top )
437 // bottom side is clipped out
438 lprPosRect->bottom = lprClipRect->bottom;
442 // outside of clipping rectange, not visible
443 lprPosRect->right = lprPosRect->left;
448 bounds.top = lprPosRect->top-lprClipRect->top;
449 bounds.bottom += bounds.top;
451 lprPosRect->top = lprClipRect->top;
452 if( lprClipRect->bottom >= lprPosRect->bottom )
454 // bottom side is not clipped out
458 // bottom side is clipped out
459 lprPosRect->bottom = lprClipRect->bottom;
462 *lprClipRect = *lprPosRect;
463 *lprPosRect = bounds;
466 HRESULT VLCPlugin::onInit(void)
470 // initialize persistable properties
478 // set default/preferred size (320x240) pixels in HIMETRIC
479 HDC hDC = CreateDevDC(NULL);
482 HimetricFromDP(hDC, (LPPOINT)&_extent, 1);
487 return CO_E_ALREADYINITIALIZED;
490 HRESULT VLCPlugin::onLoad(void)
492 if( SysStringLen(_bstr_mrl) > 0 )
495 ** try to combine MRL with client site moniker, which for Internet Explorer
496 ** is the URL of the page the plugin is embedded into. Hence, if the MRL
497 ** is a relative URL, we should end up with an absolute URL
499 LPOLECLIENTSITE pClientSite;
500 if( SUCCEEDED(vlcOleObject->GetClientSite(&pClientSite)) && (NULL != pClientSite) )
503 if( SUCCEEDED(CreateBindCtx(0, &pBC)) )
505 LPMONIKER pContMoniker = NULL;
506 if( SUCCEEDED(pClientSite->GetMoniker(OLEGETMONIKER_ONLYIFTHERE,
507 OLEWHICHMK_CONTAINER, &pContMoniker)) )
510 if( SUCCEEDED(pContMoniker->GetDisplayName(pBC, NULL, &base_url)) )
513 ** check that the moniker name is a URL
515 if( UrlIsW(base_url, URLIS_URL) )
517 DWORD len = INTERNET_MAX_URL_LENGTH;
518 LPOLESTR abs_url = (LPOLESTR)CoTaskMemAlloc(sizeof(OLECHAR)*len);
519 if( NULL != abs_url )
521 if( SUCCEEDED(UrlCombineW(base_url, _bstr_mrl, abs_url, &len,
522 URL_ESCAPE_UNSAFE|URL_PLUGGABLE_PROTOCOL)) )
524 SysFreeString(_bstr_mrl);
525 _bstr_mrl = SysAllocStringLen(abs_url, len);
527 CoTaskMemFree(abs_url);
530 CoTaskMemFree(base_url);
532 pContMoniker->Release();
536 pClientSite->Release();
543 HRESULT VLCPlugin::getVLCObject(int *i_vlc)
547 _i_vlc = VLC_Create();
555 ** default initialization options
557 char *ppsz_argv[10] = { "vlc", };
561 DWORD i_type, i_data = MAX_PATH + 1;
562 char p_data[MAX_PATH + 1];
563 if( RegOpenKeyEx( HKEY_LOCAL_MACHINE, "Software\\VideoLAN\\VLC",
564 0, KEY_READ, &h_key ) == ERROR_SUCCESS )
566 if( RegQueryValueEx( h_key, "InstallDir", 0, &i_type,
567 (LPBYTE)p_data, &i_data ) == ERROR_SUCCESS )
569 if( i_type == REG_SZ )
571 strcat( p_data, "\\vlc" );
572 ppsz_argv[0] = p_data;
575 RegCloseKey( h_key );
579 ppsz_argv[0] = "C:\\cygwin\\home\\Damien_Fouilleul\\dev\\videolan\\vlc-trunk\\vlc";
582 // make sure plugin isn't affected with VLC single instance mode
583 ppsz_argv[ppsz_argc++] = "--no-one-instance";
585 // loop mode is a configuration option only
587 ppsz_argv[ppsz_argc++] = "--loop";
589 if( IsDebuggerPresent() )
592 ** VLC default threading mechanism is designed to be as compatible
593 ** with POSIX as possible, however when debugged on win32, threads
594 ** lose signals and eventually VLC get stuck during initialization.
595 ** threading support can be configured to be more debugging friendly
596 ** but it will be less compatible with POSIX.
597 ** This is done by initializing with the following options
599 ppsz_argv[ppsz_argc++] = "--fast-mutex";
600 ppsz_argv[ppsz_argc++] = "--win9x-cv-method=1";
603 if( VLC_Init(_i_vlc, ppsz_argc, ppsz_argv) )
610 VLC_VolumeSet(_i_vlc, _i_volume);
613 VLC_VolumeMute(_i_vlc);
615 char *psz_mrl = CStrFromBSTR(CP_UTF8, _bstr_mrl);
616 if( NULL != psz_mrl )
619 const char *options[1];
624 snprintf(timeBuffer, sizeof(timeBuffer), ":start-time=%d", _i_time);
625 options[cOptions++] = timeBuffer;
627 // add default target to playlist
628 VLC_AddTarget(_i_vlc, psz_mrl, options, cOptions, PLAYLIST_APPEND, PLAYLIST_END);
629 CoTaskMemFree(psz_mrl);
636 HRESULT VLCPlugin::onAmbientChanged(LPUNKNOWN pContainer, DISPID dispID)
641 case DISPID_AMBIENT_BACKCOLOR:
643 case DISPID_AMBIENT_DISPLAYNAME:
645 case DISPID_AMBIENT_FONT:
647 case DISPID_AMBIENT_FORECOLOR:
649 case DISPID_AMBIENT_LOCALEID:
651 case DISPID_AMBIENT_MESSAGEREFLECT:
653 case DISPID_AMBIENT_SCALEUNITS:
655 case DISPID_AMBIENT_TEXTALIGN:
657 case DISPID_AMBIENT_USERMODE:
660 if( SUCCEEDED(GetObjectProperty(pContainer, dispID, v)) )
662 setUserMode(V_BOOL(&v) != VARIANT_FALSE);
665 case DISPID_AMBIENT_UIDEAD:
667 case DISPID_AMBIENT_SHOWGRABHANDLES:
669 case DISPID_AMBIENT_SHOWHATCHING:
671 case DISPID_AMBIENT_DISPLAYASDEFAULT:
673 case DISPID_AMBIENT_SUPPORTSMNEMONICS:
675 case DISPID_AMBIENT_AUTOCLIP:
677 case DISPID_AMBIENT_APPEARANCE:
679 case DISPID_AMBIENT_CODEPAGE:
682 if( SUCCEEDED(GetObjectProperty(pContainer, dispID, v)) )
684 setCodePage(V_I4(&v));
687 case DISPID_AMBIENT_PALETTE:
689 case DISPID_AMBIENT_CHARSET:
691 case DISPID_AMBIENT_RIGHTTOLEFT:
693 case DISPID_AMBIENT_TOPTOBOTTOM:
697 ** multiple property change, look up the ones we are interested in
701 if( SUCCEEDED(GetObjectProperty(pContainer, DISPID_AMBIENT_USERMODE, v)) )
703 setUserMode(V_BOOL(&v) != VARIANT_FALSE);
707 if( SUCCEEDED(GetObjectProperty(pContainer, DISPID_AMBIENT_CODEPAGE, v)) )
709 setCodePage(V_I4(&v));
716 HRESULT VLCPlugin::onClose(DWORD dwSaveOption)
718 if( isInPlaceActive() )
720 onInPlaceDeactivate();
727 vlcDataObject->onClose();
735 BOOL VLCPlugin::isInPlaceActive(void)
737 return (NULL != _inplacewnd);
740 HRESULT VLCPlugin::onActivateInPlace(LPMSG lpMesg, HWND hwndParent, LPCRECT lprcPosRect, LPCRECT lprcClipRect)
742 RECT posRect = *lprcPosRect;
743 RECT clipRect = *lprcClipRect;
746 ** record keeping of control geometry within container
751 ** convert posRect & clipRect to match control viewport coordinates
753 getViewportCoords(&posRect, &clipRect);
756 ** Create a window for in place activated control.
757 ** the window geometry matches the control viewport
758 ** within container so that embedded video is always
761 _inplacewnd = CreateWindow(_p_class->getInPlaceWndClassName(),
762 "VLC Plugin In-Place Window",
763 WS_CHILD|WS_CLIPCHILDREN|WS_CLIPSIBLINGS,
766 clipRect.right-clipRect.left,
767 clipRect.bottom-clipRect.top,
770 _p_class->getHInstance(),
774 if( NULL == _inplacewnd )
777 SetWindowLongPtr(_inplacewnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));
780 ** VLC embedded video automatically grows to cover client
781 ** area of parent window.
782 ** hence create a such a 'parent' window whose geometry
783 ** is always correct relative to the viewport bounds
785 _videownd = CreateWindow(_p_class->getVideoWndClassName(),
786 "VLC Plugin Video Window",
787 WS_CHILD|WS_CLIPCHILDREN|WS_VISIBLE,
790 posRect.right-posRect.left,
791 posRect.bottom-posRect.top,
794 _p_class->getHInstance(),
798 if( NULL == _videownd )
800 DestroyWindow(_inplacewnd);
804 SetWindowLongPtr(_videownd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));
808 /* will run vlc if not done already */
810 HRESULT result = getVLCObject(&i_vlc);
814 /* set internal video width and height */
816 val.i_int = posRect.right-posRect.left;
817 VLC_VariableSet(i_vlc, "conf::width", val);
818 val.i_int = posRect.bottom-posRect.top;
819 VLC_VariableSet(i_vlc, "conf::height", val);
821 /* set internal video parent window */
822 /* horrible cast there */
823 val.i_int = reinterpret_cast<int>(_videownd);
824 VLC_VariableSet(i_vlc, "drawable", val);
826 if( _b_autoplay & (VLC_PlaylistNumberOfItems(i_vlc) > 0) )
834 ShowWindow(_inplacewnd, SW_SHOW);
839 HRESULT VLCPlugin::onInPlaceDeactivate(void)
847 DestroyWindow(_videownd);
849 DestroyWindow(_inplacewnd);
855 void VLCPlugin::setVisible(BOOL fVisible)
857 if( fVisible != _b_visible )
859 _b_visible = fVisible;
860 if( isInPlaceActive() )
862 ShowWindow(_inplacewnd, fVisible ? SW_SHOW : SW_HIDE);
864 InvalidateRect(_videownd, NULL, TRUE);
867 firePropChangedEvent(DISPID_Visible);
871 void VLCPlugin::setVolume(int volume)
875 else if( volume > 200 )
878 if( volume != _i_volume )
883 VLC_VolumeSet(_i_vlc, _i_volume);
889 void VLCPlugin::setTime(int seconds)
894 if( seconds != _i_time )
899 VLC_TimeSet(_i_vlc, seconds, VLC_FALSE);
905 void VLCPlugin::setFocus(BOOL fFocus)
908 SetActiveWindow(_inplacewnd);
911 BOOL VLCPlugin::hasFocus(void)
913 return GetActiveWindow() == _inplacewnd;
916 void VLCPlugin::onDraw(DVTARGETDEVICE * ptd, HDC hicTargetDev,
917 HDC hdcDraw, LPCRECTL lprcBounds, LPCRECTL lprcWBounds)
921 long width = lprcBounds->right-lprcBounds->left;
922 long height = lprcBounds->bottom-lprcBounds->top;
924 RECT bounds = { lprcBounds->left, lprcBounds->top, lprcBounds->right, lprcBounds->bottom };
925 FillRect(hdcDraw, &bounds, (HBRUSH)GetStockObject(WHITE_BRUSH));
927 LPPICTURE pict = getPicture();
930 OLE_XSIZE_HIMETRIC picWidth;
931 OLE_YSIZE_HIMETRIC picHeight;
933 pict->get_Width(&picWidth);
934 pict->get_Height(&picHeight);
936 SIZEL picSize = { picWidth, picHeight };
938 if( NULL != hicTargetDev )
940 DPFromHimetric(hicTargetDev, (LPPOINT)&picSize, 1);
942 else if( NULL != (hicTargetDev = CreateDevDC(ptd)) )
944 DPFromHimetric(hicTargetDev, (LPPOINT)&picSize, 1);
945 DeleteDC(hicTargetDev);
948 if( picSize.cx > width-4 )
949 picSize.cx = width-4;
950 if( picSize.cy > height-4 )
951 picSize.cy = height-4;
953 LONG dstX = lprcBounds->left+(width-picSize.cx)/2;
954 LONG dstY = lprcBounds->top+(height-picSize.cy)/2;
956 if( NULL != lprcWBounds )
958 RECT wBounds = { lprcWBounds->left, lprcWBounds->top, lprcWBounds->right, lprcWBounds->bottom };
959 pict->Render(hdcDraw, dstX, dstY, picSize.cx, picSize.cy,
960 0L, picHeight, picWidth, -picHeight, &wBounds);
963 pict->Render(hdcDraw, dstX, dstY, picSize.cx, picSize.cy,
964 0L, picHeight, picWidth, -picHeight, NULL);
969 SelectObject(hdcDraw, GetStockObject(BLACK_BRUSH));
971 MoveToEx(hdcDraw, bounds.left, bounds.top, NULL);
972 LineTo(hdcDraw, bounds.left+width-1, bounds.top);
973 LineTo(hdcDraw, bounds.left+width-1, bounds.top+height-1);
974 LineTo(hdcDraw, bounds.left, bounds.top+height-1);
975 LineTo(hdcDraw, bounds.left, bounds.top);
979 void VLCPlugin::onPaint(HDC hdc, const RECT &bounds, const RECT &clipRect)
983 /** if VLC is playing, it may not display any VIDEO content
984 ** hence, draw control logo*/
985 HDC hdcDraw = CreateCompatibleDC(hdc);
986 if( NULL != hdcDraw )
988 SIZEL size = getExtent();
989 DPFromHimetric(hdc, (LPPOINT)&size, 1);
990 RECTL posRect = { 0, 0, size.cx, size.cy };
992 int width = bounds.right-bounds.left;
993 int height = bounds.bottom-bounds.top;
995 HBITMAP hBitmap = CreateCompatibleBitmap(hdc, width, height);
996 if( NULL != hBitmap )
998 HBITMAP oldBmp = (HBITMAP)SelectObject(hdcDraw, hBitmap);
1000 if( (size.cx != width) || (size.cy != height) )
1002 // needs to scale canvas
1003 SetMapMode(hdcDraw, MM_ANISOTROPIC);
1004 SetWindowExtEx(hdcDraw, size.cx, size.cy, NULL);
1005 SetViewportExtEx(hdcDraw, width, height, NULL);
1008 onDraw(NULL, hdc, hdcDraw, &posRect, NULL);
1010 SetMapMode(hdcDraw, MM_TEXT);
1011 BitBlt(hdc, bounds.left, bounds.top,
1016 SelectObject(hdcDraw, oldBmp);
1017 DeleteObject(hBitmap);
1024 void VLCPlugin::onPositionChange(LPCRECT lprcPosRect, LPCRECT lprcClipRect)
1026 RECT clipRect = *lprcClipRect;
1027 RECT posRect = *lprcPosRect;
1029 //RedrawWindow(GetParent(_inplacewnd), &_posRect, NULL, RDW_INVALIDATE|RDW_ERASE|RDW_ALLCHILDREN);
1032 ** record keeping of control geometry within container
1037 ** convert posRect & clipRect to match control viewport coordinates
1039 getViewportCoords(&posRect, &clipRect);
1042 ** change in-place window geometry to match clipping region
1044 SetWindowPos(_inplacewnd, NULL,
1047 clipRect.right-clipRect.left,
1048 clipRect.bottom-clipRect.top,
1052 SWP_NOOWNERZORDER );
1055 ** change video window geometry to match object bounds within clipping region
1057 SetWindowPos(_videownd, NULL,
1060 posRect.right-posRect.left,
1061 posRect.bottom-posRect.top,
1065 SWP_NOOWNERZORDER );
1067 //RedrawWindow(_videownd, &posRect, NULL, RDW_INVALIDATE|RDW_ERASE|RDW_ALLCHILDREN);
1069 val.i_int = posRect.right-posRect.left;
1070 VLC_VariableSet(_i_vlc, "conf::width", val);
1071 val.i_int = posRect.bottom-posRect.top;
1072 VLC_VariableSet(_i_vlc, "conf::height", val);
1075 void VLCPlugin::freezeEvents(BOOL freeze)
1077 vlcConnectionPointContainer->freezeEvents(freeze);
1080 void VLCPlugin::firePropChangedEvent(DISPID dispid)
1082 vlcConnectionPointContainer->firePropChangedEvent(dispid);
1085 void VLCPlugin::fireOnPlayEvent(void)
1087 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1088 vlcConnectionPointContainer->fireEvent(DISPID_PlayEvent, &dispparamsNoArgs);
1091 void VLCPlugin::fireOnPauseEvent(void)
1093 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1094 vlcConnectionPointContainer->fireEvent(DISPID_PauseEvent, &dispparamsNoArgs);
1097 void VLCPlugin::fireOnStopEvent(void)
1099 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1100 vlcConnectionPointContainer->fireEvent(DISPID_StopEvent, &dispparamsNoArgs);