kernelbase/tests: Use win_skip() for missing APIs.
[wine.git] / dlls / ieframe / oleobject.c
blob742e78ce4e408eaa089d2bc7d18c5fed7552d7e7
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: %08lx\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 if(This->ui_activated)
218 return S_OK;
220 IOleInPlaceSiteEx_OnUIActivate(This->inplace);
222 if(This->doc_host.frame)
223 IOleInPlaceFrame_SetActiveObject(This->doc_host.frame, &This->IOleInPlaceActiveObject_iface, wszitem);
224 if(This->uiwindow)
225 IOleInPlaceUIWindow_SetActiveObject(This->uiwindow, &This->IOleInPlaceActiveObject_iface, wszitem);
227 if(This->doc_host.frame)
228 IOleInPlaceFrame_SetMenu(This->doc_host.frame, NULL, NULL, This->shell_embedding_hwnd);
230 SetFocus(This->shell_embedding_hwnd);
231 notify_on_focus(This, TRUE);
233 activate_document(&This->doc_host);
235 This->ui_activated = TRUE;
237 return S_OK;
240 static HRESULT get_client_disp_property(IOleClientSite *client, DISPID dispid, VARIANT *res)
242 IDispatch *disp = NULL;
243 DISPPARAMS dispparams = {NULL, 0};
244 HRESULT hres;
246 VariantInit(res);
248 if(!client)
249 return S_OK;
251 hres = IOleClientSite_QueryInterface(client, &IID_IDispatch, (void**)&disp);
252 if(FAILED(hres)) {
253 TRACE("Could not get IDispatch\n");
254 return hres;
257 hres = IDispatch_Invoke(disp, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
258 DISPATCH_PROPERTYGET, &dispparams, res, NULL, NULL);
260 IDispatch_Release(disp);
262 return hres;
265 static HRESULT on_offlineconnected_change(WebBrowser *This)
267 VARIANT offline;
269 get_client_disp_property(This->client, DISPID_AMBIENT_OFFLINEIFNOTCONNECTED, &offline);
271 if(V_VT(&offline) == VT_BOOL)
272 IWebBrowser2_put_Offline(&This->IWebBrowser2_iface, V_BOOL(&offline));
273 else if(V_VT(&offline) != VT_EMPTY)
274 WARN("wrong V_VT(silent) %d\n", V_VT(&offline));
276 return S_OK;
279 static HRESULT on_silent_change(WebBrowser *This)
281 VARIANT silent;
283 get_client_disp_property(This->client, DISPID_AMBIENT_SILENT, &silent);
285 if(V_VT(&silent) == VT_BOOL)
286 IWebBrowser2_put_Silent(&This->IWebBrowser2_iface, V_BOOL(&silent));
287 else if(V_VT(&silent) != VT_EMPTY)
288 WARN("wrong V_VT(silent) %d\n", V_VT(&silent));
290 return S_OK;
293 static void release_client_site(WebBrowser *This, BOOL destroy_win)
295 release_dochost_client(&This->doc_host);
297 if(This->client) {
298 IOleClientSite_Release(This->client);
299 This->client = NULL;
302 if(This->client_closed) {
303 IOleClientSite_Release(This->client_closed);
304 This->client_closed = NULL;
307 if(destroy_win && This->shell_embedding_hwnd) {
308 DestroyWindow(This->shell_embedding_hwnd);
309 This->shell_embedding_hwnd = NULL;
312 if(This->inplace) {
313 IOleInPlaceSiteEx_Release(This->inplace);
314 This->inplace = NULL;
317 if(This->container) {
318 IOleContainer_Release(This->container);
319 This->container = NULL;
322 if(This->uiwindow) {
323 IOleInPlaceUIWindow_Release(This->uiwindow);
324 This->uiwindow = NULL;
328 typedef struct {
329 IEnumOLEVERB IEnumOLEVERB_iface;
330 LONG ref;
331 LONG iter;
332 } EnumOLEVERB;
334 static inline EnumOLEVERB *impl_from_IEnumOLEVERB(IEnumOLEVERB *iface)
336 return CONTAINING_RECORD(iface, EnumOLEVERB, IEnumOLEVERB_iface);
339 static HRESULT WINAPI EnumOLEVERB_QueryInterface(IEnumOLEVERB *iface, REFIID riid, void **ppv)
341 EnumOLEVERB *This = impl_from_IEnumOLEVERB(iface);
343 if(IsEqualGUID(&IID_IUnknown, riid)) {
344 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
345 *ppv = &This->IEnumOLEVERB_iface;
346 }else if(IsEqualGUID(&IID_IEnumOLEVERB, riid)) {
347 TRACE("(%p)->(IID_IEnumOLEVERB %p)\n", This, ppv);
348 *ppv = &This->IEnumOLEVERB_iface;
349 }else {
350 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
351 *ppv = NULL;
352 return E_NOINTERFACE;
355 IUnknown_AddRef((IUnknown*)*ppv);
356 return S_OK;
359 static ULONG WINAPI EnumOLEVERB_AddRef(IEnumOLEVERB *iface)
361 EnumOLEVERB *This = impl_from_IEnumOLEVERB(iface);
362 LONG ref = InterlockedIncrement(&This->ref);
364 TRACE("(%p) ref=%ld\n", This, ref);
366 return ref;
369 static ULONG WINAPI EnumOLEVERB_Release(IEnumOLEVERB *iface)
371 EnumOLEVERB *This = impl_from_IEnumOLEVERB(iface);
372 LONG ref = InterlockedDecrement(&This->ref);
374 TRACE("(%p) ref=%ld\n", This, ref);
376 if(!ref)
377 free(This);
379 return ref;
382 static HRESULT WINAPI EnumOLEVERB_Next(IEnumOLEVERB *iface, ULONG celt, OLEVERB *rgelt, ULONG *pceltFetched)
384 EnumOLEVERB *This = impl_from_IEnumOLEVERB(iface);
386 static const OLEVERB verbs[] =
387 {{OLEIVERB_PRIMARY},{OLEIVERB_INPLACEACTIVATE},{OLEIVERB_UIACTIVATE},{OLEIVERB_SHOW},{OLEIVERB_HIDE}};
389 TRACE("(%p)->(%lu %p %p)\n", This, celt, rgelt, pceltFetched);
391 /* There are a few problems with this implementation, but that's how it seems to work in native. See tests. */
392 if(pceltFetched)
393 *pceltFetched = 0;
395 if(This->iter == ARRAY_SIZE(verbs))
396 return S_FALSE;
398 if(celt)
399 *rgelt = verbs[This->iter++];
400 return S_OK;
403 static HRESULT WINAPI EnumOLEVERB_Skip(IEnumOLEVERB *iface, ULONG celt)
405 EnumOLEVERB *This = impl_from_IEnumOLEVERB(iface);
406 TRACE("(%p)->(%lu)\n", This, celt);
407 return S_OK;
410 static HRESULT WINAPI EnumOLEVERB_Reset(IEnumOLEVERB *iface)
412 EnumOLEVERB *This = impl_from_IEnumOLEVERB(iface);
414 TRACE("(%p)\n", This);
416 This->iter = 0;
417 return S_OK;
420 static HRESULT WINAPI EnumOLEVERB_Clone(IEnumOLEVERB *iface, IEnumOLEVERB **ppenum)
422 EnumOLEVERB *This = impl_from_IEnumOLEVERB(iface);
423 FIXME("(%p)->(%p)\n", This, ppenum);
424 return E_NOTIMPL;
427 static const IEnumOLEVERBVtbl EnumOLEVERBVtbl = {
428 EnumOLEVERB_QueryInterface,
429 EnumOLEVERB_AddRef,
430 EnumOLEVERB_Release,
431 EnumOLEVERB_Next,
432 EnumOLEVERB_Skip,
433 EnumOLEVERB_Reset,
434 EnumOLEVERB_Clone
437 /**********************************************************************
438 * Implement the IOleObject interface for the WebBrowser control
441 static inline WebBrowser *impl_from_IOleObject(IOleObject *iface)
443 return CONTAINING_RECORD(iface, WebBrowser, IOleObject_iface);
446 static HRESULT WINAPI OleObject_QueryInterface(IOleObject *iface, REFIID riid, void **ppv)
448 WebBrowser *This = impl_from_IOleObject(iface);
449 return IUnknown_QueryInterface(This->hlink_frame.outer, riid, ppv);
452 static ULONG WINAPI OleObject_AddRef(IOleObject *iface)
454 WebBrowser *This = impl_from_IOleObject(iface);
455 return IUnknown_AddRef(This->hlink_frame.outer);
458 static ULONG WINAPI OleObject_Release(IOleObject *iface)
460 WebBrowser *This = impl_from_IOleObject(iface);
461 return IUnknown_Release(This->hlink_frame.outer);
464 static HRESULT WINAPI OleObject_SetClientSite(IOleObject *iface, LPOLECLIENTSITE pClientSite)
466 WebBrowser *This = impl_from_IOleObject(iface);
467 IDocHostUIHandler *hostui;
468 IOleCommandTarget *olecmd;
469 BOOL get_olecmd = TRUE;
470 IOleContainer *container;
471 IDispatch *disp;
472 HRESULT hres;
474 TRACE("(%p)->(%p)\n", This, pClientSite);
476 if(This->client_closed) {
477 IOleClientSite_Release(This->client_closed);
478 This->client_closed = NULL;
481 if(This->client == pClientSite)
482 return S_OK;
484 if(This->client && pClientSite) {
485 get_olecmd = FALSE;
486 olecmd = This->doc_host.olecmd;
487 if(olecmd)
488 IOleCommandTarget_AddRef(olecmd);
491 release_client_site(This, !pClientSite);
493 if(!pClientSite) {
494 on_commandstate_change(&This->doc_host, CSC_NAVIGATEBACK, FALSE);
495 on_commandstate_change(&This->doc_host, CSC_NAVIGATEFORWARD, FALSE);
497 if(This->doc_host.document)
498 deactivate_document(&This->doc_host);
499 return S_OK;
502 IOleClientSite_AddRef(pClientSite);
503 This->client = pClientSite;
505 hres = IOleClientSite_QueryInterface(This->client, &IID_IDispatch,
506 (void**)&disp);
507 if(SUCCEEDED(hres))
508 This->doc_host.client_disp = disp;
510 hres = IOleClientSite_QueryInterface(This->client, &IID_IDocHostUIHandler,
511 (void**)&hostui);
512 if(SUCCEEDED(hres))
513 This->doc_host.hostui = hostui;
515 if(get_olecmd) {
516 hres = IOleClientSite_GetContainer(This->client, &container);
517 if(SUCCEEDED(hres)) {
518 ITargetContainer *target_container;
520 hres = IOleContainer_QueryInterface(container, &IID_ITargetContainer,
521 (void**)&target_container);
522 if(SUCCEEDED(hres)) {
523 FIXME("Unsupported ITargetContainer\n");
524 ITargetContainer_Release(target_container);
527 hres = IOleContainer_QueryInterface(container, &IID_IOleCommandTarget, (void**)&olecmd);
528 if(FAILED(hres))
529 olecmd = NULL;
531 IOleContainer_Release(container);
532 }else {
533 hres = IOleClientSite_QueryInterface(This->client, &IID_IOleCommandTarget, (void**)&olecmd);
534 if(FAILED(hres))
535 olecmd = NULL;
539 This->doc_host.olecmd = olecmd;
541 if(This->shell_embedding_hwnd) {
542 IOleInPlaceSite *inplace;
543 HWND parent;
545 hres = IOleClientSite_QueryInterface(This->client, &IID_IOleInPlaceSite, (void**)&inplace);
546 if(SUCCEEDED(hres)) {
547 hres = IOleInPlaceSite_GetWindow(inplace, &parent);
548 IOleInPlaceSite_Release(inplace);
549 if(SUCCEEDED(hres))
550 SHSetParentHwnd(This->shell_embedding_hwnd, parent);
552 }else {
553 create_shell_embedding_hwnd(This);
556 on_offlineconnected_change(This);
557 on_silent_change(This);
558 SetQueryNetSessionCount(SESSION_INCREMENT);
560 return S_OK;
563 static HRESULT WINAPI OleObject_GetClientSite(IOleObject *iface, LPOLECLIENTSITE *ppClientSite)
565 WebBrowser *This = impl_from_IOleObject(iface);
567 TRACE("(%p)->(%p)\n", This, ppClientSite);
569 if(!ppClientSite)
570 return E_INVALIDARG;
572 if(This->client)
573 IOleClientSite_AddRef(This->client);
574 *ppClientSite = This->client;
576 return S_OK;
579 static HRESULT WINAPI OleObject_SetHostNames(IOleObject *iface, LPCOLESTR szContainerApp,
580 LPCOLESTR szContainerObj)
582 WebBrowser *This = impl_from_IOleObject(iface);
584 TRACE("(%p)->(%s, %s)\n", This, debugstr_w(szContainerApp), debugstr_w(szContainerObj));
586 /* We have nothing to do here. */
587 return S_OK;
590 static void deactivate_ui(WebBrowser *This)
592 if(This->ui_activated) {
593 if(This->doc_host.frame)
594 IOleInPlaceFrame_SetActiveObject(This->doc_host.frame, NULL, NULL);
596 if(This->uiwindow)
597 IOleInPlaceUIWindow_SetActiveObject(This->uiwindow, NULL, NULL);
599 if(This->inplace)
600 IOleInPlaceSiteEx_OnUIDeactivate(This->inplace, FALSE);
601 notify_on_focus(This, FALSE);
603 This->ui_activated = FALSE;
606 if(This->inplace)
607 IOleInPlaceSiteEx_OnInPlaceDeactivate(This->inplace);
610 static HRESULT WINAPI OleObject_Close(IOleObject *iface, DWORD dwSaveOption)
612 WebBrowser *This = impl_from_IOleObject(iface);
613 IOleClientSite *client;
614 HRESULT hres;
616 TRACE("(%p)->(%ld)\n", This, dwSaveOption);
618 if(dwSaveOption != OLECLOSE_NOSAVE) {
619 FIXME("unimplemented flag: %lx\n", dwSaveOption);
620 return E_NOTIMPL;
623 deactivate_ui(This);
625 /* store old client site - we need to restore it in DoVerb */
626 client = This->client;
627 if(This->client)
628 IOleClientSite_AddRef(This->client);
629 hres = IOleObject_SetClientSite(iface, NULL);
630 This->client_closed = client;
632 if(This->advise_holder)
633 IOleAdviseHolder_SendOnClose(This->advise_holder);
635 return hres;
638 static HRESULT WINAPI OleObject_SetMoniker(IOleObject *iface, DWORD dwWhichMoniker, IMoniker* pmk)
640 WebBrowser *This = impl_from_IOleObject(iface);
641 FIXME("(%p)->(%ld, %p)\n", This, dwWhichMoniker, pmk);
642 return E_NOTIMPL;
645 static HRESULT WINAPI OleObject_GetMoniker(IOleObject *iface, DWORD dwAssign,
646 DWORD dwWhichMoniker, LPMONIKER *ppmk)
648 WebBrowser *This = impl_from_IOleObject(iface);
649 FIXME("(%p)->(%ld, %ld, %p)\n", This, dwAssign, dwWhichMoniker, ppmk);
650 return E_NOTIMPL;
653 static HRESULT WINAPI OleObject_InitFromData(IOleObject *iface, LPDATAOBJECT pDataObject,
654 BOOL fCreation, DWORD dwReserved)
656 WebBrowser *This = impl_from_IOleObject(iface);
657 FIXME("(%p)->(%p, %d, %ld)\n", This, pDataObject, fCreation, dwReserved);
658 return E_NOTIMPL;
661 static HRESULT WINAPI OleObject_GetClipboardData(IOleObject *iface, DWORD dwReserved,
662 LPDATAOBJECT *ppDataObject)
664 WebBrowser *This = impl_from_IOleObject(iface);
665 FIXME("(%p)->(%ld, %p)\n", This, dwReserved, ppDataObject);
666 return E_NOTIMPL;
669 static HRESULT WINAPI OleObject_DoVerb(IOleObject *iface, LONG iVerb, struct tagMSG* lpmsg,
670 LPOLECLIENTSITE pActiveSite, LONG lindex, HWND hwndParent, LPCRECT lprcPosRect)
672 WebBrowser *This = impl_from_IOleObject(iface);
674 TRACE("(%p)->(%ld %p %p %ld %p %s)\n", This, iVerb, lpmsg, pActiveSite, lindex, hwndParent,
675 wine_dbgstr_rect(lprcPosRect));
677 /* restore closed client site if we have one */
678 if(!This->client && This->client_closed) {
679 IOleClientSite *client = This->client_closed;
680 This->client_closed = NULL;
681 IOleObject_SetClientSite(iface, client);
682 IOleClientSite_Release(client);
685 switch (iVerb)
687 case OLEIVERB_SHOW:
688 TRACE("OLEIVERB_SHOW\n");
689 return activate_ui(This, pActiveSite);
690 case OLEIVERB_UIACTIVATE:
691 TRACE("OLEIVERB_UIACTIVATE\n");
692 return activate_ui(This, pActiveSite);
693 case OLEIVERB_INPLACEACTIVATE:
694 TRACE("OLEIVERB_INPLACEACTIVATE\n");
695 return activate_inplace(This, pActiveSite);
696 case OLEIVERB_HIDE:
697 TRACE("OLEIVERB_HIDE\n");
698 if(This->inplace) {
699 deactivate_ui(This);
700 IOleInPlaceSiteEx_Release(This->inplace);
701 This->inplace = NULL;
703 if(This->shell_embedding_hwnd)
704 ShowWindow(This->shell_embedding_hwnd, SW_HIDE);
705 return S_OK;
706 default:
707 FIXME("stub for %ld\n", iVerb);
708 break;
711 return E_NOTIMPL;
714 static HRESULT WINAPI OleObject_EnumVerbs(IOleObject *iface, IEnumOLEVERB **ppEnumOleVerb)
716 WebBrowser *This = impl_from_IOleObject(iface);
717 EnumOLEVERB *ret;
719 TRACE("(%p)->(%p)\n", This, ppEnumOleVerb);
721 ret = malloc(sizeof(*ret));
722 if(!ret)
723 return E_OUTOFMEMORY;
725 ret->IEnumOLEVERB_iface.lpVtbl = &EnumOLEVERBVtbl;
726 ret->ref = 1;
727 ret->iter = 0;
729 *ppEnumOleVerb = &ret->IEnumOLEVERB_iface;
730 return S_OK;
733 static HRESULT WINAPI OleObject_Update(IOleObject *iface)
735 WebBrowser *This = impl_from_IOleObject(iface);
736 FIXME("(%p)\n", This);
737 return E_NOTIMPL;
740 static HRESULT WINAPI OleObject_IsUpToDate(IOleObject *iface)
742 WebBrowser *This = impl_from_IOleObject(iface);
743 FIXME("(%p)\n", This);
744 return E_NOTIMPL;
747 static HRESULT WINAPI OleObject_GetUserClassID(IOleObject *iface, CLSID *pClsid)
749 WebBrowser *This = impl_from_IOleObject(iface);
751 TRACE("(%p)->(%p)\n", This, pClsid);
753 *pClsid = This->version == 1 ? CLSID_WebBrowser_V1 : CLSID_WebBrowser;
754 return S_OK;
757 static HRESULT WINAPI OleObject_GetUserType(IOleObject *iface, DWORD dwFormOfType,
758 LPOLESTR* pszUserType)
760 WebBrowser *This = impl_from_IOleObject(iface);
761 TRACE("(%p, %ld, %p)\n", This, dwFormOfType, pszUserType);
762 return OleRegGetUserType(&CLSID_WebBrowser, dwFormOfType, pszUserType);
765 static HRESULT WINAPI OleObject_SetExtent(IOleObject *iface, DWORD dwDrawAspect, SIZEL *psizel)
767 WebBrowser *This = impl_from_IOleObject(iface);
769 TRACE("(%p)->(%lx %p)\n", This, dwDrawAspect, psizel);
771 /* Tests show that dwDrawAspect is ignored */
772 This->extent = *psizel;
773 return S_OK;
776 static HRESULT WINAPI OleObject_GetExtent(IOleObject *iface, DWORD dwDrawAspect, SIZEL *psizel)
778 WebBrowser *This = impl_from_IOleObject(iface);
780 TRACE("(%p)->(%lx, %p)\n", This, dwDrawAspect, psizel);
782 /* Tests show that dwDrawAspect is ignored */
783 *psizel = This->extent;
784 return S_OK;
787 static HRESULT WINAPI OleObject_Advise(IOleObject *iface, IAdviseSink *pAdvSink,
788 DWORD *pdwConnection)
790 WebBrowser *This = impl_from_IOleObject(iface);
791 HRESULT hr = S_OK;
793 TRACE("(%p)->(%p, %p)\n", This, pAdvSink, pdwConnection);
795 if(!pdwConnection)
796 return E_INVALIDARG;
798 *pdwConnection = 0;
800 if(!pAdvSink)
801 return E_INVALIDARG;
803 if(!This->advise_holder)
804 hr = CreateOleAdviseHolder(&This->advise_holder);
806 if(hr == S_OK)
807 hr = IOleAdviseHolder_Advise(This->advise_holder, pAdvSink, pdwConnection);
809 return hr;
812 static HRESULT WINAPI OleObject_Unadvise(IOleObject *iface, DWORD dwConnection)
814 WebBrowser *This = impl_from_IOleObject(iface);
816 TRACE("(%p)->(%ld)\n", This, dwConnection);
818 if(!This->advise_holder)
819 return OLE_E_NOCONNECTION;
821 return IOleAdviseHolder_Unadvise(This->advise_holder, dwConnection);
824 static HRESULT WINAPI OleObject_EnumAdvise(IOleObject *iface, IEnumSTATDATA **ppenumAdvise)
826 WebBrowser *This = impl_from_IOleObject(iface);
828 TRACE("(%p)->(%p): returning E_NOTIMPL\n", This, ppenumAdvise);
830 *ppenumAdvise = NULL;
831 return E_NOTIMPL;
834 static HRESULT WINAPI OleObject_GetMiscStatus(IOleObject *iface, DWORD dwAspect, DWORD *pdwStatus)
836 WebBrowser *This = impl_from_IOleObject(iface);
838 TRACE("(%p)->(%lx, %p)\n", This, dwAspect, pdwStatus);
840 *pdwStatus = OLEMISC_SETCLIENTSITEFIRST|OLEMISC_ACTIVATEWHENVISIBLE|OLEMISC_INSIDEOUT
841 |OLEMISC_CANTLINKINSIDE|OLEMISC_RECOMPOSEONRESIZE;
843 return S_OK;
846 static HRESULT WINAPI OleObject_SetColorScheme(IOleObject *iface, LOGPALETTE* pLogpal)
848 WebBrowser *This = impl_from_IOleObject(iface);
849 FIXME("(%p)->(%p)\n", This, pLogpal);
850 return E_NOTIMPL;
853 static const IOleObjectVtbl OleObjectVtbl =
855 OleObject_QueryInterface,
856 OleObject_AddRef,
857 OleObject_Release,
858 OleObject_SetClientSite,
859 OleObject_GetClientSite,
860 OleObject_SetHostNames,
861 OleObject_Close,
862 OleObject_SetMoniker,
863 OleObject_GetMoniker,
864 OleObject_InitFromData,
865 OleObject_GetClipboardData,
866 OleObject_DoVerb,
867 OleObject_EnumVerbs,
868 OleObject_Update,
869 OleObject_IsUpToDate,
870 OleObject_GetUserClassID,
871 OleObject_GetUserType,
872 OleObject_SetExtent,
873 OleObject_GetExtent,
874 OleObject_Advise,
875 OleObject_Unadvise,
876 OleObject_EnumAdvise,
877 OleObject_GetMiscStatus,
878 OleObject_SetColorScheme
881 /**********************************************************************
882 * Implement the IOleInPlaceObject interface
885 static inline WebBrowser *impl_from_IOleInPlaceObject(IOleInPlaceObject *iface)
887 return CONTAINING_RECORD(iface, WebBrowser, IOleInPlaceObject_iface);
890 static HRESULT WINAPI OleInPlaceObject_QueryInterface(IOleInPlaceObject *iface,
891 REFIID riid, LPVOID *ppobj)
893 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
894 return IUnknown_QueryInterface(This->hlink_frame.outer, riid, ppobj);
897 static ULONG WINAPI OleInPlaceObject_AddRef(IOleInPlaceObject *iface)
899 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
900 return IUnknown_AddRef(This->hlink_frame.outer);
903 static ULONG WINAPI OleInPlaceObject_Release(IOleInPlaceObject *iface)
905 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
906 return IUnknown_Release(This->hlink_frame.outer);
909 static HRESULT WINAPI OleInPlaceObject_GetWindow(IOleInPlaceObject *iface, HWND* phwnd)
911 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
913 TRACE("(%p)->(%p)\n", This, phwnd);
915 *phwnd = This->shell_embedding_hwnd;
916 return S_OK;
919 static HRESULT WINAPI OleInPlaceObject_ContextSensitiveHelp(IOleInPlaceObject *iface,
920 BOOL fEnterMode)
922 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
923 FIXME("(%p)->(%x)\n", This, fEnterMode);
924 return E_NOTIMPL;
927 static HRESULT WINAPI OleInPlaceObject_InPlaceDeactivate(IOleInPlaceObject *iface)
929 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
930 FIXME("(%p)\n", This);
932 if(This->inplace) {
933 IOleInPlaceSiteEx_Release(This->inplace);
934 This->inplace = NULL;
937 return S_OK;
940 static HRESULT WINAPI OleInPlaceObject_UIDeactivate(IOleInPlaceObject *iface)
942 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
943 FIXME("(%p)\n", This);
944 return E_NOTIMPL;
947 static HRESULT WINAPI OleInPlaceObject_SetObjectRects(IOleInPlaceObject *iface,
948 LPCRECT lprcPosRect, LPCRECT lprcClipRect)
950 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
952 TRACE("(%p)->(%s %s)\n", This, wine_dbgstr_rect(lprcPosRect), wine_dbgstr_rect(lprcClipRect));
954 This->pos_rect = *lprcPosRect;
956 if(lprcClipRect)
957 This->clip_rect = *lprcClipRect;
959 if(This->shell_embedding_hwnd) {
960 SetWindowPos(This->shell_embedding_hwnd, NULL,
961 lprcPosRect->left, lprcPosRect->top,
962 lprcPosRect->right-lprcPosRect->left,
963 lprcPosRect->bottom-lprcPosRect->top,
964 SWP_NOZORDER | SWP_NOACTIVATE);
967 return S_OK;
970 static HRESULT WINAPI OleInPlaceObject_ReactivateAndUndo(IOleInPlaceObject *iface)
972 WebBrowser *This = impl_from_IOleInPlaceObject(iface);
973 FIXME("(%p)\n", This);
974 return E_NOTIMPL;
977 static const IOleInPlaceObjectVtbl OleInPlaceObjectVtbl =
979 OleInPlaceObject_QueryInterface,
980 OleInPlaceObject_AddRef,
981 OleInPlaceObject_Release,
982 OleInPlaceObject_GetWindow,
983 OleInPlaceObject_ContextSensitiveHelp,
984 OleInPlaceObject_InPlaceDeactivate,
985 OleInPlaceObject_UIDeactivate,
986 OleInPlaceObject_SetObjectRects,
987 OleInPlaceObject_ReactivateAndUndo
990 /**********************************************************************
991 * Implement the IOleControl interface
994 static inline WebBrowser *impl_from_IOleControl(IOleControl *iface)
996 return CONTAINING_RECORD(iface, WebBrowser, IOleControl_iface);
999 static HRESULT WINAPI OleControl_QueryInterface(IOleControl *iface,
1000 REFIID riid, LPVOID *ppobj)
1002 WebBrowser *This = impl_from_IOleControl(iface);
1003 return IUnknown_QueryInterface(This->hlink_frame.outer, riid, ppobj);
1006 static ULONG WINAPI OleControl_AddRef(IOleControl *iface)
1008 WebBrowser *This = impl_from_IOleControl(iface);
1009 return IUnknown_AddRef(This->hlink_frame.outer);
1012 static ULONG WINAPI OleControl_Release(IOleControl *iface)
1014 WebBrowser *This = impl_from_IOleControl(iface);
1015 return IUnknown_Release(This->hlink_frame.outer);
1018 static HRESULT WINAPI OleControl_GetControlInfo(IOleControl *iface, LPCONTROLINFO pCI)
1020 WebBrowser *This = impl_from_IOleControl(iface);
1022 TRACE("(%p)->(%p)\n", This, pCI);
1024 /* Tests show that this function should be not implemented */
1025 return E_NOTIMPL;
1028 static HRESULT WINAPI OleControl_OnMnemonic(IOleControl *iface, struct tagMSG *pMsg)
1030 WebBrowser *This = impl_from_IOleControl(iface);
1031 FIXME("(%p)->(%p)\n", This, pMsg);
1032 return E_NOTIMPL;
1035 static HRESULT WINAPI OleControl_OnAmbientPropertyChange(IOleControl *iface, DISPID dispID)
1037 WebBrowser *This = impl_from_IOleControl(iface);
1039 TRACE("(%p)->(%ld)\n", This, dispID);
1041 switch(dispID) {
1042 case DISPID_UNKNOWN:
1043 /* Unknown means multiple properties changed, so check them all.
1044 * BUT the Webbrowser OleControl object doesn't appear to do this.
1046 return S_OK;
1047 case DISPID_AMBIENT_DLCONTROL:
1048 return S_OK;
1049 case DISPID_AMBIENT_OFFLINEIFNOTCONNECTED:
1050 return on_offlineconnected_change(This);
1051 case DISPID_AMBIENT_SILENT:
1052 return on_silent_change(This);
1055 FIXME("Unknown dispID %ld\n", dispID);
1056 return E_NOTIMPL;
1059 static HRESULT WINAPI OleControl_FreezeEvents(IOleControl *iface, BOOL bFreeze)
1061 WebBrowser *This = impl_from_IOleControl(iface);
1062 FIXME("(%p)->(%x)\n", This, bFreeze);
1063 return E_NOTIMPL;
1066 static const IOleControlVtbl OleControlVtbl =
1068 OleControl_QueryInterface,
1069 OleControl_AddRef,
1070 OleControl_Release,
1071 OleControl_GetControlInfo,
1072 OleControl_OnMnemonic,
1073 OleControl_OnAmbientPropertyChange,
1074 OleControl_FreezeEvents
1077 static inline WebBrowser *impl_from_IOleInPlaceActiveObject(IOleInPlaceActiveObject *iface)
1079 return CONTAINING_RECORD(iface, WebBrowser, IOleInPlaceActiveObject_iface);
1082 static HRESULT WINAPI InPlaceActiveObject_QueryInterface(IOleInPlaceActiveObject *iface,
1083 REFIID riid, void **ppv)
1085 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
1086 return IUnknown_QueryInterface(This->hlink_frame.outer, riid, ppv);
1089 static ULONG WINAPI InPlaceActiveObject_AddRef(IOleInPlaceActiveObject *iface)
1091 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
1092 return IUnknown_AddRef(This->hlink_frame.outer);
1095 static ULONG WINAPI InPlaceActiveObject_Release(IOleInPlaceActiveObject *iface)
1097 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
1098 return IUnknown_Release(This->hlink_frame.outer);
1101 static HRESULT WINAPI InPlaceActiveObject_GetWindow(IOleInPlaceActiveObject *iface,
1102 HWND *phwnd)
1104 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
1105 return IOleInPlaceObject_GetWindow(&This->IOleInPlaceObject_iface, phwnd);
1108 static HRESULT WINAPI InPlaceActiveObject_ContextSensitiveHelp(IOleInPlaceActiveObject *iface,
1109 BOOL fEnterMode)
1111 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
1112 return IOleInPlaceObject_ContextSensitiveHelp(&This->IOleInPlaceObject_iface, fEnterMode);
1115 static HRESULT WINAPI InPlaceActiveObject_TranslateAccelerator(IOleInPlaceActiveObject *iface,
1116 LPMSG lpmsg)
1118 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
1119 IOleInPlaceActiveObject *activeobj;
1120 HRESULT hr = S_FALSE;
1122 TRACE("(%p)->(%p)\n", This, lpmsg);
1124 if(This->doc_host.document) {
1125 if(SUCCEEDED(IUnknown_QueryInterface(This->doc_host.document,
1126 &IID_IOleInPlaceActiveObject,
1127 (void**)&activeobj))) {
1128 hr = IOleInPlaceActiveObject_TranslateAccelerator(activeobj, lpmsg);
1129 IOleInPlaceActiveObject_Release(activeobj);
1133 if(SUCCEEDED(hr))
1134 return hr;
1135 else
1136 return S_FALSE;
1139 static HRESULT WINAPI InPlaceActiveObject_OnFrameWindowActivate(IOleInPlaceActiveObject *iface,
1140 BOOL fActivate)
1142 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
1143 FIXME("(%p)->(%x)\n", This, fActivate);
1144 return E_NOTIMPL;
1147 static HRESULT WINAPI InPlaceActiveObject_OnDocWindowActivate(IOleInPlaceActiveObject *iface,
1148 BOOL fActivate)
1150 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
1151 FIXME("(%p)->(%x)\n", This, fActivate);
1152 return E_NOTIMPL;
1155 static HRESULT WINAPI InPlaceActiveObject_ResizeBorder(IOleInPlaceActiveObject *iface,
1156 LPCRECT lprcBorder, IOleInPlaceUIWindow *pUIWindow, BOOL fFrameWindow)
1158 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
1159 FIXME("(%p)->(%p %p %x)\n", This, lprcBorder, pUIWindow, fFrameWindow);
1160 return E_NOTIMPL;
1163 static HRESULT WINAPI InPlaceActiveObject_EnableModeless(IOleInPlaceActiveObject *iface,
1164 BOOL fEnable)
1166 WebBrowser *This = impl_from_IOleInPlaceActiveObject(iface);
1167 FIXME("(%p)->(%x)\n", This, fEnable);
1168 return E_NOTIMPL;
1171 static const IOleInPlaceActiveObjectVtbl OleInPlaceActiveObjectVtbl = {
1172 InPlaceActiveObject_QueryInterface,
1173 InPlaceActiveObject_AddRef,
1174 InPlaceActiveObject_Release,
1175 InPlaceActiveObject_GetWindow,
1176 InPlaceActiveObject_ContextSensitiveHelp,
1177 InPlaceActiveObject_TranslateAccelerator,
1178 InPlaceActiveObject_OnFrameWindowActivate,
1179 InPlaceActiveObject_OnDocWindowActivate,
1180 InPlaceActiveObject_ResizeBorder,
1181 InPlaceActiveObject_EnableModeless
1184 static inline WebBrowser *impl_from_IOleCommandTarget(IOleCommandTarget *iface)
1186 return CONTAINING_RECORD(iface, WebBrowser, IOleCommandTarget_iface);
1189 static HRESULT WINAPI WBOleCommandTarget_QueryInterface(IOleCommandTarget *iface,
1190 REFIID riid, void **ppv)
1192 WebBrowser *This = impl_from_IOleCommandTarget(iface);
1193 return IUnknown_QueryInterface(This->hlink_frame.outer, riid, ppv);
1196 static ULONG WINAPI WBOleCommandTarget_AddRef(IOleCommandTarget *iface)
1198 WebBrowser *This = impl_from_IOleCommandTarget(iface);
1199 return IUnknown_AddRef(This->hlink_frame.outer);
1202 static ULONG WINAPI WBOleCommandTarget_Release(IOleCommandTarget *iface)
1204 WebBrowser *This = impl_from_IOleCommandTarget(iface);
1205 return IUnknown_Release(This->hlink_frame.outer);
1208 static HRESULT WINAPI WBOleCommandTarget_QueryStatus(IOleCommandTarget *iface,
1209 const GUID *pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[], OLECMDTEXT *pCmdText)
1211 WebBrowser *This = impl_from_IOleCommandTarget(iface);
1212 IOleCommandTarget *cmdtrg;
1213 HRESULT hres;
1215 TRACE("(%p)->(%s %lu %p %p)\n", This, debugstr_guid(pguidCmdGroup), cCmds, prgCmds,
1216 pCmdText);
1218 if(!This->doc_host.document)
1219 return 0x80040104;
1221 /* NOTE: There are probably some commands that we should handle here
1222 * instead of forwarding to document object. */
1224 hres = IUnknown_QueryInterface(This->doc_host.document, &IID_IOleCommandTarget, (void**)&cmdtrg);
1225 if(FAILED(hres))
1226 return hres;
1228 hres = IOleCommandTarget_QueryStatus(cmdtrg, pguidCmdGroup, cCmds, prgCmds, pCmdText);
1229 IOleCommandTarget_Release(cmdtrg);
1231 return hres;
1234 static HRESULT WINAPI WBOleCommandTarget_Exec(IOleCommandTarget *iface,
1235 const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn,
1236 VARIANT *pvaOut)
1238 WebBrowser *This = impl_from_IOleCommandTarget(iface);
1239 FIXME("(%p)->(%s %ld %ld %s %p)\n", This, debugstr_guid(pguidCmdGroup), nCmdID,
1240 nCmdexecopt, debugstr_variant(pvaIn), pvaOut);
1241 return E_NOTIMPL;
1244 static const IOleCommandTargetVtbl OleCommandTargetVtbl = {
1245 WBOleCommandTarget_QueryInterface,
1246 WBOleCommandTarget_AddRef,
1247 WBOleCommandTarget_Release,
1248 WBOleCommandTarget_QueryStatus,
1249 WBOleCommandTarget_Exec
1252 void WebBrowser_OleObject_Init(WebBrowser *This)
1254 DWORD dpi_x;
1255 DWORD dpi_y;
1256 HDC hdc;
1258 /* default aspect ratio is 96dpi / 96dpi */
1259 hdc = GetDC(0);
1260 dpi_x = GetDeviceCaps(hdc, LOGPIXELSX);
1261 dpi_y = GetDeviceCaps(hdc, LOGPIXELSY);
1262 ReleaseDC(0, hdc);
1264 This->IOleObject_iface.lpVtbl = &OleObjectVtbl;
1265 This->IOleInPlaceObject_iface.lpVtbl = &OleInPlaceObjectVtbl;
1266 This->IOleControl_iface.lpVtbl = &OleControlVtbl;
1267 This->IOleInPlaceActiveObject_iface.lpVtbl = &OleInPlaceActiveObjectVtbl;
1268 This->IOleCommandTarget_iface.lpVtbl = &OleCommandTargetVtbl;
1270 /* Default size is 50x20 pixels, in himetric units */
1271 This->extent.cx = MulDiv( 50, 2540, dpi_x );
1272 This->extent.cy = MulDiv( 20, 2540, dpi_y );
1275 void WebBrowser_OleObject_Destroy(WebBrowser *This)
1277 release_client_site(This, TRUE);