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->doc_host.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->doc_host.cp_wbe2, DISPID_NAVIGATECOMPLETE2, &dispparams);
55 call_sink(This->doc_host.cp_wbe2, DISPID_DOCUMENTCOMPLETE, &dispparams);
58 IDispatch_Release(disp);
61 static LRESULT navigate2(WebBrowser *This)
66 TRACE("(%p)\n", This);
68 if(!This->doc_host.document) {
69 WARN("document == NULL\n");
73 hres = IUnknown_QueryInterface(This->doc_host.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);
97 if(This->doc_host.view)
98 IOleDocumentView_SetRect(This->doc_host.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 DefWindowProcW(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 GetClientRect(This->shell_embedding_hwnd, &rect);
150 This->doc_host.hwnd = CreateWindowExW(0, wszShell_DocObject_View,
151 wszShell_DocObject_View,
152 WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_TABSTOP,
153 rect.left, rect.top, rect.right, rect.bottom, This->shell_embedding_hwnd,
154 NULL, shdocvw_hinstance, This);
157 void deactivate_document(DocHost *This)
159 IOleInPlaceObjectWindowless *winobj;
160 IOleObject *oleobj = NULL;
161 IHlinkTarget *hlink = NULL;
165 IOleDocumentView_UIActivate(This->view, FALSE);
167 hres = IUnknown_QueryInterface(This->document, &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(DocHost, OleCommandTarget, iface)
211 static HRESULT WINAPI ClOleCommandTarget_QueryInterface(IOleCommandTarget *iface,
212 REFIID riid, void **ppv)
214 DocHost *This = OLECMD_THIS(iface);
215 return IOleClientSite_QueryInterface(CLIENTSITE(This), riid, ppv);
218 static ULONG WINAPI ClOleCommandTarget_AddRef(IOleCommandTarget *iface)
220 DocHost *This = OLECMD_THIS(iface);
221 return IOleClientSite_AddRef(CLIENTSITE(This));
224 static ULONG WINAPI ClOleCommandTarget_Release(IOleCommandTarget *iface)
226 DocHost *This = OLECMD_THIS(iface);
227 return IOleClientSite_Release(CLIENTSITE(This));
230 static HRESULT WINAPI ClOleCommandTarget_QueryStatus(IOleCommandTarget *iface,
231 const GUID *pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[], OLECMDTEXT *pCmdText)
233 DocHost *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 DocHost *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(DocHost, DocHostUIHandler, iface)
261 static HRESULT WINAPI DocHostUIHandler_QueryInterface(IDocHostUIHandler2 *iface,
262 REFIID riid, void **ppv)
264 DocHost *This = DOCHOSTUI_THIS(iface);
265 return IOleClientSite_QueryInterface(CLIENTSITE(This), riid, ppv);
268 static ULONG WINAPI DocHostUIHandler_AddRef(IDocHostUIHandler2 *iface)
270 DocHost *This = DOCHOSTUI_THIS(iface);
271 return IOleClientSite_AddRef(CLIENTSITE(This));
274 static ULONG WINAPI DocHostUIHandler_Release(IDocHostUIHandler2 *iface)
276 DocHost *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 DocHost *This = DOCHOSTUI_THIS(iface);
286 TRACE("(%p)->(%ld %p %p %p)\n", This, dwID, ppt, pcmdtReserved, pdispReserved);
289 hres = IDocHostUIHandler_ShowContextMenu(This->hostui, dwID, ppt, pcmdtReserved,
295 FIXME("default action not implemented\n");
299 static HRESULT WINAPI DocHostUIHandler_GetHostInfo(IDocHostUIHandler2 *iface,
300 DOCHOSTUIINFO *pInfo)
302 DocHost *This = DOCHOSTUI_THIS(iface);
305 TRACE("(%p)->(%p)\n", This, pInfo);
308 hres = IDocHostUIHandler_GetHostInfo(This->hostui, pInfo);
313 pInfo->dwFlags = DOCHOSTUIFLAG_DISABLE_HELP_MENU | DOCHOSTUIFLAG_OPENNEWWIN
314 | DOCHOSTUIFLAG_URL_ENCODING_ENABLE_UTF8 | DOCHOSTUIFLAG_ENABLE_INPLACE_NAVIGATION
315 | DOCHOSTUIFLAG_IME_ENABLE_RECONVERSION;
319 static HRESULT WINAPI DocHostUIHandler_ShowUI(IDocHostUIHandler2 *iface, DWORD dwID,
320 IOleInPlaceActiveObject *pActiveObject, IOleCommandTarget *pCommandTarget,
321 IOleInPlaceFrame *pFrame, IOleInPlaceUIWindow *pDoc)
323 DocHost *This = DOCHOSTUI_THIS(iface);
324 FIXME("(%p)->(%ld %p %p %p %p)\n", This, dwID, pActiveObject, pCommandTarget,
329 static HRESULT WINAPI DocHostUIHandler_HideUI(IDocHostUIHandler2 *iface)
331 DocHost *This = DOCHOSTUI_THIS(iface);
332 FIXME("(%p)\n", This);
336 static HRESULT WINAPI DocHostUIHandler_UpdateUI(IDocHostUIHandler2 *iface)
338 DocHost *This = DOCHOSTUI_THIS(iface);
339 FIXME("(%p)\n", This);
343 static HRESULT WINAPI DocHostUIHandler_EnableModeless(IDocHostUIHandler2 *iface,
346 DocHost *This = DOCHOSTUI_THIS(iface);
347 FIXME("(%p)->(%x)\n", This, fEnable);
351 static HRESULT WINAPI DocHostUIHandler_OnDocWindowActivate(IDocHostUIHandler2 *iface,
354 DocHost *This = DOCHOSTUI_THIS(iface);
355 FIXME("(%p)->(%x)\n", This, fActivate);
359 static HRESULT WINAPI DocHostUIHandler_OnFrameWindowActivate(IDocHostUIHandler2 *iface,
362 DocHost *This = DOCHOSTUI_THIS(iface);
363 FIXME("(%p)->(%x)\n", This, fActivate);
367 static HRESULT WINAPI DocHostUIHandler_ResizeBorder(IDocHostUIHandler2 *iface,
368 LPCRECT prcBorder, IOleInPlaceUIWindow *pUIWindow, BOOL fRameWindow)
370 DocHost *This = DOCHOSTUI_THIS(iface);
371 FIXME("(%p)->(%p %p %X)\n", This, prcBorder, pUIWindow, fRameWindow);
375 static HRESULT WINAPI DocHostUIHandler_TranslateAccelerator(IDocHostUIHandler2 *iface,
376 LPMSG lpMsg, const GUID *pguidCmdGroup, DWORD nCmdID)
378 DocHost *This = DOCHOSTUI_THIS(iface);
379 FIXME("(%p)->(%p %p %ld)\n", This, lpMsg, pguidCmdGroup, nCmdID);
383 static HRESULT WINAPI DocHostUIHandler_GetOptionKeyPath(IDocHostUIHandler2 *iface,
384 LPOLESTR *pchKey, DWORD dw)
386 DocHost *This = DOCHOSTUI_THIS(iface);
388 TRACE("(%p)->(%p %ld)\n", This, pchKey, dw);
391 return IDocHostUIHandler_GetOptionKeyPath(This->hostui, pchKey, dw);
396 static HRESULT WINAPI DocHostUIHandler_GetDropTarget(IDocHostUIHandler2 *iface,
397 IDropTarget *pDropTarget, IDropTarget **ppDropTarget)
399 DocHost *This = DOCHOSTUI_THIS(iface);
400 FIXME("(%p)\n", This);
404 static HRESULT WINAPI DocHostUIHandler_GetExternal(IDocHostUIHandler2 *iface,
405 IDispatch **ppDispatch)
407 DocHost *This = DOCHOSTUI_THIS(iface);
408 FIXME("(%p)->(%p)\n", This, ppDispatch);
412 static HRESULT WINAPI DocHostUIHandler_TranslateUrl(IDocHostUIHandler2 *iface,
413 DWORD dwTranslate, OLECHAR *pchURLIn, OLECHAR **ppchURLOut)
415 DocHost *This = DOCHOSTUI_THIS(iface);
417 TRACE("(%p)->(%ld %s %p)\n", This, dwTranslate, debugstr_w(pchURLIn), ppchURLOut);
420 return IDocHostUIHandler_TranslateUrl(This->hostui, dwTranslate,
421 pchURLIn, ppchURLOut);
426 static HRESULT WINAPI DocHostUIHandler_FilterDataObject(IDocHostUIHandler2 *iface,
427 IDataObject *pDO, IDataObject **ppDORet)
429 DocHost *This = DOCHOSTUI_THIS(iface);
430 FIXME("(%p)->(%p %p)\n", This, pDO, ppDORet);
434 static HRESULT WINAPI DocHostUIHandler_GetOverrideKeyPath(IDocHostUIHandler2 *iface,
435 LPOLESTR *pchKey, DWORD dw)
437 DocHost *This = DOCHOSTUI_THIS(iface);
438 IDocHostUIHandler2 *handler;
441 TRACE("(%p)->(%p %ld)\n", This, pchKey, dw);
446 hres = IDocHostUIHandler_QueryInterface(This->hostui, &IID_IDocHostUIHandler2,
448 if(SUCCEEDED(hres)) {
449 hres = IDocHostUIHandler2_GetOverrideKeyPath(handler, pchKey, dw);
450 IDocHostUIHandler2_Release(handler);
457 #undef DOCHOSTUI_THIS
459 static const IDocHostUIHandler2Vtbl DocHostUIHandler2Vtbl = {
460 DocHostUIHandler_QueryInterface,
461 DocHostUIHandler_AddRef,
462 DocHostUIHandler_Release,
463 DocHostUIHandler_ShowContextMenu,
464 DocHostUIHandler_GetHostInfo,
465 DocHostUIHandler_ShowUI,
466 DocHostUIHandler_HideUI,
467 DocHostUIHandler_UpdateUI,
468 DocHostUIHandler_EnableModeless,
469 DocHostUIHandler_OnDocWindowActivate,
470 DocHostUIHandler_OnFrameWindowActivate,
471 DocHostUIHandler_ResizeBorder,
472 DocHostUIHandler_TranslateAccelerator,
473 DocHostUIHandler_GetOptionKeyPath,
474 DocHostUIHandler_GetDropTarget,
475 DocHostUIHandler_GetExternal,
476 DocHostUIHandler_TranslateUrl,
477 DocHostUIHandler_FilterDataObject,
478 DocHostUIHandler_GetOverrideKeyPath
481 void DocHost_Init(DocHost *This)
483 This->lpDocHostUIHandlerVtbl = &DocHostUIHandler2Vtbl;
484 This->lpOleCommandTargetVtbl = &OleCommandTargetVtbl;
486 This->document = NULL;
490 This->frame_hwnd = NULL;
492 DocHost_ClientSite_Init(This);
493 DocHost_Frame_Init(This);
494 DocHost_Events_Init(This);
497 void DocHost_Release(DocHost *This)
499 DocHost_ClientSite_Release(This);
500 DocHost_Events_Release(This);