windowscodecs: Replace a call to a deprecated libpng function.
[wine] / dlls / shdocvw / dochost.c
1 /*
2  * Copyright 2005-2006 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 "wine/debug.h"
20 #include "shdocvw.h"
21 #include "hlink.h"
22 #include "exdispid.h"
23 #include "mshtml.h"
24
25 WINE_DEFAULT_DEBUG_CHANNEL(shdocvw);
26
27 static ATOM doc_view_atom = 0;
28
29 void push_dochost_task(DocHost *This, task_header_t *task, task_proc_t proc, BOOL send)
30 {
31     task->proc = proc;
32
33     /* FIXME: Don't use lParam */
34     if(send)
35         SendMessageW(This->frame_hwnd, WM_DOCHOSTTASK, 0, (LPARAM)task);
36     else
37         PostMessageW(This->frame_hwnd, WM_DOCHOSTTASK, 0, (LPARAM)task);
38 }
39
40 LRESULT process_dochost_task(DocHost *This, LPARAM lparam)
41 {
42     task_header_t *task = (task_header_t*)lparam;
43
44     task->proc(This, task);
45
46     heap_free(task);
47     return 0;
48 }
49
50 static void notif_complete(DocHost *This, DISPID dispid)
51 {
52     DISPPARAMS dispparams;
53     VARIANTARG params[2];
54     VARIANT url;
55
56     dispparams.cArgs = 2;
57     dispparams.cNamedArgs = 0;
58     dispparams.rgdispidNamedArgs = NULL;
59     dispparams.rgvarg = params;
60
61     V_VT(params) = (VT_BYREF|VT_VARIANT);
62     V_BYREF(params) = &url;
63
64     V_VT(params+1) = VT_DISPATCH;
65     V_DISPATCH(params+1) = This->disp;
66
67     V_VT(&url) = VT_BSTR;
68     V_BSTR(&url) = SysAllocString(This->url);
69
70     TRACE("%d >>>\n", dispid);
71     call_sink(This->cps.wbe2, dispid, &dispparams);
72     TRACE("%d <<<\n", dispid);
73
74     SysFreeString(V_BSTR(&url));
75     This->busy = VARIANT_FALSE;
76 }
77
78 static void object_available(DocHost *This)
79 {
80     IHlinkTarget *hlink;
81     HRESULT hres;
82
83     TRACE("(%p)\n", This);
84
85     if(!This->document) {
86         WARN("document == NULL\n");
87         return;
88     }
89
90     hres = IUnknown_QueryInterface(This->document, &IID_IHlinkTarget, (void**)&hlink);
91     if(FAILED(hres)) {
92         FIXME("Could not get IHlinkTarget interface\n");
93         return;
94     }
95
96     hres = IHlinkTarget_Navigate(hlink, 0, NULL);
97     IHlinkTarget_Release(hlink);
98     if(FAILED(hres))
99         FIXME("Navigate failed\n");
100 }
101
102 static HRESULT get_doc_ready_state(DocHost *This, READYSTATE *ret)
103 {
104     DISPPARAMS dp = {NULL,NULL,0,0};
105     IDispatch *disp;
106     EXCEPINFO ei;
107     VARIANT var;
108     HRESULT hres;
109
110     hres = IUnknown_QueryInterface(This->document, &IID_IDispatch, (void**)&disp);
111     if(FAILED(hres))
112         return hres;
113
114     hres = IDispatch_Invoke(disp, DISPID_READYSTATE, &IID_NULL, LOCALE_SYSTEM_DEFAULT, DISPATCH_PROPERTYGET,
115             &dp, &var, &ei, NULL);
116     IDispatch_Release(disp);
117     if(FAILED(hres)) {
118         WARN("Invoke(DISPID_READYSTATE failed: %08x\n", hres);
119         return hres;
120     }
121
122     if(V_VT(&var) != VT_I4) {
123         WARN("V_VT(var) = %d\n", V_VT(&var));
124         VariantClear(&var);
125         return E_FAIL;
126     }
127
128     *ret = V_I4(&var);
129     return S_OK;
130 }
131
132 static void advise_prop_notif(DocHost *This, BOOL set)
133 {
134     IConnectionPointContainer *cp_container;
135     IConnectionPoint *cp;
136     HRESULT hres;
137
138     hres = IUnknown_QueryInterface(This->document, &IID_IConnectionPointContainer, (void**)&cp_container);
139     if(FAILED(hres))
140         return;
141
142     hres = IConnectionPointContainer_FindConnectionPoint(cp_container, &IID_IPropertyNotifySink, &cp);
143     IConnectionPointContainer_Release(cp_container);
144     if(FAILED(hres))
145         return;
146
147     if(set)
148         hres = IConnectionPoint_Advise(cp, (IUnknown*)PROPNOTIF(This), &This->prop_notif_cookie);
149     else
150         hres = IConnectionPoint_Unadvise(cp, This->prop_notif_cookie);
151     IConnectionPoint_Release(cp);
152
153     if(SUCCEEDED(hres))
154         This->is_prop_notif = set;
155 }
156
157 static void update_ready_state(DocHost *This, READYSTATE ready_state)
158 {
159     if(ready_state > READYSTATE_LOADING && This->ready_state <= READYSTATE_LOADING) {
160         notif_complete(This, DISPID_NAVIGATECOMPLETE2);
161         This->ready_state = ready_state;
162     }
163
164     if(ready_state == READYSTATE_COMPLETE && This->ready_state < READYSTATE_COMPLETE) {
165         This->ready_state = READYSTATE_COMPLETE;
166         notif_complete(This, DISPID_DOCUMENTCOMPLETE);
167     }
168 }
169
170 typedef struct {
171     task_header_t header;
172     IUnknown *doc;
173     READYSTATE ready_state;
174 } ready_state_task_t;
175
176 static void ready_state_proc(DocHost *This, task_header_t *_task)
177 {
178     ready_state_task_t *task = (ready_state_task_t*)_task;
179
180     if(task->doc == This->document)
181         update_ready_state(This, task->ready_state);
182
183     IUnknown_Release(task->doc);
184 }
185
186 static void push_ready_state_task(DocHost *This, READYSTATE ready_state)
187 {
188     ready_state_task_t *task = heap_alloc(sizeof(ready_state_task_t));
189
190     IUnknown_AddRef(This->document);
191     task->doc = This->document;
192     task->ready_state = ready_state;
193
194     push_dochost_task(This, &task->header, ready_state_proc, FALSE);
195 }
196
197 static void object_available_proc(DocHost *This, task_header_t *task)
198 {
199     object_available(This);
200 }
201
202 HRESULT dochost_object_available(DocHost *This, IUnknown *doc)
203 {
204     READYSTATE ready_state;
205     task_header_t *task;
206     IOleObject *oleobj;
207     HRESULT hres;
208
209     IUnknown_AddRef(doc);
210     This->document = doc;
211
212     hres = IUnknown_QueryInterface(doc, &IID_IOleObject, (void**)&oleobj);
213     if(SUCCEEDED(hres)) {
214         CLSID clsid;
215
216         hres = IOleObject_GetUserClassID(oleobj, &clsid);
217         if(SUCCEEDED(hres))
218             TRACE("Got clsid %s\n",
219                   IsEqualGUID(&clsid, &CLSID_HTMLDocument) ? "CLSID_HTMLDocument" : debugstr_guid(&clsid));
220
221         hres = IOleObject_SetClientSite(oleobj, CLIENTSITE(This));
222         if(FAILED(hres))
223             FIXME("SetClientSite failed: %08x\n", hres);
224
225         IOleObject_Release(oleobj);
226     }else {
227         FIXME("Could not get IOleObject iface: %08x\n", hres);
228     }
229
230     /* FIXME: Call SetAdvise */
231
232     task = heap_alloc(sizeof(*task));
233     push_dochost_task(This, task, object_available_proc, FALSE);
234
235     hres = get_doc_ready_state(This, &ready_state);
236     if(SUCCEEDED(hres)) {
237         if(ready_state == READYSTATE_COMPLETE)
238             push_ready_state_task(This, READYSTATE_COMPLETE);
239         else
240             advise_prop_notif(This, TRUE);
241     }
242
243     return S_OK;
244 }
245
246 static LRESULT resize_document(DocHost *This, LONG width, LONG height)
247 {
248     RECT rect = {0, 0, width, height};
249
250     TRACE("(%p)->(%d %d)\n", This, width, height);
251
252     if(This->view)
253         IOleDocumentView_SetRect(This->view, &rect);
254
255     return 0;
256 }
257
258 static LRESULT WINAPI doc_view_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
259 {
260     DocHost *This;
261
262     static const WCHAR wszTHIS[] = {'T','H','I','S',0};
263
264     if(msg == WM_CREATE) {
265         This = *(DocHost**)lParam;
266         SetPropW(hwnd, wszTHIS, This);
267     }else {
268         This = GetPropW(hwnd, wszTHIS);
269     }
270
271     switch(msg) {
272     case WM_SIZE:
273         return resize_document(This, LOWORD(lParam), HIWORD(lParam));
274     }
275
276     return DefWindowProcW(hwnd, msg, wParam, lParam);
277 }
278
279 void create_doc_view_hwnd(DocHost *This)
280 {
281     RECT rect;
282
283     static const WCHAR wszShell_DocObject_View[] =
284         {'S','h','e','l','l',' ','D','o','c','O','b','j','e','c','t',' ','V','i','e','w',0};
285
286     if(!doc_view_atom) {
287         static WNDCLASSEXW wndclass = {
288             sizeof(wndclass),
289             CS_PARENTDC,
290             doc_view_proc,
291             0, 0 /* native uses 4*/, NULL, NULL, NULL,
292             (HBRUSH)(COLOR_WINDOW + 1), NULL,
293             wszShell_DocObject_View,
294             NULL
295         };
296
297         wndclass.hInstance = shdocvw_hinstance;
298
299         doc_view_atom = RegisterClassExW(&wndclass);
300     }
301
302     GetClientRect(This->frame_hwnd, &rect); /* FIXME */
303     This->hwnd = CreateWindowExW(0, wszShell_DocObject_View,
304          wszShell_DocObject_View,
305          WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_TABSTOP,
306          rect.left, rect.top, rect.right, rect.bottom, This->frame_hwnd,
307          NULL, shdocvw_hinstance, This);
308 }
309
310 void deactivate_document(DocHost *This)
311 {
312     IOleInPlaceObjectWindowless *winobj;
313     IOleObject *oleobj = NULL;
314     IHlinkTarget *hlink = NULL;
315     HRESULT hres;
316
317     if(This->is_prop_notif)
318         advise_prop_notif(This, FALSE);
319
320     if(This->view)
321         IOleDocumentView_UIActivate(This->view, FALSE);
322
323     hres = IUnknown_QueryInterface(This->document, &IID_IOleInPlaceObjectWindowless,
324                                    (void**)&winobj);
325     if(SUCCEEDED(hres)) {
326         IOleInPlaceObjectWindowless_InPlaceDeactivate(winobj);
327         IOleInPlaceObjectWindowless_Release(winobj);
328     }
329
330     if(This->view) {
331         IOleDocumentView_Show(This->view, FALSE);
332         IOleDocumentView_CloseView(This->view, 0);
333         IOleDocumentView_SetInPlaceSite(This->view, NULL);
334         IOleDocumentView_Release(This->view);
335         This->view = NULL;
336     }
337
338     hres = IUnknown_QueryInterface(This->document, &IID_IOleObject, (void**)&oleobj);
339     if(SUCCEEDED(hres))
340         IOleObject_Close(oleobj, OLECLOSE_NOSAVE);
341
342     hres = IUnknown_QueryInterface(This->document, &IID_IHlinkTarget, (void**)&hlink);
343     if(SUCCEEDED(hres)) {
344         IHlinkTarget_SetBrowseContext(hlink, NULL);
345         IHlinkTarget_Release(hlink);
346     }
347
348     if(oleobj) {
349         IOleClientSite *client_site = NULL;
350
351         IOleObject_GetClientSite(oleobj, &client_site);
352         if(client_site) {
353             if(client_site == CLIENTSITE(This))
354                 IOleObject_SetClientSite(oleobj, NULL);
355             IOleClientSite_Release(client_site);
356         }
357
358         IOleObject_Release(oleobj);
359     }
360
361     IUnknown_Release(This->document);
362     This->document = NULL;
363 }
364
365 void release_dochost_client(DocHost *This)
366 {
367     if(This->hwnd) {
368         DestroyWindow(This->hwnd);
369         This->hwnd = NULL;
370     }
371
372     if(This->hostui) {
373         IDocHostUIHandler_Release(This->hostui);
374         This->hostui = NULL;
375     }
376
377     if(This->client_disp) {
378         IDispatch_Release(This->client_disp);
379         This->client_disp = NULL;
380     }
381
382     if(This->frame) {
383         IOleInPlaceFrame_Release(This->frame);
384         This->frame = NULL;
385     }
386 }
387
388 #define OLECMD_THIS(iface) DEFINE_THIS(DocHost, OleCommandTarget, iface)
389
390 static HRESULT WINAPI ClOleCommandTarget_QueryInterface(IOleCommandTarget *iface,
391         REFIID riid, void **ppv)
392 {
393     DocHost *This = OLECMD_THIS(iface);
394     return IOleClientSite_QueryInterface(CLIENTSITE(This), riid, ppv);
395 }
396
397 static ULONG WINAPI ClOleCommandTarget_AddRef(IOleCommandTarget *iface)
398 {
399     DocHost *This = OLECMD_THIS(iface);
400     return IOleClientSite_AddRef(CLIENTSITE(This));
401 }
402
403 static ULONG WINAPI ClOleCommandTarget_Release(IOleCommandTarget *iface)
404 {
405     DocHost *This = OLECMD_THIS(iface);
406     return IOleClientSite_Release(CLIENTSITE(This));
407 }
408
409 static HRESULT WINAPI ClOleCommandTarget_QueryStatus(IOleCommandTarget *iface,
410         const GUID *pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[], OLECMDTEXT *pCmdText)
411 {
412     DocHost *This = OLECMD_THIS(iface);
413     FIXME("(%p)->(%s %u %p %p)\n", This, debugstr_guid(pguidCmdGroup), cCmds, prgCmds,
414           pCmdText);
415     return E_NOTIMPL;
416 }
417
418 static HRESULT WINAPI ClOleCommandTarget_Exec(IOleCommandTarget *iface,
419         const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn,
420         VARIANT *pvaOut)
421 {
422     DocHost *This = OLECMD_THIS(iface);
423     FIXME("(%p)->(%s %d %d %p %p)\n", This, debugstr_guid(pguidCmdGroup), nCmdID,
424           nCmdexecopt, pvaIn, pvaOut);
425     return E_NOTIMPL;
426 }
427
428 #undef OLECMD_THIS
429
430 static const IOleCommandTargetVtbl OleCommandTargetVtbl = {
431     ClOleCommandTarget_QueryInterface,
432     ClOleCommandTarget_AddRef,
433     ClOleCommandTarget_Release,
434     ClOleCommandTarget_QueryStatus,
435     ClOleCommandTarget_Exec
436 };
437
438 #define DOCHOSTUI_THIS(iface) DEFINE_THIS(DocHost, DocHostUIHandler, iface)
439
440 static HRESULT WINAPI DocHostUIHandler_QueryInterface(IDocHostUIHandler2 *iface,
441                                                       REFIID riid, void **ppv)
442 {
443     DocHost *This = DOCHOSTUI_THIS(iface);
444     return IOleClientSite_QueryInterface(CLIENTSITE(This), riid, ppv);
445 }
446
447 static ULONG WINAPI DocHostUIHandler_AddRef(IDocHostUIHandler2 *iface)
448 {
449     DocHost *This = DOCHOSTUI_THIS(iface);
450     return IOleClientSite_AddRef(CLIENTSITE(This));
451 }
452
453 static ULONG WINAPI DocHostUIHandler_Release(IDocHostUIHandler2 *iface)
454 {
455     DocHost *This = DOCHOSTUI_THIS(iface);
456     return IOleClientSite_Release(CLIENTSITE(This));
457 }
458
459 static HRESULT WINAPI DocHostUIHandler_ShowContextMenu(IDocHostUIHandler2 *iface,
460          DWORD dwID, POINT *ppt, IUnknown *pcmdtReserved, IDispatch *pdispReserved)
461 {
462     DocHost *This = DOCHOSTUI_THIS(iface);
463     HRESULT hres;
464
465     TRACE("(%p)->(%d %p %p %p)\n", This, dwID, ppt, pcmdtReserved, pdispReserved);
466
467     if(This->hostui) {
468         hres = IDocHostUIHandler_ShowContextMenu(This->hostui, dwID, ppt, pcmdtReserved,
469                                                  pdispReserved);
470         if(hres == S_OK)
471             return S_OK;
472     }
473
474     FIXME("default action not implemented\n");
475     return E_NOTIMPL;
476 }
477
478 static HRESULT WINAPI DocHostUIHandler_GetHostInfo(IDocHostUIHandler2 *iface,
479         DOCHOSTUIINFO *pInfo)
480 {
481     DocHost *This = DOCHOSTUI_THIS(iface);
482     HRESULT hres;
483
484     TRACE("(%p)->(%p)\n", This, pInfo);
485
486     if(This->hostui) {
487         hres = IDocHostUIHandler_GetHostInfo(This->hostui, pInfo);
488         if(SUCCEEDED(hres))
489             return hres;
490     }
491
492     pInfo->dwFlags = DOCHOSTUIFLAG_DISABLE_HELP_MENU | DOCHOSTUIFLAG_OPENNEWWIN
493         | DOCHOSTUIFLAG_URL_ENCODING_ENABLE_UTF8 | DOCHOSTUIFLAG_ENABLE_INPLACE_NAVIGATION
494         | DOCHOSTUIFLAG_IME_ENABLE_RECONVERSION;
495     return S_OK;
496 }
497
498 static HRESULT WINAPI DocHostUIHandler_ShowUI(IDocHostUIHandler2 *iface, DWORD dwID,
499         IOleInPlaceActiveObject *pActiveObject, IOleCommandTarget *pCommandTarget,
500         IOleInPlaceFrame *pFrame, IOleInPlaceUIWindow *pDoc)
501 {
502     DocHost *This = DOCHOSTUI_THIS(iface);
503     FIXME("(%p)->(%d %p %p %p %p)\n", This, dwID, pActiveObject, pCommandTarget,
504           pFrame, pDoc);
505     return E_NOTIMPL;
506 }
507
508 static HRESULT WINAPI DocHostUIHandler_HideUI(IDocHostUIHandler2 *iface)
509 {
510     DocHost *This = DOCHOSTUI_THIS(iface);
511     FIXME("(%p)\n", This);
512     return E_NOTIMPL;
513 }
514
515 static HRESULT WINAPI DocHostUIHandler_UpdateUI(IDocHostUIHandler2 *iface)
516 {
517     DocHost *This = DOCHOSTUI_THIS(iface);
518
519     TRACE("(%p)\n", This);
520
521     if(!This->hostui)
522         return S_FALSE;
523
524     return IDocHostUIHandler_UpdateUI(This->hostui);
525 }
526
527 static HRESULT WINAPI DocHostUIHandler_EnableModeless(IDocHostUIHandler2 *iface,
528                                                       BOOL fEnable)
529 {
530     DocHost *This = DOCHOSTUI_THIS(iface);
531     FIXME("(%p)->(%x)\n", This, fEnable);
532     return E_NOTIMPL;
533 }
534
535 static HRESULT WINAPI DocHostUIHandler_OnDocWindowActivate(IDocHostUIHandler2 *iface,
536                                                            BOOL fActivate)
537 {
538     DocHost *This = DOCHOSTUI_THIS(iface);
539     FIXME("(%p)->(%x)\n", This, fActivate);
540     return E_NOTIMPL;
541 }
542
543 static HRESULT WINAPI DocHostUIHandler_OnFrameWindowActivate(IDocHostUIHandler2 *iface,
544                                                              BOOL fActivate)
545 {
546     DocHost *This = DOCHOSTUI_THIS(iface);
547     FIXME("(%p)->(%x)\n", This, fActivate);
548     return E_NOTIMPL;
549 }
550
551 static HRESULT WINAPI DocHostUIHandler_ResizeBorder(IDocHostUIHandler2 *iface,
552         LPCRECT prcBorder, IOleInPlaceUIWindow *pUIWindow, BOOL fRameWindow)
553 {
554     DocHost *This = DOCHOSTUI_THIS(iface);
555     FIXME("(%p)->(%p %p %X)\n", This, prcBorder, pUIWindow, fRameWindow);
556     return E_NOTIMPL;
557 }
558
559 static HRESULT WINAPI DocHostUIHandler_TranslateAccelerator(IDocHostUIHandler2 *iface,
560         LPMSG lpMsg, const GUID *pguidCmdGroup, DWORD nCmdID)
561 {
562     DocHost *This = DOCHOSTUI_THIS(iface);
563     FIXME("(%p)->(%p %p %d)\n", This, lpMsg, pguidCmdGroup, nCmdID);
564     return E_NOTIMPL;
565 }
566
567 static HRESULT WINAPI DocHostUIHandler_GetOptionKeyPath(IDocHostUIHandler2 *iface,
568         LPOLESTR *pchKey, DWORD dw)
569 {
570     DocHost *This = DOCHOSTUI_THIS(iface);
571
572     TRACE("(%p)->(%p %d)\n", This, pchKey, dw);
573
574     if(This->hostui)
575         return IDocHostUIHandler_GetOptionKeyPath(This->hostui, pchKey, dw);
576
577     return S_OK;
578 }
579
580 static HRESULT WINAPI DocHostUIHandler_GetDropTarget(IDocHostUIHandler2 *iface,
581         IDropTarget *pDropTarget, IDropTarget **ppDropTarget)
582 {
583     DocHost *This = DOCHOSTUI_THIS(iface);
584     FIXME("(%p)\n", This);
585     return E_NOTIMPL;
586 }
587
588 static HRESULT WINAPI DocHostUIHandler_GetExternal(IDocHostUIHandler2 *iface,
589         IDispatch **ppDispatch)
590 {
591     DocHost *This = DOCHOSTUI_THIS(iface);
592
593     TRACE("(%p)->(%p)\n", This, ppDispatch);
594
595     if(This->hostui)
596         return IDocHostUIHandler_GetExternal(This->hostui, ppDispatch);
597
598     FIXME("default action not implemented\n");
599     return E_NOTIMPL;
600 }
601
602 static HRESULT WINAPI DocHostUIHandler_TranslateUrl(IDocHostUIHandler2 *iface,
603         DWORD dwTranslate, OLECHAR *pchURLIn, OLECHAR **ppchURLOut)
604 {
605     DocHost *This = DOCHOSTUI_THIS(iface);
606
607     TRACE("(%p)->(%d %s %p)\n", This, dwTranslate, debugstr_w(pchURLIn), ppchURLOut);
608
609     if(This->hostui)
610         return IDocHostUIHandler_TranslateUrl(This->hostui, dwTranslate,
611                                               pchURLIn, ppchURLOut);
612
613     return S_FALSE;
614 }
615
616 static HRESULT WINAPI DocHostUIHandler_FilterDataObject(IDocHostUIHandler2 *iface,
617         IDataObject *pDO, IDataObject **ppDORet)
618 {
619     DocHost *This = DOCHOSTUI_THIS(iface);
620     FIXME("(%p)->(%p %p)\n", This, pDO, ppDORet);
621     return E_NOTIMPL;
622 }
623
624 static HRESULT WINAPI DocHostUIHandler_GetOverrideKeyPath(IDocHostUIHandler2 *iface,
625         LPOLESTR *pchKey, DWORD dw)
626 {
627     DocHost *This = DOCHOSTUI_THIS(iface);
628     IDocHostUIHandler2 *handler;
629     HRESULT hres;
630
631     TRACE("(%p)->(%p %d)\n", This, pchKey, dw);
632
633     if(!This->hostui)
634         return S_OK;
635
636     hres = IDocHostUIHandler_QueryInterface(This->hostui, &IID_IDocHostUIHandler2,
637                                             (void**)&handler);
638     if(SUCCEEDED(hres)) {
639         hres = IDocHostUIHandler2_GetOverrideKeyPath(handler, pchKey, dw);
640         IDocHostUIHandler2_Release(handler);
641         return hres;
642     }
643
644     return S_OK;
645 }
646
647 #undef DOCHOSTUI_THIS
648
649 static const IDocHostUIHandler2Vtbl DocHostUIHandler2Vtbl = {
650     DocHostUIHandler_QueryInterface,
651     DocHostUIHandler_AddRef,
652     DocHostUIHandler_Release,
653     DocHostUIHandler_ShowContextMenu,
654     DocHostUIHandler_GetHostInfo,
655     DocHostUIHandler_ShowUI,
656     DocHostUIHandler_HideUI,
657     DocHostUIHandler_UpdateUI,
658     DocHostUIHandler_EnableModeless,
659     DocHostUIHandler_OnDocWindowActivate,
660     DocHostUIHandler_OnFrameWindowActivate,
661     DocHostUIHandler_ResizeBorder,
662     DocHostUIHandler_TranslateAccelerator,
663     DocHostUIHandler_GetOptionKeyPath,
664     DocHostUIHandler_GetDropTarget,
665     DocHostUIHandler_GetExternal,
666     DocHostUIHandler_TranslateUrl,
667     DocHostUIHandler_FilterDataObject,
668     DocHostUIHandler_GetOverrideKeyPath
669 };
670
671 #define PROPNOTIF_THIS(iface) DEFINE_THIS(DocHost, IPropertyNotifySink, iface)
672
673 static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
674         REFIID riid, void **ppv)
675 {
676     DocHost *This = PROPNOTIF_THIS(iface);
677     return IOleClientSite_QueryInterface(CLIENTSITE(This), riid, ppv);
678 }
679
680 static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
681 {
682     DocHost *This = PROPNOTIF_THIS(iface);
683     return IOleClientSite_AddRef(CLIENTSITE(This));
684 }
685
686 static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
687 {
688     DocHost *This = PROPNOTIF_THIS(iface);
689     return IOleClientSite_Release(CLIENTSITE(This));
690 }
691
692 static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
693 {
694     DocHost *This = PROPNOTIF_THIS(iface);
695
696     TRACE("(%p)->(%d)\n", This, dispID);
697
698     switch(dispID) {
699     case DISPID_READYSTATE: {
700         READYSTATE ready_state;
701         HRESULT hres;
702
703         hres = get_doc_ready_state(This, &ready_state);
704         if(FAILED(hres))
705             return hres;
706
707         if(ready_state == READYSTATE_COMPLETE)
708             advise_prop_notif(This, FALSE);
709
710         push_ready_state_task(This, ready_state);
711         break;
712     }
713     default:
714         FIXME("unimplemented dispid %d\n", dispID);
715         return E_NOTIMPL;
716     }
717
718     return S_OK;
719 }
720
721 static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
722 {
723     DocHost *This = PROPNOTIF_THIS(iface);
724     FIXME("(%p)->(%d)\n", This, dispID);
725     return E_NOTIMPL;
726 }
727
728 #undef PROPNOTIF_THIS
729
730 static const IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
731     PropertyNotifySink_QueryInterface,
732     PropertyNotifySink_AddRef,
733     PropertyNotifySink_Release,
734     PropertyNotifySink_OnChanged,
735     PropertyNotifySink_OnRequestEdit
736 };
737
738 void DocHost_Init(DocHost *This, IDispatch *disp)
739 {
740     This->lpDocHostUIHandlerVtbl = &DocHostUIHandler2Vtbl;
741     This->lpOleCommandTargetVtbl = &OleCommandTargetVtbl;
742     This->lpIPropertyNotifySinkVtbl = &PropertyNotifySinkVtbl;
743
744     This->disp = disp;
745
746     This->client_disp = NULL;
747
748     This->document = NULL;
749     This->hostui = NULL;
750     This->frame = NULL;
751
752     This->hwnd = NULL;
753     This->frame_hwnd = NULL;
754     This->url = NULL;
755
756     This->silent = VARIANT_FALSE;
757     This->offline = VARIANT_FALSE;
758
759     This->ready_state = READYSTATE_UNINITIALIZED;
760     This->is_prop_notif = FALSE;
761
762     DocHost_ClientSite_Init(This);
763     DocHost_Frame_Init(This);
764
765     ConnectionPointContainer_Init(&This->cps, (IUnknown*)disp);
766 }
767
768 void DocHost_Release(DocHost *This)
769 {
770     release_dochost_client(This);
771     DocHost_ClientSite_Release(This);
772
773     ConnectionPointContainer_Destroy(&This->cps);
774
775     CoTaskMemFree(This->url);
776 }