ieframe: Release client site interface before destroying embedding window.
[wine.git] / dlls / ieframe / oleobject.c
blob462cf7497ecb758fac08080de842237a0cf8e9af
1 /*
2 * Implementation of IOleObject interfaces for WebBrowser control
4 * - IOleObject
5 * - IOleInPlaceObject
6 * - IOleControl
8 * Copyright 2001 John R. Sheets (for CodeWeavers)
9 * Copyright 2005 Jacek Caban
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.
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.
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
26 #include <string.h>
28 #include "ieframe.h"
30 #include "htiframe.h"
31 #include "idispids.h"
32 #include "mshtmdid.h"
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(ieframe);
38 /* shlwapi.dll */
39 HWND WINAPI SHSetParentHwnd(HWND hWnd, HWND hWndParent);
41 static ATOM shell_embedding_atom = 0;
43 static LRESULT resize_window(WebBrowser *This, LONG width, LONG height)
45 if(This->doc_host.hwnd)
46 SetWindowPos(This->doc_host.hwnd, NULL, 0, 0, width, height,
47 SWP_NOZORDER | SWP_NOACTIVATE);
49 return 0;
52 static LRESULT WINAPI shell_embedding_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
54 WebBrowser *This;
56 static const WCHAR wszTHIS[] = {'T','H','I','S',0};
58 if(msg == WM_CREATE) {
59 This = *(WebBrowser**)lParam;
60 SetPropW(hwnd, wszTHIS, This);
61 }else {
62 This = GetPropW(hwnd, wszTHIS);
65 switch(msg) {
66 case WM_SIZE:
67 return resize_window(This, LOWORD(lParam), HIWORD(lParam));
68 case WM_DOCHOSTTASK:
69 return process_dochost_tasks(&This->doc_host);
72 return DefWindowProcW(hwnd, msg, wParam, lParam);
75 static void create_shell_embedding_hwnd(WebBrowser *This)
77 IOleInPlaceSite *inplace;
78 HWND parent = NULL;
79 HRESULT hres;
81 static const WCHAR wszShellEmbedding[] =
82 {'S','h','e','l','l',' ','E','m','b','e','d','d','i','n','g',0};
84 if(!shell_embedding_atom) {
85 static WNDCLASSEXW wndclass = {
86 sizeof(wndclass),
87 CS_DBLCLKS,
88 shell_embedding_proc,
89 0, 0 /* native uses 8 */, NULL, NULL, NULL,
90 (HBRUSH)(COLOR_WINDOW + 1), NULL,
91 wszShellEmbedding,
92 NULL
94 wndclass.hInstance = ieframe_instance;
96 RegisterClassExW(&wndclass);
99 hres = IOleClientSite_QueryInterface(This->client, &IID_IOleInPlaceSite, (void**)&inplace);
100 if(SUCCEEDED(hres)) {
101 IOleInPlaceSite_GetWindow(inplace, &parent);
102 IOleInPlaceSite_Release(inplace);
105 This->doc_host.frame_hwnd = This->shell_embedding_hwnd = CreateWindowExW(
106 WS_EX_WINDOWEDGE,
107 wszShellEmbedding, wszShellEmbedding,
108 WS_CLIPSIBLINGS | WS_CLIPCHILDREN
109 | (parent ? WS_CHILD | WS_TABSTOP : WS_POPUP | WS_MAXIMIZEBOX),
110 0, 0, 0, 0, parent,
111 NULL, ieframe_instance, This);
113 TRACE("parent=%p hwnd=%p\n", parent, This->shell_embedding_hwnd);
116 static HRESULT activate_inplace(WebBrowser *This, IOleClientSite *active_site)
118 HWND parent_hwnd;
119 HRESULT hres;
121 if(This->inplace)
122 return S_OK;
124 if(!active_site)
125 return E_INVALIDARG;
127 hres = IOleClientSite_QueryInterface(active_site, &IID_IOleInPlaceSite,
128 (void**)&This->inplace);
129 if(FAILED(hres)) {
130 WARN("Could not get IOleInPlaceSite\n");
131 return hres;
134 hres = IOleInPlaceSiteEx_CanInPlaceActivate(This->inplace);
135 if(hres != S_OK) {
136 WARN("CanInPlaceActivate returned: %08x\n", hres);
137 IOleInPlaceSiteEx_Release(This->inplace);
138 This->inplace = NULL;
139 return E_FAIL;
142 hres = IOleInPlaceSiteEx_GetWindow(This->inplace, &parent_hwnd);
143 if(SUCCEEDED(hres))
144 SHSetParentHwnd(This->shell_embedding_hwnd, parent_hwnd);
146 IOleInPlaceSiteEx_OnInPlaceActivate(This->inplace);
148 This->frameinfo.cb = sizeof(OLEINPLACEFRAMEINFO);
149 IOleInPlaceSiteEx_GetWindowContext(This->inplace, &This->doc_host.frame, &This->uiwindow,
150 &This->pos_rect, &This->clip_rect,
151 &This->frameinfo);
153 SetWindowPos(This->shell_embedding_hwnd, NULL,
154 This->pos_rect.left, This->pos_rect.top,
155 This->pos_rect.right-This->pos_rect.left,
156 This->pos_rect.bottom-This->pos_rect.top,
157 SWP_NOZORDER | SWP_SHOWWINDOW);
159 if(This->client) {
160 IOleContainer *container;
162 IOleClientSite_ShowObject(This->client);
164 hres = IOleClientSite_GetContainer(This->client, &container);
165 if(SUCCEEDED(hres)) {
166 if(This->container)
167 IOleContainer_Release(This->container);
168 This->container = container;
172 if(This->doc_host.frame)
173 IOleInPlaceFrame_GetWindow(This->doc_host.frame, &This->frame_hwnd);
175 return S_OK;
178 static HRESULT activate_ui(WebBrowser *This, IOleClientSite *active_site)
180 HRESULT hres;
182 static const WCHAR wszitem[] = {'i','t','e','m',0};
184 if(This->inplace)
186 if(This->shell_embedding_hwnd)
187 ShowWindow(This->shell_embedding_hwnd, SW_SHOW);
188 return S_OK;
191 hres = activate_inplace(This, active_site);
192 if(FAILED(hres))
193 return hres;
195 IOleInPlaceSiteEx_OnUIActivate(This->inplace);
197 if(This->doc_host.frame)
198 IOleInPlaceFrame_SetActiveObject(This->doc_host.frame, &This->IOleInPlaceActiveObject_iface, wszitem);
199 if(This->uiwindow)
200 IOleInPlaceUIWindow_SetActiveObject(This->uiwindow, &This->IOleInPlaceActiveObject_iface, wszitem);
202 if(This->doc_host.frame)
203 IOleInPlaceFrame_SetMenu(This->doc_host.frame, NULL, NULL, This->shell_embedding_hwnd);
205 SetFocus(This->shell_embedding_hwnd);
207 return S_OK;
210 static HRESULT get_client_disp_property(IOleClientSite *client, DISPID dispid, VARIANT *res)
212 IDispatch *disp = NULL;
213 DISPPARAMS dispparams = {NULL, 0};
214 HRESULT hres;
216 VariantInit(res);
218 if(!client)
219 return S_OK;
221 hres = IOleClientSite_QueryInterface(client, &IID_IDispatch, (void**)&disp);
222 if(FAILED(hres)) {
223 TRACE("Could not get IDispatch\n");
224 return hres;
227 hres = IDispatch_Invoke(disp, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
228 DISPATCH_PROPERTYGET, &dispparams, res, NULL, NULL);
230 IDispatch_Release(disp);
232 return hres;
235 static HRESULT on_offlineconnected_change(WebBrowser *This)
237 VARIANT offline;
239 get_client_disp_property(This->client, DISPID_AMBIENT_OFFLINEIFNOTCONNECTED, &offline);
241 if(V_VT(&offline) == VT_BOOL)
242 IWebBrowser2_put_Offline(&This->IWebBrowser2_iface, V_BOOL(&offline));
243 else if(V_VT(&offline) != VT_EMPTY)
244 WARN("wrong V_VT(silent) %d\n", V_VT(&offline));
246 return S_OK;
249 static HRESULT on_silent_change(WebBrowser *This)
251 VARIANT silent;
253 get_client_disp_property(This->client, DISPID_AMBIENT_SILENT, &silent);
255 if(V_VT(&silent) == VT_BOOL)
256 IWebBrowser2_put_Silent(&This->IWebBrowser2_iface, V_BOOL(&silent));
257 else if(V_VT(&silent) != VT_EMPTY)
258 WARN("wrong V_VT(silent) %d\n", V_VT(&silent));
260 return S_OK;
263 static void release_client_site(WebBrowser *This)
265 release_dochost_client(&This->doc_host);
267 if(This->client) {
268 IOleClientSite_Release(This->client);
269 This->client = NULL;
272 if(This->shell_embedding_hwnd) {
273 DestroyWindow(This->shell_embedding_hwnd);
274 This->shell_embedding_hwnd = NULL;
277 if(This->inplace) {
278 IOleInPlaceSiteEx_Release(This->inplace);
279 This->inplace = NULL;
282 if(This->container) {
283 IOleContainer_Release(This->container);
284 This->container = NULL;
287 if(This->uiwindow) {
288 IOleInPlaceUIWindow_Release(This->uiwindow);
289 This->uiwindow = NULL;
292 if(This->sink) {
293 IAdviseSink_Release(This->sink);
294 This->sink = NULL;
298 typedef struct {
299 IEnumOLEVERB IEnumOLEVERB_iface;
300 LONG ref;
301 LONG iter;
302 } EnumOLEVERB;
304 static inline EnumOLEVERB *impl_from_IEnumOLEVERB(IEnumOLEVERB *iface)
306 return CONTAINING_RECORD(iface, EnumOLEVERB, IEnumOLEVERB_iface);
309 static HRESULT WINAPI EnumOLEVERB_QueryInterface(IEnumOLEVERB *iface, REFIID riid, void **ppv)
311 EnumOLEVERB *This = impl_from_IEnumOLEVERB(iface);
313 if(IsEqualGUID(&IID_IUnknown, riid)) {
314 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
315 *ppv = &This->IEnumOLEVERB_iface;
316 }else if(IsEqualGUID(&IID_IEnumOLEVERB, riid)) {
317 TRACE("(%p)->(IID_IEnumOLEVERB %p)\n", This, ppv);
318 *ppv = &This->IEnumOLEVERB_iface;
319 }else {
320 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
321 *ppv = NULL;
322 return E_NOINTERFACE;
325 IUnknown_AddRef((IUnknown*)*ppv);
326 return S_OK;
329 static ULONG WINAPI EnumOLEVERB_AddRef(IEnumOLEVERB *iface)
331 EnumOLEVERB *This = impl_from_IEnumOLEVERB(iface);
332 LONG ref = InterlockedIncrement(&This->ref);
334 TRACE("(%p) ref=%d\n", This, ref);
336 return ref;
339 static ULONG WINAPI EnumOLEVERB_Release(IEnumOLEVERB *iface)
341 EnumOLEVERB *This = impl_from_IEnumOLEVERB(iface);
342 LONG ref = InterlockedDecrement(&This->ref);
344 TRACE("(%p) ref=%d\n", This, ref);
346 if(!ref)
347 heap_free(This);
349 return ref;
352 static HRESULT WINAPI EnumOLEVERB_Next(IEnumOLEVERB *iface, ULONG celt, OLEVERB *rgelt, ULONG *pceltFetched)
354 EnumOLEVERB *This = impl_from_IEnumOLEVERB(iface);
356 static const OLEVERB verbs[] =
357 {{OLEIVERB_PRIMARY},{OLEIVERB_INPLACEACTIVATE},{OLEIVERB_UIACTIVATE},{OLEIVERB_SHOW},{OLEIVERB_HIDE}};
359 TRACE("(%p)->(%u %p %p)\n", This, celt, rgelt, pceltFetched);
361 /* There are a few problems with this implementation, but that's how it seems to work in native. See tests. */
362 if(pceltFetched)
363 *pceltFetched = 0;
365 if(This->iter == sizeof(verbs)/sizeof(*verbs))
366 return S_FALSE;
368 if(celt)
369 *rgelt = verbs[This->iter++];
370 return S_OK;
373 static HRESULT WINAPI EnumOLEVERB_Skip(IEnumOLEVERB *iface, ULONG celt)
375 EnumOLEVERB *This = impl_from_IEnumOLEVERB(iface);
376 TRACE("(%p)->(%u)\n", This, celt);
377 return S_OK;
380 static HRESULT WINAPI EnumOLEVERB_Reset(IEnumOLEVERB *iface)
382 EnumOLEVERB *This = impl_from_IEnumOLEVERB(iface);
384 TRACE("(%p)\n", This);
386 This->iter = 0;
387 return S_OK;
390 static HRESULT WINAPI EnumOLEVERB_Clone(IEnumOLEVERB *iface, IEnumOLEVERB **ppenum)
392 EnumOLEVERB *This = impl_from_IEnumOLEVERB(iface);
393 FIXME("(%p)->(%p)\n", This, ppenum);
394 return E_NOTIMPL;
397 static const IEnumOLEVERBVtbl EnumOLEVERBVtbl = {
398 EnumOLEVERB_QueryInterface,
399 EnumOLEVERB_AddRef,
400 EnumOLEVERB_Release,
401 EnumOLEVERB_Next,
402 EnumOLEVERB_Skip,
403 EnumOLEVERB_Reset,
404 EnumOLEVERB_Clone
407 /**********************************************************************
408 * Implement the IOleObject interface for the WebBrowser control
411 static inline WebBrowser *impl_from_IOleObject(IOleObject *iface)
413 return CONTAINING_RECORD(iface, WebBrowser, IOleObject_iface);
416 static HRESULT WINAPI OleObject_QueryInterface(IOleObject *iface, REFIID riid, void **ppv)
418 WebBrowser *This = impl_from_IOleObject(iface);
419 return IWebBrowser2_QueryInterface(&This->IWebBrowser2_iface, riid, ppv);
422 static ULONG WINAPI OleObject_AddRef(IOleObject *iface)
424 WebBrowser *This = impl_from_IOleObject(iface);
425 return IWebBrowser2_AddRef(&This->IWebBrowser2_iface);
428 static ULONG WINAPI OleObject_Release(IOleObject *iface)
430 WebBrowser *This = impl_from_IOleObject(iface);
431 return IWebBrowser2_Release(&This->IWebBrowser2_iface);
434 static HRESULT WINAPI OleObject_SetClientSite(IOleObject *iface, LPOLECLIENTSITE pClientSite)
436 WebBrowser *This = impl_from_IOleObject(iface);
437 IDocHostUIHandler *hostui;
438 IOleContainer *container;
439 IDispatch *disp;
440 HRESULT hres;
442 TRACE("(%p)->(%p)\n", This, pClientSite);
444 if(This->client == pClientSite)
445 return S_OK;
447 release_client_site(This);
449 if(!pClientSite) {
450 on_commandstate_change(&This->doc_host, CSC_NAVIGATEBACK, VARIANT_FALSE);
451 on_commandstate_change(&This->doc_host, CSC_NAVIGATEFORWARD, VARIANT_FALSE);
453 if(This->doc_host.document)
454 deactivate_document(&This->doc_host);
455 return S_OK;
458 IOleClientSite_AddRef(pClientSite);
459 This->client = pClientSite;
461 hres = IOleClientSite_QueryInterface(This->client, &IID_IDispatch,
462 (void**)&disp);
463 if(SUCCEEDED(hres))
464 This->doc_host.client_disp = disp;
466 hres = IOleClientSite_QueryInterface(This->client, &IID_IDocHostUIHandler,
467 (void**)&hostui);
468 if(SUCCEEDED(hres))
469 This->doc_host.hostui = hostui;
471 hres = IOleClientSite_GetContainer(This->client, &container);
472 if(SUCCEEDED(hres)) {
473 ITargetContainer *target_container;
475 hres = IOleContainer_QueryInterface(container, &IID_ITargetContainer,
476 (void**)&target_container);
477 if(SUCCEEDED(hres)) {
478 FIXME("Unsupported ITargetContainer\n");
479 ITargetContainer_Release(target_container);
482 IOleContainer_Release(container);
485 create_shell_embedding_hwnd(This);
487 on_offlineconnected_change(This);
488 on_silent_change(This);
490 return S_OK;
493 static HRESULT WINAPI OleObject_GetClientSite(IOleObject *iface, LPOLECLIENTSITE *ppClientSite)
495 WebBrowser *This = impl_from_IOleObject(iface);
497 TRACE("(%p)->(%p)\n", This, ppClientSite);
499 if(!ppClientSite)
500 return E_INVALIDARG;
502 if(This->client)
503 IOleClientSite_AddRef(This->client);
504 *ppClientSite = This->client;
506 return S_OK;
509 static HRESULT WINAPI OleObject_SetHostNames(IOleObject *iface, LPCOLESTR szContainerApp,
510 LPCOLESTR szContainerObj)
512 WebBrowser *This = impl_from_IOleObject(iface);
514 TRACE("(%p)->(%s, %s)\n", This, debugstr_w(szContainerApp), debugstr_w(szContainerObj));
516 /* We have nothing to do here. */
517 return S_OK;
520 static HRESULT WINAPI OleObject_Close(IOleObject *iface, DWORD dwSaveOption)
522 WebBrowser *This = impl_from_IOleObject(iface);
524 TRACE("(%p)->(%d)\n", This, dwSaveOption);
526 if(dwSaveOption != OLECLOSE_NOSAVE) {
527 FIXME("unimplemented flag: %x\n", dwSaveOption);
528 return E_NOTIMPL;
531 if(This->doc_host.frame)
532 IOleInPlaceFrame_SetActiveObject(This->doc_host.frame, NULL, NULL);
534 if(This->uiwindow)
535 IOleInPlaceUIWindow_SetActiveObject(This->uiwindow, NULL, NULL);
537 if(This->inplace) {
538 IOleInPlaceSiteEx_OnUIDeactivate(This->inplace, FALSE);
539 IOleInPlaceSiteEx_OnInPlaceDeactivate(This->inplace);
542 return IOleObject_SetClientSite(iface, NULL);
545 static HRESULT WINAPI OleObject_SetMoniker(IOleObject *iface, DWORD dwWhichMoniker, IMoniker* pmk)
547 WebBrowser *This = impl_from_IOleObject(iface);
548 FIXME("(%p)->(%d, %p)\n", This, dwWhichMoniker, pmk);
549 return E_NOTIMPL;
552 static HRESULT WINAPI OleObject_GetMoniker(IOleObject *iface, DWORD dwAssign,
553 DWORD dwWhichMoniker, LPMONIKER *ppmk)
555 WebBrowser *This = impl_from_IOleObject(iface);
556 FIXME("(%p)->(%d, %d, %p)\n", This, dwAssign, dwWhichMoniker, ppmk);
557 return E_NOTIMPL;
560 static HRESULT WINAPI OleObject_InitFromData(IOleObject *iface, LPDATAOBJECT pDataObject,
561 BOOL fCreation, DWORD dwReserved)
563 WebBrowser *This = impl_from_IOleObject(iface);
564 FIXME("(%p)->(%p, %d, %d)\n", This, pDataObject, fCreation, dwReserved);
565 return E_NOTIMPL;
568 static HRESULT WINAPI OleObject_GetClipboardData(IOleObject *iface, DWORD dwReserved,
569 LPDATAOBJECT *ppDataObject)
571 WebBrowser *This = impl_from_IOleObject(iface);
572 FIXME("(%p)->(%d, %p)\n", This, dwReserved, ppDataObject);
573 return E_NOTIMPL;
576 static HRESULT WINAPI OleObject_DoVerb(IOleObject *iface, LONG iVerb, struct tagMSG* lpmsg,
577 LPOLECLIENTSITE pActiveSite, LONG lindex, HWND hwndParent, LPCRECT lprcPosRect)
579 WebBrowser *This = impl_from_IOleObject(iface);
581 TRACE("(%p)->(%d %p %p %d %p %s)\n", This, iVerb, lpmsg, pActiveSite, lindex, hwndParent,
582 wine_dbgstr_rect(lprcPosRect));
584 switch (iVerb)
586 case OLEIVERB_SHOW:
587 TRACE("OLEIVERB_SHOW\n");
588 return activate_ui(This, pActiveSite);
589 case OLEIVERB_UIACTIVATE:
590 TRACE("OLEIVERB_UIACTIVATE\n");
591 return activate_ui(This, pActiveSite);
592 case OLEIVERB_INPLACEACTIVATE:
593 TRACE("OLEIVERB_INPLACEACTIVATE\n");
594 return activate_inplace(This, pActiveSite);
595 case OLEIVERB_HIDE:
596 TRACE("OLEIVERB_HIDE\n");
597 if(This->inplace)
598 IOleInPlaceSiteEx_OnInPlaceDeactivate(This->inplace);
599 if(This->shell_embedding_hwnd)
600 ShowWindow(This->shell_embedding_hwnd, SW_HIDE);
601 return S_OK;
602 default:
603 FIXME("stub for %d\n", iVerb);
604 break;
607 return E_NOTIMPL;
610 static HRESULT WINAPI OleObject_EnumVerbs(IOleObject *iface, IEnumOLEVERB **ppEnumOleVerb)
612 WebBrowser *This = impl_from_IOleObject(iface);
613 EnumOLEVERB *ret;
615 TRACE("(%p)->(%p)\n", This, ppEnumOleVerb);
617 ret = heap_alloc(sizeof(*ret));
618 if(!ret)
619 return E_OUTOFMEMORY;
621 ret->IEnumOLEVERB_iface.lpVtbl = &EnumOLEVERBVtbl;
622 ret->ref = 1;
623 ret->iter = 0;
625 *ppEnumOleVerb = &ret->IEnumOLEVERB_iface;
626 return S_OK;
629 static HRESULT WINAPI OleObject_Update(IOleObject *iface)
631 WebBrowser *This = impl_from_IOleObject(iface);
632 FIXME("(%p)\n", This);
633 return E_NOTIMPL;
636 static HRESULT WINAPI OleObject_IsUpToDate(IOleObject *iface)
638 WebBrowser *This = impl_from_IOleObject(iface);
639 FIXME("(%p)\n", This);
640 return E_NOTIMPL;
643 static HRESULT WINAPI OleObject_GetUserClassID(IOleObject *iface, CLSID* pClsid)
645 WebBrowser *This = impl_from_IOleObject(iface);
646 FIXME("(%p)->(%p)\n", This, pClsid);
647 return E_NOTIMPL;
650 static HRESULT WINAPI OleObject_GetUserType(IOleObject *iface, DWORD dwFormOfType,
651 LPOLESTR* pszUserType)
653 WebBrowser *This = impl_from_IOleObject(iface);
654 TRACE("(%p, %d, %p)\n", This, dwFormOfType, pszUserType);
655 return OleRegGetUserType(&CLSID_WebBrowser, dwFormOfType, pszUserType);
658 static HRESULT WINAPI OleObject_SetExtent(IOleObject *iface, DWORD dwDrawAspect, SIZEL *psizel)
660 WebBrowser *This = impl_from_IOleObject(iface);
662 TRACE("(%p)->(%x %p)\n", This, dwDrawAspect, psizel);
664 /* Tests show that dwDrawAspect is ignored */
665 This->extent = *psizel;
666 return S_OK;
669 static HRESULT WINAPI OleObject_GetExtent(IOleObject *iface, DWORD dwDrawAspect, SIZEL *psizel)
671 WebBrowser *This = impl_from_IOleObject(iface);
673 TRACE("(%p)->(%x, %p)\n", This, dwDrawAspect, psizel);
675 /* Tests show that dwDrawAspect is ignored */
676 *psizel = This->extent;
677 return S_OK;
680 static HRESULT WINAPI OleObject_Advise(IOleObject *iface, IAdviseSink *pAdvSink,
681 DWORD* pdwConnection)
683 WebBrowser *This = impl_from_IOleObject(iface);
684 FIXME("(%p)->(%p, %p)\n", This, pAdvSink, pdwConnection);
685 return E_NOTIMPL;
688 static HRESULT WINAPI OleObject_Unadvise(IOleObject *iface, DWORD dwConnection)
690 WebBrowser *This = impl_from_IOleObject(iface);
691 FIXME("(%p)->(%d)\n", This, dwConnection);
692 return E_NOTIMPL;
695 static HRESULT WINAPI OleObject_EnumAdvise(IOleObject *iface, IEnumSTATDATA **ppenumAdvise)
697 WebBrowser *This = impl_from_IOleObject(iface);
698 FIXME("(%p)->(%p)\n", This, ppenumAdvise);
699 return S_OK;
702 static HRESULT WINAPI OleObject_GetMiscStatus(IOleObject *iface, DWORD dwAspect, DWORD *pdwStatus)
704 WebBrowser *This = impl_from_IOleObject(iface);
706 TRACE("(%p)->(%x, %p)\n", This, dwAspect, pdwStatus);
708 *pdwStatus = OLEMISC_SETCLIENTSITEFIRST|OLEMISC_ACTIVATEWHENVISIBLE|OLEMISC_INSIDEOUT
709 |OLEMISC_CANTLINKINSIDE|OLEMISC_RECOMPOSEONRESIZE;
711 return S_OK;
714 static HRESULT WINAPI OleObject_SetColorScheme(IOleObject *iface, LOGPALETTE* pLogpal)
716 WebBrowser *This = impl_from_IOleObject(iface);
717 FIXME("(%p)->(%p)\n", This, pLogpal);
718 return E_NOTIMPL;
721 static const IOleObjectVtbl OleObjectVtbl =
723 OleObject_QueryInterface,
724 OleObject_AddRef,
725 OleObject_Release,
726 OleObject_SetClientSite,
727 OleObject_GetClientSite,
728 OleObject_SetHostNames,
729 OleObject_Close,
730 OleObject_SetMoniker,
731 OleObject_GetMoniker,
732 OleObject_InitFromData,
733 OleObject_GetClipboardData,
734 OleObject_DoVerb,
735 OleObject_EnumVerbs,
736 OleObject_Update,
737 OleObject_IsUpToDate,
738 OleObject_GetUserClassID,
739 OleObject_GetUserType,
740 OleObject_SetExtent,
741 OleObject_GetExtent,
742 OleObject_Advise,
743 OleObject_Unadvise,
744 OleObject_EnumAdvise,
745 OleObject_GetMiscStatus,
746 OleObject_SetColorScheme
749 /**********************************************************************
750 * Implement the IOleInPlaceObject interface
753 static inline WebBrowser *impl_from_IOleInPlaceObject(IOleInPlaceObject *iface)
755 return CONTAINING_RECORD(iface, WebBrowser, IOleInPlaceObject_iface);
758 static HRESULT WINAPI OleInPlaceObject_QueryInterface(IOleInPlaceObject *iface,
759 REFIID riid, LPVOID *ppobj)
761 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
762 return IWebBrowser2_QueryInterface(&This->IWebBrowser2_iface, riid, ppobj);
765 static ULONG WINAPI OleInPlaceObject_AddRef(IOleInPlaceObject *iface)
767 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
768 return IWebBrowser2_AddRef(&This->IWebBrowser2_iface);
771 static ULONG WINAPI OleInPlaceObject_Release(IOleInPlaceObject *iface)
773 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
774 return IWebBrowser2_Release(&This->IWebBrowser2_iface);
777 static HRESULT WINAPI OleInPlaceObject_GetWindow(IOleInPlaceObject *iface, HWND* phwnd)
779 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
781 TRACE("(%p)->(%p)\n", This, phwnd);
783 *phwnd = This->shell_embedding_hwnd;
784 return S_OK;
787 static HRESULT WINAPI OleInPlaceObject_ContextSensitiveHelp(IOleInPlaceObject *iface,
788 BOOL fEnterMode)
790 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
791 FIXME("(%p)->(%x)\n", This, fEnterMode);
792 return E_NOTIMPL;
795 static HRESULT WINAPI OleInPlaceObject_InPlaceDeactivate(IOleInPlaceObject *iface)
797 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
798 FIXME("(%p)\n", This);
800 if(This->inplace) {
801 IOleInPlaceSiteEx_Release(This->inplace);
802 This->inplace = NULL;
805 return S_OK;
808 static HRESULT WINAPI OleInPlaceObject_UIDeactivate(IOleInPlaceObject *iface)
810 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
811 FIXME("(%p)\n", This);
812 return E_NOTIMPL;
815 static HRESULT WINAPI OleInPlaceObject_SetObjectRects(IOleInPlaceObject *iface,
816 LPCRECT lprcPosRect, LPCRECT lprcClipRect)
818 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
820 TRACE("(%p)->(%p %p)\n", This, lprcPosRect, lprcClipRect);
822 This->pos_rect = *lprcPosRect;
824 if(lprcClipRect)
825 This->clip_rect = *lprcClipRect;
827 if(This->shell_embedding_hwnd) {
828 SetWindowPos(This->shell_embedding_hwnd, NULL,
829 lprcPosRect->left, lprcPosRect->top,
830 lprcPosRect->right-lprcPosRect->left,
831 lprcPosRect->bottom-lprcPosRect->top,
832 SWP_NOZORDER | SWP_NOACTIVATE);
835 return S_OK;
838 static HRESULT WINAPI OleInPlaceObject_ReactivateAndUndo(IOleInPlaceObject *iface)
840 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
841 FIXME("(%p)\n", This);
842 return E_NOTIMPL;
845 static const IOleInPlaceObjectVtbl OleInPlaceObjectVtbl =
847 OleInPlaceObject_QueryInterface,
848 OleInPlaceObject_AddRef,
849 OleInPlaceObject_Release,
850 OleInPlaceObject_GetWindow,
851 OleInPlaceObject_ContextSensitiveHelp,
852 OleInPlaceObject_InPlaceDeactivate,
853 OleInPlaceObject_UIDeactivate,
854 OleInPlaceObject_SetObjectRects,
855 OleInPlaceObject_ReactivateAndUndo
858 /**********************************************************************
859 * Implement the IOleControl interface
862 static inline WebBrowser *impl_from_IOleControl(IOleControl *iface)
864 return CONTAINING_RECORD(iface, WebBrowser, IOleControl_iface);
867 static HRESULT WINAPI OleControl_QueryInterface(IOleControl *iface,
868 REFIID riid, LPVOID *ppobj)
870 WebBrowser *This = impl_from_IOleControl(iface);
871 return IWebBrowser2_QueryInterface(&This->IWebBrowser2_iface, riid, ppobj);
874 static ULONG WINAPI OleControl_AddRef(IOleControl *iface)
876 WebBrowser *This = impl_from_IOleControl(iface);
877 return IWebBrowser2_AddRef(&This->IWebBrowser2_iface);
880 static ULONG WINAPI OleControl_Release(IOleControl *iface)
882 WebBrowser *This = impl_from_IOleControl(iface);
883 return IWebBrowser2_Release(&This->IWebBrowser2_iface);
886 static HRESULT WINAPI OleControl_GetControlInfo(IOleControl *iface, LPCONTROLINFO pCI)
888 WebBrowser *This = impl_from_IOleControl(iface);
890 TRACE("(%p)->(%p)\n", This, pCI);
892 /* Tests show that this function should be not implemented */
893 return E_NOTIMPL;
896 static HRESULT WINAPI OleControl_OnMnemonic(IOleControl *iface, struct tagMSG *pMsg)
898 WebBrowser *This = impl_from_IOleControl(iface);
899 FIXME("(%p)->(%p)\n", This, pMsg);
900 return E_NOTIMPL;
903 static HRESULT WINAPI OleControl_OnAmbientPropertyChange(IOleControl *iface, DISPID dispID)
905 WebBrowser *This = impl_from_IOleControl(iface);
907 TRACE("(%p)->(%d)\n", This, dispID);
909 switch(dispID) {
910 case DISPID_UNKNOWN:
911 /* Unknown means multiple properties changed, so check them all.
912 * BUT the Webbrowser OleControl object doesn't appear to do this.
914 return S_OK;
915 case DISPID_AMBIENT_DLCONTROL:
916 return S_OK;
917 case DISPID_AMBIENT_OFFLINEIFNOTCONNECTED:
918 return on_offlineconnected_change(This);
919 case DISPID_AMBIENT_SILENT:
920 return on_silent_change(This);
923 FIXME("Unknown dispID %d\n", dispID);
924 return E_NOTIMPL;
927 static HRESULT WINAPI OleControl_FreezeEvents(IOleControl *iface, BOOL bFreeze)
929 WebBrowser *This = impl_from_IOleControl(iface);
930 FIXME("(%p)->(%x)\n", This, bFreeze);
931 return E_NOTIMPL;
934 static const IOleControlVtbl OleControlVtbl =
936 OleControl_QueryInterface,
937 OleControl_AddRef,
938 OleControl_Release,
939 OleControl_GetControlInfo,
940 OleControl_OnMnemonic,
941 OleControl_OnAmbientPropertyChange,
942 OleControl_FreezeEvents
945 static inline WebBrowser *impl_from_IOleInPlaceActiveObject(IOleInPlaceActiveObject *iface)
947 return CONTAINING_RECORD(iface, WebBrowser, IOleInPlaceActiveObject_iface);
950 static HRESULT WINAPI InPlaceActiveObject_QueryInterface(IOleInPlaceActiveObject *iface,
951 REFIID riid, void **ppv)
953 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
954 return IWebBrowser2_QueryInterface(&This->IWebBrowser2_iface, riid, ppv);
957 static ULONG WINAPI InPlaceActiveObject_AddRef(IOleInPlaceActiveObject *iface)
959 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
960 return IWebBrowser2_AddRef(&This->IWebBrowser2_iface);
963 static ULONG WINAPI InPlaceActiveObject_Release(IOleInPlaceActiveObject *iface)
965 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
966 return IWebBrowser2_Release(&This->IWebBrowser2_iface);
969 static HRESULT WINAPI InPlaceActiveObject_GetWindow(IOleInPlaceActiveObject *iface,
970 HWND *phwnd)
972 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
973 return IOleInPlaceObject_GetWindow(&This->IOleInPlaceObject_iface, phwnd);
976 static HRESULT WINAPI InPlaceActiveObject_ContextSensitiveHelp(IOleInPlaceActiveObject *iface,
977 BOOL fEnterMode)
979 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
980 return IOleInPlaceObject_ContextSensitiveHelp(&This->IOleInPlaceObject_iface, fEnterMode);
983 static HRESULT WINAPI InPlaceActiveObject_TranslateAccelerator(IOleInPlaceActiveObject *iface,
984 LPMSG lpmsg)
986 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
987 IOleInPlaceActiveObject *activeobj;
988 HRESULT hr = S_FALSE;
990 TRACE("(%p)->(%p)\n", This, lpmsg);
992 if(This->doc_host.document) {
993 if(SUCCEEDED(IUnknown_QueryInterface(This->doc_host.document,
994 &IID_IOleInPlaceActiveObject,
995 (void**)&activeobj))) {
996 hr = IOleInPlaceActiveObject_TranslateAccelerator(activeobj, lpmsg);
997 IOleInPlaceActiveObject_Release(activeobj);
1001 if(SUCCEEDED(hr))
1002 return hr;
1003 else
1004 return S_FALSE;
1007 static HRESULT WINAPI InPlaceActiveObject_OnFrameWindowActivate(IOleInPlaceActiveObject *iface,
1008 BOOL fActivate)
1010 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
1011 FIXME("(%p)->(%x)\n", This, fActivate);
1012 return E_NOTIMPL;
1015 static HRESULT WINAPI InPlaceActiveObject_OnDocWindowActivate(IOleInPlaceActiveObject *iface,
1016 BOOL fActivate)
1018 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
1019 FIXME("(%p)->(%x)\n", This, fActivate);
1020 return E_NOTIMPL;
1023 static HRESULT WINAPI InPlaceActiveObject_ResizeBorder(IOleInPlaceActiveObject *iface,
1024 LPCRECT lprcBorder, IOleInPlaceUIWindow *pUIWindow, BOOL fFrameWindow)
1026 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
1027 FIXME("(%p)->(%p %p %x)\n", This, lprcBorder, pUIWindow, fFrameWindow);
1028 return E_NOTIMPL;
1031 static HRESULT WINAPI InPlaceActiveObject_EnableModeless(IOleInPlaceActiveObject *iface,
1032 BOOL fEnable)
1034 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
1035 FIXME("(%p)->(%x)\n", This, fEnable);
1036 return E_NOTIMPL;
1039 static const IOleInPlaceActiveObjectVtbl OleInPlaceActiveObjectVtbl = {
1040 InPlaceActiveObject_QueryInterface,
1041 InPlaceActiveObject_AddRef,
1042 InPlaceActiveObject_Release,
1043 InPlaceActiveObject_GetWindow,
1044 InPlaceActiveObject_ContextSensitiveHelp,
1045 InPlaceActiveObject_TranslateAccelerator,
1046 InPlaceActiveObject_OnFrameWindowActivate,
1047 InPlaceActiveObject_OnDocWindowActivate,
1048 InPlaceActiveObject_ResizeBorder,
1049 InPlaceActiveObject_EnableModeless
1052 static inline WebBrowser *impl_from_IOleCommandTarget(IOleCommandTarget *iface)
1054 return CONTAINING_RECORD(iface, WebBrowser, IOleCommandTarget_iface);
1057 static HRESULT WINAPI WBOleCommandTarget_QueryInterface(IOleCommandTarget *iface,
1058 REFIID riid, void **ppv)
1060 WebBrowser *This = impl_from_IOleCommandTarget(iface);
1061 return IWebBrowser2_QueryInterface(&This->IWebBrowser2_iface, riid, ppv);
1064 static ULONG WINAPI WBOleCommandTarget_AddRef(IOleCommandTarget *iface)
1066 WebBrowser *This = impl_from_IOleCommandTarget(iface);
1067 return IWebBrowser2_AddRef(&This->IWebBrowser2_iface);
1070 static ULONG WINAPI WBOleCommandTarget_Release(IOleCommandTarget *iface)
1072 WebBrowser *This = impl_from_IOleCommandTarget(iface);
1073 return IWebBrowser2_Release(&This->IWebBrowser2_iface);
1076 static HRESULT WINAPI WBOleCommandTarget_QueryStatus(IOleCommandTarget *iface,
1077 const GUID *pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[], OLECMDTEXT *pCmdText)
1079 WebBrowser *This = impl_from_IOleCommandTarget(iface);
1080 IOleCommandTarget *cmdtrg;
1081 HRESULT hres;
1083 TRACE("(%p)->(%s %u %p %p)\n", This, debugstr_guid(pguidCmdGroup), cCmds, prgCmds,
1084 pCmdText);
1086 if(!This->doc_host.document)
1087 return 0x80040104;
1089 /* NOTE: There are probably some commands that we should handle here
1090 * instead of forwarding to document object. */
1092 hres = IUnknown_QueryInterface(This->doc_host.document, &IID_IOleCommandTarget, (void**)&cmdtrg);
1093 if(FAILED(hres))
1094 return hres;
1096 hres = IOleCommandTarget_QueryStatus(cmdtrg, pguidCmdGroup, cCmds, prgCmds, pCmdText);
1097 IOleCommandTarget_Release(cmdtrg);
1099 return hres;
1102 static HRESULT WINAPI WBOleCommandTarget_Exec(IOleCommandTarget *iface,
1103 const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn,
1104 VARIANT *pvaOut)
1106 WebBrowser *This = impl_from_IOleCommandTarget(iface);
1107 FIXME("(%p)->(%s %d %d %s %p)\n", This, debugstr_guid(pguidCmdGroup), nCmdID,
1108 nCmdexecopt, debugstr_variant(pvaIn), pvaOut);
1109 return E_NOTIMPL;
1112 static const IOleCommandTargetVtbl OleCommandTargetVtbl = {
1113 WBOleCommandTarget_QueryInterface,
1114 WBOleCommandTarget_AddRef,
1115 WBOleCommandTarget_Release,
1116 WBOleCommandTarget_QueryStatus,
1117 WBOleCommandTarget_Exec
1120 void WebBrowser_OleObject_Init(WebBrowser *This)
1122 DWORD dpi_x;
1123 DWORD dpi_y;
1124 HDC hdc;
1126 /* default aspect ratio is 96dpi / 96dpi */
1127 hdc = GetDC(0);
1128 dpi_x = GetDeviceCaps(hdc, LOGPIXELSX);
1129 dpi_y = GetDeviceCaps(hdc, LOGPIXELSY);
1130 ReleaseDC(0, hdc);
1132 This->IOleObject_iface.lpVtbl = &OleObjectVtbl;
1133 This->IOleInPlaceObject_iface.lpVtbl = &OleInPlaceObjectVtbl;
1134 This->IOleControl_iface.lpVtbl = &OleControlVtbl;
1135 This->IOleInPlaceActiveObject_iface.lpVtbl = &OleInPlaceActiveObjectVtbl;
1136 This->IOleCommandTarget_iface.lpVtbl = &OleCommandTargetVtbl;
1138 /* Default size is 50x20 pixels, in himetric units */
1139 This->extent.cx = MulDiv( 50, 2540, dpi_x );
1140 This->extent.cy = MulDiv( 20, 2540, dpi_y );
1143 void WebBrowser_OleObject_Destroy(WebBrowser *This)
1145 release_client_site(This);