push(f) 25359c458b329fe03f66bef506b8062c200b9eb4
[wine/hacks.git] / dlls / shdocvw / oleobject.c
blob017e738e1ad3d9dda79e2e9697d680b7a4c248d9
1 /*
2 * Implementation of IOleObject interfaces for WebBrowser control
4 * - IOleObject
5 * - IOleInPlaceObject
6 * - IOleControl
8 * Copyright 2001 John R. Sheets (for CodeWeavers)
9 * Copyright 2005 Jacek Caban
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include <string.h>
27 #include "wine/debug.h"
28 #include "shdocvw.h"
29 #include "htiframe.h"
30 #include "idispids.h"
31 #include "mshtmdid.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(shdocvw);
35 /* shlwapi.dll */
36 HWND WINAPI SHSetParentHwnd(HWND hWnd, HWND hWndParent);
38 static ATOM shell_embedding_atom = 0;
40 static LRESULT resize_window(WebBrowser *This, LONG width, LONG height)
42 if(This->doc_host.hwnd)
43 SetWindowPos(This->doc_host.hwnd, NULL, 0, 0, width, height,
44 SWP_NOZORDER | SWP_NOACTIVATE);
46 return 0;
49 static LRESULT WINAPI shell_embedding_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
51 WebBrowser *This;
53 static const WCHAR wszTHIS[] = {'T','H','I','S',0};
55 if(msg == WM_CREATE) {
56 This = *(WebBrowser**)lParam;
57 SetPropW(hwnd, wszTHIS, This);
58 }else {
59 This = GetPropW(hwnd, wszTHIS);
62 switch(msg) {
63 case WM_SIZE:
64 return resize_window(This, LOWORD(lParam), HIWORD(lParam));
65 case WM_DOCHOSTTASK:
66 return process_dochost_task(&This->doc_host, lParam);
69 return DefWindowProcW(hwnd, msg, wParam, lParam);
72 static void create_shell_embedding_hwnd(WebBrowser *This)
74 IOleInPlaceSite *inplace;
75 HWND parent = NULL;
76 HRESULT hres;
78 static const WCHAR wszShellEmbedding[] =
79 {'S','h','e','l','l',' ','E','m','b','e','d','d','i','n','g',0};
81 if(!shell_embedding_atom) {
82 static WNDCLASSEXW wndclass = {
83 sizeof(wndclass),
84 CS_DBLCLKS,
85 shell_embedding_proc,
86 0, 0 /* native uses 8 */, NULL, NULL, NULL,
87 (HBRUSH)(COLOR_WINDOW + 1), NULL,
88 wszShellEmbedding,
89 NULL
91 wndclass.hInstance = shdocvw_hinstance;
93 RegisterClassExW(&wndclass);
96 hres = IOleClientSite_QueryInterface(This->client, &IID_IOleInPlaceSite, (void**)&inplace);
97 if(SUCCEEDED(hres)) {
98 IOleInPlaceSite_GetWindow(inplace, &parent);
99 IOleInPlaceSite_Release(inplace);
102 This->doc_host.frame_hwnd = This->shell_embedding_hwnd = CreateWindowExW(
103 WS_EX_WINDOWEDGE,
104 wszShellEmbedding, wszShellEmbedding,
105 WS_CLIPSIBLINGS | WS_CLIPCHILDREN
106 | (parent ? WS_CHILD | WS_TABSTOP : WS_POPUP | WS_MAXIMIZEBOX),
107 0, 0, 0, 0, parent,
108 NULL, shdocvw_hinstance, This);
110 TRACE("parent=%p hwnd=%p\n", parent, This->shell_embedding_hwnd);
113 static HRESULT activate_inplace(WebBrowser *This, IOleClientSite *active_site)
115 HWND parent_hwnd;
116 HRESULT hres;
118 if(This->inplace)
119 return S_OK;
121 if(!active_site)
122 return E_INVALIDARG;
124 hres = IOleClientSite_QueryInterface(active_site, &IID_IOleInPlaceSite,
125 (void**)&This->inplace);
126 if(FAILED(hres)) {
127 WARN("Could not get IOleInPlaceSite\n");
128 return hres;
131 hres = IOleInPlaceSite_CanInPlaceActivate(This->inplace);
132 if(hres != S_OK) {
133 WARN("CanInPlaceActivate returned: %08x\n", hres);
134 IOleInPlaceSite_Release(This->inplace);
135 return E_FAIL;
138 hres = IOleInPlaceSite_GetWindow(This->inplace, &parent_hwnd);
139 if(SUCCEEDED(hres))
140 SHSetParentHwnd(This->shell_embedding_hwnd, parent_hwnd);
142 IOleInPlaceSite_OnInPlaceActivate(This->inplace);
144 IOleInPlaceSite_GetWindowContext(This->inplace, &This->doc_host.frame, &This->uiwindow,
145 &This->pos_rect, &This->clip_rect,
146 &This->frameinfo);
148 SetWindowPos(This->shell_embedding_hwnd, NULL,
149 This->pos_rect.left, This->pos_rect.top,
150 This->pos_rect.right-This->pos_rect.left,
151 This->pos_rect.bottom-This->pos_rect.top,
152 SWP_NOZORDER | SWP_SHOWWINDOW);
154 if(This->client) {
155 IOleClientSite_ShowObject(This->client);
156 IOleClientSite_GetContainer(This->client, &This->container);
159 if(This->doc_host.frame)
160 IOleInPlaceFrame_GetWindow(This->doc_host.frame, &This->frame_hwnd);
162 return S_OK;
165 static HRESULT activate_ui(WebBrowser *This, IOleClientSite *active_site)
167 HRESULT hres;
169 static const WCHAR wszitem[] = {'i','t','e','m',0};
171 if(This->inplace)
173 if(This->shell_embedding_hwnd)
174 ShowWindow(This->shell_embedding_hwnd, SW_SHOW);
175 return S_OK;
178 hres = activate_inplace(This, active_site);
179 if(FAILED(hres))
180 return hres;
182 IOleInPlaceSite_OnUIActivate(This->inplace);
184 if(This->doc_host.frame)
185 IOleInPlaceFrame_SetActiveObject(This->doc_host.frame, ACTIVEOBJ(This), wszitem);
186 if(This->uiwindow)
187 IOleInPlaceUIWindow_SetActiveObject(This->uiwindow, ACTIVEOBJ(This), wszitem);
189 if(This->doc_host.frame)
190 IOleInPlaceFrame_SetMenu(This->doc_host.frame, NULL, NULL, This->shell_embedding_hwnd);
192 SetFocus(This->shell_embedding_hwnd);
194 return S_OK;
197 static HRESULT get_client_disp_property(IOleClientSite *client, DISPID dispid, VARIANT *res)
199 IDispatch *disp = NULL;
200 DISPPARAMS dispparams = {NULL, 0};
201 HRESULT hres;
203 VariantInit(res);
205 if(!client)
206 return S_OK;
208 hres = IOleClientSite_QueryInterface(client, &IID_IDispatch, (void**)&disp);
209 if(FAILED(hres)) {
210 TRACE("Could not get IDispatch\n");
211 return hres;
214 hres = IDispatch_Invoke(disp, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
215 DISPATCH_PROPERTYGET, &dispparams, res, NULL, NULL);
217 IDispatch_Release(disp);
219 return hres;
222 static HRESULT on_offlineconnected_change(WebBrowser *This)
224 VARIANT offline;
226 get_client_disp_property(This->client, DISPID_AMBIENT_OFFLINEIFNOTCONNECTED, &offline);
228 if(V_VT(&offline) == VT_BOOL)
229 IWebBrowser2_put_Offline(WEBBROWSER2(This), V_BOOL(&offline));
230 else if(V_VT(&offline) != VT_EMPTY)
231 WARN("wrong V_VT(silent) %d\n", V_VT(&offline));
233 return S_OK;
236 static HRESULT on_silent_change(WebBrowser *This)
238 VARIANT silent;
240 get_client_disp_property(This->client, DISPID_AMBIENT_SILENT, &silent);
242 if(V_VT(&silent) == VT_BOOL)
243 IWebBrowser2_put_Silent(WEBBROWSER2(This), V_BOOL(&silent));
244 else if(V_VT(&silent) != VT_EMPTY)
245 WARN("wrong V_VT(silent) %d\n", V_VT(&silent));
247 return S_OK;
250 /**********************************************************************
251 * Implement the IOleObject interface for the WebBrowser control
254 #define OLEOBJ_THIS(iface) DEFINE_THIS(WebBrowser, OleObject, iface)
256 static HRESULT WINAPI OleObject_QueryInterface(IOleObject *iface, REFIID riid, void **ppv)
258 WebBrowser *This = OLEOBJ_THIS(iface);
259 return IWebBrowser_QueryInterface(WEBBROWSER(This), riid, ppv);
262 static ULONG WINAPI OleObject_AddRef(IOleObject *iface)
264 WebBrowser *This = OLEOBJ_THIS(iface);
265 return IWebBrowser_AddRef(WEBBROWSER(This));
268 static ULONG WINAPI OleObject_Release(IOleObject *iface)
270 WebBrowser *This = OLEOBJ_THIS(iface);
271 return IWebBrowser_Release(WEBBROWSER(This));
274 static HRESULT WINAPI OleObject_SetClientSite(IOleObject *iface, LPOLECLIENTSITE pClientSite)
276 WebBrowser *This = OLEOBJ_THIS(iface);
277 IOleContainer *container;
278 HRESULT hres;
280 TRACE("(%p)->(%p)\n", This, pClientSite);
282 if(This->client == pClientSite)
283 return S_OK;
285 if(This->doc_host.hwnd) {
286 DestroyWindow(This->doc_host.hwnd);
287 This->doc_host.hwnd = NULL;
289 if(This->shell_embedding_hwnd) {
290 DestroyWindow(This->shell_embedding_hwnd);
291 This->shell_embedding_hwnd = NULL;
294 if(This->inplace) {
295 IOleInPlaceSite_Release(This->inplace);
296 This->inplace = NULL;
299 if(This->doc_host.hostui) {
300 IDocHostUIHandler_Release(This->doc_host.hostui);
301 This->doc_host.hostui = NULL;
304 if(This->client)
305 IOleClientSite_Release(This->client);
307 This->client = pClientSite;
309 if(!pClientSite) {
310 if(This->doc_host.document)
311 deactivate_document(&This->doc_host);
312 return S_OK;
315 IOleClientSite_AddRef(pClientSite);
317 IOleClientSite_QueryInterface(This->client, &IID_IDispatch,
318 (void**)&This->doc_host.client_disp);
320 IOleClientSite_QueryInterface(This->client, &IID_IDocHostUIHandler,
321 (void**)&This->doc_host.hostui);
323 hres = IOleClientSite_GetContainer(This->client, &container);
324 if(SUCCEEDED(hres)) {
325 ITargetContainer *target_container;
327 hres = IOleContainer_QueryInterface(container, &IID_ITargetContainer,
328 (void**)&target_container);
329 if(SUCCEEDED(hres)) {
330 FIXME("Unsupported ITargetContainer\n");
331 ITargetContainer_Release(target_container);
334 IOleContainer_Release(container);
337 create_shell_embedding_hwnd(This);
339 on_offlineconnected_change(This);
340 on_silent_change(This);
342 return S_OK;
345 static HRESULT WINAPI OleObject_GetClientSite(IOleObject *iface, LPOLECLIENTSITE *ppClientSite)
347 WebBrowser *This = OLEOBJ_THIS(iface);
349 TRACE("(%p)->(%p)\n", This, ppClientSite);
351 if(!ppClientSite)
352 return E_INVALIDARG;
354 if(This->client)
355 IOleClientSite_AddRef(This->client);
356 *ppClientSite = This->client;
358 return S_OK;
361 static HRESULT WINAPI OleObject_SetHostNames(IOleObject *iface, LPCOLESTR szContainerApp,
362 LPCOLESTR szContainerObj)
364 WebBrowser *This = OLEOBJ_THIS(iface);
366 TRACE("(%p)->(%s, %s)\n", This, debugstr_w(szContainerApp), debugstr_w(szContainerObj));
368 /* We have nothing to do here. */
369 return S_OK;
372 static HRESULT WINAPI OleObject_Close(IOleObject *iface, DWORD dwSaveOption)
374 WebBrowser *This = OLEOBJ_THIS(iface);
375 FIXME("(%p)->(%d)\n", This, dwSaveOption);
376 return E_NOTIMPL;
379 static HRESULT WINAPI OleObject_SetMoniker(IOleObject *iface, DWORD dwWhichMoniker, IMoniker* pmk)
381 WebBrowser *This = OLEOBJ_THIS(iface);
382 FIXME("(%p)->(%d, %p)\n", This, dwWhichMoniker, pmk);
383 return E_NOTIMPL;
386 static HRESULT WINAPI OleObject_GetMoniker(IOleObject *iface, DWORD dwAssign,
387 DWORD dwWhichMoniker, LPMONIKER *ppmk)
389 WebBrowser *This = OLEOBJ_THIS(iface);
390 FIXME("(%p)->(%d, %d, %p)\n", This, dwAssign, dwWhichMoniker, ppmk);
391 return E_NOTIMPL;
394 static HRESULT WINAPI OleObject_InitFromData(IOleObject *iface, LPDATAOBJECT pDataObject,
395 BOOL fCreation, DWORD dwReserved)
397 WebBrowser *This = OLEOBJ_THIS(iface);
398 FIXME("(%p)->(%p, %d, %d)\n", This, pDataObject, fCreation, dwReserved);
399 return E_NOTIMPL;
402 static HRESULT WINAPI OleObject_GetClipboardData(IOleObject *iface, DWORD dwReserved,
403 LPDATAOBJECT *ppDataObject)
405 WebBrowser *This = OLEOBJ_THIS(iface);
406 FIXME("(%p)->(%d, %p)\n", This, dwReserved, ppDataObject);
407 return E_NOTIMPL;
410 static HRESULT WINAPI OleObject_DoVerb(IOleObject *iface, LONG iVerb, struct tagMSG* lpmsg,
411 LPOLECLIENTSITE pActiveSite, LONG lindex, HWND hwndParent, LPCRECT lprcPosRect)
413 WebBrowser *This = OLEOBJ_THIS(iface);
415 TRACE("(%p)->(%d %p %p %d %p %p)\n", This, iVerb, lpmsg, pActiveSite, lindex, hwndParent,
416 lprcPosRect);
418 switch (iVerb)
420 case OLEIVERB_SHOW:
421 TRACE("OLEIVERB_SHOW\n");
422 return activate_ui(This, pActiveSite);
423 case OLEIVERB_UIACTIVATE:
424 TRACE("OLEIVERB_UIACTIVATE\n");
425 return activate_ui(This, pActiveSite);
426 case OLEIVERB_INPLACEACTIVATE:
427 TRACE("OLEIVERB_INPLACEACTIVATE\n");
428 return activate_inplace(This, pActiveSite);
429 case OLEIVERB_HIDE:
430 TRACE("OLEIVERB_HIDE\n");
431 if(This->shell_embedding_hwnd)
432 ShowWindow(This->shell_embedding_hwnd, SW_HIDE);
433 return S_OK;
434 default:
435 FIXME("stub for %d\n", iVerb);
436 break;
439 return E_NOTIMPL;
442 static HRESULT WINAPI OleObject_EnumVerbs(IOleObject *iface, IEnumOLEVERB **ppEnumOleVerb)
444 WebBrowser *This = OLEOBJ_THIS(iface);
445 TRACE("(%p)->(%p)\n", This, ppEnumOleVerb);
446 return OleRegEnumVerbs(&CLSID_WebBrowser, ppEnumOleVerb);
449 static HRESULT WINAPI OleObject_Update(IOleObject *iface)
451 WebBrowser *This = OLEOBJ_THIS(iface);
452 FIXME("(%p)\n", This);
453 return E_NOTIMPL;
456 static HRESULT WINAPI OleObject_IsUpToDate(IOleObject *iface)
458 WebBrowser *This = OLEOBJ_THIS(iface);
459 FIXME("(%p)\n", This);
460 return E_NOTIMPL;
463 static HRESULT WINAPI OleObject_GetUserClassID(IOleObject *iface, CLSID* pClsid)
465 WebBrowser *This = OLEOBJ_THIS(iface);
466 FIXME("(%p)->(%p)\n", This, pClsid);
467 return E_NOTIMPL;
470 static HRESULT WINAPI OleObject_GetUserType(IOleObject *iface, DWORD dwFormOfType,
471 LPOLESTR* pszUserType)
473 WebBrowser *This = OLEOBJ_THIS(iface);
474 TRACE("(%p, %d, %p)\n", This, dwFormOfType, pszUserType);
475 return OleRegGetUserType(&CLSID_WebBrowser, dwFormOfType, pszUserType);
478 static HRESULT WINAPI OleObject_SetExtent(IOleObject *iface, DWORD dwDrawAspect, SIZEL *psizel)
480 WebBrowser *This = OLEOBJ_THIS(iface);
482 TRACE("(%p)->(%x %p)\n", This, dwDrawAspect, psizel);
484 /* Tests show that dwDrawAspect is ignored */
485 This->extent = *psizel;
486 return S_OK;
489 static HRESULT WINAPI OleObject_GetExtent(IOleObject *iface, DWORD dwDrawAspect, SIZEL *psizel)
491 WebBrowser *This = OLEOBJ_THIS(iface);
493 TRACE("(%p)->(%x, %p)\n", This, dwDrawAspect, psizel);
495 /* Tests show that dwDrawAspect is ignored */
496 *psizel = This->extent;
497 return S_OK;
500 static HRESULT WINAPI OleObject_Advise(IOleObject *iface, IAdviseSink *pAdvSink,
501 DWORD* pdwConnection)
503 WebBrowser *This = OLEOBJ_THIS(iface);
504 FIXME("(%p)->(%p, %p)\n", This, pAdvSink, pdwConnection);
505 return E_NOTIMPL;
508 static HRESULT WINAPI OleObject_Unadvise(IOleObject *iface, DWORD dwConnection)
510 WebBrowser *This = OLEOBJ_THIS(iface);
511 FIXME("(%p)->(%d)\n", This, dwConnection);
512 return E_NOTIMPL;
515 static HRESULT WINAPI OleObject_EnumAdvise(IOleObject *iface, IEnumSTATDATA **ppenumAdvise)
517 WebBrowser *This = OLEOBJ_THIS(iface);
518 FIXME("(%p)->(%p)\n", This, ppenumAdvise);
519 return S_OK;
522 static HRESULT WINAPI OleObject_GetMiscStatus(IOleObject *iface, DWORD dwAspect, DWORD *pdwStatus)
524 WebBrowser *This = OLEOBJ_THIS(iface);
526 TRACE("(%p)->(%x, %p)\n", This, dwAspect, pdwStatus);
528 *pdwStatus = OLEMISC_SETCLIENTSITEFIRST|OLEMISC_ACTIVATEWHENVISIBLE|OLEMISC_INSIDEOUT
529 |OLEMISC_CANTLINKINSIDE|OLEMISC_RECOMPOSEONRESIZE;
531 return S_OK;
534 static HRESULT WINAPI OleObject_SetColorScheme(IOleObject *iface, LOGPALETTE* pLogpal)
536 WebBrowser *This = OLEOBJ_THIS(iface);
537 FIXME("(%p)->(%p)\n", This, pLogpal);
538 return E_NOTIMPL;
541 #undef OLEOBJ_THIS
543 static const IOleObjectVtbl OleObjectVtbl =
545 OleObject_QueryInterface,
546 OleObject_AddRef,
547 OleObject_Release,
548 OleObject_SetClientSite,
549 OleObject_GetClientSite,
550 OleObject_SetHostNames,
551 OleObject_Close,
552 OleObject_SetMoniker,
553 OleObject_GetMoniker,
554 OleObject_InitFromData,
555 OleObject_GetClipboardData,
556 OleObject_DoVerb,
557 OleObject_EnumVerbs,
558 OleObject_Update,
559 OleObject_IsUpToDate,
560 OleObject_GetUserClassID,
561 OleObject_GetUserType,
562 OleObject_SetExtent,
563 OleObject_GetExtent,
564 OleObject_Advise,
565 OleObject_Unadvise,
566 OleObject_EnumAdvise,
567 OleObject_GetMiscStatus,
568 OleObject_SetColorScheme
571 /**********************************************************************
572 * Implement the IOleInPlaceObject interface
575 #define INPLACEOBJ_THIS(iface) DEFINE_THIS(WebBrowser, OleInPlaceObject, iface)
577 static HRESULT WINAPI OleInPlaceObject_QueryInterface(IOleInPlaceObject *iface,
578 REFIID riid, LPVOID *ppobj)
580 WebBrowser *This = INPLACEOBJ_THIS(iface);
581 return IWebBrowser_QueryInterface(WEBBROWSER(This), riid, ppobj);
584 static ULONG WINAPI OleInPlaceObject_AddRef(IOleInPlaceObject *iface)
586 WebBrowser *This = INPLACEOBJ_THIS(iface);
587 return IWebBrowser_AddRef(WEBBROWSER(This));
590 static ULONG WINAPI OleInPlaceObject_Release(IOleInPlaceObject *iface)
592 WebBrowser *This = INPLACEOBJ_THIS(iface);
593 return IWebBrowser_Release(WEBBROWSER(This));
596 static HRESULT WINAPI OleInPlaceObject_GetWindow(IOleInPlaceObject *iface, HWND* phwnd)
598 WebBrowser *This = INPLACEOBJ_THIS(iface);
600 TRACE("(%p)->(%p)\n", This, phwnd);
602 *phwnd = This->shell_embedding_hwnd;
603 return S_OK;
606 static HRESULT WINAPI OleInPlaceObject_ContextSensitiveHelp(IOleInPlaceObject *iface,
607 BOOL fEnterMode)
609 WebBrowser *This = INPLACEOBJ_THIS(iface);
610 FIXME("(%p)->(%x)\n", This, fEnterMode);
611 return E_NOTIMPL;
614 static HRESULT WINAPI OleInPlaceObject_InPlaceDeactivate(IOleInPlaceObject *iface)
616 WebBrowser *This = INPLACEOBJ_THIS(iface);
617 FIXME("(%p)\n", This);
618 return E_NOTIMPL;
621 static HRESULT WINAPI OleInPlaceObject_UIDeactivate(IOleInPlaceObject *iface)
623 WebBrowser *This = INPLACEOBJ_THIS(iface);
624 FIXME("(%p)\n", This);
625 return E_NOTIMPL;
628 static HRESULT WINAPI OleInPlaceObject_SetObjectRects(IOleInPlaceObject *iface,
629 LPCRECT lprcPosRect, LPCRECT lprcClipRect)
631 WebBrowser *This = INPLACEOBJ_THIS(iface);
633 TRACE("(%p)->(%p %p)\n", This, lprcPosRect, lprcClipRect);
635 This->pos_rect = *lprcPosRect;
637 if(lprcClipRect)
638 This->clip_rect = *lprcClipRect;
640 if(This->shell_embedding_hwnd) {
641 SetWindowPos(This->shell_embedding_hwnd, NULL,
642 lprcPosRect->left, lprcPosRect->top,
643 lprcPosRect->right-lprcPosRect->left,
644 lprcPosRect->bottom-lprcPosRect->top,
645 SWP_NOZORDER | SWP_NOACTIVATE);
648 return S_OK;
651 static HRESULT WINAPI OleInPlaceObject_ReactivateAndUndo(IOleInPlaceObject *iface)
653 WebBrowser *This = INPLACEOBJ_THIS(iface);
654 FIXME("(%p)\n", This);
655 return E_NOTIMPL;
658 #undef INPLACEOBJ_THIS
660 static const IOleInPlaceObjectVtbl OleInPlaceObjectVtbl =
662 OleInPlaceObject_QueryInterface,
663 OleInPlaceObject_AddRef,
664 OleInPlaceObject_Release,
665 OleInPlaceObject_GetWindow,
666 OleInPlaceObject_ContextSensitiveHelp,
667 OleInPlaceObject_InPlaceDeactivate,
668 OleInPlaceObject_UIDeactivate,
669 OleInPlaceObject_SetObjectRects,
670 OleInPlaceObject_ReactivateAndUndo
673 /**********************************************************************
674 * Implement the IOleControl interface
677 #define CONTROL_THIS(iface) DEFINE_THIS(WebBrowser, OleControl, iface)
679 static HRESULT WINAPI OleControl_QueryInterface(IOleControl *iface,
680 REFIID riid, LPVOID *ppobj)
682 WebBrowser *This = CONTROL_THIS(iface);
683 return IWebBrowser_QueryInterface(WEBBROWSER(This), riid, ppobj);
686 static ULONG WINAPI OleControl_AddRef(IOleControl *iface)
688 WebBrowser *This = CONTROL_THIS(iface);
689 return IWebBrowser_AddRef(WEBBROWSER(This));
692 static ULONG WINAPI OleControl_Release(IOleControl *iface)
694 WebBrowser *This = CONTROL_THIS(iface);
695 return IWebBrowser_Release(WEBBROWSER(This));
698 static HRESULT WINAPI OleControl_GetControlInfo(IOleControl *iface, LPCONTROLINFO pCI)
700 WebBrowser *This = CONTROL_THIS(iface);
702 TRACE("(%p)->(%p)\n", This, pCI);
704 /* Tests show that this function should be not implemented */
705 return E_NOTIMPL;
708 static HRESULT WINAPI OleControl_OnMnemonic(IOleControl *iface, struct tagMSG *pMsg)
710 WebBrowser *This = CONTROL_THIS(iface);
711 FIXME("(%p)->(%p)\n", This, pMsg);
712 return E_NOTIMPL;
715 static HRESULT WINAPI OleControl_OnAmbientPropertyChange(IOleControl *iface, DISPID dispID)
717 WebBrowser *This = CONTROL_THIS(iface);
719 TRACE("(%p)->(%d)\n", This, dispID);
721 switch(dispID) {
722 case DISPID_UNKNOWN:
723 /* Unknown means multiple properties changed, so check them all.
724 * BUT the Webbrowser OleControl object doesn't appear to do this.
726 return S_OK;
727 case DISPID_AMBIENT_DLCONTROL:
728 return S_OK;
729 case DISPID_AMBIENT_OFFLINEIFNOTCONNECTED:
730 return on_offlineconnected_change(This);
731 case DISPID_AMBIENT_SILENT:
732 return on_silent_change(This);
735 FIXME("Unknown dispID %d\n", dispID);
736 return E_NOTIMPL;
739 static HRESULT WINAPI OleControl_FreezeEvents(IOleControl *iface, BOOL bFreeze)
741 WebBrowser *This = CONTROL_THIS(iface);
742 FIXME("(%p)->(%x)\n", This, bFreeze);
743 return E_NOTIMPL;
746 #undef CONTROL_THIS
748 static const IOleControlVtbl OleControlVtbl =
750 OleControl_QueryInterface,
751 OleControl_AddRef,
752 OleControl_Release,
753 OleControl_GetControlInfo,
754 OleControl_OnMnemonic,
755 OleControl_OnAmbientPropertyChange,
756 OleControl_FreezeEvents
759 #define ACTIVEOBJ_THIS(iface) DEFINE_THIS(WebBrowser, OleInPlaceActiveObject, iface)
761 static HRESULT WINAPI InPlaceActiveObject_QueryInterface(IOleInPlaceActiveObject *iface,
762 REFIID riid, void **ppv)
764 WebBrowser *This = ACTIVEOBJ_THIS(iface);
765 return IWebBrowser2_QueryInterface(WEBBROWSER2(This), riid, ppv);
768 static ULONG WINAPI InPlaceActiveObject_AddRef(IOleInPlaceActiveObject *iface)
770 WebBrowser *This = ACTIVEOBJ_THIS(iface);
771 return IWebBrowser2_AddRef(WEBBROWSER2(This));
774 static ULONG WINAPI InPlaceActiveObject_Release(IOleInPlaceActiveObject *iface)
776 WebBrowser *This = ACTIVEOBJ_THIS(iface);
777 return IWebBrowser2_Release(WEBBROWSER2(This));
780 static HRESULT WINAPI InPlaceActiveObject_GetWindow(IOleInPlaceActiveObject *iface,
781 HWND *phwnd)
783 WebBrowser *This = ACTIVEOBJ_THIS(iface);
784 return IOleInPlaceObject_GetWindow(INPLACEOBJ(This), phwnd);
787 static HRESULT WINAPI InPlaceActiveObject_ContextSensitiveHelp(IOleInPlaceActiveObject *iface,
788 BOOL fEnterMode)
790 WebBrowser *This = ACTIVEOBJ_THIS(iface);
791 return IOleInPlaceObject_ContextSensitiveHelp(INPLACEOBJ(This), fEnterMode);
794 static HRESULT WINAPI InPlaceActiveObject_TranslateAccelerator(IOleInPlaceActiveObject *iface,
795 LPMSG lpmsg)
797 WebBrowser *This = ACTIVEOBJ_THIS(iface);
798 FIXME("(%p)->(%p)\n", This, lpmsg);
799 return E_NOTIMPL;
802 static HRESULT WINAPI InPlaceActiveObject_OnFrameWindowActivate(IOleInPlaceActiveObject *iface,
803 BOOL fActivate)
805 WebBrowser *This = ACTIVEOBJ_THIS(iface);
806 FIXME("(%p)->(%x)\n", This, fActivate);
807 return E_NOTIMPL;
810 static HRESULT WINAPI InPlaceActiveObject_OnDocWindowActivate(IOleInPlaceActiveObject *iface,
811 BOOL fActivate)
813 WebBrowser *This = ACTIVEOBJ_THIS(iface);
814 FIXME("(%p)->(%x)\n", This, fActivate);
815 return E_NOTIMPL;
818 static HRESULT WINAPI InPlaceActiveObject_ResizeBorder(IOleInPlaceActiveObject *iface,
819 LPCRECT lprcBorder, IOleInPlaceUIWindow *pUIWindow, BOOL fFrameWindow)
821 WebBrowser *This = ACTIVEOBJ_THIS(iface);
822 FIXME("(%p)->(%p %p %x)\n", This, lprcBorder, pUIWindow, fFrameWindow);
823 return E_NOTIMPL;
826 static HRESULT WINAPI InPlaceActiveObject_EnableModeless(IOleInPlaceActiveObject *iface,
827 BOOL fEnable)
829 WebBrowser *This = ACTIVEOBJ_THIS(iface);
830 FIXME("(%p)->(%x)\n", This, fEnable);
831 return E_NOTIMPL;
834 #undef ACTIVEOBJ_THIS
836 static const IOleInPlaceActiveObjectVtbl OleInPlaceActiveObjectVtbl = {
837 InPlaceActiveObject_QueryInterface,
838 InPlaceActiveObject_AddRef,
839 InPlaceActiveObject_Release,
840 InPlaceActiveObject_GetWindow,
841 InPlaceActiveObject_ContextSensitiveHelp,
842 InPlaceActiveObject_TranslateAccelerator,
843 InPlaceActiveObject_OnFrameWindowActivate,
844 InPlaceActiveObject_OnDocWindowActivate,
845 InPlaceActiveObject_ResizeBorder,
846 InPlaceActiveObject_EnableModeless
849 #define OLECMD_THIS(iface) DEFINE_THIS(WebBrowser, OleCommandTarget, iface)
851 static HRESULT WINAPI WBOleCommandTarget_QueryInterface(IOleCommandTarget *iface,
852 REFIID riid, void **ppv)
854 WebBrowser *This = OLECMD_THIS(iface);
855 return IWebBrowser2_QueryInterface(WEBBROWSER(This), riid, ppv);
858 static ULONG WINAPI WBOleCommandTarget_AddRef(IOleCommandTarget *iface)
860 WebBrowser *This = OLECMD_THIS(iface);
861 return IWebBrowser2_AddRef(WEBBROWSER(This));
864 static ULONG WINAPI WBOleCommandTarget_Release(IOleCommandTarget *iface)
866 WebBrowser *This = OLECMD_THIS(iface);
867 return IWebBrowser2_Release(WEBBROWSER(This));
870 static HRESULT WINAPI WBOleCommandTarget_QueryStatus(IOleCommandTarget *iface,
871 const GUID *pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[], OLECMDTEXT *pCmdText)
873 WebBrowser *This = OLECMD_THIS(iface);
874 IOleCommandTarget *cmdtrg;
875 HRESULT hres;
877 TRACE("(%p)->(%s %u %p %p)\n", This, debugstr_guid(pguidCmdGroup), cCmds, prgCmds,
878 pCmdText);
880 if(!This->doc_host.document)
881 return 0x80040104;
883 /* NOTE: There are probably some commands that we should handle here
884 * instead of forwarding to document object. */
886 hres = IUnknown_QueryInterface(This->doc_host.document, &IID_IOleCommandTarget, (void**)&cmdtrg);
887 if(FAILED(hres))
888 return hres;
890 hres = IOleCommandTarget_QueryStatus(cmdtrg, pguidCmdGroup, cCmds, prgCmds, pCmdText);
891 IOleCommandTarget_Release(cmdtrg);
893 return hres;
896 static HRESULT WINAPI WBOleCommandTarget_Exec(IOleCommandTarget *iface,
897 const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn,
898 VARIANT *pvaOut)
900 WebBrowser *This = OLECMD_THIS(iface);
901 FIXME("(%p)->(%s %d %d %p %p)\n", This, debugstr_guid(pguidCmdGroup), nCmdID,
902 nCmdexecopt, pvaIn, pvaOut);
903 return E_NOTIMPL;
906 #undef OLECMD_THIS
908 static const IOleCommandTargetVtbl OleCommandTargetVtbl = {
909 WBOleCommandTarget_QueryInterface,
910 WBOleCommandTarget_AddRef,
911 WBOleCommandTarget_Release,
912 WBOleCommandTarget_QueryStatus,
913 WBOleCommandTarget_Exec
916 void WebBrowser_OleObject_Init(WebBrowser *This)
918 DWORD dpi_x;
919 DWORD dpi_y;
920 HDC hdc;
922 /* default aspect ratio is 96dpi / 96dpi */
923 hdc = GetDC(0);
924 dpi_x = GetDeviceCaps(hdc, LOGPIXELSX);
925 dpi_y = GetDeviceCaps(hdc, LOGPIXELSY);
926 ReleaseDC(0, hdc);
928 This->lpOleObjectVtbl = &OleObjectVtbl;
929 This->lpOleInPlaceObjectVtbl = &OleInPlaceObjectVtbl;
930 This->lpOleControlVtbl = &OleControlVtbl;
931 This->lpOleInPlaceActiveObjectVtbl = &OleInPlaceActiveObjectVtbl;
932 This->lpOleCommandTargetVtbl = &OleCommandTargetVtbl;
934 This->client = NULL;
935 This->inplace = NULL;
936 This->container = NULL;
937 This->frame_hwnd = NULL;
938 This->uiwindow = NULL;
939 This->shell_embedding_hwnd = NULL;
941 memset(&This->pos_rect, 0, sizeof(RECT));
942 memset(&This->clip_rect, 0, sizeof(RECT));
943 memset(&This->frameinfo, 0, sizeof(OLEINPLACEFRAMEINFO));
945 /* Default size is 50x20 pixels, in himetric units */
946 This->extent.cx = MulDiv( 50, 2540, dpi_x );
947 This->extent.cy = MulDiv( 20, 2540, dpi_y );
950 void WebBrowser_OleObject_Destroy(WebBrowser *This)
952 if(This->client)
953 IOleObject_SetClientSite(OLEOBJ(This), NULL);
954 if(This->container)
955 IOleContainer_Release(This->container);
956 if(This->uiwindow)
957 IOleInPlaceUIWindow_Release(This->uiwindow);