progman: Add close button and sysmenu to dialogs.
[wine/gsoc_dplay.git] / dlls / shdocvw / dochost.c
blob7335f53b327606b47b1ae04ce1addd822e46fe07
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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) = This->url;
54 call_sink(This->cp_wbe2, DISPID_NAVIGATECOMPLETE2, &dispparams);
55 call_sink(This->cp_wbe2, DISPID_DOCUMENTCOMPLETE, &dispparams);
57 if(disp)
58 IDispatch_Release(disp);
61 static LRESULT navigate2(DocHost *This)
63 IHlinkTarget *hlink;
64 HRESULT hres;
66 TRACE("(%p)\n", This);
68 if(!This->document) {
69 WARN("document == NULL\n");
70 return 0;
73 hres = IUnknown_QueryInterface(This->document, &IID_IHlinkTarget, (void**)&hlink);
74 if(FAILED(hres)) {
75 FIXME("Could not get IHlinkTarget interface\n");
76 return 0;
79 hres = IHlinkTarget_Navigate(hlink, 0, NULL);
80 IHlinkTarget_Release(hlink);
81 if(FAILED(hres)) {
82 FIXME("Navigate failed\n");
83 return 0;
86 navigate_complete(This);
88 return 0;
91 static LRESULT resize_document(DocHost *This, LONG width, LONG height)
93 RECT rect = {0, 0, width, height};
95 TRACE("(%p)->(%ld %ld)\n", This, width, height);
97 if(This->view)
98 IOleDocumentView_SetRect(This->view, &rect);
100 return 0;
103 static LRESULT WINAPI doc_view_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
105 DocHost *This;
107 static const WCHAR wszTHIS[] = {'T','H','I','S',0};
109 if(msg == WM_CREATE) {
110 This = *(DocHost**)lParam;
111 SetPropW(hwnd, wszTHIS, This);
112 }else {
113 This = GetPropW(hwnd, wszTHIS);
116 switch(msg) {
117 case WM_SIZE:
118 return resize_document(This, LOWORD(lParam), HIWORD(lParam));
119 case WB_WM_NAVIGATE2:
120 return navigate2(This);
123 return DefWindowProcW(hwnd, msg, wParam, lParam);
126 void create_doc_view_hwnd(DocHost *This)
128 RECT rect;
130 static const WCHAR wszShell_DocObject_View[] =
131 {'S','h','e','l','l',' ','D','o','c','O','b','j','e','c','t',' ','V','i','e','w',0};
133 if(!doc_view_atom) {
134 static WNDCLASSEXW wndclass = {
135 sizeof(wndclass),
136 CS_PARENTDC,
137 doc_view_proc,
138 0, 0 /* native uses 4*/, NULL, NULL, NULL,
139 (HBRUSH)COLOR_WINDOWFRAME, NULL,
140 wszShell_DocObject_View,
141 NULL
144 wndclass.hInstance = shdocvw_hinstance;
146 doc_view_atom = RegisterClassExW(&wndclass);
149 GetClientRect(This->frame_hwnd, &rect); /* FIXME */
150 This->hwnd = CreateWindowExW(0, wszShell_DocObject_View,
151 wszShell_DocObject_View,
152 WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_TABSTOP,
153 rect.left, rect.top, rect.right, rect.bottom, This->frame_hwnd,
154 NULL, shdocvw_hinstance, This);
157 void deactivate_document(DocHost *This)
159 IOleInPlaceObjectWindowless *winobj;
160 IOleObject *oleobj = NULL;
161 IHlinkTarget *hlink = NULL;
162 HRESULT hres;
164 if(This->view)
165 IOleDocumentView_UIActivate(This->view, FALSE);
167 hres = IUnknown_QueryInterface(This->document, &IID_IOleInPlaceObjectWindowless,
168 (void**)&winobj);
169 if(SUCCEEDED(hres)) {
170 IOleInPlaceObjectWindowless_InPlaceDeactivate(winobj);
171 IOleInPlaceObjectWindowless_Release(winobj);
174 if(This->view) {
175 IOleDocumentView_Show(This->view, FALSE);
176 IOleDocumentView_CloseView(This->view, 0);
177 IOleDocumentView_SetInPlaceSite(This->view, NULL);
178 IOleDocumentView_Release(This->view);
179 This->view = NULL;
182 hres = IUnknown_QueryInterface(This->document, &IID_IOleObject, (void**)&oleobj);
183 if(SUCCEEDED(hres))
184 IOleObject_Close(oleobj, OLECLOSE_NOSAVE);
186 hres = IUnknown_QueryInterface(This->document, &IID_IHlinkTarget, (void**)&hlink);
187 if(SUCCEEDED(hres)) {
188 IHlinkTarget_SetBrowseContext(hlink, NULL);
189 IHlinkTarget_Release(hlink);
192 if(oleobj) {
193 IOleClientSite *client_site = NULL;
195 IOleObject_GetClientSite(oleobj, &client_site);
196 if(client_site) {
197 if(client_site == CLIENTSITE(This))
198 IOleObject_SetClientSite(oleobj, NULL);
199 IOleClientSite_Release(client_site);
202 IOleObject_Release(oleobj);
205 IUnknown_Release(This->document);
206 This->document = NULL;
209 #define OLECMD_THIS(iface) DEFINE_THIS(DocHost, OleCommandTarget, iface)
211 static HRESULT WINAPI ClOleCommandTarget_QueryInterface(IOleCommandTarget *iface,
212 REFIID riid, void **ppv)
214 DocHost *This = OLECMD_THIS(iface);
215 return IOleClientSite_QueryInterface(CLIENTSITE(This), riid, ppv);
218 static ULONG WINAPI ClOleCommandTarget_AddRef(IOleCommandTarget *iface)
220 DocHost *This = OLECMD_THIS(iface);
221 return IOleClientSite_AddRef(CLIENTSITE(This));
224 static ULONG WINAPI ClOleCommandTarget_Release(IOleCommandTarget *iface)
226 DocHost *This = OLECMD_THIS(iface);
227 return IOleClientSite_Release(CLIENTSITE(This));
230 static HRESULT WINAPI ClOleCommandTarget_QueryStatus(IOleCommandTarget *iface,
231 const GUID *pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[], OLECMDTEXT *pCmdText)
233 DocHost *This = OLECMD_THIS(iface);
234 FIXME("(%p)->(%s %lu %p %p)\n", This, debugstr_guid(pguidCmdGroup), cCmds, prgCmds,
235 pCmdText);
236 return E_NOTIMPL;
239 static HRESULT WINAPI ClOleCommandTarget_Exec(IOleCommandTarget *iface,
240 const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn,
241 VARIANT *pvaOut)
243 DocHost *This = OLECMD_THIS(iface);
244 FIXME("(%p)->(%s %ld %ld %p %p)\n", This, debugstr_guid(pguidCmdGroup), nCmdID,
245 nCmdexecopt, pvaIn, pvaOut);
246 return E_NOTIMPL;
249 #undef OLECMD_THIS
251 static const IOleCommandTargetVtbl OleCommandTargetVtbl = {
252 ClOleCommandTarget_QueryInterface,
253 ClOleCommandTarget_AddRef,
254 ClOleCommandTarget_Release,
255 ClOleCommandTarget_QueryStatus,
256 ClOleCommandTarget_Exec
259 #define DOCHOSTUI_THIS(iface) DEFINE_THIS(DocHost, DocHostUIHandler, iface)
261 static HRESULT WINAPI DocHostUIHandler_QueryInterface(IDocHostUIHandler2 *iface,
262 REFIID riid, void **ppv)
264 DocHost *This = DOCHOSTUI_THIS(iface);
265 return IOleClientSite_QueryInterface(CLIENTSITE(This), riid, ppv);
268 static ULONG WINAPI DocHostUIHandler_AddRef(IDocHostUIHandler2 *iface)
270 DocHost *This = DOCHOSTUI_THIS(iface);
271 return IOleClientSite_AddRef(CLIENTSITE(This));
274 static ULONG WINAPI DocHostUIHandler_Release(IDocHostUIHandler2 *iface)
276 DocHost *This = DOCHOSTUI_THIS(iface);
277 return IOleClientSite_Release(CLIENTSITE(This));
280 static HRESULT WINAPI DocHostUIHandler_ShowContextMenu(IDocHostUIHandler2 *iface,
281 DWORD dwID, POINT *ppt, IUnknown *pcmdtReserved, IDispatch *pdispReserved)
283 DocHost *This = DOCHOSTUI_THIS(iface);
284 HRESULT hres;
286 TRACE("(%p)->(%ld %p %p %p)\n", This, dwID, ppt, pcmdtReserved, pdispReserved);
288 if(This->hostui) {
289 hres = IDocHostUIHandler_ShowContextMenu(This->hostui, dwID, ppt, pcmdtReserved,
290 pdispReserved);
291 if(hres == S_OK)
292 return S_OK;
295 FIXME("default action not implemented\n");
296 return E_NOTIMPL;
299 static HRESULT WINAPI DocHostUIHandler_GetHostInfo(IDocHostUIHandler2 *iface,
300 DOCHOSTUIINFO *pInfo)
302 DocHost *This = DOCHOSTUI_THIS(iface);
303 HRESULT hres;
305 TRACE("(%p)->(%p)\n", This, pInfo);
307 if(This->hostui) {
308 hres = IDocHostUIHandler_GetHostInfo(This->hostui, pInfo);
309 if(SUCCEEDED(hres))
310 return hres;
313 pInfo->dwFlags = DOCHOSTUIFLAG_DISABLE_HELP_MENU | DOCHOSTUIFLAG_OPENNEWWIN
314 | DOCHOSTUIFLAG_URL_ENCODING_ENABLE_UTF8 | DOCHOSTUIFLAG_ENABLE_INPLACE_NAVIGATION
315 | DOCHOSTUIFLAG_IME_ENABLE_RECONVERSION;
316 return S_OK;
319 static HRESULT WINAPI DocHostUIHandler_ShowUI(IDocHostUIHandler2 *iface, DWORD dwID,
320 IOleInPlaceActiveObject *pActiveObject, IOleCommandTarget *pCommandTarget,
321 IOleInPlaceFrame *pFrame, IOleInPlaceUIWindow *pDoc)
323 DocHost *This = DOCHOSTUI_THIS(iface);
324 FIXME("(%p)->(%ld %p %p %p %p)\n", This, dwID, pActiveObject, pCommandTarget,
325 pFrame, pDoc);
326 return E_NOTIMPL;
329 static HRESULT WINAPI DocHostUIHandler_HideUI(IDocHostUIHandler2 *iface)
331 DocHost *This = DOCHOSTUI_THIS(iface);
332 FIXME("(%p)\n", This);
333 return E_NOTIMPL;
336 static HRESULT WINAPI DocHostUIHandler_UpdateUI(IDocHostUIHandler2 *iface)
338 DocHost *This = DOCHOSTUI_THIS(iface);
339 FIXME("(%p)\n", This);
340 return E_NOTIMPL;
343 static HRESULT WINAPI DocHostUIHandler_EnableModeless(IDocHostUIHandler2 *iface,
344 BOOL fEnable)
346 DocHost *This = DOCHOSTUI_THIS(iface);
347 FIXME("(%p)->(%x)\n", This, fEnable);
348 return E_NOTIMPL;
351 static HRESULT WINAPI DocHostUIHandler_OnDocWindowActivate(IDocHostUIHandler2 *iface,
352 BOOL fActivate)
354 DocHost *This = DOCHOSTUI_THIS(iface);
355 FIXME("(%p)->(%x)\n", This, fActivate);
356 return E_NOTIMPL;
359 static HRESULT WINAPI DocHostUIHandler_OnFrameWindowActivate(IDocHostUIHandler2 *iface,
360 BOOL fActivate)
362 DocHost *This = DOCHOSTUI_THIS(iface);
363 FIXME("(%p)->(%x)\n", This, fActivate);
364 return E_NOTIMPL;
367 static HRESULT WINAPI DocHostUIHandler_ResizeBorder(IDocHostUIHandler2 *iface,
368 LPCRECT prcBorder, IOleInPlaceUIWindow *pUIWindow, BOOL fRameWindow)
370 DocHost *This = DOCHOSTUI_THIS(iface);
371 FIXME("(%p)->(%p %p %X)\n", This, prcBorder, pUIWindow, fRameWindow);
372 return E_NOTIMPL;
375 static HRESULT WINAPI DocHostUIHandler_TranslateAccelerator(IDocHostUIHandler2 *iface,
376 LPMSG lpMsg, const GUID *pguidCmdGroup, DWORD nCmdID)
378 DocHost *This = DOCHOSTUI_THIS(iface);
379 FIXME("(%p)->(%p %p %ld)\n", This, lpMsg, pguidCmdGroup, nCmdID);
380 return E_NOTIMPL;
383 static HRESULT WINAPI DocHostUIHandler_GetOptionKeyPath(IDocHostUIHandler2 *iface,
384 LPOLESTR *pchKey, DWORD dw)
386 DocHost *This = DOCHOSTUI_THIS(iface);
388 TRACE("(%p)->(%p %ld)\n", This, pchKey, dw);
390 if(This->hostui)
391 return IDocHostUIHandler_GetOptionKeyPath(This->hostui, pchKey, dw);
393 return S_OK;
396 static HRESULT WINAPI DocHostUIHandler_GetDropTarget(IDocHostUIHandler2 *iface,
397 IDropTarget *pDropTarget, IDropTarget **ppDropTarget)
399 DocHost *This = DOCHOSTUI_THIS(iface);
400 FIXME("(%p)\n", This);
401 return E_NOTIMPL;
404 static HRESULT WINAPI DocHostUIHandler_GetExternal(IDocHostUIHandler2 *iface,
405 IDispatch **ppDispatch)
407 DocHost *This = DOCHOSTUI_THIS(iface);
408 FIXME("(%p)->(%p)\n", This, ppDispatch);
409 return E_NOTIMPL;
412 static HRESULT WINAPI DocHostUIHandler_TranslateUrl(IDocHostUIHandler2 *iface,
413 DWORD dwTranslate, OLECHAR *pchURLIn, OLECHAR **ppchURLOut)
415 DocHost *This = DOCHOSTUI_THIS(iface);
417 TRACE("(%p)->(%ld %s %p)\n", This, dwTranslate, debugstr_w(pchURLIn), ppchURLOut);
419 if(This->hostui)
420 return IDocHostUIHandler_TranslateUrl(This->hostui, dwTranslate,
421 pchURLIn, ppchURLOut);
423 return S_FALSE;
426 static HRESULT WINAPI DocHostUIHandler_FilterDataObject(IDocHostUIHandler2 *iface,
427 IDataObject *pDO, IDataObject **ppDORet)
429 DocHost *This = DOCHOSTUI_THIS(iface);
430 FIXME("(%p)->(%p %p)\n", This, pDO, ppDORet);
431 return E_NOTIMPL;
434 static HRESULT WINAPI DocHostUIHandler_GetOverrideKeyPath(IDocHostUIHandler2 *iface,
435 LPOLESTR *pchKey, DWORD dw)
437 DocHost *This = DOCHOSTUI_THIS(iface);
438 IDocHostUIHandler2 *handler;
439 HRESULT hres;
441 TRACE("(%p)->(%p %ld)\n", This, pchKey, dw);
443 if(!This->hostui)
444 return S_OK;
446 hres = IDocHostUIHandler_QueryInterface(This->hostui, &IID_IDocHostUIHandler2,
447 (void**)&handler);
448 if(SUCCEEDED(hres)) {
449 hres = IDocHostUIHandler2_GetOverrideKeyPath(handler, pchKey, dw);
450 IDocHostUIHandler2_Release(handler);
451 return hres;
454 return S_OK;
457 #undef DOCHOSTUI_THIS
459 static const IDocHostUIHandler2Vtbl DocHostUIHandler2Vtbl = {
460 DocHostUIHandler_QueryInterface,
461 DocHostUIHandler_AddRef,
462 DocHostUIHandler_Release,
463 DocHostUIHandler_ShowContextMenu,
464 DocHostUIHandler_GetHostInfo,
465 DocHostUIHandler_ShowUI,
466 DocHostUIHandler_HideUI,
467 DocHostUIHandler_UpdateUI,
468 DocHostUIHandler_EnableModeless,
469 DocHostUIHandler_OnDocWindowActivate,
470 DocHostUIHandler_OnFrameWindowActivate,
471 DocHostUIHandler_ResizeBorder,
472 DocHostUIHandler_TranslateAccelerator,
473 DocHostUIHandler_GetOptionKeyPath,
474 DocHostUIHandler_GetDropTarget,
475 DocHostUIHandler_GetExternal,
476 DocHostUIHandler_TranslateUrl,
477 DocHostUIHandler_FilterDataObject,
478 DocHostUIHandler_GetOverrideKeyPath
481 void DocHost_Init(DocHost *This, IDispatch *disp)
483 This->lpDocHostUIHandlerVtbl = &DocHostUIHandler2Vtbl;
484 This->lpOleCommandTargetVtbl = &OleCommandTargetVtbl;
486 This->disp = disp;
488 This->document = NULL;
489 This->hostui = NULL;
491 This->hwnd = NULL;
492 This->frame_hwnd = NULL;
493 This->url = NULL;
495 DocHost_ClientSite_Init(This);
496 DocHost_Frame_Init(This);
497 DocHost_Events_Init(This);
500 void DocHost_Release(DocHost *This)
502 DocHost_ClientSite_Release(This);
503 DocHost_Events_Release(This);
505 SysFreeString(This->url);