gdiplus: Add tests for GdipPlayMetafileRecord.
[wine.git] / dlls / shdocvw / oleobject.c
blobb1164869ab9ab1aa8ecda68343250a7b13fd647c
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>
27 #include "wine/debug.h"
28 #include "shdocvw.h"
29 #include "htiframe.h"
30 #include "idispids.h"
31 #include "mshtmdid.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(shdocvw);
35 /* shlwapi.dll */
36 HWND WINAPI SHSetParentHwnd(HWND hWnd, HWND hWndParent);
38 static ATOM shell_embedding_atom = 0;
40 static LRESULT resize_window(WebBrowser *This, LONG width, LONG height)
42 if(This->doc_host.hwnd)
43 SetWindowPos(This->doc_host.hwnd, NULL, 0, 0, width, height,
44 SWP_NOZORDER | SWP_NOACTIVATE);
46 return 0;
49 static LRESULT WINAPI shell_embedding_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
51 WebBrowser *This;
53 static const WCHAR wszTHIS[] = {'T','H','I','S',0};
55 if(msg == WM_CREATE) {
56 This = *(WebBrowser**)lParam;
57 SetPropW(hwnd, wszTHIS, This);
58 }else {
59 This = GetPropW(hwnd, wszTHIS);
62 switch(msg) {
63 case WM_SIZE:
64 return resize_window(This, LOWORD(lParam), HIWORD(lParam));
65 case WM_DOCHOSTTASK:
66 return process_dochost_tasks(&This->doc_host);
69 return DefWindowProcW(hwnd, msg, wParam, lParam);
72 static void create_shell_embedding_hwnd(WebBrowser *This)
74 IOleInPlaceSite *inplace;
75 HWND parent = NULL;
76 HRESULT hres;
78 static const WCHAR wszShellEmbedding[] =
79 {'S','h','e','l','l',' ','E','m','b','e','d','d','i','n','g',0};
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
91 wndclass.hInstance = shdocvw_hinstance;
93 RegisterClassExW(&wndclass);
96 hres = IOleClientSite_QueryInterface(This->client, &IID_IOleInPlaceSite, (void**)&inplace);
97 if(SUCCEEDED(hres)) {
98 IOleInPlaceSite_GetWindow(inplace, &parent);
99 IOleInPlaceSite_Release(inplace);
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);
110 TRACE("parent=%p hwnd=%p\n", parent, This->shell_embedding_hwnd);
113 static HRESULT activate_inplace(WebBrowser *This, IOleClientSite *active_site)
115 HWND parent_hwnd;
116 HRESULT hres;
118 if(This->inplace)
119 return S_OK;
121 if(!active_site)
122 return E_INVALIDARG;
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;
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;
138 hres = IOleInPlaceSite_GetWindow(This->inplace, &parent_hwnd);
139 if(SUCCEEDED(hres))
140 SHSetParentHwnd(This->shell_embedding_hwnd, parent_hwnd);
142 IOleInPlaceSite_OnInPlaceActivate(This->inplace);
144 This->frameinfo.cb = sizeof(OLEINPLACEFRAMEINFO);
145 IOleInPlaceSite_GetWindowContext(This->inplace, &This->doc_host.frame, &This->uiwindow,
146 &This->pos_rect, &This->clip_rect,
147 &This->frameinfo);
149 SetWindowPos(This->shell_embedding_hwnd, NULL,
150 This->pos_rect.left, This->pos_rect.top,
151 This->pos_rect.right-This->pos_rect.left,
152 This->pos_rect.bottom-This->pos_rect.top,
153 SWP_NOZORDER | SWP_SHOWWINDOW);
155 if(This->client) {
156 IOleContainer *container;
158 IOleClientSite_ShowObject(This->client);
160 hres = IOleClientSite_GetContainer(This->client, &container);
161 if(SUCCEEDED(hres)) {
162 if(This->container)
163 IOleContainer_Release(This->container);
164 This->container = container;
168 if(This->doc_host.frame)
169 IOleInPlaceFrame_GetWindow(This->doc_host.frame, &This->frame_hwnd);
171 return S_OK;
174 static HRESULT activate_ui(WebBrowser *This, IOleClientSite *active_site)
176 HRESULT hres;
178 static const WCHAR wszitem[] = {'i','t','e','m',0};
180 if(This->inplace)
182 if(This->shell_embedding_hwnd)
183 ShowWindow(This->shell_embedding_hwnd, SW_SHOW);
184 return S_OK;
187 hres = activate_inplace(This, active_site);
188 if(FAILED(hres))
189 return hres;
191 IOleInPlaceSite_OnUIActivate(This->inplace);
193 if(This->doc_host.frame)
194 IOleInPlaceFrame_SetActiveObject(This->doc_host.frame, &This->IOleInPlaceActiveObject_iface, wszitem);
195 if(This->uiwindow)
196 IOleInPlaceUIWindow_SetActiveObject(This->uiwindow, &This->IOleInPlaceActiveObject_iface, wszitem);
198 if(This->doc_host.frame)
199 IOleInPlaceFrame_SetMenu(This->doc_host.frame, NULL, NULL, This->shell_embedding_hwnd);
201 SetFocus(This->shell_embedding_hwnd);
203 return S_OK;
206 static HRESULT get_client_disp_property(IOleClientSite *client, DISPID dispid, VARIANT *res)
208 IDispatch *disp = NULL;
209 DISPPARAMS dispparams = {NULL, 0};
210 HRESULT hres;
212 VariantInit(res);
214 if(!client)
215 return S_OK;
217 hres = IOleClientSite_QueryInterface(client, &IID_IDispatch, (void**)&disp);
218 if(FAILED(hres)) {
219 TRACE("Could not get IDispatch\n");
220 return hres;
223 hres = IDispatch_Invoke(disp, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
224 DISPATCH_PROPERTYGET, &dispparams, res, NULL, NULL);
226 IDispatch_Release(disp);
228 return hres;
231 static HRESULT on_offlineconnected_change(WebBrowser *This)
233 VARIANT offline;
235 get_client_disp_property(This->client, DISPID_AMBIENT_OFFLINEIFNOTCONNECTED, &offline);
237 if(V_VT(&offline) == VT_BOOL)
238 IWebBrowser2_put_Offline(&This->IWebBrowser2_iface, V_BOOL(&offline));
239 else if(V_VT(&offline) != VT_EMPTY)
240 WARN("wrong V_VT(silent) %d\n", V_VT(&offline));
242 return S_OK;
245 static HRESULT on_silent_change(WebBrowser *This)
247 VARIANT silent;
249 get_client_disp_property(This->client, DISPID_AMBIENT_SILENT, &silent);
251 if(V_VT(&silent) == VT_BOOL)
252 IWebBrowser2_put_Silent(&This->IWebBrowser2_iface, V_BOOL(&silent));
253 else if(V_VT(&silent) != VT_EMPTY)
254 WARN("wrong V_VT(silent) %d\n", V_VT(&silent));
256 return S_OK;
259 static void release_client_site(WebBrowser *This)
261 release_dochost_client(&This->doc_host);
263 if(This->shell_embedding_hwnd) {
264 DestroyWindow(This->shell_embedding_hwnd);
265 This->shell_embedding_hwnd = NULL;
268 if(This->inplace) {
269 IOleInPlaceSite_Release(This->inplace);
270 This->inplace = NULL;
273 if(This->container) {
274 IOleContainer_Release(This->container);
275 This->container = NULL;
278 if(This->uiwindow) {
279 IOleInPlaceUIWindow_Release(This->uiwindow);
280 This->uiwindow = NULL;
283 if(This->client) {
284 IOleClientSite_Release(This->client);
285 This->client = NULL;
289 /**********************************************************************
290 * Implement the IOleObject interface for the WebBrowser control
293 static inline WebBrowser *impl_from_IOleObject(IOleObject *iface)
295 return CONTAINING_RECORD(iface, WebBrowser, IOleObject_iface);
298 static HRESULT WINAPI OleObject_QueryInterface(IOleObject *iface, REFIID riid, void **ppv)
300 WebBrowser *This = impl_from_IOleObject(iface);
301 return IWebBrowser_QueryInterface(&This->IWebBrowser2_iface, riid, ppv);
304 static ULONG WINAPI OleObject_AddRef(IOleObject *iface)
306 WebBrowser *This = impl_from_IOleObject(iface);
307 return IWebBrowser_AddRef(&This->IWebBrowser2_iface);
310 static ULONG WINAPI OleObject_Release(IOleObject *iface)
312 WebBrowser *This = impl_from_IOleObject(iface);
313 return IWebBrowser_Release(&This->IWebBrowser2_iface);
316 static HRESULT WINAPI OleObject_SetClientSite(IOleObject *iface, LPOLECLIENTSITE pClientSite)
318 WebBrowser *This = impl_from_IOleObject(iface);
319 IDocHostUIHandler *hostui;
320 IOleContainer *container;
321 IDispatch *disp;
322 HRESULT hres;
324 TRACE("(%p)->(%p)\n", This, pClientSite);
326 if(This->client == pClientSite)
327 return S_OK;
329 release_client_site(This);
331 if(!pClientSite) {
332 if(This->doc_host.document)
333 deactivate_document(&This->doc_host);
334 return S_OK;
337 IOleClientSite_AddRef(pClientSite);
338 This->client = pClientSite;
340 hres = IOleClientSite_QueryInterface(This->client, &IID_IDispatch,
341 (void**)&disp);
342 if(SUCCEEDED(hres))
343 This->doc_host.client_disp = disp;
345 hres = IOleClientSite_QueryInterface(This->client, &IID_IDocHostUIHandler,
346 (void**)&hostui);
347 if(SUCCEEDED(hres))
348 This->doc_host.hostui = hostui;
350 hres = IOleClientSite_GetContainer(This->client, &container);
351 if(SUCCEEDED(hres)) {
352 ITargetContainer *target_container;
354 hres = IOleContainer_QueryInterface(container, &IID_ITargetContainer,
355 (void**)&target_container);
356 if(SUCCEEDED(hres)) {
357 FIXME("Unsupported ITargetContainer\n");
358 ITargetContainer_Release(target_container);
361 IOleContainer_Release(container);
364 create_shell_embedding_hwnd(This);
366 on_offlineconnected_change(This);
367 on_silent_change(This);
369 return S_OK;
372 static HRESULT WINAPI OleObject_GetClientSite(IOleObject *iface, LPOLECLIENTSITE *ppClientSite)
374 WebBrowser *This = impl_from_IOleObject(iface);
376 TRACE("(%p)->(%p)\n", This, ppClientSite);
378 if(!ppClientSite)
379 return E_INVALIDARG;
381 if(This->client)
382 IOleClientSite_AddRef(This->client);
383 *ppClientSite = This->client;
385 return S_OK;
388 static HRESULT WINAPI OleObject_SetHostNames(IOleObject *iface, LPCOLESTR szContainerApp,
389 LPCOLESTR szContainerObj)
391 WebBrowser *This = impl_from_IOleObject(iface);
393 TRACE("(%p)->(%s, %s)\n", This, debugstr_w(szContainerApp), debugstr_w(szContainerObj));
395 /* We have nothing to do here. */
396 return S_OK;
399 static HRESULT WINAPI OleObject_Close(IOleObject *iface, DWORD dwSaveOption)
401 WebBrowser *This = impl_from_IOleObject(iface);
402 FIXME("(%p)->(%d)\n", This, dwSaveOption);
403 return E_NOTIMPL;
406 static HRESULT WINAPI OleObject_SetMoniker(IOleObject *iface, DWORD dwWhichMoniker, IMoniker* pmk)
408 WebBrowser *This = impl_from_IOleObject(iface);
409 FIXME("(%p)->(%d, %p)\n", This, dwWhichMoniker, pmk);
410 return E_NOTIMPL;
413 static HRESULT WINAPI OleObject_GetMoniker(IOleObject *iface, DWORD dwAssign,
414 DWORD dwWhichMoniker, LPMONIKER *ppmk)
416 WebBrowser *This = impl_from_IOleObject(iface);
417 FIXME("(%p)->(%d, %d, %p)\n", This, dwAssign, dwWhichMoniker, ppmk);
418 return E_NOTIMPL;
421 static HRESULT WINAPI OleObject_InitFromData(IOleObject *iface, LPDATAOBJECT pDataObject,
422 BOOL fCreation, DWORD dwReserved)
424 WebBrowser *This = impl_from_IOleObject(iface);
425 FIXME("(%p)->(%p, %d, %d)\n", This, pDataObject, fCreation, dwReserved);
426 return E_NOTIMPL;
429 static HRESULT WINAPI OleObject_GetClipboardData(IOleObject *iface, DWORD dwReserved,
430 LPDATAOBJECT *ppDataObject)
432 WebBrowser *This = impl_from_IOleObject(iface);
433 FIXME("(%p)->(%d, %p)\n", This, dwReserved, ppDataObject);
434 return E_NOTIMPL;
437 static HRESULT WINAPI OleObject_DoVerb(IOleObject *iface, LONG iVerb, struct tagMSG* lpmsg,
438 LPOLECLIENTSITE pActiveSite, LONG lindex, HWND hwndParent, LPCRECT lprcPosRect)
440 WebBrowser *This = impl_from_IOleObject(iface);
442 TRACE("(%p)->(%d %p %p %d %p %p)\n", This, iVerb, lpmsg, pActiveSite, lindex, hwndParent,
443 lprcPosRect);
445 switch (iVerb)
447 case OLEIVERB_SHOW:
448 TRACE("OLEIVERB_SHOW\n");
449 return activate_ui(This, pActiveSite);
450 case OLEIVERB_UIACTIVATE:
451 TRACE("OLEIVERB_UIACTIVATE\n");
452 return activate_ui(This, pActiveSite);
453 case OLEIVERB_INPLACEACTIVATE:
454 TRACE("OLEIVERB_INPLACEACTIVATE\n");
455 return activate_inplace(This, pActiveSite);
456 case OLEIVERB_HIDE:
457 TRACE("OLEIVERB_HIDE\n");
458 if(This->shell_embedding_hwnd)
459 ShowWindow(This->shell_embedding_hwnd, SW_HIDE);
460 return S_OK;
461 default:
462 FIXME("stub for %d\n", iVerb);
463 break;
466 return E_NOTIMPL;
469 static HRESULT WINAPI OleObject_EnumVerbs(IOleObject *iface, IEnumOLEVERB **ppEnumOleVerb)
471 WebBrowser *This = impl_from_IOleObject(iface);
472 TRACE("(%p)->(%p)\n", This, ppEnumOleVerb);
473 return OleRegEnumVerbs(&CLSID_WebBrowser, ppEnumOleVerb);
476 static HRESULT WINAPI OleObject_Update(IOleObject *iface)
478 WebBrowser *This = impl_from_IOleObject(iface);
479 FIXME("(%p)\n", This);
480 return E_NOTIMPL;
483 static HRESULT WINAPI OleObject_IsUpToDate(IOleObject *iface)
485 WebBrowser *This = impl_from_IOleObject(iface);
486 FIXME("(%p)\n", This);
487 return E_NOTIMPL;
490 static HRESULT WINAPI OleObject_GetUserClassID(IOleObject *iface, CLSID* pClsid)
492 WebBrowser *This = impl_from_IOleObject(iface);
493 FIXME("(%p)->(%p)\n", This, pClsid);
494 return E_NOTIMPL;
497 static HRESULT WINAPI OleObject_GetUserType(IOleObject *iface, DWORD dwFormOfType,
498 LPOLESTR* pszUserType)
500 WebBrowser *This = impl_from_IOleObject(iface);
501 TRACE("(%p, %d, %p)\n", This, dwFormOfType, pszUserType);
502 return OleRegGetUserType(&CLSID_WebBrowser, dwFormOfType, pszUserType);
505 static HRESULT WINAPI OleObject_SetExtent(IOleObject *iface, DWORD dwDrawAspect, SIZEL *psizel)
507 WebBrowser *This = impl_from_IOleObject(iface);
509 TRACE("(%p)->(%x %p)\n", This, dwDrawAspect, psizel);
511 /* Tests show that dwDrawAspect is ignored */
512 This->extent = *psizel;
513 return S_OK;
516 static HRESULT WINAPI OleObject_GetExtent(IOleObject *iface, DWORD dwDrawAspect, SIZEL *psizel)
518 WebBrowser *This = impl_from_IOleObject(iface);
520 TRACE("(%p)->(%x, %p)\n", This, dwDrawAspect, psizel);
522 /* Tests show that dwDrawAspect is ignored */
523 *psizel = This->extent;
524 return S_OK;
527 static HRESULT WINAPI OleObject_Advise(IOleObject *iface, IAdviseSink *pAdvSink,
528 DWORD* pdwConnection)
530 WebBrowser *This = impl_from_IOleObject(iface);
531 FIXME("(%p)->(%p, %p)\n", This, pAdvSink, pdwConnection);
532 return E_NOTIMPL;
535 static HRESULT WINAPI OleObject_Unadvise(IOleObject *iface, DWORD dwConnection)
537 WebBrowser *This = impl_from_IOleObject(iface);
538 FIXME("(%p)->(%d)\n", This, dwConnection);
539 return E_NOTIMPL;
542 static HRESULT WINAPI OleObject_EnumAdvise(IOleObject *iface, IEnumSTATDATA **ppenumAdvise)
544 WebBrowser *This = impl_from_IOleObject(iface);
545 FIXME("(%p)->(%p)\n", This, ppenumAdvise);
546 return S_OK;
549 static HRESULT WINAPI OleObject_GetMiscStatus(IOleObject *iface, DWORD dwAspect, DWORD *pdwStatus)
551 WebBrowser *This = impl_from_IOleObject(iface);
553 TRACE("(%p)->(%x, %p)\n", This, dwAspect, pdwStatus);
555 *pdwStatus = OLEMISC_SETCLIENTSITEFIRST|OLEMISC_ACTIVATEWHENVISIBLE|OLEMISC_INSIDEOUT
556 |OLEMISC_CANTLINKINSIDE|OLEMISC_RECOMPOSEONRESIZE;
558 return S_OK;
561 static HRESULT WINAPI OleObject_SetColorScheme(IOleObject *iface, LOGPALETTE* pLogpal)
563 WebBrowser *This = impl_from_IOleObject(iface);
564 FIXME("(%p)->(%p)\n", This, pLogpal);
565 return E_NOTIMPL;
568 static const IOleObjectVtbl OleObjectVtbl =
570 OleObject_QueryInterface,
571 OleObject_AddRef,
572 OleObject_Release,
573 OleObject_SetClientSite,
574 OleObject_GetClientSite,
575 OleObject_SetHostNames,
576 OleObject_Close,
577 OleObject_SetMoniker,
578 OleObject_GetMoniker,
579 OleObject_InitFromData,
580 OleObject_GetClipboardData,
581 OleObject_DoVerb,
582 OleObject_EnumVerbs,
583 OleObject_Update,
584 OleObject_IsUpToDate,
585 OleObject_GetUserClassID,
586 OleObject_GetUserType,
587 OleObject_SetExtent,
588 OleObject_GetExtent,
589 OleObject_Advise,
590 OleObject_Unadvise,
591 OleObject_EnumAdvise,
592 OleObject_GetMiscStatus,
593 OleObject_SetColorScheme
596 /**********************************************************************
597 * Implement the IOleInPlaceObject interface
600 static inline WebBrowser *impl_from_IOleInPlaceObject(IOleInPlaceObject *iface)
602 return CONTAINING_RECORD(iface, WebBrowser, IOleInPlaceObject_iface);
605 static HRESULT WINAPI OleInPlaceObject_QueryInterface(IOleInPlaceObject *iface,
606 REFIID riid, LPVOID *ppobj)
608 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
609 return IWebBrowser_QueryInterface(&This->IWebBrowser2_iface, riid, ppobj);
612 static ULONG WINAPI OleInPlaceObject_AddRef(IOleInPlaceObject *iface)
614 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
615 return IWebBrowser_AddRef(&This->IWebBrowser2_iface);
618 static ULONG WINAPI OleInPlaceObject_Release(IOleInPlaceObject *iface)
620 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
621 return IWebBrowser_Release(&This->IWebBrowser2_iface);
624 static HRESULT WINAPI OleInPlaceObject_GetWindow(IOleInPlaceObject *iface, HWND* phwnd)
626 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
628 TRACE("(%p)->(%p)\n", This, phwnd);
630 *phwnd = This->shell_embedding_hwnd;
631 return S_OK;
634 static HRESULT WINAPI OleInPlaceObject_ContextSensitiveHelp(IOleInPlaceObject *iface,
635 BOOL fEnterMode)
637 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
638 FIXME("(%p)->(%x)\n", This, fEnterMode);
639 return E_NOTIMPL;
642 static HRESULT WINAPI OleInPlaceObject_InPlaceDeactivate(IOleInPlaceObject *iface)
644 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
645 FIXME("(%p)\n", This);
647 if(This->inplace) {
648 IOleInPlaceSite_Release(This->inplace);
649 This->inplace = NULL;
652 return S_OK;
655 static HRESULT WINAPI OleInPlaceObject_UIDeactivate(IOleInPlaceObject *iface)
657 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
658 FIXME("(%p)\n", This);
659 return E_NOTIMPL;
662 static HRESULT WINAPI OleInPlaceObject_SetObjectRects(IOleInPlaceObject *iface,
663 LPCRECT lprcPosRect, LPCRECT lprcClipRect)
665 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
667 TRACE("(%p)->(%p %p)\n", This, lprcPosRect, lprcClipRect);
669 This->pos_rect = *lprcPosRect;
671 if(lprcClipRect)
672 This->clip_rect = *lprcClipRect;
674 if(This->shell_embedding_hwnd) {
675 SetWindowPos(This->shell_embedding_hwnd, NULL,
676 lprcPosRect->left, lprcPosRect->top,
677 lprcPosRect->right-lprcPosRect->left,
678 lprcPosRect->bottom-lprcPosRect->top,
679 SWP_NOZORDER | SWP_NOACTIVATE);
682 return S_OK;
685 static HRESULT WINAPI OleInPlaceObject_ReactivateAndUndo(IOleInPlaceObject *iface)
687 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
688 FIXME("(%p)\n", This);
689 return E_NOTIMPL;
692 static const IOleInPlaceObjectVtbl OleInPlaceObjectVtbl =
694 OleInPlaceObject_QueryInterface,
695 OleInPlaceObject_AddRef,
696 OleInPlaceObject_Release,
697 OleInPlaceObject_GetWindow,
698 OleInPlaceObject_ContextSensitiveHelp,
699 OleInPlaceObject_InPlaceDeactivate,
700 OleInPlaceObject_UIDeactivate,
701 OleInPlaceObject_SetObjectRects,
702 OleInPlaceObject_ReactivateAndUndo
705 /**********************************************************************
706 * Implement the IOleControl interface
709 static inline WebBrowser *impl_from_IOleControl(IOleControl *iface)
711 return CONTAINING_RECORD(iface, WebBrowser, IOleControl_iface);
714 static HRESULT WINAPI OleControl_QueryInterface(IOleControl *iface,
715 REFIID riid, LPVOID *ppobj)
717 WebBrowser *This = impl_from_IOleControl(iface);
718 return IWebBrowser_QueryInterface(&This->IWebBrowser2_iface, riid, ppobj);
721 static ULONG WINAPI OleControl_AddRef(IOleControl *iface)
723 WebBrowser *This = impl_from_IOleControl(iface);
724 return IWebBrowser_AddRef(&This->IWebBrowser2_iface);
727 static ULONG WINAPI OleControl_Release(IOleControl *iface)
729 WebBrowser *This = impl_from_IOleControl(iface);
730 return IWebBrowser_Release(&This->IWebBrowser2_iface);
733 static HRESULT WINAPI OleControl_GetControlInfo(IOleControl *iface, LPCONTROLINFO pCI)
735 WebBrowser *This = impl_from_IOleControl(iface);
737 TRACE("(%p)->(%p)\n", This, pCI);
739 /* Tests show that this function should be not implemented */
740 return E_NOTIMPL;
743 static HRESULT WINAPI OleControl_OnMnemonic(IOleControl *iface, struct tagMSG *pMsg)
745 WebBrowser *This = impl_from_IOleControl(iface);
746 FIXME("(%p)->(%p)\n", This, pMsg);
747 return E_NOTIMPL;
750 static HRESULT WINAPI OleControl_OnAmbientPropertyChange(IOleControl *iface, DISPID dispID)
752 WebBrowser *This = impl_from_IOleControl(iface);
754 TRACE("(%p)->(%d)\n", This, dispID);
756 switch(dispID) {
757 case DISPID_UNKNOWN:
758 /* Unknown means multiple properties changed, so check them all.
759 * BUT the Webbrowser OleControl object doesn't appear to do this.
761 return S_OK;
762 case DISPID_AMBIENT_DLCONTROL:
763 return S_OK;
764 case DISPID_AMBIENT_OFFLINEIFNOTCONNECTED:
765 return on_offlineconnected_change(This);
766 case DISPID_AMBIENT_SILENT:
767 return on_silent_change(This);
770 FIXME("Unknown dispID %d\n", dispID);
771 return E_NOTIMPL;
774 static HRESULT WINAPI OleControl_FreezeEvents(IOleControl *iface, BOOL bFreeze)
776 WebBrowser *This = impl_from_IOleControl(iface);
777 FIXME("(%p)->(%x)\n", This, bFreeze);
778 return E_NOTIMPL;
781 static const IOleControlVtbl OleControlVtbl =
783 OleControl_QueryInterface,
784 OleControl_AddRef,
785 OleControl_Release,
786 OleControl_GetControlInfo,
787 OleControl_OnMnemonic,
788 OleControl_OnAmbientPropertyChange,
789 OleControl_FreezeEvents
792 static inline WebBrowser *impl_from_IOleInPlaceActiveObject(IOleInPlaceActiveObject *iface)
794 return CONTAINING_RECORD(iface, WebBrowser, IOleInPlaceActiveObject_iface);
797 static HRESULT WINAPI InPlaceActiveObject_QueryInterface(IOleInPlaceActiveObject *iface,
798 REFIID riid, void **ppv)
800 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
801 return IWebBrowser2_QueryInterface(&This->IWebBrowser2_iface, riid, ppv);
804 static ULONG WINAPI InPlaceActiveObject_AddRef(IOleInPlaceActiveObject *iface)
806 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
807 return IWebBrowser2_AddRef(&This->IWebBrowser2_iface);
810 static ULONG WINAPI InPlaceActiveObject_Release(IOleInPlaceActiveObject *iface)
812 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
813 return IWebBrowser2_Release(&This->IWebBrowser2_iface);
816 static HRESULT WINAPI InPlaceActiveObject_GetWindow(IOleInPlaceActiveObject *iface,
817 HWND *phwnd)
819 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
820 return IOleInPlaceObject_GetWindow(&This->IOleInPlaceObject_iface, phwnd);
823 static HRESULT WINAPI InPlaceActiveObject_ContextSensitiveHelp(IOleInPlaceActiveObject *iface,
824 BOOL fEnterMode)
826 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
827 return IOleInPlaceObject_ContextSensitiveHelp(&This->IOleInPlaceObject_iface, fEnterMode);
830 static HRESULT WINAPI InPlaceActiveObject_TranslateAccelerator(IOleInPlaceActiveObject *iface,
831 LPMSG lpmsg)
833 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
834 IOleInPlaceActiveObject *activeobj;
835 HRESULT hr = S_FALSE;
837 TRACE("(%p)->(%p)\n", This, lpmsg);
839 if(This->doc_host.document) {
840 if(SUCCEEDED(IUnknown_QueryInterface(This->doc_host.document,
841 &IID_IOleInPlaceActiveObject,
842 (void**)&activeobj))) {
843 hr = IOleInPlaceActiveObject_TranslateAccelerator(activeobj, lpmsg);
844 IOleInPlaceActiveObject_Release(activeobj);
848 if(SUCCEEDED(hr))
849 return hr;
850 else
851 return S_FALSE;
854 static HRESULT WINAPI InPlaceActiveObject_OnFrameWindowActivate(IOleInPlaceActiveObject *iface,
855 BOOL fActivate)
857 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
858 FIXME("(%p)->(%x)\n", This, fActivate);
859 return E_NOTIMPL;
862 static HRESULT WINAPI InPlaceActiveObject_OnDocWindowActivate(IOleInPlaceActiveObject *iface,
863 BOOL fActivate)
865 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
866 FIXME("(%p)->(%x)\n", This, fActivate);
867 return E_NOTIMPL;
870 static HRESULT WINAPI InPlaceActiveObject_ResizeBorder(IOleInPlaceActiveObject *iface,
871 LPCRECT lprcBorder, IOleInPlaceUIWindow *pUIWindow, BOOL fFrameWindow)
873 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
874 FIXME("(%p)->(%p %p %x)\n", This, lprcBorder, pUIWindow, fFrameWindow);
875 return E_NOTIMPL;
878 static HRESULT WINAPI InPlaceActiveObject_EnableModeless(IOleInPlaceActiveObject *iface,
879 BOOL fEnable)
881 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
882 FIXME("(%p)->(%x)\n", This, fEnable);
883 return E_NOTIMPL;
886 static const IOleInPlaceActiveObjectVtbl OleInPlaceActiveObjectVtbl = {
887 InPlaceActiveObject_QueryInterface,
888 InPlaceActiveObject_AddRef,
889 InPlaceActiveObject_Release,
890 InPlaceActiveObject_GetWindow,
891 InPlaceActiveObject_ContextSensitiveHelp,
892 InPlaceActiveObject_TranslateAccelerator,
893 InPlaceActiveObject_OnFrameWindowActivate,
894 InPlaceActiveObject_OnDocWindowActivate,
895 InPlaceActiveObject_ResizeBorder,
896 InPlaceActiveObject_EnableModeless
899 static inline WebBrowser *impl_from_IOleCommandTarget(IOleCommandTarget *iface)
901 return CONTAINING_RECORD(iface, WebBrowser, IOleCommandTarget_iface);
904 static HRESULT WINAPI WBOleCommandTarget_QueryInterface(IOleCommandTarget *iface,
905 REFIID riid, void **ppv)
907 WebBrowser *This = impl_from_IOleCommandTarget(iface);
908 return IWebBrowser2_QueryInterface(&This->IWebBrowser2_iface, riid, ppv);
911 static ULONG WINAPI WBOleCommandTarget_AddRef(IOleCommandTarget *iface)
913 WebBrowser *This = impl_from_IOleCommandTarget(iface);
914 return IWebBrowser2_AddRef(&This->IWebBrowser2_iface);
917 static ULONG WINAPI WBOleCommandTarget_Release(IOleCommandTarget *iface)
919 WebBrowser *This = impl_from_IOleCommandTarget(iface);
920 return IWebBrowser2_Release(&This->IWebBrowser2_iface);
923 static HRESULT WINAPI WBOleCommandTarget_QueryStatus(IOleCommandTarget *iface,
924 const GUID *pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[], OLECMDTEXT *pCmdText)
926 WebBrowser *This = impl_from_IOleCommandTarget(iface);
927 IOleCommandTarget *cmdtrg;
928 HRESULT hres;
930 TRACE("(%p)->(%s %u %p %p)\n", This, debugstr_guid(pguidCmdGroup), cCmds, prgCmds,
931 pCmdText);
933 if(!This->doc_host.document)
934 return 0x80040104;
936 /* NOTE: There are probably some commands that we should handle here
937 * instead of forwarding to document object. */
939 hres = IUnknown_QueryInterface(This->doc_host.document, &IID_IOleCommandTarget, (void**)&cmdtrg);
940 if(FAILED(hres))
941 return hres;
943 hres = IOleCommandTarget_QueryStatus(cmdtrg, pguidCmdGroup, cCmds, prgCmds, pCmdText);
944 IOleCommandTarget_Release(cmdtrg);
946 return hres;
949 static HRESULT WINAPI WBOleCommandTarget_Exec(IOleCommandTarget *iface,
950 const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn,
951 VARIANT *pvaOut)
953 WebBrowser *This = impl_from_IOleCommandTarget(iface);
954 FIXME("(%p)->(%s %d %d %p %p)\n", This, debugstr_guid(pguidCmdGroup), nCmdID,
955 nCmdexecopt, pvaIn, pvaOut);
956 return E_NOTIMPL;
959 static const IOleCommandTargetVtbl OleCommandTargetVtbl = {
960 WBOleCommandTarget_QueryInterface,
961 WBOleCommandTarget_AddRef,
962 WBOleCommandTarget_Release,
963 WBOleCommandTarget_QueryStatus,
964 WBOleCommandTarget_Exec
967 void WebBrowser_OleObject_Init(WebBrowser *This)
969 DWORD dpi_x;
970 DWORD dpi_y;
971 HDC hdc;
973 /* default aspect ratio is 96dpi / 96dpi */
974 hdc = GetDC(0);
975 dpi_x = GetDeviceCaps(hdc, LOGPIXELSX);
976 dpi_y = GetDeviceCaps(hdc, LOGPIXELSY);
977 ReleaseDC(0, hdc);
979 This->IOleObject_iface.lpVtbl = &OleObjectVtbl;
980 This->IOleInPlaceObject_iface.lpVtbl = &OleInPlaceObjectVtbl;
981 This->IOleControl_iface.lpVtbl = &OleControlVtbl;
982 This->IOleInPlaceActiveObject_iface.lpVtbl = &OleInPlaceActiveObjectVtbl;
983 This->IOleCommandTarget_iface.lpVtbl = &OleCommandTargetVtbl;
985 /* Default size is 50x20 pixels, in himetric units */
986 This->extent.cx = MulDiv( 50, 2540, dpi_x );
987 This->extent.cy = MulDiv( 20, 2540, dpi_y );
990 void WebBrowser_OleObject_Destroy(WebBrowser *This)
992 release_client_site(This);