int UnsafeNativeMethods.IOleInPlaceFrame.SetActiveObject(UnsafeNativeMethods.IOleInPlaceActiveObject pActiveObject, string pszObjName) { if (pActiveObject == null) { if (ctlInEditMode != null) { ctlInEditMode.SetEditMode(WebBrowserHelper.AXEditMode.None); ctlInEditMode = null; } return(NativeMethods.S_OK); } WebBrowserBase ctl = null; UnsafeNativeMethods.IOleObject oleObject = pActiveObject as UnsafeNativeMethods.IOleObject; if (oleObject != null) { UnsafeNativeMethods.IOleClientSite clientSite = null; try { clientSite = oleObject.GetClientSite(); WebBrowserSiteBase webBrowserSiteBase = clientSite as WebBrowserSiteBase; if (webBrowserSiteBase != null) { ctl = webBrowserSiteBase.GetAXHost(); } } catch (COMException t) { Debug.Fail(t.ToString()); } if (ctlInEditMode != null) { Debug.Fail("control " + ctlInEditMode.ToString() + " did not reset its edit mode to null"); ctlInEditMode.SetSelectionStyle(WebBrowserHelper.SelectionStyle.Selected); ctlInEditMode.SetEditMode(WebBrowserHelper.AXEditMode.None); } if (ctl == null) { ctlInEditMode = null; } else { if (!ctl.IsUserMode) { ctlInEditMode = ctl; ctl.SetEditMode(WebBrowserHelper.AXEditMode.Object); ctl.AddSelectionHandler(); ctl.SetSelectionStyle(WebBrowserHelper.SelectionStyle.Active); } } } return(NativeMethods.S_OK); }
HRESULT Ole32.IOleInPlaceFrame.SetActiveObject(Ole32.IOleInPlaceActiveObject pActiveObject, string pszObjName) { if (pActiveObject is null) { if (ctlInEditMode is not null) { ctlInEditMode.SetEditMode(WebBrowserHelper.AXEditMode.None); ctlInEditMode = null; } return(HRESULT.S_OK); } WebBrowserBase ctl = null; if (pActiveObject is Ole32.IOleObject oleObject) { oleObject.GetClientSite(out Ole32.IOleClientSite clientSite); if (clientSite is WebBrowserSiteBase webBrowserSiteBase) { ctl = webBrowserSiteBase.Host; } if (ctlInEditMode is not null) { Debug.Fail("control " + ctlInEditMode.ToString() + " did not reset its edit mode to null"); ctlInEditMode.SetSelectionStyle(WebBrowserHelper.SelectionStyle.Selected); ctlInEditMode.SetEditMode(WebBrowserHelper.AXEditMode.None); } if (ctl is null) { ctlInEditMode = null; } else { if (!ctl.IsUserMode) { ctlInEditMode = ctl; ctl.SetEditMode(WebBrowserHelper.AXEditMode.Object); ctl.AddSelectionHandler(); ctl.SetSelectionStyle(WebBrowserHelper.SelectionStyle.Active); } } } return(HRESULT.S_OK); }