示例#1
0
        private const string ToolboxFormat = ".NET Toolbox Item"; // used to detect if a drag is coming from the toolbox.

        internal BehaviorService(IServiceProvider serviceProvider, Control windowFrame)
        {
            _serviceProvider = serviceProvider;
            _adornerWindow   = new AdornerWindow(this, windowFrame);

            // Use the adornerWindow as an overlay
            IOverlayService os = (IOverlayService)serviceProvider.GetService(typeof(IOverlayService));

            if (os != null)
            {
                AdornerWindowIndex = os.PushOverlay(_adornerWindow);
            }

            _dragEnterReplies = new Hashtable();

            // Start with an empty adorner collection & no behavior on the stack
            Adorners       = new BehaviorServiceAdornerCollection(this);
            _behaviorStack = new ArrayList();

            _hitTestedGlyph     = null;
            _validDragArgs      = null;
            DesignerActionUI    = null;
            _trackMouseEvent    = default;
            _trackingMouseEvent = false;

            // Create out object that will handle all menucommands
            if (serviceProvider.GetService(typeof(IMenuCommandService)) is IMenuCommandService menuCommandService &&
                serviceProvider.GetService(typeof(IDesignerHost)) is IDesignerHost host)
            {
                _menuCommandHandler = new MenuCommandHandler(this, menuCommandService);
                host.RemoveService(typeof(IMenuCommandService));
                host.AddService(typeof(IMenuCommandService), _menuCommandHandler);
            }

            // Default layoutmode is SnapToGrid.
            _useSnapLines     = false;
            _queriedSnapLines = false;

            // Test hooks
            WM_GETALLSNAPLINES    = User32.RegisterWindowMessageW("WM_GETALLSNAPLINES");
            WM_GETRECENTSNAPLINES = User32.RegisterWindowMessageW("WM_GETRECENTSNAPLINES");

            // Listen to the SystemEvents so that we can resync selection based on display settings etc.
            SystemEvents.UserPreferenceChanged += new UserPreferenceChangedEventHandler(OnUserPreferenceChanged);
        }
示例#2
0
        /// <summary>
        ///  Creates a new tab order control that displays the tab order
        ///  UI for a form.
        /// </summary>
        public TabOrder(IDesignerHost host)
        {
            this.host = host;

            // Determine a font for us to use.
            //
            IUIService uisvc = (IUIService)host.GetService(typeof(IUIService));

            if (uisvc != null)
            {
                tabFont = (Font)uisvc.Styles["DialogFont"];
            }
            else
            {
                tabFont = DefaultFont;
            }

            tabFont = new Font(tabFont, FontStyle.Bold);

            // And compute the proper highlight dimensions.
            //
            selSize = DesignerUtils.GetAdornmentDimensions(AdornmentType.GrabHandle).Width;

            // Colors and brushes...
            //
            drawString         = new StringBuilder(12);
            highlightTextBrush = new SolidBrush(SystemColors.HighlightText);
            highlightPen       = new Pen(SystemColors.Highlight);

            // The decimal separator
            //
            NumberFormatInfo formatInfo = (NumberFormatInfo)CultureInfo.CurrentCulture.GetFormat(typeof(NumberFormatInfo));

            if (formatInfo != null)
            {
                decimalSep = formatInfo.NumberDecimalSeparator;
            }
            else
            {
                decimalSep = ".";
            }

            tabProperties = new Hashtable();

            // Set up a NULL brush so we never try to invalidate the control.  This is
            // more efficient for what we're doing
            //
            SetStyle(ControlStyles.Opaque, true);

            // We're an overlay on top of the form
            //
            IOverlayService os = (IOverlayService)host.GetService(typeof(IOverlayService));

            Debug.Assert(os != null, "No overlay service -- tab order UI cannot be shown");
            if (os != null)
            {
                os.PushOverlay(this);
            }

            // Push a help keyword so the help system knows we're in place.
            //
            IHelpService hs = (IHelpService)host.GetService(typeof(IHelpService));

            if (hs != null)
            {
                hs.AddContextAttribute("Keyword", "TabOrderView", HelpKeywordType.FilterKeyword);
            }

            commands = new MenuCommand[]
            {
                new MenuCommand(new EventHandler(OnKeyCancel),
                                MenuCommands.KeyCancel),

                new MenuCommand(new EventHandler(OnKeyDefault),
                                MenuCommands.KeyDefaultAction),

                new MenuCommand(new EventHandler(OnKeyPrevious),
                                MenuCommands.KeyMoveUp),

                new MenuCommand(new EventHandler(OnKeyNext),
                                MenuCommands.KeyMoveDown),

                new MenuCommand(new EventHandler(OnKeyPrevious),
                                MenuCommands.KeyMoveLeft),

                new MenuCommand(new EventHandler(OnKeyNext),
                                MenuCommands.KeyMoveRight),

                new MenuCommand(new EventHandler(OnKeyNext),
                                MenuCommands.KeySelectNext),

                new MenuCommand(new EventHandler(OnKeyPrevious),
                                MenuCommands.KeySelectPrevious),
            };

            newCommands = new MenuCommand[]
            {
                new MenuCommand(new EventHandler(OnKeyDefault),
                                MenuCommands.KeyTabOrderSelect),
            };

            IMenuCommandService mcs = (IMenuCommandService)host.GetService(typeof(IMenuCommandService));

            if (mcs != null)
            {
                foreach (MenuCommand mc in newCommands)
                {
                    mcs.AddCommand(mc);
                }
            }

            // We also override keyboard, menu and mouse handlers.  Our override relies on the
            // above array of menu commands, so this must come after we initialize the array.
            //
            IEventHandlerService ehs = (IEventHandlerService)host.GetService(typeof(IEventHandlerService));

            if (ehs != null)
            {
                ehs.PushHandler(this);
            }

            // We sync add, remove and change events so we remain in sync with any nastiness that the
            // form may pull on us.
            //
            IComponentChangeService cs = (IComponentChangeService)host.GetService(typeof(IComponentChangeService));

            if (cs != null)
            {
                cs.ComponentAdded   += new ComponentEventHandler(OnComponentAddRemove);
                cs.ComponentRemoved += new ComponentEventHandler(OnComponentAddRemove);
                cs.ComponentChanged += new ComponentChangedEventHandler(OnComponentChanged);
            }
        }
        public TabOrder(IDesignerHost host)
        {
            this.host = host;
            IUIService service = (IUIService)host.GetService(typeof(IUIService));

            if (service != null)
            {
                this.tabFont = (Font)service.Styles["DialogFont"];
            }
            else
            {
                this.tabFont = Control.DefaultFont;
            }
            this.tabFont            = new Font(this.tabFont, FontStyle.Bold);
            this.selSize            = DesignerUtils.GetAdornmentDimensions(AdornmentType.GrabHandle).Width;
            this.drawString         = new StringBuilder(12);
            this.highlightTextBrush = new SolidBrush(SystemColors.HighlightText);
            this.highlightPen       = new Pen(SystemColors.Highlight);
            NumberFormatInfo format = (NumberFormatInfo)CultureInfo.CurrentCulture.GetFormat(typeof(NumberFormatInfo));

            if (format != null)
            {
                this.decimalSep = format.NumberDecimalSeparator;
            }
            else
            {
                this.decimalSep = ".";
            }
            this.tabProperties = new Hashtable();
            base.SetStyle(ControlStyles.Opaque, true);
            IOverlayService service2 = (IOverlayService)host.GetService(typeof(IOverlayService));

            if (service2 != null)
            {
                service2.PushOverlay(this);
            }
            IHelpService service3 = (IHelpService)host.GetService(typeof(IHelpService));

            if (service3 != null)
            {
                service3.AddContextAttribute("Keyword", "TabOrderView", HelpKeywordType.FilterKeyword);
            }
            this.commands    = new MenuCommand[] { new MenuCommand(new EventHandler(this.OnKeyCancel), MenuCommands.KeyCancel), new MenuCommand(new EventHandler(this.OnKeyDefault), MenuCommands.KeyDefaultAction), new MenuCommand(new EventHandler(this.OnKeyPrevious), MenuCommands.KeyMoveUp), new MenuCommand(new EventHandler(this.OnKeyNext), MenuCommands.KeyMoveDown), new MenuCommand(new EventHandler(this.OnKeyPrevious), MenuCommands.KeyMoveLeft), new MenuCommand(new EventHandler(this.OnKeyNext), MenuCommands.KeyMoveRight), new MenuCommand(new EventHandler(this.OnKeyNext), MenuCommands.KeySelectNext), new MenuCommand(new EventHandler(this.OnKeyPrevious), MenuCommands.KeySelectPrevious) };
            this.newCommands = new MenuCommand[] { new MenuCommand(new EventHandler(this.OnKeyDefault), MenuCommands.KeyTabOrderSelect) };
            IMenuCommandService service4 = (IMenuCommandService)host.GetService(typeof(IMenuCommandService));

            if (service4 != null)
            {
                foreach (MenuCommand command in this.newCommands)
                {
                    service4.AddCommand(command);
                }
            }
            IEventHandlerService service5 = (IEventHandlerService)host.GetService(typeof(IEventHandlerService));

            if (service5 != null)
            {
                service5.PushHandler(this);
            }
            IComponentChangeService service6 = (IComponentChangeService)host.GetService(typeof(IComponentChangeService));

            if (service6 != null)
            {
                service6.ComponentAdded   += new ComponentEventHandler(this.OnComponentAddRemove);
                service6.ComponentRemoved += new ComponentEventHandler(this.OnComponentAddRemove);
                service6.ComponentChanged += new ComponentChangedEventHandler(this.OnComponentChanged);
            }
        }