Esempio n. 1
0
 /// <summary>
 /// Initialize based on a command id and the document to which
 /// to send commands to
 /// </summary>
 /// <param name="cmdID">mshtml command id (IDM_)</param>
 /// <param name="target">command target</param>
 public MshtmlCommandFromCoreSet(uint cmdID, IOleCommandTargetWithExecParams target, bool useNullOutputParam)
 {
     commandID             = cmdID;
     commandTarget         = target;
     getValueCommandTarget = (IOleCommandTargetGetCommandValue)target;
     UseNullOutputParam    = useNullOutputParam;
 }
Esempio n. 2
0
        /// <summary>
        /// Returns the InternetSecurityZone assign to the currently loaded document
        /// </summary>
        /// <returns></returns>
        protected InternetSecurityZone GetSecurityZone()
        {
            IOleCommandTargetWithExecParams target = (IOleCommandTargetWithExecParams)Document;
            object input  = null;
            object output = null;

            target.Exec(MSHTML, GETFRAMEZONE, OpenLiveWriter.Interop.Com.OLECMDEXECOPT.DODEFAULT, ref input, ref output);

            UInt32 zoneInt            = (UInt32)output;
            InternetSecurityZone zone = (InternetSecurityZone)zoneInt;

            return(zone);
        }
Esempio n. 3
0
        /// <summary>
        /// Execute the command with an input and output parameter
        /// </summary>
        public override void Execute()
        {
            // get the command target
            IOleCommandTargetWithExecParams target = GetCommandTarget();

            // if there is a target, execute the command on it
            if (target != null)
            {
                object input  = null;
                object output = null;
                try
                {
                    target.Exec(
                        CGID_IWebBrowserPrivate,
                        m_cmdID,
                        OpenLiveWriter.Interop.Com.OLECMDEXECOPT.DODEFAULT,
                        ref input,
                        ref output);
                }
                catch (COMException e)
                {
                    // The InternetOptions command throws a spurious exception
                    // every time it is invoked -- ignore it.
                    if (m_cmdID != InternetOptions)
                    {
                        throw e;
                    }
                }
            }
            // should never try to execute a command if there is no target!
            // (caller should have detected this via QueryStatus)
            else
            {
                Debug.Assert(false,
                             "Attempted to execute a command when there is no valid target");
            }
        }
Esempio n. 4
0
        public static void Run(string appId, LaunchAction action, string[] args)
        {
            Mutex m_mutex          = new Mutex(false, @"Local\" + appId);
            RunningObjectTable rot = new RunningObjectTable();

            for (int i = 0; i < 120; i++) // wait for ~60 seconds
            {
                if (m_mutex.WaitOne(1, false))
                {
                    // we are the first instance
                    try
                    {
                        using (rot.Register(appId, new OleCommandTargetImpl(action)))
                        {
                            action(args, true);
                        }
                        return;
                    }
                    finally
                    {
                        m_mutex.ReleaseMutex();
                    }
                }
                else
                {
                    // we are not the first instance
                    IOleCommandTargetWithExecParams instance = rot.GetObject(appId) as IOleCommandTargetWithExecParams;

                    if (instance != null)
                    {
                        try
                        {
                            object dummy     = null;
                            object processId = null;
                            instance.Exec(Guid.Empty, 0, OLECMDEXECOPT.DODEFAULT, ref dummy, ref processId);
                            User32.AllowSetForegroundWindow((int)processId);

                            object objArgs = args;
                            object result  = null;
                            instance.Exec(Guid.Empty, 1, OLECMDEXECOPT.DODEFAULT, ref objArgs, ref result);
                            if (result is bool && (bool)result)
                            {
                                return;
                            }
                        }
                        catch (Exception e)
                        {
                            Trace.WriteLine(e.ToString());
                        }
                        finally
                        {
                            Marshal.ReleaseComObject(instance);
                        }
                    }
                }

                Thread.Sleep(500);
            }

            Trace.WriteLine(appId + " could not start!");
        }
Esempio n. 5
0
        /// <summary>
        /// Initialize with a command target
        /// </summary>
        /// <param name="target">command target</param>
        public MshtmlCoreCommandSet(IOleCommandTargetWithExecParams target)
        {
            // keep a copy of the command target
            commandTarget = target;

            // add all of the standard commands
            AddCommand(IDM._1D_ELEMENT);
            AddCommand(IDM._2D_ELEMENT);
            AddCommand(IDM._2D_POSITION);
            AddCommand(IDM.ABSOLUTE_POSITION);
            AddCommand(IDM.ADDFAVORITES);
            AddCommand(IDM.ADDTOGLYPHTABLE);
            AddCommand(IDM.ATOMICSELECTION);
            AddCommand(IDM.AUTOURLDETECT_MODE);
            AddCommand(IDM.BACKCOLOR);
            AddCommand(IDM.BLOCKFMT);
            AddCommand(IDM.BOLD);
            AddCommand(IDM.BOOKMARK);
            AddCommand(IDM.BROWSEMODE);
            AddCommand(IDM.BUTTON);
            AddCommand(IDM.CHECKBOX);
            AddCommand(IDM.CLEARAUTHENTICATIONCACHE);
            AddCommand(IDM.CLEARSELECTION);
            AddCommand(IDM.COMPOSESETTINGS, true);
            AddCommand(IDM.COPY);
            AddCommand(IDM.CSSEDITING_LEVEL);
            AddCommand(IDM.CUT);
            AddCommand(IDM.DELETE);
            AddCommand(IDM.DISABLE_EDITFOCUS_UI);
            AddCommand(IDM.DROPDOWNBOX);
            AddCommand(IDM.EMPTYGLYPHTABLE);
            AddCommand(IDM.FIND);
            AddCommand(IDM.FONT);
            AddCommand(IDM.FONTNAME);
            AddCommand(IDM.FONTSIZE);
            AddCommand(IDM.FORECOLOR);
            AddCommand(IDM.GETBLOCKFMTS);
            AddCommand(IDM.GETFRAMEZONE);
            AddCommand(IDM.HORIZONTALLINE);
            AddCommand(IDM.HTMLEDITMODE);
            AddCommand(IDM.HYPERLINK);
            AddCommand(IDM.IFRAME);
            AddCommand(IDM.IMAGE);
            AddCommand(IDM.IME_ENABLE_RECONVERSION, true);
            AddCommand(IDM.INDENT);
            AddCommand(IDM.INSFIELDSET);
            AddCommand(IDM.INSINPUTBUTTON);
            AddCommand(IDM.INSINPUTHIDDEN);
            AddCommand(IDM.INSINPUTIMAGE);
            AddCommand(IDM.INSINPUTPASSWORD);
            AddCommand(IDM.INSINPUTRESET);
            AddCommand(IDM.INSINPUTSUBMIT);
            AddCommand(IDM.INSINPUTUPLOAD);
            AddCommand(IDM.ITALIC);
            AddCommand(IDM.JUSTIFYNONE);
            AddCommand(IDM.JUSTIFYCENTER);
            AddCommand(IDM.JUSTIFYLEFT);
            AddCommand(IDM.JUSTIFYRIGHT);
            AddCommand(IDM.JUSTIFYFULL);
            AddCommand(IDM.KEEPSELECTION);
            AddCommand(IDM.LISTBOX);
            AddCommand(IDM.LIVERESIZE);
            AddCommand(IDM.MARQUEE);
            AddCommand(IDM.MULTIPLESELECTION);
            AddCommand(IDM.NOFIXUPURLSONPASTE);
            AddCommand(IDM.ORDERLIST);
            AddCommand(IDM.OUTDENT);
            AddCommand(IDM.OVERWRITE);
            AddCommand(IDM.OVERRIDE_CURSOR);
            AddCommand(IDM.PAGESETUP);
            AddCommand(IDM.PARAGRAPH);
            AddCommand(IDM.PASTE);
            AddCommand(IDM.PRINT);
            AddCommand(IDM.PRINTPREVIEW);
            AddCommand(IDM.RADIOBUTTON);
            AddCommand(IDM.REDO);
            AddCommand(IDM.REFRESH);
            AddCommand(IDM.REMOVEFORMAT);
            AddCommand(IDM.RESPECTVISIBILITY_INDESIGN);
            AddCommand(IDM.SAVE);
            AddCommand(IDM.SAVEAS);
            AddCommand(IDM.SELECTALL);
            AddCommand(IDM.SHOWALLTAGS);
            AddCommand(IDM.SHOWHIDE_CODE);
            AddCommand(IDM.SHOWZEROBORDERATDESIGNTIME);
            AddCommand(IDM.STRIKETHROUGH);
            AddCommand(IDM.TEXTAREA);
            AddCommand(IDM.UNBOOKMARK);
            AddCommand(IDM.UNDERLINE);
            AddCommand(IDM.UNDO);
            AddCommand(IDM.UNLINK);
            AddCommand(IDM.UNORDERLIST);
            AddCommand(IDM.VIEWSOURCE);
        }