예제 #1
0
        /// <summary>
        /// Initialize a new instance of the KryptonCheckBox class.
        /// </summary>
        public KryptonCheckBox()
        {
            // Turn off standard click and double click events, we do that manually
            SetStyle(ControlStyles.StandardClick |
                     ControlStyles.StandardDoubleClick, false);

            // Set default properties
            _style         = LabelStyle.NormalControl;
            _orientation   = VisualOrientation.Top;
            _checkPosition = VisualOrientation.Left;
            _checked       = false;
            _threeState    = false;
            _checkState    = CheckState.Unchecked;
            _useMnemonic   = true;
            AutoCheck      = true;

            // Create content storage
            Values              = new LabelValues(NeedPaintDelegate);
            Values.TextChanged += OnCheckBoxTextChanged;
            Images              = new CheckBoxImages(NeedPaintDelegate);

            // Create palette redirector
            _paletteCommonRedirect = new PaletteContentInheritRedirect(Redirector, PaletteContentStyle.LabelNormalControl);
            _paletteCheckBoxImages = new PaletteRedirectCheckBox(Redirector, Images);

            // Create the palette provider
            StateCommon   = new PaletteContent(_paletteCommonRedirect, NeedPaintDelegate);
            StateDisabled = new PaletteContent(StateCommon, NeedPaintDelegate);
            StateNormal   = new PaletteContent(StateCommon, NeedPaintDelegate);
            OverrideFocus = new PaletteContent(_paletteCommonRedirect, NeedPaintDelegate);

            // Override the normal values with the focus, when the control has focus
            _overrideNormal = new PaletteContentInheritOverride(OverrideFocus, StateNormal, PaletteState.FocusOverride, false);

            // Our view contains background and border with content inside
            _drawContent = new ViewDrawContent(_overrideNormal, this, VisualOrientation.Top)
            {
                UseMnemonic = _useMnemonic,

                // Only draw a focus rectangle when focus cues are needed in the top level form
                TestForFocusCues = true
            };

            // Create the check box image drawer and place inside element so it is always centered
            _drawCheckBox = new ViewDrawCheckBox(_paletteCheckBoxImages)
            {
                CheckState = _checkState
            };
            _layoutCenter = new ViewLayoutCenter
            {
                _drawCheckBox
            };

            // Place check box on the left and the label in the remainder
            _layoutDocker = new ViewLayoutDocker
            {
                { _layoutCenter, ViewDockStyle.Left },
                { _drawContent, ViewDockStyle.Fill }
            };

            // Need a controller for handling mouse input
            _controller                   = new CheckBoxController(_drawCheckBox, _layoutDocker, NeedPaintDelegate);
            _controller.Click            += OnControllerClick;
            _controller.Enabled           = true;
            _layoutDocker.MouseController = _controller;
            _layoutDocker.KeyController   = _controller;

            // Change the layout to match the inital right to left setting and orientation
            UpdateForOrientation();

            // Create the view manager instance
            ViewManager = new ViewManager(this, _layoutDocker);

            // We want to be auto sized by default, but not the property default!
            AutoSize     = true;
            AutoSizeMode = AutoSizeMode.GrowAndShrink;
        }
예제 #2
0
        /// <summary>
        /// Key has been pressed down.
        /// </summary>
        /// <param name="c">Reference to the source control instance.</param>
        /// <param name="e">A KeyEventArgs that contains the event data.</param>
        /// <exception cref="ArgumentNullException"></exception>
        public virtual void KeyDown(Control c, KeyEventArgs e)
        {
            Debug.Assert(c != null);
            Debug.Assert(e != null);

            // Validate incoming references
            if (c == null)
            {
                throw new ArgumentNullException(nameof(c));
            }

            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }

            if (ViewManager != null)
            {
                switch (e.KeyCode)
                {
                case Keys.Tab:
                    ViewManager.KeyTab(e.Shift);
                    return;
                }
            }

            // Get the current focus date
            DateTime focusDate  = _months.FocusDay ?? (_monthCalendar?.SelectionStart ?? _months.Calendar.SelectionStart);
            DateTime anchorDate = _months.AnchorDay ?? (_monthCalendar?.SelectionStart ?? _months.Calendar.SelectionStart);

            // Use keyboard to modify the new focus date
            switch (e.KeyCode)
            {
            case Keys.Left:
                focusDate = e.Control ? focusDate.AddMonths(-1) : focusDate.AddDays(-1);

                break;

            case Keys.Right:
                focusDate = e.Control ? focusDate.AddMonths(1) : focusDate.AddDays(1);

                break;

            case Keys.Up:
                focusDate = focusDate.AddDays(-7);
                break;

            case Keys.Down:
                focusDate = focusDate.AddDays(7);
                break;

            case Keys.Home:
                if (e.Control)
                {
                    focusDate = focusDate.AddMonths(-1);
                    focusDate = new DateTime(focusDate.Year, focusDate.Month, 1);
                }
                else
                {
                    focusDate = new DateTime(focusDate.Year, focusDate.Month, 1);
                }

                break;

            case Keys.End:
                if (e.Control)
                {
                    focusDate = focusDate.AddMonths(1);
                    focusDate = new DateTime(focusDate.Year, focusDate.Month, 1);
                    focusDate = focusDate.AddMonths(1).AddDays(-1);
                }
                else
                {
                    focusDate = new DateTime(focusDate.Year, focusDate.Month, 1);
                    focusDate = focusDate.AddMonths(1).AddDays(-1);
                }
                break;

            case Keys.PageUp:
                focusDate = e.Control ? focusDate.AddMonths(-1 * _months.Months) : focusDate.AddMonths(-1);

                break;

            case Keys.PageDown:
                focusDate = e.Control ? focusDate.AddMonths(1 * _months.Months) : focusDate.AddMonths(1);

                break;

            case Keys.Enter:
            case Keys.Space:
                if ((_monthCalendar != null) && _monthCalendar.AutoClose && (_months.Provider != null))
                {
                    // Is the menu capable of being closed?
                    if (_months.Provider.ProviderCanCloseMenu)
                    {
                        // Ask the original context menu definition, if we can close
                        CancelEventArgs cea = new CancelEventArgs();
                        _months.Provider.OnClosing(cea);

                        if (!cea.Cancel)
                        {
                            // Close the menu from display and pass in the item clicked as the reason
                            _months.Provider.OnClose(new CloseReasonEventArgs(ToolStripDropDownCloseReason.Keyboard));
                        }
                    }
                }
                break;
            }

            // If the max selection count is 1 then always treat the new selection as the new focus
            // day we have just calculated. If the shift key is not pressed then definitely treat as
            // a single day selection.
            if ((_months.Calendar.MaxSelectionCount == 1) || !e.Shift)
            {
                _months.AnchorDay = focusDate;
                _months.FocusDay  = focusDate;
                _months.Calendar.SetSelectionRange(focusDate, focusDate);

                if (ViewManager != null)
                {
                    _needPaint(this, new NeedLayoutEventArgs(true));
                }
            }
            else
            {
                DateTime startDate = _months.Calendar.SelectionStart;
                DateTime endDate   = _months.Calendar.SelectionEnd;

                if (focusDate < anchorDate)
                {
                    // Cannot extend selection beyond the max selection count
                    if ((anchorDate - focusDate).Days >= _months.Calendar.MaxSelectionCount)
                    {
                        focusDate = anchorDate.AddDays(-(_months.Calendar.MaxSelectionCount - 1));
                    }

                    startDate = focusDate;
                    endDate   = anchorDate;
                }
                else if (focusDate > anchorDate)
                {
                    // Cannot extend selection beyond the max selection count
                    if ((focusDate - anchorDate).Days >= _months.Calendar.MaxSelectionCount)
                    {
                        focusDate = anchorDate.AddDays(_months.Calendar.MaxSelectionCount - 1);
                    }

                    startDate = anchorDate;
                    endDate   = focusDate;
                }

                _months.AnchorDay = anchorDate;
                _months.FocusDay  = focusDate;
                _months.Calendar.SetSelectionRange(startDate, endDate);

                if (ViewManager != null)
                {
                    _needPaint(this, new NeedLayoutEventArgs(true));
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Initialize a new instance of the KryptonButton class.
        /// </summary>
        public KryptonButton()
        {
            // We generate click events manually, suppress default
            // production of them by the base Control class
            SetStyle(ControlStyles.StandardClick |
                     ControlStyles.StandardDoubleClick, false);

            // Set default button properties
            _style       = ButtonStyle.Standalone;
            DialogResult = DialogResult.None;
            _orientation = VisualOrientation.Top;
            _useMnemonic = true;

            // Create content storage
            Values              = CreateButtonValues(NeedPaintDelegate);
            Values.TextChanged += OnButtonTextChanged;

            // Create the palette storage
            StateCommon     = new PaletteTripleRedirect(Redirector, PaletteBackStyle.ButtonStandalone, PaletteBorderStyle.ButtonStandalone, PaletteContentStyle.ButtonStandalone, NeedPaintDelegate);
            StateDisabled   = new PaletteTriple(StateCommon, NeedPaintDelegate);
            StateNormal     = new PaletteTriple(StateCommon, NeedPaintDelegate);
            StateTracking   = new PaletteTriple(StateCommon, NeedPaintDelegate);
            StatePressed    = new PaletteTriple(StateCommon, NeedPaintDelegate);
            OverrideDefault = new PaletteTripleRedirect(Redirector, PaletteBackStyle.ButtonStandalone, PaletteBorderStyle.ButtonStandalone, PaletteContentStyle.ButtonStandalone, NeedPaintDelegate);
            OverrideFocus   = new PaletteTripleRedirect(Redirector, PaletteBackStyle.ButtonStandalone, PaletteBorderStyle.ButtonStandalone, PaletteContentStyle.ButtonStandalone, NeedPaintDelegate);

            // Create the override handling classes
            _overrideFocus    = new PaletteTripleOverride(OverrideFocus, StateNormal, PaletteState.FocusOverride);
            _overrideNormal   = new PaletteTripleOverride(OverrideDefault, _overrideFocus, PaletteState.NormalDefaultOverride);
            _overrideTracking = new PaletteTripleOverride(OverrideFocus, StateTracking, PaletteState.FocusOverride);
            _overridePressed  = new PaletteTripleOverride(OverrideFocus, StatePressed, PaletteState.FocusOverride);

            // Create the view button instance
            _drawButton = new ViewDrawButton(StateDisabled,
                                             _overrideNormal,
                                             _overrideTracking,
                                             _overridePressed,
                                             new PaletteMetricRedirect(Redirector),
                                             this,
                                             Orientation,
                                             UseMnemonic)
            {
                // Only draw a focus rectangle when focus cues are needed in the top level form
                TestForFocusCues = true
            };

            // Create a button controller to handle button style behaviour
            _buttonController = new ButtonController(_drawButton, NeedPaintDelegate);

            // Assign the controller to the view element to treat as a button
            _drawButton.MouseController  = _buttonController;
            _drawButton.KeyController    = _buttonController;
            _drawButton.SourceController = _buttonController;

            // Need to know when user clicks the button view or mouse selects it
            _buttonController.Click       += OnButtonClick;
            _buttonController.MouseSelect += OnButtonSelect;

            // Create the view manager instance
            ViewManager = new ViewManager(this, _drawButton);
        }
예제 #4
0
        /// <summary>
        /// Mouse has entered the view.
        /// </summary>
        /// <param name="c">Reference to the source control instance.</param>
        public virtual void MouseEnter(Control c)
        {
            _mouseOver = true;

            ViewManager?.SetTarget(this, true);
        }