kernel32: Immediately return on failing to start wineboot
[wine/wine64.git] / dlls / shdocvw / dochost.c
blobdd6e71265d7616434859fdbec6afc077332c7612
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 void push_dochost_task(DocHost *This, task_header_t *task, task_proc_t proc, BOOL send)
30 task->proc = proc;
32 /* FIXME: Don't use lParam */
33 if(send)
34 SendMessageW(This->frame_hwnd, WM_DOCHOSTTASK, 0, (LPARAM)task);
35 else
36 PostMessageW(This->frame_hwnd, WM_DOCHOSTTASK, 0, (LPARAM)task);
39 LRESULT process_dochost_task(DocHost *This, LPARAM lparam)
41 task_header_t *task = (task_header_t*)lparam;
43 task->proc(This, task);
45 heap_free(task);
46 return 0;
49 static void navigate_complete(DocHost *This)
51 DISPPARAMS dispparams;
52 VARIANTARG params[2];
53 VARIANT url;
55 dispparams.cArgs = 2;
56 dispparams.cNamedArgs = 0;
57 dispparams.rgdispidNamedArgs = NULL;
58 dispparams.rgvarg = params;
60 V_VT(params) = (VT_BYREF|VT_VARIANT);
61 V_BYREF(params) = &url;
63 V_VT(params+1) = VT_DISPATCH;
64 V_DISPATCH(params+1) = This->disp;
66 V_VT(&url) = VT_BSTR;
67 V_BSTR(&url) = SysAllocString(This->url);
69 call_sink(This->cps.wbe2, DISPID_NAVIGATECOMPLETE2, &dispparams);
70 call_sink(This->cps.wbe2, DISPID_DOCUMENTCOMPLETE, &dispparams);
72 SysFreeString(V_BSTR(&url));
73 This->busy = VARIANT_FALSE;
76 void object_available(DocHost *This)
78 IHlinkTarget *hlink;
79 HRESULT hres;
81 TRACE("(%p)\n", This);
83 if(!This->document) {
84 WARN("document == NULL\n");
85 return;
88 hres = IUnknown_QueryInterface(This->document, &IID_IHlinkTarget, (void**)&hlink);
89 if(FAILED(hres)) {
90 FIXME("Could not get IHlinkTarget interface\n");
91 return;
94 hres = IHlinkTarget_Navigate(hlink, 0, NULL);
95 IHlinkTarget_Release(hlink);
96 if(FAILED(hres)) {
97 FIXME("Navigate failed\n");
98 return;
101 navigate_complete(This);
103 return;
106 static LRESULT resize_document(DocHost *This, LONG width, LONG height)
108 RECT rect = {0, 0, width, height};
110 TRACE("(%p)->(%d %d)\n", This, width, height);
112 if(This->view)
113 IOleDocumentView_SetRect(This->view, &rect);
115 return 0;
118 static LRESULT WINAPI doc_view_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
120 DocHost *This;
122 static const WCHAR wszTHIS[] = {'T','H','I','S',0};
124 if(msg == WM_CREATE) {
125 This = *(DocHost**)lParam;
126 SetPropW(hwnd, wszTHIS, This);
127 }else {
128 This = GetPropW(hwnd, wszTHIS);
131 switch(msg) {
132 case WM_SIZE:
133 return resize_document(This, LOWORD(lParam), HIWORD(lParam));
136 return DefWindowProcW(hwnd, msg, wParam, lParam);
139 void create_doc_view_hwnd(DocHost *This)
141 RECT rect;
143 static const WCHAR wszShell_DocObject_View[] =
144 {'S','h','e','l','l',' ','D','o','c','O','b','j','e','c','t',' ','V','i','e','w',0};
146 if(!doc_view_atom) {
147 static WNDCLASSEXW wndclass = {
148 sizeof(wndclass),
149 CS_PARENTDC,
150 doc_view_proc,
151 0, 0 /* native uses 4*/, NULL, NULL, NULL,
152 (HBRUSH)(COLOR_WINDOW + 1), NULL,
153 wszShell_DocObject_View,
154 NULL
157 wndclass.hInstance = shdocvw_hinstance;
159 doc_view_atom = RegisterClassExW(&wndclass);
162 GetClientRect(This->frame_hwnd, &rect); /* FIXME */
163 This->hwnd = CreateWindowExW(0, wszShell_DocObject_View,
164 wszShell_DocObject_View,
165 WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_TABSTOP,
166 rect.left, rect.top, rect.right, rect.bottom, This->frame_hwnd,
167 NULL, shdocvw_hinstance, This);
170 void deactivate_document(DocHost *This)
172 IOleInPlaceObjectWindowless *winobj;
173 IOleObject *oleobj = NULL;
174 IHlinkTarget *hlink = NULL;
175 HRESULT hres;
177 if(This->view)
178 IOleDocumentView_UIActivate(This->view, FALSE);
180 hres = IUnknown_QueryInterface(This->document, &IID_IOleInPlaceObjectWindowless,
181 (void**)&winobj);
182 if(SUCCEEDED(hres)) {
183 IOleInPlaceObjectWindowless_InPlaceDeactivate(winobj);
184 IOleInPlaceObjectWindowless_Release(winobj);
187 if(This->view) {
188 IOleDocumentView_Show(This->view, FALSE);
189 IOleDocumentView_CloseView(This->view, 0);
190 IOleDocumentView_SetInPlaceSite(This->view, NULL);
191 IOleDocumentView_Release(This->view);
192 This->view = NULL;
195 hres = IUnknown_QueryInterface(This->document, &IID_IOleObject, (void**)&oleobj);
196 if(SUCCEEDED(hres))
197 IOleObject_Close(oleobj, OLECLOSE_NOSAVE);
199 hres = IUnknown_QueryInterface(This->document, &IID_IHlinkTarget, (void**)&hlink);
200 if(SUCCEEDED(hres)) {
201 IHlinkTarget_SetBrowseContext(hlink, NULL);
202 IHlinkTarget_Release(hlink);
205 if(oleobj) {
206 IOleClientSite *client_site = NULL;
208 IOleObject_GetClientSite(oleobj, &client_site);
209 if(client_site) {
210 if(client_site == CLIENTSITE(This))
211 IOleObject_SetClientSite(oleobj, NULL);
212 IOleClientSite_Release(client_site);
215 IOleObject_Release(oleobj);
218 IUnknown_Release(This->document);
219 This->document = NULL;
222 #define OLECMD_THIS(iface) DEFINE_THIS(DocHost, OleCommandTarget, iface)
224 static HRESULT WINAPI ClOleCommandTarget_QueryInterface(IOleCommandTarget *iface,
225 REFIID riid, void **ppv)
227 DocHost *This = OLECMD_THIS(iface);
228 return IOleClientSite_QueryInterface(CLIENTSITE(This), riid, ppv);
231 static ULONG WINAPI ClOleCommandTarget_AddRef(IOleCommandTarget *iface)
233 DocHost *This = OLECMD_THIS(iface);
234 return IOleClientSite_AddRef(CLIENTSITE(This));
237 static ULONG WINAPI ClOleCommandTarget_Release(IOleCommandTarget *iface)
239 DocHost *This = OLECMD_THIS(iface);
240 return IOleClientSite_Release(CLIENTSITE(This));
243 static HRESULT WINAPI ClOleCommandTarget_QueryStatus(IOleCommandTarget *iface,
244 const GUID *pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[], OLECMDTEXT *pCmdText)
246 DocHost *This = OLECMD_THIS(iface);
247 FIXME("(%p)->(%s %u %p %p)\n", This, debugstr_guid(pguidCmdGroup), cCmds, prgCmds,
248 pCmdText);
249 return E_NOTIMPL;
252 static HRESULT WINAPI ClOleCommandTarget_Exec(IOleCommandTarget *iface,
253 const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn,
254 VARIANT *pvaOut)
256 DocHost *This = OLECMD_THIS(iface);
257 FIXME("(%p)->(%s %d %d %p %p)\n", This, debugstr_guid(pguidCmdGroup), nCmdID,
258 nCmdexecopt, pvaIn, pvaOut);
259 return E_NOTIMPL;
262 #undef OLECMD_THIS
264 static const IOleCommandTargetVtbl OleCommandTargetVtbl = {
265 ClOleCommandTarget_QueryInterface,
266 ClOleCommandTarget_AddRef,
267 ClOleCommandTarget_Release,
268 ClOleCommandTarget_QueryStatus,
269 ClOleCommandTarget_Exec
272 #define DOCHOSTUI_THIS(iface) DEFINE_THIS(DocHost, DocHostUIHandler, iface)
274 static HRESULT WINAPI DocHostUIHandler_QueryInterface(IDocHostUIHandler2 *iface,
275 REFIID riid, void **ppv)
277 DocHost *This = DOCHOSTUI_THIS(iface);
278 return IOleClientSite_QueryInterface(CLIENTSITE(This), riid, ppv);
281 static ULONG WINAPI DocHostUIHandler_AddRef(IDocHostUIHandler2 *iface)
283 DocHost *This = DOCHOSTUI_THIS(iface);
284 return IOleClientSite_AddRef(CLIENTSITE(This));
287 static ULONG WINAPI DocHostUIHandler_Release(IDocHostUIHandler2 *iface)
289 DocHost *This = DOCHOSTUI_THIS(iface);
290 return IOleClientSite_Release(CLIENTSITE(This));
293 static HRESULT WINAPI DocHostUIHandler_ShowContextMenu(IDocHostUIHandler2 *iface,
294 DWORD dwID, POINT *ppt, IUnknown *pcmdtReserved, IDispatch *pdispReserved)
296 DocHost *This = DOCHOSTUI_THIS(iface);
297 HRESULT hres;
299 TRACE("(%p)->(%d %p %p %p)\n", This, dwID, ppt, pcmdtReserved, pdispReserved);
301 if(This->hostui) {
302 hres = IDocHostUIHandler_ShowContextMenu(This->hostui, dwID, ppt, pcmdtReserved,
303 pdispReserved);
304 if(hres == S_OK)
305 return S_OK;
308 FIXME("default action not implemented\n");
309 return E_NOTIMPL;
312 static HRESULT WINAPI DocHostUIHandler_GetHostInfo(IDocHostUIHandler2 *iface,
313 DOCHOSTUIINFO *pInfo)
315 DocHost *This = DOCHOSTUI_THIS(iface);
316 HRESULT hres;
318 TRACE("(%p)->(%p)\n", This, pInfo);
320 if(This->hostui) {
321 hres = IDocHostUIHandler_GetHostInfo(This->hostui, pInfo);
322 if(SUCCEEDED(hres))
323 return hres;
326 pInfo->dwFlags = DOCHOSTUIFLAG_DISABLE_HELP_MENU | DOCHOSTUIFLAG_OPENNEWWIN
327 | DOCHOSTUIFLAG_URL_ENCODING_ENABLE_UTF8 | DOCHOSTUIFLAG_ENABLE_INPLACE_NAVIGATION
328 | DOCHOSTUIFLAG_IME_ENABLE_RECONVERSION;
329 return S_OK;
332 static HRESULT WINAPI DocHostUIHandler_ShowUI(IDocHostUIHandler2 *iface, DWORD dwID,
333 IOleInPlaceActiveObject *pActiveObject, IOleCommandTarget *pCommandTarget,
334 IOleInPlaceFrame *pFrame, IOleInPlaceUIWindow *pDoc)
336 DocHost *This = DOCHOSTUI_THIS(iface);
337 FIXME("(%p)->(%d %p %p %p %p)\n", This, dwID, pActiveObject, pCommandTarget,
338 pFrame, pDoc);
339 return E_NOTIMPL;
342 static HRESULT WINAPI DocHostUIHandler_HideUI(IDocHostUIHandler2 *iface)
344 DocHost *This = DOCHOSTUI_THIS(iface);
345 FIXME("(%p)\n", This);
346 return E_NOTIMPL;
349 static HRESULT WINAPI DocHostUIHandler_UpdateUI(IDocHostUIHandler2 *iface)
351 DocHost *This = DOCHOSTUI_THIS(iface);
353 TRACE("(%p)\n", This);
355 if(!This->hostui)
356 return S_FALSE;
358 return IDocHostUIHandler_UpdateUI(This->hostui);
361 static HRESULT WINAPI DocHostUIHandler_EnableModeless(IDocHostUIHandler2 *iface,
362 BOOL fEnable)
364 DocHost *This = DOCHOSTUI_THIS(iface);
365 FIXME("(%p)->(%x)\n", This, fEnable);
366 return E_NOTIMPL;
369 static HRESULT WINAPI DocHostUIHandler_OnDocWindowActivate(IDocHostUIHandler2 *iface,
370 BOOL fActivate)
372 DocHost *This = DOCHOSTUI_THIS(iface);
373 FIXME("(%p)->(%x)\n", This, fActivate);
374 return E_NOTIMPL;
377 static HRESULT WINAPI DocHostUIHandler_OnFrameWindowActivate(IDocHostUIHandler2 *iface,
378 BOOL fActivate)
380 DocHost *This = DOCHOSTUI_THIS(iface);
381 FIXME("(%p)->(%x)\n", This, fActivate);
382 return E_NOTIMPL;
385 static HRESULT WINAPI DocHostUIHandler_ResizeBorder(IDocHostUIHandler2 *iface,
386 LPCRECT prcBorder, IOleInPlaceUIWindow *pUIWindow, BOOL fRameWindow)
388 DocHost *This = DOCHOSTUI_THIS(iface);
389 FIXME("(%p)->(%p %p %X)\n", This, prcBorder, pUIWindow, fRameWindow);
390 return E_NOTIMPL;
393 static HRESULT WINAPI DocHostUIHandler_TranslateAccelerator(IDocHostUIHandler2 *iface,
394 LPMSG lpMsg, const GUID *pguidCmdGroup, DWORD nCmdID)
396 DocHost *This = DOCHOSTUI_THIS(iface);
397 FIXME("(%p)->(%p %p %d)\n", This, lpMsg, pguidCmdGroup, nCmdID);
398 return E_NOTIMPL;
401 static HRESULT WINAPI DocHostUIHandler_GetOptionKeyPath(IDocHostUIHandler2 *iface,
402 LPOLESTR *pchKey, DWORD dw)
404 DocHost *This = DOCHOSTUI_THIS(iface);
406 TRACE("(%p)->(%p %d)\n", This, pchKey, dw);
408 if(This->hostui)
409 return IDocHostUIHandler_GetOptionKeyPath(This->hostui, pchKey, dw);
411 return S_OK;
414 static HRESULT WINAPI DocHostUIHandler_GetDropTarget(IDocHostUIHandler2 *iface,
415 IDropTarget *pDropTarget, IDropTarget **ppDropTarget)
417 DocHost *This = DOCHOSTUI_THIS(iface);
418 FIXME("(%p)\n", This);
419 return E_NOTIMPL;
422 static HRESULT WINAPI DocHostUIHandler_GetExternal(IDocHostUIHandler2 *iface,
423 IDispatch **ppDispatch)
425 DocHost *This = DOCHOSTUI_THIS(iface);
427 TRACE("(%p)->(%p)\n", This, ppDispatch);
429 if(This->hostui)
430 return IDocHostUIHandler_GetExternal(This->hostui, ppDispatch);
432 FIXME("default action not implemented\n");
433 return E_NOTIMPL;
436 static HRESULT WINAPI DocHostUIHandler_TranslateUrl(IDocHostUIHandler2 *iface,
437 DWORD dwTranslate, OLECHAR *pchURLIn, OLECHAR **ppchURLOut)
439 DocHost *This = DOCHOSTUI_THIS(iface);
441 TRACE("(%p)->(%d %s %p)\n", This, dwTranslate, debugstr_w(pchURLIn), ppchURLOut);
443 if(This->hostui)
444 return IDocHostUIHandler_TranslateUrl(This->hostui, dwTranslate,
445 pchURLIn, ppchURLOut);
447 return S_FALSE;
450 static HRESULT WINAPI DocHostUIHandler_FilterDataObject(IDocHostUIHandler2 *iface,
451 IDataObject *pDO, IDataObject **ppDORet)
453 DocHost *This = DOCHOSTUI_THIS(iface);
454 FIXME("(%p)->(%p %p)\n", This, pDO, ppDORet);
455 return E_NOTIMPL;
458 static HRESULT WINAPI DocHostUIHandler_GetOverrideKeyPath(IDocHostUIHandler2 *iface,
459 LPOLESTR *pchKey, DWORD dw)
461 DocHost *This = DOCHOSTUI_THIS(iface);
462 IDocHostUIHandler2 *handler;
463 HRESULT hres;
465 TRACE("(%p)->(%p %d)\n", This, pchKey, dw);
467 if(!This->hostui)
468 return S_OK;
470 hres = IDocHostUIHandler_QueryInterface(This->hostui, &IID_IDocHostUIHandler2,
471 (void**)&handler);
472 if(SUCCEEDED(hres)) {
473 hres = IDocHostUIHandler2_GetOverrideKeyPath(handler, pchKey, dw);
474 IDocHostUIHandler2_Release(handler);
475 return hres;
478 return S_OK;
481 #undef DOCHOSTUI_THIS
483 static const IDocHostUIHandler2Vtbl DocHostUIHandler2Vtbl = {
484 DocHostUIHandler_QueryInterface,
485 DocHostUIHandler_AddRef,
486 DocHostUIHandler_Release,
487 DocHostUIHandler_ShowContextMenu,
488 DocHostUIHandler_GetHostInfo,
489 DocHostUIHandler_ShowUI,
490 DocHostUIHandler_HideUI,
491 DocHostUIHandler_UpdateUI,
492 DocHostUIHandler_EnableModeless,
493 DocHostUIHandler_OnDocWindowActivate,
494 DocHostUIHandler_OnFrameWindowActivate,
495 DocHostUIHandler_ResizeBorder,
496 DocHostUIHandler_TranslateAccelerator,
497 DocHostUIHandler_GetOptionKeyPath,
498 DocHostUIHandler_GetDropTarget,
499 DocHostUIHandler_GetExternal,
500 DocHostUIHandler_TranslateUrl,
501 DocHostUIHandler_FilterDataObject,
502 DocHostUIHandler_GetOverrideKeyPath
505 void DocHost_Init(DocHost *This, IDispatch *disp)
507 This->lpDocHostUIHandlerVtbl = &DocHostUIHandler2Vtbl;
508 This->lpOleCommandTargetVtbl = &OleCommandTargetVtbl;
510 This->disp = disp;
512 This->client_disp = NULL;
514 This->document = NULL;
515 This->hostui = NULL;
516 This->frame = NULL;
518 This->hwnd = NULL;
519 This->frame_hwnd = NULL;
520 This->url = NULL;
522 This->silent = VARIANT_FALSE;
523 This->offline = VARIANT_FALSE;
525 DocHost_ClientSite_Init(This);
526 DocHost_Frame_Init(This);
528 ConnectionPointContainer_Init(&This->cps, (IUnknown*)disp);
531 void DocHost_Release(DocHost *This)
533 if(This->client_disp)
534 IDispatch_Release(This->client_disp);
535 if(This->frame)
536 IOleInPlaceFrame_Release(This->frame);
538 DocHost_ClientSite_Release(This);
540 ConnectionPointContainer_Destroy(&This->cps);
542 SysFreeString(This->url);