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 "vlccontrol2.h"
37 #include "viewobject.h"
38 #include "dataobject.h"
51 ////////////////////////////////////////////////////////////////////////
54 static LRESULT CALLBACK VLCInPlaceClassWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
62 if( GetUpdateRect(hWnd, NULL, FALSE) )
64 BeginPaint(hWnd, &ps);
70 return DefWindowProc(hWnd, uMsg, wParam, lParam);
74 static LRESULT CALLBACK VLCVideoClassWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
75 VLCPlugin *p_instance = reinterpret_cast<VLCPlugin *>(GetWindowLongPtr(hWnd, GWLP_USERDATA));
85 if( GetUpdateRect(hWnd, &pr, FALSE) )
88 GetClientRect(hWnd, &bounds);
89 BeginPaint(hWnd, &ps);
90 p_instance->onPaint(ps.hdc, bounds, pr);
96 return DefWindowProc(hWnd, uMsg, wParam, lParam);
100 VLCPluginClass::VLCPluginClass(LONG *p_class_ref, HINSTANCE hInstance, REFCLSID rclsid) :
101 _p_class_ref(p_class_ref),
102 _hinstance(hInstance),
104 _inplace_picture(NULL)
108 if( ! GetClassInfo(hInstance, getInPlaceWndClassName(), &wClass) )
110 wClass.style = CS_NOCLOSE|CS_DBLCLKS;
111 wClass.lpfnWndProc = VLCInPlaceClassWndProc;
112 wClass.cbClsExtra = 0;
113 wClass.cbWndExtra = 0;
114 wClass.hInstance = hInstance;
116 wClass.hCursor = LoadCursor(NULL, IDC_ARROW);
117 wClass.hbrBackground = NULL;
118 wClass.lpszMenuName = NULL;
119 wClass.lpszClassName = getInPlaceWndClassName();
121 _inplace_wndclass_atom = RegisterClass(&wClass);
125 _inplace_wndclass_atom = 0;
128 if( ! GetClassInfo(hInstance, getVideoWndClassName(), &wClass) )
130 wClass.style = CS_NOCLOSE;
131 wClass.lpfnWndProc = VLCVideoClassWndProc;
132 wClass.cbClsExtra = 0;
133 wClass.cbWndExtra = 0;
134 wClass.hInstance = hInstance;
136 wClass.hCursor = LoadCursor(NULL, IDC_ARROW);
137 wClass.hbrBackground = NULL;
138 wClass.lpszMenuName = NULL;
139 wClass.lpszClassName = getVideoWndClassName();
141 _video_wndclass_atom = RegisterClass(&wClass);
145 _video_wndclass_atom = 0;
148 HBITMAP hbitmap = (HBITMAP)LoadImage(getHInstance(), TEXT("INPLACE-PICT"), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
149 if( NULL != hbitmap )
153 pictDesc.cbSizeofstruct = sizeof(PICTDESC);
154 pictDesc.picType = PICTYPE_BITMAP;
155 pictDesc.bmp.hbitmap = hbitmap;
156 pictDesc.bmp.hpal = NULL;
158 if( FAILED(OleCreatePictureIndirect(&pictDesc, IID_IPicture, TRUE, reinterpret_cast<LPVOID*>(&_inplace_picture))) )
159 _inplace_picture = NULL;
164 VLCPluginClass::~VLCPluginClass()
166 if( 0 != _inplace_wndclass_atom )
167 UnregisterClass(MAKEINTATOM(_inplace_wndclass_atom), _hinstance);
169 if( 0 != _video_wndclass_atom )
170 UnregisterClass(MAKEINTATOM(_video_wndclass_atom), _hinstance);
172 if( NULL != _inplace_picture )
173 _inplace_picture->Release();
176 STDMETHODIMP VLCPluginClass::QueryInterface(REFIID riid, void **ppv)
181 if( (IID_IUnknown == riid)
182 || (IID_IClassFactory == riid) )
185 *ppv = reinterpret_cast<LPVOID>(this);
192 return E_NOINTERFACE;
195 STDMETHODIMP_(ULONG) VLCPluginClass::AddRef(void)
197 return InterlockedIncrement(_p_class_ref);
200 STDMETHODIMP_(ULONG) VLCPluginClass::Release(void)
202 ULONG refcount = InterlockedDecrement(_p_class_ref);
211 STDMETHODIMP VLCPluginClass::CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, void **ppv)
218 if( (NULL != pUnkOuter) && (IID_IUnknown != riid) ) {
219 return CLASS_E_NOAGGREGATION;
222 VLCPlugin *plugin = new VLCPlugin(this, pUnkOuter);
225 HRESULT hr = plugin->QueryInterface(riid, ppv);
226 // the following will destroy the object if QueryInterface() failed
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 vlcControl2 = new VLCControl2(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;
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 = (CLSID_VLCPlugin2 == getClassID()) ?
341 reinterpret_cast<LPVOID>(vlcControl2) :
342 reinterpret_cast<LPVOID>(vlcControl);
343 else if( IID_IVLCControl == riid )
344 *ppv = reinterpret_cast<LPVOID>(vlcControl);
345 else if( IID_IVLCControl2 == riid )
346 *ppv = reinterpret_cast<LPVOID>(vlcControl2);
347 else if( IID_IViewObject == riid )
348 *ppv = reinterpret_cast<LPVOID>(vlcViewObject);
349 else if( IID_IViewObject2 == riid )
350 *ppv = reinterpret_cast<LPVOID>(vlcViewObject);
351 else if( IID_IDataObject == riid )
352 *ppv = reinterpret_cast<LPVOID>(vlcDataObject);
356 return E_NOINTERFACE;
358 ((LPUNKNOWN)*ppv)->AddRef();
362 STDMETHODIMP_(ULONG) VLCPlugin::AddRef(void)
364 return InterlockedIncrement((LONG *)&_i_ref);
367 STDMETHODIMP_(ULONG) VLCPlugin::Release(void)
369 if( ! InterlockedDecrement((LONG *)&_i_ref) )
377 //////////////////////////////////////
380 ** we use a window to represent plugin viewport,
381 ** whose geometry is limited by the clipping rectangle
382 ** all drawing within this window must follow must
383 ** follow coordinates system described in lprPosRect
386 static void getViewportCoords(LPRECT lprPosRect, LPRECT lprClipRect)
389 bounds.right = lprPosRect->right-lprPosRect->left;
391 if( lprClipRect->left <= lprPosRect->left )
393 // left side is not clipped out
396 if( lprClipRect->right >= lprPosRect->right )
398 // right side is not clipped out, no change
400 else if( lprClipRect->right >= lprPosRect->left )
402 // right side is clipped out
403 lprPosRect->right = lprClipRect->right;
407 // outside of clipping rectange, not visible
408 lprPosRect->right = lprPosRect->left;
413 // left side is clipped out
414 bounds.left = lprPosRect->left-lprClipRect->left;
415 bounds.right += bounds.left;
417 lprPosRect->left = lprClipRect->left;
418 if( lprClipRect->right >= lprPosRect->right )
420 // right side is not clipped out
424 // right side is clipped out
425 lprPosRect->right = lprClipRect->right;
429 bounds.bottom = lprPosRect->bottom-lprPosRect->top;
431 if( lprClipRect->top <= lprPosRect->top )
433 // top side is not clipped out
436 if( lprClipRect->bottom >= lprPosRect->bottom )
438 // bottom side is not clipped out, no change
440 else if( lprClipRect->bottom >= lprPosRect->top )
442 // bottom side is clipped out
443 lprPosRect->bottom = lprClipRect->bottom;
447 // outside of clipping rectange, not visible
448 lprPosRect->right = lprPosRect->left;
453 bounds.top = lprPosRect->top-lprClipRect->top;
454 bounds.bottom += bounds.top;
456 lprPosRect->top = lprClipRect->top;
457 if( lprClipRect->bottom >= lprPosRect->bottom )
459 // bottom side is not clipped out
463 // bottom side is clipped out
464 lprPosRect->bottom = lprClipRect->bottom;
467 *lprClipRect = *lprPosRect;
468 *lprPosRect = bounds;
471 HRESULT VLCPlugin::onInit(void)
473 if( NULL == _p_libvlc )
475 // initialize persistable properties
478 _bstr_baseurl = NULL;
484 // set default/preferred size (320x240) pixels in HIMETRIC
485 HDC hDC = CreateDevDC(NULL);
488 HimetricFromDP(hDC, (LPPOINT)&_extent, 1);
493 return CO_E_ALREADYINITIALIZED;
496 HRESULT VLCPlugin::onLoad(void)
498 if( SysStringLen(_bstr_baseurl) == 0 )
501 ** try to retreive the base URL using the client site moniker, which for Internet Explorer
502 ** is the URL of the page the plugin is embedded into.
504 LPOLECLIENTSITE pClientSite;
505 if( SUCCEEDED(vlcOleObject->GetClientSite(&pClientSite)) && (NULL != pClientSite) )
508 if( SUCCEEDED(CreateBindCtx(0, &pBC)) )
510 LPMONIKER pContMoniker = NULL;
511 if( SUCCEEDED(pClientSite->GetMoniker(OLEGETMONIKER_ONLYIFTHERE,
512 OLEWHICHMK_CONTAINER, &pContMoniker)) )
515 if( SUCCEEDED(pContMoniker->GetDisplayName(pBC, NULL, &base_url)) )
518 ** check that the moniker name is a URL
520 if( UrlIsW(base_url, URLIS_URL) )
523 _bstr_mrl = SysAllocString(base_url);
525 CoTaskMemFree(base_url);
535 HRESULT VLCPlugin::getVLCObject(int* i_vlc)
537 libvlc_instance_t *p_libvlc;
538 HRESULT result = getVLC(&p_libvlc);
539 if( SUCCEEDED(result) )
541 *i_vlc = libvlc_get_vlc_id(p_libvlc);
550 HRESULT VLCPlugin::getVLC(libvlc_instance_t** pp_libvlc)
555 ** default initialization options
557 char *ppsz_argv[32] = { "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\\damienf\\vlc-trunk\\vlc";
582 // make sure plugin isn't affected with VLC single instance mode
583 ppsz_argv[ppsz_argc++] = "--no-one-instance";
585 /* common settings */
586 ppsz_argv[ppsz_argc++] = "-vv";
587 ppsz_argv[ppsz_argc++] = "--no-stats";
588 ppsz_argv[ppsz_argc++] = "--no-media-library";
589 ppsz_argv[ppsz_argc++] = "--intf";
590 ppsz_argv[ppsz_argc++] = "dummy";
592 // loop mode is a configuration option only
594 ppsz_argv[ppsz_argc++] = "--loop";
596 // initial volume setting
598 ppsz_argv[ppsz_argc++] = "--volume";
601 ppsz_argv[ppsz_argc++] = "0";
605 snprintf(volBuffer, sizeof(volBuffer), "%d", _i_volume);
606 ppsz_argv[ppsz_argc++] = volBuffer;
609 if( IsDebuggerPresent() )
612 ** VLC default threading mechanism is designed to be as compatible
613 ** with POSIX as possible. However when debugged on win32, threads
614 ** lose signals and eventually VLC get stuck during initialization.
615 ** threading support can be configured to be more debugging friendly
616 ** but it will be less compatible with POSIX.
617 ** This is done by initializing with the following options:
619 ppsz_argv[ppsz_argc++] = "--fast-mutex";
620 ppsz_argv[ppsz_argc++] = "--win9x-cv-method=1";
623 _p_libvlc = libvlc_new(ppsz_argc, ppsz_argv, NULL);
624 if( NULL == _p_libvlc )
630 if( SysStringLen(_bstr_mrl) > 0 )
632 char *psz_mrl = NULL;
633 DWORD len = INTERNET_MAX_URL_LENGTH;
634 LPOLESTR abs_url = (LPOLESTR)CoTaskMemAlloc(sizeof(OLECHAR)*len);
635 if( NULL != abs_url )
638 ** if the MRL a relative URL, we should end up with an absolute URL
640 if( SUCCEEDED(UrlCombineW(_bstr_baseurl, _bstr_mrl, abs_url, &len,
641 URL_ESCAPE_UNSAFE|URL_PLUGGABLE_PROTOCOL)) )
643 psz_mrl = CStrFromBSTR(CP_UTF8, abs_url);
647 psz_mrl = CStrFromBSTR(CP_UTF8, _bstr_mrl);
649 CoTaskMemFree(abs_url);
651 if( NULL != psz_mrl )
653 const char *options[1];
659 snprintf(timeBuffer, sizeof(timeBuffer), ":start-time=%d", _i_time);
660 options[i_options++] = timeBuffer;
662 // add default target to playlist
663 libvlc_playlist_add_extended(_p_libvlc, psz_mrl, NULL, i_options, options, NULL);
664 CoTaskMemFree(psz_mrl);
668 *pp_libvlc = _p_libvlc;
672 HRESULT VLCPlugin::onAmbientChanged(LPUNKNOWN pContainer, DISPID dispID)
677 case DISPID_AMBIENT_BACKCOLOR:
679 case DISPID_AMBIENT_DISPLAYNAME:
681 case DISPID_AMBIENT_FONT:
683 case DISPID_AMBIENT_FORECOLOR:
685 case DISPID_AMBIENT_LOCALEID:
687 case DISPID_AMBIENT_MESSAGEREFLECT:
689 case DISPID_AMBIENT_SCALEUNITS:
691 case DISPID_AMBIENT_TEXTALIGN:
693 case DISPID_AMBIENT_USERMODE:
696 if( SUCCEEDED(GetObjectProperty(pContainer, dispID, v)) )
698 setUserMode(V_BOOL(&v) != VARIANT_FALSE);
701 case DISPID_AMBIENT_UIDEAD:
703 case DISPID_AMBIENT_SHOWGRABHANDLES:
705 case DISPID_AMBIENT_SHOWHATCHING:
707 case DISPID_AMBIENT_DISPLAYASDEFAULT:
709 case DISPID_AMBIENT_SUPPORTSMNEMONICS:
711 case DISPID_AMBIENT_AUTOCLIP:
713 case DISPID_AMBIENT_APPEARANCE:
715 case DISPID_AMBIENT_CODEPAGE:
718 if( SUCCEEDED(GetObjectProperty(pContainer, dispID, v)) )
720 setCodePage(V_I4(&v));
723 case DISPID_AMBIENT_PALETTE:
725 case DISPID_AMBIENT_CHARSET:
727 case DISPID_AMBIENT_RIGHTTOLEFT:
729 case DISPID_AMBIENT_TOPTOBOTTOM:
733 ** multiple property change, look up the ones we are interested in
737 if( SUCCEEDED(GetObjectProperty(pContainer, DISPID_AMBIENT_USERMODE, v)) )
739 setUserMode(V_BOOL(&v) != VARIANT_FALSE);
743 if( SUCCEEDED(GetObjectProperty(pContainer, DISPID_AMBIENT_CODEPAGE, v)) )
745 setCodePage(V_I4(&v));
752 HRESULT VLCPlugin::onClose(DWORD dwSaveOption)
754 if( isInPlaceActive() )
756 onInPlaceDeactivate();
760 libvlc_instance_t* p_libvlc = _p_libvlc;
763 vlcDataObject->onClose();
765 libvlc_destroy(p_libvlc, NULL );
770 BOOL VLCPlugin::isInPlaceActive(void)
772 return (NULL != _inplacewnd);
775 HRESULT VLCPlugin::onActivateInPlace(LPMSG lpMesg, HWND hwndParent, LPCRECT lprcPosRect, LPCRECT lprcClipRect)
777 RECT posRect = *lprcPosRect;
778 RECT clipRect = *lprcClipRect;
781 ** record keeping of control geometry within container
786 ** convert posRect & clipRect to match control viewport coordinates
788 getViewportCoords(&posRect, &clipRect);
791 ** Create a window for in place activated control.
792 ** the window geometry matches the control viewport
793 ** within container so that embedded video is always
796 _inplacewnd = CreateWindow(_p_class->getInPlaceWndClassName(),
797 "VLC Plugin In-Place Window",
798 WS_CHILD|WS_CLIPCHILDREN|WS_CLIPSIBLINGS,
801 clipRect.right-clipRect.left,
802 clipRect.bottom-clipRect.top,
805 _p_class->getHInstance(),
809 if( NULL == _inplacewnd )
812 SetWindowLongPtr(_inplacewnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));
815 ** VLC embedded video automatically grows to cover client
816 ** area of parent window.
817 ** hence create a such a 'parent' window whose geometry
818 ** is always correct relative to the viewport bounds
820 _videownd = CreateWindow(_p_class->getVideoWndClassName(),
821 "VLC Plugin Video Window",
822 WS_CHILD|WS_CLIPCHILDREN|WS_VISIBLE,
825 posRect.right-posRect.left,
826 posRect.bottom-posRect.top,
829 _p_class->getHInstance(),
833 if( NULL == _videownd )
835 DestroyWindow(_inplacewnd);
839 SetWindowLongPtr(_videownd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));
843 /* will run vlc if not done already */
844 libvlc_instance_t* p_libvlc;
845 HRESULT result = getVLC(&p_libvlc);
849 /* set internal video width and height */
850 libvlc_video_set_size(p_libvlc,
851 posRect.right-posRect.left,
852 posRect.bottom-posRect.top,
855 /* set internal video parent window */
856 libvlc_video_set_parent(p_libvlc,
857 reinterpret_cast<libvlc_drawable_t>(_videownd), NULL);
859 if( _b_autoplay & (libvlc_playlist_items_count(p_libvlc, NULL) > 0) )
861 libvlc_playlist_play(p_libvlc, 0, 0, NULL, NULL);
867 ShowWindow(_inplacewnd, SW_SHOW);
872 HRESULT VLCPlugin::onInPlaceDeactivate(void)
876 libvlc_playlist_stop(_p_libvlc, NULL);
880 DestroyWindow(_videownd);
882 DestroyWindow(_inplacewnd);
888 void VLCPlugin::setVisible(BOOL fVisible)
890 if( fVisible != _b_visible )
892 _b_visible = fVisible;
893 if( isInPlaceActive() )
895 ShowWindow(_inplacewnd, fVisible ? SW_SHOW : SW_HIDE);
897 InvalidateRect(_videownd, NULL, TRUE);
900 firePropChangedEvent(DISPID_Visible);
904 void VLCPlugin::setVolume(int volume)
908 else if( volume > 200 )
911 if( volume != _i_volume )
916 libvlc_audio_set_volume(_p_libvlc, _i_volume, NULL);
922 void VLCPlugin::setTime(int seconds)
927 if( seconds != _i_time )
929 setStartTime(_i_time);
932 libvlc_input_t *p_input = libvlc_playlist_get_input(_p_libvlc, NULL);
933 if( NULL != p_input )
935 libvlc_input_set_time(p_input, _i_time, NULL);
936 libvlc_input_free(p_input);
942 void VLCPlugin::setFocus(BOOL fFocus)
945 SetActiveWindow(_inplacewnd);
948 BOOL VLCPlugin::hasFocus(void)
950 return GetActiveWindow() == _inplacewnd;
953 void VLCPlugin::onDraw(DVTARGETDEVICE * ptd, HDC hicTargetDev,
954 HDC hdcDraw, LPCRECTL lprcBounds, LPCRECTL lprcWBounds)
958 long width = lprcBounds->right-lprcBounds->left;
959 long height = lprcBounds->bottom-lprcBounds->top;
961 RECT bounds = { lprcBounds->left, lprcBounds->top, lprcBounds->right, lprcBounds->bottom };
962 FillRect(hdcDraw, &bounds, (HBRUSH)GetStockObject(WHITE_BRUSH));
964 LPPICTURE pict = getPicture();
967 OLE_XSIZE_HIMETRIC picWidth;
968 OLE_YSIZE_HIMETRIC picHeight;
970 pict->get_Width(&picWidth);
971 pict->get_Height(&picHeight);
973 SIZEL picSize = { picWidth, picHeight };
975 if( NULL != hicTargetDev )
977 DPFromHimetric(hicTargetDev, (LPPOINT)&picSize, 1);
979 else if( NULL != (hicTargetDev = CreateDevDC(ptd)) )
981 DPFromHimetric(hicTargetDev, (LPPOINT)&picSize, 1);
982 DeleteDC(hicTargetDev);
985 if( picSize.cx > width-4 )
986 picSize.cx = width-4;
987 if( picSize.cy > height-4 )
988 picSize.cy = height-4;
990 LONG dstX = lprcBounds->left+(width-picSize.cx)/2;
991 LONG dstY = lprcBounds->top+(height-picSize.cy)/2;
993 if( NULL != lprcWBounds )
995 RECT wBounds = { lprcWBounds->left, lprcWBounds->top, lprcWBounds->right, lprcWBounds->bottom };
996 pict->Render(hdcDraw, dstX, dstY, picSize.cx, picSize.cy,
997 0L, picHeight, picWidth, -picHeight, &wBounds);
1000 pict->Render(hdcDraw, dstX, dstY, picSize.cx, picSize.cy,
1001 0L, picHeight, picWidth, -picHeight, NULL);
1006 SelectObject(hdcDraw, GetStockObject(BLACK_BRUSH));
1008 MoveToEx(hdcDraw, bounds.left, bounds.top, NULL);
1009 LineTo(hdcDraw, bounds.left+width-1, bounds.top);
1010 LineTo(hdcDraw, bounds.left+width-1, bounds.top+height-1);
1011 LineTo(hdcDraw, bounds.left, bounds.top+height-1);
1012 LineTo(hdcDraw, bounds.left, bounds.top);
1016 void VLCPlugin::onPaint(HDC hdc, const RECT &bounds, const RECT &clipRect)
1020 /** if VLC is playing, it may not display any VIDEO content
1021 ** hence, draw control logo*/
1022 HDC hdcDraw = CreateCompatibleDC(hdc);
1023 if( NULL != hdcDraw )
1025 SIZEL size = getExtent();
1026 DPFromHimetric(hdc, (LPPOINT)&size, 1);
1027 RECTL posRect = { 0, 0, size.cx, size.cy };
1029 int width = bounds.right-bounds.left;
1030 int height = bounds.bottom-bounds.top;
1032 HBITMAP hBitmap = CreateCompatibleBitmap(hdc, width, height);
1033 if( NULL != hBitmap )
1035 HBITMAP oldBmp = (HBITMAP)SelectObject(hdcDraw, hBitmap);
1037 if( (size.cx != width) || (size.cy != height) )
1039 // needs to scale canvas
1040 SetMapMode(hdcDraw, MM_ANISOTROPIC);
1041 SetWindowExtEx(hdcDraw, size.cx, size.cy, NULL);
1042 SetViewportExtEx(hdcDraw, width, height, NULL);
1045 onDraw(NULL, hdc, hdcDraw, &posRect, NULL);
1047 SetMapMode(hdcDraw, MM_TEXT);
1048 BitBlt(hdc, bounds.left, bounds.top,
1053 SelectObject(hdcDraw, oldBmp);
1054 DeleteObject(hBitmap);
1061 void VLCPlugin::onPositionChange(LPCRECT lprcPosRect, LPCRECT lprcClipRect)
1063 RECT clipRect = *lprcClipRect;
1064 RECT posRect = *lprcPosRect;
1066 //RedrawWindow(GetParent(_inplacewnd), &_posRect, NULL, RDW_INVALIDATE|RDW_ERASE|RDW_ALLCHILDREN);
1069 ** record keeping of control geometry within container
1074 ** convert posRect & clipRect to match control viewport coordinates
1076 getViewportCoords(&posRect, &clipRect);
1079 ** change in-place window geometry to match clipping region
1081 SetWindowPos(_inplacewnd, NULL,
1084 clipRect.right-clipRect.left,
1085 clipRect.bottom-clipRect.top,
1089 SWP_NOOWNERZORDER );
1092 ** change video window geometry to match object bounds within clipping region
1094 SetWindowPos(_videownd, NULL,
1097 posRect.right-posRect.left,
1098 posRect.bottom-posRect.top,
1102 SWP_NOOWNERZORDER );
1104 //RedrawWindow(_videownd, &posRect, NULL, RDW_INVALIDATE|RDW_ERASE|RDW_ALLCHILDREN);
1107 libvlc_video_set_size(_p_libvlc,
1108 posRect.right-posRect.left,
1109 posRect.bottom-posRect.top,
1114 void VLCPlugin::freezeEvents(BOOL freeze)
1116 vlcConnectionPointContainer->freezeEvents(freeze);
1119 void VLCPlugin::firePropChangedEvent(DISPID dispid)
1121 vlcConnectionPointContainer->firePropChangedEvent(dispid);
1124 void VLCPlugin::fireOnPlayEvent(void)
1126 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1127 vlcConnectionPointContainer->fireEvent(DISPID_PlayEvent, &dispparamsNoArgs);
1130 void VLCPlugin::fireOnPauseEvent(void)
1132 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1133 vlcConnectionPointContainer->fireEvent(DISPID_PauseEvent, &dispparamsNoArgs);
1136 void VLCPlugin::fireOnStopEvent(void)
1138 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1139 vlcConnectionPointContainer->fireEvent(DISPID_StopEvent, &dispparamsNoArgs);