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++] = "--no-stats";
479 ppsz_argv[ppsz_argc++] = "--no-media-library";
480 ppsz_argv[ppsz_argc++] = "--ignore-config";
481 ppsz_argv[ppsz_argc++] = "--intf=dummy";
483 // loop mode is a configuration option only
485 ppsz_argv[ppsz_argc++] = "--loop";
487 libvlc_exception_t ex;
488 libvlc_exception_init(&ex);
490 _p_libvlc = libvlc_new(ppsz_argc, ppsz_argv, &ex);
491 if( libvlc_exception_raised(&ex) )
494 _p_mlist = libvlc_media_list_new(_p_libvlc, &ex);
495 if( libvlc_exception_raised(&ex) )
497 libvlc_release(_p_libvlc);
501 // initial volume setting
502 libvlc_audio_set_volume(_p_libvlc, _i_volume, NULL);
505 libvlc_audio_set_mute(_p_libvlc, TRUE, NULL);
508 // initial playlist item
509 if( SysStringLen(_bstr_mrl) > 0 )
511 char *psz_mrl = NULL;
513 if( SysStringLen(_bstr_baseurl) > 0 )
516 ** if the MRL a relative URL, we should end up with an absolute URL
518 LPWSTR abs_url = CombineURL(_bstr_baseurl, _bstr_mrl);
519 if( NULL != abs_url )
521 psz_mrl = CStrFromWSTR(CP_UTF8, abs_url, wcslen(abs_url));
522 CoTaskMemFree(abs_url);
526 psz_mrl = CStrFromBSTR(CP_UTF8, _bstr_mrl);
532 ** baseURL is empty, assume MRL is absolute
534 psz_mrl = CStrFromBSTR(CP_UTF8, _bstr_mrl);
536 if( NULL != psz_mrl )
538 const char *options[1];
544 snprintf(timeBuffer, sizeof(timeBuffer), ":start-time=%d", _i_time);
545 options[i_options++] = timeBuffer;
547 // add default target to playlist
548 playlist_add_extended_untrusted(psz_mrl, i_options, options, NULL);
549 CoTaskMemFree(psz_mrl);
554 void VLCPlugin::setErrorInfo(REFIID riid, const char *description)
556 vlcSupportErrorInfo->setErrorInfo( getClassID() == CLSID_VLCPlugin2 ?
557 OLESTR("VideoLAN.VLCPlugin.2") : OLESTR("VideoLAN.VLCPlugin.1"),
561 HRESULT VLCPlugin::onAmbientChanged(LPUNKNOWN pContainer, DISPID dispID)
566 case DISPID_AMBIENT_BACKCOLOR:
569 if( SUCCEEDED(GetObjectProperty(pContainer, dispID, v)) )
571 setBackColor(V_I4(&v));
574 case DISPID_AMBIENT_DISPLAYNAME:
576 case DISPID_AMBIENT_FONT:
578 case DISPID_AMBIENT_FORECOLOR:
580 case DISPID_AMBIENT_LOCALEID:
582 case DISPID_AMBIENT_MESSAGEREFLECT:
584 case DISPID_AMBIENT_SCALEUNITS:
586 case DISPID_AMBIENT_TEXTALIGN:
588 case DISPID_AMBIENT_USERMODE:
591 if( SUCCEEDED(GetObjectProperty(pContainer, dispID, v)) )
593 setUserMode(V_BOOL(&v) != VARIANT_FALSE);
596 case DISPID_AMBIENT_UIDEAD:
598 case DISPID_AMBIENT_SHOWGRABHANDLES:
600 case DISPID_AMBIENT_SHOWHATCHING:
602 case DISPID_AMBIENT_DISPLAYASDEFAULT:
604 case DISPID_AMBIENT_SUPPORTSMNEMONICS:
606 case DISPID_AMBIENT_AUTOCLIP:
608 case DISPID_AMBIENT_APPEARANCE:
610 case DISPID_AMBIENT_CODEPAGE:
613 if( SUCCEEDED(GetObjectProperty(pContainer, dispID, v)) )
615 setCodePage(V_I4(&v));
618 case DISPID_AMBIENT_PALETTE:
620 case DISPID_AMBIENT_CHARSET:
622 case DISPID_AMBIENT_RIGHTTOLEFT:
624 case DISPID_AMBIENT_TOPTOBOTTOM:
628 ** multiple property change, look up the ones we are interested in
632 if( SUCCEEDED(GetObjectProperty(pContainer, DISPID_AMBIENT_USERMODE, v)) )
634 setUserMode(V_BOOL(&v) != VARIANT_FALSE);
638 if( SUCCEEDED(GetObjectProperty(pContainer, DISPID_AMBIENT_CODEPAGE, v)) )
640 setCodePage(V_I4(&v));
647 HRESULT VLCPlugin::onClose(DWORD dwSaveOption)
649 if( isInPlaceActive() )
651 onInPlaceDeactivate();
655 libvlc_instance_t* p_libvlc = _p_libvlc;
658 if( SUCCEEDED(vlcControl2->get_log(&p_log)) )
660 // make sure the log is disabled
661 p_log->put_verbosity(-1);
666 vlcDataObject->onClose();
669 libvlc_release(p_libvlc);
674 BOOL VLCPlugin::isInPlaceActive(void)
676 return (NULL != _inplacewnd);
679 HRESULT VLCPlugin::onActivateInPlace(LPMSG lpMesg, HWND hwndParent, LPCRECT lprcPosRect, LPCRECT lprcClipRect)
681 RECT clipRect = *lprcClipRect;
682 libvlc_exception_t ex;
683 libvlc_exception_init(&ex);
686 ** record keeping of control geometry within container
688 _posRect = *lprcPosRect;
691 ** Create a window for in place activated control.
692 ** the window geometry matches the control viewport
693 ** within container so that embedded video is always
694 ** properly displayed.
696 _inplacewnd = CreateWindow(_p_class->getInPlaceWndClassName(),
697 TEXT("VLC Plugin In-Place Window"),
698 WS_CHILD|WS_CLIPCHILDREN|WS_CLIPSIBLINGS,
701 lprcPosRect->right-lprcPosRect->left,
702 lprcPosRect->bottom-lprcPosRect->top,
705 _p_class->getHInstance(),
709 if( NULL == _inplacewnd )
712 SetWindowLongPtr(_inplacewnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));
714 /* change cliprect coordinates system relative to window bounding rect */
715 OffsetRect(&clipRect, -lprcPosRect->left, -lprcPosRect->top);
717 HRGN clipRgn = CreateRectRgnIndirect(&clipRect);
718 SetWindowRgn(_inplacewnd, clipRgn, TRUE);
722 /* will run vlc if not done already */
723 libvlc_instance_t* p_libvlc;
724 HRESULT result = getVLC(&p_libvlc);
728 if( _b_autoplay && playlist_select(0,NULL) )
730 libvlc_media_player_play(_p_mplayer,NULL);
736 ShowWindow(_inplacewnd, SW_SHOW);
741 HRESULT VLCPlugin::onInPlaceDeactivate(void)
743 if( isPlaying(NULL) )
749 DestroyWindow(_inplacewnd);
755 void VLCPlugin::setVisible(BOOL fVisible)
757 if( fVisible != _b_visible )
759 _b_visible = fVisible;
760 if( isInPlaceActive() )
762 ShowWindow(_inplacewnd, fVisible ? SW_SHOW : SW_HIDE);
764 InvalidateRect(_inplacewnd, NULL, TRUE);
767 firePropChangedEvent(DISPID_Visible);
771 void VLCPlugin::setVolume(int volume)
775 else if( volume > 200 )
778 if( volume != _i_volume )
783 libvlc_audio_set_volume(_p_libvlc, _i_volume, NULL);
789 void VLCPlugin::setBackColor(OLE_COLOR backcolor)
791 if( _i_backcolor != backcolor )
793 _i_backcolor = backcolor;
794 if( isInPlaceActive() )
802 void VLCPlugin::setTime(int seconds)
807 if( seconds != _i_time )
809 setStartTime(_i_time);
810 if( NULL != _p_mplayer )
812 libvlc_media_player_set_time(_p_mplayer, _i_time, NULL);
817 void VLCPlugin::setFocus(BOOL fFocus)
820 SetActiveWindow(_inplacewnd);
823 BOOL VLCPlugin::hasFocus(void)
825 return GetActiveWindow() == _inplacewnd;
828 void VLCPlugin::onDraw(DVTARGETDEVICE * ptd, HDC hicTargetDev,
829 HDC hdcDraw, LPCRECTL lprcBounds, LPCRECTL lprcWBounds)
833 long width = lprcBounds->right-lprcBounds->left;
834 long height = lprcBounds->bottom-lprcBounds->top;
836 RECT bounds = { lprcBounds->left, lprcBounds->top, lprcBounds->right, lprcBounds->bottom };
840 /* VLC is in user mode, just draw background color */
841 COLORREF colorref = RGB(0, 0, 0);
842 OleTranslateColor(_i_backcolor, (HPALETTE)GetStockObject(DEFAULT_PALETTE), &colorref);
843 if( colorref != RGB(0, 0, 0) )
845 /* custom background */
846 HBRUSH colorbrush = CreateSolidBrush(colorref);
847 FillRect(hdcDraw, &bounds, colorbrush);
848 DeleteObject((HANDLE)colorbrush);
852 /* black background */
853 FillRect(hdcDraw, &bounds, (HBRUSH)GetStockObject(BLACK_BRUSH));
858 /* VLC is in design mode, draw the VLC logo */
859 FillRect(hdcDraw, &bounds, (HBRUSH)GetStockObject(WHITE_BRUSH));
861 LPPICTURE pict = getPicture();
864 OLE_XSIZE_HIMETRIC picWidth;
865 OLE_YSIZE_HIMETRIC picHeight;
867 pict->get_Width(&picWidth);
868 pict->get_Height(&picHeight);
870 SIZEL picSize = { picWidth, picHeight };
872 if( NULL != hicTargetDev )
874 DPFromHimetric(hicTargetDev, (LPPOINT)&picSize, 1);
876 else if( NULL != (hicTargetDev = CreateDevDC(ptd)) )
878 DPFromHimetric(hicTargetDev, (LPPOINT)&picSize, 1);
879 DeleteDC(hicTargetDev);
882 if( picSize.cx > width-4 )
883 picSize.cx = width-4;
884 if( picSize.cy > height-4 )
885 picSize.cy = height-4;
887 LONG dstX = lprcBounds->left+(width-picSize.cx)/2;
888 LONG dstY = lprcBounds->top+(height-picSize.cy)/2;
890 if( NULL != lprcWBounds )
892 RECT wBounds = { lprcWBounds->left, lprcWBounds->top, lprcWBounds->right, lprcWBounds->bottom };
893 pict->Render(hdcDraw, dstX, dstY, picSize.cx, picSize.cy,
894 0L, picHeight, picWidth, -picHeight, &wBounds);
897 pict->Render(hdcDraw, dstX, dstY, picSize.cx, picSize.cy,
898 0L, picHeight, picWidth, -picHeight, NULL);
903 SelectObject(hdcDraw, GetStockObject(BLACK_BRUSH));
905 MoveToEx(hdcDraw, bounds.left, bounds.top, NULL);
906 LineTo(hdcDraw, bounds.left+width-1, bounds.top);
907 LineTo(hdcDraw, bounds.left+width-1, bounds.top+height-1);
908 LineTo(hdcDraw, bounds.left, bounds.top+height-1);
909 LineTo(hdcDraw, bounds.left, bounds.top);
914 void VLCPlugin::onPaint(HDC hdc, const RECT &bounds, const RECT &clipRect)
918 /* if VLC is in design mode, draw control logo */
919 HDC hdcDraw = CreateCompatibleDC(hdc);
920 if( NULL != hdcDraw )
922 SIZEL size = getExtent();
923 DPFromHimetric(hdc, (LPPOINT)&size, 1);
924 RECTL posRect = { 0, 0, size.cx, size.cy };
926 int width = bounds.right-bounds.left;
927 int height = bounds.bottom-bounds.top;
929 HBITMAP hBitmap = CreateCompatibleBitmap(hdc, width, height);
930 if( NULL != hBitmap )
932 HBITMAP oldBmp = (HBITMAP)SelectObject(hdcDraw, hBitmap);
934 if( (size.cx != width) || (size.cy != height) )
936 // needs to scale canvas
937 SetMapMode(hdcDraw, MM_ANISOTROPIC);
938 SetWindowExtEx(hdcDraw, size.cx, size.cy, NULL);
939 SetViewportExtEx(hdcDraw, width, height, NULL);
942 onDraw(NULL, hdc, hdcDraw, &posRect, NULL);
944 SetMapMode(hdcDraw, MM_TEXT);
945 BitBlt(hdc, bounds.left, bounds.top,
950 SelectObject(hdcDraw, oldBmp);
951 DeleteObject(hBitmap);
958 void VLCPlugin::onPositionChange(LPCRECT lprcPosRect, LPCRECT lprcClipRect)
960 RECT clipRect = *lprcClipRect;
962 //RedrawWindow(GetParent(_inplacewnd), &_posRect, NULL, RDW_INVALIDATE|RDW_ERASE|RDW_ALLCHILDREN);
965 ** record keeping of control geometry within container
967 _posRect = *lprcPosRect;
970 ** change in-place window geometry to match clipping region
972 SetWindowPos(_inplacewnd, NULL,
975 lprcPosRect->right-lprcPosRect->left,
976 lprcPosRect->bottom-lprcPosRect->top,
982 /* change cliprect coordinates system relative to window bounding rect */
983 OffsetRect(&clipRect, -lprcPosRect->left, -lprcPosRect->top);
984 HRGN clipRgn = CreateRectRgnIndirect(&clipRect);
985 SetWindowRgn(_inplacewnd, clipRgn, FALSE);
987 //RedrawWindow(_videownd, &posRect, NULL, RDW_INVALIDATE|RDW_ERASE|RDW_ALLCHILDREN);
990 void VLCPlugin::freezeEvents(BOOL freeze)
992 vlcConnectionPointContainer->freezeEvents(freeze);
995 void VLCPlugin::firePropChangedEvent(DISPID dispid)
997 vlcConnectionPointContainer->firePropChangedEvent(dispid);
1000 void VLCPlugin::fireOnPlayEvent(void)
1002 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1003 vlcConnectionPointContainer->fireEvent(DISPID_PlayEvent, &dispparamsNoArgs);
1006 void VLCPlugin::fireOnPauseEvent(void)
1008 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1009 vlcConnectionPointContainer->fireEvent(DISPID_PauseEvent, &dispparamsNoArgs);
1012 void VLCPlugin::fireOnStopEvent(void)
1014 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1015 vlcConnectionPointContainer->fireEvent(DISPID_StopEvent, &dispparamsNoArgs);
1018 bool VLCPlugin::playlist_select( int idx, libvlc_exception_t *ex )
1020 libvlc_media_t *p_m = NULL;
1022 libvlc_media_list_lock(_p_mlist);
1024 int count = libvlc_media_list_count(_p_mlist,ex);
1025 if( libvlc_exception_raised(ex) )
1028 if( idx<0||idx>=count )
1033 p_m = libvlc_media_list_item_at_index(_p_mlist,_i_midx,ex);
1034 libvlc_media_list_unlock(_p_mlist);
1036 if( libvlc_exception_raised(ex) )
1041 libvlc_media_player_release( _p_mplayer );
1045 _p_mplayer = libvlc_media_player_new_from_media(p_m,ex);
1047 set_player_window(ex);
1049 libvlc_media_release( p_m );
1050 return !libvlc_exception_raised(ex);
1053 libvlc_media_list_unlock(_p_mlist);
1057 void VLCPlugin::set_player_window(libvlc_exception_t *ex)
1059 // XXX FIXME no idea if this is correct or not
1060 libvlc_media_player_set_hwnd(_p_mplayer,getInPlaceWindow(),ex);
1063 int VLCPlugin::playlist_add_extended_untrusted(const char *mrl, int optc, const char **optv, libvlc_exception_t *ex)
1066 libvlc_media_t *p_m = libvlc_media_new(_p_libvlc,mrl,ex);
1067 if( libvlc_exception_raised(ex) )
1070 for( int i = 0; i < optc; ++i )
1072 libvlc_media_add_option_flag(p_m, optv[i], libvlc_media_option_unique, ex);
1073 if( libvlc_exception_raised(ex) )
1075 libvlc_media_release(p_m);
1080 libvlc_media_list_lock(_p_mlist);
1081 libvlc_media_list_add_media(_p_mlist,p_m,ex);
1082 if( !libvlc_exception_raised(ex) )
1083 item = libvlc_media_list_count(_p_mlist,ex)-1;
1084 libvlc_media_list_unlock(_p_mlist);
1085 libvlc_media_release(p_m);