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"
24 WINE_DEFAULT_DEBUG_CHANNEL(shdocvw);
26 static ATOM doc_view_atom = 0;
28 void push_dochost_task(DocHost *This, task_header_t *task, task_proc_t proc, BOOL send)
32 /* FIXME: Don't use lParam */
34 SendMessageW(This->frame_hwnd, WM_DOCHOSTTASK, 0, (LPARAM)task);
36 PostMessageW(This->frame_hwnd, WM_DOCHOSTTASK, 0, (LPARAM)task);
39 LRESULT process_dochost_task(DocHost *This, LPARAM lparam)
41 task_header_t *task = (task_header_t*)lparam;
43 task->proc(This, task);
49 static void navigate_complete(DocHost *This)
51 IDispatch *disp = NULL;
52 DISPPARAMS dispparams;
57 hres = IUnknown_QueryInterface(This->document, &IID_IDispatch, (void**)&disp);
59 FIXME("Could not get IDispatch interface\n");
62 dispparams.cNamedArgs = 0;
63 dispparams.rgdispidNamedArgs = NULL;
64 dispparams.rgvarg = params;
66 V_VT(params) = (VT_BYREF|VT_VARIANT);
67 V_BYREF(params) = &url;
69 V_VT(params+1) = VT_DISPATCH;
70 V_DISPATCH(params+1) = disp;
73 V_BSTR(&url) = SysAllocString(This->url);
75 call_sink(This->cps.wbe2, DISPID_NAVIGATECOMPLETE2, &dispparams);
76 call_sink(This->cps.wbe2, DISPID_DOCUMENTCOMPLETE, &dispparams);
78 SysFreeString(V_BSTR(&url));
80 IDispatch_Release(disp);
81 This->busy = VARIANT_FALSE;
84 void object_available(DocHost *This)
89 TRACE("(%p)\n", This);
92 WARN("document == NULL\n");
96 hres = IUnknown_QueryInterface(This->document, &IID_IHlinkTarget, (void**)&hlink);
98 FIXME("Could not get IHlinkTarget interface\n");
102 hres = IHlinkTarget_Navigate(hlink, 0, NULL);
103 IHlinkTarget_Release(hlink);
105 FIXME("Navigate failed\n");
109 navigate_complete(This);
114 static LRESULT resize_document(DocHost *This, LONG width, LONG height)
116 RECT rect = {0, 0, width, height};
118 TRACE("(%p)->(%d %d)\n", This, width, height);
121 IOleDocumentView_SetRect(This->view, &rect);
126 static LRESULT WINAPI doc_view_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
130 static const WCHAR wszTHIS[] = {'T','H','I','S',0};
132 if(msg == WM_CREATE) {
133 This = *(DocHost**)lParam;
134 SetPropW(hwnd, wszTHIS, This);
136 This = GetPropW(hwnd, wszTHIS);
141 return resize_document(This, LOWORD(lParam), HIWORD(lParam));
144 return DefWindowProcW(hwnd, msg, wParam, lParam);
147 void create_doc_view_hwnd(DocHost *This)
151 static const WCHAR wszShell_DocObject_View[] =
152 {'S','h','e','l','l',' ','D','o','c','O','b','j','e','c','t',' ','V','i','e','w',0};
155 static WNDCLASSEXW wndclass = {
159 0, 0 /* native uses 4*/, NULL, NULL, NULL,
160 (HBRUSH)COLOR_WINDOWFRAME, NULL,
161 wszShell_DocObject_View,
165 wndclass.hInstance = shdocvw_hinstance;
167 doc_view_atom = RegisterClassExW(&wndclass);
170 GetClientRect(This->frame_hwnd, &rect); /* FIXME */
171 This->hwnd = CreateWindowExW(0, wszShell_DocObject_View,
172 wszShell_DocObject_View,
173 WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_TABSTOP,
174 rect.left, rect.top, rect.right, rect.bottom, This->frame_hwnd,
175 NULL, shdocvw_hinstance, This);
178 void deactivate_document(DocHost *This)
180 IOleInPlaceObjectWindowless *winobj;
181 IOleObject *oleobj = NULL;
182 IHlinkTarget *hlink = NULL;
186 IOleDocumentView_UIActivate(This->view, FALSE);
188 hres = IUnknown_QueryInterface(This->document, &IID_IOleInPlaceObjectWindowless,
190 if(SUCCEEDED(hres)) {
191 IOleInPlaceObjectWindowless_InPlaceDeactivate(winobj);
192 IOleInPlaceObjectWindowless_Release(winobj);
196 IOleDocumentView_Show(This->view, FALSE);
197 IOleDocumentView_CloseView(This->view, 0);
198 IOleDocumentView_SetInPlaceSite(This->view, NULL);
199 IOleDocumentView_Release(This->view);
203 hres = IUnknown_QueryInterface(This->document, &IID_IOleObject, (void**)&oleobj);
205 IOleObject_Close(oleobj, OLECLOSE_NOSAVE);
207 hres = IUnknown_QueryInterface(This->document, &IID_IHlinkTarget, (void**)&hlink);
208 if(SUCCEEDED(hres)) {
209 IHlinkTarget_SetBrowseContext(hlink, NULL);
210 IHlinkTarget_Release(hlink);
214 IOleClientSite *client_site = NULL;
216 IOleObject_GetClientSite(oleobj, &client_site);
218 if(client_site == CLIENTSITE(This))
219 IOleObject_SetClientSite(oleobj, NULL);
220 IOleClientSite_Release(client_site);
223 IOleObject_Release(oleobj);
226 IUnknown_Release(This->document);
227 This->document = NULL;
230 #define OLECMD_THIS(iface) DEFINE_THIS(DocHost, OleCommandTarget, iface)
232 static HRESULT WINAPI ClOleCommandTarget_QueryInterface(IOleCommandTarget *iface,
233 REFIID riid, void **ppv)
235 DocHost *This = OLECMD_THIS(iface);
236 return IOleClientSite_QueryInterface(CLIENTSITE(This), riid, ppv);
239 static ULONG WINAPI ClOleCommandTarget_AddRef(IOleCommandTarget *iface)
241 DocHost *This = OLECMD_THIS(iface);
242 return IOleClientSite_AddRef(CLIENTSITE(This));
245 static ULONG WINAPI ClOleCommandTarget_Release(IOleCommandTarget *iface)
247 DocHost *This = OLECMD_THIS(iface);
248 return IOleClientSite_Release(CLIENTSITE(This));
251 static HRESULT WINAPI ClOleCommandTarget_QueryStatus(IOleCommandTarget *iface,
252 const GUID *pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[], OLECMDTEXT *pCmdText)
254 DocHost *This = OLECMD_THIS(iface);
255 FIXME("(%p)->(%s %u %p %p)\n", This, debugstr_guid(pguidCmdGroup), cCmds, prgCmds,
260 static HRESULT WINAPI ClOleCommandTarget_Exec(IOleCommandTarget *iface,
261 const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn,
264 DocHost *This = OLECMD_THIS(iface);
265 FIXME("(%p)->(%s %d %d %p %p)\n", This, debugstr_guid(pguidCmdGroup), nCmdID,
266 nCmdexecopt, pvaIn, pvaOut);
272 static const IOleCommandTargetVtbl OleCommandTargetVtbl = {
273 ClOleCommandTarget_QueryInterface,
274 ClOleCommandTarget_AddRef,
275 ClOleCommandTarget_Release,
276 ClOleCommandTarget_QueryStatus,
277 ClOleCommandTarget_Exec
280 #define DOCHOSTUI_THIS(iface) DEFINE_THIS(DocHost, DocHostUIHandler, iface)
282 static HRESULT WINAPI DocHostUIHandler_QueryInterface(IDocHostUIHandler2 *iface,
283 REFIID riid, void **ppv)
285 DocHost *This = DOCHOSTUI_THIS(iface);
286 return IOleClientSite_QueryInterface(CLIENTSITE(This), riid, ppv);
289 static ULONG WINAPI DocHostUIHandler_AddRef(IDocHostUIHandler2 *iface)
291 DocHost *This = DOCHOSTUI_THIS(iface);
292 return IOleClientSite_AddRef(CLIENTSITE(This));
295 static ULONG WINAPI DocHostUIHandler_Release(IDocHostUIHandler2 *iface)
297 DocHost *This = DOCHOSTUI_THIS(iface);
298 return IOleClientSite_Release(CLIENTSITE(This));
301 static HRESULT WINAPI DocHostUIHandler_ShowContextMenu(IDocHostUIHandler2 *iface,
302 DWORD dwID, POINT *ppt, IUnknown *pcmdtReserved, IDispatch *pdispReserved)
304 DocHost *This = DOCHOSTUI_THIS(iface);
307 TRACE("(%p)->(%d %p %p %p)\n", This, dwID, ppt, pcmdtReserved, pdispReserved);
310 hres = IDocHostUIHandler_ShowContextMenu(This->hostui, dwID, ppt, pcmdtReserved,
316 FIXME("default action not implemented\n");
320 static HRESULT WINAPI DocHostUIHandler_GetHostInfo(IDocHostUIHandler2 *iface,
321 DOCHOSTUIINFO *pInfo)
323 DocHost *This = DOCHOSTUI_THIS(iface);
326 TRACE("(%p)->(%p)\n", This, pInfo);
329 hres = IDocHostUIHandler_GetHostInfo(This->hostui, pInfo);
334 pInfo->dwFlags = DOCHOSTUIFLAG_DISABLE_HELP_MENU | DOCHOSTUIFLAG_OPENNEWWIN
335 | DOCHOSTUIFLAG_URL_ENCODING_ENABLE_UTF8 | DOCHOSTUIFLAG_ENABLE_INPLACE_NAVIGATION
336 | DOCHOSTUIFLAG_IME_ENABLE_RECONVERSION;
340 static HRESULT WINAPI DocHostUIHandler_ShowUI(IDocHostUIHandler2 *iface, DWORD dwID,
341 IOleInPlaceActiveObject *pActiveObject, IOleCommandTarget *pCommandTarget,
342 IOleInPlaceFrame *pFrame, IOleInPlaceUIWindow *pDoc)
344 DocHost *This = DOCHOSTUI_THIS(iface);
345 FIXME("(%p)->(%d %p %p %p %p)\n", This, dwID, pActiveObject, pCommandTarget,
350 static HRESULT WINAPI DocHostUIHandler_HideUI(IDocHostUIHandler2 *iface)
352 DocHost *This = DOCHOSTUI_THIS(iface);
353 FIXME("(%p)\n", This);
357 static HRESULT WINAPI DocHostUIHandler_UpdateUI(IDocHostUIHandler2 *iface)
359 DocHost *This = DOCHOSTUI_THIS(iface);
361 TRACE("(%p)\n", This);
366 return IDocHostUIHandler_UpdateUI(This->hostui);
369 static HRESULT WINAPI DocHostUIHandler_EnableModeless(IDocHostUIHandler2 *iface,
372 DocHost *This = DOCHOSTUI_THIS(iface);
373 FIXME("(%p)->(%x)\n", This, fEnable);
377 static HRESULT WINAPI DocHostUIHandler_OnDocWindowActivate(IDocHostUIHandler2 *iface,
380 DocHost *This = DOCHOSTUI_THIS(iface);
381 FIXME("(%p)->(%x)\n", This, fActivate);
385 static HRESULT WINAPI DocHostUIHandler_OnFrameWindowActivate(IDocHostUIHandler2 *iface,
388 DocHost *This = DOCHOSTUI_THIS(iface);
389 FIXME("(%p)->(%x)\n", This, fActivate);
393 static HRESULT WINAPI DocHostUIHandler_ResizeBorder(IDocHostUIHandler2 *iface,
394 LPCRECT prcBorder, IOleInPlaceUIWindow *pUIWindow, BOOL fRameWindow)
396 DocHost *This = DOCHOSTUI_THIS(iface);
397 FIXME("(%p)->(%p %p %X)\n", This, prcBorder, pUIWindow, fRameWindow);
401 static HRESULT WINAPI DocHostUIHandler_TranslateAccelerator(IDocHostUIHandler2 *iface,
402 LPMSG lpMsg, const GUID *pguidCmdGroup, DWORD nCmdID)
404 DocHost *This = DOCHOSTUI_THIS(iface);
405 FIXME("(%p)->(%p %p %d)\n", This, lpMsg, pguidCmdGroup, nCmdID);
409 static HRESULT WINAPI DocHostUIHandler_GetOptionKeyPath(IDocHostUIHandler2 *iface,
410 LPOLESTR *pchKey, DWORD dw)
412 DocHost *This = DOCHOSTUI_THIS(iface);
414 TRACE("(%p)->(%p %d)\n", This, pchKey, dw);
417 return IDocHostUIHandler_GetOptionKeyPath(This->hostui, pchKey, dw);
422 static HRESULT WINAPI DocHostUIHandler_GetDropTarget(IDocHostUIHandler2 *iface,
423 IDropTarget *pDropTarget, IDropTarget **ppDropTarget)
425 DocHost *This = DOCHOSTUI_THIS(iface);
426 FIXME("(%p)\n", This);
430 static HRESULT WINAPI DocHostUIHandler_GetExternal(IDocHostUIHandler2 *iface,
431 IDispatch **ppDispatch)
433 DocHost *This = DOCHOSTUI_THIS(iface);
435 TRACE("(%p)->(%p)\n", This, ppDispatch);
438 return IDocHostUIHandler_GetExternal(This->hostui, ppDispatch);
440 FIXME("default action not implemented\n");
444 static HRESULT WINAPI DocHostUIHandler_TranslateUrl(IDocHostUIHandler2 *iface,
445 DWORD dwTranslate, OLECHAR *pchURLIn, OLECHAR **ppchURLOut)
447 DocHost *This = DOCHOSTUI_THIS(iface);
449 TRACE("(%p)->(%d %s %p)\n", This, dwTranslate, debugstr_w(pchURLIn), ppchURLOut);
452 return IDocHostUIHandler_TranslateUrl(This->hostui, dwTranslate,
453 pchURLIn, ppchURLOut);
458 static HRESULT WINAPI DocHostUIHandler_FilterDataObject(IDocHostUIHandler2 *iface,
459 IDataObject *pDO, IDataObject **ppDORet)
461 DocHost *This = DOCHOSTUI_THIS(iface);
462 FIXME("(%p)->(%p %p)\n", This, pDO, ppDORet);
466 static HRESULT WINAPI DocHostUIHandler_GetOverrideKeyPath(IDocHostUIHandler2 *iface,
467 LPOLESTR *pchKey, DWORD dw)
469 DocHost *This = DOCHOSTUI_THIS(iface);
470 IDocHostUIHandler2 *handler;
473 TRACE("(%p)->(%p %d)\n", This, pchKey, dw);
478 hres = IDocHostUIHandler_QueryInterface(This->hostui, &IID_IDocHostUIHandler2,
480 if(SUCCEEDED(hres)) {
481 hres = IDocHostUIHandler2_GetOverrideKeyPath(handler, pchKey, dw);
482 IDocHostUIHandler2_Release(handler);
489 #undef DOCHOSTUI_THIS
491 static const IDocHostUIHandler2Vtbl DocHostUIHandler2Vtbl = {
492 DocHostUIHandler_QueryInterface,
493 DocHostUIHandler_AddRef,
494 DocHostUIHandler_Release,
495 DocHostUIHandler_ShowContextMenu,
496 DocHostUIHandler_GetHostInfo,
497 DocHostUIHandler_ShowUI,
498 DocHostUIHandler_HideUI,
499 DocHostUIHandler_UpdateUI,
500 DocHostUIHandler_EnableModeless,
501 DocHostUIHandler_OnDocWindowActivate,
502 DocHostUIHandler_OnFrameWindowActivate,
503 DocHostUIHandler_ResizeBorder,
504 DocHostUIHandler_TranslateAccelerator,
505 DocHostUIHandler_GetOptionKeyPath,
506 DocHostUIHandler_GetDropTarget,
507 DocHostUIHandler_GetExternal,
508 DocHostUIHandler_TranslateUrl,
509 DocHostUIHandler_FilterDataObject,
510 DocHostUIHandler_GetOverrideKeyPath
513 void DocHost_Init(DocHost *This, IDispatch *disp)
515 This->lpDocHostUIHandlerVtbl = &DocHostUIHandler2Vtbl;
516 This->lpOleCommandTargetVtbl = &OleCommandTargetVtbl;
520 This->client_disp = NULL;
522 This->document = NULL;
527 This->frame_hwnd = NULL;
530 This->silent = VARIANT_FALSE;
531 This->offline = VARIANT_FALSE;
533 DocHost_ClientSite_Init(This);
534 DocHost_Frame_Init(This);
536 ConnectionPointContainer_Init(&This->cps, (IUnknown*)disp);
539 void DocHost_Release(DocHost *This)
541 if(This->client_disp)
542 IDispatch_Release(This->client_disp);
544 IOleInPlaceFrame_Release(This->frame);
546 DocHost_ClientSite_Release(This);
548 ConnectionPointContainer_Destroy(&This->cps);
550 SysFreeString(This->url);