sync with trunk r46493
[reactos.git] / dll / win32 / shdocvw / oleobject.c
1 /*
2 * Implementation of IOleObject interfaces for WebBrowser control
3 *
4 * - IOleObject
5 * - IOleInPlaceObject
6 * - IOleControl
7 *
8 * Copyright 2001 John R. Sheets (for CodeWeavers)
9 * Copyright 2005 Jacek Caban
10 *
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26 #include <string.h>
27 #include "wine/debug.h"
28 #include "shdocvw.h"
29 #include "htiframe.h"
30 #include "idispids.h"
31 #include "mshtmdid.h"
32
33 WINE_DEFAULT_DEBUG_CHANNEL(shdocvw);
34
35 /* shlwapi.dll */
36 HWND WINAPI SHSetParentHwnd(HWND hWnd, HWND hWndParent);
37
38 static ATOM shell_embedding_atom = 0;
39
40 static LRESULT resize_window(WebBrowser *This, LONG width, LONG height)
41 {
42 if(This->doc_host.hwnd)
43 SetWindowPos(This->doc_host.hwnd, NULL, 0, 0, width, height,
44 SWP_NOZORDER | SWP_NOACTIVATE);
45
46 return 0;
47 }
48
49 static LRESULT WINAPI shell_embedding_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
50 {
51 WebBrowser *This;
52
53 static const WCHAR wszTHIS[] = {'T','H','I','S',0};
54
55 if(msg == WM_CREATE) {
56 This = *(WebBrowser**)lParam;
57 SetPropW(hwnd, wszTHIS, This);
58 }else {
59 This = GetPropW(hwnd, wszTHIS);
60 }
61
62 switch(msg) {
63 case WM_SIZE:
64 return resize_window(This, LOWORD(lParam), HIWORD(lParam));
65 case WM_DOCHOSTTASK:
66 return process_dochost_task(&This->doc_host, lParam);
67 }
68
69 return DefWindowProcW(hwnd, msg, wParam, lParam);
70 }
71
72 static void create_shell_embedding_hwnd(WebBrowser *This)
73 {
74 IOleInPlaceSite *inplace;
75 HWND parent = NULL;
76 HRESULT hres;
77
78 static const WCHAR wszShellEmbedding[] =
79 {'S','h','e','l','l',' ','E','m','b','e','d','d','i','n','g',0};
80
81 if(!shell_embedding_atom) {
82 static WNDCLASSEXW wndclass = {
83 sizeof(wndclass),
84 CS_DBLCLKS,
85 shell_embedding_proc,
86 0, 0 /* native uses 8 */, NULL, NULL, NULL,
87 (HBRUSH)(COLOR_WINDOW + 1), NULL,
88 wszShellEmbedding,
89 NULL
90 };
91 wndclass.hInstance = shdocvw_hinstance;
92
93 RegisterClassExW(&wndclass);
94 }
95
96 hres = IOleClientSite_QueryInterface(This->client, &IID_IOleInPlaceSite, (void**)&inplace);
97 if(SUCCEEDED(hres)) {
98 IOleInPlaceSite_GetWindow(inplace, &parent);
99 IOleInPlaceSite_Release(inplace);
100 }
101
102 This->doc_host.frame_hwnd = This->shell_embedding_hwnd = CreateWindowExW(
103 WS_EX_WINDOWEDGE,
104 wszShellEmbedding, wszShellEmbedding,
105 WS_CLIPSIBLINGS | WS_CLIPCHILDREN
106 | (parent ? WS_CHILD | WS_TABSTOP : WS_POPUP | WS_MAXIMIZEBOX),
107 0, 0, 0, 0, parent,
108 NULL, shdocvw_hinstance, This);
109
110 TRACE("parent=%p hwnd=%p\n", parent, This->shell_embedding_hwnd);
111 }
112
113 static HRESULT activate_inplace(WebBrowser *This, IOleClientSite *active_site)
114 {
115 HWND parent_hwnd;
116 HRESULT hres;
117
118 if(This->inplace)
119 return S_OK;
120
121 if(!active_site)
122 return E_INVALIDARG;
123
124 hres = IOleClientSite_QueryInterface(active_site, &IID_IOleInPlaceSite,
125 (void**)&This->inplace);
126 if(FAILED(hres)) {
127 WARN("Could not get IOleInPlaceSite\n");
128 return hres;
129 }
130
131 hres = IOleInPlaceSite_CanInPlaceActivate(This->inplace);
132 if(hres != S_OK) {
133 WARN("CanInPlaceActivate returned: %08x\n", hres);
134 IOleInPlaceSite_Release(This->inplace);
135 return E_FAIL;
136 }
137
138 hres = IOleInPlaceSite_GetWindow(This->inplace, &parent_hwnd);
139 if(SUCCEEDED(hres))
140 SHSetParentHwnd(This->shell_embedding_hwnd, parent_hwnd);
141
142 IOleInPlaceSite_OnInPlaceActivate(This->inplace);
143
144 IOleInPlaceSite_GetWindowContext(This->inplace, &This->doc_host.frame, &This->uiwindow,
145 &This->pos_rect, &This->clip_rect,
146 &This->frameinfo);
147
148 SetWindowPos(This->shell_embedding_hwnd, NULL,
149 This->pos_rect.left, This->pos_rect.top,
150 This->pos_rect.right-This->pos_rect.left,
151 This->pos_rect.bottom-This->pos_rect.top,
152 SWP_NOZORDER | SWP_SHOWWINDOW);
153
154 if(This->client) {
155 IOleContainer *container;
156
157 IOleClientSite_ShowObject(This->client);
158
159 hres = IOleClientSite_GetContainer(This->client, &container);
160 if(SUCCEEDED(hres)) {
161 if(This->container)
162 IOleContainer_Release(This->container);
163 This->container = container;
164 }
165 }
166
167 if(This->doc_host.frame)
168 IOleInPlaceFrame_GetWindow(This->doc_host.frame, &This->frame_hwnd);
169
170 return S_OK;
171 }
172
173 static HRESULT activate_ui(WebBrowser *This, IOleClientSite *active_site)
174 {
175 HRESULT hres;
176
177 static const WCHAR wszitem[] = {'i','t','e','m',0};
178
179 if(This->inplace)
180 {
181 if(This->shell_embedding_hwnd)
182 ShowWindow(This->shell_embedding_hwnd, SW_SHOW);
183 return S_OK;
184 }
185
186 hres = activate_inplace(This, active_site);
187 if(FAILED(hres))
188 return hres;
189
190 IOleInPlaceSite_OnUIActivate(This->inplace);
191
192 if(This->doc_host.frame)
193 IOleInPlaceFrame_SetActiveObject(This->doc_host.frame, ACTIVEOBJ(This), wszitem);
194 if(This->uiwindow)
195 IOleInPlaceUIWindow_SetActiveObject(This->uiwindow, ACTIVEOBJ(This), wszitem);
196
197 if(This->doc_host.frame)
198 IOleInPlaceFrame_SetMenu(This->doc_host.frame, NULL, NULL, This->shell_embedding_hwnd);
199
200 SetFocus(This->shell_embedding_hwnd);
201
202 return S_OK;
203 }
204
205 static HRESULT get_client_disp_property(IOleClientSite *client, DISPID dispid, VARIANT *res)
206 {
207 IDispatch *disp = NULL;
208 DISPPARAMS dispparams = {NULL, 0};
209 HRESULT hres;
210
211 VariantInit(res);
212
213 if(!client)
214 return S_OK;
215
216 hres = IOleClientSite_QueryInterface(client, &IID_IDispatch, (void**)&disp);
217 if(FAILED(hres)) {
218 TRACE("Could not get IDispatch\n");
219 return hres;
220 }
221
222 hres = IDispatch_Invoke(disp, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
223 DISPATCH_PROPERTYGET, &dispparams, res, NULL, NULL);
224
225 IDispatch_Release(disp);
226
227 return hres;
228 }
229
230 static HRESULT on_offlineconnected_change(WebBrowser *This)
231 {
232 VARIANT offline;
233
234 get_client_disp_property(This->client, DISPID_AMBIENT_OFFLINEIFNOTCONNECTED, &offline);
235
236 if(V_VT(&offline) == VT_BOOL)
237 IWebBrowser2_put_Offline(WEBBROWSER2(This), V_BOOL(&offline));
238 else if(V_VT(&offline) != VT_EMPTY)
239 WARN("wrong V_VT(silent) %d\n", V_VT(&offline));
240
241 return S_OK;
242 }
243
244 static HRESULT on_silent_change(WebBrowser *This)
245 {
246 VARIANT silent;
247
248 get_client_disp_property(This->client, DISPID_AMBIENT_SILENT, &silent);
249
250 if(V_VT(&silent) == VT_BOOL)
251 IWebBrowser2_put_Silent(WEBBROWSER2(This), V_BOOL(&silent));
252 else if(V_VT(&silent) != VT_EMPTY)
253 WARN("wrong V_VT(silent) %d\n", V_VT(&silent));
254
255 return S_OK;
256 }
257
258 static void release_client_site(WebBrowser *This)
259 {
260 release_dochost_client(&This->doc_host);
261
262 if(This->shell_embedding_hwnd) {
263 DestroyWindow(This->shell_embedding_hwnd);
264 This->shell_embedding_hwnd = NULL;
265 }
266
267 if(This->inplace) {
268 IOleInPlaceSite_Release(This->inplace);
269 This->inplace = NULL;
270 }
271
272 if(This->container) {
273 IOleContainer_Release(This->container);
274 This->container = NULL;
275 }
276
277 if(This->uiwindow) {
278 IOleInPlaceUIWindow_Release(This->uiwindow);
279 This->uiwindow = NULL;
280 }
281
282 if(This->client) {
283 IOleClientSite_Release(This->client);
284 This->client = NULL;
285 }
286 }
287
288 /**********************************************************************
289 * Implement the IOleObject interface for the WebBrowser control
290 */
291
292 #define OLEOBJ_THIS(iface) DEFINE_THIS(WebBrowser, OleObject, iface)
293
294 static HRESULT WINAPI OleObject_QueryInterface(IOleObject *iface, REFIID riid, void **ppv)
295 {
296 WebBrowser *This = OLEOBJ_THIS(iface);
297 return IWebBrowser_QueryInterface(WEBBROWSER(This), riid, ppv);
298 }
299
300 static ULONG WINAPI OleObject_AddRef(IOleObject *iface)
301 {
302 WebBrowser *This = OLEOBJ_THIS(iface);
303 return IWebBrowser_AddRef(WEBBROWSER(This));
304 }
305
306 static ULONG WINAPI OleObject_Release(IOleObject *iface)
307 {
308 WebBrowser *This = OLEOBJ_THIS(iface);
309 return IWebBrowser_Release(WEBBROWSER(This));
310 }
311
312 static HRESULT WINAPI OleObject_SetClientSite(IOleObject *iface, LPOLECLIENTSITE pClientSite)
313 {
314 WebBrowser *This = OLEOBJ_THIS(iface);
315 IDocHostUIHandler *hostui;
316 IOleContainer *container;
317 IDispatch *disp;
318 HRESULT hres;
319
320 TRACE("(%p)->(%p)\n", This, pClientSite);
321
322 if(This->client == pClientSite)
323 return S_OK;
324
325 release_client_site(This);
326
327 if(!pClientSite) {
328 if(This->doc_host.document)
329 deactivate_document(&This->doc_host);
330 return S_OK;
331 }
332
333 IOleClientSite_AddRef(pClientSite);
334 This->client = pClientSite;
335
336 hres = IOleClientSite_QueryInterface(This->client, &IID_IDispatch,
337 (void**)&disp);
338 if(SUCCEEDED(hres))
339 This->doc_host.client_disp = disp;
340
341 hres = IOleClientSite_QueryInterface(This->client, &IID_IDocHostUIHandler,
342 (void**)&hostui);
343 if(SUCCEEDED(hres))
344 This->doc_host.hostui = hostui;
345
346 hres = IOleClientSite_GetContainer(This->client, &container);
347 if(SUCCEEDED(hres)) {
348 ITargetContainer *target_container;
349
350 hres = IOleContainer_QueryInterface(container, &IID_ITargetContainer,
351 (void**)&target_container);
352 if(SUCCEEDED(hres)) {
353 FIXME("Unsupported ITargetContainer\n");
354 ITargetContainer_Release(target_container);
355 }
356
357 IOleContainer_Release(container);
358 }
359
360 create_shell_embedding_hwnd(This);
361
362 on_offlineconnected_change(This);
363 on_silent_change(This);
364
365 return S_OK;
366 }
367
368 static HRESULT WINAPI OleObject_GetClientSite(IOleObject *iface, LPOLECLIENTSITE *ppClientSite)
369 {
370 WebBrowser *This = OLEOBJ_THIS(iface);
371
372 TRACE("(%p)->(%p)\n", This, ppClientSite);
373
374 if(!ppClientSite)
375 return E_INVALIDARG;
376
377 if(This->client)
378 IOleClientSite_AddRef(This->client);
379 *ppClientSite = This->client;
380
381 return S_OK;
382 }
383
384 static HRESULT WINAPI OleObject_SetHostNames(IOleObject *iface, LPCOLESTR szContainerApp,
385 LPCOLESTR szContainerObj)
386 {
387 WebBrowser *This = OLEOBJ_THIS(iface);
388
389 TRACE("(%p)->(%s, %s)\n", This, debugstr_w(szContainerApp), debugstr_w(szContainerObj));
390
391 /* We have nothing to do here. */
392 return S_OK;
393 }
394
395 static HRESULT WINAPI OleObject_Close(IOleObject *iface, DWORD dwSaveOption)
396 {
397 WebBrowser *This = OLEOBJ_THIS(iface);
398 FIXME("(%p)->(%d)\n", This, dwSaveOption);
399 return E_NOTIMPL;
400 }
401
402 static HRESULT WINAPI OleObject_SetMoniker(IOleObject *iface, DWORD dwWhichMoniker, IMoniker* pmk)
403 {
404 WebBrowser *This = OLEOBJ_THIS(iface);
405 FIXME("(%p)->(%d, %p)\n", This, dwWhichMoniker, pmk);
406 return E_NOTIMPL;
407 }
408
409 static HRESULT WINAPI OleObject_GetMoniker(IOleObject *iface, DWORD dwAssign,
410 DWORD dwWhichMoniker, LPMONIKER *ppmk)
411 {
412 WebBrowser *This = OLEOBJ_THIS(iface);
413 FIXME("(%p)->(%d, %d, %p)\n", This, dwAssign, dwWhichMoniker, ppmk);
414 return E_NOTIMPL;
415 }
416
417 static HRESULT WINAPI OleObject_InitFromData(IOleObject *iface, LPDATAOBJECT pDataObject,
418 BOOL fCreation, DWORD dwReserved)
419 {
420 WebBrowser *This = OLEOBJ_THIS(iface);
421 FIXME("(%p)->(%p, %d, %d)\n", This, pDataObject, fCreation, dwReserved);
422 return E_NOTIMPL;
423 }
424
425 static HRESULT WINAPI OleObject_GetClipboardData(IOleObject *iface, DWORD dwReserved,
426 LPDATAOBJECT *ppDataObject)
427 {
428 WebBrowser *This = OLEOBJ_THIS(iface);
429 FIXME("(%p)->(%d, %p)\n", This, dwReserved, ppDataObject);
430 return E_NOTIMPL;
431 }
432
433 static HRESULT WINAPI OleObject_DoVerb(IOleObject *iface, LONG iVerb, struct tagMSG* lpmsg,
434 LPOLECLIENTSITE pActiveSite, LONG lindex, HWND hwndParent, LPCRECT lprcPosRect)
435 {
436 WebBrowser *This = OLEOBJ_THIS(iface);
437
438 TRACE("(%p)->(%d %p %p %d %p %p)\n", This, iVerb, lpmsg, pActiveSite, lindex, hwndParent,
439 lprcPosRect);
440
441 switch (iVerb)
442 {
443 case OLEIVERB_SHOW:
444 TRACE("OLEIVERB_SHOW\n");
445 return activate_ui(This, pActiveSite);
446 case OLEIVERB_UIACTIVATE:
447 TRACE("OLEIVERB_UIACTIVATE\n");
448 return activate_ui(This, pActiveSite);
449 case OLEIVERB_INPLACEACTIVATE:
450 TRACE("OLEIVERB_INPLACEACTIVATE\n");
451 return activate_inplace(This, pActiveSite);
452 case OLEIVERB_HIDE:
453 TRACE("OLEIVERB_HIDE\n");
454 if(This->shell_embedding_hwnd)
455 ShowWindow(This->shell_embedding_hwnd, SW_HIDE);
456 return S_OK;
457 default:
458 FIXME("stub for %d\n", iVerb);
459 break;
460 }
461
462 return E_NOTIMPL;
463 }
464
465 static HRESULT WINAPI OleObject_EnumVerbs(IOleObject *iface, IEnumOLEVERB **ppEnumOleVerb)
466 {
467 WebBrowser *This = OLEOBJ_THIS(iface);
468 TRACE("(%p)->(%p)\n", This, ppEnumOleVerb);
469 return OleRegEnumVerbs(&CLSID_WebBrowser, ppEnumOleVerb);
470 }
471
472 static HRESULT WINAPI OleObject_Update(IOleObject *iface)
473 {
474 WebBrowser *This = OLEOBJ_THIS(iface);
475 FIXME("(%p)\n", This);
476 return E_NOTIMPL;
477 }
478
479 static HRESULT WINAPI OleObject_IsUpToDate(IOleObject *iface)
480 {
481 WebBrowser *This = OLEOBJ_THIS(iface);
482 FIXME("(%p)\n", This);
483 return E_NOTIMPL;
484 }
485
486 static HRESULT WINAPI OleObject_GetUserClassID(IOleObject *iface, CLSID* pClsid)
487 {
488 WebBrowser *This = OLEOBJ_THIS(iface);
489 FIXME("(%p)->(%p)\n", This, pClsid);
490 return E_NOTIMPL;
491 }
492
493 static HRESULT WINAPI OleObject_GetUserType(IOleObject *iface, DWORD dwFormOfType,
494 LPOLESTR* pszUserType)
495 {
496 WebBrowser *This = OLEOBJ_THIS(iface);
497 TRACE("(%p, %d, %p)\n", This, dwFormOfType, pszUserType);
498 return OleRegGetUserType(&CLSID_WebBrowser, dwFormOfType, pszUserType);
499 }
500
501 static HRESULT WINAPI OleObject_SetExtent(IOleObject *iface, DWORD dwDrawAspect, SIZEL *psizel)
502 {
503 WebBrowser *This = OLEOBJ_THIS(iface);
504
505 TRACE("(%p)->(%x %p)\n", This, dwDrawAspect, psizel);
506
507 /* Tests show that dwDrawAspect is ignored */
508 This->extent = *psizel;
509 return S_OK;
510 }
511
512 static HRESULT WINAPI OleObject_GetExtent(IOleObject *iface, DWORD dwDrawAspect, SIZEL *psizel)
513 {
514 WebBrowser *This = OLEOBJ_THIS(iface);
515
516 TRACE("(%p)->(%x, %p)\n", This, dwDrawAspect, psizel);
517
518 /* Tests show that dwDrawAspect is ignored */
519 *psizel = This->extent;
520 return S_OK;
521 }
522
523 static HRESULT WINAPI OleObject_Advise(IOleObject *iface, IAdviseSink *pAdvSink,
524 DWORD* pdwConnection)
525 {
526 WebBrowser *This = OLEOBJ_THIS(iface);
527 FIXME("(%p)->(%p, %p)\n", This, pAdvSink, pdwConnection);
528 return E_NOTIMPL;
529 }
530
531 static HRESULT WINAPI OleObject_Unadvise(IOleObject *iface, DWORD dwConnection)
532 {
533 WebBrowser *This = OLEOBJ_THIS(iface);
534 FIXME("(%p)->(%d)\n", This, dwConnection);
535 return E_NOTIMPL;
536 }
537
538 static HRESULT WINAPI OleObject_EnumAdvise(IOleObject *iface, IEnumSTATDATA **ppenumAdvise)
539 {
540 WebBrowser *This = OLEOBJ_THIS(iface);
541 FIXME("(%p)->(%p)\n", This, ppenumAdvise);
542 return S_OK;
543 }
544
545 static HRESULT WINAPI OleObject_GetMiscStatus(IOleObject *iface, DWORD dwAspect, DWORD *pdwStatus)
546 {
547 WebBrowser *This = OLEOBJ_THIS(iface);
548
549 TRACE("(%p)->(%x, %p)\n", This, dwAspect, pdwStatus);
550
551 *pdwStatus = OLEMISC_SETCLIENTSITEFIRST|OLEMISC_ACTIVATEWHENVISIBLE|OLEMISC_INSIDEOUT
552 |OLEMISC_CANTLINKINSIDE|OLEMISC_RECOMPOSEONRESIZE;
553
554 return S_OK;
555 }
556
557 static HRESULT WINAPI OleObject_SetColorScheme(IOleObject *iface, LOGPALETTE* pLogpal)
558 {
559 WebBrowser *This = OLEOBJ_THIS(iface);
560 FIXME("(%p)->(%p)\n", This, pLogpal);
561 return E_NOTIMPL;
562 }
563
564 #undef OLEOBJ_THIS
565
566 static const IOleObjectVtbl OleObjectVtbl =
567 {
568 OleObject_QueryInterface,
569 OleObject_AddRef,
570 OleObject_Release,
571 OleObject_SetClientSite,
572 OleObject_GetClientSite,
573 OleObject_SetHostNames,
574 OleObject_Close,
575 OleObject_SetMoniker,
576 OleObject_GetMoniker,
577 OleObject_InitFromData,
578 OleObject_GetClipboardData,
579 OleObject_DoVerb,
580 OleObject_EnumVerbs,
581 OleObject_Update,
582 OleObject_IsUpToDate,
583 OleObject_GetUserClassID,
584 OleObject_GetUserType,
585 OleObject_SetExtent,
586 OleObject_GetExtent,
587 OleObject_Advise,
588 OleObject_Unadvise,
589 OleObject_EnumAdvise,
590 OleObject_GetMiscStatus,
591 OleObject_SetColorScheme
592 };
593
594 /**********************************************************************
595 * Implement the IOleInPlaceObject interface
596 */
597
598 #define INPLACEOBJ_THIS(iface) DEFINE_THIS(WebBrowser, OleInPlaceObject, iface)
599
600 static HRESULT WINAPI OleInPlaceObject_QueryInterface(IOleInPlaceObject *iface,
601 REFIID riid, LPVOID *ppobj)
602 {
603 WebBrowser *This = INPLACEOBJ_THIS(iface);
604 return IWebBrowser_QueryInterface(WEBBROWSER(This), riid, ppobj);
605 }
606
607 static ULONG WINAPI OleInPlaceObject_AddRef(IOleInPlaceObject *iface)
608 {
609 WebBrowser *This = INPLACEOBJ_THIS(iface);
610 return IWebBrowser_AddRef(WEBBROWSER(This));
611 }
612
613 static ULONG WINAPI OleInPlaceObject_Release(IOleInPlaceObject *iface)
614 {
615 WebBrowser *This = INPLACEOBJ_THIS(iface);
616 return IWebBrowser_Release(WEBBROWSER(This));
617 }
618
619 static HRESULT WINAPI OleInPlaceObject_GetWindow(IOleInPlaceObject *iface, HWND* phwnd)
620 {
621 WebBrowser *This = INPLACEOBJ_THIS(iface);
622
623 TRACE("(%p)->(%p)\n", This, phwnd);
624
625 *phwnd = This->shell_embedding_hwnd;
626 return S_OK;
627 }
628
629 static HRESULT WINAPI OleInPlaceObject_ContextSensitiveHelp(IOleInPlaceObject *iface,
630 BOOL fEnterMode)
631 {
632 WebBrowser *This = INPLACEOBJ_THIS(iface);
633 FIXME("(%p)->(%x)\n", This, fEnterMode);
634 return E_NOTIMPL;
635 }
636
637 static HRESULT WINAPI OleInPlaceObject_InPlaceDeactivate(IOleInPlaceObject *iface)
638 {
639 WebBrowser *This = INPLACEOBJ_THIS(iface);
640 FIXME("(%p)\n", This);
641
642 if(This->inplace) {
643 IOleInPlaceSite_Release(This->inplace);
644 This->inplace = NULL;
645 }
646
647 return S_OK;
648 }
649
650 static HRESULT WINAPI OleInPlaceObject_UIDeactivate(IOleInPlaceObject *iface)
651 {
652 WebBrowser *This = INPLACEOBJ_THIS(iface);
653 FIXME("(%p)\n", This);
654 return E_NOTIMPL;
655 }
656
657 static HRESULT WINAPI OleInPlaceObject_SetObjectRects(IOleInPlaceObject *iface,
658 LPCRECT lprcPosRect, LPCRECT lprcClipRect)
659 {
660 WebBrowser *This = INPLACEOBJ_THIS(iface);
661
662 TRACE("(%p)->(%p %p)\n", This, lprcPosRect, lprcClipRect);
663
664 This->pos_rect = *lprcPosRect;
665
666 if(lprcClipRect)
667 This->clip_rect = *lprcClipRect;
668
669 if(This->shell_embedding_hwnd) {
670 SetWindowPos(This->shell_embedding_hwnd, NULL,
671 lprcPosRect->left, lprcPosRect->top,
672 lprcPosRect->right-lprcPosRect->left,
673 lprcPosRect->bottom-lprcPosRect->top,
674 SWP_NOZORDER | SWP_NOACTIVATE);
675 }
676
677 return S_OK;
678 }
679
680 static HRESULT WINAPI OleInPlaceObject_ReactivateAndUndo(IOleInPlaceObject *iface)
681 {
682 WebBrowser *This = INPLACEOBJ_THIS(iface);
683 FIXME("(%p)\n", This);
684 return E_NOTIMPL;
685 }
686
687 #undef INPLACEOBJ_THIS
688
689 static const IOleInPlaceObjectVtbl OleInPlaceObjectVtbl =
690 {
691 OleInPlaceObject_QueryInterface,
692 OleInPlaceObject_AddRef,
693 OleInPlaceObject_Release,
694 OleInPlaceObject_GetWindow,
695 OleInPlaceObject_ContextSensitiveHelp,
696 OleInPlaceObject_InPlaceDeactivate,
697 OleInPlaceObject_UIDeactivate,
698 OleInPlaceObject_SetObjectRects,
699 OleInPlaceObject_ReactivateAndUndo
700 };
701
702 /**********************************************************************
703 * Implement the IOleControl interface
704 */
705
706 #define CONTROL_THIS(iface) DEFINE_THIS(WebBrowser, OleControl, iface)
707
708 static HRESULT WINAPI OleControl_QueryInterface(IOleControl *iface,
709 REFIID riid, LPVOID *ppobj)
710 {
711 WebBrowser *This = CONTROL_THIS(iface);
712 return IWebBrowser_QueryInterface(WEBBROWSER(This), riid, ppobj);
713 }
714
715 static ULONG WINAPI OleControl_AddRef(IOleControl *iface)
716 {
717 WebBrowser *This = CONTROL_THIS(iface);
718 return IWebBrowser_AddRef(WEBBROWSER(This));
719 }
720
721 static ULONG WINAPI OleControl_Release(IOleControl *iface)
722 {
723 WebBrowser *This = CONTROL_THIS(iface);
724 return IWebBrowser_Release(WEBBROWSER(This));
725 }
726
727 static HRESULT WINAPI OleControl_GetControlInfo(IOleControl *iface, LPCONTROLINFO pCI)
728 {
729 WebBrowser *This = CONTROL_THIS(iface);
730
731 TRACE("(%p)->(%p)\n", This, pCI);
732
733 /* Tests show that this function should be not implemented */
734 return E_NOTIMPL;
735 }
736
737 static HRESULT WINAPI OleControl_OnMnemonic(IOleControl *iface, struct tagMSG *pMsg)
738 {
739 WebBrowser *This = CONTROL_THIS(iface);
740 FIXME("(%p)->(%p)\n", This, pMsg);
741 return E_NOTIMPL;
742 }
743
744 static HRESULT WINAPI OleControl_OnAmbientPropertyChange(IOleControl *iface, DISPID dispID)
745 {
746 WebBrowser *This = CONTROL_THIS(iface);
747
748 TRACE("(%p)->(%d)\n", This, dispID);
749
750 switch(dispID) {
751 case DISPID_UNKNOWN:
752 /* Unknown means multiple properties changed, so check them all.
753 * BUT the Webbrowser OleControl object doesn't appear to do this.
754 */
755 return S_OK;
756 case DISPID_AMBIENT_DLCONTROL:
757 return S_OK;
758 case DISPID_AMBIENT_OFFLINEIFNOTCONNECTED:
759 return on_offlineconnected_change(This);
760 case DISPID_AMBIENT_SILENT:
761 return on_silent_change(This);
762 }
763
764 FIXME("Unknown dispID %d\n", dispID);
765 return E_NOTIMPL;
766 }
767
768 static HRESULT WINAPI OleControl_FreezeEvents(IOleControl *iface, BOOL bFreeze)
769 {
770 WebBrowser *This = CONTROL_THIS(iface);
771 FIXME("(%p)->(%x)\n", This, bFreeze);
772 return E_NOTIMPL;
773 }
774
775 #undef CONTROL_THIS
776
777 static const IOleControlVtbl OleControlVtbl =
778 {
779 OleControl_QueryInterface,
780 OleControl_AddRef,
781 OleControl_Release,
782 OleControl_GetControlInfo,
783 OleControl_OnMnemonic,
784 OleControl_OnAmbientPropertyChange,
785 OleControl_FreezeEvents
786 };
787
788 #define ACTIVEOBJ_THIS(iface) DEFINE_THIS(WebBrowser, OleInPlaceActiveObject, iface)
789
790 static HRESULT WINAPI InPlaceActiveObject_QueryInterface(IOleInPlaceActiveObject *iface,
791 REFIID riid, void **ppv)
792 {
793 WebBrowser *This = ACTIVEOBJ_THIS(iface);
794 return IWebBrowser2_QueryInterface(WEBBROWSER2(This), riid, ppv);
795 }
796
797 static ULONG WINAPI InPlaceActiveObject_AddRef(IOleInPlaceActiveObject *iface)
798 {
799 WebBrowser *This = ACTIVEOBJ_THIS(iface);
800 return IWebBrowser2_AddRef(WEBBROWSER2(This));
801 }
802
803 static ULONG WINAPI InPlaceActiveObject_Release(IOleInPlaceActiveObject *iface)
804 {
805 WebBrowser *This = ACTIVEOBJ_THIS(iface);
806 return IWebBrowser2_Release(WEBBROWSER2(This));
807 }
808
809 static HRESULT WINAPI InPlaceActiveObject_GetWindow(IOleInPlaceActiveObject *iface,
810 HWND *phwnd)
811 {
812 WebBrowser *This = ACTIVEOBJ_THIS(iface);
813 return IOleInPlaceObject_GetWindow(INPLACEOBJ(This), phwnd);
814 }
815
816 static HRESULT WINAPI InPlaceActiveObject_ContextSensitiveHelp(IOleInPlaceActiveObject *iface,
817 BOOL fEnterMode)
818 {
819 WebBrowser *This = ACTIVEOBJ_THIS(iface);
820 return IOleInPlaceObject_ContextSensitiveHelp(INPLACEOBJ(This), fEnterMode);
821 }
822
823 static HRESULT WINAPI InPlaceActiveObject_TranslateAccelerator(IOleInPlaceActiveObject *iface,
824 LPMSG lpmsg)
825 {
826 WebBrowser *This = ACTIVEOBJ_THIS(iface);
827 FIXME("(%p)->(%p)\n", This, lpmsg);
828 return E_NOTIMPL;
829 }
830
831 static HRESULT WINAPI InPlaceActiveObject_OnFrameWindowActivate(IOleInPlaceActiveObject *iface,
832 BOOL fActivate)
833 {
834 WebBrowser *This = ACTIVEOBJ_THIS(iface);
835 FIXME("(%p)->(%x)\n", This, fActivate);
836 return E_NOTIMPL;
837 }
838
839 static HRESULT WINAPI InPlaceActiveObject_OnDocWindowActivate(IOleInPlaceActiveObject *iface,
840 BOOL fActivate)
841 {
842 WebBrowser *This = ACTIVEOBJ_THIS(iface);
843 FIXME("(%p)->(%x)\n", This, fActivate);
844 return E_NOTIMPL;
845 }
846
847 static HRESULT WINAPI InPlaceActiveObject_ResizeBorder(IOleInPlaceActiveObject *iface,
848 LPCRECT lprcBorder, IOleInPlaceUIWindow *pUIWindow, BOOL fFrameWindow)
849 {
850 WebBrowser *This = ACTIVEOBJ_THIS(iface);
851 FIXME("(%p)->(%p %p %x)\n", This, lprcBorder, pUIWindow, fFrameWindow);
852 return E_NOTIMPL;
853 }
854
855 static HRESULT WINAPI InPlaceActiveObject_EnableModeless(IOleInPlaceActiveObject *iface,
856 BOOL fEnable)
857 {
858 WebBrowser *This = ACTIVEOBJ_THIS(iface);
859 FIXME("(%p)->(%x)\n", This, fEnable);
860 return E_NOTIMPL;
861 }
862
863 #undef ACTIVEOBJ_THIS
864
865 static const IOleInPlaceActiveObjectVtbl OleInPlaceActiveObjectVtbl = {
866 InPlaceActiveObject_QueryInterface,
867 InPlaceActiveObject_AddRef,
868 InPlaceActiveObject_Release,
869 InPlaceActiveObject_GetWindow,
870 InPlaceActiveObject_ContextSensitiveHelp,
871 InPlaceActiveObject_TranslateAccelerator,
872 InPlaceActiveObject_OnFrameWindowActivate,
873 InPlaceActiveObject_OnDocWindowActivate,
874 InPlaceActiveObject_ResizeBorder,
875 InPlaceActiveObject_EnableModeless
876 };
877
878 #define OLECMD_THIS(iface) DEFINE_THIS(WebBrowser, OleCommandTarget, iface)
879
880 static HRESULT WINAPI WBOleCommandTarget_QueryInterface(IOleCommandTarget *iface,
881 REFIID riid, void **ppv)
882 {
883 WebBrowser *This = OLECMD_THIS(iface);
884 return IWebBrowser2_QueryInterface(WEBBROWSER(This), riid, ppv);
885 }
886
887 static ULONG WINAPI WBOleCommandTarget_AddRef(IOleCommandTarget *iface)
888 {
889 WebBrowser *This = OLECMD_THIS(iface);
890 return IWebBrowser2_AddRef(WEBBROWSER(This));
891 }
892
893 static ULONG WINAPI WBOleCommandTarget_Release(IOleCommandTarget *iface)
894 {
895 WebBrowser *This = OLECMD_THIS(iface);
896 return IWebBrowser2_Release(WEBBROWSER(This));
897 }
898
899 static HRESULT WINAPI WBOleCommandTarget_QueryStatus(IOleCommandTarget *iface,
900 const GUID *pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[], OLECMDTEXT *pCmdText)
901 {
902 WebBrowser *This = OLECMD_THIS(iface);
903 IOleCommandTarget *cmdtrg;
904 HRESULT hres;
905
906 TRACE("(%p)->(%s %u %p %p)\n", This, debugstr_guid(pguidCmdGroup), cCmds, prgCmds,
907 pCmdText);
908
909 if(!This->doc_host.document)
910 return 0x80040104;
911
912 /* NOTE: There are probably some commands that we should handle here
913 * instead of forwarding to document object. */
914
915 hres = IUnknown_QueryInterface(This->doc_host.document, &IID_IOleCommandTarget, (void**)&cmdtrg);
916 if(FAILED(hres))
917 return hres;
918
919 hres = IOleCommandTarget_QueryStatus(cmdtrg, pguidCmdGroup, cCmds, prgCmds, pCmdText);
920 IOleCommandTarget_Release(cmdtrg);
921
922 return hres;
923 }
924
925 static HRESULT WINAPI WBOleCommandTarget_Exec(IOleCommandTarget *iface,
926 const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn,
927 VARIANT *pvaOut)
928 {
929 WebBrowser *This = OLECMD_THIS(iface);
930 FIXME("(%p)->(%s %d %d %p %p)\n", This, debugstr_guid(pguidCmdGroup), nCmdID,
931 nCmdexecopt, pvaIn, pvaOut);
932 return E_NOTIMPL;
933 }
934
935 #undef OLECMD_THIS
936
937 static const IOleCommandTargetVtbl OleCommandTargetVtbl = {
938 WBOleCommandTarget_QueryInterface,
939 WBOleCommandTarget_AddRef,
940 WBOleCommandTarget_Release,
941 WBOleCommandTarget_QueryStatus,
942 WBOleCommandTarget_Exec
943 };
944
945 void WebBrowser_OleObject_Init(WebBrowser *This)
946 {
947 DWORD dpi_x;
948 DWORD dpi_y;
949 HDC hdc;
950
951 /* default aspect ratio is 96dpi / 96dpi */
952 hdc = GetDC(0);
953 dpi_x = GetDeviceCaps(hdc, LOGPIXELSX);
954 dpi_y = GetDeviceCaps(hdc, LOGPIXELSY);
955 ReleaseDC(0, hdc);
956
957 This->lpOleObjectVtbl = &OleObjectVtbl;
958 This->lpOleInPlaceObjectVtbl = &OleInPlaceObjectVtbl;
959 This->lpOleControlVtbl = &OleControlVtbl;
960 This->lpOleInPlaceActiveObjectVtbl = &OleInPlaceActiveObjectVtbl;
961 This->lpOleCommandTargetVtbl = &OleCommandTargetVtbl;
962
963 /* Default size is 50x20 pixels, in himetric units */
964 This->extent.cx = MulDiv( 50, 2540, dpi_x );
965 This->extent.cy = MulDiv( 20, 2540, dpi_y );
966 }
967
968 void WebBrowser_OleObject_Destroy(WebBrowser *This)
969 {
970 release_client_site(This);
971 }