Esempio n. 1
0
        public void CreateHtml()
        {
            Debug.Assert(this.document == null, "Must call CloseHtml before recreating.");

            bool created = false;

            try
            {
                // create the trident instance
                this.document  = (NativeMethods.IHTMLDocument2) new NativeMethods.HTMLDocument();
                this.oleObject = (NativeMethods.IOleObject) this.document;

                // hand it our NativeMethods.IOleClientSite implementation
                this.oleObject.SetClientSite((NativeMethods.IOleClientSite) this);

                created = true;

                this.propertyNotifySinkCookie = new NativeMethods.ConnectionPointCookie(this.document, this, typeof(NativeMethods.IPropertyNotifySink), false);

                this.oleObject.Advise((NativeMethods.IAdviseSink) this, out adviseSinkCookie);
                Debug.Assert(adviseSinkCookie != 0);

                this.commandTarget = (NativeMethods.IOleCommandTarget) this.document;
            }
            finally
            {
                if (created == false)
                {
                    this.document      = null;
                    this.oleObject     = null;
                    this.commandTarget = null;
                }
            }
        }
Esempio n. 2
0
        public void CloseHtml()
        {
            this.hostControl.Resize -= new EventHandler(this.HostControl_Resize);

            try
            {
                if (this.propertyNotifySinkCookie != null)
                {
                    this.propertyNotifySinkCookie.Disconnect();
                    this.propertyNotifySinkCookie = null;
                }

                if (this.document != null)
                {
                    this.documentView  = null;
                    this.document      = null;
                    this.commandTarget = null;
                    this.activeObject  = null;

                    if (adviseSinkCookie != 0)
                    {
                        this.oleObject.Unadvise(adviseSinkCookie);
                        this.adviseSinkCookie = 0;
                    }

                    this.oleObject.Close(NativeMethods.OLECLOSE_NOSAVE);
                    this.oleObject.SetClientSite(null);
                    this.oleObject = null;
                }
            }
            catch (Exception exception)
            {
                Debug.Fail(exception.ToString());
            }
        }
         /// <include file='doc\PropertyBrowserService.uex' path='docs/doc[@for="PropertyBrowserService.PbrsCommandTarget.NativeMethods.IOleCommandTarget.QueryStatus"]/*' />
         /// <devdoc>
         /// Delegate to the current user context command target for undo/redo commands,
         /// otherwise call the default target.
         /// </devdoc>
         int NativeMethods.IOleCommandTarget.QueryStatus(ref Guid pguidCmdGroup,int cCmds, NativeMethods._tagOLECMD prgCmds,IntPtr pCmdText) {

             if (pguidCmdGroup == ShellGuids.VSStandardCommandSet97) {
                switch (prgCmds.cmdID) {
                    case VSStandardCommands.cmdidUndo:
                       if (pbrsSvc.GetPropertyBrowser().CanUndo) {
                           prgCmds.cmdf = (int)(NativeMethods.tagOLECMDF.OLECMDF_ENABLED | NativeMethods.tagOLECMDF.OLECMDF_SUPPORTED);
                            return NativeMethods.S_OK;
                       }
                       goto case VSStandardCommands.cmdidMultiLevelUndo;
                        
                    case VSStandardCommands.cmdidMultiLevelUndo:
                    case VSStandardCommands.cmdidMultiLevelUndoList:
                    case VSStandardCommands.cmdidRedo:
                    case VSStandardCommands.cmdidMultiLevelRedo:
                    case VSStandardCommands.cmdidMultiLevelRedoList:

                        // get the current context and delegate to it
                        NativeMethods.IOleCommandTarget currentTarget = GetCurrentContextTarget();
                        if (currentTarget != null && currentTarget != this) {
                           int hr = currentTarget.QueryStatus(ref pguidCmdGroup, 1, prgCmds, pCmdText);
                           return hr;
                        }
                        break;
                        
                    case VSStandardCommands.cmdidPaste:
                        if (pbrsSvc.GetPropertyBrowser().CanPaste) {
                            prgCmds.cmdf = (int)(NativeMethods.tagOLECMDF.OLECMDF_ENABLED | NativeMethods.tagOLECMDF.OLECMDF_SUPPORTED);
                        }
                        else {
                            prgCmds.cmdf = (int)(NativeMethods.tagOLECMDF.OLECMDF_SUPPORTED);
                        }
                        return NativeMethods.S_OK;
                        
                    case VSStandardCommands.cmdidCut:
                        if (pbrsSvc.GetPropertyBrowser().CanCut) {
                            prgCmds.cmdf = (int)(NativeMethods.tagOLECMDF.OLECMDF_ENABLED | NativeMethods.tagOLECMDF.OLECMDF_SUPPORTED);
                        }
                        else {
                            prgCmds.cmdf = (int)(NativeMethods.tagOLECMDF.OLECMDF_SUPPORTED);
                        }
                        return NativeMethods.S_OK;
                    
                     case VSStandardCommands.cmdidCopy:
                        if (pbrsSvc.GetPropertyBrowser().CanCopy) {
                            prgCmds.cmdf = (int)(NativeMethods.tagOLECMDF.OLECMDF_ENABLED | NativeMethods.tagOLECMDF.OLECMDF_SUPPORTED);
                        }
                        else {
                            prgCmds.cmdf = (int)(NativeMethods.tagOLECMDF.OLECMDF_SUPPORTED);
                        }
                        return NativeMethods.S_OK;
                 }
             }

             // just call down to the base.
             Debug.Assert(baseCommandTarget != this, "we're calling ourselves and will recurse!");
             return baseCommandTarget.QueryStatus(ref pguidCmdGroup, cCmds, prgCmds, pCmdText);
         }
Esempio n. 4
0
 public int ShowUI(
     int dwID,
     UnsafeNativeMethods.IOleInPlaceActiveObject activeObject,
     NativeMethods.IOleCommandTarget commandTarget,
     UnsafeNativeMethods.IOleInPlaceFrame frame,
     UnsafeNativeMethods.IOleInPlaceUIWindow doc)
 {
     // default means we don't have any UI, and control should show its UI
     return(NativeMethods.SRESULTS.S_FALSE);
 }
         public void Dispose() {
            if (vsMonitorSelection != null) {
               vsMonitorSelection = null;
            }

            if (baseCommandTarget != null) {
               baseCommandTarget = null;
            }

         }
Esempio n. 6
0
 /// <include file='doc\VsWindowPane.uex' path='docs/doc[@for="VsWindowPane.NativeMethods.IOleCommandTarget.Exec"]/*' />
 /// <devdoc>
 ///     This is called by Visual Studio when the user has requested to execute a particular
 ///     command.  There is no need to override this method.  If you need access to menu
 ///     commands use IMenuCommandService.
 /// </devdoc>
 int NativeMethods.IOleCommandTarget.Exec(ref Guid guidGroup, int nCmdId, int nCmdExcept, Object[] vIn, int vOut)
 {
     NativeMethods.IOleCommandTarget tgt = (NativeMethods.IOleCommandTarget)GetService((typeof(NativeMethods.IOleCommandTarget)));
     if (tgt != null)
     {
         return(tgt.Exec(ref guidGroup, nCmdId, nCmdExcept, vIn, vOut));
     }
     else
     {
         return(NativeMethods.OLECMDERR_E_NOTSUPPORTED);
     }
 }
         /// <include file='doc\PropertyBrowserService.uex' path='docs/doc[@for="PropertyBrowserService.PbrsCommandTarget.NativeMethods.IOleCommandTarget.Exec"]/*' />
         /// <devdoc>
         /// Delegate to the current user context command target for undo/redo commands,
         /// otherwise call the default target.
         /// </devdoc>
         int NativeMethods.IOleCommandTarget.Exec(ref Guid pguidCmdGroup, int nCmdID, int nCmdexecopt, Object[] pIn, int pOut) {
             if (pguidCmdGroup == ShellGuids.VSStandardCommandSet97) {
                switch (nCmdID) {
                    case VSStandardCommands.cmdidUndo:
                       if (pbrsSvc.GetPropertyBrowser().CanUndo) {
                            
                            pbrsSvc.GetPropertyBrowser().Undo();
                            return NativeMethods.S_OK;
                       }
                       goto case VSStandardCommands.cmdidMultiLevelUndo;
                       
                    case VSStandardCommands.cmdidMultiLevelUndo:
                    case VSStandardCommands.cmdidMultiLevelUndoList:
                    case VSStandardCommands.cmdidRedo:
                    case VSStandardCommands.cmdidMultiLevelRedo:
                    case VSStandardCommands.cmdidMultiLevelRedoList:

                        // delegate to the curent context target
                        NativeMethods.IOleCommandTarget currentTarget = GetCurrentContextTarget();
                        if (currentTarget != null && currentTarget != this) {
                           int hr = currentTarget.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pIn, pOut);
                           return hr;
                        }
                        break;
                        
                    case VSStandardCommands.cmdidPaste:
                        if (pbrsSvc.GetPropertyBrowser().CanPaste) {
                            pbrsSvc.GetPropertyBrowser().Paste();
                            return NativeMethods.S_OK;
                        }
                        break;
                        
                    case VSStandardCommands.cmdidCut:
                        if (pbrsSvc.GetPropertyBrowser().CanCut) {
                            pbrsSvc.GetPropertyBrowser().Cut();
                            return NativeMethods.S_OK;
                        }
                        break;
                    
                     case VSStandardCommands.cmdidCopy:
                        if (pbrsSvc.GetPropertyBrowser().CanCopy) {
                            pbrsSvc.GetPropertyBrowser().Copy();
                            return NativeMethods.S_OK;
                        }
                        break;

                }
             }

             // just call down to the base.
             Debug.Assert(baseCommandTarget != this, "we're calling ourselves and will recurse!");
             return baseCommandTarget.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pIn, pOut);
         }
Esempio n. 8
0
 /// <include file='doc\VsWindowPane.uex' path='docs/doc[@for="VsWindowPane.NativeMethods.IOleCommandTarget.QueryStatus"]/*' />
 /// <devdoc>
 ///     This is called by Visual Studio when it needs the status of our menu commands.  There
 ///     is no need to override this method.  If you need access to menu commands use
 ///     IMenuCommandService.
 /// </devdoc>
 int NativeMethods.IOleCommandTarget.QueryStatus(ref Guid guidGroup, int nCmdId, NativeMethods._tagOLECMD oleCmd, IntPtr oleText)
 {
     NativeMethods.IOleCommandTarget tgt = (NativeMethods.IOleCommandTarget)GetService((typeof(NativeMethods.IOleCommandTarget)));
     if (tgt != null)
     {
         return(tgt.QueryStatus(ref guidGroup, nCmdId, oleCmd, oleText));
     }
     else
     {
         return(NativeMethods.OLECMDERR_E_NOTSUPPORTED);
     }
 }
Esempio n. 9
0
        private void DoNavigate(Uri source, ref object targetFrameName, ref object postData, ref object headers, bool ignoreEscaping = false)
        {
            base.VerifyAccess();
            NativeMethods.IOleCommandTarget oleCommandTarget = (NativeMethods.IOleCommandTarget) this.AxIWebBrowser2;
            object obj = false;

            oleCommandTarget.Exec(null, 23, 0, new object[]
            {
                obj
            }, 0);
            this.LastNavigation = Guid.NewGuid();
            if (source == null)
            {
                this.NavigatingToAboutBlank = true;
                source = new Uri("about:blank");
            }
            else
            {
                this.CleanInternalState();
            }
            if (!source.IsAbsoluteUri)
            {
                throw new ArgumentException(SR.Get("AbsoluteUriOnly"), "source");
            }
            if (PackUriHelper.IsPackUri(source))
            {
                source = BaseUriHelper.ConvertPackUriToAbsoluteExternallyVisibleUri(source);
            }
            if (!string.IsNullOrEmpty((string)targetFrameName))
            {
                new WebPermission(PermissionState.Unrestricted).Demand();
            }
            else if (!this.NavigatingToAboutBlank)
            {
                SecurityHelper.DemandWebPermission(source);
            }
            object obj2 = null;
            object obj3 = ignoreEscaping ? source.AbsoluteUri : BindUriHelper.UriToString(source);

            try
            {
                this.AxIWebBrowser2.Navigate2(ref obj3, ref obj2, ref targetFrameName, ref postData, ref headers);
            }
            catch (COMException ex)
            {
                this.CleanInternalState();
                if (ex.ErrorCode != -2147023673)
                {
                    throw;
                }
            }
        }
Esempio n. 10
0
 int NativeMethods.IDocHostUIHandler.ShowUI(int dwID, NativeMethods.IOleInPlaceActiveObject activeObject, NativeMethods.IOleCommandTarget commandTarget, NativeMethods.IOleInPlaceFrame frame, NativeMethods.IOleInPlaceUIWindow doc)
 {
     return(NativeMethods.S_OK);
 }
Esempio n. 11
0
        private void DoNavigate(Uri source, ref object targetFrameName, ref object postData, ref object headers, bool ignoreEscaping = false)
        {
            VerifyAccess();

            // TFS  - Calling Navigate and NavigateToStream subsequently causes internal state
            // of the WebBrowser control to become invalid. By cancelling outstanding navigations in the
            // browser, we make sure not to get a NavigationCompleted2 event for the original request while
            // we've already overwritten internal state (more specifically the NavigatingToAboutBlank and
            // DocumentStream properties), therefore avoiding the Invariant.Assert over there to fail.
            // Notice we're passing showCancelPage = false as the input parameter. This keeps the browser
            // from navigating to res://ieframe.dll/navcancl.htm because of the cancellation (which would
            // by itself cause navigation events to occur). See inetcore/ieframe/shdocvw/shvocx.cpp.
            NativeMethods.IOleCommandTarget cmdTarget = (NativeMethods.IOleCommandTarget)AxIWebBrowser2;
            object showCancelPage = false;

            cmdTarget.Exec(
                null /* default command group */,
                (int)UnsafeNativeMethods.OLECMDID.OLECMDID_STOP,
                (int)UnsafeNativeMethods.OLECMDEXECOPT.OLECMDEXECOPT_DODEFAULT,
                new object[] { showCancelPage }, /* don't navigate to res://ieframe.dll/navcancl.htm */
                0
                );

            // TFS  - Launching a navigation from the Navigating event handler causes reentrancy.
            // For more info, see WebBrowser.LastNavigation. Here we generate a new navigation identifier which
            // is used to detect reentrant calls during handling of the Navigating event.
            LastNavigation = Guid.NewGuid();

            // When source set to null or navigating to stream/string, we navigate to "about:blank" internally.
            if (source == null)
            {
                NavigatingToAboutBlank = true;
                source = new Uri(AboutBlankUriString);
            }
            else
            {
                CleanInternalState();
            }

            if (!source.IsAbsoluteUri)
            {
                throw new ArgumentException(SR.Get(SRID.AbsoluteUriOnly), "source");
            }

            // Resolve Pack://siteoforigin.
            if (PackUriHelper.IsPackUri(source))
            {
                source = BaseUriHelper.ConvertPackUriToAbsoluteExternallyVisibleUri(source);
            }

            // figure out why BrowserNavConstants.NewWindowsManaged does not work.
            object flags = (object)null; // UnsafeNativeMethods.BrowserNavConstants.NewWindowsManaged;

            // Fix for inability to navigate to a URI containing invalid UTF-8 sequences
            // BindUriHelper.UriToString does use Uri.GetComponents with the UriFormat.SafeUnescaped flag passed in,
            // causing invalid UTF-8 sequences to get dropped, resulting in a strictly speaking valid URI but for
            // some websites this causes breakage. Therefore we allow ignoring this treatment by means of string-
            // based overloads for the public Navigate methods, creating a Uri internally and using AbsoluteUri
            // to get back the URI string to feed in to the WebOC in its original form. WinForms has a similar
            // set of overloads to enable this scenario.
            object sourceString = ignoreEscaping ? source.AbsoluteUri : BindUriHelper.UriToString(source);

            try
            {
                AxIWebBrowser2.Navigate2(ref sourceString, ref flags, ref targetFrameName, ref postData, ref headers);
            }
            catch (COMException ce)
            {
                // Clear internal state if Navigation fails.
                CleanInternalState();

                // "the operation was canceled by the user" - navigation failed
                // ignore this error, IE has already alerted the user.
                if ((uint)unchecked (ce.ErrorCode) != (uint)unchecked (0x800704c7))
                {
                    throw;
                }
            }
        }
Esempio n. 12
0
 public virtual int ShowUI(int dwID, NativeMethods.IOleInPlaceActiveObject activeObject, NativeMethods.IOleCommandTarget commandTarget, NativeMethods.IOleInPlaceFrame frame, NativeMethods.IOleInPlaceUIWindow doc)
 {
     return(NativeMethods.S_OK);
 }
Esempio n. 13
0
        public void CloseHtml()
        {
            this.hostControl.Resize -= new EventHandler(this.HostControl_Resize);

            try
            {
                if (this.propertyNotifySinkCookie != null)
                {
                    this.propertyNotifySinkCookie.Disconnect();
                    this.propertyNotifySinkCookie = null;
                }

                if (this.document != null)
                {
                    this.documentView = null;
                    this.document = null;
                    this.commandTarget = null;
                    this.activeObject = null;

                    if (adviseSinkCookie != 0)
                    {
                        this.oleObject.Unadvise(adviseSinkCookie);
                        this.adviseSinkCookie = 0;
                    }

                    this.oleObject.Close(NativeMethods.OLECLOSE_NOSAVE);
                    this.oleObject.SetClientSite(null);
                    this.oleObject = null;
                }
            }
            catch (Exception exception)
            {
                Debug.Fail(exception.ToString());
            }
        }
 public PbrsCommandTarget(PropertyBrowserService pbrsSvc, NativeMethods.IOleCommandTarget baseTarget, IVsMonitorSelection pMonSel) {
    this.vsMonitorSelection = pMonSel;
    this.baseCommandTarget = baseTarget;
    this.pbrsSvc = pbrsSvc;
 }
Esempio n. 15
0
        public void CreateHtml()
        {
            Debug.Assert(this.document == null, "Must call CloseHtml before recreating.");

            bool created = false;
            try
            {
                // create the trident instance
                this.document = (NativeMethods.IHTMLDocument2) new NativeMethods.HTMLDocument();
                this.oleObject = (NativeMethods.IOleObject) this.document;

                // hand it our NativeMethods.IOleClientSite implementation
                this.oleObject.SetClientSite((NativeMethods.IOleClientSite)this);

                created = true;

                this.propertyNotifySinkCookie = new NativeMethods.ConnectionPointCookie(this.document, this, typeof(NativeMethods.IPropertyNotifySink), false);

                this.oleObject.Advise((NativeMethods.IAdviseSink)this, out adviseSinkCookie);
                Debug.Assert(adviseSinkCookie != 0);

                this.commandTarget = (NativeMethods.IOleCommandTarget) this.document;
            }
            finally
            {
                if (created == false)
                {
                    this.document = null;
                    this.oleObject = null;
                    this.commandTarget = null;
                }
            }
        }
Esempio n. 16
0
 int UnsafeNativeMethods.IDocHostUIHandler.ShowUI(int dwID, UnsafeNativeMethods.IOleInPlaceActiveObject activeObject,
                                                  NativeMethods.IOleCommandTarget commandTarget, UnsafeNativeMethods.IOleInPlaceFrame frame,
                                                  UnsafeNativeMethods.IOleInPlaceUIWindow doc)
 {
     return(NativeMethods.E_NOTIMPL);
 }
Esempio n. 17
0
 int NativeMethods.IDocHostUIHandler.ShowUI(int dwID, NativeMethods.IOleInPlaceActiveObject activeObject, NativeMethods.IOleCommandTarget commandTarget, NativeMethods.IOleInPlaceFrame frame, NativeMethods.IOleInPlaceUIWindow doc)
 {
     Debug.WriteLineIf(StyleBuilder.StyleBuilderSwitch.TraceVerbose, "CTridentSite: IDocHostUIHandler::ShowUI");
     return(NativeMethods.S_OK);
 }