1 /*****************************************************************************
2 * plugin.cpp: ActiveX control for VLC
3 *****************************************************************************
4 * Copyright (C) 2006-2010 the VideoLAN team
6 * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>
7 * Jean-Paul Saman <jpsaman@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
26 #include "oleobject.h"
27 #include "olecontrol.h"
28 #include "oleinplaceobject.h"
29 #include "oleinplaceactiveobject.h"
30 #include "persistpropbag.h"
31 #include "persiststreaminit.h"
32 #include "persiststorage.h"
33 #include "provideclassinfo.h"
34 #include "connectioncontainer.h"
35 #include "objectsafety.h"
36 #include "vlccontrol.h"
37 #include "vlccontrol2.h"
38 #include "viewobject.h"
39 #include "dataobject.h"
40 #include "supporterrorinfo.h"
55 ////////////////////////////////////////////////////////////////////////
58 static LRESULT CALLBACK VLCInPlaceClassWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
59 VLCPlugin *p_instance = reinterpret_cast<VLCPlugin *>(GetWindowLongPtr(hWnd, GWLP_USERDATA));
69 if( GetUpdateRect(hWnd, &pr, FALSE) )
72 GetClientRect(hWnd, &bounds);
73 BeginPaint(hWnd, &ps);
74 p_instance->onPaint(ps.hdc, bounds, pr);
80 return DefWindowProc(hWnd, uMsg, wParam, lParam);
84 VLCPluginClass::VLCPluginClass(LONG *p_class_ref, HINSTANCE hInstance, REFCLSID rclsid) :
85 _p_class_ref(p_class_ref),
86 _hinstance(hInstance),
88 _inplace_picture(NULL)
92 if( ! GetClassInfo(hInstance, getInPlaceWndClassName(), &wClass) )
94 wClass.style = CS_NOCLOSE|CS_DBLCLKS;
95 wClass.lpfnWndProc = VLCInPlaceClassWndProc;
96 wClass.cbClsExtra = 0;
97 wClass.cbWndExtra = 0;
98 wClass.hInstance = hInstance;
100 wClass.hCursor = LoadCursor(NULL, IDC_ARROW);
101 wClass.hbrBackground = NULL;
102 wClass.lpszMenuName = NULL;
103 wClass.lpszClassName = getInPlaceWndClassName();
105 _inplace_wndclass_atom = RegisterClass(&wClass);
109 _inplace_wndclass_atom = 0;
112 HBITMAP hbitmap = (HBITMAP)LoadImage(getHInstance(), MAKEINTRESOURCE(2), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
113 if( NULL != hbitmap )
117 pictDesc.cbSizeofstruct = sizeof(PICTDESC);
118 pictDesc.picType = PICTYPE_BITMAP;
119 pictDesc.bmp.hbitmap = hbitmap;
120 pictDesc.bmp.hpal = NULL;
122 if( FAILED(OleCreatePictureIndirect(&pictDesc, IID_IPicture, TRUE, reinterpret_cast<LPVOID*>(&_inplace_picture))) )
123 _inplace_picture = NULL;
128 VLCPluginClass::~VLCPluginClass()
130 if( 0 != _inplace_wndclass_atom )
131 UnregisterClass(MAKEINTATOM(_inplace_wndclass_atom), _hinstance);
133 if( NULL != _inplace_picture )
134 _inplace_picture->Release();
137 STDMETHODIMP VLCPluginClass::QueryInterface(REFIID riid, void **ppv)
142 if( (IID_IUnknown == riid)
143 || (IID_IClassFactory == riid) )
146 *ppv = reinterpret_cast<LPVOID>(this);
153 return E_NOINTERFACE;
156 STDMETHODIMP_(ULONG) VLCPluginClass::AddRef(void)
158 return InterlockedIncrement(_p_class_ref);
161 STDMETHODIMP_(ULONG) VLCPluginClass::Release(void)
163 ULONG refcount = InterlockedDecrement(_p_class_ref);
172 STDMETHODIMP VLCPluginClass::CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, void **ppv)
179 if( (NULL != pUnkOuter) && (IID_IUnknown != riid) ) {
180 return CLASS_E_NOAGGREGATION;
183 VLCPlugin *plugin = new VLCPlugin(this, pUnkOuter);
186 HRESULT hr = plugin->QueryInterface(riid, ppv);
187 // the following will destroy the object if QueryInterface() failed
191 return E_OUTOFMEMORY;
194 STDMETHODIMP VLCPluginClass::LockServer(BOOL fLock)
204 ////////////////////////////////////////////////////////////////////////
206 VLCPlugin::VLCPlugin(VLCPluginClass *p_class, LPUNKNOWN pUnkOuter) :
219 vlcOleControl = new VLCOleControl(this);
220 vlcOleInPlaceObject = new VLCOleInPlaceObject(this);
221 vlcOleInPlaceActiveObject = new VLCOleInPlaceActiveObject(this);
222 vlcPersistStorage = new VLCPersistStorage(this);
223 vlcPersistStreamInit = new VLCPersistStreamInit(this);
224 vlcPersistPropertyBag = new VLCPersistPropertyBag(this);
225 vlcProvideClassInfo = new VLCProvideClassInfo(this);
226 vlcConnectionPointContainer = new VLCConnectionPointContainer(this);
227 vlcObjectSafety = new VLCObjectSafety(this);
228 vlcControl = new VLCControl(this);
229 vlcControl2 = new VLCControl2(this);
230 vlcViewObject = new VLCViewObject(this);
231 vlcDataObject = new VLCDataObject(this);
232 vlcOleObject = new VLCOleObject(this);
233 vlcSupportErrorInfo = new VLCSupportErrorInfo(this);
235 // configure controlling IUnknown interface for implemented interfaces
236 this->pUnkOuter = (NULL != pUnkOuter) ? pUnkOuter : dynamic_cast<LPUNKNOWN>(this);
239 _p_pict = p_class->getInPlacePict();
241 // make sure that persistable properties are initialized
245 VLCPlugin::~VLCPlugin()
248 ** bump refcount to avoid recursive release from
249 ** following interfaces when releasing this interface
253 delete vlcSupportErrorInfo;
255 delete vlcDataObject;
256 delete vlcViewObject;
259 delete vlcConnectionPointContainer;
260 delete vlcProvideClassInfo;
261 delete vlcPersistPropertyBag;
262 delete vlcPersistStreamInit;
263 delete vlcPersistStorage;
264 delete vlcOleInPlaceActiveObject;
265 delete vlcOleInPlaceObject;
266 delete vlcObjectSafety;
268 delete vlcOleControl;
272 SysFreeString(_bstr_mrl);
273 SysFreeString(_bstr_baseurl);
280 player_unregister_events();
281 libvlc_media_player_release(_p_mplayer);
284 if( _p_mlist ) { libvlc_media_list_release(_p_mlist); _p_mlist=NULL; }
285 if( _p_libvlc ) { libvlc_release(_p_libvlc); _p_libvlc=NULL; }
290 STDMETHODIMP VLCPlugin::QueryInterface(REFIID riid, void **ppv)
295 if( IID_IUnknown == riid )
296 *ppv = reinterpret_cast<LPVOID>(this);
297 else if( IID_IOleObject == riid )
298 *ppv = reinterpret_cast<LPVOID>(vlcOleObject);
299 else if( IID_IOleControl == riid )
300 *ppv = reinterpret_cast<LPVOID>(vlcOleControl);
301 else if( IID_IOleWindow == riid )
302 *ppv = reinterpret_cast<LPVOID>(vlcOleInPlaceObject);
303 else if( IID_IOleInPlaceObject == riid )
304 *ppv = reinterpret_cast<LPVOID>(vlcOleInPlaceObject);
305 else if( IID_IOleInPlaceActiveObject == riid )
306 *ppv = reinterpret_cast<LPVOID>(vlcOleInPlaceActiveObject);
307 else if( IID_IPersist == riid )
308 *ppv = reinterpret_cast<LPVOID>(vlcPersistStreamInit);
309 else if( IID_IPersistStreamInit == riid )
310 *ppv = reinterpret_cast<LPVOID>(vlcPersistStreamInit);
311 else if( IID_IPersistStorage == riid )
312 *ppv = reinterpret_cast<LPVOID>(vlcPersistStorage);
313 else if( IID_IPersistPropertyBag == riid )
314 *ppv = reinterpret_cast<LPVOID>(vlcPersistPropertyBag);
315 else if( IID_IProvideClassInfo == riid )
316 *ppv = reinterpret_cast<LPVOID>(vlcProvideClassInfo);
317 else if( IID_IProvideClassInfo2 == riid )
318 *ppv = reinterpret_cast<LPVOID>(vlcProvideClassInfo);
319 else if( IID_IConnectionPointContainer == riid )
320 *ppv = reinterpret_cast<LPVOID>(vlcConnectionPointContainer);
321 else if( IID_IObjectSafety == riid )
322 *ppv = reinterpret_cast<LPVOID>(vlcObjectSafety);
323 else if( IID_IDispatch == riid )
324 *ppv = (CLSID_VLCPlugin2 == getClassID()) ?
325 reinterpret_cast<LPVOID>(vlcControl2) :
326 reinterpret_cast<LPVOID>(vlcControl);
327 else if( IID_IVLCControl == riid )
328 *ppv = reinterpret_cast<LPVOID>(vlcControl);
329 else if( IID_IVLCControl2 == riid )
330 *ppv = reinterpret_cast<LPVOID>(vlcControl2);
331 else if( IID_IViewObject == riid )
332 *ppv = reinterpret_cast<LPVOID>(vlcViewObject);
333 else if( IID_IViewObject2 == riid )
334 *ppv = reinterpret_cast<LPVOID>(vlcViewObject);
335 else if( IID_IDataObject == riid )
336 *ppv = reinterpret_cast<LPVOID>(vlcDataObject);
337 else if( IID_ISupportErrorInfo == riid )
338 *ppv = reinterpret_cast<LPVOID>(vlcSupportErrorInfo);
342 return E_NOINTERFACE;
344 ((LPUNKNOWN)*ppv)->AddRef();
348 STDMETHODIMP_(ULONG) VLCPlugin::AddRef(void)
350 return InterlockedIncrement((LONG *)&_i_ref);
353 STDMETHODIMP_(ULONG) VLCPlugin::Release(void)
355 if( ! InterlockedDecrement((LONG *)&_i_ref) )
363 //////////////////////////////////////
365 HRESULT VLCPlugin::onInit(void)
367 if( NULL == _p_libvlc )
369 // initialize persistable properties
373 _bstr_baseurl = NULL;
380 // set default/preferred size (320x240) pixels in HIMETRIC
381 HDC hDC = CreateDevDC(NULL);
384 HimetricFromDP(hDC, (LPPOINT)&_extent, 1);
389 return CO_E_ALREADYINITIALIZED;
392 HRESULT VLCPlugin::onLoad(void)
394 if( SysStringLen(_bstr_baseurl) == 0 )
397 ** try to retreive the base URL using the client site moniker, which for Internet Explorer
398 ** is the URL of the page the plugin is embedded into.
400 LPOLECLIENTSITE pClientSite;
401 if( SUCCEEDED(vlcOleObject->GetClientSite(&pClientSite)) && (NULL != pClientSite) )
404 if( SUCCEEDED(CreateBindCtx(0, &pBC)) )
406 LPMONIKER pContMoniker = NULL;
407 if( SUCCEEDED(pClientSite->GetMoniker(OLEGETMONIKER_ONLYIFTHERE,
408 OLEWHICHMK_CONTAINER, &pContMoniker)) )
411 if( SUCCEEDED(pContMoniker->GetDisplayName(pBC, NULL, &base_url)) )
414 ** check that the moniker name is a URL
416 if( UrlIsW(base_url, URLIS_URL) )
419 _bstr_baseurl = SysAllocString(base_url);
421 CoTaskMemFree(base_url);
431 void VLCPlugin::initVLC()
433 extern HMODULE DllGetModule();
436 ** default initialization options
438 const char *ppsz_argv[32] = { };
441 char p_progpath[MAX_PATH];
443 TCHAR w_progpath[MAX_PATH];
444 DWORD len = GetModuleFileName(DllGetModule(), w_progpath, MAX_PATH);
447 len = WideCharToMultiByte(CP_UTF8, 0, w_progpath, len, p_progpath,
448 sizeof(p_progpath)-1, NULL, NULL);
451 p_progpath[len] = '\0';
452 ppsz_argv[0] = p_progpath;
457 ppsz_argv[ppsz_argc++] = "-vv";
460 char p_pluginpath[MAX_PATH];
461 if( RegOpenKeyEx( HKEY_LOCAL_MACHINE, TEXT("Software\\VideoLAN\\VLC"),
462 0, KEY_READ, &h_key ) == ERROR_SUCCESS )
464 DWORD i_type, i_data = MAX_PATH;
465 TCHAR w_pluginpath[MAX_PATH];
466 if( RegQueryValueEx( h_key, TEXT("InstallDir"), 0, &i_type,
467 (LPBYTE)w_pluginpath, &i_data ) == ERROR_SUCCESS )
469 if( i_type == REG_SZ )
471 if( WideCharToMultiByte(CP_UTF8, 0, w_pluginpath, -1, p_pluginpath,
472 sizeof(p_pluginpath)-sizeof("\\plugins")+1, NULL, NULL) )
474 strcat( p_pluginpath, "\\plugins" );
475 ppsz_argv[ppsz_argc++] = "--plugin-path";
476 ppsz_argv[ppsz_argc++] = p_pluginpath;
480 RegCloseKey( h_key );
483 // make sure plugin isn't affected with VLC single instance mode
484 ppsz_argv[ppsz_argc++] = "--no-one-instance";
486 /* common settings */
487 ppsz_argv[ppsz_argc++] = "-vv";
488 ppsz_argv[ppsz_argc++] = "--no-stats";
489 ppsz_argv[ppsz_argc++] = "--no-media-library";
490 ppsz_argv[ppsz_argc++] = "--intf=dummy";
491 ppsz_argv[ppsz_argc++] = "--no-video-title-show";
494 // loop mode is a configuration option only
496 ppsz_argv[ppsz_argc++] = "--loop";
498 _p_libvlc = libvlc_new(ppsz_argc, ppsz_argv);
502 _p_mlist = libvlc_media_list_new(_p_libvlc);
504 // initial playlist item
505 if( SysStringLen(_bstr_mrl) > 0 )
507 char *psz_mrl = NULL;
509 if( SysStringLen(_bstr_baseurl) > 0 )
512 ** if the MRL a relative URL, we should end up with an absolute URL
514 LPWSTR abs_url = CombineURL(_bstr_baseurl, _bstr_mrl);
515 if( NULL != abs_url )
517 psz_mrl = CStrFromWSTR(CP_UTF8, abs_url, wcslen(abs_url));
518 CoTaskMemFree(abs_url);
522 psz_mrl = CStrFromBSTR(CP_UTF8, _bstr_mrl);
528 ** baseURL is empty, assume MRL is absolute
530 psz_mrl = CStrFromBSTR(CP_UTF8, _bstr_mrl);
532 if( NULL != psz_mrl )
534 const char *options[1];
540 snprintf(timeBuffer, sizeof(timeBuffer), ":start-time=%d", _i_time);
541 options[i_options++] = timeBuffer;
543 // add default target to playlist
544 playlist_add_extended_untrusted(psz_mrl, i_options, options);
545 CoTaskMemFree(psz_mrl);
550 void VLCPlugin::setErrorInfo(REFIID riid, const char *description)
552 vlcSupportErrorInfo->setErrorInfo( getClassID() == CLSID_VLCPlugin2 ?
553 OLESTR("VideoLAN.VLCPlugin.2") : OLESTR("VideoLAN.VLCPlugin.1"),
557 HRESULT VLCPlugin::onAmbientChanged(LPUNKNOWN pContainer, DISPID dispID)
562 case DISPID_AMBIENT_BACKCOLOR:
565 if( SUCCEEDED(GetObjectProperty(pContainer, dispID, v)) )
567 setBackColor(V_I4(&v));
570 case DISPID_AMBIENT_DISPLAYNAME:
572 case DISPID_AMBIENT_FONT:
574 case DISPID_AMBIENT_FORECOLOR:
576 case DISPID_AMBIENT_LOCALEID:
578 case DISPID_AMBIENT_MESSAGEREFLECT:
580 case DISPID_AMBIENT_SCALEUNITS:
582 case DISPID_AMBIENT_TEXTALIGN:
584 case DISPID_AMBIENT_USERMODE:
587 if( SUCCEEDED(GetObjectProperty(pContainer, dispID, v)) )
589 setUserMode(V_BOOL(&v) != VARIANT_FALSE);
592 case DISPID_AMBIENT_UIDEAD:
594 case DISPID_AMBIENT_SHOWGRABHANDLES:
596 case DISPID_AMBIENT_SHOWHATCHING:
598 case DISPID_AMBIENT_DISPLAYASDEFAULT:
600 case DISPID_AMBIENT_SUPPORTSMNEMONICS:
602 case DISPID_AMBIENT_AUTOCLIP:
604 case DISPID_AMBIENT_APPEARANCE:
606 case DISPID_AMBIENT_CODEPAGE:
609 if( SUCCEEDED(GetObjectProperty(pContainer, dispID, v)) )
611 setCodePage(V_I4(&v));
614 case DISPID_AMBIENT_PALETTE:
616 case DISPID_AMBIENT_CHARSET:
618 case DISPID_AMBIENT_RIGHTTOLEFT:
620 case DISPID_AMBIENT_TOPTOBOTTOM:
624 ** multiple property change, look up the ones we are interested in
628 if( SUCCEEDED(GetObjectProperty(pContainer, DISPID_AMBIENT_USERMODE, v)) )
630 setUserMode(V_BOOL(&v) != VARIANT_FALSE);
634 if( SUCCEEDED(GetObjectProperty(pContainer, DISPID_AMBIENT_CODEPAGE, v)) )
636 setCodePage(V_I4(&v));
643 HRESULT VLCPlugin::onClose(DWORD dwSaveOption)
645 if( isInPlaceActive() )
647 onInPlaceDeactivate();
651 libvlc_instance_t* p_libvlc = _p_libvlc;
654 vlcDataObject->onClose();
657 libvlc_release(p_libvlc);
662 BOOL VLCPlugin::isInPlaceActive(void)
664 return (NULL != _inplacewnd);
667 HRESULT VLCPlugin::onActivateInPlace(LPMSG lpMesg, HWND hwndParent, LPCRECT lprcPosRect, LPCRECT lprcClipRect)
669 RECT clipRect = *lprcClipRect;
672 ** record keeping of control geometry within container
674 _posRect = *lprcPosRect;
677 ** Create a window for in place activated control.
678 ** the window geometry matches the control viewport
679 ** within container so that embedded video is always
680 ** properly displayed.
682 _inplacewnd = CreateWindow(_p_class->getInPlaceWndClassName(),
683 TEXT("VLC Plugin In-Place Window"),
684 WS_CHILD|WS_CLIPCHILDREN|WS_CLIPSIBLINGS,
687 lprcPosRect->right-lprcPosRect->left,
688 lprcPosRect->bottom-lprcPosRect->top,
691 _p_class->getHInstance(),
695 if( NULL == _inplacewnd )
698 SetWindowLongPtr(_inplacewnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));
700 /* change cliprect coordinates system relative to window bounding rect */
701 OffsetRect(&clipRect, -lprcPosRect->left, -lprcPosRect->top);
703 HRGN clipRgn = CreateRectRgnIndirect(&clipRect);
704 SetWindowRgn(_inplacewnd, clipRgn, TRUE);
708 /* will run vlc if not done already */
709 libvlc_instance_t* p_libvlc;
710 HRESULT result = getVLC(&p_libvlc);
714 if( _b_autoplay && playlist_select(0) )
716 libvlc_media_player_play(_p_mplayer);
722 ShowWindow(_inplacewnd, SW_SHOW);
727 HRESULT VLCPlugin::onInPlaceDeactivate(void)
735 DestroyWindow(_inplacewnd);
741 void VLCPlugin::setVisible(BOOL fVisible)
743 if( fVisible != _b_visible )
745 _b_visible = fVisible;
746 if( isInPlaceActive() )
748 ShowWindow(_inplacewnd, fVisible ? SW_SHOW : SW_HIDE);
750 InvalidateRect(_inplacewnd, NULL, TRUE);
753 firePropChangedEvent(DISPID_Visible);
757 void VLCPlugin::setVolume(int volume)
761 else if( volume > 200 )
764 if( volume != _i_volume )
769 libvlc_media_player_t *p_md;
770 HRESULT hr = getMD(&p_md);
772 libvlc_audio_set_volume(p_md, _i_volume);
778 void VLCPlugin::setBackColor(OLE_COLOR backcolor)
780 if( _i_backcolor != backcolor )
782 _i_backcolor = backcolor;
783 if( isInPlaceActive() )
791 void VLCPlugin::setTime(int seconds)
796 if( seconds != _i_time )
798 setStartTime(_i_time);
799 if( NULL != _p_mplayer )
801 libvlc_media_player_set_time(_p_mplayer, _i_time);
806 void VLCPlugin::setFocus(BOOL fFocus)
809 SetActiveWindow(_inplacewnd);
812 BOOL VLCPlugin::hasFocus(void)
814 return GetActiveWindow() == _inplacewnd;
817 void VLCPlugin::onDraw(DVTARGETDEVICE * ptd, HDC hicTargetDev,
818 HDC hdcDraw, LPCRECTL lprcBounds, LPCRECTL lprcWBounds)
822 long width = lprcBounds->right-lprcBounds->left;
823 long height = lprcBounds->bottom-lprcBounds->top;
825 RECT bounds = { lprcBounds->left, lprcBounds->top, lprcBounds->right, lprcBounds->bottom };
829 /* VLC is in user mode, just draw background color */
830 COLORREF colorref = RGB(0, 0, 0);
831 OleTranslateColor(_i_backcolor, (HPALETTE)GetStockObject(DEFAULT_PALETTE), &colorref);
832 if( colorref != RGB(0, 0, 0) )
834 /* custom background */
835 HBRUSH colorbrush = CreateSolidBrush(colorref);
836 FillRect(hdcDraw, &bounds, colorbrush);
837 DeleteObject((HANDLE)colorbrush);
841 /* black background */
842 FillRect(hdcDraw, &bounds, (HBRUSH)GetStockObject(BLACK_BRUSH));
847 /* VLC is in design mode, draw the VLC logo */
848 FillRect(hdcDraw, &bounds, (HBRUSH)GetStockObject(WHITE_BRUSH));
850 LPPICTURE pict = getPicture();
853 OLE_XSIZE_HIMETRIC picWidth;
854 OLE_YSIZE_HIMETRIC picHeight;
856 pict->get_Width(&picWidth);
857 pict->get_Height(&picHeight);
859 SIZEL picSize = { picWidth, picHeight };
861 if( NULL != hicTargetDev )
863 DPFromHimetric(hicTargetDev, (LPPOINT)&picSize, 1);
865 else if( NULL != (hicTargetDev = CreateDevDC(ptd)) )
867 DPFromHimetric(hicTargetDev, (LPPOINT)&picSize, 1);
868 DeleteDC(hicTargetDev);
871 if( picSize.cx > width-4 )
872 picSize.cx = width-4;
873 if( picSize.cy > height-4 )
874 picSize.cy = height-4;
876 LONG dstX = lprcBounds->left+(width-picSize.cx)/2;
877 LONG dstY = lprcBounds->top+(height-picSize.cy)/2;
879 if( NULL != lprcWBounds )
881 RECT wBounds = { lprcWBounds->left, lprcWBounds->top, lprcWBounds->right, lprcWBounds->bottom };
882 pict->Render(hdcDraw, dstX, dstY, picSize.cx, picSize.cy,
883 0L, picHeight, picWidth, -picHeight, &wBounds);
886 pict->Render(hdcDraw, dstX, dstY, picSize.cx, picSize.cy,
887 0L, picHeight, picWidth, -picHeight, NULL);
892 SelectObject(hdcDraw, GetStockObject(BLACK_BRUSH));
894 MoveToEx(hdcDraw, bounds.left, bounds.top, NULL);
895 LineTo(hdcDraw, bounds.left+width-1, bounds.top);
896 LineTo(hdcDraw, bounds.left+width-1, bounds.top+height-1);
897 LineTo(hdcDraw, bounds.left, bounds.top+height-1);
898 LineTo(hdcDraw, bounds.left, bounds.top);
903 void VLCPlugin::onPaint(HDC hdc, const RECT &bounds, const RECT &clipRect)
907 /* if VLC is in design mode, draw control logo */
908 HDC hdcDraw = CreateCompatibleDC(hdc);
909 if( NULL != hdcDraw )
911 SIZEL size = getExtent();
912 DPFromHimetric(hdc, (LPPOINT)&size, 1);
913 RECTL posRect = { 0, 0, size.cx, size.cy };
915 int width = bounds.right-bounds.left;
916 int height = bounds.bottom-bounds.top;
918 HBITMAP hBitmap = CreateCompatibleBitmap(hdc, width, height);
919 if( NULL != hBitmap )
921 HBITMAP oldBmp = (HBITMAP)SelectObject(hdcDraw, hBitmap);
923 if( (size.cx != width) || (size.cy != height) )
925 // needs to scale canvas
926 SetMapMode(hdcDraw, MM_ANISOTROPIC);
927 SetWindowExtEx(hdcDraw, size.cx, size.cy, NULL);
928 SetViewportExtEx(hdcDraw, width, height, NULL);
931 onDraw(NULL, hdc, hdcDraw, &posRect, NULL);
933 SetMapMode(hdcDraw, MM_TEXT);
934 BitBlt(hdc, bounds.left, bounds.top,
939 SelectObject(hdcDraw, oldBmp);
940 DeleteObject(hBitmap);
947 void VLCPlugin::onPositionChange(LPCRECT lprcPosRect, LPCRECT lprcClipRect)
949 RECT clipRect = *lprcClipRect;
951 //RedrawWindow(GetParent(_inplacewnd), &_posRect, NULL, RDW_INVALIDATE|RDW_ERASE|RDW_ALLCHILDREN);
954 ** record keeping of control geometry within container
956 _posRect = *lprcPosRect;
959 ** change in-place window geometry to match clipping region
961 SetWindowPos(_inplacewnd, NULL,
964 lprcPosRect->right-lprcPosRect->left,
965 lprcPosRect->bottom-lprcPosRect->top,
971 /* change cliprect coordinates system relative to window bounding rect */
972 OffsetRect(&clipRect, -lprcPosRect->left, -lprcPosRect->top);
973 HRGN clipRgn = CreateRectRgnIndirect(&clipRect);
974 SetWindowRgn(_inplacewnd, clipRgn, FALSE);
976 //RedrawWindow(_videownd, &posRect, NULL, RDW_INVALIDATE|RDW_ERASE|RDW_ALLCHILDREN);
979 void VLCPlugin::freezeEvents(BOOL freeze)
981 vlcConnectionPointContainer->freezeEvents(freeze);
984 void VLCPlugin::firePropChangedEvent(DISPID dispid)
986 vlcConnectionPointContainer->firePropChangedEvent(dispid);
989 void VLCPlugin::fireOnPlayEvent(void)
991 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
992 vlcConnectionPointContainer->fireEvent(DISPID_PlayEvent, &dispparamsNoArgs);
995 void VLCPlugin::fireOnPauseEvent(void)
997 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
998 vlcConnectionPointContainer->fireEvent(DISPID_PauseEvent, &dispparamsNoArgs);
1001 void VLCPlugin::fireOnStopEvent(void)
1003 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1004 vlcConnectionPointContainer->fireEvent(DISPID_StopEvent, &dispparamsNoArgs);
1010 void VLCPlugin::fireOnIdleEvent()
1012 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1013 vlcConnectionPointContainer->fireEvent(DISPID_NothingSpecialEvent, &dispparamsNoArgs);
1016 void VLCPlugin::fireOnOpeningEvent()
1018 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1019 vlcConnectionPointContainer->fireEvent(DISPID_OpeningEvent, &dispparamsNoArgs);
1022 void VLCPlugin::fireOnBufferingEvent()
1024 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1025 vlcConnectionPointContainer->fireEvent(DISPID_BufferingEvent, &dispparamsNoArgs);
1028 void VLCPlugin::fireOnPlayingEvent()
1030 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1031 vlcConnectionPointContainer->fireEvent(DISPID_PlayingEvent, &dispparamsNoArgs);
1034 void VLCPlugin::fireOnPausedEvent()
1036 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1037 vlcConnectionPointContainer->fireEvent(DISPID_PausedEvent, &dispparamsNoArgs);
1040 void VLCPlugin::fireOnErrorEvent()
1042 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1043 vlcConnectionPointContainer->fireEvent(DISPID_EncounteredErrorEvent, &dispparamsNoArgs);
1046 void VLCPlugin::fireOnEndedEvent()
1048 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1049 vlcConnectionPointContainer->fireEvent(DISPID_EndReachedEvent, &dispparamsNoArgs);
1052 void VLCPlugin::fireOnStoppedEvent()
1054 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1055 vlcConnectionPointContainer->fireEvent(DISPID_StoppedEvent, &dispparamsNoArgs);
1058 void VLCPlugin::fireOnForwardEvent()
1060 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1061 vlcConnectionPointContainer->fireEvent(DISPID_ForwardEvent, &dispparamsNoArgs);
1064 void VLCPlugin::fireOnBackwardEvent()
1066 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1067 vlcConnectionPointContainer->fireEvent(DISPID_BackwardEvent, &dispparamsNoArgs);
1070 static void handle_input_state_event(const libvlc_event_t* event, void *param)
1072 VLCPlugin *plugin = (VLCPlugin*)param;
1073 switch( event->type )
1075 case libvlc_MediaPlayerNothingSpecial:
1076 plugin->fireOnIdleEvent();
1078 case libvlc_MediaPlayerOpening:
1079 plugin->fireOnOpeningEvent();
1081 case libvlc_MediaPlayerBuffering:
1082 plugin->fireOnBufferingEvent();
1084 case libvlc_MediaPlayerPlaying:
1085 plugin->fireOnPlayingEvent();
1087 case libvlc_MediaPlayerPaused:
1088 plugin->fireOnPausedEvent();
1090 case libvlc_MediaPlayerStopped:
1091 plugin->fireOnStoppedEvent();
1093 case libvlc_MediaPlayerForward:
1094 plugin->fireOnForwardEvent();
1096 case libvlc_MediaPlayerBackward:
1097 plugin->fireOnBackwardEvent();
1099 case libvlc_MediaPlayerEndReached:
1100 plugin->fireOnEndedEvent();
1102 case libvlc_MediaPlayerEncounteredError:
1103 plugin->fireOnErrorEvent();
1108 void VLCPlugin::fireOnTimeChangedEvent(long time)
1111 DISPPARAMS params = { &varPos, NULL, 1, 0 };
1114 vlcConnectionPointContainer->fireEvent(DISPID_TimeChangedEvent, ¶ms);
1117 static void handle_time_changed_event(const libvlc_event_t* event, void *param)
1119 VLCPlugin *plugin = (VLCPlugin*)param;
1120 plugin->fireOnTimeChangedEvent(event->u.media_player_time_changed.new_time);
1123 void VLCPlugin::fireOnPositionChangedEvent(long position)
1126 DISPPARAMS params = { &varPos, NULL, 1, 0 };
1128 varPos.lVal = position;
1129 vlcConnectionPointContainer->fireEvent(DISPID_PositionChangedEvent, ¶ms);
1132 static void handle_position_changed_event(const libvlc_event_t* event, void *param)
1134 VLCPlugin *plugin = (VLCPlugin*)param;
1135 plugin->fireOnPositionChangedEvent(event->u.media_player_position_changed.new_position);
1138 #define B(val) ((val) ? 0xFFFF : 0x0000)
1139 void VLCPlugin::fireOnSeekableChangedEvent(VARIANT_BOOL seekable)
1142 DISPPARAMS params = { &varSeek, NULL, 1, 0 };
1143 varSeek.vt = VT_BOOL;
1144 varSeek.boolVal = seekable;
1145 vlcConnectionPointContainer->fireEvent(DISPID_SeekableChangedEvent, ¶ms);
1148 static void handle_seekable_changed_event(const libvlc_event_t* event, void *param)
1150 VLCPlugin *plugin = (VLCPlugin*)param;
1151 plugin->fireOnSeekableChangedEvent(B(event->u.media_player_seekable_changed.new_seekable));
1154 void VLCPlugin::fireOnPausableChangedEvent(VARIANT_BOOL pausable)
1157 DISPPARAMS params = { &varPause, NULL, 1, 0 };
1158 varPause.vt = VT_BOOL;
1159 varPause.boolVal = pausable;
1160 vlcConnectionPointContainer->fireEvent(DISPID_PausableChangedEvent, ¶ms);
1163 static void handle_pausable_changed_event(const libvlc_event_t* event, void *param)
1165 VLCPlugin *plugin = (VLCPlugin*)param;
1166 plugin->fireOnPausableChangedEvent(B(event->u.media_player_pausable_changed.new_pausable));
1172 bool VLCPlugin::playlist_select( int idx )
1174 libvlc_media_t *p_m = NULL;
1178 libvlc_media_list_lock(_p_mlist);
1180 int count = libvlc_media_list_count(_p_mlist);
1182 if( (idx < 0) || (idx >= count) )
1187 p_m = libvlc_media_list_item_at_index(_p_mlist,_i_midx);
1188 libvlc_media_list_unlock(_p_mlist);
1196 player_unregister_events();
1197 libvlc_media_player_release( _p_mplayer );
1201 _p_mplayer = libvlc_media_player_new_from_media(p_m);
1204 // initial volume setting
1205 libvlc_audio_set_volume(_p_mplayer, _i_volume);
1207 libvlc_audio_set_mute(_p_mplayer, TRUE);
1208 set_player_window();
1209 player_register_events();
1212 libvlc_media_release(p_m);
1213 return _p_mplayer ? true : false;
1216 libvlc_media_list_unlock(_p_mlist);
1220 void VLCPlugin::set_player_window()
1222 // XXX FIXME no idea if this is correct or not
1223 libvlc_media_player_set_hwnd(_p_mplayer,getInPlaceWindow());
1226 void VLCPlugin::player_register_events()
1228 libvlc_event_manager_t *eventManager = NULL;
1231 eventManager = libvlc_media_player_event_manager(_p_mplayer);
1233 libvlc_event_attach(eventManager, libvlc_MediaPlayerNothingSpecial,
1234 handle_input_state_event, this);
1235 libvlc_event_attach(eventManager, libvlc_MediaPlayerOpening,
1236 handle_input_state_event, this);
1237 libvlc_event_attach(eventManager, libvlc_MediaPlayerBuffering,
1238 handle_input_state_event, this);
1239 libvlc_event_attach(eventManager, libvlc_MediaPlayerPlaying,
1240 handle_input_state_event, this);
1241 libvlc_event_attach(eventManager, libvlc_MediaPlayerPaused,
1242 handle_input_state_event, this);
1243 libvlc_event_attach(eventManager, libvlc_MediaPlayerStopped,
1244 handle_input_state_event, this);
1245 libvlc_event_attach(eventManager, libvlc_MediaPlayerForward,
1246 handle_input_state_event, this);
1247 libvlc_event_attach(eventManager, libvlc_MediaPlayerBackward,
1248 handle_input_state_event, this);
1249 libvlc_event_attach(eventManager, libvlc_MediaPlayerEndReached,
1250 handle_input_state_event, this);
1251 libvlc_event_attach(eventManager, libvlc_MediaPlayerEncounteredError,
1252 handle_input_state_event, this);
1254 libvlc_event_attach(eventManager, libvlc_MediaPlayerTimeChanged,
1255 handle_time_changed_event, this);
1256 libvlc_event_attach(eventManager, libvlc_MediaPlayerPositionChanged,
1257 handle_position_changed_event, this);
1258 libvlc_event_attach(eventManager, libvlc_MediaPlayerSeekableChanged,
1259 handle_seekable_changed_event, this);
1260 libvlc_event_attach(eventManager, libvlc_MediaPlayerPausableChanged,
1261 handle_pausable_changed_event, this);
1265 void VLCPlugin::player_unregister_events()
1267 libvlc_event_manager_t *eventManager = NULL;
1270 eventManager = libvlc_media_player_event_manager(_p_mplayer);
1272 libvlc_event_detach(eventManager, libvlc_MediaPlayerNothingSpecial,
1273 handle_input_state_event, this);
1274 libvlc_event_detach(eventManager, libvlc_MediaPlayerOpening,
1275 handle_input_state_event, this);
1276 libvlc_event_detach(eventManager, libvlc_MediaPlayerBuffering,
1277 handle_input_state_event, this);
1278 libvlc_event_detach(eventManager, libvlc_MediaPlayerPlaying,
1279 handle_input_state_event, this);
1280 libvlc_event_detach(eventManager, libvlc_MediaPlayerPaused,
1281 handle_input_state_event, this);
1282 libvlc_event_detach(eventManager, libvlc_MediaPlayerStopped,
1283 handle_input_state_event, this);
1284 libvlc_event_detach(eventManager, libvlc_MediaPlayerForward,
1285 handle_input_state_event, this);
1286 libvlc_event_detach(eventManager, libvlc_MediaPlayerBackward,
1287 handle_input_state_event, this);
1288 libvlc_event_detach(eventManager, libvlc_MediaPlayerEndReached,
1289 handle_input_state_event, this);
1290 libvlc_event_detach(eventManager, libvlc_MediaPlayerEncounteredError,
1291 handle_input_state_event, this);
1293 libvlc_event_detach(eventManager, libvlc_MediaPlayerTimeChanged,
1294 handle_time_changed_event, this);
1295 libvlc_event_detach(eventManager, libvlc_MediaPlayerPositionChanged,
1296 handle_position_changed_event, this);
1297 libvlc_event_detach(eventManager, libvlc_MediaPlayerSeekableChanged,
1298 handle_seekable_changed_event, this);
1299 libvlc_event_detach(eventManager, libvlc_MediaPlayerPausableChanged,
1300 handle_pausable_changed_event, this);
1304 int VLCPlugin::playlist_add_extended_untrusted(const char *mrl, int optc, const char **optv)
1307 libvlc_media_t *p_m = libvlc_media_new_location(_p_libvlc,mrl);
1311 for( int i = 0; i < optc; ++i )
1312 libvlc_media_add_option_flag(p_m, optv[i], libvlc_media_option_unique);
1314 libvlc_media_list_lock(_p_mlist);
1315 if( libvlc_media_list_add_media(_p_mlist,p_m) == 0 )
1316 item = libvlc_media_list_count(_p_mlist)-1;
1317 libvlc_media_list_unlock(_p_mlist);
1318 libvlc_media_release(p_m);