Пример #1
0
        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);
        }
        int UnsafeNativeMethods.IOleInPlaceFrame.SetActiveObject(UnsafeNativeMethods.IOleInPlaceActiveObject pActiveObject, string pszObjName)
        {
            if (pActiveObject == null)
            {
                if (this.ctlInEditMode != null)
                {
                    this.ctlInEditMode.SetEditMode(WebBrowserHelper.AXEditMode.None);
                    this.ctlInEditMode = null;
                }
                return(0);
            }
            WebBrowserBase aXHost = null;

            UnsafeNativeMethods.IOleObject obj2 = pActiveObject as UnsafeNativeMethods.IOleObject;
            if (obj2 != null)
            {
                try
                {
                    WebBrowserSiteBase clientSite = obj2.GetClientSite() as WebBrowserSiteBase;
                    if (clientSite != null)
                    {
                        aXHost = clientSite.GetAXHost();
                    }
                }
                catch (COMException)
                {
                }
                if (this.ctlInEditMode != null)
                {
                    this.ctlInEditMode.SetSelectionStyle(WebBrowserHelper.SelectionStyle.Selected);
                    this.ctlInEditMode.SetEditMode(WebBrowserHelper.AXEditMode.None);
                }
                if (aXHost == null)
                {
                    this.ctlInEditMode = null;
                }
                else if (!aXHost.IsUserMode)
                {
                    this.ctlInEditMode = aXHost;
                    aXHost.SetEditMode(WebBrowserHelper.AXEditMode.Object);
                    aXHost.AddSelectionHandler();
                    aXHost.SetSelectionStyle(WebBrowserHelper.SelectionStyle.Active);
                }
            }
            return(0);
        }