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 DISPPARAMS dispparams
;
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
;
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
)
81 TRACE("(%p)\n", This
);
84 WARN("document == NULL\n");
88 hres
= IUnknown_QueryInterface(This
->document
, &IID_IHlinkTarget
, (void**)&hlink
);
90 FIXME("Could not get IHlinkTarget interface\n");
94 hres
= IHlinkTarget_Navigate(hlink
, 0, NULL
);
95 IHlinkTarget_Release(hlink
);
97 FIXME("Navigate failed\n");
101 navigate_complete(This
);
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
);
113 IOleDocumentView_SetRect(This
->view
, &rect
);
118 static LRESULT WINAPI
doc_view_proc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
122 static const WCHAR wszTHIS
[] = {'T','H','I','S',0};
124 if(msg
== WM_CREATE
) {
125 This
= *(DocHost
**)lParam
;
126 SetPropW(hwnd
, wszTHIS
, This
);
128 This
= GetPropW(hwnd
, wszTHIS
);
133 return resize_document(This
, LOWORD(lParam
), HIWORD(lParam
));
136 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
139 void create_doc_view_hwnd(DocHost
*This
)
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};
147 static WNDCLASSEXW wndclass
= {
151 0, 0 /* native uses 4*/, NULL
, NULL
, NULL
,
152 (HBRUSH
)(COLOR_WINDOW
+ 1), NULL
,
153 wszShell_DocObject_View
,
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
;
178 IOleDocumentView_UIActivate(This
->view
, FALSE
);
180 hres
= IUnknown_QueryInterface(This
->document
, &IID_IOleInPlaceObjectWindowless
,
182 if(SUCCEEDED(hres
)) {
183 IOleInPlaceObjectWindowless_InPlaceDeactivate(winobj
);
184 IOleInPlaceObjectWindowless_Release(winobj
);
188 IOleDocumentView_Show(This
->view
, FALSE
);
189 IOleDocumentView_CloseView(This
->view
, 0);
190 IOleDocumentView_SetInPlaceSite(This
->view
, NULL
);
191 IOleDocumentView_Release(This
->view
);
195 hres
= IUnknown_QueryInterface(This
->document
, &IID_IOleObject
, (void**)&oleobj
);
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
);
206 IOleClientSite
*client_site
= NULL
;
208 IOleObject_GetClientSite(oleobj
, &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
,
252 static HRESULT WINAPI
ClOleCommandTarget_Exec(IOleCommandTarget
*iface
,
253 const GUID
*pguidCmdGroup
, DWORD nCmdID
, DWORD nCmdexecopt
, VARIANT
*pvaIn
,
256 DocHost
*This
= OLECMD_THIS(iface
);
257 FIXME("(%p)->(%s %d %d %p %p)\n", This
, debugstr_guid(pguidCmdGroup
), nCmdID
,
258 nCmdexecopt
, pvaIn
, pvaOut
);
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
);
299 TRACE("(%p)->(%d %p %p %p)\n", This
, dwID
, ppt
, pcmdtReserved
, pdispReserved
);
302 hres
= IDocHostUIHandler_ShowContextMenu(This
->hostui
, dwID
, ppt
, pcmdtReserved
,
308 FIXME("default action not implemented\n");
312 static HRESULT WINAPI
DocHostUIHandler_GetHostInfo(IDocHostUIHandler2
*iface
,
313 DOCHOSTUIINFO
*pInfo
)
315 DocHost
*This
= DOCHOSTUI_THIS(iface
);
318 TRACE("(%p)->(%p)\n", This
, pInfo
);
321 hres
= IDocHostUIHandler_GetHostInfo(This
->hostui
, pInfo
);
326 pInfo
->dwFlags
= DOCHOSTUIFLAG_DISABLE_HELP_MENU
| DOCHOSTUIFLAG_OPENNEWWIN
327 | DOCHOSTUIFLAG_URL_ENCODING_ENABLE_UTF8
| DOCHOSTUIFLAG_ENABLE_INPLACE_NAVIGATION
328 | DOCHOSTUIFLAG_IME_ENABLE_RECONVERSION
;
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
,
342 static HRESULT WINAPI
DocHostUIHandler_HideUI(IDocHostUIHandler2
*iface
)
344 DocHost
*This
= DOCHOSTUI_THIS(iface
);
345 FIXME("(%p)\n", This
);
349 static HRESULT WINAPI
DocHostUIHandler_UpdateUI(IDocHostUIHandler2
*iface
)
351 DocHost
*This
= DOCHOSTUI_THIS(iface
);
353 TRACE("(%p)\n", This
);
358 return IDocHostUIHandler_UpdateUI(This
->hostui
);
361 static HRESULT WINAPI
DocHostUIHandler_EnableModeless(IDocHostUIHandler2
*iface
,
364 DocHost
*This
= DOCHOSTUI_THIS(iface
);
365 FIXME("(%p)->(%x)\n", This
, fEnable
);
369 static HRESULT WINAPI
DocHostUIHandler_OnDocWindowActivate(IDocHostUIHandler2
*iface
,
372 DocHost
*This
= DOCHOSTUI_THIS(iface
);
373 FIXME("(%p)->(%x)\n", This
, fActivate
);
377 static HRESULT WINAPI
DocHostUIHandler_OnFrameWindowActivate(IDocHostUIHandler2
*iface
,
380 DocHost
*This
= DOCHOSTUI_THIS(iface
);
381 FIXME("(%p)->(%x)\n", This
, fActivate
);
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
);
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
);
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
);
409 return IDocHostUIHandler_GetOptionKeyPath(This
->hostui
, pchKey
, dw
);
414 static HRESULT WINAPI
DocHostUIHandler_GetDropTarget(IDocHostUIHandler2
*iface
,
415 IDropTarget
*pDropTarget
, IDropTarget
**ppDropTarget
)
417 DocHost
*This
= DOCHOSTUI_THIS(iface
);
418 FIXME("(%p)\n", This
);
422 static HRESULT WINAPI
DocHostUIHandler_GetExternal(IDocHostUIHandler2
*iface
,
423 IDispatch
**ppDispatch
)
425 DocHost
*This
= DOCHOSTUI_THIS(iface
);
427 TRACE("(%p)->(%p)\n", This
, ppDispatch
);
430 return IDocHostUIHandler_GetExternal(This
->hostui
, ppDispatch
);
432 FIXME("default action not implemented\n");
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
);
444 return IDocHostUIHandler_TranslateUrl(This
->hostui
, dwTranslate
,
445 pchURLIn
, ppchURLOut
);
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
);
458 static HRESULT WINAPI
DocHostUIHandler_GetOverrideKeyPath(IDocHostUIHandler2
*iface
,
459 LPOLESTR
*pchKey
, DWORD dw
)
461 DocHost
*This
= DOCHOSTUI_THIS(iface
);
462 IDocHostUIHandler2
*handler
;
465 TRACE("(%p)->(%p %d)\n", This
, pchKey
, dw
);
470 hres
= IDocHostUIHandler_QueryInterface(This
->hostui
, &IID_IDocHostUIHandler2
,
472 if(SUCCEEDED(hres
)) {
473 hres
= IDocHostUIHandler2_GetOverrideKeyPath(handler
, pchKey
, dw
);
474 IDocHostUIHandler2_Release(handler
);
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
;
512 This
->client_disp
= NULL
;
514 This
->document
= NULL
;
519 This
->frame_hwnd
= 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
);
536 IOleInPlaceFrame_Release(This
->frame
);
538 DocHost_ClientSite_Release(This
);
540 ConnectionPointContainer_Destroy(&This
->cps
);
542 SysFreeString(This
->url
);