advapi32: Remove wrong "is NULL and error out" code (coccicheck).
[wine/wine-gecko.git] / dlls / shdocvw / dochost.c
blob2ab79758d95064b1e5ed22f6eb947fba4e8c3e64
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, task_destr_t destr, BOOL send)
36 BOOL is_empty;
38 task->proc = proc;
39 task->destr = destr;
41 is_empty = list_empty(&This->task_queue);
42 list_add_tail(&This->task_queue, &task->entry);
44 if(send)
45 SendMessageW(This->frame_hwnd, WM_DOCHOSTTASK, 0, 0);
46 else if(is_empty)
47 PostMessageW(This->frame_hwnd, WM_DOCHOSTTASK, 0, 0);
50 LRESULT process_dochost_tasks(DocHost *This)
52 task_header_t *task;
54 while(!list_empty(&This->task_queue)) {
55 task = LIST_ENTRY(This->task_queue.next, task_header_t, entry);
56 list_remove(&task->entry);
58 task->proc(This, task);
59 task->destr(task);
62 return 0;
65 void abort_dochost_tasks(DocHost *This, task_proc_t proc)
67 task_header_t *task, *cursor;
69 LIST_FOR_EACH_ENTRY_SAFE(task, cursor, &This->task_queue, task_header_t, entry) {
70 if(proc && proc != task->proc)
71 continue;
73 list_remove(&task->entry);
74 task->destr(task);
78 static void notif_complete(DocHost *This, DISPID dispid)
80 DISPPARAMS dispparams;
81 VARIANTARG params[2];
82 VARIANT url;
84 dispparams.cArgs = 2;
85 dispparams.cNamedArgs = 0;
86 dispparams.rgdispidNamedArgs = NULL;
87 dispparams.rgvarg = params;
89 V_VT(params) = (VT_BYREF|VT_VARIANT);
90 V_BYREF(params) = &url;
92 V_VT(params+1) = VT_DISPATCH;
93 V_DISPATCH(params+1) = This->disp;
95 V_VT(&url) = VT_BSTR;
96 V_BSTR(&url) = SysAllocString(This->url);
98 TRACE("%d >>>\n", dispid);
99 call_sink(This->cps.wbe2, dispid, &dispparams);
100 TRACE("%d <<<\n", dispid);
102 SysFreeString(V_BSTR(&url));
103 This->busy = VARIANT_FALSE;
106 static void object_available(DocHost *This)
108 IHlinkTarget *hlink;
109 HRESULT hres;
111 TRACE("(%p)\n", This);
113 if(!This->document) {
114 WARN("document == NULL\n");
115 return;
118 hres = IUnknown_QueryInterface(This->document, &IID_IHlinkTarget, (void**)&hlink);
119 if(FAILED(hres)) {
120 FIXME("Could not get IHlinkTarget interface\n");
121 return;
124 hres = IHlinkTarget_Navigate(hlink, 0, NULL);
125 IHlinkTarget_Release(hlink);
126 if(FAILED(hres))
127 FIXME("Navigate failed\n");
130 static HRESULT get_doc_ready_state(DocHost *This, READYSTATE *ret)
132 DISPPARAMS dp = {NULL,NULL,0,0};
133 IDispatch *disp;
134 EXCEPINFO ei;
135 VARIANT var;
136 HRESULT hres;
138 hres = IUnknown_QueryInterface(This->document, &IID_IDispatch, (void**)&disp);
139 if(FAILED(hres))
140 return hres;
142 hres = IDispatch_Invoke(disp, DISPID_READYSTATE, &IID_NULL, LOCALE_SYSTEM_DEFAULT, DISPATCH_PROPERTYGET,
143 &dp, &var, &ei, NULL);
144 IDispatch_Release(disp);
145 if(FAILED(hres)) {
146 WARN("Invoke(DISPID_READYSTATE failed: %08x\n", hres);
147 return hres;
150 if(V_VT(&var) != VT_I4) {
151 WARN("V_VT(var) = %d\n", V_VT(&var));
152 VariantClear(&var);
153 return E_FAIL;
156 *ret = V_I4(&var);
157 return S_OK;
160 static void advise_prop_notif(DocHost *This, BOOL set)
162 IConnectionPointContainer *cp_container;
163 IConnectionPoint *cp;
164 HRESULT hres;
166 hres = IUnknown_QueryInterface(This->document, &IID_IConnectionPointContainer, (void**)&cp_container);
167 if(FAILED(hres))
168 return;
170 hres = IConnectionPointContainer_FindConnectionPoint(cp_container, &IID_IPropertyNotifySink, &cp);
171 IConnectionPointContainer_Release(cp_container);
172 if(FAILED(hres))
173 return;
175 if(set)
176 hres = IConnectionPoint_Advise(cp, (IUnknown*)&This->IPropertyNotifySink_iface, &This->prop_notif_cookie);
177 else
178 hres = IConnectionPoint_Unadvise(cp, This->prop_notif_cookie);
179 IConnectionPoint_Release(cp);
181 if(SUCCEEDED(hres))
182 This->is_prop_notif = set;
185 void set_doc_state(DocHost *This, READYSTATE doc_state)
187 This->doc_state = doc_state;
188 if(doc_state > This->ready_state)
189 This->ready_state = doc_state;
192 static void update_ready_state(DocHost *This, READYSTATE ready_state)
194 if(ready_state > READYSTATE_LOADING && This->doc_state <= READYSTATE_LOADING)
195 notif_complete(This, DISPID_NAVIGATECOMPLETE2);
197 if(ready_state == READYSTATE_COMPLETE && This->doc_state < READYSTATE_COMPLETE) {
198 set_doc_state(This, READYSTATE_COMPLETE);
199 notif_complete(This, DISPID_DOCUMENTCOMPLETE);
200 }else {
201 set_doc_state(This, ready_state);
205 typedef struct {
206 task_header_t header;
207 IUnknown *doc;
208 READYSTATE ready_state;
209 } ready_state_task_t;
211 static void ready_state_task_destr(task_header_t *_task)
213 ready_state_task_t *task = (ready_state_task_t*)_task;
215 IUnknown_Release(task->doc);
216 heap_free(task);
219 static void ready_state_proc(DocHost *This, task_header_t *_task)
221 ready_state_task_t *task = (ready_state_task_t*)_task;
223 if(task->doc == This->document)
224 update_ready_state(This, task->ready_state);
227 static void push_ready_state_task(DocHost *This, READYSTATE ready_state)
229 ready_state_task_t *task = heap_alloc(sizeof(ready_state_task_t));
231 IUnknown_AddRef(This->document);
232 task->doc = This->document;
233 task->ready_state = ready_state;
235 push_dochost_task(This, &task->header, ready_state_proc, ready_state_task_destr, FALSE);
238 static void object_available_task_destr(task_header_t *task)
240 heap_free(task);
243 static void object_available_proc(DocHost *This, task_header_t *task)
245 object_available(This);
248 HRESULT dochost_object_available(DocHost *This, IUnknown *doc)
250 READYSTATE ready_state;
251 task_header_t *task;
252 IOleObject *oleobj;
253 HRESULT hres;
255 IUnknown_AddRef(doc);
256 This->document = doc;
258 hres = IUnknown_QueryInterface(doc, &IID_IOleObject, (void**)&oleobj);
259 if(SUCCEEDED(hres)) {
260 CLSID clsid;
262 hres = IOleObject_GetUserClassID(oleobj, &clsid);
263 if(SUCCEEDED(hres))
264 TRACE("Got clsid %s\n",
265 IsEqualGUID(&clsid, &CLSID_HTMLDocument) ? "CLSID_HTMLDocument" : debugstr_guid(&clsid));
267 hres = IOleObject_SetClientSite(oleobj, &This->IOleClientSite_iface);
268 if(FAILED(hres))
269 FIXME("SetClientSite failed: %08x\n", hres);
271 IOleObject_Release(oleobj);
272 }else {
273 FIXME("Could not get IOleObject iface: %08x\n", hres);
276 /* FIXME: Call SetAdvise */
278 task = heap_alloc(sizeof(*task));
279 push_dochost_task(This, task, object_available_proc, object_available_task_destr, FALSE);
281 hres = get_doc_ready_state(This, &ready_state);
282 if(SUCCEEDED(hres)) {
283 if(ready_state == READYSTATE_COMPLETE)
284 push_ready_state_task(This, READYSTATE_COMPLETE);
285 if(ready_state != READYSTATE_COMPLETE || This->doc_navigate)
286 advise_prop_notif(This, TRUE);
289 return S_OK;
292 static LRESULT resize_document(DocHost *This, LONG width, LONG height)
294 RECT rect = {0, 0, width, height};
296 TRACE("(%p)->(%d %d)\n", This, width, height);
298 if(This->view)
299 IOleDocumentView_SetRect(This->view, &rect);
301 return 0;
304 static LRESULT WINAPI doc_view_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
306 DocHost *This;
308 static const WCHAR wszTHIS[] = {'T','H','I','S',0};
310 if(msg == WM_CREATE) {
311 This = *(DocHost**)lParam;
312 SetPropW(hwnd, wszTHIS, This);
313 }else {
314 This = GetPropW(hwnd, wszTHIS);
317 switch(msg) {
318 case WM_SIZE:
319 return resize_document(This, LOWORD(lParam), HIWORD(lParam));
322 return DefWindowProcW(hwnd, msg, wParam, lParam);
325 void create_doc_view_hwnd(DocHost *This)
327 RECT rect;
329 static const WCHAR wszShell_DocObject_View[] =
330 {'S','h','e','l','l',' ','D','o','c','O','b','j','e','c','t',' ','V','i','e','w',0};
332 if(!doc_view_atom) {
333 static WNDCLASSEXW wndclass = {
334 sizeof(wndclass),
335 CS_PARENTDC,
336 doc_view_proc,
337 0, 0 /* native uses 4*/, NULL, NULL, NULL,
338 (HBRUSH)(COLOR_WINDOW + 1), NULL,
339 wszShell_DocObject_View,
340 NULL
343 wndclass.hInstance = shdocvw_hinstance;
345 doc_view_atom = RegisterClassExW(&wndclass);
348 This->container_vtbl->GetDocObjRect(This, &rect);
349 This->hwnd = CreateWindowExW(0, wszShell_DocObject_View,
350 wszShell_DocObject_View,
351 WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_TABSTOP,
352 rect.left, rect.top, rect.right, rect.bottom, This->frame_hwnd,
353 NULL, shdocvw_hinstance, This);
356 void deactivate_document(DocHost *This)
358 IOleInPlaceObjectWindowless *winobj;
359 IOleObject *oleobj = NULL;
360 IHlinkTarget *hlink = NULL;
361 HRESULT hres;
363 if(!This->document) return;
365 if(This->doc_navigate) {
366 IUnknown_Release(This->doc_navigate);
367 This->doc_navigate = NULL;
370 if(This->is_prop_notif)
371 advise_prop_notif(This, FALSE);
373 if(This->view)
374 IOleDocumentView_UIActivate(This->view, FALSE);
376 hres = IUnknown_QueryInterface(This->document, &IID_IOleInPlaceObjectWindowless,
377 (void**)&winobj);
378 if(SUCCEEDED(hres)) {
379 IOleInPlaceObjectWindowless_InPlaceDeactivate(winobj);
380 IOleInPlaceObjectWindowless_Release(winobj);
383 if(This->view) {
384 IOleDocumentView_Show(This->view, FALSE);
385 IOleDocumentView_CloseView(This->view, 0);
386 IOleDocumentView_SetInPlaceSite(This->view, NULL);
387 IOleDocumentView_Release(This->view);
388 This->view = NULL;
391 hres = IUnknown_QueryInterface(This->document, &IID_IOleObject, (void**)&oleobj);
392 if(SUCCEEDED(hres))
393 IOleObject_Close(oleobj, OLECLOSE_NOSAVE);
395 hres = IUnknown_QueryInterface(This->document, &IID_IHlinkTarget, (void**)&hlink);
396 if(SUCCEEDED(hres)) {
397 IHlinkTarget_SetBrowseContext(hlink, NULL);
398 IHlinkTarget_Release(hlink);
401 if(oleobj) {
402 IOleClientSite *client_site = NULL;
404 IOleObject_GetClientSite(oleobj, &client_site);
405 if(client_site) {
406 if(client_site == &This->IOleClientSite_iface)
407 IOleObject_SetClientSite(oleobj, NULL);
408 IOleClientSite_Release(client_site);
411 IOleObject_Release(oleobj);
414 IUnknown_Release(This->document);
415 This->document = NULL;
418 void release_dochost_client(DocHost *This)
420 if(This->hwnd) {
421 DestroyWindow(This->hwnd);
422 This->hwnd = NULL;
425 if(This->hostui) {
426 IDocHostUIHandler_Release(This->hostui);
427 This->hostui = NULL;
430 if(This->client_disp) {
431 IDispatch_Release(This->client_disp);
432 This->client_disp = NULL;
435 if(This->frame) {
436 IOleInPlaceFrame_Release(This->frame);
437 This->frame = NULL;
441 static inline DocHost *impl_from_IOleCommandTarget(IOleCommandTarget *iface)
443 return CONTAINING_RECORD(iface, DocHost, IOleCommandTarget_iface);
446 static HRESULT WINAPI ClOleCommandTarget_QueryInterface(IOleCommandTarget *iface,
447 REFIID riid, void **ppv)
449 DocHost *This = impl_from_IOleCommandTarget(iface);
450 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
453 static ULONG WINAPI ClOleCommandTarget_AddRef(IOleCommandTarget *iface)
455 DocHost *This = impl_from_IOleCommandTarget(iface);
456 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
459 static ULONG WINAPI ClOleCommandTarget_Release(IOleCommandTarget *iface)
461 DocHost *This = impl_from_IOleCommandTarget(iface);
462 return IOleClientSite_Release(&This->IOleClientSite_iface);
465 static HRESULT WINAPI ClOleCommandTarget_QueryStatus(IOleCommandTarget *iface,
466 const GUID *pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[], OLECMDTEXT *pCmdText)
468 DocHost *This = impl_from_IOleCommandTarget(iface);
469 ULONG i= 0;
470 FIXME("(%p)->(%s %u %p %p)\n", This, debugstr_guid(pguidCmdGroup), cCmds, prgCmds,
471 pCmdText);
472 while (prgCmds && (cCmds > i)) {
473 FIXME("command_%u: %u, 0x%x\n", i, prgCmds[i].cmdID, prgCmds[i].cmdf);
474 i++;
476 return E_NOTIMPL;
479 static HRESULT WINAPI ClOleCommandTarget_Exec(IOleCommandTarget *iface,
480 const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn,
481 VARIANT *pvaOut)
483 DocHost *This = impl_from_IOleCommandTarget(iface);
485 TRACE("(%p)->(%s %d %d %p %p)\n", This, debugstr_guid(pguidCmdGroup), nCmdID,
486 nCmdexecopt, debugstr_variant(pvaIn), debugstr_variant(pvaOut));
488 if(!pguidCmdGroup) {
489 switch(nCmdID) {
490 case OLECMDID_UPDATECOMMANDS:
491 return This->container_vtbl->exec(This, pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);
492 default:
493 FIXME("Unimplemented cmdid %d\n", nCmdID);
494 return E_NOTIMPL;
496 return S_OK;
499 if(IsEqualGUID(pguidCmdGroup, &CGID_DocHostCmdPriv)) {
500 switch(nCmdID) {
501 case DOCHOST_DOCCANNAVIGATE:
502 if(!pvaIn || V_VT(pvaIn) != VT_UNKNOWN)
503 return E_INVALIDARG;
505 if(This->doc_navigate)
506 IUnknown_Release(This->doc_navigate);
507 IUnknown_AddRef(V_UNKNOWN(pvaIn));
508 This->doc_navigate = V_UNKNOWN(pvaIn);
509 return S_OK;
511 case 1: {
512 IHTMLWindow2 *win2;
513 SAFEARRAY *sa = V_ARRAY(pvaIn);
514 VARIANT status_code, url, htmlwindow;
515 LONG ind;
516 HRESULT hres;
518 if(V_VT(pvaIn) != VT_ARRAY || !sa || (SafeArrayGetDim(sa) != 1))
519 return E_INVALIDARG;
521 ind = 0;
522 hres = SafeArrayGetElement(sa, &ind, &status_code);
523 if(FAILED(hres) || V_VT(&status_code)!=VT_I4)
524 return E_INVALIDARG;
526 ind = 1;
527 hres = SafeArrayGetElement(sa, &ind, &url);
528 if(FAILED(hres) || V_VT(&url)!=VT_BSTR)
529 return E_INVALIDARG;
531 ind = 3;
532 hres = SafeArrayGetElement(sa, &ind, &htmlwindow);
533 if(FAILED(hres) || V_VT(&htmlwindow)!=VT_UNKNOWN || !V_UNKNOWN(&htmlwindow))
534 return E_INVALIDARG;
536 hres = IUnknown_QueryInterface(V_UNKNOWN(&htmlwindow), &IID_IHTMLWindow2, (void**)&win2);
537 if(FAILED(hres))
538 return E_INVALIDARG;
540 handle_navigation_error(This, V_I4(&status_code), V_BSTR(&url), win2);
541 IHTMLWindow2_Release(win2);
542 return S_OK;
545 default:
546 FIXME("unsupported command %d of CGID_DocHostCmdPriv\n", nCmdID);
547 return E_NOTIMPL;
551 FIXME("Unimplemented group %s\n", debugstr_guid(pguidCmdGroup));
552 return E_NOTIMPL;
555 #undef impl_from_IOleCommandTarget
557 static const IOleCommandTargetVtbl OleCommandTargetVtbl = {
558 ClOleCommandTarget_QueryInterface,
559 ClOleCommandTarget_AddRef,
560 ClOleCommandTarget_Release,
561 ClOleCommandTarget_QueryStatus,
562 ClOleCommandTarget_Exec
565 static inline DocHost *impl_from_IDocHostUIHandler2(IDocHostUIHandler2 *iface)
567 return CONTAINING_RECORD(iface, DocHost, IDocHostUIHandler2_iface);
570 static HRESULT WINAPI DocHostUIHandler_QueryInterface(IDocHostUIHandler2 *iface,
571 REFIID riid, void **ppv)
573 DocHost *This = impl_from_IDocHostUIHandler2(iface);
574 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
577 static ULONG WINAPI DocHostUIHandler_AddRef(IDocHostUIHandler2 *iface)
579 DocHost *This = impl_from_IDocHostUIHandler2(iface);
580 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
583 static ULONG WINAPI DocHostUIHandler_Release(IDocHostUIHandler2 *iface)
585 DocHost *This = impl_from_IDocHostUIHandler2(iface);
586 return IOleClientSite_Release(&This->IOleClientSite_iface);
589 static HRESULT WINAPI DocHostUIHandler_ShowContextMenu(IDocHostUIHandler2 *iface,
590 DWORD dwID, POINT *ppt, IUnknown *pcmdtReserved, IDispatch *pdispReserved)
592 DocHost *This = impl_from_IDocHostUIHandler2(iface);
593 HRESULT hres;
595 TRACE("(%p)->(%d %p %p %p)\n", This, dwID, ppt, pcmdtReserved, pdispReserved);
597 if(This->hostui) {
598 hres = IDocHostUIHandler_ShowContextMenu(This->hostui, dwID, ppt, pcmdtReserved,
599 pdispReserved);
600 if(hres == S_OK)
601 return S_OK;
604 FIXME("default action not implemented\n");
605 return E_NOTIMPL;
608 static HRESULT WINAPI DocHostUIHandler_GetHostInfo(IDocHostUIHandler2 *iface,
609 DOCHOSTUIINFO *pInfo)
611 DocHost *This = impl_from_IDocHostUIHandler2(iface);
612 HRESULT hres;
614 TRACE("(%p)->(%p)\n", This, pInfo);
616 if(This->hostui) {
617 hres = IDocHostUIHandler_GetHostInfo(This->hostui, pInfo);
618 if(SUCCEEDED(hres))
619 return hres;
622 pInfo->dwFlags = DOCHOSTUIFLAG_DISABLE_HELP_MENU | DOCHOSTUIFLAG_OPENNEWWIN
623 | DOCHOSTUIFLAG_URL_ENCODING_ENABLE_UTF8 | DOCHOSTUIFLAG_ENABLE_INPLACE_NAVIGATION
624 | DOCHOSTUIFLAG_IME_ENABLE_RECONVERSION;
625 return S_OK;
628 static HRESULT WINAPI DocHostUIHandler_ShowUI(IDocHostUIHandler2 *iface, DWORD dwID,
629 IOleInPlaceActiveObject *pActiveObject, IOleCommandTarget *pCommandTarget,
630 IOleInPlaceFrame *pFrame, IOleInPlaceUIWindow *pDoc)
632 DocHost *This = impl_from_IDocHostUIHandler2(iface);
633 FIXME("(%p)->(%d %p %p %p %p)\n", This, dwID, pActiveObject, pCommandTarget,
634 pFrame, pDoc);
635 return E_NOTIMPL;
638 static HRESULT WINAPI DocHostUIHandler_HideUI(IDocHostUIHandler2 *iface)
640 DocHost *This = impl_from_IDocHostUIHandler2(iface);
641 FIXME("(%p)\n", This);
642 return E_NOTIMPL;
645 static HRESULT WINAPI DocHostUIHandler_UpdateUI(IDocHostUIHandler2 *iface)
647 DocHost *This = impl_from_IDocHostUIHandler2(iface);
649 TRACE("(%p)\n", This);
651 if(!This->hostui)
652 return S_FALSE;
654 return IDocHostUIHandler_UpdateUI(This->hostui);
657 static HRESULT WINAPI DocHostUIHandler_EnableModeless(IDocHostUIHandler2 *iface,
658 BOOL fEnable)
660 DocHost *This = impl_from_IDocHostUIHandler2(iface);
661 FIXME("(%p)->(%x)\n", This, fEnable);
662 return E_NOTIMPL;
665 static HRESULT WINAPI DocHostUIHandler_OnDocWindowActivate(IDocHostUIHandler2 *iface,
666 BOOL fActivate)
668 DocHost *This = impl_from_IDocHostUIHandler2(iface);
669 FIXME("(%p)->(%x)\n", This, fActivate);
670 return E_NOTIMPL;
673 static HRESULT WINAPI DocHostUIHandler_OnFrameWindowActivate(IDocHostUIHandler2 *iface,
674 BOOL fActivate)
676 DocHost *This = impl_from_IDocHostUIHandler2(iface);
677 FIXME("(%p)->(%x)\n", This, fActivate);
678 return E_NOTIMPL;
681 static HRESULT WINAPI DocHostUIHandler_ResizeBorder(IDocHostUIHandler2 *iface,
682 LPCRECT prcBorder, IOleInPlaceUIWindow *pUIWindow, BOOL fRameWindow)
684 DocHost *This = impl_from_IDocHostUIHandler2(iface);
685 FIXME("(%p)->(%p %p %X)\n", This, prcBorder, pUIWindow, fRameWindow);
686 return E_NOTIMPL;
689 static HRESULT WINAPI DocHostUIHandler_TranslateAccelerator(IDocHostUIHandler2 *iface,
690 LPMSG lpMsg, const GUID *pguidCmdGroup, DWORD nCmdID)
692 DocHost *This = impl_from_IDocHostUIHandler2(iface);
693 HRESULT hr = S_FALSE;
694 TRACE("(%p)->(%p %p %d)\n", This, lpMsg, pguidCmdGroup, nCmdID);
696 if(This->hostui)
697 hr = IDocHostUIHandler_TranslateAccelerator(This->hostui, lpMsg, pguidCmdGroup, nCmdID);
699 return hr;
702 static HRESULT WINAPI DocHostUIHandler_GetOptionKeyPath(IDocHostUIHandler2 *iface,
703 LPOLESTR *pchKey, DWORD dw)
705 DocHost *This = impl_from_IDocHostUIHandler2(iface);
707 TRACE("(%p)->(%p %d)\n", This, pchKey, dw);
709 if(This->hostui)
710 return IDocHostUIHandler_GetOptionKeyPath(This->hostui, pchKey, dw);
712 return S_OK;
715 static HRESULT WINAPI DocHostUIHandler_GetDropTarget(IDocHostUIHandler2 *iface,
716 IDropTarget *pDropTarget, IDropTarget **ppDropTarget)
718 DocHost *This = impl_from_IDocHostUIHandler2(iface);
719 FIXME("(%p)\n", This);
720 return E_NOTIMPL;
723 static HRESULT WINAPI DocHostUIHandler_GetExternal(IDocHostUIHandler2 *iface,
724 IDispatch **ppDispatch)
726 DocHost *This = impl_from_IDocHostUIHandler2(iface);
728 TRACE("(%p)->(%p)\n", This, ppDispatch);
730 if(This->hostui)
731 return IDocHostUIHandler_GetExternal(This->hostui, ppDispatch);
733 FIXME("default action not implemented\n");
734 return E_NOTIMPL;
737 static HRESULT WINAPI DocHostUIHandler_TranslateUrl(IDocHostUIHandler2 *iface,
738 DWORD dwTranslate, OLECHAR *pchURLIn, OLECHAR **ppchURLOut)
740 DocHost *This = impl_from_IDocHostUIHandler2(iface);
742 TRACE("(%p)->(%d %s %p)\n", This, dwTranslate, debugstr_w(pchURLIn), ppchURLOut);
744 if(This->hostui)
745 return IDocHostUIHandler_TranslateUrl(This->hostui, dwTranslate,
746 pchURLIn, ppchURLOut);
748 return S_FALSE;
751 static HRESULT WINAPI DocHostUIHandler_FilterDataObject(IDocHostUIHandler2 *iface,
752 IDataObject *pDO, IDataObject **ppDORet)
754 DocHost *This = impl_from_IDocHostUIHandler2(iface);
755 FIXME("(%p)->(%p %p)\n", This, pDO, ppDORet);
756 return E_NOTIMPL;
759 static HRESULT WINAPI DocHostUIHandler_GetOverrideKeyPath(IDocHostUIHandler2 *iface,
760 LPOLESTR *pchKey, DWORD dw)
762 DocHost *This = impl_from_IDocHostUIHandler2(iface);
763 IDocHostUIHandler2 *handler;
764 HRESULT hres;
766 TRACE("(%p)->(%p %d)\n", This, pchKey, dw);
768 if(!This->hostui)
769 return S_OK;
771 hres = IDocHostUIHandler_QueryInterface(This->hostui, &IID_IDocHostUIHandler2,
772 (void**)&handler);
773 if(SUCCEEDED(hres)) {
774 hres = IDocHostUIHandler2_GetOverrideKeyPath(handler, pchKey, dw);
775 IDocHostUIHandler2_Release(handler);
776 return hres;
779 return S_OK;
782 static const IDocHostUIHandler2Vtbl DocHostUIHandler2Vtbl = {
783 DocHostUIHandler_QueryInterface,
784 DocHostUIHandler_AddRef,
785 DocHostUIHandler_Release,
786 DocHostUIHandler_ShowContextMenu,
787 DocHostUIHandler_GetHostInfo,
788 DocHostUIHandler_ShowUI,
789 DocHostUIHandler_HideUI,
790 DocHostUIHandler_UpdateUI,
791 DocHostUIHandler_EnableModeless,
792 DocHostUIHandler_OnDocWindowActivate,
793 DocHostUIHandler_OnFrameWindowActivate,
794 DocHostUIHandler_ResizeBorder,
795 DocHostUIHandler_TranslateAccelerator,
796 DocHostUIHandler_GetOptionKeyPath,
797 DocHostUIHandler_GetDropTarget,
798 DocHostUIHandler_GetExternal,
799 DocHostUIHandler_TranslateUrl,
800 DocHostUIHandler_FilterDataObject,
801 DocHostUIHandler_GetOverrideKeyPath
804 static inline DocHost *impl_from_IPropertyNotifySink(IPropertyNotifySink *iface)
806 return CONTAINING_RECORD(iface, DocHost, IPropertyNotifySink_iface);
809 static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
810 REFIID riid, void **ppv)
812 DocHost *This = impl_from_IPropertyNotifySink(iface);
813 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
816 static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
818 DocHost *This = impl_from_IPropertyNotifySink(iface);
819 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
822 static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
824 DocHost *This = impl_from_IPropertyNotifySink(iface);
825 return IOleClientSite_Release(&This->IOleClientSite_iface);
828 static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
830 DocHost *This = impl_from_IPropertyNotifySink(iface);
832 TRACE("(%p)->(%d)\n", This, dispID);
834 switch(dispID) {
835 case DISPID_READYSTATE: {
836 READYSTATE ready_state;
837 HRESULT hres;
839 hres = get_doc_ready_state(This, &ready_state);
840 if(FAILED(hres))
841 return hres;
843 if(ready_state == READYSTATE_COMPLETE && !This->doc_navigate)
844 advise_prop_notif(This, FALSE);
846 push_ready_state_task(This, ready_state);
847 break;
849 default:
850 FIXME("unimplemented dispid %d\n", dispID);
851 return E_NOTIMPL;
854 return S_OK;
857 static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
859 DocHost *This = impl_from_IPropertyNotifySink(iface);
860 FIXME("(%p)->(%d)\n", This, dispID);
861 return E_NOTIMPL;
864 static const IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
865 PropertyNotifySink_QueryInterface,
866 PropertyNotifySink_AddRef,
867 PropertyNotifySink_Release,
868 PropertyNotifySink_OnChanged,
869 PropertyNotifySink_OnRequestEdit
872 void DocHost_Init(DocHost *This, IDispatch *disp, const IDocHostContainerVtbl* container)
874 This->IDocHostUIHandler2_iface.lpVtbl = &DocHostUIHandler2Vtbl;
875 This->IOleCommandTarget_iface.lpVtbl = &OleCommandTargetVtbl;
876 This->IPropertyNotifySink_iface.lpVtbl = &PropertyNotifySinkVtbl;
878 This->disp = disp;
879 This->container_vtbl = container;
881 This->ready_state = READYSTATE_UNINITIALIZED;
882 list_init(&This->task_queue);
884 DocHost_ClientSite_Init(This);
885 DocHost_Frame_Init(This);
887 ConnectionPointContainer_Init(&This->cps, (IUnknown*)disp);
890 void DocHost_Release(DocHost *This)
892 abort_dochost_tasks(This, NULL);
893 release_dochost_client(This);
894 DocHost_ClientSite_Release(This);
896 ConnectionPointContainer_Destroy(&This->cps);
898 heap_free(This->url);