po: Remove English strings from the Polish shell folder path translations.
[wine/multimedia.git] / dlls / ieframe / dochost.c
blob1b24dd2c7feeed8cb1c2b17af30ce18e6ad635ed
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 "ieframe.h"
21 #include "exdispid.h"
22 #include "mshtml.h"
23 #include "initguid.h"
25 #include "wine/debug.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(ieframe);
29 DEFINE_OLEGUID(CGID_DocHostCmdPriv, 0x000214D4L, 0, 0);
31 #define DOCHOST_DOCCANNAVIGATE 0
33 /* Undocumented notification, see mshtml tests */
34 #define CMDID_EXPLORER_UPDATEHISTORY 38
36 static ATOM doc_view_atom = 0;
38 void push_dochost_task(DocHost *This, task_header_t *task, task_proc_t proc, task_destr_t destr, BOOL send)
40 BOOL is_empty;
42 task->proc = proc;
43 task->destr = destr;
45 is_empty = list_empty(&This->task_queue);
46 list_add_tail(&This->task_queue, &task->entry);
48 if(send)
49 SendMessageW(This->frame_hwnd, WM_DOCHOSTTASK, 0, 0);
50 else if(is_empty)
51 PostMessageW(This->frame_hwnd, WM_DOCHOSTTASK, 0, 0);
54 LRESULT process_dochost_tasks(DocHost *This)
56 task_header_t *task;
58 while(!list_empty(&This->task_queue)) {
59 task = LIST_ENTRY(This->task_queue.next, task_header_t, entry);
60 list_remove(&task->entry);
62 task->proc(This, task);
63 task->destr(task);
66 return 0;
69 void abort_dochost_tasks(DocHost *This, task_proc_t proc)
71 task_header_t *task, *cursor;
73 LIST_FOR_EACH_ENTRY_SAFE(task, cursor, &This->task_queue, task_header_t, entry) {
74 if(proc && proc != task->proc)
75 continue;
77 list_remove(&task->entry);
78 task->destr(task);
82 static void notif_complete(DocHost *This, DISPID dispid)
84 DISPPARAMS dispparams;
85 VARIANTARG params[2];
86 VARIANT url;
88 dispparams.cArgs = 2;
89 dispparams.cNamedArgs = 0;
90 dispparams.rgdispidNamedArgs = NULL;
91 dispparams.rgvarg = params;
93 V_VT(params) = (VT_BYREF|VT_VARIANT);
94 V_BYREF(params) = &url;
96 V_VT(params+1) = VT_DISPATCH;
97 V_DISPATCH(params+1) = (IDispatch*)This->wb;
99 V_VT(&url) = VT_BSTR;
100 V_BSTR(&url) = SysAllocString(This->url);
102 TRACE("%d >>>\n", dispid);
103 call_sink(This->cps.wbe2, dispid, &dispparams);
104 TRACE("%d <<<\n", dispid);
106 SysFreeString(V_BSTR(&url));
107 This->busy = VARIANT_FALSE;
110 static void object_available(DocHost *This)
112 IHlinkTarget *hlink;
113 HRESULT hres;
115 TRACE("(%p)\n", This);
117 if(!This->document) {
118 WARN("document == NULL\n");
119 return;
122 hres = IUnknown_QueryInterface(This->document, &IID_IHlinkTarget, (void**)&hlink);
123 if(FAILED(hres)) {
124 FIXME("Could not get IHlinkTarget interface\n");
125 return;
128 hres = IHlinkTarget_Navigate(hlink, 0, NULL);
129 IHlinkTarget_Release(hlink);
130 if(FAILED(hres))
131 FIXME("Navigate failed\n");
134 static HRESULT get_doc_ready_state(DocHost *This, READYSTATE *ret)
136 DISPPARAMS dp = {NULL,NULL,0,0};
137 IDispatch *disp;
138 EXCEPINFO ei;
139 VARIANT var;
140 HRESULT hres;
142 hres = IUnknown_QueryInterface(This->document, &IID_IDispatch, (void**)&disp);
143 if(FAILED(hres))
144 return hres;
146 hres = IDispatch_Invoke(disp, DISPID_READYSTATE, &IID_NULL, LOCALE_SYSTEM_DEFAULT, DISPATCH_PROPERTYGET,
147 &dp, &var, &ei, NULL);
148 IDispatch_Release(disp);
149 if(FAILED(hres)) {
150 WARN("Invoke(DISPID_READYSTATE failed: %08x\n", hres);
151 return hres;
154 if(V_VT(&var) != VT_I4) {
155 WARN("V_VT(var) = %d\n", V_VT(&var));
156 VariantClear(&var);
157 return E_FAIL;
160 *ret = V_I4(&var);
161 return S_OK;
164 static void advise_prop_notif(DocHost *This, BOOL set)
166 IConnectionPointContainer *cp_container;
167 IConnectionPoint *cp;
168 HRESULT hres;
170 hres = IUnknown_QueryInterface(This->document, &IID_IConnectionPointContainer, (void**)&cp_container);
171 if(FAILED(hres))
172 return;
174 hres = IConnectionPointContainer_FindConnectionPoint(cp_container, &IID_IPropertyNotifySink, &cp);
175 IConnectionPointContainer_Release(cp_container);
176 if(FAILED(hres))
177 return;
179 if(set)
180 hres = IConnectionPoint_Advise(cp, (IUnknown*)&This->IPropertyNotifySink_iface, &This->prop_notif_cookie);
181 else
182 hres = IConnectionPoint_Unadvise(cp, This->prop_notif_cookie);
183 IConnectionPoint_Release(cp);
185 if(SUCCEEDED(hres))
186 This->is_prop_notif = set;
189 void set_doc_state(DocHost *This, READYSTATE doc_state)
191 This->doc_state = doc_state;
192 if(doc_state > This->ready_state)
193 This->ready_state = doc_state;
196 static void update_ready_state(DocHost *This, READYSTATE ready_state)
198 if(ready_state > READYSTATE_LOADING && This->doc_state <= READYSTATE_LOADING && !This->browser_service /* FIXME */)
199 notif_complete(This, DISPID_NAVIGATECOMPLETE2);
201 if(ready_state == READYSTATE_COMPLETE && This->doc_state < READYSTATE_COMPLETE) {
202 set_doc_state(This, READYSTATE_COMPLETE);
203 if(!This->browser_service) /* FIXME: Not fully correct */
204 notif_complete(This, DISPID_DOCUMENTCOMPLETE);
205 }else {
206 set_doc_state(This, ready_state);
210 typedef struct {
211 task_header_t header;
212 IUnknown *doc;
213 READYSTATE ready_state;
214 } ready_state_task_t;
216 static void ready_state_task_destr(task_header_t *_task)
218 ready_state_task_t *task = (ready_state_task_t*)_task;
220 IUnknown_Release(task->doc);
221 heap_free(task);
224 static void ready_state_proc(DocHost *This, task_header_t *_task)
226 ready_state_task_t *task = (ready_state_task_t*)_task;
228 if(task->doc == This->document)
229 update_ready_state(This, task->ready_state);
232 static void push_ready_state_task(DocHost *This, READYSTATE ready_state)
234 ready_state_task_t *task = heap_alloc(sizeof(ready_state_task_t));
236 IUnknown_AddRef(This->document);
237 task->doc = This->document;
238 task->ready_state = ready_state;
240 push_dochost_task(This, &task->header, ready_state_proc, ready_state_task_destr, FALSE);
243 static void object_available_task_destr(task_header_t *task)
245 heap_free(task);
248 static void object_available_proc(DocHost *This, task_header_t *task)
250 object_available(This);
253 HRESULT dochost_object_available(DocHost *This, IUnknown *doc)
255 READYSTATE ready_state;
256 task_header_t *task;
257 IOleObject *oleobj;
258 HRESULT hres;
260 IUnknown_AddRef(doc);
261 This->document = doc;
263 hres = IUnknown_QueryInterface(doc, &IID_IOleObject, (void**)&oleobj);
264 if(SUCCEEDED(hres)) {
265 CLSID clsid;
267 hres = IOleObject_GetUserClassID(oleobj, &clsid);
268 if(SUCCEEDED(hres))
269 TRACE("Got clsid %s\n",
270 IsEqualGUID(&clsid, &CLSID_HTMLDocument) ? "CLSID_HTMLDocument" : debugstr_guid(&clsid));
272 hres = IOleObject_SetClientSite(oleobj, &This->IOleClientSite_iface);
273 if(FAILED(hres))
274 FIXME("SetClientSite failed: %08x\n", hres);
276 IOleObject_Release(oleobj);
277 }else {
278 FIXME("Could not get IOleObject iface: %08x\n", hres);
281 /* FIXME: Call SetAdvise */
283 task = heap_alloc(sizeof(*task));
284 push_dochost_task(This, task, object_available_proc, object_available_task_destr, FALSE);
286 hres = get_doc_ready_state(This, &ready_state);
287 if(SUCCEEDED(hres)) {
288 if(ready_state == READYSTATE_COMPLETE)
289 push_ready_state_task(This, READYSTATE_COMPLETE);
290 if(ready_state != READYSTATE_COMPLETE || This->doc_navigate)
291 advise_prop_notif(This, TRUE);
294 return S_OK;
297 static LRESULT resize_document(DocHost *This, LONG width, LONG height)
299 RECT rect = {0, 0, width, height};
301 TRACE("(%p)->(%d %d)\n", This, width, height);
303 if(This->view)
304 IOleDocumentView_SetRect(This->view, &rect);
306 return 0;
309 static LRESULT WINAPI doc_view_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
311 DocHost *This;
313 static const WCHAR wszTHIS[] = {'T','H','I','S',0};
315 if(msg == WM_CREATE) {
316 This = *(DocHost**)lParam;
317 SetPropW(hwnd, wszTHIS, This);
318 }else {
319 This = GetPropW(hwnd, wszTHIS);
322 switch(msg) {
323 case WM_SIZE:
324 return resize_document(This, LOWORD(lParam), HIWORD(lParam));
327 return DefWindowProcW(hwnd, msg, wParam, lParam);
330 static void update_travellog(DocHost *This)
332 travellog_entry_t *new_entry;
334 if(!This->travellog) {
335 This->travellog = heap_alloc(4 * sizeof(*This->travellog));
336 if(!This->travellog)
337 return;
339 This->travellog_size = 4;
340 }else if(This->travellog_size < This->travellog_position+1) {
341 travellog_entry_t *new_travellog;
343 new_travellog = heap_realloc(This->travellog, This->travellog_size*2);
344 if(!new_travellog)
345 return;
347 This->travellog = new_travellog;
348 This->travellog_size *= 2;
351 while(This->travellog_length > This->travellog_position)
352 heap_free(This->travellog[--This->travellog_length].url);
354 new_entry = This->travellog + This->travellog_position;
356 new_entry->url = heap_strdupW(This->url);
357 if(!new_entry->url)
358 return;
360 This->travellog_position++;
363 void create_doc_view_hwnd(DocHost *This)
365 RECT rect;
367 static const WCHAR wszShell_DocObject_View[] =
368 {'S','h','e','l','l',' ','D','o','c','O','b','j','e','c','t',' ','V','i','e','w',0};
370 if(!doc_view_atom) {
371 static WNDCLASSEXW wndclass = {
372 sizeof(wndclass),
373 CS_PARENTDC,
374 doc_view_proc,
375 0, 0 /* native uses 4*/, NULL, NULL, NULL,
376 (HBRUSH)(COLOR_WINDOW + 1), NULL,
377 wszShell_DocObject_View,
378 NULL
381 wndclass.hInstance = ieframe_instance;
383 doc_view_atom = RegisterClassExW(&wndclass);
386 This->container_vtbl->GetDocObjRect(This, &rect);
387 This->hwnd = CreateWindowExW(0, wszShell_DocObject_View,
388 wszShell_DocObject_View,
389 WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_TABSTOP,
390 rect.left, rect.top, rect.right, rect.bottom, This->frame_hwnd,
391 NULL, ieframe_instance, This);
394 void deactivate_document(DocHost *This)
396 IOleInPlaceObjectWindowless *winobj;
397 IOleObject *oleobj = NULL;
398 IHlinkTarget *hlink = NULL;
399 HRESULT hres;
401 if(!This->document) return;
403 if(This->doc_navigate) {
404 IUnknown_Release(This->doc_navigate);
405 This->doc_navigate = NULL;
408 if(This->is_prop_notif)
409 advise_prop_notif(This, FALSE);
411 if(This->view)
412 IOleDocumentView_UIActivate(This->view, FALSE);
414 hres = IUnknown_QueryInterface(This->document, &IID_IOleInPlaceObjectWindowless,
415 (void**)&winobj);
416 if(SUCCEEDED(hres)) {
417 IOleInPlaceObjectWindowless_InPlaceDeactivate(winobj);
418 IOleInPlaceObjectWindowless_Release(winobj);
421 if(This->view) {
422 IOleDocumentView_Show(This->view, FALSE);
423 IOleDocumentView_CloseView(This->view, 0);
424 IOleDocumentView_SetInPlaceSite(This->view, NULL);
425 IOleDocumentView_Release(This->view);
426 This->view = NULL;
429 hres = IUnknown_QueryInterface(This->document, &IID_IOleObject, (void**)&oleobj);
430 if(SUCCEEDED(hres))
431 IOleObject_Close(oleobj, OLECLOSE_NOSAVE);
433 hres = IUnknown_QueryInterface(This->document, &IID_IHlinkTarget, (void**)&hlink);
434 if(SUCCEEDED(hres)) {
435 IHlinkTarget_SetBrowseContext(hlink, NULL);
436 IHlinkTarget_Release(hlink);
439 if(oleobj) {
440 IOleClientSite *client_site = NULL;
442 IOleObject_GetClientSite(oleobj, &client_site);
443 if(client_site) {
444 if(client_site == &This->IOleClientSite_iface)
445 IOleObject_SetClientSite(oleobj, NULL);
446 IOleClientSite_Release(client_site);
449 IOleObject_Release(oleobj);
452 IUnknown_Release(This->document);
453 This->document = NULL;
456 void release_dochost_client(DocHost *This)
458 if(This->hwnd) {
459 DestroyWindow(This->hwnd);
460 This->hwnd = NULL;
463 if(This->hostui) {
464 IDocHostUIHandler_Release(This->hostui);
465 This->hostui = NULL;
468 if(This->client_disp) {
469 IDispatch_Release(This->client_disp);
470 This->client_disp = NULL;
473 if(This->frame) {
474 IOleInPlaceFrame_Release(This->frame);
475 This->frame = NULL;
479 static inline DocHost *impl_from_IOleCommandTarget(IOleCommandTarget *iface)
481 return CONTAINING_RECORD(iface, DocHost, IOleCommandTarget_iface);
484 static HRESULT WINAPI ClOleCommandTarget_QueryInterface(IOleCommandTarget *iface,
485 REFIID riid, void **ppv)
487 DocHost *This = impl_from_IOleCommandTarget(iface);
488 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
491 static ULONG WINAPI ClOleCommandTarget_AddRef(IOleCommandTarget *iface)
493 DocHost *This = impl_from_IOleCommandTarget(iface);
494 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
497 static ULONG WINAPI ClOleCommandTarget_Release(IOleCommandTarget *iface)
499 DocHost *This = impl_from_IOleCommandTarget(iface);
500 return IOleClientSite_Release(&This->IOleClientSite_iface);
503 static HRESULT WINAPI ClOleCommandTarget_QueryStatus(IOleCommandTarget *iface,
504 const GUID *pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[], OLECMDTEXT *pCmdText)
506 DocHost *This = impl_from_IOleCommandTarget(iface);
507 ULONG i= 0;
508 FIXME("(%p)->(%s %u %p %p)\n", This, debugstr_guid(pguidCmdGroup), cCmds, prgCmds,
509 pCmdText);
510 while (prgCmds && (cCmds > i)) {
511 FIXME("command_%u: %u, 0x%x\n", i, prgCmds[i].cmdID, prgCmds[i].cmdf);
512 i++;
514 return E_NOTIMPL;
517 static HRESULT WINAPI ClOleCommandTarget_Exec(IOleCommandTarget *iface,
518 const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn,
519 VARIANT *pvaOut)
521 DocHost *This = impl_from_IOleCommandTarget(iface);
523 TRACE("(%p)->(%s %d %d %p %p)\n", This, debugstr_guid(pguidCmdGroup), nCmdID,
524 nCmdexecopt, debugstr_variant(pvaIn), debugstr_variant(pvaOut));
526 if(!pguidCmdGroup) {
527 switch(nCmdID) {
528 case OLECMDID_UPDATECOMMANDS:
529 return This->container_vtbl->exec(This, pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);
530 default:
531 FIXME("Unimplemented cmdid %d\n", nCmdID);
532 return E_NOTIMPL;
536 if(IsEqualGUID(pguidCmdGroup, &CGID_DocHostCmdPriv)) {
537 switch(nCmdID) {
538 case DOCHOST_DOCCANNAVIGATE:
539 if(!pvaIn || V_VT(pvaIn) != VT_UNKNOWN)
540 return E_INVALIDARG;
542 if(This->doc_navigate)
543 IUnknown_Release(This->doc_navigate);
544 IUnknown_AddRef(V_UNKNOWN(pvaIn));
545 This->doc_navigate = V_UNKNOWN(pvaIn);
546 return S_OK;
548 case 1: {
549 IHTMLWindow2 *win2;
550 SAFEARRAY *sa = V_ARRAY(pvaIn);
551 VARIANT status_code, url, htmlwindow;
552 LONG ind;
553 HRESULT hres;
555 if(V_VT(pvaIn) != VT_ARRAY || !sa || (SafeArrayGetDim(sa) != 1))
556 return E_INVALIDARG;
558 ind = 0;
559 hres = SafeArrayGetElement(sa, &ind, &status_code);
560 if(FAILED(hres) || V_VT(&status_code)!=VT_I4)
561 return E_INVALIDARG;
563 ind = 1;
564 hres = SafeArrayGetElement(sa, &ind, &url);
565 if(FAILED(hres) || V_VT(&url)!=VT_BSTR)
566 return E_INVALIDARG;
568 ind = 3;
569 hres = SafeArrayGetElement(sa, &ind, &htmlwindow);
570 if(FAILED(hres) || V_VT(&htmlwindow)!=VT_UNKNOWN || !V_UNKNOWN(&htmlwindow))
571 return E_INVALIDARG;
573 hres = IUnknown_QueryInterface(V_UNKNOWN(&htmlwindow), &IID_IHTMLWindow2, (void**)&win2);
574 if(FAILED(hres))
575 return E_INVALIDARG;
577 handle_navigation_error(This, V_I4(&status_code), V_BSTR(&url), win2);
578 IHTMLWindow2_Release(win2);
579 return S_OK;
582 default:
583 FIXME("unsupported command %d of CGID_DocHostCmdPriv\n", nCmdID);
584 return E_NOTIMPL;
588 if(IsEqualGUID(pguidCmdGroup, &CGID_Explorer)) {
589 switch(nCmdID) {
590 case CMDID_EXPLORER_UPDATEHISTORY:
591 update_travellog(This);
592 return S_OK;
594 default:
595 FIXME("Unimplemented cmdid %d of CGID_Explorer\n", nCmdID);
596 return E_NOTIMPL;
600 FIXME("Unimplemented cmdid %d of group %s\n", nCmdID, debugstr_guid(pguidCmdGroup));
601 return E_NOTIMPL;
604 static const IOleCommandTargetVtbl OleCommandTargetVtbl = {
605 ClOleCommandTarget_QueryInterface,
606 ClOleCommandTarget_AddRef,
607 ClOleCommandTarget_Release,
608 ClOleCommandTarget_QueryStatus,
609 ClOleCommandTarget_Exec
612 static inline DocHost *impl_from_IDocHostUIHandler2(IDocHostUIHandler2 *iface)
614 return CONTAINING_RECORD(iface, DocHost, IDocHostUIHandler2_iface);
617 static HRESULT WINAPI DocHostUIHandler_QueryInterface(IDocHostUIHandler2 *iface,
618 REFIID riid, void **ppv)
620 DocHost *This = impl_from_IDocHostUIHandler2(iface);
621 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
624 static ULONG WINAPI DocHostUIHandler_AddRef(IDocHostUIHandler2 *iface)
626 DocHost *This = impl_from_IDocHostUIHandler2(iface);
627 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
630 static ULONG WINAPI DocHostUIHandler_Release(IDocHostUIHandler2 *iface)
632 DocHost *This = impl_from_IDocHostUIHandler2(iface);
633 return IOleClientSite_Release(&This->IOleClientSite_iface);
636 static HRESULT WINAPI DocHostUIHandler_ShowContextMenu(IDocHostUIHandler2 *iface,
637 DWORD dwID, POINT *ppt, IUnknown *pcmdtReserved, IDispatch *pdispReserved)
639 DocHost *This = impl_from_IDocHostUIHandler2(iface);
640 HRESULT hres;
642 TRACE("(%p)->(%d %p %p %p)\n", This, dwID, ppt, pcmdtReserved, pdispReserved);
644 if(This->hostui) {
645 hres = IDocHostUIHandler_ShowContextMenu(This->hostui, dwID, ppt, pcmdtReserved,
646 pdispReserved);
647 if(hres == S_OK)
648 return S_OK;
651 FIXME("default action not implemented\n");
652 return E_NOTIMPL;
655 static HRESULT WINAPI DocHostUIHandler_GetHostInfo(IDocHostUIHandler2 *iface,
656 DOCHOSTUIINFO *pInfo)
658 DocHost *This = impl_from_IDocHostUIHandler2(iface);
659 HRESULT hres;
661 TRACE("(%p)->(%p)\n", This, pInfo);
663 if(This->hostui) {
664 hres = IDocHostUIHandler_GetHostInfo(This->hostui, pInfo);
665 if(SUCCEEDED(hres))
666 return hres;
669 pInfo->dwFlags = DOCHOSTUIFLAG_DISABLE_HELP_MENU | DOCHOSTUIFLAG_OPENNEWWIN
670 | DOCHOSTUIFLAG_URL_ENCODING_ENABLE_UTF8 | DOCHOSTUIFLAG_ENABLE_INPLACE_NAVIGATION
671 | DOCHOSTUIFLAG_IME_ENABLE_RECONVERSION;
672 return S_OK;
675 static HRESULT WINAPI DocHostUIHandler_ShowUI(IDocHostUIHandler2 *iface, DWORD dwID,
676 IOleInPlaceActiveObject *pActiveObject, IOleCommandTarget *pCommandTarget,
677 IOleInPlaceFrame *pFrame, IOleInPlaceUIWindow *pDoc)
679 DocHost *This = impl_from_IDocHostUIHandler2(iface);
680 FIXME("(%p)->(%d %p %p %p %p)\n", This, dwID, pActiveObject, pCommandTarget,
681 pFrame, pDoc);
682 return E_NOTIMPL;
685 static HRESULT WINAPI DocHostUIHandler_HideUI(IDocHostUIHandler2 *iface)
687 DocHost *This = impl_from_IDocHostUIHandler2(iface);
688 FIXME("(%p)\n", This);
689 return E_NOTIMPL;
692 static HRESULT WINAPI DocHostUIHandler_UpdateUI(IDocHostUIHandler2 *iface)
694 DocHost *This = impl_from_IDocHostUIHandler2(iface);
696 TRACE("(%p)\n", This);
698 if(!This->hostui)
699 return S_FALSE;
701 return IDocHostUIHandler_UpdateUI(This->hostui);
704 static HRESULT WINAPI DocHostUIHandler_EnableModeless(IDocHostUIHandler2 *iface,
705 BOOL fEnable)
707 DocHost *This = impl_from_IDocHostUIHandler2(iface);
708 FIXME("(%p)->(%x)\n", This, fEnable);
709 return E_NOTIMPL;
712 static HRESULT WINAPI DocHostUIHandler_OnDocWindowActivate(IDocHostUIHandler2 *iface,
713 BOOL fActivate)
715 DocHost *This = impl_from_IDocHostUIHandler2(iface);
716 FIXME("(%p)->(%x)\n", This, fActivate);
717 return E_NOTIMPL;
720 static HRESULT WINAPI DocHostUIHandler_OnFrameWindowActivate(IDocHostUIHandler2 *iface,
721 BOOL fActivate)
723 DocHost *This = impl_from_IDocHostUIHandler2(iface);
724 FIXME("(%p)->(%x)\n", This, fActivate);
725 return E_NOTIMPL;
728 static HRESULT WINAPI DocHostUIHandler_ResizeBorder(IDocHostUIHandler2 *iface,
729 LPCRECT prcBorder, IOleInPlaceUIWindow *pUIWindow, BOOL fRameWindow)
731 DocHost *This = impl_from_IDocHostUIHandler2(iface);
732 FIXME("(%p)->(%p %p %X)\n", This, prcBorder, pUIWindow, fRameWindow);
733 return E_NOTIMPL;
736 static HRESULT WINAPI DocHostUIHandler_TranslateAccelerator(IDocHostUIHandler2 *iface,
737 LPMSG lpMsg, const GUID *pguidCmdGroup, DWORD nCmdID)
739 DocHost *This = impl_from_IDocHostUIHandler2(iface);
740 HRESULT hr = S_FALSE;
741 TRACE("(%p)->(%p %p %d)\n", This, lpMsg, pguidCmdGroup, nCmdID);
743 if(This->hostui)
744 hr = IDocHostUIHandler_TranslateAccelerator(This->hostui, lpMsg, pguidCmdGroup, nCmdID);
746 return hr;
749 static HRESULT WINAPI DocHostUIHandler_GetOptionKeyPath(IDocHostUIHandler2 *iface,
750 LPOLESTR *pchKey, DWORD dw)
752 DocHost *This = impl_from_IDocHostUIHandler2(iface);
754 TRACE("(%p)->(%p %d)\n", This, pchKey, dw);
756 if(This->hostui)
757 return IDocHostUIHandler_GetOptionKeyPath(This->hostui, pchKey, dw);
759 return S_OK;
762 static HRESULT WINAPI DocHostUIHandler_GetDropTarget(IDocHostUIHandler2 *iface,
763 IDropTarget *pDropTarget, IDropTarget **ppDropTarget)
765 DocHost *This = impl_from_IDocHostUIHandler2(iface);
766 FIXME("(%p)\n", This);
767 return E_NOTIMPL;
770 static HRESULT WINAPI DocHostUIHandler_GetExternal(IDocHostUIHandler2 *iface,
771 IDispatch **ppDispatch)
773 DocHost *This = impl_from_IDocHostUIHandler2(iface);
775 TRACE("(%p)->(%p)\n", This, ppDispatch);
777 if(This->hostui)
778 return IDocHostUIHandler_GetExternal(This->hostui, ppDispatch);
780 FIXME("default action not implemented\n");
781 return E_NOTIMPL;
784 static HRESULT WINAPI DocHostUIHandler_TranslateUrl(IDocHostUIHandler2 *iface,
785 DWORD dwTranslate, OLECHAR *pchURLIn, OLECHAR **ppchURLOut)
787 DocHost *This = impl_from_IDocHostUIHandler2(iface);
789 TRACE("(%p)->(%d %s %p)\n", This, dwTranslate, debugstr_w(pchURLIn), ppchURLOut);
791 if(This->hostui)
792 return IDocHostUIHandler_TranslateUrl(This->hostui, dwTranslate,
793 pchURLIn, ppchURLOut);
795 return S_FALSE;
798 static HRESULT WINAPI DocHostUIHandler_FilterDataObject(IDocHostUIHandler2 *iface,
799 IDataObject *pDO, IDataObject **ppDORet)
801 DocHost *This = impl_from_IDocHostUIHandler2(iface);
802 FIXME("(%p)->(%p %p)\n", This, pDO, ppDORet);
803 return E_NOTIMPL;
806 static HRESULT WINAPI DocHostUIHandler_GetOverrideKeyPath(IDocHostUIHandler2 *iface,
807 LPOLESTR *pchKey, DWORD dw)
809 DocHost *This = impl_from_IDocHostUIHandler2(iface);
810 IDocHostUIHandler2 *handler;
811 HRESULT hres;
813 TRACE("(%p)->(%p %d)\n", This, pchKey, dw);
815 if(!This->hostui)
816 return S_OK;
818 hres = IDocHostUIHandler_QueryInterface(This->hostui, &IID_IDocHostUIHandler2,
819 (void**)&handler);
820 if(SUCCEEDED(hres)) {
821 hres = IDocHostUIHandler2_GetOverrideKeyPath(handler, pchKey, dw);
822 IDocHostUIHandler2_Release(handler);
823 return hres;
826 return S_OK;
829 static const IDocHostUIHandler2Vtbl DocHostUIHandler2Vtbl = {
830 DocHostUIHandler_QueryInterface,
831 DocHostUIHandler_AddRef,
832 DocHostUIHandler_Release,
833 DocHostUIHandler_ShowContextMenu,
834 DocHostUIHandler_GetHostInfo,
835 DocHostUIHandler_ShowUI,
836 DocHostUIHandler_HideUI,
837 DocHostUIHandler_UpdateUI,
838 DocHostUIHandler_EnableModeless,
839 DocHostUIHandler_OnDocWindowActivate,
840 DocHostUIHandler_OnFrameWindowActivate,
841 DocHostUIHandler_ResizeBorder,
842 DocHostUIHandler_TranslateAccelerator,
843 DocHostUIHandler_GetOptionKeyPath,
844 DocHostUIHandler_GetDropTarget,
845 DocHostUIHandler_GetExternal,
846 DocHostUIHandler_TranslateUrl,
847 DocHostUIHandler_FilterDataObject,
848 DocHostUIHandler_GetOverrideKeyPath
851 static inline DocHost *impl_from_IPropertyNotifySink(IPropertyNotifySink *iface)
853 return CONTAINING_RECORD(iface, DocHost, IPropertyNotifySink_iface);
856 static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
857 REFIID riid, void **ppv)
859 DocHost *This = impl_from_IPropertyNotifySink(iface);
860 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
863 static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
865 DocHost *This = impl_from_IPropertyNotifySink(iface);
866 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
869 static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
871 DocHost *This = impl_from_IPropertyNotifySink(iface);
872 return IOleClientSite_Release(&This->IOleClientSite_iface);
875 static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
877 DocHost *This = impl_from_IPropertyNotifySink(iface);
879 TRACE("(%p)->(%d)\n", This, dispID);
881 switch(dispID) {
882 case DISPID_READYSTATE: {
883 READYSTATE ready_state;
884 HRESULT hres;
886 hres = get_doc_ready_state(This, &ready_state);
887 if(FAILED(hres))
888 return hres;
890 if(ready_state == READYSTATE_COMPLETE && !This->doc_navigate)
891 advise_prop_notif(This, FALSE);
893 update_ready_state(This, ready_state);
894 break;
896 default:
897 FIXME("unimplemented dispid %d\n", dispID);
898 return E_NOTIMPL;
901 return S_OK;
904 static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
906 DocHost *This = impl_from_IPropertyNotifySink(iface);
907 FIXME("(%p)->(%d)\n", This, dispID);
908 return E_NOTIMPL;
911 static const IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
912 PropertyNotifySink_QueryInterface,
913 PropertyNotifySink_AddRef,
914 PropertyNotifySink_Release,
915 PropertyNotifySink_OnChanged,
916 PropertyNotifySink_OnRequestEdit
919 void DocHost_Init(DocHost *This, IWebBrowser2 *wb, const IDocHostContainerVtbl* container)
921 This->IDocHostUIHandler2_iface.lpVtbl = &DocHostUIHandler2Vtbl;
922 This->IOleCommandTarget_iface.lpVtbl = &OleCommandTargetVtbl;
923 This->IPropertyNotifySink_iface.lpVtbl = &PropertyNotifySinkVtbl;
925 This->wb = wb;
926 This->container_vtbl = container;
928 This->ready_state = READYSTATE_UNINITIALIZED;
929 list_init(&This->task_queue);
931 DocHost_ClientSite_Init(This);
932 DocHost_Frame_Init(This);
934 ConnectionPointContainer_Init(&This->cps, (IUnknown*)wb);
935 IEHTMLWindow_Init(This);
936 NewWindowManager_Init(This);
939 void DocHost_Release(DocHost *This)
941 abort_dochost_tasks(This, NULL);
942 release_dochost_client(This);
943 DocHost_ClientSite_Release(This);
945 ConnectionPointContainer_Destroy(&This->cps);
947 while(This->travellog_length)
948 heap_free(This->travellog[--This->travellog_length].url);
949 heap_free(This->travellog);
951 heap_free(This->url);