1 /*
2 * Copyright 2005-2006 Jacek Caban for CodeWeavers
3 *
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.
8 *
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.
13 *
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
17 */
18
19 #include "wine/debug.h"
20 #include "shdocvw.h"
21 #include "hlink.h"
22 #include "exdispid.h"
23
24 WINE_DEFAULT_DEBUG_CHANNEL(shdocvw);
25
26 static ATOM doc_view_atom = 0;
27
28 void push_dochost_task(DocHost *This, task_header_t *task, task_proc_t proc, BOOL send)
29 {
30 task->proc = proc;
31
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);
37 }
38
39 LRESULT process_dochost_task(DocHost *This, LPARAM lparam)
40 {
41 task_header_t *task = (task_header_t*)lparam;
42
43 task->proc(This, task);
44
45 heap_free(task);
46 return 0;
47 }
48
49 static void navigate_complete(DocHost *This)
50 {
51 DISPPARAMS dispparams;
52 VARIANTARG params[2];
53 VARIANT url;
54
55 dispparams.cArgs = 2;
56 dispparams.cNamedArgs = 0;
57 dispparams.rgdispidNamedArgs = NULL;
58 dispparams.rgvarg = params;
59
60 V_VT(params) = (VT_BYREF|VT_VARIANT);
61 V_BYREF(params) = &url;
62
63 V_VT(params+1) = VT_DISPATCH;
64 V_DISPATCH(params+1) = This->disp;
65
66 V_VT(&url) = VT_BSTR;
67 V_BSTR(&url) = SysAllocString(This->url);
68
69 call_sink(This->cps.wbe2, DISPID_NAVIGATECOMPLETE2, &dispparams);
70 call_sink(This->cps.wbe2, DISPID_DOCUMENTCOMPLETE, &dispparams);
71
72 SysFreeString(V_BSTR(&url));
73 This->busy = VARIANT_FALSE;
74 }
75
76 void object_available(DocHost *This)
77 {
78 IHlinkTarget *hlink;
79 HRESULT hres;
80
81 TRACE("(%p)\n", This);
82
83 if(!This->document) {
84 WARN("document == NULL\n");
85 return;
86 }
87
88 hres = IUnknown_QueryInterface(This->document, &IID_IHlinkTarget, (void**)&hlink);
89 if(FAILED(hres)) {
90 FIXME("Could not get IHlinkTarget interface\n");
91 return;
92 }
93
94 hres = IHlinkTarget_Navigate(hlink, 0, NULL);
95 IHlinkTarget_Release(hlink);
96 if(FAILED(hres)) {
97 FIXME("Navigate failed\n");
98 return;
99 }
100
101 navigate_complete(This);
102
103 return;
104 }
105
106 static LRESULT resize_document(DocHost *This, LONG width, LONG height)
107 {
108 RECT rect = {0, 0, width, height};
109
110 TRACE("(%p)->(%d %d)\n", This, width, height);
111
112 if(This->view)
113 IOleDocumentView_SetRect(This->view, &rect);
114
115 return 0;
116 }
117
118 static LRESULT WINAPI doc_view_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
119 {
120 DocHost *This;
121
122 static const WCHAR wszTHIS[] = {'T','H','I','S',0};
123
124 if(msg == WM_CREATE) {
125 This = *(DocHost**)lParam;
126 SetPropW(hwnd, wszTHIS, This);
127 }else {
128 This = GetPropW(hwnd, wszTHIS);
129 }
130
131 switch(msg) {
132 case WM_SIZE:
133 return resize_document(This, LOWORD(lParam), HIWORD(lParam));
134 }
135
136 return DefWindowProcW(hwnd, msg, wParam, lParam);
137 }
138
139 void create_doc_view_hwnd(DocHost *This)
140 {
141 RECT rect;
142
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};
145
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
155 };
156
157 wndclass.hInstance = shdocvw_hinstance;
158
159 doc_view_atom = RegisterClassExW(&wndclass);
160 }
161
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);
168 }
169
170 void deactivate_document(DocHost *This)
171 {
172 IOleInPlaceObjectWindowless *winobj;
173 IOleObject *oleobj = NULL;
174 IHlinkTarget *hlink = NULL;
175 HRESULT hres;
176
177 if(This->view)
178 IOleDocumentView_UIActivate(This->view, FALSE);
179
180 hres = IUnknown_QueryInterface(This->document, &IID_IOleInPlaceObjectWindowless,
181 (void**)&winobj);
182 if(SUCCEEDED(hres)) {
183 IOleInPlaceObjectWindowless_InPlaceDeactivate(winobj);
184 IOleInPlaceObjectWindowless_Release(winobj);
185 }
186
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;
193 }
194
195 hres = IUnknown_QueryInterface(This->document, &IID_IOleObject, (void**)&oleobj);
196 if(SUCCEEDED(hres))
197 IOleObject_Close(oleobj, OLECLOSE_NOSAVE);
198
199 hres = IUnknown_QueryInterface(This->document, &IID_IHlinkTarget, (void**)&hlink);
200 if(SUCCEEDED(hres)) {
201 IHlinkTarget_SetBrowseContext(hlink, NULL);
202 IHlinkTarget_Release(hlink);
203 }
204
205 if(oleobj) {
206 IOleClientSite *client_site = NULL;
207
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);
213 }
214
215 IOleObject_Release(oleobj);
216 }
217
218 IUnknown_Release(This->document);
219 This->document = NULL;
220 }
221
222 #define OLECMD_THIS(iface) DEFINE_THIS(DocHost, OleCommandTarget, iface)
223
224 static HRESULT WINAPI ClOleCommandTarget_QueryInterface(IOleCommandTarget *iface,
225 REFIID riid, void **ppv)
226 {
227 DocHost *This = OLECMD_THIS(iface);
228 return IOleClientSite_QueryInterface(CLIENTSITE(This), riid, ppv);
229 }
230
231 static ULONG WINAPI ClOleCommandTarget_AddRef(IOleCommandTarget *iface)
232 {
233 DocHost *This = OLECMD_THIS(iface);
234 return IOleClientSite_AddRef(CLIENTSITE(This));
235 }
236
237 static ULONG WINAPI ClOleCommandTarget_Release(IOleCommandTarget *iface)
238 {
239 DocHost *This = OLECMD_THIS(iface);
240 return IOleClientSite_Release(CLIENTSITE(This));
241 }
242
243 static HRESULT WINAPI ClOleCommandTarget_QueryStatus(IOleCommandTarget *iface,
244 const GUID *pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[], OLECMDTEXT *pCmdText)
245 {
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;
250 }
251
252 static HRESULT WINAPI ClOleCommandTarget_Exec(IOleCommandTarget *iface,
253 const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn,
254 VARIANT *pvaOut)
255 {
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;
260 }
261
262 #undef OLECMD_THIS
263
264 static const IOleCommandTargetVtbl OleCommandTargetVtbl = {
265 ClOleCommandTarget_QueryInterface,
266 ClOleCommandTarget_AddRef,
267 ClOleCommandTarget_Release,
268 ClOleCommandTarget_QueryStatus,
269 ClOleCommandTarget_Exec
270 };
271
272 #define DOCHOSTUI_THIS(iface) DEFINE_THIS(DocHost, DocHostUIHandler, iface)
273
274 static HRESULT WINAPI DocHostUIHandler_QueryInterface(IDocHostUIHandler2 *iface,
275 REFIID riid, void **ppv)
276 {
277 DocHost *This = DOCHOSTUI_THIS(iface);
278 return IOleClientSite_QueryInterface(CLIENTSITE(This), riid, ppv);
279 }
280
281 static ULONG WINAPI DocHostUIHandler_AddRef(IDocHostUIHandler2 *iface)
282 {
283 DocHost *This = DOCHOSTUI_THIS(iface);
284 return IOleClientSite_AddRef(CLIENTSITE(This));
285 }
286
287 static ULONG WINAPI DocHostUIHandler_Release(IDocHostUIHandler2 *iface)
288 {
289 DocHost *This = DOCHOSTUI_THIS(iface);
290 return IOleClientSite_Release(CLIENTSITE(This));
291 }
292
293 static HRESULT WINAPI DocHostUIHandler_ShowContextMenu(IDocHostUIHandler2 *iface,
294 DWORD dwID, POINT *ppt, IUnknown *pcmdtReserved, IDispatch *pdispReserved)
295 {
296 DocHost *This = DOCHOSTUI_THIS(iface);
297 HRESULT hres;
298
299 TRACE("(%p)->(%d %p %p %p)\n", This, dwID, ppt, pcmdtReserved, pdispReserved);
300
301 if(This->hostui) {
302 hres = IDocHostUIHandler_ShowContextMenu(This->hostui, dwID, ppt, pcmdtReserved,
303 pdispReserved);
304 if(hres == S_OK)
305 return S_OK;
306 }
307
308 FIXME("default action not implemented\n");
309 return E_NOTIMPL;
310 }
311
312 static HRESULT WINAPI DocHostUIHandler_GetHostInfo(IDocHostUIHandler2 *iface,
313 DOCHOSTUIINFO *pInfo)
314 {
315 DocHost *This = DOCHOSTUI_THIS(iface);
316 HRESULT hres;
317
318 TRACE("(%p)->(%p)\n", This, pInfo);
319
320 if(This->hostui) {
321 hres = IDocHostUIHandler_GetHostInfo(This->hostui, pInfo);
322 if(SUCCEEDED(hres))
323 return hres;
324 }
325
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;
330 }
331
332 static HRESULT WINAPI DocHostUIHandler_ShowUI(IDocHostUIHandler2 *iface, DWORD dwID,
333 IOleInPlaceActiveObject *pActiveObject, IOleCommandTarget *pCommandTarget,
334 IOleInPlaceFrame *pFrame, IOleInPlaceUIWindow *pDoc)
335 {
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;
340 }
341
342 static HRESULT WINAPI DocHostUIHandler_HideUI(IDocHostUIHandler2 *iface)
343 {
344 DocHost *This = DOCHOSTUI_THIS(iface);
345 FIXME("(%p)\n", This);
346 return E_NOTIMPL;
347 }
348
349 static HRESULT WINAPI DocHostUIHandler_UpdateUI(IDocHostUIHandler2 *iface)
350 {
351 DocHost *This = DOCHOSTUI_THIS(iface);
352
353 TRACE("(%p)\n", This);
354
355 if(!This->hostui)
356 return S_FALSE;
357
358 return IDocHostUIHandler_UpdateUI(This->hostui);
359 }
360
361 static HRESULT WINAPI DocHostUIHandler_EnableModeless(IDocHostUIHandler2 *iface,
362 BOOL fEnable)
363 {
364 DocHost *This = DOCHOSTUI_THIS(iface);
365 FIXME("(%p)->(%x)\n", This, fEnable);
366 return E_NOTIMPL;
367 }
368
369 static HRESULT WINAPI DocHostUIHandler_OnDocWindowActivate(IDocHostUIHandler2 *iface,
370 BOOL fActivate)
371 {
372 DocHost *This = DOCHOSTUI_THIS(iface);
373 FIXME("(%p)->(%x)\n", This, fActivate);
374 return E_NOTIMPL;
375 }
376
377 static HRESULT WINAPI DocHostUIHandler_OnFrameWindowActivate(IDocHostUIHandler2 *iface,
378 BOOL fActivate)
379 {
380 DocHost *This = DOCHOSTUI_THIS(iface);
381 FIXME("(%p)->(%x)\n", This, fActivate);
382 return E_NOTIMPL;
383 }
384
385 static HRESULT WINAPI DocHostUIHandler_ResizeBorder(IDocHostUIHandler2 *iface,
386 LPCRECT prcBorder, IOleInPlaceUIWindow *pUIWindow, BOOL fRameWindow)
387 {
388 DocHost *This = DOCHOSTUI_THIS(iface);
389 FIXME("(%p)->(%p %p %X)\n", This, prcBorder, pUIWindow, fRameWindow);
390 return E_NOTIMPL;
391 }
392
393 static HRESULT WINAPI DocHostUIHandler_TranslateAccelerator(IDocHostUIHandler2 *iface,
394 LPMSG lpMsg, const GUID *pguidCmdGroup, DWORD nCmdID)
395 {
396 DocHost *This = DOCHOSTUI_THIS(iface);
397 FIXME("(%p)->(%p %p %d)\n", This, lpMsg, pguidCmdGroup, nCmdID);
398 return E_NOTIMPL;
399 }
400
401 static HRESULT WINAPI DocHostUIHandler_GetOptionKeyPath(IDocHostUIHandler2 *iface,
402 LPOLESTR *pchKey, DWORD dw)
403 {
404 DocHost *This = DOCHOSTUI_THIS(iface);
405
406 TRACE("(%p)->(%p %d)\n", This, pchKey, dw);
407
408 if(This->hostui)
409 return IDocHostUIHandler_GetOptionKeyPath(This->hostui, pchKey, dw);
410
411 return S_OK;
412 }
413
414 static HRESULT WINAPI DocHostUIHandler_GetDropTarget(IDocHostUIHandler2 *iface,
415 IDropTarget *pDropTarget, IDropTarget **ppDropTarget)
416 {
417 DocHost *This = DOCHOSTUI_THIS(iface);
418 FIXME("(%p)\n", This);
419 return E_NOTIMPL;
420 }
421
422 static HRESULT WINAPI DocHostUIHandler_GetExternal(IDocHostUIHandler2 *iface,
423 IDispatch **ppDispatch)
424 {
425 DocHost *This = DOCHOSTUI_THIS(iface);
426
427 TRACE("(%p)->(%p)\n", This, ppDispatch);
428
429 if(This->hostui)
430 return IDocHostUIHandler_GetExternal(This->hostui, ppDispatch);
431
432 FIXME("default action not implemented\n");
433 return E_NOTIMPL;
434 }
435
436 static HRESULT WINAPI DocHostUIHandler_TranslateUrl(IDocHostUIHandler2 *iface,
437 DWORD dwTranslate, OLECHAR *pchURLIn, OLECHAR **ppchURLOut)
438 {
439 DocHost *This = DOCHOSTUI_THIS(iface);
440
441 TRACE("(%p)->(%d %s %p)\n", This, dwTranslate, debugstr_w(pchURLIn), ppchURLOut);
442
443 if(This->hostui)
444 return IDocHostUIHandler_TranslateUrl(This->hostui, dwTranslate,
445 pchURLIn, ppchURLOut);
446
447 return S_FALSE;
448 }
449
450 static HRESULT WINAPI DocHostUIHandler_FilterDataObject(IDocHostUIHandler2 *iface,
451 IDataObject *pDO, IDataObject **ppDORet)
452 {
453 DocHost *This = DOCHOSTUI_THIS(iface);
454 FIXME("(%p)->(%p %p)\n", This, pDO, ppDORet);
455 return E_NOTIMPL;
456 }
457
458 static HRESULT WINAPI DocHostUIHandler_GetOverrideKeyPath(IDocHostUIHandler2 *iface,
459 LPOLESTR *pchKey, DWORD dw)
460 {
461 DocHost *This = DOCHOSTUI_THIS(iface);
462 IDocHostUIHandler2 *handler;
463 HRESULT hres;
464
465 TRACE("(%p)->(%p %d)\n", This, pchKey, dw);
466
467 if(!This->hostui)
468 return S_OK;
469
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;
476 }
477
478 return S_OK;
479 }
480
481 #undef DOCHOSTUI_THIS
482
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
503 };
504
505 void DocHost_Init(DocHost *This, IDispatch *disp)
506 {
507 This->lpDocHostUIHandlerVtbl = &DocHostUIHandler2Vtbl;
508 This->lpOleCommandTargetVtbl = &OleCommandTargetVtbl;
509
510 This->disp = disp;
511
512 This->client_disp = NULL;
513
514 This->document = NULL;
515 This->hostui = NULL;
516 This->frame = NULL;
517
518 This->hwnd = NULL;
519 This->frame_hwnd = NULL;
520 This->url = NULL;
521
522 This->silent = VARIANT_FALSE;
523 This->offline = VARIANT_FALSE;
524
525 DocHost_ClientSite_Init(This);
526 DocHost_Frame_Init(This);
527
528 ConnectionPointContainer_Init(&This->cps, (IUnknown*)disp);
529 }
530
531 void DocHost_Release(DocHost *This)
532 {
533 if(This->client_disp)
534 IDispatch_Release(This->client_disp);
535 if(This->frame)
536 IOleInPlaceFrame_Release(This->frame);
537
538 DocHost_ClientSite_Release(This);
539
540 ConnectionPointContainer_Destroy(&This->cps);
541
542 SysFreeString(This->url);
543 }
544
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.