push b59ba84f7e04af9ef068bd4c6e96701941f0256e
[wine/hacks.git] / dlls / shdocvw / dochost.c
blobc3a22f461dffd95115b294859ea7f79361b2db8b
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 IDispatch *disp = NULL;
52 DISPPARAMS dispparams;
53 VARIANTARG params[2];
54 VARIANT url;
55 HRESULT hres;
57 hres = IUnknown_QueryInterface(This->document, &IID_IDispatch, (void**)&disp);
58 if(FAILED(hres))
59 FIXME("Could not get IDispatch interface\n");
61 dispparams.cArgs = 2;
62 dispparams.cNamedArgs = 0;
63 dispparams.rgdispidNamedArgs = NULL;
64 dispparams.rgvarg = params;
66 V_VT(params) = (VT_BYREF|VT_VARIANT);
67 V_BYREF(params) = &url;
69 V_VT(params+1) = VT_DISPATCH;
70 V_DISPATCH(params+1) = disp;
72 V_VT(&url) = VT_BSTR;
73 V_BSTR(&url) = SysAllocString(This->url);
75 call_sink(This->cps.wbe2, DISPID_NAVIGATECOMPLETE2, &dispparams);
76 call_sink(This->cps.wbe2, DISPID_DOCUMENTCOMPLETE, &dispparams);
78 SysFreeString(V_BSTR(&url));
79 if(disp)
80 IDispatch_Release(disp);
83 void object_available(DocHost *This)
85 IHlinkTarget *hlink;
86 HRESULT hres;
88 TRACE("(%p)\n", This);
90 if(!This->document) {
91 WARN("document == NULL\n");
92 return;
95 hres = IUnknown_QueryInterface(This->document, &IID_IHlinkTarget, (void**)&hlink);
96 if(FAILED(hres)) {
97 FIXME("Could not get IHlinkTarget interface\n");
98 return;
101 hres = IHlinkTarget_Navigate(hlink, 0, NULL);
102 IHlinkTarget_Release(hlink);
103 if(FAILED(hres)) {
104 FIXME("Navigate failed\n");
105 return;
108 navigate_complete(This);
110 return;
113 static LRESULT resize_document(DocHost *This, LONG width, LONG height)
115 RECT rect = {0, 0, width, height};
117 TRACE("(%p)->(%d %d)\n", This, width, height);
119 if(This->view)
120 IOleDocumentView_SetRect(This->view, &rect);
122 return 0;
125 static LRESULT WINAPI doc_view_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
127 DocHost *This;
129 static const WCHAR wszTHIS[] = {'T','H','I','S',0};
131 if(msg == WM_CREATE) {
132 This = *(DocHost**)lParam;
133 SetPropW(hwnd, wszTHIS, This);
134 }else {
135 This = GetPropW(hwnd, wszTHIS);
138 switch(msg) {
139 case WM_SIZE:
140 return resize_document(This, LOWORD(lParam), HIWORD(lParam));
143 return DefWindowProcW(hwnd, msg, wParam, lParam);
146 void create_doc_view_hwnd(DocHost *This)
148 RECT rect;
150 static const WCHAR wszShell_DocObject_View[] =
151 {'S','h','e','l','l',' ','D','o','c','O','b','j','e','c','t',' ','V','i','e','w',0};
153 if(!doc_view_atom) {
154 static WNDCLASSEXW wndclass = {
155 sizeof(wndclass),
156 CS_PARENTDC,
157 doc_view_proc,
158 0, 0 /* native uses 4*/, NULL, NULL, NULL,
159 (HBRUSH)COLOR_WINDOWFRAME, NULL,
160 wszShell_DocObject_View,
161 NULL
164 wndclass.hInstance = shdocvw_hinstance;
166 doc_view_atom = RegisterClassExW(&wndclass);
169 GetClientRect(This->frame_hwnd, &rect); /* FIXME */
170 This->hwnd = CreateWindowExW(0, wszShell_DocObject_View,
171 wszShell_DocObject_View,
172 WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_TABSTOP,
173 rect.left, rect.top, rect.right, rect.bottom, This->frame_hwnd,
174 NULL, shdocvw_hinstance, This);
177 void deactivate_document(DocHost *This)
179 IOleInPlaceObjectWindowless *winobj;
180 IOleObject *oleobj = NULL;
181 IHlinkTarget *hlink = NULL;
182 HRESULT hres;
184 if(This->view)
185 IOleDocumentView_UIActivate(This->view, FALSE);
187 hres = IUnknown_QueryInterface(This->document, &IID_IOleInPlaceObjectWindowless,
188 (void**)&winobj);
189 if(SUCCEEDED(hres)) {
190 IOleInPlaceObjectWindowless_InPlaceDeactivate(winobj);
191 IOleInPlaceObjectWindowless_Release(winobj);
194 if(This->view) {
195 IOleDocumentView_Show(This->view, FALSE);
196 IOleDocumentView_CloseView(This->view, 0);
197 IOleDocumentView_SetInPlaceSite(This->view, NULL);
198 IOleDocumentView_Release(This->view);
199 This->view = NULL;
202 hres = IUnknown_QueryInterface(This->document, &IID_IOleObject, (void**)&oleobj);
203 if(SUCCEEDED(hres))
204 IOleObject_Close(oleobj, OLECLOSE_NOSAVE);
206 hres = IUnknown_QueryInterface(This->document, &IID_IHlinkTarget, (void**)&hlink);
207 if(SUCCEEDED(hres)) {
208 IHlinkTarget_SetBrowseContext(hlink, NULL);
209 IHlinkTarget_Release(hlink);
212 if(oleobj) {
213 IOleClientSite *client_site = NULL;
215 IOleObject_GetClientSite(oleobj, &client_site);
216 if(client_site) {
217 if(client_site == CLIENTSITE(This))
218 IOleObject_SetClientSite(oleobj, NULL);
219 IOleClientSite_Release(client_site);
222 IOleObject_Release(oleobj);
225 IUnknown_Release(This->document);
226 This->document = NULL;
229 #define OLECMD_THIS(iface) DEFINE_THIS(DocHost, OleCommandTarget, iface)
231 static HRESULT WINAPI ClOleCommandTarget_QueryInterface(IOleCommandTarget *iface,
232 REFIID riid, void **ppv)
234 DocHost *This = OLECMD_THIS(iface);
235 return IOleClientSite_QueryInterface(CLIENTSITE(This), riid, ppv);
238 static ULONG WINAPI ClOleCommandTarget_AddRef(IOleCommandTarget *iface)
240 DocHost *This = OLECMD_THIS(iface);
241 return IOleClientSite_AddRef(CLIENTSITE(This));
244 static ULONG WINAPI ClOleCommandTarget_Release(IOleCommandTarget *iface)
246 DocHost *This = OLECMD_THIS(iface);
247 return IOleClientSite_Release(CLIENTSITE(This));
250 static HRESULT WINAPI ClOleCommandTarget_QueryStatus(IOleCommandTarget *iface,
251 const GUID *pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[], OLECMDTEXT *pCmdText)
253 DocHost *This = OLECMD_THIS(iface);
254 FIXME("(%p)->(%s %u %p %p)\n", This, debugstr_guid(pguidCmdGroup), cCmds, prgCmds,
255 pCmdText);
256 return E_NOTIMPL;
259 static HRESULT WINAPI ClOleCommandTarget_Exec(IOleCommandTarget *iface,
260 const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn,
261 VARIANT *pvaOut)
263 DocHost *This = OLECMD_THIS(iface);
264 FIXME("(%p)->(%s %d %d %p %p)\n", This, debugstr_guid(pguidCmdGroup), nCmdID,
265 nCmdexecopt, pvaIn, pvaOut);
266 return E_NOTIMPL;
269 #undef OLECMD_THIS
271 static const IOleCommandTargetVtbl OleCommandTargetVtbl = {
272 ClOleCommandTarget_QueryInterface,
273 ClOleCommandTarget_AddRef,
274 ClOleCommandTarget_Release,
275 ClOleCommandTarget_QueryStatus,
276 ClOleCommandTarget_Exec
279 #define DOCHOSTUI_THIS(iface) DEFINE_THIS(DocHost, DocHostUIHandler, iface)
281 static HRESULT WINAPI DocHostUIHandler_QueryInterface(IDocHostUIHandler2 *iface,
282 REFIID riid, void **ppv)
284 DocHost *This = DOCHOSTUI_THIS(iface);
285 return IOleClientSite_QueryInterface(CLIENTSITE(This), riid, ppv);
288 static ULONG WINAPI DocHostUIHandler_AddRef(IDocHostUIHandler2 *iface)
290 DocHost *This = DOCHOSTUI_THIS(iface);
291 return IOleClientSite_AddRef(CLIENTSITE(This));
294 static ULONG WINAPI DocHostUIHandler_Release(IDocHostUIHandler2 *iface)
296 DocHost *This = DOCHOSTUI_THIS(iface);
297 return IOleClientSite_Release(CLIENTSITE(This));
300 static HRESULT WINAPI DocHostUIHandler_ShowContextMenu(IDocHostUIHandler2 *iface,
301 DWORD dwID, POINT *ppt, IUnknown *pcmdtReserved, IDispatch *pdispReserved)
303 DocHost *This = DOCHOSTUI_THIS(iface);
304 HRESULT hres;
306 TRACE("(%p)->(%d %p %p %p)\n", This, dwID, ppt, pcmdtReserved, pdispReserved);
308 if(This->hostui) {
309 hres = IDocHostUIHandler_ShowContextMenu(This->hostui, dwID, ppt, pcmdtReserved,
310 pdispReserved);
311 if(hres == S_OK)
312 return S_OK;
315 FIXME("default action not implemented\n");
316 return E_NOTIMPL;
319 static HRESULT WINAPI DocHostUIHandler_GetHostInfo(IDocHostUIHandler2 *iface,
320 DOCHOSTUIINFO *pInfo)
322 DocHost *This = DOCHOSTUI_THIS(iface);
323 HRESULT hres;
325 TRACE("(%p)->(%p)\n", This, pInfo);
327 if(This->hostui) {
328 hres = IDocHostUIHandler_GetHostInfo(This->hostui, pInfo);
329 if(SUCCEEDED(hres))
330 return hres;
333 pInfo->dwFlags = DOCHOSTUIFLAG_DISABLE_HELP_MENU | DOCHOSTUIFLAG_OPENNEWWIN
334 | DOCHOSTUIFLAG_URL_ENCODING_ENABLE_UTF8 | DOCHOSTUIFLAG_ENABLE_INPLACE_NAVIGATION
335 | DOCHOSTUIFLAG_IME_ENABLE_RECONVERSION;
336 return S_OK;
339 static HRESULT WINAPI DocHostUIHandler_ShowUI(IDocHostUIHandler2 *iface, DWORD dwID,
340 IOleInPlaceActiveObject *pActiveObject, IOleCommandTarget *pCommandTarget,
341 IOleInPlaceFrame *pFrame, IOleInPlaceUIWindow *pDoc)
343 DocHost *This = DOCHOSTUI_THIS(iface);
344 FIXME("(%p)->(%d %p %p %p %p)\n", This, dwID, pActiveObject, pCommandTarget,
345 pFrame, pDoc);
346 return E_NOTIMPL;
349 static HRESULT WINAPI DocHostUIHandler_HideUI(IDocHostUIHandler2 *iface)
351 DocHost *This = DOCHOSTUI_THIS(iface);
352 FIXME("(%p)\n", This);
353 return E_NOTIMPL;
356 static HRESULT WINAPI DocHostUIHandler_UpdateUI(IDocHostUIHandler2 *iface)
358 DocHost *This = DOCHOSTUI_THIS(iface);
360 TRACE("(%p)\n", This);
362 if(!This->hostui)
363 return S_FALSE;
365 return IDocHostUIHandler_UpdateUI(This->hostui);
368 static HRESULT WINAPI DocHostUIHandler_EnableModeless(IDocHostUIHandler2 *iface,
369 BOOL fEnable)
371 DocHost *This = DOCHOSTUI_THIS(iface);
372 FIXME("(%p)->(%x)\n", This, fEnable);
373 return E_NOTIMPL;
376 static HRESULT WINAPI DocHostUIHandler_OnDocWindowActivate(IDocHostUIHandler2 *iface,
377 BOOL fActivate)
379 DocHost *This = DOCHOSTUI_THIS(iface);
380 FIXME("(%p)->(%x)\n", This, fActivate);
381 return E_NOTIMPL;
384 static HRESULT WINAPI DocHostUIHandler_OnFrameWindowActivate(IDocHostUIHandler2 *iface,
385 BOOL fActivate)
387 DocHost *This = DOCHOSTUI_THIS(iface);
388 FIXME("(%p)->(%x)\n", This, fActivate);
389 return E_NOTIMPL;
392 static HRESULT WINAPI DocHostUIHandler_ResizeBorder(IDocHostUIHandler2 *iface,
393 LPCRECT prcBorder, IOleInPlaceUIWindow *pUIWindow, BOOL fRameWindow)
395 DocHost *This = DOCHOSTUI_THIS(iface);
396 FIXME("(%p)->(%p %p %X)\n", This, prcBorder, pUIWindow, fRameWindow);
397 return E_NOTIMPL;
400 static HRESULT WINAPI DocHostUIHandler_TranslateAccelerator(IDocHostUIHandler2 *iface,
401 LPMSG lpMsg, const GUID *pguidCmdGroup, DWORD nCmdID)
403 DocHost *This = DOCHOSTUI_THIS(iface);
404 FIXME("(%p)->(%p %p %d)\n", This, lpMsg, pguidCmdGroup, nCmdID);
405 return E_NOTIMPL;
408 static HRESULT WINAPI DocHostUIHandler_GetOptionKeyPath(IDocHostUIHandler2 *iface,
409 LPOLESTR *pchKey, DWORD dw)
411 DocHost *This = DOCHOSTUI_THIS(iface);
413 TRACE("(%p)->(%p %d)\n", This, pchKey, dw);
415 if(This->hostui)
416 return IDocHostUIHandler_GetOptionKeyPath(This->hostui, pchKey, dw);
418 return S_OK;
421 static HRESULT WINAPI DocHostUIHandler_GetDropTarget(IDocHostUIHandler2 *iface,
422 IDropTarget *pDropTarget, IDropTarget **ppDropTarget)
424 DocHost *This = DOCHOSTUI_THIS(iface);
425 FIXME("(%p)\n", This);
426 return E_NOTIMPL;
429 static HRESULT WINAPI DocHostUIHandler_GetExternal(IDocHostUIHandler2 *iface,
430 IDispatch **ppDispatch)
432 DocHost *This = DOCHOSTUI_THIS(iface);
434 TRACE("(%p)->(%p)\n", This, ppDispatch);
436 if(This->hostui)
437 return IDocHostUIHandler_GetExternal(This->hostui, ppDispatch);
439 FIXME("default action not implemented\n");
440 return E_NOTIMPL;
443 static HRESULT WINAPI DocHostUIHandler_TranslateUrl(IDocHostUIHandler2 *iface,
444 DWORD dwTranslate, OLECHAR *pchURLIn, OLECHAR **ppchURLOut)
446 DocHost *This = DOCHOSTUI_THIS(iface);
448 TRACE("(%p)->(%d %s %p)\n", This, dwTranslate, debugstr_w(pchURLIn), ppchURLOut);
450 if(This->hostui)
451 return IDocHostUIHandler_TranslateUrl(This->hostui, dwTranslate,
452 pchURLIn, ppchURLOut);
454 return S_FALSE;
457 static HRESULT WINAPI DocHostUIHandler_FilterDataObject(IDocHostUIHandler2 *iface,
458 IDataObject *pDO, IDataObject **ppDORet)
460 DocHost *This = DOCHOSTUI_THIS(iface);
461 FIXME("(%p)->(%p %p)\n", This, pDO, ppDORet);
462 return E_NOTIMPL;
465 static HRESULT WINAPI DocHostUIHandler_GetOverrideKeyPath(IDocHostUIHandler2 *iface,
466 LPOLESTR *pchKey, DWORD dw)
468 DocHost *This = DOCHOSTUI_THIS(iface);
469 IDocHostUIHandler2 *handler;
470 HRESULT hres;
472 TRACE("(%p)->(%p %d)\n", This, pchKey, dw);
474 if(!This->hostui)
475 return S_OK;
477 hres = IDocHostUIHandler_QueryInterface(This->hostui, &IID_IDocHostUIHandler2,
478 (void**)&handler);
479 if(SUCCEEDED(hres)) {
480 hres = IDocHostUIHandler2_GetOverrideKeyPath(handler, pchKey, dw);
481 IDocHostUIHandler2_Release(handler);
482 return hres;
485 return S_OK;
488 #undef DOCHOSTUI_THIS
490 static const IDocHostUIHandler2Vtbl DocHostUIHandler2Vtbl = {
491 DocHostUIHandler_QueryInterface,
492 DocHostUIHandler_AddRef,
493 DocHostUIHandler_Release,
494 DocHostUIHandler_ShowContextMenu,
495 DocHostUIHandler_GetHostInfo,
496 DocHostUIHandler_ShowUI,
497 DocHostUIHandler_HideUI,
498 DocHostUIHandler_UpdateUI,
499 DocHostUIHandler_EnableModeless,
500 DocHostUIHandler_OnDocWindowActivate,
501 DocHostUIHandler_OnFrameWindowActivate,
502 DocHostUIHandler_ResizeBorder,
503 DocHostUIHandler_TranslateAccelerator,
504 DocHostUIHandler_GetOptionKeyPath,
505 DocHostUIHandler_GetDropTarget,
506 DocHostUIHandler_GetExternal,
507 DocHostUIHandler_TranslateUrl,
508 DocHostUIHandler_FilterDataObject,
509 DocHostUIHandler_GetOverrideKeyPath
512 void DocHost_Init(DocHost *This, IDispatch *disp)
514 This->lpDocHostUIHandlerVtbl = &DocHostUIHandler2Vtbl;
515 This->lpOleCommandTargetVtbl = &OleCommandTargetVtbl;
517 This->disp = disp;
519 This->client_disp = NULL;
521 This->document = NULL;
522 This->hostui = NULL;
523 This->frame = NULL;
525 This->hwnd = NULL;
526 This->frame_hwnd = NULL;
527 This->url = NULL;
529 This->silent = VARIANT_FALSE;
530 This->offline = VARIANT_FALSE;
532 DocHost_ClientSite_Init(This);
533 DocHost_Frame_Init(This);
535 ConnectionPointContainer_Init(&This->cps, (IUnknown*)disp);
538 void DocHost_Release(DocHost *This)
540 if(This->client_disp)
541 IDispatch_Release(This->client_disp);
542 if(This->frame)
543 IOleInPlaceFrame_Release(This->frame);
545 DocHost_ClientSite_Release(This);
547 ConnectionPointContainer_Destroy(&This->cps);
549 SysFreeString(This->url);