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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, 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;
145 else if( NULL == lprcPosRect )
147 SetRect(&posRect, 0, 0, 0, 0);
148 lprcPosRect = &posRect;
149 lprcClipRect = &posRect;
152 if( FAILED(_p_instance->onActivateInPlace(lpMsg, hwndParent, lprcPosRect, lprcClipRect)) )
154 if( NULL != p_inPlaceSite )
155 p_inPlaceSite->Release();
156 return OLEOBJ_S_CANNOT_DOVERB_NOW;
159 if( NULL != p_inPlaceSite )
161 p_inPlaceSite->OnInPlaceActivate();
162 p_inPlaceSite->OnPosRectChange(lprcPosRect);
163 p_inPlaceSite->Release();
166 if( _p_instance->getVisible() )
167 pActiveSite->ShowObject();
171 switch( lpMsg->message )
174 case WM_LBUTTONDBLCLK:
175 doUIActivate(lpMsg, pActiveSite, hwndParent, lprcPosRect);
183 return OLEOBJ_S_CANNOT_DOVERB_NOW;
186 HRESULT VLCOleObject::doUIActivate(LPMSG lpMsg, LPOLECLIENTSITE pActiveSite, HWND hwndParent, LPCRECT lprcPosRect)
188 if( NULL != pActiveSite )
190 // check if already activated
191 if( ! _p_instance->isInPlaceActive() )
192 return OLE_E_NOT_INPLACEACTIVE;
194 LPOLEINPLACESITE p_inPlaceSite;
196 if( SUCCEEDED(pActiveSite->QueryInterface(IID_IOleInPlaceSite, (void**)&p_inPlaceSite)) )
198 p_inPlaceSite->OnUIActivate();
200 if( NULL != lprcPosRect )
202 p_inPlaceSite->OnPosRectChange(lprcPosRect);
204 p_inPlaceSite->Release();
207 pActiveSite->ShowObject();
208 _p_instance->setVisible(TRUE);
209 _p_instance->setFocus(TRUE);
216 STDMETHODIMP VLCOleObject::EnumAdvise(IEnumSTATDATA **ppEnumAdvise)
218 return _p_advise_holder->EnumAdvise(ppEnumAdvise);
221 STDMETHODIMP VLCOleObject::EnumVerbs(IEnumOleVerb **ppEnumOleVerb)
223 return OleRegEnumVerbs(_p_instance->getClassID(),
227 STDMETHODIMP VLCOleObject::GetClientSite(LPOLECLIENTSITE *ppClientSite)
229 if( NULL == ppClientSite )
232 if( NULL != _p_clientsite )
233 _p_clientsite->AddRef();
235 *ppClientSite = _p_clientsite;
239 STDMETHODIMP VLCOleObject::GetClipboardData(DWORD dwReserved, LPDATAOBJECT *ppDataObject)
241 return _p_instance->pUnkOuter->QueryInterface(IID_IDataObject, (void **)ppDataObject);
244 STDMETHODIMP VLCOleObject::GetExtent(DWORD dwDrawAspect, SIZEL *pSizel)
249 if( dwDrawAspect & DVASPECT_CONTENT )
251 *pSizel = _p_instance->getExtent();
259 STDMETHODIMP VLCOleObject::GetMiscStatus(DWORD dwAspect, DWORD *pdwStatus)
261 if( NULL == pdwStatus )
266 case DVASPECT_CONTENT:
267 *pdwStatus = OLEMISC_RECOMPOSEONRESIZE
268 | OLEMISC_CANTLINKINSIDE
270 | OLEMISC_ACTIVATEWHENVISIBLE
271 | OLEMISC_SETCLIENTSITEFIRST;
280 STDMETHODIMP VLCOleObject::GetMoniker(DWORD dwAssign, DWORD dwWhichMoniker, LPMONIKER *ppMoniker)
282 if( NULL != _p_clientsite )
283 return _p_clientsite->GetMoniker(dwAssign,dwWhichMoniker, ppMoniker);
288 STDMETHODIMP VLCOleObject::GetUserClassID(LPCLSID pClsid)
293 *pClsid = _p_instance->getClassID();
297 STDMETHODIMP VLCOleObject::GetUserType(DWORD dwFormOfType, LPOLESTR *pszUserType)
299 return OleRegGetUserType(_p_instance->getClassID(),
300 dwFormOfType, pszUserType);
303 STDMETHODIMP VLCOleObject::InitFromData(LPDATAOBJECT pDataObject, BOOL fCreation, DWORD dwReserved)
308 STDMETHODIMP VLCOleObject::IsUpToDate(void)
313 STDMETHODIMP VLCOleObject::SetClientSite(LPOLECLIENTSITE pClientSite)
315 if( NULL != _p_clientsite )
316 _p_clientsite->Release();
318 _p_clientsite = pClientSite;
320 if( NULL != pClientSite )
322 pClientSite->AddRef();
323 _p_instance->onAmbientChanged(pClientSite, DISPID_UNKNOWN);
328 STDMETHODIMP VLCOleObject::SetColorScheme(LOGPALETTE *pLogpal)
333 STDMETHODIMP VLCOleObject::SetExtent(DWORD dwDrawAspect, SIZEL *pSizel)
339 if( dwDrawAspect & DVASPECT_CONTENT )
341 _p_instance->setExtent(*pSizel);
343 if( _p_instance->isInPlaceActive() )
345 LPOLEINPLACESITE p_inPlaceSite;
347 if( SUCCEEDED(_p_clientsite->QueryInterface(IID_IOleInPlaceSite, (void**)&p_inPlaceSite)) )
351 if( SUCCEEDED(p_inPlaceSite->GetWindow(&hwnd)) )
353 // use HIMETRIC to pixel transform
354 RECT posRect = _p_instance->getPosRect();
355 HDC hDC = GetDC(hwnd);
356 posRect.right = (pSizel->cx*GetDeviceCaps(hDC, LOGPIXELSX)/2540L)+posRect.left;
357 posRect.bottom = (pSizel->cy*GetDeviceCaps(hDC, LOGPIXELSY)/2540L)+posRect.top;
359 p_inPlaceSite->OnPosRectChange(&posRect);
361 p_inPlaceSite->Release();
369 STDMETHODIMP VLCOleObject::SetHostNames(LPCOLESTR szContainerApp, LPCOLESTR szContainerObj)
374 STDMETHODIMP VLCOleObject::SetMoniker(DWORD dwWhichMoniker, LPMONIKER pMoniker)
376 return _p_advise_holder->SendOnRename(pMoniker);
379 STDMETHODIMP VLCOleObject::Unadvise(DWORD dwConnection)
381 return _p_advise_holder->Unadvise(dwConnection);
384 STDMETHODIMP VLCOleObject::Update(void)