Changes in crossover-wine-src-6.1.0 except for configure
[wine/hacks.git] / dlls / shdocvw / dochost.c
blob7391239b29d1016c5acea97fc4b5e2c008aea5c4
1 /*
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"
20 #include "shdocvw.h"
21 #include "hlink.h"
22 #include "exdispid.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;
32 VARIANTARG params[2];
33 VARIANT url;
34 HRESULT hres;
36 hres = IUnknown_QueryInterface(This->document, &IID_IDispatch, (void**)&disp);
37 if(FAILED(hres))
38 FIXME("Could not get IDispatch interface\n");
40 dispparams.cArgs = 2;
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;
51 V_VT(&url) = VT_BSTR;
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));
58 if(disp)
59 IDispatch_Release(disp);
62 static LRESULT navigate2(DocHost *This)
64 IHlinkTarget *hlink;
65 HRESULT hres;
67 TRACE("(%p)\n", This);
69 if(!This->document) {
70 WARN("document == NULL\n");
71 return 0;
74 hres = IUnknown_QueryInterface(This->document, &IID_IHlinkTarget, (void**)&hlink);
75 if(FAILED(hres)) {
76 FIXME("Could not get IHlinkTarget interface\n");
77 return 0;
80 hres = IHlinkTarget_Navigate(hlink, 0, NULL);
81 IHlinkTarget_Release(hlink);
82 if(FAILED(hres)) {
83 FIXME("Navigate failed\n");
84 return 0;
87 navigate_complete(This);
89 return 0;
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);
98 if(This->view)
99 IOleDocumentView_SetRect(This->view, &rect);
101 return 0;
104 static LRESULT WINAPI doc_view_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
106 DocHost *This;
108 static const WCHAR wszTHIS[] = {'T','H','I','S',0};
110 if(msg == WM_CREATE) {
111 This = *(DocHost**)lParam;
112 SetPropW(hwnd, wszTHIS, This);
113 }else {
114 This = GetPropW(hwnd, wszTHIS);
117 switch(msg) {
118 case WM_SIZE:
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)
129 RECT rect;
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};
134 if(!doc_view_atom) {
135 static WNDCLASSEXW wndclass = {
136 sizeof(wndclass),
137 CS_PARENTDC,
138 doc_view_proc,
139 0, 0 /* native uses 4*/, NULL, NULL, NULL,
140 (HBRUSH)COLOR_WINDOWFRAME, NULL,
141 wszShell_DocObject_View,
142 NULL
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;
163 HRESULT hres;
165 if(This->view)
166 IOleDocumentView_UIActivate(This->view, FALSE);
168 hres = IUnknown_QueryInterface(This->document, &IID_IOleInPlaceObjectWindowless,
169 (void**)&winobj);
170 if(SUCCEEDED(hres)) {
171 IOleInPlaceObjectWindowless_InPlaceDeactivate(winobj);
172 IOleInPlaceObjectWindowless_Release(winobj);
175 if(This->view) {
176 IOleDocumentView_Show(This->view, FALSE);
177 IOleDocumentView_CloseView(This->view, 0);
178 IOleDocumentView_SetInPlaceSite(This->view, NULL);
179 IOleDocumentView_Release(This->view);
180 This->view = NULL;
183 hres = IUnknown_QueryInterface(This->document, &IID_IOleObject, (void**)&oleobj);
184 if(SUCCEEDED(hres))
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);
193 if(oleobj) {
194 IOleClientSite *client_site = NULL;
196 IOleObject_GetClientSite(oleobj, &client_site);
197 if(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,
236 pCmdText);
237 return E_NOTIMPL;
240 static HRESULT WINAPI ClOleCommandTarget_Exec(IOleCommandTarget *iface,
241 const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn,
242 VARIANT *pvaOut)
244 DocHost *This = OLECMD_THIS(iface);
245 FIXME("(%p)->(%s %d %d %p %p)\n", This, debugstr_guid(pguidCmdGroup), nCmdID,
246 nCmdexecopt, pvaIn, pvaOut);
247 return E_NOTIMPL;
250 #undef OLECMD_THIS
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);
285 HRESULT hres;
287 TRACE("(%p)->(%d %p %p %p)\n", This, dwID, ppt, pcmdtReserved, pdispReserved);
289 if(This->hostui) {
290 hres = IDocHostUIHandler_ShowContextMenu(This->hostui, dwID, ppt, pcmdtReserved,
291 pdispReserved);
292 if(hres == S_OK)
293 return S_OK;
296 FIXME("default action not implemented\n");
297 return E_NOTIMPL;
300 static HRESULT WINAPI DocHostUIHandler_GetHostInfo(IDocHostUIHandler2 *iface,
301 DOCHOSTUIINFO *pInfo)
303 DocHost *This = DOCHOSTUI_THIS(iface);
304 HRESULT hres;
306 TRACE("(%p)->(%p)\n", This, pInfo);
308 if(This->hostui) {
309 hres = IDocHostUIHandler_GetHostInfo(This->hostui, pInfo);
310 if(SUCCEEDED(hres))
311 return hres;
314 pInfo->dwFlags = DOCHOSTUIFLAG_DISABLE_HELP_MENU | DOCHOSTUIFLAG_OPENNEWWIN
315 | DOCHOSTUIFLAG_URL_ENCODING_ENABLE_UTF8 | DOCHOSTUIFLAG_ENABLE_INPLACE_NAVIGATION
316 | DOCHOSTUIFLAG_IME_ENABLE_RECONVERSION;
317 return S_OK;
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,
326 pFrame, pDoc);
327 return E_NOTIMPL;
330 static HRESULT WINAPI DocHostUIHandler_HideUI(IDocHostUIHandler2 *iface)
332 DocHost *This = DOCHOSTUI_THIS(iface);
333 FIXME("(%p)\n", This);
334 return E_NOTIMPL;
337 static HRESULT WINAPI DocHostUIHandler_UpdateUI(IDocHostUIHandler2 *iface)
339 DocHost *This = DOCHOSTUI_THIS(iface);
340 FIXME("(%p)\n", This);
341 return E_NOTIMPL;
344 static HRESULT WINAPI DocHostUIHandler_EnableModeless(IDocHostUIHandler2 *iface,
345 BOOL fEnable)
347 DocHost *This = DOCHOSTUI_THIS(iface);
348 FIXME("(%p)->(%x)\n", This, fEnable);
349 return E_NOTIMPL;
352 static HRESULT WINAPI DocHostUIHandler_OnDocWindowActivate(IDocHostUIHandler2 *iface,
353 BOOL fActivate)
355 DocHost *This = DOCHOSTUI_THIS(iface);
356 FIXME("(%p)->(%x)\n", This, fActivate);
357 return E_NOTIMPL;
360 static HRESULT WINAPI DocHostUIHandler_OnFrameWindowActivate(IDocHostUIHandler2 *iface,
361 BOOL fActivate)
363 DocHost *This = DOCHOSTUI_THIS(iface);
364 FIXME("(%p)->(%x)\n", This, fActivate);
365 return E_NOTIMPL;
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);
373 return E_NOTIMPL;
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);
381 return E_NOTIMPL;
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);
391 if(This->hostui)
392 return IDocHostUIHandler_GetOptionKeyPath(This->hostui, pchKey, dw);
394 return S_OK;
397 static HRESULT WINAPI DocHostUIHandler_GetDropTarget(IDocHostUIHandler2 *iface,
398 IDropTarget *pDropTarget, IDropTarget **ppDropTarget)
400 DocHost *This = DOCHOSTUI_THIS(iface);
401 FIXME("(%p)\n", This);
402 return E_NOTIMPL;
405 static HRESULT WINAPI DocHostUIHandler_GetExternal(IDocHostUIHandler2 *iface,
406 IDispatch **ppDispatch)
408 DocHost *This = DOCHOSTUI_THIS(iface);
409 FIXME("(%p)->(%p)\n", This, ppDispatch);
410 return E_NOTIMPL;
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);
420 if(This->hostui)
421 return IDocHostUIHandler_TranslateUrl(This->hostui, dwTranslate,
422 pchURLIn, ppchURLOut);
424 return S_FALSE;
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);
432 return E_NOTIMPL;
435 static HRESULT WINAPI DocHostUIHandler_GetOverrideKeyPath(IDocHostUIHandler2 *iface,
436 LPOLESTR *pchKey, DWORD dw)
438 DocHost *This = DOCHOSTUI_THIS(iface);
439 IDocHostUIHandler2 *handler;
440 HRESULT hres;
442 TRACE("(%p)->(%p %d)\n", This, pchKey, dw);
444 if(!This->hostui)
445 return S_OK;
447 hres = IDocHostUIHandler_QueryInterface(This->hostui, &IID_IDocHostUIHandler2,
448 (void**)&handler);
449 if(SUCCEEDED(hres)) {
450 hres = IDocHostUIHandler2_GetOverrideKeyPath(handler, pchKey, dw);
451 IDocHostUIHandler2_Release(handler);
452 return hres;
455 return S_OK;
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;
487 This->disp = disp;
489 This->client_disp = NULL;
491 This->document = NULL;
492 This->hostui = NULL;
493 This->frame = NULL;
495 This->hwnd = NULL;
496 This->frame_hwnd = NULL;
497 This->url = NULL;
499 This->navigate_call = FALSE;
500 This->silent = VARIANT_FALSE;
501 This->offline = VARIANT_FALSE;
503 DocHost_ClientSite_Init(This);
504 DocHost_Frame_Init(This);
506 ConnectionPointContainer_Init(&This->cps, (IUnknown*)disp);
509 void DocHost_Release(DocHost *This)
511 if(This->client_disp)
512 IDispatch_Release(This->client_disp);
513 if(This->frame)
514 IOleInPlaceFrame_Release(This->frame);
516 DocHost_ClientSite_Release(This);
518 ConnectionPointContainer_Destroy(&This->cps);
520 SysFreeString(This->url);