[SHDOCVW]
[reactos.git] / reactos / dll / win32 / shdocvw / client.c
1 /*
2 * Copyright 2005 Jacek Caban for CodeWeavers
3 *
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.
8 *
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.
13 *
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
17 */
18
19 #include <stdio.h>
20
21 #include "wine/debug.h"
22 #include "shdocvw.h"
23 #include "mshtmdid.h"
24 #include "idispids.h"
25
26 WINE_DEFAULT_DEBUG_CHANNEL(shdocvw);
27
28 #define CLIENTSITE_THIS(iface) DEFINE_THIS(DocHost, OleClientSite, iface)
29
30 static HRESULT WINAPI ClientSite_QueryInterface(IOleClientSite *iface, REFIID riid, void **ppv)
31 {
32 DocHost *This = CLIENTSITE_THIS(iface);
33
34 *ppv = NULL;
35
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);
69 }
70
71 if(*ppv) {
72 IOleClientSite_AddRef(CLIENTSITE(This));
73 return S_OK;
74 }
75
76 WARN("Unsupported interface %s\n", debugstr_guid(riid));
77
78 return E_NOINTERFACE;
79 }
80
81 static ULONG WINAPI ClientSite_AddRef(IOleClientSite *iface)
82 {
83 DocHost *This = CLIENTSITE_THIS(iface);
84 return IDispatch_AddRef(This->disp);
85 }
86
87 static ULONG WINAPI ClientSite_Release(IOleClientSite *iface)
88 {
89 DocHost *This = CLIENTSITE_THIS(iface);
90 return IDispatch_Release(This->disp);
91 }
92
93 static HRESULT WINAPI ClientSite_SaveObject(IOleClientSite *iface)
94 {
95 DocHost *This = CLIENTSITE_THIS(iface);
96 FIXME("(%p)\n", This);
97 return E_NOTIMPL;
98 }
99
100 static HRESULT WINAPI ClientSite_GetMoniker(IOleClientSite *iface, DWORD dwAssign,
101 DWORD dwWhichMoniker, IMoniker **ppmk)
102 {
103 DocHost *This = CLIENTSITE_THIS(iface);
104 FIXME("(%p)->(%d %d %p)\n", This, dwAssign, dwWhichMoniker, ppmk);
105 return E_NOTIMPL;
106 }
107
108 static HRESULT WINAPI ClientSite_GetContainer(IOleClientSite *iface, IOleContainer **ppContainer)
109 {
110 DocHost *This = CLIENTSITE_THIS(iface);
111 FIXME("(%p)->(%p)\n", This, ppContainer);
112 return E_NOTIMPL;
113 }
114
115 static HRESULT WINAPI ClientSite_ShowObject(IOleClientSite *iface)
116 {
117 DocHost *This = CLIENTSITE_THIS(iface);
118 FIXME("(%p)\n", This);
119 return E_NOTIMPL;
120 }
121
122 static HRESULT WINAPI ClientSite_OnShowWindow(IOleClientSite *iface, BOOL fShow)
123 {
124 DocHost *This = CLIENTSITE_THIS(iface);
125 FIXME("(%p)->(%x)\n", This, fShow);
126 return E_NOTIMPL;
127 }
128
129 static HRESULT WINAPI ClientSite_RequestNewObjectLayout(IOleClientSite *iface)
130 {
131 DocHost *This = CLIENTSITE_THIS(iface);
132 FIXME("(%p)\n", This);
133 return E_NOTIMPL;
134 }
135
136 #undef CLIENTSITE_THIS
137
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
148 };
149
150 #define INPLACESITE_THIS(iface) DEFINE_THIS(DocHost, OleInPlaceSite, iface)
151
152 static HRESULT WINAPI InPlaceSite_QueryInterface(IOleInPlaceSite *iface, REFIID riid, void **ppv)
153 {
154 DocHost *This = INPLACESITE_THIS(iface);
155 return IOleClientSite_QueryInterface(CLIENTSITE(This), riid, ppv);
156 }
157
158 static ULONG WINAPI InPlaceSite_AddRef(IOleInPlaceSite *iface)
159 {
160 DocHost *This = INPLACESITE_THIS(iface);
161 return IOleClientSite_AddRef(CLIENTSITE(This));
162 }
163
164 static ULONG WINAPI InPlaceSite_Release(IOleInPlaceSite *iface)
165 {
166 DocHost *This = INPLACESITE_THIS(iface);
167 return IOleClientSite_Release(CLIENTSITE(This));
168 }
169
170 static HRESULT WINAPI InPlaceSite_GetWindow(IOleInPlaceSite *iface, HWND *phwnd)
171 {
172 DocHost *This = INPLACESITE_THIS(iface);
173
174 TRACE("(%p)->(%p)\n", This, phwnd);
175
176 *phwnd = This->hwnd;
177 return S_OK;
178 }
179
180 static HRESULT WINAPI InPlaceSite_ContextSensitiveHelp(IOleInPlaceSite *iface, BOOL fEnterMode)
181 {
182 DocHost *This = INPLACESITE_THIS(iface);
183 FIXME("(%p)->(%x)\n", This, fEnterMode);
184 return E_NOTIMPL;
185 }
186
187 static HRESULT WINAPI InPlaceSite_CanInPlaceActivate(IOleInPlaceSite *iface)
188 {
189 DocHost *This = INPLACESITE_THIS(iface);
190
191 TRACE("(%p)\n", This);
192
193 /* Nothing to do here */
194 return S_OK;
195 }
196
197 static HRESULT WINAPI InPlaceSite_OnInPlaceActivate(IOleInPlaceSite *iface)
198 {
199 DocHost *This = INPLACESITE_THIS(iface);
200
201 TRACE("(%p)\n", This);
202
203 /* Nothing to do here */
204 return S_OK;
205 }
206
207 static HRESULT WINAPI InPlaceSite_OnUIActivate(IOleInPlaceSite *iface)
208 {
209 DocHost *This = INPLACESITE_THIS(iface);
210 FIXME("(%p)\n", This);
211 return E_NOTIMPL;
212 }
213
214 static HRESULT WINAPI InPlaceSite_GetWindowContext(IOleInPlaceSite *iface,
215 IOleInPlaceFrame **ppFrame, IOleInPlaceUIWindow **ppDoc, LPRECT lprcPosRect,
216 LPRECT lprcClipRect, LPOLEINPLACEFRAMEINFO lpFrameInfo)
217 {
218 DocHost *This = INPLACESITE_THIS(iface);
219
220 TRACE("(%p)->(%p %p %p %p %p)\n", This, ppFrame, ppDoc, lprcPosRect,
221 lprcClipRect, lpFrameInfo);
222
223 IOleInPlaceFrame_AddRef(INPLACEFRAME(This));
224 *ppFrame = INPLACEFRAME(This);
225 *ppDoc = NULL;
226
227 GetClientRect(This->hwnd, lprcPosRect);
228 *lprcClipRect = *lprcPosRect;
229
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 */
235
236 return S_OK;
237 }
238
239 static HRESULT WINAPI InPlaceSite_Scroll(IOleInPlaceSite *iface, SIZE scrollExtent)
240 {
241 DocHost *This = INPLACESITE_THIS(iface);
242 FIXME("(%p)->({%d %d})\n", This, scrollExtent.cx, scrollExtent.cy);
243 return E_NOTIMPL;
244 }
245
246 static HRESULT WINAPI InPlaceSite_OnUIDeactivate(IOleInPlaceSite *iface, BOOL fUndoable)
247 {
248 DocHost *This = INPLACESITE_THIS(iface);
249 FIXME("(%p)->(%x)\n", This, fUndoable);
250 return E_NOTIMPL;
251 }
252
253 static HRESULT WINAPI InPlaceSite_OnInPlaceDeactivate(IOleInPlaceSite *iface)
254 {
255 DocHost *This = INPLACESITE_THIS(iface);
256
257 TRACE("(%p)\n", This);
258
259 /* Nothing to do here */
260 return S_OK;
261 }
262
263 static HRESULT WINAPI InPlaceSite_DiscardUndoState(IOleInPlaceSite *iface)
264 {
265 DocHost *This = INPLACESITE_THIS(iface);
266 FIXME("(%p)\n", This);
267 return E_NOTIMPL;
268 }
269
270 static HRESULT WINAPI InPlaceSite_DeactivateAndUndo(IOleInPlaceSite *iface)
271 {
272 DocHost *This = INPLACESITE_THIS(iface);
273 FIXME("(%p)\n", This);
274 return E_NOTIMPL;
275 }
276
277 static HRESULT WINAPI InPlaceSite_OnPosRectChange(IOleInPlaceSite *iface,
278 LPCRECT lprcPosRect)
279 {
280 DocHost *This = INPLACESITE_THIS(iface);
281 FIXME("(%p)->(%p)\n", This, lprcPosRect);
282 return E_NOTIMPL;
283 }
284
285 #undef INPLACESITE_THIS
286
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
303 };
304
305 #define DOCSITE_THIS(iface) DEFINE_THIS(DocHost, OleDocumentSite, iface)
306
307 static HRESULT WINAPI OleDocumentSite_QueryInterface(IOleDocumentSite *iface,
308 REFIID riid, void **ppv)
309 {
310 DocHost *This = DOCSITE_THIS(iface);
311 return IOleClientSite_QueryInterface(CLIENTSITE(This), riid, ppv);
312 }
313
314 static ULONG WINAPI OleDocumentSite_AddRef(IOleDocumentSite *iface)
315 {
316 DocHost *This = DOCSITE_THIS(iface);
317 return IOleClientSite_AddRef(CLIENTSITE(This));
318 }
319
320 static ULONG WINAPI OleDocumentSite_Release(IOleDocumentSite *iface)
321 {
322 DocHost *This = DOCSITE_THIS(iface);
323 return IOleClientSite_Release(CLIENTSITE(This));
324 }
325
326 static HRESULT WINAPI OleDocumentSite_ActivateMe(IOleDocumentSite *iface,
327 IOleDocumentView *pViewToActivate)
328 {
329 DocHost *This = DOCSITE_THIS(iface);
330 IOleDocument *oledoc;
331 RECT rect;
332 HRESULT hres;
333
334 TRACE("(%p)->(%p)\n", This, pViewToActivate);
335
336 hres = IUnknown_QueryInterface(This->document, &IID_IOleDocument, (void**)&oledoc);
337 if(FAILED(hres))
338 return hres;
339
340 IOleDocument_CreateView(oledoc, INPLACESITE(This), NULL, 0, &This->view);
341 IOleDocument_Release(oledoc);
342
343 GetClientRect(This->hwnd, &rect);
344 IOleDocumentView_SetRect(This->view, &rect);
345
346 hres = IOleDocumentView_Show(This->view, TRUE);
347
348 return hres;
349 }
350
351 #undef DOCSITE_THIS
352
353 static const IOleDocumentSiteVtbl OleDocumentSiteVtbl = {
354 OleDocumentSite_QueryInterface,
355 OleDocumentSite_AddRef,
356 OleDocumentSite_Release,
357 OleDocumentSite_ActivateMe
358 };
359
360 #define DISP_THIS(iface) DEFINE_THIS(DocHost, Dispatch, iface)
361
362 static HRESULT WINAPI ClDispatch_QueryInterface(IDispatch *iface, REFIID riid, void **ppv)
363 {
364 DocHost *This = DISP_THIS(iface);
365 return IOleClientSite_QueryInterface(CLIENTSITE(This), riid, ppv);
366 }
367
368 static ULONG WINAPI ClDispatch_AddRef(IDispatch *iface)
369 {
370 DocHost *This = DISP_THIS(iface);
371 return IOleClientSite_AddRef(CLIENTSITE(This));
372 }
373
374 static ULONG WINAPI ClDispatch_Release(IDispatch *iface)
375 {
376 DocHost *This = DISP_THIS(iface);
377 return IOleClientSite_Release(CLIENTSITE(This));
378 }
379
380 static HRESULT WINAPI ClDispatch_GetTypeInfoCount(IDispatch *iface, UINT *pctinfo)
381 {
382 DocHost *This = DISP_THIS(iface);
383
384 TRACE("(%p)->(%p)\n", This, pctinfo);
385
386 return E_NOTIMPL;
387 }
388
389 static HRESULT WINAPI ClDispatch_GetTypeInfo(IDispatch *iface, UINT iTInfo, LCID lcid,
390 ITypeInfo **ppTInfo)
391 {
392 DocHost *This = DISP_THIS(iface);
393
394 TRACE("(%p)->(%u %d %p)\n", This, iTInfo, lcid, ppTInfo);
395
396 return E_NOTIMPL;
397 }
398
399 static HRESULT WINAPI ClDispatch_GetIDsOfNames(IDispatch *iface, REFIID riid, LPOLESTR *rgszNames,
400 UINT cNames, LCID lcid, DISPID *rgDispId)
401 {
402 DocHost *This = DISP_THIS(iface);
403
404 TRACE("(%p)->(%s %p %u %d %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
405 lcid, rgDispId);
406
407 return E_NOTIMPL;
408 }
409
410 static const char *debugstr_dispid(DISPID dispid)
411 {
412 static char buf[16];
413
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);
422 }
423 #undef CASE_DISPID
424
425 sprintf(buf, "%d", dispid);
426 return buf;
427 }
428
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)
432 {
433 DocHost *This = DISP_THIS(iface);
434
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);
437
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;
455 }
456
457 FIXME("unhandled dispid %d\n", dispIdMember);
458 return E_NOTIMPL;
459 }
460
461 #undef DISP_THIS
462
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
471 };
472
473 #define SERVPROV_THIS(iface) DEFINE_THIS(DocHost, ServiceProvider, iface)
474
475 static HRESULT WINAPI ClServiceProvider_QueryInterface(IServiceProvider *iface, REFIID riid,
476 void **ppv)
477 {
478 DocHost *This = SERVPROV_THIS(iface);
479 return IOleClientSite_QueryInterface(CLIENTSITE(This), riid, ppv);
480 }
481
482 static ULONG WINAPI ClServiceProvider_AddRef(IServiceProvider *iface)
483 {
484 DocHost *This = SERVPROV_THIS(iface);
485 return IOleClientSite_AddRef(CLIENTSITE(This));
486 }
487
488 static ULONG WINAPI ClServiceProvider_Release(IServiceProvider *iface)
489 {
490 DocHost *This = SERVPROV_THIS(iface);
491 return IOleClientSite_Release(CLIENTSITE(This));
492 }
493
494 static HRESULT WINAPI ClServiceProvider_QueryService(IServiceProvider *iface, REFGUID guidService,
495 REFIID riid, void **ppv)
496 {
497 DocHost *This = SERVPROV_THIS(iface);
498
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);
502 }
503
504 FIXME("(%p)->(%s %s %p)\n", This, debugstr_guid(guidService), debugstr_guid(riid), ppv);
505
506 return E_NOINTERFACE;
507 }
508
509 #undef SERVPROV_THIS
510
511 static const IServiceProviderVtbl ServiceProviderVtbl = {
512 ClServiceProvider_QueryInterface,
513 ClServiceProvider_AddRef,
514 ClServiceProvider_Release,
515 ClServiceProvider_QueryService
516 };
517
518 void DocHost_ClientSite_Init(DocHost *This)
519 {
520 This->lpOleClientSiteVtbl = &OleClientSiteVtbl;
521 This->lpOleInPlaceSiteVtbl = &OleInPlaceSiteVtbl;
522 This->lpOleDocumentSiteVtbl = &OleDocumentSiteVtbl;
523 This->lpDispatchVtbl = &DispatchVtbl;
524 This->lpServiceProviderVtbl = &ServiceProviderVtbl;
525
526 This->view = NULL;
527 }
528
529 void DocHost_ClientSite_Release(DocHost *This)
530 {
531 if(This->view)
532 IOleDocumentView_Release(This->view);
533 }