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"
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
)
32 /* FIXME: Don't use lParam */
34 SendMessageW(This
->frame_hwnd
, WM_DOCHOSTTASK
, 0, (LPARAM
)task
);
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
);
49 static void navigate_complete(DocHost
*This
)
51 IDispatch
*disp
= NULL
;
52 DISPPARAMS dispparams
;
57 hres
= IUnknown_QueryInterface(This
->document
, &IID_IDispatch
, (void**)&disp
);
59 FIXME("Could not get IDispatch interface\n");
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
;
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
));
80 IDispatch_Release(disp
);
83 void object_available(DocHost
*This
)
88 TRACE("(%p)\n", This
);
91 WARN("document == NULL\n");
95 hres
= IUnknown_QueryInterface(This
->document
, &IID_IHlinkTarget
, (void**)&hlink
);
97 FIXME("Could not get IHlinkTarget interface\n");
101 hres
= IHlinkTarget_Navigate(hlink
, 0, NULL
);
102 IHlinkTarget_Release(hlink
);
104 FIXME("Navigate failed\n");
108 navigate_complete(This
);
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
);
120 IOleDocumentView_SetRect(This
->view
, &rect
);
125 static LRESULT WINAPI
doc_view_proc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
129 static const WCHAR wszTHIS
[] = {'T','H','I','S',0};
131 if(msg
== WM_CREATE
) {
132 This
= *(DocHost
**)lParam
;
133 SetPropW(hwnd
, wszTHIS
, This
);
135 This
= GetPropW(hwnd
, wszTHIS
);
140 return resize_document(This
, LOWORD(lParam
), HIWORD(lParam
));
143 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
146 void create_doc_view_hwnd(DocHost
*This
)
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};
154 static WNDCLASSEXW wndclass
= {
158 0, 0 /* native uses 4*/, NULL
, NULL
, NULL
,
159 (HBRUSH
)COLOR_WINDOWFRAME
, NULL
,
160 wszShell_DocObject_View
,
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
;
185 IOleDocumentView_UIActivate(This
->view
, FALSE
);
187 hres
= IUnknown_QueryInterface(This
->document
, &IID_IOleInPlaceObjectWindowless
,
189 if(SUCCEEDED(hres
)) {
190 IOleInPlaceObjectWindowless_InPlaceDeactivate(winobj
);
191 IOleInPlaceObjectWindowless_Release(winobj
);
195 IOleDocumentView_Show(This
->view
, FALSE
);
196 IOleDocumentView_CloseView(This
->view
, 0);
197 IOleDocumentView_SetInPlaceSite(This
->view
, NULL
);
198 IOleDocumentView_Release(This
->view
);
202 hres
= IUnknown_QueryInterface(This
->document
, &IID_IOleObject
, (void**)&oleobj
);
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
);
213 IOleClientSite
*client_site
= NULL
;
215 IOleObject_GetClientSite(oleobj
, &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
,
259 static HRESULT WINAPI
ClOleCommandTarget_Exec(IOleCommandTarget
*iface
,
260 const GUID
*pguidCmdGroup
, DWORD nCmdID
, DWORD nCmdexecopt
, VARIANT
*pvaIn
,
263 DocHost
*This
= OLECMD_THIS(iface
);
264 FIXME("(%p)->(%s %d %d %p %p)\n", This
, debugstr_guid(pguidCmdGroup
), nCmdID
,
265 nCmdexecopt
, pvaIn
, pvaOut
);
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
);
306 TRACE("(%p)->(%d %p %p %p)\n", This
, dwID
, ppt
, pcmdtReserved
, pdispReserved
);
309 hres
= IDocHostUIHandler_ShowContextMenu(This
->hostui
, dwID
, ppt
, pcmdtReserved
,
315 FIXME("default action not implemented\n");
319 static HRESULT WINAPI
DocHostUIHandler_GetHostInfo(IDocHostUIHandler2
*iface
,
320 DOCHOSTUIINFO
*pInfo
)
322 DocHost
*This
= DOCHOSTUI_THIS(iface
);
325 TRACE("(%p)->(%p)\n", This
, pInfo
);
328 hres
= IDocHostUIHandler_GetHostInfo(This
->hostui
, pInfo
);
333 pInfo
->dwFlags
= DOCHOSTUIFLAG_DISABLE_HELP_MENU
| DOCHOSTUIFLAG_OPENNEWWIN
334 | DOCHOSTUIFLAG_URL_ENCODING_ENABLE_UTF8
| DOCHOSTUIFLAG_ENABLE_INPLACE_NAVIGATION
335 | DOCHOSTUIFLAG_IME_ENABLE_RECONVERSION
;
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
,
349 static HRESULT WINAPI
DocHostUIHandler_HideUI(IDocHostUIHandler2
*iface
)
351 DocHost
*This
= DOCHOSTUI_THIS(iface
);
352 FIXME("(%p)\n", This
);
356 static HRESULT WINAPI
DocHostUIHandler_UpdateUI(IDocHostUIHandler2
*iface
)
358 DocHost
*This
= DOCHOSTUI_THIS(iface
);
360 TRACE("(%p)\n", This
);
365 return IDocHostUIHandler_UpdateUI(This
->hostui
);
368 static HRESULT WINAPI
DocHostUIHandler_EnableModeless(IDocHostUIHandler2
*iface
,
371 DocHost
*This
= DOCHOSTUI_THIS(iface
);
372 FIXME("(%p)->(%x)\n", This
, fEnable
);
376 static HRESULT WINAPI
DocHostUIHandler_OnDocWindowActivate(IDocHostUIHandler2
*iface
,
379 DocHost
*This
= DOCHOSTUI_THIS(iface
);
380 FIXME("(%p)->(%x)\n", This
, fActivate
);
384 static HRESULT WINAPI
DocHostUIHandler_OnFrameWindowActivate(IDocHostUIHandler2
*iface
,
387 DocHost
*This
= DOCHOSTUI_THIS(iface
);
388 FIXME("(%p)->(%x)\n", This
, fActivate
);
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
);
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
);
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
);
416 return IDocHostUIHandler_GetOptionKeyPath(This
->hostui
, pchKey
, dw
);
421 static HRESULT WINAPI
DocHostUIHandler_GetDropTarget(IDocHostUIHandler2
*iface
,
422 IDropTarget
*pDropTarget
, IDropTarget
**ppDropTarget
)
424 DocHost
*This
= DOCHOSTUI_THIS(iface
);
425 FIXME("(%p)\n", This
);
429 static HRESULT WINAPI
DocHostUIHandler_GetExternal(IDocHostUIHandler2
*iface
,
430 IDispatch
**ppDispatch
)
432 DocHost
*This
= DOCHOSTUI_THIS(iface
);
434 TRACE("(%p)->(%p)\n", This
, ppDispatch
);
437 return IDocHostUIHandler_GetExternal(This
->hostui
, ppDispatch
);
439 FIXME("default action not implemented\n");
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
);
451 return IDocHostUIHandler_TranslateUrl(This
->hostui
, dwTranslate
,
452 pchURLIn
, ppchURLOut
);
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
);
465 static HRESULT WINAPI
DocHostUIHandler_GetOverrideKeyPath(IDocHostUIHandler2
*iface
,
466 LPOLESTR
*pchKey
, DWORD dw
)
468 DocHost
*This
= DOCHOSTUI_THIS(iface
);
469 IDocHostUIHandler2
*handler
;
472 TRACE("(%p)->(%p %d)\n", This
, pchKey
, dw
);
477 hres
= IDocHostUIHandler_QueryInterface(This
->hostui
, &IID_IDocHostUIHandler2
,
479 if(SUCCEEDED(hres
)) {
480 hres
= IDocHostUIHandler2_GetOverrideKeyPath(handler
, pchKey
, dw
);
481 IDocHostUIHandler2_Release(handler
);
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
;
519 This
->client_disp
= NULL
;
521 This
->document
= NULL
;
526 This
->frame_hwnd
= 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
);
543 IOleInPlaceFrame_Release(This
->frame
);
545 DocHost_ClientSite_Release(This
);
547 ConnectionPointContainer_Destroy(&This
->cps
);
549 SysFreeString(This
->url
);