2 * WebBrowser Implementation
4 * Copyright 2005 James Hawkins
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #define ICOM_THIS_MULTI(impl,field,iface) impl* const This=(impl*)((char*)(iface) - offsetof(impl,field))
25 typedef struct IOleClientSiteImpl
27 const IOleClientSiteVtbl *lpVtbl;
28 const IOleInPlaceSiteVtbl *lpvtblOleInPlaceSite;
29 const IOleInPlaceFrameVtbl *lpvtblOleInPlaceFrame;
30 const IDocHostUIHandlerVtbl *lpvtblDocHostUIHandler;
32 /* IOleClientSiteImpl data */
33 IOleObject *pBrowserObject;
36 /* IOleInPlaceFrame data */
40 static HRESULT STDMETHODCALLTYPE Site_QueryInterface(IOleClientSite *iface, REFIID riid, void **ppvObj)
42 ICOM_THIS_MULTI(IOleClientSiteImpl, lpVtbl, iface);
45 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IOleClientSite))
49 else if (IsEqualIID(riid, &IID_IOleInPlaceSite))
51 *ppvObj = &(This->lpvtblOleInPlaceSite);
53 else if (IsEqualIID(riid, &IID_IDocHostUIHandler))
55 *ppvObj = &(This->lpvtblDocHostUIHandler);
63 static ULONG STDMETHODCALLTYPE Site_AddRef(IOleClientSite *iface)
65 ICOM_THIS_MULTI(IOleClientSiteImpl, lpVtbl, iface);
66 return InterlockedIncrement(&This->ref);
69 static ULONG STDMETHODCALLTYPE Site_Release(IOleClientSite *iface)
71 ICOM_THIS_MULTI(IOleClientSiteImpl, lpVtbl, iface);
72 LONG refCount = InterlockedDecrement(&This->ref);
81 static HRESULT STDMETHODCALLTYPE Site_SaveObject(IOleClientSite *iface)
86 static HRESULT STDMETHODCALLTYPE Site_GetMoniker(IOleClientSite *iface, DWORD dwAssign, DWORD dwWhichMoniker, IMoniker **ppmk)
91 static HRESULT STDMETHODCALLTYPE Site_GetContainer(IOleClientSite *iface, LPOLECONTAINER *ppContainer)
98 static HRESULT STDMETHODCALLTYPE Site_ShowObject(IOleClientSite *iface)
103 static HRESULT STDMETHODCALLTYPE Site_OnShowWindow(IOleClientSite *iface, BOOL fShow)
108 static HRESULT STDMETHODCALLTYPE Site_RequestNewObjectLayout(IOleClientSite *iface)
113 static const IOleClientSiteVtbl MyIOleClientSiteTable =
123 Site_RequestNewObjectLayout
126 static HRESULT STDMETHODCALLTYPE UI_QueryInterface(IDocHostUIHandler *iface, REFIID riid, LPVOID *ppvObj)
128 ICOM_THIS_MULTI(IOleClientSiteImpl, lpvtblDocHostUIHandler, iface);
129 return Site_QueryInterface((IOleClientSite *)This, riid, ppvObj);
132 static ULONG STDMETHODCALLTYPE UI_AddRef(IDocHostUIHandler *iface)
137 static ULONG STDMETHODCALLTYPE UI_Release(IDocHostUIHandler * iface)
142 static HRESULT STDMETHODCALLTYPE UI_ShowContextMenu(IDocHostUIHandler *iface, DWORD dwID, POINT *ppt, IUnknown *pcmdtReserved, IDispatch *pdispReserved)
147 static HRESULT STDMETHODCALLTYPE UI_GetHostInfo(IDocHostUIHandler *iface, DOCHOSTUIINFO *pInfo)
149 pInfo->cbSize = sizeof(DOCHOSTUIINFO);
150 pInfo->dwFlags = DOCHOSTUIFLAG_NO3DBORDER;
151 pInfo->dwDoubleClick = DOCHOSTUIDBLCLK_DEFAULT;
156 static HRESULT STDMETHODCALLTYPE UI_ShowUI(IDocHostUIHandler *iface, DWORD dwID, IOleInPlaceActiveObject *pActiveObject, IOleCommandTarget *pCommandTarget, IOleInPlaceFrame *pFrame, IOleInPlaceUIWindow *pDoc)
161 static HRESULT STDMETHODCALLTYPE UI_HideUI(IDocHostUIHandler *iface)
166 static HRESULT STDMETHODCALLTYPE UI_UpdateUI(IDocHostUIHandler *iface)
171 static HRESULT STDMETHODCALLTYPE UI_EnableModeless(IDocHostUIHandler *iface, BOOL fEnable)
176 static HRESULT STDMETHODCALLTYPE UI_OnDocWindowActivate(IDocHostUIHandler *iface, BOOL fActivate)
181 static HRESULT STDMETHODCALLTYPE UI_OnFrameWindowActivate(IDocHostUIHandler *iface, BOOL fActivate)
186 static HRESULT STDMETHODCALLTYPE UI_ResizeBorder(IDocHostUIHandler *iface, LPCRECT prcBorder, IOleInPlaceUIWindow *pUIWindow, BOOL fRameWindow)
191 static HRESULT STDMETHODCALLTYPE UI_TranslateAccelerator(IDocHostUIHandler *iface, LPMSG lpMsg, const GUID *pguidCmdGroup, DWORD nCmdID)
196 static HRESULT STDMETHODCALLTYPE UI_GetOptionKeyPath(IDocHostUIHandler *iface, LPOLESTR *pchKey, DWORD dw)
201 static HRESULT STDMETHODCALLTYPE UI_GetDropTarget(IDocHostUIHandler *iface, IDropTarget *pDropTarget, IDropTarget **ppDropTarget)
206 static HRESULT STDMETHODCALLTYPE UI_GetExternal(IDocHostUIHandler *iface, IDispatch **ppDispatch)
212 static HRESULT STDMETHODCALLTYPE UI_TranslateUrl(IDocHostUIHandler *iface, DWORD dwTranslate, OLECHAR *pchURLIn, OLECHAR **ppchURLOut)
218 static HRESULT STDMETHODCALLTYPE UI_FilterDataObject(IDocHostUIHandler *iface, IDataObject *pDO, IDataObject **ppDORet)
224 static const IDocHostUIHandlerVtbl MyIDocHostUIHandlerTable =
235 UI_OnDocWindowActivate,
236 UI_OnFrameWindowActivate,
238 UI_TranslateAccelerator,
246 static HRESULT STDMETHODCALLTYPE InPlace_QueryInterface(IOleInPlaceSite *iface, REFIID riid, LPVOID *ppvObj)
248 ICOM_THIS_MULTI(IOleClientSiteImpl, lpvtblOleInPlaceSite, iface);
249 return Site_QueryInterface((IOleClientSite *)This, riid, ppvObj);
252 static ULONG STDMETHODCALLTYPE InPlace_AddRef(IOleInPlaceSite *iface)
257 static ULONG STDMETHODCALLTYPE InPlace_Release(IOleInPlaceSite *iface)
262 static HRESULT STDMETHODCALLTYPE InPlace_GetWindow(IOleInPlaceSite *iface, HWND *lphwnd)
264 ICOM_THIS_MULTI(IOleClientSiteImpl, lpvtblOleInPlaceSite, iface);
265 *lphwnd = This->hwndWindow;
270 static HRESULT STDMETHODCALLTYPE InPlace_ContextSensitiveHelp(IOleInPlaceSite *iface, BOOL fEnterMode)
275 static HRESULT STDMETHODCALLTYPE InPlace_CanInPlaceActivate(IOleInPlaceSite *iface)
280 static HRESULT STDMETHODCALLTYPE InPlace_OnInPlaceActivate(IOleInPlaceSite *iface)
285 static HRESULT STDMETHODCALLTYPE InPlace_OnUIActivate(IOleInPlaceSite *iface)
290 static HRESULT STDMETHODCALLTYPE InPlace_GetWindowContext(IOleInPlaceSite *iface, LPOLEINPLACEFRAME *lplpFrame, LPOLEINPLACEUIWINDOW *lplpDoc, LPRECT lprcPosRect, LPRECT lprcClipRect, LPOLEINPLACEFRAMEINFO lpFrameInfo)
292 ICOM_THIS_MULTI(IOleClientSiteImpl, lpvtblOleInPlaceSite, iface);
293 *lplpFrame = (LPOLEINPLACEFRAME)&This->lpvtblOleInPlaceFrame;
296 lpFrameInfo->fMDIApp = FALSE;
297 lpFrameInfo->hwndFrame = This->hwndWindow;
298 lpFrameInfo->haccel = NULL;
299 lpFrameInfo->cAccelEntries = 0;
304 static HRESULT STDMETHODCALLTYPE InPlace_Scroll(IOleInPlaceSite *iface, SIZE scrollExtent)
309 static HRESULT STDMETHODCALLTYPE InPlace_OnUIDeactivate(IOleInPlaceSite *iface, BOOL fUndoable)
314 static HRESULT STDMETHODCALLTYPE InPlace_OnInPlaceDeactivate(IOleInPlaceSite *iface)
319 static HRESULT STDMETHODCALLTYPE InPlace_DiscardUndoState(IOleInPlaceSite *iface)
324 static HRESULT STDMETHODCALLTYPE InPlace_DeactivateAndUndo(IOleInPlaceSite *iface)
329 static HRESULT STDMETHODCALLTYPE InPlace_OnPosRectChange(IOleInPlaceSite *iface, LPCRECT lprcPosRect)
331 ICOM_THIS_MULTI(IOleClientSiteImpl, lpvtblOleInPlaceSite, iface);
332 IOleInPlaceObject *inplace;
334 if (!IOleObject_QueryInterface(This->pBrowserObject, &IID_IOleInPlaceObject, (void **)&inplace))
335 IOleInPlaceObject_SetObjectRects(inplace, lprcPosRect, lprcPosRect);
340 static const IOleInPlaceSiteVtbl MyIOleInPlaceSiteTable =
342 InPlace_QueryInterface,
346 InPlace_ContextSensitiveHelp,
347 InPlace_CanInPlaceActivate,
348 InPlace_OnInPlaceActivate,
349 InPlace_OnUIActivate,
350 InPlace_GetWindowContext,
352 InPlace_OnUIDeactivate,
353 InPlace_OnInPlaceDeactivate,
354 InPlace_DiscardUndoState,
355 InPlace_DeactivateAndUndo,
356 InPlace_OnPosRectChange
359 static HRESULT STDMETHODCALLTYPE Frame_QueryInterface(IOleInPlaceFrame *iface, REFIID riid, LPVOID *ppvObj)
364 static ULONG STDMETHODCALLTYPE Frame_AddRef(IOleInPlaceFrame *iface)
369 static ULONG STDMETHODCALLTYPE Frame_Release(IOleInPlaceFrame *iface)
374 static HRESULT STDMETHODCALLTYPE Frame_GetWindow(IOleInPlaceFrame *iface, HWND *lphwnd)
376 ICOM_THIS_MULTI(IOleClientSiteImpl, lpvtblOleInPlaceFrame, iface);
377 *lphwnd = This->hwndWindow;
382 static HRESULT STDMETHODCALLTYPE Frame_ContextSensitiveHelp(IOleInPlaceFrame *iface, BOOL fEnterMode)
387 static HRESULT STDMETHODCALLTYPE Frame_GetBorder(IOleInPlaceFrame *iface, LPRECT lprectBorder)
392 static HRESULT STDMETHODCALLTYPE Frame_RequestBorderSpace(IOleInPlaceFrame *iface, LPCBORDERWIDTHS pborderwidths)
397 static HRESULT STDMETHODCALLTYPE Frame_SetBorderSpace(IOleInPlaceFrame *iface, LPCBORDERWIDTHS pborderwidths)
402 static HRESULT STDMETHODCALLTYPE Frame_SetActiveObject(IOleInPlaceFrame *iface, IOleInPlaceActiveObject *pActiveObject, LPCOLESTR pszObjName)
407 static HRESULT STDMETHODCALLTYPE Frame_InsertMenus(IOleInPlaceFrame *iface, HMENU hmenuShared, LPOLEMENUGROUPWIDTHS lpMenuWidths)
412 static HRESULT STDMETHODCALLTYPE Frame_SetMenu(IOleInPlaceFrame *iface, HMENU hmenuShared, HOLEMENU holemenu, HWND hwndActiveObject)
417 static HRESULT STDMETHODCALLTYPE Frame_RemoveMenus(IOleInPlaceFrame *iface, HMENU hmenuShared)
422 static HRESULT STDMETHODCALLTYPE Frame_SetStatusText(IOleInPlaceFrame *iface, LPCOLESTR pszStatusText)
427 static HRESULT STDMETHODCALLTYPE Frame_EnableModeless(IOleInPlaceFrame *iface, BOOL fEnable)
432 static HRESULT STDMETHODCALLTYPE Frame_TranslateAccelerator(IOleInPlaceFrame *iface, LPMSG lpmsg, WORD wID)
437 static const IOleInPlaceFrameVtbl MyIOleInPlaceFrameTable =
439 Frame_QueryInterface,
443 Frame_ContextSensitiveHelp,
445 Frame_RequestBorderSpace,
446 Frame_SetBorderSpace,
447 Frame_SetActiveObject,
452 Frame_EnableModeless,
453 Frame_TranslateAccelerator
456 static HRESULT STDMETHODCALLTYPE Storage_QueryInterface(IStorage *This, REFIID riid, LPVOID *ppvObj)
461 static ULONG STDMETHODCALLTYPE Storage_AddRef(IStorage *This)
466 static ULONG STDMETHODCALLTYPE Storage_Release(IStorage *This)
471 static HRESULT STDMETHODCALLTYPE Storage_CreateStream(IStorage *This, const WCHAR *pwcsName, DWORD grfMode, DWORD reserved1, DWORD reserved2, IStream **ppstm)
476 static HRESULT STDMETHODCALLTYPE Storage_OpenStream(IStorage *This, const WCHAR * pwcsName, void *reserved1, DWORD grfMode, DWORD reserved2, IStream **ppstm)
481 static HRESULT STDMETHODCALLTYPE Storage_CreateStorage(IStorage *This, const WCHAR *pwcsName, DWORD grfMode, DWORD reserved1, DWORD reserved2, IStorage **ppstg)
486 static HRESULT STDMETHODCALLTYPE Storage_OpenStorage(IStorage *This, const WCHAR * pwcsName, IStorage * pstgPriority, DWORD grfMode, SNB snbExclude, DWORD reserved, IStorage **ppstg)
491 static HRESULT STDMETHODCALLTYPE Storage_CopyTo(IStorage *This, DWORD ciidExclude, IID const *rgiidExclude, SNB snbExclude,IStorage *pstgDest)
496 static HRESULT STDMETHODCALLTYPE Storage_MoveElementTo(IStorage *This, const OLECHAR *pwcsName,IStorage * pstgDest, const OLECHAR *pwcsNewName, DWORD grfFlags)
501 static HRESULT STDMETHODCALLTYPE Storage_Commit(IStorage *This, DWORD grfCommitFlags)
506 static HRESULT STDMETHODCALLTYPE Storage_Revert(IStorage *This)
511 static HRESULT STDMETHODCALLTYPE Storage_EnumElements(IStorage *This, DWORD reserved1, void *reserved2, DWORD reserved3, IEnumSTATSTG **ppenum)
516 static HRESULT STDMETHODCALLTYPE Storage_DestroyElement(IStorage *This, const OLECHAR *pwcsName)
521 static HRESULT STDMETHODCALLTYPE Storage_RenameElement(IStorage *This, const WCHAR *pwcsOldName, const WCHAR *pwcsNewName)
526 static HRESULT STDMETHODCALLTYPE Storage_SetElementTimes(IStorage *This, const WCHAR *pwcsName, FILETIME const *pctime, FILETIME const *patime, FILETIME const *pmtime)
531 static HRESULT STDMETHODCALLTYPE Storage_SetClass(IStorage *This, REFCLSID clsid)
536 static HRESULT STDMETHODCALLTYPE Storage_SetStateBits(IStorage *This, DWORD grfStateBits, DWORD grfMask)
541 static HRESULT STDMETHODCALLTYPE Storage_Stat(IStorage *This, STATSTG *pstatstg, DWORD grfStatFlag)
546 static const IStorageVtbl MyIStorageTable =
548 Storage_QueryInterface,
551 Storage_CreateStream,
553 Storage_CreateStorage,
556 Storage_MoveElementTo,
559 Storage_EnumElements,
560 Storage_DestroyElement,
561 Storage_RenameElement,
562 Storage_SetElementTimes,
564 Storage_SetStateBits,
568 static IStorage MyIStorage = { &MyIStorageTable };
570 BOOL InitWebBrowser(HHInfo *info, HWND hwndParent)
572 IOleClientSiteImpl *iOleClientSiteImpl;
573 IOleInPlaceObject *inplace;
574 IOleObject *browserObject;
575 IWebBrowser2 *webBrowser2;
579 iOleClientSiteImpl = hhctrl_alloc_zero(sizeof(IOleClientSiteImpl));
580 if (!iOleClientSiteImpl)
583 iOleClientSiteImpl->ref = 1;
584 iOleClientSiteImpl->lpVtbl = &MyIOleClientSiteTable;
585 iOleClientSiteImpl->lpvtblOleInPlaceSite = &MyIOleInPlaceSiteTable;
586 iOleClientSiteImpl->lpvtblOleInPlaceFrame = &MyIOleInPlaceFrameTable;
587 iOleClientSiteImpl->hwndWindow = hwndParent;
588 iOleClientSiteImpl->lpvtblDocHostUIHandler = &MyIDocHostUIHandlerTable;
590 hr = OleCreate(&CLSID_WebBrowser, &IID_IOleObject, OLERENDER_DRAW, 0,
591 (IOleClientSite *)iOleClientSiteImpl, &MyIStorage,
592 (void **)&browserObject);
594 info->client_site = (IOleClientSite *)iOleClientSiteImpl;
595 info->wb_object = browserObject;
597 if (FAILED(hr)) goto error;
599 /* make the browser object accessible to the IOleClientSite implementation */
600 iOleClientSiteImpl->pBrowserObject = browserObject;
602 GetClientRect(hwndParent, &rc);
604 hr = OleSetContainedObject((struct IUnknown *)browserObject, TRUE);
605 if (FAILED(hr)) goto error;
607 hr = IOleObject_DoVerb(browserObject, OLEIVERB_SHOW, NULL,
608 (IOleClientSite *)iOleClientSiteImpl,
609 -1, hwndParent, &rc);
610 if (FAILED(hr)) goto error;
612 hr = IOleObject_QueryInterface(browserObject, &IID_IOleInPlaceObject, (void**)&inplace);
613 if (FAILED(hr)) goto error;
615 IOleInPlaceObject_SetObjectRects(inplace, &rc, &rc);
616 IOleInPlaceObject_Release(inplace);
618 hr = IOleObject_QueryInterface(browserObject, &IID_IWebBrowser2,
619 (void **)&webBrowser2);
622 info->web_browser = webBrowser2;
627 ReleaseWebBrowser(info);
628 hhctrl_free(iOleClientSiteImpl);
633 void ReleaseWebBrowser(HHInfo *info)
637 if (info->web_browser)
639 IWebBrowser2_Release(info->web_browser);
640 info->web_browser = NULL;
643 if (info->client_site)
645 IOleClientSite_Release(info->client_site);
646 info->client_site = NULL;
649 if(info->wb_object) {
650 IOleInPlaceSite *inplace;
652 hres = IOleObject_QueryInterface(info->wb_object, &IID_IOleInPlaceSite, (void**)&inplace);
653 if(SUCCEEDED(hres)) {
654 IOleInPlaceSite_OnInPlaceDeactivate(inplace);
655 IOleInPlaceSite_Release(inplace);
658 IOleObject_SetClientSite(info->wb_object, NULL);
660 IOleObject_Release(info->wb_object);
661 info->wb_object = NULL;
665 void ResizeWebBrowser(HHInfo *info, DWORD dwWidth, DWORD dwHeight)
667 if (!info->web_browser)
670 IWebBrowser2_put_Width(info->web_browser, dwWidth);
671 IWebBrowser2_put_Height(info->web_browser, dwHeight);
674 void DoPageAction(HHInfo *info, DWORD dwAction)
676 IWebBrowser2 *pWebBrowser2 = info->web_browser;
684 IWebBrowser2_GoBack(pWebBrowser2);
687 IWebBrowser2_GoForward(pWebBrowser2);
690 IWebBrowser2_GoHome(pWebBrowser2);
693 IWebBrowser2_GoSearch(pWebBrowser2);
696 IWebBrowser2_Refresh(pWebBrowser2);
698 IWebBrowser2_Stop(pWebBrowser2);