ieframe: Don't release the advise sink in IOleObject::SetClientSite.
[wine.git] / dlls / ieframe / oleobject.c
blob1076afe448e8a31dcbaaf65f73ab1b94fac7a727
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)
288 release_dochost_client(&This->doc_host);
290 if(This->client) {
291 IOleClientSite_Release(This->client);
292 This->client = NULL;
295 if(This->shell_embedding_hwnd) {
296 DestroyWindow(This->shell_embedding_hwnd);
297 This->shell_embedding_hwnd = NULL;
300 if(This->inplace) {
301 IOleInPlaceSiteEx_Release(This->inplace);
302 This->inplace = NULL;
305 if(This->container) {
306 IOleContainer_Release(This->container);
307 This->container = NULL;
310 if(This->uiwindow) {
311 IOleInPlaceUIWindow_Release(This->uiwindow);
312 This->uiwindow = NULL;
316 typedef struct {
317 IEnumOLEVERB IEnumOLEVERB_iface;
318 LONG ref;
319 LONG iter;
320 } EnumOLEVERB;
322 static inline EnumOLEVERB *impl_from_IEnumOLEVERB(IEnumOLEVERB *iface)
324 return CONTAINING_RECORD(iface, EnumOLEVERB, IEnumOLEVERB_iface);
327 static HRESULT WINAPI EnumOLEVERB_QueryInterface(IEnumOLEVERB *iface, REFIID riid, void **ppv)
329 EnumOLEVERB *This = impl_from_IEnumOLEVERB(iface);
331 if(IsEqualGUID(&IID_IUnknown, riid)) {
332 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
333 *ppv = &This->IEnumOLEVERB_iface;
334 }else if(IsEqualGUID(&IID_IEnumOLEVERB, riid)) {
335 TRACE("(%p)->(IID_IEnumOLEVERB %p)\n", This, ppv);
336 *ppv = &This->IEnumOLEVERB_iface;
337 }else {
338 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
339 *ppv = NULL;
340 return E_NOINTERFACE;
343 IUnknown_AddRef((IUnknown*)*ppv);
344 return S_OK;
347 static ULONG WINAPI EnumOLEVERB_AddRef(IEnumOLEVERB *iface)
349 EnumOLEVERB *This = impl_from_IEnumOLEVERB(iface);
350 LONG ref = InterlockedIncrement(&This->ref);
352 TRACE("(%p) ref=%d\n", This, ref);
354 return ref;
357 static ULONG WINAPI EnumOLEVERB_Release(IEnumOLEVERB *iface)
359 EnumOLEVERB *This = impl_from_IEnumOLEVERB(iface);
360 LONG ref = InterlockedDecrement(&This->ref);
362 TRACE("(%p) ref=%d\n", This, ref);
364 if(!ref)
365 heap_free(This);
367 return ref;
370 static HRESULT WINAPI EnumOLEVERB_Next(IEnumOLEVERB *iface, ULONG celt, OLEVERB *rgelt, ULONG *pceltFetched)
372 EnumOLEVERB *This = impl_from_IEnumOLEVERB(iface);
374 static const OLEVERB verbs[] =
375 {{OLEIVERB_PRIMARY},{OLEIVERB_INPLACEACTIVATE},{OLEIVERB_UIACTIVATE},{OLEIVERB_SHOW},{OLEIVERB_HIDE}};
377 TRACE("(%p)->(%u %p %p)\n", This, celt, rgelt, pceltFetched);
379 /* There are a few problems with this implementation, but that's how it seems to work in native. See tests. */
380 if(pceltFetched)
381 *pceltFetched = 0;
383 if(This->iter == sizeof(verbs)/sizeof(*verbs))
384 return S_FALSE;
386 if(celt)
387 *rgelt = verbs[This->iter++];
388 return S_OK;
391 static HRESULT WINAPI EnumOLEVERB_Skip(IEnumOLEVERB *iface, ULONG celt)
393 EnumOLEVERB *This = impl_from_IEnumOLEVERB(iface);
394 TRACE("(%p)->(%u)\n", This, celt);
395 return S_OK;
398 static HRESULT WINAPI EnumOLEVERB_Reset(IEnumOLEVERB *iface)
400 EnumOLEVERB *This = impl_from_IEnumOLEVERB(iface);
402 TRACE("(%p)\n", This);
404 This->iter = 0;
405 return S_OK;
408 static HRESULT WINAPI EnumOLEVERB_Clone(IEnumOLEVERB *iface, IEnumOLEVERB **ppenum)
410 EnumOLEVERB *This = impl_from_IEnumOLEVERB(iface);
411 FIXME("(%p)->(%p)\n", This, ppenum);
412 return E_NOTIMPL;
415 static const IEnumOLEVERBVtbl EnumOLEVERBVtbl = {
416 EnumOLEVERB_QueryInterface,
417 EnumOLEVERB_AddRef,
418 EnumOLEVERB_Release,
419 EnumOLEVERB_Next,
420 EnumOLEVERB_Skip,
421 EnumOLEVERB_Reset,
422 EnumOLEVERB_Clone
425 /**********************************************************************
426 * Implement the IOleObject interface for the WebBrowser control
429 static inline WebBrowser *impl_from_IOleObject(IOleObject *iface)
431 return CONTAINING_RECORD(iface, WebBrowser, IOleObject_iface);
434 static HRESULT WINAPI OleObject_QueryInterface(IOleObject *iface, REFIID riid, void **ppv)
436 WebBrowser *This = impl_from_IOleObject(iface);
437 return IWebBrowser2_QueryInterface(&This->IWebBrowser2_iface, riid, ppv);
440 static ULONG WINAPI OleObject_AddRef(IOleObject *iface)
442 WebBrowser *This = impl_from_IOleObject(iface);
443 return IWebBrowser2_AddRef(&This->IWebBrowser2_iface);
446 static ULONG WINAPI OleObject_Release(IOleObject *iface)
448 WebBrowser *This = impl_from_IOleObject(iface);
449 return IWebBrowser2_Release(&This->IWebBrowser2_iface);
452 static HRESULT WINAPI OleObject_SetClientSite(IOleObject *iface, LPOLECLIENTSITE pClientSite)
454 WebBrowser *This = impl_from_IOleObject(iface);
455 IDocHostUIHandler *hostui;
456 IOleCommandTarget *olecmd;
457 IOleContainer *container;
458 IDispatch *disp;
459 HRESULT hres;
461 TRACE("(%p)->(%p)\n", This, pClientSite);
463 if(This->client == pClientSite)
464 return S_OK;
466 release_client_site(This);
468 if(!pClientSite) {
469 on_commandstate_change(&This->doc_host, CSC_NAVIGATEBACK, FALSE);
470 on_commandstate_change(&This->doc_host, CSC_NAVIGATEFORWARD, FALSE);
472 if(This->doc_host.document)
473 deactivate_document(&This->doc_host);
474 return S_OK;
477 IOleClientSite_AddRef(pClientSite);
478 This->client = pClientSite;
480 hres = IOleClientSite_QueryInterface(This->client, &IID_IDispatch,
481 (void**)&disp);
482 if(SUCCEEDED(hres))
483 This->doc_host.client_disp = disp;
485 hres = IOleClientSite_QueryInterface(This->client, &IID_IDocHostUIHandler,
486 (void**)&hostui);
487 if(SUCCEEDED(hres))
488 This->doc_host.hostui = hostui;
490 hres = IOleClientSite_GetContainer(This->client, &container);
491 if(SUCCEEDED(hres)) {
492 ITargetContainer *target_container;
494 hres = IOleContainer_QueryInterface(container, &IID_ITargetContainer,
495 (void**)&target_container);
496 if(SUCCEEDED(hres)) {
497 FIXME("Unsupported ITargetContainer\n");
498 ITargetContainer_Release(target_container);
501 hres = IOleContainer_QueryInterface(container, &IID_IOleCommandTarget, (void**)&olecmd);
502 if(FAILED(hres))
503 olecmd = NULL;
505 IOleContainer_Release(container);
506 }else {
507 hres = IOleClientSite_QueryInterface(This->client, &IID_IOleCommandTarget, (void**)&olecmd);
508 if(FAILED(hres))
509 olecmd = NULL;
512 This->doc_host.olecmd = olecmd;
514 create_shell_embedding_hwnd(This);
516 on_offlineconnected_change(This);
517 on_silent_change(This);
519 return S_OK;
522 static HRESULT WINAPI OleObject_GetClientSite(IOleObject *iface, LPOLECLIENTSITE *ppClientSite)
524 WebBrowser *This = impl_from_IOleObject(iface);
526 TRACE("(%p)->(%p)\n", This, ppClientSite);
528 if(!ppClientSite)
529 return E_INVALIDARG;
531 if(This->client)
532 IOleClientSite_AddRef(This->client);
533 *ppClientSite = This->client;
535 return S_OK;
538 static HRESULT WINAPI OleObject_SetHostNames(IOleObject *iface, LPCOLESTR szContainerApp,
539 LPCOLESTR szContainerObj)
541 WebBrowser *This = impl_from_IOleObject(iface);
543 TRACE("(%p)->(%s, %s)\n", This, debugstr_w(szContainerApp), debugstr_w(szContainerObj));
545 /* We have nothing to do here. */
546 return S_OK;
549 static HRESULT WINAPI OleObject_Close(IOleObject *iface, DWORD dwSaveOption)
551 WebBrowser *This = impl_from_IOleObject(iface);
553 TRACE("(%p)->(%d)\n", This, dwSaveOption);
555 if(dwSaveOption != OLECLOSE_NOSAVE) {
556 FIXME("unimplemented flag: %x\n", dwSaveOption);
557 return E_NOTIMPL;
560 if(This->doc_host.frame)
561 IOleInPlaceFrame_SetActiveObject(This->doc_host.frame, NULL, NULL);
563 if(This->uiwindow)
564 IOleInPlaceUIWindow_SetActiveObject(This->uiwindow, NULL, NULL);
566 if(This->inplace)
567 IOleInPlaceSiteEx_OnUIDeactivate(This->inplace, FALSE);
568 notify_on_focus(This, FALSE);
569 if(This->inplace)
570 IOleInPlaceSiteEx_OnInPlaceDeactivate(This->inplace);
572 return IOleObject_SetClientSite(iface, NULL);
575 static HRESULT WINAPI OleObject_SetMoniker(IOleObject *iface, DWORD dwWhichMoniker, IMoniker* pmk)
577 WebBrowser *This = impl_from_IOleObject(iface);
578 FIXME("(%p)->(%d, %p)\n", This, dwWhichMoniker, pmk);
579 return E_NOTIMPL;
582 static HRESULT WINAPI OleObject_GetMoniker(IOleObject *iface, DWORD dwAssign,
583 DWORD dwWhichMoniker, LPMONIKER *ppmk)
585 WebBrowser *This = impl_from_IOleObject(iface);
586 FIXME("(%p)->(%d, %d, %p)\n", This, dwAssign, dwWhichMoniker, ppmk);
587 return E_NOTIMPL;
590 static HRESULT WINAPI OleObject_InitFromData(IOleObject *iface, LPDATAOBJECT pDataObject,
591 BOOL fCreation, DWORD dwReserved)
593 WebBrowser *This = impl_from_IOleObject(iface);
594 FIXME("(%p)->(%p, %d, %d)\n", This, pDataObject, fCreation, dwReserved);
595 return E_NOTIMPL;
598 static HRESULT WINAPI OleObject_GetClipboardData(IOleObject *iface, DWORD dwReserved,
599 LPDATAOBJECT *ppDataObject)
601 WebBrowser *This = impl_from_IOleObject(iface);
602 FIXME("(%p)->(%d, %p)\n", This, dwReserved, ppDataObject);
603 return E_NOTIMPL;
606 static HRESULT WINAPI OleObject_DoVerb(IOleObject *iface, LONG iVerb, struct tagMSG* lpmsg,
607 LPOLECLIENTSITE pActiveSite, LONG lindex, HWND hwndParent, LPCRECT lprcPosRect)
609 WebBrowser *This = impl_from_IOleObject(iface);
611 TRACE("(%p)->(%d %p %p %d %p %s)\n", This, iVerb, lpmsg, pActiveSite, lindex, hwndParent,
612 wine_dbgstr_rect(lprcPosRect));
614 switch (iVerb)
616 case OLEIVERB_SHOW:
617 TRACE("OLEIVERB_SHOW\n");
618 return activate_ui(This, pActiveSite);
619 case OLEIVERB_UIACTIVATE:
620 TRACE("OLEIVERB_UIACTIVATE\n");
621 return activate_ui(This, pActiveSite);
622 case OLEIVERB_INPLACEACTIVATE:
623 TRACE("OLEIVERB_INPLACEACTIVATE\n");
624 return activate_inplace(This, pActiveSite);
625 case OLEIVERB_HIDE:
626 TRACE("OLEIVERB_HIDE\n");
627 if(This->inplace)
628 IOleInPlaceSiteEx_OnInPlaceDeactivate(This->inplace);
629 if(This->shell_embedding_hwnd)
630 ShowWindow(This->shell_embedding_hwnd, SW_HIDE);
631 return S_OK;
632 default:
633 FIXME("stub for %d\n", iVerb);
634 break;
637 return E_NOTIMPL;
640 static HRESULT WINAPI OleObject_EnumVerbs(IOleObject *iface, IEnumOLEVERB **ppEnumOleVerb)
642 WebBrowser *This = impl_from_IOleObject(iface);
643 EnumOLEVERB *ret;
645 TRACE("(%p)->(%p)\n", This, ppEnumOleVerb);
647 ret = heap_alloc(sizeof(*ret));
648 if(!ret)
649 return E_OUTOFMEMORY;
651 ret->IEnumOLEVERB_iface.lpVtbl = &EnumOLEVERBVtbl;
652 ret->ref = 1;
653 ret->iter = 0;
655 *ppEnumOleVerb = &ret->IEnumOLEVERB_iface;
656 return S_OK;
659 static HRESULT WINAPI OleObject_Update(IOleObject *iface)
661 WebBrowser *This = impl_from_IOleObject(iface);
662 FIXME("(%p)\n", This);
663 return E_NOTIMPL;
666 static HRESULT WINAPI OleObject_IsUpToDate(IOleObject *iface)
668 WebBrowser *This = impl_from_IOleObject(iface);
669 FIXME("(%p)\n", This);
670 return E_NOTIMPL;
673 static HRESULT WINAPI OleObject_GetUserClassID(IOleObject *iface, CLSID* pClsid)
675 WebBrowser *This = impl_from_IOleObject(iface);
676 FIXME("(%p)->(%p)\n", This, pClsid);
677 return E_NOTIMPL;
680 static HRESULT WINAPI OleObject_GetUserType(IOleObject *iface, DWORD dwFormOfType,
681 LPOLESTR* pszUserType)
683 WebBrowser *This = impl_from_IOleObject(iface);
684 TRACE("(%p, %d, %p)\n", This, dwFormOfType, pszUserType);
685 return OleRegGetUserType(&CLSID_WebBrowser, dwFormOfType, pszUserType);
688 static HRESULT WINAPI OleObject_SetExtent(IOleObject *iface, DWORD dwDrawAspect, SIZEL *psizel)
690 WebBrowser *This = impl_from_IOleObject(iface);
692 TRACE("(%p)->(%x %p)\n", This, dwDrawAspect, psizel);
694 /* Tests show that dwDrawAspect is ignored */
695 This->extent = *psizel;
696 return S_OK;
699 static HRESULT WINAPI OleObject_GetExtent(IOleObject *iface, DWORD dwDrawAspect, SIZEL *psizel)
701 WebBrowser *This = impl_from_IOleObject(iface);
703 TRACE("(%p)->(%x, %p)\n", This, dwDrawAspect, psizel);
705 /* Tests show that dwDrawAspect is ignored */
706 *psizel = This->extent;
707 return S_OK;
710 static HRESULT WINAPI OleObject_Advise(IOleObject *iface, IAdviseSink *pAdvSink,
711 DWORD* pdwConnection)
713 WebBrowser *This = impl_from_IOleObject(iface);
714 FIXME("(%p)->(%p, %p)\n", This, pAdvSink, pdwConnection);
715 return E_NOTIMPL;
718 static HRESULT WINAPI OleObject_Unadvise(IOleObject *iface, DWORD dwConnection)
720 WebBrowser *This = impl_from_IOleObject(iface);
721 FIXME("(%p)->(%d)\n", This, dwConnection);
722 return E_NOTIMPL;
725 static HRESULT WINAPI OleObject_EnumAdvise(IOleObject *iface, IEnumSTATDATA **ppenumAdvise)
727 WebBrowser *This = impl_from_IOleObject(iface);
728 FIXME("(%p)->(%p)\n", This, ppenumAdvise);
729 return S_OK;
732 static HRESULT WINAPI OleObject_GetMiscStatus(IOleObject *iface, DWORD dwAspect, DWORD *pdwStatus)
734 WebBrowser *This = impl_from_IOleObject(iface);
736 TRACE("(%p)->(%x, %p)\n", This, dwAspect, pdwStatus);
738 *pdwStatus = OLEMISC_SETCLIENTSITEFIRST|OLEMISC_ACTIVATEWHENVISIBLE|OLEMISC_INSIDEOUT
739 |OLEMISC_CANTLINKINSIDE|OLEMISC_RECOMPOSEONRESIZE;
741 return S_OK;
744 static HRESULT WINAPI OleObject_SetColorScheme(IOleObject *iface, LOGPALETTE* pLogpal)
746 WebBrowser *This = impl_from_IOleObject(iface);
747 FIXME("(%p)->(%p)\n", This, pLogpal);
748 return E_NOTIMPL;
751 static const IOleObjectVtbl OleObjectVtbl =
753 OleObject_QueryInterface,
754 OleObject_AddRef,
755 OleObject_Release,
756 OleObject_SetClientSite,
757 OleObject_GetClientSite,
758 OleObject_SetHostNames,
759 OleObject_Close,
760 OleObject_SetMoniker,
761 OleObject_GetMoniker,
762 OleObject_InitFromData,
763 OleObject_GetClipboardData,
764 OleObject_DoVerb,
765 OleObject_EnumVerbs,
766 OleObject_Update,
767 OleObject_IsUpToDate,
768 OleObject_GetUserClassID,
769 OleObject_GetUserType,
770 OleObject_SetExtent,
771 OleObject_GetExtent,
772 OleObject_Advise,
773 OleObject_Unadvise,
774 OleObject_EnumAdvise,
775 OleObject_GetMiscStatus,
776 OleObject_SetColorScheme
779 /**********************************************************************
780 * Implement the IOleInPlaceObject interface
783 static inline WebBrowser *impl_from_IOleInPlaceObject(IOleInPlaceObject *iface)
785 return CONTAINING_RECORD(iface, WebBrowser, IOleInPlaceObject_iface);
788 static HRESULT WINAPI OleInPlaceObject_QueryInterface(IOleInPlaceObject *iface,
789 REFIID riid, LPVOID *ppobj)
791 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
792 return IWebBrowser2_QueryInterface(&This->IWebBrowser2_iface, riid, ppobj);
795 static ULONG WINAPI OleInPlaceObject_AddRef(IOleInPlaceObject *iface)
797 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
798 return IWebBrowser2_AddRef(&This->IWebBrowser2_iface);
801 static ULONG WINAPI OleInPlaceObject_Release(IOleInPlaceObject *iface)
803 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
804 return IWebBrowser2_Release(&This->IWebBrowser2_iface);
807 static HRESULT WINAPI OleInPlaceObject_GetWindow(IOleInPlaceObject *iface, HWND* phwnd)
809 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
811 TRACE("(%p)->(%p)\n", This, phwnd);
813 *phwnd = This->shell_embedding_hwnd;
814 return S_OK;
817 static HRESULT WINAPI OleInPlaceObject_ContextSensitiveHelp(IOleInPlaceObject *iface,
818 BOOL fEnterMode)
820 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
821 FIXME("(%p)->(%x)\n", This, fEnterMode);
822 return E_NOTIMPL;
825 static HRESULT WINAPI OleInPlaceObject_InPlaceDeactivate(IOleInPlaceObject *iface)
827 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
828 FIXME("(%p)\n", This);
830 if(This->inplace) {
831 IOleInPlaceSiteEx_Release(This->inplace);
832 This->inplace = NULL;
835 return S_OK;
838 static HRESULT WINAPI OleInPlaceObject_UIDeactivate(IOleInPlaceObject *iface)
840 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
841 FIXME("(%p)\n", This);
842 return E_NOTIMPL;
845 static HRESULT WINAPI OleInPlaceObject_SetObjectRects(IOleInPlaceObject *iface,
846 LPCRECT lprcPosRect, LPCRECT lprcClipRect)
848 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
850 TRACE("(%p)->(%s %s)\n", This, wine_dbgstr_rect(lprcPosRect), wine_dbgstr_rect(lprcClipRect));
852 This->pos_rect = *lprcPosRect;
854 if(lprcClipRect)
855 This->clip_rect = *lprcClipRect;
857 if(This->shell_embedding_hwnd) {
858 SetWindowPos(This->shell_embedding_hwnd, NULL,
859 lprcPosRect->left, lprcPosRect->top,
860 lprcPosRect->right-lprcPosRect->left,
861 lprcPosRect->bottom-lprcPosRect->top,
862 SWP_NOZORDER | SWP_NOACTIVATE);
865 return S_OK;
868 static HRESULT WINAPI OleInPlaceObject_ReactivateAndUndo(IOleInPlaceObject *iface)
870 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
871 FIXME("(%p)\n", This);
872 return E_NOTIMPL;
875 static const IOleInPlaceObjectVtbl OleInPlaceObjectVtbl =
877 OleInPlaceObject_QueryInterface,
878 OleInPlaceObject_AddRef,
879 OleInPlaceObject_Release,
880 OleInPlaceObject_GetWindow,
881 OleInPlaceObject_ContextSensitiveHelp,
882 OleInPlaceObject_InPlaceDeactivate,
883 OleInPlaceObject_UIDeactivate,
884 OleInPlaceObject_SetObjectRects,
885 OleInPlaceObject_ReactivateAndUndo
888 /**********************************************************************
889 * Implement the IOleControl interface
892 static inline WebBrowser *impl_from_IOleControl(IOleControl *iface)
894 return CONTAINING_RECORD(iface, WebBrowser, IOleControl_iface);
897 static HRESULT WINAPI OleControl_QueryInterface(IOleControl *iface,
898 REFIID riid, LPVOID *ppobj)
900 WebBrowser *This = impl_from_IOleControl(iface);
901 return IWebBrowser2_QueryInterface(&This->IWebBrowser2_iface, riid, ppobj);
904 static ULONG WINAPI OleControl_AddRef(IOleControl *iface)
906 WebBrowser *This = impl_from_IOleControl(iface);
907 return IWebBrowser2_AddRef(&This->IWebBrowser2_iface);
910 static ULONG WINAPI OleControl_Release(IOleControl *iface)
912 WebBrowser *This = impl_from_IOleControl(iface);
913 return IWebBrowser2_Release(&This->IWebBrowser2_iface);
916 static HRESULT WINAPI OleControl_GetControlInfo(IOleControl *iface, LPCONTROLINFO pCI)
918 WebBrowser *This = impl_from_IOleControl(iface);
920 TRACE("(%p)->(%p)\n", This, pCI);
922 /* Tests show that this function should be not implemented */
923 return E_NOTIMPL;
926 static HRESULT WINAPI OleControl_OnMnemonic(IOleControl *iface, struct tagMSG *pMsg)
928 WebBrowser *This = impl_from_IOleControl(iface);
929 FIXME("(%p)->(%p)\n", This, pMsg);
930 return E_NOTIMPL;
933 static HRESULT WINAPI OleControl_OnAmbientPropertyChange(IOleControl *iface, DISPID dispID)
935 WebBrowser *This = impl_from_IOleControl(iface);
937 TRACE("(%p)->(%d)\n", This, dispID);
939 switch(dispID) {
940 case DISPID_UNKNOWN:
941 /* Unknown means multiple properties changed, so check them all.
942 * BUT the Webbrowser OleControl object doesn't appear to do this.
944 return S_OK;
945 case DISPID_AMBIENT_DLCONTROL:
946 return S_OK;
947 case DISPID_AMBIENT_OFFLINEIFNOTCONNECTED:
948 return on_offlineconnected_change(This);
949 case DISPID_AMBIENT_SILENT:
950 return on_silent_change(This);
953 FIXME("Unknown dispID %d\n", dispID);
954 return E_NOTIMPL;
957 static HRESULT WINAPI OleControl_FreezeEvents(IOleControl *iface, BOOL bFreeze)
959 WebBrowser *This = impl_from_IOleControl(iface);
960 FIXME("(%p)->(%x)\n", This, bFreeze);
961 return E_NOTIMPL;
964 static const IOleControlVtbl OleControlVtbl =
966 OleControl_QueryInterface,
967 OleControl_AddRef,
968 OleControl_Release,
969 OleControl_GetControlInfo,
970 OleControl_OnMnemonic,
971 OleControl_OnAmbientPropertyChange,
972 OleControl_FreezeEvents
975 static inline WebBrowser *impl_from_IOleInPlaceActiveObject(IOleInPlaceActiveObject *iface)
977 return CONTAINING_RECORD(iface, WebBrowser, IOleInPlaceActiveObject_iface);
980 static HRESULT WINAPI InPlaceActiveObject_QueryInterface(IOleInPlaceActiveObject *iface,
981 REFIID riid, void **ppv)
983 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
984 return IWebBrowser2_QueryInterface(&This->IWebBrowser2_iface, riid, ppv);
987 static ULONG WINAPI InPlaceActiveObject_AddRef(IOleInPlaceActiveObject *iface)
989 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
990 return IWebBrowser2_AddRef(&This->IWebBrowser2_iface);
993 static ULONG WINAPI InPlaceActiveObject_Release(IOleInPlaceActiveObject *iface)
995 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
996 return IWebBrowser2_Release(&This->IWebBrowser2_iface);
999 static HRESULT WINAPI InPlaceActiveObject_GetWindow(IOleInPlaceActiveObject *iface,
1000 HWND *phwnd)
1002 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
1003 return IOleInPlaceObject_GetWindow(&This->IOleInPlaceObject_iface, phwnd);
1006 static HRESULT WINAPI InPlaceActiveObject_ContextSensitiveHelp(IOleInPlaceActiveObject *iface,
1007 BOOL fEnterMode)
1009 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
1010 return IOleInPlaceObject_ContextSensitiveHelp(&This->IOleInPlaceObject_iface, fEnterMode);
1013 static HRESULT WINAPI InPlaceActiveObject_TranslateAccelerator(IOleInPlaceActiveObject *iface,
1014 LPMSG lpmsg)
1016 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
1017 IOleInPlaceActiveObject *activeobj;
1018 HRESULT hr = S_FALSE;
1020 TRACE("(%p)->(%p)\n", This, lpmsg);
1022 if(This->doc_host.document) {
1023 if(SUCCEEDED(IUnknown_QueryInterface(This->doc_host.document,
1024 &IID_IOleInPlaceActiveObject,
1025 (void**)&activeobj))) {
1026 hr = IOleInPlaceActiveObject_TranslateAccelerator(activeobj, lpmsg);
1027 IOleInPlaceActiveObject_Release(activeobj);
1031 if(SUCCEEDED(hr))
1032 return hr;
1033 else
1034 return S_FALSE;
1037 static HRESULT WINAPI InPlaceActiveObject_OnFrameWindowActivate(IOleInPlaceActiveObject *iface,
1038 BOOL fActivate)
1040 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
1041 FIXME("(%p)->(%x)\n", This, fActivate);
1042 return E_NOTIMPL;
1045 static HRESULT WINAPI InPlaceActiveObject_OnDocWindowActivate(IOleInPlaceActiveObject *iface,
1046 BOOL fActivate)
1048 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
1049 FIXME("(%p)->(%x)\n", This, fActivate);
1050 return E_NOTIMPL;
1053 static HRESULT WINAPI InPlaceActiveObject_ResizeBorder(IOleInPlaceActiveObject *iface,
1054 LPCRECT lprcBorder, IOleInPlaceUIWindow *pUIWindow, BOOL fFrameWindow)
1056 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
1057 FIXME("(%p)->(%p %p %x)\n", This, lprcBorder, pUIWindow, fFrameWindow);
1058 return E_NOTIMPL;
1061 static HRESULT WINAPI InPlaceActiveObject_EnableModeless(IOleInPlaceActiveObject *iface,
1062 BOOL fEnable)
1064 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
1065 FIXME("(%p)->(%x)\n", This, fEnable);
1066 return E_NOTIMPL;
1069 static const IOleInPlaceActiveObjectVtbl OleInPlaceActiveObjectVtbl = {
1070 InPlaceActiveObject_QueryInterface,
1071 InPlaceActiveObject_AddRef,
1072 InPlaceActiveObject_Release,
1073 InPlaceActiveObject_GetWindow,
1074 InPlaceActiveObject_ContextSensitiveHelp,
1075 InPlaceActiveObject_TranslateAccelerator,
1076 InPlaceActiveObject_OnFrameWindowActivate,
1077 InPlaceActiveObject_OnDocWindowActivate,
1078 InPlaceActiveObject_ResizeBorder,
1079 InPlaceActiveObject_EnableModeless
1082 static inline WebBrowser *impl_from_IOleCommandTarget(IOleCommandTarget *iface)
1084 return CONTAINING_RECORD(iface, WebBrowser, IOleCommandTarget_iface);
1087 static HRESULT WINAPI WBOleCommandTarget_QueryInterface(IOleCommandTarget *iface,
1088 REFIID riid, void **ppv)
1090 WebBrowser *This = impl_from_IOleCommandTarget(iface);
1091 return IWebBrowser2_QueryInterface(&This->IWebBrowser2_iface, riid, ppv);
1094 static ULONG WINAPI WBOleCommandTarget_AddRef(IOleCommandTarget *iface)
1096 WebBrowser *This = impl_from_IOleCommandTarget(iface);
1097 return IWebBrowser2_AddRef(&This->IWebBrowser2_iface);
1100 static ULONG WINAPI WBOleCommandTarget_Release(IOleCommandTarget *iface)
1102 WebBrowser *This = impl_from_IOleCommandTarget(iface);
1103 return IWebBrowser2_Release(&This->IWebBrowser2_iface);
1106 static HRESULT WINAPI WBOleCommandTarget_QueryStatus(IOleCommandTarget *iface,
1107 const GUID *pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[], OLECMDTEXT *pCmdText)
1109 WebBrowser *This = impl_from_IOleCommandTarget(iface);
1110 IOleCommandTarget *cmdtrg;
1111 HRESULT hres;
1113 TRACE("(%p)->(%s %u %p %p)\n", This, debugstr_guid(pguidCmdGroup), cCmds, prgCmds,
1114 pCmdText);
1116 if(!This->doc_host.document)
1117 return 0x80040104;
1119 /* NOTE: There are probably some commands that we should handle here
1120 * instead of forwarding to document object. */
1122 hres = IUnknown_QueryInterface(This->doc_host.document, &IID_IOleCommandTarget, (void**)&cmdtrg);
1123 if(FAILED(hres))
1124 return hres;
1126 hres = IOleCommandTarget_QueryStatus(cmdtrg, pguidCmdGroup, cCmds, prgCmds, pCmdText);
1127 IOleCommandTarget_Release(cmdtrg);
1129 return hres;
1132 static HRESULT WINAPI WBOleCommandTarget_Exec(IOleCommandTarget *iface,
1133 const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn,
1134 VARIANT *pvaOut)
1136 WebBrowser *This = impl_from_IOleCommandTarget(iface);
1137 FIXME("(%p)->(%s %d %d %s %p)\n", This, debugstr_guid(pguidCmdGroup), nCmdID,
1138 nCmdexecopt, debugstr_variant(pvaIn), pvaOut);
1139 return E_NOTIMPL;
1142 static const IOleCommandTargetVtbl OleCommandTargetVtbl = {
1143 WBOleCommandTarget_QueryInterface,
1144 WBOleCommandTarget_AddRef,
1145 WBOleCommandTarget_Release,
1146 WBOleCommandTarget_QueryStatus,
1147 WBOleCommandTarget_Exec
1150 void WebBrowser_OleObject_Init(WebBrowser *This)
1152 DWORD dpi_x;
1153 DWORD dpi_y;
1154 HDC hdc;
1156 /* default aspect ratio is 96dpi / 96dpi */
1157 hdc = GetDC(0);
1158 dpi_x = GetDeviceCaps(hdc, LOGPIXELSX);
1159 dpi_y = GetDeviceCaps(hdc, LOGPIXELSY);
1160 ReleaseDC(0, hdc);
1162 This->IOleObject_iface.lpVtbl = &OleObjectVtbl;
1163 This->IOleInPlaceObject_iface.lpVtbl = &OleInPlaceObjectVtbl;
1164 This->IOleControl_iface.lpVtbl = &OleControlVtbl;
1165 This->IOleInPlaceActiveObject_iface.lpVtbl = &OleInPlaceActiveObjectVtbl;
1166 This->IOleCommandTarget_iface.lpVtbl = &OleCommandTargetVtbl;
1168 /* Default size is 50x20 pixels, in himetric units */
1169 This->extent.cx = MulDiv( 50, 2540, dpi_x );
1170 This->extent.cy = MulDiv( 20, 2540, dpi_y );
1173 void WebBrowser_OleObject_Destroy(WebBrowser *This)
1175 release_client_site(This);