d3d9/tests: Move a Present out of the loops in fog_with_shader_test().
[wine/multimedia.git] / dlls / ieframe / oleobject.c
blobe1dd37d59fb10165385afdcd8d85f368825d0014
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->shell_embedding_hwnd) {
268 DestroyWindow(This->shell_embedding_hwnd);
269 This->shell_embedding_hwnd = NULL;
272 if(This->inplace) {
273 IOleInPlaceSiteEx_Release(This->inplace);
274 This->inplace = NULL;
277 if(This->container) {
278 IOleContainer_Release(This->container);
279 This->container = NULL;
282 if(This->uiwindow) {
283 IOleInPlaceUIWindow_Release(This->uiwindow);
284 This->uiwindow = NULL;
287 if(This->client) {
288 IOleClientSite_Release(This->client);
289 This->client = NULL;
293 typedef struct {
294 IEnumOLEVERB IEnumOLEVERB_iface;
295 LONG ref;
296 LONG iter;
297 } EnumOLEVERB;
299 static inline EnumOLEVERB *impl_from_IEnumOLEVERB(IEnumOLEVERB *iface)
301 return CONTAINING_RECORD(iface, EnumOLEVERB, IEnumOLEVERB_iface);
304 static HRESULT WINAPI EnumOLEVERB_QueryInterface(IEnumOLEVERB *iface, REFIID riid, void **ppv)
306 EnumOLEVERB *This = impl_from_IEnumOLEVERB(iface);
308 if(IsEqualGUID(&IID_IUnknown, riid)) {
309 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
310 *ppv = &This->IEnumOLEVERB_iface;
311 }else if(IsEqualGUID(&IID_IEnumOLEVERB, riid)) {
312 TRACE("(%p)->(IID_IEnumOLEVERB %p)\n", This, ppv);
313 *ppv = &This->IEnumOLEVERB_iface;
314 }else {
315 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
316 *ppv = NULL;
317 return E_NOINTERFACE;
320 IUnknown_AddRef((IUnknown*)*ppv);
321 return S_OK;
324 static ULONG WINAPI EnumOLEVERB_AddRef(IEnumOLEVERB *iface)
326 EnumOLEVERB *This = impl_from_IEnumOLEVERB(iface);
327 LONG ref = InterlockedIncrement(&This->ref);
329 TRACE("(%p) ref=%d\n", This, ref);
331 return ref;
334 static ULONG WINAPI EnumOLEVERB_Release(IEnumOLEVERB *iface)
336 EnumOLEVERB *This = impl_from_IEnumOLEVERB(iface);
337 LONG ref = InterlockedDecrement(&This->ref);
339 TRACE("(%p) ref=%d\n", This, ref);
341 if(!ref)
342 heap_free(This);
344 return ref;
347 static HRESULT WINAPI EnumOLEVERB_Next(IEnumOLEVERB *iface, ULONG celt, OLEVERB *rgelt, ULONG *pceltFetched)
349 EnumOLEVERB *This = impl_from_IEnumOLEVERB(iface);
351 static const OLEVERB verbs[] =
352 {{OLEIVERB_PRIMARY},{OLEIVERB_INPLACEACTIVATE},{OLEIVERB_UIACTIVATE},{OLEIVERB_SHOW},{OLEIVERB_HIDE}};
354 TRACE("(%p)->(%u %p %p)\n", This, celt, rgelt, pceltFetched);
356 /* There are a few problems with this implementation, but that's how it seems to work in native. See tests. */
357 if(pceltFetched)
358 *pceltFetched = 0;
360 if(This->iter == sizeof(verbs)/sizeof(*verbs))
361 return S_FALSE;
363 if(celt)
364 *rgelt = verbs[This->iter++];
365 return S_OK;
368 static HRESULT WINAPI EnumOLEVERB_Skip(IEnumOLEVERB *iface, ULONG celt)
370 EnumOLEVERB *This = impl_from_IEnumOLEVERB(iface);
371 TRACE("(%p)->(%u)\n", This, celt);
372 return S_OK;
375 static HRESULT WINAPI EnumOLEVERB_Reset(IEnumOLEVERB *iface)
377 EnumOLEVERB *This = impl_from_IEnumOLEVERB(iface);
379 TRACE("(%p)\n", This);
381 This->iter = 0;
382 return S_OK;
385 static HRESULT WINAPI EnumOLEVERB_Clone(IEnumOLEVERB *iface, IEnumOLEVERB **ppenum)
387 EnumOLEVERB *This = impl_from_IEnumOLEVERB(iface);
388 FIXME("(%p)->(%p)\n", This, ppenum);
389 return E_NOTIMPL;
392 static const IEnumOLEVERBVtbl EnumOLEVERBVtbl = {
393 EnumOLEVERB_QueryInterface,
394 EnumOLEVERB_AddRef,
395 EnumOLEVERB_Release,
396 EnumOLEVERB_Next,
397 EnumOLEVERB_Skip,
398 EnumOLEVERB_Reset,
399 EnumOLEVERB_Clone
402 /**********************************************************************
403 * Implement the IOleObject interface for the WebBrowser control
406 static inline WebBrowser *impl_from_IOleObject(IOleObject *iface)
408 return CONTAINING_RECORD(iface, WebBrowser, IOleObject_iface);
411 static HRESULT WINAPI OleObject_QueryInterface(IOleObject *iface, REFIID riid, void **ppv)
413 WebBrowser *This = impl_from_IOleObject(iface);
414 return IWebBrowser2_QueryInterface(&This->IWebBrowser2_iface, riid, ppv);
417 static ULONG WINAPI OleObject_AddRef(IOleObject *iface)
419 WebBrowser *This = impl_from_IOleObject(iface);
420 return IWebBrowser2_AddRef(&This->IWebBrowser2_iface);
423 static ULONG WINAPI OleObject_Release(IOleObject *iface)
425 WebBrowser *This = impl_from_IOleObject(iface);
426 return IWebBrowser2_Release(&This->IWebBrowser2_iface);
429 static HRESULT WINAPI OleObject_SetClientSite(IOleObject *iface, LPOLECLIENTSITE pClientSite)
431 WebBrowser *This = impl_from_IOleObject(iface);
432 IDocHostUIHandler *hostui;
433 IOleContainer *container;
434 IDispatch *disp;
435 HRESULT hres;
437 TRACE("(%p)->(%p)\n", This, pClientSite);
439 if(This->client == pClientSite)
440 return S_OK;
442 release_client_site(This);
444 if(!pClientSite) {
445 on_commandstate_change(&This->doc_host, CSC_NAVIGATEBACK, VARIANT_FALSE);
446 on_commandstate_change(&This->doc_host, CSC_NAVIGATEFORWARD, VARIANT_FALSE);
448 if(This->doc_host.document)
449 deactivate_document(&This->doc_host);
450 return S_OK;
453 IOleClientSite_AddRef(pClientSite);
454 This->client = pClientSite;
456 hres = IOleClientSite_QueryInterface(This->client, &IID_IDispatch,
457 (void**)&disp);
458 if(SUCCEEDED(hres))
459 This->doc_host.client_disp = disp;
461 hres = IOleClientSite_QueryInterface(This->client, &IID_IDocHostUIHandler,
462 (void**)&hostui);
463 if(SUCCEEDED(hres))
464 This->doc_host.hostui = hostui;
466 hres = IOleClientSite_GetContainer(This->client, &container);
467 if(SUCCEEDED(hres)) {
468 ITargetContainer *target_container;
470 hres = IOleContainer_QueryInterface(container, &IID_ITargetContainer,
471 (void**)&target_container);
472 if(SUCCEEDED(hres)) {
473 FIXME("Unsupported ITargetContainer\n");
474 ITargetContainer_Release(target_container);
477 IOleContainer_Release(container);
480 create_shell_embedding_hwnd(This);
482 on_offlineconnected_change(This);
483 on_silent_change(This);
485 return S_OK;
488 static HRESULT WINAPI OleObject_GetClientSite(IOleObject *iface, LPOLECLIENTSITE *ppClientSite)
490 WebBrowser *This = impl_from_IOleObject(iface);
492 TRACE("(%p)->(%p)\n", This, ppClientSite);
494 if(!ppClientSite)
495 return E_INVALIDARG;
497 if(This->client)
498 IOleClientSite_AddRef(This->client);
499 *ppClientSite = This->client;
501 return S_OK;
504 static HRESULT WINAPI OleObject_SetHostNames(IOleObject *iface, LPCOLESTR szContainerApp,
505 LPCOLESTR szContainerObj)
507 WebBrowser *This = impl_from_IOleObject(iface);
509 TRACE("(%p)->(%s, %s)\n", This, debugstr_w(szContainerApp), debugstr_w(szContainerObj));
511 /* We have nothing to do here. */
512 return S_OK;
515 static HRESULT WINAPI OleObject_Close(IOleObject *iface, DWORD dwSaveOption)
517 WebBrowser *This = impl_from_IOleObject(iface);
519 TRACE("(%p)->(%d)\n", This, dwSaveOption);
521 if(dwSaveOption != OLECLOSE_NOSAVE) {
522 FIXME("unimplemented flag: %x\n", dwSaveOption);
523 return E_NOTIMPL;
526 if(This->doc_host.frame)
527 IOleInPlaceFrame_SetActiveObject(This->doc_host.frame, NULL, NULL);
529 if(This->uiwindow)
530 IOleInPlaceUIWindow_SetActiveObject(This->uiwindow, NULL, NULL);
532 if(This->inplace) {
533 IOleInPlaceSiteEx_OnUIDeactivate(This->inplace, FALSE);
534 IOleInPlaceSiteEx_OnInPlaceDeactivate(This->inplace);
537 return IOleObject_SetClientSite(iface, NULL);
540 static HRESULT WINAPI OleObject_SetMoniker(IOleObject *iface, DWORD dwWhichMoniker, IMoniker* pmk)
542 WebBrowser *This = impl_from_IOleObject(iface);
543 FIXME("(%p)->(%d, %p)\n", This, dwWhichMoniker, pmk);
544 return E_NOTIMPL;
547 static HRESULT WINAPI OleObject_GetMoniker(IOleObject *iface, DWORD dwAssign,
548 DWORD dwWhichMoniker, LPMONIKER *ppmk)
550 WebBrowser *This = impl_from_IOleObject(iface);
551 FIXME("(%p)->(%d, %d, %p)\n", This, dwAssign, dwWhichMoniker, ppmk);
552 return E_NOTIMPL;
555 static HRESULT WINAPI OleObject_InitFromData(IOleObject *iface, LPDATAOBJECT pDataObject,
556 BOOL fCreation, DWORD dwReserved)
558 WebBrowser *This = impl_from_IOleObject(iface);
559 FIXME("(%p)->(%p, %d, %d)\n", This, pDataObject, fCreation, dwReserved);
560 return E_NOTIMPL;
563 static HRESULT WINAPI OleObject_GetClipboardData(IOleObject *iface, DWORD dwReserved,
564 LPDATAOBJECT *ppDataObject)
566 WebBrowser *This = impl_from_IOleObject(iface);
567 FIXME("(%p)->(%d, %p)\n", This, dwReserved, ppDataObject);
568 return E_NOTIMPL;
571 static HRESULT WINAPI OleObject_DoVerb(IOleObject *iface, LONG iVerb, struct tagMSG* lpmsg,
572 LPOLECLIENTSITE pActiveSite, LONG lindex, HWND hwndParent, LPCRECT lprcPosRect)
574 WebBrowser *This = impl_from_IOleObject(iface);
576 TRACE("(%p)->(%d %p %p %d %p %s)\n", This, iVerb, lpmsg, pActiveSite, lindex, hwndParent,
577 wine_dbgstr_rect(lprcPosRect));
579 switch (iVerb)
581 case OLEIVERB_SHOW:
582 TRACE("OLEIVERB_SHOW\n");
583 return activate_ui(This, pActiveSite);
584 case OLEIVERB_UIACTIVATE:
585 TRACE("OLEIVERB_UIACTIVATE\n");
586 return activate_ui(This, pActiveSite);
587 case OLEIVERB_INPLACEACTIVATE:
588 TRACE("OLEIVERB_INPLACEACTIVATE\n");
589 return activate_inplace(This, pActiveSite);
590 case OLEIVERB_HIDE:
591 TRACE("OLEIVERB_HIDE\n");
592 if(This->inplace)
593 IOleInPlaceSiteEx_OnInPlaceDeactivate(This->inplace);
594 if(This->shell_embedding_hwnd)
595 ShowWindow(This->shell_embedding_hwnd, SW_HIDE);
596 return S_OK;
597 default:
598 FIXME("stub for %d\n", iVerb);
599 break;
602 return E_NOTIMPL;
605 static HRESULT WINAPI OleObject_EnumVerbs(IOleObject *iface, IEnumOLEVERB **ppEnumOleVerb)
607 WebBrowser *This = impl_from_IOleObject(iface);
608 EnumOLEVERB *ret;
610 TRACE("(%p)->(%p)\n", This, ppEnumOleVerb);
612 ret = heap_alloc(sizeof(*ret));
613 if(!ret)
614 return E_OUTOFMEMORY;
616 ret->IEnumOLEVERB_iface.lpVtbl = &EnumOLEVERBVtbl;
617 ret->ref = 1;
618 ret->iter = 0;
620 *ppEnumOleVerb = &ret->IEnumOLEVERB_iface;
621 return S_OK;
624 static HRESULT WINAPI OleObject_Update(IOleObject *iface)
626 WebBrowser *This = impl_from_IOleObject(iface);
627 FIXME("(%p)\n", This);
628 return E_NOTIMPL;
631 static HRESULT WINAPI OleObject_IsUpToDate(IOleObject *iface)
633 WebBrowser *This = impl_from_IOleObject(iface);
634 FIXME("(%p)\n", This);
635 return E_NOTIMPL;
638 static HRESULT WINAPI OleObject_GetUserClassID(IOleObject *iface, CLSID* pClsid)
640 WebBrowser *This = impl_from_IOleObject(iface);
641 FIXME("(%p)->(%p)\n", This, pClsid);
642 return E_NOTIMPL;
645 static HRESULT WINAPI OleObject_GetUserType(IOleObject *iface, DWORD dwFormOfType,
646 LPOLESTR* pszUserType)
648 WebBrowser *This = impl_from_IOleObject(iface);
649 TRACE("(%p, %d, %p)\n", This, dwFormOfType, pszUserType);
650 return OleRegGetUserType(&CLSID_WebBrowser, dwFormOfType, pszUserType);
653 static HRESULT WINAPI OleObject_SetExtent(IOleObject *iface, DWORD dwDrawAspect, SIZEL *psizel)
655 WebBrowser *This = impl_from_IOleObject(iface);
657 TRACE("(%p)->(%x %p)\n", This, dwDrawAspect, psizel);
659 /* Tests show that dwDrawAspect is ignored */
660 This->extent = *psizel;
661 return S_OK;
664 static HRESULT WINAPI OleObject_GetExtent(IOleObject *iface, DWORD dwDrawAspect, SIZEL *psizel)
666 WebBrowser *This = impl_from_IOleObject(iface);
668 TRACE("(%p)->(%x, %p)\n", This, dwDrawAspect, psizel);
670 /* Tests show that dwDrawAspect is ignored */
671 *psizel = This->extent;
672 return S_OK;
675 static HRESULT WINAPI OleObject_Advise(IOleObject *iface, IAdviseSink *pAdvSink,
676 DWORD* pdwConnection)
678 WebBrowser *This = impl_from_IOleObject(iface);
679 FIXME("(%p)->(%p, %p)\n", This, pAdvSink, pdwConnection);
680 return E_NOTIMPL;
683 static HRESULT WINAPI OleObject_Unadvise(IOleObject *iface, DWORD dwConnection)
685 WebBrowser *This = impl_from_IOleObject(iface);
686 FIXME("(%p)->(%d)\n", This, dwConnection);
687 return E_NOTIMPL;
690 static HRESULT WINAPI OleObject_EnumAdvise(IOleObject *iface, IEnumSTATDATA **ppenumAdvise)
692 WebBrowser *This = impl_from_IOleObject(iface);
693 FIXME("(%p)->(%p)\n", This, ppenumAdvise);
694 return S_OK;
697 static HRESULT WINAPI OleObject_GetMiscStatus(IOleObject *iface, DWORD dwAspect, DWORD *pdwStatus)
699 WebBrowser *This = impl_from_IOleObject(iface);
701 TRACE("(%p)->(%x, %p)\n", This, dwAspect, pdwStatus);
703 *pdwStatus = OLEMISC_SETCLIENTSITEFIRST|OLEMISC_ACTIVATEWHENVISIBLE|OLEMISC_INSIDEOUT
704 |OLEMISC_CANTLINKINSIDE|OLEMISC_RECOMPOSEONRESIZE;
706 return S_OK;
709 static HRESULT WINAPI OleObject_SetColorScheme(IOleObject *iface, LOGPALETTE* pLogpal)
711 WebBrowser *This = impl_from_IOleObject(iface);
712 FIXME("(%p)->(%p)\n", This, pLogpal);
713 return E_NOTIMPL;
716 static const IOleObjectVtbl OleObjectVtbl =
718 OleObject_QueryInterface,
719 OleObject_AddRef,
720 OleObject_Release,
721 OleObject_SetClientSite,
722 OleObject_GetClientSite,
723 OleObject_SetHostNames,
724 OleObject_Close,
725 OleObject_SetMoniker,
726 OleObject_GetMoniker,
727 OleObject_InitFromData,
728 OleObject_GetClipboardData,
729 OleObject_DoVerb,
730 OleObject_EnumVerbs,
731 OleObject_Update,
732 OleObject_IsUpToDate,
733 OleObject_GetUserClassID,
734 OleObject_GetUserType,
735 OleObject_SetExtent,
736 OleObject_GetExtent,
737 OleObject_Advise,
738 OleObject_Unadvise,
739 OleObject_EnumAdvise,
740 OleObject_GetMiscStatus,
741 OleObject_SetColorScheme
744 /**********************************************************************
745 * Implement the IOleInPlaceObject interface
748 static inline WebBrowser *impl_from_IOleInPlaceObject(IOleInPlaceObject *iface)
750 return CONTAINING_RECORD(iface, WebBrowser, IOleInPlaceObject_iface);
753 static HRESULT WINAPI OleInPlaceObject_QueryInterface(IOleInPlaceObject *iface,
754 REFIID riid, LPVOID *ppobj)
756 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
757 return IWebBrowser2_QueryInterface(&This->IWebBrowser2_iface, riid, ppobj);
760 static ULONG WINAPI OleInPlaceObject_AddRef(IOleInPlaceObject *iface)
762 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
763 return IWebBrowser2_AddRef(&This->IWebBrowser2_iface);
766 static ULONG WINAPI OleInPlaceObject_Release(IOleInPlaceObject *iface)
768 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
769 return IWebBrowser2_Release(&This->IWebBrowser2_iface);
772 static HRESULT WINAPI OleInPlaceObject_GetWindow(IOleInPlaceObject *iface, HWND* phwnd)
774 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
776 TRACE("(%p)->(%p)\n", This, phwnd);
778 *phwnd = This->shell_embedding_hwnd;
779 return S_OK;
782 static HRESULT WINAPI OleInPlaceObject_ContextSensitiveHelp(IOleInPlaceObject *iface,
783 BOOL fEnterMode)
785 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
786 FIXME("(%p)->(%x)\n", This, fEnterMode);
787 return E_NOTIMPL;
790 static HRESULT WINAPI OleInPlaceObject_InPlaceDeactivate(IOleInPlaceObject *iface)
792 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
793 FIXME("(%p)\n", This);
795 if(This->inplace) {
796 IOleInPlaceSiteEx_Release(This->inplace);
797 This->inplace = NULL;
800 return S_OK;
803 static HRESULT WINAPI OleInPlaceObject_UIDeactivate(IOleInPlaceObject *iface)
805 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
806 FIXME("(%p)\n", This);
807 return E_NOTIMPL;
810 static HRESULT WINAPI OleInPlaceObject_SetObjectRects(IOleInPlaceObject *iface,
811 LPCRECT lprcPosRect, LPCRECT lprcClipRect)
813 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
815 TRACE("(%p)->(%p %p)\n", This, lprcPosRect, lprcClipRect);
817 This->pos_rect = *lprcPosRect;
819 if(lprcClipRect)
820 This->clip_rect = *lprcClipRect;
822 if(This->shell_embedding_hwnd) {
823 SetWindowPos(This->shell_embedding_hwnd, NULL,
824 lprcPosRect->left, lprcPosRect->top,
825 lprcPosRect->right-lprcPosRect->left,
826 lprcPosRect->bottom-lprcPosRect->top,
827 SWP_NOZORDER | SWP_NOACTIVATE);
830 return S_OK;
833 static HRESULT WINAPI OleInPlaceObject_ReactivateAndUndo(IOleInPlaceObject *iface)
835 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
836 FIXME("(%p)\n", This);
837 return E_NOTIMPL;
840 static const IOleInPlaceObjectVtbl OleInPlaceObjectVtbl =
842 OleInPlaceObject_QueryInterface,
843 OleInPlaceObject_AddRef,
844 OleInPlaceObject_Release,
845 OleInPlaceObject_GetWindow,
846 OleInPlaceObject_ContextSensitiveHelp,
847 OleInPlaceObject_InPlaceDeactivate,
848 OleInPlaceObject_UIDeactivate,
849 OleInPlaceObject_SetObjectRects,
850 OleInPlaceObject_ReactivateAndUndo
853 /**********************************************************************
854 * Implement the IOleControl interface
857 static inline WebBrowser *impl_from_IOleControl(IOleControl *iface)
859 return CONTAINING_RECORD(iface, WebBrowser, IOleControl_iface);
862 static HRESULT WINAPI OleControl_QueryInterface(IOleControl *iface,
863 REFIID riid, LPVOID *ppobj)
865 WebBrowser *This = impl_from_IOleControl(iface);
866 return IWebBrowser2_QueryInterface(&This->IWebBrowser2_iface, riid, ppobj);
869 static ULONG WINAPI OleControl_AddRef(IOleControl *iface)
871 WebBrowser *This = impl_from_IOleControl(iface);
872 return IWebBrowser2_AddRef(&This->IWebBrowser2_iface);
875 static ULONG WINAPI OleControl_Release(IOleControl *iface)
877 WebBrowser *This = impl_from_IOleControl(iface);
878 return IWebBrowser2_Release(&This->IWebBrowser2_iface);
881 static HRESULT WINAPI OleControl_GetControlInfo(IOleControl *iface, LPCONTROLINFO pCI)
883 WebBrowser *This = impl_from_IOleControl(iface);
885 TRACE("(%p)->(%p)\n", This, pCI);
887 /* Tests show that this function should be not implemented */
888 return E_NOTIMPL;
891 static HRESULT WINAPI OleControl_OnMnemonic(IOleControl *iface, struct tagMSG *pMsg)
893 WebBrowser *This = impl_from_IOleControl(iface);
894 FIXME("(%p)->(%p)\n", This, pMsg);
895 return E_NOTIMPL;
898 static HRESULT WINAPI OleControl_OnAmbientPropertyChange(IOleControl *iface, DISPID dispID)
900 WebBrowser *This = impl_from_IOleControl(iface);
902 TRACE("(%p)->(%d)\n", This, dispID);
904 switch(dispID) {
905 case DISPID_UNKNOWN:
906 /* Unknown means multiple properties changed, so check them all.
907 * BUT the Webbrowser OleControl object doesn't appear to do this.
909 return S_OK;
910 case DISPID_AMBIENT_DLCONTROL:
911 return S_OK;
912 case DISPID_AMBIENT_OFFLINEIFNOTCONNECTED:
913 return on_offlineconnected_change(This);
914 case DISPID_AMBIENT_SILENT:
915 return on_silent_change(This);
918 FIXME("Unknown dispID %d\n", dispID);
919 return E_NOTIMPL;
922 static HRESULT WINAPI OleControl_FreezeEvents(IOleControl *iface, BOOL bFreeze)
924 WebBrowser *This = impl_from_IOleControl(iface);
925 FIXME("(%p)->(%x)\n", This, bFreeze);
926 return E_NOTIMPL;
929 static const IOleControlVtbl OleControlVtbl =
931 OleControl_QueryInterface,
932 OleControl_AddRef,
933 OleControl_Release,
934 OleControl_GetControlInfo,
935 OleControl_OnMnemonic,
936 OleControl_OnAmbientPropertyChange,
937 OleControl_FreezeEvents
940 static inline WebBrowser *impl_from_IOleInPlaceActiveObject(IOleInPlaceActiveObject *iface)
942 return CONTAINING_RECORD(iface, WebBrowser, IOleInPlaceActiveObject_iface);
945 static HRESULT WINAPI InPlaceActiveObject_QueryInterface(IOleInPlaceActiveObject *iface,
946 REFIID riid, void **ppv)
948 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
949 return IWebBrowser2_QueryInterface(&This->IWebBrowser2_iface, riid, ppv);
952 static ULONG WINAPI InPlaceActiveObject_AddRef(IOleInPlaceActiveObject *iface)
954 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
955 return IWebBrowser2_AddRef(&This->IWebBrowser2_iface);
958 static ULONG WINAPI InPlaceActiveObject_Release(IOleInPlaceActiveObject *iface)
960 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
961 return IWebBrowser2_Release(&This->IWebBrowser2_iface);
964 static HRESULT WINAPI InPlaceActiveObject_GetWindow(IOleInPlaceActiveObject *iface,
965 HWND *phwnd)
967 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
968 return IOleInPlaceObject_GetWindow(&This->IOleInPlaceObject_iface, phwnd);
971 static HRESULT WINAPI InPlaceActiveObject_ContextSensitiveHelp(IOleInPlaceActiveObject *iface,
972 BOOL fEnterMode)
974 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
975 return IOleInPlaceObject_ContextSensitiveHelp(&This->IOleInPlaceObject_iface, fEnterMode);
978 static HRESULT WINAPI InPlaceActiveObject_TranslateAccelerator(IOleInPlaceActiveObject *iface,
979 LPMSG lpmsg)
981 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
982 IOleInPlaceActiveObject *activeobj;
983 HRESULT hr = S_FALSE;
985 TRACE("(%p)->(%p)\n", This, lpmsg);
987 if(This->doc_host.document) {
988 if(SUCCEEDED(IUnknown_QueryInterface(This->doc_host.document,
989 &IID_IOleInPlaceActiveObject,
990 (void**)&activeobj))) {
991 hr = IOleInPlaceActiveObject_TranslateAccelerator(activeobj, lpmsg);
992 IOleInPlaceActiveObject_Release(activeobj);
996 if(SUCCEEDED(hr))
997 return hr;
998 else
999 return S_FALSE;
1002 static HRESULT WINAPI InPlaceActiveObject_OnFrameWindowActivate(IOleInPlaceActiveObject *iface,
1003 BOOL fActivate)
1005 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
1006 FIXME("(%p)->(%x)\n", This, fActivate);
1007 return E_NOTIMPL;
1010 static HRESULT WINAPI InPlaceActiveObject_OnDocWindowActivate(IOleInPlaceActiveObject *iface,
1011 BOOL fActivate)
1013 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
1014 FIXME("(%p)->(%x)\n", This, fActivate);
1015 return E_NOTIMPL;
1018 static HRESULT WINAPI InPlaceActiveObject_ResizeBorder(IOleInPlaceActiveObject *iface,
1019 LPCRECT lprcBorder, IOleInPlaceUIWindow *pUIWindow, BOOL fFrameWindow)
1021 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
1022 FIXME("(%p)->(%p %p %x)\n", This, lprcBorder, pUIWindow, fFrameWindow);
1023 return E_NOTIMPL;
1026 static HRESULT WINAPI InPlaceActiveObject_EnableModeless(IOleInPlaceActiveObject *iface,
1027 BOOL fEnable)
1029 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
1030 FIXME("(%p)->(%x)\n", This, fEnable);
1031 return E_NOTIMPL;
1034 static const IOleInPlaceActiveObjectVtbl OleInPlaceActiveObjectVtbl = {
1035 InPlaceActiveObject_QueryInterface,
1036 InPlaceActiveObject_AddRef,
1037 InPlaceActiveObject_Release,
1038 InPlaceActiveObject_GetWindow,
1039 InPlaceActiveObject_ContextSensitiveHelp,
1040 InPlaceActiveObject_TranslateAccelerator,
1041 InPlaceActiveObject_OnFrameWindowActivate,
1042 InPlaceActiveObject_OnDocWindowActivate,
1043 InPlaceActiveObject_ResizeBorder,
1044 InPlaceActiveObject_EnableModeless
1047 static inline WebBrowser *impl_from_IOleCommandTarget(IOleCommandTarget *iface)
1049 return CONTAINING_RECORD(iface, WebBrowser, IOleCommandTarget_iface);
1052 static HRESULT WINAPI WBOleCommandTarget_QueryInterface(IOleCommandTarget *iface,
1053 REFIID riid, void **ppv)
1055 WebBrowser *This = impl_from_IOleCommandTarget(iface);
1056 return IWebBrowser2_QueryInterface(&This->IWebBrowser2_iface, riid, ppv);
1059 static ULONG WINAPI WBOleCommandTarget_AddRef(IOleCommandTarget *iface)
1061 WebBrowser *This = impl_from_IOleCommandTarget(iface);
1062 return IWebBrowser2_AddRef(&This->IWebBrowser2_iface);
1065 static ULONG WINAPI WBOleCommandTarget_Release(IOleCommandTarget *iface)
1067 WebBrowser *This = impl_from_IOleCommandTarget(iface);
1068 return IWebBrowser2_Release(&This->IWebBrowser2_iface);
1071 static HRESULT WINAPI WBOleCommandTarget_QueryStatus(IOleCommandTarget *iface,
1072 const GUID *pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[], OLECMDTEXT *pCmdText)
1074 WebBrowser *This = impl_from_IOleCommandTarget(iface);
1075 IOleCommandTarget *cmdtrg;
1076 HRESULT hres;
1078 TRACE("(%p)->(%s %u %p %p)\n", This, debugstr_guid(pguidCmdGroup), cCmds, prgCmds,
1079 pCmdText);
1081 if(!This->doc_host.document)
1082 return 0x80040104;
1084 /* NOTE: There are probably some commands that we should handle here
1085 * instead of forwarding to document object. */
1087 hres = IUnknown_QueryInterface(This->doc_host.document, &IID_IOleCommandTarget, (void**)&cmdtrg);
1088 if(FAILED(hres))
1089 return hres;
1091 hres = IOleCommandTarget_QueryStatus(cmdtrg, pguidCmdGroup, cCmds, prgCmds, pCmdText);
1092 IOleCommandTarget_Release(cmdtrg);
1094 return hres;
1097 static HRESULT WINAPI WBOleCommandTarget_Exec(IOleCommandTarget *iface,
1098 const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn,
1099 VARIANT *pvaOut)
1101 WebBrowser *This = impl_from_IOleCommandTarget(iface);
1102 FIXME("(%p)->(%s %d %d %p %p)\n", This, debugstr_guid(pguidCmdGroup), nCmdID,
1103 nCmdexecopt, pvaIn, pvaOut);
1104 return E_NOTIMPL;
1107 static const IOleCommandTargetVtbl OleCommandTargetVtbl = {
1108 WBOleCommandTarget_QueryInterface,
1109 WBOleCommandTarget_AddRef,
1110 WBOleCommandTarget_Release,
1111 WBOleCommandTarget_QueryStatus,
1112 WBOleCommandTarget_Exec
1115 void WebBrowser_OleObject_Init(WebBrowser *This)
1117 DWORD dpi_x;
1118 DWORD dpi_y;
1119 HDC hdc;
1121 /* default aspect ratio is 96dpi / 96dpi */
1122 hdc = GetDC(0);
1123 dpi_x = GetDeviceCaps(hdc, LOGPIXELSX);
1124 dpi_y = GetDeviceCaps(hdc, LOGPIXELSY);
1125 ReleaseDC(0, hdc);
1127 This->IOleObject_iface.lpVtbl = &OleObjectVtbl;
1128 This->IOleInPlaceObject_iface.lpVtbl = &OleInPlaceObjectVtbl;
1129 This->IOleControl_iface.lpVtbl = &OleControlVtbl;
1130 This->IOleInPlaceActiveObject_iface.lpVtbl = &OleInPlaceActiveObjectVtbl;
1131 This->IOleCommandTarget_iface.lpVtbl = &OleCommandTargetVtbl;
1133 /* Default size is 50x20 pixels, in himetric units */
1134 This->extent.cx = MulDiv( 50, 2540, dpi_x );
1135 This->extent.cy = MulDiv( 20, 2540, dpi_y );
1138 void WebBrowser_OleObject_Destroy(WebBrowser *This)
1140 release_client_site(This);