ieframe: Moved WebBrowser and InternetExplorer objects implementations to ieframe.
[wine/testsucceed.git] / dlls / ieframe / oleobject.c
blobe4ee7173c20e89e0614df983f25f22ffac182bb3
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(shdocvw);
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 = IOleInPlaceSite_CanInPlaceActivate(This->inplace);
135 if(hres != S_OK) {
136 WARN("CanInPlaceActivate returned: %08x\n", hres);
137 IOleInPlaceSite_Release(This->inplace);
138 return E_FAIL;
141 hres = IOleInPlaceSite_GetWindow(This->inplace, &parent_hwnd);
142 if(SUCCEEDED(hres))
143 SHSetParentHwnd(This->shell_embedding_hwnd, parent_hwnd);
145 IOleInPlaceSite_OnInPlaceActivate(This->inplace);
147 This->frameinfo.cb = sizeof(OLEINPLACEFRAMEINFO);
148 IOleInPlaceSite_GetWindowContext(This->inplace, &This->doc_host.frame, &This->uiwindow,
149 &This->pos_rect, &This->clip_rect,
150 &This->frameinfo);
152 SetWindowPos(This->shell_embedding_hwnd, NULL,
153 This->pos_rect.left, This->pos_rect.top,
154 This->pos_rect.right-This->pos_rect.left,
155 This->pos_rect.bottom-This->pos_rect.top,
156 SWP_NOZORDER | SWP_SHOWWINDOW);
158 if(This->client) {
159 IOleContainer *container;
161 IOleClientSite_ShowObject(This->client);
163 hres = IOleClientSite_GetContainer(This->client, &container);
164 if(SUCCEEDED(hres)) {
165 if(This->container)
166 IOleContainer_Release(This->container);
167 This->container = container;
171 if(This->doc_host.frame)
172 IOleInPlaceFrame_GetWindow(This->doc_host.frame, &This->frame_hwnd);
174 return S_OK;
177 static HRESULT activate_ui(WebBrowser *This, IOleClientSite *active_site)
179 HRESULT hres;
181 static const WCHAR wszitem[] = {'i','t','e','m',0};
183 if(This->inplace)
185 if(This->shell_embedding_hwnd)
186 ShowWindow(This->shell_embedding_hwnd, SW_SHOW);
187 return S_OK;
190 hres = activate_inplace(This, active_site);
191 if(FAILED(hres))
192 return hres;
194 IOleInPlaceSite_OnUIActivate(This->inplace);
196 if(This->doc_host.frame)
197 IOleInPlaceFrame_SetActiveObject(This->doc_host.frame, &This->IOleInPlaceActiveObject_iface, wszitem);
198 if(This->uiwindow)
199 IOleInPlaceUIWindow_SetActiveObject(This->uiwindow, &This->IOleInPlaceActiveObject_iface, wszitem);
201 if(This->doc_host.frame)
202 IOleInPlaceFrame_SetMenu(This->doc_host.frame, NULL, NULL, This->shell_embedding_hwnd);
204 SetFocus(This->shell_embedding_hwnd);
206 return S_OK;
209 static HRESULT get_client_disp_property(IOleClientSite *client, DISPID dispid, VARIANT *res)
211 IDispatch *disp = NULL;
212 DISPPARAMS dispparams = {NULL, 0};
213 HRESULT hres;
215 VariantInit(res);
217 if(!client)
218 return S_OK;
220 hres = IOleClientSite_QueryInterface(client, &IID_IDispatch, (void**)&disp);
221 if(FAILED(hres)) {
222 TRACE("Could not get IDispatch\n");
223 return hres;
226 hres = IDispatch_Invoke(disp, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
227 DISPATCH_PROPERTYGET, &dispparams, res, NULL, NULL);
229 IDispatch_Release(disp);
231 return hres;
234 static HRESULT on_offlineconnected_change(WebBrowser *This)
236 VARIANT offline;
238 get_client_disp_property(This->client, DISPID_AMBIENT_OFFLINEIFNOTCONNECTED, &offline);
240 if(V_VT(&offline) == VT_BOOL)
241 IWebBrowser2_put_Offline(&This->IWebBrowser2_iface, V_BOOL(&offline));
242 else if(V_VT(&offline) != VT_EMPTY)
243 WARN("wrong V_VT(silent) %d\n", V_VT(&offline));
245 return S_OK;
248 static HRESULT on_silent_change(WebBrowser *This)
250 VARIANT silent;
252 get_client_disp_property(This->client, DISPID_AMBIENT_SILENT, &silent);
254 if(V_VT(&silent) == VT_BOOL)
255 IWebBrowser2_put_Silent(&This->IWebBrowser2_iface, V_BOOL(&silent));
256 else if(V_VT(&silent) != VT_EMPTY)
257 WARN("wrong V_VT(silent) %d\n", V_VT(&silent));
259 return S_OK;
262 static void release_client_site(WebBrowser *This)
264 release_dochost_client(&This->doc_host);
266 if(This->shell_embedding_hwnd) {
267 DestroyWindow(This->shell_embedding_hwnd);
268 This->shell_embedding_hwnd = NULL;
271 if(This->inplace) {
272 IOleInPlaceSite_Release(This->inplace);
273 This->inplace = NULL;
276 if(This->container) {
277 IOleContainer_Release(This->container);
278 This->container = NULL;
281 if(This->uiwindow) {
282 IOleInPlaceUIWindow_Release(This->uiwindow);
283 This->uiwindow = NULL;
286 if(This->client) {
287 IOleClientSite_Release(This->client);
288 This->client = NULL;
292 /**********************************************************************
293 * Implement the IOleObject interface for the WebBrowser control
296 static inline WebBrowser *impl_from_IOleObject(IOleObject *iface)
298 return CONTAINING_RECORD(iface, WebBrowser, IOleObject_iface);
301 static HRESULT WINAPI OleObject_QueryInterface(IOleObject *iface, REFIID riid, void **ppv)
303 WebBrowser *This = impl_from_IOleObject(iface);
304 return IWebBrowser_QueryInterface(&This->IWebBrowser2_iface, riid, ppv);
307 static ULONG WINAPI OleObject_AddRef(IOleObject *iface)
309 WebBrowser *This = impl_from_IOleObject(iface);
310 return IWebBrowser_AddRef(&This->IWebBrowser2_iface);
313 static ULONG WINAPI OleObject_Release(IOleObject *iface)
315 WebBrowser *This = impl_from_IOleObject(iface);
316 return IWebBrowser_Release(&This->IWebBrowser2_iface);
319 static HRESULT WINAPI OleObject_SetClientSite(IOleObject *iface, LPOLECLIENTSITE pClientSite)
321 WebBrowser *This = impl_from_IOleObject(iface);
322 IDocHostUIHandler *hostui;
323 IOleContainer *container;
324 IDispatch *disp;
325 HRESULT hres;
327 TRACE("(%p)->(%p)\n", This, pClientSite);
329 if(This->client == pClientSite)
330 return S_OK;
332 release_client_site(This);
334 if(!pClientSite) {
335 if(This->doc_host.document)
336 deactivate_document(&This->doc_host);
337 return S_OK;
340 IOleClientSite_AddRef(pClientSite);
341 This->client = pClientSite;
343 hres = IOleClientSite_QueryInterface(This->client, &IID_IDispatch,
344 (void**)&disp);
345 if(SUCCEEDED(hres))
346 This->doc_host.client_disp = disp;
348 hres = IOleClientSite_QueryInterface(This->client, &IID_IDocHostUIHandler,
349 (void**)&hostui);
350 if(SUCCEEDED(hres))
351 This->doc_host.hostui = hostui;
353 hres = IOleClientSite_GetContainer(This->client, &container);
354 if(SUCCEEDED(hres)) {
355 ITargetContainer *target_container;
357 hres = IOleContainer_QueryInterface(container, &IID_ITargetContainer,
358 (void**)&target_container);
359 if(SUCCEEDED(hres)) {
360 FIXME("Unsupported ITargetContainer\n");
361 ITargetContainer_Release(target_container);
364 IOleContainer_Release(container);
367 create_shell_embedding_hwnd(This);
369 on_offlineconnected_change(This);
370 on_silent_change(This);
372 return S_OK;
375 static HRESULT WINAPI OleObject_GetClientSite(IOleObject *iface, LPOLECLIENTSITE *ppClientSite)
377 WebBrowser *This = impl_from_IOleObject(iface);
379 TRACE("(%p)->(%p)\n", This, ppClientSite);
381 if(!ppClientSite)
382 return E_INVALIDARG;
384 if(This->client)
385 IOleClientSite_AddRef(This->client);
386 *ppClientSite = This->client;
388 return S_OK;
391 static HRESULT WINAPI OleObject_SetHostNames(IOleObject *iface, LPCOLESTR szContainerApp,
392 LPCOLESTR szContainerObj)
394 WebBrowser *This = impl_from_IOleObject(iface);
396 TRACE("(%p)->(%s, %s)\n", This, debugstr_w(szContainerApp), debugstr_w(szContainerObj));
398 /* We have nothing to do here. */
399 return S_OK;
402 static HRESULT WINAPI OleObject_Close(IOleObject *iface, DWORD dwSaveOption)
404 WebBrowser *This = impl_from_IOleObject(iface);
405 FIXME("(%p)->(%d)\n", This, dwSaveOption);
406 return E_NOTIMPL;
409 static HRESULT WINAPI OleObject_SetMoniker(IOleObject *iface, DWORD dwWhichMoniker, IMoniker* pmk)
411 WebBrowser *This = impl_from_IOleObject(iface);
412 FIXME("(%p)->(%d, %p)\n", This, dwWhichMoniker, pmk);
413 return E_NOTIMPL;
416 static HRESULT WINAPI OleObject_GetMoniker(IOleObject *iface, DWORD dwAssign,
417 DWORD dwWhichMoniker, LPMONIKER *ppmk)
419 WebBrowser *This = impl_from_IOleObject(iface);
420 FIXME("(%p)->(%d, %d, %p)\n", This, dwAssign, dwWhichMoniker, ppmk);
421 return E_NOTIMPL;
424 static HRESULT WINAPI OleObject_InitFromData(IOleObject *iface, LPDATAOBJECT pDataObject,
425 BOOL fCreation, DWORD dwReserved)
427 WebBrowser *This = impl_from_IOleObject(iface);
428 FIXME("(%p)->(%p, %d, %d)\n", This, pDataObject, fCreation, dwReserved);
429 return E_NOTIMPL;
432 static HRESULT WINAPI OleObject_GetClipboardData(IOleObject *iface, DWORD dwReserved,
433 LPDATAOBJECT *ppDataObject)
435 WebBrowser *This = impl_from_IOleObject(iface);
436 FIXME("(%p)->(%d, %p)\n", This, dwReserved, ppDataObject);
437 return E_NOTIMPL;
440 static HRESULT WINAPI OleObject_DoVerb(IOleObject *iface, LONG iVerb, struct tagMSG* lpmsg,
441 LPOLECLIENTSITE pActiveSite, LONG lindex, HWND hwndParent, LPCRECT lprcPosRect)
443 WebBrowser *This = impl_from_IOleObject(iface);
445 TRACE("(%p)->(%d %p %p %d %p %p)\n", This, iVerb, lpmsg, pActiveSite, lindex, hwndParent,
446 lprcPosRect);
448 switch (iVerb)
450 case OLEIVERB_SHOW:
451 TRACE("OLEIVERB_SHOW\n");
452 return activate_ui(This, pActiveSite);
453 case OLEIVERB_UIACTIVATE:
454 TRACE("OLEIVERB_UIACTIVATE\n");
455 return activate_ui(This, pActiveSite);
456 case OLEIVERB_INPLACEACTIVATE:
457 TRACE("OLEIVERB_INPLACEACTIVATE\n");
458 return activate_inplace(This, pActiveSite);
459 case OLEIVERB_HIDE:
460 TRACE("OLEIVERB_HIDE\n");
461 if(This->shell_embedding_hwnd)
462 ShowWindow(This->shell_embedding_hwnd, SW_HIDE);
463 return S_OK;
464 default:
465 FIXME("stub for %d\n", iVerb);
466 break;
469 return E_NOTIMPL;
472 static HRESULT WINAPI OleObject_EnumVerbs(IOleObject *iface, IEnumOLEVERB **ppEnumOleVerb)
474 WebBrowser *This = impl_from_IOleObject(iface);
475 TRACE("(%p)->(%p)\n", This, ppEnumOleVerb);
476 return OleRegEnumVerbs(&CLSID_WebBrowser, ppEnumOleVerb);
479 static HRESULT WINAPI OleObject_Update(IOleObject *iface)
481 WebBrowser *This = impl_from_IOleObject(iface);
482 FIXME("(%p)\n", This);
483 return E_NOTIMPL;
486 static HRESULT WINAPI OleObject_IsUpToDate(IOleObject *iface)
488 WebBrowser *This = impl_from_IOleObject(iface);
489 FIXME("(%p)\n", This);
490 return E_NOTIMPL;
493 static HRESULT WINAPI OleObject_GetUserClassID(IOleObject *iface, CLSID* pClsid)
495 WebBrowser *This = impl_from_IOleObject(iface);
496 FIXME("(%p)->(%p)\n", This, pClsid);
497 return E_NOTIMPL;
500 static HRESULT WINAPI OleObject_GetUserType(IOleObject *iface, DWORD dwFormOfType,
501 LPOLESTR* pszUserType)
503 WebBrowser *This = impl_from_IOleObject(iface);
504 TRACE("(%p, %d, %p)\n", This, dwFormOfType, pszUserType);
505 return OleRegGetUserType(&CLSID_WebBrowser, dwFormOfType, pszUserType);
508 static HRESULT WINAPI OleObject_SetExtent(IOleObject *iface, DWORD dwDrawAspect, SIZEL *psizel)
510 WebBrowser *This = impl_from_IOleObject(iface);
512 TRACE("(%p)->(%x %p)\n", This, dwDrawAspect, psizel);
514 /* Tests show that dwDrawAspect is ignored */
515 This->extent = *psizel;
516 return S_OK;
519 static HRESULT WINAPI OleObject_GetExtent(IOleObject *iface, DWORD dwDrawAspect, SIZEL *psizel)
521 WebBrowser *This = impl_from_IOleObject(iface);
523 TRACE("(%p)->(%x, %p)\n", This, dwDrawAspect, psizel);
525 /* Tests show that dwDrawAspect is ignored */
526 *psizel = This->extent;
527 return S_OK;
530 static HRESULT WINAPI OleObject_Advise(IOleObject *iface, IAdviseSink *pAdvSink,
531 DWORD* pdwConnection)
533 WebBrowser *This = impl_from_IOleObject(iface);
534 FIXME("(%p)->(%p, %p)\n", This, pAdvSink, pdwConnection);
535 return E_NOTIMPL;
538 static HRESULT WINAPI OleObject_Unadvise(IOleObject *iface, DWORD dwConnection)
540 WebBrowser *This = impl_from_IOleObject(iface);
541 FIXME("(%p)->(%d)\n", This, dwConnection);
542 return E_NOTIMPL;
545 static HRESULT WINAPI OleObject_EnumAdvise(IOleObject *iface, IEnumSTATDATA **ppenumAdvise)
547 WebBrowser *This = impl_from_IOleObject(iface);
548 FIXME("(%p)->(%p)\n", This, ppenumAdvise);
549 return S_OK;
552 static HRESULT WINAPI OleObject_GetMiscStatus(IOleObject *iface, DWORD dwAspect, DWORD *pdwStatus)
554 WebBrowser *This = impl_from_IOleObject(iface);
556 TRACE("(%p)->(%x, %p)\n", This, dwAspect, pdwStatus);
558 *pdwStatus = OLEMISC_SETCLIENTSITEFIRST|OLEMISC_ACTIVATEWHENVISIBLE|OLEMISC_INSIDEOUT
559 |OLEMISC_CANTLINKINSIDE|OLEMISC_RECOMPOSEONRESIZE;
561 return S_OK;
564 static HRESULT WINAPI OleObject_SetColorScheme(IOleObject *iface, LOGPALETTE* pLogpal)
566 WebBrowser *This = impl_from_IOleObject(iface);
567 FIXME("(%p)->(%p)\n", This, pLogpal);
568 return E_NOTIMPL;
571 static const IOleObjectVtbl OleObjectVtbl =
573 OleObject_QueryInterface,
574 OleObject_AddRef,
575 OleObject_Release,
576 OleObject_SetClientSite,
577 OleObject_GetClientSite,
578 OleObject_SetHostNames,
579 OleObject_Close,
580 OleObject_SetMoniker,
581 OleObject_GetMoniker,
582 OleObject_InitFromData,
583 OleObject_GetClipboardData,
584 OleObject_DoVerb,
585 OleObject_EnumVerbs,
586 OleObject_Update,
587 OleObject_IsUpToDate,
588 OleObject_GetUserClassID,
589 OleObject_GetUserType,
590 OleObject_SetExtent,
591 OleObject_GetExtent,
592 OleObject_Advise,
593 OleObject_Unadvise,
594 OleObject_EnumAdvise,
595 OleObject_GetMiscStatus,
596 OleObject_SetColorScheme
599 /**********************************************************************
600 * Implement the IOleInPlaceObject interface
603 static inline WebBrowser *impl_from_IOleInPlaceObject(IOleInPlaceObject *iface)
605 return CONTAINING_RECORD(iface, WebBrowser, IOleInPlaceObject_iface);
608 static HRESULT WINAPI OleInPlaceObject_QueryInterface(IOleInPlaceObject *iface,
609 REFIID riid, LPVOID *ppobj)
611 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
612 return IWebBrowser_QueryInterface(&This->IWebBrowser2_iface, riid, ppobj);
615 static ULONG WINAPI OleInPlaceObject_AddRef(IOleInPlaceObject *iface)
617 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
618 return IWebBrowser_AddRef(&This->IWebBrowser2_iface);
621 static ULONG WINAPI OleInPlaceObject_Release(IOleInPlaceObject *iface)
623 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
624 return IWebBrowser_Release(&This->IWebBrowser2_iface);
627 static HRESULT WINAPI OleInPlaceObject_GetWindow(IOleInPlaceObject *iface, HWND* phwnd)
629 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
631 TRACE("(%p)->(%p)\n", This, phwnd);
633 *phwnd = This->shell_embedding_hwnd;
634 return S_OK;
637 static HRESULT WINAPI OleInPlaceObject_ContextSensitiveHelp(IOleInPlaceObject *iface,
638 BOOL fEnterMode)
640 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
641 FIXME("(%p)->(%x)\n", This, fEnterMode);
642 return E_NOTIMPL;
645 static HRESULT WINAPI OleInPlaceObject_InPlaceDeactivate(IOleInPlaceObject *iface)
647 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
648 FIXME("(%p)\n", This);
650 if(This->inplace) {
651 IOleInPlaceSite_Release(This->inplace);
652 This->inplace = NULL;
655 return S_OK;
658 static HRESULT WINAPI OleInPlaceObject_UIDeactivate(IOleInPlaceObject *iface)
660 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
661 FIXME("(%p)\n", This);
662 return E_NOTIMPL;
665 static HRESULT WINAPI OleInPlaceObject_SetObjectRects(IOleInPlaceObject *iface,
666 LPCRECT lprcPosRect, LPCRECT lprcClipRect)
668 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
670 TRACE("(%p)->(%p %p)\n", This, lprcPosRect, lprcClipRect);
672 This->pos_rect = *lprcPosRect;
674 if(lprcClipRect)
675 This->clip_rect = *lprcClipRect;
677 if(This->shell_embedding_hwnd) {
678 SetWindowPos(This->shell_embedding_hwnd, NULL,
679 lprcPosRect->left, lprcPosRect->top,
680 lprcPosRect->right-lprcPosRect->left,
681 lprcPosRect->bottom-lprcPosRect->top,
682 SWP_NOZORDER | SWP_NOACTIVATE);
685 return S_OK;
688 static HRESULT WINAPI OleInPlaceObject_ReactivateAndUndo(IOleInPlaceObject *iface)
690 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
691 FIXME("(%p)\n", This);
692 return E_NOTIMPL;
695 static const IOleInPlaceObjectVtbl OleInPlaceObjectVtbl =
697 OleInPlaceObject_QueryInterface,
698 OleInPlaceObject_AddRef,
699 OleInPlaceObject_Release,
700 OleInPlaceObject_GetWindow,
701 OleInPlaceObject_ContextSensitiveHelp,
702 OleInPlaceObject_InPlaceDeactivate,
703 OleInPlaceObject_UIDeactivate,
704 OleInPlaceObject_SetObjectRects,
705 OleInPlaceObject_ReactivateAndUndo
708 /**********************************************************************
709 * Implement the IOleControl interface
712 static inline WebBrowser *impl_from_IOleControl(IOleControl *iface)
714 return CONTAINING_RECORD(iface, WebBrowser, IOleControl_iface);
717 static HRESULT WINAPI OleControl_QueryInterface(IOleControl *iface,
718 REFIID riid, LPVOID *ppobj)
720 WebBrowser *This = impl_from_IOleControl(iface);
721 return IWebBrowser_QueryInterface(&This->IWebBrowser2_iface, riid, ppobj);
724 static ULONG WINAPI OleControl_AddRef(IOleControl *iface)
726 WebBrowser *This = impl_from_IOleControl(iface);
727 return IWebBrowser_AddRef(&This->IWebBrowser2_iface);
730 static ULONG WINAPI OleControl_Release(IOleControl *iface)
732 WebBrowser *This = impl_from_IOleControl(iface);
733 return IWebBrowser_Release(&This->IWebBrowser2_iface);
736 static HRESULT WINAPI OleControl_GetControlInfo(IOleControl *iface, LPCONTROLINFO pCI)
738 WebBrowser *This = impl_from_IOleControl(iface);
740 TRACE("(%p)->(%p)\n", This, pCI);
742 /* Tests show that this function should be not implemented */
743 return E_NOTIMPL;
746 static HRESULT WINAPI OleControl_OnMnemonic(IOleControl *iface, struct tagMSG *pMsg)
748 WebBrowser *This = impl_from_IOleControl(iface);
749 FIXME("(%p)->(%p)\n", This, pMsg);
750 return E_NOTIMPL;
753 static HRESULT WINAPI OleControl_OnAmbientPropertyChange(IOleControl *iface, DISPID dispID)
755 WebBrowser *This = impl_from_IOleControl(iface);
757 TRACE("(%p)->(%d)\n", This, dispID);
759 switch(dispID) {
760 case DISPID_UNKNOWN:
761 /* Unknown means multiple properties changed, so check them all.
762 * BUT the Webbrowser OleControl object doesn't appear to do this.
764 return S_OK;
765 case DISPID_AMBIENT_DLCONTROL:
766 return S_OK;
767 case DISPID_AMBIENT_OFFLINEIFNOTCONNECTED:
768 return on_offlineconnected_change(This);
769 case DISPID_AMBIENT_SILENT:
770 return on_silent_change(This);
773 FIXME("Unknown dispID %d\n", dispID);
774 return E_NOTIMPL;
777 static HRESULT WINAPI OleControl_FreezeEvents(IOleControl *iface, BOOL bFreeze)
779 WebBrowser *This = impl_from_IOleControl(iface);
780 FIXME("(%p)->(%x)\n", This, bFreeze);
781 return E_NOTIMPL;
784 static const IOleControlVtbl OleControlVtbl =
786 OleControl_QueryInterface,
787 OleControl_AddRef,
788 OleControl_Release,
789 OleControl_GetControlInfo,
790 OleControl_OnMnemonic,
791 OleControl_OnAmbientPropertyChange,
792 OleControl_FreezeEvents
795 static inline WebBrowser *impl_from_IOleInPlaceActiveObject(IOleInPlaceActiveObject *iface)
797 return CONTAINING_RECORD(iface, WebBrowser, IOleInPlaceActiveObject_iface);
800 static HRESULT WINAPI InPlaceActiveObject_QueryInterface(IOleInPlaceActiveObject *iface,
801 REFIID riid, void **ppv)
803 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
804 return IWebBrowser2_QueryInterface(&This->IWebBrowser2_iface, riid, ppv);
807 static ULONG WINAPI InPlaceActiveObject_AddRef(IOleInPlaceActiveObject *iface)
809 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
810 return IWebBrowser2_AddRef(&This->IWebBrowser2_iface);
813 static ULONG WINAPI InPlaceActiveObject_Release(IOleInPlaceActiveObject *iface)
815 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
816 return IWebBrowser2_Release(&This->IWebBrowser2_iface);
819 static HRESULT WINAPI InPlaceActiveObject_GetWindow(IOleInPlaceActiveObject *iface,
820 HWND *phwnd)
822 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
823 return IOleInPlaceObject_GetWindow(&This->IOleInPlaceObject_iface, phwnd);
826 static HRESULT WINAPI InPlaceActiveObject_ContextSensitiveHelp(IOleInPlaceActiveObject *iface,
827 BOOL fEnterMode)
829 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
830 return IOleInPlaceObject_ContextSensitiveHelp(&This->IOleInPlaceObject_iface, fEnterMode);
833 static HRESULT WINAPI InPlaceActiveObject_TranslateAccelerator(IOleInPlaceActiveObject *iface,
834 LPMSG lpmsg)
836 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
837 IOleInPlaceActiveObject *activeobj;
838 HRESULT hr = S_FALSE;
840 TRACE("(%p)->(%p)\n", This, lpmsg);
842 if(This->doc_host.document) {
843 if(SUCCEEDED(IUnknown_QueryInterface(This->doc_host.document,
844 &IID_IOleInPlaceActiveObject,
845 (void**)&activeobj))) {
846 hr = IOleInPlaceActiveObject_TranslateAccelerator(activeobj, lpmsg);
847 IOleInPlaceActiveObject_Release(activeobj);
851 if(SUCCEEDED(hr))
852 return hr;
853 else
854 return S_FALSE;
857 static HRESULT WINAPI InPlaceActiveObject_OnFrameWindowActivate(IOleInPlaceActiveObject *iface,
858 BOOL fActivate)
860 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
861 FIXME("(%p)->(%x)\n", This, fActivate);
862 return E_NOTIMPL;
865 static HRESULT WINAPI InPlaceActiveObject_OnDocWindowActivate(IOleInPlaceActiveObject *iface,
866 BOOL fActivate)
868 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
869 FIXME("(%p)->(%x)\n", This, fActivate);
870 return E_NOTIMPL;
873 static HRESULT WINAPI InPlaceActiveObject_ResizeBorder(IOleInPlaceActiveObject *iface,
874 LPCRECT lprcBorder, IOleInPlaceUIWindow *pUIWindow, BOOL fFrameWindow)
876 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
877 FIXME("(%p)->(%p %p %x)\n", This, lprcBorder, pUIWindow, fFrameWindow);
878 return E_NOTIMPL;
881 static HRESULT WINAPI InPlaceActiveObject_EnableModeless(IOleInPlaceActiveObject *iface,
882 BOOL fEnable)
884 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
885 FIXME("(%p)->(%x)\n", This, fEnable);
886 return E_NOTIMPL;
889 static const IOleInPlaceActiveObjectVtbl OleInPlaceActiveObjectVtbl = {
890 InPlaceActiveObject_QueryInterface,
891 InPlaceActiveObject_AddRef,
892 InPlaceActiveObject_Release,
893 InPlaceActiveObject_GetWindow,
894 InPlaceActiveObject_ContextSensitiveHelp,
895 InPlaceActiveObject_TranslateAccelerator,
896 InPlaceActiveObject_OnFrameWindowActivate,
897 InPlaceActiveObject_OnDocWindowActivate,
898 InPlaceActiveObject_ResizeBorder,
899 InPlaceActiveObject_EnableModeless
902 static inline WebBrowser *impl_from_IOleCommandTarget(IOleCommandTarget *iface)
904 return CONTAINING_RECORD(iface, WebBrowser, IOleCommandTarget_iface);
907 static HRESULT WINAPI WBOleCommandTarget_QueryInterface(IOleCommandTarget *iface,
908 REFIID riid, void **ppv)
910 WebBrowser *This = impl_from_IOleCommandTarget(iface);
911 return IWebBrowser2_QueryInterface(&This->IWebBrowser2_iface, riid, ppv);
914 static ULONG WINAPI WBOleCommandTarget_AddRef(IOleCommandTarget *iface)
916 WebBrowser *This = impl_from_IOleCommandTarget(iface);
917 return IWebBrowser2_AddRef(&This->IWebBrowser2_iface);
920 static ULONG WINAPI WBOleCommandTarget_Release(IOleCommandTarget *iface)
922 WebBrowser *This = impl_from_IOleCommandTarget(iface);
923 return IWebBrowser2_Release(&This->IWebBrowser2_iface);
926 static HRESULT WINAPI WBOleCommandTarget_QueryStatus(IOleCommandTarget *iface,
927 const GUID *pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[], OLECMDTEXT *pCmdText)
929 WebBrowser *This = impl_from_IOleCommandTarget(iface);
930 IOleCommandTarget *cmdtrg;
931 HRESULT hres;
933 TRACE("(%p)->(%s %u %p %p)\n", This, debugstr_guid(pguidCmdGroup), cCmds, prgCmds,
934 pCmdText);
936 if(!This->doc_host.document)
937 return 0x80040104;
939 /* NOTE: There are probably some commands that we should handle here
940 * instead of forwarding to document object. */
942 hres = IUnknown_QueryInterface(This->doc_host.document, &IID_IOleCommandTarget, (void**)&cmdtrg);
943 if(FAILED(hres))
944 return hres;
946 hres = IOleCommandTarget_QueryStatus(cmdtrg, pguidCmdGroup, cCmds, prgCmds, pCmdText);
947 IOleCommandTarget_Release(cmdtrg);
949 return hres;
952 static HRESULT WINAPI WBOleCommandTarget_Exec(IOleCommandTarget *iface,
953 const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn,
954 VARIANT *pvaOut)
956 WebBrowser *This = impl_from_IOleCommandTarget(iface);
957 FIXME("(%p)->(%s %d %d %p %p)\n", This, debugstr_guid(pguidCmdGroup), nCmdID,
958 nCmdexecopt, pvaIn, pvaOut);
959 return E_NOTIMPL;
962 static const IOleCommandTargetVtbl OleCommandTargetVtbl = {
963 WBOleCommandTarget_QueryInterface,
964 WBOleCommandTarget_AddRef,
965 WBOleCommandTarget_Release,
966 WBOleCommandTarget_QueryStatus,
967 WBOleCommandTarget_Exec
970 void WebBrowser_OleObject_Init(WebBrowser *This)
972 DWORD dpi_x;
973 DWORD dpi_y;
974 HDC hdc;
976 /* default aspect ratio is 96dpi / 96dpi */
977 hdc = GetDC(0);
978 dpi_x = GetDeviceCaps(hdc, LOGPIXELSX);
979 dpi_y = GetDeviceCaps(hdc, LOGPIXELSY);
980 ReleaseDC(0, hdc);
982 This->IOleObject_iface.lpVtbl = &OleObjectVtbl;
983 This->IOleInPlaceObject_iface.lpVtbl = &OleInPlaceObjectVtbl;
984 This->IOleControl_iface.lpVtbl = &OleControlVtbl;
985 This->IOleInPlaceActiveObject_iface.lpVtbl = &OleInPlaceActiveObjectVtbl;
986 This->IOleCommandTarget_iface.lpVtbl = &OleCommandTargetVtbl;
988 /* Default size is 50x20 pixels, in himetric units */
989 This->extent.cx = MulDiv( 50, 2540, dpi_x );
990 This->extent.cy = MulDiv( 20, 2540, dpi_y );
993 void WebBrowser_OleObject_Destroy(WebBrowser *This)
995 release_client_site(This);