Release 1.1.37.
[wine/gsoc-2012-control.git] / dlls / shdocvw / oleobject.c
blobdde850f08c7ba9cfc03fc6239178bea06b10e858
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 IOleContainer *container;
157 IOleClientSite_ShowObject(This->client);
159 hres = IOleClientSite_GetContainer(This->client, &container);
160 if(SUCCEEDED(hres)) {
161 if(This->container)
162 IOleContainer_Release(This->container);
163 This->container = container;
167 if(This->doc_host.frame)
168 IOleInPlaceFrame_GetWindow(This->doc_host.frame, &This->frame_hwnd);
170 return S_OK;
173 static HRESULT activate_ui(WebBrowser *This, IOleClientSite *active_site)
175 HRESULT hres;
177 static const WCHAR wszitem[] = {'i','t','e','m',0};
179 if(This->inplace)
181 if(This->shell_embedding_hwnd)
182 ShowWindow(This->shell_embedding_hwnd, SW_SHOW);
183 return S_OK;
186 hres = activate_inplace(This, active_site);
187 if(FAILED(hres))
188 return hres;
190 IOleInPlaceSite_OnUIActivate(This->inplace);
192 if(This->doc_host.frame)
193 IOleInPlaceFrame_SetActiveObject(This->doc_host.frame, ACTIVEOBJ(This), wszitem);
194 if(This->uiwindow)
195 IOleInPlaceUIWindow_SetActiveObject(This->uiwindow, ACTIVEOBJ(This), wszitem);
197 if(This->doc_host.frame)
198 IOleInPlaceFrame_SetMenu(This->doc_host.frame, NULL, NULL, This->shell_embedding_hwnd);
200 SetFocus(This->shell_embedding_hwnd);
202 return S_OK;
205 static HRESULT get_client_disp_property(IOleClientSite *client, DISPID dispid, VARIANT *res)
207 IDispatch *disp = NULL;
208 DISPPARAMS dispparams = {NULL, 0};
209 HRESULT hres;
211 VariantInit(res);
213 if(!client)
214 return S_OK;
216 hres = IOleClientSite_QueryInterface(client, &IID_IDispatch, (void**)&disp);
217 if(FAILED(hres)) {
218 TRACE("Could not get IDispatch\n");
219 return hres;
222 hres = IDispatch_Invoke(disp, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
223 DISPATCH_PROPERTYGET, &dispparams, res, NULL, NULL);
225 IDispatch_Release(disp);
227 return hres;
230 static HRESULT on_offlineconnected_change(WebBrowser *This)
232 VARIANT offline;
234 get_client_disp_property(This->client, DISPID_AMBIENT_OFFLINEIFNOTCONNECTED, &offline);
236 if(V_VT(&offline) == VT_BOOL)
237 IWebBrowser2_put_Offline(WEBBROWSER2(This), V_BOOL(&offline));
238 else if(V_VT(&offline) != VT_EMPTY)
239 WARN("wrong V_VT(silent) %d\n", V_VT(&offline));
241 return S_OK;
244 static HRESULT on_silent_change(WebBrowser *This)
246 VARIANT silent;
248 get_client_disp_property(This->client, DISPID_AMBIENT_SILENT, &silent);
250 if(V_VT(&silent) == VT_BOOL)
251 IWebBrowser2_put_Silent(WEBBROWSER2(This), V_BOOL(&silent));
252 else if(V_VT(&silent) != VT_EMPTY)
253 WARN("wrong V_VT(silent) %d\n", V_VT(&silent));
255 return S_OK;
258 /**********************************************************************
259 * Implement the IOleObject interface for the WebBrowser control
262 #define OLEOBJ_THIS(iface) DEFINE_THIS(WebBrowser, OleObject, iface)
264 static HRESULT WINAPI OleObject_QueryInterface(IOleObject *iface, REFIID riid, void **ppv)
266 WebBrowser *This = OLEOBJ_THIS(iface);
267 return IWebBrowser_QueryInterface(WEBBROWSER(This), riid, ppv);
270 static ULONG WINAPI OleObject_AddRef(IOleObject *iface)
272 WebBrowser *This = OLEOBJ_THIS(iface);
273 return IWebBrowser_AddRef(WEBBROWSER(This));
276 static ULONG WINAPI OleObject_Release(IOleObject *iface)
278 WebBrowser *This = OLEOBJ_THIS(iface);
279 return IWebBrowser_Release(WEBBROWSER(This));
282 static HRESULT WINAPI OleObject_SetClientSite(IOleObject *iface, LPOLECLIENTSITE pClientSite)
284 WebBrowser *This = OLEOBJ_THIS(iface);
285 IDocHostUIHandler *hostui;
286 IOleContainer *container;
287 IDispatch *disp;
288 HRESULT hres;
290 TRACE("(%p)->(%p)\n", This, pClientSite);
292 if(This->client == pClientSite)
293 return S_OK;
295 if(This->doc_host.hwnd) {
296 DestroyWindow(This->doc_host.hwnd);
297 This->doc_host.hwnd = NULL;
299 if(This->shell_embedding_hwnd) {
300 DestroyWindow(This->shell_embedding_hwnd);
301 This->shell_embedding_hwnd = NULL;
304 if(This->inplace) {
305 IOleInPlaceSite_Release(This->inplace);
306 This->inplace = NULL;
309 if(This->doc_host.hostui) {
310 IDocHostUIHandler_Release(This->doc_host.hostui);
311 This->doc_host.hostui = NULL;
314 if(This->client)
315 IOleClientSite_Release(This->client);
317 This->client = pClientSite;
319 if(!pClientSite) {
320 if(This->doc_host.document)
321 deactivate_document(&This->doc_host);
322 return S_OK;
325 IOleClientSite_AddRef(pClientSite);
327 hres = IOleClientSite_QueryInterface(This->client, &IID_IDispatch,
328 (void**)&disp);
329 if(SUCCEEDED(hres))
330 This->doc_host.client_disp = disp;
332 hres = IOleClientSite_QueryInterface(This->client, &IID_IDocHostUIHandler,
333 (void**)&hostui);
334 if(SUCCEEDED(hres))
335 This->doc_host.hostui = hostui;
337 hres = IOleClientSite_GetContainer(This->client, &container);
338 if(SUCCEEDED(hres)) {
339 ITargetContainer *target_container;
341 hres = IOleContainer_QueryInterface(container, &IID_ITargetContainer,
342 (void**)&target_container);
343 if(SUCCEEDED(hres)) {
344 FIXME("Unsupported ITargetContainer\n");
345 ITargetContainer_Release(target_container);
348 IOleContainer_Release(container);
351 create_shell_embedding_hwnd(This);
353 on_offlineconnected_change(This);
354 on_silent_change(This);
356 return S_OK;
359 static HRESULT WINAPI OleObject_GetClientSite(IOleObject *iface, LPOLECLIENTSITE *ppClientSite)
361 WebBrowser *This = OLEOBJ_THIS(iface);
363 TRACE("(%p)->(%p)\n", This, ppClientSite);
365 if(!ppClientSite)
366 return E_INVALIDARG;
368 if(This->client)
369 IOleClientSite_AddRef(This->client);
370 *ppClientSite = This->client;
372 return S_OK;
375 static HRESULT WINAPI OleObject_SetHostNames(IOleObject *iface, LPCOLESTR szContainerApp,
376 LPCOLESTR szContainerObj)
378 WebBrowser *This = OLEOBJ_THIS(iface);
380 TRACE("(%p)->(%s, %s)\n", This, debugstr_w(szContainerApp), debugstr_w(szContainerObj));
382 /* We have nothing to do here. */
383 return S_OK;
386 static HRESULT WINAPI OleObject_Close(IOleObject *iface, DWORD dwSaveOption)
388 WebBrowser *This = OLEOBJ_THIS(iface);
389 FIXME("(%p)->(%d)\n", This, dwSaveOption);
390 return E_NOTIMPL;
393 static HRESULT WINAPI OleObject_SetMoniker(IOleObject *iface, DWORD dwWhichMoniker, IMoniker* pmk)
395 WebBrowser *This = OLEOBJ_THIS(iface);
396 FIXME("(%p)->(%d, %p)\n", This, dwWhichMoniker, pmk);
397 return E_NOTIMPL;
400 static HRESULT WINAPI OleObject_GetMoniker(IOleObject *iface, DWORD dwAssign,
401 DWORD dwWhichMoniker, LPMONIKER *ppmk)
403 WebBrowser *This = OLEOBJ_THIS(iface);
404 FIXME("(%p)->(%d, %d, %p)\n", This, dwAssign, dwWhichMoniker, ppmk);
405 return E_NOTIMPL;
408 static HRESULT WINAPI OleObject_InitFromData(IOleObject *iface, LPDATAOBJECT pDataObject,
409 BOOL fCreation, DWORD dwReserved)
411 WebBrowser *This = OLEOBJ_THIS(iface);
412 FIXME("(%p)->(%p, %d, %d)\n", This, pDataObject, fCreation, dwReserved);
413 return E_NOTIMPL;
416 static HRESULT WINAPI OleObject_GetClipboardData(IOleObject *iface, DWORD dwReserved,
417 LPDATAOBJECT *ppDataObject)
419 WebBrowser *This = OLEOBJ_THIS(iface);
420 FIXME("(%p)->(%d, %p)\n", This, dwReserved, ppDataObject);
421 return E_NOTIMPL;
424 static HRESULT WINAPI OleObject_DoVerb(IOleObject *iface, LONG iVerb, struct tagMSG* lpmsg,
425 LPOLECLIENTSITE pActiveSite, LONG lindex, HWND hwndParent, LPCRECT lprcPosRect)
427 WebBrowser *This = OLEOBJ_THIS(iface);
429 TRACE("(%p)->(%d %p %p %d %p %p)\n", This, iVerb, lpmsg, pActiveSite, lindex, hwndParent,
430 lprcPosRect);
432 switch (iVerb)
434 case OLEIVERB_SHOW:
435 TRACE("OLEIVERB_SHOW\n");
436 return activate_ui(This, pActiveSite);
437 case OLEIVERB_UIACTIVATE:
438 TRACE("OLEIVERB_UIACTIVATE\n");
439 return activate_ui(This, pActiveSite);
440 case OLEIVERB_INPLACEACTIVATE:
441 TRACE("OLEIVERB_INPLACEACTIVATE\n");
442 return activate_inplace(This, pActiveSite);
443 case OLEIVERB_HIDE:
444 TRACE("OLEIVERB_HIDE\n");
445 if(This->shell_embedding_hwnd)
446 ShowWindow(This->shell_embedding_hwnd, SW_HIDE);
447 return S_OK;
448 default:
449 FIXME("stub for %d\n", iVerb);
450 break;
453 return E_NOTIMPL;
456 static HRESULT WINAPI OleObject_EnumVerbs(IOleObject *iface, IEnumOLEVERB **ppEnumOleVerb)
458 WebBrowser *This = OLEOBJ_THIS(iface);
459 TRACE("(%p)->(%p)\n", This, ppEnumOleVerb);
460 return OleRegEnumVerbs(&CLSID_WebBrowser, ppEnumOleVerb);
463 static HRESULT WINAPI OleObject_Update(IOleObject *iface)
465 WebBrowser *This = OLEOBJ_THIS(iface);
466 FIXME("(%p)\n", This);
467 return E_NOTIMPL;
470 static HRESULT WINAPI OleObject_IsUpToDate(IOleObject *iface)
472 WebBrowser *This = OLEOBJ_THIS(iface);
473 FIXME("(%p)\n", This);
474 return E_NOTIMPL;
477 static HRESULT WINAPI OleObject_GetUserClassID(IOleObject *iface, CLSID* pClsid)
479 WebBrowser *This = OLEOBJ_THIS(iface);
480 FIXME("(%p)->(%p)\n", This, pClsid);
481 return E_NOTIMPL;
484 static HRESULT WINAPI OleObject_GetUserType(IOleObject *iface, DWORD dwFormOfType,
485 LPOLESTR* pszUserType)
487 WebBrowser *This = OLEOBJ_THIS(iface);
488 TRACE("(%p, %d, %p)\n", This, dwFormOfType, pszUserType);
489 return OleRegGetUserType(&CLSID_WebBrowser, dwFormOfType, pszUserType);
492 static HRESULT WINAPI OleObject_SetExtent(IOleObject *iface, DWORD dwDrawAspect, SIZEL *psizel)
494 WebBrowser *This = OLEOBJ_THIS(iface);
496 TRACE("(%p)->(%x %p)\n", This, dwDrawAspect, psizel);
498 /* Tests show that dwDrawAspect is ignored */
499 This->extent = *psizel;
500 return S_OK;
503 static HRESULT WINAPI OleObject_GetExtent(IOleObject *iface, DWORD dwDrawAspect, SIZEL *psizel)
505 WebBrowser *This = OLEOBJ_THIS(iface);
507 TRACE("(%p)->(%x, %p)\n", This, dwDrawAspect, psizel);
509 /* Tests show that dwDrawAspect is ignored */
510 *psizel = This->extent;
511 return S_OK;
514 static HRESULT WINAPI OleObject_Advise(IOleObject *iface, IAdviseSink *pAdvSink,
515 DWORD* pdwConnection)
517 WebBrowser *This = OLEOBJ_THIS(iface);
518 FIXME("(%p)->(%p, %p)\n", This, pAdvSink, pdwConnection);
519 return E_NOTIMPL;
522 static HRESULT WINAPI OleObject_Unadvise(IOleObject *iface, DWORD dwConnection)
524 WebBrowser *This = OLEOBJ_THIS(iface);
525 FIXME("(%p)->(%d)\n", This, dwConnection);
526 return E_NOTIMPL;
529 static HRESULT WINAPI OleObject_EnumAdvise(IOleObject *iface, IEnumSTATDATA **ppenumAdvise)
531 WebBrowser *This = OLEOBJ_THIS(iface);
532 FIXME("(%p)->(%p)\n", This, ppenumAdvise);
533 return S_OK;
536 static HRESULT WINAPI OleObject_GetMiscStatus(IOleObject *iface, DWORD dwAspect, DWORD *pdwStatus)
538 WebBrowser *This = OLEOBJ_THIS(iface);
540 TRACE("(%p)->(%x, %p)\n", This, dwAspect, pdwStatus);
542 *pdwStatus = OLEMISC_SETCLIENTSITEFIRST|OLEMISC_ACTIVATEWHENVISIBLE|OLEMISC_INSIDEOUT
543 |OLEMISC_CANTLINKINSIDE|OLEMISC_RECOMPOSEONRESIZE;
545 return S_OK;
548 static HRESULT WINAPI OleObject_SetColorScheme(IOleObject *iface, LOGPALETTE* pLogpal)
550 WebBrowser *This = OLEOBJ_THIS(iface);
551 FIXME("(%p)->(%p)\n", This, pLogpal);
552 return E_NOTIMPL;
555 #undef OLEOBJ_THIS
557 static const IOleObjectVtbl OleObjectVtbl =
559 OleObject_QueryInterface,
560 OleObject_AddRef,
561 OleObject_Release,
562 OleObject_SetClientSite,
563 OleObject_GetClientSite,
564 OleObject_SetHostNames,
565 OleObject_Close,
566 OleObject_SetMoniker,
567 OleObject_GetMoniker,
568 OleObject_InitFromData,
569 OleObject_GetClipboardData,
570 OleObject_DoVerb,
571 OleObject_EnumVerbs,
572 OleObject_Update,
573 OleObject_IsUpToDate,
574 OleObject_GetUserClassID,
575 OleObject_GetUserType,
576 OleObject_SetExtent,
577 OleObject_GetExtent,
578 OleObject_Advise,
579 OleObject_Unadvise,
580 OleObject_EnumAdvise,
581 OleObject_GetMiscStatus,
582 OleObject_SetColorScheme
585 /**********************************************************************
586 * Implement the IOleInPlaceObject interface
589 #define INPLACEOBJ_THIS(iface) DEFINE_THIS(WebBrowser, OleInPlaceObject, iface)
591 static HRESULT WINAPI OleInPlaceObject_QueryInterface(IOleInPlaceObject *iface,
592 REFIID riid, LPVOID *ppobj)
594 WebBrowser *This = INPLACEOBJ_THIS(iface);
595 return IWebBrowser_QueryInterface(WEBBROWSER(This), riid, ppobj);
598 static ULONG WINAPI OleInPlaceObject_AddRef(IOleInPlaceObject *iface)
600 WebBrowser *This = INPLACEOBJ_THIS(iface);
601 return IWebBrowser_AddRef(WEBBROWSER(This));
604 static ULONG WINAPI OleInPlaceObject_Release(IOleInPlaceObject *iface)
606 WebBrowser *This = INPLACEOBJ_THIS(iface);
607 return IWebBrowser_Release(WEBBROWSER(This));
610 static HRESULT WINAPI OleInPlaceObject_GetWindow(IOleInPlaceObject *iface, HWND* phwnd)
612 WebBrowser *This = INPLACEOBJ_THIS(iface);
614 TRACE("(%p)->(%p)\n", This, phwnd);
616 *phwnd = This->shell_embedding_hwnd;
617 return S_OK;
620 static HRESULT WINAPI OleInPlaceObject_ContextSensitiveHelp(IOleInPlaceObject *iface,
621 BOOL fEnterMode)
623 WebBrowser *This = INPLACEOBJ_THIS(iface);
624 FIXME("(%p)->(%x)\n", This, fEnterMode);
625 return E_NOTIMPL;
628 static HRESULT WINAPI OleInPlaceObject_InPlaceDeactivate(IOleInPlaceObject *iface)
630 WebBrowser *This = INPLACEOBJ_THIS(iface);
631 FIXME("(%p)\n", This);
633 if(This->inplace) {
634 IOleInPlaceSite_Release(This->inplace);
635 This->inplace = NULL;
638 return S_OK;
641 static HRESULT WINAPI OleInPlaceObject_UIDeactivate(IOleInPlaceObject *iface)
643 WebBrowser *This = INPLACEOBJ_THIS(iface);
644 FIXME("(%p)\n", This);
645 return E_NOTIMPL;
648 static HRESULT WINAPI OleInPlaceObject_SetObjectRects(IOleInPlaceObject *iface,
649 LPCRECT lprcPosRect, LPCRECT lprcClipRect)
651 WebBrowser *This = INPLACEOBJ_THIS(iface);
653 TRACE("(%p)->(%p %p)\n", This, lprcPosRect, lprcClipRect);
655 This->pos_rect = *lprcPosRect;
657 if(lprcClipRect)
658 This->clip_rect = *lprcClipRect;
660 if(This->shell_embedding_hwnd) {
661 SetWindowPos(This->shell_embedding_hwnd, NULL,
662 lprcPosRect->left, lprcPosRect->top,
663 lprcPosRect->right-lprcPosRect->left,
664 lprcPosRect->bottom-lprcPosRect->top,
665 SWP_NOZORDER | SWP_NOACTIVATE);
668 return S_OK;
671 static HRESULT WINAPI OleInPlaceObject_ReactivateAndUndo(IOleInPlaceObject *iface)
673 WebBrowser *This = INPLACEOBJ_THIS(iface);
674 FIXME("(%p)\n", This);
675 return E_NOTIMPL;
678 #undef INPLACEOBJ_THIS
680 static const IOleInPlaceObjectVtbl OleInPlaceObjectVtbl =
682 OleInPlaceObject_QueryInterface,
683 OleInPlaceObject_AddRef,
684 OleInPlaceObject_Release,
685 OleInPlaceObject_GetWindow,
686 OleInPlaceObject_ContextSensitiveHelp,
687 OleInPlaceObject_InPlaceDeactivate,
688 OleInPlaceObject_UIDeactivate,
689 OleInPlaceObject_SetObjectRects,
690 OleInPlaceObject_ReactivateAndUndo
693 /**********************************************************************
694 * Implement the IOleControl interface
697 #define CONTROL_THIS(iface) DEFINE_THIS(WebBrowser, OleControl, iface)
699 static HRESULT WINAPI OleControl_QueryInterface(IOleControl *iface,
700 REFIID riid, LPVOID *ppobj)
702 WebBrowser *This = CONTROL_THIS(iface);
703 return IWebBrowser_QueryInterface(WEBBROWSER(This), riid, ppobj);
706 static ULONG WINAPI OleControl_AddRef(IOleControl *iface)
708 WebBrowser *This = CONTROL_THIS(iface);
709 return IWebBrowser_AddRef(WEBBROWSER(This));
712 static ULONG WINAPI OleControl_Release(IOleControl *iface)
714 WebBrowser *This = CONTROL_THIS(iface);
715 return IWebBrowser_Release(WEBBROWSER(This));
718 static HRESULT WINAPI OleControl_GetControlInfo(IOleControl *iface, LPCONTROLINFO pCI)
720 WebBrowser *This = CONTROL_THIS(iface);
722 TRACE("(%p)->(%p)\n", This, pCI);
724 /* Tests show that this function should be not implemented */
725 return E_NOTIMPL;
728 static HRESULT WINAPI OleControl_OnMnemonic(IOleControl *iface, struct tagMSG *pMsg)
730 WebBrowser *This = CONTROL_THIS(iface);
731 FIXME("(%p)->(%p)\n", This, pMsg);
732 return E_NOTIMPL;
735 static HRESULT WINAPI OleControl_OnAmbientPropertyChange(IOleControl *iface, DISPID dispID)
737 WebBrowser *This = CONTROL_THIS(iface);
739 TRACE("(%p)->(%d)\n", This, dispID);
741 switch(dispID) {
742 case DISPID_UNKNOWN:
743 /* Unknown means multiple properties changed, so check them all.
744 * BUT the Webbrowser OleControl object doesn't appear to do this.
746 return S_OK;
747 case DISPID_AMBIENT_DLCONTROL:
748 return S_OK;
749 case DISPID_AMBIENT_OFFLINEIFNOTCONNECTED:
750 return on_offlineconnected_change(This);
751 case DISPID_AMBIENT_SILENT:
752 return on_silent_change(This);
755 FIXME("Unknown dispID %d\n", dispID);
756 return E_NOTIMPL;
759 static HRESULT WINAPI OleControl_FreezeEvents(IOleControl *iface, BOOL bFreeze)
761 WebBrowser *This = CONTROL_THIS(iface);
762 FIXME("(%p)->(%x)\n", This, bFreeze);
763 return E_NOTIMPL;
766 #undef CONTROL_THIS
768 static const IOleControlVtbl OleControlVtbl =
770 OleControl_QueryInterface,
771 OleControl_AddRef,
772 OleControl_Release,
773 OleControl_GetControlInfo,
774 OleControl_OnMnemonic,
775 OleControl_OnAmbientPropertyChange,
776 OleControl_FreezeEvents
779 #define ACTIVEOBJ_THIS(iface) DEFINE_THIS(WebBrowser, OleInPlaceActiveObject, iface)
781 static HRESULT WINAPI InPlaceActiveObject_QueryInterface(IOleInPlaceActiveObject *iface,
782 REFIID riid, void **ppv)
784 WebBrowser *This = ACTIVEOBJ_THIS(iface);
785 return IWebBrowser2_QueryInterface(WEBBROWSER2(This), riid, ppv);
788 static ULONG WINAPI InPlaceActiveObject_AddRef(IOleInPlaceActiveObject *iface)
790 WebBrowser *This = ACTIVEOBJ_THIS(iface);
791 return IWebBrowser2_AddRef(WEBBROWSER2(This));
794 static ULONG WINAPI InPlaceActiveObject_Release(IOleInPlaceActiveObject *iface)
796 WebBrowser *This = ACTIVEOBJ_THIS(iface);
797 return IWebBrowser2_Release(WEBBROWSER2(This));
800 static HRESULT WINAPI InPlaceActiveObject_GetWindow(IOleInPlaceActiveObject *iface,
801 HWND *phwnd)
803 WebBrowser *This = ACTIVEOBJ_THIS(iface);
804 return IOleInPlaceObject_GetWindow(INPLACEOBJ(This), phwnd);
807 static HRESULT WINAPI InPlaceActiveObject_ContextSensitiveHelp(IOleInPlaceActiveObject *iface,
808 BOOL fEnterMode)
810 WebBrowser *This = ACTIVEOBJ_THIS(iface);
811 return IOleInPlaceObject_ContextSensitiveHelp(INPLACEOBJ(This), fEnterMode);
814 static HRESULT WINAPI InPlaceActiveObject_TranslateAccelerator(IOleInPlaceActiveObject *iface,
815 LPMSG lpmsg)
817 WebBrowser *This = ACTIVEOBJ_THIS(iface);
818 FIXME("(%p)->(%p)\n", This, lpmsg);
819 return E_NOTIMPL;
822 static HRESULT WINAPI InPlaceActiveObject_OnFrameWindowActivate(IOleInPlaceActiveObject *iface,
823 BOOL fActivate)
825 WebBrowser *This = ACTIVEOBJ_THIS(iface);
826 FIXME("(%p)->(%x)\n", This, fActivate);
827 return E_NOTIMPL;
830 static HRESULT WINAPI InPlaceActiveObject_OnDocWindowActivate(IOleInPlaceActiveObject *iface,
831 BOOL fActivate)
833 WebBrowser *This = ACTIVEOBJ_THIS(iface);
834 FIXME("(%p)->(%x)\n", This, fActivate);
835 return E_NOTIMPL;
838 static HRESULT WINAPI InPlaceActiveObject_ResizeBorder(IOleInPlaceActiveObject *iface,
839 LPCRECT lprcBorder, IOleInPlaceUIWindow *pUIWindow, BOOL fFrameWindow)
841 WebBrowser *This = ACTIVEOBJ_THIS(iface);
842 FIXME("(%p)->(%p %p %x)\n", This, lprcBorder, pUIWindow, fFrameWindow);
843 return E_NOTIMPL;
846 static HRESULT WINAPI InPlaceActiveObject_EnableModeless(IOleInPlaceActiveObject *iface,
847 BOOL fEnable)
849 WebBrowser *This = ACTIVEOBJ_THIS(iface);
850 FIXME("(%p)->(%x)\n", This, fEnable);
851 return E_NOTIMPL;
854 #undef ACTIVEOBJ_THIS
856 static const IOleInPlaceActiveObjectVtbl OleInPlaceActiveObjectVtbl = {
857 InPlaceActiveObject_QueryInterface,
858 InPlaceActiveObject_AddRef,
859 InPlaceActiveObject_Release,
860 InPlaceActiveObject_GetWindow,
861 InPlaceActiveObject_ContextSensitiveHelp,
862 InPlaceActiveObject_TranslateAccelerator,
863 InPlaceActiveObject_OnFrameWindowActivate,
864 InPlaceActiveObject_OnDocWindowActivate,
865 InPlaceActiveObject_ResizeBorder,
866 InPlaceActiveObject_EnableModeless
869 #define OLECMD_THIS(iface) DEFINE_THIS(WebBrowser, OleCommandTarget, iface)
871 static HRESULT WINAPI WBOleCommandTarget_QueryInterface(IOleCommandTarget *iface,
872 REFIID riid, void **ppv)
874 WebBrowser *This = OLECMD_THIS(iface);
875 return IWebBrowser2_QueryInterface(WEBBROWSER(This), riid, ppv);
878 static ULONG WINAPI WBOleCommandTarget_AddRef(IOleCommandTarget *iface)
880 WebBrowser *This = OLECMD_THIS(iface);
881 return IWebBrowser2_AddRef(WEBBROWSER(This));
884 static ULONG WINAPI WBOleCommandTarget_Release(IOleCommandTarget *iface)
886 WebBrowser *This = OLECMD_THIS(iface);
887 return IWebBrowser2_Release(WEBBROWSER(This));
890 static HRESULT WINAPI WBOleCommandTarget_QueryStatus(IOleCommandTarget *iface,
891 const GUID *pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[], OLECMDTEXT *pCmdText)
893 WebBrowser *This = OLECMD_THIS(iface);
894 IOleCommandTarget *cmdtrg;
895 HRESULT hres;
897 TRACE("(%p)->(%s %u %p %p)\n", This, debugstr_guid(pguidCmdGroup), cCmds, prgCmds,
898 pCmdText);
900 if(!This->doc_host.document)
901 return 0x80040104;
903 /* NOTE: There are probably some commands that we should handle here
904 * instead of forwarding to document object. */
906 hres = IUnknown_QueryInterface(This->doc_host.document, &IID_IOleCommandTarget, (void**)&cmdtrg);
907 if(FAILED(hres))
908 return hres;
910 hres = IOleCommandTarget_QueryStatus(cmdtrg, pguidCmdGroup, cCmds, prgCmds, pCmdText);
911 IOleCommandTarget_Release(cmdtrg);
913 return hres;
916 static HRESULT WINAPI WBOleCommandTarget_Exec(IOleCommandTarget *iface,
917 const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn,
918 VARIANT *pvaOut)
920 WebBrowser *This = OLECMD_THIS(iface);
921 FIXME("(%p)->(%s %d %d %p %p)\n", This, debugstr_guid(pguidCmdGroup), nCmdID,
922 nCmdexecopt, pvaIn, pvaOut);
923 return E_NOTIMPL;
926 #undef OLECMD_THIS
928 static const IOleCommandTargetVtbl OleCommandTargetVtbl = {
929 WBOleCommandTarget_QueryInterface,
930 WBOleCommandTarget_AddRef,
931 WBOleCommandTarget_Release,
932 WBOleCommandTarget_QueryStatus,
933 WBOleCommandTarget_Exec
936 void WebBrowser_OleObject_Init(WebBrowser *This)
938 DWORD dpi_x;
939 DWORD dpi_y;
940 HDC hdc;
942 /* default aspect ratio is 96dpi / 96dpi */
943 hdc = GetDC(0);
944 dpi_x = GetDeviceCaps(hdc, LOGPIXELSX);
945 dpi_y = GetDeviceCaps(hdc, LOGPIXELSY);
946 ReleaseDC(0, hdc);
948 This->lpOleObjectVtbl = &OleObjectVtbl;
949 This->lpOleInPlaceObjectVtbl = &OleInPlaceObjectVtbl;
950 This->lpOleControlVtbl = &OleControlVtbl;
951 This->lpOleInPlaceActiveObjectVtbl = &OleInPlaceActiveObjectVtbl;
952 This->lpOleCommandTargetVtbl = &OleCommandTargetVtbl;
954 This->client = NULL;
955 This->inplace = NULL;
956 This->container = NULL;
957 This->frame_hwnd = NULL;
958 This->uiwindow = NULL;
959 This->shell_embedding_hwnd = NULL;
961 memset(&This->pos_rect, 0, sizeof(RECT));
962 memset(&This->clip_rect, 0, sizeof(RECT));
963 memset(&This->frameinfo, 0, sizeof(OLEINPLACEFRAMEINFO));
965 /* Default size is 50x20 pixels, in himetric units */
966 This->extent.cx = MulDiv( 50, 2540, dpi_x );
967 This->extent.cy = MulDiv( 20, 2540, dpi_y );
970 void WebBrowser_OleObject_Destroy(WebBrowser *This)
972 if(This->client)
973 IOleObject_SetClientSite(OLEOBJ(This), NULL);
974 if(This->container)
975 IOleContainer_Release(This->container);
976 if(This->uiwindow)
977 IOleInPlaceUIWindow_Release(This->uiwindow);