mshtml: Check for null pointers in IHTMLLocation_get*.
[wine/hramrach.git] / dlls / shdocvw / client.c
bloba351bd1e37f011592284c1d536bd9064d2fa8b73
1 /*
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
19 #include <stdio.h>
21 #include "wine/debug.h"
22 #include "shdocvw.h"
23 #include "mshtmdid.h"
24 #include "idispids.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(shdocvw);
28 #define CLIENTSITE_THIS(iface) DEFINE_THIS(DocHost, OleClientSite, iface)
30 static HRESULT WINAPI ClientSite_QueryInterface(IOleClientSite *iface, REFIID riid, void **ppv)
32 DocHost *This = CLIENTSITE_THIS(iface);
34 *ppv = NULL;
36 if(IsEqualGUID(&IID_IUnknown, riid)) {
37 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
38 *ppv = CLIENTSITE(This);
39 }else if(IsEqualGUID(&IID_IOleClientSite, riid)) {
40 TRACE("(%p)->(IID_IOleClientSite %p)\n", This, ppv);
41 *ppv = CLIENTSITE(This);
42 }else if(IsEqualGUID(&IID_IOleWindow, riid)) {
43 TRACE("(%p)->(IID_IOleWindow %p)\n", This, ppv);
44 *ppv = INPLACESITE(This);
45 }else if(IsEqualGUID(&IID_IOleInPlaceSite, riid)) {
46 TRACE("(%p)->(IID_IOleInPlaceSite %p)\n", This, ppv);
47 *ppv = INPLACESITE(This);
48 }else if(IsEqualGUID(&IID_IDocHostUIHandler, riid)) {
49 TRACE("(%p)->(IID_IDocHostUIHandler %p)\n", This, ppv);
50 *ppv = DOCHOSTUI(This);
51 }else if(IsEqualGUID(&IID_IDocHostUIHandler2, riid)) {
52 TRACE("(%p)->(IID_IDocHostUIHandler2 %p)\n", This, ppv);
53 *ppv = DOCHOSTUI2(This);
54 }else if(IsEqualGUID(&IID_IOleDocumentSite, riid)) {
55 TRACE("(%p)->(IID_IOleDocumentSite %p)\n", This, ppv);
56 *ppv = DOCSITE(This);
57 }else if(IsEqualGUID(&IID_IOleCommandTarget, riid)) {
58 TRACE("(%p)->(IID_IOleCommandTarget %p)\n", This, ppv);
59 *ppv = OLECMD(This);
60 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
61 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
62 *ppv = CLDISP(This);
63 }else if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
64 TRACE("(%p)->(IID_IPropertyNotifySink %p)\n", This, ppv);
65 *ppv = PROPNOTIF(This);
66 }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
67 TRACE("(%p)->(IID_IServiceProvider %p)\n", This, ppv);
68 *ppv = SERVPROV(This);
71 if(*ppv) {
72 IOleClientSite_AddRef(CLIENTSITE(This));
73 return S_OK;
76 WARN("Unsupported intrface %s\n", debugstr_guid(riid));
78 return E_NOINTERFACE;
81 static ULONG WINAPI ClientSite_AddRef(IOleClientSite *iface)
83 DocHost *This = CLIENTSITE_THIS(iface);
84 return IDispatch_AddRef(This->disp);
87 static ULONG WINAPI ClientSite_Release(IOleClientSite *iface)
89 DocHost *This = CLIENTSITE_THIS(iface);
90 return IDispatch_Release(This->disp);
93 static HRESULT WINAPI ClientSite_SaveObject(IOleClientSite *iface)
95 DocHost *This = CLIENTSITE_THIS(iface);
96 FIXME("(%p)\n", This);
97 return E_NOTIMPL;
100 static HRESULT WINAPI ClientSite_GetMoniker(IOleClientSite *iface, DWORD dwAssign,
101 DWORD dwWhichMoniker, IMoniker **ppmk)
103 DocHost *This = CLIENTSITE_THIS(iface);
104 FIXME("(%p)->(%d %d %p)\n", This, dwAssign, dwWhichMoniker, ppmk);
105 return E_NOTIMPL;
108 static HRESULT WINAPI ClientSite_GetContainer(IOleClientSite *iface, IOleContainer **ppContainer)
110 DocHost *This = CLIENTSITE_THIS(iface);
111 FIXME("(%p)->(%p)\n", This, ppContainer);
112 return E_NOTIMPL;
115 static HRESULT WINAPI ClientSite_ShowObject(IOleClientSite *iface)
117 DocHost *This = CLIENTSITE_THIS(iface);
118 FIXME("(%p)\n", This);
119 return E_NOTIMPL;
122 static HRESULT WINAPI ClientSite_OnShowWindow(IOleClientSite *iface, BOOL fShow)
124 DocHost *This = CLIENTSITE_THIS(iface);
125 FIXME("(%p)->(%x)\n", This, fShow);
126 return E_NOTIMPL;
129 static HRESULT WINAPI ClientSite_RequestNewObjectLayout(IOleClientSite *iface)
131 DocHost *This = CLIENTSITE_THIS(iface);
132 FIXME("(%p)\n", This);
133 return E_NOTIMPL;
136 #undef CLIENTSITE_THIS
138 static const IOleClientSiteVtbl OleClientSiteVtbl = {
139 ClientSite_QueryInterface,
140 ClientSite_AddRef,
141 ClientSite_Release,
142 ClientSite_SaveObject,
143 ClientSite_GetMoniker,
144 ClientSite_GetContainer,
145 ClientSite_ShowObject,
146 ClientSite_OnShowWindow,
147 ClientSite_RequestNewObjectLayout
150 #define INPLACESITE_THIS(iface) DEFINE_THIS(DocHost, OleInPlaceSite, iface)
152 static HRESULT WINAPI InPlaceSite_QueryInterface(IOleInPlaceSite *iface, REFIID riid, void **ppv)
154 DocHost *This = INPLACESITE_THIS(iface);
155 return IOleClientSite_QueryInterface(CLIENTSITE(This), riid, ppv);
158 static ULONG WINAPI InPlaceSite_AddRef(IOleInPlaceSite *iface)
160 DocHost *This = INPLACESITE_THIS(iface);
161 return IOleClientSite_AddRef(CLIENTSITE(This));
164 static ULONG WINAPI InPlaceSite_Release(IOleInPlaceSite *iface)
166 DocHost *This = INPLACESITE_THIS(iface);
167 return IOleClientSite_Release(CLIENTSITE(This));
170 static HRESULT WINAPI InPlaceSite_GetWindow(IOleInPlaceSite *iface, HWND *phwnd)
172 DocHost *This = INPLACESITE_THIS(iface);
174 TRACE("(%p)->(%p)\n", This, phwnd);
176 *phwnd = This->hwnd;
177 return S_OK;
180 static HRESULT WINAPI InPlaceSite_ContextSensitiveHelp(IOleInPlaceSite *iface, BOOL fEnterMode)
182 DocHost *This = INPLACESITE_THIS(iface);
183 FIXME("(%p)->(%x)\n", This, fEnterMode);
184 return E_NOTIMPL;
187 static HRESULT WINAPI InPlaceSite_CanInPlaceActivate(IOleInPlaceSite *iface)
189 DocHost *This = INPLACESITE_THIS(iface);
191 TRACE("(%p)\n", This);
193 /* Nothing to do here */
194 return S_OK;
197 static HRESULT WINAPI InPlaceSite_OnInPlaceActivate(IOleInPlaceSite *iface)
199 DocHost *This = INPLACESITE_THIS(iface);
201 TRACE("(%p)\n", This);
203 /* Nothing to do here */
204 return S_OK;
207 static HRESULT WINAPI InPlaceSite_OnUIActivate(IOleInPlaceSite *iface)
209 DocHost *This = INPLACESITE_THIS(iface);
210 FIXME("(%p)\n", This);
211 return E_NOTIMPL;
214 static HRESULT WINAPI InPlaceSite_GetWindowContext(IOleInPlaceSite *iface,
215 IOleInPlaceFrame **ppFrame, IOleInPlaceUIWindow **ppDoc, LPRECT lprcPosRect,
216 LPRECT lprcClipRect, LPOLEINPLACEFRAMEINFO lpFrameInfo)
218 DocHost *This = INPLACESITE_THIS(iface);
220 TRACE("(%p)->(%p %p %p %p %p)\n", This, ppFrame, ppDoc, lprcPosRect,
221 lprcClipRect, lpFrameInfo);
223 IOleInPlaceFrame_AddRef(INPLACEFRAME(This));
224 *ppFrame = INPLACEFRAME(This);
225 *ppDoc = NULL;
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 */
236 return S_OK;
239 static HRESULT WINAPI InPlaceSite_Scroll(IOleInPlaceSite *iface, SIZE scrollExtent)
241 DocHost *This = INPLACESITE_THIS(iface);
242 FIXME("(%p)->({%d %d})\n", This, scrollExtent.cx, scrollExtent.cy);
243 return E_NOTIMPL;
246 static HRESULT WINAPI InPlaceSite_OnUIDeactivate(IOleInPlaceSite *iface, BOOL fUndoable)
248 DocHost *This = INPLACESITE_THIS(iface);
249 FIXME("(%p)->(%x)\n", This, fUndoable);
250 return E_NOTIMPL;
253 static HRESULT WINAPI InPlaceSite_OnInPlaceDeactivate(IOleInPlaceSite *iface)
255 DocHost *This = INPLACESITE_THIS(iface);
257 TRACE("(%p)\n", This);
259 /* Nothing to do here */
260 return S_OK;
263 static HRESULT WINAPI InPlaceSite_DiscardUndoState(IOleInPlaceSite *iface)
265 DocHost *This = INPLACESITE_THIS(iface);
266 FIXME("(%p)\n", This);
267 return E_NOTIMPL;
270 static HRESULT WINAPI InPlaceSite_DeactivateAndUndo(IOleInPlaceSite *iface)
272 DocHost *This = INPLACESITE_THIS(iface);
273 FIXME("(%p)\n", This);
274 return E_NOTIMPL;
277 static HRESULT WINAPI InPlaceSite_OnPosRectChange(IOleInPlaceSite *iface,
278 LPCRECT lprcPosRect)
280 DocHost *This = INPLACESITE_THIS(iface);
281 FIXME("(%p)->(%p)\n", This, lprcPosRect);
282 return E_NOTIMPL;
285 #undef INPLACESITE_THIS
287 static const IOleInPlaceSiteVtbl OleInPlaceSiteVtbl = {
288 InPlaceSite_QueryInterface,
289 InPlaceSite_AddRef,
290 InPlaceSite_Release,
291 InPlaceSite_GetWindow,
292 InPlaceSite_ContextSensitiveHelp,
293 InPlaceSite_CanInPlaceActivate,
294 InPlaceSite_OnInPlaceActivate,
295 InPlaceSite_OnUIActivate,
296 InPlaceSite_GetWindowContext,
297 InPlaceSite_Scroll,
298 InPlaceSite_OnUIDeactivate,
299 InPlaceSite_OnInPlaceDeactivate,
300 InPlaceSite_DiscardUndoState,
301 InPlaceSite_DeactivateAndUndo,
302 InPlaceSite_OnPosRectChange
305 #define DOCSITE_THIS(iface) DEFINE_THIS(DocHost, OleDocumentSite, iface)
307 static HRESULT WINAPI OleDocumentSite_QueryInterface(IOleDocumentSite *iface,
308 REFIID riid, void **ppv)
310 DocHost *This = DOCSITE_THIS(iface);
311 return IOleClientSite_QueryInterface(CLIENTSITE(This), riid, ppv);
314 static ULONG WINAPI OleDocumentSite_AddRef(IOleDocumentSite *iface)
316 DocHost *This = DOCSITE_THIS(iface);
317 return IOleClientSite_AddRef(CLIENTSITE(This));
320 static ULONG WINAPI OleDocumentSite_Release(IOleDocumentSite *iface)
322 DocHost *This = DOCSITE_THIS(iface);
323 return IOleClientSite_Release(CLIENTSITE(This));
326 static HRESULT WINAPI OleDocumentSite_ActivateMe(IOleDocumentSite *iface,
327 IOleDocumentView *pViewToActivate)
329 DocHost *This = DOCSITE_THIS(iface);
330 IOleDocument *oledoc;
331 RECT rect;
332 HRESULT hres;
334 TRACE("(%p)->(%p)\n", This, pViewToActivate);
336 hres = IUnknown_QueryInterface(This->document, &IID_IOleDocument, (void**)&oledoc);
337 if(FAILED(hres))
338 return hres;
340 IOleDocument_CreateView(oledoc, INPLACESITE(This), NULL, 0, &This->view);
341 IOleDocument_Release(oledoc);
343 GetClientRect(This->hwnd, &rect);
344 IOleDocumentView_SetRect(This->view, &rect);
346 hres = IOleDocumentView_Show(This->view, TRUE);
348 return hres;
351 #undef DOCSITE_THIS
353 static const IOleDocumentSiteVtbl OleDocumentSiteVtbl = {
354 OleDocumentSite_QueryInterface,
355 OleDocumentSite_AddRef,
356 OleDocumentSite_Release,
357 OleDocumentSite_ActivateMe
360 #define DISP_THIS(iface) DEFINE_THIS(DocHost, Dispatch, iface)
362 static HRESULT WINAPI ClDispatch_QueryInterface(IDispatch *iface, REFIID riid, void **ppv)
364 DocHost *This = DISP_THIS(iface);
365 return IOleClientSite_QueryInterface(CLIENTSITE(This), riid, ppv);
368 static ULONG WINAPI ClDispatch_AddRef(IDispatch *iface)
370 DocHost *This = DISP_THIS(iface);
371 return IOleClientSite_AddRef(CLIENTSITE(This));
374 static ULONG WINAPI ClDispatch_Release(IDispatch *iface)
376 DocHost *This = DISP_THIS(iface);
377 return IOleClientSite_Release(CLIENTSITE(This));
380 static HRESULT WINAPI ClDispatch_GetTypeInfoCount(IDispatch *iface, UINT *pctinfo)
382 DocHost *This = DISP_THIS(iface);
384 TRACE("(%p)->(%p)\n", This, pctinfo);
386 return E_NOTIMPL;
389 static HRESULT WINAPI ClDispatch_GetTypeInfo(IDispatch *iface, UINT iTInfo, LCID lcid,
390 ITypeInfo **ppTInfo)
392 DocHost *This = DISP_THIS(iface);
394 TRACE("(%p)->(%u %d %p)\n", This, iTInfo, lcid, ppTInfo);
396 return E_NOTIMPL;
399 static HRESULT WINAPI ClDispatch_GetIDsOfNames(IDispatch *iface, REFIID riid, LPOLESTR *rgszNames,
400 UINT cNames, LCID lcid, DISPID *rgDispId)
402 DocHost *This = DISP_THIS(iface);
404 TRACE("(%p)->(%s %p %u %d %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
405 lcid, rgDispId);
407 return E_NOTIMPL;
410 static const char *debugstr_dispid(DISPID dispid)
412 static char buf[16];
414 #define CASE_DISPID(did) case did: return #did
415 switch(dispid) {
416 CASE_DISPID(DISPID_AMBIENT_USERMODE);
417 CASE_DISPID(DISPID_AMBIENT_DLCONTROL);
418 CASE_DISPID(DISPID_AMBIENT_USERAGENT);
419 CASE_DISPID(DISPID_AMBIENT_PALETTE);
420 CASE_DISPID(DISPID_AMBIENT_OFFLINEIFNOTCONNECTED);
421 CASE_DISPID(DISPID_AMBIENT_SILENT);
423 #undef CASE_DISPID
425 sprintf(buf, "%d", dispid);
426 return buf;
429 static HRESULT WINAPI ClDispatch_Invoke(IDispatch *iface, DISPID dispIdMember, REFIID riid,
430 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
431 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
433 DocHost *This = DISP_THIS(iface);
435 TRACE("(%p)->(%s %s %d %04x %p %p %p %p)\n", This, debugstr_dispid(dispIdMember),
436 debugstr_guid(riid), lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
438 switch(dispIdMember) {
439 case DISPID_AMBIENT_USERMODE:
440 case DISPID_AMBIENT_DLCONTROL:
441 case DISPID_AMBIENT_USERAGENT:
442 case DISPID_AMBIENT_PALETTE:
443 if(!This->client_disp)
444 return E_FAIL;
445 return IDispatch_Invoke(This->client_disp, dispIdMember, riid, lcid, wFlags,
446 pDispParams, pVarResult, pExcepInfo, puArgErr);
447 case DISPID_AMBIENT_OFFLINEIFNOTCONNECTED:
448 V_VT(pVarResult) = VT_BOOL;
449 V_BOOL(pVarResult) = This->offline;
450 return S_OK;
451 case DISPID_AMBIENT_SILENT:
452 V_VT(pVarResult) = VT_BOOL;
453 V_BOOL(pVarResult) = This->offline;
454 return S_OK;
457 FIXME("unhandled dispid %d\n", dispIdMember);
458 return E_NOTIMPL;
461 #undef DISP_THIS
463 static const IDispatchVtbl DispatchVtbl = {
464 ClDispatch_QueryInterface,
465 ClDispatch_AddRef,
466 ClDispatch_Release,
467 ClDispatch_GetTypeInfoCount,
468 ClDispatch_GetTypeInfo,
469 ClDispatch_GetIDsOfNames,
470 ClDispatch_Invoke
473 #define SERVPROV_THIS(iface) DEFINE_THIS(DocHost, ServiceProvider, iface)
475 static HRESULT WINAPI ClServiceProvider_QueryInterface(IServiceProvider *iface, REFIID riid,
476 void **ppv)
478 DocHost *This = SERVPROV_THIS(iface);
479 return IOleClientSite_QueryInterface(CLIENTSITE(This), riid, ppv);
482 static ULONG WINAPI ClServiceProvider_AddRef(IServiceProvider *iface)
484 DocHost *This = SERVPROV_THIS(iface);
485 return IOleClientSite_AddRef(CLIENTSITE(This));
488 static ULONG WINAPI ClServiceProvider_Release(IServiceProvider *iface)
490 DocHost *This = SERVPROV_THIS(iface);
491 return IOleClientSite_Release(CLIENTSITE(This));
494 static HRESULT WINAPI ClServiceProvider_QueryService(IServiceProvider *iface, REFGUID guidService,
495 REFIID riid, void **ppv)
497 DocHost *This = SERVPROV_THIS(iface);
499 if(IsEqualGUID(&IID_IHlinkFrame, guidService)) {
500 TRACE("(%p)->(IID_IHlinkFrame %s %p)\n", This, debugstr_guid(riid), ppv);
501 return IDispatch_QueryInterface(This->disp, riid, ppv);
504 FIXME("(%p)->(%s %s %p)\n", This, debugstr_guid(guidService), debugstr_guid(riid), ppv);
506 return E_NOINTERFACE;
509 #undef SERVPROV_THIS
511 static const IServiceProviderVtbl ServiceProviderVtbl = {
512 ClServiceProvider_QueryInterface,
513 ClServiceProvider_AddRef,
514 ClServiceProvider_Release,
515 ClServiceProvider_QueryService
518 void DocHost_ClientSite_Init(DocHost *This)
520 This->lpOleClientSiteVtbl = &OleClientSiteVtbl;
521 This->lpOleInPlaceSiteVtbl = &OleInPlaceSiteVtbl;
522 This->lpOleDocumentSiteVtbl = &OleDocumentSiteVtbl;
523 This->lpDispatchVtbl = &DispatchVtbl;
524 This->lpServiceProviderVtbl = &ServiceProviderVtbl;
526 This->view = NULL;
529 void DocHost_ClientSite_Release(DocHost *This)
531 if(This->view)
532 IOleDocumentView_Release(This->view);