1 /*****************************************************************************
2 * oleobject.cpp: ActiveX control for VLC
3 *****************************************************************************
4 * Copyright (C) 2005 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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
21 *****************************************************************************/
24 #include "oleobject.h"
32 VLCOleObject::VLCOleObject(VLCPlugin *p_instance) :
33 _p_clientsite(NULL), _p_instance(p_instance)
35 CreateOleAdviseHolder(&_p_advise_holder);
38 VLCOleObject::~VLCOleObject()
41 Close(OLECLOSE_NOSAVE);
42 _p_advise_holder->Release();
45 STDMETHODIMP VLCOleObject::Advise(IAdviseSink *pAdvSink, DWORD *dwConnection)
47 return _p_advise_holder->Advise(pAdvSink, dwConnection);
50 STDMETHODIMP VLCOleObject::Close(DWORD dwSaveOption)
52 if( _p_instance->isRunning() )
54 _p_advise_holder->SendOnClose();
55 return _p_instance->onClose(dwSaveOption);
60 STDMETHODIMP VLCOleObject::DoVerb(LONG iVerb, LPMSG lpMsg, LPOLECLIENTSITE pActiveSite,
61 LONG lIndex, HWND hwndParent, LPCRECT lprcPosRect)
65 case OLEIVERB_PRIMARY:
68 // force control to be visible when activating in place
69 _p_instance->setVisible(TRUE);
70 case OLEIVERB_INPLACEACTIVATE:
71 return doInPlaceActivate(lpMsg, pActiveSite, hwndParent, lprcPosRect);
74 _p_instance->setVisible(FALSE);
77 case OLEIVERB_UIACTIVATE:
78 return doUIActivate(lpMsg, pActiveSite, hwndParent, lprcPosRect);
80 case OLEIVERB_DISCARDUNDOSTATE:
85 _p_instance->setVisible(TRUE);
86 doInPlaceActivate(lpMsg, pActiveSite, hwndParent, lprcPosRect);
87 return OLEOBJ_S_INVALIDVERB;
93 HRESULT VLCOleObject::doInPlaceActivate(LPMSG lpMsg, LPOLECLIENTSITE pActiveSite, HWND hwndParent, LPCRECT lprcPosRect)
97 LPCRECT lprcClipRect = lprcPosRect;
99 if( NULL != pActiveSite )
101 // check if already activated
102 if( _p_instance->isInPlaceActive() )
104 // just attempt to show object then
105 if( _p_instance->getVisible() )
106 pActiveSite->ShowObject();
110 LPOLEINPLACESITE p_inPlaceSite;
112 if( SUCCEEDED(pActiveSite->QueryInterface(IID_IOleInPlaceSite, (void**)&p_inPlaceSite)) )
114 if( S_OK != p_inPlaceSite->CanInPlaceActivate() )
116 return OLEOBJ_S_CANNOT_DOVERB_NOW;
119 LPOLEINPLACEFRAME p_inPlaceFrame;
120 LPOLEINPLACEUIWINDOW p_inPlaceUIWindow;
121 OLEINPLACEFRAMEINFO oleFrameInfo;
123 oleFrameInfo.cb = sizeof(OLEINPLACEFRAMEINFO);
124 if( SUCCEEDED(p_inPlaceSite->GetWindowContext(&p_inPlaceFrame, &p_inPlaceUIWindow, &posRect, &clipRect, &oleFrameInfo)) )
126 lprcPosRect = &posRect;
127 lprcClipRect = &clipRect;
129 if( NULL != p_inPlaceFrame )
130 p_inPlaceFrame->Release();
131 if( NULL != p_inPlaceUIWindow )
132 p_inPlaceUIWindow->Release();
135 if( (NULL == hwndParent) && FAILED(p_inPlaceSite->GetWindow(&hwndParent)) )
137 p_inPlaceSite->Release();
138 return OLEOBJ_S_INVALIDHWND;
141 else if( NULL == hwndParent )
143 return OLEOBJ_S_INVALIDHWND;
146 if( FAILED(_p_instance->onActivateInPlace(lpMsg, hwndParent, lprcPosRect, lprcClipRect)) )
148 if( NULL != p_inPlaceSite )
149 p_inPlaceSite->Release();
150 return OLEOBJ_S_CANNOT_DOVERB_NOW;
153 if( NULL != p_inPlaceSite )
154 p_inPlaceSite->OnPosRectChange(lprcPosRect);
156 pActiveSite->ShowObject();
157 _p_instance->setVisible(TRUE);
159 if( NULL != p_inPlaceSite )
161 p_inPlaceSite->OnInPlaceActivate();
162 p_inPlaceSite->Release();
167 switch( lpMsg->message )
170 case WM_LBUTTONDBLCLK:
171 doUIActivate(lpMsg, pActiveSite, hwndParent, lprcPosRect);
179 return OLEOBJ_S_CANNOT_DOVERB_NOW;
182 HRESULT VLCOleObject::doUIActivate(LPMSG lpMsg, LPOLECLIENTSITE pActiveSite, HWND hwndParent, LPCRECT lprcPosRect)
184 if( NULL != pActiveSite )
186 // check if already activated
187 if( ! _p_instance->isInPlaceActive() )
188 return OLE_E_NOT_INPLACEACTIVE;
190 LPOLEINPLACESITE p_inPlaceSite;
192 if( SUCCEEDED(pActiveSite->QueryInterface(IID_IOleInPlaceSite, (void**)&p_inPlaceSite)) )
194 p_inPlaceSite->OnUIActivate();
196 if( NULL != lprcPosRect )
198 p_inPlaceSite->OnPosRectChange(lprcPosRect);
200 p_inPlaceSite->Release();
203 pActiveSite->ShowObject();
204 _p_instance->setVisible(TRUE);
205 _p_instance->setFocus(TRUE);
212 STDMETHODIMP VLCOleObject::EnumAdvise(IEnumSTATDATA **ppEnumAdvise)
214 return _p_advise_holder->EnumAdvise(ppEnumAdvise);
217 STDMETHODIMP VLCOleObject::EnumVerbs(IEnumOleVerb **ppEnumOleVerb)
219 return OleRegEnumVerbs(_p_instance->getClassID(),
223 STDMETHODIMP VLCOleObject::GetClientSite(LPOLECLIENTSITE *ppClientSite)
225 if( NULL == ppClientSite )
228 if( NULL != _p_clientsite )
229 _p_clientsite->AddRef();
231 *ppClientSite = _p_clientsite;
235 STDMETHODIMP VLCOleObject::GetClipboardData(DWORD dwReserved, LPDATAOBJECT *ppDataObject)
237 return _p_instance->pUnkOuter->QueryInterface(IID_IDataObject, (void **)ppDataObject);
240 STDMETHODIMP VLCOleObject::GetExtent(DWORD dwDrawAspect, SIZEL *pSizel)
245 if( dwDrawAspect & DVASPECT_CONTENT )
247 *pSizel = _p_instance->getExtent();
255 STDMETHODIMP VLCOleObject::GetMiscStatus(DWORD dwAspect, DWORD *pdwStatus)
257 if( NULL == pdwStatus )
262 case DVASPECT_CONTENT:
263 *pdwStatus = OLEMISC_RECOMPOSEONRESIZE
264 | OLEMISC_CANTLINKINSIDE
266 | OLEMISC_ACTIVATEWHENVISIBLE
267 | OLEMISC_SETCLIENTSITEFIRST;
276 STDMETHODIMP VLCOleObject::GetMoniker(DWORD dwAssign, DWORD dwWhichMoniker, LPMONIKER *ppMoniker)
278 if( NULL != _p_clientsite )
279 return _p_clientsite->GetMoniker(dwAssign,dwWhichMoniker, ppMoniker);
284 STDMETHODIMP VLCOleObject::GetUserClassID(LPCLSID pClsid)
289 *pClsid = _p_instance->getClassID();
293 STDMETHODIMP VLCOleObject::GetUserType(DWORD dwFormOfType, LPOLESTR *pszUserType)
295 return OleRegGetUserType(_p_instance->getClassID(),
296 dwFormOfType, pszUserType);
299 STDMETHODIMP VLCOleObject::InitFromData(LPDATAOBJECT pDataObject, BOOL fCreation, DWORD dwReserved)
304 STDMETHODIMP VLCOleObject::IsUpToDate(void)
309 STDMETHODIMP VLCOleObject::SetClientSite(LPOLECLIENTSITE pClientSite)
311 if( NULL != _p_clientsite )
312 _p_clientsite->Release();
314 _p_clientsite = pClientSite;
316 if( NULL != pClientSite )
318 pClientSite->AddRef();
319 _p_instance->onAmbientChanged(pClientSite, DISPID_UNKNOWN);
324 STDMETHODIMP VLCOleObject::SetColorScheme(LOGPALETTE *pLogpal)
329 STDMETHODIMP VLCOleObject::SetExtent(DWORD dwDrawAspect, SIZEL *pSizel)
334 if( dwDrawAspect & DVASPECT_CONTENT )
336 _p_instance->setExtent(*pSizel);
338 if( _p_instance->isInPlaceActive() )
340 LPOLEINPLACESITE p_inPlaceSite;
342 if( SUCCEEDED(_p_clientsite->QueryInterface(IID_IOleInPlaceSite, (void**)&p_inPlaceSite)) )
346 if( SUCCEEDED(p_inPlaceSite->GetWindow(&hwnd)) )
348 // use HIMETRIC to pixel transform
349 RECT posRect = _p_instance->getPosRect();
350 HDC hDC = GetDC(hwnd);
351 posRect.right = (pSizel->cx*GetDeviceCaps(hDC, LOGPIXELSX)/2540L)+posRect.left;
352 posRect.bottom = (pSizel->cy*GetDeviceCaps(hDC, LOGPIXELSY)/2540L)+posRect.top;
354 p_inPlaceSite->OnPosRectChange(&posRect);
356 p_inPlaceSite->Release();
364 STDMETHODIMP VLCOleObject::SetHostNames(LPCOLESTR szContainerApp, LPCOLESTR szContainerObj)
369 STDMETHODIMP VLCOleObject::SetMoniker(DWORD dwWhichMoniker, LPMONIKER pMoniker)
371 return _p_advise_holder->SendOnRename(pMoniker);
374 STDMETHODIMP VLCOleObject::Unadvise(DWORD dwConnection)
376 return _p_advise_holder->Unadvise(dwConnection);
379 STDMETHODIMP VLCOleObject::Update(void)