2 * Copyright 2005 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "wine/debug.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(shdocvw);
28 static inline DocHost *impl_from_IOleClientSite(IOleClientSite *iface)
30 return (DocHost*)((char*)iface - FIELD_OFFSET(DocHost, IOleClientSite_iface));
33 static HRESULT WINAPI ClientSite_QueryInterface(IOleClientSite *iface, REFIID riid, void **ppv)
35 DocHost *This = impl_from_IOleClientSite(iface);
37 if(IsEqualGUID(&IID_IUnknown, riid)) {
38 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
39 *ppv = &This->IOleClientSite_iface;
40 }else if(IsEqualGUID(&IID_IOleClientSite, riid)) {
41 TRACE("(%p)->(IID_IOleClientSite %p)\n", This, ppv);
42 *ppv = &This->IOleClientSite_iface;
43 }else if(IsEqualGUID(&IID_IOleWindow, riid)) {
44 TRACE("(%p)->(IID_IOleWindow %p)\n", This, ppv);
45 *ppv = &This->IOleInPlaceSite_iface;
46 }else if(IsEqualGUID(&IID_IOleInPlaceSite, riid)) {
47 TRACE("(%p)->(IID_IOleInPlaceSite %p)\n", This, ppv);
48 *ppv = &This->IOleInPlaceSite_iface;
49 }else if(IsEqualGUID(&IID_IDocHostUIHandler, riid)) {
50 TRACE("(%p)->(IID_IDocHostUIHandler %p)\n", This, ppv);
51 *ppv = &This->IDocHostUIHandler2_iface;
52 }else if(IsEqualGUID(&IID_IDocHostUIHandler2, riid)) {
53 TRACE("(%p)->(IID_IDocHostUIHandler2 %p)\n", This, ppv);
54 *ppv = &This->IDocHostUIHandler2_iface;
55 }else if(IsEqualGUID(&IID_IOleDocumentSite, riid)) {
56 TRACE("(%p)->(IID_IOleDocumentSite %p)\n", This, ppv);
57 *ppv = &This->IOleDocumentSite_iface;
58 }else if(IsEqualGUID(&IID_IOleCommandTarget, riid)) {
59 TRACE("(%p)->(IID_IOleCommandTarget %p)\n", This, ppv);
60 *ppv = &This->IOleCommandTarget_iface;
61 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
62 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
63 *ppv = &This->IDispatch_iface;
64 }else if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
65 TRACE("(%p)->(IID_IPropertyNotifySink %p)\n", This, ppv);
66 *ppv = &This->IPropertyNotifySink_iface;
67 }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
68 TRACE("(%p)->(IID_IServiceProvider %p)\n", This, ppv);
69 *ppv = &This->IServiceProvider_iface;
72 WARN("Unsupported interface %s\n", debugstr_guid(riid));
76 IOleClientSite_AddRef((IUnknown*)*ppv);
80 static ULONG WINAPI ClientSite_AddRef(IOleClientSite *iface)
82 DocHost *This = impl_from_IOleClientSite(iface);
83 return IDispatch_AddRef(This->disp);
86 static ULONG WINAPI ClientSite_Release(IOleClientSite *iface)
88 DocHost *This = impl_from_IOleClientSite(iface);
89 return IDispatch_Release(This->disp);
92 static HRESULT WINAPI ClientSite_SaveObject(IOleClientSite *iface)
94 DocHost *This = impl_from_IOleClientSite(iface);
95 FIXME("(%p)\n", This);
99 static HRESULT WINAPI ClientSite_GetMoniker(IOleClientSite *iface, DWORD dwAssign,
100 DWORD dwWhichMoniker, IMoniker **ppmk)
102 DocHost *This = impl_from_IOleClientSite(iface);
103 FIXME("(%p)->(%d %d %p)\n", This, dwAssign, dwWhichMoniker, ppmk);
107 static HRESULT WINAPI ClientSite_GetContainer(IOleClientSite *iface, IOleContainer **ppContainer)
109 DocHost *This = impl_from_IOleClientSite(iface);
110 FIXME("(%p)->(%p)\n", This, ppContainer);
114 static HRESULT WINAPI ClientSite_ShowObject(IOleClientSite *iface)
116 DocHost *This = impl_from_IOleClientSite(iface);
117 FIXME("(%p)\n", This);
121 static HRESULT WINAPI ClientSite_OnShowWindow(IOleClientSite *iface, BOOL fShow)
123 DocHost *This = impl_from_IOleClientSite(iface);
124 FIXME("(%p)->(%x)\n", This, fShow);
128 static HRESULT WINAPI ClientSite_RequestNewObjectLayout(IOleClientSite *iface)
130 DocHost *This = impl_from_IOleClientSite(iface);
131 FIXME("(%p)\n", This);
135 static const IOleClientSiteVtbl OleClientSiteVtbl = {
136 ClientSite_QueryInterface,
139 ClientSite_SaveObject,
140 ClientSite_GetMoniker,
141 ClientSite_GetContainer,
142 ClientSite_ShowObject,
143 ClientSite_OnShowWindow,
144 ClientSite_RequestNewObjectLayout
147 static inline DocHost *impl_from_IOleInPlaceSite(IOleInPlaceSite *iface)
149 return (DocHost*)((char*)iface - FIELD_OFFSET(DocHost, IOleInPlaceSite_iface));
152 static HRESULT WINAPI InPlaceSite_QueryInterface(IOleInPlaceSite *iface, REFIID riid, void **ppv)
154 DocHost *This = impl_from_IOleInPlaceSite(iface);
155 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
158 static ULONG WINAPI InPlaceSite_AddRef(IOleInPlaceSite *iface)
160 DocHost *This = impl_from_IOleInPlaceSite(iface);
161 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
164 static ULONG WINAPI InPlaceSite_Release(IOleInPlaceSite *iface)
166 DocHost *This = impl_from_IOleInPlaceSite(iface);
167 return IOleClientSite_Release(&This->IOleClientSite_iface);
170 static HRESULT WINAPI InPlaceSite_GetWindow(IOleInPlaceSite *iface, HWND *phwnd)
172 DocHost *This = impl_from_IOleInPlaceSite(iface);
174 TRACE("(%p)->(%p)\n", This, phwnd);
180 static HRESULT WINAPI InPlaceSite_ContextSensitiveHelp(IOleInPlaceSite *iface, BOOL fEnterMode)
182 DocHost *This = impl_from_IOleInPlaceSite(iface);
183 FIXME("(%p)->(%x)\n", This, fEnterMode);
187 static HRESULT WINAPI InPlaceSite_CanInPlaceActivate(IOleInPlaceSite *iface)
189 DocHost *This = impl_from_IOleInPlaceSite(iface);
191 TRACE("(%p)\n", This);
193 /* Nothing to do here */
197 static HRESULT WINAPI InPlaceSite_OnInPlaceActivate(IOleInPlaceSite *iface)
199 DocHost *This = impl_from_IOleInPlaceSite(iface);
201 TRACE("(%p)\n", This);
203 /* Nothing to do here */
207 static HRESULT WINAPI InPlaceSite_OnUIActivate(IOleInPlaceSite *iface)
209 DocHost *This = impl_from_IOleInPlaceSite(iface);
210 FIXME("(%p)\n", This);
214 static HRESULT WINAPI InPlaceSite_GetWindowContext(IOleInPlaceSite *iface,
215 IOleInPlaceFrame **ppFrame, IOleInPlaceUIWindow **ppDoc, LPRECT lprcPosRect,
216 LPRECT lprcClipRect, LPOLEINPLACEFRAMEINFO lpFrameInfo)
218 DocHost *This = impl_from_IOleInPlaceSite(iface);
220 TRACE("(%p)->(%p %p %p %p %p)\n", This, ppFrame, ppDoc, lprcPosRect,
221 lprcClipRect, lpFrameInfo);
223 IOleInPlaceFrame_AddRef(&This->IOleInPlaceFrame_iface);
224 *ppFrame = &This->IOleInPlaceFrame_iface;
227 GetClientRect(This->hwnd, lprcPosRect);
228 *lprcClipRect = *lprcPosRect;
230 lpFrameInfo->cb = sizeof(*lpFrameInfo);
231 lpFrameInfo->fMDIApp = FALSE;
232 lpFrameInfo->hwndFrame = This->frame_hwnd;
233 lpFrameInfo->haccel = NULL;
234 lpFrameInfo->cAccelEntries = 0; /* FIXME: should be 5 */
239 static HRESULT WINAPI InPlaceSite_Scroll(IOleInPlaceSite *iface, SIZE scrollExtent)
241 DocHost *This = impl_from_IOleInPlaceSite(iface);
242 FIXME("(%p)->({%d %d})\n", This, scrollExtent.cx, scrollExtent.cy);
246 static HRESULT WINAPI InPlaceSite_OnUIDeactivate(IOleInPlaceSite *iface, BOOL fUndoable)
248 DocHost *This = impl_from_IOleInPlaceSite(iface);
249 FIXME("(%p)->(%x)\n", This, fUndoable);
253 static HRESULT WINAPI InPlaceSite_OnInPlaceDeactivate(IOleInPlaceSite *iface)
255 DocHost *This = impl_from_IOleInPlaceSite(iface);
257 TRACE("(%p)\n", This);
259 /* Nothing to do here */
263 static HRESULT WINAPI InPlaceSite_DiscardUndoState(IOleInPlaceSite *iface)
265 DocHost *This = impl_from_IOleInPlaceSite(iface);
266 FIXME("(%p)\n", This);
270 static HRESULT WINAPI InPlaceSite_DeactivateAndUndo(IOleInPlaceSite *iface)
272 DocHost *This = impl_from_IOleInPlaceSite(iface);
273 FIXME("(%p)\n", This);
277 static HRESULT WINAPI InPlaceSite_OnPosRectChange(IOleInPlaceSite *iface,
280 DocHost *This = impl_from_IOleInPlaceSite(iface);
281 FIXME("(%p)->(%p)\n", This, lprcPosRect);
285 static const IOleInPlaceSiteVtbl OleInPlaceSiteVtbl = {
286 InPlaceSite_QueryInterface,
289 InPlaceSite_GetWindow,
290 InPlaceSite_ContextSensitiveHelp,
291 InPlaceSite_CanInPlaceActivate,
292 InPlaceSite_OnInPlaceActivate,
293 InPlaceSite_OnUIActivate,
294 InPlaceSite_GetWindowContext,
296 InPlaceSite_OnUIDeactivate,
297 InPlaceSite_OnInPlaceDeactivate,
298 InPlaceSite_DiscardUndoState,
299 InPlaceSite_DeactivateAndUndo,
300 InPlaceSite_OnPosRectChange
303 static inline DocHost *impl_from_IOleDocumentSite(IOleDocumentSite *iface)
305 return (DocHost*)((char*)iface - FIELD_OFFSET(DocHost, IOleDocumentSite_iface));
308 static HRESULT WINAPI OleDocumentSite_QueryInterface(IOleDocumentSite *iface,
309 REFIID riid, void **ppv)
311 DocHost *This = impl_from_IOleDocumentSite(iface);
312 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
315 static ULONG WINAPI OleDocumentSite_AddRef(IOleDocumentSite *iface)
317 DocHost *This = impl_from_IOleDocumentSite(iface);
318 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
321 static ULONG WINAPI OleDocumentSite_Release(IOleDocumentSite *iface)
323 DocHost *This = impl_from_IOleDocumentSite(iface);
324 return IOleClientSite_Release(&This->IOleClientSite_iface);
327 static HRESULT WINAPI OleDocumentSite_ActivateMe(IOleDocumentSite *iface,
328 IOleDocumentView *pViewToActivate)
330 DocHost *This = impl_from_IOleDocumentSite(iface);
331 IOleDocument *oledoc;
335 TRACE("(%p)->(%p)\n", This, pViewToActivate);
337 hres = IUnknown_QueryInterface(This->document, &IID_IOleDocument, (void**)&oledoc);
341 IOleDocument_CreateView(oledoc, &This->IOleInPlaceSite_iface, NULL, 0, &This->view);
342 IOleDocument_Release(oledoc);
344 GetClientRect(This->hwnd, &rect);
345 IOleDocumentView_SetRect(This->view, &rect);
347 hres = IOleDocumentView_Show(This->view, TRUE);
352 static const IOleDocumentSiteVtbl OleDocumentSiteVtbl = {
353 OleDocumentSite_QueryInterface,
354 OleDocumentSite_AddRef,
355 OleDocumentSite_Release,
356 OleDocumentSite_ActivateMe
359 static inline DocHost *impl_from_IDispatch(IDispatch *iface)
361 return (DocHost*)((char*)iface - FIELD_OFFSET(DocHost, IDispatch_iface));
364 static HRESULT WINAPI ClDispatch_QueryInterface(IDispatch *iface, REFIID riid, void **ppv)
366 DocHost *This = impl_from_IDispatch(iface);
367 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
370 static ULONG WINAPI ClDispatch_AddRef(IDispatch *iface)
372 DocHost *This = impl_from_IDispatch(iface);
373 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
376 static ULONG WINAPI ClDispatch_Release(IDispatch *iface)
378 DocHost *This = impl_from_IDispatch(iface);
379 return IOleClientSite_Release(&This->IOleClientSite_iface);
382 static HRESULT WINAPI ClDispatch_GetTypeInfoCount(IDispatch *iface, UINT *pctinfo)
384 DocHost *This = impl_from_IDispatch(iface);
386 TRACE("(%p)->(%p)\n", This, pctinfo);
391 static HRESULT WINAPI ClDispatch_GetTypeInfo(IDispatch *iface, UINT iTInfo, LCID lcid,
394 DocHost *This = impl_from_IDispatch(iface);
396 TRACE("(%p)->(%u %d %p)\n", This, iTInfo, lcid, ppTInfo);
401 static HRESULT WINAPI ClDispatch_GetIDsOfNames(IDispatch *iface, REFIID riid, LPOLESTR *rgszNames,
402 UINT cNames, LCID lcid, DISPID *rgDispId)
404 DocHost *This = impl_from_IDispatch(iface);
406 TRACE("(%p)->(%s %p %u %d %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
412 static const char *debugstr_dispid(DISPID dispid)
416 #define CASE_DISPID(did) case did: return #did
418 CASE_DISPID(DISPID_AMBIENT_USERMODE);
419 CASE_DISPID(DISPID_AMBIENT_DLCONTROL);
420 CASE_DISPID(DISPID_AMBIENT_USERAGENT);
421 CASE_DISPID(DISPID_AMBIENT_PALETTE);
422 CASE_DISPID(DISPID_AMBIENT_OFFLINEIFNOTCONNECTED);
423 CASE_DISPID(DISPID_AMBIENT_SILENT);
427 sprintf(buf, "%d", dispid);
431 static HRESULT WINAPI ClDispatch_Invoke(IDispatch *iface, DISPID dispIdMember, REFIID riid,
432 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
433 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
435 DocHost *This = impl_from_IDispatch(iface);
437 TRACE("(%p)->(%s %s %d %04x %p %p %p %p)\n", This, debugstr_dispid(dispIdMember),
438 debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
440 switch(dispIdMember) {
441 case DISPID_AMBIENT_USERMODE:
442 case DISPID_AMBIENT_DLCONTROL:
443 case DISPID_AMBIENT_USERAGENT:
444 case DISPID_AMBIENT_PALETTE:
445 if(!This->client_disp)
447 return IDispatch_Invoke(This->client_disp, dispIdMember, riid, lcid, wFlags,
448 pDispParams, pVarResult, pExcepInfo, puArgErr);
449 case DISPID_AMBIENT_OFFLINEIFNOTCONNECTED:
450 V_VT(pVarResult) = VT_BOOL;
451 V_BOOL(pVarResult) = This->offline;
453 case DISPID_AMBIENT_SILENT:
454 V_VT(pVarResult) = VT_BOOL;
455 V_BOOL(pVarResult) = This->offline;
459 FIXME("unhandled dispid %d\n", dispIdMember);
463 static const IDispatchVtbl DispatchVtbl = {
464 ClDispatch_QueryInterface,
467 ClDispatch_GetTypeInfoCount,
468 ClDispatch_GetTypeInfo,
469 ClDispatch_GetIDsOfNames,
473 static inline DocHost *impl_from_IServiceProvider(IServiceProvider *iface)
475 return (DocHost*)((char*)iface - FIELD_OFFSET(DocHost, IServiceProvider_iface));
478 static HRESULT WINAPI ClServiceProvider_QueryInterface(IServiceProvider *iface, REFIID riid,
481 DocHost *This = impl_from_IServiceProvider(iface);
482 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
485 static ULONG WINAPI ClServiceProvider_AddRef(IServiceProvider *iface)
487 DocHost *This = impl_from_IServiceProvider(iface);
488 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
491 static ULONG WINAPI ClServiceProvider_Release(IServiceProvider *iface)
493 DocHost *This = impl_from_IServiceProvider(iface);
494 return IOleClientSite_Release(&This->IOleClientSite_iface);
497 static HRESULT WINAPI ClServiceProvider_QueryService(IServiceProvider *iface, REFGUID guidService,
498 REFIID riid, void **ppv)
500 DocHost *This = impl_from_IServiceProvider(iface);
502 if(IsEqualGUID(&IID_IHlinkFrame, guidService)) {
503 TRACE("(%p)->(IID_IHlinkFrame %s %p)\n", This, debugstr_guid(riid), ppv);
504 return IDispatch_QueryInterface(This->disp, riid, ppv);
507 FIXME("(%p)->(%s %s %p)\n", This, debugstr_guid(guidService), debugstr_guid(riid), ppv);
509 return E_NOINTERFACE;
512 static const IServiceProviderVtbl ServiceProviderVtbl = {
513 ClServiceProvider_QueryInterface,
514 ClServiceProvider_AddRef,
515 ClServiceProvider_Release,
516 ClServiceProvider_QueryService
519 void DocHost_ClientSite_Init(DocHost *This)
521 This->IOleClientSite_iface.lpVtbl = &OleClientSiteVtbl;
522 This->IOleInPlaceSite_iface.lpVtbl = &OleInPlaceSiteVtbl;
523 This->IOleDocumentSite_iface.lpVtbl = &OleDocumentSiteVtbl;
524 This->IDispatch_iface.lpVtbl = &DispatchVtbl;
525 This->IServiceProvider_iface.lpVtbl = &ServiceProviderVtbl;
528 void DocHost_ClientSite_Release(DocHost *This)
531 IOleDocumentView_Release(This->view);