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_baseurl = 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)
552 extern HMODULE DllGetModule();
557 ** default initialization options
559 char *ppsz_argv[32] = { "vlc" };
563 DWORD i_type, i_data = MAX_PATH + 1;
564 char p_data[MAX_PATH + 1];
565 if( RegOpenKeyEx( HKEY_LOCAL_MACHINE, "Software\\VideoLAN\\VLC",
566 0, KEY_READ, &h_key ) == ERROR_SUCCESS )
568 if( RegQueryValueEx( h_key, "InstallDir", 0, &i_type,
569 (LPBYTE)p_data, &i_data ) == ERROR_SUCCESS )
571 if( i_type == REG_SZ )
573 strcat( p_data, "\\plugins" );
574 ppsz_argv[ppsz_argc++] = "--plugin-path";
575 ppsz_argv[ppsz_argc++] = p_data;
578 RegCloseKey( h_key );
581 char p_path[MAX_PATH+1];
582 DWORD len = GetModuleFileNameA(DllGetModule(), p_path, sizeof(p_path));
586 ppsz_argv[0] = p_path;
589 // make sure plugin isn't affected with VLC single instance mode
590 ppsz_argv[ppsz_argc++] = "--no-one-instance";
592 /* common settings */
593 ppsz_argv[ppsz_argc++] = "-vv";
594 ppsz_argv[ppsz_argc++] = "--no-stats";
595 ppsz_argv[ppsz_argc++] = "--no-media-library";
596 ppsz_argv[ppsz_argc++] = "--intf";
597 ppsz_argv[ppsz_argc++] = "dummy";
599 // loop mode is a configuration option only
601 ppsz_argv[ppsz_argc++] = "--loop";
603 // initial volume setting
605 ppsz_argv[ppsz_argc++] = "--volume";
608 ppsz_argv[ppsz_argc++] = "0";
612 snprintf(volBuffer, sizeof(volBuffer), "%d", _i_volume);
613 ppsz_argv[ppsz_argc++] = volBuffer;
616 if( IsDebuggerPresent() )
619 ** VLC default threading mechanism is designed to be as compatible
620 ** with POSIX as possible. However when debugged on win32, threads
621 ** lose signals and eventually VLC get stuck during initialization.
622 ** threading support can be configured to be more debugging friendly
623 ** but it will be less compatible with POSIX.
624 ** This is done by initializing with the following options:
626 ppsz_argv[ppsz_argc++] = "--fast-mutex";
627 ppsz_argv[ppsz_argc++] = "--win9x-cv-method=1";
630 _p_libvlc = libvlc_new(ppsz_argc, ppsz_argv, NULL);
631 if( NULL == _p_libvlc )
637 if( SysStringLen(_bstr_mrl) > 0 )
639 char *psz_mrl = NULL;
641 if( SysStringLen(_bstr_baseurl) > 0 )
643 DWORD len = INTERNET_MAX_URL_LENGTH;
644 LPOLESTR abs_url = (LPOLESTR)CoTaskMemAlloc(sizeof(OLECHAR)*len);
645 if( NULL != abs_url )
648 ** if the MRL a relative URL, we should end up with an absolute URL
650 if( SUCCEEDED(UrlCombineW(_bstr_baseurl, _bstr_mrl, abs_url, &len,
651 URL_ESCAPE_UNSAFE|URL_PLUGGABLE_PROTOCOL)) )
653 psz_mrl = CStrFromBSTR(CP_UTF8, abs_url);
657 psz_mrl = CStrFromBSTR(CP_UTF8, _bstr_mrl);
659 CoTaskMemFree(abs_url);
665 ** baseURL is empty, assume MRL is absolute
667 psz_mrl = CStrFromBSTR(CP_UTF8, _bstr_mrl);
669 if( NULL != psz_mrl )
671 const char *options[1];
677 snprintf(timeBuffer, sizeof(timeBuffer), ":start-time=%d", _i_time);
678 options[i_options++] = timeBuffer;
680 // add default target to playlist
681 libvlc_playlist_add_extended(_p_libvlc, psz_mrl, NULL, i_options, options, NULL);
682 CoTaskMemFree(psz_mrl);
686 *pp_libvlc = _p_libvlc;
690 HRESULT VLCPlugin::onAmbientChanged(LPUNKNOWN pContainer, DISPID dispID)
695 case DISPID_AMBIENT_BACKCOLOR:
697 case DISPID_AMBIENT_DISPLAYNAME:
699 case DISPID_AMBIENT_FONT:
701 case DISPID_AMBIENT_FORECOLOR:
703 case DISPID_AMBIENT_LOCALEID:
705 case DISPID_AMBIENT_MESSAGEREFLECT:
707 case DISPID_AMBIENT_SCALEUNITS:
709 case DISPID_AMBIENT_TEXTALIGN:
711 case DISPID_AMBIENT_USERMODE:
714 if( SUCCEEDED(GetObjectProperty(pContainer, dispID, v)) )
716 setUserMode(V_BOOL(&v) != VARIANT_FALSE);
719 case DISPID_AMBIENT_UIDEAD:
721 case DISPID_AMBIENT_SHOWGRABHANDLES:
723 case DISPID_AMBIENT_SHOWHATCHING:
725 case DISPID_AMBIENT_DISPLAYASDEFAULT:
727 case DISPID_AMBIENT_SUPPORTSMNEMONICS:
729 case DISPID_AMBIENT_AUTOCLIP:
731 case DISPID_AMBIENT_APPEARANCE:
733 case DISPID_AMBIENT_CODEPAGE:
736 if( SUCCEEDED(GetObjectProperty(pContainer, dispID, v)) )
738 setCodePage(V_I4(&v));
741 case DISPID_AMBIENT_PALETTE:
743 case DISPID_AMBIENT_CHARSET:
745 case DISPID_AMBIENT_RIGHTTOLEFT:
747 case DISPID_AMBIENT_TOPTOBOTTOM:
751 ** multiple property change, look up the ones we are interested in
755 if( SUCCEEDED(GetObjectProperty(pContainer, DISPID_AMBIENT_USERMODE, v)) )
757 setUserMode(V_BOOL(&v) != VARIANT_FALSE);
761 if( SUCCEEDED(GetObjectProperty(pContainer, DISPID_AMBIENT_CODEPAGE, v)) )
763 setCodePage(V_I4(&v));
770 HRESULT VLCPlugin::onClose(DWORD dwSaveOption)
772 if( isInPlaceActive() )
774 onInPlaceDeactivate();
778 libvlc_instance_t* p_libvlc = _p_libvlc;
781 vlcDataObject->onClose();
783 libvlc_destroy(p_libvlc, NULL );
788 BOOL VLCPlugin::isInPlaceActive(void)
790 return (NULL != _inplacewnd);
793 HRESULT VLCPlugin::onActivateInPlace(LPMSG lpMesg, HWND hwndParent, LPCRECT lprcPosRect, LPCRECT lprcClipRect)
795 RECT posRect = *lprcPosRect;
796 RECT clipRect = *lprcClipRect;
799 ** record keeping of control geometry within container
804 ** convert posRect & clipRect to match control viewport coordinates
806 getViewportCoords(&posRect, &clipRect);
809 ** Create a window for in place activated control.
810 ** the window geometry matches the control viewport
811 ** within container so that embedded video is always
814 _inplacewnd = CreateWindow(_p_class->getInPlaceWndClassName(),
815 "VLC Plugin In-Place Window",
816 WS_CHILD|WS_CLIPCHILDREN|WS_CLIPSIBLINGS,
819 clipRect.right-clipRect.left,
820 clipRect.bottom-clipRect.top,
823 _p_class->getHInstance(),
827 if( NULL == _inplacewnd )
830 SetWindowLongPtr(_inplacewnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));
833 ** VLC embedded video automatically grows to cover client
834 ** area of parent window.
835 ** hence create a such a 'parent' window whose geometry
836 ** is always correct relative to the viewport bounds
838 _videownd = CreateWindow(_p_class->getVideoWndClassName(),
839 "VLC Plugin Video Window",
840 WS_CHILD|WS_CLIPCHILDREN|WS_VISIBLE,
843 posRect.right-posRect.left,
844 posRect.bottom-posRect.top,
847 _p_class->getHInstance(),
851 if( NULL == _videownd )
853 DestroyWindow(_inplacewnd);
857 SetWindowLongPtr(_videownd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));
861 /* will run vlc if not done already */
862 libvlc_instance_t* p_libvlc;
863 HRESULT result = getVLC(&p_libvlc);
867 /* set internal video width and height */
868 libvlc_video_set_size(p_libvlc,
869 posRect.right-posRect.left,
870 posRect.bottom-posRect.top,
873 /* set internal video parent window */
874 libvlc_video_set_parent(p_libvlc,
875 reinterpret_cast<libvlc_drawable_t>(_videownd), NULL);
877 if( _b_autoplay & (libvlc_playlist_items_count(p_libvlc, NULL) > 0) )
879 libvlc_playlist_play(p_libvlc, 0, 0, NULL, NULL);
885 ShowWindow(_inplacewnd, SW_SHOW);
890 HRESULT VLCPlugin::onInPlaceDeactivate(void)
894 libvlc_playlist_stop(_p_libvlc, NULL);
898 DestroyWindow(_videownd);
900 DestroyWindow(_inplacewnd);
906 void VLCPlugin::setVisible(BOOL fVisible)
908 if( fVisible != _b_visible )
910 _b_visible = fVisible;
911 if( isInPlaceActive() )
913 ShowWindow(_inplacewnd, fVisible ? SW_SHOW : SW_HIDE);
915 InvalidateRect(_videownd, NULL, TRUE);
918 firePropChangedEvent(DISPID_Visible);
922 void VLCPlugin::setVolume(int volume)
926 else if( volume > 200 )
929 if( volume != _i_volume )
934 libvlc_audio_set_volume(_p_libvlc, _i_volume, NULL);
940 void VLCPlugin::setTime(int seconds)
945 if( seconds != _i_time )
947 setStartTime(_i_time);
950 libvlc_input_t *p_input = libvlc_playlist_get_input(_p_libvlc, NULL);
951 if( NULL != p_input )
953 libvlc_input_set_time(p_input, _i_time, NULL);
954 libvlc_input_free(p_input);
960 void VLCPlugin::setFocus(BOOL fFocus)
963 SetActiveWindow(_inplacewnd);
966 BOOL VLCPlugin::hasFocus(void)
968 return GetActiveWindow() == _inplacewnd;
971 void VLCPlugin::onDraw(DVTARGETDEVICE * ptd, HDC hicTargetDev,
972 HDC hdcDraw, LPCRECTL lprcBounds, LPCRECTL lprcWBounds)
976 long width = lprcBounds->right-lprcBounds->left;
977 long height = lprcBounds->bottom-lprcBounds->top;
979 RECT bounds = { lprcBounds->left, lprcBounds->top, lprcBounds->right, lprcBounds->bottom };
980 FillRect(hdcDraw, &bounds, (HBRUSH)GetStockObject(WHITE_BRUSH));
982 LPPICTURE pict = getPicture();
985 OLE_XSIZE_HIMETRIC picWidth;
986 OLE_YSIZE_HIMETRIC picHeight;
988 pict->get_Width(&picWidth);
989 pict->get_Height(&picHeight);
991 SIZEL picSize = { picWidth, picHeight };
993 if( NULL != hicTargetDev )
995 DPFromHimetric(hicTargetDev, (LPPOINT)&picSize, 1);
997 else if( NULL != (hicTargetDev = CreateDevDC(ptd)) )
999 DPFromHimetric(hicTargetDev, (LPPOINT)&picSize, 1);
1000 DeleteDC(hicTargetDev);
1003 if( picSize.cx > width-4 )
1004 picSize.cx = width-4;
1005 if( picSize.cy > height-4 )
1006 picSize.cy = height-4;
1008 LONG dstX = lprcBounds->left+(width-picSize.cx)/2;
1009 LONG dstY = lprcBounds->top+(height-picSize.cy)/2;
1011 if( NULL != lprcWBounds )
1013 RECT wBounds = { lprcWBounds->left, lprcWBounds->top, lprcWBounds->right, lprcWBounds->bottom };
1014 pict->Render(hdcDraw, dstX, dstY, picSize.cx, picSize.cy,
1015 0L, picHeight, picWidth, -picHeight, &wBounds);
1018 pict->Render(hdcDraw, dstX, dstY, picSize.cx, picSize.cy,
1019 0L, picHeight, picWidth, -picHeight, NULL);
1024 SelectObject(hdcDraw, GetStockObject(BLACK_BRUSH));
1026 MoveToEx(hdcDraw, bounds.left, bounds.top, NULL);
1027 LineTo(hdcDraw, bounds.left+width-1, bounds.top);
1028 LineTo(hdcDraw, bounds.left+width-1, bounds.top+height-1);
1029 LineTo(hdcDraw, bounds.left, bounds.top+height-1);
1030 LineTo(hdcDraw, bounds.left, bounds.top);
1034 void VLCPlugin::onPaint(HDC hdc, const RECT &bounds, const RECT &clipRect)
1038 /** if VLC is playing, it may not display any VIDEO content
1039 ** hence, draw control logo*/
1040 HDC hdcDraw = CreateCompatibleDC(hdc);
1041 if( NULL != hdcDraw )
1043 SIZEL size = getExtent();
1044 DPFromHimetric(hdc, (LPPOINT)&size, 1);
1045 RECTL posRect = { 0, 0, size.cx, size.cy };
1047 int width = bounds.right-bounds.left;
1048 int height = bounds.bottom-bounds.top;
1050 HBITMAP hBitmap = CreateCompatibleBitmap(hdc, width, height);
1051 if( NULL != hBitmap )
1053 HBITMAP oldBmp = (HBITMAP)SelectObject(hdcDraw, hBitmap);
1055 if( (size.cx != width) || (size.cy != height) )
1057 // needs to scale canvas
1058 SetMapMode(hdcDraw, MM_ANISOTROPIC);
1059 SetWindowExtEx(hdcDraw, size.cx, size.cy, NULL);
1060 SetViewportExtEx(hdcDraw, width, height, NULL);
1063 onDraw(NULL, hdc, hdcDraw, &posRect, NULL);
1065 SetMapMode(hdcDraw, MM_TEXT);
1066 BitBlt(hdc, bounds.left, bounds.top,
1071 SelectObject(hdcDraw, oldBmp);
1072 DeleteObject(hBitmap);
1079 void VLCPlugin::onPositionChange(LPCRECT lprcPosRect, LPCRECT lprcClipRect)
1081 RECT clipRect = *lprcClipRect;
1082 RECT posRect = *lprcPosRect;
1084 //RedrawWindow(GetParent(_inplacewnd), &_posRect, NULL, RDW_INVALIDATE|RDW_ERASE|RDW_ALLCHILDREN);
1087 ** record keeping of control geometry within container
1092 ** convert posRect & clipRect to match control viewport coordinates
1094 getViewportCoords(&posRect, &clipRect);
1097 ** change in-place window geometry to match clipping region
1099 SetWindowPos(_inplacewnd, NULL,
1102 clipRect.right-clipRect.left,
1103 clipRect.bottom-clipRect.top,
1107 SWP_NOOWNERZORDER );
1110 ** change video window geometry to match object bounds within clipping region
1112 SetWindowPos(_videownd, NULL,
1115 posRect.right-posRect.left,
1116 posRect.bottom-posRect.top,
1120 SWP_NOOWNERZORDER );
1122 //RedrawWindow(_videownd, &posRect, NULL, RDW_INVALIDATE|RDW_ERASE|RDW_ALLCHILDREN);
1125 libvlc_video_set_size(_p_libvlc,
1126 posRect.right-posRect.left,
1127 posRect.bottom-posRect.top,
1132 void VLCPlugin::freezeEvents(BOOL freeze)
1134 vlcConnectionPointContainer->freezeEvents(freeze);
1137 void VLCPlugin::firePropChangedEvent(DISPID dispid)
1139 vlcConnectionPointContainer->firePropChangedEvent(dispid);
1142 void VLCPlugin::fireOnPlayEvent(void)
1144 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1145 vlcConnectionPointContainer->fireEvent(DISPID_PlayEvent, &dispparamsNoArgs);
1148 void VLCPlugin::fireOnPauseEvent(void)
1150 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1151 vlcConnectionPointContainer->fireEvent(DISPID_PauseEvent, &dispparamsNoArgs);
1154 void VLCPlugin::fireOnStopEvent(void)
1156 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1157 vlcConnectionPointContainer->fireEvent(DISPID_StopEvent, &dispparamsNoArgs);