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 static void navigate_complete(DocHost *This)
30 IDispatch *disp = NULL;
31 DISPPARAMS dispparams;
36 hres = IUnknown_QueryInterface(This->document, &IID_IDispatch, (void**)&disp);
38 FIXME("Could not get IDispatch interface\n");
41 dispparams.cNamedArgs = 0;
42 dispparams.rgdispidNamedArgs = NULL;
43 dispparams.rgvarg = params;
45 V_VT(params) = (VT_BYREF|VT_VARIANT);
46 V_BYREF(params) = &url;
48 V_VT(params+1) = VT_DISPATCH;
49 V_DISPATCH(params+1) = disp;
52 V_BSTR(&url) = SysAllocString(This->url);
54 call_sink(This->cps.wbe2, DISPID_NAVIGATECOMPLETE2, &dispparams);
55 call_sink(This->cps.wbe2, DISPID_DOCUMENTCOMPLETE, &dispparams);
57 SysFreeString(V_BSTR(&url));
59 IDispatch_Release(disp);
62 static LRESULT navigate2(DocHost *This)
67 TRACE("(%p)\n", This);
70 WARN("document == NULL\n");
74 hres = IUnknown_QueryInterface(This->document, &IID_IHlinkTarget, (void**)&hlink);
76 FIXME("Could not get IHlinkTarget interface\n");
80 hres = IHlinkTarget_Navigate(hlink, 0, NULL);
81 IHlinkTarget_Release(hlink);
83 FIXME("Navigate failed\n");
87 navigate_complete(This);
92 static LRESULT resize_document(DocHost *This, LONG width, LONG height)
94 RECT rect = {0, 0, width, height};
96 TRACE("(%p)->(%d %d)\n", This, width, height);
99 IOleDocumentView_SetRect(This->view, &rect);
104 static LRESULT WINAPI doc_view_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
108 static const WCHAR wszTHIS[] = {'T','H','I','S',0};
110 if(msg == WM_CREATE) {
111 This = *(DocHost**)lParam;
112 SetPropW(hwnd, wszTHIS, This);
114 This = GetPropW(hwnd, wszTHIS);
119 return resize_document(This, LOWORD(lParam), HIWORD(lParam));
120 case WB_WM_NAVIGATE2:
121 return navigate2(This);
124 return DefWindowProcW(hwnd, msg, wParam, lParam);
127 void create_doc_view_hwnd(DocHost *This)
131 static const WCHAR wszShell_DocObject_View[] =
132 {'S','h','e','l','l',' ','D','o','c','O','b','j','e','c','t',' ','V','i','e','w',0};
135 static WNDCLASSEXW wndclass = {
139 0, 0 /* native uses 4*/, NULL, NULL, NULL,
140 (HBRUSH)COLOR_WINDOWFRAME, NULL,
141 wszShell_DocObject_View,
145 wndclass.hInstance = shdocvw_hinstance;
147 doc_view_atom = RegisterClassExW(&wndclass);
150 GetClientRect(This->frame_hwnd, &rect); /* FIXME */
151 This->hwnd = CreateWindowExW(0, wszShell_DocObject_View,
152 wszShell_DocObject_View,
153 WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_TABSTOP,
154 rect.left, rect.top, rect.right, rect.bottom, This->frame_hwnd,
155 NULL, shdocvw_hinstance, This);
158 void deactivate_document(DocHost *This)
160 IOleInPlaceObjectWindowless *winobj;
161 IOleObject *oleobj = NULL;
162 IHlinkTarget *hlink = NULL;
166 IOleDocumentView_UIActivate(This->view, FALSE);
168 hres = IUnknown_QueryInterface(This->document, &IID_IOleInPlaceObjectWindowless,
170 if(SUCCEEDED(hres)) {
171 IOleInPlaceObjectWindowless_InPlaceDeactivate(winobj);
172 IOleInPlaceObjectWindowless_Release(winobj);
176 IOleDocumentView_Show(This->view, FALSE);
177 IOleDocumentView_CloseView(This->view, 0);
178 IOleDocumentView_SetInPlaceSite(This->view, NULL);
179 IOleDocumentView_Release(This->view);
183 hres = IUnknown_QueryInterface(This->document, &IID_IOleObject, (void**)&oleobj);
185 IOleObject_Close(oleobj, OLECLOSE_NOSAVE);
187 hres = IUnknown_QueryInterface(This->document, &IID_IHlinkTarget, (void**)&hlink);
188 if(SUCCEEDED(hres)) {
189 IHlinkTarget_SetBrowseContext(hlink, NULL);
190 IHlinkTarget_Release(hlink);
194 IOleClientSite *client_site = NULL;
196 IOleObject_GetClientSite(oleobj, &client_site);
198 if(client_site == CLIENTSITE(This))
199 IOleObject_SetClientSite(oleobj, NULL);
200 IOleClientSite_Release(client_site);
203 IOleObject_Release(oleobj);
206 IUnknown_Release(This->document);
207 This->document = NULL;
210 #define OLECMD_THIS(iface) DEFINE_THIS(DocHost, OleCommandTarget, iface)
212 static HRESULT WINAPI ClOleCommandTarget_QueryInterface(IOleCommandTarget *iface,
213 REFIID riid, void **ppv)
215 DocHost *This = OLECMD_THIS(iface);
216 return IOleClientSite_QueryInterface(CLIENTSITE(This), riid, ppv);
219 static ULONG WINAPI ClOleCommandTarget_AddRef(IOleCommandTarget *iface)
221 DocHost *This = OLECMD_THIS(iface);
222 return IOleClientSite_AddRef(CLIENTSITE(This));
225 static ULONG WINAPI ClOleCommandTarget_Release(IOleCommandTarget *iface)
227 DocHost *This = OLECMD_THIS(iface);
228 return IOleClientSite_Release(CLIENTSITE(This));
231 static HRESULT WINAPI ClOleCommandTarget_QueryStatus(IOleCommandTarget *iface,
232 const GUID *pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[], OLECMDTEXT *pCmdText)
234 DocHost *This = OLECMD_THIS(iface);
235 FIXME("(%p)->(%s %u %p %p)\n", This, debugstr_guid(pguidCmdGroup), cCmds, prgCmds,
240 static HRESULT WINAPI ClOleCommandTarget_Exec(IOleCommandTarget *iface,
241 const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn,
244 DocHost *This = OLECMD_THIS(iface);
245 FIXME("(%p)->(%s %d %d %p %p)\n", This, debugstr_guid(pguidCmdGroup), nCmdID,
246 nCmdexecopt, pvaIn, pvaOut);
252 static const IOleCommandTargetVtbl OleCommandTargetVtbl = {
253 ClOleCommandTarget_QueryInterface,
254 ClOleCommandTarget_AddRef,
255 ClOleCommandTarget_Release,
256 ClOleCommandTarget_QueryStatus,
257 ClOleCommandTarget_Exec
260 #define DOCHOSTUI_THIS(iface) DEFINE_THIS(DocHost, DocHostUIHandler, iface)
262 static HRESULT WINAPI DocHostUIHandler_QueryInterface(IDocHostUIHandler2 *iface,
263 REFIID riid, void **ppv)
265 DocHost *This = DOCHOSTUI_THIS(iface);
266 return IOleClientSite_QueryInterface(CLIENTSITE(This), riid, ppv);
269 static ULONG WINAPI DocHostUIHandler_AddRef(IDocHostUIHandler2 *iface)
271 DocHost *This = DOCHOSTUI_THIS(iface);
272 return IOleClientSite_AddRef(CLIENTSITE(This));
275 static ULONG WINAPI DocHostUIHandler_Release(IDocHostUIHandler2 *iface)
277 DocHost *This = DOCHOSTUI_THIS(iface);
278 return IOleClientSite_Release(CLIENTSITE(This));
281 static HRESULT WINAPI DocHostUIHandler_ShowContextMenu(IDocHostUIHandler2 *iface,
282 DWORD dwID, POINT *ppt, IUnknown *pcmdtReserved, IDispatch *pdispReserved)
284 DocHost *This = DOCHOSTUI_THIS(iface);
287 TRACE("(%p)->(%d %p %p %p)\n", This, dwID, ppt, pcmdtReserved, pdispReserved);
290 hres = IDocHostUIHandler_ShowContextMenu(This->hostui, dwID, ppt, pcmdtReserved,
296 FIXME("default action not implemented\n");
300 static HRESULT WINAPI DocHostUIHandler_GetHostInfo(IDocHostUIHandler2 *iface,
301 DOCHOSTUIINFO *pInfo)
303 DocHost *This = DOCHOSTUI_THIS(iface);
306 TRACE("(%p)->(%p)\n", This, pInfo);
309 hres = IDocHostUIHandler_GetHostInfo(This->hostui, pInfo);
314 pInfo->dwFlags = DOCHOSTUIFLAG_DISABLE_HELP_MENU | DOCHOSTUIFLAG_OPENNEWWIN
315 | DOCHOSTUIFLAG_URL_ENCODING_ENABLE_UTF8 | DOCHOSTUIFLAG_ENABLE_INPLACE_NAVIGATION
316 | DOCHOSTUIFLAG_IME_ENABLE_RECONVERSION;
320 static HRESULT WINAPI DocHostUIHandler_ShowUI(IDocHostUIHandler2 *iface, DWORD dwID,
321 IOleInPlaceActiveObject *pActiveObject, IOleCommandTarget *pCommandTarget,
322 IOleInPlaceFrame *pFrame, IOleInPlaceUIWindow *pDoc)
324 DocHost *This = DOCHOSTUI_THIS(iface);
325 FIXME("(%p)->(%d %p %p %p %p)\n", This, dwID, pActiveObject, pCommandTarget,
330 static HRESULT WINAPI DocHostUIHandler_HideUI(IDocHostUIHandler2 *iface)
332 DocHost *This = DOCHOSTUI_THIS(iface);
333 FIXME("(%p)\n", This);
337 static HRESULT WINAPI DocHostUIHandler_UpdateUI(IDocHostUIHandler2 *iface)
339 DocHost *This = DOCHOSTUI_THIS(iface);
340 FIXME("(%p)\n", This);
344 static HRESULT WINAPI DocHostUIHandler_EnableModeless(IDocHostUIHandler2 *iface,
347 DocHost *This = DOCHOSTUI_THIS(iface);
348 FIXME("(%p)->(%x)\n", This, fEnable);
352 static HRESULT WINAPI DocHostUIHandler_OnDocWindowActivate(IDocHostUIHandler2 *iface,
355 DocHost *This = DOCHOSTUI_THIS(iface);
356 FIXME("(%p)->(%x)\n", This, fActivate);
360 static HRESULT WINAPI DocHostUIHandler_OnFrameWindowActivate(IDocHostUIHandler2 *iface,
363 DocHost *This = DOCHOSTUI_THIS(iface);
364 FIXME("(%p)->(%x)\n", This, fActivate);
368 static HRESULT WINAPI DocHostUIHandler_ResizeBorder(IDocHostUIHandler2 *iface,
369 LPCRECT prcBorder, IOleInPlaceUIWindow *pUIWindow, BOOL fRameWindow)
371 DocHost *This = DOCHOSTUI_THIS(iface);
372 FIXME("(%p)->(%p %p %X)\n", This, prcBorder, pUIWindow, fRameWindow);
376 static HRESULT WINAPI DocHostUIHandler_TranslateAccelerator(IDocHostUIHandler2 *iface,
377 LPMSG lpMsg, const GUID *pguidCmdGroup, DWORD nCmdID)
379 DocHost *This = DOCHOSTUI_THIS(iface);
380 FIXME("(%p)->(%p %p %d)\n", This, lpMsg, pguidCmdGroup, nCmdID);
384 static HRESULT WINAPI DocHostUIHandler_GetOptionKeyPath(IDocHostUIHandler2 *iface,
385 LPOLESTR *pchKey, DWORD dw)
387 DocHost *This = DOCHOSTUI_THIS(iface);
389 TRACE("(%p)->(%p %d)\n", This, pchKey, dw);
392 return IDocHostUIHandler_GetOptionKeyPath(This->hostui, pchKey, dw);
397 static HRESULT WINAPI DocHostUIHandler_GetDropTarget(IDocHostUIHandler2 *iface,
398 IDropTarget *pDropTarget, IDropTarget **ppDropTarget)
400 DocHost *This = DOCHOSTUI_THIS(iface);
401 FIXME("(%p)\n", This);
405 static HRESULT WINAPI DocHostUIHandler_GetExternal(IDocHostUIHandler2 *iface,
406 IDispatch **ppDispatch)
408 DocHost *This = DOCHOSTUI_THIS(iface);
409 FIXME("(%p)->(%p)\n", This, ppDispatch);
413 static HRESULT WINAPI DocHostUIHandler_TranslateUrl(IDocHostUIHandler2 *iface,
414 DWORD dwTranslate, OLECHAR *pchURLIn, OLECHAR **ppchURLOut)
416 DocHost *This = DOCHOSTUI_THIS(iface);
418 TRACE("(%p)->(%d %s %p)\n", This, dwTranslate, debugstr_w(pchURLIn), ppchURLOut);
421 return IDocHostUIHandler_TranslateUrl(This->hostui, dwTranslate,
422 pchURLIn, ppchURLOut);
427 static HRESULT WINAPI DocHostUIHandler_FilterDataObject(IDocHostUIHandler2 *iface,
428 IDataObject *pDO, IDataObject **ppDORet)
430 DocHost *This = DOCHOSTUI_THIS(iface);
431 FIXME("(%p)->(%p %p)\n", This, pDO, ppDORet);
435 static HRESULT WINAPI DocHostUIHandler_GetOverrideKeyPath(IDocHostUIHandler2 *iface,
436 LPOLESTR *pchKey, DWORD dw)
438 DocHost *This = DOCHOSTUI_THIS(iface);
439 IDocHostUIHandler2 *handler;
442 TRACE("(%p)->(%p %d)\n", This, pchKey, dw);
447 hres = IDocHostUIHandler_QueryInterface(This->hostui, &IID_IDocHostUIHandler2,
449 if(SUCCEEDED(hres)) {
450 hres = IDocHostUIHandler2_GetOverrideKeyPath(handler, pchKey, dw);
451 IDocHostUIHandler2_Release(handler);
458 #undef DOCHOSTUI_THIS
460 static const IDocHostUIHandler2Vtbl DocHostUIHandler2Vtbl = {
461 DocHostUIHandler_QueryInterface,
462 DocHostUIHandler_AddRef,
463 DocHostUIHandler_Release,
464 DocHostUIHandler_ShowContextMenu,
465 DocHostUIHandler_GetHostInfo,
466 DocHostUIHandler_ShowUI,
467 DocHostUIHandler_HideUI,
468 DocHostUIHandler_UpdateUI,
469 DocHostUIHandler_EnableModeless,
470 DocHostUIHandler_OnDocWindowActivate,
471 DocHostUIHandler_OnFrameWindowActivate,
472 DocHostUIHandler_ResizeBorder,
473 DocHostUIHandler_TranslateAccelerator,
474 DocHostUIHandler_GetOptionKeyPath,
475 DocHostUIHandler_GetDropTarget,
476 DocHostUIHandler_GetExternal,
477 DocHostUIHandler_TranslateUrl,
478 DocHostUIHandler_FilterDataObject,
479 DocHostUIHandler_GetOverrideKeyPath
482 void DocHost_Init(DocHost *This, IDispatch *disp)
484 This->lpDocHostUIHandlerVtbl = &DocHostUIHandler2Vtbl;
485 This->lpOleCommandTargetVtbl = &OleCommandTargetVtbl;
489 This->client_disp = NULL;
491 This->document = NULL;
496 This->frame_hwnd = NULL;
499 This->silent = VARIANT_FALSE;
500 This->offline = VARIANT_FALSE;
502 DocHost_ClientSite_Init(This);
503 DocHost_Frame_Init(This);
505 ConnectionPointContainer_Init(&This->cps, (IUnknown*)disp);
508 void DocHost_Release(DocHost *This)
510 if(This->client_disp)
511 IDispatch_Release(This->client_disp);
513 IOleInPlaceFrame_Release(This->frame);
515 DocHost_ClientSite_Release(This);
517 ConnectionPointContainer_Destroy(&This->cps);
519 SysFreeString(This->url);