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"
25 WINE_DEFAULT_DEBUG_CHANNEL(shdocvw);
27 static ATOM doc_view_atom = 0;
29 void push_dochost_task(DocHost *This, task_header_t *task, task_proc_t proc, BOOL send)
33 /* FIXME: Don't use lParam */
35 SendMessageW(This->frame_hwnd, WM_DOCHOSTTASK, 0, (LPARAM)task);
37 PostMessageW(This->frame_hwnd, WM_DOCHOSTTASK, 0, (LPARAM)task);
40 LRESULT process_dochost_task(DocHost *This, LPARAM lparam)
42 task_header_t *task = (task_header_t*)lparam;
44 task->proc(This, task);
50 static void notif_complete(DocHost *This, DISPID dispid)
52 DISPPARAMS dispparams;
57 dispparams.cNamedArgs = 0;
58 dispparams.rgdispidNamedArgs = NULL;
59 dispparams.rgvarg = params;
61 V_VT(params) = (VT_BYREF|VT_VARIANT);
62 V_BYREF(params) = &url;
64 V_VT(params+1) = VT_DISPATCH;
65 V_DISPATCH(params+1) = This->disp;
68 V_BSTR(&url) = SysAllocString(This->url);
70 TRACE("%d >>>\n", dispid);
71 call_sink(This->cps.wbe2, dispid, &dispparams);
72 TRACE("%d <<<\n", dispid);
74 SysFreeString(V_BSTR(&url));
75 This->busy = VARIANT_FALSE;
78 static void object_available(DocHost *This)
83 TRACE("(%p)\n", This);
86 WARN("document == NULL\n");
90 hres = IUnknown_QueryInterface(This->document, &IID_IHlinkTarget, (void**)&hlink);
92 FIXME("Could not get IHlinkTarget interface\n");
96 hres = IHlinkTarget_Navigate(hlink, 0, NULL);
97 IHlinkTarget_Release(hlink);
99 FIXME("Navigate failed\n");
102 static HRESULT get_doc_ready_state(DocHost *This, READYSTATE *ret)
104 DISPPARAMS dp = {NULL,NULL,0,0};
110 hres = IUnknown_QueryInterface(This->document, &IID_IDispatch, (void**)&disp);
114 hres = IDispatch_Invoke(disp, DISPID_READYSTATE, &IID_NULL, LOCALE_SYSTEM_DEFAULT, DISPATCH_PROPERTYGET,
115 &dp, &var, &ei, NULL);
116 IDispatch_Release(disp);
118 WARN("Invoke(DISPID_READYSTATE failed: %08x\n", hres);
122 if(V_VT(&var) != VT_I4) {
123 WARN("V_VT(var) = %d\n", V_VT(&var));
132 static void advise_prop_notif(DocHost *This, BOOL set)
134 IConnectionPointContainer *cp_container;
135 IConnectionPoint *cp;
138 hres = IUnknown_QueryInterface(This->document, &IID_IConnectionPointContainer, (void**)&cp_container);
142 hres = IConnectionPointContainer_FindConnectionPoint(cp_container, &IID_IPropertyNotifySink, &cp);
143 IConnectionPointContainer_Release(cp_container);
148 hres = IConnectionPoint_Advise(cp, (IUnknown*)PROPNOTIF(This), &This->prop_notif_cookie);
150 hres = IConnectionPoint_Unadvise(cp, This->prop_notif_cookie);
151 IConnectionPoint_Release(cp);
154 This->is_prop_notif = set;
157 static void update_ready_state(DocHost *This, READYSTATE ready_state)
159 if(ready_state > READYSTATE_LOADING && This->ready_state <= READYSTATE_LOADING) {
160 notif_complete(This, DISPID_NAVIGATECOMPLETE2);
161 This->ready_state = ready_state;
164 if(ready_state == READYSTATE_COMPLETE && This->ready_state < READYSTATE_COMPLETE) {
165 This->ready_state = READYSTATE_COMPLETE;
166 notif_complete(This, DISPID_DOCUMENTCOMPLETE);
171 task_header_t header;
173 READYSTATE ready_state;
174 } ready_state_task_t;
176 static void ready_state_proc(DocHost *This, task_header_t *_task)
178 ready_state_task_t *task = (ready_state_task_t*)_task;
180 if(task->doc == This->document)
181 update_ready_state(This, task->ready_state);
183 IUnknown_Release(task->doc);
186 static void push_ready_state_task(DocHost *This, READYSTATE ready_state)
188 ready_state_task_t *task = heap_alloc(sizeof(ready_state_task_t));
190 IUnknown_AddRef(This->document);
191 task->doc = This->document;
192 task->ready_state = ready_state;
194 push_dochost_task(This, &task->header, ready_state_proc, FALSE);
197 static void object_available_proc(DocHost *This, task_header_t *task)
199 object_available(This);
202 HRESULT dochost_object_available(DocHost *This, IUnknown *doc)
204 READYSTATE ready_state;
209 IUnknown_AddRef(doc);
210 This->document = doc;
212 hres = IUnknown_QueryInterface(doc, &IID_IOleObject, (void**)&oleobj);
213 if(SUCCEEDED(hres)) {
216 hres = IOleObject_GetUserClassID(oleobj, &clsid);
218 TRACE("Got clsid %s\n",
219 IsEqualGUID(&clsid, &CLSID_HTMLDocument) ? "CLSID_HTMLDocument" : debugstr_guid(&clsid));
221 hres = IOleObject_SetClientSite(oleobj, CLIENTSITE(This));
223 FIXME("SetClientSite failed: %08x\n", hres);
225 IOleObject_Release(oleobj);
227 FIXME("Could not get IOleObject iface: %08x\n", hres);
230 /* FIXME: Call SetAdvise */
232 task = heap_alloc(sizeof(*task));
233 push_dochost_task(This, task, object_available_proc, FALSE);
235 hres = get_doc_ready_state(This, &ready_state);
236 if(SUCCEEDED(hres)) {
237 if(ready_state == READYSTATE_COMPLETE)
238 push_ready_state_task(This, READYSTATE_COMPLETE);
240 advise_prop_notif(This, TRUE);
246 static LRESULT resize_document(DocHost *This, LONG width, LONG height)
248 RECT rect = {0, 0, width, height};
250 TRACE("(%p)->(%d %d)\n", This, width, height);
253 IOleDocumentView_SetRect(This->view, &rect);
258 static LRESULT WINAPI doc_view_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
262 static const WCHAR wszTHIS[] = {'T','H','I','S',0};
264 if(msg == WM_CREATE) {
265 This = *(DocHost**)lParam;
266 SetPropW(hwnd, wszTHIS, This);
268 This = GetPropW(hwnd, wszTHIS);
273 return resize_document(This, LOWORD(lParam), HIWORD(lParam));
276 return DefWindowProcW(hwnd, msg, wParam, lParam);
279 void create_doc_view_hwnd(DocHost *This)
283 static const WCHAR wszShell_DocObject_View[] =
284 {'S','h','e','l','l',' ','D','o','c','O','b','j','e','c','t',' ','V','i','e','w',0};
287 static WNDCLASSEXW wndclass = {
291 0, 0 /* native uses 4*/, NULL, NULL, NULL,
292 (HBRUSH)(COLOR_WINDOW + 1), NULL,
293 wszShell_DocObject_View,
297 wndclass.hInstance = shdocvw_hinstance;
299 doc_view_atom = RegisterClassExW(&wndclass);
302 GetClientRect(This->frame_hwnd, &rect); /* FIXME */
303 This->hwnd = CreateWindowExW(0, wszShell_DocObject_View,
304 wszShell_DocObject_View,
305 WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_TABSTOP,
306 rect.left, rect.top, rect.right, rect.bottom, This->frame_hwnd,
307 NULL, shdocvw_hinstance, This);
310 void deactivate_document(DocHost *This)
312 IOleInPlaceObjectWindowless *winobj;
313 IOleObject *oleobj = NULL;
314 IHlinkTarget *hlink = NULL;
317 if(This->is_prop_notif)
318 advise_prop_notif(This, FALSE);
321 IOleDocumentView_UIActivate(This->view, FALSE);
323 hres = IUnknown_QueryInterface(This->document, &IID_IOleInPlaceObjectWindowless,
325 if(SUCCEEDED(hres)) {
326 IOleInPlaceObjectWindowless_InPlaceDeactivate(winobj);
327 IOleInPlaceObjectWindowless_Release(winobj);
331 IOleDocumentView_Show(This->view, FALSE);
332 IOleDocumentView_CloseView(This->view, 0);
333 IOleDocumentView_SetInPlaceSite(This->view, NULL);
334 IOleDocumentView_Release(This->view);
338 hres = IUnknown_QueryInterface(This->document, &IID_IOleObject, (void**)&oleobj);
340 IOleObject_Close(oleobj, OLECLOSE_NOSAVE);
342 hres = IUnknown_QueryInterface(This->document, &IID_IHlinkTarget, (void**)&hlink);
343 if(SUCCEEDED(hres)) {
344 IHlinkTarget_SetBrowseContext(hlink, NULL);
345 IHlinkTarget_Release(hlink);
349 IOleClientSite *client_site = NULL;
351 IOleObject_GetClientSite(oleobj, &client_site);
353 if(client_site == CLIENTSITE(This))
354 IOleObject_SetClientSite(oleobj, NULL);
355 IOleClientSite_Release(client_site);
358 IOleObject_Release(oleobj);
361 IUnknown_Release(This->document);
362 This->document = NULL;
365 #define OLECMD_THIS(iface) DEFINE_THIS(DocHost, OleCommandTarget, iface)
367 static HRESULT WINAPI ClOleCommandTarget_QueryInterface(IOleCommandTarget *iface,
368 REFIID riid, void **ppv)
370 DocHost *This = OLECMD_THIS(iface);
371 return IOleClientSite_QueryInterface(CLIENTSITE(This), riid, ppv);
374 static ULONG WINAPI ClOleCommandTarget_AddRef(IOleCommandTarget *iface)
376 DocHost *This = OLECMD_THIS(iface);
377 return IOleClientSite_AddRef(CLIENTSITE(This));
380 static ULONG WINAPI ClOleCommandTarget_Release(IOleCommandTarget *iface)
382 DocHost *This = OLECMD_THIS(iface);
383 return IOleClientSite_Release(CLIENTSITE(This));
386 static HRESULT WINAPI ClOleCommandTarget_QueryStatus(IOleCommandTarget *iface,
387 const GUID *pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[], OLECMDTEXT *pCmdText)
389 DocHost *This = OLECMD_THIS(iface);
390 FIXME("(%p)->(%s %u %p %p)\n", This, debugstr_guid(pguidCmdGroup), cCmds, prgCmds,
395 static HRESULT WINAPI ClOleCommandTarget_Exec(IOleCommandTarget *iface,
396 const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn,
399 DocHost *This = OLECMD_THIS(iface);
400 FIXME("(%p)->(%s %d %d %p %p)\n", This, debugstr_guid(pguidCmdGroup), nCmdID,
401 nCmdexecopt, pvaIn, pvaOut);
407 static const IOleCommandTargetVtbl OleCommandTargetVtbl = {
408 ClOleCommandTarget_QueryInterface,
409 ClOleCommandTarget_AddRef,
410 ClOleCommandTarget_Release,
411 ClOleCommandTarget_QueryStatus,
412 ClOleCommandTarget_Exec
415 #define DOCHOSTUI_THIS(iface) DEFINE_THIS(DocHost, DocHostUIHandler, iface)
417 static HRESULT WINAPI DocHostUIHandler_QueryInterface(IDocHostUIHandler2 *iface,
418 REFIID riid, void **ppv)
420 DocHost *This = DOCHOSTUI_THIS(iface);
421 return IOleClientSite_QueryInterface(CLIENTSITE(This), riid, ppv);
424 static ULONG WINAPI DocHostUIHandler_AddRef(IDocHostUIHandler2 *iface)
426 DocHost *This = DOCHOSTUI_THIS(iface);
427 return IOleClientSite_AddRef(CLIENTSITE(This));
430 static ULONG WINAPI DocHostUIHandler_Release(IDocHostUIHandler2 *iface)
432 DocHost *This = DOCHOSTUI_THIS(iface);
433 return IOleClientSite_Release(CLIENTSITE(This));
436 static HRESULT WINAPI DocHostUIHandler_ShowContextMenu(IDocHostUIHandler2 *iface,
437 DWORD dwID, POINT *ppt, IUnknown *pcmdtReserved, IDispatch *pdispReserved)
439 DocHost *This = DOCHOSTUI_THIS(iface);
442 TRACE("(%p)->(%d %p %p %p)\n", This, dwID, ppt, pcmdtReserved, pdispReserved);
445 hres = IDocHostUIHandler_ShowContextMenu(This->hostui, dwID, ppt, pcmdtReserved,
451 FIXME("default action not implemented\n");
455 static HRESULT WINAPI DocHostUIHandler_GetHostInfo(IDocHostUIHandler2 *iface,
456 DOCHOSTUIINFO *pInfo)
458 DocHost *This = DOCHOSTUI_THIS(iface);
461 TRACE("(%p)->(%p)\n", This, pInfo);
464 hres = IDocHostUIHandler_GetHostInfo(This->hostui, pInfo);
469 pInfo->dwFlags = DOCHOSTUIFLAG_DISABLE_HELP_MENU | DOCHOSTUIFLAG_OPENNEWWIN
470 | DOCHOSTUIFLAG_URL_ENCODING_ENABLE_UTF8 | DOCHOSTUIFLAG_ENABLE_INPLACE_NAVIGATION
471 | DOCHOSTUIFLAG_IME_ENABLE_RECONVERSION;
475 static HRESULT WINAPI DocHostUIHandler_ShowUI(IDocHostUIHandler2 *iface, DWORD dwID,
476 IOleInPlaceActiveObject *pActiveObject, IOleCommandTarget *pCommandTarget,
477 IOleInPlaceFrame *pFrame, IOleInPlaceUIWindow *pDoc)
479 DocHost *This = DOCHOSTUI_THIS(iface);
480 FIXME("(%p)->(%d %p %p %p %p)\n", This, dwID, pActiveObject, pCommandTarget,
485 static HRESULT WINAPI DocHostUIHandler_HideUI(IDocHostUIHandler2 *iface)
487 DocHost *This = DOCHOSTUI_THIS(iface);
488 FIXME("(%p)\n", This);
492 static HRESULT WINAPI DocHostUIHandler_UpdateUI(IDocHostUIHandler2 *iface)
494 DocHost *This = DOCHOSTUI_THIS(iface);
496 TRACE("(%p)\n", This);
501 return IDocHostUIHandler_UpdateUI(This->hostui);
504 static HRESULT WINAPI DocHostUIHandler_EnableModeless(IDocHostUIHandler2 *iface,
507 DocHost *This = DOCHOSTUI_THIS(iface);
508 FIXME("(%p)->(%x)\n", This, fEnable);
512 static HRESULT WINAPI DocHostUIHandler_OnDocWindowActivate(IDocHostUIHandler2 *iface,
515 DocHost *This = DOCHOSTUI_THIS(iface);
516 FIXME("(%p)->(%x)\n", This, fActivate);
520 static HRESULT WINAPI DocHostUIHandler_OnFrameWindowActivate(IDocHostUIHandler2 *iface,
523 DocHost *This = DOCHOSTUI_THIS(iface);
524 FIXME("(%p)->(%x)\n", This, fActivate);
528 static HRESULT WINAPI DocHostUIHandler_ResizeBorder(IDocHostUIHandler2 *iface,
529 LPCRECT prcBorder, IOleInPlaceUIWindow *pUIWindow, BOOL fRameWindow)
531 DocHost *This = DOCHOSTUI_THIS(iface);
532 FIXME("(%p)->(%p %p %X)\n", This, prcBorder, pUIWindow, fRameWindow);
536 static HRESULT WINAPI DocHostUIHandler_TranslateAccelerator(IDocHostUIHandler2 *iface,
537 LPMSG lpMsg, const GUID *pguidCmdGroup, DWORD nCmdID)
539 DocHost *This = DOCHOSTUI_THIS(iface);
540 FIXME("(%p)->(%p %p %d)\n", This, lpMsg, pguidCmdGroup, nCmdID);
544 static HRESULT WINAPI DocHostUIHandler_GetOptionKeyPath(IDocHostUIHandler2 *iface,
545 LPOLESTR *pchKey, DWORD dw)
547 DocHost *This = DOCHOSTUI_THIS(iface);
549 TRACE("(%p)->(%p %d)\n", This, pchKey, dw);
552 return IDocHostUIHandler_GetOptionKeyPath(This->hostui, pchKey, dw);
557 static HRESULT WINAPI DocHostUIHandler_GetDropTarget(IDocHostUIHandler2 *iface,
558 IDropTarget *pDropTarget, IDropTarget **ppDropTarget)
560 DocHost *This = DOCHOSTUI_THIS(iface);
561 FIXME("(%p)\n", This);
565 static HRESULT WINAPI DocHostUIHandler_GetExternal(IDocHostUIHandler2 *iface,
566 IDispatch **ppDispatch)
568 DocHost *This = DOCHOSTUI_THIS(iface);
570 TRACE("(%p)->(%p)\n", This, ppDispatch);
573 return IDocHostUIHandler_GetExternal(This->hostui, ppDispatch);
575 FIXME("default action not implemented\n");
579 static HRESULT WINAPI DocHostUIHandler_TranslateUrl(IDocHostUIHandler2 *iface,
580 DWORD dwTranslate, OLECHAR *pchURLIn, OLECHAR **ppchURLOut)
582 DocHost *This = DOCHOSTUI_THIS(iface);
584 TRACE("(%p)->(%d %s %p)\n", This, dwTranslate, debugstr_w(pchURLIn), ppchURLOut);
587 return IDocHostUIHandler_TranslateUrl(This->hostui, dwTranslate,
588 pchURLIn, ppchURLOut);
593 static HRESULT WINAPI DocHostUIHandler_FilterDataObject(IDocHostUIHandler2 *iface,
594 IDataObject *pDO, IDataObject **ppDORet)
596 DocHost *This = DOCHOSTUI_THIS(iface);
597 FIXME("(%p)->(%p %p)\n", This, pDO, ppDORet);
601 static HRESULT WINAPI DocHostUIHandler_GetOverrideKeyPath(IDocHostUIHandler2 *iface,
602 LPOLESTR *pchKey, DWORD dw)
604 DocHost *This = DOCHOSTUI_THIS(iface);
605 IDocHostUIHandler2 *handler;
608 TRACE("(%p)->(%p %d)\n", This, pchKey, dw);
613 hres = IDocHostUIHandler_QueryInterface(This->hostui, &IID_IDocHostUIHandler2,
615 if(SUCCEEDED(hres)) {
616 hres = IDocHostUIHandler2_GetOverrideKeyPath(handler, pchKey, dw);
617 IDocHostUIHandler2_Release(handler);
624 #undef DOCHOSTUI_THIS
626 static const IDocHostUIHandler2Vtbl DocHostUIHandler2Vtbl = {
627 DocHostUIHandler_QueryInterface,
628 DocHostUIHandler_AddRef,
629 DocHostUIHandler_Release,
630 DocHostUIHandler_ShowContextMenu,
631 DocHostUIHandler_GetHostInfo,
632 DocHostUIHandler_ShowUI,
633 DocHostUIHandler_HideUI,
634 DocHostUIHandler_UpdateUI,
635 DocHostUIHandler_EnableModeless,
636 DocHostUIHandler_OnDocWindowActivate,
637 DocHostUIHandler_OnFrameWindowActivate,
638 DocHostUIHandler_ResizeBorder,
639 DocHostUIHandler_TranslateAccelerator,
640 DocHostUIHandler_GetOptionKeyPath,
641 DocHostUIHandler_GetDropTarget,
642 DocHostUIHandler_GetExternal,
643 DocHostUIHandler_TranslateUrl,
644 DocHostUIHandler_FilterDataObject,
645 DocHostUIHandler_GetOverrideKeyPath
648 #define PROPNOTIF_THIS(iface) DEFINE_THIS(DocHost, IPropertyNotifySink, iface)
650 static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
651 REFIID riid, void **ppv)
653 DocHost *This = PROPNOTIF_THIS(iface);
654 return IOleClientSite_QueryInterface(CLIENTSITE(This), riid, ppv);
657 static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
659 DocHost *This = PROPNOTIF_THIS(iface);
660 return IOleClientSite_AddRef(CLIENTSITE(This));
663 static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
665 DocHost *This = PROPNOTIF_THIS(iface);
666 return IOleClientSite_Release(CLIENTSITE(This));
669 static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
671 DocHost *This = PROPNOTIF_THIS(iface);
673 TRACE("(%p)->(%d)\n", This, dispID);
676 case DISPID_READYSTATE: {
677 READYSTATE ready_state;
680 hres = get_doc_ready_state(This, &ready_state);
684 if(ready_state == READYSTATE_COMPLETE)
685 advise_prop_notif(This, FALSE);
687 push_ready_state_task(This, ready_state);
691 FIXME("unimplemented dispid %d\n", dispID);
698 static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
700 DocHost *This = PROPNOTIF_THIS(iface);
701 FIXME("(%p)->(%d)\n", This, dispID);
705 #undef PROPNOTIF_THIS
707 static const IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
708 PropertyNotifySink_QueryInterface,
709 PropertyNotifySink_AddRef,
710 PropertyNotifySink_Release,
711 PropertyNotifySink_OnChanged,
712 PropertyNotifySink_OnRequestEdit
715 void DocHost_Init(DocHost *This, IDispatch *disp)
717 This->lpDocHostUIHandlerVtbl = &DocHostUIHandler2Vtbl;
718 This->lpOleCommandTargetVtbl = &OleCommandTargetVtbl;
719 This->lpIPropertyNotifySinkVtbl = &PropertyNotifySinkVtbl;
723 This->client_disp = NULL;
725 This->document = NULL;
730 This->frame_hwnd = NULL;
733 This->silent = VARIANT_FALSE;
734 This->offline = VARIANT_FALSE;
736 This->ready_state = READYSTATE_UNINITIALIZED;
737 This->is_prop_notif = FALSE;
739 DocHost_ClientSite_Init(This);
740 DocHost_Frame_Init(This);
742 ConnectionPointContainer_Init(&This->cps, (IUnknown*)disp);
745 void DocHost_Release(DocHost *This)
747 if(This->client_disp)
748 IDispatch_Release(This->client_disp);
750 IOleInPlaceFrame_Release(This->frame);
752 DocHost_ClientSite_Release(This);
754 ConnectionPointContainer_Destroy(&This->cps);
756 SysFreeString(This->url);