1 /*****************************************************************************
2 * plugin.cpp: ActiveX control for VLC
3 *****************************************************************************
4 * Copyright (C) 2006 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, REFCLSID rclsid) :
104 _p_class_ref(p_class_ref),
105 _hinstance(hInstance),
107 _inplace_picture(NULL)
111 if( ! GetClassInfo(hInstance, getInPlaceWndClassName(), &wClass) )
113 wClass.style = CS_NOCLOSE|CS_DBLCLKS;
114 wClass.lpfnWndProc = VLCInPlaceClassWndProc;
115 wClass.cbClsExtra = 0;
116 wClass.cbWndExtra = 0;
117 wClass.hInstance = hInstance;
119 wClass.hCursor = LoadCursor(NULL, IDC_ARROW);
120 wClass.hbrBackground = NULL;
121 wClass.lpszMenuName = NULL;
122 wClass.lpszClassName = getInPlaceWndClassName();
124 _inplace_wndclass_atom = RegisterClass(&wClass);
128 _inplace_wndclass_atom = 0;
131 if( ! GetClassInfo(hInstance, getVideoWndClassName(), &wClass) )
133 wClass.style = CS_NOCLOSE;
134 wClass.lpfnWndProc = VLCVideoClassWndProc;
135 wClass.cbClsExtra = 0;
136 wClass.cbWndExtra = 0;
137 wClass.hInstance = hInstance;
139 wClass.hCursor = LoadCursor(NULL, IDC_ARROW);
140 wClass.hbrBackground = NULL;
141 wClass.lpszMenuName = NULL;
142 wClass.lpszClassName = getVideoWndClassName();
144 _video_wndclass_atom = RegisterClass(&wClass);
148 _video_wndclass_atom = 0;
151 HBITMAP hbitmap = (HBITMAP)LoadImage(getHInstance(), TEXT("INPLACE-PICT"), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
152 if( NULL != hbitmap )
156 pictDesc.cbSizeofstruct = sizeof(PICTDESC);
157 pictDesc.picType = PICTYPE_BITMAP;
158 pictDesc.bmp.hbitmap = hbitmap;
159 pictDesc.bmp.hpal = NULL;
161 if( FAILED(OleCreatePictureIndirect(&pictDesc, IID_IPicture, TRUE, reinterpret_cast<LPVOID*>(&_inplace_picture))) )
162 _inplace_picture = NULL;
167 VLCPluginClass::~VLCPluginClass()
169 if( 0 != _inplace_wndclass_atom )
170 UnregisterClass(MAKEINTATOM(_inplace_wndclass_atom), _hinstance);
172 if( 0 != _video_wndclass_atom )
173 UnregisterClass(MAKEINTATOM(_video_wndclass_atom), _hinstance);
175 if( NULL != _inplace_picture )
176 _inplace_picture->Release();
179 STDMETHODIMP VLCPluginClass::QueryInterface(REFIID riid, void **ppv)
184 if( (IID_IUnknown == riid)
185 || (IID_IClassFactory == riid) )
188 *ppv = reinterpret_cast<LPVOID>(this);
195 return E_NOINTERFACE;
198 STDMETHODIMP_(ULONG) VLCPluginClass::AddRef(void)
200 return InterlockedIncrement(_p_class_ref);
203 STDMETHODIMP_(ULONG) VLCPluginClass::Release(void)
205 ULONG refcount = InterlockedDecrement(_p_class_ref);
214 STDMETHODIMP VLCPluginClass::CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, void **ppv)
221 if( (NULL != pUnkOuter) && (IID_IUnknown != riid) ) {
222 return CLASS_E_NOAGGREGATION;
225 VLCPlugin *plugin = new VLCPlugin(this, pUnkOuter);
228 HRESULT hr = plugin->QueryInterface(riid, ppv);
232 return E_OUTOFMEMORY;
235 STDMETHODIMP VLCPluginClass::LockServer(BOOL fLock)
245 ////////////////////////////////////////////////////////////////////////
247 VLCPlugin::VLCPlugin(VLCPluginClass *p_class, LPUNKNOWN pUnkOuter) :
258 vlcOleControl = new VLCOleControl(this);
259 vlcOleInPlaceObject = new VLCOleInPlaceObject(this);
260 vlcOleInPlaceActiveObject = new VLCOleInPlaceActiveObject(this);
261 vlcPersistStorage = new VLCPersistStorage(this);
262 vlcPersistStreamInit = new VLCPersistStreamInit(this);
263 vlcPersistPropertyBag = new VLCPersistPropertyBag(this);
264 vlcProvideClassInfo = new VLCProvideClassInfo(this);
265 vlcConnectionPointContainer = new VLCConnectionPointContainer(this);
266 vlcObjectSafety = new VLCObjectSafety(this);
267 vlcControl = new VLCControl(this);
268 vlcViewObject = new VLCViewObject(this);
269 vlcDataObject = new VLCDataObject(this);
270 vlcOleObject = new VLCOleObject(this);
272 // configure controlling IUnknown interface for implemented interfaces
273 this->pUnkOuter = (NULL != pUnkOuter) ? pUnkOuter : dynamic_cast<LPUNKNOWN>(this);
276 _p_pict = p_class->getInPlacePict();
278 // make sure that persistable properties are initialized
282 VLCPlugin::~VLCPlugin()
285 delete vlcDataObject;
286 delete vlcViewObject;
288 delete vlcConnectionPointContainer;
289 delete vlcProvideClassInfo;
290 delete vlcPersistPropertyBag;
291 delete vlcPersistStreamInit;
292 delete vlcPersistStorage;
293 delete vlcOleInPlaceActiveObject;
294 delete vlcOleInPlaceObject;
295 delete vlcObjectSafety;
297 delete vlcOleControl;
301 SysFreeString(_bstr_mrl);
306 STDMETHODIMP VLCPlugin::QueryInterface(REFIID riid, void **ppv)
311 if( IID_IUnknown == riid )
312 *ppv = reinterpret_cast<LPVOID>(this);
313 else if( IID_IOleObject == riid )
314 *ppv = reinterpret_cast<LPVOID>(vlcOleObject);
315 else if( IID_IOleControl == riid )
316 *ppv = reinterpret_cast<LPVOID>(vlcOleControl);
317 else if( IID_IOleWindow == riid )
318 *ppv = reinterpret_cast<LPVOID>(vlcOleInPlaceObject);
319 else if( IID_IOleInPlaceObject == riid )
320 *ppv = reinterpret_cast<LPVOID>(vlcOleInPlaceObject);
321 else if( IID_IOleInPlaceActiveObject == riid )
322 *ppv = reinterpret_cast<LPVOID>(vlcOleInPlaceActiveObject);
323 else if( IID_IPersist == riid )
324 *ppv = reinterpret_cast<LPVOID>(vlcPersistStreamInit);
325 else if( IID_IPersistStreamInit == riid )
326 *ppv = reinterpret_cast<LPVOID>(vlcPersistStreamInit);
327 else if( IID_IPersistStorage == riid )
328 *ppv = reinterpret_cast<LPVOID>(vlcPersistStorage);
329 else if( IID_IPersistPropertyBag == riid )
330 *ppv = reinterpret_cast<LPVOID>(vlcPersistPropertyBag);
331 else if( IID_IProvideClassInfo == riid )
332 *ppv = reinterpret_cast<LPVOID>(vlcProvideClassInfo);
333 else if( IID_IProvideClassInfo2 == riid )
334 *ppv = reinterpret_cast<LPVOID>(vlcProvideClassInfo);
335 else if( IID_IConnectionPointContainer == riid )
336 *ppv = reinterpret_cast<LPVOID>(vlcConnectionPointContainer);
337 else if( IID_IObjectSafety == riid )
338 *ppv = reinterpret_cast<LPVOID>(vlcObjectSafety);
339 else if( IID_IDispatch == riid )
340 *ppv = reinterpret_cast<LPVOID>(vlcControl);
341 else if( IID_IVLCControl == riid )
342 *ppv = reinterpret_cast<LPVOID>(vlcControl);
343 else if( IID_IVLCControl2 == riid )
344 *ppv = reinterpret_cast<LPVOID>(vlcControl2);
345 else if( IID_IViewObject == riid )
346 *ppv = reinterpret_cast<LPVOID>(vlcViewObject);
347 else if( IID_IViewObject2 == riid )
348 *ppv = reinterpret_cast<LPVOID>(vlcViewObject);
349 else if( IID_IDataObject == riid )
350 *ppv = reinterpret_cast<LPVOID>(vlcDataObject);
354 return E_NOINTERFACE;
356 ((LPUNKNOWN)*ppv)->AddRef();
360 STDMETHODIMP_(ULONG) VLCPlugin::AddRef(void)
362 return InterlockedIncrement((LONG *)&_i_ref);
365 STDMETHODIMP_(ULONG) VLCPlugin::Release(void)
367 if( ! InterlockedDecrement((LONG *)&_i_ref) )
375 //////////////////////////////////////
378 ** we use a window to represent plugin viewport,
379 ** whose geometry is limited by the clipping rectangle
380 ** all drawing within this window must follow must
381 ** follow coordinates system described in lprPosRect
384 static void getViewportCoords(LPRECT lprPosRect, LPRECT lprClipRect)
387 bounds.right = lprPosRect->right-lprPosRect->left;
389 if( lprClipRect->left <= lprPosRect->left )
391 // left side is not clipped out
394 if( lprClipRect->right >= lprPosRect->right )
396 // right side is not clipped out, no change
398 else if( lprClipRect->right >= lprPosRect->left )
400 // right side is clipped out
401 lprPosRect->right = lprClipRect->right;
405 // outside of clipping rectange, not visible
406 lprPosRect->right = lprPosRect->left;
411 // left side is clipped out
412 bounds.left = lprPosRect->left-lprClipRect->left;
413 bounds.right += bounds.left;
415 lprPosRect->left = lprClipRect->left;
416 if( lprClipRect->right >= lprPosRect->right )
418 // right side is not clipped out
422 // right side is clipped out
423 lprPosRect->right = lprClipRect->right;
427 bounds.bottom = lprPosRect->bottom-lprPosRect->top;
429 if( lprClipRect->top <= lprPosRect->top )
431 // top side is not clipped out
434 if( lprClipRect->bottom >= lprPosRect->bottom )
436 // bottom side is not clipped out, no change
438 else if( lprClipRect->bottom >= lprPosRect->top )
440 // bottom side is clipped out
441 lprPosRect->bottom = lprClipRect->bottom;
445 // outside of clipping rectange, not visible
446 lprPosRect->right = lprPosRect->left;
451 bounds.top = lprPosRect->top-lprClipRect->top;
452 bounds.bottom += bounds.top;
454 lprPosRect->top = lprClipRect->top;
455 if( lprClipRect->bottom >= lprPosRect->bottom )
457 // bottom side is not clipped out
461 // bottom side is clipped out
462 lprPosRect->bottom = lprClipRect->bottom;
465 *lprClipRect = *lprPosRect;
466 *lprPosRect = bounds;
469 HRESULT VLCPlugin::onInit(void)
471 if( NULL == _p_libvlc )
473 // initialize persistable properties
481 // set default/preferred size (320x240) pixels in HIMETRIC
482 HDC hDC = CreateDevDC(NULL);
485 HimetricFromDP(hDC, (LPPOINT)&_extent, 1);
490 return CO_E_ALREADYINITIALIZED;
493 HRESULT VLCPlugin::onLoad(void)
495 if( SysStringLen(_bstr_mrl) > 0 )
498 ** try to combine MRL with client site moniker, which for Internet Explorer
499 ** is the URL of the page the plugin is embedded into. Hence, if the MRL
500 ** is a relative URL, we should end up with an absolute URL
502 LPOLECLIENTSITE pClientSite;
503 if( SUCCEEDED(vlcOleObject->GetClientSite(&pClientSite)) && (NULL != pClientSite) )
506 if( SUCCEEDED(CreateBindCtx(0, &pBC)) )
508 LPMONIKER pContMoniker = NULL;
509 if( SUCCEEDED(pClientSite->GetMoniker(OLEGETMONIKER_ONLYIFTHERE,
510 OLEWHICHMK_CONTAINER, &pContMoniker)) )
513 if( SUCCEEDED(pContMoniker->GetDisplayName(pBC, NULL, &base_url)) )
516 ** check that the moniker name is a URL
518 if( UrlIsW(base_url, URLIS_URL) )
520 DWORD len = INTERNET_MAX_URL_LENGTH;
521 LPOLESTR abs_url = (LPOLESTR)CoTaskMemAlloc(sizeof(OLECHAR)*len);
522 if( NULL != abs_url )
524 if( SUCCEEDED(UrlCombineW(base_url, _bstr_mrl, abs_url, &len,
525 URL_ESCAPE_UNSAFE|URL_PLUGGABLE_PROTOCOL)) )
527 SysFreeString(_bstr_mrl);
528 _bstr_mrl = SysAllocStringLen(abs_url, len);
530 CoTaskMemFree(abs_url);
533 CoTaskMemFree(base_url);
535 pContMoniker->Release();
539 pClientSite->Release();
546 HRESULT VLCPlugin::getVLCObject(int* i_vlc)
548 libvlc_instance_t *p_libvlc;
549 HRESULT result = getVLC(&p_libvlc);
550 if( SUCCEEDED(result) )
552 *i_vlc = libvlc_get_vlc_id(p_libvlc);
561 HRESULT VLCPlugin::getVLC(libvlc_instance_t** pp_libvlc)
566 ** default initialization options
568 char *ppsz_argv[32] = { "vlc" };
572 DWORD i_type, i_data = MAX_PATH + 1;
573 char p_data[MAX_PATH + 1];
574 if( RegOpenKeyEx( HKEY_LOCAL_MACHINE, "Software\\VideoLAN\\VLC",
575 0, KEY_READ, &h_key ) == ERROR_SUCCESS )
577 if( RegQueryValueEx( h_key, "InstallDir", 0, &i_type,
578 (LPBYTE)p_data, &i_data ) == ERROR_SUCCESS )
580 if( i_type == REG_SZ )
582 strcat( p_data, "\\vlc" );
583 ppsz_argv[0] = p_data;
586 RegCloseKey( h_key );
590 //ppsz_argv[0] = "C:\\cygwin\\home\\Damien_Fouilleul\\dev\\videolan\\vlc-trunk\\vlc";
591 ppsz_argv[0] = "C:\\cygwin\\home\\damienf\\vlc-trunk\\vlc";
594 // make sure plugin isn't affected with VLC single instance mode
595 ppsz_argv[ppsz_argc++] = "--no-one-instance";
597 /* common settings */
598 ppsz_argv[ppsz_argc++] = "-vv";
599 ppsz_argv[ppsz_argc++] = "--no-stats";
600 ppsz_argv[ppsz_argc++] = "--no-media-library";
601 ppsz_argv[ppsz_argc++] = "--intf";
602 ppsz_argv[ppsz_argc++] = "dummy";
604 // loop mode is a configuration option only
606 ppsz_argv[ppsz_argc++] = "--loop";
608 // initial volume setting
610 ppsz_argv[ppsz_argc++] = "--volume";
613 ppsz_argv[ppsz_argc++] = "0";
617 snprintf(volBuffer, sizeof(volBuffer), "%d", _i_volume);
618 ppsz_argv[ppsz_argc++] = volBuffer;
621 if( IsDebuggerPresent() )
624 ** VLC default threading mechanism is designed to be as compatible
625 ** with POSIX as possible, however when debugged on win32, threads
626 ** lose signals and eventually VLC get stuck during initialization.
627 ** threading support can be configured to be more debugging friendly
628 ** but it will be less compatible with POSIX.
629 ** This is done by initializing with the following options
631 ppsz_argv[ppsz_argc++] = "--fast-mutex";
632 ppsz_argv[ppsz_argc++] = "--win9x-cv-method=1";
635 _p_libvlc = libvlc_new(ppsz_argc, ppsz_argv, NULL);
636 if( NULL == _p_libvlc )
642 char *psz_mrl = CStrFromBSTR(CP_UTF8, _bstr_mrl);
643 if( NULL != psz_mrl )
645 const char *options[1];
651 snprintf(timeBuffer, sizeof(timeBuffer), ":start-time=%d", _i_time);
652 options[i_options++] = timeBuffer;
654 // add default target to playlist
655 libvlc_playlist_add_extended(_p_libvlc, psz_mrl, NULL, i_options, options, NULL);
656 CoTaskMemFree(psz_mrl);
659 *pp_libvlc = _p_libvlc;
663 HRESULT VLCPlugin::onAmbientChanged(LPUNKNOWN pContainer, DISPID dispID)
668 case DISPID_AMBIENT_BACKCOLOR:
670 case DISPID_AMBIENT_DISPLAYNAME:
672 case DISPID_AMBIENT_FONT:
674 case DISPID_AMBIENT_FORECOLOR:
676 case DISPID_AMBIENT_LOCALEID:
678 case DISPID_AMBIENT_MESSAGEREFLECT:
680 case DISPID_AMBIENT_SCALEUNITS:
682 case DISPID_AMBIENT_TEXTALIGN:
684 case DISPID_AMBIENT_USERMODE:
687 if( SUCCEEDED(GetObjectProperty(pContainer, dispID, v)) )
689 setUserMode(V_BOOL(&v) != VARIANT_FALSE);
692 case DISPID_AMBIENT_UIDEAD:
694 case DISPID_AMBIENT_SHOWGRABHANDLES:
696 case DISPID_AMBIENT_SHOWHATCHING:
698 case DISPID_AMBIENT_DISPLAYASDEFAULT:
700 case DISPID_AMBIENT_SUPPORTSMNEMONICS:
702 case DISPID_AMBIENT_AUTOCLIP:
704 case DISPID_AMBIENT_APPEARANCE:
706 case DISPID_AMBIENT_CODEPAGE:
709 if( SUCCEEDED(GetObjectProperty(pContainer, dispID, v)) )
711 setCodePage(V_I4(&v));
714 case DISPID_AMBIENT_PALETTE:
716 case DISPID_AMBIENT_CHARSET:
718 case DISPID_AMBIENT_RIGHTTOLEFT:
720 case DISPID_AMBIENT_TOPTOBOTTOM:
724 ** multiple property change, look up the ones we are interested in
728 if( SUCCEEDED(GetObjectProperty(pContainer, DISPID_AMBIENT_USERMODE, v)) )
730 setUserMode(V_BOOL(&v) != VARIANT_FALSE);
734 if( SUCCEEDED(GetObjectProperty(pContainer, DISPID_AMBIENT_CODEPAGE, v)) )
736 setCodePage(V_I4(&v));
743 HRESULT VLCPlugin::onClose(DWORD dwSaveOption)
745 if( isInPlaceActive() )
747 onInPlaceDeactivate();
751 libvlc_instance_t* p_libvlc = _p_libvlc;
754 vlcDataObject->onClose();
756 libvlc_destroy(p_libvlc);
761 BOOL VLCPlugin::isInPlaceActive(void)
763 return (NULL != _inplacewnd);
766 HRESULT VLCPlugin::onActivateInPlace(LPMSG lpMesg, HWND hwndParent, LPCRECT lprcPosRect, LPCRECT lprcClipRect)
768 RECT posRect = *lprcPosRect;
769 RECT clipRect = *lprcClipRect;
772 ** record keeping of control geometry within container
777 ** convert posRect & clipRect to match control viewport coordinates
779 getViewportCoords(&posRect, &clipRect);
782 ** Create a window for in place activated control.
783 ** the window geometry matches the control viewport
784 ** within container so that embedded video is always
787 _inplacewnd = CreateWindow(_p_class->getInPlaceWndClassName(),
788 "VLC Plugin In-Place Window",
789 WS_CHILD|WS_CLIPCHILDREN|WS_CLIPSIBLINGS,
792 clipRect.right-clipRect.left,
793 clipRect.bottom-clipRect.top,
796 _p_class->getHInstance(),
800 if( NULL == _inplacewnd )
803 SetWindowLongPtr(_inplacewnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));
806 ** VLC embedded video automatically grows to cover client
807 ** area of parent window.
808 ** hence create a such a 'parent' window whose geometry
809 ** is always correct relative to the viewport bounds
811 _videownd = CreateWindow(_p_class->getVideoWndClassName(),
812 "VLC Plugin Video Window",
813 WS_CHILD|WS_CLIPCHILDREN|WS_VISIBLE,
816 posRect.right-posRect.left,
817 posRect.bottom-posRect.top,
820 _p_class->getHInstance(),
824 if( NULL == _videownd )
826 DestroyWindow(_inplacewnd);
830 SetWindowLongPtr(_videownd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));
834 /* will run vlc if not done already */
835 libvlc_instance_t* p_libvlc;
836 HRESULT result = getVLC(&p_libvlc);
840 /* set internal video width and height */
841 libvlc_video_set_size(p_libvlc,
842 posRect.right-posRect.left,
843 posRect.bottom-posRect.top,
846 /* set internal video parent window */
847 libvlc_video_set_parent(p_libvlc,
848 reinterpret_cast<libvlc_drawable_t>(_videownd), NULL);
850 if( _b_autoplay & (libvlc_playlist_items_count(p_libvlc, NULL) > 0) )
852 libvlc_playlist_play(p_libvlc, 0, 0, NULL, NULL);
858 ShowWindow(_inplacewnd, SW_SHOW);
863 HRESULT VLCPlugin::onInPlaceDeactivate(void)
867 libvlc_playlist_stop(_p_libvlc, NULL);
871 DestroyWindow(_videownd);
873 DestroyWindow(_inplacewnd);
879 void VLCPlugin::setVisible(BOOL fVisible)
881 if( fVisible != _b_visible )
883 _b_visible = fVisible;
884 if( isInPlaceActive() )
886 ShowWindow(_inplacewnd, fVisible ? SW_SHOW : SW_HIDE);
888 InvalidateRect(_videownd, NULL, TRUE);
891 firePropChangedEvent(DISPID_Visible);
895 void VLCPlugin::setVolume(int volume)
899 else if( volume > 200 )
902 if( volume != _i_volume )
907 libvlc_audio_set_volume(_p_libvlc, _i_volume, NULL);
913 void VLCPlugin::setTime(int seconds)
918 if( seconds != _i_time )
923 libvlc_input_t *p_input = libvlc_playlist_get_input(_p_libvlc, NULL);
924 if( NULL != p_input )
926 libvlc_input_set_time(p_input, _i_time, NULL);
927 libvlc_input_free(p_input);
934 void VLCPlugin::setFocus(BOOL fFocus)
937 SetActiveWindow(_inplacewnd);
940 BOOL VLCPlugin::hasFocus(void)
942 return GetActiveWindow() == _inplacewnd;
945 void VLCPlugin::onDraw(DVTARGETDEVICE * ptd, HDC hicTargetDev,
946 HDC hdcDraw, LPCRECTL lprcBounds, LPCRECTL lprcWBounds)
950 long width = lprcBounds->right-lprcBounds->left;
951 long height = lprcBounds->bottom-lprcBounds->top;
953 RECT bounds = { lprcBounds->left, lprcBounds->top, lprcBounds->right, lprcBounds->bottom };
954 FillRect(hdcDraw, &bounds, (HBRUSH)GetStockObject(WHITE_BRUSH));
956 LPPICTURE pict = getPicture();
959 OLE_XSIZE_HIMETRIC picWidth;
960 OLE_YSIZE_HIMETRIC picHeight;
962 pict->get_Width(&picWidth);
963 pict->get_Height(&picHeight);
965 SIZEL picSize = { picWidth, picHeight };
967 if( NULL != hicTargetDev )
969 DPFromHimetric(hicTargetDev, (LPPOINT)&picSize, 1);
971 else if( NULL != (hicTargetDev = CreateDevDC(ptd)) )
973 DPFromHimetric(hicTargetDev, (LPPOINT)&picSize, 1);
974 DeleteDC(hicTargetDev);
977 if( picSize.cx > width-4 )
978 picSize.cx = width-4;
979 if( picSize.cy > height-4 )
980 picSize.cy = height-4;
982 LONG dstX = lprcBounds->left+(width-picSize.cx)/2;
983 LONG dstY = lprcBounds->top+(height-picSize.cy)/2;
985 if( NULL != lprcWBounds )
987 RECT wBounds = { lprcWBounds->left, lprcWBounds->top, lprcWBounds->right, lprcWBounds->bottom };
988 pict->Render(hdcDraw, dstX, dstY, picSize.cx, picSize.cy,
989 0L, picHeight, picWidth, -picHeight, &wBounds);
992 pict->Render(hdcDraw, dstX, dstY, picSize.cx, picSize.cy,
993 0L, picHeight, picWidth, -picHeight, NULL);
998 SelectObject(hdcDraw, GetStockObject(BLACK_BRUSH));
1000 MoveToEx(hdcDraw, bounds.left, bounds.top, NULL);
1001 LineTo(hdcDraw, bounds.left+width-1, bounds.top);
1002 LineTo(hdcDraw, bounds.left+width-1, bounds.top+height-1);
1003 LineTo(hdcDraw, bounds.left, bounds.top+height-1);
1004 LineTo(hdcDraw, bounds.left, bounds.top);
1008 void VLCPlugin::onPaint(HDC hdc, const RECT &bounds, const RECT &clipRect)
1012 /** if VLC is playing, it may not display any VIDEO content
1013 ** hence, draw control logo*/
1014 HDC hdcDraw = CreateCompatibleDC(hdc);
1015 if( NULL != hdcDraw )
1017 SIZEL size = getExtent();
1018 DPFromHimetric(hdc, (LPPOINT)&size, 1);
1019 RECTL posRect = { 0, 0, size.cx, size.cy };
1021 int width = bounds.right-bounds.left;
1022 int height = bounds.bottom-bounds.top;
1024 HBITMAP hBitmap = CreateCompatibleBitmap(hdc, width, height);
1025 if( NULL != hBitmap )
1027 HBITMAP oldBmp = (HBITMAP)SelectObject(hdcDraw, hBitmap);
1029 if( (size.cx != width) || (size.cy != height) )
1031 // needs to scale canvas
1032 SetMapMode(hdcDraw, MM_ANISOTROPIC);
1033 SetWindowExtEx(hdcDraw, size.cx, size.cy, NULL);
1034 SetViewportExtEx(hdcDraw, width, height, NULL);
1037 onDraw(NULL, hdc, hdcDraw, &posRect, NULL);
1039 SetMapMode(hdcDraw, MM_TEXT);
1040 BitBlt(hdc, bounds.left, bounds.top,
1045 SelectObject(hdcDraw, oldBmp);
1046 DeleteObject(hBitmap);
1053 void VLCPlugin::onPositionChange(LPCRECT lprcPosRect, LPCRECT lprcClipRect)
1055 RECT clipRect = *lprcClipRect;
1056 RECT posRect = *lprcPosRect;
1058 //RedrawWindow(GetParent(_inplacewnd), &_posRect, NULL, RDW_INVALIDATE|RDW_ERASE|RDW_ALLCHILDREN);
1061 ** record keeping of control geometry within container
1066 ** convert posRect & clipRect to match control viewport coordinates
1068 getViewportCoords(&posRect, &clipRect);
1071 ** change in-place window geometry to match clipping region
1073 SetWindowPos(_inplacewnd, NULL,
1076 clipRect.right-clipRect.left,
1077 clipRect.bottom-clipRect.top,
1081 SWP_NOOWNERZORDER );
1084 ** change video window geometry to match object bounds within clipping region
1086 SetWindowPos(_videownd, NULL,
1089 posRect.right-posRect.left,
1090 posRect.bottom-posRect.top,
1094 SWP_NOOWNERZORDER );
1096 //RedrawWindow(_videownd, &posRect, NULL, RDW_INVALIDATE|RDW_ERASE|RDW_ALLCHILDREN);
1099 libvlc_video_set_size(_p_libvlc,
1100 posRect.right-posRect.left,
1101 posRect.bottom-posRect.top,
1106 void VLCPlugin::freezeEvents(BOOL freeze)
1108 vlcConnectionPointContainer->freezeEvents(freeze);
1111 void VLCPlugin::firePropChangedEvent(DISPID dispid)
1113 vlcConnectionPointContainer->firePropChangedEvent(dispid);
1116 void VLCPlugin::fireOnPlayEvent(void)
1118 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1119 vlcConnectionPointContainer->fireEvent(DISPID_PlayEvent, &dispparamsNoArgs);
1122 void VLCPlugin::fireOnPauseEvent(void)
1124 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1125 vlcConnectionPointContainer->fireEvent(DISPID_PauseEvent, &dispparamsNoArgs);
1128 void VLCPlugin::fireOnStopEvent(void)
1130 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1131 vlcConnectionPointContainer->fireEvent(DISPID_StopEvent, &dispparamsNoArgs);