ieframe: Implement IOleObject::Advise().
[wine.git] / dlls / ieframe / oleobject.c
blob9f5da4039d58473a69cc50d52fd64b436ee05330
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 void notify_on_focus(WebBrowser *This, BOOL got_focus)
54 IOleControlSite *control_site;
55 HRESULT hres;
57 if(!This->client)
58 return;
60 hres = IOleClientSite_QueryInterface(This->client, &IID_IOleControlSite, (void**)&control_site);
61 if(FAILED(hres))
62 return;
64 IOleControlSite_OnFocus(control_site, got_focus);
65 IOleControlSite_Release(control_site);
68 static LRESULT WINAPI shell_embedding_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
70 WebBrowser *This;
72 static const WCHAR wszTHIS[] = {'T','H','I','S',0};
74 if(msg == WM_CREATE) {
75 This = *(WebBrowser**)lParam;
76 SetPropW(hwnd, wszTHIS, This);
77 }else {
78 This = GetPropW(hwnd, wszTHIS);
81 switch(msg) {
82 case WM_SIZE:
83 return resize_window(This, LOWORD(lParam), HIWORD(lParam));
84 case WM_DOCHOSTTASK:
85 return process_dochost_tasks(&This->doc_host);
86 case WM_SETFOCUS:
87 notify_on_focus(This, TRUE);
88 break;
89 case WM_KILLFOCUS:
90 notify_on_focus(This, FALSE);
91 break;
94 return DefWindowProcW(hwnd, msg, wParam, lParam);
97 static void create_shell_embedding_hwnd(WebBrowser *This)
99 IOleInPlaceSite *inplace;
100 HWND parent = NULL;
101 HRESULT hres;
103 static const WCHAR wszShellEmbedding[] =
104 {'S','h','e','l','l',' ','E','m','b','e','d','d','i','n','g',0};
106 if(!shell_embedding_atom) {
107 static WNDCLASSEXW wndclass = {
108 sizeof(wndclass),
109 CS_DBLCLKS,
110 shell_embedding_proc,
111 0, 0 /* native uses 8 */, NULL, NULL, NULL,
112 (HBRUSH)(COLOR_WINDOW + 1), NULL,
113 wszShellEmbedding,
114 NULL
116 wndclass.hInstance = ieframe_instance;
118 RegisterClassExW(&wndclass);
121 hres = IOleClientSite_QueryInterface(This->client, &IID_IOleInPlaceSite, (void**)&inplace);
122 if(SUCCEEDED(hres)) {
123 IOleInPlaceSite_GetWindow(inplace, &parent);
124 IOleInPlaceSite_Release(inplace);
127 This->doc_host.frame_hwnd = This->shell_embedding_hwnd = CreateWindowExW(
128 WS_EX_WINDOWEDGE,
129 wszShellEmbedding, wszShellEmbedding,
130 WS_CLIPSIBLINGS | WS_CLIPCHILDREN
131 | (parent ? WS_CHILD | WS_TABSTOP : WS_POPUP | WS_MAXIMIZEBOX),
132 0, 0, 0, 0, parent,
133 NULL, ieframe_instance, This);
135 TRACE("parent=%p hwnd=%p\n", parent, This->shell_embedding_hwnd);
138 static HRESULT activate_inplace(WebBrowser *This, IOleClientSite *active_site)
140 HWND parent_hwnd;
141 HRESULT hres;
143 if(This->inplace)
144 return S_OK;
146 if(!active_site)
147 return E_INVALIDARG;
149 hres = IOleClientSite_QueryInterface(active_site, &IID_IOleInPlaceSite,
150 (void**)&This->inplace);
151 if(FAILED(hres)) {
152 WARN("Could not get IOleInPlaceSite\n");
153 return hres;
156 hres = IOleInPlaceSiteEx_CanInPlaceActivate(This->inplace);
157 if(hres != S_OK) {
158 WARN("CanInPlaceActivate returned: %08x\n", hres);
159 IOleInPlaceSiteEx_Release(This->inplace);
160 This->inplace = NULL;
161 return E_FAIL;
164 hres = IOleInPlaceSiteEx_GetWindow(This->inplace, &parent_hwnd);
165 if(SUCCEEDED(hres))
166 SHSetParentHwnd(This->shell_embedding_hwnd, parent_hwnd);
168 IOleInPlaceSiteEx_OnInPlaceActivate(This->inplace);
170 This->frameinfo.cb = sizeof(OLEINPLACEFRAMEINFO);
171 IOleInPlaceSiteEx_GetWindowContext(This->inplace, &This->doc_host.frame, &This->uiwindow,
172 &This->pos_rect, &This->clip_rect,
173 &This->frameinfo);
175 SetWindowPos(This->shell_embedding_hwnd, NULL,
176 This->pos_rect.left, This->pos_rect.top,
177 This->pos_rect.right-This->pos_rect.left,
178 This->pos_rect.bottom-This->pos_rect.top,
179 SWP_NOZORDER | SWP_SHOWWINDOW);
181 if(This->client) {
182 IOleContainer *container;
184 IOleClientSite_ShowObject(This->client);
186 hres = IOleClientSite_GetContainer(This->client, &container);
187 if(SUCCEEDED(hres)) {
188 if(This->container)
189 IOleContainer_Release(This->container);
190 This->container = container;
194 if(This->doc_host.frame)
195 IOleInPlaceFrame_GetWindow(This->doc_host.frame, &This->frame_hwnd);
197 return S_OK;
200 static HRESULT activate_ui(WebBrowser *This, IOleClientSite *active_site)
202 HRESULT hres;
204 static const WCHAR wszitem[] = {'i','t','e','m',0};
206 if(This->inplace)
208 if(This->shell_embedding_hwnd)
209 ShowWindow(This->shell_embedding_hwnd, SW_SHOW);
210 return S_OK;
213 hres = activate_inplace(This, active_site);
214 if(FAILED(hres))
215 return hres;
217 IOleInPlaceSiteEx_OnUIActivate(This->inplace);
219 if(This->doc_host.frame)
220 IOleInPlaceFrame_SetActiveObject(This->doc_host.frame, &This->IOleInPlaceActiveObject_iface, wszitem);
221 if(This->uiwindow)
222 IOleInPlaceUIWindow_SetActiveObject(This->uiwindow, &This->IOleInPlaceActiveObject_iface, wszitem);
224 if(This->doc_host.frame)
225 IOleInPlaceFrame_SetMenu(This->doc_host.frame, NULL, NULL, This->shell_embedding_hwnd);
227 SetFocus(This->shell_embedding_hwnd);
228 notify_on_focus(This, TRUE);
230 return S_OK;
233 static HRESULT get_client_disp_property(IOleClientSite *client, DISPID dispid, VARIANT *res)
235 IDispatch *disp = NULL;
236 DISPPARAMS dispparams = {NULL, 0};
237 HRESULT hres;
239 VariantInit(res);
241 if(!client)
242 return S_OK;
244 hres = IOleClientSite_QueryInterface(client, &IID_IDispatch, (void**)&disp);
245 if(FAILED(hres)) {
246 TRACE("Could not get IDispatch\n");
247 return hres;
250 hres = IDispatch_Invoke(disp, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
251 DISPATCH_PROPERTYGET, &dispparams, res, NULL, NULL);
253 IDispatch_Release(disp);
255 return hres;
258 static HRESULT on_offlineconnected_change(WebBrowser *This)
260 VARIANT offline;
262 get_client_disp_property(This->client, DISPID_AMBIENT_OFFLINEIFNOTCONNECTED, &offline);
264 if(V_VT(&offline) == VT_BOOL)
265 IWebBrowser2_put_Offline(&This->IWebBrowser2_iface, V_BOOL(&offline));
266 else if(V_VT(&offline) != VT_EMPTY)
267 WARN("wrong V_VT(silent) %d\n", V_VT(&offline));
269 return S_OK;
272 static HRESULT on_silent_change(WebBrowser *This)
274 VARIANT silent;
276 get_client_disp_property(This->client, DISPID_AMBIENT_SILENT, &silent);
278 if(V_VT(&silent) == VT_BOOL)
279 IWebBrowser2_put_Silent(&This->IWebBrowser2_iface, V_BOOL(&silent));
280 else if(V_VT(&silent) != VT_EMPTY)
281 WARN("wrong V_VT(silent) %d\n", V_VT(&silent));
283 return S_OK;
286 static void release_client_site(WebBrowser *This, BOOL destroy_win)
288 release_dochost_client(&This->doc_host);
290 if(This->client) {
291 IOleClientSite_Release(This->client);
292 This->client = NULL;
295 if(This->client_closed) {
296 IOleClientSite_Release(This->client_closed);
297 This->client_closed = NULL;
300 if(destroy_win && This->shell_embedding_hwnd) {
301 DestroyWindow(This->shell_embedding_hwnd);
302 This->shell_embedding_hwnd = NULL;
305 if(This->inplace) {
306 IOleInPlaceSiteEx_Release(This->inplace);
307 This->inplace = NULL;
310 if(This->container) {
311 IOleContainer_Release(This->container);
312 This->container = NULL;
315 if(This->uiwindow) {
316 IOleInPlaceUIWindow_Release(This->uiwindow);
317 This->uiwindow = NULL;
321 typedef struct {
322 IEnumOLEVERB IEnumOLEVERB_iface;
323 LONG ref;
324 LONG iter;
325 } EnumOLEVERB;
327 static inline EnumOLEVERB *impl_from_IEnumOLEVERB(IEnumOLEVERB *iface)
329 return CONTAINING_RECORD(iface, EnumOLEVERB, IEnumOLEVERB_iface);
332 static HRESULT WINAPI EnumOLEVERB_QueryInterface(IEnumOLEVERB *iface, REFIID riid, void **ppv)
334 EnumOLEVERB *This = impl_from_IEnumOLEVERB(iface);
336 if(IsEqualGUID(&IID_IUnknown, riid)) {
337 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
338 *ppv = &This->IEnumOLEVERB_iface;
339 }else if(IsEqualGUID(&IID_IEnumOLEVERB, riid)) {
340 TRACE("(%p)->(IID_IEnumOLEVERB %p)\n", This, ppv);
341 *ppv = &This->IEnumOLEVERB_iface;
342 }else {
343 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
344 *ppv = NULL;
345 return E_NOINTERFACE;
348 IUnknown_AddRef((IUnknown*)*ppv);
349 return S_OK;
352 static ULONG WINAPI EnumOLEVERB_AddRef(IEnumOLEVERB *iface)
354 EnumOLEVERB *This = impl_from_IEnumOLEVERB(iface);
355 LONG ref = InterlockedIncrement(&This->ref);
357 TRACE("(%p) ref=%d\n", This, ref);
359 return ref;
362 static ULONG WINAPI EnumOLEVERB_Release(IEnumOLEVERB *iface)
364 EnumOLEVERB *This = impl_from_IEnumOLEVERB(iface);
365 LONG ref = InterlockedDecrement(&This->ref);
367 TRACE("(%p) ref=%d\n", This, ref);
369 if(!ref)
370 heap_free(This);
372 return ref;
375 static HRESULT WINAPI EnumOLEVERB_Next(IEnumOLEVERB *iface, ULONG celt, OLEVERB *rgelt, ULONG *pceltFetched)
377 EnumOLEVERB *This = impl_from_IEnumOLEVERB(iface);
379 static const OLEVERB verbs[] =
380 {{OLEIVERB_PRIMARY},{OLEIVERB_INPLACEACTIVATE},{OLEIVERB_UIACTIVATE},{OLEIVERB_SHOW},{OLEIVERB_HIDE}};
382 TRACE("(%p)->(%u %p %p)\n", This, celt, rgelt, pceltFetched);
384 /* There are a few problems with this implementation, but that's how it seems to work in native. See tests. */
385 if(pceltFetched)
386 *pceltFetched = 0;
388 if(This->iter == ARRAY_SIZE(verbs))
389 return S_FALSE;
391 if(celt)
392 *rgelt = verbs[This->iter++];
393 return S_OK;
396 static HRESULT WINAPI EnumOLEVERB_Skip(IEnumOLEVERB *iface, ULONG celt)
398 EnumOLEVERB *This = impl_from_IEnumOLEVERB(iface);
399 TRACE("(%p)->(%u)\n", This, celt);
400 return S_OK;
403 static HRESULT WINAPI EnumOLEVERB_Reset(IEnumOLEVERB *iface)
405 EnumOLEVERB *This = impl_from_IEnumOLEVERB(iface);
407 TRACE("(%p)\n", This);
409 This->iter = 0;
410 return S_OK;
413 static HRESULT WINAPI EnumOLEVERB_Clone(IEnumOLEVERB *iface, IEnumOLEVERB **ppenum)
415 EnumOLEVERB *This = impl_from_IEnumOLEVERB(iface);
416 FIXME("(%p)->(%p)\n", This, ppenum);
417 return E_NOTIMPL;
420 static const IEnumOLEVERBVtbl EnumOLEVERBVtbl = {
421 EnumOLEVERB_QueryInterface,
422 EnumOLEVERB_AddRef,
423 EnumOLEVERB_Release,
424 EnumOLEVERB_Next,
425 EnumOLEVERB_Skip,
426 EnumOLEVERB_Reset,
427 EnumOLEVERB_Clone
430 /**********************************************************************
431 * Implement the IOleObject interface for the WebBrowser control
434 static inline WebBrowser *impl_from_IOleObject(IOleObject *iface)
436 return CONTAINING_RECORD(iface, WebBrowser, IOleObject_iface);
439 static HRESULT WINAPI OleObject_QueryInterface(IOleObject *iface, REFIID riid, void **ppv)
441 WebBrowser *This = impl_from_IOleObject(iface);
442 return IUnknown_QueryInterface(This->hlink_frame.outer, riid, ppv);
445 static ULONG WINAPI OleObject_AddRef(IOleObject *iface)
447 WebBrowser *This = impl_from_IOleObject(iface);
448 return IUnknown_AddRef(This->hlink_frame.outer);
451 static ULONG WINAPI OleObject_Release(IOleObject *iface)
453 WebBrowser *This = impl_from_IOleObject(iface);
454 return IUnknown_Release(This->hlink_frame.outer);
457 static HRESULT WINAPI OleObject_SetClientSite(IOleObject *iface, LPOLECLIENTSITE pClientSite)
459 WebBrowser *This = impl_from_IOleObject(iface);
460 IDocHostUIHandler *hostui;
461 IOleCommandTarget *olecmd;
462 BOOL get_olecmd = TRUE;
463 IOleContainer *container;
464 IDispatch *disp;
465 HRESULT hres;
467 TRACE("(%p)->(%p)\n", This, pClientSite);
469 if(This->client_closed) {
470 IOleClientSite_Release(This->client_closed);
471 This->client_closed = NULL;
474 if(This->client == pClientSite)
475 return S_OK;
477 if(This->client && pClientSite) {
478 get_olecmd = FALSE;
479 olecmd = This->doc_host.olecmd;
480 if(olecmd)
481 IOleCommandTarget_AddRef(olecmd);
484 release_client_site(This, !pClientSite);
486 if(!pClientSite) {
487 on_commandstate_change(&This->doc_host, CSC_NAVIGATEBACK, FALSE);
488 on_commandstate_change(&This->doc_host, CSC_NAVIGATEFORWARD, FALSE);
490 if(This->doc_host.document)
491 deactivate_document(&This->doc_host);
492 return S_OK;
495 IOleClientSite_AddRef(pClientSite);
496 This->client = pClientSite;
498 hres = IOleClientSite_QueryInterface(This->client, &IID_IDispatch,
499 (void**)&disp);
500 if(SUCCEEDED(hres))
501 This->doc_host.client_disp = disp;
503 hres = IOleClientSite_QueryInterface(This->client, &IID_IDocHostUIHandler,
504 (void**)&hostui);
505 if(SUCCEEDED(hres))
506 This->doc_host.hostui = hostui;
508 if(get_olecmd) {
509 hres = IOleClientSite_GetContainer(This->client, &container);
510 if(SUCCEEDED(hres)) {
511 ITargetContainer *target_container;
513 hres = IOleContainer_QueryInterface(container, &IID_ITargetContainer,
514 (void**)&target_container);
515 if(SUCCEEDED(hres)) {
516 FIXME("Unsupported ITargetContainer\n");
517 ITargetContainer_Release(target_container);
520 hres = IOleContainer_QueryInterface(container, &IID_IOleCommandTarget, (void**)&olecmd);
521 if(FAILED(hres))
522 olecmd = NULL;
524 IOleContainer_Release(container);
525 }else {
526 hres = IOleClientSite_QueryInterface(This->client, &IID_IOleCommandTarget, (void**)&olecmd);
527 if(FAILED(hres))
528 olecmd = NULL;
532 This->doc_host.olecmd = olecmd;
534 if(This->shell_embedding_hwnd) {
535 IOleInPlaceSite *inplace;
536 HWND parent;
538 hres = IOleClientSite_QueryInterface(This->client, &IID_IOleInPlaceSite, (void**)&inplace);
539 if(SUCCEEDED(hres)) {
540 hres = IOleInPlaceSite_GetWindow(inplace, &parent);
541 IOleInPlaceSite_Release(inplace);
542 if(SUCCEEDED(hres))
543 SHSetParentHwnd(This->shell_embedding_hwnd, parent);
545 }else {
546 create_shell_embedding_hwnd(This);
549 on_offlineconnected_change(This);
550 on_silent_change(This);
552 return S_OK;
555 static HRESULT WINAPI OleObject_GetClientSite(IOleObject *iface, LPOLECLIENTSITE *ppClientSite)
557 WebBrowser *This = impl_from_IOleObject(iface);
559 TRACE("(%p)->(%p)\n", This, ppClientSite);
561 if(!ppClientSite)
562 return E_INVALIDARG;
564 if(This->client)
565 IOleClientSite_AddRef(This->client);
566 *ppClientSite = This->client;
568 return S_OK;
571 static HRESULT WINAPI OleObject_SetHostNames(IOleObject *iface, LPCOLESTR szContainerApp,
572 LPCOLESTR szContainerObj)
574 WebBrowser *This = impl_from_IOleObject(iface);
576 TRACE("(%p)->(%s, %s)\n", This, debugstr_w(szContainerApp), debugstr_w(szContainerObj));
578 /* We have nothing to do here. */
579 return S_OK;
582 static HRESULT WINAPI OleObject_Close(IOleObject *iface, DWORD dwSaveOption)
584 WebBrowser *This = impl_from_IOleObject(iface);
585 IOleClientSite *client;
586 HRESULT hres;
588 TRACE("(%p)->(%d)\n", This, dwSaveOption);
590 if(dwSaveOption != OLECLOSE_NOSAVE) {
591 FIXME("unimplemented flag: %x\n", dwSaveOption);
592 return E_NOTIMPL;
595 if(This->doc_host.frame)
596 IOleInPlaceFrame_SetActiveObject(This->doc_host.frame, NULL, NULL);
598 if(This->uiwindow)
599 IOleInPlaceUIWindow_SetActiveObject(This->uiwindow, NULL, NULL);
601 if(This->inplace)
602 IOleInPlaceSiteEx_OnUIDeactivate(This->inplace, FALSE);
603 notify_on_focus(This, FALSE);
604 if(This->inplace)
605 IOleInPlaceSiteEx_OnInPlaceDeactivate(This->inplace);
607 /* store old client site - we need to restore it in DoVerb */
608 client = This->client;
609 if(This->client)
610 IOleClientSite_AddRef(This->client);
611 hres = IOleObject_SetClientSite(iface, NULL);
612 This->client_closed = client;
613 return hres;
616 static HRESULT WINAPI OleObject_SetMoniker(IOleObject *iface, DWORD dwWhichMoniker, IMoniker* pmk)
618 WebBrowser *This = impl_from_IOleObject(iface);
619 FIXME("(%p)->(%d, %p)\n", This, dwWhichMoniker, pmk);
620 return E_NOTIMPL;
623 static HRESULT WINAPI OleObject_GetMoniker(IOleObject *iface, DWORD dwAssign,
624 DWORD dwWhichMoniker, LPMONIKER *ppmk)
626 WebBrowser *This = impl_from_IOleObject(iface);
627 FIXME("(%p)->(%d, %d, %p)\n", This, dwAssign, dwWhichMoniker, ppmk);
628 return E_NOTIMPL;
631 static HRESULT WINAPI OleObject_InitFromData(IOleObject *iface, LPDATAOBJECT pDataObject,
632 BOOL fCreation, DWORD dwReserved)
634 WebBrowser *This = impl_from_IOleObject(iface);
635 FIXME("(%p)->(%p, %d, %d)\n", This, pDataObject, fCreation, dwReserved);
636 return E_NOTIMPL;
639 static HRESULT WINAPI OleObject_GetClipboardData(IOleObject *iface, DWORD dwReserved,
640 LPDATAOBJECT *ppDataObject)
642 WebBrowser *This = impl_from_IOleObject(iface);
643 FIXME("(%p)->(%d, %p)\n", This, dwReserved, ppDataObject);
644 return E_NOTIMPL;
647 static HRESULT WINAPI OleObject_DoVerb(IOleObject *iface, LONG iVerb, struct tagMSG* lpmsg,
648 LPOLECLIENTSITE pActiveSite, LONG lindex, HWND hwndParent, LPCRECT lprcPosRect)
650 WebBrowser *This = impl_from_IOleObject(iface);
652 TRACE("(%p)->(%d %p %p %d %p %s)\n", This, iVerb, lpmsg, pActiveSite, lindex, hwndParent,
653 wine_dbgstr_rect(lprcPosRect));
655 /* restore closed client site if we have one */
656 if(!This->client && This->client_closed) {
657 IOleClientSite *client = This->client_closed;
658 This->client_closed = NULL;
659 IOleObject_SetClientSite(iface, client);
660 IOleClientSite_Release(client);
663 switch (iVerb)
665 case OLEIVERB_SHOW:
666 TRACE("OLEIVERB_SHOW\n");
667 return activate_ui(This, pActiveSite);
668 case OLEIVERB_UIACTIVATE:
669 TRACE("OLEIVERB_UIACTIVATE\n");
670 return activate_ui(This, pActiveSite);
671 case OLEIVERB_INPLACEACTIVATE:
672 TRACE("OLEIVERB_INPLACEACTIVATE\n");
673 return activate_inplace(This, pActiveSite);
674 case OLEIVERB_HIDE:
675 TRACE("OLEIVERB_HIDE\n");
676 if(This->inplace)
677 IOleInPlaceSiteEx_OnInPlaceDeactivate(This->inplace);
678 if(This->shell_embedding_hwnd)
679 ShowWindow(This->shell_embedding_hwnd, SW_HIDE);
680 return S_OK;
681 default:
682 FIXME("stub for %d\n", iVerb);
683 break;
686 return E_NOTIMPL;
689 static HRESULT WINAPI OleObject_EnumVerbs(IOleObject *iface, IEnumOLEVERB **ppEnumOleVerb)
691 WebBrowser *This = impl_from_IOleObject(iface);
692 EnumOLEVERB *ret;
694 TRACE("(%p)->(%p)\n", This, ppEnumOleVerb);
696 ret = heap_alloc(sizeof(*ret));
697 if(!ret)
698 return E_OUTOFMEMORY;
700 ret->IEnumOLEVERB_iface.lpVtbl = &EnumOLEVERBVtbl;
701 ret->ref = 1;
702 ret->iter = 0;
704 *ppEnumOleVerb = &ret->IEnumOLEVERB_iface;
705 return S_OK;
708 static HRESULT WINAPI OleObject_Update(IOleObject *iface)
710 WebBrowser *This = impl_from_IOleObject(iface);
711 FIXME("(%p)\n", This);
712 return E_NOTIMPL;
715 static HRESULT WINAPI OleObject_IsUpToDate(IOleObject *iface)
717 WebBrowser *This = impl_from_IOleObject(iface);
718 FIXME("(%p)\n", This);
719 return E_NOTIMPL;
722 static HRESULT WINAPI OleObject_GetUserClassID(IOleObject *iface, CLSID *pClsid)
724 WebBrowser *This = impl_from_IOleObject(iface);
726 TRACE("(%p)->(%p)\n", This, pClsid);
728 *pClsid = This->version == 1 ? CLSID_WebBrowser_V1 : CLSID_WebBrowser;
729 return S_OK;
732 static HRESULT WINAPI OleObject_GetUserType(IOleObject *iface, DWORD dwFormOfType,
733 LPOLESTR* pszUserType)
735 WebBrowser *This = impl_from_IOleObject(iface);
736 TRACE("(%p, %d, %p)\n", This, dwFormOfType, pszUserType);
737 return OleRegGetUserType(&CLSID_WebBrowser, dwFormOfType, pszUserType);
740 static HRESULT WINAPI OleObject_SetExtent(IOleObject *iface, DWORD dwDrawAspect, SIZEL *psizel)
742 WebBrowser *This = impl_from_IOleObject(iface);
744 TRACE("(%p)->(%x %p)\n", This, dwDrawAspect, psizel);
746 /* Tests show that dwDrawAspect is ignored */
747 This->extent = *psizel;
748 return S_OK;
751 static HRESULT WINAPI OleObject_GetExtent(IOleObject *iface, DWORD dwDrawAspect, SIZEL *psizel)
753 WebBrowser *This = impl_from_IOleObject(iface);
755 TRACE("(%p)->(%x, %p)\n", This, dwDrawAspect, psizel);
757 /* Tests show that dwDrawAspect is ignored */
758 *psizel = This->extent;
759 return S_OK;
762 static HRESULT WINAPI OleObject_Advise(IOleObject *iface, IAdviseSink *pAdvSink,
763 DWORD *pdwConnection)
765 WebBrowser *This = impl_from_IOleObject(iface);
766 HRESULT hr = S_OK;
768 TRACE("(%p)->(%p, %p)\n", This, pAdvSink, pdwConnection);
770 if(!pdwConnection)
771 return E_INVALIDARG;
773 *pdwConnection = 0;
775 if(!pAdvSink)
776 return E_INVALIDARG;
778 if(!This->advise_holder)
779 hr = CreateOleAdviseHolder(&This->advise_holder);
781 if(hr == S_OK)
782 hr = IOleAdviseHolder_Advise(This->advise_holder, pAdvSink, pdwConnection);
784 return hr;
787 static HRESULT WINAPI OleObject_Unadvise(IOleObject *iface, DWORD dwConnection)
789 WebBrowser *This = impl_from_IOleObject(iface);
790 FIXME("(%p)->(%d)\n", This, dwConnection);
791 return E_NOTIMPL;
794 static HRESULT WINAPI OleObject_EnumAdvise(IOleObject *iface, IEnumSTATDATA **ppenumAdvise)
796 WebBrowser *This = impl_from_IOleObject(iface);
797 FIXME("(%p)->(%p)\n", This, ppenumAdvise);
798 return S_OK;
801 static HRESULT WINAPI OleObject_GetMiscStatus(IOleObject *iface, DWORD dwAspect, DWORD *pdwStatus)
803 WebBrowser *This = impl_from_IOleObject(iface);
805 TRACE("(%p)->(%x, %p)\n", This, dwAspect, pdwStatus);
807 *pdwStatus = OLEMISC_SETCLIENTSITEFIRST|OLEMISC_ACTIVATEWHENVISIBLE|OLEMISC_INSIDEOUT
808 |OLEMISC_CANTLINKINSIDE|OLEMISC_RECOMPOSEONRESIZE;
810 return S_OK;
813 static HRESULT WINAPI OleObject_SetColorScheme(IOleObject *iface, LOGPALETTE* pLogpal)
815 WebBrowser *This = impl_from_IOleObject(iface);
816 FIXME("(%p)->(%p)\n", This, pLogpal);
817 return E_NOTIMPL;
820 static const IOleObjectVtbl OleObjectVtbl =
822 OleObject_QueryInterface,
823 OleObject_AddRef,
824 OleObject_Release,
825 OleObject_SetClientSite,
826 OleObject_GetClientSite,
827 OleObject_SetHostNames,
828 OleObject_Close,
829 OleObject_SetMoniker,
830 OleObject_GetMoniker,
831 OleObject_InitFromData,
832 OleObject_GetClipboardData,
833 OleObject_DoVerb,
834 OleObject_EnumVerbs,
835 OleObject_Update,
836 OleObject_IsUpToDate,
837 OleObject_GetUserClassID,
838 OleObject_GetUserType,
839 OleObject_SetExtent,
840 OleObject_GetExtent,
841 OleObject_Advise,
842 OleObject_Unadvise,
843 OleObject_EnumAdvise,
844 OleObject_GetMiscStatus,
845 OleObject_SetColorScheme
848 /**********************************************************************
849 * Implement the IOleInPlaceObject interface
852 static inline WebBrowser *impl_from_IOleInPlaceObject(IOleInPlaceObject *iface)
854 return CONTAINING_RECORD(iface, WebBrowser, IOleInPlaceObject_iface);
857 static HRESULT WINAPI OleInPlaceObject_QueryInterface(IOleInPlaceObject *iface,
858 REFIID riid, LPVOID *ppobj)
860 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
861 return IUnknown_QueryInterface(This->hlink_frame.outer, riid, ppobj);
864 static ULONG WINAPI OleInPlaceObject_AddRef(IOleInPlaceObject *iface)
866 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
867 return IUnknown_AddRef(This->hlink_frame.outer);
870 static ULONG WINAPI OleInPlaceObject_Release(IOleInPlaceObject *iface)
872 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
873 return IUnknown_Release(This->hlink_frame.outer);
876 static HRESULT WINAPI OleInPlaceObject_GetWindow(IOleInPlaceObject *iface, HWND* phwnd)
878 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
880 TRACE("(%p)->(%p)\n", This, phwnd);
882 *phwnd = This->shell_embedding_hwnd;
883 return S_OK;
886 static HRESULT WINAPI OleInPlaceObject_ContextSensitiveHelp(IOleInPlaceObject *iface,
887 BOOL fEnterMode)
889 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
890 FIXME("(%p)->(%x)\n", This, fEnterMode);
891 return E_NOTIMPL;
894 static HRESULT WINAPI OleInPlaceObject_InPlaceDeactivate(IOleInPlaceObject *iface)
896 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
897 FIXME("(%p)\n", This);
899 if(This->inplace) {
900 IOleInPlaceSiteEx_Release(This->inplace);
901 This->inplace = NULL;
904 return S_OK;
907 static HRESULT WINAPI OleInPlaceObject_UIDeactivate(IOleInPlaceObject *iface)
909 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
910 FIXME("(%p)\n", This);
911 return E_NOTIMPL;
914 static HRESULT WINAPI OleInPlaceObject_SetObjectRects(IOleInPlaceObject *iface,
915 LPCRECT lprcPosRect, LPCRECT lprcClipRect)
917 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
919 TRACE("(%p)->(%s %s)\n", This, wine_dbgstr_rect(lprcPosRect), wine_dbgstr_rect(lprcClipRect));
921 This->pos_rect = *lprcPosRect;
923 if(lprcClipRect)
924 This->clip_rect = *lprcClipRect;
926 if(This->shell_embedding_hwnd) {
927 SetWindowPos(This->shell_embedding_hwnd, NULL,
928 lprcPosRect->left, lprcPosRect->top,
929 lprcPosRect->right-lprcPosRect->left,
930 lprcPosRect->bottom-lprcPosRect->top,
931 SWP_NOZORDER | SWP_NOACTIVATE);
934 return S_OK;
937 static HRESULT WINAPI OleInPlaceObject_ReactivateAndUndo(IOleInPlaceObject *iface)
939 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
940 FIXME("(%p)\n", This);
941 return E_NOTIMPL;
944 static const IOleInPlaceObjectVtbl OleInPlaceObjectVtbl =
946 OleInPlaceObject_QueryInterface,
947 OleInPlaceObject_AddRef,
948 OleInPlaceObject_Release,
949 OleInPlaceObject_GetWindow,
950 OleInPlaceObject_ContextSensitiveHelp,
951 OleInPlaceObject_InPlaceDeactivate,
952 OleInPlaceObject_UIDeactivate,
953 OleInPlaceObject_SetObjectRects,
954 OleInPlaceObject_ReactivateAndUndo
957 /**********************************************************************
958 * Implement the IOleControl interface
961 static inline WebBrowser *impl_from_IOleControl(IOleControl *iface)
963 return CONTAINING_RECORD(iface, WebBrowser, IOleControl_iface);
966 static HRESULT WINAPI OleControl_QueryInterface(IOleControl *iface,
967 REFIID riid, LPVOID *ppobj)
969 WebBrowser *This = impl_from_IOleControl(iface);
970 return IUnknown_QueryInterface(This->hlink_frame.outer, riid, ppobj);
973 static ULONG WINAPI OleControl_AddRef(IOleControl *iface)
975 WebBrowser *This = impl_from_IOleControl(iface);
976 return IUnknown_AddRef(This->hlink_frame.outer);
979 static ULONG WINAPI OleControl_Release(IOleControl *iface)
981 WebBrowser *This = impl_from_IOleControl(iface);
982 return IUnknown_Release(This->hlink_frame.outer);
985 static HRESULT WINAPI OleControl_GetControlInfo(IOleControl *iface, LPCONTROLINFO pCI)
987 WebBrowser *This = impl_from_IOleControl(iface);
989 TRACE("(%p)->(%p)\n", This, pCI);
991 /* Tests show that this function should be not implemented */
992 return E_NOTIMPL;
995 static HRESULT WINAPI OleControl_OnMnemonic(IOleControl *iface, struct tagMSG *pMsg)
997 WebBrowser *This = impl_from_IOleControl(iface);
998 FIXME("(%p)->(%p)\n", This, pMsg);
999 return E_NOTIMPL;
1002 static HRESULT WINAPI OleControl_OnAmbientPropertyChange(IOleControl *iface, DISPID dispID)
1004 WebBrowser *This = impl_from_IOleControl(iface);
1006 TRACE("(%p)->(%d)\n", This, dispID);
1008 switch(dispID) {
1009 case DISPID_UNKNOWN:
1010 /* Unknown means multiple properties changed, so check them all.
1011 * BUT the Webbrowser OleControl object doesn't appear to do this.
1013 return S_OK;
1014 case DISPID_AMBIENT_DLCONTROL:
1015 return S_OK;
1016 case DISPID_AMBIENT_OFFLINEIFNOTCONNECTED:
1017 return on_offlineconnected_change(This);
1018 case DISPID_AMBIENT_SILENT:
1019 return on_silent_change(This);
1022 FIXME("Unknown dispID %d\n", dispID);
1023 return E_NOTIMPL;
1026 static HRESULT WINAPI OleControl_FreezeEvents(IOleControl *iface, BOOL bFreeze)
1028 WebBrowser *This = impl_from_IOleControl(iface);
1029 FIXME("(%p)->(%x)\n", This, bFreeze);
1030 return E_NOTIMPL;
1033 static const IOleControlVtbl OleControlVtbl =
1035 OleControl_QueryInterface,
1036 OleControl_AddRef,
1037 OleControl_Release,
1038 OleControl_GetControlInfo,
1039 OleControl_OnMnemonic,
1040 OleControl_OnAmbientPropertyChange,
1041 OleControl_FreezeEvents
1044 static inline WebBrowser *impl_from_IOleInPlaceActiveObject(IOleInPlaceActiveObject *iface)
1046 return CONTAINING_RECORD(iface, WebBrowser, IOleInPlaceActiveObject_iface);
1049 static HRESULT WINAPI InPlaceActiveObject_QueryInterface(IOleInPlaceActiveObject *iface,
1050 REFIID riid, void **ppv)
1052 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
1053 return IUnknown_QueryInterface(This->hlink_frame.outer, riid, ppv);
1056 static ULONG WINAPI InPlaceActiveObject_AddRef(IOleInPlaceActiveObject *iface)
1058 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
1059 return IUnknown_AddRef(This->hlink_frame.outer);
1062 static ULONG WINAPI InPlaceActiveObject_Release(IOleInPlaceActiveObject *iface)
1064 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
1065 return IUnknown_Release(This->hlink_frame.outer);
1068 static HRESULT WINAPI InPlaceActiveObject_GetWindow(IOleInPlaceActiveObject *iface,
1069 HWND *phwnd)
1071 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
1072 return IOleInPlaceObject_GetWindow(&This->IOleInPlaceObject_iface, phwnd);
1075 static HRESULT WINAPI InPlaceActiveObject_ContextSensitiveHelp(IOleInPlaceActiveObject *iface,
1076 BOOL fEnterMode)
1078 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
1079 return IOleInPlaceObject_ContextSensitiveHelp(&This->IOleInPlaceObject_iface, fEnterMode);
1082 static HRESULT WINAPI InPlaceActiveObject_TranslateAccelerator(IOleInPlaceActiveObject *iface,
1083 LPMSG lpmsg)
1085 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
1086 IOleInPlaceActiveObject *activeobj;
1087 HRESULT hr = S_FALSE;
1089 TRACE("(%p)->(%p)\n", This, lpmsg);
1091 if(This->doc_host.document) {
1092 if(SUCCEEDED(IUnknown_QueryInterface(This->doc_host.document,
1093 &IID_IOleInPlaceActiveObject,
1094 (void**)&activeobj))) {
1095 hr = IOleInPlaceActiveObject_TranslateAccelerator(activeobj, lpmsg);
1096 IOleInPlaceActiveObject_Release(activeobj);
1100 if(SUCCEEDED(hr))
1101 return hr;
1102 else
1103 return S_FALSE;
1106 static HRESULT WINAPI InPlaceActiveObject_OnFrameWindowActivate(IOleInPlaceActiveObject *iface,
1107 BOOL fActivate)
1109 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
1110 FIXME("(%p)->(%x)\n", This, fActivate);
1111 return E_NOTIMPL;
1114 static HRESULT WINAPI InPlaceActiveObject_OnDocWindowActivate(IOleInPlaceActiveObject *iface,
1115 BOOL fActivate)
1117 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
1118 FIXME("(%p)->(%x)\n", This, fActivate);
1119 return E_NOTIMPL;
1122 static HRESULT WINAPI InPlaceActiveObject_ResizeBorder(IOleInPlaceActiveObject *iface,
1123 LPCRECT lprcBorder, IOleInPlaceUIWindow *pUIWindow, BOOL fFrameWindow)
1125 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
1126 FIXME("(%p)->(%p %p %x)\n", This, lprcBorder, pUIWindow, fFrameWindow);
1127 return E_NOTIMPL;
1130 static HRESULT WINAPI InPlaceActiveObject_EnableModeless(IOleInPlaceActiveObject *iface,
1131 BOOL fEnable)
1133 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
1134 FIXME("(%p)->(%x)\n", This, fEnable);
1135 return E_NOTIMPL;
1138 static const IOleInPlaceActiveObjectVtbl OleInPlaceActiveObjectVtbl = {
1139 InPlaceActiveObject_QueryInterface,
1140 InPlaceActiveObject_AddRef,
1141 InPlaceActiveObject_Release,
1142 InPlaceActiveObject_GetWindow,
1143 InPlaceActiveObject_ContextSensitiveHelp,
1144 InPlaceActiveObject_TranslateAccelerator,
1145 InPlaceActiveObject_OnFrameWindowActivate,
1146 InPlaceActiveObject_OnDocWindowActivate,
1147 InPlaceActiveObject_ResizeBorder,
1148 InPlaceActiveObject_EnableModeless
1151 static inline WebBrowser *impl_from_IOleCommandTarget(IOleCommandTarget *iface)
1153 return CONTAINING_RECORD(iface, WebBrowser, IOleCommandTarget_iface);
1156 static HRESULT WINAPI WBOleCommandTarget_QueryInterface(IOleCommandTarget *iface,
1157 REFIID riid, void **ppv)
1159 WebBrowser *This = impl_from_IOleCommandTarget(iface);
1160 return IUnknown_QueryInterface(This->hlink_frame.outer, riid, ppv);
1163 static ULONG WINAPI WBOleCommandTarget_AddRef(IOleCommandTarget *iface)
1165 WebBrowser *This = impl_from_IOleCommandTarget(iface);
1166 return IUnknown_AddRef(This->hlink_frame.outer);
1169 static ULONG WINAPI WBOleCommandTarget_Release(IOleCommandTarget *iface)
1171 WebBrowser *This = impl_from_IOleCommandTarget(iface);
1172 return IUnknown_Release(This->hlink_frame.outer);
1175 static HRESULT WINAPI WBOleCommandTarget_QueryStatus(IOleCommandTarget *iface,
1176 const GUID *pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[], OLECMDTEXT *pCmdText)
1178 WebBrowser *This = impl_from_IOleCommandTarget(iface);
1179 IOleCommandTarget *cmdtrg;
1180 HRESULT hres;
1182 TRACE("(%p)->(%s %u %p %p)\n", This, debugstr_guid(pguidCmdGroup), cCmds, prgCmds,
1183 pCmdText);
1185 if(!This->doc_host.document)
1186 return 0x80040104;
1188 /* NOTE: There are probably some commands that we should handle here
1189 * instead of forwarding to document object. */
1191 hres = IUnknown_QueryInterface(This->doc_host.document, &IID_IOleCommandTarget, (void**)&cmdtrg);
1192 if(FAILED(hres))
1193 return hres;
1195 hres = IOleCommandTarget_QueryStatus(cmdtrg, pguidCmdGroup, cCmds, prgCmds, pCmdText);
1196 IOleCommandTarget_Release(cmdtrg);
1198 return hres;
1201 static HRESULT WINAPI WBOleCommandTarget_Exec(IOleCommandTarget *iface,
1202 const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn,
1203 VARIANT *pvaOut)
1205 WebBrowser *This = impl_from_IOleCommandTarget(iface);
1206 FIXME("(%p)->(%s %d %d %s %p)\n", This, debugstr_guid(pguidCmdGroup), nCmdID,
1207 nCmdexecopt, debugstr_variant(pvaIn), pvaOut);
1208 return E_NOTIMPL;
1211 static const IOleCommandTargetVtbl OleCommandTargetVtbl = {
1212 WBOleCommandTarget_QueryInterface,
1213 WBOleCommandTarget_AddRef,
1214 WBOleCommandTarget_Release,
1215 WBOleCommandTarget_QueryStatus,
1216 WBOleCommandTarget_Exec
1219 void WebBrowser_OleObject_Init(WebBrowser *This)
1221 DWORD dpi_x;
1222 DWORD dpi_y;
1223 HDC hdc;
1225 /* default aspect ratio is 96dpi / 96dpi */
1226 hdc = GetDC(0);
1227 dpi_x = GetDeviceCaps(hdc, LOGPIXELSX);
1228 dpi_y = GetDeviceCaps(hdc, LOGPIXELSY);
1229 ReleaseDC(0, hdc);
1231 This->IOleObject_iface.lpVtbl = &OleObjectVtbl;
1232 This->IOleInPlaceObject_iface.lpVtbl = &OleInPlaceObjectVtbl;
1233 This->IOleControl_iface.lpVtbl = &OleControlVtbl;
1234 This->IOleInPlaceActiveObject_iface.lpVtbl = &OleInPlaceActiveObjectVtbl;
1235 This->IOleCommandTarget_iface.lpVtbl = &OleCommandTargetVtbl;
1237 /* Default size is 50x20 pixels, in himetric units */
1238 This->extent.cx = MulDiv( 50, 2540, dpi_x );
1239 This->extent.cy = MulDiv( 20, 2540, dpi_y );
1242 void WebBrowser_OleObject_Destroy(WebBrowser *This)
1244 release_client_site(This, TRUE);