comctl32/treeview: Always return state from TVM_GETITEM handler.
[wine/multimedia.git] / dlls / shdocvw / dochost.c
blob301ea3254c6210b15e73cce56a02242e5db3c0d5
1 /*
2 * Copyright 2005-2006 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 "wine/debug.h"
20 #include "shdocvw.h"
21 #include "hlink.h"
22 #include "exdispid.h"
23 #include "mshtml.h"
24 #include "initguid.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(shdocvw);
28 DEFINE_OLEGUID(CGID_DocHostCmdPriv, 0x000214D4L, 0, 0);
30 #define DOCHOST_DOCCANNAVIGATE 0
32 static ATOM doc_view_atom = 0;
34 void push_dochost_task(DocHost *This, task_header_t *task, task_proc_t proc, BOOL send)
36 task->proc = proc;
38 /* FIXME: Don't use lParam */
39 if(send)
40 SendMessageW(This->frame_hwnd, WM_DOCHOSTTASK, 0, (LPARAM)task);
41 else
42 PostMessageW(This->frame_hwnd, WM_DOCHOSTTASK, 0, (LPARAM)task);
45 LRESULT process_dochost_task(DocHost *This, LPARAM lparam)
47 task_header_t *task = (task_header_t*)lparam;
49 task->proc(This, task);
51 heap_free(task);
52 return 0;
55 static void notif_complete(DocHost *This, DISPID dispid)
57 DISPPARAMS dispparams;
58 VARIANTARG params[2];
59 VARIANT url;
61 dispparams.cArgs = 2;
62 dispparams.cNamedArgs = 0;
63 dispparams.rgdispidNamedArgs = NULL;
64 dispparams.rgvarg = params;
66 V_VT(params) = (VT_BYREF|VT_VARIANT);
67 V_BYREF(params) = &url;
69 V_VT(params+1) = VT_DISPATCH;
70 V_DISPATCH(params+1) = This->disp;
72 V_VT(&url) = VT_BSTR;
73 V_BSTR(&url) = SysAllocString(This->url);
75 TRACE("%d >>>\n", dispid);
76 call_sink(This->cps.wbe2, dispid, &dispparams);
77 TRACE("%d <<<\n", dispid);
79 SysFreeString(V_BSTR(&url));
80 This->busy = VARIANT_FALSE;
83 static void object_available(DocHost *This)
85 IHlinkTarget *hlink;
86 HRESULT hres;
88 TRACE("(%p)\n", This);
90 if(!This->document) {
91 WARN("document == NULL\n");
92 return;
95 hres = IUnknown_QueryInterface(This->document, &IID_IHlinkTarget, (void**)&hlink);
96 if(FAILED(hres)) {
97 FIXME("Could not get IHlinkTarget interface\n");
98 return;
101 hres = IHlinkTarget_Navigate(hlink, 0, NULL);
102 IHlinkTarget_Release(hlink);
103 if(FAILED(hres))
104 FIXME("Navigate failed\n");
107 static HRESULT get_doc_ready_state(DocHost *This, READYSTATE *ret)
109 DISPPARAMS dp = {NULL,NULL,0,0};
110 IDispatch *disp;
111 EXCEPINFO ei;
112 VARIANT var;
113 HRESULT hres;
115 hres = IUnknown_QueryInterface(This->document, &IID_IDispatch, (void**)&disp);
116 if(FAILED(hres))
117 return hres;
119 hres = IDispatch_Invoke(disp, DISPID_READYSTATE, &IID_NULL, LOCALE_SYSTEM_DEFAULT, DISPATCH_PROPERTYGET,
120 &dp, &var, &ei, NULL);
121 IDispatch_Release(disp);
122 if(FAILED(hres)) {
123 WARN("Invoke(DISPID_READYSTATE failed: %08x\n", hres);
124 return hres;
127 if(V_VT(&var) != VT_I4) {
128 WARN("V_VT(var) = %d\n", V_VT(&var));
129 VariantClear(&var);
130 return E_FAIL;
133 *ret = V_I4(&var);
134 return S_OK;
137 static void advise_prop_notif(DocHost *This, BOOL set)
139 IConnectionPointContainer *cp_container;
140 IConnectionPoint *cp;
141 HRESULT hres;
143 hres = IUnknown_QueryInterface(This->document, &IID_IConnectionPointContainer, (void**)&cp_container);
144 if(FAILED(hres))
145 return;
147 hres = IConnectionPointContainer_FindConnectionPoint(cp_container, &IID_IPropertyNotifySink, &cp);
148 IConnectionPointContainer_Release(cp_container);
149 if(FAILED(hres))
150 return;
152 if(set)
153 hres = IConnectionPoint_Advise(cp, (IUnknown*)&This->IPropertyNotifySink_iface, &This->prop_notif_cookie);
154 else
155 hres = IConnectionPoint_Unadvise(cp, This->prop_notif_cookie);
156 IConnectionPoint_Release(cp);
158 if(SUCCEEDED(hres))
159 This->is_prop_notif = set;
162 void set_doc_state(DocHost *This, READYSTATE doc_state)
164 This->doc_state = doc_state;
165 if(doc_state > This->ready_state)
166 This->ready_state = doc_state;
169 static void update_ready_state(DocHost *This, READYSTATE ready_state)
171 if(ready_state > READYSTATE_LOADING && This->doc_state <= READYSTATE_LOADING)
172 notif_complete(This, DISPID_NAVIGATECOMPLETE2);
174 if(ready_state == READYSTATE_COMPLETE && This->doc_state < READYSTATE_COMPLETE) {
175 set_doc_state(This, READYSTATE_COMPLETE);
176 notif_complete(This, DISPID_DOCUMENTCOMPLETE);
177 }else {
178 set_doc_state(This, ready_state);
182 typedef struct {
183 task_header_t header;
184 IUnknown *doc;
185 READYSTATE ready_state;
186 } ready_state_task_t;
188 static void ready_state_proc(DocHost *This, task_header_t *_task)
190 ready_state_task_t *task = (ready_state_task_t*)_task;
192 if(task->doc == This->document)
193 update_ready_state(This, task->ready_state);
195 IUnknown_Release(task->doc);
198 static void push_ready_state_task(DocHost *This, READYSTATE ready_state)
200 ready_state_task_t *task = heap_alloc(sizeof(ready_state_task_t));
202 IUnknown_AddRef(This->document);
203 task->doc = This->document;
204 task->ready_state = ready_state;
206 push_dochost_task(This, &task->header, ready_state_proc, FALSE);
209 static void object_available_proc(DocHost *This, task_header_t *task)
211 object_available(This);
214 HRESULT dochost_object_available(DocHost *This, IUnknown *doc)
216 READYSTATE ready_state;
217 task_header_t *task;
218 IOleObject *oleobj;
219 HRESULT hres;
221 IUnknown_AddRef(doc);
222 This->document = doc;
224 hres = IUnknown_QueryInterface(doc, &IID_IOleObject, (void**)&oleobj);
225 if(SUCCEEDED(hres)) {
226 CLSID clsid;
228 hres = IOleObject_GetUserClassID(oleobj, &clsid);
229 if(SUCCEEDED(hres))
230 TRACE("Got clsid %s\n",
231 IsEqualGUID(&clsid, &CLSID_HTMLDocument) ? "CLSID_HTMLDocument" : debugstr_guid(&clsid));
233 hres = IOleObject_SetClientSite(oleobj, &This->IOleClientSite_iface);
234 if(FAILED(hres))
235 FIXME("SetClientSite failed: %08x\n", hres);
237 IOleObject_Release(oleobj);
238 }else {
239 FIXME("Could not get IOleObject iface: %08x\n", hres);
242 /* FIXME: Call SetAdvise */
244 task = heap_alloc(sizeof(*task));
245 push_dochost_task(This, task, object_available_proc, FALSE);
247 hres = get_doc_ready_state(This, &ready_state);
248 if(SUCCEEDED(hres)) {
249 if(ready_state == READYSTATE_COMPLETE)
250 push_ready_state_task(This, READYSTATE_COMPLETE);
251 if(ready_state != READYSTATE_COMPLETE || This->doc_navigate)
252 advise_prop_notif(This, TRUE);
255 return S_OK;
258 static LRESULT resize_document(DocHost *This, LONG width, LONG height)
260 RECT rect = {0, 0, width, height};
262 TRACE("(%p)->(%d %d)\n", This, width, height);
264 if(This->view)
265 IOleDocumentView_SetRect(This->view, &rect);
267 return 0;
270 static LRESULT WINAPI doc_view_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
272 DocHost *This;
274 static const WCHAR wszTHIS[] = {'T','H','I','S',0};
276 if(msg == WM_CREATE) {
277 This = *(DocHost**)lParam;
278 SetPropW(hwnd, wszTHIS, This);
279 }else {
280 This = GetPropW(hwnd, wszTHIS);
283 switch(msg) {
284 case WM_SIZE:
285 return resize_document(This, LOWORD(lParam), HIWORD(lParam));
288 return DefWindowProcW(hwnd, msg, wParam, lParam);
291 void create_doc_view_hwnd(DocHost *This)
293 RECT rect;
295 static const WCHAR wszShell_DocObject_View[] =
296 {'S','h','e','l','l',' ','D','o','c','O','b','j','e','c','t',' ','V','i','e','w',0};
298 if(!doc_view_atom) {
299 static WNDCLASSEXW wndclass = {
300 sizeof(wndclass),
301 CS_PARENTDC,
302 doc_view_proc,
303 0, 0 /* native uses 4*/, NULL, NULL, NULL,
304 (HBRUSH)(COLOR_WINDOW + 1), NULL,
305 wszShell_DocObject_View,
306 NULL
309 wndclass.hInstance = shdocvw_hinstance;
311 doc_view_atom = RegisterClassExW(&wndclass);
314 This->container_vtbl->GetDocObjRect(This, &rect);
315 This->hwnd = CreateWindowExW(0, wszShell_DocObject_View,
316 wszShell_DocObject_View,
317 WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_TABSTOP,
318 rect.left, rect.top, rect.right, rect.bottom, This->frame_hwnd,
319 NULL, shdocvw_hinstance, This);
322 void deactivate_document(DocHost *This)
324 IOleInPlaceObjectWindowless *winobj;
325 IOleObject *oleobj = NULL;
326 IHlinkTarget *hlink = NULL;
327 HRESULT hres;
329 if(!This->document) return;
331 if(This->doc_navigate) {
332 IUnknown_Release(This->doc_navigate);
333 This->doc_navigate = NULL;
336 if(This->is_prop_notif)
337 advise_prop_notif(This, FALSE);
339 if(This->view)
340 IOleDocumentView_UIActivate(This->view, FALSE);
342 hres = IUnknown_QueryInterface(This->document, &IID_IOleInPlaceObjectWindowless,
343 (void**)&winobj);
344 if(SUCCEEDED(hres)) {
345 IOleInPlaceObjectWindowless_InPlaceDeactivate(winobj);
346 IOleInPlaceObjectWindowless_Release(winobj);
349 if(This->view) {
350 IOleDocumentView_Show(This->view, FALSE);
351 IOleDocumentView_CloseView(This->view, 0);
352 IOleDocumentView_SetInPlaceSite(This->view, NULL);
353 IOleDocumentView_Release(This->view);
354 This->view = NULL;
357 hres = IUnknown_QueryInterface(This->document, &IID_IOleObject, (void**)&oleobj);
358 if(SUCCEEDED(hres))
359 IOleObject_Close(oleobj, OLECLOSE_NOSAVE);
361 hres = IUnknown_QueryInterface(This->document, &IID_IHlinkTarget, (void**)&hlink);
362 if(SUCCEEDED(hres)) {
363 IHlinkTarget_SetBrowseContext(hlink, NULL);
364 IHlinkTarget_Release(hlink);
367 if(oleobj) {
368 IOleClientSite *client_site = NULL;
370 IOleObject_GetClientSite(oleobj, &client_site);
371 if(client_site) {
372 if(client_site == &This->IOleClientSite_iface)
373 IOleObject_SetClientSite(oleobj, NULL);
374 IOleClientSite_Release(client_site);
377 IOleObject_Release(oleobj);
380 IUnknown_Release(This->document);
381 This->document = NULL;
384 void release_dochost_client(DocHost *This)
386 if(This->hwnd) {
387 DestroyWindow(This->hwnd);
388 This->hwnd = NULL;
391 if(This->hostui) {
392 IDocHostUIHandler_Release(This->hostui);
393 This->hostui = NULL;
396 if(This->client_disp) {
397 IDispatch_Release(This->client_disp);
398 This->client_disp = NULL;
401 if(This->frame) {
402 IOleInPlaceFrame_Release(This->frame);
403 This->frame = NULL;
407 static inline DocHost *impl_from_IOleCommandTarget(IOleCommandTarget *iface)
409 return CONTAINING_RECORD(iface, DocHost, IOleCommandTarget_iface);
412 static HRESULT WINAPI ClOleCommandTarget_QueryInterface(IOleCommandTarget *iface,
413 REFIID riid, void **ppv)
415 DocHost *This = impl_from_IOleCommandTarget(iface);
416 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
419 static ULONG WINAPI ClOleCommandTarget_AddRef(IOleCommandTarget *iface)
421 DocHost *This = impl_from_IOleCommandTarget(iface);
422 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
425 static ULONG WINAPI ClOleCommandTarget_Release(IOleCommandTarget *iface)
427 DocHost *This = impl_from_IOleCommandTarget(iface);
428 return IOleClientSite_Release(&This->IOleClientSite_iface);
431 static HRESULT WINAPI ClOleCommandTarget_QueryStatus(IOleCommandTarget *iface,
432 const GUID *pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[], OLECMDTEXT *pCmdText)
434 DocHost *This = impl_from_IOleCommandTarget(iface);
435 ULONG i= 0;
436 FIXME("(%p)->(%s %u %p %p)\n", This, debugstr_guid(pguidCmdGroup), cCmds, prgCmds,
437 pCmdText);
438 while (prgCmds && (cCmds > i)) {
439 FIXME("command_%u: %u, 0x%x\n", i, prgCmds[i].cmdID, prgCmds[i].cmdf);
440 i++;
442 return E_NOTIMPL;
445 static HRESULT WINAPI ClOleCommandTarget_Exec(IOleCommandTarget *iface,
446 const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn,
447 VARIANT *pvaOut)
449 DocHost *This = impl_from_IOleCommandTarget(iface);
451 TRACE("(%p)->(%s %d %d %p %p)\n", This, debugstr_guid(pguidCmdGroup), nCmdID,
452 nCmdexecopt, debugstr_variant(pvaIn), debugstr_variant(pvaOut));
454 if(!pguidCmdGroup) {
455 switch(nCmdID) {
456 case OLECMDID_UPDATECOMMANDS:
457 return This->container_vtbl->exec(This, pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);
458 default:
459 FIXME("Unimplemented cmdid %d\n", nCmdID);
460 return E_NOTIMPL;
462 return S_OK;
465 if(IsEqualGUID(pguidCmdGroup, &CGID_DocHostCmdPriv)) {
466 switch(nCmdID) {
467 case DOCHOST_DOCCANNAVIGATE:
468 if(!pvaIn || V_VT(pvaIn) != VT_UNKNOWN)
469 return E_INVALIDARG;
471 if(This->doc_navigate)
472 IUnknown_Release(This->doc_navigate);
473 IUnknown_AddRef(V_UNKNOWN(pvaIn));
474 This->doc_navigate = V_UNKNOWN(pvaIn);
475 return S_OK;
477 case 1: {
478 IHTMLWindow2 *win2;
479 SAFEARRAY *sa = V_ARRAY(pvaIn);
480 VARIANT status_code, url, htmlwindow;
481 LONG ind;
482 HRESULT hres;
484 if(V_VT(pvaIn) != VT_ARRAY || !sa || (SafeArrayGetDim(sa) != 1))
485 return E_INVALIDARG;
487 ind = 0;
488 hres = SafeArrayGetElement(sa, &ind, &status_code);
489 if(FAILED(hres) || V_VT(&status_code)!=VT_I4)
490 return E_INVALIDARG;
492 ind = 1;
493 hres = SafeArrayGetElement(sa, &ind, &url);
494 if(FAILED(hres) || V_VT(&url)!=VT_BSTR)
495 return E_INVALIDARG;
497 ind = 3;
498 hres = SafeArrayGetElement(sa, &ind, &htmlwindow);
499 if(FAILED(hres) || V_VT(&htmlwindow)!=VT_UNKNOWN || !V_UNKNOWN(&htmlwindow))
500 return E_INVALIDARG;
502 hres = IUnknown_QueryInterface(V_UNKNOWN(&htmlwindow), &IID_IHTMLWindow2, (void**)&win2);
503 if(FAILED(hres))
504 return E_INVALIDARG;
506 handle_navigation_error(This, V_I4(&status_code), V_BSTR(&url), win2);
507 IHTMLWindow2_Release(win2);
508 return S_OK;
511 default:
512 FIXME("unsupported command %d of CGID_DocHostCmdPriv\n", nCmdID);
513 return E_NOTIMPL;
517 FIXME("Unimplemented group %s\n", debugstr_guid(pguidCmdGroup));
518 return E_NOTIMPL;
521 #undef impl_from_IOleCommandTarget
523 static const IOleCommandTargetVtbl OleCommandTargetVtbl = {
524 ClOleCommandTarget_QueryInterface,
525 ClOleCommandTarget_AddRef,
526 ClOleCommandTarget_Release,
527 ClOleCommandTarget_QueryStatus,
528 ClOleCommandTarget_Exec
531 static inline DocHost *impl_from_IDocHostUIHandler2(IDocHostUIHandler2 *iface)
533 return CONTAINING_RECORD(iface, DocHost, IDocHostUIHandler2_iface);
536 static HRESULT WINAPI DocHostUIHandler_QueryInterface(IDocHostUIHandler2 *iface,
537 REFIID riid, void **ppv)
539 DocHost *This = impl_from_IDocHostUIHandler2(iface);
540 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
543 static ULONG WINAPI DocHostUIHandler_AddRef(IDocHostUIHandler2 *iface)
545 DocHost *This = impl_from_IDocHostUIHandler2(iface);
546 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
549 static ULONG WINAPI DocHostUIHandler_Release(IDocHostUIHandler2 *iface)
551 DocHost *This = impl_from_IDocHostUIHandler2(iface);
552 return IOleClientSite_Release(&This->IOleClientSite_iface);
555 static HRESULT WINAPI DocHostUIHandler_ShowContextMenu(IDocHostUIHandler2 *iface,
556 DWORD dwID, POINT *ppt, IUnknown *pcmdtReserved, IDispatch *pdispReserved)
558 DocHost *This = impl_from_IDocHostUIHandler2(iface);
559 HRESULT hres;
561 TRACE("(%p)->(%d %p %p %p)\n", This, dwID, ppt, pcmdtReserved, pdispReserved);
563 if(This->hostui) {
564 hres = IDocHostUIHandler_ShowContextMenu(This->hostui, dwID, ppt, pcmdtReserved,
565 pdispReserved);
566 if(hres == S_OK)
567 return S_OK;
570 FIXME("default action not implemented\n");
571 return E_NOTIMPL;
574 static HRESULT WINAPI DocHostUIHandler_GetHostInfo(IDocHostUIHandler2 *iface,
575 DOCHOSTUIINFO *pInfo)
577 DocHost *This = impl_from_IDocHostUIHandler2(iface);
578 HRESULT hres;
580 TRACE("(%p)->(%p)\n", This, pInfo);
582 if(This->hostui) {
583 hres = IDocHostUIHandler_GetHostInfo(This->hostui, pInfo);
584 if(SUCCEEDED(hres))
585 return hres;
588 pInfo->dwFlags = DOCHOSTUIFLAG_DISABLE_HELP_MENU | DOCHOSTUIFLAG_OPENNEWWIN
589 | DOCHOSTUIFLAG_URL_ENCODING_ENABLE_UTF8 | DOCHOSTUIFLAG_ENABLE_INPLACE_NAVIGATION
590 | DOCHOSTUIFLAG_IME_ENABLE_RECONVERSION;
591 return S_OK;
594 static HRESULT WINAPI DocHostUIHandler_ShowUI(IDocHostUIHandler2 *iface, DWORD dwID,
595 IOleInPlaceActiveObject *pActiveObject, IOleCommandTarget *pCommandTarget,
596 IOleInPlaceFrame *pFrame, IOleInPlaceUIWindow *pDoc)
598 DocHost *This = impl_from_IDocHostUIHandler2(iface);
599 FIXME("(%p)->(%d %p %p %p %p)\n", This, dwID, pActiveObject, pCommandTarget,
600 pFrame, pDoc);
601 return E_NOTIMPL;
604 static HRESULT WINAPI DocHostUIHandler_HideUI(IDocHostUIHandler2 *iface)
606 DocHost *This = impl_from_IDocHostUIHandler2(iface);
607 FIXME("(%p)\n", This);
608 return E_NOTIMPL;
611 static HRESULT WINAPI DocHostUIHandler_UpdateUI(IDocHostUIHandler2 *iface)
613 DocHost *This = impl_from_IDocHostUIHandler2(iface);
615 TRACE("(%p)\n", This);
617 if(!This->hostui)
618 return S_FALSE;
620 return IDocHostUIHandler_UpdateUI(This->hostui);
623 static HRESULT WINAPI DocHostUIHandler_EnableModeless(IDocHostUIHandler2 *iface,
624 BOOL fEnable)
626 DocHost *This = impl_from_IDocHostUIHandler2(iface);
627 FIXME("(%p)->(%x)\n", This, fEnable);
628 return E_NOTIMPL;
631 static HRESULT WINAPI DocHostUIHandler_OnDocWindowActivate(IDocHostUIHandler2 *iface,
632 BOOL fActivate)
634 DocHost *This = impl_from_IDocHostUIHandler2(iface);
635 FIXME("(%p)->(%x)\n", This, fActivate);
636 return E_NOTIMPL;
639 static HRESULT WINAPI DocHostUIHandler_OnFrameWindowActivate(IDocHostUIHandler2 *iface,
640 BOOL fActivate)
642 DocHost *This = impl_from_IDocHostUIHandler2(iface);
643 FIXME("(%p)->(%x)\n", This, fActivate);
644 return E_NOTIMPL;
647 static HRESULT WINAPI DocHostUIHandler_ResizeBorder(IDocHostUIHandler2 *iface,
648 LPCRECT prcBorder, IOleInPlaceUIWindow *pUIWindow, BOOL fRameWindow)
650 DocHost *This = impl_from_IDocHostUIHandler2(iface);
651 FIXME("(%p)->(%p %p %X)\n", This, prcBorder, pUIWindow, fRameWindow);
652 return E_NOTIMPL;
655 static HRESULT WINAPI DocHostUIHandler_TranslateAccelerator(IDocHostUIHandler2 *iface,
656 LPMSG lpMsg, const GUID *pguidCmdGroup, DWORD nCmdID)
658 DocHost *This = impl_from_IDocHostUIHandler2(iface);
659 HRESULT hr = S_FALSE;
660 TRACE("(%p)->(%p %p %d)\n", This, lpMsg, pguidCmdGroup, nCmdID);
662 if(This->hostui)
663 hr = IDocHostUIHandler_TranslateAccelerator(This->hostui, lpMsg, pguidCmdGroup, nCmdID);
665 return hr;
668 static HRESULT WINAPI DocHostUIHandler_GetOptionKeyPath(IDocHostUIHandler2 *iface,
669 LPOLESTR *pchKey, DWORD dw)
671 DocHost *This = impl_from_IDocHostUIHandler2(iface);
673 TRACE("(%p)->(%p %d)\n", This, pchKey, dw);
675 if(This->hostui)
676 return IDocHostUIHandler_GetOptionKeyPath(This->hostui, pchKey, dw);
678 return S_OK;
681 static HRESULT WINAPI DocHostUIHandler_GetDropTarget(IDocHostUIHandler2 *iface,
682 IDropTarget *pDropTarget, IDropTarget **ppDropTarget)
684 DocHost *This = impl_from_IDocHostUIHandler2(iface);
685 FIXME("(%p)\n", This);
686 return E_NOTIMPL;
689 static HRESULT WINAPI DocHostUIHandler_GetExternal(IDocHostUIHandler2 *iface,
690 IDispatch **ppDispatch)
692 DocHost *This = impl_from_IDocHostUIHandler2(iface);
694 TRACE("(%p)->(%p)\n", This, ppDispatch);
696 if(This->hostui)
697 return IDocHostUIHandler_GetExternal(This->hostui, ppDispatch);
699 FIXME("default action not implemented\n");
700 return E_NOTIMPL;
703 static HRESULT WINAPI DocHostUIHandler_TranslateUrl(IDocHostUIHandler2 *iface,
704 DWORD dwTranslate, OLECHAR *pchURLIn, OLECHAR **ppchURLOut)
706 DocHost *This = impl_from_IDocHostUIHandler2(iface);
708 TRACE("(%p)->(%d %s %p)\n", This, dwTranslate, debugstr_w(pchURLIn), ppchURLOut);
710 if(This->hostui)
711 return IDocHostUIHandler_TranslateUrl(This->hostui, dwTranslate,
712 pchURLIn, ppchURLOut);
714 return S_FALSE;
717 static HRESULT WINAPI DocHostUIHandler_FilterDataObject(IDocHostUIHandler2 *iface,
718 IDataObject *pDO, IDataObject **ppDORet)
720 DocHost *This = impl_from_IDocHostUIHandler2(iface);
721 FIXME("(%p)->(%p %p)\n", This, pDO, ppDORet);
722 return E_NOTIMPL;
725 static HRESULT WINAPI DocHostUIHandler_GetOverrideKeyPath(IDocHostUIHandler2 *iface,
726 LPOLESTR *pchKey, DWORD dw)
728 DocHost *This = impl_from_IDocHostUIHandler2(iface);
729 IDocHostUIHandler2 *handler;
730 HRESULT hres;
732 TRACE("(%p)->(%p %d)\n", This, pchKey, dw);
734 if(!This->hostui)
735 return S_OK;
737 hres = IDocHostUIHandler_QueryInterface(This->hostui, &IID_IDocHostUIHandler2,
738 (void**)&handler);
739 if(SUCCEEDED(hres)) {
740 hres = IDocHostUIHandler2_GetOverrideKeyPath(handler, pchKey, dw);
741 IDocHostUIHandler2_Release(handler);
742 return hres;
745 return S_OK;
748 static const IDocHostUIHandler2Vtbl DocHostUIHandler2Vtbl = {
749 DocHostUIHandler_QueryInterface,
750 DocHostUIHandler_AddRef,
751 DocHostUIHandler_Release,
752 DocHostUIHandler_ShowContextMenu,
753 DocHostUIHandler_GetHostInfo,
754 DocHostUIHandler_ShowUI,
755 DocHostUIHandler_HideUI,
756 DocHostUIHandler_UpdateUI,
757 DocHostUIHandler_EnableModeless,
758 DocHostUIHandler_OnDocWindowActivate,
759 DocHostUIHandler_OnFrameWindowActivate,
760 DocHostUIHandler_ResizeBorder,
761 DocHostUIHandler_TranslateAccelerator,
762 DocHostUIHandler_GetOptionKeyPath,
763 DocHostUIHandler_GetDropTarget,
764 DocHostUIHandler_GetExternal,
765 DocHostUIHandler_TranslateUrl,
766 DocHostUIHandler_FilterDataObject,
767 DocHostUIHandler_GetOverrideKeyPath
770 static inline DocHost *impl_from_IPropertyNotifySink(IPropertyNotifySink *iface)
772 return CONTAINING_RECORD(iface, DocHost, IPropertyNotifySink_iface);
775 static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
776 REFIID riid, void **ppv)
778 DocHost *This = impl_from_IPropertyNotifySink(iface);
779 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
782 static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
784 DocHost *This = impl_from_IPropertyNotifySink(iface);
785 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
788 static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
790 DocHost *This = impl_from_IPropertyNotifySink(iface);
791 return IOleClientSite_Release(&This->IOleClientSite_iface);
794 static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
796 DocHost *This = impl_from_IPropertyNotifySink(iface);
798 TRACE("(%p)->(%d)\n", This, dispID);
800 switch(dispID) {
801 case DISPID_READYSTATE: {
802 READYSTATE ready_state;
803 HRESULT hres;
805 hres = get_doc_ready_state(This, &ready_state);
806 if(FAILED(hres))
807 return hres;
809 if(ready_state == READYSTATE_COMPLETE && !This->doc_navigate)
810 advise_prop_notif(This, FALSE);
812 push_ready_state_task(This, ready_state);
813 break;
815 default:
816 FIXME("unimplemented dispid %d\n", dispID);
817 return E_NOTIMPL;
820 return S_OK;
823 static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
825 DocHost *This = impl_from_IPropertyNotifySink(iface);
826 FIXME("(%p)->(%d)\n", This, dispID);
827 return E_NOTIMPL;
830 static const IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
831 PropertyNotifySink_QueryInterface,
832 PropertyNotifySink_AddRef,
833 PropertyNotifySink_Release,
834 PropertyNotifySink_OnChanged,
835 PropertyNotifySink_OnRequestEdit
838 void DocHost_Init(DocHost *This, IDispatch *disp, const IDocHostContainerVtbl* container)
840 This->IDocHostUIHandler2_iface.lpVtbl = &DocHostUIHandler2Vtbl;
841 This->IOleCommandTarget_iface.lpVtbl = &OleCommandTargetVtbl;
842 This->IPropertyNotifySink_iface.lpVtbl = &PropertyNotifySinkVtbl;
844 This->disp = disp;
845 This->container_vtbl = container;
847 This->ready_state = READYSTATE_UNINITIALIZED;
849 DocHost_ClientSite_Init(This);
850 DocHost_Frame_Init(This);
852 ConnectionPointContainer_Init(&This->cps, (IUnknown*)disp);
855 void DocHost_Release(DocHost *This)
857 release_dochost_client(This);
858 DocHost_ClientSite_Release(This);
860 ConnectionPointContainer_Destroy(&This->cps);
862 heap_free(This->url);