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
477 // set default/preferred size (320x240) pixels in HIMETRIC
478 HDC hDC = CreateDevDC(NULL);
481 HimetricFromDP(hDC, (LPPOINT)&_extent, 1);
486 return CO_E_ALREADYINITIALIZED;
489 HRESULT VLCPlugin::onLoad(void)
491 if( SysStringLen(_bstr_mrl) > 0 )
494 ** try to combine MRL with client site moniker, which for Internet Explorer
495 ** is the URL of the page the plugin is embedded into. Hence, if the MRL
496 ** is a relative URL, we should end up with an absolute URL
498 LPOLECLIENTSITE pClientSite;
499 if( SUCCEEDED(vlcOleObject->GetClientSite(&pClientSite)) && (NULL != pClientSite) )
502 if( SUCCEEDED(CreateBindCtx(0, &pBC)) )
504 LPMONIKER pContMoniker = NULL;
505 if( SUCCEEDED(pClientSite->GetMoniker(OLEGETMONIKER_ONLYIFTHERE,
506 OLEWHICHMK_CONTAINER, &pContMoniker)) )
509 if( SUCCEEDED(pContMoniker->GetDisplayName(pBC, NULL, &base_url)) )
512 ** check that the moniker name is a URL
514 if( UrlIsW(base_url, URLIS_URL) )
516 DWORD len = INTERNET_MAX_URL_LENGTH;
517 LPOLESTR abs_url = (LPOLESTR)CoTaskMemAlloc(sizeof(OLECHAR)*len);
518 if( NULL != abs_url )
520 if( SUCCEEDED(UrlCombineW(base_url, _bstr_mrl, abs_url, &len,
521 URL_ESCAPE_UNSAFE|URL_PLUGGABLE_PROTOCOL)) )
523 SysFreeString(_bstr_mrl);
524 _bstr_mrl = SysAllocStringLen(abs_url, len);
526 CoTaskMemFree(abs_url);
529 CoTaskMemFree(base_url);
531 pContMoniker->Release();
535 pClientSite->Release();
542 HRESULT VLCPlugin::getVLCObject(int *i_vlc)
546 _i_vlc = VLC_Create();
554 ** default initialization options
556 char *ppsz_argv[10] = { "vlc", };
560 DWORD i_type, i_data = MAX_PATH + 1;
561 char p_data[MAX_PATH + 1];
562 if( RegOpenKeyEx( HKEY_LOCAL_MACHINE, "Software\\VideoLAN\\VLC",
563 0, KEY_READ, &h_key ) == ERROR_SUCCESS )
565 if( RegQueryValueEx( h_key, "InstallDir", 0, &i_type,
566 (LPBYTE)p_data, &i_data ) == ERROR_SUCCESS )
568 if( i_type == REG_SZ )
570 strcat( p_data, "\\vlc" );
571 ppsz_argv[0] = p_data;
574 RegCloseKey( h_key );
578 ppsz_argv[0] = "C:\\cygwin\\home\\Damien_Fouilleul\\dev\\videolan\\vlc-trunk\\vlc";
581 // make sure plugin isn't affected with VLC single instance mode
582 ppsz_argv[ppsz_argc++] = "--no-one-instance";
584 // loop mode is a configuration option only
586 ppsz_argv[ppsz_argc++] = "--loop";
588 if( IsDebuggerPresent() )
591 ** VLC default threading mechanism is designed to be as compatible
592 ** with POSIX as possible, however when debugged on win32, threads
593 ** lose signals and eventually VLC get stuck during initialization.
594 ** threading support can be configured to be more debugging friendly
595 ** but it will be less compatible with POSIX.
596 ** This is done by initializing with the following options
598 ppsz_argv[ppsz_argc++] = "--fast-mutex";
599 ppsz_argv[ppsz_argc++] = "--win9x-cv-method=1";
602 if( VLC_Init(_i_vlc, ppsz_argc, ppsz_argv) )
609 VLC_VolumeSet(_i_vlc, _i_volume);
612 VLC_VolumeMute(_i_vlc);
614 char *psz_mrl = CStrFromBSTR(CP_UTF8, _bstr_mrl);
615 if( NULL != psz_mrl )
618 const char *options[1];
623 snprintf(timeBuffer, sizeof(timeBuffer), ":start-time=%d", _i_time);
624 options[cOptions++] = timeBuffer;
626 // add default target to playlist
627 VLC_AddTarget(_i_vlc, psz_mrl, options, cOptions, PLAYLIST_APPEND, PLAYLIST_END);
628 CoTaskMemFree(psz_mrl);
635 HRESULT VLCPlugin::onAmbientChanged(LPUNKNOWN pContainer, DISPID dispID)
640 case DISPID_AMBIENT_BACKCOLOR:
642 case DISPID_AMBIENT_DISPLAYNAME:
644 case DISPID_AMBIENT_FONT:
646 case DISPID_AMBIENT_FORECOLOR:
648 case DISPID_AMBIENT_LOCALEID:
650 case DISPID_AMBIENT_MESSAGEREFLECT:
652 case DISPID_AMBIENT_SCALEUNITS:
654 case DISPID_AMBIENT_TEXTALIGN:
656 case DISPID_AMBIENT_USERMODE:
659 if( SUCCEEDED(GetObjectProperty(pContainer, dispID, v)) )
661 setUserMode(V_BOOL(&v) != VARIANT_FALSE);
664 case DISPID_AMBIENT_UIDEAD:
666 case DISPID_AMBIENT_SHOWGRABHANDLES:
668 case DISPID_AMBIENT_SHOWHATCHING:
670 case DISPID_AMBIENT_DISPLAYASDEFAULT:
672 case DISPID_AMBIENT_SUPPORTSMNEMONICS:
674 case DISPID_AMBIENT_AUTOCLIP:
676 case DISPID_AMBIENT_APPEARANCE:
678 case DISPID_AMBIENT_CODEPAGE:
681 if( SUCCEEDED(GetObjectProperty(pContainer, dispID, v)) )
683 setCodePage(V_I4(&v));
686 case DISPID_AMBIENT_PALETTE:
688 case DISPID_AMBIENT_CHARSET:
690 case DISPID_AMBIENT_RIGHTTOLEFT:
692 case DISPID_AMBIENT_TOPTOBOTTOM:
696 ** multiple property change, look up the ones we are interested in
700 if( SUCCEEDED(GetObjectProperty(pContainer, DISPID_AMBIENT_USERMODE, v)) )
702 setUserMode(V_BOOL(&v) != VARIANT_FALSE);
706 if( SUCCEEDED(GetObjectProperty(pContainer, DISPID_AMBIENT_CODEPAGE, v)) )
708 setCodePage(V_I4(&v));
715 HRESULT VLCPlugin::onClose(DWORD dwSaveOption)
717 if( isInPlaceActive() )
719 onInPlaceDeactivate();
726 vlcDataObject->onClose();
734 BOOL VLCPlugin::isInPlaceActive(void)
736 return (NULL != _inplacewnd);
739 HRESULT VLCPlugin::onActivateInPlace(LPMSG lpMesg, HWND hwndParent, LPCRECT lprcPosRect, LPCRECT lprcClipRect)
741 RECT posRect = *lprcPosRect;
742 RECT clipRect = *lprcClipRect;
745 ** record keeping of control geometry within container
750 ** convert posRect & clipRect to match control viewport coordinates
752 getViewportCoords(&posRect, &clipRect);
755 ** Create a window for in place activated control.
756 ** the window geometry matches the control viewport
757 ** within container so that embedded video is always
760 _inplacewnd = CreateWindow(_p_class->getInPlaceWndClassName(),
761 "VLC Plugin In-Place Window",
762 WS_CHILD|WS_CLIPCHILDREN|WS_CLIPSIBLINGS,
765 clipRect.right-clipRect.left,
766 clipRect.bottom-clipRect.top,
769 _p_class->getHInstance(),
773 if( NULL == _inplacewnd )
776 SetWindowLongPtr(_inplacewnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));
779 ** VLC embedded video automatically grows to cover client
780 ** area of parent window.
781 ** hence create a such a 'parent' window whose geometry
782 ** is always correct relative to the viewport bounds
784 _videownd = CreateWindow(_p_class->getVideoWndClassName(),
785 "VLC Plugin Video Window",
786 WS_CHILD|WS_CLIPCHILDREN|WS_VISIBLE,
789 posRect.right-posRect.left,
790 posRect.bottom-posRect.top,
793 _p_class->getHInstance(),
797 if( NULL == _videownd )
799 DestroyWindow(_inplacewnd);
803 SetWindowLongPtr(_videownd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));
807 /* will run vlc if not done already */
809 HRESULT result = getVLCObject(&i_vlc);
813 /* set internal video width and height */
815 val.i_int = posRect.right-posRect.left;
816 VLC_VariableSet(i_vlc, "conf::width", val);
817 val.i_int = posRect.bottom-posRect.top;
818 VLC_VariableSet(i_vlc, "conf::height", val);
820 /* set internal video parent window */
821 /* horrible cast there */
822 val.i_int = reinterpret_cast<int>(_videownd);
823 VLC_VariableSet(i_vlc, "drawable", val);
825 if( _b_autoplay & (VLC_PlaylistNumberOfItems(i_vlc) > 0) )
833 ShowWindow(_inplacewnd, SW_SHOW);
838 HRESULT VLCPlugin::onInPlaceDeactivate(void)
846 DestroyWindow(_videownd);
848 DestroyWindow(_inplacewnd);
854 void VLCPlugin::setVisible(BOOL fVisible)
856 if( fVisible != _b_visible )
858 _b_visible = fVisible;
859 if( isInPlaceActive() )
861 ShowWindow(_inplacewnd, fVisible ? SW_SHOW : SW_HIDE);
863 InvalidateRect(_videownd, NULL, TRUE);
866 firePropChangedEvent(DISPID_Visible);
870 void VLCPlugin::setVolume(int volume)
874 else if( volume > 200 )
877 if( volume != _i_volume )
882 VLC_VolumeSet(_i_vlc, _i_volume);
888 void VLCPlugin::setTime(int seconds)
893 if( seconds != _i_time )
898 VLC_TimeSet(_i_vlc, seconds, VLC_FALSE);
904 void VLCPlugin::setFocus(BOOL fFocus)
907 SetActiveWindow(_inplacewnd);
910 BOOL VLCPlugin::hasFocus(void)
912 return GetActiveWindow() == _inplacewnd;
915 void VLCPlugin::onDraw(DVTARGETDEVICE * ptd, HDC hicTargetDev,
916 HDC hdcDraw, LPCRECTL lprcBounds, LPCRECTL lprcWBounds)
920 long width = lprcBounds->right-lprcBounds->left;
921 long height = lprcBounds->bottom-lprcBounds->top;
923 RECT bounds = { lprcBounds->left, lprcBounds->top, lprcBounds->right, lprcBounds->bottom };
924 FillRect(hdcDraw, &bounds, (HBRUSH)GetStockObject(WHITE_BRUSH));
926 LPPICTURE pict = getPicture();
929 OLE_XSIZE_HIMETRIC picWidth;
930 OLE_YSIZE_HIMETRIC picHeight;
932 pict->get_Width(&picWidth);
933 pict->get_Height(&picHeight);
935 SIZEL picSize = { picWidth, picHeight };
937 if( NULL != hicTargetDev )
939 DPFromHimetric(hicTargetDev, (LPPOINT)&picSize, 1);
941 else if( NULL != (hicTargetDev = CreateDevDC(ptd)) )
943 DPFromHimetric(hicTargetDev, (LPPOINT)&picSize, 1);
944 DeleteDC(hicTargetDev);
947 if( picSize.cx > width-4 )
948 picSize.cx = width-4;
949 if( picSize.cy > height-4 )
950 picSize.cy = height-4;
952 LONG dstX = lprcBounds->left+(width-picSize.cx)/2;
953 LONG dstY = lprcBounds->top+(height-picSize.cy)/2;
955 if( NULL != lprcWBounds )
957 RECT wBounds = { lprcWBounds->left, lprcWBounds->top, lprcWBounds->right, lprcWBounds->bottom };
958 pict->Render(hdcDraw, dstX, dstY, picSize.cx, picSize.cy,
959 0L, picHeight, picWidth, -picHeight, &wBounds);
962 pict->Render(hdcDraw, dstX, dstY, picSize.cx, picSize.cy,
963 0L, picHeight, picWidth, -picHeight, NULL);
968 SelectObject(hdcDraw, GetStockObject(BLACK_BRUSH));
970 MoveToEx(hdcDraw, bounds.left, bounds.top, NULL);
971 LineTo(hdcDraw, bounds.left+width-1, bounds.top);
972 LineTo(hdcDraw, bounds.left+width-1, bounds.top+height-1);
973 LineTo(hdcDraw, bounds.left, bounds.top+height-1);
974 LineTo(hdcDraw, bounds.left, bounds.top);
978 void VLCPlugin::onPaint(HDC hdc, const RECT &bounds, const RECT &clipRect)
982 /** if VLC is playing, it may not display any VIDEO content
983 ** hence, draw control logo*/
984 HDC hdcDraw = CreateCompatibleDC(hdc);
985 if( NULL != hdcDraw )
987 SIZEL size = getExtent();
988 DPFromHimetric(hdc, (LPPOINT)&size, 1);
989 RECTL posRect = { 0, 0, size.cx, size.cy };
991 int width = bounds.right-bounds.left;
992 int height = bounds.bottom-bounds.top;
994 HBITMAP hBitmap = CreateCompatibleBitmap(hdc, width, height);
995 if( NULL != hBitmap )
997 HBITMAP oldBmp = (HBITMAP)SelectObject(hdcDraw, hBitmap);
999 if( (size.cx != width) || (size.cy != height) )
1001 // needs to scale canvas
1002 SetMapMode(hdcDraw, MM_ANISOTROPIC);
1003 SetWindowExtEx(hdcDraw, size.cx, size.cy, NULL);
1004 SetViewportExtEx(hdcDraw, width, height, NULL);
1007 onDraw(NULL, hdc, hdcDraw, &posRect, NULL);
1009 SetMapMode(hdcDraw, MM_TEXT);
1010 BitBlt(hdc, bounds.left, bounds.top,
1015 SelectObject(hdcDraw, oldBmp);
1016 DeleteObject(hBitmap);
1023 void VLCPlugin::onPositionChange(LPCRECT lprcPosRect, LPCRECT lprcClipRect)
1025 RECT clipRect = *lprcClipRect;
1026 RECT posRect = *lprcPosRect;
1028 //RedrawWindow(GetParent(_inplacewnd), &_posRect, NULL, RDW_INVALIDATE|RDW_ERASE|RDW_ALLCHILDREN);
1031 ** record keeping of control geometry within container
1036 ** convert posRect & clipRect to match control viewport coordinates
1038 getViewportCoords(&posRect, &clipRect);
1041 ** change in-place window geometry to match clipping region
1043 SetWindowPos(_inplacewnd, NULL,
1046 clipRect.right-clipRect.left,
1047 clipRect.bottom-clipRect.top,
1051 SWP_NOOWNERZORDER );
1054 ** change video window geometry to match object bounds within clipping region
1056 SetWindowPos(_videownd, NULL,
1059 posRect.right-posRect.left,
1060 posRect.bottom-posRect.top,
1064 SWP_NOOWNERZORDER );
1066 //RedrawWindow(_videownd, &posRect, NULL, RDW_INVALIDATE|RDW_ERASE|RDW_ALLCHILDREN);
1068 val.i_int = posRect.right-posRect.left;
1069 VLC_VariableSet(_i_vlc, "conf::width", val);
1070 val.i_int = posRect.bottom-posRect.top;
1071 VLC_VariableSet(_i_vlc, "conf::height", val);
1074 void VLCPlugin::freezeEvents(BOOL freeze)
1076 vlcConnectionPointContainer->freezeEvents(freeze);
1079 void VLCPlugin::firePropChangedEvent(DISPID dispid)
1081 vlcConnectionPointContainer->firePropChangedEvent(dispid);
1084 void VLCPlugin::fireOnPlayEvent(void)
1086 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1087 vlcConnectionPointContainer->fireEvent(DISPID_PlayEvent, &dispparamsNoArgs);
1090 void VLCPlugin::fireOnPauseEvent(void)
1092 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1093 vlcConnectionPointContainer->fireEvent(DISPID_PauseEvent, &dispparamsNoArgs);
1096 void VLCPlugin::fireOnStopEvent(void)
1098 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1099 vlcConnectionPointContainer->fireEvent(DISPID_StopEvent, &dispparamsNoArgs);