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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include "wine/debug.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(shdocvw);
26 static ATOM doc_view_atom = 0;
28 static void navigate_complete(WebBrowser *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) = This->url;
54 call_sink(This->cp_wbe2, DISPID_NAVIGATECOMPLETE2, &dispparams);
55 call_sink(This->cp_wbe2, DISPID_DOCUMENTCOMPLETE, &dispparams);
58 IDispatch_Release(disp);
61 static LRESULT navigate2(WebBrowser *This)
66 TRACE("(%p)\n", This);
69 WARN("document == NULL\n");
73 hres = IUnknown_QueryInterface(This->document, &IID_IHlinkTarget, (void**)&hlink);
75 FIXME("Could not get IHlinkTarget interface\n");
79 hres = IHlinkTarget_Navigate(hlink, 0, NULL);
80 IHlinkTarget_Release(hlink);
82 FIXME("Navigate failed\n");
86 navigate_complete(This);
91 static LRESULT resize_document(WebBrowser *This, LONG width, LONG height)
93 RECT rect = {0, 0, width, height};
95 TRACE("(%p)->(%ld %ld)\n", This, width, height);
98 IOleDocumentView_SetRect(This->view, &rect);
103 static LRESULT WINAPI doc_view_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
107 static const WCHAR wszTHIS[] = {'T','H','I','S',0};
109 if(msg == WM_CREATE) {
110 This = *(WebBrowser**)lParam;
111 SetPropW(hwnd, wszTHIS, This);
113 This = GetPropW(hwnd, wszTHIS);
118 return resize_document(This, LOWORD(lParam), HIWORD(lParam));
119 case WB_WM_NAVIGATE2:
120 return navigate2(This);
123 return DefWindowProcA(hwnd, msg, wParam, lParam);
126 void create_doc_view_hwnd(WebBrowser *This)
130 static const WCHAR wszShell_DocObject_View[] =
131 {'S','h','e','l','l',' ','D','o','c','O','b','j','e','c','t',' ','V','i','e','w',0};
134 static WNDCLASSEXW wndclass = {
138 0, 0 /* native uses 4*/, NULL, NULL, NULL,
139 (HBRUSH)COLOR_WINDOWFRAME, NULL,
140 wszShell_DocObject_View,
144 wndclass.hInstance = shdocvw_hinstance;
146 doc_view_atom = RegisterClassExW(&wndclass);
149 GetWindowRect(This->shell_embedding_hwnd, &rect);
150 This->doc_view_hwnd = CreateWindowExW(0, wszShell_DocObject_View,
151 wszShell_DocObject_View,
152 WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_TABSTOP | WS_MAXIMIZEBOX,
153 rect.left, rect.top, rect.right, rect.bottom, This->shell_embedding_hwnd,
154 NULL, shdocvw_hinstance, This);
157 void deactivate_document(WebBrowser *This)
159 IOleInPlaceObjectWindowless *winobj;
160 IOleObject *oleobj = NULL;
161 IHlinkTarget *hlink = NULL;
165 IOleDocumentView_UIActivate(This->view, FALSE);
167 hres = IUnknown_QueryInterface(This->client, &IID_IOleInPlaceObjectWindowless,
169 if(SUCCEEDED(hres)) {
170 IOleInPlaceObjectWindowless_InPlaceDeactivate(winobj);
171 IOleInPlaceObjectWindowless_Release(winobj);
175 IOleDocumentView_Show(This->view, FALSE);
176 IOleDocumentView_CloseView(This->view, 0);
177 IOleDocumentView_SetInPlaceSite(This->view, NULL);
178 IOleDocumentView_Release(This->view);
182 hres = IUnknown_QueryInterface(This->document, &IID_IOleObject, (void**)&oleobj);
184 IOleObject_Close(oleobj, OLECLOSE_NOSAVE);
186 hres = IUnknown_QueryInterface(This->document, &IID_IHlinkTarget, (void**)&hlink);
187 if(SUCCEEDED(hres)) {
188 IHlinkTarget_SetBrowseContext(hlink, NULL);
189 IHlinkTarget_Release(hlink);
193 IOleClientSite *client_site = NULL;
195 IOleObject_GetClientSite(oleobj, &client_site);
197 if(client_site == CLIENTSITE(This))
198 IOleObject_SetClientSite(oleobj, NULL);
199 IOleClientSite_Release(client_site);
202 IOleObject_Release(oleobj);
205 IUnknown_Release(This->document);
206 This->document = NULL;
209 #define OLECMD_THIS(iface) DEFINE_THIS(WebBrowser, ClOleCommandTarget, iface)
211 static HRESULT WINAPI ClOleCommandTarget_QueryInterface(IOleCommandTarget *iface,
212 REFIID riid, void **ppv)
214 WebBrowser *This = OLECMD_THIS(iface);
215 return IOleClientSite_QueryInterface(CLIENTSITE(This), riid, ppv);
218 static ULONG WINAPI ClOleCommandTarget_AddRef(IOleCommandTarget *iface)
220 WebBrowser *This = OLECMD_THIS(iface);
221 return IWebBrowser2_AddRef(WEBBROWSER(This));
224 static ULONG WINAPI ClOleCommandTarget_Release(IOleCommandTarget *iface)
226 WebBrowser *This = OLECMD_THIS(iface);
227 return IWebBrowser2_Release(WEBBROWSER(This));
230 static HRESULT WINAPI ClOleCommandTarget_QueryStatus(IOleCommandTarget *iface,
231 const GUID *pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[], OLECMDTEXT *pCmdText)
233 WebBrowser *This = OLECMD_THIS(iface);
234 FIXME("(%p)->(%s %lu %p %p)\n", This, debugstr_guid(pguidCmdGroup), cCmds, prgCmds,
239 static HRESULT WINAPI ClOleCommandTarget_Exec(IOleCommandTarget *iface,
240 const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn,
243 WebBrowser *This = OLECMD_THIS(iface);
244 FIXME("(%p)->(%s %ld %ld %p %p)\n", This, debugstr_guid(pguidCmdGroup), nCmdID,
245 nCmdexecopt, pvaIn, pvaOut);
251 static const IOleCommandTargetVtbl OleCommandTargetVtbl = {
252 ClOleCommandTarget_QueryInterface,
253 ClOleCommandTarget_AddRef,
254 ClOleCommandTarget_Release,
255 ClOleCommandTarget_QueryStatus,
256 ClOleCommandTarget_Exec
259 #define DOCHOSTUI_THIS(iface) DEFINE_THIS(WebBrowser, DocHostUIHandler, iface)
261 static HRESULT WINAPI DocHostUIHandler_QueryInterface(IDocHostUIHandler2 *iface,
262 REFIID riid, void **ppv)
264 WebBrowser *This = DOCHOSTUI_THIS(iface);
265 return IOleClientSite_QueryInterface(CLIENTSITE(This), riid, ppv);
268 static ULONG WINAPI DocHostUIHandler_AddRef(IDocHostUIHandler2 *iface)
270 WebBrowser *This = DOCHOSTUI_THIS(iface);
271 return IOleClientSite_AddRef(CLIENTSITE(This));
274 static ULONG WINAPI DocHostUIHandler_Release(IDocHostUIHandler2 *iface)
276 WebBrowser *This = DOCHOSTUI_THIS(iface);
277 return IOleClientSite_Release(CLIENTSITE(This));
280 static HRESULT WINAPI DocHostUIHandler_ShowContextMenu(IDocHostUIHandler2 *iface,
281 DWORD dwID, POINT *ppt, IUnknown *pcmdtReserved, IDispatch *pdispReserved)
283 WebBrowser *This = DOCHOSTUI_THIS(iface);
284 FIXME("(%p)->(%ld %p %p %p)\n", This, dwID, ppt, pcmdtReserved, pdispReserved);
288 static HRESULT WINAPI DocHostUIHandler_GetHostInfo(IDocHostUIHandler2 *iface,
289 DOCHOSTUIINFO *pInfo)
291 WebBrowser *This = DOCHOSTUI_THIS(iface);
294 TRACE("(%p)->(%p)\n", This, pInfo);
297 hres = IDocHostUIHandler_GetHostInfo(This->hostui, pInfo);
302 pInfo->dwFlags = DOCHOSTUIFLAG_DISABLE_HELP_MENU | DOCHOSTUIFLAG_OPENNEWWIN
303 | DOCHOSTUIFLAG_URL_ENCODING_ENABLE_UTF8 | DOCHOSTUIFLAG_ENABLE_INPLACE_NAVIGATION
304 | DOCHOSTUIFLAG_IME_ENABLE_RECONVERSION;
308 static HRESULT WINAPI DocHostUIHandler_ShowUI(IDocHostUIHandler2 *iface, DWORD dwID,
309 IOleInPlaceActiveObject *pActiveObject, IOleCommandTarget *pCommandTarget,
310 IOleInPlaceFrame *pFrame, IOleInPlaceUIWindow *pDoc)
312 WebBrowser *This = DOCHOSTUI_THIS(iface);
313 FIXME("(%p)->(%ld %p %p %p %p)\n", This, dwID, pActiveObject, pCommandTarget,
318 static HRESULT WINAPI DocHostUIHandler_HideUI(IDocHostUIHandler2 *iface)
320 WebBrowser *This = DOCHOSTUI_THIS(iface);
321 FIXME("(%p)\n", This);
325 static HRESULT WINAPI DocHostUIHandler_UpdateUI(IDocHostUIHandler2 *iface)
327 WebBrowser *This = DOCHOSTUI_THIS(iface);
328 FIXME("(%p)\n", This);
332 static HRESULT WINAPI DocHostUIHandler_EnableModeless(IDocHostUIHandler2 *iface,
335 WebBrowser *This = DOCHOSTUI_THIS(iface);
336 FIXME("(%p)->(%x)\n", This, fEnable);
340 static HRESULT WINAPI DocHostUIHandler_OnDocWindowActivate(IDocHostUIHandler2 *iface,
343 WebBrowser *This = DOCHOSTUI_THIS(iface);
344 FIXME("(%p)->(%x)\n", This, fActivate);
348 static HRESULT WINAPI DocHostUIHandler_OnFrameWindowActivate(IDocHostUIHandler2 *iface,
351 WebBrowser *This = DOCHOSTUI_THIS(iface);
352 FIXME("(%p)->(%x)\n", This, fActivate);
356 static HRESULT WINAPI DocHostUIHandler_ResizeBorder(IDocHostUIHandler2 *iface,
357 LPCRECT prcBorder, IOleInPlaceUIWindow *pUIWindow, BOOL fRameWindow)
359 WebBrowser *This = DOCHOSTUI_THIS(iface);
360 FIXME("(%p)->(%p %p %X)\n", This, prcBorder, pUIWindow, fRameWindow);
364 static HRESULT WINAPI DocHostUIHandler_TranslateAccelerator(IDocHostUIHandler2 *iface,
365 LPMSG lpMsg, const GUID *pguidCmdGroup, DWORD nCmdID)
367 WebBrowser *This = DOCHOSTUI_THIS(iface);
368 FIXME("(%p)->(%p %p %ld)\n", This, lpMsg, pguidCmdGroup, nCmdID);
372 static HRESULT WINAPI DocHostUIHandler_GetOptionKeyPath(IDocHostUIHandler2 *iface,
373 LPOLESTR *pchKey, DWORD dw)
375 WebBrowser *This = DOCHOSTUI_THIS(iface);
377 TRACE("(%p)->(%p %ld)\n", This, pchKey, dw);
380 return IDocHostUIHandler_GetOptionKeyPath(This->hostui, pchKey, dw);
385 static HRESULT WINAPI DocHostUIHandler_GetDropTarget(IDocHostUIHandler2 *iface,
386 IDropTarget *pDropTarget, IDropTarget **ppDropTarget)
388 WebBrowser *This = DOCHOSTUI_THIS(iface);
389 FIXME("(%p)\n", This);
393 static HRESULT WINAPI DocHostUIHandler_GetExternal(IDocHostUIHandler2 *iface,
394 IDispatch **ppDispatch)
396 WebBrowser *This = DOCHOSTUI_THIS(iface);
397 FIXME("(%p)->(%p)\n", This, ppDispatch);
401 static HRESULT WINAPI DocHostUIHandler_TranslateUrl(IDocHostUIHandler2 *iface,
402 DWORD dwTranslate, OLECHAR *pchURLIn, OLECHAR **ppchURLOut)
404 WebBrowser *This = DOCHOSTUI_THIS(iface);
406 TRACE("(%p)->(%ld %s %p)\n", This, dwTranslate, debugstr_w(pchURLIn), ppchURLOut);
409 return IDocHostUIHandler_TranslateUrl(This->hostui, dwTranslate,
410 pchURLIn, ppchURLOut);
415 static HRESULT WINAPI DocHostUIHandler_FilterDataObject(IDocHostUIHandler2 *iface,
416 IDataObject *pDO, IDataObject **ppDORet)
418 WebBrowser *This = DOCHOSTUI_THIS(iface);
419 FIXME("(%p)->(%p %p)\n", This, pDO, ppDORet);
423 static HRESULT WINAPI DocHostUIHandler_GetOverrideKeyPath(IDocHostUIHandler2 *iface,
424 LPOLESTR *pchKey, DWORD dw)
426 WebBrowser *This = DOCHOSTUI_THIS(iface);
427 IDocHostUIHandler2 *handler;
430 TRACE("(%p)->(%p %ld)\n", This, pchKey, dw);
435 hres = IOleClientSite_QueryInterface(This->client, &IID_IDocHostUIHandler2,
437 if(SUCCEEDED(hres)) {
438 hres = IDocHostUIHandler2_GetOverrideKeyPath(handler, pchKey, dw);
439 IDocHostUIHandler2_Release(handler);
446 #undef DOCHOSTUI_THIS
448 static const IDocHostUIHandler2Vtbl DocHostUIHandler2Vtbl = {
449 DocHostUIHandler_QueryInterface,
450 DocHostUIHandler_AddRef,
451 DocHostUIHandler_Release,
452 DocHostUIHandler_ShowContextMenu,
453 DocHostUIHandler_GetHostInfo,
454 DocHostUIHandler_ShowUI,
455 DocHostUIHandler_HideUI,
456 DocHostUIHandler_UpdateUI,
457 DocHostUIHandler_EnableModeless,
458 DocHostUIHandler_OnDocWindowActivate,
459 DocHostUIHandler_OnFrameWindowActivate,
460 DocHostUIHandler_ResizeBorder,
461 DocHostUIHandler_TranslateAccelerator,
462 DocHostUIHandler_GetOptionKeyPath,
463 DocHostUIHandler_GetDropTarget,
464 DocHostUIHandler_GetExternal,
465 DocHostUIHandler_TranslateUrl,
466 DocHostUIHandler_FilterDataObject,
467 DocHostUIHandler_GetOverrideKeyPath
470 void WebBrowser_DocHost_Init(WebBrowser *This)
472 This->lpDocHostUIHandlerVtbl = &DocHostUIHandler2Vtbl;
473 This->lpClOleCommandTargetVtbl = &OleCommandTargetVtbl;
477 This->doc_view_hwnd = NULL;