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 // {E23FE9C6-778E-49d4-B537-38FCDE4887D8}
55 //const GUID CLSID_VLCPlugin =
56 // { 0xe23fe9c6, 0x778e, 0x49d4, { 0xb5, 0x37, 0x38, 0xfc, 0xde, 0x48, 0x87, 0xd8 } };
58 static LRESULT CALLBACK VLCInPlaceClassWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
66 if( GetUpdateRect(hWnd, NULL, FALSE) )
68 BeginPaint(hWnd, &ps);
74 return DefWindowProc(hWnd, uMsg, wParam, lParam);
78 static LRESULT CALLBACK VLCVideoClassWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
79 VLCPlugin *p_instance = reinterpret_cast<VLCPlugin *>(GetWindowLongPtr(hWnd, GWLP_USERDATA));
89 if( GetUpdateRect(hWnd, &pr, FALSE) )
92 GetClientRect(hWnd, &bounds);
93 BeginPaint(hWnd, &ps);
94 p_instance->onPaint(ps.hdc, bounds, pr);
100 return DefWindowProc(hWnd, uMsg, wParam, lParam);
104 VLCPluginClass::VLCPluginClass(LONG *p_class_ref, HINSTANCE hInstance, REFCLSID rclsid) :
105 _p_class_ref(p_class_ref),
106 _hinstance(hInstance),
108 _inplace_picture(NULL)
112 if( ! GetClassInfo(hInstance, getInPlaceWndClassName(), &wClass) )
114 wClass.style = CS_NOCLOSE|CS_DBLCLKS;
115 wClass.lpfnWndProc = VLCInPlaceClassWndProc;
116 wClass.cbClsExtra = 0;
117 wClass.cbWndExtra = 0;
118 wClass.hInstance = hInstance;
120 wClass.hCursor = LoadCursor(NULL, IDC_ARROW);
121 wClass.hbrBackground = NULL;
122 wClass.lpszMenuName = NULL;
123 wClass.lpszClassName = getInPlaceWndClassName();
125 _inplace_wndclass_atom = RegisterClass(&wClass);
129 _inplace_wndclass_atom = 0;
132 if( ! GetClassInfo(hInstance, getVideoWndClassName(), &wClass) )
134 wClass.style = CS_NOCLOSE;
135 wClass.lpfnWndProc = VLCVideoClassWndProc;
136 wClass.cbClsExtra = 0;
137 wClass.cbWndExtra = 0;
138 wClass.hInstance = hInstance;
140 wClass.hCursor = LoadCursor(NULL, IDC_ARROW);
141 wClass.hbrBackground = NULL;
142 wClass.lpszMenuName = NULL;
143 wClass.lpszClassName = getVideoWndClassName();
145 _video_wndclass_atom = RegisterClass(&wClass);
149 _video_wndclass_atom = 0;
152 HBITMAP hbitmap = (HBITMAP)LoadImage(getHInstance(), TEXT("INPLACE-PICT"), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
153 if( NULL != hbitmap )
157 pictDesc.cbSizeofstruct = sizeof(PICTDESC);
158 pictDesc.picType = PICTYPE_BITMAP;
159 pictDesc.bmp.hbitmap = hbitmap;
160 pictDesc.bmp.hpal = NULL;
162 if( FAILED(OleCreatePictureIndirect(&pictDesc, IID_IPicture, TRUE, reinterpret_cast<LPVOID*>(&_inplace_picture))) )
163 _inplace_picture = NULL;
168 VLCPluginClass::~VLCPluginClass()
170 if( 0 != _inplace_wndclass_atom )
171 UnregisterClass(MAKEINTATOM(_inplace_wndclass_atom), _hinstance);
173 if( 0 != _video_wndclass_atom )
174 UnregisterClass(MAKEINTATOM(_video_wndclass_atom), _hinstance);
176 if( NULL != _inplace_picture )
177 _inplace_picture->Release();
180 STDMETHODIMP VLCPluginClass::QueryInterface(REFIID riid, void **ppv)
185 if( (IID_IUnknown == riid)
186 || (IID_IClassFactory == riid) )
189 *ppv = reinterpret_cast<LPVOID>(this);
196 return E_NOINTERFACE;
199 STDMETHODIMP_(ULONG) VLCPluginClass::AddRef(void)
201 return InterlockedIncrement(_p_class_ref);
204 STDMETHODIMP_(ULONG) VLCPluginClass::Release(void)
206 ULONG refcount = InterlockedDecrement(_p_class_ref);
215 STDMETHODIMP VLCPluginClass::CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, void **ppv)
222 if( (NULL != pUnkOuter) && (IID_IUnknown != riid) ) {
223 return CLASS_E_NOAGGREGATION;
226 VLCPlugin *plugin = new VLCPlugin(this, pUnkOuter);
229 HRESULT hr = plugin->QueryInterface(riid, ppv);
233 return E_OUTOFMEMORY;
236 STDMETHODIMP VLCPluginClass::LockServer(BOOL fLock)
246 ////////////////////////////////////////////////////////////////////////
248 VLCPlugin::VLCPlugin(VLCPluginClass *p_class, LPUNKNOWN pUnkOuter) :
259 vlcOleControl = new VLCOleControl(this);
260 vlcOleInPlaceObject = new VLCOleInPlaceObject(this);
261 vlcOleInPlaceActiveObject = new VLCOleInPlaceActiveObject(this);
262 vlcPersistStorage = new VLCPersistStorage(this);
263 vlcPersistStreamInit = new VLCPersistStreamInit(this);
264 vlcPersistPropertyBag = new VLCPersistPropertyBag(this);
265 vlcProvideClassInfo = new VLCProvideClassInfo(this);
266 vlcConnectionPointContainer = new VLCConnectionPointContainer(this);
267 vlcObjectSafety = new VLCObjectSafety(this);
268 vlcControl = new VLCControl(this);
269 vlcControl2 = new VLCControl2(this);
270 vlcViewObject = new VLCViewObject(this);
271 vlcDataObject = new VLCDataObject(this);
272 vlcOleObject = new VLCOleObject(this);
274 // configure controlling IUnknown interface for implemented interfaces
275 this->pUnkOuter = (NULL != pUnkOuter) ? pUnkOuter : dynamic_cast<LPUNKNOWN>(this);
278 _p_pict = p_class->getInPlacePict();
280 // make sure that persistable properties are initialized
284 VLCPlugin::~VLCPlugin()
287 delete vlcDataObject;
288 delete vlcViewObject;
291 delete vlcConnectionPointContainer;
292 delete vlcProvideClassInfo;
293 delete vlcPersistPropertyBag;
294 delete vlcPersistStreamInit;
295 delete vlcPersistStorage;
296 delete vlcOleInPlaceActiveObject;
297 delete vlcOleInPlaceObject;
298 delete vlcObjectSafety;
300 delete vlcOleControl;
304 SysFreeString(_bstr_mrl);
309 STDMETHODIMP VLCPlugin::QueryInterface(REFIID riid, void **ppv)
314 if( IID_IUnknown == riid )
315 *ppv = reinterpret_cast<LPVOID>(this);
316 else if( IID_IOleObject == riid )
317 *ppv = reinterpret_cast<LPVOID>(vlcOleObject);
318 else if( IID_IOleControl == riid )
319 *ppv = reinterpret_cast<LPVOID>(vlcOleControl);
320 else if( IID_IOleWindow == riid )
321 *ppv = reinterpret_cast<LPVOID>(vlcOleInPlaceObject);
322 else if( IID_IOleInPlaceObject == riid )
323 *ppv = reinterpret_cast<LPVOID>(vlcOleInPlaceObject);
324 else if( IID_IOleInPlaceActiveObject == riid )
325 *ppv = reinterpret_cast<LPVOID>(vlcOleInPlaceActiveObject);
326 else if( IID_IPersist == riid )
327 *ppv = reinterpret_cast<LPVOID>(vlcPersistStreamInit);
328 else if( IID_IPersistStreamInit == riid )
329 *ppv = reinterpret_cast<LPVOID>(vlcPersistStreamInit);
330 else if( IID_IPersistStorage == riid )
331 *ppv = reinterpret_cast<LPVOID>(vlcPersistStorage);
332 else if( IID_IPersistPropertyBag == riid )
333 *ppv = reinterpret_cast<LPVOID>(vlcPersistPropertyBag);
334 else if( IID_IProvideClassInfo == riid )
335 *ppv = reinterpret_cast<LPVOID>(vlcProvideClassInfo);
336 else if( IID_IProvideClassInfo2 == riid )
337 *ppv = reinterpret_cast<LPVOID>(vlcProvideClassInfo);
338 else if( IID_IConnectionPointContainer == riid )
339 *ppv = reinterpret_cast<LPVOID>(vlcConnectionPointContainer);
340 else if( IID_IObjectSafety == riid )
341 *ppv = reinterpret_cast<LPVOID>(vlcObjectSafety);
342 else if( IID_IDispatch == riid )
343 *ppv = reinterpret_cast<LPVOID>(vlcControl);
344 else if( IID_IVLCControl == riid )
345 *ppv = reinterpret_cast<LPVOID>(vlcControl);
346 else if( IID_IVLCControl2 == riid )
347 *ppv = reinterpret_cast<LPVOID>(vlcControl2);
348 else if( IID_IViewObject == riid )
349 *ppv = reinterpret_cast<LPVOID>(vlcViewObject);
350 else if( IID_IViewObject2 == riid )
351 *ppv = reinterpret_cast<LPVOID>(vlcViewObject);
352 else if( IID_IDataObject == riid )
353 *ppv = reinterpret_cast<LPVOID>(vlcDataObject);
357 return E_NOINTERFACE;
359 ((LPUNKNOWN)*ppv)->AddRef();
363 STDMETHODIMP_(ULONG) VLCPlugin::AddRef(void)
365 return InterlockedIncrement((LONG *)&_i_ref);
368 STDMETHODIMP_(ULONG) VLCPlugin::Release(void)
370 if( ! InterlockedDecrement((LONG *)&_i_ref) )
378 //////////////////////////////////////
381 ** we use a window to represent plugin viewport,
382 ** whose geometry is limited by the clipping rectangle
383 ** all drawing within this window must follow must
384 ** follow coordinates system described in lprPosRect
387 static void getViewportCoords(LPRECT lprPosRect, LPRECT lprClipRect)
390 bounds.right = lprPosRect->right-lprPosRect->left;
392 if( lprClipRect->left <= lprPosRect->left )
394 // left side is not clipped out
397 if( lprClipRect->right >= lprPosRect->right )
399 // right side is not clipped out, no change
401 else if( lprClipRect->right >= lprPosRect->left )
403 // right side is clipped out
404 lprPosRect->right = lprClipRect->right;
408 // outside of clipping rectange, not visible
409 lprPosRect->right = lprPosRect->left;
414 // left side is clipped out
415 bounds.left = lprPosRect->left-lprClipRect->left;
416 bounds.right += bounds.left;
418 lprPosRect->left = lprClipRect->left;
419 if( lprClipRect->right >= lprPosRect->right )
421 // right side is not clipped out
425 // right side is clipped out
426 lprPosRect->right = lprClipRect->right;
430 bounds.bottom = lprPosRect->bottom-lprPosRect->top;
432 if( lprClipRect->top <= lprPosRect->top )
434 // top side is not clipped out
437 if( lprClipRect->bottom >= lprPosRect->bottom )
439 // bottom side is not clipped out, no change
441 else if( lprClipRect->bottom >= lprPosRect->top )
443 // bottom side is clipped out
444 lprPosRect->bottom = lprClipRect->bottom;
448 // outside of clipping rectange, not visible
449 lprPosRect->right = lprPosRect->left;
454 bounds.top = lprPosRect->top-lprClipRect->top;
455 bounds.bottom += bounds.top;
457 lprPosRect->top = lprClipRect->top;
458 if( lprClipRect->bottom >= lprPosRect->bottom )
460 // bottom side is not clipped out
464 // bottom side is clipped out
465 lprPosRect->bottom = lprClipRect->bottom;
468 *lprClipRect = *lprPosRect;
469 *lprPosRect = bounds;
472 HRESULT VLCPlugin::onInit(void)
474 if( NULL == _p_libvlc )
476 // initialize persistable properties
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_mrl) > 0 )
501 ** try to combine MRL with client site moniker, which for Internet Explorer
502 ** is the URL of the page the plugin is embedded into. Hence, if the MRL
503 ** is a relative URL, we should end up with an absolute URL
505 LPOLECLIENTSITE pClientSite;
506 if( SUCCEEDED(vlcOleObject->GetClientSite(&pClientSite)) && (NULL != pClientSite) )
509 if( SUCCEEDED(CreateBindCtx(0, &pBC)) )
511 LPMONIKER pContMoniker = NULL;
512 if( SUCCEEDED(pClientSite->GetMoniker(OLEGETMONIKER_ONLYIFTHERE,
513 OLEWHICHMK_CONTAINER, &pContMoniker)) )
516 if( SUCCEEDED(pContMoniker->GetDisplayName(pBC, NULL, &base_url)) )
519 ** check that the moniker name is a URL
521 if( UrlIsW(base_url, URLIS_URL) )
523 DWORD len = INTERNET_MAX_URL_LENGTH;
524 LPOLESTR abs_url = (LPOLESTR)CoTaskMemAlloc(sizeof(OLECHAR)*len);
525 if( NULL != abs_url )
527 if( SUCCEEDED(UrlCombineW(base_url, _bstr_mrl, abs_url, &len,
528 URL_ESCAPE_UNSAFE|URL_PLUGGABLE_PROTOCOL)) )
530 SysFreeString(_bstr_mrl);
531 _bstr_mrl = SysAllocStringLen(abs_url, len);
533 CoTaskMemFree(abs_url);
536 CoTaskMemFree(base_url);
538 pContMoniker->Release();
542 pClientSite->Release();
549 HRESULT VLCPlugin::getVLCObject(int* i_vlc)
551 libvlc_instance_t *p_libvlc;
552 HRESULT result = getVLC(&p_libvlc);
553 if( SUCCEEDED(result) )
555 *i_vlc = libvlc_get_vlc_id(p_libvlc);
564 HRESULT VLCPlugin::getVLC(libvlc_instance_t** pp_libvlc)
569 ** default initialization options
571 char *ppsz_argv[32] = { "vlc" };
575 DWORD i_type, i_data = MAX_PATH + 1;
576 char p_data[MAX_PATH + 1];
577 if( RegOpenKeyEx( HKEY_LOCAL_MACHINE, "Software\\VideoLAN\\VLC",
578 0, KEY_READ, &h_key ) == ERROR_SUCCESS )
580 if( RegQueryValueEx( h_key, "InstallDir", 0, &i_type,
581 (LPBYTE)p_data, &i_data ) == ERROR_SUCCESS )
583 if( i_type == REG_SZ )
585 strcat( p_data, "\\vlc" );
586 ppsz_argv[0] = p_data;
589 RegCloseKey( h_key );
593 ppsz_argv[0] = "C:\\cygwin\\home\\Damien_Fouilleul\\dev\\videolan\\vlc-trunk\\vlc";
596 // make sure plugin isn't affected with VLC single instance mode
597 ppsz_argv[ppsz_argc++] = "--no-one-instance";
599 /* common settings */
600 ppsz_argv[ppsz_argc++] = "-vv";
601 ppsz_argv[ppsz_argc++] = "--no-stats";
602 ppsz_argv[ppsz_argc++] = "--no-media-library";
603 ppsz_argv[ppsz_argc++] = "--intf";
604 ppsz_argv[ppsz_argc++] = "dummy";
606 // loop mode is a configuration option only
608 ppsz_argv[ppsz_argc++] = "--loop";
610 // initial volume setting
612 ppsz_argv[ppsz_argc++] = "--volume";
615 ppsz_argv[ppsz_argc++] = "0";
619 snprintf(volBuffer, sizeof(volBuffer), "%d", _i_volume);
620 ppsz_argv[ppsz_argc++] = volBuffer;
623 if( IsDebuggerPresent() )
626 ** VLC default threading mechanism is designed to be as compatible
627 ** with POSIX as possible, however when debugged on win32, threads
628 ** lose signals and eventually VLC get stuck during initialization.
629 ** threading support can be configured to be more debugging friendly
630 ** but it will be less compatible with POSIX.
631 ** This is done by initializing with the following options
633 ppsz_argv[ppsz_argc++] = "--fast-mutex";
634 ppsz_argv[ppsz_argc++] = "--win9x-cv-method=1";
637 _p_libvlc = libvlc_new(ppsz_argc, ppsz_argv, NULL);
638 if( NULL == _p_libvlc )
644 char *psz_mrl = CStrFromBSTR(CP_UTF8, _bstr_mrl);
645 if( NULL != psz_mrl )
647 const char *options[1];
653 snprintf(timeBuffer, sizeof(timeBuffer), ":start-time=%d", _i_time);
654 options[i_options++] = timeBuffer;
656 // add default target to playlist
657 libvlc_playlist_add_extended(_p_libvlc, psz_mrl, NULL, i_options, options, NULL);
658 CoTaskMemFree(psz_mrl);
661 *pp_libvlc = _p_libvlc;
665 HRESULT VLCPlugin::onAmbientChanged(LPUNKNOWN pContainer, DISPID dispID)
670 case DISPID_AMBIENT_BACKCOLOR:
672 case DISPID_AMBIENT_DISPLAYNAME:
674 case DISPID_AMBIENT_FONT:
676 case DISPID_AMBIENT_FORECOLOR:
678 case DISPID_AMBIENT_LOCALEID:
680 case DISPID_AMBIENT_MESSAGEREFLECT:
682 case DISPID_AMBIENT_SCALEUNITS:
684 case DISPID_AMBIENT_TEXTALIGN:
686 case DISPID_AMBIENT_USERMODE:
689 if( SUCCEEDED(GetObjectProperty(pContainer, dispID, v)) )
691 setUserMode(V_BOOL(&v) != VARIANT_FALSE);
694 case DISPID_AMBIENT_UIDEAD:
696 case DISPID_AMBIENT_SHOWGRABHANDLES:
698 case DISPID_AMBIENT_SHOWHATCHING:
700 case DISPID_AMBIENT_DISPLAYASDEFAULT:
702 case DISPID_AMBIENT_SUPPORTSMNEMONICS:
704 case DISPID_AMBIENT_AUTOCLIP:
706 case DISPID_AMBIENT_APPEARANCE:
708 case DISPID_AMBIENT_CODEPAGE:
711 if( SUCCEEDED(GetObjectProperty(pContainer, dispID, v)) )
713 setCodePage(V_I4(&v));
716 case DISPID_AMBIENT_PALETTE:
718 case DISPID_AMBIENT_CHARSET:
720 case DISPID_AMBIENT_RIGHTTOLEFT:
722 case DISPID_AMBIENT_TOPTOBOTTOM:
726 ** multiple property change, look up the ones we are interested in
730 if( SUCCEEDED(GetObjectProperty(pContainer, DISPID_AMBIENT_USERMODE, v)) )
732 setUserMode(V_BOOL(&v) != VARIANT_FALSE);
736 if( SUCCEEDED(GetObjectProperty(pContainer, DISPID_AMBIENT_CODEPAGE, v)) )
738 setCodePage(V_I4(&v));
745 HRESULT VLCPlugin::onClose(DWORD dwSaveOption)
747 if( isInPlaceActive() )
749 onInPlaceDeactivate();
753 libvlc_instance_t* p_libvlc = _p_libvlc;
756 vlcDataObject->onClose();
758 libvlc_destroy(p_libvlc, NULL );
763 BOOL VLCPlugin::isInPlaceActive(void)
765 return (NULL != _inplacewnd);
768 HRESULT VLCPlugin::onActivateInPlace(LPMSG lpMesg, HWND hwndParent, LPCRECT lprcPosRect, LPCRECT lprcClipRect)
770 RECT posRect = *lprcPosRect;
771 RECT clipRect = *lprcClipRect;
774 ** record keeping of control geometry within container
779 ** convert posRect & clipRect to match control viewport coordinates
781 getViewportCoords(&posRect, &clipRect);
784 ** Create a window for in place activated control.
785 ** the window geometry matches the control viewport
786 ** within container so that embedded video is always
789 _inplacewnd = CreateWindow(_p_class->getInPlaceWndClassName(),
790 "VLC Plugin In-Place Window",
791 WS_CHILD|WS_CLIPCHILDREN|WS_CLIPSIBLINGS,
794 clipRect.right-clipRect.left,
795 clipRect.bottom-clipRect.top,
798 _p_class->getHInstance(),
802 if( NULL == _inplacewnd )
805 SetWindowLongPtr(_inplacewnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));
808 ** VLC embedded video automatically grows to cover client
809 ** area of parent window.
810 ** hence create a such a 'parent' window whose geometry
811 ** is always correct relative to the viewport bounds
813 _videownd = CreateWindow(_p_class->getVideoWndClassName(),
814 "VLC Plugin Video Window",
815 WS_CHILD|WS_CLIPCHILDREN|WS_VISIBLE,
818 posRect.right-posRect.left,
819 posRect.bottom-posRect.top,
822 _p_class->getHInstance(),
826 if( NULL == _videownd )
828 DestroyWindow(_inplacewnd);
832 SetWindowLongPtr(_videownd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));
836 /* will run vlc if not done already */
837 libvlc_instance_t* p_libvlc;
838 HRESULT result = getVLC(&p_libvlc);
842 /* set internal video width and height */
843 libvlc_video_set_size(p_libvlc,
844 posRect.right-posRect.left,
845 posRect.bottom-posRect.top,
848 /* set internal video parent window */
849 libvlc_video_set_parent(p_libvlc,
850 reinterpret_cast<libvlc_drawable_t>(_videownd), NULL);
852 if( _b_autoplay & (libvlc_playlist_items_count(p_libvlc, NULL) > 0) )
854 libvlc_playlist_play(p_libvlc, 0, 0, NULL, NULL);
860 ShowWindow(_inplacewnd, SW_SHOW);
865 HRESULT VLCPlugin::onInPlaceDeactivate(void)
869 libvlc_playlist_stop(_p_libvlc, NULL);
873 DestroyWindow(_videownd);
875 DestroyWindow(_inplacewnd);
881 void VLCPlugin::setVisible(BOOL fVisible)
883 if( fVisible != _b_visible )
885 _b_visible = fVisible;
886 if( isInPlaceActive() )
888 ShowWindow(_inplacewnd, fVisible ? SW_SHOW : SW_HIDE);
890 InvalidateRect(_videownd, NULL, TRUE);
893 firePropChangedEvent(DISPID_Visible);
897 void VLCPlugin::setVolume(int volume)
901 else if( volume > 200 )
904 if( volume != _i_volume )
909 libvlc_audio_set_volume(_p_libvlc, _i_volume, NULL);
915 void VLCPlugin::setTime(int seconds)
920 if( seconds != _i_time )
925 libvlc_input_t *p_input = libvlc_playlist_get_input(_p_libvlc, NULL);
926 if( NULL != p_input )
928 libvlc_input_set_time(p_input, _i_time, NULL);
929 libvlc_input_free(p_input);
936 void VLCPlugin::setFocus(BOOL fFocus)
939 SetActiveWindow(_inplacewnd);
942 BOOL VLCPlugin::hasFocus(void)
944 return GetActiveWindow() == _inplacewnd;
947 void VLCPlugin::onDraw(DVTARGETDEVICE * ptd, HDC hicTargetDev,
948 HDC hdcDraw, LPCRECTL lprcBounds, LPCRECTL lprcWBounds)
952 long width = lprcBounds->right-lprcBounds->left;
953 long height = lprcBounds->bottom-lprcBounds->top;
955 RECT bounds = { lprcBounds->left, lprcBounds->top, lprcBounds->right, lprcBounds->bottom };
956 FillRect(hdcDraw, &bounds, (HBRUSH)GetStockObject(WHITE_BRUSH));
958 LPPICTURE pict = getPicture();
961 OLE_XSIZE_HIMETRIC picWidth;
962 OLE_YSIZE_HIMETRIC picHeight;
964 pict->get_Width(&picWidth);
965 pict->get_Height(&picHeight);
967 SIZEL picSize = { picWidth, picHeight };
969 if( NULL != hicTargetDev )
971 DPFromHimetric(hicTargetDev, (LPPOINT)&picSize, 1);
973 else if( NULL != (hicTargetDev = CreateDevDC(ptd)) )
975 DPFromHimetric(hicTargetDev, (LPPOINT)&picSize, 1);
976 DeleteDC(hicTargetDev);
979 if( picSize.cx > width-4 )
980 picSize.cx = width-4;
981 if( picSize.cy > height-4 )
982 picSize.cy = height-4;
984 LONG dstX = lprcBounds->left+(width-picSize.cx)/2;
985 LONG dstY = lprcBounds->top+(height-picSize.cy)/2;
987 if( NULL != lprcWBounds )
989 RECT wBounds = { lprcWBounds->left, lprcWBounds->top, lprcWBounds->right, lprcWBounds->bottom };
990 pict->Render(hdcDraw, dstX, dstY, picSize.cx, picSize.cy,
991 0L, picHeight, picWidth, -picHeight, &wBounds);
994 pict->Render(hdcDraw, dstX, dstY, picSize.cx, picSize.cy,
995 0L, picHeight, picWidth, -picHeight, NULL);
1000 SelectObject(hdcDraw, GetStockObject(BLACK_BRUSH));
1002 MoveToEx(hdcDraw, bounds.left, bounds.top, NULL);
1003 LineTo(hdcDraw, bounds.left+width-1, bounds.top);
1004 LineTo(hdcDraw, bounds.left+width-1, bounds.top+height-1);
1005 LineTo(hdcDraw, bounds.left, bounds.top+height-1);
1006 LineTo(hdcDraw, bounds.left, bounds.top);
1010 void VLCPlugin::onPaint(HDC hdc, const RECT &bounds, const RECT &clipRect)
1014 /** if VLC is playing, it may not display any VIDEO content
1015 ** hence, draw control logo*/
1016 HDC hdcDraw = CreateCompatibleDC(hdc);
1017 if( NULL != hdcDraw )
1019 SIZEL size = getExtent();
1020 DPFromHimetric(hdc, (LPPOINT)&size, 1);
1021 RECTL posRect = { 0, 0, size.cx, size.cy };
1023 int width = bounds.right-bounds.left;
1024 int height = bounds.bottom-bounds.top;
1026 HBITMAP hBitmap = CreateCompatibleBitmap(hdc, width, height);
1027 if( NULL != hBitmap )
1029 HBITMAP oldBmp = (HBITMAP)SelectObject(hdcDraw, hBitmap);
1031 if( (size.cx != width) || (size.cy != height) )
1033 // needs to scale canvas
1034 SetMapMode(hdcDraw, MM_ANISOTROPIC);
1035 SetWindowExtEx(hdcDraw, size.cx, size.cy, NULL);
1036 SetViewportExtEx(hdcDraw, width, height, NULL);
1039 onDraw(NULL, hdc, hdcDraw, &posRect, NULL);
1041 SetMapMode(hdcDraw, MM_TEXT);
1042 BitBlt(hdc, bounds.left, bounds.top,
1047 SelectObject(hdcDraw, oldBmp);
1048 DeleteObject(hBitmap);
1055 void VLCPlugin::onPositionChange(LPCRECT lprcPosRect, LPCRECT lprcClipRect)
1057 RECT clipRect = *lprcClipRect;
1058 RECT posRect = *lprcPosRect;
1060 //RedrawWindow(GetParent(_inplacewnd), &_posRect, NULL, RDW_INVALIDATE|RDW_ERASE|RDW_ALLCHILDREN);
1063 ** record keeping of control geometry within container
1068 ** convert posRect & clipRect to match control viewport coordinates
1070 getViewportCoords(&posRect, &clipRect);
1073 ** change in-place window geometry to match clipping region
1075 SetWindowPos(_inplacewnd, NULL,
1078 clipRect.right-clipRect.left,
1079 clipRect.bottom-clipRect.top,
1083 SWP_NOOWNERZORDER );
1086 ** change video window geometry to match object bounds within clipping region
1088 SetWindowPos(_videownd, NULL,
1091 posRect.right-posRect.left,
1092 posRect.bottom-posRect.top,
1096 SWP_NOOWNERZORDER );
1098 //RedrawWindow(_videownd, &posRect, NULL, RDW_INVALIDATE|RDW_ERASE|RDW_ALLCHILDREN);
1101 libvlc_video_set_size(_p_libvlc,
1102 posRect.right-posRect.left,
1103 posRect.bottom-posRect.top,
1108 void VLCPlugin::freezeEvents(BOOL freeze)
1110 vlcConnectionPointContainer->freezeEvents(freeze);
1113 void VLCPlugin::firePropChangedEvent(DISPID dispid)
1115 vlcConnectionPointContainer->firePropChangedEvent(dispid);
1118 void VLCPlugin::fireOnPlayEvent(void)
1120 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1121 vlcConnectionPointContainer->fireEvent(DISPID_PlayEvent, &dispparamsNoArgs);
1124 void VLCPlugin::fireOnPauseEvent(void)
1126 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1127 vlcConnectionPointContainer->fireEvent(DISPID_PauseEvent, &dispparamsNoArgs);
1130 void VLCPlugin::fireOnStopEvent(void)
1132 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
1133 vlcConnectionPointContainer->fireEvent(DISPID_StopEvent, &dispparamsNoArgs);