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);
341 TRACE("(%p)\n", This);
346 return IDocHostUIHandler_UpdateUI(This->hostui);
349 static HRESULT WINAPI DocHostUIHandler_EnableModeless(IDocHostUIHandler2 *iface,
352 DocHost *This = DOCHOSTUI_THIS(iface);
353 FIXME("(%p)->(%x)\n", This, fEnable);
357 static HRESULT WINAPI DocHostUIHandler_OnDocWindowActivate(IDocHostUIHandler2 *iface,
360 DocHost *This = DOCHOSTUI_THIS(iface);
361 FIXME("(%p)->(%x)\n", This, fActivate);
365 static HRESULT WINAPI DocHostUIHandler_OnFrameWindowActivate(IDocHostUIHandler2 *iface,
368 DocHost *This = DOCHOSTUI_THIS(iface);
369 FIXME("(%p)->(%x)\n", This, fActivate);
373 static HRESULT WINAPI DocHostUIHandler_ResizeBorder(IDocHostUIHandler2 *iface,
374 LPCRECT prcBorder, IOleInPlaceUIWindow *pUIWindow, BOOL fRameWindow)
376 DocHost *This = DOCHOSTUI_THIS(iface);
377 FIXME("(%p)->(%p %p %X)\n", This, prcBorder, pUIWindow, fRameWindow);
381 static HRESULT WINAPI DocHostUIHandler_TranslateAccelerator(IDocHostUIHandler2 *iface,
382 LPMSG lpMsg, const GUID *pguidCmdGroup, DWORD nCmdID)
384 DocHost *This = DOCHOSTUI_THIS(iface);
385 FIXME("(%p)->(%p %p %d)\n", This, lpMsg, pguidCmdGroup, nCmdID);
389 static HRESULT WINAPI DocHostUIHandler_GetOptionKeyPath(IDocHostUIHandler2 *iface,
390 LPOLESTR *pchKey, DWORD dw)
392 DocHost *This = DOCHOSTUI_THIS(iface);
394 TRACE("(%p)->(%p %d)\n", This, pchKey, dw);
397 return IDocHostUIHandler_GetOptionKeyPath(This->hostui, pchKey, dw);
402 static HRESULT WINAPI DocHostUIHandler_GetDropTarget(IDocHostUIHandler2 *iface,
403 IDropTarget *pDropTarget, IDropTarget **ppDropTarget)
405 DocHost *This = DOCHOSTUI_THIS(iface);
406 FIXME("(%p)\n", This);
410 static HRESULT WINAPI DocHostUIHandler_GetExternal(IDocHostUIHandler2 *iface,
411 IDispatch **ppDispatch)
413 DocHost *This = DOCHOSTUI_THIS(iface);
415 TRACE("(%p)->(%p)\n", This, ppDispatch);
418 return IDocHostUIHandler_GetExternal(This->hostui, ppDispatch);
420 FIXME("default action not implemented\n");
424 static HRESULT WINAPI DocHostUIHandler_TranslateUrl(IDocHostUIHandler2 *iface,
425 DWORD dwTranslate, OLECHAR *pchURLIn, OLECHAR **ppchURLOut)
427 DocHost *This = DOCHOSTUI_THIS(iface);
429 TRACE("(%p)->(%d %s %p)\n", This, dwTranslate, debugstr_w(pchURLIn), ppchURLOut);
432 return IDocHostUIHandler_TranslateUrl(This->hostui, dwTranslate,
433 pchURLIn, ppchURLOut);
438 static HRESULT WINAPI DocHostUIHandler_FilterDataObject(IDocHostUIHandler2 *iface,
439 IDataObject *pDO, IDataObject **ppDORet)
441 DocHost *This = DOCHOSTUI_THIS(iface);
442 FIXME("(%p)->(%p %p)\n", This, pDO, ppDORet);
446 static HRESULT WINAPI DocHostUIHandler_GetOverrideKeyPath(IDocHostUIHandler2 *iface,
447 LPOLESTR *pchKey, DWORD dw)
449 DocHost *This = DOCHOSTUI_THIS(iface);
450 IDocHostUIHandler2 *handler;
453 TRACE("(%p)->(%p %d)\n", This, pchKey, dw);
458 hres = IDocHostUIHandler_QueryInterface(This->hostui, &IID_IDocHostUIHandler2,
460 if(SUCCEEDED(hres)) {
461 hres = IDocHostUIHandler2_GetOverrideKeyPath(handler, pchKey, dw);
462 IDocHostUIHandler2_Release(handler);
469 #undef DOCHOSTUI_THIS
471 static const IDocHostUIHandler2Vtbl DocHostUIHandler2Vtbl = {
472 DocHostUIHandler_QueryInterface,
473 DocHostUIHandler_AddRef,
474 DocHostUIHandler_Release,
475 DocHostUIHandler_ShowContextMenu,
476 DocHostUIHandler_GetHostInfo,
477 DocHostUIHandler_ShowUI,
478 DocHostUIHandler_HideUI,
479 DocHostUIHandler_UpdateUI,
480 DocHostUIHandler_EnableModeless,
481 DocHostUIHandler_OnDocWindowActivate,
482 DocHostUIHandler_OnFrameWindowActivate,
483 DocHostUIHandler_ResizeBorder,
484 DocHostUIHandler_TranslateAccelerator,
485 DocHostUIHandler_GetOptionKeyPath,
486 DocHostUIHandler_GetDropTarget,
487 DocHostUIHandler_GetExternal,
488 DocHostUIHandler_TranslateUrl,
489 DocHostUIHandler_FilterDataObject,
490 DocHostUIHandler_GetOverrideKeyPath
493 void DocHost_Init(DocHost *This, IDispatch *disp)
495 This->lpDocHostUIHandlerVtbl = &DocHostUIHandler2Vtbl;
496 This->lpOleCommandTargetVtbl = &OleCommandTargetVtbl;
500 This->client_disp = NULL;
502 This->document = NULL;
507 This->frame_hwnd = NULL;
510 This->silent = VARIANT_FALSE;
511 This->offline = VARIANT_FALSE;
513 DocHost_ClientSite_Init(This);
514 DocHost_Frame_Init(This);
516 ConnectionPointContainer_Init(&This->cps, (IUnknown*)disp);
519 void DocHost_Release(DocHost *This)
521 if(This->client_disp)
522 IDispatch_Release(This->client_disp);
524 IOleInPlaceFrame_Release(This->frame);
526 DocHost_ClientSite_Release(This);
528 ConnectionPointContainer_Destroy(&This->cps);
530 SysFreeString(This->url);