d3d10/effect: Use case-insensitive comparison in GetMemberTypeBySemantic().
[wine.git] / dlls / ieframe / dochost.c
blob042417b5b173b68320d3bfe9ca995c9456074d4d
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 "perhist.h"
24 #include "initguid.h"
26 #include "wine/debug.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(ieframe);
30 DEFINE_OLEGUID(CGID_DocHostCmdPriv, 0x000214D4L, 0, 0);
32 #define DOCHOST_DOCCANNAVIGATE 0
34 /* Undocumented notification, see mshtml tests */
35 #define CMDID_EXPLORER_UPDATEHISTORY 38
37 static ATOM doc_view_atom = 0;
39 void push_dochost_task(DocHost *This, task_header_t *task, task_proc_t proc, task_destr_t destr, BOOL send)
41 BOOL is_empty;
43 task->proc = proc;
44 task->destr = destr;
46 is_empty = list_empty(&This->task_queue);
47 list_add_tail(&This->task_queue, &task->entry);
49 if(send)
50 SendMessageW(This->frame_hwnd, WM_DOCHOSTTASK, 0, 0);
51 else if(is_empty)
52 PostMessageW(This->frame_hwnd, WM_DOCHOSTTASK, 0, 0);
55 LRESULT process_dochost_tasks(DocHost *This)
57 task_header_t *task;
59 while(!list_empty(&This->task_queue)) {
60 task = LIST_ENTRY(This->task_queue.next, task_header_t, entry);
61 list_remove(&task->entry);
63 task->proc(This, task);
64 task->destr(task);
67 return 0;
70 void abort_dochost_tasks(DocHost *This, task_proc_t proc)
72 task_header_t *task, *cursor;
74 LIST_FOR_EACH_ENTRY_SAFE(task, cursor, &This->task_queue, task_header_t, entry) {
75 if(proc && proc != task->proc)
76 continue;
78 list_remove(&task->entry);
79 task->destr(task);
83 void on_commandstate_change(DocHost *doc_host, LONG command, BOOL enable)
85 DISPPARAMS dispparams;
86 VARIANTARG params[2];
88 TRACE("command=%d enable=%d\n", command, enable);
90 dispparams.cArgs = 2;
91 dispparams.cNamedArgs = 0;
92 dispparams.rgdispidNamedArgs = NULL;
93 dispparams.rgvarg = params;
95 V_VT(params) = VT_BOOL;
96 V_BOOL(params) = enable ? VARIANT_TRUE : VARIANT_FALSE;
98 V_VT(params+1) = VT_I4;
99 V_I4(params+1) = command;
101 call_sink(doc_host->cps.wbe2, DISPID_COMMANDSTATECHANGE, &dispparams);
103 doc_host->container_vtbl->on_command_state_change(doc_host, command, enable);
106 void update_navigation_commands(DocHost *dochost)
108 unsigned pos = dochost->travellog.loading_pos == -1 ? dochost->travellog.position : dochost->travellog.loading_pos;
110 on_commandstate_change(dochost, CSC_NAVIGATEBACK, pos > 0);
111 on_commandstate_change(dochost, CSC_NAVIGATEFORWARD, pos < dochost->travellog.length);
114 static void notif_complete(DocHost *This, DISPID dispid)
116 DISPPARAMS dispparams;
117 VARIANTARG params[2];
118 VARIANT url;
120 dispparams.cArgs = 2;
121 dispparams.cNamedArgs = 0;
122 dispparams.rgdispidNamedArgs = NULL;
123 dispparams.rgvarg = params;
125 V_VT(params) = (VT_BYREF|VT_VARIANT);
126 V_BYREF(params) = &url;
128 V_VT(params+1) = VT_DISPATCH;
129 V_DISPATCH(params+1) = (IDispatch*)This->wb;
131 V_VT(&url) = VT_BSTR;
132 V_BSTR(&url) = SysAllocString(This->url);
134 TRACE("%d >>>\n", dispid);
135 call_sink(This->cps.wbe2, dispid, &dispparams);
136 TRACE("%d <<<\n", dispid);
138 SysFreeString(V_BSTR(&url));
141 static void object_available(DocHost *This)
143 IHlinkTarget *hlink;
144 HRESULT hres;
146 TRACE("(%p)\n", This);
148 if(!This->document) {
149 WARN("document == NULL\n");
150 return;
153 hres = IUnknown_QueryInterface(This->document, &IID_IHlinkTarget, (void**)&hlink);
154 if(SUCCEEDED(hres)) {
155 hres = IHlinkTarget_Navigate(hlink, 0, NULL);
156 IHlinkTarget_Release(hlink);
157 if(FAILED(hres))
158 FIXME("Navigate failed\n");
159 }else {
160 IOleObject *ole_object;
161 RECT rect;
163 TRACE("No IHlink iface\n");
165 hres = IUnknown_QueryInterface(This->document, &IID_IOleObject, (void**)&ole_object);
166 if(FAILED(hres)) {
167 FIXME("Could not get IOleObject iface: %08x\n", hres);
168 return;
171 GetClientRect(This->hwnd, &rect);
172 hres = IOleObject_DoVerb(ole_object, OLEIVERB_SHOW, NULL, &This->IOleClientSite_iface, -1, This->hwnd, &rect);
173 IOleObject_Release(ole_object);
174 if(FAILED(hres))
175 FIXME("DoVerb failed: %08x\n", hres);
179 static HRESULT get_doc_ready_state(DocHost *This, READYSTATE *ret)
181 DISPPARAMS dp = {NULL,NULL,0,0};
182 IDispatch *disp;
183 EXCEPINFO ei;
184 VARIANT var;
185 HRESULT hres;
187 hres = IUnknown_QueryInterface(This->document, &IID_IDispatch, (void**)&disp);
188 if(FAILED(hres))
189 return hres;
191 hres = IDispatch_Invoke(disp, DISPID_READYSTATE, &IID_NULL, LOCALE_SYSTEM_DEFAULT, DISPATCH_PROPERTYGET,
192 &dp, &var, &ei, NULL);
193 IDispatch_Release(disp);
194 if(FAILED(hres)) {
195 WARN("Invoke(DISPID_READYSTATE failed: %08x\n", hres);
196 return hres;
199 if(V_VT(&var) != VT_I4) {
200 WARN("V_VT(var) = %d\n", V_VT(&var));
201 VariantClear(&var);
202 return E_FAIL;
205 *ret = V_I4(&var);
206 return S_OK;
209 static void advise_prop_notif(DocHost *This, BOOL set)
211 IConnectionPointContainer *cp_container;
212 IConnectionPoint *cp;
213 HRESULT hres;
215 hres = IUnknown_QueryInterface(This->document, &IID_IConnectionPointContainer, (void**)&cp_container);
216 if(FAILED(hres))
217 return;
219 hres = IConnectionPointContainer_FindConnectionPoint(cp_container, &IID_IPropertyNotifySink, &cp);
220 IConnectionPointContainer_Release(cp_container);
221 if(FAILED(hres))
222 return;
224 if(set)
225 hres = IConnectionPoint_Advise(cp, (IUnknown*)&This->IPropertyNotifySink_iface, &This->prop_notif_cookie);
226 else
227 hres = IConnectionPoint_Unadvise(cp, This->prop_notif_cookie);
228 IConnectionPoint_Release(cp);
230 if(SUCCEEDED(hres))
231 This->is_prop_notif = set;
234 void set_doc_state(DocHost *This, READYSTATE doc_state)
236 This->doc_state = doc_state;
237 if(doc_state > This->ready_state)
238 This->ready_state = doc_state;
241 static void update_ready_state(DocHost *This, READYSTATE ready_state)
243 if(ready_state > READYSTATE_LOADING && This->travellog.loading_pos != -1) {
244 WARN("histupdate not notified\n");
245 This->travellog.position = This->travellog.loading_pos;
246 This->travellog.loading_pos = -1;
249 if(ready_state > READYSTATE_LOADING && This->doc_state <= READYSTATE_LOADING && !This->browser_service /* FIXME */)
250 notif_complete(This, DISPID_NAVIGATECOMPLETE2);
252 if(ready_state == READYSTATE_COMPLETE && This->doc_state < READYSTATE_COMPLETE) {
253 set_doc_state(This, READYSTATE_COMPLETE);
254 if(!This->browser_service) /* FIXME: Not fully correct */
255 notif_complete(This, DISPID_DOCUMENTCOMPLETE);
256 }else {
257 set_doc_state(This, ready_state);
261 typedef struct {
262 task_header_t header;
263 IUnknown *doc;
264 READYSTATE ready_state;
265 } ready_state_task_t;
267 static void ready_state_task_destr(task_header_t *_task)
269 ready_state_task_t *task = (ready_state_task_t*)_task;
271 IUnknown_Release(task->doc);
272 heap_free(task);
275 static void ready_state_proc(DocHost *This, task_header_t *_task)
277 ready_state_task_t *task = (ready_state_task_t*)_task;
279 if(task->doc == This->document)
280 update_ready_state(This, task->ready_state);
283 static void push_ready_state_task(DocHost *This, READYSTATE ready_state)
285 ready_state_task_t *task = heap_alloc(sizeof(ready_state_task_t));
287 IUnknown_AddRef(This->document);
288 task->doc = This->document;
289 task->ready_state = ready_state;
291 push_dochost_task(This, &task->header, ready_state_proc, ready_state_task_destr, FALSE);
294 static void object_available_task_destr(task_header_t *task)
296 heap_free(task);
299 static void object_available_proc(DocHost *This, task_header_t *task)
301 object_available(This);
304 HRESULT dochost_object_available(DocHost *This, IUnknown *doc)
306 READYSTATE ready_state;
307 task_header_t *task;
308 IOleObject *oleobj;
309 HRESULT hres;
311 IUnknown_AddRef(doc);
312 This->document = doc;
314 hres = IUnknown_QueryInterface(doc, &IID_IOleObject, (void**)&oleobj);
315 if(SUCCEEDED(hres)) {
316 CLSID clsid;
318 hres = IOleObject_GetUserClassID(oleobj, &clsid);
319 if(SUCCEEDED(hres))
320 TRACE("Got clsid %s\n",
321 IsEqualGUID(&clsid, &CLSID_HTMLDocument) ? "CLSID_HTMLDocument" : debugstr_guid(&clsid));
323 hres = IOleObject_SetClientSite(oleobj, &This->IOleClientSite_iface);
324 if(FAILED(hres))
325 FIXME("SetClientSite failed: %08x\n", hres);
327 IOleObject_Release(oleobj);
328 }else {
329 FIXME("Could not get IOleObject iface: %08x\n", hres);
332 /* FIXME: Call SetAdvise */
334 task = heap_alloc(sizeof(*task));
335 push_dochost_task(This, task, object_available_proc, object_available_task_destr, FALSE);
337 hres = get_doc_ready_state(This, &ready_state);
338 if(SUCCEEDED(hres)) {
339 if(ready_state == READYSTATE_COMPLETE)
340 push_ready_state_task(This, READYSTATE_COMPLETE);
341 if(ready_state != READYSTATE_COMPLETE || This->doc_navigate)
342 advise_prop_notif(This, TRUE);
343 }else if(!This->doc_navigate) {
344 /* If we can't get document's ready state, there is not much we can do.
345 * Assume that document is complete at this point. */
346 push_ready_state_task(This, READYSTATE_COMPLETE);
349 return S_OK;
352 static LRESULT resize_document(DocHost *This, LONG width, LONG height)
354 RECT rect = {0, 0, width, height};
356 TRACE("(%p)->(%d %d)\n", This, width, height);
358 if(This->view)
359 IOleDocumentView_SetRect(This->view, &rect);
361 return 0;
364 static LRESULT WINAPI doc_view_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
366 DocHost *This;
368 static const WCHAR wszTHIS[] = {'T','H','I','S',0};
370 if(msg == WM_CREATE) {
371 This = *(DocHost**)lParam;
372 SetPropW(hwnd, wszTHIS, This);
373 }else {
374 This = GetPropW(hwnd, wszTHIS);
377 switch(msg) {
378 case WM_SIZE:
379 return resize_document(This, LOWORD(lParam), HIWORD(lParam));
382 return DefWindowProcW(hwnd, msg, wParam, lParam);
385 static void free_travellog_entry(travellog_entry_t *entry)
387 if(entry->stream)
388 IStream_Release(entry->stream);
389 heap_free(entry->url);
392 static IStream *get_travellog_stream(DocHost *This)
394 IPersistHistory *persist_history;
395 IStream *stream;
396 HRESULT hres;
398 hres = IUnknown_QueryInterface(This->document, &IID_IPersistHistory, (void**)&persist_history);
399 if(FAILED(hres))
400 return NULL;
402 hres = CreateStreamOnHGlobal(NULL, TRUE, &stream);
403 if(SUCCEEDED(hres))
404 hres = IPersistHistory_SaveHistory(persist_history, stream);
405 IPersistHistory_Release(persist_history);
406 if(FAILED(hres)) {
407 IStream_Release(stream);
408 return NULL;
411 return stream;
414 static void dump_travellog(DocHost *This)
416 unsigned i;
418 for(i=0; i < This->travellog.length; i++)
419 TRACE("%d: %s %s\n", i, i == This->travellog.position ? "=>" : " ", debugstr_w(This->travellog.log[i].url));
420 if(i == This->travellog.position)
421 TRACE("%d: =>\n", i);
424 static void update_travellog(DocHost *This)
426 travellog_entry_t *new_entry;
428 static const WCHAR about_schemeW[] = {'a','b','o','u','t',':'};
430 if(This->url && !wcsnicmp(This->url, about_schemeW, ARRAY_SIZE(about_schemeW))) {
431 TRACE("Skipping about URL\n");
432 return;
435 if(!This->travellog.log) {
436 This->travellog.log = heap_alloc(4 * sizeof(*This->travellog.log));
437 if(!This->travellog.log)
438 return;
440 This->travellog.size = 4;
441 }else if(This->travellog.size < This->travellog.position+1) {
442 travellog_entry_t *new_travellog;
444 new_travellog = heap_realloc(This->travellog.log, This->travellog.size*2*sizeof(*This->travellog.log));
445 if(!new_travellog)
446 return;
448 This->travellog.log = new_travellog;
449 This->travellog.size *= 2;
452 if(This->travellog.loading_pos == -1) {
453 /* Clear forward history. */
454 while(This->travellog.length > This->travellog.position)
455 free_travellog_entry(This->travellog.log + --This->travellog.length);
458 new_entry = This->travellog.log + This->travellog.position;
460 new_entry->url = heap_strdupW(This->url);
461 TRACE("Adding %s at %d\n", debugstr_w(This->url), This->travellog.position);
462 if(!new_entry->url)
463 return;
465 new_entry->stream = get_travellog_stream(This);
467 if(This->travellog.loading_pos == -1) {
468 This->travellog.position++;
469 }else {
470 This->travellog.position = This->travellog.loading_pos;
471 This->travellog.loading_pos = -1;
473 if(This->travellog.position > This->travellog.length)
474 This->travellog.length = This->travellog.position;
476 dump_travellog(This);
479 void create_doc_view_hwnd(DocHost *This)
481 RECT rect;
483 static const WCHAR wszShell_DocObject_View[] =
484 {'S','h','e','l','l',' ','D','o','c','O','b','j','e','c','t',' ','V','i','e','w',0};
486 if(!doc_view_atom) {
487 static WNDCLASSEXW wndclass = {
488 sizeof(wndclass),
489 CS_PARENTDC,
490 doc_view_proc,
491 0, 0 /* native uses 4*/, NULL, NULL, NULL,
492 (HBRUSH)(COLOR_WINDOW + 1), NULL,
493 wszShell_DocObject_View,
494 NULL
497 wndclass.hInstance = ieframe_instance;
499 doc_view_atom = RegisterClassExW(&wndclass);
502 This->container_vtbl->get_docobj_rect(This, &rect);
503 This->hwnd = CreateWindowExW(0, wszShell_DocObject_View,
504 wszShell_DocObject_View,
505 WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_TABSTOP,
506 rect.left, rect.top, rect.right, rect.bottom, This->frame_hwnd,
507 NULL, ieframe_instance, This);
510 void deactivate_document(DocHost *This)
512 IOleInPlaceObjectWindowless *winobj;
513 IOleObject *oleobj = NULL;
514 IHlinkTarget *hlink = NULL;
515 HRESULT hres;
517 if(!This->document) return;
519 if(This->doc_navigate) {
520 IUnknown_Release(This->doc_navigate);
521 This->doc_navigate = NULL;
524 if(This->is_prop_notif)
525 advise_prop_notif(This, FALSE);
527 if(This->view)
528 IOleDocumentView_UIActivate(This->view, FALSE);
530 hres = IUnknown_QueryInterface(This->document, &IID_IOleInPlaceObjectWindowless,
531 (void**)&winobj);
532 if(SUCCEEDED(hres)) {
533 IOleInPlaceObjectWindowless_InPlaceDeactivate(winobj);
534 IOleInPlaceObjectWindowless_Release(winobj);
537 if(This->view) {
538 IOleDocumentView_Show(This->view, FALSE);
539 IOleDocumentView_CloseView(This->view, 0);
540 IOleDocumentView_SetInPlaceSite(This->view, NULL);
541 IOleDocumentView_Release(This->view);
542 This->view = NULL;
545 hres = IUnknown_QueryInterface(This->document, &IID_IOleObject, (void**)&oleobj);
546 if(SUCCEEDED(hres))
547 IOleObject_Close(oleobj, OLECLOSE_NOSAVE);
549 hres = IUnknown_QueryInterface(This->document, &IID_IHlinkTarget, (void**)&hlink);
550 if(SUCCEEDED(hres)) {
551 IHlinkTarget_SetBrowseContext(hlink, NULL);
552 IHlinkTarget_Release(hlink);
555 if(oleobj) {
556 IOleClientSite *client_site = NULL;
558 IOleObject_GetClientSite(oleobj, &client_site);
559 if(client_site) {
560 if(client_site == &This->IOleClientSite_iface)
561 IOleObject_SetClientSite(oleobj, NULL);
562 IOleClientSite_Release(client_site);
565 IOleObject_Release(oleobj);
568 IUnknown_Release(This->document);
569 This->document = NULL;
572 HRESULT refresh_document(DocHost *This, const VARIANT *level)
574 IOleCommandTarget *cmdtrg;
575 VARIANT vin, vout;
576 HRESULT hres;
578 if(level && (V_VT(level) != VT_I4 || V_I4(level) != REFRESH_NORMAL))
579 FIXME("Unsupported refresh level %s\n", debugstr_variant(level));
581 if(!This->document) {
582 FIXME("no document\n");
583 return E_FAIL;
586 hres = IUnknown_QueryInterface(This->document, &IID_IOleCommandTarget, (void**)&cmdtrg);
587 if(FAILED(hres))
588 return hres;
590 V_VT(&vin) = VT_EMPTY;
591 V_VT(&vout) = VT_EMPTY;
592 hres = IOleCommandTarget_Exec(cmdtrg, NULL, OLECMDID_REFRESH, OLECMDEXECOPT_PROMPTUSER, &vin, &vout);
593 IOleCommandTarget_Release(cmdtrg);
594 if(FAILED(hres))
595 return hres;
597 VariantClear(&vout);
598 return S_OK;
601 void activate_document(DocHost *This)
603 IOleObject *oleobj;
604 IHlinkTarget *hlink;
605 HRESULT hres;
607 if(!This->document) return;
609 hres = IUnknown_QueryInterface(This->document, &IID_IHlinkTarget, (void**)&hlink);
610 if(SUCCEEDED(hres)) {
611 IHlinkTarget_Navigate(hlink, 0, NULL);
612 IHlinkTarget_Release(hlink);
615 hres = IUnknown_QueryInterface(This->document, &IID_IOleObject, (void**)&oleobj);
616 if(SUCCEEDED(hres)) {
617 IOleObject_DoVerb(oleobj, OLEIVERB_SHOW, NULL, NULL, -1, 0, NULL);
618 IOleObject_Release(oleobj);
621 refresh_document(This, NULL);
623 if(This->view)
624 IOleDocumentView_UIActivate(This->view, TRUE);
627 void release_dochost_client(DocHost *This)
629 if(This->hwnd) {
630 DestroyWindow(This->hwnd);
631 This->hwnd = NULL;
634 if(This->hostui) {
635 IDocHostUIHandler_Release(This->hostui);
636 This->hostui = NULL;
639 if(This->client_disp) {
640 IDispatch_Release(This->client_disp);
641 This->client_disp = NULL;
644 if(This->frame) {
645 IOleInPlaceFrame_Release(This->frame);
646 This->frame = NULL;
649 if(This->olecmd) {
650 IOleCommandTarget_Release(This->olecmd);
651 This->olecmd = NULL;
655 static inline DocHost *impl_from_IOleCommandTarget(IOleCommandTarget *iface)
657 return CONTAINING_RECORD(iface, DocHost, IOleCommandTarget_iface);
660 static HRESULT WINAPI ClOleCommandTarget_QueryInterface(IOleCommandTarget *iface,
661 REFIID riid, void **ppv)
663 DocHost *This = impl_from_IOleCommandTarget(iface);
664 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
667 static ULONG WINAPI ClOleCommandTarget_AddRef(IOleCommandTarget *iface)
669 DocHost *This = impl_from_IOleCommandTarget(iface);
670 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
673 static ULONG WINAPI ClOleCommandTarget_Release(IOleCommandTarget *iface)
675 DocHost *This = impl_from_IOleCommandTarget(iface);
676 return IOleClientSite_Release(&This->IOleClientSite_iface);
679 static HRESULT WINAPI ClOleCommandTarget_QueryStatus(IOleCommandTarget *iface,
680 const GUID *pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[], OLECMDTEXT *pCmdText)
682 DocHost *This = impl_from_IOleCommandTarget(iface);
683 ULONG i;
685 TRACE("(%p)->(%s %u %p %p)\n", This, debugstr_guid(pguidCmdGroup), cCmds, prgCmds,
686 pCmdText);
687 for(i=0; prgCmds && i < cCmds; i++)
688 TRACE("unsupported command %u (%x)\n", prgCmds[i].cmdID, prgCmds[i].cmdf);
690 return E_NOTIMPL;
693 static HRESULT WINAPI ClOleCommandTarget_Exec(IOleCommandTarget *iface,
694 const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn,
695 VARIANT *pvaOut)
697 DocHost *This = impl_from_IOleCommandTarget(iface);
699 TRACE("(%p)->(%s %d %d %s %s)\n", This, debugstr_guid(pguidCmdGroup), nCmdID, nCmdexecopt,
700 debugstr_variant(pvaIn), debugstr_variant(pvaOut));
702 if(!pguidCmdGroup) {
703 switch(nCmdID) {
704 case OLECMDID_UPDATECOMMANDS:
705 if(!This->olecmd)
706 return E_NOTIMPL;
707 return IOleCommandTarget_Exec(This->olecmd, pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);
708 case OLECMDID_SETDOWNLOADSTATE:
709 if(pvaIn && V_VT(pvaIn) == VT_I4)
710 This->busy = V_I4(pvaIn) ? VARIANT_TRUE : VARIANT_FALSE;
711 if(This->olecmd)
712 return IOleCommandTarget_Exec(This->olecmd, pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);
714 if(!pvaIn || V_VT(pvaIn) != VT_I4)
715 return E_INVALIDARG;
717 notify_download_state(This, V_I4(pvaIn));
718 return S_OK;
719 default:
720 TRACE("Unimplemented cmdid %d\n", nCmdID);
721 return E_NOTIMPL;
725 if(IsEqualGUID(pguidCmdGroup, &CGID_DocHostCmdPriv)) {
726 switch(nCmdID) {
727 case DOCHOST_DOCCANNAVIGATE:
728 if(!pvaIn || V_VT(pvaIn) != VT_UNKNOWN)
729 return E_INVALIDARG;
731 if(This->doc_navigate)
732 IUnknown_Release(This->doc_navigate);
733 IUnknown_AddRef(V_UNKNOWN(pvaIn));
734 This->doc_navigate = V_UNKNOWN(pvaIn);
735 return S_OK;
737 case 1: {
738 IHTMLWindow2 *win2;
739 SAFEARRAY *sa = V_ARRAY(pvaIn);
740 VARIANT status_code, url, htmlwindow;
741 LONG ind;
742 HRESULT hres;
744 if(V_VT(pvaIn) != VT_ARRAY || !sa || (SafeArrayGetDim(sa) != 1))
745 return E_INVALIDARG;
747 ind = 0;
748 hres = SafeArrayGetElement(sa, &ind, &status_code);
749 if(FAILED(hres) || V_VT(&status_code)!=VT_I4)
750 return E_INVALIDARG;
752 ind = 1;
753 hres = SafeArrayGetElement(sa, &ind, &url);
754 if(FAILED(hres) || V_VT(&url)!=VT_BSTR)
755 return E_INVALIDARG;
757 ind = 3;
758 hres = SafeArrayGetElement(sa, &ind, &htmlwindow);
759 if(FAILED(hres) || V_VT(&htmlwindow)!=VT_UNKNOWN || !V_UNKNOWN(&htmlwindow))
760 return E_INVALIDARG;
762 hres = IUnknown_QueryInterface(V_UNKNOWN(&htmlwindow), &IID_IHTMLWindow2, (void**)&win2);
763 if(FAILED(hres))
764 return E_INVALIDARG;
766 handle_navigation_error(This, V_I4(&status_code), V_BSTR(&url), win2);
767 IHTMLWindow2_Release(win2);
768 return S_OK;
771 default:
772 TRACE("unsupported command %d of CGID_DocHostCmdPriv\n", nCmdID);
773 return E_NOTIMPL;
777 if(IsEqualGUID(pguidCmdGroup, &CGID_Explorer)) {
778 switch(nCmdID) {
779 case CMDID_EXPLORER_UPDATEHISTORY:
780 update_travellog(This);
781 update_navigation_commands(This);
782 return S_OK;
784 default:
785 TRACE("Unimplemented cmdid %d of CGID_Explorer\n", nCmdID);
786 return E_NOTIMPL;
790 if(IsEqualGUID(pguidCmdGroup, &CGID_ShellDocView)) {
791 switch(nCmdID) {
792 default:
793 TRACE("Unimplemented cmdid %d of CGID_ShellDocView\n", nCmdID);
794 return E_NOTIMPL;
798 if(IsEqualGUID(&CGID_DocHostCommandHandler, pguidCmdGroup)) {
799 if(!This->olecmd)
800 return E_NOTIMPL;
801 return IOleCommandTarget_Exec(This->olecmd, pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);
804 TRACE("Unimplemented cmdid %d of group %s\n", nCmdID, debugstr_guid(pguidCmdGroup));
805 return E_NOTIMPL;
808 static const IOleCommandTargetVtbl OleCommandTargetVtbl = {
809 ClOleCommandTarget_QueryInterface,
810 ClOleCommandTarget_AddRef,
811 ClOleCommandTarget_Release,
812 ClOleCommandTarget_QueryStatus,
813 ClOleCommandTarget_Exec
816 static inline DocHost *impl_from_IDocHostUIHandler2(IDocHostUIHandler2 *iface)
818 return CONTAINING_RECORD(iface, DocHost, IDocHostUIHandler2_iface);
821 static HRESULT WINAPI DocHostUIHandler_QueryInterface(IDocHostUIHandler2 *iface,
822 REFIID riid, void **ppv)
824 DocHost *This = impl_from_IDocHostUIHandler2(iface);
825 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
828 static ULONG WINAPI DocHostUIHandler_AddRef(IDocHostUIHandler2 *iface)
830 DocHost *This = impl_from_IDocHostUIHandler2(iface);
831 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
834 static ULONG WINAPI DocHostUIHandler_Release(IDocHostUIHandler2 *iface)
836 DocHost *This = impl_from_IDocHostUIHandler2(iface);
837 return IOleClientSite_Release(&This->IOleClientSite_iface);
840 static HRESULT WINAPI DocHostUIHandler_ShowContextMenu(IDocHostUIHandler2 *iface,
841 DWORD dwID, POINT *ppt, IUnknown *pcmdtReserved, IDispatch *pdispReserved)
843 DocHost *This = impl_from_IDocHostUIHandler2(iface);
844 HRESULT hres;
846 TRACE("(%p)->(%d %p %p %p)\n", This, dwID, ppt, pcmdtReserved, pdispReserved);
848 if(This->hostui) {
849 hres = IDocHostUIHandler_ShowContextMenu(This->hostui, dwID, ppt, pcmdtReserved,
850 pdispReserved);
851 if(hres == S_OK)
852 return S_OK;
855 FIXME("default action not implemented\n");
856 return E_NOTIMPL;
859 static HRESULT WINAPI DocHostUIHandler_GetHostInfo(IDocHostUIHandler2 *iface,
860 DOCHOSTUIINFO *pInfo)
862 DocHost *This = impl_from_IDocHostUIHandler2(iface);
863 HRESULT hres;
865 TRACE("(%p)->(%p)\n", This, pInfo);
867 if(This->hostui) {
868 hres = IDocHostUIHandler_GetHostInfo(This->hostui, pInfo);
869 if(SUCCEEDED(hres))
870 return hres;
873 pInfo->dwFlags = DOCHOSTUIFLAG_DISABLE_HELP_MENU | DOCHOSTUIFLAG_OPENNEWWIN
874 | DOCHOSTUIFLAG_URL_ENCODING_ENABLE_UTF8 | DOCHOSTUIFLAG_ENABLE_INPLACE_NAVIGATION
875 | DOCHOSTUIFLAG_IME_ENABLE_RECONVERSION;
876 return S_OK;
879 static HRESULT WINAPI DocHostUIHandler_ShowUI(IDocHostUIHandler2 *iface, DWORD dwID,
880 IOleInPlaceActiveObject *pActiveObject, IOleCommandTarget *pCommandTarget,
881 IOleInPlaceFrame *pFrame, IOleInPlaceUIWindow *pDoc)
883 DocHost *This = impl_from_IDocHostUIHandler2(iface);
884 FIXME("(%p)->(%d %p %p %p %p)\n", This, dwID, pActiveObject, pCommandTarget,
885 pFrame, pDoc);
886 return E_NOTIMPL;
889 static HRESULT WINAPI DocHostUIHandler_HideUI(IDocHostUIHandler2 *iface)
891 DocHost *This = impl_from_IDocHostUIHandler2(iface);
892 FIXME("(%p)\n", This);
893 return E_NOTIMPL;
896 static HRESULT WINAPI DocHostUIHandler_UpdateUI(IDocHostUIHandler2 *iface)
898 DocHost *This = impl_from_IDocHostUIHandler2(iface);
900 TRACE("(%p)\n", This);
902 if(!This->hostui)
903 return S_FALSE;
905 return IDocHostUIHandler_UpdateUI(This->hostui);
908 static HRESULT WINAPI DocHostUIHandler_EnableModeless(IDocHostUIHandler2 *iface,
909 BOOL fEnable)
911 DocHost *This = impl_from_IDocHostUIHandler2(iface);
912 FIXME("(%p)->(%x)\n", This, fEnable);
913 return E_NOTIMPL;
916 static HRESULT WINAPI DocHostUIHandler_OnDocWindowActivate(IDocHostUIHandler2 *iface,
917 BOOL fActivate)
919 DocHost *This = impl_from_IDocHostUIHandler2(iface);
920 FIXME("(%p)->(%x)\n", This, fActivate);
921 return E_NOTIMPL;
924 static HRESULT WINAPI DocHostUIHandler_OnFrameWindowActivate(IDocHostUIHandler2 *iface,
925 BOOL fActivate)
927 DocHost *This = impl_from_IDocHostUIHandler2(iface);
928 FIXME("(%p)->(%x)\n", This, fActivate);
929 return E_NOTIMPL;
932 static HRESULT WINAPI DocHostUIHandler_ResizeBorder(IDocHostUIHandler2 *iface,
933 LPCRECT prcBorder, IOleInPlaceUIWindow *pUIWindow, BOOL fRameWindow)
935 DocHost *This = impl_from_IDocHostUIHandler2(iface);
936 FIXME("(%p)->(%p %p %X)\n", This, prcBorder, pUIWindow, fRameWindow);
937 return E_NOTIMPL;
940 static HRESULT WINAPI DocHostUIHandler_TranslateAccelerator(IDocHostUIHandler2 *iface,
941 LPMSG lpMsg, const GUID *pguidCmdGroup, DWORD nCmdID)
943 DocHost *This = impl_from_IDocHostUIHandler2(iface);
944 HRESULT hr = S_FALSE;
945 TRACE("(%p)->(%p %p %d)\n", This, lpMsg, pguidCmdGroup, nCmdID);
947 if(This->hostui)
948 hr = IDocHostUIHandler_TranslateAccelerator(This->hostui, lpMsg, pguidCmdGroup, nCmdID);
950 return hr;
953 static HRESULT WINAPI DocHostUIHandler_GetOptionKeyPath(IDocHostUIHandler2 *iface,
954 LPOLESTR *pchKey, DWORD dw)
956 DocHost *This = impl_from_IDocHostUIHandler2(iface);
958 TRACE("(%p)->(%p %d)\n", This, pchKey, dw);
960 if(This->hostui)
961 return IDocHostUIHandler_GetOptionKeyPath(This->hostui, pchKey, dw);
963 return S_OK;
966 static HRESULT WINAPI DocHostUIHandler_GetDropTarget(IDocHostUIHandler2 *iface,
967 IDropTarget *pDropTarget, IDropTarget **ppDropTarget)
969 DocHost *This = impl_from_IDocHostUIHandler2(iface);
970 FIXME("(%p)\n", This);
971 return E_NOTIMPL;
974 static HRESULT WINAPI DocHostUIHandler_GetExternal(IDocHostUIHandler2 *iface,
975 IDispatch **ppDispatch)
977 DocHost *This = impl_from_IDocHostUIHandler2(iface);
979 TRACE("(%p)->(%p)\n", This, ppDispatch);
981 if(This->hostui)
982 return IDocHostUIHandler_GetExternal(This->hostui, ppDispatch);
984 if(!This->shell_ui_helper) {
985 HRESULT hres;
987 hres = create_shell_ui_helper(&This->shell_ui_helper);
988 if(FAILED(hres))
989 return hres;
992 *ppDispatch = (IDispatch*)This->shell_ui_helper;
993 IDispatch_AddRef(*ppDispatch);
994 return S_OK;
997 static HRESULT WINAPI DocHostUIHandler_TranslateUrl(IDocHostUIHandler2 *iface,
998 DWORD dwTranslate, OLECHAR *pchURLIn, OLECHAR **ppchURLOut)
1000 DocHost *This = impl_from_IDocHostUIHandler2(iface);
1002 TRACE("(%p)->(%d %s %p)\n", This, dwTranslate, debugstr_w(pchURLIn), ppchURLOut);
1004 if(This->hostui)
1005 return IDocHostUIHandler_TranslateUrl(This->hostui, dwTranslate,
1006 pchURLIn, ppchURLOut);
1008 return S_FALSE;
1011 static HRESULT WINAPI DocHostUIHandler_FilterDataObject(IDocHostUIHandler2 *iface,
1012 IDataObject *pDO, IDataObject **ppDORet)
1014 DocHost *This = impl_from_IDocHostUIHandler2(iface);
1015 FIXME("(%p)->(%p %p)\n", This, pDO, ppDORet);
1016 return E_NOTIMPL;
1019 static HRESULT WINAPI DocHostUIHandler_GetOverrideKeyPath(IDocHostUIHandler2 *iface,
1020 LPOLESTR *pchKey, DWORD dw)
1022 DocHost *This = impl_from_IDocHostUIHandler2(iface);
1023 IDocHostUIHandler2 *handler;
1024 HRESULT hres;
1026 TRACE("(%p)->(%p %d)\n", This, pchKey, dw);
1028 if(!This->hostui)
1029 return S_OK;
1031 hres = IDocHostUIHandler_QueryInterface(This->hostui, &IID_IDocHostUIHandler2,
1032 (void**)&handler);
1033 if(SUCCEEDED(hres)) {
1034 hres = IDocHostUIHandler2_GetOverrideKeyPath(handler, pchKey, dw);
1035 IDocHostUIHandler2_Release(handler);
1036 return hres;
1039 return S_OK;
1042 static const IDocHostUIHandler2Vtbl DocHostUIHandler2Vtbl = {
1043 DocHostUIHandler_QueryInterface,
1044 DocHostUIHandler_AddRef,
1045 DocHostUIHandler_Release,
1046 DocHostUIHandler_ShowContextMenu,
1047 DocHostUIHandler_GetHostInfo,
1048 DocHostUIHandler_ShowUI,
1049 DocHostUIHandler_HideUI,
1050 DocHostUIHandler_UpdateUI,
1051 DocHostUIHandler_EnableModeless,
1052 DocHostUIHandler_OnDocWindowActivate,
1053 DocHostUIHandler_OnFrameWindowActivate,
1054 DocHostUIHandler_ResizeBorder,
1055 DocHostUIHandler_TranslateAccelerator,
1056 DocHostUIHandler_GetOptionKeyPath,
1057 DocHostUIHandler_GetDropTarget,
1058 DocHostUIHandler_GetExternal,
1059 DocHostUIHandler_TranslateUrl,
1060 DocHostUIHandler_FilterDataObject,
1061 DocHostUIHandler_GetOverrideKeyPath
1064 static inline DocHost *impl_from_IPropertyNotifySink(IPropertyNotifySink *iface)
1066 return CONTAINING_RECORD(iface, DocHost, IPropertyNotifySink_iface);
1069 static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
1070 REFIID riid, void **ppv)
1072 DocHost *This = impl_from_IPropertyNotifySink(iface);
1073 return IOleClientSite_QueryInterface(&This->IOleClientSite_iface, riid, ppv);
1076 static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
1078 DocHost *This = impl_from_IPropertyNotifySink(iface);
1079 return IOleClientSite_AddRef(&This->IOleClientSite_iface);
1082 static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
1084 DocHost *This = impl_from_IPropertyNotifySink(iface);
1085 return IOleClientSite_Release(&This->IOleClientSite_iface);
1088 static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
1090 DocHost *This = impl_from_IPropertyNotifySink(iface);
1092 TRACE("(%p)->(%d)\n", This, dispID);
1094 switch(dispID) {
1095 case DISPID_READYSTATE: {
1096 READYSTATE ready_state;
1097 HRESULT hres;
1099 hres = get_doc_ready_state(This, &ready_state);
1100 if(FAILED(hres))
1101 return hres;
1103 if(ready_state == READYSTATE_COMPLETE && !This->doc_navigate)
1104 advise_prop_notif(This, FALSE);
1106 update_ready_state(This, ready_state);
1107 break;
1109 default:
1110 FIXME("unimplemented dispid %d\n", dispID);
1111 return E_NOTIMPL;
1114 return S_OK;
1117 static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
1119 DocHost *This = impl_from_IPropertyNotifySink(iface);
1120 FIXME("(%p)->(%d)\n", This, dispID);
1121 return E_NOTIMPL;
1124 static const IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
1125 PropertyNotifySink_QueryInterface,
1126 PropertyNotifySink_AddRef,
1127 PropertyNotifySink_Release,
1128 PropertyNotifySink_OnChanged,
1129 PropertyNotifySink_OnRequestEdit
1132 void DocHost_Init(DocHost *This, IWebBrowser2 *wb, const IDocHostContainerVtbl* container)
1134 This->IDocHostUIHandler2_iface.lpVtbl = &DocHostUIHandler2Vtbl;
1135 This->IOleCommandTarget_iface.lpVtbl = &OleCommandTargetVtbl;
1136 This->IPropertyNotifySink_iface.lpVtbl = &PropertyNotifySinkVtbl;
1138 This->wb = wb;
1139 This->container_vtbl = container;
1141 This->ready_state = READYSTATE_UNINITIALIZED;
1142 list_init(&This->task_queue);
1144 This->travellog.loading_pos = -1;
1146 DocHost_ClientSite_Init(This);
1147 DocHost_Frame_Init(This);
1149 ConnectionPointContainer_Init(&This->cps, (IUnknown*)wb);
1150 IEHTMLWindow_Init(This);
1151 NewWindowManager_Init(This);
1154 void DocHost_Release(DocHost *This)
1156 if(This->shell_ui_helper)
1157 IShellUIHelper2_Release(This->shell_ui_helper);
1159 abort_dochost_tasks(This, NULL);
1160 release_dochost_client(This);
1161 DocHost_ClientSite_Release(This);
1163 ConnectionPointContainer_Destroy(&This->cps);
1165 while(This->travellog.length)
1166 free_travellog_entry(This->travellog.log + --This->travellog.length);
1167 heap_free(This->travellog.log);
1169 heap_free(This->url);