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"
39 #include "supporterrorinfo.h"
53 ////////////////////////////////////////////////////////////////////////
56 static LRESULT CALLBACK VLCInPlaceClassWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
57 VLCPlugin *p_instance = reinterpret_cast<VLCPlugin *>(GetWindowLongPtr(hWnd, GWLP_USERDATA));
67 if( GetUpdateRect(hWnd, &pr, FALSE) )
70 GetClientRect(hWnd, &bounds);
71 BeginPaint(hWnd, &ps);
72 p_instance->onPaint(ps.hdc, bounds, pr);
78 return DefWindowProc(hWnd, uMsg, wParam, lParam);
82 VLCPluginClass::VLCPluginClass(LONG *p_class_ref, HINSTANCE hInstance, REFCLSID rclsid) :
83 _p_class_ref(p_class_ref),
84 _hinstance(hInstance),
86 _inplace_picture(NULL)
90 if( ! GetClassInfo(hInstance, getInPlaceWndClassName(), &wClass) )
92 wClass.style = CS_NOCLOSE|CS_DBLCLKS;
93 wClass.lpfnWndProc = VLCInPlaceClassWndProc;
94 wClass.cbClsExtra = 0;
95 wClass.cbWndExtra = 0;
96 wClass.hInstance = hInstance;
98 wClass.hCursor = LoadCursor(NULL, IDC_ARROW);
99 wClass.hbrBackground = NULL;
100 wClass.lpszMenuName = NULL;
101 wClass.lpszClassName = getInPlaceWndClassName();
103 _inplace_wndclass_atom = RegisterClass(&wClass);
107 _inplace_wndclass_atom = 0;
110 HBITMAP hbitmap = (HBITMAP)LoadImage(getHInstance(), MAKEINTRESOURCE(2), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
111 if( NULL != hbitmap )
115 pictDesc.cbSizeofstruct = sizeof(PICTDESC);
116 pictDesc.picType = PICTYPE_BITMAP;
117 pictDesc.bmp.hbitmap = hbitmap;
118 pictDesc.bmp.hpal = NULL;
120 if( FAILED(OleCreatePictureIndirect(&pictDesc, IID_IPicture, TRUE, reinterpret_cast<LPVOID*>(&_inplace_picture))) )
121 _inplace_picture = NULL;
126 VLCPluginClass::~VLCPluginClass()
128 if( 0 != _inplace_wndclass_atom )
129 UnregisterClass(MAKEINTATOM(_inplace_wndclass_atom), _hinstance);
131 if( NULL != _inplace_picture )
132 _inplace_picture->Release();
135 STDMETHODIMP VLCPluginClass::QueryInterface(REFIID riid, void **ppv)
140 if( (IID_IUnknown == riid)
141 || (IID_IClassFactory == riid) )
144 *ppv = reinterpret_cast<LPVOID>(this);
151 return E_NOINTERFACE;
154 STDMETHODIMP_(ULONG) VLCPluginClass::AddRef(void)
156 return InterlockedIncrement(_p_class_ref);
159 STDMETHODIMP_(ULONG) VLCPluginClass::Release(void)
161 ULONG refcount = InterlockedDecrement(_p_class_ref);
170 STDMETHODIMP VLCPluginClass::CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, void **ppv)
177 if( (NULL != pUnkOuter) && (IID_IUnknown != riid) ) {
178 return CLASS_E_NOAGGREGATION;
181 VLCPlugin *plugin = new VLCPlugin(this, pUnkOuter);
184 HRESULT hr = plugin->QueryInterface(riid, ppv);
185 // the following will destroy the object if QueryInterface() failed
189 return E_OUTOFMEMORY;
192 STDMETHODIMP VLCPluginClass::LockServer(BOOL fLock)
202 ////////////////////////////////////////////////////////////////////////
204 VLCPlugin::VLCPlugin(VLCPluginClass *p_class, LPUNKNOWN pUnkOuter) :
217 vlcOleControl = new VLCOleControl(this);
218 vlcOleInPlaceObject = new VLCOleInPlaceObject(this);
219 vlcOleInPlaceActiveObject = new VLCOleInPlaceActiveObject(this);
220 vlcPersistStorage = new VLCPersistStorage(this);
221 vlcPersistStreamInit = new VLCPersistStreamInit(this);
222 vlcPersistPropertyBag = new VLCPersistPropertyBag(this);
223 vlcProvideClassInfo = new VLCProvideClassInfo(this);
224 vlcConnectionPointContainer = new VLCConnectionPointContainer(this);
225 vlcObjectSafety = new VLCObjectSafety(this);
226 vlcControl = new VLCControl(this);
227 vlcControl2 = new VLCControl2(this);
228 vlcViewObject = new VLCViewObject(this);
229 vlcDataObject = new VLCDataObject(this);
230 vlcOleObject = new VLCOleObject(this);
231 vlcSupportErrorInfo = new VLCSupportErrorInfo(this);
233 // configure controlling IUnknown interface for implemented interfaces
234 this->pUnkOuter = (NULL != pUnkOuter) ? pUnkOuter : dynamic_cast<LPUNKNOWN>(this);
237 _p_pict = p_class->getInPlacePict();
239 // make sure that persistable properties are initialized
243 VLCPlugin::~VLCPlugin()
246 ** bump refcount to avoid recursive release from
247 ** following interfaces when releasing this interface
251 delete vlcSupportErrorInfo;
253 delete vlcDataObject;
254 delete vlcViewObject;
257 delete vlcConnectionPointContainer;
258 delete vlcProvideClassInfo;
259 delete vlcPersistPropertyBag;
260 delete vlcPersistStreamInit;
261 delete vlcPersistStorage;
262 delete vlcOleInPlaceActiveObject;
263 delete vlcOleInPlaceObject;
264 delete vlcObjectSafety;
266 delete vlcOleControl;
270 SysFreeString(_bstr_mrl);
271 SysFreeString(_bstr_baseurl);
273 if( _p_mplayer ) { libvlc_media_player_release(_p_mplayer); _p_mplayer=NULL; }
274 if( _p_mlist ) { libvlc_media_list_release(_p_mlist); _p_mlist=NULL; }
275 if( _p_libvlc ) { libvlc_release(_p_libvlc); _p_libvlc=NULL; }
280 STDMETHODIMP VLCPlugin::QueryInterface(REFIID riid, void **ppv)
285 if( IID_IUnknown == riid )
286 *ppv = reinterpret_cast<LPVOID>(this);
287 else if( IID_IOleObject == riid )
288 *ppv = reinterpret_cast<LPVOID>(vlcOleObject);
289 else if( IID_IOleControl == riid )
290 *ppv = reinterpret_cast<LPVOID>(vlcOleControl);
291 else if( IID_IOleWindow == riid )
292 *ppv = reinterpret_cast<LPVOID>(vlcOleInPlaceObject);
293 else if( IID_IOleInPlaceObject == riid )
294 *ppv = reinterpret_cast<LPVOID>(vlcOleInPlaceObject);
295 else if( IID_IOleInPlaceActiveObject == riid )
296 *ppv = reinterpret_cast<LPVOID>(vlcOleInPlaceActiveObject);
297 else if( IID_IPersist == riid )
298 *ppv = reinterpret_cast<LPVOID>(vlcPersistStreamInit);
299 else if( IID_IPersistStreamInit == riid )
300 *ppv = reinterpret_cast<LPVOID>(vlcPersistStreamInit);
301 else if( IID_IPersistStorage == riid )
302 *ppv = reinterpret_cast<LPVOID>(vlcPersistStorage);
303 else if( IID_IPersistPropertyBag == riid )
304 *ppv = reinterpret_cast<LPVOID>(vlcPersistPropertyBag);
305 else if( IID_IProvideClassInfo == riid )
306 *ppv = reinterpret_cast<LPVOID>(vlcProvideClassInfo);
307 else if( IID_IProvideClassInfo2 == riid )
308 *ppv = reinterpret_cast<LPVOID>(vlcProvideClassInfo);
309 else if( IID_IConnectionPointContainer == riid )
310 *ppv = reinterpret_cast<LPVOID>(vlcConnectionPointContainer);
311 else if( IID_IObjectSafety == riid )
312 *ppv = reinterpret_cast<LPVOID>(vlcObjectSafety);
313 else if( IID_IDispatch == riid )
314 *ppv = (CLSID_VLCPlugin2 == getClassID()) ?
315 reinterpret_cast<LPVOID>(vlcControl2) :
316 reinterpret_cast<LPVOID>(vlcControl);
317 else if( IID_IVLCControl == riid )
318 *ppv = reinterpret_cast<LPVOID>(vlcControl);
319 else if( IID_IVLCControl2 == riid )
320 *ppv = reinterpret_cast<LPVOID>(vlcControl2);
321 else if( IID_IViewObject == riid )
322 *ppv = reinterpret_cast<LPVOID>(vlcViewObject);
323 else if( IID_IViewObject2 == riid )
324 *ppv = reinterpret_cast<LPVOID>(vlcViewObject);
325 else if( IID_IDataObject == riid )
326 *ppv = reinterpret_cast<LPVOID>(vlcDataObject);
327 else if( IID_ISupportErrorInfo == riid )
328 *ppv = reinterpret_cast<LPVOID>(vlcSupportErrorInfo);
332 return E_NOINTERFACE;
334 ((LPUNKNOWN)*ppv)->AddRef();
338 STDMETHODIMP_(ULONG) VLCPlugin::AddRef(void)
340 return InterlockedIncrement((LONG *)&_i_ref);
343 STDMETHODIMP_(ULONG) VLCPlugin::Release(void)
345 if( ! InterlockedDecrement((LONG *)&_i_ref) )
353 //////////////////////////////////////
355 HRESULT VLCPlugin::onInit(void)
357 if( NULL == _p_libvlc )
359 // initialize persistable properties
363 _bstr_baseurl = NULL;
370 // set default/preferred size (320x240) pixels in HIMETRIC
371 HDC hDC = CreateDevDC(NULL);
374 HimetricFromDP(hDC, (LPPOINT)&_extent, 1);
379 return CO_E_ALREADYINITIALIZED;
382 HRESULT VLCPlugin::onLoad(void)
384 if( SysStringLen(_bstr_baseurl) == 0 )
387 ** try to retreive the base URL using the client site moniker, which for Internet Explorer
388 ** is the URL of the page the plugin is embedded into.
390 LPOLECLIENTSITE pClientSite;
391 if( SUCCEEDED(vlcOleObject->GetClientSite(&pClientSite)) && (NULL != pClientSite) )
394 if( SUCCEEDED(CreateBindCtx(0, &pBC)) )
396 LPMONIKER pContMoniker = NULL;
397 if( SUCCEEDED(pClientSite->GetMoniker(OLEGETMONIKER_ONLYIFTHERE,
398 OLEWHICHMK_CONTAINER, &pContMoniker)) )
401 if( SUCCEEDED(pContMoniker->GetDisplayName(pBC, NULL, &base_url)) )
404 ** check that the moniker name is a URL
406 if( UrlIsW(base_url, URLIS_URL) )
409 _bstr_baseurl = SysAllocString(base_url);
411 CoTaskMemFree(base_url);
422 void VLCPlugin::initVLC()
424 extern HMODULE DllGetModule();
427 ** default initialization options
429 const char *ppsz_argv[32] = { };
432 char p_progpath[MAX_PATH];
434 TCHAR w_progpath[MAX_PATH];
435 DWORD len = GetModuleFileName(DllGetModule(), w_progpath, MAX_PATH);
438 len = WideCharToMultiByte(CP_UTF8, 0, w_progpath, len, p_progpath,
439 sizeof(p_progpath)-1, NULL, NULL);
442 p_progpath[len] = '\0';
443 ppsz_argv[0] = p_progpath;
448 ppsz_argv[ppsz_argc++] = "-vv";
451 char p_pluginpath[MAX_PATH];
452 if( RegOpenKeyEx( HKEY_LOCAL_MACHINE, TEXT("Software\\VideoLAN\\VLC"),
453 0, KEY_READ, &h_key ) == ERROR_SUCCESS )
455 DWORD i_type, i_data = MAX_PATH;
456 TCHAR w_pluginpath[MAX_PATH];
457 if( RegQueryValueEx( h_key, TEXT("InstallDir"), 0, &i_type,
458 (LPBYTE)w_pluginpath, &i_data ) == ERROR_SUCCESS )
460 if( i_type == REG_SZ )
462 if( WideCharToMultiByte(CP_UTF8, 0, w_pluginpath, -1, p_pluginpath,
463 sizeof(p_pluginpath)-sizeof("\\plugins")+1, NULL, NULL) )
465 strcat( p_pluginpath, "\\plugins" );
466 ppsz_argv[ppsz_argc++] = "--plugin-path";
467 ppsz_argv[ppsz_argc++] = p_pluginpath;
471 RegCloseKey( h_key );
474 // make sure plugin isn't affected with VLC single instance mode
475 ppsz_argv[ppsz_argc++] = "--no-one-instance";
477 /* common settings */
478 ppsz_argv[ppsz_argc++] = "-vv";
479 ppsz_argv[ppsz_argc++] = "--no-stats";
480 ppsz_argv[ppsz_argc++] = "--no-media-library";
481 ppsz_argv[ppsz_argc++] = "--intf=dummy";
482 ppsz_argv[ppsz_argc++] = "--no-video-title-show";
485 // loop mode is a configuration option only
487 ppsz_argv[ppsz_argc++] = "--loop";
489 libvlc_exception_t ex;
490 libvlc_exception_init(&ex);
492 _p_libvlc = libvlc_new(ppsz_argc, ppsz_argv, &ex);
493 if( libvlc_exception_raised(&ex) )
496 _p_mlist = libvlc_media_list_new(_p_libvlc, &ex);
497 if( libvlc_exception_raised(&ex) )
499 libvlc_release(_p_libvlc);
503 // initial volume setting
504 libvlc_audio_set_volume(_p_libvlc, _i_volume, NULL);
507 libvlc_audio_set_mute(_p_libvlc, TRUE);
510 // initial playlist item
511 if( SysStringLen(_bstr_mrl) > 0 )
513 char *psz_mrl = NULL;
515 if( SysStringLen(_bstr_baseurl) > 0 )
518 ** if the MRL a relative URL, we should end up with an absolute URL
520 LPWSTR abs_url = CombineURL(_bstr_baseurl, _bstr_mrl);
521 if( NULL != abs_url )
523 psz_mrl = CStrFromWSTR(CP_UTF8, abs_url, wcslen(abs_url));
524 CoTaskMemFree(abs_url);
528 psz_mrl = CStrFromBSTR(CP_UTF8, _bstr_mrl);
534 ** baseURL is empty, assume MRL is absolute
536 psz_mrl = CStrFromBSTR(CP_UTF8, _bstr_mrl);
538 if( NULL != psz_mrl )
540 const char *options[1];
546 snprintf(timeBuffer, sizeof(timeBuffer), ":start-time=%d", _i_time);
547 options[i_options++] = timeBuffer;
549 // add default target to playlist
550 playlist_add_extended_untrusted(psz_mrl, i_options, options, NULL);
551 CoTaskMemFree(psz_mrl);
556 void VLCPlugin::setErrorInfo(REFIID riid, const char *description)
558 vlcSupportErrorInfo->setErrorInfo( getClassID() == CLSID_VLCPlugin2 ?
559 OLESTR("VideoLAN.VLCPlugin.2") : OLESTR("VideoLAN.VLCPlugin.1"),
563 HRESULT VLCPlugin::onAmbientChanged(LPUNKNOWN pContainer, DISPID dispID)
568 case DISPID_AMBIENT_BACKCOLOR:
571 if( SUCCEEDED(GetObjectProperty(pContainer, dispID, v)) )
573 setBackColor(V_I4(&v));
576 case DISPID_AMBIENT_DISPLAYNAME:
578 case DISPID_AMBIENT_FONT:
580 case DISPID_AMBIENT_FORECOLOR:
582 case DISPID_AMBIENT_LOCALEID:
584 case DISPID_AMBIENT_MESSAGEREFLECT:
586 case DISPID_AMBIENT_SCALEUNITS:
588 case DISPID_AMBIENT_TEXTALIGN:
590 case DISPID_AMBIENT_USERMODE:
593 if( SUCCEEDED(GetObjectProperty(pContainer, dispID, v)) )
595 setUserMode(V_BOOL(&v) != VARIANT_FALSE);
598 case DISPID_AMBIENT_UIDEAD:
600 case DISPID_AMBIENT_SHOWGRABHANDLES:
602 case DISPID_AMBIENT_SHOWHATCHING:
604 case DISPID_AMBIENT_DISPLAYASDEFAULT:
606 case DISPID_AMBIENT_SUPPORTSMNEMONICS:
608 case DISPID_AMBIENT_AUTOCLIP:
610 case DISPID_AMBIENT_APPEARANCE:
612 case DISPID_AMBIENT_CODEPAGE:
615 if( SUCCEEDED(GetObjectProperty(pContainer, dispID, v)) )
617 setCodePage(V_I4(&v));
620 case DISPID_AMBIENT_PALETTE:
622 case DISPID_AMBIENT_CHARSET:
624 case DISPID_AMBIENT_RIGHTTOLEFT:
626 case DISPID_AMBIENT_TOPTOBOTTOM:
630 ** multiple property change, look up the ones we are interested in
634 if( SUCCEEDED(GetObjectProperty(pContainer, DISPID_AMBIENT_USERMODE, v)) )
636 setUserMode(V_BOOL(&v) != VARIANT_FALSE);
640 if( SUCCEEDED(GetObjectProperty(pContainer, DISPID_AMBIENT_CODEPAGE, v)) )
642 setCodePage(V_I4(&v));
649 HRESULT VLCPlugin::onClose(DWORD dwSaveOption)
651 if( isInPlaceActive() )
653 onInPlaceDeactivate();
657 libvlc_instance_t* p_libvlc = _p_libvlc;
660 if( SUCCEEDED(vlcControl2->get_log(&p_log)) )
662 // make sure the log is disabled
663 p_log->put_verbosity(-1);
668 vlcDataObject->onClose();
671 libvlc_release(p_libvlc);
676 BOOL VLCPlugin::isInPlaceActive(void)
678 return (NULL != _inplacewnd);
681 HRESULT VLCPlugin::onActivateInPlace(LPMSG lpMesg, HWND hwndParent, LPCRECT lprcPosRect, LPCRECT lprcClipRect)
683 RECT clipRect = *lprcClipRect;
684 libvlc_exception_t ex;
685 libvlc_exception_init(&ex);
688 ** record keeping of control geometry within container
690 _posRect = *lprcPosRect;
693 ** Create a window for in place activated control.
694 ** the window geometry matches the control viewport
695 ** within container so that embedded video is always
696 ** properly displayed.
698 _inplacewnd = CreateWindow(_p_class->getInPlaceWndClassName(),
699 TEXT("VLC Plugin In-Place Window"),
700 WS_CHILD|WS_CLIPCHILDREN|WS_CLIPSIBLINGS,
703 lprcPosRect->right-lprcPosRect->left,
704 lprcPosRect->bottom-lprcPosRect->top,
707 _p_class->getHInstance(),
711 if( NULL == _inplacewnd )
714 SetWindowLongPtr(_inplacewnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));
716 /* change cliprect coordinates system relative to window bounding rect */
717 OffsetRect(&clipRect, -lprcPosRect->left, -lprcPosRect->top);
719 HRGN clipRgn = CreateRectRgnIndirect(&clipRect);
720 SetWindowRgn(_inplacewnd, clipRgn, TRUE);
724 /* will run vlc if not done already */
725 libvlc_instance_t* p_libvlc;
726 HRESULT result = getVLC(&p_libvlc);
730 if( _b_autoplay && playlist_select(0,NULL) )
732 libvlc_media_player_play(_p_mplayer,NULL);
738 ShowWindow(_inplacewnd, SW_SHOW);
743 HRESULT VLCPlugin::onInPlaceDeactivate(void)
745 if( isPlaying(NULL) )
751 DestroyWindow(_inplacewnd);
757 void VLCPlugin::setVisible(BOOL fVisible)
759 if( fVisible != _b_visible )
761 _b_visible = fVisible;
762 if( isInPlaceActive() )
764 ShowWindow(_inplacewnd, fVisible ? SW_SHOW : SW_HIDE);
766 InvalidateRect(_inplacewnd, NULL, TRUE);
769 firePropChangedEvent(DISPID_Visible);
773 void VLCPlugin::setVolume(int volume)
777 else if( volume > 200 )
780 if( volume != _i_volume )
785 libvlc_audio_set_volume(_p_libvlc, _i_volume, NULL);
791 void VLCPlugin::setBackColor(OLE_COLOR backcolor)
793 if( _i_backcolor != backcolor )
795 _i_backcolor = backcolor;
796 if( isInPlaceActive() )
804 void VLCPlugin::setTime(int seconds)
809 if( seconds != _i_time )
811 setStartTime(_i_time);
812 if( NULL != _p_mplayer )
814 libvlc_media_player_set_time(_p_mplayer, _i_time, NULL);
819 void VLCPlugin::setFocus(BOOL fFocus)
822 SetActiveWindow(_inplacewnd);
825 BOOL VLCPlugin::hasFocus(void)
827 return GetActiveWindow() == _inplacewnd;
830 void VLCPlugin::onDraw(DVTARGETDEVICE * ptd, HDC hicTargetDev,
831 HDC hdcDraw, LPCRECTL lprcBounds, LPCRECTL lprcWBounds)
835 long width = lprcBounds->right-lprcBounds->left;
836 long height = lprcBounds->bottom-lprcBounds->top;
838 RECT bounds = { lprcBounds->left, lprcBounds->top, lprcBounds->right, lprcBounds->bottom };
842 /* VLC is in user mode, just draw background color */
843 COLORREF colorref = RGB(0, 0, 0);
844 OleTranslateColor(_i_backcolor, (HPALETTE)GetStockObject(DEFAULT_PALETTE), &colorref);
845 if( colorref != RGB(0, 0, 0) )
847 /* custom background */
848 HBRUSH colorbrush = CreateSolidBrush(colorref);
849 FillRect(hdcDraw, &bounds, colorbrush);
850 DeleteObject((HANDLE)colorbrush);
854 /* black background */
855 FillRect(hdcDraw, &bounds, (HBRUSH)GetStockObject(BLACK_BRUSH));
860 /* VLC is in design mode, draw the VLC logo */
861 FillRect(hdcDraw, &bounds, (HBRUSH)GetStockObject(WHITE_BRUSH));
863 LPPICTURE pict = getPicture();
866 OLE_XSIZE_HIMETRIC picWidth;
867 OLE_YSIZE_HIMETRIC picHeight;
869 pict->get_Width(&picWidth);
870 pict->get_Height(&picHeight);
872 SIZEL picSize = { picWidth, picHeight };
874 if( NULL != hicTargetDev )
876 DPFromHimetric(hicTargetDev, (LPPOINT)&picSize, 1);
878 else if( NULL != (hicTargetDev = CreateDevDC(ptd)) )
880 DPFromHimetric(hicTargetDev, (LPPOINT)&picSize, 1);
881 DeleteDC(hicTargetDev);
884 if( picSize.cx > width-4 )
885 picSize.cx = width-4;
886 if( picSize.cy > height-4 )
887 picSize.cy = height-4;
889 LONG dstX = lprcBounds->left+(width-picSize.cx)/2;
890 LONG dstY = lprcBounds->top+(height-picSize.cy)/2;
892 if( NULL != lprcWBounds )
894 RECT wBounds = { lprcWBounds->left, lprcWBounds->top, lprcWBounds->right, lprcWBounds->bottom };
895 pict->Render(hdcDraw, dstX, dstY, picSize.cx, picSize.cy,
896 0L, picHeight, picWidth, -picHeight, &wBounds);
899 pict->Render(hdcDraw, dstX, dstY, picSize.cx, picSize.cy,
900 0L, picHeight, picWidth, -picHeight, NULL);
905 SelectObject(hdcDraw, GetStockObject(BLACK_BRUSH));
907 MoveToEx(hdcDraw, bounds.left, bounds.top, NULL);
908 LineTo(hdcDraw, bounds.left+width-1, bounds.top);
909 LineTo(hdcDraw, bounds.left+width-1, bounds.top+height-1);
910 LineTo(hdcDraw, bounds.left, bounds.top+height-1);
911 LineTo(hdcDraw, bounds.left, bounds.top);
916 void VLCPlugin::onPaint(HDC hdc, const RECT &bounds, const RECT &clipRect)
920 /* if VLC is in design mode, draw control logo */
921 HDC hdcDraw = CreateCompatibleDC(hdc);
922 if( NULL != hdcDraw )
924 SIZEL size = getExtent();
925 DPFromHimetric(hdc, (LPPOINT)&size, 1);
926 RECTL posRect = { 0, 0, size.cx, size.cy };
928 int width = bounds.right-bounds.left;
929 int height = bounds.bottom-bounds.top;
931 HBITMAP hBitmap = CreateCompatibleBitmap(hdc, width, height);
932 if( NULL != hBitmap )
934 HBITMAP oldBmp = (HBITMAP)SelectObject(hdcDraw, hBitmap);
936 if( (size.cx != width) || (size.cy != height) )
938 // needs to scale canvas
939 SetMapMode(hdcDraw, MM_ANISOTROPIC);
940 SetWindowExtEx(hdcDraw, size.cx, size.cy, NULL);
941 SetViewportExtEx(hdcDraw, width, height, NULL);
944 onDraw(NULL, hdc, hdcDraw, &posRect, NULL);
946 SetMapMode(hdcDraw, MM_TEXT);
947 BitBlt(hdc, bounds.left, bounds.top,
952 SelectObject(hdcDraw, oldBmp);
953 DeleteObject(hBitmap);
960 void VLCPlugin::onPositionChange(LPCRECT lprcPosRect, LPCRECT lprcClipRect)
962 RECT clipRect = *lprcClipRect;
964 //RedrawWindow(GetParent(_inplacewnd), &_posRect, NULL, RDW_INVALIDATE|RDW_ERASE|RDW_ALLCHILDREN);
967 ** record keeping of control geometry within container
969 _posRect = *lprcPosRect;
972 ** change in-place window geometry to match clipping region
974 SetWindowPos(_inplacewnd, NULL,
977 lprcPosRect->right-lprcPosRect->left,
978 lprcPosRect->bottom-lprcPosRect->top,
984 /* change cliprect coordinates system relative to window bounding rect */
985 OffsetRect(&clipRect, -lprcPosRect->left, -lprcPosRect->top);
986 HRGN clipRgn = CreateRectRgnIndirect(&clipRect);
987 SetWindowRgn(_inplacewnd, clipRgn, FALSE);
989 //RedrawWindow(_videownd, &posRect, NULL, RDW_INVALIDATE|RDW_ERASE|RDW_ALLCHILDREN);
992 void VLCPlugin::freezeEvents(BOOL freeze)
994 vlcConnectionPointContainer->freezeEvents(freeze);
997 void VLCPlugin::firePropChangedEvent(DISPID dispid)
999 vlcConnectionPointContainer->firePropChangedEvent(dispid);
1002 void VLCPlugin::fireOnPlayEvent(void)
1004 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1005 vlcConnectionPointContainer->fireEvent(DISPID_PlayEvent, &dispparamsNoArgs);
1008 void VLCPlugin::fireOnPauseEvent(void)
1010 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1011 vlcConnectionPointContainer->fireEvent(DISPID_PauseEvent, &dispparamsNoArgs);
1014 void VLCPlugin::fireOnStopEvent(void)
1016 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1017 vlcConnectionPointContainer->fireEvent(DISPID_StopEvent, &dispparamsNoArgs);
1020 bool VLCPlugin::playlist_select( int idx, libvlc_exception_t *ex )
1022 libvlc_media_t *p_m = NULL;
1024 libvlc_media_list_lock(_p_mlist);
1026 int count = libvlc_media_list_count(_p_mlist,ex);
1027 if( libvlc_exception_raised(ex) )
1030 if( idx<0||idx>=count )
1035 p_m = libvlc_media_list_item_at_index(_p_mlist,_i_midx,ex);
1036 libvlc_media_list_unlock(_p_mlist);
1038 if( libvlc_exception_raised(ex) )
1043 libvlc_media_player_release( _p_mplayer );
1047 _p_mplayer = libvlc_media_player_new_from_media(p_m,ex);
1049 set_player_window(ex);
1051 libvlc_media_release( p_m );
1052 return !libvlc_exception_raised(ex);
1055 libvlc_media_list_unlock(_p_mlist);
1059 void VLCPlugin::set_player_window(libvlc_exception_t *ex)
1061 // XXX FIXME no idea if this is correct or not
1062 libvlc_media_player_set_hwnd(_p_mplayer,getInPlaceWindow(),ex);
1065 int VLCPlugin::playlist_add_extended_untrusted(const char *mrl, int optc, const char **optv, libvlc_exception_t *ex)
1068 libvlc_media_t *p_m = libvlc_media_new(_p_libvlc,mrl,ex);
1069 if( libvlc_exception_raised(ex) )
1072 for( int i = 0; i < optc; ++i )
1073 libvlc_media_add_option_flag(p_m, optv[i], libvlc_media_option_unique);
1075 libvlc_media_list_lock(_p_mlist);
1076 libvlc_media_list_add_media(_p_mlist,p_m,ex);
1077 if( !libvlc_exception_raised(ex) )
1078 item = libvlc_media_list_count(_p_mlist,ex)-1;
1079 libvlc_media_list_unlock(_p_mlist);
1080 libvlc_media_release(p_m);